Skip to content

Commit ca41180

Browse files
committed
Working develop API
1 parent ef8e374 commit ca41180

File tree

102 files changed

+29775
-819
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+29775
-819
lines changed

.github/workflows/publish.yml

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: "publish"
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
7+
jobs:
8+
publish:
9+
name: publish
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
14+
- name: Extract branch name
15+
shell: bash
16+
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
17+
18+
- name: checkout
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
ref: ${{ env.branch }}
23+
24+
- name: node
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: 20
28+
registry-url: https://registry.npmjs.org
29+
30+
- name: Get tag version
31+
run: |
32+
echo "tag_version=`awk '/^## \[[0-9]+/' CHANGELOG.md | awk 'NR==1 && -F"\[\]" {print $2}' 2>/dev/null | tail -c +2 | head -c -2`" >> $GITHUB_ENV
33+
34+
- name: Check if tag is for develop and if it already exists
35+
run: |
36+
git fetch --prune --tags
37+
if [ ${{ env.branch }} == 'develop' ]; then
38+
for i in {1..100}; do
39+
if [ `git tag --list | grep ${{ env.tag_version }}"-alpha.${i}" | wc -l` -eq 0 ]; then
40+
tag_version=${{ env.tag_version }}"-alpha.${i}"
41+
echo "tag_version=${tag_version}" >> $GITHUB_ENV
42+
echo "npm_tag_version=develop" >> $GITHUB_ENV
43+
break;
44+
fi
45+
done
46+
elif [ ${{ env.branch }} == 'master' ]; then
47+
echo "npm_tag_version=latest" >> $GITHUB_ENV
48+
elif [ `git tag --list | grep -q ${{ env.tag_version }}` -ne 0 ]; then exit 1; fi
49+
50+
- name: Update package.json version, package-lock.json and commit
51+
working-directory: ./src
52+
run: |
53+
jq '.version = "'"$tag_version"'"' package.json > package.tmp && mv package.tmp package.json
54+
npm install --package-lock-only
55+
git config user.name "GitHub Actions Bot"
56+
git config user.email "<>"
57+
58+
if [ "$(git diff --exit-code)" ]; then
59+
git add package.json package-lock.json
60+
git commit -m "Updated package and package-lock with ${npm_version}"
61+
git push
62+
fi
63+
64+
- name: publish
65+
working-directory: ./src
66+
run: |
67+
cp ../README.md ../CHANGELOG.md .
68+
npm publish --tag ${{ env.npm_tag_version }} --access public
69+
env:
70+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
71+
72+
- name: Get changelog body
73+
run: |
74+
awk '/^## \[[0-9]+/,EOF' CHANGELOG.md | awk '(NR>1)' | awk '1;/^## \[[0-9]+/{exit}' | sed '$d' > release_body.md
75+
76+
- name: Set pre-release boolean
77+
run: |
78+
prerelease=false
79+
if [ ${{ env.branch }} == 'develop' ]; then
80+
prerelease=true
81+
fi
82+
echo "prerelease=$prerelease" >> $GITHUB_ENV
83+
84+
- name: Create GitHub release
85+
uses: ncipollo/release-action@v1
86+
with:
87+
prerelease: ${{ env.prerelease }}
88+
commit: ${{ env.branch }}
89+
tag: ${{ env.tag_version }}
90+
name: ${{ env.tag_version }}
91+
token: ${{ secrets.GITHUB_TOKEN }}
92+
bodyFile: "release_body.md"

.gitignore

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
wwwroot/*.js
2-
node_modules
3-
typings
4-
dist
51
.idea
2+
openapi.clean.json

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## [0.1.0] - 2025-01-08
6+
7+
### Added
8+
9+
- Initial release of the Thinger.io Node.js SDK for Devices, Plugins and Products
10+
11+
[0.1.0]: https://github.com/thinger-io/thinger-node/tag/0.1.0
12+
13+

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
MIT License
3+
4+
Copyright (c) 2025 Thinger.io
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

+18-23
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1+
# Thinger.io Node.js Library
12

2-
# Thinger Node.js library
3-
4-
This library provides a Node.js client for the Thinger.io platform, autogenerated from the OpenAPI specification.
5-
6-
```
7-
docker run --rm --user 1000 \
8-
-v ${PWD}:/local openapitools/openapi-generator-cli generate \
9-
-i /local/out/swagger.json \
10-
-g typescript-node \
11-
-c /local/out/config.yaml \
12-
--skip-validate-spec \
13-
-e mustache \
14-
-t /local/out/node/templates \
15-
--remove-operation-id-prefix \
16-
--reserved-words-mappings \
17-
-o /local/out/node
18-
```
19-
20-
## Extract templates
21-
22-
```
23-
docker run --rm --user 1000 \
24-
-v ${PWD}:/local openapitools/openapi-generator-cli author template -g typescript-node -o /local/templates
3+
> [!WARNING]
4+
> Currently this Library is in development and may contain bugs or incomplete features.
5+
6+
The Thinger.io Node library provides convenient access to the Thinger.io API from applications written in server-side JavaScript.
7+
8+
## Documentation
9+
10+
See the [Thinger.io API documentation](https://console.thinger.io/swagger/) for a complete reference of the Thinger.io API.
11+
12+
Library documentation is available in [src/README.md](./src/README.md).
13+
14+
## Installation
15+
16+
Install the package with:
17+
18+
```sh
19+
npm install @thinger-io/thinger-node
2520
```

TODO.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# thinger-node
2+
3+
This generator creates TypeScript/JavaScript client that utilizes native fetch-api.
4+
5+
### Todo
6+
7+
- [X] Full replacement of `node-fetch` for native fetch in templates
8+
- [X] `fetch` in `isomorphic-fetch.ts` interaction with http file
9+
- [ ] Add `User-Agent` header to `fetch` in `isomorphic-fetch.ts`
10+
- [ ] Add tests with mock functionality
11+
- [ ] Add Thinger.io API
12+
- [ ] Add `Server` API
13+
- [X] Add `Plugins` API
14+
- [ ] Add `Users` API
15+
- [ ] Add `Brands` API
16+
- [ ] Add `Claims` API
17+
- [ ] Add `Domains` API
18+
- [ ] Add `Endpoints` API
19+
- [ ] Add `Hosts` API
20+
- [ ] Add `OauthClients` API
21+
- [ ] Add `Proxies` API
22+
- [ ] Add `Alarms` API
23+
- [ ] Add `Alarms` API
24+
- [ ] Add `Assets` API
25+
- [ ] Add `Buckets` API
26+
- [ ] Add `Dashboards` API
27+
- [X] Add `Devices` API
28+
- [ ] Add `Groups` API
29+
- [X] Add `Products` API
30+
- [ ] Add `Projects` API
31+
- [ ] Add `Roles` API
32+
- [ ] Add `Storages` API
33+
- [ ] Add `Syncs` API
34+
- [ ] Add `Tokens` API
35+
- [ ] Add `Types` API
36+
- [ ] Allow declaration of arrays in body as well as simple objects (see property create)

config.yaml

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
disallowAdditionalPropertiesIfNotPresent: false
2-
licenseName: "MIT"
3-
npmName: "thinger-node"
4-
npmRepository: "https://github.com/thinger-io/thinger-node"
5-
npmVersion: "0.0.1"
6-
supportsES6: true
7-
validationAttributes: true
8-
withInterfaces: true
1+
generatorName: typescript
2+
outputDir: /local/src
3+
inputSpec: /local/openapi.clean.json
4+
templateDir: /local/templates
5+
additionalProperties:
6+
disallowAdditionalPropertiesIfNotPresent: false
7+
licenseName: "MIT"
8+
npmName: "@thinger-io/thinger-node"
9+
npmVersion: "0.1.0"
10+
platform: "node"
11+
supportsES6: true
12+
useObjectParameters: false
13+
importFileExtension: ".js"
14+
#validationAttributes: true
15+
#withInterfaces: true
916
openapiNormalizer:
17+
SIMPLIFY_ONEOF_ANYOF: true
1018
REMOVE_X_INTERNAL: true
1119
KEEP_ONLY_FIRST_TAG_IN_OPERATION: true
20+
SIMPLIFY_ANYOF_STRING_AND_ENUM_STRING: true
21+
REFACTOR_ALLOF_WITH_PROPERTIES_ONLY: false
1222
reservedWordsMappings:
1323
delete: remove
1424
export: exportData
15-
# Global config
16-
apiTests: true
17-
modelTests: true

generate.sh

100644100755
+61-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,69 @@ curl -X 'GET' \
66
-H 'accept: application/json' \
77
-o openapi.json
88

9+
# Remove previous generated files
10+
rm -rf src
11+
12+
jq . openapi.json > openapi.tmp1.json # prettify
13+
# Remove unused schemas
14+
jq 'del(
15+
.components.schemas.alarm_rule,
16+
.components.schemas.bucket_backend,
17+
.components.schemas.bucket_config,
18+
.components.schemas.bucket_retention,
19+
.components.schemas.claim_config,
20+
.components.schemas.permission,
21+
.components.schemas.projects_ids,
22+
.components.schemas.sync_config
23+
)' openapi.tmp1.json > openapi.tmp2.json
24+
25+
# Remove paths that are not tagged with Products or Plugins
26+
jq 'del(.paths[] | select([.[]? | .tags? | (
27+
index("Products") //
28+
index("Plugins") //
29+
index("Devices")
30+
)] | any == false))' openapi.tmp2.json > openapi.tmp3.json
31+
32+
# Remove the array as body when another body is present ( property create )
33+
jq 'walk(
34+
if type == "object" then
35+
with_entries(
36+
# Check if the key is "requestBody" and if it contains "oneOf"
37+
if .key == "requestBody" and
38+
.value.content?.["application/json"]?.schema?.oneOf then
39+
.value.content."application/json".schema |= { "$ref": "#/components/schemas/property_create" }
40+
else
41+
. # Leave other parts as is
42+
end
43+
)
44+
else
45+
. # No changes to non-object values
46+
end
47+
)' openapi.tmp3.json > openapi.tmp4.json
48+
49+
mv openapi.tmp4.json openapi.clean.json
50+
rm openapi.tmp*.json
51+
952
# Generate the client
1053
docker run --rm --user 1000 \
1154
-v ${PWD}:/local openapitools/openapi-generator-cli generate \
12-
-i /local/openapi.json \
13-
-g typescript-node \
55+
-g typescript \
1456
-c /local/config.yaml \
1557
-e mustache \
16-
-t /local/templates \
17-
--remove-operation-id-prefix \
18-
-o /local
58+
--remove-operation-id-prefix
59+
60+
# -i /local/openapi.json \
61+
# -t /local/templates \
62+
# --skip-validate-spec \
63+
#--dry-run
64+
# --git-host <git host>
65+
# Git host, e.g. gitlab.com.
66+
#
67+
# --git-repo-id <git repo id>
68+
# Git repo ID, e.g. openapi-generator.
69+
#
70+
# --git-user-id <git user id>
71+
# Git user ID, e.g. openapitools.
72+
# --reserved-words-mappings
73+
74+

openapi.json

+1
Large diffs are not rendered by default.

src/.gitattributes

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.gitignore

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.openapi-generator-ignore

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)