@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,49 @@
1
+ import { H as HttpClientConfig } from '../types-DgixK-ll.js';
2
+ import { ContentstackRegion } from '../regions/index.js';
3
+ import { C as ContentstackHttpClient } from '../client-DwVGVSQz.js';
4
+
5
+ interface KnowledgeVaultItem {
6
+ uid: string;
7
+ status: "processing" | "ready" | "failed";
8
+ created_at: string;
9
+ updated_at: string;
10
+ }
11
+ interface KnowledgeVaultUsage {
12
+ total_items: number;
13
+ storage_used: number;
14
+ }
15
+ interface IngestContentData {
16
+ content: string;
17
+ }
18
+ interface UpdateContentData {
19
+ content: string;
20
+ }
21
+
22
+ declare class KnowledgeVaultItemsClient {
23
+ private readonly http;
24
+ constructor(http: ContentstackHttpClient);
25
+ ingest(data: IngestContentData): Promise<KnowledgeVaultItem>;
26
+ update(itemUid: string, data: UpdateContentData): Promise<KnowledgeVaultItem>;
27
+ delete(itemUid: string): Promise<void>;
28
+ getUsage(): Promise<KnowledgeVaultUsage>;
29
+ }
30
+
31
+ interface KnowledgeVaultClientConfig {
32
+ region: ContentstackRegion;
33
+ organizationUid: string;
34
+ brandKitUid: string;
35
+ auth: {
36
+ type: "oauth";
37
+ accessToken: string;
38
+ } | {
39
+ type: "authtoken";
40
+ token: string;
41
+ };
42
+ httpOptions?: Partial<HttpClientConfig>;
43
+ }
44
+ interface KnowledgeVaultClient {
45
+ items: KnowledgeVaultItemsClient;
46
+ }
47
+ declare function createKnowledgeVaultClient(config: KnowledgeVaultClientConfig): KnowledgeVaultClient;
48
+
49
+ export { type IngestContentData, type KnowledgeVaultClient, type KnowledgeVaultClientConfig, type KnowledgeVaultItem, type KnowledgeVaultUsage, type UpdateContentData, createKnowledgeVaultClient };
@@ -0,0 +1,10 @@
1
+ import {
2
+ createKnowledgeVaultClient
3
+ } from "../chunk-3KE63N3I.mjs";
4
+ import "../chunk-4CJ4IVPJ.mjs";
5
+ import "../chunk-BK2IBTQS.mjs";
6
+ import "../chunk-DMERADWM.mjs";
7
+ export {
8
+ createKnowledgeVaultClient
9
+ };
10
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,624 @@
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/launch/index.ts
21
+ var launch_exports = {};
22
+ __export(launch_exports, {
23
+ createLaunchClient: () => createLaunchClient
24
+ });
25
+ module.exports = __toCommonJS(launch_exports);
26
+
27
+ // src/http/errors.ts
28
+ var ContentstackError = class extends Error {
29
+ name = "ContentstackError";
30
+ status;
31
+ errorCode;
32
+ errors;
33
+ requestPath;
34
+ constructor(message, options) {
35
+ super(message, options?.cause ? { cause: options.cause } : void 0);
36
+ this.status = options?.status;
37
+ this.errorCode = options?.errorCode;
38
+ this.errors = options?.errors;
39
+ this.requestPath = options?.requestPath;
40
+ }
41
+ };
42
+ var ContentstackAuthError = class extends ContentstackError {
43
+ name = "ContentstackAuthError";
44
+ status = 401;
45
+ };
46
+ var ContentstackForbiddenError = class extends ContentstackError {
47
+ name = "ContentstackForbiddenError";
48
+ status = 403;
49
+ };
50
+ var ContentstackNotFoundError = class extends ContentstackError {
51
+ name = "ContentstackNotFoundError";
52
+ status = 404;
53
+ };
54
+ var ContentstackValidationError = class extends ContentstackError {
55
+ name = "ContentstackValidationError";
56
+ status;
57
+ constructor(message, options) {
58
+ super(message, options);
59
+ this.status = options?.status ?? 400;
60
+ }
61
+ };
62
+ var ContentstackInvalidApiKeyError = class extends ContentstackError {
63
+ name = "ContentstackInvalidApiKeyError";
64
+ status = 412;
65
+ };
66
+ var ContentstackRateLimitError = class extends ContentstackError {
67
+ name = "ContentstackRateLimitError";
68
+ status = 429;
69
+ retryAfter;
70
+ constructor(message, options) {
71
+ super(message, { ...options, status: 429 });
72
+ this.retryAfter = options?.retryAfter;
73
+ }
74
+ };
75
+ var ContentstackServerError = class extends ContentstackError {
76
+ name = "ContentstackServerError";
77
+ };
78
+
79
+ // src/http/client.ts
80
+ var DEFAULT_TIMEOUT = 3e4;
81
+ var DEFAULT_RETRY_LIMIT = 5;
82
+ var DEFAULT_RETRY_DELAY = 300;
83
+ var MAX_JITTER = 100;
84
+ var ContentstackHttpClient = class _ContentstackHttpClient {
85
+ config;
86
+ constructor(config) {
87
+ this.config = {
88
+ baseUrl: config.baseUrl,
89
+ headers: config.headers ?? {},
90
+ timeout: config.timeout ?? DEFAULT_TIMEOUT,
91
+ retryOnError: config.retryOnError ?? true,
92
+ retryLimit: config.retryLimit ?? DEFAULT_RETRY_LIMIT,
93
+ retryDelay: config.retryDelay ?? DEFAULT_RETRY_DELAY,
94
+ fetch: config.fetch ?? globalThis.fetch.bind(globalThis)
95
+ };
96
+ }
97
+ async get(path, params) {
98
+ let url = `${this.config.baseUrl}${path}`;
99
+ if (params) {
100
+ const searchParams = new URLSearchParams(params);
101
+ url += `?${searchParams.toString()}`;
102
+ }
103
+ return this.request(url, { method: "GET" }, path);
104
+ }
105
+ async post(path, body) {
106
+ const url = `${this.config.baseUrl}${path}`;
107
+ return this.request(
108
+ url,
109
+ {
110
+ method: "POST",
111
+ headers: { "Content-Type": "application/json" },
112
+ body: body !== void 0 ? JSON.stringify(body) : void 0
113
+ },
114
+ path
115
+ );
116
+ }
117
+ async put(path, body) {
118
+ const url = `${this.config.baseUrl}${path}`;
119
+ return this.request(
120
+ url,
121
+ {
122
+ method: "PUT",
123
+ headers: { "Content-Type": "application/json" },
124
+ body: body !== void 0 ? JSON.stringify(body) : void 0
125
+ },
126
+ path
127
+ );
128
+ }
129
+ async patch(path, body) {
130
+ const url = `${this.config.baseUrl}${path}`;
131
+ return this.request(
132
+ url,
133
+ {
134
+ method: "PATCH",
135
+ headers: { "Content-Type": "application/json" },
136
+ body: body !== void 0 ? JSON.stringify(body) : void 0
137
+ },
138
+ path
139
+ );
140
+ }
141
+ async delete(path) {
142
+ const url = `${this.config.baseUrl}${path}`;
143
+ return this.request(url, { method: "DELETE" }, path);
144
+ }
145
+ async postForm(path, params) {
146
+ const url = `${this.config.baseUrl}${path}`;
147
+ return this.request(
148
+ url,
149
+ {
150
+ method: "POST",
151
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
152
+ body: params.toString()
153
+ },
154
+ path
155
+ );
156
+ }
157
+ async upload(path, form) {
158
+ const url = `${this.config.baseUrl}${path}`;
159
+ return this.request(url, { method: "POST", body: form }, path);
160
+ }
161
+ /** Return a new client with additional headers merged */
162
+ withHeaders(headers) {
163
+ return new _ContentstackHttpClient({
164
+ ...this.config,
165
+ headers: { ...this.config.headers, ...headers }
166
+ });
167
+ }
168
+ /** Return a new client with a different base URL */
169
+ withBaseUrl(baseUrl) {
170
+ return new _ContentstackHttpClient({
171
+ ...this.config,
172
+ baseUrl
173
+ });
174
+ }
175
+ async request(url, init, path) {
176
+ const headers = new Headers(this.config.headers);
177
+ if (init.headers) {
178
+ const initHeaders = init.headers instanceof Headers ? init.headers : new Headers(init.headers);
179
+ initHeaders.forEach((value, key) => headers.set(key, value));
180
+ }
181
+ let lastError;
182
+ const maxAttempts = this.config.retryOnError ? this.config.retryLimit + 1 : 1;
183
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
184
+ const controller = new AbortController();
185
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
186
+ try {
187
+ const response = await this.config.fetch(url, {
188
+ ...init,
189
+ headers,
190
+ signal: controller.signal
191
+ });
192
+ if (response.ok) {
193
+ const data = await response.json().catch(() => ({}));
194
+ return { data, status: response.status, headers: response.headers };
195
+ }
196
+ const isRetryable = response.status === 429 || response.status >= 500;
197
+ if (isRetryable && this.config.retryOnError && attempt < maxAttempts - 1) {
198
+ const delay = this.calculateDelay(response, attempt);
199
+ await sleep(delay);
200
+ lastError = await this.createError(response, path);
201
+ continue;
202
+ }
203
+ throw await this.createError(response, path);
204
+ } catch (error) {
205
+ if (error instanceof ContentstackError) {
206
+ throw error;
207
+ }
208
+ if (error instanceof DOMException && error.name === "AbortError") {
209
+ throw new ContentstackError(`Request timed out after ${this.config.timeout}ms`, {
210
+ requestPath: path,
211
+ cause: error
212
+ });
213
+ }
214
+ throw new ContentstackError("Network request failed", {
215
+ requestPath: path,
216
+ cause: error instanceof Error ? error : new Error(String(error))
217
+ });
218
+ } finally {
219
+ clearTimeout(timeoutId);
220
+ }
221
+ }
222
+ throw lastError ?? new ContentstackError("Request failed after retries", { requestPath: path });
223
+ }
224
+ calculateDelay(response, attempt) {
225
+ const retryAfter = response.headers.get("Retry-After");
226
+ if (retryAfter) {
227
+ const seconds = Number.parseFloat(retryAfter);
228
+ if (!Number.isNaN(seconds)) {
229
+ return seconds * 1e3;
230
+ }
231
+ }
232
+ const jitter = Math.random() * MAX_JITTER;
233
+ return this.config.retryDelay * 2 ** attempt + jitter;
234
+ }
235
+ async createError(response, path) {
236
+ let body = {};
237
+ try {
238
+ body = await response.json();
239
+ } catch {
240
+ }
241
+ const message = body.error_message ?? body.error_description ?? body.message ?? `HTTP ${response.status} error`;
242
+ const errorCode = body.error_code;
243
+ const errors = body.errors;
244
+ const retryAfter = response.headers.get("Retry-After");
245
+ const opts = { status: response.status, errorCode, errors, requestPath: path };
246
+ switch (response.status) {
247
+ case 400:
248
+ return new ContentstackValidationError(message, { ...opts, status: 400 });
249
+ case 401:
250
+ return new ContentstackAuthError(message, opts);
251
+ case 403:
252
+ return new ContentstackForbiddenError(message, opts);
253
+ case 404:
254
+ return new ContentstackNotFoundError(message, opts);
255
+ case 412:
256
+ return new ContentstackInvalidApiKeyError(message, opts);
257
+ case 422:
258
+ return new ContentstackValidationError(message, { ...opts, status: 422 });
259
+ case 429:
260
+ return new ContentstackRateLimitError(message, {
261
+ ...opts,
262
+ retryAfter: retryAfter ? Number.parseFloat(retryAfter) : void 0
263
+ });
264
+ default:
265
+ if (response.status >= 500) {
266
+ return new ContentstackServerError(message, opts);
267
+ }
268
+ return new ContentstackError(message, opts);
269
+ }
270
+ }
271
+ };
272
+ function sleep(ms) {
273
+ return new Promise((resolve) => setTimeout(resolve, ms));
274
+ }
275
+
276
+ // src/regions/endpoints.ts
277
+ var import_contentstack_endpoints = require("@timbenniks/contentstack-endpoints");
278
+ var BRAND_KIT_URLS = {
279
+ us: {
280
+ brandKit: "https://brand-kits-api.contentstack.com",
281
+ brandKitAI: "https://ai.contentstack.com/brand-kits"
282
+ },
283
+ eu: {
284
+ brandKit: "https://eu-brand-kits-api.contentstack.com",
285
+ brandKitAI: "https://eu-ai.contentstack.com/brand-kits"
286
+ },
287
+ au: {
288
+ brandKit: "https://au-brand-kits-api.contentstack.com",
289
+ brandKitAI: "https://au-ai.contentstack.com/brand-kits"
290
+ },
291
+ "azure-na": {
292
+ brandKit: "https://azure-na-brand-kits-api.contentstack.com",
293
+ brandKitAI: "https://azure-na-ai.contentstack.com/brand-kits"
294
+ },
295
+ "azure-eu": {
296
+ brandKit: "https://azure-eu-brand-kits-api.contentstack.com",
297
+ brandKitAI: "https://azure-eu-ai.contentstack.com/brand-kits"
298
+ },
299
+ "gcp-na": {
300
+ brandKit: "https://gcp-na-brand-kits-api.contentstack.com",
301
+ brandKitAI: "https://gcp-na-ai.contentstack.com/brand-kits"
302
+ },
303
+ "gcp-eu": {
304
+ brandKit: "https://gcp-eu-brand-kits-api.contentstack.com",
305
+ brandKitAI: "https://gcp-eu-ai.contentstack.com/brand-kits"
306
+ }
307
+ };
308
+ function mapEndpoints(upstream, region, hostsOnly) {
309
+ const bk = BRAND_KIT_URLS[region];
310
+ const stripProtocol = (url) => url.replace(/^https?:\/\//, "");
311
+ return Object.freeze({
312
+ cma: upstream.contentManagement ?? "",
313
+ cda: upstream.contentDelivery ?? "",
314
+ graphql: upstream.graphqlDelivery ?? "",
315
+ images: upstream.images ?? "",
316
+ app: upstream.application ?? "",
317
+ preview: upstream.preview ?? "",
318
+ graphqlPreview: upstream.graphqlPreview ?? "",
319
+ launch: upstream.launch ?? "",
320
+ personalizeEdge: upstream.personalizeEdge ?? "",
321
+ brandKit: hostsOnly ? stripProtocol(bk.brandKit) : bk.brandKit,
322
+ brandKitAI: hostsOnly ? stripProtocol(bk.brandKitAI) : bk.brandKitAI
323
+ });
324
+ }
325
+ var ALL_REGIONS = [
326
+ "us",
327
+ "eu",
328
+ "au",
329
+ "azure-na",
330
+ "azure-eu",
331
+ "gcp-na",
332
+ "gcp-eu"
333
+ ];
334
+ function buildEndpointMap() {
335
+ const map = {};
336
+ for (const region of ALL_REGIONS) {
337
+ map[region] = mapEndpoints((0, import_contentstack_endpoints.getContentstackEndpoints)(region), region, false);
338
+ }
339
+ return Object.freeze(map);
340
+ }
341
+ function buildHostMap() {
342
+ const map = {};
343
+ for (const region of ALL_REGIONS) {
344
+ map[region] = mapEndpoints((0, import_contentstack_endpoints.getContentstackEndpoints)(region, true), region, true);
345
+ }
346
+ return Object.freeze(map);
347
+ }
348
+ var ENDPOINT_MAP = buildEndpointMap();
349
+ var HOST_MAP = buildHostMap();
350
+
351
+ // src/regions/resolver.ts
352
+ var VALID_REGIONS = new Set(Object.keys(ENDPOINT_MAP));
353
+ function resolveEndpoints(region) {
354
+ return ENDPOINT_MAP[region];
355
+ }
356
+
357
+ // src/cma/pagination.ts
358
+ var DEFAULT_PAGE_SIZE = 25;
359
+ function paginate(fetchPage, options) {
360
+ const pageSize = options?.limit ?? DEFAULT_PAGE_SIZE;
361
+ return {
362
+ [Symbol.asyncIterator]() {
363
+ let skip = 0;
364
+ let done = false;
365
+ let buffer = [];
366
+ let bufferIndex = 0;
367
+ let totalCount;
368
+ return {
369
+ async next() {
370
+ if (bufferIndex < buffer.length) {
371
+ return { value: buffer[bufferIndex++], done: false };
372
+ }
373
+ if (done) {
374
+ return { value: void 0, done: true };
375
+ }
376
+ const page = await fetchPage(skip, pageSize);
377
+ buffer = page.items;
378
+ bufferIndex = 0;
379
+ skip += page.items.length;
380
+ if (typeof page.count === "number") {
381
+ totalCount = page.count;
382
+ }
383
+ if (page.items.length === 0) {
384
+ done = true;
385
+ return { value: void 0, done: true };
386
+ }
387
+ if (typeof totalCount === "number" && skip >= totalCount) {
388
+ done = true;
389
+ }
390
+ return { value: buffer[bufferIndex++], done: false };
391
+ }
392
+ };
393
+ }
394
+ };
395
+ }
396
+ async function collectAll(iterable) {
397
+ const items = [];
398
+ for await (const item of iterable) {
399
+ items.push(item);
400
+ }
401
+ return items;
402
+ }
403
+
404
+ // src/launch/response.ts
405
+ function extractList(body, key) {
406
+ if (Array.isArray(body)) {
407
+ return { items: body };
408
+ }
409
+ if (body && typeof body === "object") {
410
+ const obj = body;
411
+ if (key in obj && Array.isArray(obj[key])) {
412
+ const pagination = obj.pagination;
413
+ return { items: obj[key], count: pagination?.count };
414
+ }
415
+ if ("data" in obj && Array.isArray(obj.data)) {
416
+ return { items: obj.data, count: obj.count };
417
+ }
418
+ }
419
+ return { items: [] };
420
+ }
421
+ function extractItem(body) {
422
+ if (body && typeof body === "object" && "data" in body) {
423
+ return body.data;
424
+ }
425
+ return body;
426
+ }
427
+
428
+ // src/launch/deployments.ts
429
+ var DeploymentsClient = class {
430
+ constructor(http) {
431
+ this.http = http;
432
+ }
433
+ basePath(projectUid, environmentUid) {
434
+ return `/projects/${projectUid}/environments/${environmentUid}/deployments`;
435
+ }
436
+ list(projectUid, environmentUid, options) {
437
+ return paginate(
438
+ async (skip, limit) => {
439
+ const params = {
440
+ skip: String(skip),
441
+ limit: String(limit)
442
+ };
443
+ const response = await this.http.get(
444
+ this.basePath(projectUid, environmentUid),
445
+ params
446
+ );
447
+ return extractList(response.data, "deployments");
448
+ },
449
+ { limit: options?.limit }
450
+ );
451
+ }
452
+ async listAll(projectUid, environmentUid, options) {
453
+ return collectAll(this.list(projectUid, environmentUid, options));
454
+ }
455
+ async get(projectUid, environmentUid, deploymentUid) {
456
+ const response = await this.http.get(
457
+ `${this.basePath(projectUid, environmentUid)}/${deploymentUid}`
458
+ );
459
+ return extractItem(response.data);
460
+ }
461
+ async create(projectUid, environmentUid, data) {
462
+ const response = await this.http.post(this.basePath(projectUid, environmentUid), data);
463
+ return extractItem(response.data);
464
+ }
465
+ async getDeploymentLogs(projectUid, environmentUid, deploymentUid, options) {
466
+ const params = {};
467
+ if (options?.timestamp) params.timestamp = options.timestamp;
468
+ const response = await this.http.get(
469
+ `${this.basePath(projectUid, environmentUid)}/${deploymentUid}/logs/deployment-logs`,
470
+ Object.keys(params).length > 0 ? params : void 0
471
+ );
472
+ return extractList(response.data, "logs").items;
473
+ }
474
+ async getServerLogs(projectUid, environmentUid, deploymentUid, options) {
475
+ const params = {};
476
+ if (options?.startTime !== void 0) params.startTime = String(options.startTime);
477
+ if (options?.endTime !== void 0) params.endTime = String(options.endTime);
478
+ const response = await this.http.get(
479
+ `${this.basePath(projectUid, environmentUid)}/${deploymentUid}/logs/server-logs`,
480
+ Object.keys(params).length > 0 ? params : void 0
481
+ );
482
+ return extractList(response.data, "logs").items;
483
+ }
484
+ async getUploadUrl(projectUid, environmentUid) {
485
+ const response = await this.http.get(
486
+ `${this.basePath(projectUid, environmentUid)}/upload/signed_url`
487
+ );
488
+ return extractItem(response.data);
489
+ }
490
+ async getDownloadUrl(projectUid, environmentUid, deploymentUid) {
491
+ const response = await this.http.get(
492
+ `${this.basePath(projectUid, environmentUid)}/${deploymentUid}/download/signed_url`
493
+ );
494
+ const item = extractItem(response.data);
495
+ return item.downloadUrl;
496
+ }
497
+ };
498
+
499
+ // src/launch/environments.ts
500
+ var EnvironmentsClient = class {
501
+ constructor(http) {
502
+ this.http = http;
503
+ }
504
+ list(projectUid) {
505
+ return paginate(async (skip, limit) => {
506
+ const response = await this.http.get(`/projects/${projectUid}/environments`, {
507
+ skip: String(skip),
508
+ limit: String(limit)
509
+ });
510
+ return extractList(response.data, "environments");
511
+ });
512
+ }
513
+ async listAll(projectUid) {
514
+ return collectAll(this.list(projectUid));
515
+ }
516
+ async get(projectUid, envUid) {
517
+ const response = await this.http.get(`/projects/${projectUid}/environments/${envUid}`);
518
+ return extractItem(response.data);
519
+ }
520
+ async create(projectUid, data) {
521
+ const response = await this.http.post(`/projects/${projectUid}/environments`, data);
522
+ return extractItem(response.data);
523
+ }
524
+ async update(projectUid, envUid, data) {
525
+ const response = await this.http.put(
526
+ `/projects/${projectUid}/environments/${envUid}`,
527
+ data
528
+ );
529
+ return extractItem(response.data);
530
+ }
531
+ async delete(projectUid, envUid) {
532
+ await this.http.delete(`/projects/${projectUid}/environments/${envUid}`);
533
+ }
534
+ async revalidateCDNCache(projectUid, envUid, data) {
535
+ await this.http.post(
536
+ `/projects/${projectUid}/environments/${envUid}/revalidate-cdn-cache`,
537
+ data
538
+ );
539
+ }
540
+ async getUploadUrl(projectUid) {
541
+ const response = await this.http.get(
542
+ `/projects/${projectUid}/environments/upload/signed_url`
543
+ );
544
+ return extractItem(response.data);
545
+ }
546
+ };
547
+
548
+ // src/launch/projects.ts
549
+ var ProjectsClient = class {
550
+ constructor(http) {
551
+ this.http = http;
552
+ }
553
+ list(options) {
554
+ return paginate(
555
+ async (skip, limit) => {
556
+ const response = await this.http.get("/projects", {
557
+ skip: String(skip),
558
+ limit: String(limit)
559
+ });
560
+ return extractList(response.data, "projects");
561
+ },
562
+ { limit: options?.limit }
563
+ );
564
+ }
565
+ async listAll(options) {
566
+ return collectAll(this.list(options));
567
+ }
568
+ async get(projectUid) {
569
+ const response = await this.http.get(`/projects/${projectUid}`);
570
+ return extractItem(response.data);
571
+ }
572
+ async create(data) {
573
+ const response = await this.http.post("/projects", data);
574
+ return extractItem(response.data);
575
+ }
576
+ async update(projectUid, data) {
577
+ const response = await this.http.put(`/projects/${projectUid}`, data);
578
+ return extractItem(response.data);
579
+ }
580
+ async delete(projectUid) {
581
+ await this.http.delete(`/projects/${projectUid}`);
582
+ }
583
+ async transferGitRepository(projectUid, data) {
584
+ await this.http.patch(`/projects/${projectUid}/git-repository`, data);
585
+ }
586
+ async getUploadUrl() {
587
+ const response = await this.http.get("/projects/upload/signed_url");
588
+ return extractItem(response.data);
589
+ }
590
+ };
591
+
592
+ // src/launch/client.ts
593
+ function createLaunchClient(config) {
594
+ const endpoints = resolveEndpoints(config.region);
595
+ const headers = {
596
+ organization_uid: config.organizationUid
597
+ };
598
+ switch (config.auth.type) {
599
+ case "oauth":
600
+ headers.authorization = `Bearer ${config.auth.accessToken}`;
601
+ break;
602
+ case "authtoken":
603
+ headers.authtoken = config.auth.token;
604
+ break;
605
+ }
606
+ const http = new ContentstackHttpClient({
607
+ ...config.httpOptions,
608
+ baseUrl: config.httpOptions?.baseUrl ?? endpoints.launch,
609
+ headers: {
610
+ ...config.httpOptions?.headers,
611
+ ...headers
612
+ }
613
+ });
614
+ return {
615
+ projects: new ProjectsClient(http),
616
+ environments: new EnvironmentsClient(http),
617
+ deployments: new DeploymentsClient(http)
618
+ };
619
+ }
620
+ // Annotate the CommonJS export names for ESM import in node:
621
+ 0 && (module.exports = {
622
+ createLaunchClient
623
+ });
624
+ //# sourceMappingURL=index.cjs.map