@viu/emporix-sdk 1.0.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 (132) hide show
  1. package/CHANGELOG.md +407 -0
  2. package/LICENSE +21 -0
  3. package/README.md +115 -0
  4. package/dist/cart.cjs +214 -0
  5. package/dist/cart.cjs.map +1 -0
  6. package/dist/cart.d.cts +1807 -0
  7. package/dist/cart.d.ts +1807 -0
  8. package/dist/cart.js +4 -0
  9. package/dist/cart.js.map +1 -0
  10. package/dist/category.cjs +97 -0
  11. package/dist/category.cjs.map +1 -0
  12. package/dist/category.d.cts +313 -0
  13. package/dist/category.d.ts +313 -0
  14. package/dist/category.js +4 -0
  15. package/dist/category.js.map +1 -0
  16. package/dist/checkout.cjs +98 -0
  17. package/dist/checkout.cjs.map +1 -0
  18. package/dist/checkout.d.cts +252 -0
  19. package/dist/checkout.d.ts +252 -0
  20. package/dist/checkout.js +4 -0
  21. package/dist/checkout.js.map +1 -0
  22. package/dist/chunk-4BJUCCKJ.js +86 -0
  23. package/dist/chunk-4BJUCCKJ.js.map +1 -0
  24. package/dist/chunk-6UNFMCHZ.js +95 -0
  25. package/dist/chunk-6UNFMCHZ.js.map +1 -0
  26. package/dist/chunk-B56JZNI7.js +49 -0
  27. package/dist/chunk-B56JZNI7.js.map +1 -0
  28. package/dist/chunk-BFQ732VZ.js +11 -0
  29. package/dist/chunk-BFQ732VZ.js.map +1 -0
  30. package/dist/chunk-F3WAQH2E.js +120 -0
  31. package/dist/chunk-F3WAQH2E.js.map +1 -0
  32. package/dist/chunk-GWJ2U2CP.js +14 -0
  33. package/dist/chunk-GWJ2U2CP.js.map +1 -0
  34. package/dist/chunk-HEO34WLO.js +47 -0
  35. package/dist/chunk-HEO34WLO.js.map +1 -0
  36. package/dist/chunk-HKPZI7Y5.js +30 -0
  37. package/dist/chunk-HKPZI7Y5.js.map +1 -0
  38. package/dist/chunk-IEZHGU7F.js +171 -0
  39. package/dist/chunk-IEZHGU7F.js.map +1 -0
  40. package/dist/chunk-KTODT6DV.js +86 -0
  41. package/dist/chunk-KTODT6DV.js.map +1 -0
  42. package/dist/chunk-NM7VDXBR.js +57 -0
  43. package/dist/chunk-NM7VDXBR.js.map +1 -0
  44. package/dist/chunk-OMYVOOSX.js +57 -0
  45. package/dist/chunk-OMYVOOSX.js.map +1 -0
  46. package/dist/chunk-QDABAMVN.js +89 -0
  47. package/dist/chunk-QDABAMVN.js.map +1 -0
  48. package/dist/chunk-RXVVFNYN.js +56 -0
  49. package/dist/chunk-RXVVFNYN.js.map +1 -0
  50. package/dist/chunk-SKX7KCMH.js +23 -0
  51. package/dist/chunk-SKX7KCMH.js.map +1 -0
  52. package/dist/chunk-TLH6SLAF.js +215 -0
  53. package/dist/chunk-TLH6SLAF.js.map +1 -0
  54. package/dist/chunk-Z6PNI5VT.js +142 -0
  55. package/dist/chunk-Z6PNI5VT.js.map +1 -0
  56. package/dist/companies.cjs +58 -0
  57. package/dist/companies.cjs.map +1 -0
  58. package/dist/companies.d.cts +31 -0
  59. package/dist/companies.d.ts +31 -0
  60. package/dist/companies.js +3 -0
  61. package/dist/companies.js.map +1 -0
  62. package/dist/contacts.cjs +51 -0
  63. package/dist/contacts.cjs.map +1 -0
  64. package/dist/contacts.d.cts +28 -0
  65. package/dist/contacts.d.ts +28 -0
  66. package/dist/contacts.js +3 -0
  67. package/dist/contacts.js.map +1 -0
  68. package/dist/context-vKgzZ-5f.d.cts +329 -0
  69. package/dist/context-vKgzZ-5f.d.ts +329 -0
  70. package/dist/customer-groups.cjs +25 -0
  71. package/dist/customer-groups.cjs.map +1 -0
  72. package/dist/customer-groups.d.cts +36 -0
  73. package/dist/customer-groups.d.ts +36 -0
  74. package/dist/customer-groups.js +3 -0
  75. package/dist/customer-groups.js.map +1 -0
  76. package/dist/customer.cjs +262 -0
  77. package/dist/customer.cjs.map +1 -0
  78. package/dist/customer.d.cts +386 -0
  79. package/dist/customer.d.ts +386 -0
  80. package/dist/customer.js +5 -0
  81. package/dist/customer.js.map +1 -0
  82. package/dist/index.cjs +2075 -0
  83. package/dist/index.cjs.map +1 -0
  84. package/dist/index.d.cts +218 -0
  85. package/dist/index.d.ts +218 -0
  86. package/dist/index.js +791 -0
  87. package/dist/index.js.map +1 -0
  88. package/dist/locations.cjs +59 -0
  89. package/dist/locations.cjs.map +1 -0
  90. package/dist/locations.d.cts +30 -0
  91. package/dist/locations.d.ts +30 -0
  92. package/dist/locations.js +3 -0
  93. package/dist/locations.js.map +1 -0
  94. package/dist/media.cjs +123 -0
  95. package/dist/media.cjs.map +1 -0
  96. package/dist/media.d.cts +219 -0
  97. package/dist/media.d.ts +219 -0
  98. package/dist/media.js +3 -0
  99. package/dist/media.js.map +1 -0
  100. package/dist/orders.cjs +98 -0
  101. package/dist/orders.cjs.map +1 -0
  102. package/dist/orders.d.cts +167 -0
  103. package/dist/orders.d.ts +167 -0
  104. package/dist/orders.js +3 -0
  105. package/dist/orders.js.map +1 -0
  106. package/dist/payment.cjs +77 -0
  107. package/dist/payment.cjs.map +1 -0
  108. package/dist/payment.d.cts +110 -0
  109. package/dist/payment.d.ts +110 -0
  110. package/dist/payment.js +5 -0
  111. package/dist/payment.js.map +1 -0
  112. package/dist/price.cjs +88 -0
  113. package/dist/price.cjs.map +1 -0
  114. package/dist/price.d.cts +445 -0
  115. package/dist/price.d.ts +445 -0
  116. package/dist/price.js +4 -0
  117. package/dist/price.js.map +1 -0
  118. package/dist/product.cjs +100 -0
  119. package/dist/product.cjs.map +1 -0
  120. package/dist/product.d.cts +400 -0
  121. package/dist/product.d.ts +400 -0
  122. package/dist/product.js +4 -0
  123. package/dist/product.js.map +1 -0
  124. package/dist/segment.cjs +189 -0
  125. package/dist/segment.cjs.map +1 -0
  126. package/dist/segment.d.cts +241 -0
  127. package/dist/segment.d.ts +241 -0
  128. package/dist/segment.js +5 -0
  129. package/dist/segment.js.map +1 -0
  130. package/dist/types.gen-D1QuqPLs.d.cts +166 -0
  131. package/dist/types.gen-D1QuqPLs.d.ts +166 -0
  132. package/package.json +141 -0
@@ -0,0 +1,313 @@
1
+ import { C as ClientContext, b as AuthContext, P as PaginatedItems } from './context-vKgzZ-5f.js';
2
+ import { Product } from './product.js';
3
+
4
+ /**
5
+ * Classification mixin defined for a given category.
6
+ */
7
+ type OwnClassificationMixin = {
8
+ /**
9
+ * Name of the mixin.
10
+ */
11
+ name: string;
12
+ /**
13
+ * URL of the mixin schema.
14
+ */
15
+ schemaUrl: string;
16
+ /**
17
+ * Indicates whether the mixin is required.
18
+ */
19
+ required?: boolean;
20
+ };
21
+ /**
22
+ * Classification mixin with source category information.
23
+ */
24
+ type ClassificationMixin = {
25
+ /**
26
+ * Name of the mixin
27
+ */
28
+ name: string;
29
+ /**
30
+ * The mixins path that should be used when defining attributes on a product. It's built based on the following pattern - `class_<sourceCategory.code>_<name>`.
31
+ */
32
+ mixinPath?: string;
33
+ /**
34
+ * URL of the mixin schema.
35
+ */
36
+ schemaUrl: string;
37
+ /**
38
+ * Indicates whether the mixin is required.
39
+ */
40
+ required?: boolean;
41
+ /**
42
+ * Unique identifier of the category from which the mixin comes from. Can be this category ID or one of the parent categories IDs.
43
+ */
44
+ sourceCategoryId?: string;
45
+ };
46
+ /**
47
+ * Definition of category
48
+ */
49
+ type Category$1 = {
50
+ /**
51
+ * Category unique identifier generated when the category is created.
52
+ */
53
+ id: string;
54
+ /**
55
+ * Unique identifier of the parent category. No parentId in the body indicates that this is a root category.
56
+ */
57
+ parentId?: string | null;
58
+ /**
59
+ * Localized category name as a map of translations.
60
+ */
61
+ localizedName: {
62
+ [key: string]: string;
63
+ };
64
+ /**
65
+ * Localized category description as a map of translations.
66
+ */
67
+ localizedDescription?: {
68
+ [key: string]: string;
69
+ };
70
+ /**
71
+ * Provides localized category name or code without diacritics for the URL.
72
+ */
73
+ localizedSlug?: {
74
+ [key: string]: string;
75
+ };
76
+ /**
77
+ * Category name in tenant default language.
78
+ * @deprecated
79
+ */
80
+ name?: string;
81
+ /**
82
+ * Description in tenant default language.
83
+ * @deprecated
84
+ */
85
+ description?: string;
86
+ /**
87
+ * Unique category identifier defined by the tenant.
88
+ */
89
+ code?: string;
90
+ /**
91
+ * List of external category numbers (ECNs) unique for each category.
92
+ */
93
+ ecn?: Array<string>;
94
+ validity?: Validity;
95
+ /**
96
+ * Category position relative to sibling categories.
97
+ */
98
+ position: number;
99
+ /**
100
+ * Flag indicating whether the category has been published.
101
+ */
102
+ published: boolean;
103
+ /**
104
+ * IDs of supercategories.
105
+ */
106
+ supercategoriesIds?: Array<string>;
107
+ /**
108
+ * List of classification mixins defined for this category.
109
+ */
110
+ ownClassificationMixins?: Array<OwnClassificationMixin>;
111
+ /**
112
+ * Combined list of classification mixins from parent categories and category's ownClassification mixins.
113
+ */
114
+ classificationMixins?: Array<ClassificationMixin>;
115
+ /**
116
+ * Custom category attributes included directly in the mixins object.
117
+ */
118
+ mixins?: {
119
+ [key: string]: unknown;
120
+ };
121
+ metadata: MetadataResponse;
122
+ media: Array<Media>;
123
+ };
124
+ /**
125
+ * Definition of category tree
126
+ */
127
+ type CategoryTree = {
128
+ /**
129
+ * Category unique identifier generated when the category is created.
130
+ */
131
+ id: string;
132
+ /**
133
+ * Category name in tenant default language.
134
+ * @deprecated
135
+ */
136
+ name: string;
137
+ /**
138
+ * Description in tenant default language.
139
+ * @deprecated
140
+ */
141
+ description?: string;
142
+ /**
143
+ * Unique category identifier defined by the tenant.
144
+ * @deprecated
145
+ */
146
+ code?: string;
147
+ /**
148
+ * Localized category name as a map of translations.
149
+ */
150
+ localizedName: {
151
+ [key: string]: string;
152
+ };
153
+ /**
154
+ * Localized category description as a map of translations.
155
+ */
156
+ localizedDescription?: {
157
+ [key: string]: string;
158
+ };
159
+ /**
160
+ * Provides localized category name or code without diacritics for the URL.
161
+ */
162
+ localizedSlug?: {
163
+ [key: string]: string;
164
+ };
165
+ validity?: Validity;
166
+ /**
167
+ * Category position in relation to sibling categories.
168
+ */
169
+ position: number;
170
+ /**
171
+ * Flag indicating whether the category has been published.
172
+ */
173
+ published: boolean;
174
+ /**
175
+ * List of external category numbers (ECNs) unique for each category.
176
+ */
177
+ ecn?: Array<string>;
178
+ /**
179
+ * Subcategories of this category.
180
+ */
181
+ subcategories?: Array<CategoryTree>;
182
+ };
183
+ type Media = {
184
+ /**
185
+ * Unique identifier of media.
186
+ */
187
+ id?: string;
188
+ /**
189
+ * Url of the file.
190
+ */
191
+ url?: string;
192
+ /**
193
+ * Content type of the file.
194
+ */
195
+ contentType?: string;
196
+ metadata?: MediaMetadataQueryDocument & unknown;
197
+ customAttributes?: MediaCustomAttributesQueryDocument & unknown;
198
+ };
199
+ /**
200
+ * Custom attributes of the file.
201
+ */
202
+ type MediaCustomAttributesQueryDocument = {
203
+ /**
204
+ * Unique identifier of media's custom attributes.
205
+ */
206
+ id?: string;
207
+ /**
208
+ * Height of the media image.
209
+ */
210
+ height?: number;
211
+ /**
212
+ * Width of the media image.
213
+ */
214
+ width?: number;
215
+ /**
216
+ * Size in kilobytes of the file.
217
+ */
218
+ sizeKB?: number;
219
+ /**
220
+ * Mime type of the file.
221
+ */
222
+ type?: string;
223
+ /**
224
+ * Name of the file.
225
+ */
226
+ name?: string;
227
+ };
228
+ /**
229
+ * Metadata of the file.
230
+ */
231
+ type MediaMetadataQueryDocument = {
232
+ /**
233
+ * Timestamp indicating when the media was created compliant with the ISO 8601 standard.
234
+ */
235
+ createdAt?: string;
236
+ /**
237
+ * Timestamp indicating when the media was modified compliant with the ISO 8601 standard.
238
+ */
239
+ modifiedAt?: string;
240
+ };
241
+ type MetadataCreate = {
242
+ /**
243
+ * A key-value map, where key is a mixin name and value is a link to the mixin schema.
244
+ */
245
+ mixins?: {
246
+ [key: string]: string;
247
+ };
248
+ };
249
+ type MetadataUpdate = {
250
+ /**
251
+ * Category version.
252
+ */
253
+ version?: number;
254
+ } & MetadataCreate;
255
+ type MetadataResponse = {
256
+ /**
257
+ * Timestamp indicating when the category was created compliant with the ISO 8601 standard.
258
+ */
259
+ createdAt?: string;
260
+ /**
261
+ * Timestamp indicating when the category was last modified compliant with the ISO 8601 standard.
262
+ */
263
+ modifiedAt?: string;
264
+ } & MetadataUpdate;
265
+ type Validity = {
266
+ /**
267
+ * Date and time from which the category is valid compliant with the ISO 8601 standard.
268
+ */
269
+ from?: string;
270
+ /**
271
+ * Date and time to which the category is valid compliant with the ISO 8601 standard.
272
+ */
273
+ to?: string;
274
+ };
275
+
276
+ /** A category as returned by the Category service (all generated fields). */
277
+ type Category = Category$1;
278
+ /** The category tree as returned by the Category service. */
279
+ type CategoryNode = CategoryTree;
280
+ /** Category reads. Default auth: anonymous. */
281
+ declare class CategoryService {
282
+ private readonly ctx;
283
+ constructor(ctx: ClientContext);
284
+ /** Fetches one category by id. */
285
+ get(categoryId: string, auth?: AuthContext): Promise<Category>;
286
+ /** One page of categories. */
287
+ list(params?: {
288
+ pageNumber?: number;
289
+ pageSize?: number;
290
+ }, auth?: AuthContext): Promise<PaginatedItems<Category>>;
291
+ /** Async-iterates every category across pages. */
292
+ listAll(params?: {
293
+ pageSize?: number;
294
+ }, auth?: AuthContext): AsyncIterable<Category>;
295
+ /** Fetches the category tree, optionally rooted at `rootId`. */
296
+ tree(rootId?: string, auth?: AuthContext): Promise<CategoryNode>;
297
+ /** One page of products in a category. */
298
+ productsIn(categoryId: string, params?: {
299
+ pageNumber?: number;
300
+ pageSize?: number;
301
+ }, auth?: AuthContext): Promise<PaginatedItems<Product>>;
302
+ /**
303
+ * Bulk fetch by id. POSTs `/categories/search` with `q="id:(id1,id2,…)"`,
304
+ * chunking when the list is larger than `options.chunkSize` (default
305
+ * 100). An empty list short-circuits with no HTTP call. **Order is not
306
+ * guaranteed** across chunks — re-index by `id` if order matters.
307
+ */
308
+ searchByIds(ids: string[], options?: {
309
+ chunkSize?: number;
310
+ }, auth?: AuthContext): Promise<Category[]>;
311
+ }
312
+
313
+ export { type Category, type CategoryNode, CategoryService };
@@ -0,0 +1,4 @@
1
+ export { CategoryService } from './chunk-4BJUCCKJ.js';
2
+ import './chunk-GWJ2U2CP.js';
3
+ //# sourceMappingURL=category.js.map
4
+ //# sourceMappingURL=category.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"category.js"}
@@ -0,0 +1,98 @@
1
+ 'use strict';
2
+
3
+ // src/core/errors.ts
4
+ var REDACTED_BODY_KEYS = /* @__PURE__ */ new Set([
5
+ "access_token",
6
+ "refresh_token",
7
+ "token",
8
+ "customertoken",
9
+ "saastoken",
10
+ "secret",
11
+ "client_secret",
12
+ "authorization",
13
+ "password"
14
+ ]);
15
+ function scrub(body) {
16
+ if (Array.isArray(body)) return body.map(scrub);
17
+ if (body && typeof body === "object") {
18
+ const out = {};
19
+ for (const [k, v] of Object.entries(body)) {
20
+ out[k] = REDACTED_BODY_KEYS.has(k.toLowerCase()) ? "***redacted***" : scrub(v);
21
+ }
22
+ return out;
23
+ }
24
+ return body;
25
+ }
26
+ var EmporixError = class extends Error {
27
+ status;
28
+ body;
29
+ constructor(message, status, body) {
30
+ super(message);
31
+ this.name = new.target.name;
32
+ this.status = status;
33
+ this.body = body;
34
+ Object.setPrototypeOf(this, new.target.prototype);
35
+ }
36
+ /** Safe serialisation — token-like body fields are redacted. */
37
+ toJSON() {
38
+ return { name: this.name, message: this.message, status: this.status, body: scrub(this.body) };
39
+ }
40
+ };
41
+ var EmporixAuthError = class extends EmporixError {
42
+ };
43
+
44
+ // src/services/checkout.ts
45
+ function isGuest(customer) {
46
+ return customer?.guest === true;
47
+ }
48
+ function resolveAuth(auth, guest) {
49
+ if (auth && (auth.kind === "customer" || auth.kind === "raw")) return auth;
50
+ if (guest && auth && auth.kind === "anonymous") return auth;
51
+ throw new EmporixAuthError(
52
+ "checkout requires a customer/raw AuthContext (or anonymous for a guest checkout)"
53
+ );
54
+ }
55
+ var CheckoutService = class {
56
+ constructor(ctx) {
57
+ this.ctx = ctx;
58
+ }
59
+ ctx;
60
+ headers(opts, guest) {
61
+ if (guest || !opts.saasToken) return void 0;
62
+ return { "saas-token": opts.saasToken };
63
+ }
64
+ query(opts) {
65
+ return opts.siteCode ? { siteCode: opts.siteCode } : void 0;
66
+ }
67
+ /** Checkout from a cart. Requires customer/raw auth (or anonymous for guest). */
68
+ async placeOrder(input, auth, opts = {}) {
69
+ const guest = isGuest(input.customer);
70
+ const headers = this.headers(opts, guest);
71
+ const query = this.query(opts);
72
+ return this.ctx.http.request({
73
+ method: "POST",
74
+ path: `/checkout/${this.ctx.tenant}/checkouts/order`,
75
+ auth: resolveAuth(auth, guest),
76
+ ...query ? { query } : {},
77
+ ...headers ? { headers } : {},
78
+ body: input
79
+ });
80
+ }
81
+ /** Checkout from a quote. */
82
+ async placeOrderFromQuote(input, auth, opts = {}) {
83
+ const headers = this.headers(opts, false);
84
+ const query = this.query(opts);
85
+ return this.ctx.http.request({
86
+ method: "POST",
87
+ path: `/checkout/${this.ctx.tenant}/checkouts/order`,
88
+ auth: resolveAuth(auth, false),
89
+ ...query ? { query } : {},
90
+ ...headers ? { headers } : {},
91
+ body: input
92
+ });
93
+ }
94
+ };
95
+
96
+ exports.CheckoutService = CheckoutService;
97
+ //# sourceMappingURL=checkout.cjs.map
98
+ //# sourceMappingURL=checkout.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/errors.ts","../src/services/checkout.ts"],"names":[],"mappings":";;;AACA,IAAM,kBAAA,uBAAyB,GAAA,CAAI;AAAA,EACjC,cAAA;AAAA,EAAgB,eAAA;AAAA,EAAiB,OAAA;AAAA,EAAS,eAAA;AAAA,EAAiB,WAAA;AAAA,EAC3D,QAAA;AAAA,EAAU,eAAA;AAAA,EAAiB,eAAA;AAAA,EAAiB;AAC9C,CAAC,CAAA;AAED,SAAS,MAAM,IAAA,EAAwB;AACrC,EAAA,IAAI,MAAM,OAAA,CAAQ,IAAI,GAAG,OAAO,IAAA,CAAK,IAAI,KAAK,CAAA;AAC9C,EAAA,IAAI,IAAA,IAAQ,OAAO,IAAA,KAAS,QA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GAAQ,EAAE,KAAA,KAAU,EAAC;AAAA,MACzB,GAAI,OAAA,GAAU,EAAE,OAAA,KAAY,EAAC;AAAA,MAC7B,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AAAA;AAAA,EAGA,MAAM,mBAAA,CACJ,KAAA,EACA,IAAA,EACA,IAAA,GAAwB,EAAC,EACA;AACzB,IAAA,MAAM,OAAA,GAAU,IAAA,CAAK,OAAA,CAAQ,IAAA,EAAM,KAAK,CAAA;AACxC,IAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,KAAA,CAAM,IAAI,CAAA;AAC7B,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAwB;AAAA,MAC3C,MAAA,EAAQ,MAAA;AAAA,MACR,IAAA,EAAM,CAAA,UAAA,EAAa,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA,gBAAA,CAAA;AAAA,MAClC,IAAA,EAAM,WAAA,CAAY,IAAA,EAAM,KAAK,CAAA;AAAA,MAC7B,GAAI,KAAA,GAAQ,EAAE,KAAA,KAAU,EAAC;AAAA,MACzB,GAAI,OAAA,GAAU,EAAE,OAAA,KAAY,EAAC;AAAA,MAC7B,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACF","file":"checkout.cjs","sourcesContent":["/** Keys whose values are stripped from any serialised error body. */\nconst REDACTED_BODY_KEYS = new Set([\n \"access_token\", \"refresh_token\", \"token\", \"customertoken\", \"saastoken\",\n \"secret\", \"client_secret\", \"authorization\", \"password\",\n]);\n\nfunction scrub(body: unknown): unknown {\n if (Array.isArray(body)) return body.map(scrub);\n if (body && typeof body === \"object\") {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(body as Record<string, unknown>)) {\n out[k] = REDACTED_BODY_KEYS.has(k.toLowerCase()) ? \"***redacted***\" : scrub(v);\n }\n return out;\n }\n return body;\n}\n\n/** Base class for every error thrown by the SDK. */\nexport class EmporixError extends Error {\n readonly status: number | undefined;\n readonly body: unknown;\n constructor(message: string, status?: number, body?: unknown) {\n super(message);\n this.name = new.target.name;\n this.status = status;\n this.body = body;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n /** Safe serialisation — token-like body fields are redacted. */\n toJSON(): Record<string, unknown> {\n return { name: this.name, message: this.message, status: this.status, body: scrub(this.body) };\n }\n}\n\n/** 401 — authentication failed or token expired. */\nexport class EmporixAuthError extends EmporixError {}\n/** 403 — authenticated but not permitted. */\nexport class EmporixForbiddenError extends EmporixError {}\n/** 404 — resource not found. */\nexport class EmporixNotFoundError extends EmporixError {}\n/** 400/422 — request validation failed. */\nexport class EmporixValidationError extends EmporixError {}\n/** 5xx — server-side failure. */\nexport class EmporixServerError extends EmporixError {}\n\n/**\n * 403 with a `missing scope: <name>` hint in the body's `details` array.\n * Subclasses {@link EmporixForbiddenError} so existing 403 catches still work.\n */\nexport class EmporixInsufficientScopeError extends EmporixForbiddenError {\n readonly requiredScope: string | undefined;\n constructor(message: string, status: number, body: unknown, requiredScope?: string) {\n super(message, status, body);\n this.requiredScope = requiredScope;\n }\n}\n\nconst SCOPE_HINT_RE = /missing scope[: ]+([a-z0-9._-]+)/i;\n\nfunction extractRequiredScope(body: unknown): string | undefined {\n if (body && typeof body === \"object\" && \"details\" in body) {\n const details = (body as { details?: unknown }).details;\n if (Array.isArray(details)) {\n for (const d of details) {\n if (typeof d === \"string\") {\n const m = d.match(SCOPE_HINT_RE);\n if (m) return m[1];\n }\n }\n }\n }\n return undefined;\n}\n\n/** Maps an HTTP status to the matching {@link EmporixError} subclass. */\nexport function errorFromResponse(status: number, message: string, body: unknown): EmporixError {\n if (status === 401) return new EmporixAuthError(message, status, body);\n if (status === 403) {\n const scope = extractRequiredScope(body);\n if (scope) return new EmporixInsufficientScopeError(message, status, body, scope);\n return new EmporixForbiddenError(message, status, body);\n }\n if (status === 404) return new EmporixNotFoundError(message, status, body);\n if (status === 400 || status === 422) return new EmporixValidationError(message, status, body);\n if (status >= 500) return new EmporixServerError(message, status, body);\n return new EmporixError(message, status, body);\n}\n","import type { ClientContext } from \"../core/context\";\nimport type { AuthContext } from \"../core/auth\";\nimport { EmporixAuthError } from \"../core/errors\";\nimport type {\n ResponseCheckout,\n RequestCheckout,\n RequestFromQuoteCheckout,\n CustomerJson,\n} from \"../generated/checkout\";\n\n/** `requestCheckout` body (cart-based, generated). */\nexport type CheckoutInput = RequestCheckout;\n\n/** `requestFromQuoteCheckout` body (quote-based, generated). */\nexport type QuoteCheckoutInput = RequestFromQuoteCheckout;\n\n/** `responseCheckout` — the full generated checkout response. */\nexport type CheckoutResult = ResponseCheckout;\n\n/** Options for a checkout call. */\nexport interface CheckoutOptions {\n /** Customer `saasToken` from `customers.login()` — required for logged-in checkout. */\n saasToken?: string;\n /** Site code (`?siteCode=`). */\n siteCode?: string;\n}\n\nfunction isGuest(customer: CustomerJson | undefined): boolean {\n return customer?.guest === true;\n}\n\nfunction resolveAuth(auth: AuthContext | undefined, guest: boolean): AuthContext {\n if (auth && (auth.kind === \"customer\" || auth.kind === \"raw\")) return auth;\n if (guest && auth && auth.kind === \"anonymous\") return auth;\n throw new EmporixAuthError(\n \"checkout requires a customer/raw AuthContext (or anonymous for a guest checkout)\",\n );\n}\n\n/** Triggers Emporix checkout (atomic: validate → order → payment → close cart). */\nexport class CheckoutService {\n constructor(private readonly ctx: ClientContext) {}\n\n private headers(opts: CheckoutOptions, guest: boolean): Record<string, string> | undefined {\n if (guest || !opts.saasToken) return undefined;\n return { \"saas-token\": opts.saasToken };\n }\n\n private query(opts: CheckoutOptions): Record<string, string> | undefined {\n return opts.siteCode ? { siteCode: opts.siteCode } : undefined;\n }\n\n /** Checkout from a cart. Requires customer/raw auth (or anonymous for guest). */\n async placeOrder(\n input: CheckoutInput,\n auth?: AuthContext,\n opts: CheckoutOptions = {},\n ): Promise<CheckoutResult> {\n const guest = isGuest(input.customer);\n const headers = this.headers(opts, guest);\n const query = this.query(opts);\n return this.ctx.http.request<CheckoutResult>({\n method: \"POST\",\n path: `/checkout/${this.ctx.tenant}/checkouts/order`,\n auth: resolveAuth(auth, guest),\n ...(query ? { query } : {}),\n ...(headers ? { headers } : {}),\n body: input,\n });\n }\n\n /** Checkout from a quote. */\n async placeOrderFromQuote(\n input: QuoteCheckoutInput,\n auth?: AuthContext,\n opts: CheckoutOptions = {},\n ): Promise<CheckoutResult> {\n const headers = this.headers(opts, false);\n const query = this.query(opts);\n return this.ctx.http.request<CheckoutResult>({\n method: \"POST\",\n path: `/checkout/${this.ctx.tenant}/checkouts/order`,\n auth: resolveAuth(auth, false),\n ...(query ? { query } : {}),\n ...(headers ? { headers } : {}),\n body: input,\n });\n }\n}\n"]}
@@ -0,0 +1,252 @@
1
+ import { C as ClientContext, b as AuthContext } from './context-vKgzZ-5f.cjs';
2
+
3
+ /**
4
+ * Information about the customer's address.
5
+ */
6
+ type AddressJson = {
7
+ /**
8
+ * Contact name
9
+ */
10
+ contactName: string;
11
+ /**
12
+ * Company name
13
+ */
14
+ companyName?: string;
15
+ /**
16
+ * Street
17
+ */
18
+ street: string;
19
+ /**
20
+ * Street number
21
+ */
22
+ streetNumber?: string;
23
+ /**
24
+ * Street appendix
25
+ */
26
+ streetAppendix?: string;
27
+ /**
28
+ * zip code
29
+ */
30
+ zipCode: string;
31
+ /**
32
+ * City
33
+ */
34
+ city: string;
35
+ /**
36
+ * Country
37
+ */
38
+ country: string;
39
+ /**
40
+ * State
41
+ */
42
+ state?: string;
43
+ /**
44
+ * Contact phone
45
+ */
46
+ contactPhone?: string;
47
+ /**
48
+ * Type of the address data, for example `BILLING` or `SHIPPING`.
49
+ */
50
+ type: string;
51
+ metadata?: MixinMetadataJson;
52
+ /**
53
+ * Mixins object
54
+ */
55
+ mixins?: {
56
+ [key: string]: unknown;
57
+ };
58
+ };
59
+ /**
60
+ * Information about the customer.
61
+ */
62
+ type CustomerJson = {
63
+ /**
64
+ * Customers’s unique identifier generated when a customer’s account is created. Required only when checkout is done by a logged in customer.
65
+ */
66
+ id?: string;
67
+ /**
68
+ * Name
69
+ */
70
+ name?: string;
71
+ /**
72
+ * Title
73
+ */
74
+ title?: string;
75
+ /**
76
+ * First name. Providing either `firstName` or `lastName` is required.
77
+ */
78
+ firstName?: string;
79
+ /**
80
+ * Middle name
81
+ */
82
+ middleName?: string;
83
+ /**
84
+ * Last name. Providing either `firstName` or `lastName` is required.
85
+ */
86
+ lastName?: string;
87
+ /**
88
+ * Contact phone
89
+ */
90
+ contactPhone?: string;
91
+ /**
92
+ * Email
93
+ */
94
+ email: string;
95
+ /**
96
+ * Company name
97
+ */
98
+ company?: string;
99
+ metadata?: MixinMetadataJson;
100
+ /**
101
+ * Mixins object
102
+ */
103
+ mixins?: {
104
+ [key: string]: unknown;
105
+ };
106
+ /**
107
+ * Indicates if the checkout is done by an anonymous customer (if true) or logged in customer (if false). Required only for guest checkout.
108
+ */
109
+ guest?: boolean;
110
+ };
111
+ type MixinMetadataJson = {
112
+ mixins?: {
113
+ [key: string]: unknown;
114
+ };
115
+ };
116
+ /**
117
+ * Schema for triggering a checkout.
118
+ */
119
+ type RequestCheckout = {
120
+ /**
121
+ * Customer cart’s unique identifier generated when a cart is created.
122
+ */
123
+ cartId: string;
124
+ /**
125
+ * Methods chosen to process the payment for the order.
126
+ */
127
+ paymentMethods: Array<RequestPaymentMethodJson>;
128
+ /**
129
+ * Three-letter currency code, compliant with the ISO 4217 standard.
130
+ */
131
+ currency?: string;
132
+ shipping: ShippingJson;
133
+ /**
134
+ * List of addresses associated with the order. There must be at least one address of type `SHIPPING` and one address of type `BILLING`.
135
+ */
136
+ addresses: Array<AddressJson>;
137
+ customer: CustomerJson;
138
+ };
139
+ /**
140
+ * Schema for triggering a checkout from the quote.
141
+ */
142
+ type RequestFromQuoteCheckout = {
143
+ /**
144
+ * The identifier of the quote.
145
+ */
146
+ quoteId: string;
147
+ /**
148
+ * Methods chosen to process the payment for the order.
149
+ */
150
+ paymentMethods: Array<RequestPaymentMethodJson>;
151
+ /**
152
+ * Delivery window's unique identifier.
153
+ */
154
+ deliveryWindowId?: string;
155
+ };
156
+ type RequestPaymentMethodJson = {
157
+ /**
158
+ * Payment provider, possible values:
159
+ * * `payment-gateway` - When the Emporix Payment-Gateway service should be used to handle a payment. For details about custom attributes that are required for a particular payment mode, check https://developer.emporix.io/user-guides/system-management/payment-gateway/payments.
160
+ * * `custom` - When a custom provider is used. In this case the created order has the `IN_CHECKOUT` status.
161
+ * * `none` - For payment by cash or invoice.
162
+ *
163
+ */
164
+ provider: string;
165
+ /**
166
+ * Additional information about the payment method.
167
+ */
168
+ customAttributes?: {
169
+ /**
170
+ * Payment token used for the tokenized credit card flows. The field is used when provider type is `payment-gateway`. For more details, check https://developer.emporix.io/user-guides/system-management/payment-gateway/payments
171
+ */
172
+ token?: string;
173
+ /**
174
+ * Identifier of a payment mode. The payment mode has to be configured in the Emporix Payment Gateway service beforehand. For more details, check https://developer.emporix.io/user-guides/system-management/payment-gateway/payments
175
+ */
176
+ modeId?: string;
177
+ /**
178
+ * Payment type chosen by the customer, for example `paymentByCredit` or `paymentByDebit`.
179
+ */
180
+ paymentType?: string;
181
+ };
182
+ /**
183
+ * Payment method chosen by the customer, for example `invoice` or `cash-on-delivery`.
184
+ */
185
+ method?: string;
186
+ /**
187
+ * Amount to be paid by the customer.
188
+ */
189
+ amount?: number;
190
+ };
191
+ type ResponseCheckout = {
192
+ /**
193
+ * Order’s unique identifier generated when a checkout is triggered.
194
+ */
195
+ orderId?: string;
196
+ paymentDetails?: {
197
+ [key: string]: unknown;
198
+ } | null;
199
+ checkoutId?: string | null;
200
+ };
201
+ /**
202
+ * Information about the shipping.
203
+ */
204
+ type ShippingJson = {
205
+ /**
206
+ * Shipping method's unique identifier.
207
+ */
208
+ methodId: string;
209
+ /**
210
+ * Shipping zone identifier.
211
+ */
212
+ zoneId: string;
213
+ /**
214
+ * Shipping method chosen by the customer.
215
+ */
216
+ methodName: string;
217
+ /**
218
+ * Shipping cost.
219
+ */
220
+ amount: number;
221
+ /**
222
+ * The tax code of the shipping
223
+ */
224
+ shippingTaxCode?: string;
225
+ };
226
+
227
+ /** `requestCheckout` body (cart-based, generated). */
228
+ type CheckoutInput = RequestCheckout;
229
+ /** `requestFromQuoteCheckout` body (quote-based, generated). */
230
+ type QuoteCheckoutInput = RequestFromQuoteCheckout;
231
+ /** `responseCheckout` — the full generated checkout response. */
232
+ type CheckoutResult = ResponseCheckout;
233
+ /** Options for a checkout call. */
234
+ interface CheckoutOptions {
235
+ /** Customer `saasToken` from `customers.login()` — required for logged-in checkout. */
236
+ saasToken?: string;
237
+ /** Site code (`?siteCode=`). */
238
+ siteCode?: string;
239
+ }
240
+ /** Triggers Emporix checkout (atomic: validate → order → payment → close cart). */
241
+ declare class CheckoutService {
242
+ private readonly ctx;
243
+ constructor(ctx: ClientContext);
244
+ private headers;
245
+ private query;
246
+ /** Checkout from a cart. Requires customer/raw auth (or anonymous for guest). */
247
+ placeOrder(input: CheckoutInput, auth?: AuthContext, opts?: CheckoutOptions): Promise<CheckoutResult>;
248
+ /** Checkout from a quote. */
249
+ placeOrderFromQuote(input: QuoteCheckoutInput, auth?: AuthContext, opts?: CheckoutOptions): Promise<CheckoutResult>;
250
+ }
251
+
252
+ export { type CheckoutInput, type CheckoutOptions, type CheckoutResult, CheckoutService, type QuoteCheckoutInput };