@budibase/sdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2019-2021, Budibase Ltd.
2
+
3
+ Each Budibase package has its own license, please check the license file in each package.
4
+
5
+ You can consider Budibase to be GPLv3 licensed overall.
6
+
7
+ The apps that you build with Budibase do not package any GPLv3 licensed code, thus do not fall under those restrictions.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Budibase Public API SDK
2
+ JS SDK for the Budibase Public API.
3
+
4
+ This SDK is generated by [swagger-codegen](https://github.com/swagger-api/swagger-codegen).
5
+
6
+ Docker is used to run the generator, so Java is not required. Docker is the only requirement to generate the SDK.
7
+
8
+ The generated code will only run in a browser. It is not currently useable in a NodeJS environment.
9
+
10
+ ## Example usage
11
+ ```js
12
+ import { configure, ApplicationsApi } from "@budibase/sdk"
13
+
14
+ // Configure the API client
15
+ configure({
16
+ apiKey: "my-api-key",
17
+ host: "https://my.budibase.app"
18
+ })
19
+
20
+ // Search for an app.
21
+ // We can use the promisified version...
22
+ const res = await ApplicationsApi.applicationsSearchPost({ name: "foo" })
23
+ console.log("Applications:", res.data)
24
+
25
+ // ...or the callback version
26
+ ApplicationsApi.applicationsSearchPost({ name: "foo" }, ((error, data) => {
27
+ if (error) {
28
+ console.error("Failed to search:", error)
29
+ } else {
30
+ console.log("Applications:", data.data)
31
+ }
32
+ }))
33
+ ```
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@budibase/sdk",
3
+ "version": "0.0.1",
4
+ "description": "Budibase Public API SDK",
5
+ "author": "Budibase",
6
+ "license": "MPL-2.0",
7
+ "module": "dist/sdk.mjs",
8
+ "type": "module",
9
+ "scripts": {
10
+ "generate": "cd scripts && bash generate-sdk.sh",
11
+ "build:sdk": "yarn run generate && rollup -c"
12
+ },
13
+ "dependencies": {
14
+ "superagent": "^5.3.0"
15
+ },
16
+ "devDependencies": {
17
+ "@rollup/plugin-commonjs": "^18.0.0",
18
+ "@rollup/plugin-node-resolve": "^11.2.1",
19
+ "rollup": "^2.44.0",
20
+ "rollup-plugin-polyfill-node": "^0.8.0",
21
+ "rollup-plugin-terser": "^7.0.2"
22
+ },
23
+ "gitHead": "365911a77f6365818fd82fe8e2fe7e2b5d9fc1b3"
24
+ }
@@ -0,0 +1,22 @@
1
+ import commonjs from "@rollup/plugin-commonjs"
2
+ import resolve from "@rollup/plugin-node-resolve"
3
+ import nodePolyfills from "rollup-plugin-polyfill-node"
4
+
5
+ export default {
6
+ input: "src/index.js",
7
+ output: [
8
+ {
9
+ sourcemap: false,
10
+ format: "esm",
11
+ file: "./dist/sdk.mjs",
12
+ },
13
+ ],
14
+ plugins: [
15
+ commonjs(),
16
+ nodePolyfills(),
17
+ resolve({
18
+ preferBuiltins: true,
19
+ browser: true,
20
+ }),
21
+ ],
22
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "usePromises": true
3
+ }
@@ -0,0 +1,37 @@
1
+ #!/bin/bash
2
+
3
+ # Cleanup
4
+ if [[ -f "openapi.yaml" ]]; then
5
+ rm openapi.yaml
6
+ fi
7
+ if [[ -d "generated" ]]; then
8
+ rm -r generated
9
+ fi
10
+ if [[ -d "../sdk" ]]; then
11
+ rm -r ../sdk
12
+ fi
13
+
14
+ # Generate new SDK
15
+ mkdir generated
16
+ cp ../../server/specs/openapi.yaml ./
17
+ docker run --rm \
18
+ -v ${PWD}/openapi.yaml:/openapi.yml \
19
+ -v ${PWD}/generated:/generated \
20
+ -v ${PWD}/config.json:/config.json \
21
+ -u $(id -u):$(id -g) \
22
+ swaggerapi/swagger-codegen-cli-v3 generate \
23
+ -i /openapi.yml \
24
+ -l javascript \
25
+ -o /generated \
26
+ -c /config.json
27
+
28
+ # Use a subset of the generated files
29
+ mv generated/src ../sdk
30
+
31
+ # Cleanup
32
+ if [[ -f "openapi.yaml" ]]; then
33
+ rm openapi.yaml
34
+ fi
35
+ if [[ -d "generated" ]]; then
36
+ rm -r generated
37
+ fi
package/src/index.js ADDED
@@ -0,0 +1,23 @@
1
+ import * as BudibaseApi from "../sdk"
2
+
3
+ export default class SDK {
4
+ applications = new BudibaseApi.ApplicationsApi()
5
+ queries = new BudibaseApi.QueriesApi()
6
+ rows = new BudibaseApi.RowsApi()
7
+ tables = new BudibaseApi.TablesApi()
8
+ users = new BudibaseApi.UsersApi()
9
+
10
+ constructor({ apiKey, host }) {
11
+ let ApiClient = new BudibaseApi.ApiClient()
12
+
13
+ // Default to current host
14
+ ApiClient.basePath = `${host || ""}/api/public/v1`
15
+ ApiClient.authentications["ApiKeyAuth"].apiKey = apiKey
16
+
17
+ this.applications = new BudibaseApi.ApplicationsApi(ApiClient)
18
+ this.queries = new BudibaseApi.QueriesApi(ApiClient)
19
+ this.rows = new BudibaseApi.RowsApi(ApiClient)
20
+ this.tables = new BudibaseApi.TablesApi(ApiClient)
21
+ this.users = new BudibaseApi.UsersApi(ApiClient)
22
+ }
23
+ }