@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,252 @@
1
+ import { C as ClientContext, b as AuthContext } from './context-vKgzZ-5f.js';
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 };
@@ -0,0 +1,4 @@
1
+ export { CheckoutService } from './chunk-OMYVOOSX.js';
2
+ import './chunk-KTODT6DV.js';
3
+ //# sourceMappingURL=checkout.js.map
4
+ //# sourceMappingURL=checkout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"checkout.js"}
@@ -0,0 +1,86 @@
1
+ import { iterateAll } from './chunk-GWJ2U2CP.js';
2
+
3
+ // src/services/category.ts
4
+ var ANON = { kind: "anonymous" };
5
+ var CategoryService = class {
6
+ constructor(ctx) {
7
+ this.ctx = ctx;
8
+ }
9
+ ctx;
10
+ /** Fetches one category by id. */
11
+ async get(categoryId, auth = ANON) {
12
+ return this.ctx.http.request({
13
+ method: "GET",
14
+ path: `/category/${this.ctx.tenant}/categories/${categoryId}`,
15
+ auth
16
+ });
17
+ }
18
+ /** One page of categories. */
19
+ async list(params = {}, auth = ANON) {
20
+ const pageNumber = params.pageNumber ?? 1;
21
+ const pageSize = params.pageSize ?? 50;
22
+ const items = await this.ctx.http.request({
23
+ method: "GET",
24
+ path: `/category/${this.ctx.tenant}/categories`,
25
+ query: { pageNumber, pageSize },
26
+ auth
27
+ });
28
+ return { items, pageNumber, pageSize, hasNextPage: items.length === pageSize };
29
+ }
30
+ /** Async-iterates every category across pages. */
31
+ listAll(params = {}, auth = ANON) {
32
+ const pageSize = params.pageSize ?? 50;
33
+ return iterateAll((pageNumber) => this.list({ pageNumber, pageSize }, auth));
34
+ }
35
+ /** Fetches the category tree, optionally rooted at `rootId`. */
36
+ async tree(rootId, auth = ANON) {
37
+ return this.ctx.http.request({
38
+ method: "GET",
39
+ path: `/category/${this.ctx.tenant}/categories/tree`,
40
+ query: rootId ? { rootId } : {},
41
+ auth
42
+ });
43
+ }
44
+ /** One page of products in a category. */
45
+ async productsIn(categoryId, params = {}, auth = ANON) {
46
+ const pageNumber = params.pageNumber ?? 1;
47
+ const pageSize = params.pageSize ?? 50;
48
+ const items = await this.ctx.http.request({
49
+ method: "GET",
50
+ path: `/category/${this.ctx.tenant}/categories/${categoryId}/products`,
51
+ query: { pageNumber, pageSize },
52
+ auth
53
+ });
54
+ return { items, pageNumber, pageSize, hasNextPage: items.length === pageSize };
55
+ }
56
+ /**
57
+ * Bulk fetch by id. POSTs `/categories/search` with `q="id:(id1,id2,…)"`,
58
+ * chunking when the list is larger than `options.chunkSize` (default
59
+ * 100). An empty list short-circuits with no HTTP call. **Order is not
60
+ * guaranteed** across chunks — re-index by `id` if order matters.
61
+ */
62
+ async searchByIds(ids, options = {}, auth = ANON) {
63
+ if (ids.length === 0) return [];
64
+ const chunkSize = options.chunkSize ?? 100;
65
+ const chunks = [];
66
+ for (let i = 0; i < ids.length; i += chunkSize) {
67
+ chunks.push(ids.slice(i, i + chunkSize));
68
+ }
69
+ const pages = await Promise.all(
70
+ chunks.map(
71
+ (chunk) => this.ctx.http.request({
72
+ method: "POST",
73
+ path: `/category/${this.ctx.tenant}/categories/search`,
74
+ query: { pageSize: chunk.length },
75
+ auth,
76
+ body: { q: `id:(${chunk.join(",")})` }
77
+ })
78
+ )
79
+ );
80
+ return pages.flat();
81
+ }
82
+ };
83
+
84
+ export { CategoryService };
85
+ //# sourceMappingURL=chunk-4BJUCCKJ.js.map
86
+ //# sourceMappingURL=chunk-4BJUCCKJ.js.map
@@ -0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AoB,IAAA,EACC;AACrB,IAAA,IAAI,GAAA,CAAI,MAAA,KAAW,CAAA,EAAG,OAAO,EAAC;AAC9B,IAAA,MAAM,SAAA,GAAY,QAAQ,SAAA,IAAa,GAAA;AACvC,IAAA,MAAM,SAAqB,EAAC;AAC5B,IAAA,KAAA,IAAS,IAAI,CAAA,EAAG,CAAA,GAAI,GAAA,CAAI,MAAA,EAAQ,KAAK,SAAA,EAAW;AAC9C,MAAA,MAAA,CAAO,KAAK,GAAA,CAAI,KAAA,CAAM,CAAA,EAAG,CAAA,GAAI,SAAS,CAAC,CAAA;AAAA,IACzC;AACA,IAAA,MAAM,KAAA,GAAQ,MAAM,OAAA,CAAQ,GAAA;AAAA,MAC1B,MAAA,CAAO,GAAA;AAAA,QAAI,CAAC,KAAA,KACV,IAAA,CAAK,GAAA,CAAI,KAAK,OAAA,CAAoB;AAAA,UAChC,MAAA,EAAQ,MAAA;AAAA,UACR,IAAA,EAAM,CAAA,UAAA,EAAa,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA,kBAAA,CAAA;AAAA,UAClC,KAAA,EAAO,EAAE,QAAA,EAAU,KAAA,CAAM,MAAA,EAAO;AAAA,UAChC,IAAA;AAAA,UACA,IAAA,EAAM,EAAE,CAAA,EAAG,CAAA,IAAA,EAAO,MAAM,IAAA,CAAK,GAAG,CAAC,CAAA,CAAA,CAAA;AAAI,SACtC;AAAA;AACH,KACF;AACA,IAAA,OAAO,MAAM,IAAA,EAAK;AAAA,EACpB;AACF","file":"chunk-4BJUCCKJ.js","sourcesContent":["import type { ClientContext, PaginatedItems } from \"../core/context\";\nimport { iterateAll } from \"../core/context\";\nimport type { AuthContext } from \"../core/auth\";\nimport type { Product } from \"./product\";\nimport type { Category as GeneratedCategory, CategoryTree } from \"../generated/category\";\n\nconst ANON: AuthContext = { kind: \"anonymous\" };\n\n/** A category as returned by the Category service (all generated fields). */\nexport type Category = GeneratedCategory;\n\n/** The category tree as returned by the Category service. */\nexport type CategoryNode = CategoryTree;\n\n/** Category reads. Default auth: anonymous. */\nexport class CategoryService {\n constructor(private readonly ctx: ClientContext) {}\n\n /** Fetches one category by id. */\n async get(categoryId: string, auth: AuthContext = ANON): Promise<Category> {\n return this.ctx.http.request<Category>({\n method: \"GET\",\n path: `/category/${this.ctx.tenant}/categories/${categoryId}`,\n auth,\n });\n }\n\n /** One page of categories. */\n async list(\n params: { pageNumber?: number; pageSize?: number } = {},\n auth: AuthContext = ANON,\n ): Promise<PaginatedItems<Category>> {\n const pageNumber = params.pageNumber ?? 1;\n const pageSize = params.pageSize ?? 50;\n const items = await this.ctx.http.request<Category[]>({\n method: \"GET\",\n path: `/category/${this.ctx.tenant}/categories`,\n query: { pageNumber, pageSize },\n auth,\n });\n return { items, pageNumber, pageSize, hasNextPage: items.length === pageSize };\n }\n\n /** Async-iterates every category across pages. */\n listAll(params: { pageSize?: number } = {}, auth: AuthContext = ANON): AsyncIterable<Category> {\n const pageSize = params.pageSize ?? 50;\n return iterateAll<Category>((pageNumber) => this.list({ pageNumber, pageSize }, auth));\n }\n\n /** Fetches the category tree, optionally rooted at `rootId`. */\n async tree(rootId?: string, auth: AuthContext = ANON): Promise<CategoryNode> {\n return this.ctx.http.request<CategoryNode>({\n method: \"GET\",\n path: `/category/${this.ctx.tenant}/categories/tree`,\n query: rootId ? { rootId } : {},\n auth,\n });\n }\n\n /** One page of products in a category. */\n async productsIn(\n categoryId: string,\n params: { pageNumber?: number; pageSize?: number } = {},\n auth: AuthContext = ANON,\n ): Promise<PaginatedItems<Product>> {\n const pageNumber = params.pageNumber ?? 1;\n const pageSize = params.pageSize ?? 50;\n const items = await this.ctx.http.request<Product[]>({\n method: \"GET\",\n path: `/category/${this.ctx.tenant}/categories/${categoryId}/products`,\n query: { pageNumber, pageSize },\n auth,\n });\n return { items, pageNumber, pageSize, hasNextPage: items.length === pageSize };\n }\n\n /**\n * Bulk fetch by id. POSTs `/categories/search` with `q=\"id:(id1,id2,…)\"`,\n * chunking when the list is larger than `options.chunkSize` (default\n * 100). An empty list short-circuits with no HTTP call. **Order is not\n * guaranteed** across chunks — re-index by `id` if order matters.\n */\n async searchByIds(\n ids: string[],\n options: { chunkSize?: number } = {},\n auth: AuthContext = ANON,\n ): Promise<Category[]> {\n if (ids.length === 0) return [];\n const chunkSize = options.chunkSize ?? 100;\n const chunks: string[][] = [];\n for (let i = 0; i < ids.length; i += chunkSize) {\n chunks.push(ids.slice(i, i + chunkSize));\n }\n const pages = await Promise.all(\n chunks.map((chunk) =>\n this.ctx.http.request<Category[]>({\n method: \"POST\",\n path: `/category/${this.ctx.tenant}/categories/search`,\n query: { pageSize: chunk.length },\n auth,\n body: { q: `id:(${chunk.join(\",\")})` },\n }),\n ),\n );\n return pages.flat();\n }\n}\n"]}
@@ -0,0 +1,95 @@
1
+ // src/services/orders.ts
2
+ function setIfDefined(q, key, value) {
3
+ if (value !== void 0 && value !== "") {
4
+ q[key] = value;
5
+ }
6
+ }
7
+ var OrdersService = class {
8
+ constructor(ctx) {
9
+ this.ctx = ctx;
10
+ }
11
+ ctx;
12
+ base() {
13
+ return `/order-v2/${this.ctx.tenant}/orders`;
14
+ }
15
+ saasHeader(saasToken) {
16
+ return saasToken ? { "saas-token": saasToken } : void 0;
17
+ }
18
+ /** Lists the calling customer's orders. */
19
+ async listMine(auth, opts = {}) {
20
+ const query = {};
21
+ setIfDefined(query, "pageNumber", opts.pageNumber);
22
+ setIfDefined(query, "pageSize", opts.pageSize);
23
+ setIfDefined(query, "status", opts.status);
24
+ setIfDefined(query, "legalEntityId", opts.legalEntityId);
25
+ setIfDefined(query, "siteCode", opts.siteCode);
26
+ const headers = this.saasHeader(opts.saasToken);
27
+ return this.ctx.http.request({
28
+ method: "GET",
29
+ path: this.base(),
30
+ query,
31
+ auth,
32
+ ...headers ? { headers } : {}
33
+ });
34
+ }
35
+ /** Fetches one of the calling customer's orders by id. */
36
+ async get(orderId, auth, opts = {}) {
37
+ const headers = this.saasHeader(opts.saasToken);
38
+ return this.ctx.http.request({
39
+ method: "GET",
40
+ path: `${this.base()}/${orderId}`,
41
+ auth,
42
+ ...headers ? { headers } : {}
43
+ });
44
+ }
45
+ /** Transitions an order to a new status. Server enforces legal transitions. */
46
+ async transition(orderId, status, auth, opts = {}) {
47
+ const body = { status };
48
+ if (opts.comment !== void 0) body.comment = opts.comment;
49
+ const headers = this.saasHeader(opts.saasToken);
50
+ await this.ctx.http.request({
51
+ method: "POST",
52
+ path: `${this.base()}/${orderId}/transitions`,
53
+ auth,
54
+ body,
55
+ ...headers ? { headers } : {}
56
+ });
57
+ }
58
+ /** Convenience: transitions to `DECLINED` (customer cancel). */
59
+ async cancel(orderId, auth, opts = {}) {
60
+ await this.transition(orderId, "DECLINED", auth, opts);
61
+ }
62
+ };
63
+ var SalesOrdersService = class {
64
+ constructor(ctx) {
65
+ this.ctx = ctx;
66
+ }
67
+ ctx;
68
+ base() {
69
+ return `/order-v2/${this.ctx.tenant}/salesorders`;
70
+ }
71
+ /** Fetches a single sales-order by id. */
72
+ async get(orderId, auth) {
73
+ return this.ctx.http.request({
74
+ method: "GET",
75
+ path: `${this.base()}/${orderId}`,
76
+ auth
77
+ });
78
+ }
79
+ /** Patches an existing order (status, mixins, customAttributes, metadata). */
80
+ async update(orderId, patch, auth, opts = {}) {
81
+ const query = {};
82
+ if (opts.recalculate === false) query.recalculate = "false";
83
+ return this.ctx.http.request({
84
+ method: "PATCH",
85
+ path: `${this.base()}/${orderId}`,
86
+ auth,
87
+ ...Object.keys(query).length > 0 ? { query } : {},
88
+ body: patch
89
+ });
90
+ }
91
+ };
92
+
93
+ export { OrdersService, SalesOrdersService };
94
+ //# sourceMappingURL=chunk-6UNFMCHZ.js.map
95
+ //# sourceMappingURL=chunk-6UNFMCHZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/services/orders.ts"],"names":[],"mappings":";AAmCA,SAAS,YAAA,CACP,CAAA,EACA,GAAA,EACA,KAAA,EACM;AACN,EAAA,IAAI,KAAA,KAAU,MAAA,I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,EACvD;AACF;AAWO,IAAM,qBAAN,MAAyB;AAAA,EAC9B,YAA6B,GAAA,EAAoB;AAApB,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAAA,EAAqB;AAAA,EAArB,GAAA;AAAA,EAErB,IAAA,GAAe;AACrB,IAAA,OAAO,CAAA,UAAA,EAAa,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA,YAAA,CAAA;AAAA,EACrC;AAAA;AAAA,EAGA,MAAM,GAAA,CAAI,OAAA,EAAiB,IAAA,EAAmC;AAC5D,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAe;AAAA,MAClC,MAAA,EAAQ,KAAA;AAAA,MACR,MAAM,CAAA,EAAG,IAAA,CAAK,IAAA,EAAM,IAAI,OAAO,CAAA,CAAA;AAAA,MAC/B;AAAA,KACD,CAAA;AAAA,EACH;AAAA;AAAA,EAGA,MAAM,MAAA,CACJ,OAAA,EACA,OACA,IAAA,EACA,IAAA,GAAgC,EAAC,EACjB;AAChB,IAAA,MAAM,QAAgC,EAAC;AACvC,IAAA,IAAI,IAAA,CAAK,WAAA,KAAgB,KAAA,EAAO,KAAA,CAAM,WAAA,GAAc,OAAA;AACpD,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,OAAA,CAAe;AAAA,MAClC,MAAA,EAAQ,OAAA;AAAA,MACR,MAAM,CAAA,EAAG,IAAA,CAAK,IAAA,EAAM,IAAI,OAAO,CAAA,CAAA;AAAA,MAC/B,IAAA;AAAA,MACA,GAAI,MAAA,CAAO,IAAA,CAAK,KAAK,CAAA,CAAE,SAAS,CAAA,GAAI,EAAE,KAAA,EAAM,GAAI,EAAC;AAAA,MACjD,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACF","file":"chunk-6UNFMCHZ.js","sourcesContent":["import type { ClientContext, PaginatedItems } from \"../core/context\";\nimport type { AuthContext } from \"../core/auth\";\nimport type {\n Order,\n OrderStatus,\n SalesOrderPatch,\n} from \"../generated/order-v2\";\n\n/** Optional fields supported by the order-v2 list endpoint. */\nexport interface ListMyOrdersOptions {\n pageNumber?: number;\n pageSize?: number;\n status?: OrderStatus;\n legalEntityId?: string;\n siteCode?: string;\n saasToken?: string;\n}\n\n/** Options for single-order reads (saas-token only). */\nexport interface GetOrderOptions {\n saasToken?: string;\n}\n\n/** Options for status transitions. */\nexport interface OrderTransitionOptions {\n saasToken?: string;\n comment?: string;\n}\n\n/** Options for `salesOrders.update`. */\nexport interface UpdateSalesOrderOptions {\n /** Forwarded as `?recalculate=`. Omit to use the server default (true). */\n recalculate?: boolean;\n}\n\nfunction setIfDefined<V>(\n q: Record<string, string | number | undefined>,\n key: string,\n value: V | undefined,\n): void {\n if (value !== undefined && value !== \"\") {\n q[key] = value as unknown as string | number;\n }\n}\n\n/**\n * Storefront-customer access to Order-v2's customer endpoints.\n *\n * `listMine`/`get` require `order.order_read_own`; transitions require\n * `order.order_manage_own`. All methods accept an optional `saasToken` that\n * is passed as the `saas-token` header (mirrors `checkout.placeOrder`).\n */\nexport class OrdersService {\n constructor(private readonly ctx: ClientContext) {}\n\n private base(): string {\n return `/order-v2/${this.ctx.tenant}/orders`;\n }\n\n private saasHeader(saasToken: string | undefined): Record<string, string> | undefined {\n return saasToken ? { \"saas-token\": saasToken } : undefined;\n }\n\n /** Lists the calling customer's orders. */\n async listMine(\n auth: AuthContext,\n opts: ListMyOrdersOptions = {},\n ): Promise<PaginatedItems<Order>> {\n const query: Record<string, string | number | undefined> = {};\n setIfDefined(query, \"pageNumber\", opts.pageNumber);\n setIfDefined(query, \"pageSize\", opts.pageSize);\n setIfDefined(query, \"status\", opts.status);\n setIfDefined(query, \"legalEntityId\", opts.legalEntityId);\n setIfDefined(query, \"siteCode\", opts.siteCode);\n const headers = this.saasHeader(opts.saasToken);\n return this.ctx.http.request<PaginatedItems<Order>>({\n method: \"GET\",\n path: this.base(),\n query,\n auth,\n ...(headers ? { headers } : {}),\n });\n }\n\n /** Fetches one of the calling customer's orders by id. */\n async get(\n orderId: string,\n auth: AuthContext,\n opts: GetOrderOptions = {},\n ): Promise<Order> {\n const headers = this.saasHeader(opts.saasToken);\n return this.ctx.http.request<Order>({\n method: \"GET\",\n path: `${this.base()}/${orderId}`,\n auth,\n ...(headers ? { headers } : {}),\n });\n }\n\n /** Transitions an order to a new status. Server enforces legal transitions. */\n async transition(\n orderId: string,\n status: OrderStatus,\n auth: AuthContext,\n opts: OrderTransitionOptions = {},\n ): Promise<void> {\n const body: { status: OrderStatus; comment?: string } = { status };\n if (opts.comment !== undefined) body.comment = opts.comment;\n const headers = this.saasHeader(opts.saasToken);\n await this.ctx.http.request<void>({\n method: \"POST\",\n path: `${this.base()}/${orderId}/transitions`,\n auth,\n body,\n ...(headers ? { headers } : {}),\n });\n }\n\n /** Convenience: transitions to `DECLINED` (customer cancel). */\n async cancel(\n orderId: string,\n auth: AuthContext,\n opts: { saasToken?: string } = {},\n ): Promise<void> {\n await this.transition(orderId, \"DECLINED\", auth, opts);\n }\n}\n\n/**\n * Backend / service-account access to the merchant-facing\n * `/salesorders/{id}` resource. Requires `order.order_read` (read) /\n * `order.order_manage` (update) scopes on a service token.\n *\n * The full admin list + filter surface is deferred to a follow-up\n * sub-spec. This service ships only single-resource read + patch — the\n * common backend use case (e.g. mixin updates after fulfilment).\n */\nexport class SalesOrdersService {\n constructor(private readonly ctx: ClientContext) {}\n\n private base(): string {\n return `/order-v2/${this.ctx.tenant}/salesorders`;\n }\n\n /** Fetches a single sales-order by id. */\n async get(orderId: string, auth: AuthContext): Promise<Order> {\n return this.ctx.http.request<Order>({\n method: \"GET\",\n path: `${this.base()}/${orderId}`,\n auth,\n });\n }\n\n /** Patches an existing order (status, mixins, customAttributes, metadata). */\n async update(\n orderId: string,\n patch: SalesOrderPatch,\n auth: AuthContext,\n opts: UpdateSalesOrderOptions = {},\n ): Promise<Order> {\n const query: Record<string, string> = {};\n if (opts.recalculate === false) query.recalculate = \"false\";\n return this.ctx.http.request<Order>({\n method: \"PATCH\",\n path: `${this.base()}/${orderId}`,\n auth,\n ...(Object.keys(query).length > 0 ? { query } : {}),\n body: patch,\n });\n }\n}\n"]}
@@ -0,0 +1,49 @@
1
+ // src/services/contacts.ts
2
+ var ContactsService = class {
3
+ constructor(ctx) {
4
+ this.ctx = ctx;
5
+ }
6
+ ctx;
7
+ base() {
8
+ return `/customer-management/${this.ctx.tenant}/contact-assignments`;
9
+ }
10
+ /** Lists contact assignments for one legal entity. */
11
+ async listForCompany(legalEntityId, auth) {
12
+ return this.ctx.http.request({
13
+ method: "GET",
14
+ path: this.base(),
15
+ query: { legalEntityId },
16
+ auth
17
+ });
18
+ }
19
+ /** Creates a contact assignment. */
20
+ async assign(input, auth) {
21
+ return this.ctx.http.request({
22
+ method: "POST",
23
+ path: this.base(),
24
+ auth,
25
+ body: input
26
+ });
27
+ }
28
+ /** Patches a contact assignment. */
29
+ async update(contactAssignmentId, patch, auth) {
30
+ return this.ctx.http.request({
31
+ method: "PATCH",
32
+ path: `${this.base()}/${contactAssignmentId}`,
33
+ auth,
34
+ body: patch
35
+ });
36
+ }
37
+ /** Deletes a contact assignment. */
38
+ async unassign(contactAssignmentId, auth) {
39
+ await this.ctx.http.request({
40
+ method: "DELETE",
41
+ path: `${this.base()}/${contactAssignmentId}`,
42
+ auth
43
+ });
44
+ }
45
+ };
46
+
47
+ export { ContactsService };
48
+ //# sourceMappingURL=chunk-B56JZNI7.js.map
49
+ //# sourceMappingURL=chunk-B56JZNI7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/services/contacts.ts"],"names":[],"mappings":";AAeO,IAAM,kBAAN,MAAsB;AAAA,EAC3B,YAA6B,GAAA,EAAoB;AAApB,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAAA,EAAqB;AAAA,EAArB,GAAA;AAAA,EAErB,IAAA,GAAe;AACrB,IAAA,OAAO,CAAA,qBAAA,EAAwB,IAAA,CAAK,GAAA,CAAI,MAAM,CAAA,oBAAA,C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context\";\nimport type { AuthContext } from \"../core/auth\";\nimport type {\n ContactAssignment,\n ContactAssignmentCreate,\n ContactAssignmentUpdate,\n} from \"../generated/customer-management\";\n\n/**\n * Manages contact assignments linking customers to legal entities.\n *\n * `listForCompany` requires `customermanagement.contactassignment_read`;\n * `assign`/`update`/`unassign` require `_manage`. The query param\n * `legalEntityId` scopes the list to one company.\n */\nexport class ContactsService {\n constructor(private readonly ctx: ClientContext) {}\n\n private base(): string {\n return `/customer-management/${this.ctx.tenant}/contact-assignments`;\n }\n\n /** Lists contact assignments for one legal entity. */\n async listForCompany(legalEntityId: string, auth: AuthContext): Promise<ContactAssignment[]> {\n return this.ctx.http.request<ContactAssignment[]>({\n method: \"GET\",\n path: this.base(),\n query: { legalEntityId },\n auth,\n });\n }\n\n /** Creates a contact assignment. */\n async assign(input: ContactAssignmentCreate, auth: AuthContext): Promise<{ id: string }> {\n return this.ctx.http.request<{ id: string }>({\n method: \"POST\",\n path: this.base(),\n auth,\n body: input,\n });\n }\n\n /** Patches a contact assignment. */\n async update(\n contactAssignmentId: string,\n patch: ContactAssignmentUpdate,\n auth: AuthContext,\n ): Promise<ContactAssignment> {\n return this.ctx.http.request<ContactAssignment>({\n method: \"PATCH\",\n path: `${this.base()}/${contactAssignmentId}`,\n auth,\n body: patch,\n });\n }\n\n /** Deletes a contact assignment. */\n async unassign(contactAssignmentId: string, auth: AuthContext): Promise<void> {\n await this.ctx.http.request<void>({\n method: \"DELETE\",\n path: `${this.base()}/${contactAssignmentId}`,\n auth,\n });\n }\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import { EmporixAuthError } from './chunk-KTODT6DV.js';
2
+
3
+ // src/core/require-customer.ts
4
+ function requireCustomer(auth) {
5
+ if (auth && (auth.kind === "customer" || auth.kind === "raw")) return auth;
6
+ throw new EmporixAuthError("This operation requires a customer or raw AuthContext");
7
+ }
8
+
9
+ export { requireCustomer };
10
+ //# sourceMappingURL=chunk-BFQ732VZ.js.map
11
+ //# sourceMappingURL=chunk-BFQ732VZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/require-customer.ts"],"names":[],"mappings":";;;AASO,SAAS,gBAAgB,IAAA,EAA4C;AAC1E,EAAA,IAAI,SAAS,IAAA,CAAK,IAAA,KAAS,cAAc,IAAA,CAAK,IAAA,KAAS,QAAQ,OAAO,IAAA;AACtE,EAAA,MAAM,IAAI,iBAAiB,uDAAuD,CAAA;AACpF","file":"chunk-BFQ732VZ.js","sourcesContent":["import type { AuthContext } from \"./auth\";\nimport { EmporixAuthError } from \"./errors\";\n\n/**\n * Enforces a caller-owned customer or raw token. Throws `EmporixAuthError`\n * for any other `AuthContext` kind (or when `auth` is missing). Shared by\n * services whose endpoints require a customer scope (`/me`, payments,\n * customer-segments…).\n */\nexport function requireCustomer(auth: AuthContext | undefined): AuthContext {\n if (auth && (auth.kind === \"customer\" || auth.kind === \"raw\")) return auth;\n throw new EmporixAuthError(\"This operation requires a customer or raw AuthContext\");\n}\n"]}
@@ -0,0 +1,120 @@
1
+ // src/services/media.ts
2
+ var SERVICE = { kind: "service" };
3
+ function isProductRef(r, productId) {
4
+ return r.type === "PRODUCT" && r.id === productId;
5
+ }
6
+ var MediaService = class {
7
+ constructor(ctx) {
8
+ this.ctx = ctx;
9
+ }
10
+ ctx;
11
+ base() {
12
+ return `/media/${this.ctx.tenant}/assets`;
13
+ }
14
+ /** Create an asset. BLOB uploads via multipart; LINK via JSON. */
15
+ async create(input, auth = SERVICE) {
16
+ if (input.kind === "blob") {
17
+ const fd = new FormData();
18
+ fd.set("file", input.file);
19
+ fd.set("body", JSON.stringify(input.body));
20
+ return this.ctx.http.request({
21
+ method: "POST",
22
+ path: this.base(),
23
+ auth,
24
+ body: fd
25
+ });
26
+ }
27
+ return this.ctx.http.request({
28
+ method: "POST",
29
+ path: this.base(),
30
+ auth,
31
+ body: input.body
32
+ });
33
+ }
34
+ /** List assets. Optional `query` is passed through to Emporix verbatim. */
35
+ async list(query, auth = SERVICE) {
36
+ return this.ctx.http.request({
37
+ method: "GET",
38
+ path: this.base(),
39
+ auth,
40
+ ...query ? { query } : {}
41
+ });
42
+ }
43
+ /** Fetch an asset by id. */
44
+ async get(assetId, auth = SERVICE) {
45
+ return this.ctx.http.request({
46
+ method: "GET",
47
+ path: `${this.base()}/${assetId}`,
48
+ auth
49
+ });
50
+ }
51
+ /** Update an asset (e.g. swap `refIds` or `access`). */
52
+ async update(assetId, patch, auth = SERVICE) {
53
+ return this.ctx.http.request({
54
+ method: "PUT",
55
+ path: `${this.base()}/${assetId}`,
56
+ auth,
57
+ body: patch
58
+ });
59
+ }
60
+ /** Remove an asset. */
61
+ async remove(assetId, auth = SERVICE) {
62
+ await this.ctx.http.request({
63
+ method: "DELETE",
64
+ path: `${this.base()}/${assetId}`,
65
+ auth
66
+ });
67
+ }
68
+ /** Multipart upload sugar: builds `AssetCreateBlob` from input. */
69
+ async uploadFile(input, auth = SERVICE) {
70
+ const body = {
71
+ type: "BLOB",
72
+ access: input.access ?? "PUBLIC",
73
+ ...input.productId ? { refIds: [{ type: "PRODUCT", id: input.productId }] } : {},
74
+ ...input.filename || input.mimeType ? {
75
+ details: {
76
+ ...input.filename ? { filename: input.filename } : {},
77
+ ...input.mimeType ? { mimeType: input.mimeType } : {}
78
+ }
79
+ } : {}
80
+ };
81
+ return this.create({ kind: "blob", file: input.file, body }, auth);
82
+ }
83
+ /** External-URL sugar: builds `AssetCreateLink`. */
84
+ async link(input, auth = SERVICE) {
85
+ const body = {
86
+ type: "LINK",
87
+ access: input.access ?? "PUBLIC",
88
+ url: input.url,
89
+ ...input.productId ? { refIds: [{ type: "PRODUCT", id: input.productId }] } : {}
90
+ };
91
+ return this.create({ kind: "link", body }, auth);
92
+ }
93
+ /** Idempotently add a PRODUCT refId to an asset. */
94
+ async attachToProduct(assetId, productId, auth = SERVICE) {
95
+ const a = await this.get(assetId, auth);
96
+ const refIds = a.refIds ?? [];
97
+ if (refIds.some((r) => isProductRef(r, productId))) return a;
98
+ const next = [...refIds, { type: "PRODUCT", id: productId }];
99
+ const patch = { type: a.type, refIds: next };
100
+ return this.update(assetId, patch, auth);
101
+ }
102
+ /** Remove a PRODUCT refId from an asset (no-op if absent). */
103
+ async detachFromProduct(assetId, productId, auth = SERVICE) {
104
+ const a = await this.get(assetId, auth);
105
+ const refIds = a.refIds ?? [];
106
+ const next = refIds.filter((r) => !isProductRef(r, productId));
107
+ if (next.length === refIds.length) return a;
108
+ const patch = { type: a.type, refIds: next };
109
+ return this.update(assetId, patch, auth);
110
+ }
111
+ /** Convenience: list assets attached to a product (server-side filter). */
112
+ async listForProduct(productId, auth = SERVICE) {
113
+ return this.list({ "refIds.id": productId }, auth);
114
+ }
115
+ };
116
+ var _internalMedia = { isProductRef };
117
+
118
+ export { MediaService, _internalMedia };
119
+ //# sourceMappingURL=chunk-F3WAQH2E.js.map
120
+ //# sourceMappingURL=chunk-F3WAQH2E.js.map