@xube/kit-sdk 0.1.0

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/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@xube/kit-sdk",
3
+ "version": "0.1.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "xube-sdk": "./dist/cli.js"
8
+ },
9
+ "scripts": {
10
+ "generate": "xube-sdk generate",
11
+ "test": "echo \"Error: no test specified\" && exit 1"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+ssh://git@github.com/XubeLtd/data-logger.git"
16
+ },
17
+ "author": "Xube Pty Ltd",
18
+ "license": "MIT",
19
+ "bugs": {
20
+ "url": "https://github.com/XubeLtd/data-logger/issues"
21
+ },
22
+ "homepage": "https://github.com/XubeLtd/data-logger#readme",
23
+ "dependencies": {
24
+ "@zodios/core": "^10.9.6",
25
+ "axios": "^1.7.7",
26
+ "case-anything": "^2.1.13",
27
+ "handlebars": "^4.7.8",
28
+ "openapi-types": "^12.1.3",
29
+ "openapi-zod-client": "^1.18.3",
30
+ "openapi3-ts": "^4.4.0",
31
+ "zod": "3.25.76",
32
+ "zodios": "^5.1.0"
33
+ },
34
+ "devDependencies": {
35
+ "@xube/kit-build": "^0.1.0"
36
+ }
37
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env node
2
+
3
+ import axios from "axios";
4
+ import { camelCase } from "case-anything";
5
+ import { existsSync, mkdirSync } from "fs";
6
+ import { generateZodClientFromOpenAPI } from "openapi-zod-client";
7
+ import type { OpenAPIObject } from "openapi3-ts/oas30";
8
+ import { dirname, join } from "path";
9
+
10
+ const getTemplatePath = () => {
11
+ let currentDir = __dirname;
12
+ while (currentDir !== dirname(currentDir)) {
13
+ if (existsSync(join(currentDir, "package.json"))) {
14
+ const templatePath = join(
15
+ currentDir,
16
+ "templates",
17
+ "schemas-and-types.hbs"
18
+ );
19
+ if (existsSync(templatePath)) {
20
+ return templatePath;
21
+ }
22
+ }
23
+ currentDir = dirname(currentDir);
24
+ }
25
+ throw new Error(
26
+ "Could not find templates/schemas-and-types.hbs in package root"
27
+ );
28
+ };
29
+
30
+ const getApiEnvironmentUrl = () =>
31
+ `https://xube-docs-prod.s3.eu-west-1.amazonaws.com/api.json`;
32
+
33
+ const fetchOpenApiSpec = async (): Promise<OpenAPIObject> => {
34
+ const url = getApiEnvironmentUrl();
35
+
36
+ try {
37
+ const response = await axios.get(url);
38
+
39
+ console.log("Got OpenAPI spec");
40
+
41
+ return response.data;
42
+ } catch (e) {
43
+ console.error(
44
+ `Error fetching OpenAPI spec from ${url}: ${JSON.stringify(e)}`
45
+ );
46
+ process.exit(1);
47
+ }
48
+ };
49
+
50
+ const generateSdk = async (openApiSpec: OpenAPIObject) => {
51
+ const destinationDirectory = "packages/kit-sdk/src/sdk";
52
+ const distPath = join(destinationDirectory, `xube-sdk.ts`);
53
+
54
+ if (!existsSync(destinationDirectory)) {
55
+ mkdirSync(destinationDirectory, { recursive: true });
56
+ }
57
+
58
+ const sdkCode = await generateZodClientFromOpenAPI({
59
+ openApiDoc: openApiSpec,
60
+ distPath,
61
+ templatePath: getTemplatePath(),
62
+ options: {
63
+ withAlias: true,
64
+ apiClientName: "XubeSdk",
65
+ withDocs: true,
66
+ exportAllNamedSchemas: true,
67
+ shouldExportAllSchemas: true,
68
+ shouldExportAllTypes: true,
69
+ withImplicitRequiredProps: true,
70
+ additionalPropertiesDefaultValue: false,
71
+ },
72
+ });
73
+
74
+ console.log(`SDK generated successfully at ${distPath}`);
75
+ };
76
+
77
+ const run = async () => {
78
+ const args = process.argv.slice(2);
79
+
80
+ switch (args[0]) {
81
+ case "generate": {
82
+ try {
83
+ const openApiSpec = await fetchOpenApiSpec();
84
+ await generateSdk(openApiSpec);
85
+ } catch (error) {
86
+ console.error("Error generating SDK:", error);
87
+ process.exit(1);
88
+ }
89
+ break;
90
+ }
91
+ default:
92
+ console.error("Option must be provided: generate");
93
+ process.exit(1);
94
+ }
95
+ };
96
+
97
+ run();
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./sdk/xube-sdk";