@timbenniks/contentstack-platform-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/auth/index.cjs +607 -0
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.cts +108 -0
- package/dist/auth/index.d.ts +108 -0
- package/dist/auth/index.mjs +25 -0
- package/dist/auth/index.mjs.map +1 -0
- package/dist/brandkit/index.cjs +525 -0
- package/dist/brandkit/index.cjs.map +1 -0
- package/dist/brandkit/index.d.cts +95 -0
- package/dist/brandkit/index.d.ts +95 -0
- package/dist/brandkit/index.mjs +11 -0
- package/dist/brandkit/index.mjs.map +1 -0
- package/dist/chunk-3C6J2BDB.mjs +84 -0
- package/dist/chunk-3C6J2BDB.mjs.map +1 -0
- package/dist/chunk-3KE63N3I.mjs +64 -0
- package/dist/chunk-3KE63N3I.mjs.map +1 -0
- package/dist/chunk-4CJ4IVPJ.mjs +212 -0
- package/dist/chunk-4CJ4IVPJ.mjs.map +1 -0
- package/dist/chunk-4JFUI7MJ.mjs +368 -0
- package/dist/chunk-4JFUI7MJ.mjs.map +1 -0
- package/dist/chunk-7VFGD32I.mjs +26 -0
- package/dist/chunk-7VFGD32I.mjs.map +1 -0
- package/dist/chunk-ARPJDW3A.mjs +44 -0
- package/dist/chunk-ARPJDW3A.mjs.map +1 -0
- package/dist/chunk-AVJHCFRK.mjs +52 -0
- package/dist/chunk-AVJHCFRK.mjs.map +1 -0
- package/dist/chunk-BK2IBTQS.mjs +131 -0
- package/dist/chunk-BK2IBTQS.mjs.map +1 -0
- package/dist/chunk-BUZ6CQHE.mjs +75 -0
- package/dist/chunk-BUZ6CQHE.mjs.map +1 -0
- package/dist/chunk-CKMAOWBQ.mjs +379 -0
- package/dist/chunk-CKMAOWBQ.mjs.map +1 -0
- package/dist/chunk-DJQLN4TR.mjs +1 -0
- package/dist/chunk-DJQLN4TR.mjs.map +1 -0
- package/dist/chunk-DMERADWM.mjs +67 -0
- package/dist/chunk-DMERADWM.mjs.map +1 -0
- package/dist/chunk-EREPKWTW.mjs +926 -0
- package/dist/chunk-EREPKWTW.mjs.map +1 -0
- package/dist/chunk-FQP4PB5X.mjs +88 -0
- package/dist/chunk-FQP4PB5X.mjs.map +1 -0
- package/dist/chunk-GNPQJBFX.mjs +144 -0
- package/dist/chunk-GNPQJBFX.mjs.map +1 -0
- package/dist/chunk-GOSB24M6.mjs +87 -0
- package/dist/chunk-GOSB24M6.mjs.map +1 -0
- package/dist/chunk-JL2E3EOT.mjs +255 -0
- package/dist/chunk-JL2E3EOT.mjs.map +1 -0
- package/dist/chunk-JYGZBKTH.mjs +222 -0
- package/dist/chunk-JYGZBKTH.mjs.map +1 -0
- package/dist/chunk-JZE2W7VW.mjs +52 -0
- package/dist/chunk-JZE2W7VW.mjs.map +1 -0
- package/dist/chunk-K76DKSHJ.mjs +18 -0
- package/dist/chunk-K76DKSHJ.mjs.map +1 -0
- package/dist/chunk-KLVIROVU.mjs +232 -0
- package/dist/chunk-KLVIROVU.mjs.map +1 -0
- package/dist/chunk-LPVVA5J3.mjs +18 -0
- package/dist/chunk-LPVVA5J3.mjs.map +1 -0
- package/dist/chunk-NKLOZ5VI.mjs +112 -0
- package/dist/chunk-NKLOZ5VI.mjs.map +1 -0
- package/dist/chunk-QGA4WBDC.mjs +7 -0
- package/dist/chunk-QGA4WBDC.mjs.map +1 -0
- package/dist/chunk-QW7TVYOA.mjs +56 -0
- package/dist/chunk-QW7TVYOA.mjs.map +1 -0
- package/dist/chunk-SU5QEKYW.mjs +83 -0
- package/dist/chunk-SU5QEKYW.mjs.map +1 -0
- package/dist/chunk-T5A2E2RI.mjs +654 -0
- package/dist/chunk-T5A2E2RI.mjs.map +1 -0
- package/dist/chunk-T5OIJQK7.mjs +116 -0
- package/dist/chunk-T5OIJQK7.mjs.map +1 -0
- package/dist/chunk-VW7DD6HV.mjs +253 -0
- package/dist/chunk-VW7DD6HV.mjs.map +1 -0
- package/dist/chunk-XH7NLHGW.mjs +133 -0
- package/dist/chunk-XH7NLHGW.mjs.map +1 -0
- package/dist/client-DJ5haQGd.d.cts +22 -0
- package/dist/client-DwVGVSQz.d.ts +22 -0
- package/dist/cma/index.cjs +1349 -0
- package/dist/cma/index.cjs.map +1 -0
- package/dist/cma/index.d.cts +22 -0
- package/dist/cma/index.d.ts +22 -0
- package/dist/cma/index.mjs +70 -0
- package/dist/cma/index.mjs.map +1 -0
- package/dist/errors-CAw-IRCP.d.cts +65 -0
- package/dist/errors-CAw-IRCP.d.ts +65 -0
- package/dist/generative-ai/index.cjs +401 -0
- package/dist/generative-ai/index.cjs.map +1 -0
- package/dist/generative-ai/index.d.cts +31 -0
- package/dist/generative-ai/index.d.ts +31 -0
- package/dist/generative-ai/index.mjs +10 -0
- package/dist/generative-ai/index.mjs.map +1 -0
- package/dist/images/index.cjs +185 -0
- package/dist/images/index.cjs.map +1 -0
- package/dist/images/index.d.cts +27 -0
- package/dist/images/index.d.ts +27 -0
- package/dist/images/index.mjs +8 -0
- package/dist/images/index.mjs.map +1 -0
- package/dist/index.cjs +2909 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +30 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.mjs +153 -0
- package/dist/index.mjs.map +1 -0
- package/dist/knowledge-vault/index.cjs +413 -0
- package/dist/knowledge-vault/index.cjs.map +1 -0
- package/dist/knowledge-vault/index.d.cts +49 -0
- package/dist/knowledge-vault/index.d.ts +49 -0
- package/dist/knowledge-vault/index.mjs +10 -0
- package/dist/knowledge-vault/index.mjs.map +1 -0
- package/dist/launch/index.cjs +624 -0
- package/dist/launch/index.cjs.map +1 -0
- package/dist/launch/index.d.cts +169 -0
- package/dist/launch/index.d.ts +169 -0
- package/dist/launch/index.mjs +11 -0
- package/dist/launch/index.mjs.map +1 -0
- package/dist/react/auth/index.cjs +113 -0
- package/dist/react/auth/index.cjs.map +1 -0
- package/dist/react/auth/index.d.cts +33 -0
- package/dist/react/auth/index.d.ts +33 -0
- package/dist/react/auth/index.mjs +13 -0
- package/dist/react/auth/index.mjs.map +1 -0
- package/dist/react/content/index.cjs +113 -0
- package/dist/react/content/index.cjs.map +1 -0
- package/dist/react/content/index.d.cts +25 -0
- package/dist/react/content/index.d.ts +25 -0
- package/dist/react/content/index.mjs +7 -0
- package/dist/react/content/index.mjs.map +1 -0
- package/dist/react/hooks/index.cjs +2097 -0
- package/dist/react/hooks/index.cjs.map +1 -0
- package/dist/react/hooks/index.d.cts +77 -0
- package/dist/react/hooks/index.d.ts +77 -0
- package/dist/react/hooks/index.mjs +46 -0
- package/dist/react/hooks/index.mjs.map +1 -0
- package/dist/react/index.cjs +2307 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +16 -0
- package/dist/react/index.d.ts +16 -0
- package/dist/react/index.mjs +67 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/react/provider/index.cjs +83 -0
- package/dist/react/provider/index.cjs.map +1 -0
- package/dist/react/provider/index.d.cts +30 -0
- package/dist/react/provider/index.d.ts +30 -0
- package/dist/react/provider/index.mjs +11 -0
- package/dist/react/provider/index.mjs.map +1 -0
- package/dist/regions/index.cjs +171 -0
- package/dist/regions/index.cjs.map +1 -0
- package/dist/regions/index.d.cts +55 -0
- package/dist/regions/index.d.ts +55 -0
- package/dist/regions/index.mjs +13 -0
- package/dist/regions/index.mjs.map +1 -0
- package/dist/request-builders-BxeolQIw.d.ts +735 -0
- package/dist/request-builders-C2IG1LUo.d.cts +735 -0
- package/dist/rte/index.cjs +683 -0
- package/dist/rte/index.cjs.map +1 -0
- package/dist/rte/index.d.cts +33 -0
- package/dist/rte/index.d.ts +33 -0
- package/dist/rte/index.mjs +17 -0
- package/dist/rte/index.mjs.map +1 -0
- package/dist/server/index.cjs +917 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +6 -0
- package/dist/server/index.d.ts +6 -0
- package/dist/server/index.mjs +45 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/server/middleware/index.cjs +614 -0
- package/dist/server/middleware/index.cjs.map +1 -0
- package/dist/server/middleware/index.d.cts +77 -0
- package/dist/server/middleware/index.d.ts +77 -0
- package/dist/server/middleware/index.mjs +27 -0
- package/dist/server/middleware/index.mjs.map +1 -0
- package/dist/server/proxy/index.cjs +329 -0
- package/dist/server/proxy/index.cjs.map +1 -0
- package/dist/server/proxy/index.d.cts +143 -0
- package/dist/server/proxy/index.d.ts +143 -0
- package/dist/server/proxy/index.mjs +29 -0
- package/dist/server/proxy/index.mjs.map +1 -0
- package/dist/server/webhooks/index.cjs +131 -0
- package/dist/server/webhooks/index.cjs.map +1 -0
- package/dist/server/webhooks/index.d.cts +230 -0
- package/dist/server/webhooks/index.d.ts +230 -0
- package/dist/server/webhooks/index.mjs +23 -0
- package/dist/server/webhooks/index.mjs.map +1 -0
- package/dist/types-6D9VR7pT.d.cts +26 -0
- package/dist/types-AelT0rFJ.d.cts +21 -0
- package/dist/types-AelT0rFJ.d.ts +21 -0
- package/dist/types-Bu5yCgmw.d.ts +26 -0
- package/dist/types-DgixK-ll.d.cts +23 -0
- package/dist/types-DgixK-ll.d.ts +23 -0
- package/dist/types-DrMwdlH9.d.cts +245 -0
- package/dist/types-DrMwdlH9.d.ts +245 -0
- package/dist/ui/css/index.cjs +31 -0
- package/dist/ui/css/index.cjs.map +1 -0
- package/dist/ui/css/index.d.cts +15 -0
- package/dist/ui/css/index.d.ts +15 -0
- package/dist/ui/css/index.mjs +7 -0
- package/dist/ui/css/index.mjs.map +1 -0
- package/dist/ui/index.cjs +368 -0
- package/dist/ui/index.cjs.map +1 -0
- package/dist/ui/index.d.cts +4 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.mjs +33 -0
- package/dist/ui/index.mjs.map +1 -0
- package/dist/ui/theme/index.cjs +105 -0
- package/dist/ui/theme/index.cjs.map +1 -0
- package/dist/ui/theme/index.d.cts +33 -0
- package/dist/ui/theme/index.d.ts +33 -0
- package/dist/ui/theme/index.mjs +15 -0
- package/dist/ui/theme/index.mjs.map +1 -0
- package/dist/ui/tokens/index.cjs +286 -0
- package/dist/ui/tokens/index.cjs.map +1 -0
- package/dist/ui/tokens/index.d.cts +54 -0
- package/dist/ui/tokens/index.d.ts +54 -0
- package/dist/ui/tokens/index.mjs +17 -0
- package/dist/ui/tokens/index.mjs.map +1 -0
- package/dist/ui/tokens.css +408 -0
- package/dist/vue/auth/index.cjs +141 -0
- package/dist/vue/auth/index.cjs.map +1 -0
- package/dist/vue/auth/index.d.cts +78 -0
- package/dist/vue/auth/index.d.ts +78 -0
- package/dist/vue/auth/index.mjs +13 -0
- package/dist/vue/auth/index.mjs.map +1 -0
- package/dist/vue/composables/index.cjs +2108 -0
- package/dist/vue/composables/index.cjs.map +1 -0
- package/dist/vue/composables/index.d.cts +78 -0
- package/dist/vue/composables/index.d.ts +78 -0
- package/dist/vue/composables/index.mjs +46 -0
- package/dist/vue/composables/index.mjs.map +1 -0
- package/dist/vue/content/index.cjs +142 -0
- package/dist/vue/content/index.cjs.map +1 -0
- package/dist/vue/content/index.d.cts +47 -0
- package/dist/vue/content/index.d.ts +47 -0
- package/dist/vue/content/index.mjs +7 -0
- package/dist/vue/content/index.mjs.map +1 -0
- package/dist/vue/index.cjs +2389 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.cts +16 -0
- package/dist/vue/index.d.ts +16 -0
- package/dist/vue/index.mjs +69 -0
- package/dist/vue/index.mjs.map +1 -0
- package/dist/vue/provider/index.cjs +97 -0
- package/dist/vue/provider/index.cjs.map +1 -0
- package/dist/vue/provider/index.d.cts +90 -0
- package/dist/vue/provider/index.d.ts +90 -0
- package/dist/vue/provider/index.mjs +13 -0
- package/dist/vue/provider/index.mjs.map +1 -0
- package/package.json +195 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2909 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AssetsClient: () => AssetsClient,
|
|
24
|
+
AuditLogClient: () => AuditLogClient,
|
|
25
|
+
BranchAliasesClient: () => BranchAliasesClient,
|
|
26
|
+
BranchesClient: () => BranchesClient,
|
|
27
|
+
BulkOperationsClient: () => BulkOperationsClient,
|
|
28
|
+
ContentTypesClient: () => ContentTypesClient,
|
|
29
|
+
ContentstackAuthError: () => ContentstackAuthError,
|
|
30
|
+
ContentstackConfigError: () => ContentstackConfigError,
|
|
31
|
+
ContentstackError: () => ContentstackError,
|
|
32
|
+
ContentstackForbiddenError: () => ContentstackForbiddenError,
|
|
33
|
+
ContentstackInvalidApiKeyError: () => ContentstackInvalidApiKeyError,
|
|
34
|
+
ContentstackNotFoundError: () => ContentstackNotFoundError,
|
|
35
|
+
ContentstackRateLimitError: () => ContentstackRateLimitError,
|
|
36
|
+
ContentstackServerError: () => ContentstackServerError,
|
|
37
|
+
ContentstackValidationError: () => ContentstackValidationError,
|
|
38
|
+
CrudClient: () => CrudClient,
|
|
39
|
+
EntriesClient: () => EntriesClient,
|
|
40
|
+
EnvironmentsClient: () => EnvironmentsClient,
|
|
41
|
+
ExtensionsClient: () => ExtensionsClient,
|
|
42
|
+
GlobalFieldsClient: () => GlobalFieldsClient,
|
|
43
|
+
LabelsClient: () => LabelsClient,
|
|
44
|
+
LocalesClient: () => LocalesClient,
|
|
45
|
+
PublishRulesClient: () => PublishRulesClient,
|
|
46
|
+
ReleasesClient: () => ReleasesClient,
|
|
47
|
+
RolesClient: () => RolesClient,
|
|
48
|
+
TaxonomiesClient: () => TaxonomiesClient,
|
|
49
|
+
TokensClient: () => TokensClient,
|
|
50
|
+
WebhooksClient: () => WebhooksClient,
|
|
51
|
+
WorkflowsClient: () => WorkflowsClient,
|
|
52
|
+
buildAssetsParams: () => buildAssetsParams,
|
|
53
|
+
buildAuthorizationUrl: () => buildAuthorizationUrl,
|
|
54
|
+
buildCreateEntryRequest: () => buildCreateEntryRequest,
|
|
55
|
+
buildDeleteEntryRequest: () => buildDeleteEntryRequest,
|
|
56
|
+
buildEntriesParams: () => buildEntriesParams,
|
|
57
|
+
buildEntryParams: () => buildEntryParams,
|
|
58
|
+
buildPublishEntryRequest: () => buildPublishEntryRequest,
|
|
59
|
+
buildUpdateEntryRequest: () => buildUpdateEntryRequest,
|
|
60
|
+
collectAll: () => collectAll,
|
|
61
|
+
contentstackAuthCallbacks: () => contentstackAuthCallbacks,
|
|
62
|
+
createAuthProvider: () => createAuthProvider,
|
|
63
|
+
createBrandKitClient: () => createBrandKitClient,
|
|
64
|
+
createCMAClient: () => createCMAClient,
|
|
65
|
+
createGenerativeAIClient: () => createGenerativeAIClient,
|
|
66
|
+
createKnowledgeVaultClient: () => createKnowledgeVaultClient,
|
|
67
|
+
createLaunchClient: () => createLaunchClient,
|
|
68
|
+
exchangeCode: () => exchangeCode,
|
|
69
|
+
fromHTML: () => fromHTML,
|
|
70
|
+
generateCodeChallenge: () => generateCodeChallenge,
|
|
71
|
+
generateCodeVerifier: () => generateCodeVerifier,
|
|
72
|
+
getUser: () => getUser,
|
|
73
|
+
imageTransform: () => imageTransform,
|
|
74
|
+
normalizeRegion: () => normalizeRegion,
|
|
75
|
+
paginate: () => paginate,
|
|
76
|
+
parseErrorResponse: () => parseErrorResponse,
|
|
77
|
+
refreshToken: () => refreshToken,
|
|
78
|
+
resolveEndpoints: () => resolveEndpoints,
|
|
79
|
+
resolveHosts: () => resolveHosts,
|
|
80
|
+
toHTML: () => toHTML,
|
|
81
|
+
toMarkdown: () => toMarkdown,
|
|
82
|
+
toPlainText: () => toPlainText,
|
|
83
|
+
transform: () => transform,
|
|
84
|
+
validate: () => validate
|
|
85
|
+
});
|
|
86
|
+
module.exports = __toCommonJS(index_exports);
|
|
87
|
+
|
|
88
|
+
// src/http/errors.ts
|
|
89
|
+
var ContentstackError = class extends Error {
|
|
90
|
+
name = "ContentstackError";
|
|
91
|
+
status;
|
|
92
|
+
errorCode;
|
|
93
|
+
errors;
|
|
94
|
+
requestPath;
|
|
95
|
+
constructor(message, options) {
|
|
96
|
+
super(message, options?.cause ? { cause: options.cause } : void 0);
|
|
97
|
+
this.status = options?.status;
|
|
98
|
+
this.errorCode = options?.errorCode;
|
|
99
|
+
this.errors = options?.errors;
|
|
100
|
+
this.requestPath = options?.requestPath;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var ContentstackAuthError = class extends ContentstackError {
|
|
104
|
+
name = "ContentstackAuthError";
|
|
105
|
+
status = 401;
|
|
106
|
+
};
|
|
107
|
+
var ContentstackForbiddenError = class extends ContentstackError {
|
|
108
|
+
name = "ContentstackForbiddenError";
|
|
109
|
+
status = 403;
|
|
110
|
+
};
|
|
111
|
+
var ContentstackNotFoundError = class extends ContentstackError {
|
|
112
|
+
name = "ContentstackNotFoundError";
|
|
113
|
+
status = 404;
|
|
114
|
+
};
|
|
115
|
+
var ContentstackValidationError = class extends ContentstackError {
|
|
116
|
+
name = "ContentstackValidationError";
|
|
117
|
+
status;
|
|
118
|
+
constructor(message, options) {
|
|
119
|
+
super(message, options);
|
|
120
|
+
this.status = options?.status ?? 400;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
var ContentstackInvalidApiKeyError = class extends ContentstackError {
|
|
124
|
+
name = "ContentstackInvalidApiKeyError";
|
|
125
|
+
status = 412;
|
|
126
|
+
};
|
|
127
|
+
var ContentstackRateLimitError = class extends ContentstackError {
|
|
128
|
+
name = "ContentstackRateLimitError";
|
|
129
|
+
status = 429;
|
|
130
|
+
retryAfter;
|
|
131
|
+
constructor(message, options) {
|
|
132
|
+
super(message, { ...options, status: 429 });
|
|
133
|
+
this.retryAfter = options?.retryAfter;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
var ContentstackServerError = class extends ContentstackError {
|
|
137
|
+
name = "ContentstackServerError";
|
|
138
|
+
};
|
|
139
|
+
var ContentstackConfigError = class extends ContentstackError {
|
|
140
|
+
name = "ContentstackConfigError";
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// src/regions/endpoints.ts
|
|
144
|
+
var import_contentstack_endpoints = require("@timbenniks/contentstack-endpoints");
|
|
145
|
+
var BRAND_KIT_URLS = {
|
|
146
|
+
us: {
|
|
147
|
+
brandKit: "https://brand-kits-api.contentstack.com",
|
|
148
|
+
brandKitAI: "https://ai.contentstack.com/brand-kits"
|
|
149
|
+
},
|
|
150
|
+
eu: {
|
|
151
|
+
brandKit: "https://eu-brand-kits-api.contentstack.com",
|
|
152
|
+
brandKitAI: "https://eu-ai.contentstack.com/brand-kits"
|
|
153
|
+
},
|
|
154
|
+
au: {
|
|
155
|
+
brandKit: "https://au-brand-kits-api.contentstack.com",
|
|
156
|
+
brandKitAI: "https://au-ai.contentstack.com/brand-kits"
|
|
157
|
+
},
|
|
158
|
+
"azure-na": {
|
|
159
|
+
brandKit: "https://azure-na-brand-kits-api.contentstack.com",
|
|
160
|
+
brandKitAI: "https://azure-na-ai.contentstack.com/brand-kits"
|
|
161
|
+
},
|
|
162
|
+
"azure-eu": {
|
|
163
|
+
brandKit: "https://azure-eu-brand-kits-api.contentstack.com",
|
|
164
|
+
brandKitAI: "https://azure-eu-ai.contentstack.com/brand-kits"
|
|
165
|
+
},
|
|
166
|
+
"gcp-na": {
|
|
167
|
+
brandKit: "https://gcp-na-brand-kits-api.contentstack.com",
|
|
168
|
+
brandKitAI: "https://gcp-na-ai.contentstack.com/brand-kits"
|
|
169
|
+
},
|
|
170
|
+
"gcp-eu": {
|
|
171
|
+
brandKit: "https://gcp-eu-brand-kits-api.contentstack.com",
|
|
172
|
+
brandKitAI: "https://gcp-eu-ai.contentstack.com/brand-kits"
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
function mapEndpoints(upstream, region, hostsOnly) {
|
|
176
|
+
const bk = BRAND_KIT_URLS[region];
|
|
177
|
+
const stripProtocol = (url) => url.replace(/^https?:\/\//, "");
|
|
178
|
+
return Object.freeze({
|
|
179
|
+
cma: upstream.contentManagement ?? "",
|
|
180
|
+
cda: upstream.contentDelivery ?? "",
|
|
181
|
+
graphql: upstream.graphqlDelivery ?? "",
|
|
182
|
+
images: upstream.images ?? "",
|
|
183
|
+
app: upstream.application ?? "",
|
|
184
|
+
preview: upstream.preview ?? "",
|
|
185
|
+
graphqlPreview: upstream.graphqlPreview ?? "",
|
|
186
|
+
launch: upstream.launch ?? "",
|
|
187
|
+
personalizeEdge: upstream.personalizeEdge ?? "",
|
|
188
|
+
brandKit: hostsOnly ? stripProtocol(bk.brandKit) : bk.brandKit,
|
|
189
|
+
brandKitAI: hostsOnly ? stripProtocol(bk.brandKitAI) : bk.brandKitAI
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
var ALL_REGIONS = [
|
|
193
|
+
"us",
|
|
194
|
+
"eu",
|
|
195
|
+
"au",
|
|
196
|
+
"azure-na",
|
|
197
|
+
"azure-eu",
|
|
198
|
+
"gcp-na",
|
|
199
|
+
"gcp-eu"
|
|
200
|
+
];
|
|
201
|
+
function buildEndpointMap() {
|
|
202
|
+
const map = {};
|
|
203
|
+
for (const region of ALL_REGIONS) {
|
|
204
|
+
map[region] = mapEndpoints((0, import_contentstack_endpoints.getContentstackEndpoints)(region), region, false);
|
|
205
|
+
}
|
|
206
|
+
return Object.freeze(map);
|
|
207
|
+
}
|
|
208
|
+
function buildHostMap() {
|
|
209
|
+
const map = {};
|
|
210
|
+
for (const region of ALL_REGIONS) {
|
|
211
|
+
map[region] = mapEndpoints((0, import_contentstack_endpoints.getContentstackEndpoints)(region, true), region, true);
|
|
212
|
+
}
|
|
213
|
+
return Object.freeze(map);
|
|
214
|
+
}
|
|
215
|
+
var ENDPOINT_MAP = buildEndpointMap();
|
|
216
|
+
var HOST_MAP = buildHostMap();
|
|
217
|
+
function isValidRegion(input) {
|
|
218
|
+
return (0, import_contentstack_endpoints.getRegionForString)(input) !== void 0;
|
|
219
|
+
}
|
|
220
|
+
var EXTRA_ALIASES = {
|
|
221
|
+
"north-america": "us",
|
|
222
|
+
europe: "eu",
|
|
223
|
+
australia: "au"
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// src/regions/resolver.ts
|
|
227
|
+
var VALID_REGIONS = new Set(Object.keys(ENDPOINT_MAP));
|
|
228
|
+
function resolveEndpoints(region) {
|
|
229
|
+
return ENDPOINT_MAP[region];
|
|
230
|
+
}
|
|
231
|
+
function resolveHosts(region) {
|
|
232
|
+
return HOST_MAP[region];
|
|
233
|
+
}
|
|
234
|
+
function normalizeRegion(input) {
|
|
235
|
+
const lower = input.toLowerCase().trim();
|
|
236
|
+
if (VALID_REGIONS.has(lower)) {
|
|
237
|
+
return lower;
|
|
238
|
+
}
|
|
239
|
+
const extraAlias = EXTRA_ALIASES[lower];
|
|
240
|
+
if (extraAlias) {
|
|
241
|
+
return extraAlias;
|
|
242
|
+
}
|
|
243
|
+
if (isValidRegion(lower)) {
|
|
244
|
+
if (lower === "na" || lower === "aws-na" || lower === "aws_na") return "us";
|
|
245
|
+
if (lower === "aws-eu" || lower === "aws_eu") return "eu";
|
|
246
|
+
if (lower === "aws-au" || lower === "aws_au") return "au";
|
|
247
|
+
if (lower === "azure_na") return "azure-na";
|
|
248
|
+
if (lower === "azure_eu") return "azure-eu";
|
|
249
|
+
if (lower === "gcp_na") return "gcp-na";
|
|
250
|
+
if (lower === "gcp_eu") return "gcp-eu";
|
|
251
|
+
}
|
|
252
|
+
const validRegions = [...VALID_REGIONS].join(", ");
|
|
253
|
+
const validAliases = [...Object.keys(EXTRA_ALIASES), "na", "aws-na", "aws-eu", "aws-au"].join(
|
|
254
|
+
", "
|
|
255
|
+
);
|
|
256
|
+
throw new ContentstackConfigError(
|
|
257
|
+
`Unknown region "${input}". Valid regions: ${validRegions}. Aliases: ${validAliases}.`
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// src/http/parse-error.ts
|
|
262
|
+
async function parseErrorResponse(response, path) {
|
|
263
|
+
try {
|
|
264
|
+
const body = await response.json();
|
|
265
|
+
return new ContentstackError(body.error_message ?? body.message ?? response.statusText, {
|
|
266
|
+
status: response.status,
|
|
267
|
+
errorCode: body.error_code,
|
|
268
|
+
errors: body.errors,
|
|
269
|
+
requestPath: path
|
|
270
|
+
});
|
|
271
|
+
} catch {
|
|
272
|
+
return new ContentstackError(response.statusText, {
|
|
273
|
+
status: response.status,
|
|
274
|
+
requestPath: path
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// src/http/client.ts
|
|
280
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
281
|
+
var DEFAULT_RETRY_LIMIT = 5;
|
|
282
|
+
var DEFAULT_RETRY_DELAY = 300;
|
|
283
|
+
var MAX_JITTER = 100;
|
|
284
|
+
var ContentstackHttpClient = class _ContentstackHttpClient {
|
|
285
|
+
config;
|
|
286
|
+
constructor(config) {
|
|
287
|
+
this.config = {
|
|
288
|
+
baseUrl: config.baseUrl,
|
|
289
|
+
headers: config.headers ?? {},
|
|
290
|
+
timeout: config.timeout ?? DEFAULT_TIMEOUT,
|
|
291
|
+
retryOnError: config.retryOnError ?? true,
|
|
292
|
+
retryLimit: config.retryLimit ?? DEFAULT_RETRY_LIMIT,
|
|
293
|
+
retryDelay: config.retryDelay ?? DEFAULT_RETRY_DELAY,
|
|
294
|
+
fetch: config.fetch ?? globalThis.fetch.bind(globalThis)
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
async get(path, params) {
|
|
298
|
+
let url = `${this.config.baseUrl}${path}`;
|
|
299
|
+
if (params) {
|
|
300
|
+
const searchParams = new URLSearchParams(params);
|
|
301
|
+
url += `?${searchParams.toString()}`;
|
|
302
|
+
}
|
|
303
|
+
return this.request(url, { method: "GET" }, path);
|
|
304
|
+
}
|
|
305
|
+
async post(path, body) {
|
|
306
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
307
|
+
return this.request(
|
|
308
|
+
url,
|
|
309
|
+
{
|
|
310
|
+
method: "POST",
|
|
311
|
+
headers: { "Content-Type": "application/json" },
|
|
312
|
+
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
313
|
+
},
|
|
314
|
+
path
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
async put(path, body) {
|
|
318
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
319
|
+
return this.request(
|
|
320
|
+
url,
|
|
321
|
+
{
|
|
322
|
+
method: "PUT",
|
|
323
|
+
headers: { "Content-Type": "application/json" },
|
|
324
|
+
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
325
|
+
},
|
|
326
|
+
path
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
async patch(path, body) {
|
|
330
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
331
|
+
return this.request(
|
|
332
|
+
url,
|
|
333
|
+
{
|
|
334
|
+
method: "PATCH",
|
|
335
|
+
headers: { "Content-Type": "application/json" },
|
|
336
|
+
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
337
|
+
},
|
|
338
|
+
path
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
async delete(path) {
|
|
342
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
343
|
+
return this.request(url, { method: "DELETE" }, path);
|
|
344
|
+
}
|
|
345
|
+
async postForm(path, params) {
|
|
346
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
347
|
+
return this.request(
|
|
348
|
+
url,
|
|
349
|
+
{
|
|
350
|
+
method: "POST",
|
|
351
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
352
|
+
body: params.toString()
|
|
353
|
+
},
|
|
354
|
+
path
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
async upload(path, form) {
|
|
358
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
359
|
+
return this.request(url, { method: "POST", body: form }, path);
|
|
360
|
+
}
|
|
361
|
+
/** Return a new client with additional headers merged */
|
|
362
|
+
withHeaders(headers) {
|
|
363
|
+
return new _ContentstackHttpClient({
|
|
364
|
+
...this.config,
|
|
365
|
+
headers: { ...this.config.headers, ...headers }
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
/** Return a new client with a different base URL */
|
|
369
|
+
withBaseUrl(baseUrl) {
|
|
370
|
+
return new _ContentstackHttpClient({
|
|
371
|
+
...this.config,
|
|
372
|
+
baseUrl
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
async request(url, init, path) {
|
|
376
|
+
const headers = new Headers(this.config.headers);
|
|
377
|
+
if (init.headers) {
|
|
378
|
+
const initHeaders = init.headers instanceof Headers ? init.headers : new Headers(init.headers);
|
|
379
|
+
initHeaders.forEach((value, key) => headers.set(key, value));
|
|
380
|
+
}
|
|
381
|
+
let lastError;
|
|
382
|
+
const maxAttempts = this.config.retryOnError ? this.config.retryLimit + 1 : 1;
|
|
383
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
384
|
+
const controller = new AbortController();
|
|
385
|
+
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
386
|
+
try {
|
|
387
|
+
const response = await this.config.fetch(url, {
|
|
388
|
+
...init,
|
|
389
|
+
headers,
|
|
390
|
+
signal: controller.signal
|
|
391
|
+
});
|
|
392
|
+
if (response.ok) {
|
|
393
|
+
const data = await response.json().catch(() => ({}));
|
|
394
|
+
return { data, status: response.status, headers: response.headers };
|
|
395
|
+
}
|
|
396
|
+
const isRetryable = response.status === 429 || response.status >= 500;
|
|
397
|
+
if (isRetryable && this.config.retryOnError && attempt < maxAttempts - 1) {
|
|
398
|
+
const delay = this.calculateDelay(response, attempt);
|
|
399
|
+
await sleep(delay);
|
|
400
|
+
lastError = await this.createError(response, path);
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
throw await this.createError(response, path);
|
|
404
|
+
} catch (error) {
|
|
405
|
+
if (error instanceof ContentstackError) {
|
|
406
|
+
throw error;
|
|
407
|
+
}
|
|
408
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
409
|
+
throw new ContentstackError(`Request timed out after ${this.config.timeout}ms`, {
|
|
410
|
+
requestPath: path,
|
|
411
|
+
cause: error
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
throw new ContentstackError("Network request failed", {
|
|
415
|
+
requestPath: path,
|
|
416
|
+
cause: error instanceof Error ? error : new Error(String(error))
|
|
417
|
+
});
|
|
418
|
+
} finally {
|
|
419
|
+
clearTimeout(timeoutId);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
throw lastError ?? new ContentstackError("Request failed after retries", { requestPath: path });
|
|
423
|
+
}
|
|
424
|
+
calculateDelay(response, attempt) {
|
|
425
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
426
|
+
if (retryAfter) {
|
|
427
|
+
const seconds = Number.parseFloat(retryAfter);
|
|
428
|
+
if (!Number.isNaN(seconds)) {
|
|
429
|
+
return seconds * 1e3;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
const jitter = Math.random() * MAX_JITTER;
|
|
433
|
+
return this.config.retryDelay * 2 ** attempt + jitter;
|
|
434
|
+
}
|
|
435
|
+
async createError(response, path) {
|
|
436
|
+
let body = {};
|
|
437
|
+
try {
|
|
438
|
+
body = await response.json();
|
|
439
|
+
} catch {
|
|
440
|
+
}
|
|
441
|
+
const message = body.error_message ?? body.error_description ?? body.message ?? `HTTP ${response.status} error`;
|
|
442
|
+
const errorCode = body.error_code;
|
|
443
|
+
const errors = body.errors;
|
|
444
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
445
|
+
const opts = { status: response.status, errorCode, errors, requestPath: path };
|
|
446
|
+
switch (response.status) {
|
|
447
|
+
case 400:
|
|
448
|
+
return new ContentstackValidationError(message, { ...opts, status: 400 });
|
|
449
|
+
case 401:
|
|
450
|
+
return new ContentstackAuthError(message, opts);
|
|
451
|
+
case 403:
|
|
452
|
+
return new ContentstackForbiddenError(message, opts);
|
|
453
|
+
case 404:
|
|
454
|
+
return new ContentstackNotFoundError(message, opts);
|
|
455
|
+
case 412:
|
|
456
|
+
return new ContentstackInvalidApiKeyError(message, opts);
|
|
457
|
+
case 422:
|
|
458
|
+
return new ContentstackValidationError(message, { ...opts, status: 422 });
|
|
459
|
+
case 429:
|
|
460
|
+
return new ContentstackRateLimitError(message, {
|
|
461
|
+
...opts,
|
|
462
|
+
retryAfter: retryAfter ? Number.parseFloat(retryAfter) : void 0
|
|
463
|
+
});
|
|
464
|
+
default:
|
|
465
|
+
if (response.status >= 500) {
|
|
466
|
+
return new ContentstackServerError(message, opts);
|
|
467
|
+
}
|
|
468
|
+
return new ContentstackError(message, opts);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
function sleep(ms) {
|
|
473
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// src/auth/pkce.ts
|
|
477
|
+
var CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
|
|
478
|
+
function generateCodeVerifier() {
|
|
479
|
+
const bytes = new Uint8Array(43);
|
|
480
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
481
|
+
let result = "";
|
|
482
|
+
for (const byte of bytes) {
|
|
483
|
+
result += CHARSET[byte % CHARSET.length];
|
|
484
|
+
}
|
|
485
|
+
return result;
|
|
486
|
+
}
|
|
487
|
+
async function generateCodeChallenge(verifier) {
|
|
488
|
+
const encoder = new TextEncoder();
|
|
489
|
+
const data = encoder.encode(verifier);
|
|
490
|
+
const digest = await globalThis.crypto.subtle.digest("SHA-256", data);
|
|
491
|
+
const bytes = new Uint8Array(digest);
|
|
492
|
+
let binary = "";
|
|
493
|
+
for (const byte of bytes) {
|
|
494
|
+
binary += String.fromCharCode(byte);
|
|
495
|
+
}
|
|
496
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// src/auth/oauth-client.ts
|
|
500
|
+
function validateConfig(config) {
|
|
501
|
+
if (!config.appId) {
|
|
502
|
+
throw new ContentstackConfigError(
|
|
503
|
+
"appId is required for OAuth. This is your Contentstack app's UID, not the client ID."
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
if (config.appId === config.clientId) {
|
|
507
|
+
throw new ContentstackConfigError(
|
|
508
|
+
"appId and clientId must be different. appId is your Contentstack app UID; clientId is the OAuth client identifier."
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
async function buildAuthorizationUrl(config, options) {
|
|
513
|
+
validateConfig(config);
|
|
514
|
+
const endpoints = resolveEndpoints(config.region);
|
|
515
|
+
const authorizationUrl = `${endpoints.app}/apps/${config.appId}/authorize`;
|
|
516
|
+
const state = options?.state ?? generateCodeVerifier();
|
|
517
|
+
const params = new URLSearchParams({
|
|
518
|
+
response_type: "code",
|
|
519
|
+
client_id: config.clientId,
|
|
520
|
+
redirect_uri: config.redirectUri,
|
|
521
|
+
scope: config.scopes.join(" "),
|
|
522
|
+
state
|
|
523
|
+
});
|
|
524
|
+
let codeVerifier;
|
|
525
|
+
if (options?.usePKCE) {
|
|
526
|
+
codeVerifier = generateCodeVerifier();
|
|
527
|
+
const codeChallenge = await generateCodeChallenge(codeVerifier);
|
|
528
|
+
params.set("code_challenge", codeChallenge);
|
|
529
|
+
params.set("code_challenge_method", "S256");
|
|
530
|
+
}
|
|
531
|
+
return {
|
|
532
|
+
url: `${authorizationUrl}?${params.toString()}`,
|
|
533
|
+
state,
|
|
534
|
+
codeVerifier
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
function mapTokenResponse(data) {
|
|
538
|
+
return {
|
|
539
|
+
accessToken: data.access_token,
|
|
540
|
+
refreshToken: data.refresh_token,
|
|
541
|
+
expiresIn: data.expires_in,
|
|
542
|
+
tokenType: data.token_type
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
async function makeTokenRequest(appBaseUrl, body, errorMessage) {
|
|
546
|
+
const client = new ContentstackHttpClient({ baseUrl: appBaseUrl });
|
|
547
|
+
try {
|
|
548
|
+
const { data } = await client.postForm("/apps-api/token", body);
|
|
549
|
+
return mapTokenResponse(data);
|
|
550
|
+
} catch (err) {
|
|
551
|
+
if (err instanceof ContentstackError) {
|
|
552
|
+
throw new ContentstackAuthError(err.message || errorMessage, {
|
|
553
|
+
status: err.status,
|
|
554
|
+
requestPath: "/apps-api/token",
|
|
555
|
+
cause: err
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
throw new ContentstackAuthError(errorMessage, {
|
|
559
|
+
requestPath: "/apps-api/token",
|
|
560
|
+
cause: err instanceof Error ? err : void 0
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
async function exchangeCode(config, code, options) {
|
|
565
|
+
const endpoints = resolveEndpoints(config.region);
|
|
566
|
+
const body = new URLSearchParams({
|
|
567
|
+
grant_type: "authorization_code",
|
|
568
|
+
code,
|
|
569
|
+
redirect_uri: config.redirectUri,
|
|
570
|
+
client_id: config.clientId,
|
|
571
|
+
client_secret: config.clientSecret
|
|
572
|
+
});
|
|
573
|
+
if (options?.codeVerifier) {
|
|
574
|
+
body.set("code_verifier", options.codeVerifier);
|
|
575
|
+
}
|
|
576
|
+
return makeTokenRequest(endpoints.app, body, "Failed to exchange authorization code");
|
|
577
|
+
}
|
|
578
|
+
async function refreshToken(config, token) {
|
|
579
|
+
const endpoints = resolveEndpoints(config.region);
|
|
580
|
+
const body = new URLSearchParams({
|
|
581
|
+
grant_type: "refresh_token",
|
|
582
|
+
refresh_token: token,
|
|
583
|
+
client_id: config.clientId,
|
|
584
|
+
client_secret: config.clientSecret
|
|
585
|
+
});
|
|
586
|
+
return makeTokenRequest(endpoints.app, body, "Failed to refresh token");
|
|
587
|
+
}
|
|
588
|
+
function mapUser(user) {
|
|
589
|
+
return {
|
|
590
|
+
uid: user.uid,
|
|
591
|
+
email: user.email,
|
|
592
|
+
firstName: user.first_name ?? void 0,
|
|
593
|
+
lastName: user.last_name ?? void 0,
|
|
594
|
+
username: user.username ?? void 0,
|
|
595
|
+
profileImage: user.profile_image ?? void 0
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
async function getUser(region, accessToken) {
|
|
599
|
+
const endpoints = resolveEndpoints(region);
|
|
600
|
+
const client = new ContentstackHttpClient({
|
|
601
|
+
baseUrl: `${endpoints.cma}/v3`,
|
|
602
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
603
|
+
});
|
|
604
|
+
try {
|
|
605
|
+
const { data } = await client.get("/user");
|
|
606
|
+
return mapUser(data.user);
|
|
607
|
+
} catch (err) {
|
|
608
|
+
if (err instanceof ContentstackError) {
|
|
609
|
+
throw new ContentstackAuthError(err.message || "Failed to fetch user profile", {
|
|
610
|
+
status: err.status,
|
|
611
|
+
requestPath: "/v3/user",
|
|
612
|
+
cause: err
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
throw new ContentstackAuthError("Failed to fetch user profile", {
|
|
616
|
+
requestPath: "/v3/user",
|
|
617
|
+
cause: err instanceof Error ? err : void 0
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
function createAuthProvider(config) {
|
|
622
|
+
validateConfig(config);
|
|
623
|
+
const endpoints = resolveEndpoints(config.region);
|
|
624
|
+
const userClient = new ContentstackHttpClient({ baseUrl: `${endpoints.cma}/v3` });
|
|
625
|
+
return {
|
|
626
|
+
id: "contentstack",
|
|
627
|
+
name: "Contentstack",
|
|
628
|
+
type: "oauth",
|
|
629
|
+
checks: ["state"],
|
|
630
|
+
authorization: {
|
|
631
|
+
url: `${endpoints.app}/apps/${config.appId}/authorize`,
|
|
632
|
+
params: {
|
|
633
|
+
response_type: "code",
|
|
634
|
+
scope: config.scopes.join(" ")
|
|
635
|
+
}
|
|
636
|
+
},
|
|
637
|
+
token: `${endpoints.app}/apps-api/token`,
|
|
638
|
+
userinfo: {
|
|
639
|
+
url: `${endpoints.cma}/v3/user`,
|
|
640
|
+
async request({ tokens }) {
|
|
641
|
+
const authedClient = userClient.withHeaders({
|
|
642
|
+
Authorization: `Bearer ${tokens.access_token}`
|
|
643
|
+
});
|
|
644
|
+
const { data } = await authedClient.get("/user");
|
|
645
|
+
return data;
|
|
646
|
+
}
|
|
647
|
+
},
|
|
648
|
+
profile(profile) {
|
|
649
|
+
const user = profile.user;
|
|
650
|
+
return {
|
|
651
|
+
id: user.uid,
|
|
652
|
+
name: [user.first_name, user.last_name].filter(Boolean).join(" ") || user.username,
|
|
653
|
+
email: user.email,
|
|
654
|
+
image: user.profile_image ?? null
|
|
655
|
+
};
|
|
656
|
+
},
|
|
657
|
+
clientId: config.clientId,
|
|
658
|
+
clientSecret: config.clientSecret
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
function contentstackAuthCallbacks(config) {
|
|
662
|
+
return {
|
|
663
|
+
async jwt({
|
|
664
|
+
token,
|
|
665
|
+
account
|
|
666
|
+
}) {
|
|
667
|
+
if (account) {
|
|
668
|
+
token.accessToken = account.access_token;
|
|
669
|
+
token.refreshToken = account.refresh_token;
|
|
670
|
+
token.accessTokenExpiresAt = Date.now() + (account.expires_in ?? 3600) * 1e3;
|
|
671
|
+
return token;
|
|
672
|
+
}
|
|
673
|
+
const expiresAt = token.accessTokenExpiresAt;
|
|
674
|
+
if (expiresAt && Date.now() < expiresAt - 6e4) {
|
|
675
|
+
return token;
|
|
676
|
+
}
|
|
677
|
+
const currentRefreshToken = token.refreshToken;
|
|
678
|
+
if (!currentRefreshToken) {
|
|
679
|
+
token.error = "RefreshAccessTokenError";
|
|
680
|
+
return token;
|
|
681
|
+
}
|
|
682
|
+
try {
|
|
683
|
+
const tokens = await refreshToken(config, currentRefreshToken);
|
|
684
|
+
token.accessToken = tokens.accessToken;
|
|
685
|
+
token.refreshToken = tokens.refreshToken;
|
|
686
|
+
token.accessTokenExpiresAt = Date.now() + tokens.expiresIn * 1e3;
|
|
687
|
+
token.error = void 0;
|
|
688
|
+
} catch {
|
|
689
|
+
token.error = "RefreshAccessTokenError";
|
|
690
|
+
}
|
|
691
|
+
return token;
|
|
692
|
+
},
|
|
693
|
+
async session({
|
|
694
|
+
session,
|
|
695
|
+
token
|
|
696
|
+
}) {
|
|
697
|
+
session.accessToken = token.accessToken;
|
|
698
|
+
if (token.error) {
|
|
699
|
+
session.error = token.error;
|
|
700
|
+
}
|
|
701
|
+
return session;
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
// src/cma/pagination.ts
|
|
707
|
+
var DEFAULT_PAGE_SIZE = 25;
|
|
708
|
+
function paginate(fetchPage, options) {
|
|
709
|
+
const pageSize = options?.limit ?? DEFAULT_PAGE_SIZE;
|
|
710
|
+
return {
|
|
711
|
+
[Symbol.asyncIterator]() {
|
|
712
|
+
let skip = 0;
|
|
713
|
+
let done = false;
|
|
714
|
+
let buffer = [];
|
|
715
|
+
let bufferIndex = 0;
|
|
716
|
+
let totalCount;
|
|
717
|
+
return {
|
|
718
|
+
async next() {
|
|
719
|
+
if (bufferIndex < buffer.length) {
|
|
720
|
+
return { value: buffer[bufferIndex++], done: false };
|
|
721
|
+
}
|
|
722
|
+
if (done) {
|
|
723
|
+
return { value: void 0, done: true };
|
|
724
|
+
}
|
|
725
|
+
const page = await fetchPage(skip, pageSize);
|
|
726
|
+
buffer = page.items;
|
|
727
|
+
bufferIndex = 0;
|
|
728
|
+
skip += page.items.length;
|
|
729
|
+
if (typeof page.count === "number") {
|
|
730
|
+
totalCount = page.count;
|
|
731
|
+
}
|
|
732
|
+
if (page.items.length === 0) {
|
|
733
|
+
done = true;
|
|
734
|
+
return { value: void 0, done: true };
|
|
735
|
+
}
|
|
736
|
+
if (typeof totalCount === "number" && skip >= totalCount) {
|
|
737
|
+
done = true;
|
|
738
|
+
}
|
|
739
|
+
return { value: buffer[bufferIndex++], done: false };
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
async function collectAll(iterable) {
|
|
746
|
+
const items = [];
|
|
747
|
+
for await (const item of iterable) {
|
|
748
|
+
items.push(item);
|
|
749
|
+
}
|
|
750
|
+
return items;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// src/cma/assets.ts
|
|
754
|
+
var AssetsClient = class {
|
|
755
|
+
constructor(http) {
|
|
756
|
+
this.http = http;
|
|
757
|
+
}
|
|
758
|
+
list(opts) {
|
|
759
|
+
return paginate(
|
|
760
|
+
async (skip, limit) => {
|
|
761
|
+
const params = {
|
|
762
|
+
skip: String(skip),
|
|
763
|
+
limit: String(limit)
|
|
764
|
+
};
|
|
765
|
+
if (opts?.folder) params.folder = opts.folder;
|
|
766
|
+
const response = await this.http.get("/assets", params);
|
|
767
|
+
return { items: response.data.assets ?? [], count: response.data.count };
|
|
768
|
+
},
|
|
769
|
+
{ limit: opts?.limit }
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
async listAll(opts) {
|
|
773
|
+
return collectAll(this.list(opts));
|
|
774
|
+
}
|
|
775
|
+
async get(uid) {
|
|
776
|
+
const response = await this.http.get(`/assets/${uid}`);
|
|
777
|
+
return response.data.asset;
|
|
778
|
+
}
|
|
779
|
+
async upload(form) {
|
|
780
|
+
const response = await this.http.upload("/assets", form);
|
|
781
|
+
return response.data.asset;
|
|
782
|
+
}
|
|
783
|
+
async update(uid, data) {
|
|
784
|
+
const response = await this.http.put(`/assets/${uid}`, { asset: data });
|
|
785
|
+
return response.data.asset;
|
|
786
|
+
}
|
|
787
|
+
async delete(uid) {
|
|
788
|
+
await this.http.delete(`/assets/${uid}`);
|
|
789
|
+
}
|
|
790
|
+
async publish(uid, data) {
|
|
791
|
+
await this.http.post(`/assets/${uid}/publish`, { asset: data });
|
|
792
|
+
}
|
|
793
|
+
async unpublish(uid, data) {
|
|
794
|
+
await this.http.post(`/assets/${uid}/unpublish`, { asset: data });
|
|
795
|
+
}
|
|
796
|
+
// ─── Folders ──────────────────────────────────────────────────────
|
|
797
|
+
async listFolders(opts) {
|
|
798
|
+
const response = await this.http.get("/assets/folders", {
|
|
799
|
+
limit: String(opts?.limit ?? 100)
|
|
800
|
+
});
|
|
801
|
+
return response.data.assets ?? [];
|
|
802
|
+
}
|
|
803
|
+
async getFolder(uid) {
|
|
804
|
+
const response = await this.http.get(`/assets/folders/${uid}`);
|
|
805
|
+
return response.data.asset;
|
|
806
|
+
}
|
|
807
|
+
async createFolder(data) {
|
|
808
|
+
const response = await this.http.post("/assets/folders", {
|
|
809
|
+
asset: data
|
|
810
|
+
});
|
|
811
|
+
return response.data.asset;
|
|
812
|
+
}
|
|
813
|
+
async updateFolder(uid, data) {
|
|
814
|
+
const response = await this.http.put(`/assets/folders/${uid}`, {
|
|
815
|
+
asset: data
|
|
816
|
+
});
|
|
817
|
+
return response.data.asset;
|
|
818
|
+
}
|
|
819
|
+
async deleteFolder(uid) {
|
|
820
|
+
await this.http.delete(`/assets/folders/${uid}`);
|
|
821
|
+
}
|
|
822
|
+
// ─── Additional Operations ──────────────────────────────────────
|
|
823
|
+
async replace(uid, form) {
|
|
824
|
+
const response = await this.http.upload(`/assets/${uid}`, form);
|
|
825
|
+
return response.data.asset;
|
|
826
|
+
}
|
|
827
|
+
async getReferences(uid) {
|
|
828
|
+
const response = await this.http.get(`/assets/${uid}/references`);
|
|
829
|
+
return response.data.references ?? [];
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
// src/cma/base-client.ts
|
|
834
|
+
var CrudClient = class {
|
|
835
|
+
constructor(http, config) {
|
|
836
|
+
this.http = http;
|
|
837
|
+
this.config = config;
|
|
838
|
+
}
|
|
839
|
+
list(opts) {
|
|
840
|
+
return paginate(
|
|
841
|
+
async (skip, limit) => {
|
|
842
|
+
const response = await this.http.get(this.config.basePath, {
|
|
843
|
+
skip: String(skip),
|
|
844
|
+
limit: String(limit)
|
|
845
|
+
});
|
|
846
|
+
const items = response.data[this.config.pluralKey] ?? [];
|
|
847
|
+
return { items, count: response.data.count };
|
|
848
|
+
},
|
|
849
|
+
{ limit: opts?.limit }
|
|
850
|
+
);
|
|
851
|
+
}
|
|
852
|
+
async listAll(opts) {
|
|
853
|
+
return collectAll(this.list(opts));
|
|
854
|
+
}
|
|
855
|
+
async get(uid) {
|
|
856
|
+
const response = await this.http.get(`${this.config.basePath}/${uid}`);
|
|
857
|
+
return response.data[this.config.singularKey];
|
|
858
|
+
}
|
|
859
|
+
async create(data) {
|
|
860
|
+
const response = await this.http.post(this.config.basePath, {
|
|
861
|
+
[this.config.singularKey]: data
|
|
862
|
+
});
|
|
863
|
+
return response.data[this.config.singularKey];
|
|
864
|
+
}
|
|
865
|
+
async update(uid, data) {
|
|
866
|
+
const response = await this.http.put(
|
|
867
|
+
`${this.config.basePath}/${uid}`,
|
|
868
|
+
{ [this.config.singularKey]: data }
|
|
869
|
+
);
|
|
870
|
+
return response.data[this.config.singularKey];
|
|
871
|
+
}
|
|
872
|
+
async delete(uid) {
|
|
873
|
+
await this.http.delete(`${this.config.basePath}/${uid}`);
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
|
|
877
|
+
// src/cma/audit-log.ts
|
|
878
|
+
var AuditLogClient = class extends CrudClient {
|
|
879
|
+
constructor(http) {
|
|
880
|
+
super(http, { basePath: "/audit-logs", singularKey: "audit_log", pluralKey: "audit_logs" });
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
|
|
884
|
+
// src/cma/branch-aliases.ts
|
|
885
|
+
var BranchAliasesClient = class {
|
|
886
|
+
constructor(http) {
|
|
887
|
+
this.http = http;
|
|
888
|
+
}
|
|
889
|
+
async list() {
|
|
890
|
+
const response = await this.http.get(
|
|
891
|
+
"/stacks/branch_aliases"
|
|
892
|
+
);
|
|
893
|
+
return response.data.branch_aliases ?? [];
|
|
894
|
+
}
|
|
895
|
+
async get(uid) {
|
|
896
|
+
const response = await this.http.get(
|
|
897
|
+
`/stacks/branch_aliases/${uid}`
|
|
898
|
+
);
|
|
899
|
+
return response.data.branch_alias;
|
|
900
|
+
}
|
|
901
|
+
async createOrUpdate(uid, targetBranch) {
|
|
902
|
+
const response = await this.http.put(
|
|
903
|
+
`/stacks/branch_aliases/${uid}`,
|
|
904
|
+
{ branch_alias: { target_branch: targetBranch } }
|
|
905
|
+
);
|
|
906
|
+
return response.data.branch_alias;
|
|
907
|
+
}
|
|
908
|
+
async delete(uid) {
|
|
909
|
+
await this.http.delete(`/stacks/branch_aliases/${uid}`);
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
|
|
913
|
+
// src/cma/branches.ts
|
|
914
|
+
var BranchesClient = class {
|
|
915
|
+
constructor(http) {
|
|
916
|
+
this.http = http;
|
|
917
|
+
}
|
|
918
|
+
list(opts) {
|
|
919
|
+
return paginate(
|
|
920
|
+
async (skip, limit) => {
|
|
921
|
+
const response = await this.http.get(
|
|
922
|
+
"/stacks/branches",
|
|
923
|
+
{ skip: String(skip), limit: String(limit) }
|
|
924
|
+
);
|
|
925
|
+
return { items: response.data.branches ?? [], count: response.data.count };
|
|
926
|
+
},
|
|
927
|
+
{ limit: opts?.limit }
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
async listAll(opts) {
|
|
931
|
+
return collectAll(this.list(opts));
|
|
932
|
+
}
|
|
933
|
+
async get(uid) {
|
|
934
|
+
const response = await this.http.get(`/stacks/branches/${uid}`);
|
|
935
|
+
return response.data.branch;
|
|
936
|
+
}
|
|
937
|
+
async create(data) {
|
|
938
|
+
const response = await this.http.post("/stacks/branches", {
|
|
939
|
+
branch: data
|
|
940
|
+
});
|
|
941
|
+
return response.data.branch;
|
|
942
|
+
}
|
|
943
|
+
async delete(uid) {
|
|
944
|
+
await this.http.delete(`/stacks/branches/${uid}`);
|
|
945
|
+
}
|
|
946
|
+
async compare(baseBranch, compareBranch) {
|
|
947
|
+
const response = await this.http.get("/stacks/branches_compare", {
|
|
948
|
+
base_branch: baseBranch,
|
|
949
|
+
compare_branch: compareBranch
|
|
950
|
+
});
|
|
951
|
+
return response.data;
|
|
952
|
+
}
|
|
953
|
+
async merge(data) {
|
|
954
|
+
const response = await this.http.post("/stacks/branches_merge", data);
|
|
955
|
+
return response.data.merge_job;
|
|
956
|
+
}
|
|
957
|
+
async listMergeJobs() {
|
|
958
|
+
const response = await this.http.get("/stacks/branches_queue");
|
|
959
|
+
return response.data.merge_jobs ?? [];
|
|
960
|
+
}
|
|
961
|
+
async getMergeJob(uid) {
|
|
962
|
+
const response = await this.http.get(`/stacks/branches_queue/${uid}`);
|
|
963
|
+
return response.data.merge_job;
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
// src/cma/bulk.ts
|
|
968
|
+
var BulkOperationsClient = class {
|
|
969
|
+
constructor(http) {
|
|
970
|
+
this.http = http;
|
|
971
|
+
}
|
|
972
|
+
async publish(data) {
|
|
973
|
+
await this.http.post("/bulk/publish", data);
|
|
974
|
+
}
|
|
975
|
+
async unpublish(data) {
|
|
976
|
+
await this.http.post("/bulk/unpublish", data);
|
|
977
|
+
}
|
|
978
|
+
async delete(data) {
|
|
979
|
+
await this.http.post("/bulk/delete", data);
|
|
980
|
+
}
|
|
981
|
+
async updateWorkflow(data) {
|
|
982
|
+
await this.http.post("/bulk/workflow", data);
|
|
983
|
+
}
|
|
984
|
+
async addItems(data) {
|
|
985
|
+
await this.http.post("/bulk/add", data);
|
|
986
|
+
}
|
|
987
|
+
async updateItems(data) {
|
|
988
|
+
await this.http.post("/bulk/update", data);
|
|
989
|
+
}
|
|
990
|
+
async jobStatus(jobId) {
|
|
991
|
+
const response = await this.http.get(`/bulk/jobs/${jobId}`);
|
|
992
|
+
return response.data.job;
|
|
993
|
+
}
|
|
994
|
+
async getJobItems(jobId, opts) {
|
|
995
|
+
const params = {};
|
|
996
|
+
if (opts?.limit) params.limit = String(opts.limit);
|
|
997
|
+
if (opts?.skip) params.skip = String(opts.skip);
|
|
998
|
+
const response = await this.http.get(
|
|
999
|
+
`/bulk/jobs/${jobId}/items`,
|
|
1000
|
+
Object.keys(params).length > 0 ? params : void 0
|
|
1001
|
+
);
|
|
1002
|
+
return response.data.items ?? [];
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
|
|
1006
|
+
// src/cma/content-types.ts
|
|
1007
|
+
var ContentTypesClient = class extends CrudClient {
|
|
1008
|
+
constructor(http) {
|
|
1009
|
+
super(http, {
|
|
1010
|
+
basePath: "/content_types",
|
|
1011
|
+
singularKey: "content_type",
|
|
1012
|
+
pluralKey: "content_types"
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
list(opts) {
|
|
1016
|
+
return paginate(
|
|
1017
|
+
async (skip, limit) => {
|
|
1018
|
+
const params = {
|
|
1019
|
+
skip: String(skip),
|
|
1020
|
+
limit: String(limit)
|
|
1021
|
+
};
|
|
1022
|
+
if (opts?.include_count) params.include_count = "true";
|
|
1023
|
+
const response = await this.http.get("/content_types", params);
|
|
1024
|
+
return { items: response.data.content_types ?? [], count: response.data.count };
|
|
1025
|
+
},
|
|
1026
|
+
{ limit: opts?.limit }
|
|
1027
|
+
);
|
|
1028
|
+
}
|
|
1029
|
+
async listAll(opts) {
|
|
1030
|
+
return collectAll(this.list(opts));
|
|
1031
|
+
}
|
|
1032
|
+
async export(uid) {
|
|
1033
|
+
const response = await this.http.get(
|
|
1034
|
+
`/content_types/${uid}/export`
|
|
1035
|
+
);
|
|
1036
|
+
return response.data.content_type;
|
|
1037
|
+
}
|
|
1038
|
+
async import(data) {
|
|
1039
|
+
const response = await this.http.post(
|
|
1040
|
+
"/content_types/import",
|
|
1041
|
+
data
|
|
1042
|
+
);
|
|
1043
|
+
return response.data.content_type;
|
|
1044
|
+
}
|
|
1045
|
+
};
|
|
1046
|
+
|
|
1047
|
+
// src/cma/entries.ts
|
|
1048
|
+
var EntriesClient = class {
|
|
1049
|
+
constructor(http) {
|
|
1050
|
+
this.http = http;
|
|
1051
|
+
}
|
|
1052
|
+
basePath(ctUid) {
|
|
1053
|
+
return `/content_types/${ctUid}/entries`;
|
|
1054
|
+
}
|
|
1055
|
+
list(ctUid, opts) {
|
|
1056
|
+
return paginate(
|
|
1057
|
+
async (skip, limit) => {
|
|
1058
|
+
const params = {
|
|
1059
|
+
skip: String(skip),
|
|
1060
|
+
limit: String(limit)
|
|
1061
|
+
};
|
|
1062
|
+
if (opts?.locale) params.locale = opts.locale;
|
|
1063
|
+
if (opts?.include_publish_details) params.include_publish_details = "true";
|
|
1064
|
+
if (opts?.include_workflow) params.include_workflow = "true";
|
|
1065
|
+
if (opts?.include_count) params.include_count = "true";
|
|
1066
|
+
if (opts?.query) params.query = JSON.stringify(opts.query);
|
|
1067
|
+
if (opts?.asc) params.asc = opts.asc;
|
|
1068
|
+
if (opts?.desc) params.desc = opts.desc;
|
|
1069
|
+
const response = await this.http.get(
|
|
1070
|
+
this.basePath(ctUid),
|
|
1071
|
+
params
|
|
1072
|
+
);
|
|
1073
|
+
return { items: response.data.entries ?? [], count: response.data.count };
|
|
1074
|
+
},
|
|
1075
|
+
{ limit: opts?.limit }
|
|
1076
|
+
);
|
|
1077
|
+
}
|
|
1078
|
+
async listAll(ctUid, opts) {
|
|
1079
|
+
return collectAll(this.list(ctUid, opts));
|
|
1080
|
+
}
|
|
1081
|
+
async get(ctUid, entryUid, opts) {
|
|
1082
|
+
const params = {};
|
|
1083
|
+
if (opts?.locale) params.locale = opts.locale;
|
|
1084
|
+
if (opts?.include_publish_details) params.include_publish_details = "true";
|
|
1085
|
+
if (opts?.include_workflow) params.include_workflow = "true";
|
|
1086
|
+
if (opts?.version) params.version = String(opts.version);
|
|
1087
|
+
const response = await this.http.get(
|
|
1088
|
+
`${this.basePath(ctUid)}/${entryUid}`,
|
|
1089
|
+
Object.keys(params).length > 0 ? params : void 0
|
|
1090
|
+
);
|
|
1091
|
+
return response.data.entry;
|
|
1092
|
+
}
|
|
1093
|
+
async create(ctUid, data) {
|
|
1094
|
+
const response = await this.http.post(this.basePath(ctUid), { entry: data });
|
|
1095
|
+
return response.data.entry;
|
|
1096
|
+
}
|
|
1097
|
+
async update(ctUid, entryUid, data) {
|
|
1098
|
+
const response = await this.http.put(`${this.basePath(ctUid)}/${entryUid}`, {
|
|
1099
|
+
entry: data
|
|
1100
|
+
});
|
|
1101
|
+
return response.data.entry;
|
|
1102
|
+
}
|
|
1103
|
+
async delete(ctUid, entryUid, opts) {
|
|
1104
|
+
let path = `${this.basePath(ctUid)}/${entryUid}`;
|
|
1105
|
+
if (opts?.locale) path += `?locale=${encodeURIComponent(opts.locale)}`;
|
|
1106
|
+
await this.http.delete(path);
|
|
1107
|
+
}
|
|
1108
|
+
async publish(ctUid, entryUid, data) {
|
|
1109
|
+
await this.http.post(`${this.basePath(ctUid)}/${entryUid}/publish`, { entry: data });
|
|
1110
|
+
}
|
|
1111
|
+
async unpublish(ctUid, entryUid, data) {
|
|
1112
|
+
await this.http.post(`${this.basePath(ctUid)}/${entryUid}/unpublish`, { entry: data });
|
|
1113
|
+
}
|
|
1114
|
+
async localize(ctUid, entryUid, data) {
|
|
1115
|
+
const response = await this.http.post(
|
|
1116
|
+
`${this.basePath(ctUid)}/${entryUid}/localize`,
|
|
1117
|
+
{ entry: data }
|
|
1118
|
+
);
|
|
1119
|
+
return response.data.entry;
|
|
1120
|
+
}
|
|
1121
|
+
async setWorkflowStage(ctUid, entryUid, data) {
|
|
1122
|
+
await this.http.post(`${this.basePath(ctUid)}/${entryUid}/workflow`, data);
|
|
1123
|
+
}
|
|
1124
|
+
async references(ctUid, entryUid) {
|
|
1125
|
+
const response = await this.http.get(
|
|
1126
|
+
`${this.basePath(ctUid)}/${entryUid}/references`
|
|
1127
|
+
);
|
|
1128
|
+
return response.data.references ?? [];
|
|
1129
|
+
}
|
|
1130
|
+
async languages(ctUid, entryUid) {
|
|
1131
|
+
const response = await this.http.get(
|
|
1132
|
+
`${this.basePath(ctUid)}/${entryUid}/languages`
|
|
1133
|
+
);
|
|
1134
|
+
return response.data.locales ?? [];
|
|
1135
|
+
}
|
|
1136
|
+
async versions(ctUid, entryUid) {
|
|
1137
|
+
const response = await this.http.get(
|
|
1138
|
+
`${this.basePath(ctUid)}/${entryUid}/versions`
|
|
1139
|
+
);
|
|
1140
|
+
return response.data.versions ?? [];
|
|
1141
|
+
}
|
|
1142
|
+
async import(ctUid, data, opts) {
|
|
1143
|
+
let path = `${this.basePath(ctUid)}/import`;
|
|
1144
|
+
const params = [];
|
|
1145
|
+
if (opts?.locale) params.push(`locale=${encodeURIComponent(opts.locale)}`);
|
|
1146
|
+
if (opts?.overwrite) params.push("overwrite=true");
|
|
1147
|
+
if (params.length > 0) path += `?${params.join("&")}`;
|
|
1148
|
+
const response = await this.http.post(path, data);
|
|
1149
|
+
return response.data.entry;
|
|
1150
|
+
}
|
|
1151
|
+
};
|
|
1152
|
+
|
|
1153
|
+
// src/cma/environments.ts
|
|
1154
|
+
var EnvironmentsClient = class extends CrudClient {
|
|
1155
|
+
constructor(http) {
|
|
1156
|
+
super(http, {
|
|
1157
|
+
basePath: "/environments",
|
|
1158
|
+
singularKey: "environment",
|
|
1159
|
+
pluralKey: "environments"
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
};
|
|
1163
|
+
|
|
1164
|
+
// src/cma/extensions.ts
|
|
1165
|
+
var ExtensionsClient = class extends CrudClient {
|
|
1166
|
+
constructor(http) {
|
|
1167
|
+
super(http, { basePath: "/extensions", singularKey: "extension", pluralKey: "extensions" });
|
|
1168
|
+
}
|
|
1169
|
+
async upload(form) {
|
|
1170
|
+
const response = await this.http.upload("/extensions", form);
|
|
1171
|
+
return response.data.extension;
|
|
1172
|
+
}
|
|
1173
|
+
};
|
|
1174
|
+
|
|
1175
|
+
// src/cma/global-fields.ts
|
|
1176
|
+
var GlobalFieldsClient = class extends CrudClient {
|
|
1177
|
+
constructor(http) {
|
|
1178
|
+
super(http, {
|
|
1179
|
+
basePath: "/global_fields",
|
|
1180
|
+
singularKey: "global_field",
|
|
1181
|
+
pluralKey: "global_fields"
|
|
1182
|
+
});
|
|
1183
|
+
}
|
|
1184
|
+
async export(uid) {
|
|
1185
|
+
const response = await this.http.get(
|
|
1186
|
+
`/global_fields/${uid}/export`
|
|
1187
|
+
);
|
|
1188
|
+
return response.data.global_field;
|
|
1189
|
+
}
|
|
1190
|
+
async import(data) {
|
|
1191
|
+
const response = await this.http.post(
|
|
1192
|
+
"/global_fields/import",
|
|
1193
|
+
data
|
|
1194
|
+
);
|
|
1195
|
+
return response.data.global_field;
|
|
1196
|
+
}
|
|
1197
|
+
};
|
|
1198
|
+
|
|
1199
|
+
// src/cma/labels.ts
|
|
1200
|
+
var LabelsClient = class extends CrudClient {
|
|
1201
|
+
constructor(http) {
|
|
1202
|
+
super(http, { basePath: "/labels", singularKey: "label", pluralKey: "labels" });
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
|
|
1206
|
+
// src/cma/locales.ts
|
|
1207
|
+
var LocalesClient = class extends CrudClient {
|
|
1208
|
+
constructor(http) {
|
|
1209
|
+
super(http, { basePath: "/locales", singularKey: "locale", pluralKey: "locales" });
|
|
1210
|
+
}
|
|
1211
|
+
};
|
|
1212
|
+
|
|
1213
|
+
// src/cma/publish-rules.ts
|
|
1214
|
+
var PublishRulesClient = class extends CrudClient {
|
|
1215
|
+
constructor(http) {
|
|
1216
|
+
super(http, {
|
|
1217
|
+
basePath: "/workflows/publishing_rules",
|
|
1218
|
+
singularKey: "publishing_rule",
|
|
1219
|
+
pluralKey: "publishing_rules"
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
|
|
1224
|
+
// src/cma/releases.ts
|
|
1225
|
+
var ReleasesClient = class {
|
|
1226
|
+
constructor(http) {
|
|
1227
|
+
this.http = http;
|
|
1228
|
+
}
|
|
1229
|
+
list(opts) {
|
|
1230
|
+
return paginate(
|
|
1231
|
+
async (skip, limit) => {
|
|
1232
|
+
const params = {
|
|
1233
|
+
skip: String(skip),
|
|
1234
|
+
limit: String(limit)
|
|
1235
|
+
};
|
|
1236
|
+
if (opts?.include_count) params.include_count = "true";
|
|
1237
|
+
const response = await this.http.get(
|
|
1238
|
+
"/releases",
|
|
1239
|
+
params
|
|
1240
|
+
);
|
|
1241
|
+
return { items: response.data.releases ?? [], count: response.data.count };
|
|
1242
|
+
},
|
|
1243
|
+
{ limit: opts?.limit }
|
|
1244
|
+
);
|
|
1245
|
+
}
|
|
1246
|
+
async listAll(opts) {
|
|
1247
|
+
return collectAll(this.list(opts));
|
|
1248
|
+
}
|
|
1249
|
+
async get(uid) {
|
|
1250
|
+
const response = await this.http.get(`/releases/${uid}`);
|
|
1251
|
+
return response.data.release;
|
|
1252
|
+
}
|
|
1253
|
+
async create(data) {
|
|
1254
|
+
const response = await this.http.post("/releases", { release: data });
|
|
1255
|
+
return response.data.release;
|
|
1256
|
+
}
|
|
1257
|
+
async update(uid, data) {
|
|
1258
|
+
const response = await this.http.put(`/releases/${uid}`, {
|
|
1259
|
+
release: data
|
|
1260
|
+
});
|
|
1261
|
+
return response.data.release;
|
|
1262
|
+
}
|
|
1263
|
+
async delete(uid) {
|
|
1264
|
+
await this.http.delete(`/releases/${uid}`);
|
|
1265
|
+
}
|
|
1266
|
+
async deploy(uid, data) {
|
|
1267
|
+
await this.http.post(`/releases/${uid}/deploy`, { release: data });
|
|
1268
|
+
}
|
|
1269
|
+
// ─── Items ──────────────────────────────────────────────────────
|
|
1270
|
+
async listItems(uid) {
|
|
1271
|
+
const response = await this.http.get(`/releases/${uid}/items`);
|
|
1272
|
+
return response.data.items ?? [];
|
|
1273
|
+
}
|
|
1274
|
+
async addItem(uid, item) {
|
|
1275
|
+
await this.http.post(`/releases/${uid}/items`, { item });
|
|
1276
|
+
}
|
|
1277
|
+
async removeItem(uid, item) {
|
|
1278
|
+
await this.http.post(`/releases/${uid}/items/delete`, { item });
|
|
1279
|
+
}
|
|
1280
|
+
async clone(uid, data) {
|
|
1281
|
+
const response = await this.http.post(`/releases/${uid}/clone`, {
|
|
1282
|
+
release: data
|
|
1283
|
+
});
|
|
1284
|
+
return response.data.release;
|
|
1285
|
+
}
|
|
1286
|
+
};
|
|
1287
|
+
|
|
1288
|
+
// src/cma/roles.ts
|
|
1289
|
+
var RolesClient = class extends CrudClient {
|
|
1290
|
+
constructor(http) {
|
|
1291
|
+
super(http, { basePath: "/roles", singularKey: "role", pluralKey: "roles" });
|
|
1292
|
+
}
|
|
1293
|
+
};
|
|
1294
|
+
|
|
1295
|
+
// src/cma/taxonomies.ts
|
|
1296
|
+
var TaxonomiesClient = class {
|
|
1297
|
+
constructor(http) {
|
|
1298
|
+
this.http = http;
|
|
1299
|
+
}
|
|
1300
|
+
// ─── Taxonomies ───────────────────────────────────────────────────
|
|
1301
|
+
list(opts) {
|
|
1302
|
+
return paginate(
|
|
1303
|
+
async (skip, limit) => {
|
|
1304
|
+
const response = await this.http.get(
|
|
1305
|
+
"/taxonomies",
|
|
1306
|
+
{ skip: String(skip), limit: String(limit) }
|
|
1307
|
+
);
|
|
1308
|
+
return { items: response.data.taxonomies ?? [], count: response.data.count };
|
|
1309
|
+
},
|
|
1310
|
+
{ limit: opts?.limit }
|
|
1311
|
+
);
|
|
1312
|
+
}
|
|
1313
|
+
async listAll(opts) {
|
|
1314
|
+
return collectAll(this.list(opts));
|
|
1315
|
+
}
|
|
1316
|
+
async get(uid) {
|
|
1317
|
+
const response = await this.http.get(`/taxonomies/${uid}`);
|
|
1318
|
+
return response.data.taxonomy;
|
|
1319
|
+
}
|
|
1320
|
+
async create(data) {
|
|
1321
|
+
const response = await this.http.post("/taxonomies", {
|
|
1322
|
+
taxonomy: data
|
|
1323
|
+
});
|
|
1324
|
+
return response.data.taxonomy;
|
|
1325
|
+
}
|
|
1326
|
+
async update(uid, data) {
|
|
1327
|
+
const response = await this.http.put(`/taxonomies/${uid}`, {
|
|
1328
|
+
taxonomy: data
|
|
1329
|
+
});
|
|
1330
|
+
return response.data.taxonomy;
|
|
1331
|
+
}
|
|
1332
|
+
async delete(uid) {
|
|
1333
|
+
await this.http.delete(`/taxonomies/${uid}`);
|
|
1334
|
+
}
|
|
1335
|
+
// ─── Terms ────────────────────────────────────────────────────────
|
|
1336
|
+
listTerms(taxonomyUid, opts) {
|
|
1337
|
+
return paginate(
|
|
1338
|
+
async (skip, limit) => {
|
|
1339
|
+
const response = await this.http.get(
|
|
1340
|
+
`/taxonomies/${taxonomyUid}/terms`,
|
|
1341
|
+
{ skip: String(skip), limit: String(limit) }
|
|
1342
|
+
);
|
|
1343
|
+
return { items: response.data.terms ?? [], count: response.data.count };
|
|
1344
|
+
},
|
|
1345
|
+
{ limit: opts?.limit }
|
|
1346
|
+
);
|
|
1347
|
+
}
|
|
1348
|
+
async listAllTerms(taxonomyUid, opts) {
|
|
1349
|
+
return collectAll(this.listTerms(taxonomyUid, opts));
|
|
1350
|
+
}
|
|
1351
|
+
async getTerm(taxonomyUid, termUid) {
|
|
1352
|
+
const response = await this.http.get(
|
|
1353
|
+
`/taxonomies/${taxonomyUid}/terms/${termUid}`
|
|
1354
|
+
);
|
|
1355
|
+
return response.data.term;
|
|
1356
|
+
}
|
|
1357
|
+
async createTerm(taxonomyUid, data) {
|
|
1358
|
+
const response = await this.http.post(
|
|
1359
|
+
`/taxonomies/${taxonomyUid}/terms`,
|
|
1360
|
+
{ term: data }
|
|
1361
|
+
);
|
|
1362
|
+
return response.data.term;
|
|
1363
|
+
}
|
|
1364
|
+
async updateTerm(taxonomyUid, termUid, data) {
|
|
1365
|
+
const response = await this.http.put(
|
|
1366
|
+
`/taxonomies/${taxonomyUid}/terms/${termUid}`,
|
|
1367
|
+
{ term: data }
|
|
1368
|
+
);
|
|
1369
|
+
return response.data.term;
|
|
1370
|
+
}
|
|
1371
|
+
async deleteTerm(taxonomyUid, termUid) {
|
|
1372
|
+
await this.http.delete(`/taxonomies/${taxonomyUid}/terms/${termUid}`);
|
|
1373
|
+
}
|
|
1374
|
+
async ancestors(taxonomyUid, termUid) {
|
|
1375
|
+
const response = await this.http.get(
|
|
1376
|
+
`/taxonomies/${taxonomyUid}/terms/${termUid}/ancestors`
|
|
1377
|
+
);
|
|
1378
|
+
return response.data.terms ?? [];
|
|
1379
|
+
}
|
|
1380
|
+
async descendants(taxonomyUid, termUid) {
|
|
1381
|
+
const response = await this.http.get(
|
|
1382
|
+
`/taxonomies/${taxonomyUid}/terms/${termUid}/descendants`
|
|
1383
|
+
);
|
|
1384
|
+
return response.data.terms ?? [];
|
|
1385
|
+
}
|
|
1386
|
+
async moveTerm(taxonomyUid, termUid, data) {
|
|
1387
|
+
const response = await this.http.put(
|
|
1388
|
+
`/taxonomies/${taxonomyUid}/terms/${termUid}/move`,
|
|
1389
|
+
{ term: data }
|
|
1390
|
+
);
|
|
1391
|
+
return response.data.term;
|
|
1392
|
+
}
|
|
1393
|
+
// ─── Import / Export ──────────────────────────────────────────────
|
|
1394
|
+
async export(uid) {
|
|
1395
|
+
const response = await this.http.get(`/taxonomies/${uid}/export`);
|
|
1396
|
+
return response.data.taxonomy;
|
|
1397
|
+
}
|
|
1398
|
+
async import(data) {
|
|
1399
|
+
const response = await this.http.post("/taxonomies/import", data);
|
|
1400
|
+
return response.data.taxonomy;
|
|
1401
|
+
}
|
|
1402
|
+
};
|
|
1403
|
+
|
|
1404
|
+
// src/cma/tokens.ts
|
|
1405
|
+
function tokenCrud(http, basePath) {
|
|
1406
|
+
return {
|
|
1407
|
+
async list() {
|
|
1408
|
+
const response = await http.get(basePath);
|
|
1409
|
+
return response.data.tokens ?? [];
|
|
1410
|
+
},
|
|
1411
|
+
async get(uid) {
|
|
1412
|
+
const response = await http.get(`${basePath}/${uid}`);
|
|
1413
|
+
return response.data.token;
|
|
1414
|
+
},
|
|
1415
|
+
async create(data) {
|
|
1416
|
+
const response = await http.post(basePath, { token: data });
|
|
1417
|
+
return response.data.token;
|
|
1418
|
+
},
|
|
1419
|
+
async update(uid, data) {
|
|
1420
|
+
const response = await http.put(`${basePath}/${uid}`, { token: data });
|
|
1421
|
+
return response.data.token;
|
|
1422
|
+
},
|
|
1423
|
+
async delete(uid) {
|
|
1424
|
+
await http.delete(`${basePath}/${uid}`);
|
|
1425
|
+
}
|
|
1426
|
+
};
|
|
1427
|
+
}
|
|
1428
|
+
var TokensClient = class {
|
|
1429
|
+
management;
|
|
1430
|
+
delivery;
|
|
1431
|
+
preview;
|
|
1432
|
+
constructor(http) {
|
|
1433
|
+
this.management = tokenCrud(http, "/stacks/management_tokens");
|
|
1434
|
+
this.delivery = tokenCrud(http, "/stacks/delivery_tokens");
|
|
1435
|
+
this.preview = tokenCrud(http, "/stacks/preview_tokens");
|
|
1436
|
+
}
|
|
1437
|
+
// ─── Management Tokens ────────────────────────────────────────────
|
|
1438
|
+
listManagementTokens() {
|
|
1439
|
+
return this.management.list();
|
|
1440
|
+
}
|
|
1441
|
+
getManagementToken(uid) {
|
|
1442
|
+
return this.management.get(uid);
|
|
1443
|
+
}
|
|
1444
|
+
createManagementToken(data) {
|
|
1445
|
+
return this.management.create(data);
|
|
1446
|
+
}
|
|
1447
|
+
updateManagementToken(uid, data) {
|
|
1448
|
+
return this.management.update(uid, data);
|
|
1449
|
+
}
|
|
1450
|
+
deleteManagementToken(uid) {
|
|
1451
|
+
return this.management.delete(uid);
|
|
1452
|
+
}
|
|
1453
|
+
// ─── Delivery Tokens ──────────────────────────────────────────────
|
|
1454
|
+
listDeliveryTokens() {
|
|
1455
|
+
return this.delivery.list();
|
|
1456
|
+
}
|
|
1457
|
+
getDeliveryToken(uid) {
|
|
1458
|
+
return this.delivery.get(uid);
|
|
1459
|
+
}
|
|
1460
|
+
createDeliveryToken(data) {
|
|
1461
|
+
return this.delivery.create(data);
|
|
1462
|
+
}
|
|
1463
|
+
updateDeliveryToken(uid, data) {
|
|
1464
|
+
return this.delivery.update(uid, data);
|
|
1465
|
+
}
|
|
1466
|
+
deleteDeliveryToken(uid) {
|
|
1467
|
+
return this.delivery.delete(uid);
|
|
1468
|
+
}
|
|
1469
|
+
// ─── Preview Tokens ──────────────────────────────────────────────
|
|
1470
|
+
listPreviewTokens() {
|
|
1471
|
+
return this.preview.list();
|
|
1472
|
+
}
|
|
1473
|
+
getPreviewToken(uid) {
|
|
1474
|
+
return this.preview.get(uid);
|
|
1475
|
+
}
|
|
1476
|
+
createPreviewToken(data) {
|
|
1477
|
+
return this.preview.create(data);
|
|
1478
|
+
}
|
|
1479
|
+
updatePreviewToken(uid, data) {
|
|
1480
|
+
return this.preview.update(uid, data);
|
|
1481
|
+
}
|
|
1482
|
+
deletePreviewToken(uid) {
|
|
1483
|
+
return this.preview.delete(uid);
|
|
1484
|
+
}
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1487
|
+
// src/cma/webhooks.ts
|
|
1488
|
+
var WebhooksClient = class extends CrudClient {
|
|
1489
|
+
constructor(http) {
|
|
1490
|
+
super(http, { basePath: "/webhooks", singularKey: "webhook", pluralKey: "webhooks" });
|
|
1491
|
+
}
|
|
1492
|
+
async logs(uid) {
|
|
1493
|
+
const response = await this.http.get(`/webhooks/${uid}/logs`);
|
|
1494
|
+
return response.data.logs ?? [];
|
|
1495
|
+
}
|
|
1496
|
+
async retry(uid, executionUid) {
|
|
1497
|
+
await this.http.post(`/webhooks/${uid}/retry/${executionUid}`, {});
|
|
1498
|
+
}
|
|
1499
|
+
};
|
|
1500
|
+
|
|
1501
|
+
// src/cma/workflows.ts
|
|
1502
|
+
var WorkflowsClient = class extends CrudClient {
|
|
1503
|
+
constructor(http) {
|
|
1504
|
+
super(http, { basePath: "/workflows", singularKey: "workflow", pluralKey: "workflows" });
|
|
1505
|
+
}
|
|
1506
|
+
};
|
|
1507
|
+
|
|
1508
|
+
// src/cma/client.ts
|
|
1509
|
+
function createCMAClient(config) {
|
|
1510
|
+
const endpoints = resolveEndpoints(config.region);
|
|
1511
|
+
const headers = { api_key: config.apiKey };
|
|
1512
|
+
switch (config.auth.type) {
|
|
1513
|
+
case "management-token":
|
|
1514
|
+
headers.authorization = config.auth.token;
|
|
1515
|
+
break;
|
|
1516
|
+
case "oauth":
|
|
1517
|
+
headers.authorization = `Bearer ${config.auth.accessToken}`;
|
|
1518
|
+
break;
|
|
1519
|
+
case "authtoken":
|
|
1520
|
+
headers.authtoken = config.auth.token;
|
|
1521
|
+
break;
|
|
1522
|
+
}
|
|
1523
|
+
if (config.branch) {
|
|
1524
|
+
headers.branch = config.branch;
|
|
1525
|
+
}
|
|
1526
|
+
const http = new ContentstackHttpClient({
|
|
1527
|
+
...config.httpOptions,
|
|
1528
|
+
baseUrl: config.httpOptions?.baseUrl ?? `${endpoints.cma}/v3`,
|
|
1529
|
+
headers: {
|
|
1530
|
+
...config.httpOptions?.headers,
|
|
1531
|
+
...headers
|
|
1532
|
+
}
|
|
1533
|
+
});
|
|
1534
|
+
return {
|
|
1535
|
+
entries: new EntriesClient(http),
|
|
1536
|
+
contentTypes: new ContentTypesClient(http),
|
|
1537
|
+
assets: new AssetsClient(http),
|
|
1538
|
+
environments: new EnvironmentsClient(http),
|
|
1539
|
+
locales: new LocalesClient(http),
|
|
1540
|
+
globalFields: new GlobalFieldsClient(http),
|
|
1541
|
+
webhooks: new WebhooksClient(http),
|
|
1542
|
+
workflows: new WorkflowsClient(http),
|
|
1543
|
+
releases: new ReleasesClient(http),
|
|
1544
|
+
branches: new BranchesClient(http),
|
|
1545
|
+
branchAliases: new BranchAliasesClient(http),
|
|
1546
|
+
taxonomies: new TaxonomiesClient(http),
|
|
1547
|
+
bulk: new BulkOperationsClient(http),
|
|
1548
|
+
tokens: new TokensClient(http),
|
|
1549
|
+
labels: new LabelsClient(http),
|
|
1550
|
+
roles: new RolesClient(http),
|
|
1551
|
+
auditLog: new AuditLogClient(http),
|
|
1552
|
+
extensions: new ExtensionsClient(http),
|
|
1553
|
+
publishRules: new PublishRulesClient(http),
|
|
1554
|
+
onBranch(branchUid) {
|
|
1555
|
+
return createCMAClient({ ...config, branch: branchUid });
|
|
1556
|
+
}
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
// src/cma/request-builders.ts
|
|
1561
|
+
function nonEmptyParams(params) {
|
|
1562
|
+
return Object.keys(params).length > 0 ? params : void 0;
|
|
1563
|
+
}
|
|
1564
|
+
function buildEntryParams(options) {
|
|
1565
|
+
if (!options) return void 0;
|
|
1566
|
+
const params = {};
|
|
1567
|
+
if (options.locale) params.locale = options.locale;
|
|
1568
|
+
if (options.version !== void 0) params.version = String(options.version);
|
|
1569
|
+
if (options.includePublishDetails) params.include_publish_details = "true";
|
|
1570
|
+
return nonEmptyParams(params);
|
|
1571
|
+
}
|
|
1572
|
+
function buildEntriesParams(options) {
|
|
1573
|
+
if (!options) return void 0;
|
|
1574
|
+
const params = {};
|
|
1575
|
+
if (options.locale) params.locale = options.locale;
|
|
1576
|
+
if (options.limit !== void 0) params.limit = String(options.limit);
|
|
1577
|
+
if (options.skip !== void 0) params.skip = String(options.skip);
|
|
1578
|
+
if (options.includePublishDetails) params.include_publish_details = "true";
|
|
1579
|
+
if (options.query) params.query = JSON.stringify(options.query);
|
|
1580
|
+
return nonEmptyParams(params);
|
|
1581
|
+
}
|
|
1582
|
+
function buildAssetsParams(options) {
|
|
1583
|
+
if (!options) return void 0;
|
|
1584
|
+
const params = {};
|
|
1585
|
+
if (options.folder) params.folder = options.folder;
|
|
1586
|
+
if (options.limit !== void 0) params.limit = String(options.limit);
|
|
1587
|
+
if (options.skip !== void 0) params.skip = String(options.skip);
|
|
1588
|
+
return nonEmptyParams(params);
|
|
1589
|
+
}
|
|
1590
|
+
function appendQueryString(path, params) {
|
|
1591
|
+
const query = params.toString();
|
|
1592
|
+
return query ? `${path}?${query}` : path;
|
|
1593
|
+
}
|
|
1594
|
+
function buildCreateEntryRequest(vars) {
|
|
1595
|
+
const params = new URLSearchParams();
|
|
1596
|
+
if (vars.locale) params.set("locale", vars.locale);
|
|
1597
|
+
return {
|
|
1598
|
+
path: appendQueryString(`/content_types/${vars.contentTypeUid}/entries`, params),
|
|
1599
|
+
body: { entry: vars.entry }
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1602
|
+
function buildUpdateEntryRequest(vars) {
|
|
1603
|
+
const params = new URLSearchParams();
|
|
1604
|
+
if (vars.locale) params.set("locale", vars.locale);
|
|
1605
|
+
return {
|
|
1606
|
+
path: appendQueryString(
|
|
1607
|
+
`/content_types/${vars.contentTypeUid}/entries/${vars.entryUid}`,
|
|
1608
|
+
params
|
|
1609
|
+
),
|
|
1610
|
+
body: { entry: vars.entry }
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
function buildDeleteEntryRequest(vars) {
|
|
1614
|
+
const params = new URLSearchParams();
|
|
1615
|
+
if (vars.locale) params.set("locale", vars.locale);
|
|
1616
|
+
if (vars.deleteAllLocalized) params.set("delete_all_localized", "true");
|
|
1617
|
+
return {
|
|
1618
|
+
path: appendQueryString(
|
|
1619
|
+
`/content_types/${vars.contentTypeUid}/entries/${vars.entryUid}`,
|
|
1620
|
+
params
|
|
1621
|
+
)
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1624
|
+
function buildPublishEntryRequest(vars) {
|
|
1625
|
+
return {
|
|
1626
|
+
path: `/content_types/${vars.contentTypeUid}/entries/${vars.entryUid}/publish`,
|
|
1627
|
+
body: {
|
|
1628
|
+
entry: {
|
|
1629
|
+
environments: vars.environments,
|
|
1630
|
+
locales: vars.locales,
|
|
1631
|
+
...vars.scheduledAt ? { scheduled_at: vars.scheduledAt } : {}
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
};
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
// src/images/builder.ts
|
|
1638
|
+
var VALID_FORMATS = /* @__PURE__ */ new Set(["webp", "jpg", "png", "gif", "avif", "pjpg"]);
|
|
1639
|
+
var VALID_FITS = /* @__PURE__ */ new Set(["bounds", "crop", "cover"]);
|
|
1640
|
+
var VALID_FILTERS = /* @__PURE__ */ new Set([
|
|
1641
|
+
"nearest",
|
|
1642
|
+
"bilinear",
|
|
1643
|
+
"bicubic",
|
|
1644
|
+
"lanczos2",
|
|
1645
|
+
"lanczos3"
|
|
1646
|
+
]);
|
|
1647
|
+
var ImageTransformBuilderImpl = class _ImageTransformBuilderImpl {
|
|
1648
|
+
constructor(assetUrl, params = {}) {
|
|
1649
|
+
this.assetUrl = assetUrl;
|
|
1650
|
+
this.params = params;
|
|
1651
|
+
}
|
|
1652
|
+
width(px) {
|
|
1653
|
+
assertPositiveInteger("width", px);
|
|
1654
|
+
return this.with("width", String(px));
|
|
1655
|
+
}
|
|
1656
|
+
height(px) {
|
|
1657
|
+
assertPositiveInteger("height", px);
|
|
1658
|
+
return this.with("height", String(px));
|
|
1659
|
+
}
|
|
1660
|
+
quality(q) {
|
|
1661
|
+
if (!Number.isInteger(q) || q < 1 || q > 100) {
|
|
1662
|
+
throw new ContentstackConfigError("quality() expects an integer between 1 and 100");
|
|
1663
|
+
}
|
|
1664
|
+
return this.with("quality", String(q));
|
|
1665
|
+
}
|
|
1666
|
+
format(fmt) {
|
|
1667
|
+
if (!VALID_FORMATS.has(fmt)) {
|
|
1668
|
+
throw new ContentstackConfigError(`Unsupported image format: ${fmt}`);
|
|
1669
|
+
}
|
|
1670
|
+
return this.with("format", fmt);
|
|
1671
|
+
}
|
|
1672
|
+
fit(mode) {
|
|
1673
|
+
if (!VALID_FITS.has(mode)) {
|
|
1674
|
+
throw new ContentstackConfigError(`Unsupported fit mode: ${mode}`);
|
|
1675
|
+
}
|
|
1676
|
+
return this.with("fit", mode);
|
|
1677
|
+
}
|
|
1678
|
+
crop(params) {
|
|
1679
|
+
return this.withNonEmptyString("crop", params);
|
|
1680
|
+
}
|
|
1681
|
+
trim(edges) {
|
|
1682
|
+
return this.withNonEmptyString("trim", edges);
|
|
1683
|
+
}
|
|
1684
|
+
orient(angle) {
|
|
1685
|
+
if (!Number.isInteger(angle) || angle < 1 || angle > 8) {
|
|
1686
|
+
throw new ContentstackConfigError("orient() expects a value between 1 and 8");
|
|
1687
|
+
}
|
|
1688
|
+
return this.with("orient", String(angle));
|
|
1689
|
+
}
|
|
1690
|
+
overlay(params) {
|
|
1691
|
+
const entries = Object.entries(params).filter(([, value2]) => value2.trim().length > 0).sort(([a], [b]) => a.localeCompare(b));
|
|
1692
|
+
if (entries.length === 0) {
|
|
1693
|
+
throw new ContentstackConfigError("overlay() requires at least one non-empty key/value pair");
|
|
1694
|
+
}
|
|
1695
|
+
const value = entries.map(([key, val]) => `${key}:${val}`).join(",");
|
|
1696
|
+
return this.with("overlay", value);
|
|
1697
|
+
}
|
|
1698
|
+
pad(pixels) {
|
|
1699
|
+
return this.withNonEmptyString("pad", pixels);
|
|
1700
|
+
}
|
|
1701
|
+
bgColor(hex) {
|
|
1702
|
+
const normalized = hex.trim().replace(/^#/, "");
|
|
1703
|
+
if (!/^[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/.test(normalized)) {
|
|
1704
|
+
throw new ContentstackConfigError("bgColor() expects a 3 or 6 character hex value");
|
|
1705
|
+
}
|
|
1706
|
+
return this.with("bg-color", normalized.toLowerCase());
|
|
1707
|
+
}
|
|
1708
|
+
dpr(ratio) {
|
|
1709
|
+
if (!Number.isFinite(ratio) || ratio <= 0) {
|
|
1710
|
+
throw new ContentstackConfigError("dpr() expects a positive number");
|
|
1711
|
+
}
|
|
1712
|
+
return this.with("dpr", String(ratio));
|
|
1713
|
+
}
|
|
1714
|
+
disableUpscale() {
|
|
1715
|
+
return this.with("disable", "upscale");
|
|
1716
|
+
}
|
|
1717
|
+
resizeFilter(filter) {
|
|
1718
|
+
if (!VALID_FILTERS.has(filter)) {
|
|
1719
|
+
throw new ContentstackConfigError(`Unsupported resize filter: ${filter}`);
|
|
1720
|
+
}
|
|
1721
|
+
return this.with("resize-filter", filter);
|
|
1722
|
+
}
|
|
1723
|
+
toURL() {
|
|
1724
|
+
if (Object.keys(this.params).length === 0) {
|
|
1725
|
+
return this.assetUrl;
|
|
1726
|
+
}
|
|
1727
|
+
const query = new URLSearchParams(this.params);
|
|
1728
|
+
try {
|
|
1729
|
+
const url = new URL(this.assetUrl);
|
|
1730
|
+
for (const [key, value] of query.entries()) {
|
|
1731
|
+
url.searchParams.set(key, value);
|
|
1732
|
+
}
|
|
1733
|
+
return url.toString();
|
|
1734
|
+
} catch {
|
|
1735
|
+
const separator = this.assetUrl.includes("?") ? "&" : "?";
|
|
1736
|
+
return `${this.assetUrl}${separator}${query.toString()}`;
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
toSrcSet(widths) {
|
|
1740
|
+
return widths.map((width) => {
|
|
1741
|
+
assertPositiveInteger("toSrcSet width", width);
|
|
1742
|
+
return `${this.width(width).toURL()} ${width}w`;
|
|
1743
|
+
}).join(", ");
|
|
1744
|
+
}
|
|
1745
|
+
toParams() {
|
|
1746
|
+
return { ...this.params };
|
|
1747
|
+
}
|
|
1748
|
+
with(key, value) {
|
|
1749
|
+
return new _ImageTransformBuilderImpl(this.assetUrl, {
|
|
1750
|
+
...this.params,
|
|
1751
|
+
[key]: value
|
|
1752
|
+
});
|
|
1753
|
+
}
|
|
1754
|
+
withNonEmptyString(key, value) {
|
|
1755
|
+
if (!value.trim()) {
|
|
1756
|
+
throw new ContentstackConfigError(`${key}() requires a non-empty string value`);
|
|
1757
|
+
}
|
|
1758
|
+
return this.with(key, value);
|
|
1759
|
+
}
|
|
1760
|
+
};
|
|
1761
|
+
function imageTransform(assetUrl) {
|
|
1762
|
+
if (!assetUrl.trim()) {
|
|
1763
|
+
throw new ContentstackConfigError("imageTransform() requires a non-empty asset URL");
|
|
1764
|
+
}
|
|
1765
|
+
return new ImageTransformBuilderImpl(assetUrl);
|
|
1766
|
+
}
|
|
1767
|
+
function assertPositiveInteger(name, value) {
|
|
1768
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
1769
|
+
throw new ContentstackConfigError(`${name} expects a positive integer`);
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
// src/rte/to-html.ts
|
|
1774
|
+
var import_json_rte_serializer = require("@contentstack/json-rte-serializer");
|
|
1775
|
+
|
|
1776
|
+
// src/rte/utils.ts
|
|
1777
|
+
var KNOWN_RTE_TYPES = /* @__PURE__ */ new Set([
|
|
1778
|
+
"doc",
|
|
1779
|
+
"p",
|
|
1780
|
+
"h1",
|
|
1781
|
+
"h2",
|
|
1782
|
+
"h3",
|
|
1783
|
+
"h4",
|
|
1784
|
+
"h5",
|
|
1785
|
+
"h6",
|
|
1786
|
+
"ul",
|
|
1787
|
+
"ol",
|
|
1788
|
+
"li",
|
|
1789
|
+
"blockquote",
|
|
1790
|
+
"code",
|
|
1791
|
+
"img",
|
|
1792
|
+
"a",
|
|
1793
|
+
"table",
|
|
1794
|
+
"tr",
|
|
1795
|
+
"td",
|
|
1796
|
+
"th",
|
|
1797
|
+
"hr",
|
|
1798
|
+
"reference"
|
|
1799
|
+
]);
|
|
1800
|
+
function isRecord(value) {
|
|
1801
|
+
return typeof value === "object" && value !== null;
|
|
1802
|
+
}
|
|
1803
|
+
function isTextNode(value) {
|
|
1804
|
+
return isRecord(value) && typeof value.text === "string" && typeof value.type !== "string";
|
|
1805
|
+
}
|
|
1806
|
+
function isElementNode(value) {
|
|
1807
|
+
return isRecord(value) && typeof value.type === "string" && typeof value.uid === "string";
|
|
1808
|
+
}
|
|
1809
|
+
function decodeHTML(value) {
|
|
1810
|
+
return value.replace(/ /g, " ").replace(/"/g, '"').replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
1811
|
+
}
|
|
1812
|
+
function createUid() {
|
|
1813
|
+
const uuid = globalThis.crypto?.randomUUID;
|
|
1814
|
+
if (typeof uuid === "function") {
|
|
1815
|
+
return uuid.call(globalThis.crypto);
|
|
1816
|
+
}
|
|
1817
|
+
return `rte-${Math.random().toString(36).slice(2, 10)}`;
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
// src/rte/serializer.ts
|
|
1821
|
+
var DEFAULT_TABLE_COLUMN_WIDTH = 250;
|
|
1822
|
+
function normalizeForSerializer(doc) {
|
|
1823
|
+
const normalized = normalizeNode(doc);
|
|
1824
|
+
if (!isTextNode(normalized) && normalized.type === "doc") {
|
|
1825
|
+
return normalized;
|
|
1826
|
+
}
|
|
1827
|
+
return {
|
|
1828
|
+
...doc,
|
|
1829
|
+
children: []
|
|
1830
|
+
};
|
|
1831
|
+
}
|
|
1832
|
+
function normalizeNode(node) {
|
|
1833
|
+
if (isTextNode(node)) {
|
|
1834
|
+
return { ...node };
|
|
1835
|
+
}
|
|
1836
|
+
const children = node.children?.map((child) => normalizeNode(child));
|
|
1837
|
+
const attrs = isRecord(node.attrs) ? { ...node.attrs } : {};
|
|
1838
|
+
if (node.type === "a" && typeof attrs.url !== "string" && typeof attrs.href === "string") {
|
|
1839
|
+
attrs.url = attrs.href;
|
|
1840
|
+
}
|
|
1841
|
+
if (node.type === "img" && typeof attrs.url !== "string" && typeof attrs.src === "string") {
|
|
1842
|
+
attrs.url = attrs.src;
|
|
1843
|
+
}
|
|
1844
|
+
if (node.type === "table") {
|
|
1845
|
+
const tableRows = (children ?? []).filter(
|
|
1846
|
+
(row) => !isTextNode(row) && row.type === "tr"
|
|
1847
|
+
);
|
|
1848
|
+
const inferredCols = tableRows.reduce((max, row) => {
|
|
1849
|
+
const columnCount = (row.children ?? []).filter(
|
|
1850
|
+
(cell) => !isTextNode(cell) && (cell.type === "td" || cell.type === "th")
|
|
1851
|
+
).length;
|
|
1852
|
+
return Math.max(max, columnCount);
|
|
1853
|
+
}, 0);
|
|
1854
|
+
const normalizedCols = typeof attrs.cols === "number" && attrs.cols > 0 ? attrs.cols : inferredCols;
|
|
1855
|
+
const normalizedRows = typeof attrs.rows === "number" && attrs.rows > 0 ? attrs.rows : tableRows.length;
|
|
1856
|
+
const normalizedWidths = Array.isArray(attrs.colWidths) && attrs.colWidths.length > 0 && attrs.colWidths.every((width) => typeof width === "number") ? attrs.colWidths : Array.from({ length: Math.max(normalizedCols, 1) }, () => DEFAULT_TABLE_COLUMN_WIDTH);
|
|
1857
|
+
return {
|
|
1858
|
+
...node,
|
|
1859
|
+
attrs: {
|
|
1860
|
+
...attrs,
|
|
1861
|
+
rows: normalizedRows,
|
|
1862
|
+
cols: Math.max(normalizedCols, 1),
|
|
1863
|
+
colWidths: normalizedWidths
|
|
1864
|
+
},
|
|
1865
|
+
...children ? { children } : {}
|
|
1866
|
+
};
|
|
1867
|
+
}
|
|
1868
|
+
return {
|
|
1869
|
+
...node,
|
|
1870
|
+
attrs,
|
|
1871
|
+
...children ? { children } : {}
|
|
1872
|
+
};
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
// src/rte/to-html.ts
|
|
1876
|
+
function toHTML(doc, options = {}) {
|
|
1877
|
+
return (0, import_json_rte_serializer.jsonToHtml)(
|
|
1878
|
+
normalizeForSerializer(doc),
|
|
1879
|
+
buildSerializerOptions(options)
|
|
1880
|
+
);
|
|
1881
|
+
}
|
|
1882
|
+
function buildSerializerOptions(options) {
|
|
1883
|
+
const { renderEntry, renderAsset, serializerOptions } = options;
|
|
1884
|
+
if (!renderEntry && !renderAsset) {
|
|
1885
|
+
return serializerOptions;
|
|
1886
|
+
}
|
|
1887
|
+
const customElementTypes = {
|
|
1888
|
+
...serializerOptions?.customElementTypes ?? {}
|
|
1889
|
+
};
|
|
1890
|
+
const existingReferenceRenderer = customElementTypes.reference;
|
|
1891
|
+
customElementTypes.reference = (attrs, child, jsonBlock, extraProps) => {
|
|
1892
|
+
const block = asRTENode(jsonBlock);
|
|
1893
|
+
const referenceAttrs = isRecord(block.attrs) ? block.attrs : {};
|
|
1894
|
+
if (referenceAttrs.type === "entry" && renderEntry) {
|
|
1895
|
+
return renderEntry(referenceAttrs, block);
|
|
1896
|
+
}
|
|
1897
|
+
if (referenceAttrs.type === "asset" && renderAsset) {
|
|
1898
|
+
return renderAsset(referenceAttrs, block);
|
|
1899
|
+
}
|
|
1900
|
+
return typeof existingReferenceRenderer === "function" ? existingReferenceRenderer(attrs, child, jsonBlock, extraProps) : "";
|
|
1901
|
+
};
|
|
1902
|
+
return {
|
|
1903
|
+
...serializerOptions,
|
|
1904
|
+
customElementTypes
|
|
1905
|
+
};
|
|
1906
|
+
}
|
|
1907
|
+
function asRTENode(value) {
|
|
1908
|
+
if (isRecord(value) && typeof value.type === "string" && typeof value.uid === "string") {
|
|
1909
|
+
return value;
|
|
1910
|
+
}
|
|
1911
|
+
return {
|
|
1912
|
+
type: "reference",
|
|
1913
|
+
uid: "reference"
|
|
1914
|
+
};
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
// src/rte/to-markdown.ts
|
|
1918
|
+
var import_json_rte_serializer2 = require("@contentstack/json-rte-serializer");
|
|
1919
|
+
function toMarkdown(doc, options = {}) {
|
|
1920
|
+
const mappedDoc = options.renderEntry || options.renderAsset ? mapReferenceNodes(doc, options) : doc;
|
|
1921
|
+
const markdown = (0, import_json_rte_serializer2.jsonToMarkdown)(normalizeForSerializer(mappedDoc)).trim();
|
|
1922
|
+
return normalizeMarkdownOutput(markdown);
|
|
1923
|
+
}
|
|
1924
|
+
function mapReferenceNodes(doc, options) {
|
|
1925
|
+
const mapped = mapNode(doc, options);
|
|
1926
|
+
if (isTextNode(mapped)) {
|
|
1927
|
+
return {
|
|
1928
|
+
...doc,
|
|
1929
|
+
children: []
|
|
1930
|
+
};
|
|
1931
|
+
}
|
|
1932
|
+
return {
|
|
1933
|
+
...doc,
|
|
1934
|
+
...mapped,
|
|
1935
|
+
type: "doc",
|
|
1936
|
+
uid: mapped.uid ?? doc.uid
|
|
1937
|
+
};
|
|
1938
|
+
}
|
|
1939
|
+
function mapNode(node, options) {
|
|
1940
|
+
if (isTextNode(node)) {
|
|
1941
|
+
return { ...node };
|
|
1942
|
+
}
|
|
1943
|
+
if (node.type === "reference") {
|
|
1944
|
+
const attrs = node.attrs ?? {};
|
|
1945
|
+
if (attrs.type === "entry" && options.renderEntry) {
|
|
1946
|
+
return { text: options.renderEntry(attrs, node) };
|
|
1947
|
+
}
|
|
1948
|
+
if (attrs.type === "asset" && options.renderAsset) {
|
|
1949
|
+
return { text: options.renderAsset(attrs, node) };
|
|
1950
|
+
}
|
|
1951
|
+
return { text: "" };
|
|
1952
|
+
}
|
|
1953
|
+
return {
|
|
1954
|
+
...node,
|
|
1955
|
+
...node.children ? { children: node.children.map((child) => mapNode(child, options)) } : {}
|
|
1956
|
+
};
|
|
1957
|
+
}
|
|
1958
|
+
function normalizeMarkdownOutput(markdown) {
|
|
1959
|
+
return markdown.replace(/!\[([^\]]*)\]\s*\n\s*\(([^)\n]+)\)/g, "");
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
// src/rte/to-plaintext.ts
|
|
1963
|
+
var DOUBLE_BREAK_TYPES = /* @__PURE__ */ new Set([
|
|
1964
|
+
"p",
|
|
1965
|
+
"h1",
|
|
1966
|
+
"h2",
|
|
1967
|
+
"h3",
|
|
1968
|
+
"h4",
|
|
1969
|
+
"h5",
|
|
1970
|
+
"h6",
|
|
1971
|
+
"blockquote",
|
|
1972
|
+
"code",
|
|
1973
|
+
"ul",
|
|
1974
|
+
"ol",
|
|
1975
|
+
"table"
|
|
1976
|
+
]);
|
|
1977
|
+
var SINGLE_BREAK_TYPES = /* @__PURE__ */ new Set(["li", "tr", "td", "th"]);
|
|
1978
|
+
function toPlainText(doc) {
|
|
1979
|
+
return renderNode(doc).replace(/\n{3,}/g, "\n\n").trim();
|
|
1980
|
+
}
|
|
1981
|
+
function renderNode(node) {
|
|
1982
|
+
if (isTextNode(node)) {
|
|
1983
|
+
return node.text;
|
|
1984
|
+
}
|
|
1985
|
+
const children = (node.children ?? []).map((child) => renderNode(child)).join("");
|
|
1986
|
+
if (node.type === "doc") {
|
|
1987
|
+
return children;
|
|
1988
|
+
}
|
|
1989
|
+
if (node.type === "img") {
|
|
1990
|
+
const alt = node.attrs?.alt;
|
|
1991
|
+
if (typeof alt === "string" && alt.trim()) {
|
|
1992
|
+
return `${alt}
|
|
1993
|
+
|
|
1994
|
+
`;
|
|
1995
|
+
}
|
|
1996
|
+
return "\n";
|
|
1997
|
+
}
|
|
1998
|
+
if (node.type === "a") {
|
|
1999
|
+
const href = node.attrs?.href;
|
|
2000
|
+
const text = children || (typeof href === "string" ? href : "");
|
|
2001
|
+
return text;
|
|
2002
|
+
}
|
|
2003
|
+
if (node.type === "hr") {
|
|
2004
|
+
return "\n";
|
|
2005
|
+
}
|
|
2006
|
+
if (node.type === "reference") {
|
|
2007
|
+
return "";
|
|
2008
|
+
}
|
|
2009
|
+
if (DOUBLE_BREAK_TYPES.has(node.type)) {
|
|
2010
|
+
return `${children}
|
|
2011
|
+
|
|
2012
|
+
`;
|
|
2013
|
+
}
|
|
2014
|
+
if (SINGLE_BREAK_TYPES.has(node.type)) {
|
|
2015
|
+
return `${children}
|
|
2016
|
+
`;
|
|
2017
|
+
}
|
|
2018
|
+
return children;
|
|
2019
|
+
}
|
|
2020
|
+
|
|
2021
|
+
// src/rte/from-html.ts
|
|
2022
|
+
var import_json_rte_serializer3 = require("@contentstack/json-rte-serializer");
|
|
2023
|
+
var VOID_TAGS = /* @__PURE__ */ new Set(["img", "hr", "br", "meta", "link", "input"]);
|
|
2024
|
+
function fromHTML(html, options = {}) {
|
|
2025
|
+
const parsed = parseWithSerializer(html, options);
|
|
2026
|
+
if (parsed) {
|
|
2027
|
+
return parsed;
|
|
2028
|
+
}
|
|
2029
|
+
return parseWithFallback(html);
|
|
2030
|
+
}
|
|
2031
|
+
function parseWithSerializer(html, options) {
|
|
2032
|
+
try {
|
|
2033
|
+
const parsed = (0, import_json_rte_serializer3.htmlToJson)(html, options.serializerOptions);
|
|
2034
|
+
return normalizeDoc(parsed);
|
|
2035
|
+
} catch {
|
|
2036
|
+
return null;
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
function normalizeDoc(value) {
|
|
2040
|
+
if (isRecord(value) && value.type === "doc" && Array.isArray(value.children)) {
|
|
2041
|
+
return {
|
|
2042
|
+
...value,
|
|
2043
|
+
type: "doc",
|
|
2044
|
+
uid: typeof value.uid === "string" && value.uid.length > 0 ? value.uid : createUid(),
|
|
2045
|
+
children: value.children
|
|
2046
|
+
};
|
|
2047
|
+
}
|
|
2048
|
+
return null;
|
|
2049
|
+
}
|
|
2050
|
+
function parseWithFallback(html) {
|
|
2051
|
+
const root = parseHTML(html);
|
|
2052
|
+
const children = convertNodes(root.children);
|
|
2053
|
+
return {
|
|
2054
|
+
type: "doc",
|
|
2055
|
+
uid: createUid(),
|
|
2056
|
+
children
|
|
2057
|
+
};
|
|
2058
|
+
}
|
|
2059
|
+
function parseHTML(html) {
|
|
2060
|
+
const root = {
|
|
2061
|
+
kind: "element",
|
|
2062
|
+
tag: "root",
|
|
2063
|
+
attrs: {},
|
|
2064
|
+
children: []
|
|
2065
|
+
};
|
|
2066
|
+
const stack = [root];
|
|
2067
|
+
const tokenPattern = /<!--[\s\S]*?-->|<\/?[^>]+>|[^<]+/g;
|
|
2068
|
+
const tokens = html.match(tokenPattern) ?? [];
|
|
2069
|
+
for (const token of tokens) {
|
|
2070
|
+
if (!token) {
|
|
2071
|
+
continue;
|
|
2072
|
+
}
|
|
2073
|
+
if (token.startsWith("<!--")) {
|
|
2074
|
+
continue;
|
|
2075
|
+
}
|
|
2076
|
+
if (!token.startsWith("<")) {
|
|
2077
|
+
const text = decodeHTML(token);
|
|
2078
|
+
if (text.length === 0) {
|
|
2079
|
+
continue;
|
|
2080
|
+
}
|
|
2081
|
+
const parent2 = stack[stack.length - 1];
|
|
2082
|
+
if (!parent2) {
|
|
2083
|
+
continue;
|
|
2084
|
+
}
|
|
2085
|
+
parent2.children.push({
|
|
2086
|
+
kind: "text",
|
|
2087
|
+
value: text
|
|
2088
|
+
});
|
|
2089
|
+
continue;
|
|
2090
|
+
}
|
|
2091
|
+
if (token.startsWith("</")) {
|
|
2092
|
+
const closingTag = token.slice(2, -1).trim().toLowerCase();
|
|
2093
|
+
while (stack.length > 1) {
|
|
2094
|
+
const current = stack.pop();
|
|
2095
|
+
if (current?.tag === closingTag) {
|
|
2096
|
+
break;
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
continue;
|
|
2100
|
+
}
|
|
2101
|
+
const parsed = parseOpeningTag(token);
|
|
2102
|
+
if (!parsed) {
|
|
2103
|
+
continue;
|
|
2104
|
+
}
|
|
2105
|
+
const parent = stack[stack.length - 1];
|
|
2106
|
+
if (!parent) {
|
|
2107
|
+
continue;
|
|
2108
|
+
}
|
|
2109
|
+
parent.children.push(parsed.element);
|
|
2110
|
+
const isVoid = parsed.selfClosing || VOID_TAGS.has(parsed.element.tag);
|
|
2111
|
+
if (!isVoid) {
|
|
2112
|
+
stack.push(parsed.element);
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
return root;
|
|
2116
|
+
}
|
|
2117
|
+
function parseOpeningTag(token) {
|
|
2118
|
+
const isSelfClosing = token.endsWith("/>");
|
|
2119
|
+
const content = token.slice(1, token.length - (isSelfClosing ? 2 : 1)).trim();
|
|
2120
|
+
if (!content) {
|
|
2121
|
+
return null;
|
|
2122
|
+
}
|
|
2123
|
+
const tagMatch = content.match(/^([a-zA-Z0-9-]+)/);
|
|
2124
|
+
if (!tagMatch?.[1]) {
|
|
2125
|
+
return null;
|
|
2126
|
+
}
|
|
2127
|
+
const tag = tagMatch[1].toLowerCase();
|
|
2128
|
+
const attrs = parseAttributes(content.slice(tag.length).trim());
|
|
2129
|
+
return {
|
|
2130
|
+
element: {
|
|
2131
|
+
kind: "element",
|
|
2132
|
+
tag,
|
|
2133
|
+
attrs,
|
|
2134
|
+
children: []
|
|
2135
|
+
},
|
|
2136
|
+
selfClosing: isSelfClosing
|
|
2137
|
+
};
|
|
2138
|
+
}
|
|
2139
|
+
function parseAttributes(input) {
|
|
2140
|
+
const attrs = {};
|
|
2141
|
+
const attrPattern = /([:@a-zA-Z0-9_-]+)(?:\s*=\s*("([^"]*)"|'([^']*)'|([^\s"'>/]+)))?/g;
|
|
2142
|
+
let match = attrPattern.exec(input);
|
|
2143
|
+
while (match) {
|
|
2144
|
+
const key = match[1];
|
|
2145
|
+
if (key) {
|
|
2146
|
+
const value = decodeHTML(match[3] ?? match[4] ?? match[5] ?? "");
|
|
2147
|
+
attrs[key] = value;
|
|
2148
|
+
}
|
|
2149
|
+
match = attrPattern.exec(input);
|
|
2150
|
+
}
|
|
2151
|
+
return attrs;
|
|
2152
|
+
}
|
|
2153
|
+
function convertNodes(nodes, marks = {}) {
|
|
2154
|
+
const output = [];
|
|
2155
|
+
for (const node of nodes) {
|
|
2156
|
+
if (node.kind === "text") {
|
|
2157
|
+
const cleaned = normalizeText(node.value);
|
|
2158
|
+
if (!cleaned) {
|
|
2159
|
+
continue;
|
|
2160
|
+
}
|
|
2161
|
+
output.push({
|
|
2162
|
+
text: cleaned,
|
|
2163
|
+
...marks.bold ? { bold: true } : {},
|
|
2164
|
+
...marks.italic ? { italic: true } : {},
|
|
2165
|
+
...marks.underline ? { underline: true } : {},
|
|
2166
|
+
...marks.strikethrough ? { strikethrough: true } : {},
|
|
2167
|
+
...marks.code ? { code: true } : {},
|
|
2168
|
+
...marks.superscript ? { superscript: true } : {},
|
|
2169
|
+
...marks.subscript ? { subscript: true } : {}
|
|
2170
|
+
});
|
|
2171
|
+
continue;
|
|
2172
|
+
}
|
|
2173
|
+
output.push(...convertElement(node, marks));
|
|
2174
|
+
}
|
|
2175
|
+
return output;
|
|
2176
|
+
}
|
|
2177
|
+
function convertElement(element, marks) {
|
|
2178
|
+
switch (element.tag) {
|
|
2179
|
+
case "strong":
|
|
2180
|
+
case "b":
|
|
2181
|
+
return convertNodes(element.children, { ...marks, bold: true });
|
|
2182
|
+
case "em":
|
|
2183
|
+
case "i":
|
|
2184
|
+
return convertNodes(element.children, { ...marks, italic: true });
|
|
2185
|
+
case "u":
|
|
2186
|
+
return convertNodes(element.children, { ...marks, underline: true });
|
|
2187
|
+
case "s":
|
|
2188
|
+
case "strike":
|
|
2189
|
+
case "del":
|
|
2190
|
+
return convertNodes(element.children, { ...marks, strikethrough: true });
|
|
2191
|
+
case "sup":
|
|
2192
|
+
return convertNodes(element.children, { ...marks, superscript: true });
|
|
2193
|
+
case "sub":
|
|
2194
|
+
return convertNodes(element.children, { ...marks, subscript: true });
|
|
2195
|
+
case "code":
|
|
2196
|
+
return convertNodes(element.children, { ...marks, code: true });
|
|
2197
|
+
case "br":
|
|
2198
|
+
return [{ text: "\n" }];
|
|
2199
|
+
case "img":
|
|
2200
|
+
return [
|
|
2201
|
+
{
|
|
2202
|
+
type: "img",
|
|
2203
|
+
uid: createUid(),
|
|
2204
|
+
attrs: {
|
|
2205
|
+
src: element.attrs.src ?? "",
|
|
2206
|
+
alt: element.attrs.alt ?? ""
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
];
|
|
2210
|
+
case "hr":
|
|
2211
|
+
return [
|
|
2212
|
+
{
|
|
2213
|
+
type: "hr",
|
|
2214
|
+
uid: createUid()
|
|
2215
|
+
}
|
|
2216
|
+
];
|
|
2217
|
+
case "a":
|
|
2218
|
+
return [
|
|
2219
|
+
{
|
|
2220
|
+
type: "a",
|
|
2221
|
+
uid: createUid(),
|
|
2222
|
+
attrs: {
|
|
2223
|
+
href: element.attrs.href ?? "",
|
|
2224
|
+
...element.attrs.target ? { target: element.attrs.target } : {}
|
|
2225
|
+
},
|
|
2226
|
+
children: convertNodes(element.children)
|
|
2227
|
+
}
|
|
2228
|
+
];
|
|
2229
|
+
case "reference":
|
|
2230
|
+
return [
|
|
2231
|
+
{
|
|
2232
|
+
type: "reference",
|
|
2233
|
+
uid: createUid(),
|
|
2234
|
+
attrs: {
|
|
2235
|
+
...element.attrs
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
];
|
|
2239
|
+
case "pre": {
|
|
2240
|
+
const codeText = extractTextContent(element);
|
|
2241
|
+
return [
|
|
2242
|
+
{
|
|
2243
|
+
type: "code",
|
|
2244
|
+
uid: createUid(),
|
|
2245
|
+
children: codeText ? [{ text: codeText }] : []
|
|
2246
|
+
}
|
|
2247
|
+
];
|
|
2248
|
+
}
|
|
2249
|
+
case "p":
|
|
2250
|
+
case "h1":
|
|
2251
|
+
case "h2":
|
|
2252
|
+
case "h3":
|
|
2253
|
+
case "h4":
|
|
2254
|
+
case "h5":
|
|
2255
|
+
case "h6":
|
|
2256
|
+
case "ul":
|
|
2257
|
+
case "ol":
|
|
2258
|
+
case "li":
|
|
2259
|
+
case "blockquote":
|
|
2260
|
+
case "table":
|
|
2261
|
+
case "tr":
|
|
2262
|
+
case "td":
|
|
2263
|
+
case "th":
|
|
2264
|
+
return [
|
|
2265
|
+
{
|
|
2266
|
+
type: element.tag,
|
|
2267
|
+
uid: createUid(),
|
|
2268
|
+
children: convertNodes(element.children)
|
|
2269
|
+
}
|
|
2270
|
+
];
|
|
2271
|
+
default:
|
|
2272
|
+
return convertNodes(element.children, marks);
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
function extractTextContent(node) {
|
|
2276
|
+
if (node.kind === "text") {
|
|
2277
|
+
return decodeHTML(node.value);
|
|
2278
|
+
}
|
|
2279
|
+
return node.children.map((child) => extractTextContent(child)).join("");
|
|
2280
|
+
}
|
|
2281
|
+
function normalizeText(value) {
|
|
2282
|
+
const collapsed = value.replace(/\s+/g, " ");
|
|
2283
|
+
if (collapsed.trim().length === 0) {
|
|
2284
|
+
return " ";
|
|
2285
|
+
}
|
|
2286
|
+
return collapsed;
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2289
|
+
// src/rte/transform.ts
|
|
2290
|
+
function transform(doc, visitors) {
|
|
2291
|
+
const transformed = visitNode(doc, visitors);
|
|
2292
|
+
if (!transformed || isTextNode(transformed) || transformed.type !== "doc") {
|
|
2293
|
+
return {
|
|
2294
|
+
...doc,
|
|
2295
|
+
children: []
|
|
2296
|
+
};
|
|
2297
|
+
}
|
|
2298
|
+
return transformed;
|
|
2299
|
+
}
|
|
2300
|
+
function visitNode(node, visitors) {
|
|
2301
|
+
if (isTextNode(node)) {
|
|
2302
|
+
return { ...node };
|
|
2303
|
+
}
|
|
2304
|
+
const nextChildren = (node.children ?? []).map((child) => visitNode(child, visitors)).filter((child) => Boolean(child));
|
|
2305
|
+
const withChildren = {
|
|
2306
|
+
...node,
|
|
2307
|
+
...node.children ? { children: nextChildren } : {}
|
|
2308
|
+
};
|
|
2309
|
+
const visitor = visitors[withChildren.type];
|
|
2310
|
+
if (!visitor) {
|
|
2311
|
+
return withChildren;
|
|
2312
|
+
}
|
|
2313
|
+
return visitor(withChildren);
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
// src/rte/validate.ts
|
|
2317
|
+
function validate(doc) {
|
|
2318
|
+
const errors = [];
|
|
2319
|
+
if (!isElementNode(doc)) {
|
|
2320
|
+
errors.push("Document must be an object node with type and uid");
|
|
2321
|
+
return { valid: false, errors };
|
|
2322
|
+
}
|
|
2323
|
+
if (doc.type !== "doc") {
|
|
2324
|
+
errors.push('Document root node must have type "doc"');
|
|
2325
|
+
}
|
|
2326
|
+
if (!Array.isArray(doc.children)) {
|
|
2327
|
+
errors.push('Document root node must include a "children" array');
|
|
2328
|
+
} else {
|
|
2329
|
+
validateChildren(doc.children, "doc.children", errors);
|
|
2330
|
+
}
|
|
2331
|
+
return { valid: errors.length === 0, errors };
|
|
2332
|
+
}
|
|
2333
|
+
function validateChildren(children, path, errors) {
|
|
2334
|
+
children.forEach((child, index) => {
|
|
2335
|
+
validateNode(child, `${path}[${index}]`, errors);
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
function validateNode(node, path, errors) {
|
|
2339
|
+
if (isTextNode(node)) {
|
|
2340
|
+
if (typeof node.text !== "string") {
|
|
2341
|
+
errors.push(`${path} must have a string text value`);
|
|
2342
|
+
}
|
|
2343
|
+
return;
|
|
2344
|
+
}
|
|
2345
|
+
if (!isElementNode(node)) {
|
|
2346
|
+
errors.push(`${path} must be a valid element node or text node`);
|
|
2347
|
+
return;
|
|
2348
|
+
}
|
|
2349
|
+
validateElementNode(node, path, errors);
|
|
2350
|
+
}
|
|
2351
|
+
function validateElementNode(node, path, errors) {
|
|
2352
|
+
if (!KNOWN_RTE_TYPES.has(node.type)) {
|
|
2353
|
+
errors.push(`${path}.type "${node.type}" is not a supported RTE node type`);
|
|
2354
|
+
}
|
|
2355
|
+
if (typeof node.uid !== "string" || node.uid.trim().length === 0) {
|
|
2356
|
+
errors.push(`${path}.uid must be a non-empty string`);
|
|
2357
|
+
}
|
|
2358
|
+
if (node.children !== void 0) {
|
|
2359
|
+
if (!Array.isArray(node.children)) {
|
|
2360
|
+
errors.push(`${path}.children must be an array when provided`);
|
|
2361
|
+
} else {
|
|
2362
|
+
validateChildren(node.children, `${path}.children`, errors);
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
switch (node.type) {
|
|
2366
|
+
case "img":
|
|
2367
|
+
validateImgNode(node, path, errors);
|
|
2368
|
+
break;
|
|
2369
|
+
case "a":
|
|
2370
|
+
validateAnchorNode(node, path, errors);
|
|
2371
|
+
break;
|
|
2372
|
+
case "reference":
|
|
2373
|
+
validateReferenceNode(node, path, errors);
|
|
2374
|
+
break;
|
|
2375
|
+
case "hr":
|
|
2376
|
+
if (Array.isArray(node.children) && node.children.length > 0) {
|
|
2377
|
+
errors.push(`${path}.children must be empty for hr nodes`);
|
|
2378
|
+
}
|
|
2379
|
+
break;
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
function validateImgNode(node, path, errors) {
|
|
2383
|
+
if (!isRecord(node.attrs) || typeof node.attrs.src !== "string" || node.attrs.src.length === 0) {
|
|
2384
|
+
errors.push(`${path}.attrs.src must be a non-empty string for img nodes`);
|
|
2385
|
+
}
|
|
2386
|
+
if (isRecord(node.attrs) && node.attrs.alt !== void 0 && typeof node.attrs.alt !== "string") {
|
|
2387
|
+
errors.push(`${path}.attrs.alt must be a string when provided`);
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
function validateAnchorNode(node, path, errors) {
|
|
2391
|
+
if (!isRecord(node.attrs) || typeof node.attrs.href !== "string" || node.attrs.href.length === 0) {
|
|
2392
|
+
errors.push(`${path}.attrs.href must be a non-empty string for a nodes`);
|
|
2393
|
+
}
|
|
2394
|
+
if (isRecord(node.attrs) && node.attrs.target !== void 0 && typeof node.attrs.target !== "string") {
|
|
2395
|
+
errors.push(`${path}.attrs.target must be a string when provided`);
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
function validateReferenceNode(node, path, errors) {
|
|
2399
|
+
if (!isRecord(node.attrs)) {
|
|
2400
|
+
errors.push(`${path}.attrs must be present for reference nodes`);
|
|
2401
|
+
return;
|
|
2402
|
+
}
|
|
2403
|
+
const refType = node.attrs.type;
|
|
2404
|
+
if (refType !== "entry" && refType !== "asset") {
|
|
2405
|
+
errors.push(`${path}.attrs.type must be "entry" or "asset" for reference nodes`);
|
|
2406
|
+
return;
|
|
2407
|
+
}
|
|
2408
|
+
if (refType === "entry" && typeof node.attrs["entry-uid"] !== "string") {
|
|
2409
|
+
errors.push(`${path}.attrs["entry-uid"] must be provided for entry references`);
|
|
2410
|
+
}
|
|
2411
|
+
if (refType === "asset" && typeof node.attrs["asset-uid"] !== "string") {
|
|
2412
|
+
errors.push(`${path}.attrs["asset-uid"] must be provided for asset references`);
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2416
|
+
// src/launch/response.ts
|
|
2417
|
+
function extractList(body, key) {
|
|
2418
|
+
if (Array.isArray(body)) {
|
|
2419
|
+
return { items: body };
|
|
2420
|
+
}
|
|
2421
|
+
if (body && typeof body === "object") {
|
|
2422
|
+
const obj = body;
|
|
2423
|
+
if (key in obj && Array.isArray(obj[key])) {
|
|
2424
|
+
const pagination = obj.pagination;
|
|
2425
|
+
return { items: obj[key], count: pagination?.count };
|
|
2426
|
+
}
|
|
2427
|
+
if ("data" in obj && Array.isArray(obj.data)) {
|
|
2428
|
+
return { items: obj.data, count: obj.count };
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
return { items: [] };
|
|
2432
|
+
}
|
|
2433
|
+
function extractItem(body) {
|
|
2434
|
+
if (body && typeof body === "object" && "data" in body) {
|
|
2435
|
+
return body.data;
|
|
2436
|
+
}
|
|
2437
|
+
return body;
|
|
2438
|
+
}
|
|
2439
|
+
|
|
2440
|
+
// src/launch/deployments.ts
|
|
2441
|
+
var DeploymentsClient = class {
|
|
2442
|
+
constructor(http) {
|
|
2443
|
+
this.http = http;
|
|
2444
|
+
}
|
|
2445
|
+
basePath(projectUid, environmentUid) {
|
|
2446
|
+
return `/projects/${projectUid}/environments/${environmentUid}/deployments`;
|
|
2447
|
+
}
|
|
2448
|
+
list(projectUid, environmentUid, options) {
|
|
2449
|
+
return paginate(
|
|
2450
|
+
async (skip, limit) => {
|
|
2451
|
+
const params = {
|
|
2452
|
+
skip: String(skip),
|
|
2453
|
+
limit: String(limit)
|
|
2454
|
+
};
|
|
2455
|
+
const response = await this.http.get(
|
|
2456
|
+
this.basePath(projectUid, environmentUid),
|
|
2457
|
+
params
|
|
2458
|
+
);
|
|
2459
|
+
return extractList(response.data, "deployments");
|
|
2460
|
+
},
|
|
2461
|
+
{ limit: options?.limit }
|
|
2462
|
+
);
|
|
2463
|
+
}
|
|
2464
|
+
async listAll(projectUid, environmentUid, options) {
|
|
2465
|
+
return collectAll(this.list(projectUid, environmentUid, options));
|
|
2466
|
+
}
|
|
2467
|
+
async get(projectUid, environmentUid, deploymentUid) {
|
|
2468
|
+
const response = await this.http.get(
|
|
2469
|
+
`${this.basePath(projectUid, environmentUid)}/${deploymentUid}`
|
|
2470
|
+
);
|
|
2471
|
+
return extractItem(response.data);
|
|
2472
|
+
}
|
|
2473
|
+
async create(projectUid, environmentUid, data) {
|
|
2474
|
+
const response = await this.http.post(this.basePath(projectUid, environmentUid), data);
|
|
2475
|
+
return extractItem(response.data);
|
|
2476
|
+
}
|
|
2477
|
+
async getDeploymentLogs(projectUid, environmentUid, deploymentUid, options) {
|
|
2478
|
+
const params = {};
|
|
2479
|
+
if (options?.timestamp) params.timestamp = options.timestamp;
|
|
2480
|
+
const response = await this.http.get(
|
|
2481
|
+
`${this.basePath(projectUid, environmentUid)}/${deploymentUid}/logs/deployment-logs`,
|
|
2482
|
+
Object.keys(params).length > 0 ? params : void 0
|
|
2483
|
+
);
|
|
2484
|
+
return extractList(response.data, "logs").items;
|
|
2485
|
+
}
|
|
2486
|
+
async getServerLogs(projectUid, environmentUid, deploymentUid, options) {
|
|
2487
|
+
const params = {};
|
|
2488
|
+
if (options?.startTime !== void 0) params.startTime = String(options.startTime);
|
|
2489
|
+
if (options?.endTime !== void 0) params.endTime = String(options.endTime);
|
|
2490
|
+
const response = await this.http.get(
|
|
2491
|
+
`${this.basePath(projectUid, environmentUid)}/${deploymentUid}/logs/server-logs`,
|
|
2492
|
+
Object.keys(params).length > 0 ? params : void 0
|
|
2493
|
+
);
|
|
2494
|
+
return extractList(response.data, "logs").items;
|
|
2495
|
+
}
|
|
2496
|
+
async getUploadUrl(projectUid, environmentUid) {
|
|
2497
|
+
const response = await this.http.get(
|
|
2498
|
+
`${this.basePath(projectUid, environmentUid)}/upload/signed_url`
|
|
2499
|
+
);
|
|
2500
|
+
return extractItem(response.data);
|
|
2501
|
+
}
|
|
2502
|
+
async getDownloadUrl(projectUid, environmentUid, deploymentUid) {
|
|
2503
|
+
const response = await this.http.get(
|
|
2504
|
+
`${this.basePath(projectUid, environmentUid)}/${deploymentUid}/download/signed_url`
|
|
2505
|
+
);
|
|
2506
|
+
const item = extractItem(response.data);
|
|
2507
|
+
return item.downloadUrl;
|
|
2508
|
+
}
|
|
2509
|
+
};
|
|
2510
|
+
|
|
2511
|
+
// src/launch/environments.ts
|
|
2512
|
+
var EnvironmentsClient2 = class {
|
|
2513
|
+
constructor(http) {
|
|
2514
|
+
this.http = http;
|
|
2515
|
+
}
|
|
2516
|
+
list(projectUid) {
|
|
2517
|
+
return paginate(async (skip, limit) => {
|
|
2518
|
+
const response = await this.http.get(`/projects/${projectUid}/environments`, {
|
|
2519
|
+
skip: String(skip),
|
|
2520
|
+
limit: String(limit)
|
|
2521
|
+
});
|
|
2522
|
+
return extractList(response.data, "environments");
|
|
2523
|
+
});
|
|
2524
|
+
}
|
|
2525
|
+
async listAll(projectUid) {
|
|
2526
|
+
return collectAll(this.list(projectUid));
|
|
2527
|
+
}
|
|
2528
|
+
async get(projectUid, envUid) {
|
|
2529
|
+
const response = await this.http.get(`/projects/${projectUid}/environments/${envUid}`);
|
|
2530
|
+
return extractItem(response.data);
|
|
2531
|
+
}
|
|
2532
|
+
async create(projectUid, data) {
|
|
2533
|
+
const response = await this.http.post(`/projects/${projectUid}/environments`, data);
|
|
2534
|
+
return extractItem(response.data);
|
|
2535
|
+
}
|
|
2536
|
+
async update(projectUid, envUid, data) {
|
|
2537
|
+
const response = await this.http.put(
|
|
2538
|
+
`/projects/${projectUid}/environments/${envUid}`,
|
|
2539
|
+
data
|
|
2540
|
+
);
|
|
2541
|
+
return extractItem(response.data);
|
|
2542
|
+
}
|
|
2543
|
+
async delete(projectUid, envUid) {
|
|
2544
|
+
await this.http.delete(`/projects/${projectUid}/environments/${envUid}`);
|
|
2545
|
+
}
|
|
2546
|
+
async revalidateCDNCache(projectUid, envUid, data) {
|
|
2547
|
+
await this.http.post(
|
|
2548
|
+
`/projects/${projectUid}/environments/${envUid}/revalidate-cdn-cache`,
|
|
2549
|
+
data
|
|
2550
|
+
);
|
|
2551
|
+
}
|
|
2552
|
+
async getUploadUrl(projectUid) {
|
|
2553
|
+
const response = await this.http.get(
|
|
2554
|
+
`/projects/${projectUid}/environments/upload/signed_url`
|
|
2555
|
+
);
|
|
2556
|
+
return extractItem(response.data);
|
|
2557
|
+
}
|
|
2558
|
+
};
|
|
2559
|
+
|
|
2560
|
+
// src/launch/projects.ts
|
|
2561
|
+
var ProjectsClient = class {
|
|
2562
|
+
constructor(http) {
|
|
2563
|
+
this.http = http;
|
|
2564
|
+
}
|
|
2565
|
+
list(options) {
|
|
2566
|
+
return paginate(
|
|
2567
|
+
async (skip, limit) => {
|
|
2568
|
+
const response = await this.http.get("/projects", {
|
|
2569
|
+
skip: String(skip),
|
|
2570
|
+
limit: String(limit)
|
|
2571
|
+
});
|
|
2572
|
+
return extractList(response.data, "projects");
|
|
2573
|
+
},
|
|
2574
|
+
{ limit: options?.limit }
|
|
2575
|
+
);
|
|
2576
|
+
}
|
|
2577
|
+
async listAll(options) {
|
|
2578
|
+
return collectAll(this.list(options));
|
|
2579
|
+
}
|
|
2580
|
+
async get(projectUid) {
|
|
2581
|
+
const response = await this.http.get(`/projects/${projectUid}`);
|
|
2582
|
+
return extractItem(response.data);
|
|
2583
|
+
}
|
|
2584
|
+
async create(data) {
|
|
2585
|
+
const response = await this.http.post("/projects", data);
|
|
2586
|
+
return extractItem(response.data);
|
|
2587
|
+
}
|
|
2588
|
+
async update(projectUid, data) {
|
|
2589
|
+
const response = await this.http.put(`/projects/${projectUid}`, data);
|
|
2590
|
+
return extractItem(response.data);
|
|
2591
|
+
}
|
|
2592
|
+
async delete(projectUid) {
|
|
2593
|
+
await this.http.delete(`/projects/${projectUid}`);
|
|
2594
|
+
}
|
|
2595
|
+
async transferGitRepository(projectUid, data) {
|
|
2596
|
+
await this.http.patch(`/projects/${projectUid}/git-repository`, data);
|
|
2597
|
+
}
|
|
2598
|
+
async getUploadUrl() {
|
|
2599
|
+
const response = await this.http.get("/projects/upload/signed_url");
|
|
2600
|
+
return extractItem(response.data);
|
|
2601
|
+
}
|
|
2602
|
+
};
|
|
2603
|
+
|
|
2604
|
+
// src/launch/client.ts
|
|
2605
|
+
function createLaunchClient(config) {
|
|
2606
|
+
const endpoints = resolveEndpoints(config.region);
|
|
2607
|
+
const headers = {
|
|
2608
|
+
organization_uid: config.organizationUid
|
|
2609
|
+
};
|
|
2610
|
+
switch (config.auth.type) {
|
|
2611
|
+
case "oauth":
|
|
2612
|
+
headers.authorization = `Bearer ${config.auth.accessToken}`;
|
|
2613
|
+
break;
|
|
2614
|
+
case "authtoken":
|
|
2615
|
+
headers.authtoken = config.auth.token;
|
|
2616
|
+
break;
|
|
2617
|
+
}
|
|
2618
|
+
const http = new ContentstackHttpClient({
|
|
2619
|
+
...config.httpOptions,
|
|
2620
|
+
baseUrl: config.httpOptions?.baseUrl ?? endpoints.launch,
|
|
2621
|
+
headers: {
|
|
2622
|
+
...config.httpOptions?.headers,
|
|
2623
|
+
...headers
|
|
2624
|
+
}
|
|
2625
|
+
});
|
|
2626
|
+
return {
|
|
2627
|
+
projects: new ProjectsClient(http),
|
|
2628
|
+
environments: new EnvironmentsClient2(http),
|
|
2629
|
+
deployments: new DeploymentsClient(http)
|
|
2630
|
+
};
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2633
|
+
// src/brandkit/brand-kits.ts
|
|
2634
|
+
var BrandKitsSubClient = class {
|
|
2635
|
+
constructor(http) {
|
|
2636
|
+
this.http = http;
|
|
2637
|
+
}
|
|
2638
|
+
list(options) {
|
|
2639
|
+
return paginate(
|
|
2640
|
+
async (skip, limit) => {
|
|
2641
|
+
const response = await this.http.get(
|
|
2642
|
+
"/v1/brand-kits",
|
|
2643
|
+
{
|
|
2644
|
+
skip: String(skip),
|
|
2645
|
+
limit: String(limit)
|
|
2646
|
+
}
|
|
2647
|
+
);
|
|
2648
|
+
return { items: response.data.data ?? [], count: response.data.count };
|
|
2649
|
+
},
|
|
2650
|
+
{ limit: options?.limit }
|
|
2651
|
+
);
|
|
2652
|
+
}
|
|
2653
|
+
async listAll(options) {
|
|
2654
|
+
return collectAll(this.list(options));
|
|
2655
|
+
}
|
|
2656
|
+
async get(brandKitUid) {
|
|
2657
|
+
const response = await this.http.get(`/v1/brand-kits/${brandKitUid}`);
|
|
2658
|
+
return response.data.data;
|
|
2659
|
+
}
|
|
2660
|
+
async create(data) {
|
|
2661
|
+
const response = await this.http.post("/v1/brand-kits", data);
|
|
2662
|
+
return response.data.data;
|
|
2663
|
+
}
|
|
2664
|
+
async update(brandKitUid, data) {
|
|
2665
|
+
const response = await this.http.put(`/v1/brand-kits/${brandKitUid}`, data);
|
|
2666
|
+
return response.data.data;
|
|
2667
|
+
}
|
|
2668
|
+
async delete(brandKitUid) {
|
|
2669
|
+
await this.http.delete(`/v1/brand-kits/${brandKitUid}`);
|
|
2670
|
+
}
|
|
2671
|
+
};
|
|
2672
|
+
|
|
2673
|
+
// src/brandkit/voice-profiles.ts
|
|
2674
|
+
var VoiceProfilesSubClient = class {
|
|
2675
|
+
constructor(http) {
|
|
2676
|
+
this.http = http;
|
|
2677
|
+
}
|
|
2678
|
+
list(brandKitUid, options) {
|
|
2679
|
+
const scoped = this.http.withHeaders({ brand_kit_uid: brandKitUid });
|
|
2680
|
+
return paginate(
|
|
2681
|
+
async (skip, limit) => {
|
|
2682
|
+
const response = await scoped.get(
|
|
2683
|
+
`/v1/brand-kits/${brandKitUid}/voice-profiles`,
|
|
2684
|
+
{ skip: String(skip), limit: String(limit) }
|
|
2685
|
+
);
|
|
2686
|
+
return { items: response.data.data ?? [], count: response.data.count };
|
|
2687
|
+
},
|
|
2688
|
+
{ limit: options?.limit }
|
|
2689
|
+
);
|
|
2690
|
+
}
|
|
2691
|
+
async listAll(brandKitUid, options) {
|
|
2692
|
+
return collectAll(this.list(brandKitUid, options));
|
|
2693
|
+
}
|
|
2694
|
+
async get(brandKitUid, voiceProfileUid) {
|
|
2695
|
+
const scoped = this.http.withHeaders({ brand_kit_uid: brandKitUid });
|
|
2696
|
+
const response = await scoped.get(
|
|
2697
|
+
`/v1/brand-kits/${brandKitUid}/voice-profiles/${voiceProfileUid}`
|
|
2698
|
+
);
|
|
2699
|
+
return response.data.data;
|
|
2700
|
+
}
|
|
2701
|
+
async create(brandKitUid, data) {
|
|
2702
|
+
const scoped = this.http.withHeaders({ brand_kit_uid: brandKitUid });
|
|
2703
|
+
const response = await scoped.post(
|
|
2704
|
+
`/v1/brand-kits/${brandKitUid}/voice-profiles`,
|
|
2705
|
+
data
|
|
2706
|
+
);
|
|
2707
|
+
return response.data.data;
|
|
2708
|
+
}
|
|
2709
|
+
async update(brandKitUid, voiceProfileUid, data) {
|
|
2710
|
+
const scoped = this.http.withHeaders({ brand_kit_uid: brandKitUid });
|
|
2711
|
+
const response = await scoped.put(
|
|
2712
|
+
`/v1/brand-kits/${brandKitUid}/voice-profiles/${voiceProfileUid}`,
|
|
2713
|
+
data
|
|
2714
|
+
);
|
|
2715
|
+
return response.data.data;
|
|
2716
|
+
}
|
|
2717
|
+
async delete(brandKitUid, voiceProfileUid) {
|
|
2718
|
+
const scoped = this.http.withHeaders({ brand_kit_uid: brandKitUid });
|
|
2719
|
+
await scoped.delete(`/v1/brand-kits/${brandKitUid}/voice-profiles/${voiceProfileUid}`);
|
|
2720
|
+
}
|
|
2721
|
+
};
|
|
2722
|
+
|
|
2723
|
+
// src/brandkit/client.ts
|
|
2724
|
+
function createBrandKitClient(config) {
|
|
2725
|
+
const endpoints = resolveEndpoints(config.region);
|
|
2726
|
+
const headers = {
|
|
2727
|
+
organization_uid: config.organizationUid
|
|
2728
|
+
};
|
|
2729
|
+
switch (config.auth.type) {
|
|
2730
|
+
case "oauth":
|
|
2731
|
+
headers.authorization = `Bearer ${config.auth.accessToken}`;
|
|
2732
|
+
break;
|
|
2733
|
+
case "authtoken":
|
|
2734
|
+
headers.authtoken = config.auth.token;
|
|
2735
|
+
break;
|
|
2736
|
+
}
|
|
2737
|
+
const http = new ContentstackHttpClient({
|
|
2738
|
+
...config.httpOptions,
|
|
2739
|
+
baseUrl: config.httpOptions?.baseUrl ?? endpoints.brandKit,
|
|
2740
|
+
headers: {
|
|
2741
|
+
...config.httpOptions?.headers,
|
|
2742
|
+
...headers
|
|
2743
|
+
}
|
|
2744
|
+
});
|
|
2745
|
+
return {
|
|
2746
|
+
brandKits: new BrandKitsSubClient(http),
|
|
2747
|
+
voiceProfiles: new VoiceProfilesSubClient(http)
|
|
2748
|
+
};
|
|
2749
|
+
}
|
|
2750
|
+
|
|
2751
|
+
// src/knowledge-vault/items.ts
|
|
2752
|
+
var KnowledgeVaultItemsClient = class {
|
|
2753
|
+
constructor(http) {
|
|
2754
|
+
this.http = http;
|
|
2755
|
+
}
|
|
2756
|
+
async ingest(data) {
|
|
2757
|
+
const response = await this.http.post("/v1/knowledge-vault", data);
|
|
2758
|
+
return response.data.data;
|
|
2759
|
+
}
|
|
2760
|
+
async update(itemUid, data) {
|
|
2761
|
+
const response = await this.http.put(
|
|
2762
|
+
`/v1/knowledge-vault/${itemUid}`,
|
|
2763
|
+
data
|
|
2764
|
+
);
|
|
2765
|
+
return response.data.data;
|
|
2766
|
+
}
|
|
2767
|
+
async delete(itemUid) {
|
|
2768
|
+
await this.http.delete(`/v1/knowledge-vault/${itemUid}`);
|
|
2769
|
+
}
|
|
2770
|
+
async getUsage() {
|
|
2771
|
+
const response = await this.http.get("/v1/knowledge-vault/usage");
|
|
2772
|
+
return response.data.data;
|
|
2773
|
+
}
|
|
2774
|
+
};
|
|
2775
|
+
|
|
2776
|
+
// src/knowledge-vault/client.ts
|
|
2777
|
+
function createKnowledgeVaultClient(config) {
|
|
2778
|
+
const endpoints = resolveEndpoints(config.region);
|
|
2779
|
+
const headers = {
|
|
2780
|
+
organization_uid: config.organizationUid,
|
|
2781
|
+
brand_kit_uid: config.brandKitUid
|
|
2782
|
+
};
|
|
2783
|
+
switch (config.auth.type) {
|
|
2784
|
+
case "oauth":
|
|
2785
|
+
headers.authorization = `Bearer ${config.auth.accessToken}`;
|
|
2786
|
+
break;
|
|
2787
|
+
case "authtoken":
|
|
2788
|
+
headers.authtoken = config.auth.token;
|
|
2789
|
+
break;
|
|
2790
|
+
}
|
|
2791
|
+
const http = new ContentstackHttpClient({
|
|
2792
|
+
...config.httpOptions,
|
|
2793
|
+
baseUrl: config.httpOptions?.baseUrl ?? endpoints.brandKitAI,
|
|
2794
|
+
headers: {
|
|
2795
|
+
...config.httpOptions?.headers,
|
|
2796
|
+
...headers
|
|
2797
|
+
}
|
|
2798
|
+
});
|
|
2799
|
+
return {
|
|
2800
|
+
items: new KnowledgeVaultItemsClient(http)
|
|
2801
|
+
};
|
|
2802
|
+
}
|
|
2803
|
+
|
|
2804
|
+
// src/generative-ai/client.ts
|
|
2805
|
+
function createGenerativeAIClient(config) {
|
|
2806
|
+
const endpoints = resolveEndpoints(config.region);
|
|
2807
|
+
const headers = {
|
|
2808
|
+
organization_uid: config.organizationUid,
|
|
2809
|
+
brand_kit_uid: config.brandKitUid
|
|
2810
|
+
};
|
|
2811
|
+
switch (config.auth.type) {
|
|
2812
|
+
case "oauth":
|
|
2813
|
+
headers.authorization = `Bearer ${config.auth.accessToken}`;
|
|
2814
|
+
break;
|
|
2815
|
+
case "authtoken":
|
|
2816
|
+
headers.authtoken = config.auth.token;
|
|
2817
|
+
break;
|
|
2818
|
+
}
|
|
2819
|
+
const http = new ContentstackHttpClient({
|
|
2820
|
+
...config.httpOptions,
|
|
2821
|
+
baseUrl: config.httpOptions?.baseUrl ?? endpoints.brandKitAI,
|
|
2822
|
+
headers: {
|
|
2823
|
+
...config.httpOptions?.headers,
|
|
2824
|
+
...headers
|
|
2825
|
+
}
|
|
2826
|
+
});
|
|
2827
|
+
return {
|
|
2828
|
+
async generate(data) {
|
|
2829
|
+
const body = { prompt: data.prompt };
|
|
2830
|
+
if (data.voiceProfileUid) {
|
|
2831
|
+
body.voice_profile_uid = data.voiceProfileUid;
|
|
2832
|
+
}
|
|
2833
|
+
if (data.useKnowledgeVault !== void 0) {
|
|
2834
|
+
body.knowledge_vault = data.useKnowledgeVault;
|
|
2835
|
+
}
|
|
2836
|
+
const response = await http.post(
|
|
2837
|
+
"/v1/generative-ai/generate",
|
|
2838
|
+
body
|
|
2839
|
+
);
|
|
2840
|
+
return response.data.data;
|
|
2841
|
+
}
|
|
2842
|
+
};
|
|
2843
|
+
}
|
|
2844
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2845
|
+
0 && (module.exports = {
|
|
2846
|
+
AssetsClient,
|
|
2847
|
+
AuditLogClient,
|
|
2848
|
+
BranchAliasesClient,
|
|
2849
|
+
BranchesClient,
|
|
2850
|
+
BulkOperationsClient,
|
|
2851
|
+
ContentTypesClient,
|
|
2852
|
+
ContentstackAuthError,
|
|
2853
|
+
ContentstackConfigError,
|
|
2854
|
+
ContentstackError,
|
|
2855
|
+
ContentstackForbiddenError,
|
|
2856
|
+
ContentstackInvalidApiKeyError,
|
|
2857
|
+
ContentstackNotFoundError,
|
|
2858
|
+
ContentstackRateLimitError,
|
|
2859
|
+
ContentstackServerError,
|
|
2860
|
+
ContentstackValidationError,
|
|
2861
|
+
CrudClient,
|
|
2862
|
+
EntriesClient,
|
|
2863
|
+
EnvironmentsClient,
|
|
2864
|
+
ExtensionsClient,
|
|
2865
|
+
GlobalFieldsClient,
|
|
2866
|
+
LabelsClient,
|
|
2867
|
+
LocalesClient,
|
|
2868
|
+
PublishRulesClient,
|
|
2869
|
+
ReleasesClient,
|
|
2870
|
+
RolesClient,
|
|
2871
|
+
TaxonomiesClient,
|
|
2872
|
+
TokensClient,
|
|
2873
|
+
WebhooksClient,
|
|
2874
|
+
WorkflowsClient,
|
|
2875
|
+
buildAssetsParams,
|
|
2876
|
+
buildAuthorizationUrl,
|
|
2877
|
+
buildCreateEntryRequest,
|
|
2878
|
+
buildDeleteEntryRequest,
|
|
2879
|
+
buildEntriesParams,
|
|
2880
|
+
buildEntryParams,
|
|
2881
|
+
buildPublishEntryRequest,
|
|
2882
|
+
buildUpdateEntryRequest,
|
|
2883
|
+
collectAll,
|
|
2884
|
+
contentstackAuthCallbacks,
|
|
2885
|
+
createAuthProvider,
|
|
2886
|
+
createBrandKitClient,
|
|
2887
|
+
createCMAClient,
|
|
2888
|
+
createGenerativeAIClient,
|
|
2889
|
+
createKnowledgeVaultClient,
|
|
2890
|
+
createLaunchClient,
|
|
2891
|
+
exchangeCode,
|
|
2892
|
+
fromHTML,
|
|
2893
|
+
generateCodeChallenge,
|
|
2894
|
+
generateCodeVerifier,
|
|
2895
|
+
getUser,
|
|
2896
|
+
imageTransform,
|
|
2897
|
+
normalizeRegion,
|
|
2898
|
+
paginate,
|
|
2899
|
+
parseErrorResponse,
|
|
2900
|
+
refreshToken,
|
|
2901
|
+
resolveEndpoints,
|
|
2902
|
+
resolveHosts,
|
|
2903
|
+
toHTML,
|
|
2904
|
+
toMarkdown,
|
|
2905
|
+
toPlainText,
|
|
2906
|
+
transform,
|
|
2907
|
+
validate
|
|
2908
|
+
});
|
|
2909
|
+
//# sourceMappingURL=index.cjs.map
|