@viu/emporix-sdk 2.11.0 → 2.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/availability.d.cts +1 -1
- package/dist/availability.d.ts +1 -1
- package/dist/cart.d.cts +1 -1
- package/dist/cart.d.ts +1 -1
- package/dist/category.d.cts +1 -1
- package/dist/category.d.ts +1 -1
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/{chunk-KVBCTXVH.js → chunk-WW3H7VJ5.js} +10 -6
- package/dist/chunk-WW3H7VJ5.js.map +1 -0
- package/dist/companies.d.cts +1 -1
- package/dist/companies.d.ts +1 -1
- package/dist/contacts.d.cts +1 -1
- package/dist/contacts.d.ts +1 -1
- package/dist/{context-CmShWI_R.d.cts → context-CD7F_LHT.d.cts} +10 -0
- package/dist/{context-CmShWI_R.d.ts → context-CD7F_LHT.d.ts} +10 -0
- package/dist/customer-groups.d.cts +1 -1
- package/dist/customer-groups.d.ts +1 -1
- package/dist/customer.d.cts +1 -1
- package/dist/customer.d.ts +1 -1
- package/dist/index.cjs +58 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +52 -27
- package/dist/index.js.map +1 -1
- package/dist/locations.d.cts +1 -1
- package/dist/locations.d.ts +1 -1
- package/dist/media.d.cts +1 -1
- package/dist/media.d.ts +1 -1
- package/dist/orders.cjs +8 -4
- package/dist/orders.cjs.map +1 -1
- package/dist/orders.d.cts +1 -1
- package/dist/orders.d.ts +1 -1
- package/dist/orders.js +1 -1
- package/dist/payment.d.cts +1 -1
- package/dist/payment.d.ts +1 -1
- package/dist/price.d.cts +1 -1
- package/dist/price.d.ts +1 -1
- package/dist/product.d.cts +1 -1
- package/dist/product.d.ts +1 -1
- package/dist/segment.d.cts +1 -1
- package/dist/segment.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-KVBCTXVH.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @viu/emporix-sdk
|
|
2
2
|
|
|
3
|
+
## 2.13.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#121](https://github.com/viuteam/emporix-sdk/pull/121) [`2c58d04`](https://github.com/viuteam/emporix-sdk/commit/2c58d049aacdd7cc2e05e937ef6cb9fc50145c15) Thanks [@amnael1](https://github.com/amnael1)! - Fix customer order history showing no orders. `GET /order-v2/{tenant}/orders` returns a bare JSON array (the total count lives in the `X-Total-Count` header), but `OrdersService.listMine` cast that array straight to `PaginatedItems<Order>` without wrapping it — so at runtime `.items` was `undefined` and `useMyOrders` / `useMyOrdersInfinite` (and any order-history UI) rendered no orders even when the API returned them. `listMine` now normalizes the array into the shared `{ items, pageNumber, pageSize, hasNextPage }` envelope, like every other paginated service.
|
|
8
|
+
|
|
9
|
+
- [#123](https://github.com/viuteam/emporix-sdk/pull/123) [`3d2b047`](https://github.com/viuteam/emporix-sdk/commit/3d2b047c85f0218229c1236faf3e7ec467c2c209) Thanks [@amnael1](https://github.com/amnael1)! - Fix the reward-points balance/summary erroring for customers who have no points. `GET /reward-points/public/customer` (and `…/customer/summary`) is the correct Emporix endpoint, but it answers `404 "No reward points found"` for a signed-in customer who has never earned points — i.e. every customer without a completed order. `rewardPoints.getMyPoints` now maps that 404 to `0`, and `getMySummary` to an empty summary (`{ activePoints: 0, summary: { addedPointsList: [] } }`), so `useMyRewardPoints` / `useMyRewardPointsSummary` resolve cleanly instead of throwing. The admin lookups (`getCustomerPoints` / `getCustomerSummary`) still surface 404s, where a missing customer is a real error.
|
|
10
|
+
|
|
11
|
+
## 2.12.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [#116](https://github.com/viuteam/emporix-sdk/pull/116) [`5411502`](https://github.com/viuteam/emporix-sdk/commit/5411502fdde0737ad457812e28a86c505f938282) Thanks [@amnael1](https://github.com/amnael1)! - Add a runtime language switch. `client.setStorefrontContext({ language })` now sets an `Accept-Language` header on every read. React's `useSiteContext()` exposes `language` + `setLanguage(lang)` (modeled on `setCurrency`), persists the choice via `EmporixStorage` (`emporix.language`), mirrors it into the server session context, and keys localized reads (products, categories, segments, cart, shopping lists, orders) by language so the cache never serves stale-language text. A new `initialLanguage` provider prop seeds the active language.
|
|
16
|
+
|
|
3
17
|
## 2.11.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
package/dist/availability.d.cts
CHANGED
package/dist/availability.d.ts
CHANGED
package/dist/cart.d.cts
CHANGED
package/dist/cart.d.ts
CHANGED
package/dist/category.d.cts
CHANGED
package/dist/category.d.ts
CHANGED
package/dist/checkout.d.cts
CHANGED
package/dist/checkout.d.ts
CHANGED
|
@@ -17,20 +17,24 @@ var OrdersService = class {
|
|
|
17
17
|
}
|
|
18
18
|
/** Lists the calling customer's orders. */
|
|
19
19
|
async listMine(auth, opts = {}) {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const pageNumber = opts.pageNumber ?? 1;
|
|
21
|
+
const pageSize = opts.pageSize ?? 50;
|
|
22
|
+
const query = {
|
|
23
|
+
pageNumber,
|
|
24
|
+
pageSize
|
|
25
|
+
};
|
|
23
26
|
setIfDefined(query, "status", opts.status);
|
|
24
27
|
setIfDefined(query, "legalEntityId", opts.legalEntityId);
|
|
25
28
|
setIfDefined(query, "siteCode", opts.siteCode);
|
|
26
29
|
const headers = this.saasHeader(opts.saasToken);
|
|
27
|
-
|
|
30
|
+
const items = await this.ctx.http.request({
|
|
28
31
|
method: "GET",
|
|
29
32
|
path: this.base(),
|
|
30
33
|
query,
|
|
31
34
|
auth,
|
|
32
35
|
...headers ? { headers } : {}
|
|
33
36
|
});
|
|
37
|
+
return { items, pageNumber, pageSize, hasNextPage: items.length === pageSize };
|
|
34
38
|
}
|
|
35
39
|
/** Fetches one of the calling customer's orders by id. */
|
|
36
40
|
async get(orderId, auth, opts = {}) {
|
|
@@ -91,5 +95,5 @@ var SalesOrdersService = class {
|
|
|
91
95
|
};
|
|
92
96
|
|
|
93
97
|
export { OrdersService, SalesOrdersService };
|
|
94
|
-
//# sourceMappingURL=chunk-
|
|
95
|
-
//# sourceMappingURL=chunk-
|
|
98
|
+
//# sourceMappingURL=chunk-WW3H7VJ5.js.map
|
|
99
|
+
//# sourceMappingURL=chunk-WW3H7VJ5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/orders.ts"],"names":[],"mappings":";AAsCA,SAAS,YAAA,CACP,CAAA,EACA,GAAA,EACA,KAAA,EACM;AACN,EAAA,IAAI,KAAA,KAAU,MAAA,IAAa,KAAA,KAAU,EAAA,EAAI;AACvC,IAAA,CAAA,CAAE,GAAG,CAAA,GAAI,KAAA;AAAA,EACX;AACF;AASO,IAAM,gBAAN,MAAoB;AAAA,EACzB,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,OAAA,CAAA;AAAA,EACrC;AAAA,EAEQ,WAAW,SAAA,EAAmE;AACpF,IAAA,OAAO,SAAA,GAAY,EAAE,YAAA,EAAc,SAAA,EAAU,GAAI,MAAA;AAAA,EACnD;AAAA;AAAA,EAGA,MAAM,QAAA,CACJ,IAAA,EACA,IAAA,GAA4B,EAAC,EACG;AAChC,IAAA,MAAM,UAAA,GAAa,KAAK,UAAA,IAAc,CAAA;AACtC,IAAA,MAAM,QAAA,GAAW,KAAK,QAAA,IAAY,EAAA;AAClC,IAAA,MAAM,KAAA,GAAqD;AAAA,MACzD,UAAA;AAAA,MACA;AAAA,KACF;AACA,IAAA,YAAA,CAAa,KAAA,EAAO,QAAA,EAAU,IAAA,CAAK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AAC;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-WW3H7VJ5.js","sourcesContent":["import type { ClientContext, PaginatedItems } from \"../core/context\";\nimport type { AuthContext } from \"../core/auth\";\nimport type { Order, OrderStatus, OrderUpdateDto } from \"../generated/order-v2\";\n\n/**\n * Salesorder PATCH body. The generated `orderUpdateDto` models a full order\n * (it requires `entries`/`customer`), but `PATCH /salesorders/{id}` accepts a\n * subset — so the SDK exposes a partial of it.\n */\nexport type SalesOrderPatch = Partial<OrderUpdateDto>;\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 pageNumber = opts.pageNumber ?? 1;\n const pageSize = opts.pageSize ?? 50;\n const query: Record<string, string | number | undefined> = {\n pageNumber,\n pageSize,\n };\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 // order-v2 returns a bare JSON array (the total count lives in the\n // X-Total-Count header), not a {items,...} envelope — so wrap it into the\n // shared PaginatedItems shape like every other paginated service.\n // hasNextPage is inferred from the page being full.\n const items = await this.ctx.http.request<Order[]>({\n method: \"GET\",\n path: this.base(),\n query,\n auth,\n ...(headers ? { headers } : {}),\n });\n return { items, pageNumber, pageSize, hasNextPage: items.length === pageSize };\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"]}
|
package/dist/companies.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ClientContext, b as AuthContext } from './context-
|
|
1
|
+
import { C as ClientContext, b as AuthContext } from './context-CD7F_LHT.cjs';
|
|
2
2
|
import { L as LegalEntity, e as LegalEntityCreate, f as LegalEntityUpdate } from './types.gen-C_wOXYZB.cjs';
|
|
3
3
|
export { A as AccountLimit, d as CustomerGroup, g as LegalInfo } from './types.gen-C_wOXYZB.cjs';
|
|
4
4
|
|
package/dist/companies.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ClientContext, b as AuthContext } from './context-
|
|
1
|
+
import { C as ClientContext, b as AuthContext } from './context-CD7F_LHT.js';
|
|
2
2
|
import { L as LegalEntity, e as LegalEntityCreate, f as LegalEntityUpdate } from './types.gen-C_wOXYZB.js';
|
|
3
3
|
export { A as AccountLimit, d as CustomerGroup, g as LegalInfo } from './types.gen-C_wOXYZB.js';
|
|
4
4
|
|
package/dist/contacts.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ClientContext, b as AuthContext } from './context-
|
|
1
|
+
import { C as ClientContext, b as AuthContext } from './context-CD7F_LHT.cjs';
|
|
2
2
|
import { C as ContactAssignment, a as ContactAssignmentCreate, b as ContactAssignmentUpdate } from './types.gen-C_wOXYZB.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
package/dist/contacts.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ClientContext, b as AuthContext } from './context-
|
|
1
|
+
import { C as ClientContext, b as AuthContext } from './context-CD7F_LHT.js';
|
|
2
2
|
import { C as ContactAssignment, a as ContactAssignmentCreate, b as ContactAssignmentUpdate } from './types.gen-C_wOXYZB.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -93,6 +93,7 @@ interface StorefrontCredentials {
|
|
|
93
93
|
currency?: string;
|
|
94
94
|
siteCode?: string;
|
|
95
95
|
targetLocation?: string;
|
|
96
|
+
language?: string;
|
|
96
97
|
};
|
|
97
98
|
}
|
|
98
99
|
/** User-supplied SDK configuration. */
|
|
@@ -335,12 +336,21 @@ interface HttpClientOptions {
|
|
|
335
336
|
sleep?: (ms: number) => Promise<void>;
|
|
336
337
|
/** Opt-in customer-token refresher registry (off unless a refresher is set). */
|
|
337
338
|
customerRefresh?: CustomerRefreshRegistry;
|
|
339
|
+
/**
|
|
340
|
+
* Shared storefront request context. When `language` is set, every request
|
|
341
|
+
* carries `Accept-Language: <language>`. Mutated at runtime via
|
|
342
|
+
* `EmporixClient.setStorefrontContext({ language })`.
|
|
343
|
+
*/
|
|
344
|
+
requestContext?: {
|
|
345
|
+
language?: string | undefined;
|
|
346
|
+
};
|
|
338
347
|
}
|
|
339
348
|
/** Fetch wrapper: auth resolution, JSON parsing, typed error mapping, logging. */
|
|
340
349
|
declare class HttpClient {
|
|
341
350
|
private readonly opts;
|
|
342
351
|
private readonly sleep;
|
|
343
352
|
constructor(opts: HttpClientOptions);
|
|
353
|
+
private buildHeaders;
|
|
344
354
|
request<T = unknown>(o: RequestOptions): Promise<T>;
|
|
345
355
|
/**
|
|
346
356
|
* Single-shot fetch that returns the raw {@link Response} unparsed. Used by
|
|
@@ -93,6 +93,7 @@ interface StorefrontCredentials {
|
|
|
93
93
|
currency?: string;
|
|
94
94
|
siteCode?: string;
|
|
95
95
|
targetLocation?: string;
|
|
96
|
+
language?: string;
|
|
96
97
|
};
|
|
97
98
|
}
|
|
98
99
|
/** User-supplied SDK configuration. */
|
|
@@ -335,12 +336,21 @@ interface HttpClientOptions {
|
|
|
335
336
|
sleep?: (ms: number) => Promise<void>;
|
|
336
337
|
/** Opt-in customer-token refresher registry (off unless a refresher is set). */
|
|
337
338
|
customerRefresh?: CustomerRefreshRegistry;
|
|
339
|
+
/**
|
|
340
|
+
* Shared storefront request context. When `language` is set, every request
|
|
341
|
+
* carries `Accept-Language: <language>`. Mutated at runtime via
|
|
342
|
+
* `EmporixClient.setStorefrontContext({ language })`.
|
|
343
|
+
*/
|
|
344
|
+
requestContext?: {
|
|
345
|
+
language?: string | undefined;
|
|
346
|
+
};
|
|
338
347
|
}
|
|
339
348
|
/** Fetch wrapper: auth resolution, JSON parsing, typed error mapping, logging. */
|
|
340
349
|
declare class HttpClient {
|
|
341
350
|
private readonly opts;
|
|
342
351
|
private readonly sleep;
|
|
343
352
|
constructor(opts: HttpClientOptions);
|
|
353
|
+
private buildHeaders;
|
|
344
354
|
request<T = unknown>(o: RequestOptions): Promise<T>;
|
|
345
355
|
/**
|
|
346
356
|
* Single-shot fetch that returns the raw {@link Response} unparsed. Used by
|
package/dist/customer.d.cts
CHANGED
package/dist/customer.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -583,6 +583,16 @@ var HttpClient = class {
|
|
|
583
583
|
}
|
|
584
584
|
opts;
|
|
585
585
|
sleep;
|
|
586
|
+
buildHeaders(o, token, isFormData) {
|
|
587
|
+
return {
|
|
588
|
+
...this.opts.requestContext?.language ? { "Accept-Language": this.opts.requestContext.language } : {},
|
|
589
|
+
...o.headers ?? {},
|
|
590
|
+
Authorization: `Bearer ${token}`,
|
|
591
|
+
// JSON bodies: set Content-Type. FormData bodies: let `fetch`
|
|
592
|
+
// emit `multipart/form-data; boundary=...` itself.
|
|
593
|
+
...o.body !== void 0 && !isFormData ? { "Content-Type": "application/json" } : {}
|
|
594
|
+
};
|
|
595
|
+
}
|
|
586
596
|
async request(o) {
|
|
587
597
|
const requestId = `req-${++requestSeq}`;
|
|
588
598
|
const log = this.opts.logger.child({ requestId });
|
|
@@ -611,13 +621,7 @@ var HttpClient = class {
|
|
|
611
621
|
const isFormData = typeof FormData !== "undefined" && o.body instanceof FormData;
|
|
612
622
|
const init = {
|
|
613
623
|
method: o.method,
|
|
614
|
-
headers:
|
|
615
|
-
...o.headers ?? {},
|
|
616
|
-
Authorization: `Bearer ${token}`,
|
|
617
|
-
// JSON bodies: set Content-Type. FormData bodies: let `fetch`
|
|
618
|
-
// emit `multipart/form-data; boundary=...` itself.
|
|
619
|
-
...o.body !== void 0 && !isFormData ? { "Content-Type": "application/json" } : {}
|
|
620
|
-
},
|
|
624
|
+
headers: this.buildHeaders(o, token, isFormData),
|
|
621
625
|
signal: controller.signal
|
|
622
626
|
};
|
|
623
627
|
if (o.body !== void 0) {
|
|
@@ -705,11 +709,7 @@ var HttpClient = class {
|
|
|
705
709
|
const isFormData = typeof FormData !== "undefined" && o.body instanceof FormData;
|
|
706
710
|
const init = {
|
|
707
711
|
method: o.method,
|
|
708
|
-
headers:
|
|
709
|
-
...o.headers ?? {},
|
|
710
|
-
Authorization: `Bearer ${token}`,
|
|
711
|
-
...o.body !== void 0 && !isFormData ? { "Content-Type": "application/json" } : {}
|
|
712
|
-
},
|
|
712
|
+
headers: this.buildHeaders(o, token, isFormData),
|
|
713
713
|
signal: controller.signal,
|
|
714
714
|
...extra?.redirect ? { redirect: extra.redirect } : {}
|
|
715
715
|
};
|
|
@@ -2276,20 +2276,24 @@ var OrdersService = class {
|
|
|
2276
2276
|
}
|
|
2277
2277
|
/** Lists the calling customer's orders. */
|
|
2278
2278
|
async listMine(auth2, opts = {}) {
|
|
2279
|
-
const
|
|
2280
|
-
|
|
2281
|
-
|
|
2279
|
+
const pageNumber = opts.pageNumber ?? 1;
|
|
2280
|
+
const pageSize = opts.pageSize ?? 50;
|
|
2281
|
+
const query = {
|
|
2282
|
+
pageNumber,
|
|
2283
|
+
pageSize
|
|
2284
|
+
};
|
|
2282
2285
|
setIfDefined2(query, "status", opts.status);
|
|
2283
2286
|
setIfDefined2(query, "legalEntityId", opts.legalEntityId);
|
|
2284
2287
|
setIfDefined2(query, "siteCode", opts.siteCode);
|
|
2285
2288
|
const headers = this.saasHeader(opts.saasToken);
|
|
2286
|
-
|
|
2289
|
+
const items = await this.ctx.http.request({
|
|
2287
2290
|
method: "GET",
|
|
2288
2291
|
path: this.base(),
|
|
2289
2292
|
query,
|
|
2290
2293
|
auth: auth2,
|
|
2291
2294
|
...headers ? { headers } : {}
|
|
2292
2295
|
});
|
|
2296
|
+
return { items, pageNumber, pageSize, hasNextPage: items.length === pageSize };
|
|
2293
2297
|
}
|
|
2294
2298
|
/** Fetches one of the calling customer's orders by id. */
|
|
2295
2299
|
async get(orderId, auth2, opts = {}) {
|
|
@@ -3650,19 +3654,31 @@ var RewardPointsService = class {
|
|
|
3650
3654
|
// --- Storefront: the signed-in customer's own points (customer token required) ---
|
|
3651
3655
|
/** The signed-in customer's reward-points balance. Requires a customer `auth`. */
|
|
3652
3656
|
async getMyPoints(auth2) {
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3657
|
+
try {
|
|
3658
|
+
return await this.ctx.http.request({
|
|
3659
|
+
method: "GET",
|
|
3660
|
+
path: `${this.base()}/public/customer`,
|
|
3661
|
+
auth: auth2
|
|
3662
|
+
});
|
|
3663
|
+
} catch (err) {
|
|
3664
|
+
if (err instanceof EmporixNotFoundError) return 0;
|
|
3665
|
+
throw err;
|
|
3666
|
+
}
|
|
3658
3667
|
}
|
|
3659
3668
|
/** The signed-in customer's reward-points summary. Requires a customer `auth`. */
|
|
3660
3669
|
async getMySummary(auth2) {
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3670
|
+
try {
|
|
3671
|
+
return await this.ctx.http.request({
|
|
3672
|
+
method: "GET",
|
|
3673
|
+
path: `${this.base()}/public/customer/summary`,
|
|
3674
|
+
auth: auth2
|
|
3675
|
+
});
|
|
3676
|
+
} catch (err) {
|
|
3677
|
+
if (err instanceof EmporixNotFoundError) {
|
|
3678
|
+
return { activePoints: 0, summary: { addedPointsList: [] } };
|
|
3679
|
+
}
|
|
3680
|
+
throw err;
|
|
3681
|
+
}
|
|
3666
3682
|
}
|
|
3667
3683
|
/**
|
|
3668
3684
|
* Redeem the signed-in customer's points for a coupon code. Requires a
|
|
@@ -5096,7 +5112,7 @@ var ApprovalService = class {
|
|
|
5096
5112
|
};
|
|
5097
5113
|
|
|
5098
5114
|
// package.json
|
|
5099
|
-
var version = "2.
|
|
5115
|
+
var version = "2.13.1";
|
|
5100
5116
|
|
|
5101
5117
|
// src/version.ts
|
|
5102
5118
|
var SDK_VERSION = version;
|
|
@@ -5165,6 +5181,7 @@ var EmporixClient = class {
|
|
|
5165
5181
|
config;
|
|
5166
5182
|
resolver;
|
|
5167
5183
|
customerRefresh;
|
|
5184
|
+
requestContext;
|
|
5168
5185
|
constructor(config) {
|
|
5169
5186
|
const cfg = validateConfig(config);
|
|
5170
5187
|
this.tenant = cfg.tenant;
|
|
@@ -5188,6 +5205,8 @@ var EmporixClient = class {
|
|
|
5188
5205
|
this.tokenProvider = tokenProvider;
|
|
5189
5206
|
const customerRefresh = new CustomerRefreshRegistry();
|
|
5190
5207
|
this.customerRefresh = customerRefresh;
|
|
5208
|
+
this.requestContext = { language: cfg.credentials.storefront?.context?.language };
|
|
5209
|
+
const requestContext = this.requestContext;
|
|
5191
5210
|
const mk = (service) => ({
|
|
5192
5211
|
tenant: cfg.tenant,
|
|
5193
5212
|
tokenProvider,
|
|
@@ -5198,7 +5217,8 @@ var EmporixClient = class {
|
|
|
5198
5217
|
logger: root.child({ service: "http" }),
|
|
5199
5218
|
retry: cfg.retry,
|
|
5200
5219
|
timeouts: cfg.timeouts,
|
|
5201
|
-
customerRefresh
|
|
5220
|
+
customerRefresh,
|
|
5221
|
+
requestContext
|
|
5202
5222
|
})
|
|
5203
5223
|
});
|
|
5204
5224
|
this.customers = new CustomerService(mk("customer"));
|
|
@@ -5256,9 +5276,18 @@ var EmporixClient = class {
|
|
|
5256
5276
|
* next request re-mints a token bound to the new context. Use this to switch
|
|
5257
5277
|
* currency at runtime. Carts are currency-bound — clear the cart after a
|
|
5258
5278
|
* currency change (the React `setCurrency` does this for you).
|
|
5279
|
+
*
|
|
5280
|
+
* Also sets the storefront `language` (an `Accept-Language` header on every
|
|
5281
|
+
* read); a language-only change does NOT re-mint the token.
|
|
5259
5282
|
*/
|
|
5260
5283
|
setStorefrontContext(ctx) {
|
|
5261
|
-
|
|
5284
|
+
if (ctx.language !== void 0) {
|
|
5285
|
+
this.requestContext.language = ctx.language || void 0;
|
|
5286
|
+
}
|
|
5287
|
+
const { language: _language, ...priceContext } = ctx;
|
|
5288
|
+
if (Object.keys(priceContext).length > 0) {
|
|
5289
|
+
this.tokenProvider.setAnonymousContext?.(priceContext);
|
|
5290
|
+
}
|
|
5262
5291
|
}
|
|
5263
5292
|
/** Sets the runtime log level globally or for one service. */
|
|
5264
5293
|
setLogLevel(level, opts = {}) {
|