@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/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +79 -0
- package/dist/error.d.ts +2 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +14 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/sdk/xube-sdk.d.ts +110267 -0
- package/dist/sdk/xube-sdk.d.ts.map +1 -0
- package/dist/sdk/xube-sdk.js +7506 -0
- package/package.json +37 -0
- package/src/cli.ts +97 -0
- package/src/index.ts +1 -0
- package/src/sdk/xube-sdk.ts +8146 -0
- package/templates/schemas-and-types.hbs +87 -0
- package/tsconfig.json +13 -0
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const openapi_zod_client_1 = require("openapi-zod-client");
|
|
10
|
+
const path_1 = require("path");
|
|
11
|
+
const getTemplatePath = () => {
|
|
12
|
+
let currentDir = __dirname;
|
|
13
|
+
while (currentDir !== (0, path_1.dirname)(currentDir)) {
|
|
14
|
+
if ((0, fs_1.existsSync)((0, path_1.join)(currentDir, "package.json"))) {
|
|
15
|
+
const templatePath = (0, path_1.join)(currentDir, "templates", "schemas-and-types.hbs");
|
|
16
|
+
if ((0, fs_1.existsSync)(templatePath)) {
|
|
17
|
+
return templatePath;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
currentDir = (0, path_1.dirname)(currentDir);
|
|
21
|
+
}
|
|
22
|
+
throw new Error("Could not find templates/schemas-and-types.hbs in package root");
|
|
23
|
+
};
|
|
24
|
+
const getApiEnvironmentUrl = () => `https://xube-docs-prod.s3.eu-west-1.amazonaws.com/api.json`;
|
|
25
|
+
const fetchOpenApiSpec = async () => {
|
|
26
|
+
const url = getApiEnvironmentUrl();
|
|
27
|
+
try {
|
|
28
|
+
const response = await axios_1.default.get(url);
|
|
29
|
+
console.log("Got OpenAPI spec");
|
|
30
|
+
return response.data;
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
console.error(`Error fetching OpenAPI spec from ${url}: ${JSON.stringify(e)}`);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const generateSdk = async (openApiSpec) => {
|
|
38
|
+
const destinationDirectory = "packages/kit-sdk/src/sdk";
|
|
39
|
+
const distPath = (0, path_1.join)(destinationDirectory, `xube-sdk.ts`);
|
|
40
|
+
if (!(0, fs_1.existsSync)(destinationDirectory)) {
|
|
41
|
+
(0, fs_1.mkdirSync)(destinationDirectory, { recursive: true });
|
|
42
|
+
}
|
|
43
|
+
const sdkCode = await (0, openapi_zod_client_1.generateZodClientFromOpenAPI)({
|
|
44
|
+
openApiDoc: openApiSpec,
|
|
45
|
+
distPath,
|
|
46
|
+
templatePath: getTemplatePath(),
|
|
47
|
+
options: {
|
|
48
|
+
withAlias: true,
|
|
49
|
+
apiClientName: "XubeSdk",
|
|
50
|
+
withDocs: true,
|
|
51
|
+
exportAllNamedSchemas: true,
|
|
52
|
+
shouldExportAllSchemas: true,
|
|
53
|
+
shouldExportAllTypes: true,
|
|
54
|
+
withImplicitRequiredProps: true,
|
|
55
|
+
additionalPropertiesDefaultValue: false,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
console.log(`SDK generated successfully at ${distPath}`);
|
|
59
|
+
};
|
|
60
|
+
const run = async () => {
|
|
61
|
+
const args = process.argv.slice(2);
|
|
62
|
+
switch (args[0]) {
|
|
63
|
+
case "generate": {
|
|
64
|
+
try {
|
|
65
|
+
const openApiSpec = await fetchOpenApiSpec();
|
|
66
|
+
await generateSdk(openApiSpec);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
console.error("Error generating SDK:", error);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
default:
|
|
75
|
+
console.error("Option must be provided: generate");
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
run();
|
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,MAAO,MAAM,SAavC,CAAC"}
|
package/dist/error.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleApiError = void 0;
|
|
4
|
+
const handleApiError = (e) => {
|
|
5
|
+
if ("cause" in e &&
|
|
6
|
+
e.cause &&
|
|
7
|
+
typeof e.cause === "object" &&
|
|
8
|
+
"name" in e.cause &&
|
|
9
|
+
e.cause.name === "ZodError") {
|
|
10
|
+
console.error("Response Validation Error: Response schema different from response data");
|
|
11
|
+
console.info(JSON.stringify(e.cause, null, 2));
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
exports.handleApiError = handleApiError;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./sdk/xube-sdk"), exports);
|