@viu/emporix-sdk 2.12.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 +8 -0
- package/dist/{chunk-KVBCTXVH.js → chunk-WW3H7VJ5.js} +10 -6
- package/dist/chunk-WW3H7VJ5.js.map +1 -0
- package/dist/index.cjs +31 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -13
- package/dist/index.js.map +1 -1
- package/dist/orders.cjs +8 -4
- package/dist/orders.cjs.map +1 -1
- package/dist/orders.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-KVBCTXVH.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
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
|
+
|
|
3
11
|
## 2.12.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
|
@@ -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=chun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,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/index.cjs
CHANGED
|
@@ -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;
|