@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.
Files changed (244) hide show
  1. package/dist/auth/index.cjs +607 -0
  2. package/dist/auth/index.cjs.map +1 -0
  3. package/dist/auth/index.d.cts +108 -0
  4. package/dist/auth/index.d.ts +108 -0
  5. package/dist/auth/index.mjs +25 -0
  6. package/dist/auth/index.mjs.map +1 -0
  7. package/dist/brandkit/index.cjs +525 -0
  8. package/dist/brandkit/index.cjs.map +1 -0
  9. package/dist/brandkit/index.d.cts +95 -0
  10. package/dist/brandkit/index.d.ts +95 -0
  11. package/dist/brandkit/index.mjs +11 -0
  12. package/dist/brandkit/index.mjs.map +1 -0
  13. package/dist/chunk-3C6J2BDB.mjs +84 -0
  14. package/dist/chunk-3C6J2BDB.mjs.map +1 -0
  15. package/dist/chunk-3KE63N3I.mjs +64 -0
  16. package/dist/chunk-3KE63N3I.mjs.map +1 -0
  17. package/dist/chunk-4CJ4IVPJ.mjs +212 -0
  18. package/dist/chunk-4CJ4IVPJ.mjs.map +1 -0
  19. package/dist/chunk-4JFUI7MJ.mjs +368 -0
  20. package/dist/chunk-4JFUI7MJ.mjs.map +1 -0
  21. package/dist/chunk-7VFGD32I.mjs +26 -0
  22. package/dist/chunk-7VFGD32I.mjs.map +1 -0
  23. package/dist/chunk-ARPJDW3A.mjs +44 -0
  24. package/dist/chunk-ARPJDW3A.mjs.map +1 -0
  25. package/dist/chunk-AVJHCFRK.mjs +52 -0
  26. package/dist/chunk-AVJHCFRK.mjs.map +1 -0
  27. package/dist/chunk-BK2IBTQS.mjs +131 -0
  28. package/dist/chunk-BK2IBTQS.mjs.map +1 -0
  29. package/dist/chunk-BUZ6CQHE.mjs +75 -0
  30. package/dist/chunk-BUZ6CQHE.mjs.map +1 -0
  31. package/dist/chunk-CKMAOWBQ.mjs +379 -0
  32. package/dist/chunk-CKMAOWBQ.mjs.map +1 -0
  33. package/dist/chunk-DJQLN4TR.mjs +1 -0
  34. package/dist/chunk-DJQLN4TR.mjs.map +1 -0
  35. package/dist/chunk-DMERADWM.mjs +67 -0
  36. package/dist/chunk-DMERADWM.mjs.map +1 -0
  37. package/dist/chunk-EREPKWTW.mjs +926 -0
  38. package/dist/chunk-EREPKWTW.mjs.map +1 -0
  39. package/dist/chunk-FQP4PB5X.mjs +88 -0
  40. package/dist/chunk-FQP4PB5X.mjs.map +1 -0
  41. package/dist/chunk-GNPQJBFX.mjs +144 -0
  42. package/dist/chunk-GNPQJBFX.mjs.map +1 -0
  43. package/dist/chunk-GOSB24M6.mjs +87 -0
  44. package/dist/chunk-GOSB24M6.mjs.map +1 -0
  45. package/dist/chunk-JL2E3EOT.mjs +255 -0
  46. package/dist/chunk-JL2E3EOT.mjs.map +1 -0
  47. package/dist/chunk-JYGZBKTH.mjs +222 -0
  48. package/dist/chunk-JYGZBKTH.mjs.map +1 -0
  49. package/dist/chunk-JZE2W7VW.mjs +52 -0
  50. package/dist/chunk-JZE2W7VW.mjs.map +1 -0
  51. package/dist/chunk-K76DKSHJ.mjs +18 -0
  52. package/dist/chunk-K76DKSHJ.mjs.map +1 -0
  53. package/dist/chunk-KLVIROVU.mjs +232 -0
  54. package/dist/chunk-KLVIROVU.mjs.map +1 -0
  55. package/dist/chunk-LPVVA5J3.mjs +18 -0
  56. package/dist/chunk-LPVVA5J3.mjs.map +1 -0
  57. package/dist/chunk-NKLOZ5VI.mjs +112 -0
  58. package/dist/chunk-NKLOZ5VI.mjs.map +1 -0
  59. package/dist/chunk-QGA4WBDC.mjs +7 -0
  60. package/dist/chunk-QGA4WBDC.mjs.map +1 -0
  61. package/dist/chunk-QW7TVYOA.mjs +56 -0
  62. package/dist/chunk-QW7TVYOA.mjs.map +1 -0
  63. package/dist/chunk-SU5QEKYW.mjs +83 -0
  64. package/dist/chunk-SU5QEKYW.mjs.map +1 -0
  65. package/dist/chunk-T5A2E2RI.mjs +654 -0
  66. package/dist/chunk-T5A2E2RI.mjs.map +1 -0
  67. package/dist/chunk-T5OIJQK7.mjs +116 -0
  68. package/dist/chunk-T5OIJQK7.mjs.map +1 -0
  69. package/dist/chunk-VW7DD6HV.mjs +253 -0
  70. package/dist/chunk-VW7DD6HV.mjs.map +1 -0
  71. package/dist/chunk-XH7NLHGW.mjs +133 -0
  72. package/dist/chunk-XH7NLHGW.mjs.map +1 -0
  73. package/dist/client-DJ5haQGd.d.cts +22 -0
  74. package/dist/client-DwVGVSQz.d.ts +22 -0
  75. package/dist/cma/index.cjs +1349 -0
  76. package/dist/cma/index.cjs.map +1 -0
  77. package/dist/cma/index.d.cts +22 -0
  78. package/dist/cma/index.d.ts +22 -0
  79. package/dist/cma/index.mjs +70 -0
  80. package/dist/cma/index.mjs.map +1 -0
  81. package/dist/errors-CAw-IRCP.d.cts +65 -0
  82. package/dist/errors-CAw-IRCP.d.ts +65 -0
  83. package/dist/generative-ai/index.cjs +401 -0
  84. package/dist/generative-ai/index.cjs.map +1 -0
  85. package/dist/generative-ai/index.d.cts +31 -0
  86. package/dist/generative-ai/index.d.ts +31 -0
  87. package/dist/generative-ai/index.mjs +10 -0
  88. package/dist/generative-ai/index.mjs.map +1 -0
  89. package/dist/images/index.cjs +185 -0
  90. package/dist/images/index.cjs.map +1 -0
  91. package/dist/images/index.d.cts +27 -0
  92. package/dist/images/index.d.ts +27 -0
  93. package/dist/images/index.mjs +8 -0
  94. package/dist/images/index.mjs.map +1 -0
  95. package/dist/index.cjs +2909 -0
  96. package/dist/index.cjs.map +1 -0
  97. package/dist/index.d.cts +30 -0
  98. package/dist/index.d.ts +30 -0
  99. package/dist/index.mjs +153 -0
  100. package/dist/index.mjs.map +1 -0
  101. package/dist/knowledge-vault/index.cjs +413 -0
  102. package/dist/knowledge-vault/index.cjs.map +1 -0
  103. package/dist/knowledge-vault/index.d.cts +49 -0
  104. package/dist/knowledge-vault/index.d.ts +49 -0
  105. package/dist/knowledge-vault/index.mjs +10 -0
  106. package/dist/knowledge-vault/index.mjs.map +1 -0
  107. package/dist/launch/index.cjs +624 -0
  108. package/dist/launch/index.cjs.map +1 -0
  109. package/dist/launch/index.d.cts +169 -0
  110. package/dist/launch/index.d.ts +169 -0
  111. package/dist/launch/index.mjs +11 -0
  112. package/dist/launch/index.mjs.map +1 -0
  113. package/dist/react/auth/index.cjs +113 -0
  114. package/dist/react/auth/index.cjs.map +1 -0
  115. package/dist/react/auth/index.d.cts +33 -0
  116. package/dist/react/auth/index.d.ts +33 -0
  117. package/dist/react/auth/index.mjs +13 -0
  118. package/dist/react/auth/index.mjs.map +1 -0
  119. package/dist/react/content/index.cjs +113 -0
  120. package/dist/react/content/index.cjs.map +1 -0
  121. package/dist/react/content/index.d.cts +25 -0
  122. package/dist/react/content/index.d.ts +25 -0
  123. package/dist/react/content/index.mjs +7 -0
  124. package/dist/react/content/index.mjs.map +1 -0
  125. package/dist/react/hooks/index.cjs +2097 -0
  126. package/dist/react/hooks/index.cjs.map +1 -0
  127. package/dist/react/hooks/index.d.cts +77 -0
  128. package/dist/react/hooks/index.d.ts +77 -0
  129. package/dist/react/hooks/index.mjs +46 -0
  130. package/dist/react/hooks/index.mjs.map +1 -0
  131. package/dist/react/index.cjs +2307 -0
  132. package/dist/react/index.cjs.map +1 -0
  133. package/dist/react/index.d.cts +16 -0
  134. package/dist/react/index.d.ts +16 -0
  135. package/dist/react/index.mjs +67 -0
  136. package/dist/react/index.mjs.map +1 -0
  137. package/dist/react/provider/index.cjs +83 -0
  138. package/dist/react/provider/index.cjs.map +1 -0
  139. package/dist/react/provider/index.d.cts +30 -0
  140. package/dist/react/provider/index.d.ts +30 -0
  141. package/dist/react/provider/index.mjs +11 -0
  142. package/dist/react/provider/index.mjs.map +1 -0
  143. package/dist/regions/index.cjs +171 -0
  144. package/dist/regions/index.cjs.map +1 -0
  145. package/dist/regions/index.d.cts +55 -0
  146. package/dist/regions/index.d.ts +55 -0
  147. package/dist/regions/index.mjs +13 -0
  148. package/dist/regions/index.mjs.map +1 -0
  149. package/dist/request-builders-BxeolQIw.d.ts +735 -0
  150. package/dist/request-builders-C2IG1LUo.d.cts +735 -0
  151. package/dist/rte/index.cjs +683 -0
  152. package/dist/rte/index.cjs.map +1 -0
  153. package/dist/rte/index.d.cts +33 -0
  154. package/dist/rte/index.d.ts +33 -0
  155. package/dist/rte/index.mjs +17 -0
  156. package/dist/rte/index.mjs.map +1 -0
  157. package/dist/server/index.cjs +917 -0
  158. package/dist/server/index.cjs.map +1 -0
  159. package/dist/server/index.d.cts +6 -0
  160. package/dist/server/index.d.ts +6 -0
  161. package/dist/server/index.mjs +45 -0
  162. package/dist/server/index.mjs.map +1 -0
  163. package/dist/server/middleware/index.cjs +614 -0
  164. package/dist/server/middleware/index.cjs.map +1 -0
  165. package/dist/server/middleware/index.d.cts +77 -0
  166. package/dist/server/middleware/index.d.ts +77 -0
  167. package/dist/server/middleware/index.mjs +27 -0
  168. package/dist/server/middleware/index.mjs.map +1 -0
  169. package/dist/server/proxy/index.cjs +329 -0
  170. package/dist/server/proxy/index.cjs.map +1 -0
  171. package/dist/server/proxy/index.d.cts +143 -0
  172. package/dist/server/proxy/index.d.ts +143 -0
  173. package/dist/server/proxy/index.mjs +29 -0
  174. package/dist/server/proxy/index.mjs.map +1 -0
  175. package/dist/server/webhooks/index.cjs +131 -0
  176. package/dist/server/webhooks/index.cjs.map +1 -0
  177. package/dist/server/webhooks/index.d.cts +230 -0
  178. package/dist/server/webhooks/index.d.ts +230 -0
  179. package/dist/server/webhooks/index.mjs +23 -0
  180. package/dist/server/webhooks/index.mjs.map +1 -0
  181. package/dist/types-6D9VR7pT.d.cts +26 -0
  182. package/dist/types-AelT0rFJ.d.cts +21 -0
  183. package/dist/types-AelT0rFJ.d.ts +21 -0
  184. package/dist/types-Bu5yCgmw.d.ts +26 -0
  185. package/dist/types-DgixK-ll.d.cts +23 -0
  186. package/dist/types-DgixK-ll.d.ts +23 -0
  187. package/dist/types-DrMwdlH9.d.cts +245 -0
  188. package/dist/types-DrMwdlH9.d.ts +245 -0
  189. package/dist/ui/css/index.cjs +31 -0
  190. package/dist/ui/css/index.cjs.map +1 -0
  191. package/dist/ui/css/index.d.cts +15 -0
  192. package/dist/ui/css/index.d.ts +15 -0
  193. package/dist/ui/css/index.mjs +7 -0
  194. package/dist/ui/css/index.mjs.map +1 -0
  195. package/dist/ui/index.cjs +368 -0
  196. package/dist/ui/index.cjs.map +1 -0
  197. package/dist/ui/index.d.cts +4 -0
  198. package/dist/ui/index.d.ts +4 -0
  199. package/dist/ui/index.mjs +33 -0
  200. package/dist/ui/index.mjs.map +1 -0
  201. package/dist/ui/theme/index.cjs +105 -0
  202. package/dist/ui/theme/index.cjs.map +1 -0
  203. package/dist/ui/theme/index.d.cts +33 -0
  204. package/dist/ui/theme/index.d.ts +33 -0
  205. package/dist/ui/theme/index.mjs +15 -0
  206. package/dist/ui/theme/index.mjs.map +1 -0
  207. package/dist/ui/tokens/index.cjs +286 -0
  208. package/dist/ui/tokens/index.cjs.map +1 -0
  209. package/dist/ui/tokens/index.d.cts +54 -0
  210. package/dist/ui/tokens/index.d.ts +54 -0
  211. package/dist/ui/tokens/index.mjs +17 -0
  212. package/dist/ui/tokens/index.mjs.map +1 -0
  213. package/dist/ui/tokens.css +408 -0
  214. package/dist/vue/auth/index.cjs +141 -0
  215. package/dist/vue/auth/index.cjs.map +1 -0
  216. package/dist/vue/auth/index.d.cts +78 -0
  217. package/dist/vue/auth/index.d.ts +78 -0
  218. package/dist/vue/auth/index.mjs +13 -0
  219. package/dist/vue/auth/index.mjs.map +1 -0
  220. package/dist/vue/composables/index.cjs +2108 -0
  221. package/dist/vue/composables/index.cjs.map +1 -0
  222. package/dist/vue/composables/index.d.cts +78 -0
  223. package/dist/vue/composables/index.d.ts +78 -0
  224. package/dist/vue/composables/index.mjs +46 -0
  225. package/dist/vue/composables/index.mjs.map +1 -0
  226. package/dist/vue/content/index.cjs +142 -0
  227. package/dist/vue/content/index.cjs.map +1 -0
  228. package/dist/vue/content/index.d.cts +47 -0
  229. package/dist/vue/content/index.d.ts +47 -0
  230. package/dist/vue/content/index.mjs +7 -0
  231. package/dist/vue/content/index.mjs.map +1 -0
  232. package/dist/vue/index.cjs +2389 -0
  233. package/dist/vue/index.cjs.map +1 -0
  234. package/dist/vue/index.d.cts +16 -0
  235. package/dist/vue/index.d.ts +16 -0
  236. package/dist/vue/index.mjs +69 -0
  237. package/dist/vue/index.mjs.map +1 -0
  238. package/dist/vue/provider/index.cjs +97 -0
  239. package/dist/vue/provider/index.cjs.map +1 -0
  240. package/dist/vue/provider/index.d.cts +90 -0
  241. package/dist/vue/provider/index.d.ts +90 -0
  242. package/dist/vue/provider/index.mjs +13 -0
  243. package/dist/vue/provider/index.mjs.map +1 -0
  244. package/package.json +195 -0
@@ -0,0 +1,2097 @@
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/react/hooks/index.ts
21
+ var hooks_exports = {};
22
+ __export(hooks_exports, {
23
+ useAssets: () => useAssets,
24
+ useBrandKit: () => useBrandKit,
25
+ useCMA: () => useCMA,
26
+ useContentTypes: () => useContentTypes,
27
+ useCreateEntry: () => useCreateEntry,
28
+ useDeleteEntry: () => useDeleteEntry,
29
+ useEntries: () => useEntries,
30
+ useEntry: () => useEntry,
31
+ useGenerativeAI: () => useGenerativeAI,
32
+ useKnowledgeVault: () => useKnowledgeVault,
33
+ useLaunch: () => useLaunch,
34
+ usePublishEntry: () => usePublishEntry,
35
+ useUpdateEntry: () => useUpdateEntry
36
+ });
37
+ module.exports = __toCommonJS(hooks_exports);
38
+
39
+ // src/http/errors.ts
40
+ var ContentstackError = class extends Error {
41
+ name = "ContentstackError";
42
+ status;
43
+ errorCode;
44
+ errors;
45
+ requestPath;
46
+ constructor(message, options) {
47
+ super(message, options?.cause ? { cause: options.cause } : void 0);
48
+ this.status = options?.status;
49
+ this.errorCode = options?.errorCode;
50
+ this.errors = options?.errors;
51
+ this.requestPath = options?.requestPath;
52
+ }
53
+ };
54
+ var ContentstackAuthError = class extends ContentstackError {
55
+ name = "ContentstackAuthError";
56
+ status = 401;
57
+ };
58
+ var ContentstackForbiddenError = class extends ContentstackError {
59
+ name = "ContentstackForbiddenError";
60
+ status = 403;
61
+ };
62
+ var ContentstackNotFoundError = class extends ContentstackError {
63
+ name = "ContentstackNotFoundError";
64
+ status = 404;
65
+ };
66
+ var ContentstackValidationError = class extends ContentstackError {
67
+ name = "ContentstackValidationError";
68
+ status;
69
+ constructor(message, options) {
70
+ super(message, options);
71
+ this.status = options?.status ?? 400;
72
+ }
73
+ };
74
+ var ContentstackInvalidApiKeyError = class extends ContentstackError {
75
+ name = "ContentstackInvalidApiKeyError";
76
+ status = 412;
77
+ };
78
+ var ContentstackRateLimitError = class extends ContentstackError {
79
+ name = "ContentstackRateLimitError";
80
+ status = 429;
81
+ retryAfter;
82
+ constructor(message, options) {
83
+ super(message, { ...options, status: 429 });
84
+ this.retryAfter = options?.retryAfter;
85
+ }
86
+ };
87
+ var ContentstackServerError = class extends ContentstackError {
88
+ name = "ContentstackServerError";
89
+ };
90
+
91
+ // src/regions/endpoints.ts
92
+ var import_contentstack_endpoints = require("@timbenniks/contentstack-endpoints");
93
+ var BRAND_KIT_URLS = {
94
+ us: {
95
+ brandKit: "https://brand-kits-api.contentstack.com",
96
+ brandKitAI: "https://ai.contentstack.com/brand-kits"
97
+ },
98
+ eu: {
99
+ brandKit: "https://eu-brand-kits-api.contentstack.com",
100
+ brandKitAI: "https://eu-ai.contentstack.com/brand-kits"
101
+ },
102
+ au: {
103
+ brandKit: "https://au-brand-kits-api.contentstack.com",
104
+ brandKitAI: "https://au-ai.contentstack.com/brand-kits"
105
+ },
106
+ "azure-na": {
107
+ brandKit: "https://azure-na-brand-kits-api.contentstack.com",
108
+ brandKitAI: "https://azure-na-ai.contentstack.com/brand-kits"
109
+ },
110
+ "azure-eu": {
111
+ brandKit: "https://azure-eu-brand-kits-api.contentstack.com",
112
+ brandKitAI: "https://azure-eu-ai.contentstack.com/brand-kits"
113
+ },
114
+ "gcp-na": {
115
+ brandKit: "https://gcp-na-brand-kits-api.contentstack.com",
116
+ brandKitAI: "https://gcp-na-ai.contentstack.com/brand-kits"
117
+ },
118
+ "gcp-eu": {
119
+ brandKit: "https://gcp-eu-brand-kits-api.contentstack.com",
120
+ brandKitAI: "https://gcp-eu-ai.contentstack.com/brand-kits"
121
+ }
122
+ };
123
+ function mapEndpoints(upstream, region, hostsOnly) {
124
+ const bk = BRAND_KIT_URLS[region];
125
+ const stripProtocol = (url) => url.replace(/^https?:\/\//, "");
126
+ return Object.freeze({
127
+ cma: upstream.contentManagement ?? "",
128
+ cda: upstream.contentDelivery ?? "",
129
+ graphql: upstream.graphqlDelivery ?? "",
130
+ images: upstream.images ?? "",
131
+ app: upstream.application ?? "",
132
+ preview: upstream.preview ?? "",
133
+ graphqlPreview: upstream.graphqlPreview ?? "",
134
+ launch: upstream.launch ?? "",
135
+ personalizeEdge: upstream.personalizeEdge ?? "",
136
+ brandKit: hostsOnly ? stripProtocol(bk.brandKit) : bk.brandKit,
137
+ brandKitAI: hostsOnly ? stripProtocol(bk.brandKitAI) : bk.brandKitAI
138
+ });
139
+ }
140
+ var ALL_REGIONS = [
141
+ "us",
142
+ "eu",
143
+ "au",
144
+ "azure-na",
145
+ "azure-eu",
146
+ "gcp-na",
147
+ "gcp-eu"
148
+ ];
149
+ function buildEndpointMap() {
150
+ const map = {};
151
+ for (const region of ALL_REGIONS) {
152
+ map[region] = mapEndpoints((0, import_contentstack_endpoints.getContentstackEndpoints)(region), region, false);
153
+ }
154
+ return Object.freeze(map);
155
+ }
156
+ function buildHostMap() {
157
+ const map = {};
158
+ for (const region of ALL_REGIONS) {
159
+ map[region] = mapEndpoints((0, import_contentstack_endpoints.getContentstackEndpoints)(region, true), region, true);
160
+ }
161
+ return Object.freeze(map);
162
+ }
163
+ var ENDPOINT_MAP = buildEndpointMap();
164
+ var HOST_MAP = buildHostMap();
165
+
166
+ // src/regions/resolver.ts
167
+ var VALID_REGIONS = new Set(Object.keys(ENDPOINT_MAP));
168
+ function resolveEndpoints(region) {
169
+ return ENDPOINT_MAP[region];
170
+ }
171
+
172
+ // src/http/parse-error.ts
173
+ async function parseErrorResponse(response, path) {
174
+ try {
175
+ const body = await response.json();
176
+ return new ContentstackError(body.error_message ?? body.message ?? response.statusText, {
177
+ status: response.status,
178
+ errorCode: body.error_code,
179
+ errors: body.errors,
180
+ requestPath: path
181
+ });
182
+ } catch {
183
+ return new ContentstackError(response.statusText, {
184
+ status: response.status,
185
+ requestPath: path
186
+ });
187
+ }
188
+ }
189
+
190
+ // src/http/client.ts
191
+ var DEFAULT_TIMEOUT = 3e4;
192
+ var DEFAULT_RETRY_LIMIT = 5;
193
+ var DEFAULT_RETRY_DELAY = 300;
194
+ var MAX_JITTER = 100;
195
+ var ContentstackHttpClient = class _ContentstackHttpClient {
196
+ config;
197
+ constructor(config) {
198
+ this.config = {
199
+ baseUrl: config.baseUrl,
200
+ headers: config.headers ?? {},
201
+ timeout: config.timeout ?? DEFAULT_TIMEOUT,
202
+ retryOnError: config.retryOnError ?? true,
203
+ retryLimit: config.retryLimit ?? DEFAULT_RETRY_LIMIT,
204
+ retryDelay: config.retryDelay ?? DEFAULT_RETRY_DELAY,
205
+ fetch: config.fetch ?? globalThis.fetch.bind(globalThis)
206
+ };
207
+ }
208
+ async get(path, params) {
209
+ let url = `${this.config.baseUrl}${path}`;
210
+ if (params) {
211
+ const searchParams = new URLSearchParams(params);
212
+ url += `?${searchParams.toString()}`;
213
+ }
214
+ return this.request(url, { method: "GET" }, path);
215
+ }
216
+ async post(path, body) {
217
+ const url = `${this.config.baseUrl}${path}`;
218
+ return this.request(
219
+ url,
220
+ {
221
+ method: "POST",
222
+ headers: { "Content-Type": "application/json" },
223
+ body: body !== void 0 ? JSON.stringify(body) : void 0
224
+ },
225
+ path
226
+ );
227
+ }
228
+ async put(path, body) {
229
+ const url = `${this.config.baseUrl}${path}`;
230
+ return this.request(
231
+ url,
232
+ {
233
+ method: "PUT",
234
+ headers: { "Content-Type": "application/json" },
235
+ body: body !== void 0 ? JSON.stringify(body) : void 0
236
+ },
237
+ path
238
+ );
239
+ }
240
+ async patch(path, body) {
241
+ const url = `${this.config.baseUrl}${path}`;
242
+ return this.request(
243
+ url,
244
+ {
245
+ method: "PATCH",
246
+ headers: { "Content-Type": "application/json" },
247
+ body: body !== void 0 ? JSON.stringify(body) : void 0
248
+ },
249
+ path
250
+ );
251
+ }
252
+ async delete(path) {
253
+ const url = `${this.config.baseUrl}${path}`;
254
+ return this.request(url, { method: "DELETE" }, path);
255
+ }
256
+ async postForm(path, params) {
257
+ const url = `${this.config.baseUrl}${path}`;
258
+ return this.request(
259
+ url,
260
+ {
261
+ method: "POST",
262
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
263
+ body: params.toString()
264
+ },
265
+ path
266
+ );
267
+ }
268
+ async upload(path, form) {
269
+ const url = `${this.config.baseUrl}${path}`;
270
+ return this.request(url, { method: "POST", body: form }, path);
271
+ }
272
+ /** Return a new client with additional headers merged */
273
+ withHeaders(headers) {
274
+ return new _ContentstackHttpClient({
275
+ ...this.config,
276
+ headers: { ...this.config.headers, ...headers }
277
+ });
278
+ }
279
+ /** Return a new client with a different base URL */
280
+ withBaseUrl(baseUrl) {
281
+ return new _ContentstackHttpClient({
282
+ ...this.config,
283
+ baseUrl
284
+ });
285
+ }
286
+ async request(url, init, path) {
287
+ const headers = new Headers(this.config.headers);
288
+ if (init.headers) {
289
+ const initHeaders = init.headers instanceof Headers ? init.headers : new Headers(init.headers);
290
+ initHeaders.forEach((value, key) => headers.set(key, value));
291
+ }
292
+ let lastError;
293
+ const maxAttempts = this.config.retryOnError ? this.config.retryLimit + 1 : 1;
294
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
295
+ const controller = new AbortController();
296
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
297
+ try {
298
+ const response = await this.config.fetch(url, {
299
+ ...init,
300
+ headers,
301
+ signal: controller.signal
302
+ });
303
+ if (response.ok) {
304
+ const data = await response.json().catch(() => ({}));
305
+ return { data, status: response.status, headers: response.headers };
306
+ }
307
+ const isRetryable = response.status === 429 || response.status >= 500;
308
+ if (isRetryable && this.config.retryOnError && attempt < maxAttempts - 1) {
309
+ const delay = this.calculateDelay(response, attempt);
310
+ await sleep(delay);
311
+ lastError = await this.createError(response, path);
312
+ continue;
313
+ }
314
+ throw await this.createError(response, path);
315
+ } catch (error) {
316
+ if (error instanceof ContentstackError) {
317
+ throw error;
318
+ }
319
+ if (error instanceof DOMException && error.name === "AbortError") {
320
+ throw new ContentstackError(`Request timed out after ${this.config.timeout}ms`, {
321
+ requestPath: path,
322
+ cause: error
323
+ });
324
+ }
325
+ throw new ContentstackError("Network request failed", {
326
+ requestPath: path,
327
+ cause: error instanceof Error ? error : new Error(String(error))
328
+ });
329
+ } finally {
330
+ clearTimeout(timeoutId);
331
+ }
332
+ }
333
+ throw lastError ?? new ContentstackError("Request failed after retries", { requestPath: path });
334
+ }
335
+ calculateDelay(response, attempt) {
336
+ const retryAfter = response.headers.get("Retry-After");
337
+ if (retryAfter) {
338
+ const seconds = Number.parseFloat(retryAfter);
339
+ if (!Number.isNaN(seconds)) {
340
+ return seconds * 1e3;
341
+ }
342
+ }
343
+ const jitter = Math.random() * MAX_JITTER;
344
+ return this.config.retryDelay * 2 ** attempt + jitter;
345
+ }
346
+ async createError(response, path) {
347
+ let body = {};
348
+ try {
349
+ body = await response.json();
350
+ } catch {
351
+ }
352
+ const message = body.error_message ?? body.error_description ?? body.message ?? `HTTP ${response.status} error`;
353
+ const errorCode = body.error_code;
354
+ const errors = body.errors;
355
+ const retryAfter = response.headers.get("Retry-After");
356
+ const opts = { status: response.status, errorCode, errors, requestPath: path };
357
+ switch (response.status) {
358
+ case 400:
359
+ return new ContentstackValidationError(message, { ...opts, status: 400 });
360
+ case 401:
361
+ return new ContentstackAuthError(message, opts);
362
+ case 403:
363
+ return new ContentstackForbiddenError(message, opts);
364
+ case 404:
365
+ return new ContentstackNotFoundError(message, opts);
366
+ case 412:
367
+ return new ContentstackInvalidApiKeyError(message, opts);
368
+ case 422:
369
+ return new ContentstackValidationError(message, { ...opts, status: 422 });
370
+ case 429:
371
+ return new ContentstackRateLimitError(message, {
372
+ ...opts,
373
+ retryAfter: retryAfter ? Number.parseFloat(retryAfter) : void 0
374
+ });
375
+ default:
376
+ if (response.status >= 500) {
377
+ return new ContentstackServerError(message, opts);
378
+ }
379
+ return new ContentstackError(message, opts);
380
+ }
381
+ }
382
+ };
383
+ function sleep(ms) {
384
+ return new Promise((resolve) => setTimeout(resolve, ms));
385
+ }
386
+
387
+ // src/cma/pagination.ts
388
+ var DEFAULT_PAGE_SIZE = 25;
389
+ function paginate(fetchPage, options) {
390
+ const pageSize = options?.limit ?? DEFAULT_PAGE_SIZE;
391
+ return {
392
+ [Symbol.asyncIterator]() {
393
+ let skip = 0;
394
+ let done = false;
395
+ let buffer = [];
396
+ let bufferIndex = 0;
397
+ let totalCount;
398
+ return {
399
+ async next() {
400
+ if (bufferIndex < buffer.length) {
401
+ return { value: buffer[bufferIndex++], done: false };
402
+ }
403
+ if (done) {
404
+ return { value: void 0, done: true };
405
+ }
406
+ const page = await fetchPage(skip, pageSize);
407
+ buffer = page.items;
408
+ bufferIndex = 0;
409
+ skip += page.items.length;
410
+ if (typeof page.count === "number") {
411
+ totalCount = page.count;
412
+ }
413
+ if (page.items.length === 0) {
414
+ done = true;
415
+ return { value: void 0, done: true };
416
+ }
417
+ if (typeof totalCount === "number" && skip >= totalCount) {
418
+ done = true;
419
+ }
420
+ return { value: buffer[bufferIndex++], done: false };
421
+ }
422
+ };
423
+ }
424
+ };
425
+ }
426
+ async function collectAll(iterable) {
427
+ const items = [];
428
+ for await (const item of iterable) {
429
+ items.push(item);
430
+ }
431
+ return items;
432
+ }
433
+
434
+ // src/cma/assets.ts
435
+ var AssetsClient = class {
436
+ constructor(http) {
437
+ this.http = http;
438
+ }
439
+ list(opts) {
440
+ return paginate(
441
+ async (skip, limit) => {
442
+ const params = {
443
+ skip: String(skip),
444
+ limit: String(limit)
445
+ };
446
+ if (opts?.folder) params.folder = opts.folder;
447
+ const response = await this.http.get("/assets", params);
448
+ return { items: response.data.assets ?? [], count: response.data.count };
449
+ },
450
+ { limit: opts?.limit }
451
+ );
452
+ }
453
+ async listAll(opts) {
454
+ return collectAll(this.list(opts));
455
+ }
456
+ async get(uid) {
457
+ const response = await this.http.get(`/assets/${uid}`);
458
+ return response.data.asset;
459
+ }
460
+ async upload(form) {
461
+ const response = await this.http.upload("/assets", form);
462
+ return response.data.asset;
463
+ }
464
+ async update(uid, data) {
465
+ const response = await this.http.put(`/assets/${uid}`, { asset: data });
466
+ return response.data.asset;
467
+ }
468
+ async delete(uid) {
469
+ await this.http.delete(`/assets/${uid}`);
470
+ }
471
+ async publish(uid, data) {
472
+ await this.http.post(`/assets/${uid}/publish`, { asset: data });
473
+ }
474
+ async unpublish(uid, data) {
475
+ await this.http.post(`/assets/${uid}/unpublish`, { asset: data });
476
+ }
477
+ // ─── Folders ──────────────────────────────────────────────────────
478
+ async listFolders(opts) {
479
+ const response = await this.http.get("/assets/folders", {
480
+ limit: String(opts?.limit ?? 100)
481
+ });
482
+ return response.data.assets ?? [];
483
+ }
484
+ async getFolder(uid) {
485
+ const response = await this.http.get(`/assets/folders/${uid}`);
486
+ return response.data.asset;
487
+ }
488
+ async createFolder(data) {
489
+ const response = await this.http.post("/assets/folders", {
490
+ asset: data
491
+ });
492
+ return response.data.asset;
493
+ }
494
+ async updateFolder(uid, data) {
495
+ const response = await this.http.put(`/assets/folders/${uid}`, {
496
+ asset: data
497
+ });
498
+ return response.data.asset;
499
+ }
500
+ async deleteFolder(uid) {
501
+ await this.http.delete(`/assets/folders/${uid}`);
502
+ }
503
+ // ─── Additional Operations ──────────────────────────────────────
504
+ async replace(uid, form) {
505
+ const response = await this.http.upload(`/assets/${uid}`, form);
506
+ return response.data.asset;
507
+ }
508
+ async getReferences(uid) {
509
+ const response = await this.http.get(`/assets/${uid}/references`);
510
+ return response.data.references ?? [];
511
+ }
512
+ };
513
+
514
+ // src/cma/base-client.ts
515
+ var CrudClient = class {
516
+ constructor(http, config) {
517
+ this.http = http;
518
+ this.config = config;
519
+ }
520
+ list(opts) {
521
+ return paginate(
522
+ async (skip, limit) => {
523
+ const response = await this.http.get(this.config.basePath, {
524
+ skip: String(skip),
525
+ limit: String(limit)
526
+ });
527
+ const items = response.data[this.config.pluralKey] ?? [];
528
+ return { items, count: response.data.count };
529
+ },
530
+ { limit: opts?.limit }
531
+ );
532
+ }
533
+ async listAll(opts) {
534
+ return collectAll(this.list(opts));
535
+ }
536
+ async get(uid) {
537
+ const response = await this.http.get(`${this.config.basePath}/${uid}`);
538
+ return response.data[this.config.singularKey];
539
+ }
540
+ async create(data) {
541
+ const response = await this.http.post(this.config.basePath, {
542
+ [this.config.singularKey]: data
543
+ });
544
+ return response.data[this.config.singularKey];
545
+ }
546
+ async update(uid, data) {
547
+ const response = await this.http.put(
548
+ `${this.config.basePath}/${uid}`,
549
+ { [this.config.singularKey]: data }
550
+ );
551
+ return response.data[this.config.singularKey];
552
+ }
553
+ async delete(uid) {
554
+ await this.http.delete(`${this.config.basePath}/${uid}`);
555
+ }
556
+ };
557
+
558
+ // src/cma/audit-log.ts
559
+ var AuditLogClient = class extends CrudClient {
560
+ constructor(http) {
561
+ super(http, { basePath: "/audit-logs", singularKey: "audit_log", pluralKey: "audit_logs" });
562
+ }
563
+ };
564
+
565
+ // src/cma/branch-aliases.ts
566
+ var BranchAliasesClient = class {
567
+ constructor(http) {
568
+ this.http = http;
569
+ }
570
+ async list() {
571
+ const response = await this.http.get(
572
+ "/stacks/branch_aliases"
573
+ );
574
+ return response.data.branch_aliases ?? [];
575
+ }
576
+ async get(uid) {
577
+ const response = await this.http.get(
578
+ `/stacks/branch_aliases/${uid}`
579
+ );
580
+ return response.data.branch_alias;
581
+ }
582
+ async createOrUpdate(uid, targetBranch) {
583
+ const response = await this.http.put(
584
+ `/stacks/branch_aliases/${uid}`,
585
+ { branch_alias: { target_branch: targetBranch } }
586
+ );
587
+ return response.data.branch_alias;
588
+ }
589
+ async delete(uid) {
590
+ await this.http.delete(`/stacks/branch_aliases/${uid}`);
591
+ }
592
+ };
593
+
594
+ // src/cma/branches.ts
595
+ var BranchesClient = class {
596
+ constructor(http) {
597
+ this.http = http;
598
+ }
599
+ list(opts) {
600
+ return paginate(
601
+ async (skip, limit) => {
602
+ const response = await this.http.get(
603
+ "/stacks/branches",
604
+ { skip: String(skip), limit: String(limit) }
605
+ );
606
+ return { items: response.data.branches ?? [], count: response.data.count };
607
+ },
608
+ { limit: opts?.limit }
609
+ );
610
+ }
611
+ async listAll(opts) {
612
+ return collectAll(this.list(opts));
613
+ }
614
+ async get(uid) {
615
+ const response = await this.http.get(`/stacks/branches/${uid}`);
616
+ return response.data.branch;
617
+ }
618
+ async create(data) {
619
+ const response = await this.http.post("/stacks/branches", {
620
+ branch: data
621
+ });
622
+ return response.data.branch;
623
+ }
624
+ async delete(uid) {
625
+ await this.http.delete(`/stacks/branches/${uid}`);
626
+ }
627
+ async compare(baseBranch, compareBranch) {
628
+ const response = await this.http.get("/stacks/branches_compare", {
629
+ base_branch: baseBranch,
630
+ compare_branch: compareBranch
631
+ });
632
+ return response.data;
633
+ }
634
+ async merge(data) {
635
+ const response = await this.http.post("/stacks/branches_merge", data);
636
+ return response.data.merge_job;
637
+ }
638
+ async listMergeJobs() {
639
+ const response = await this.http.get("/stacks/branches_queue");
640
+ return response.data.merge_jobs ?? [];
641
+ }
642
+ async getMergeJob(uid) {
643
+ const response = await this.http.get(`/stacks/branches_queue/${uid}`);
644
+ return response.data.merge_job;
645
+ }
646
+ };
647
+
648
+ // src/cma/bulk.ts
649
+ var BulkOperationsClient = class {
650
+ constructor(http) {
651
+ this.http = http;
652
+ }
653
+ async publish(data) {
654
+ await this.http.post("/bulk/publish", data);
655
+ }
656
+ async unpublish(data) {
657
+ await this.http.post("/bulk/unpublish", data);
658
+ }
659
+ async delete(data) {
660
+ await this.http.post("/bulk/delete", data);
661
+ }
662
+ async updateWorkflow(data) {
663
+ await this.http.post("/bulk/workflow", data);
664
+ }
665
+ async addItems(data) {
666
+ await this.http.post("/bulk/add", data);
667
+ }
668
+ async updateItems(data) {
669
+ await this.http.post("/bulk/update", data);
670
+ }
671
+ async jobStatus(jobId) {
672
+ const response = await this.http.get(`/bulk/jobs/${jobId}`);
673
+ return response.data.job;
674
+ }
675
+ async getJobItems(jobId, opts) {
676
+ const params = {};
677
+ if (opts?.limit) params.limit = String(opts.limit);
678
+ if (opts?.skip) params.skip = String(opts.skip);
679
+ const response = await this.http.get(
680
+ `/bulk/jobs/${jobId}/items`,
681
+ Object.keys(params).length > 0 ? params : void 0
682
+ );
683
+ return response.data.items ?? [];
684
+ }
685
+ };
686
+
687
+ // src/cma/content-types.ts
688
+ var ContentTypesClient = class extends CrudClient {
689
+ constructor(http) {
690
+ super(http, {
691
+ basePath: "/content_types",
692
+ singularKey: "content_type",
693
+ pluralKey: "content_types"
694
+ });
695
+ }
696
+ list(opts) {
697
+ return paginate(
698
+ async (skip, limit) => {
699
+ const params = {
700
+ skip: String(skip),
701
+ limit: String(limit)
702
+ };
703
+ if (opts?.include_count) params.include_count = "true";
704
+ const response = await this.http.get("/content_types", params);
705
+ return { items: response.data.content_types ?? [], count: response.data.count };
706
+ },
707
+ { limit: opts?.limit }
708
+ );
709
+ }
710
+ async listAll(opts) {
711
+ return collectAll(this.list(opts));
712
+ }
713
+ async export(uid) {
714
+ const response = await this.http.get(
715
+ `/content_types/${uid}/export`
716
+ );
717
+ return response.data.content_type;
718
+ }
719
+ async import(data) {
720
+ const response = await this.http.post(
721
+ "/content_types/import",
722
+ data
723
+ );
724
+ return response.data.content_type;
725
+ }
726
+ };
727
+
728
+ // src/cma/entries.ts
729
+ var EntriesClient = class {
730
+ constructor(http) {
731
+ this.http = http;
732
+ }
733
+ basePath(ctUid) {
734
+ return `/content_types/${ctUid}/entries`;
735
+ }
736
+ list(ctUid, opts) {
737
+ return paginate(
738
+ async (skip, limit) => {
739
+ const params = {
740
+ skip: String(skip),
741
+ limit: String(limit)
742
+ };
743
+ if (opts?.locale) params.locale = opts.locale;
744
+ if (opts?.include_publish_details) params.include_publish_details = "true";
745
+ if (opts?.include_workflow) params.include_workflow = "true";
746
+ if (opts?.include_count) params.include_count = "true";
747
+ if (opts?.query) params.query = JSON.stringify(opts.query);
748
+ if (opts?.asc) params.asc = opts.asc;
749
+ if (opts?.desc) params.desc = opts.desc;
750
+ const response = await this.http.get(
751
+ this.basePath(ctUid),
752
+ params
753
+ );
754
+ return { items: response.data.entries ?? [], count: response.data.count };
755
+ },
756
+ { limit: opts?.limit }
757
+ );
758
+ }
759
+ async listAll(ctUid, opts) {
760
+ return collectAll(this.list(ctUid, opts));
761
+ }
762
+ async get(ctUid, entryUid, opts) {
763
+ const params = {};
764
+ if (opts?.locale) params.locale = opts.locale;
765
+ if (opts?.include_publish_details) params.include_publish_details = "true";
766
+ if (opts?.include_workflow) params.include_workflow = "true";
767
+ if (opts?.version) params.version = String(opts.version);
768
+ const response = await this.http.get(
769
+ `${this.basePath(ctUid)}/${entryUid}`,
770
+ Object.keys(params).length > 0 ? params : void 0
771
+ );
772
+ return response.data.entry;
773
+ }
774
+ async create(ctUid, data) {
775
+ const response = await this.http.post(this.basePath(ctUid), { entry: data });
776
+ return response.data.entry;
777
+ }
778
+ async update(ctUid, entryUid, data) {
779
+ const response = await this.http.put(`${this.basePath(ctUid)}/${entryUid}`, {
780
+ entry: data
781
+ });
782
+ return response.data.entry;
783
+ }
784
+ async delete(ctUid, entryUid, opts) {
785
+ let path = `${this.basePath(ctUid)}/${entryUid}`;
786
+ if (opts?.locale) path += `?locale=${encodeURIComponent(opts.locale)}`;
787
+ await this.http.delete(path);
788
+ }
789
+ async publish(ctUid, entryUid, data) {
790
+ await this.http.post(`${this.basePath(ctUid)}/${entryUid}/publish`, { entry: data });
791
+ }
792
+ async unpublish(ctUid, entryUid, data) {
793
+ await this.http.post(`${this.basePath(ctUid)}/${entryUid}/unpublish`, { entry: data });
794
+ }
795
+ async localize(ctUid, entryUid, data) {
796
+ const response = await this.http.post(
797
+ `${this.basePath(ctUid)}/${entryUid}/localize`,
798
+ { entry: data }
799
+ );
800
+ return response.data.entry;
801
+ }
802
+ async setWorkflowStage(ctUid, entryUid, data) {
803
+ await this.http.post(`${this.basePath(ctUid)}/${entryUid}/workflow`, data);
804
+ }
805
+ async references(ctUid, entryUid) {
806
+ const response = await this.http.get(
807
+ `${this.basePath(ctUid)}/${entryUid}/references`
808
+ );
809
+ return response.data.references ?? [];
810
+ }
811
+ async languages(ctUid, entryUid) {
812
+ const response = await this.http.get(
813
+ `${this.basePath(ctUid)}/${entryUid}/languages`
814
+ );
815
+ return response.data.locales ?? [];
816
+ }
817
+ async versions(ctUid, entryUid) {
818
+ const response = await this.http.get(
819
+ `${this.basePath(ctUid)}/${entryUid}/versions`
820
+ );
821
+ return response.data.versions ?? [];
822
+ }
823
+ async import(ctUid, data, opts) {
824
+ let path = `${this.basePath(ctUid)}/import`;
825
+ const params = [];
826
+ if (opts?.locale) params.push(`locale=${encodeURIComponent(opts.locale)}`);
827
+ if (opts?.overwrite) params.push("overwrite=true");
828
+ if (params.length > 0) path += `?${params.join("&")}`;
829
+ const response = await this.http.post(path, data);
830
+ return response.data.entry;
831
+ }
832
+ };
833
+
834
+ // src/cma/environments.ts
835
+ var EnvironmentsClient = class extends CrudClient {
836
+ constructor(http) {
837
+ super(http, {
838
+ basePath: "/environments",
839
+ singularKey: "environment",
840
+ pluralKey: "environments"
841
+ });
842
+ }
843
+ };
844
+
845
+ // src/cma/extensions.ts
846
+ var ExtensionsClient = class extends CrudClient {
847
+ constructor(http) {
848
+ super(http, { basePath: "/extensions", singularKey: "extension", pluralKey: "extensions" });
849
+ }
850
+ async upload(form) {
851
+ const response = await this.http.upload("/extensions", form);
852
+ return response.data.extension;
853
+ }
854
+ };
855
+
856
+ // src/cma/global-fields.ts
857
+ var GlobalFieldsClient = class extends CrudClient {
858
+ constructor(http) {
859
+ super(http, {
860
+ basePath: "/global_fields",
861
+ singularKey: "global_field",
862
+ pluralKey: "global_fields"
863
+ });
864
+ }
865
+ async export(uid) {
866
+ const response = await this.http.get(
867
+ `/global_fields/${uid}/export`
868
+ );
869
+ return response.data.global_field;
870
+ }
871
+ async import(data) {
872
+ const response = await this.http.post(
873
+ "/global_fields/import",
874
+ data
875
+ );
876
+ return response.data.global_field;
877
+ }
878
+ };
879
+
880
+ // src/cma/labels.ts
881
+ var LabelsClient = class extends CrudClient {
882
+ constructor(http) {
883
+ super(http, { basePath: "/labels", singularKey: "label", pluralKey: "labels" });
884
+ }
885
+ };
886
+
887
+ // src/cma/locales.ts
888
+ var LocalesClient = class extends CrudClient {
889
+ constructor(http) {
890
+ super(http, { basePath: "/locales", singularKey: "locale", pluralKey: "locales" });
891
+ }
892
+ };
893
+
894
+ // src/cma/publish-rules.ts
895
+ var PublishRulesClient = class extends CrudClient {
896
+ constructor(http) {
897
+ super(http, {
898
+ basePath: "/workflows/publishing_rules",
899
+ singularKey: "publishing_rule",
900
+ pluralKey: "publishing_rules"
901
+ });
902
+ }
903
+ };
904
+
905
+ // src/cma/releases.ts
906
+ var ReleasesClient = class {
907
+ constructor(http) {
908
+ this.http = http;
909
+ }
910
+ list(opts) {
911
+ return paginate(
912
+ async (skip, limit) => {
913
+ const params = {
914
+ skip: String(skip),
915
+ limit: String(limit)
916
+ };
917
+ if (opts?.include_count) params.include_count = "true";
918
+ const response = await this.http.get(
919
+ "/releases",
920
+ params
921
+ );
922
+ return { items: response.data.releases ?? [], count: response.data.count };
923
+ },
924
+ { limit: opts?.limit }
925
+ );
926
+ }
927
+ async listAll(opts) {
928
+ return collectAll(this.list(opts));
929
+ }
930
+ async get(uid) {
931
+ const response = await this.http.get(`/releases/${uid}`);
932
+ return response.data.release;
933
+ }
934
+ async create(data) {
935
+ const response = await this.http.post("/releases", { release: data });
936
+ return response.data.release;
937
+ }
938
+ async update(uid, data) {
939
+ const response = await this.http.put(`/releases/${uid}`, {
940
+ release: data
941
+ });
942
+ return response.data.release;
943
+ }
944
+ async delete(uid) {
945
+ await this.http.delete(`/releases/${uid}`);
946
+ }
947
+ async deploy(uid, data) {
948
+ await this.http.post(`/releases/${uid}/deploy`, { release: data });
949
+ }
950
+ // ─── Items ──────────────────────────────────────────────────────
951
+ async listItems(uid) {
952
+ const response = await this.http.get(`/releases/${uid}/items`);
953
+ return response.data.items ?? [];
954
+ }
955
+ async addItem(uid, item) {
956
+ await this.http.post(`/releases/${uid}/items`, { item });
957
+ }
958
+ async removeItem(uid, item) {
959
+ await this.http.post(`/releases/${uid}/items/delete`, { item });
960
+ }
961
+ async clone(uid, data) {
962
+ const response = await this.http.post(`/releases/${uid}/clone`, {
963
+ release: data
964
+ });
965
+ return response.data.release;
966
+ }
967
+ };
968
+
969
+ // src/cma/roles.ts
970
+ var RolesClient = class extends CrudClient {
971
+ constructor(http) {
972
+ super(http, { basePath: "/roles", singularKey: "role", pluralKey: "roles" });
973
+ }
974
+ };
975
+
976
+ // src/cma/taxonomies.ts
977
+ var TaxonomiesClient = class {
978
+ constructor(http) {
979
+ this.http = http;
980
+ }
981
+ // ─── Taxonomies ───────────────────────────────────────────────────
982
+ list(opts) {
983
+ return paginate(
984
+ async (skip, limit) => {
985
+ const response = await this.http.get(
986
+ "/taxonomies",
987
+ { skip: String(skip), limit: String(limit) }
988
+ );
989
+ return { items: response.data.taxonomies ?? [], count: response.data.count };
990
+ },
991
+ { limit: opts?.limit }
992
+ );
993
+ }
994
+ async listAll(opts) {
995
+ return collectAll(this.list(opts));
996
+ }
997
+ async get(uid) {
998
+ const response = await this.http.get(`/taxonomies/${uid}`);
999
+ return response.data.taxonomy;
1000
+ }
1001
+ async create(data) {
1002
+ const response = await this.http.post("/taxonomies", {
1003
+ taxonomy: data
1004
+ });
1005
+ return response.data.taxonomy;
1006
+ }
1007
+ async update(uid, data) {
1008
+ const response = await this.http.put(`/taxonomies/${uid}`, {
1009
+ taxonomy: data
1010
+ });
1011
+ return response.data.taxonomy;
1012
+ }
1013
+ async delete(uid) {
1014
+ await this.http.delete(`/taxonomies/${uid}`);
1015
+ }
1016
+ // ─── Terms ────────────────────────────────────────────────────────
1017
+ listTerms(taxonomyUid, opts) {
1018
+ return paginate(
1019
+ async (skip, limit) => {
1020
+ const response = await this.http.get(
1021
+ `/taxonomies/${taxonomyUid}/terms`,
1022
+ { skip: String(skip), limit: String(limit) }
1023
+ );
1024
+ return { items: response.data.terms ?? [], count: response.data.count };
1025
+ },
1026
+ { limit: opts?.limit }
1027
+ );
1028
+ }
1029
+ async listAllTerms(taxonomyUid, opts) {
1030
+ return collectAll(this.listTerms(taxonomyUid, opts));
1031
+ }
1032
+ async getTerm(taxonomyUid, termUid) {
1033
+ const response = await this.http.get(
1034
+ `/taxonomies/${taxonomyUid}/terms/${termUid}`
1035
+ );
1036
+ return response.data.term;
1037
+ }
1038
+ async createTerm(taxonomyUid, data) {
1039
+ const response = await this.http.post(
1040
+ `/taxonomies/${taxonomyUid}/terms`,
1041
+ { term: data }
1042
+ );
1043
+ return response.data.term;
1044
+ }
1045
+ async updateTerm(taxonomyUid, termUid, data) {
1046
+ const response = await this.http.put(
1047
+ `/taxonomies/${taxonomyUid}/terms/${termUid}`,
1048
+ { term: data }
1049
+ );
1050
+ return response.data.term;
1051
+ }
1052
+ async deleteTerm(taxonomyUid, termUid) {
1053
+ await this.http.delete(`/taxonomies/${taxonomyUid}/terms/${termUid}`);
1054
+ }
1055
+ async ancestors(taxonomyUid, termUid) {
1056
+ const response = await this.http.get(
1057
+ `/taxonomies/${taxonomyUid}/terms/${termUid}/ancestors`
1058
+ );
1059
+ return response.data.terms ?? [];
1060
+ }
1061
+ async descendants(taxonomyUid, termUid) {
1062
+ const response = await this.http.get(
1063
+ `/taxonomies/${taxonomyUid}/terms/${termUid}/descendants`
1064
+ );
1065
+ return response.data.terms ?? [];
1066
+ }
1067
+ async moveTerm(taxonomyUid, termUid, data) {
1068
+ const response = await this.http.put(
1069
+ `/taxonomies/${taxonomyUid}/terms/${termUid}/move`,
1070
+ { term: data }
1071
+ );
1072
+ return response.data.term;
1073
+ }
1074
+ // ─── Import / Export ──────────────────────────────────────────────
1075
+ async export(uid) {
1076
+ const response = await this.http.get(`/taxonomies/${uid}/export`);
1077
+ return response.data.taxonomy;
1078
+ }
1079
+ async import(data) {
1080
+ const response = await this.http.post("/taxonomies/import", data);
1081
+ return response.data.taxonomy;
1082
+ }
1083
+ };
1084
+
1085
+ // src/cma/tokens.ts
1086
+ function tokenCrud(http, basePath) {
1087
+ return {
1088
+ async list() {
1089
+ const response = await http.get(basePath);
1090
+ return response.data.tokens ?? [];
1091
+ },
1092
+ async get(uid) {
1093
+ const response = await http.get(`${basePath}/${uid}`);
1094
+ return response.data.token;
1095
+ },
1096
+ async create(data) {
1097
+ const response = await http.post(basePath, { token: data });
1098
+ return response.data.token;
1099
+ },
1100
+ async update(uid, data) {
1101
+ const response = await http.put(`${basePath}/${uid}`, { token: data });
1102
+ return response.data.token;
1103
+ },
1104
+ async delete(uid) {
1105
+ await http.delete(`${basePath}/${uid}`);
1106
+ }
1107
+ };
1108
+ }
1109
+ var TokensClient = class {
1110
+ management;
1111
+ delivery;
1112
+ preview;
1113
+ constructor(http) {
1114
+ this.management = tokenCrud(http, "/stacks/management_tokens");
1115
+ this.delivery = tokenCrud(http, "/stacks/delivery_tokens");
1116
+ this.preview = tokenCrud(http, "/stacks/preview_tokens");
1117
+ }
1118
+ // ─── Management Tokens ────────────────────────────────────────────
1119
+ listManagementTokens() {
1120
+ return this.management.list();
1121
+ }
1122
+ getManagementToken(uid) {
1123
+ return this.management.get(uid);
1124
+ }
1125
+ createManagementToken(data) {
1126
+ return this.management.create(data);
1127
+ }
1128
+ updateManagementToken(uid, data) {
1129
+ return this.management.update(uid, data);
1130
+ }
1131
+ deleteManagementToken(uid) {
1132
+ return this.management.delete(uid);
1133
+ }
1134
+ // ─── Delivery Tokens ──────────────────────────────────────────────
1135
+ listDeliveryTokens() {
1136
+ return this.delivery.list();
1137
+ }
1138
+ getDeliveryToken(uid) {
1139
+ return this.delivery.get(uid);
1140
+ }
1141
+ createDeliveryToken(data) {
1142
+ return this.delivery.create(data);
1143
+ }
1144
+ updateDeliveryToken(uid, data) {
1145
+ return this.delivery.update(uid, data);
1146
+ }
1147
+ deleteDeliveryToken(uid) {
1148
+ return this.delivery.delete(uid);
1149
+ }
1150
+ // ─── Preview Tokens ──────────────────────────────────────────────
1151
+ listPreviewTokens() {
1152
+ return this.preview.list();
1153
+ }
1154
+ getPreviewToken(uid) {
1155
+ return this.preview.get(uid);
1156
+ }
1157
+ createPreviewToken(data) {
1158
+ return this.preview.create(data);
1159
+ }
1160
+ updatePreviewToken(uid, data) {
1161
+ return this.preview.update(uid, data);
1162
+ }
1163
+ deletePreviewToken(uid) {
1164
+ return this.preview.delete(uid);
1165
+ }
1166
+ };
1167
+
1168
+ // src/cma/webhooks.ts
1169
+ var WebhooksClient = class extends CrudClient {
1170
+ constructor(http) {
1171
+ super(http, { basePath: "/webhooks", singularKey: "webhook", pluralKey: "webhooks" });
1172
+ }
1173
+ async logs(uid) {
1174
+ const response = await this.http.get(`/webhooks/${uid}/logs`);
1175
+ return response.data.logs ?? [];
1176
+ }
1177
+ async retry(uid, executionUid) {
1178
+ await this.http.post(`/webhooks/${uid}/retry/${executionUid}`, {});
1179
+ }
1180
+ };
1181
+
1182
+ // src/cma/workflows.ts
1183
+ var WorkflowsClient = class extends CrudClient {
1184
+ constructor(http) {
1185
+ super(http, { basePath: "/workflows", singularKey: "workflow", pluralKey: "workflows" });
1186
+ }
1187
+ };
1188
+
1189
+ // src/cma/client.ts
1190
+ function createCMAClient(config) {
1191
+ const endpoints = resolveEndpoints(config.region);
1192
+ const headers = { api_key: config.apiKey };
1193
+ switch (config.auth.type) {
1194
+ case "management-token":
1195
+ headers.authorization = config.auth.token;
1196
+ break;
1197
+ case "oauth":
1198
+ headers.authorization = `Bearer ${config.auth.accessToken}`;
1199
+ break;
1200
+ case "authtoken":
1201
+ headers.authtoken = config.auth.token;
1202
+ break;
1203
+ }
1204
+ if (config.branch) {
1205
+ headers.branch = config.branch;
1206
+ }
1207
+ const http = new ContentstackHttpClient({
1208
+ ...config.httpOptions,
1209
+ baseUrl: config.httpOptions?.baseUrl ?? `${endpoints.cma}/v3`,
1210
+ headers: {
1211
+ ...config.httpOptions?.headers,
1212
+ ...headers
1213
+ }
1214
+ });
1215
+ return {
1216
+ entries: new EntriesClient(http),
1217
+ contentTypes: new ContentTypesClient(http),
1218
+ assets: new AssetsClient(http),
1219
+ environments: new EnvironmentsClient(http),
1220
+ locales: new LocalesClient(http),
1221
+ globalFields: new GlobalFieldsClient(http),
1222
+ webhooks: new WebhooksClient(http),
1223
+ workflows: new WorkflowsClient(http),
1224
+ releases: new ReleasesClient(http),
1225
+ branches: new BranchesClient(http),
1226
+ branchAliases: new BranchAliasesClient(http),
1227
+ taxonomies: new TaxonomiesClient(http),
1228
+ bulk: new BulkOperationsClient(http),
1229
+ tokens: new TokensClient(http),
1230
+ labels: new LabelsClient(http),
1231
+ roles: new RolesClient(http),
1232
+ auditLog: new AuditLogClient(http),
1233
+ extensions: new ExtensionsClient(http),
1234
+ publishRules: new PublishRulesClient(http),
1235
+ onBranch(branchUid) {
1236
+ return createCMAClient({ ...config, branch: branchUid });
1237
+ }
1238
+ };
1239
+ }
1240
+
1241
+ // src/cma/request-builders.ts
1242
+ function nonEmptyParams(params) {
1243
+ return Object.keys(params).length > 0 ? params : void 0;
1244
+ }
1245
+ function buildEntryParams(options) {
1246
+ if (!options) return void 0;
1247
+ const params = {};
1248
+ if (options.locale) params.locale = options.locale;
1249
+ if (options.version !== void 0) params.version = String(options.version);
1250
+ if (options.includePublishDetails) params.include_publish_details = "true";
1251
+ return nonEmptyParams(params);
1252
+ }
1253
+ function buildEntriesParams(options) {
1254
+ if (!options) return void 0;
1255
+ const params = {};
1256
+ if (options.locale) params.locale = options.locale;
1257
+ if (options.limit !== void 0) params.limit = String(options.limit);
1258
+ if (options.skip !== void 0) params.skip = String(options.skip);
1259
+ if (options.includePublishDetails) params.include_publish_details = "true";
1260
+ if (options.query) params.query = JSON.stringify(options.query);
1261
+ return nonEmptyParams(params);
1262
+ }
1263
+ function buildAssetsParams(options) {
1264
+ if (!options) return void 0;
1265
+ const params = {};
1266
+ if (options.folder) params.folder = options.folder;
1267
+ if (options.limit !== void 0) params.limit = String(options.limit);
1268
+ if (options.skip !== void 0) params.skip = String(options.skip);
1269
+ return nonEmptyParams(params);
1270
+ }
1271
+ function appendQueryString(path, params) {
1272
+ const query = params.toString();
1273
+ return query ? `${path}?${query}` : path;
1274
+ }
1275
+ function buildCreateEntryRequest(vars) {
1276
+ const params = new URLSearchParams();
1277
+ if (vars.locale) params.set("locale", vars.locale);
1278
+ return {
1279
+ path: appendQueryString(`/content_types/${vars.contentTypeUid}/entries`, params),
1280
+ body: { entry: vars.entry }
1281
+ };
1282
+ }
1283
+ function buildUpdateEntryRequest(vars) {
1284
+ const params = new URLSearchParams();
1285
+ if (vars.locale) params.set("locale", vars.locale);
1286
+ return {
1287
+ path: appendQueryString(
1288
+ `/content_types/${vars.contentTypeUid}/entries/${vars.entryUid}`,
1289
+ params
1290
+ ),
1291
+ body: { entry: vars.entry }
1292
+ };
1293
+ }
1294
+ function buildDeleteEntryRequest(vars) {
1295
+ const params = new URLSearchParams();
1296
+ if (vars.locale) params.set("locale", vars.locale);
1297
+ if (vars.deleteAllLocalized) params.set("delete_all_localized", "true");
1298
+ return {
1299
+ path: appendQueryString(
1300
+ `/content_types/${vars.contentTypeUid}/entries/${vars.entryUid}`,
1301
+ params
1302
+ )
1303
+ };
1304
+ }
1305
+ function buildPublishEntryRequest(vars) {
1306
+ return {
1307
+ path: `/content_types/${vars.contentTypeUid}/entries/${vars.entryUid}/publish`,
1308
+ body: {
1309
+ entry: {
1310
+ environments: vars.environments,
1311
+ locales: vars.locales,
1312
+ ...vars.scheduledAt ? { scheduled_at: vars.scheduledAt } : {}
1313
+ }
1314
+ }
1315
+ };
1316
+ }
1317
+
1318
+ // src/launch/response.ts
1319
+ function extractList(body, key) {
1320
+ if (Array.isArray(body)) {
1321
+ return { items: body };
1322
+ }
1323
+ if (body && typeof body === "object") {
1324
+ const obj = body;
1325
+ if (key in obj && Array.isArray(obj[key])) {
1326
+ const pagination = obj.pagination;
1327
+ return { items: obj[key], count: pagination?.count };
1328
+ }
1329
+ if ("data" in obj && Array.isArray(obj.data)) {
1330
+ return { items: obj.data, count: obj.count };
1331
+ }
1332
+ }
1333
+ return { items: [] };
1334
+ }
1335
+ function extractItem(body) {
1336
+ if (body && typeof body === "object" && "data" in body) {
1337
+ return body.data;
1338
+ }
1339
+ return body;
1340
+ }
1341
+
1342
+ // src/launch/deployments.ts
1343
+ var DeploymentsClient = class {
1344
+ constructor(http) {
1345
+ this.http = http;
1346
+ }
1347
+ basePath(projectUid, environmentUid) {
1348
+ return `/projects/${projectUid}/environments/${environmentUid}/deployments`;
1349
+ }
1350
+ list(projectUid, environmentUid, options) {
1351
+ return paginate(
1352
+ async (skip, limit) => {
1353
+ const params = {
1354
+ skip: String(skip),
1355
+ limit: String(limit)
1356
+ };
1357
+ const response = await this.http.get(
1358
+ this.basePath(projectUid, environmentUid),
1359
+ params
1360
+ );
1361
+ return extractList(response.data, "deployments");
1362
+ },
1363
+ { limit: options?.limit }
1364
+ );
1365
+ }
1366
+ async listAll(projectUid, environmentUid, options) {
1367
+ return collectAll(this.list(projectUid, environmentUid, options));
1368
+ }
1369
+ async get(projectUid, environmentUid, deploymentUid) {
1370
+ const response = await this.http.get(
1371
+ `${this.basePath(projectUid, environmentUid)}/${deploymentUid}`
1372
+ );
1373
+ return extractItem(response.data);
1374
+ }
1375
+ async create(projectUid, environmentUid, data) {
1376
+ const response = await this.http.post(this.basePath(projectUid, environmentUid), data);
1377
+ return extractItem(response.data);
1378
+ }
1379
+ async getDeploymentLogs(projectUid, environmentUid, deploymentUid, options) {
1380
+ const params = {};
1381
+ if (options?.timestamp) params.timestamp = options.timestamp;
1382
+ const response = await this.http.get(
1383
+ `${this.basePath(projectUid, environmentUid)}/${deploymentUid}/logs/deployment-logs`,
1384
+ Object.keys(params).length > 0 ? params : void 0
1385
+ );
1386
+ return extractList(response.data, "logs").items;
1387
+ }
1388
+ async getServerLogs(projectUid, environmentUid, deploymentUid, options) {
1389
+ const params = {};
1390
+ if (options?.startTime !== void 0) params.startTime = String(options.startTime);
1391
+ if (options?.endTime !== void 0) params.endTime = String(options.endTime);
1392
+ const response = await this.http.get(
1393
+ `${this.basePath(projectUid, environmentUid)}/${deploymentUid}/logs/server-logs`,
1394
+ Object.keys(params).length > 0 ? params : void 0
1395
+ );
1396
+ return extractList(response.data, "logs").items;
1397
+ }
1398
+ async getUploadUrl(projectUid, environmentUid) {
1399
+ const response = await this.http.get(
1400
+ `${this.basePath(projectUid, environmentUid)}/upload/signed_url`
1401
+ );
1402
+ return extractItem(response.data);
1403
+ }
1404
+ async getDownloadUrl(projectUid, environmentUid, deploymentUid) {
1405
+ const response = await this.http.get(
1406
+ `${this.basePath(projectUid, environmentUid)}/${deploymentUid}/download/signed_url`
1407
+ );
1408
+ const item = extractItem(response.data);
1409
+ return item.downloadUrl;
1410
+ }
1411
+ };
1412
+
1413
+ // src/launch/environments.ts
1414
+ var EnvironmentsClient2 = class {
1415
+ constructor(http) {
1416
+ this.http = http;
1417
+ }
1418
+ list(projectUid) {
1419
+ return paginate(async (skip, limit) => {
1420
+ const response = await this.http.get(`/projects/${projectUid}/environments`, {
1421
+ skip: String(skip),
1422
+ limit: String(limit)
1423
+ });
1424
+ return extractList(response.data, "environments");
1425
+ });
1426
+ }
1427
+ async listAll(projectUid) {
1428
+ return collectAll(this.list(projectUid));
1429
+ }
1430
+ async get(projectUid, envUid) {
1431
+ const response = await this.http.get(`/projects/${projectUid}/environments/${envUid}`);
1432
+ return extractItem(response.data);
1433
+ }
1434
+ async create(projectUid, data) {
1435
+ const response = await this.http.post(`/projects/${projectUid}/environments`, data);
1436
+ return extractItem(response.data);
1437
+ }
1438
+ async update(projectUid, envUid, data) {
1439
+ const response = await this.http.put(
1440
+ `/projects/${projectUid}/environments/${envUid}`,
1441
+ data
1442
+ );
1443
+ return extractItem(response.data);
1444
+ }
1445
+ async delete(projectUid, envUid) {
1446
+ await this.http.delete(`/projects/${projectUid}/environments/${envUid}`);
1447
+ }
1448
+ async revalidateCDNCache(projectUid, envUid, data) {
1449
+ await this.http.post(
1450
+ `/projects/${projectUid}/environments/${envUid}/revalidate-cdn-cache`,
1451
+ data
1452
+ );
1453
+ }
1454
+ async getUploadUrl(projectUid) {
1455
+ const response = await this.http.get(
1456
+ `/projects/${projectUid}/environments/upload/signed_url`
1457
+ );
1458
+ return extractItem(response.data);
1459
+ }
1460
+ };
1461
+
1462
+ // src/launch/projects.ts
1463
+ var ProjectsClient = class {
1464
+ constructor(http) {
1465
+ this.http = http;
1466
+ }
1467
+ list(options) {
1468
+ return paginate(
1469
+ async (skip, limit) => {
1470
+ const response = await this.http.get("/projects", {
1471
+ skip: String(skip),
1472
+ limit: String(limit)
1473
+ });
1474
+ return extractList(response.data, "projects");
1475
+ },
1476
+ { limit: options?.limit }
1477
+ );
1478
+ }
1479
+ async listAll(options) {
1480
+ return collectAll(this.list(options));
1481
+ }
1482
+ async get(projectUid) {
1483
+ const response = await this.http.get(`/projects/${projectUid}`);
1484
+ return extractItem(response.data);
1485
+ }
1486
+ async create(data) {
1487
+ const response = await this.http.post("/projects", data);
1488
+ return extractItem(response.data);
1489
+ }
1490
+ async update(projectUid, data) {
1491
+ const response = await this.http.put(`/projects/${projectUid}`, data);
1492
+ return extractItem(response.data);
1493
+ }
1494
+ async delete(projectUid) {
1495
+ await this.http.delete(`/projects/${projectUid}`);
1496
+ }
1497
+ async transferGitRepository(projectUid, data) {
1498
+ await this.http.patch(`/projects/${projectUid}/git-repository`, data);
1499
+ }
1500
+ async getUploadUrl() {
1501
+ const response = await this.http.get("/projects/upload/signed_url");
1502
+ return extractItem(response.data);
1503
+ }
1504
+ };
1505
+
1506
+ // src/launch/client.ts
1507
+ function createLaunchClient(config) {
1508
+ const endpoints = resolveEndpoints(config.region);
1509
+ const headers = {
1510
+ organization_uid: config.organizationUid
1511
+ };
1512
+ switch (config.auth.type) {
1513
+ case "oauth":
1514
+ headers.authorization = `Bearer ${config.auth.accessToken}`;
1515
+ break;
1516
+ case "authtoken":
1517
+ headers.authtoken = config.auth.token;
1518
+ break;
1519
+ }
1520
+ const http = new ContentstackHttpClient({
1521
+ ...config.httpOptions,
1522
+ baseUrl: config.httpOptions?.baseUrl ?? endpoints.launch,
1523
+ headers: {
1524
+ ...config.httpOptions?.headers,
1525
+ ...headers
1526
+ }
1527
+ });
1528
+ return {
1529
+ projects: new ProjectsClient(http),
1530
+ environments: new EnvironmentsClient2(http),
1531
+ deployments: new DeploymentsClient(http)
1532
+ };
1533
+ }
1534
+
1535
+ // src/brandkit/brand-kits.ts
1536
+ var BrandKitsSubClient = class {
1537
+ constructor(http) {
1538
+ this.http = http;
1539
+ }
1540
+ list(options) {
1541
+ return paginate(
1542
+ async (skip, limit) => {
1543
+ const response = await this.http.get(
1544
+ "/v1/brand-kits",
1545
+ {
1546
+ skip: String(skip),
1547
+ limit: String(limit)
1548
+ }
1549
+ );
1550
+ return { items: response.data.data ?? [], count: response.data.count };
1551
+ },
1552
+ { limit: options?.limit }
1553
+ );
1554
+ }
1555
+ async listAll(options) {
1556
+ return collectAll(this.list(options));
1557
+ }
1558
+ async get(brandKitUid) {
1559
+ const response = await this.http.get(`/v1/brand-kits/${brandKitUid}`);
1560
+ return response.data.data;
1561
+ }
1562
+ async create(data) {
1563
+ const response = await this.http.post("/v1/brand-kits", data);
1564
+ return response.data.data;
1565
+ }
1566
+ async update(brandKitUid, data) {
1567
+ const response = await this.http.put(`/v1/brand-kits/${brandKitUid}`, data);
1568
+ return response.data.data;
1569
+ }
1570
+ async delete(brandKitUid) {
1571
+ await this.http.delete(`/v1/brand-kits/${brandKitUid}`);
1572
+ }
1573
+ };
1574
+
1575
+ // src/brandkit/voice-profiles.ts
1576
+ var VoiceProfilesSubClient = class {
1577
+ constructor(http) {
1578
+ this.http = http;
1579
+ }
1580
+ list(brandKitUid, options) {
1581
+ const scoped = this.http.withHeaders({ brand_kit_uid: brandKitUid });
1582
+ return paginate(
1583
+ async (skip, limit) => {
1584
+ const response = await scoped.get(
1585
+ `/v1/brand-kits/${brandKitUid}/voice-profiles`,
1586
+ { skip: String(skip), limit: String(limit) }
1587
+ );
1588
+ return { items: response.data.data ?? [], count: response.data.count };
1589
+ },
1590
+ { limit: options?.limit }
1591
+ );
1592
+ }
1593
+ async listAll(brandKitUid, options) {
1594
+ return collectAll(this.list(brandKitUid, options));
1595
+ }
1596
+ async get(brandKitUid, voiceProfileUid) {
1597
+ const scoped = this.http.withHeaders({ brand_kit_uid: brandKitUid });
1598
+ const response = await scoped.get(
1599
+ `/v1/brand-kits/${brandKitUid}/voice-profiles/${voiceProfileUid}`
1600
+ );
1601
+ return response.data.data;
1602
+ }
1603
+ async create(brandKitUid, data) {
1604
+ const scoped = this.http.withHeaders({ brand_kit_uid: brandKitUid });
1605
+ const response = await scoped.post(
1606
+ `/v1/brand-kits/${brandKitUid}/voice-profiles`,
1607
+ data
1608
+ );
1609
+ return response.data.data;
1610
+ }
1611
+ async update(brandKitUid, voiceProfileUid, data) {
1612
+ const scoped = this.http.withHeaders({ brand_kit_uid: brandKitUid });
1613
+ const response = await scoped.put(
1614
+ `/v1/brand-kits/${brandKitUid}/voice-profiles/${voiceProfileUid}`,
1615
+ data
1616
+ );
1617
+ return response.data.data;
1618
+ }
1619
+ async delete(brandKitUid, voiceProfileUid) {
1620
+ const scoped = this.http.withHeaders({ brand_kit_uid: brandKitUid });
1621
+ await scoped.delete(`/v1/brand-kits/${brandKitUid}/voice-profiles/${voiceProfileUid}`);
1622
+ }
1623
+ };
1624
+
1625
+ // src/brandkit/client.ts
1626
+ function createBrandKitClient(config) {
1627
+ const endpoints = resolveEndpoints(config.region);
1628
+ const headers = {
1629
+ organization_uid: config.organizationUid
1630
+ };
1631
+ switch (config.auth.type) {
1632
+ case "oauth":
1633
+ headers.authorization = `Bearer ${config.auth.accessToken}`;
1634
+ break;
1635
+ case "authtoken":
1636
+ headers.authtoken = config.auth.token;
1637
+ break;
1638
+ }
1639
+ const http = new ContentstackHttpClient({
1640
+ ...config.httpOptions,
1641
+ baseUrl: config.httpOptions?.baseUrl ?? endpoints.brandKit,
1642
+ headers: {
1643
+ ...config.httpOptions?.headers,
1644
+ ...headers
1645
+ }
1646
+ });
1647
+ return {
1648
+ brandKits: new BrandKitsSubClient(http),
1649
+ voiceProfiles: new VoiceProfilesSubClient(http)
1650
+ };
1651
+ }
1652
+
1653
+ // src/knowledge-vault/items.ts
1654
+ var KnowledgeVaultItemsClient = class {
1655
+ constructor(http) {
1656
+ this.http = http;
1657
+ }
1658
+ async ingest(data) {
1659
+ const response = await this.http.post("/v1/knowledge-vault", data);
1660
+ return response.data.data;
1661
+ }
1662
+ async update(itemUid, data) {
1663
+ const response = await this.http.put(
1664
+ `/v1/knowledge-vault/${itemUid}`,
1665
+ data
1666
+ );
1667
+ return response.data.data;
1668
+ }
1669
+ async delete(itemUid) {
1670
+ await this.http.delete(`/v1/knowledge-vault/${itemUid}`);
1671
+ }
1672
+ async getUsage() {
1673
+ const response = await this.http.get("/v1/knowledge-vault/usage");
1674
+ return response.data.data;
1675
+ }
1676
+ };
1677
+
1678
+ // src/knowledge-vault/client.ts
1679
+ function createKnowledgeVaultClient(config) {
1680
+ const endpoints = resolveEndpoints(config.region);
1681
+ const headers = {
1682
+ organization_uid: config.organizationUid,
1683
+ brand_kit_uid: config.brandKitUid
1684
+ };
1685
+ switch (config.auth.type) {
1686
+ case "oauth":
1687
+ headers.authorization = `Bearer ${config.auth.accessToken}`;
1688
+ break;
1689
+ case "authtoken":
1690
+ headers.authtoken = config.auth.token;
1691
+ break;
1692
+ }
1693
+ const http = new ContentstackHttpClient({
1694
+ ...config.httpOptions,
1695
+ baseUrl: config.httpOptions?.baseUrl ?? endpoints.brandKitAI,
1696
+ headers: {
1697
+ ...config.httpOptions?.headers,
1698
+ ...headers
1699
+ }
1700
+ });
1701
+ return {
1702
+ items: new KnowledgeVaultItemsClient(http)
1703
+ };
1704
+ }
1705
+
1706
+ // src/generative-ai/client.ts
1707
+ function createGenerativeAIClient(config) {
1708
+ const endpoints = resolveEndpoints(config.region);
1709
+ const headers = {
1710
+ organization_uid: config.organizationUid,
1711
+ brand_kit_uid: config.brandKitUid
1712
+ };
1713
+ switch (config.auth.type) {
1714
+ case "oauth":
1715
+ headers.authorization = `Bearer ${config.auth.accessToken}`;
1716
+ break;
1717
+ case "authtoken":
1718
+ headers.authtoken = config.auth.token;
1719
+ break;
1720
+ }
1721
+ const http = new ContentstackHttpClient({
1722
+ ...config.httpOptions,
1723
+ baseUrl: config.httpOptions?.baseUrl ?? endpoints.brandKitAI,
1724
+ headers: {
1725
+ ...config.httpOptions?.headers,
1726
+ ...headers
1727
+ }
1728
+ });
1729
+ return {
1730
+ async generate(data) {
1731
+ const body = { prompt: data.prompt };
1732
+ if (data.voiceProfileUid) {
1733
+ body.voice_profile_uid = data.voiceProfileUid;
1734
+ }
1735
+ if (data.useKnowledgeVault !== void 0) {
1736
+ body.knowledge_vault = data.useKnowledgeVault;
1737
+ }
1738
+ const response = await http.post(
1739
+ "/v1/generative-ai/generate",
1740
+ body
1741
+ );
1742
+ return response.data.data;
1743
+ }
1744
+ };
1745
+ }
1746
+
1747
+ // src/react/hooks/shared/useQuery.ts
1748
+ var import_react2 = require("react");
1749
+
1750
+ // src/react/provider/context.ts
1751
+ var import_react = require("react");
1752
+ var ContentstackContext = (0, import_react.createContext)(null);
1753
+ function useContentstackContext() {
1754
+ const ctx = (0, import_react.useContext)(ContentstackContext);
1755
+ if (!ctx) {
1756
+ throw new Error(
1757
+ 'useContentstackContext must be used within a <ContentstackProvider>. Wrap your app with <ContentstackProvider region="..." proxyBasePath="/api/cma">.'
1758
+ );
1759
+ }
1760
+ return ctx;
1761
+ }
1762
+
1763
+ // src/react/hooks/shared/useQuery.ts
1764
+ function useQuery(path, params, options) {
1765
+ const { proxyBasePath } = useContentstackContext();
1766
+ const [data, setData] = (0, import_react2.useState)(void 0);
1767
+ const [loading, setLoading] = (0, import_react2.useState)(false);
1768
+ const [error, setError] = (0, import_react2.useState)(null);
1769
+ const abortRef = (0, import_react2.useRef)(null);
1770
+ const enabled = options?.enabled ?? true;
1771
+ const refetchInterval = options?.refetchInterval ?? 0;
1772
+ const search = params ? `?${new URLSearchParams(params).toString()}` : "";
1773
+ const url = `${proxyBasePath}${path}${search}`;
1774
+ const fetchData = (0, import_react2.useCallback)(
1775
+ async (signal) => {
1776
+ setLoading(true);
1777
+ setError(null);
1778
+ try {
1779
+ const response = await fetch(url, { signal });
1780
+ if (signal?.aborted) return;
1781
+ if (!response.ok) {
1782
+ const err = await parseErrorResponse(response, path);
1783
+ setError(err);
1784
+ setData(void 0);
1785
+ return;
1786
+ }
1787
+ const json = await response.json();
1788
+ setData(json);
1789
+ } catch (err) {
1790
+ if (err instanceof DOMException && err.name === "AbortError") return;
1791
+ setError(
1792
+ new ContentstackError(err instanceof Error ? err.message : "Network error", {
1793
+ requestPath: path,
1794
+ cause: err instanceof Error ? err : void 0
1795
+ })
1796
+ );
1797
+ setData(void 0);
1798
+ } finally {
1799
+ if (!signal?.aborted) {
1800
+ setLoading(false);
1801
+ }
1802
+ }
1803
+ },
1804
+ [url, path]
1805
+ );
1806
+ (0, import_react2.useEffect)(() => {
1807
+ if (!enabled) return;
1808
+ abortRef.current?.abort();
1809
+ const controller = new AbortController();
1810
+ abortRef.current = controller;
1811
+ fetchData(controller.signal);
1812
+ return () => {
1813
+ controller.abort();
1814
+ };
1815
+ }, [enabled, fetchData]);
1816
+ (0, import_react2.useEffect)(() => {
1817
+ if (!enabled || refetchInterval <= 0) return;
1818
+ const id = setInterval(() => {
1819
+ abortRef.current?.abort();
1820
+ const controller = new AbortController();
1821
+ abortRef.current = controller;
1822
+ fetchData(controller.signal);
1823
+ }, refetchInterval);
1824
+ return () => {
1825
+ clearInterval(id);
1826
+ };
1827
+ }, [enabled, refetchInterval, fetchData]);
1828
+ const refetch = (0, import_react2.useCallback)(async () => {
1829
+ abortRef.current?.abort();
1830
+ const controller = new AbortController();
1831
+ abortRef.current = controller;
1832
+ await fetchData(controller.signal);
1833
+ }, [fetchData]);
1834
+ return { data, loading, error, refetch };
1835
+ }
1836
+
1837
+ // src/react/hooks/useEntries.ts
1838
+ function useEntries(contentTypeUid, options) {
1839
+ const result = useQuery(
1840
+ `/content_types/${contentTypeUid}/entries`,
1841
+ buildEntriesParams(options),
1842
+ options
1843
+ );
1844
+ return {
1845
+ ...result,
1846
+ data: result.data?.entries,
1847
+ count: result.data?.count
1848
+ };
1849
+ }
1850
+
1851
+ // src/react/hooks/useEntry.ts
1852
+ function useEntry(contentTypeUid, entryUid, options) {
1853
+ const result = useQuery(
1854
+ `/content_types/${contentTypeUid}/entries/${entryUid}`,
1855
+ buildEntryParams(options),
1856
+ options
1857
+ );
1858
+ return {
1859
+ ...result,
1860
+ data: result.data?.entry
1861
+ };
1862
+ }
1863
+
1864
+ // src/react/hooks/useAssets.ts
1865
+ function useAssets(options) {
1866
+ const result = useQuery("/assets", buildAssetsParams(options), options);
1867
+ return {
1868
+ ...result,
1869
+ data: result.data?.assets
1870
+ };
1871
+ }
1872
+
1873
+ // src/react/hooks/useContentTypes.ts
1874
+ function useContentTypes(options) {
1875
+ const result = useQuery("/content_types", void 0, options);
1876
+ return {
1877
+ ...result,
1878
+ data: result.data?.content_types
1879
+ };
1880
+ }
1881
+
1882
+ // src/react/hooks/useCMA.ts
1883
+ var import_react3 = require("react");
1884
+ function useCMA() {
1885
+ const { proxyBasePath, region, apiKey } = useContentstackContext();
1886
+ return (0, import_react3.useMemo)(
1887
+ () => createCMAClient({
1888
+ region,
1889
+ apiKey: apiKey ?? "proxy",
1890
+ auth: { type: "oauth", accessToken: "proxy" },
1891
+ httpOptions: { baseUrl: proxyBasePath }
1892
+ }),
1893
+ [proxyBasePath, region, apiKey]
1894
+ );
1895
+ }
1896
+
1897
+ // src/react/hooks/useLaunch.ts
1898
+ var import_react4 = require("react");
1899
+ function useLaunch() {
1900
+ const { launchProxyBasePath = "/api/launch", region, organizationUid } = useContentstackContext();
1901
+ return (0, import_react4.useMemo)(
1902
+ () => createLaunchClient({
1903
+ region,
1904
+ organizationUid: organizationUid ?? "proxy",
1905
+ auth: { type: "oauth", accessToken: "proxy" },
1906
+ httpOptions: { baseUrl: launchProxyBasePath }
1907
+ }),
1908
+ [launchProxyBasePath, region, organizationUid]
1909
+ );
1910
+ }
1911
+
1912
+ // src/react/hooks/useBrandKit.ts
1913
+ var import_react5 = require("react");
1914
+ function useBrandKit() {
1915
+ const {
1916
+ brandKitProxyBasePath = "/api/brandkit",
1917
+ region,
1918
+ organizationUid
1919
+ } = useContentstackContext();
1920
+ return (0, import_react5.useMemo)(
1921
+ () => createBrandKitClient({
1922
+ region,
1923
+ organizationUid: organizationUid ?? "proxy",
1924
+ auth: { type: "oauth", accessToken: "proxy" },
1925
+ httpOptions: { baseUrl: brandKitProxyBasePath }
1926
+ }),
1927
+ [brandKitProxyBasePath, region, organizationUid]
1928
+ );
1929
+ }
1930
+
1931
+ // src/react/hooks/useKnowledgeVault.ts
1932
+ var import_react6 = require("react");
1933
+ function useKnowledgeVault() {
1934
+ const {
1935
+ brandKitProxyBasePath = "/api/brandkit",
1936
+ region,
1937
+ organizationUid,
1938
+ brandKitUid
1939
+ } = useContentstackContext();
1940
+ return (0, import_react6.useMemo)(
1941
+ () => createKnowledgeVaultClient({
1942
+ region,
1943
+ organizationUid: organizationUid ?? "proxy",
1944
+ brandKitUid: brandKitUid ?? "proxy",
1945
+ auth: { type: "oauth", accessToken: "proxy" },
1946
+ httpOptions: { baseUrl: brandKitProxyBasePath }
1947
+ }),
1948
+ [brandKitProxyBasePath, region, organizationUid, brandKitUid]
1949
+ );
1950
+ }
1951
+
1952
+ // src/react/hooks/useGenerativeAI.ts
1953
+ var import_react7 = require("react");
1954
+ function useGenerativeAI() {
1955
+ const {
1956
+ brandKitProxyBasePath = "/api/brandkit",
1957
+ region,
1958
+ organizationUid,
1959
+ brandKitUid
1960
+ } = useContentstackContext();
1961
+ return (0, import_react7.useMemo)(
1962
+ () => createGenerativeAIClient({
1963
+ region,
1964
+ organizationUid: organizationUid ?? "proxy",
1965
+ brandKitUid: brandKitUid ?? "proxy",
1966
+ auth: { type: "oauth", accessToken: "proxy" },
1967
+ httpOptions: { baseUrl: brandKitProxyBasePath }
1968
+ }),
1969
+ [brandKitProxyBasePath, region, organizationUid, brandKitUid]
1970
+ );
1971
+ }
1972
+
1973
+ // src/react/hooks/shared/useMutation.ts
1974
+ var import_react8 = require("react");
1975
+ function useMutation(method, buildRequest) {
1976
+ const { proxyBasePath } = useContentstackContext();
1977
+ const [data, setData] = (0, import_react8.useState)(void 0);
1978
+ const [loading, setLoading] = (0, import_react8.useState)(false);
1979
+ const [error, setError] = (0, import_react8.useState)(null);
1980
+ const buildRequestRef = (0, import_react8.useRef)(buildRequest);
1981
+ buildRequestRef.current = buildRequest;
1982
+ const mutate = (0, import_react8.useCallback)(
1983
+ async (variables) => {
1984
+ const { path, body } = buildRequestRef.current(variables);
1985
+ const url = `${proxyBasePath}${path}`;
1986
+ setLoading(true);
1987
+ setError(null);
1988
+ try {
1989
+ const response = await fetch(url, {
1990
+ method,
1991
+ headers: body !== void 0 ? { "Content-Type": "application/json" } : void 0,
1992
+ body: body !== void 0 ? JSON.stringify(body) : void 0
1993
+ });
1994
+ if (!response.ok) {
1995
+ const err = await parseErrorResponse(response, path);
1996
+ setError(err);
1997
+ setData(void 0);
1998
+ throw err;
1999
+ }
2000
+ let json;
2001
+ try {
2002
+ json = await response.json();
2003
+ } catch {
2004
+ json = void 0;
2005
+ }
2006
+ setData(json);
2007
+ return json;
2008
+ } catch (err) {
2009
+ if (err instanceof ContentstackError) throw err;
2010
+ const csError = new ContentstackError(
2011
+ err instanceof Error ? err.message : "Network error",
2012
+ {
2013
+ requestPath: path,
2014
+ cause: err instanceof Error ? err : void 0
2015
+ }
2016
+ );
2017
+ setError(csError);
2018
+ setData(void 0);
2019
+ throw csError;
2020
+ } finally {
2021
+ setLoading(false);
2022
+ }
2023
+ },
2024
+ [proxyBasePath, method]
2025
+ );
2026
+ const reset = (0, import_react8.useCallback)(() => {
2027
+ setData(void 0);
2028
+ setError(null);
2029
+ }, []);
2030
+ return { mutate, loading, error, data, reset };
2031
+ }
2032
+
2033
+ // src/react/hooks/usePublishEntry.ts
2034
+ function usePublishEntry() {
2035
+ return useMutation("POST", buildPublishEntryRequest);
2036
+ }
2037
+
2038
+ // src/react/hooks/useCreateEntry.ts
2039
+ var import_react9 = require("react");
2040
+ function useCreateEntry() {
2041
+ const result = useMutation(
2042
+ "POST",
2043
+ buildCreateEntryRequest
2044
+ );
2045
+ const mutate = (0, import_react9.useCallback)(
2046
+ async (variables) => {
2047
+ const raw = await result.mutate(variables);
2048
+ return raw.entry;
2049
+ },
2050
+ [result.mutate]
2051
+ );
2052
+ return {
2053
+ ...result,
2054
+ data: result.data?.entry,
2055
+ mutate
2056
+ };
2057
+ }
2058
+
2059
+ // src/react/hooks/useUpdateEntry.ts
2060
+ var import_react10 = require("react");
2061
+ function useUpdateEntry() {
2062
+ const result = useMutation("PUT", buildUpdateEntryRequest);
2063
+ const mutate = (0, import_react10.useCallback)(
2064
+ async (variables) => {
2065
+ const raw = await result.mutate(variables);
2066
+ return raw.entry;
2067
+ },
2068
+ [result.mutate]
2069
+ );
2070
+ return {
2071
+ ...result,
2072
+ data: result.data?.entry,
2073
+ mutate
2074
+ };
2075
+ }
2076
+
2077
+ // src/react/hooks/useDeleteEntry.ts
2078
+ function useDeleteEntry() {
2079
+ return useMutation("DELETE", buildDeleteEntryRequest);
2080
+ }
2081
+ // Annotate the CommonJS export names for ESM import in node:
2082
+ 0 && (module.exports = {
2083
+ useAssets,
2084
+ useBrandKit,
2085
+ useCMA,
2086
+ useContentTypes,
2087
+ useCreateEntry,
2088
+ useDeleteEntry,
2089
+ useEntries,
2090
+ useEntry,
2091
+ useGenerativeAI,
2092
+ useKnowledgeVault,
2093
+ useLaunch,
2094
+ usePublishEntry,
2095
+ useUpdateEntry
2096
+ });
2097
+ //# sourceMappingURL=index.cjs.map