@omnixdp/typegen 0.1.0 → 0.2.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/README.md +13 -7
- package/dist/cli.js +30 -3
- 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.js
CHANGED
|
@@ -89,12 +89,30 @@ function assignArg(out, key, value) {
|
|
|
89
89
|
case "management-token":
|
|
90
90
|
out.managementToken = value;
|
|
91
91
|
break;
|
|
92
|
+
case "management-client-id":
|
|
93
|
+
out.managementClientId = value;
|
|
94
|
+
break;
|
|
95
|
+
case "management-client-secret":
|
|
96
|
+
out.managementClientSecret = value;
|
|
97
|
+
break;
|
|
92
98
|
case "business-objects-token":
|
|
93
99
|
out.businessObjectsToken = value;
|
|
94
100
|
break;
|
|
101
|
+
case "business-objects-client-id":
|
|
102
|
+
out.businessObjectsClientId = value;
|
|
103
|
+
break;
|
|
104
|
+
case "business-objects-client-secret":
|
|
105
|
+
out.businessObjectsClientSecret = value;
|
|
106
|
+
break;
|
|
95
107
|
case "ratings-and-reviews-token":
|
|
96
108
|
out.ratingsAndReviewsToken = value;
|
|
97
109
|
break;
|
|
110
|
+
case "ratings-and-reviews-client-id":
|
|
111
|
+
out.ratingsAndReviewsClientId = value;
|
|
112
|
+
break;
|
|
113
|
+
case "ratings-and-reviews-client-secret":
|
|
114
|
+
out.ratingsAndReviewsClientSecret = value;
|
|
115
|
+
break;
|
|
98
116
|
case "cms-space":
|
|
99
117
|
out.cmsSpace = value;
|
|
100
118
|
break;
|
|
@@ -142,9 +160,18 @@ function printHelp() {
|
|
|
142
160
|
|
|
143
161
|
Options:
|
|
144
162
|
--config <path> Load omnixdp typegen config
|
|
145
|
-
--management-token <token> CMS Management API bearer token
|
|
146
|
-
--
|
|
147
|
-
--
|
|
163
|
+
--management-token <token> CMS Management API bearer token, or use client credentials below
|
|
164
|
+
--management-client-id <id> CMS Management API OAuth client id
|
|
165
|
+
--management-client-secret <secret> CMS Management API OAuth client secret
|
|
166
|
+
--business-objects-token <token> Business Objects API bearer token, or use client credentials below
|
|
167
|
+
--business-objects-client-id <id> Business Objects API OAuth client id
|
|
168
|
+
--business-objects-client-secret <secret>
|
|
169
|
+
Business Objects API OAuth client secret
|
|
170
|
+
--ratings-and-reviews-token <token> Ratings and Reviews API bearer token, or use client credentials below
|
|
171
|
+
--ratings-and-reviews-client-id <id>
|
|
172
|
+
Ratings and Reviews API OAuth client id
|
|
173
|
+
--ratings-and-reviews-client-secret <secret>
|
|
174
|
+
Ratings and Reviews API OAuth client secret
|
|
148
175
|
--cms-space <id|slug|name> CMS space to generate
|
|
149
176
|
--bo-space <id|slug|name> Business Objects space to generate
|
|
150
177
|
--rr-space <id|slug|name> Ratings and Reviews space to generate
|
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;
|