@omnixdp/typegen 0.1.0 → 0.2.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/README.md +13 -7
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +50 -8
- package/dist/fetch-schema.js +48 -6
- package/dist/schema.d.ts +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,16 +13,19 @@ npm install -D @omnixdp/typegen
|
|
|
13
13
|
```bash
|
|
14
14
|
npx omnixdp-typegen \
|
|
15
15
|
--api-url https://api.example.com \
|
|
16
|
-
--management-
|
|
17
|
-
--
|
|
18
|
-
--
|
|
16
|
+
--management-client-id "$OMNIXDP_MANAGEMENT_CLIENT_ID" \
|
|
17
|
+
--management-client-secret "$OMNIXDP_MANAGEMENT_CLIENT_SECRET" \
|
|
18
|
+
--business-objects-client-id "$OMNIXDP_BO_CLIENT_ID" \
|
|
19
|
+
--business-objects-client-secret "$OMNIXDP_BO_CLIENT_SECRET" \
|
|
20
|
+
--ratings-and-reviews-client-id "$OMNIXDP_RR_CLIENT_ID" \
|
|
21
|
+
--ratings-and-reviews-client-secret "$OMNIXDP_RR_CLIENT_SECRET" \
|
|
19
22
|
--cms-space marketing \
|
|
20
23
|
--bo-space products \
|
|
21
24
|
--rr-space storefront-reviews \
|
|
22
25
|
--out src/omnixdp.generated.ts
|
|
23
26
|
```
|
|
24
27
|
|
|
25
|
-
Space arguments can be a space id, slug, or exact name. Regenerate the output after changing content types, taxonomy types, data types, or global fields in the admin.
|
|
28
|
+
Space arguments can be a space id, slug, or exact name. Typegen exchanges client credentials for short-lived access tokens. Existing `--management-token`, `--business-objects-token`, and `--ratings-and-reviews-token` flags remain supported when you already have bearer tokens. Regenerate the output after changing content types, taxonomy types, data types, or global fields in the admin.
|
|
26
29
|
|
|
27
30
|
## Check in CI
|
|
28
31
|
|
|
@@ -37,9 +40,12 @@ npx omnixdp-typegen --config omnixdp.typegen.config.js --check
|
|
|
37
40
|
```js
|
|
38
41
|
module.exports = {
|
|
39
42
|
apiUrl: process.env.OMNIXDP_API_URL,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
managementClientId: process.env.OMNIXDP_MANAGEMENT_CLIENT_ID,
|
|
44
|
+
managementClientSecret: process.env.OMNIXDP_MANAGEMENT_CLIENT_SECRET,
|
|
45
|
+
businessObjectsClientId: process.env.OMNIXDP_BO_CLIENT_ID,
|
|
46
|
+
businessObjectsClientSecret: process.env.OMNIXDP_BO_CLIENT_SECRET,
|
|
47
|
+
ratingsAndReviewsClientId: process.env.OMNIXDP_RR_CLIENT_ID,
|
|
48
|
+
ratingsAndReviewsClientSecret: process.env.OMNIXDP_RR_CLIENT_SECRET,
|
|
43
49
|
cmsSpace: "marketing",
|
|
44
50
|
boSpace: "products",
|
|
45
51
|
rrSpace: "storefront-reviews",
|
package/dist/cli.d.ts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -24,11 +24,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
return result;
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.loadConfig = loadConfig;
|
|
27
28
|
const promises_1 = require("node:fs/promises");
|
|
29
|
+
const node_module_1 = require("node:module");
|
|
28
30
|
const node_path_1 = require("node:path");
|
|
29
31
|
const node_url_1 = require("node:url");
|
|
30
32
|
const fetch_schema_1 = require("./fetch-schema");
|
|
31
33
|
const generate_1 = require("./generate");
|
|
34
|
+
const requireConfig = (0, node_module_1.createRequire)(__filename);
|
|
32
35
|
async function main() {
|
|
33
36
|
const args = parseArgs(process.argv.slice(2));
|
|
34
37
|
if (args.help) {
|
|
@@ -89,12 +92,30 @@ function assignArg(out, key, value) {
|
|
|
89
92
|
case "management-token":
|
|
90
93
|
out.managementToken = value;
|
|
91
94
|
break;
|
|
95
|
+
case "management-client-id":
|
|
96
|
+
out.managementClientId = value;
|
|
97
|
+
break;
|
|
98
|
+
case "management-client-secret":
|
|
99
|
+
out.managementClientSecret = value;
|
|
100
|
+
break;
|
|
92
101
|
case "business-objects-token":
|
|
93
102
|
out.businessObjectsToken = value;
|
|
94
103
|
break;
|
|
104
|
+
case "business-objects-client-id":
|
|
105
|
+
out.businessObjectsClientId = value;
|
|
106
|
+
break;
|
|
107
|
+
case "business-objects-client-secret":
|
|
108
|
+
out.businessObjectsClientSecret = value;
|
|
109
|
+
break;
|
|
95
110
|
case "ratings-and-reviews-token":
|
|
96
111
|
out.ratingsAndReviewsToken = value;
|
|
97
112
|
break;
|
|
113
|
+
case "ratings-and-reviews-client-id":
|
|
114
|
+
out.ratingsAndReviewsClientId = value;
|
|
115
|
+
break;
|
|
116
|
+
case "ratings-and-reviews-client-secret":
|
|
117
|
+
out.ratingsAndReviewsClientSecret = value;
|
|
118
|
+
break;
|
|
98
119
|
case "cms-space":
|
|
99
120
|
out.cmsSpace = value;
|
|
100
121
|
break;
|
|
@@ -131,8 +152,18 @@ async function loadConfig(file) {
|
|
|
131
152
|
if (path.endsWith(".json")) {
|
|
132
153
|
return JSON.parse(await (0, promises_1.readFile)(path, "utf8"));
|
|
133
154
|
}
|
|
155
|
+
if (path.endsWith(".cjs") || path.endsWith(".js")) {
|
|
156
|
+
return normalizeLoadedConfig(requireConfig(path));
|
|
157
|
+
}
|
|
134
158
|
const imported = await Promise.resolve(`${(0, node_url_1.pathToFileURL)(path).href}`).then(s => __importStar(require(s)));
|
|
135
|
-
return (imported
|
|
159
|
+
return normalizeLoadedConfig(imported);
|
|
160
|
+
}
|
|
161
|
+
function normalizeLoadedConfig(imported) {
|
|
162
|
+
if (imported && typeof imported === "object") {
|
|
163
|
+
const record = imported;
|
|
164
|
+
return (record.default ?? record.config ?? imported);
|
|
165
|
+
}
|
|
166
|
+
return {};
|
|
136
167
|
}
|
|
137
168
|
function compactConfig(config) {
|
|
138
169
|
return Object.fromEntries(Object.entries(config).filter(([, value]) => value !== undefined && value !== ""));
|
|
@@ -142,9 +173,18 @@ function printHelp() {
|
|
|
142
173
|
|
|
143
174
|
Options:
|
|
144
175
|
--config <path> Load omnixdp typegen config
|
|
145
|
-
--management-token <token> CMS Management API bearer token
|
|
146
|
-
--
|
|
147
|
-
--
|
|
176
|
+
--management-token <token> CMS Management API bearer token, or use client credentials below
|
|
177
|
+
--management-client-id <id> CMS Management API OAuth client id
|
|
178
|
+
--management-client-secret <secret> CMS Management API OAuth client secret
|
|
179
|
+
--business-objects-token <token> Business Objects API bearer token, or use client credentials below
|
|
180
|
+
--business-objects-client-id <id> Business Objects API OAuth client id
|
|
181
|
+
--business-objects-client-secret <secret>
|
|
182
|
+
Business Objects API OAuth client secret
|
|
183
|
+
--ratings-and-reviews-token <token> Ratings and Reviews API bearer token, or use client credentials below
|
|
184
|
+
--ratings-and-reviews-client-id <id>
|
|
185
|
+
Ratings and Reviews API OAuth client id
|
|
186
|
+
--ratings-and-reviews-client-secret <secret>
|
|
187
|
+
Ratings and Reviews API OAuth client secret
|
|
148
188
|
--cms-space <id|slug|name> CMS space to generate
|
|
149
189
|
--bo-space <id|slug|name> Business Objects space to generate
|
|
150
190
|
--rr-space <id|slug|name> Ratings and Reviews space to generate
|
|
@@ -152,7 +192,9 @@ Options:
|
|
|
152
192
|
--check Fail if the output file is stale
|
|
153
193
|
`);
|
|
154
194
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
195
|
+
if (require.main === module) {
|
|
196
|
+
main().catch((error) => {
|
|
197
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
198
|
+
process.exitCode = 1;
|
|
199
|
+
});
|
|
200
|
+
}
|
package/dist/fetch-schema.js
CHANGED
|
@@ -11,14 +11,26 @@ function normalizeApiUrl(apiUrl) {
|
|
|
11
11
|
async function fetchTypegenSchema(config) {
|
|
12
12
|
const apiBase = normalizeApiUrl(config.apiUrl);
|
|
13
13
|
const [cms, businessObjects, ratingsAndReviews] = await Promise.all([
|
|
14
|
-
config.
|
|
15
|
-
? fetchCmsSchema(apiBase,
|
|
14
|
+
config.cmsSpace
|
|
15
|
+
? fetchCmsSchema(apiBase, await resolveAccessToken(apiBase, "management", {
|
|
16
|
+
token: config.managementToken,
|
|
17
|
+
clientId: config.managementClientId,
|
|
18
|
+
clientSecret: config.managementClientSecret
|
|
19
|
+
}), config.cmsSpace)
|
|
16
20
|
: Promise.resolve({ contentTypes: [], taxonomyTypes: [] }),
|
|
17
|
-
config.
|
|
18
|
-
? fetchBoSchema(apiBase, "business-objects",
|
|
21
|
+
config.boSpace
|
|
22
|
+
? fetchBoSchema(apiBase, "business-objects", await resolveAccessToken(apiBase, "business-objects", {
|
|
23
|
+
token: config.businessObjectsToken,
|
|
24
|
+
clientId: config.businessObjectsClientId,
|
|
25
|
+
clientSecret: config.businessObjectsClientSecret
|
|
26
|
+
}), config.boSpace)
|
|
19
27
|
: Promise.resolve({ dataTypes: [] }),
|
|
20
|
-
config.
|
|
21
|
-
? fetchBoSchema(apiBase, "ratings-and-reviews",
|
|
28
|
+
config.rrSpace
|
|
29
|
+
? fetchBoSchema(apiBase, "ratings-and-reviews", await resolveAccessToken(apiBase, "ratings-and-reviews", {
|
|
30
|
+
token: config.ratingsAndReviewsToken,
|
|
31
|
+
clientId: config.ratingsAndReviewsClientId,
|
|
32
|
+
clientSecret: config.ratingsAndReviewsClientSecret
|
|
33
|
+
}), config.rrSpace)
|
|
22
34
|
: Promise.resolve({ dataTypes: [] })
|
|
23
35
|
]);
|
|
24
36
|
const canonical = JSON.stringify({ cms, businessObjects, ratingsAndReviews });
|
|
@@ -30,6 +42,36 @@ async function fetchTypegenSchema(config) {
|
|
|
30
42
|
ratingsAndReviews
|
|
31
43
|
};
|
|
32
44
|
}
|
|
45
|
+
async function resolveAccessToken(apiBase, app, auth) {
|
|
46
|
+
const token = auth.token?.trim();
|
|
47
|
+
if (token)
|
|
48
|
+
return token;
|
|
49
|
+
const clientId = auth.clientId?.trim();
|
|
50
|
+
const clientSecret = auth.clientSecret?.trim();
|
|
51
|
+
if (!clientId && !clientSecret) {
|
|
52
|
+
throw new Error(`Either a bearer token or client credentials are required for ${app} type generation.`);
|
|
53
|
+
}
|
|
54
|
+
if (!clientId || !clientSecret) {
|
|
55
|
+
throw new Error(`Both client id and client secret are required for ${app} type generation.`);
|
|
56
|
+
}
|
|
57
|
+
const response = await fetch(`${apiBase}/${app}/oauth/token`, {
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers: {
|
|
60
|
+
accept: "application/json",
|
|
61
|
+
"content-type": "application/x-www-form-urlencoded"
|
|
62
|
+
},
|
|
63
|
+
body: new URLSearchParams({
|
|
64
|
+
grant_type: "client_credentials",
|
|
65
|
+
client_id: clientId,
|
|
66
|
+
client_secret: clientSecret
|
|
67
|
+
})
|
|
68
|
+
});
|
|
69
|
+
const body = (await response.json().catch(() => null));
|
|
70
|
+
if (!response.ok || typeof body?.access_token !== "string" || !body.access_token.trim()) {
|
|
71
|
+
throw new Error(`Failed to request ${app} access token: ${response.statusText}`);
|
|
72
|
+
}
|
|
73
|
+
return body.access_token;
|
|
74
|
+
}
|
|
33
75
|
async function fetchCmsSchema(apiBase, token, spaceRef) {
|
|
34
76
|
const space = await resolveSpace(apiBase, "management", token, spaceRef);
|
|
35
77
|
const [contentTypes, taxonomyTypes] = await Promise.all([
|
package/dist/schema.d.ts
CHANGED
|
@@ -49,8 +49,14 @@ export type TypegenSchema = {
|
|
|
49
49
|
export type TypegenConfig = {
|
|
50
50
|
apiUrl: string;
|
|
51
51
|
managementToken?: string;
|
|
52
|
+
managementClientId?: string;
|
|
53
|
+
managementClientSecret?: string;
|
|
52
54
|
businessObjectsToken?: string;
|
|
55
|
+
businessObjectsClientId?: string;
|
|
56
|
+
businessObjectsClientSecret?: string;
|
|
53
57
|
ratingsAndReviewsToken?: string;
|
|
58
|
+
ratingsAndReviewsClientId?: string;
|
|
59
|
+
ratingsAndReviewsClientSecret?: string;
|
|
54
60
|
cmsSpace?: string;
|
|
55
61
|
boSpace?: string;
|
|
56
62
|
rrSpace?: string;
|