@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.
- package/CHANGELOG.md +407 -0
- package/LICENSE +21 -0
- package/README.md +115 -0
- package/dist/cart.cjs +214 -0
- package/dist/cart.cjs.map +1 -0
- package/dist/cart.d.cts +1807 -0
- package/dist/cart.d.ts +1807 -0
- package/dist/cart.js +4 -0
- package/dist/cart.js.map +1 -0
- package/dist/category.cjs +97 -0
- package/dist/category.cjs.map +1 -0
- package/dist/category.d.cts +313 -0
- package/dist/category.d.ts +313 -0
- package/dist/category.js +4 -0
- package/dist/category.js.map +1 -0
- package/dist/checkout.cjs +98 -0
- package/dist/checkout.cjs.map +1 -0
- package/dist/checkout.d.cts +252 -0
- package/dist/checkout.d.ts +252 -0
- package/dist/checkout.js +4 -0
- package/dist/checkout.js.map +1 -0
- package/dist/chunk-4BJUCCKJ.js +86 -0
- package/dist/chunk-4BJUCCKJ.js.map +1 -0
- package/dist/chunk-6UNFMCHZ.js +95 -0
- package/dist/chunk-6UNFMCHZ.js.map +1 -0
- package/dist/chunk-B56JZNI7.js +49 -0
- package/dist/chunk-B56JZNI7.js.map +1 -0
- package/dist/chunk-BFQ732VZ.js +11 -0
- package/dist/chunk-BFQ732VZ.js.map +1 -0
- package/dist/chunk-F3WAQH2E.js +120 -0
- package/dist/chunk-F3WAQH2E.js.map +1 -0
- package/dist/chunk-GWJ2U2CP.js +14 -0
- package/dist/chunk-GWJ2U2CP.js.map +1 -0
- package/dist/chunk-HEO34WLO.js +47 -0
- package/dist/chunk-HEO34WLO.js.map +1 -0
- package/dist/chunk-HKPZI7Y5.js +30 -0
- package/dist/chunk-HKPZI7Y5.js.map +1 -0
- package/dist/chunk-IEZHGU7F.js +171 -0
- package/dist/chunk-IEZHGU7F.js.map +1 -0
- package/dist/chunk-KTODT6DV.js +86 -0
- package/dist/chunk-KTODT6DV.js.map +1 -0
- package/dist/chunk-NM7VDXBR.js +57 -0
- package/dist/chunk-NM7VDXBR.js.map +1 -0
- package/dist/chunk-OMYVOOSX.js +57 -0
- package/dist/chunk-OMYVOOSX.js.map +1 -0
- package/dist/chunk-QDABAMVN.js +89 -0
- package/dist/chunk-QDABAMVN.js.map +1 -0
- package/dist/chunk-RXVVFNYN.js +56 -0
- package/dist/chunk-RXVVFNYN.js.map +1 -0
- package/dist/chunk-SKX7KCMH.js +23 -0
- package/dist/chunk-SKX7KCMH.js.map +1 -0
- package/dist/chunk-TLH6SLAF.js +215 -0
- package/dist/chunk-TLH6SLAF.js.map +1 -0
- package/dist/chunk-Z6PNI5VT.js +142 -0
- package/dist/chunk-Z6PNI5VT.js.map +1 -0
- package/dist/companies.cjs +58 -0
- package/dist/companies.cjs.map +1 -0
- package/dist/companies.d.cts +31 -0
- package/dist/companies.d.ts +31 -0
- package/dist/companies.js +3 -0
- package/dist/companies.js.map +1 -0
- package/dist/contacts.cjs +51 -0
- package/dist/contacts.cjs.map +1 -0
- package/dist/contacts.d.cts +28 -0
- package/dist/contacts.d.ts +28 -0
- package/dist/contacts.js +3 -0
- package/dist/contacts.js.map +1 -0
- package/dist/context-vKgzZ-5f.d.cts +329 -0
- package/dist/context-vKgzZ-5f.d.ts +329 -0
- package/dist/customer-groups.cjs +25 -0
- package/dist/customer-groups.cjs.map +1 -0
- package/dist/customer-groups.d.cts +36 -0
- package/dist/customer-groups.d.ts +36 -0
- package/dist/customer-groups.js +3 -0
- package/dist/customer-groups.js.map +1 -0
- package/dist/customer.cjs +262 -0
- package/dist/customer.cjs.map +1 -0
- package/dist/customer.d.cts +386 -0
- package/dist/customer.d.ts +386 -0
- package/dist/customer.js +5 -0
- package/dist/customer.js.map +1 -0
- package/dist/index.cjs +2075 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +218 -0
- package/dist/index.d.ts +218 -0
- package/dist/index.js +791 -0
- package/dist/index.js.map +1 -0
- package/dist/locations.cjs +59 -0
- package/dist/locations.cjs.map +1 -0
- package/dist/locations.d.cts +30 -0
- package/dist/locations.d.ts +30 -0
- package/dist/locations.js +3 -0
- package/dist/locations.js.map +1 -0
- package/dist/media.cjs +123 -0
- package/dist/media.cjs.map +1 -0
- package/dist/media.d.cts +219 -0
- package/dist/media.d.ts +219 -0
- package/dist/media.js +3 -0
- package/dist/media.js.map +1 -0
- package/dist/orders.cjs +98 -0
- package/dist/orders.cjs.map +1 -0
- package/dist/orders.d.cts +167 -0
- package/dist/orders.d.ts +167 -0
- package/dist/orders.js +3 -0
- package/dist/orders.js.map +1 -0
- package/dist/payment.cjs +77 -0
- package/dist/payment.cjs.map +1 -0
- package/dist/payment.d.cts +110 -0
- package/dist/payment.d.ts +110 -0
- package/dist/payment.js +5 -0
- package/dist/payment.js.map +1 -0
- package/dist/price.cjs +88 -0
- package/dist/price.cjs.map +1 -0
- package/dist/price.d.cts +445 -0
- package/dist/price.d.ts +445 -0
- package/dist/price.js +4 -0
- package/dist/price.js.map +1 -0
- package/dist/product.cjs +100 -0
- package/dist/product.cjs.map +1 -0
- package/dist/product.d.cts +400 -0
- package/dist/product.d.ts +400 -0
- package/dist/product.js +4 -0
- package/dist/product.js.map +1 -0
- package/dist/segment.cjs +189 -0
- package/dist/segment.cjs.map +1 -0
- package/dist/segment.d.cts +241 -0
- package/dist/segment.d.ts +241 -0
- package/dist/segment.js +5 -0
- package/dist/segment.js.map +1 -0
- package/dist/types.gen-D1QuqPLs.d.cts +166 -0
- package/dist/types.gen-D1QuqPLs.d.ts +166 -0
- package/package.json +141 -0
package/dist/price.cjs
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
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/price.ts
|
|
45
|
+
var ANON = { kind: "anonymous" };
|
|
46
|
+
var SERVICE = { kind: "service" };
|
|
47
|
+
function requireContextAuth(auth) {
|
|
48
|
+
const a = auth ?? ANON;
|
|
49
|
+
if (a.kind === "anonymous" || a.kind === "customer" || a.kind === "raw") return a;
|
|
50
|
+
throw new EmporixAuthError(
|
|
51
|
+
"match-prices-by-context requires an anonymous, customer, or raw AuthContext"
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
var PriceService = class {
|
|
55
|
+
constructor(ctx) {
|
|
56
|
+
this.ctx = ctx;
|
|
57
|
+
}
|
|
58
|
+
ctx;
|
|
59
|
+
/**
|
|
60
|
+
* Resolves prices using the session context bound to the bearer token
|
|
61
|
+
* (currency/site/country were set at anonymous-login time). Default auth:
|
|
62
|
+
* anonymous; pass a customer/raw context for personalized pricing.
|
|
63
|
+
*/
|
|
64
|
+
async matchByContext(input, auth) {
|
|
65
|
+
return this.ctx.http.request({
|
|
66
|
+
method: "POST",
|
|
67
|
+
path: `/price/${this.ctx.tenant}/match-prices-by-context`,
|
|
68
|
+
auth: requireContextAuth(auth),
|
|
69
|
+
body: input
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Resolves prices from an explicit context. Default auth: service
|
|
74
|
+
* (requires `price.price_read` / `price.price_manage`).
|
|
75
|
+
*/
|
|
76
|
+
async match(input, auth = SERVICE) {
|
|
77
|
+
return this.ctx.http.request({
|
|
78
|
+
method: "POST",
|
|
79
|
+
path: `/price/${this.ctx.tenant}/match-prices`,
|
|
80
|
+
auth,
|
|
81
|
+
body: input
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
exports.PriceService = PriceService;
|
|
87
|
+
//# sourceMappingURL=price.cjs.map
|
|
88
|
+
//# sourceMappingURL=price.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/errors.ts","../src/services/price.ts"],"names":[],"mappings":"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","file":"price.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 { Match, MatchByContext, MatchResponse } from \"../generated/price\";\n\n/** Session-context match request body (generated). */\nexport type PriceMatchByContextInput = MatchByContext;\n\n/** Explicit-context match request body (generated). */\nexport type PriceMatchInput = Match;\n\n/** A resolved price (full generated match-response schema). */\nexport type PriceMatch = MatchResponse;\n\nconst ANON: AuthContext = { kind: \"anonymous\" };\nconst SERVICE: AuthContext = { kind: \"service\" };\n\nfunction requireContextAuth(auth: AuthContext | undefined): AuthContext {\n const a = auth ?? ANON;\n if (a.kind === \"anonymous\" || a.kind === \"customer\" || a.kind === \"raw\") return a;\n throw new EmporixAuthError(\n \"match-prices-by-context requires an anonymous, customer, or raw AuthContext\",\n );\n}\n\n/**\n * Price matching. The Cart service does not resolve prices — call this\n * explicitly before rendering money and again right before placing an order.\n * The SDK is stateless: it never caches or revalidates prices.\n */\nexport class PriceService {\n constructor(private readonly ctx: ClientContext) {}\n\n /**\n * Resolves prices using the session context bound to the bearer token\n * (currency/site/country were set at anonymous-login time). Default auth:\n * anonymous; pass a customer/raw context for personalized pricing.\n */\n async matchByContext(\n input: PriceMatchByContextInput,\n auth?: AuthContext,\n ): Promise<PriceMatch[]> {\n return this.ctx.http.request<PriceMatch[]>({\n method: \"POST\",\n path: `/price/${this.ctx.tenant}/match-prices-by-context`,\n auth: requireContextAuth(auth),\n body: input,\n });\n }\n\n /**\n * Resolves prices from an explicit context. Default auth: service\n * (requires `price.price_read` / `price.price_manage`).\n */\n async match(input: PriceMatchInput, auth: AuthContext = SERVICE): Promise<PriceMatch[]> {\n return this.ctx.http.request<PriceMatch[]>({\n method: \"POST\",\n path: `/price/${this.ctx.tenant}/match-prices`,\n auth,\n body: input,\n });\n }\n}\n"]}
|
package/dist/price.d.cts
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { C as ClientContext, b as AuthContext } from './context-vKgzZ-5f.cjs';
|
|
2
|
+
|
|
3
|
+
type Metadata = {
|
|
4
|
+
/**
|
|
5
|
+
* Date and time when the price was created.
|
|
6
|
+
*/
|
|
7
|
+
createdAt?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Date and time when the price was last modified.
|
|
10
|
+
*/
|
|
11
|
+
modifiedAt?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Version of the price object. If provided optimistic locking will be enabled and it has to match version in the database
|
|
14
|
+
*/
|
|
15
|
+
version?: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Measurement unit for which the price is defined.
|
|
19
|
+
*/
|
|
20
|
+
type MeasurementUnit = {
|
|
21
|
+
/**
|
|
22
|
+
* Quantity of the measurement unit.
|
|
23
|
+
*/
|
|
24
|
+
quantity: number;
|
|
25
|
+
/**
|
|
26
|
+
* Code of the measurement unit.
|
|
27
|
+
*/
|
|
28
|
+
unitCode: 'kg' | 'g' | 'mg' | 'l' | 'ml' | 'lb' | 'qt' | 'qtr' | 'gal' | 'pt' | 'oz' | 'MTR' | 'XRO' | 'MLT' | 'LTR' | 'H87' | 'KGM' | 'GRM' | 'HLT' | 'DL' | 'DAG' | 'RO';
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Measurement unit for which the price is defined.
|
|
32
|
+
*/
|
|
33
|
+
type MeasurementUnitV2 = {
|
|
34
|
+
/**
|
|
35
|
+
* Quantity of the measurement unit.
|
|
36
|
+
*/
|
|
37
|
+
quantity: number;
|
|
38
|
+
/**
|
|
39
|
+
* Code of the measurement unit, as defined in the Unit Handling Service.
|
|
40
|
+
*/
|
|
41
|
+
unitCode: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Measurement unit for which the price is defined.
|
|
45
|
+
*/
|
|
46
|
+
type MatchMeasurementUnitV2 = {
|
|
47
|
+
/**
|
|
48
|
+
* Quantity of the measurement unit.
|
|
49
|
+
*/
|
|
50
|
+
quantity: number;
|
|
51
|
+
/**
|
|
52
|
+
* Code of the measurement unit, as defined in the Unit Handling Service. This attribute is optional, if not provided the price model unit will be used.
|
|
53
|
+
*/
|
|
54
|
+
unitCode?: string;
|
|
55
|
+
};
|
|
56
|
+
type SalePrice = {
|
|
57
|
+
/**
|
|
58
|
+
* Discount expressed as a fixed amount.
|
|
59
|
+
*/
|
|
60
|
+
discountAmount?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Discount expressed as a percentage of the original price.
|
|
63
|
+
*/
|
|
64
|
+
discountRate?: number;
|
|
65
|
+
/**
|
|
66
|
+
* Additional information about the discount.
|
|
67
|
+
*/
|
|
68
|
+
description?: string;
|
|
69
|
+
};
|
|
70
|
+
type MatchByContext = {
|
|
71
|
+
/**
|
|
72
|
+
* List of items (products or prices) for which the prices should be matched.
|
|
73
|
+
*/
|
|
74
|
+
items?: Array<{
|
|
75
|
+
/**
|
|
76
|
+
* Product or price for which a price should be matched.
|
|
77
|
+
*/
|
|
78
|
+
itemId?: {
|
|
79
|
+
/**
|
|
80
|
+
* Type of the referenced item. Possible values:
|
|
81
|
+
* * `PRODUCT`
|
|
82
|
+
* * `PRICE`
|
|
83
|
+
* * `SKU`
|
|
84
|
+
*
|
|
85
|
+
* **Note**: The `SKU` value is a `preview` value - the system does not fully operate on the SKU concept yet.
|
|
86
|
+
*/
|
|
87
|
+
itemType?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Item's unique identifier, generated when the item is created.
|
|
90
|
+
*/
|
|
91
|
+
id?: string;
|
|
92
|
+
};
|
|
93
|
+
quantity?: MatchMeasurementUnitV2;
|
|
94
|
+
}>;
|
|
95
|
+
};
|
|
96
|
+
type Match = {
|
|
97
|
+
/**
|
|
98
|
+
* Code of the currency in which the prices should be matched, as defined in the Currency Service.
|
|
99
|
+
*
|
|
100
|
+
* **Note**: If the matched price is defined in another currency, a currency exchange algorithm will be used, but only if exchange rates between the two currencies have been defined.
|
|
101
|
+
*/
|
|
102
|
+
targetCurrency: string;
|
|
103
|
+
/**
|
|
104
|
+
* Code of the site to which the matched prices should apply.
|
|
105
|
+
*/
|
|
106
|
+
siteCode: string;
|
|
107
|
+
targetLocation: {
|
|
108
|
+
/**
|
|
109
|
+
* Code of the country for which the prices should be matched, as defined in the Country Service.
|
|
110
|
+
*
|
|
111
|
+
* **Note**: If the matched price is defined for another country, a tax calculation algorithm will be used, but only if tax classes for the two countries have been defined for relevant products.
|
|
112
|
+
*/
|
|
113
|
+
countryCode: string;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* List of items (products or prices) for which the prices should be matched.
|
|
117
|
+
*/
|
|
118
|
+
items: Array<{
|
|
119
|
+
/**
|
|
120
|
+
* Product or price for which a price should be matched.
|
|
121
|
+
*/
|
|
122
|
+
itemId?: {
|
|
123
|
+
/**
|
|
124
|
+
* Type of the referenced item. Possible values:
|
|
125
|
+
* * `PRODUCT`
|
|
126
|
+
* * `PRICE`
|
|
127
|
+
* * `SKU`
|
|
128
|
+
*
|
|
129
|
+
* **Note**: The `SKU` value is a `preview` value - the system does not fully operate on the SKU concept yet.
|
|
130
|
+
*/
|
|
131
|
+
itemType: string;
|
|
132
|
+
/**
|
|
133
|
+
* Item's unique identifier, generated when the item is created.
|
|
134
|
+
*/
|
|
135
|
+
id: string;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Quantity of the product for which a matched price should be calculated.
|
|
139
|
+
*/
|
|
140
|
+
quantity: {
|
|
141
|
+
/**
|
|
142
|
+
* Quantity of the product, expressed as a number.
|
|
143
|
+
*/
|
|
144
|
+
quantity: number;
|
|
145
|
+
/**
|
|
146
|
+
* Code of the measurement unit, as defined in the Unit Handling Service. This atribute is optional, if not provided the price model unit will be used.
|
|
147
|
+
*/
|
|
148
|
+
unitCode?: string;
|
|
149
|
+
};
|
|
150
|
+
}>;
|
|
151
|
+
/**
|
|
152
|
+
* Customer or customer group for whom the matched prices should be valid.
|
|
153
|
+
*/
|
|
154
|
+
principal?: {
|
|
155
|
+
/**
|
|
156
|
+
* Unique identifier of the customer or customer group.
|
|
157
|
+
*/
|
|
158
|
+
id?: string;
|
|
159
|
+
/**
|
|
160
|
+
* Customer or customer group for whom the matched should be valid. Possible values:
|
|
161
|
+
* * `CUSTOMER`
|
|
162
|
+
* * `GROUP`
|
|
163
|
+
*
|
|
164
|
+
* **Note**: The `GROUP` value is a `preview` value - the system does not fully operate on the customer groups concept yet.
|
|
165
|
+
*/
|
|
166
|
+
type?: string;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* If no price that matches the criteria is found for the specified site, the price matching functionality will try to find the best price for the `main` site. To enable this option, this field needs to be set to `true`.
|
|
170
|
+
*
|
|
171
|
+
* **Note**: Using the fallback mechanism may impact the performance as the price matching has to run a second time. If the fallback mechanism is used, the response's `siteCode` field will be set to `main`.
|
|
172
|
+
*/
|
|
173
|
+
useFallback?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Legal entity for which price lists are included in the price match.
|
|
176
|
+
* **Note**: Price lists for the entity's parent legal entities are also included.
|
|
177
|
+
*/
|
|
178
|
+
legalEntityId?: string;
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Price model holds additional attributes that are extending price. For example it's possible to define a price which will be specific for a given customer or customer group.
|
|
182
|
+
*
|
|
183
|
+
*/
|
|
184
|
+
type PriceModelRetrieval = {
|
|
185
|
+
/**
|
|
186
|
+
* Price model's unique identifier, generated when the price model is created.
|
|
187
|
+
*
|
|
188
|
+
*/
|
|
189
|
+
id?: string;
|
|
190
|
+
name?: {
|
|
191
|
+
[key: string]: unknown;
|
|
192
|
+
} | string;
|
|
193
|
+
description?: {
|
|
194
|
+
[key: string]: unknown;
|
|
195
|
+
} | string;
|
|
196
|
+
/**
|
|
197
|
+
* Flag indicating whether prices assigned to the price model are expressed as net or gross.
|
|
198
|
+
*
|
|
199
|
+
* | Value | Description |
|
|
200
|
+
* | --- | --- |
|
|
201
|
+
* | `true` | Prices are expressed as gross values. |
|
|
202
|
+
* | `false` | Prices are expressed as net values. |
|
|
203
|
+
*
|
|
204
|
+
*/
|
|
205
|
+
includesTax?: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Flag indicating whether prices assigned to the price model include markup.
|
|
208
|
+
*
|
|
209
|
+
* **Note**: This is a **preview** field.
|
|
210
|
+
*
|
|
211
|
+
*/
|
|
212
|
+
includesMarkup?: boolean;
|
|
213
|
+
measurementUnit?: MeasurementUnitV2;
|
|
214
|
+
tierDefinition?: {
|
|
215
|
+
/**
|
|
216
|
+
* If the price is created based on a price model (the `priceModelId` is provided, the field should stay null. Otherwise the provided value will override a value from price model.
|
|
217
|
+
*
|
|
218
|
+
* Possible values:
|
|
219
|
+
* * `BASIC`
|
|
220
|
+
* * `VOLUME`
|
|
221
|
+
* * `TIERED`
|
|
222
|
+
*
|
|
223
|
+
* `BASIC`: Used to offer the same price per unit, regardless of the ordered quantity.
|
|
224
|
+
*
|
|
225
|
+
* **Note**: When using basic pricing, you need to define a single tier and set its `minQuantity` field to `0`.
|
|
226
|
+
*
|
|
227
|
+
* `VOLUME`: Used to offer a lower price per unit depending on the total ordered quantity.
|
|
228
|
+
*
|
|
229
|
+
* `TIERED`: Used to offer a lower price per unit based on the tiers that the total ordered quantity falls into.
|
|
230
|
+
*
|
|
231
|
+
* **Example**: You defined three tiers, starting at 5, 10, and 15 pieces respectively. A customer orders 16 pieces. In this pricing model, the first 5 pieces will be priced according to the first tier, the next 5 according to the second tier, and the 16th piece will be priced according to the third tier.
|
|
232
|
+
*/
|
|
233
|
+
tierType?: string;
|
|
234
|
+
tiers?: Array<{
|
|
235
|
+
minQuantity?: MeasurementUnit;
|
|
236
|
+
/**
|
|
237
|
+
* Identifier of a given tier.
|
|
238
|
+
*/
|
|
239
|
+
id?: string;
|
|
240
|
+
}>;
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* Indicates if the price model is a default price model.
|
|
244
|
+
*/
|
|
245
|
+
isDefault?: boolean;
|
|
246
|
+
metadata?: Metadata;
|
|
247
|
+
};
|
|
248
|
+
type MatchResponse = {
|
|
249
|
+
/**
|
|
250
|
+
* Price's unique identifier, generated when the price is created.
|
|
251
|
+
*
|
|
252
|
+
*/
|
|
253
|
+
priceId?: string;
|
|
254
|
+
/**
|
|
255
|
+
* Price list's unique identifier. The property is populated only in case when the return price belongs to any price list.
|
|
256
|
+
*
|
|
257
|
+
*/
|
|
258
|
+
priceListId?: string;
|
|
259
|
+
/**
|
|
260
|
+
* Item (product or price) for which the price was matched.
|
|
261
|
+
*/
|
|
262
|
+
itemRef?: {
|
|
263
|
+
/**
|
|
264
|
+
* Type of the retrieved item. Possible values:
|
|
265
|
+
* * `PRODUCT`
|
|
266
|
+
* * `SKU`
|
|
267
|
+
*
|
|
268
|
+
* **Note**: The `SKU` value is a `preview` value - the system does not fully operate on the SKU concept yet.
|
|
269
|
+
*/
|
|
270
|
+
itemType?: string;
|
|
271
|
+
/**
|
|
272
|
+
* Item's unique identifier, generated when the item is created.
|
|
273
|
+
*
|
|
274
|
+
*/
|
|
275
|
+
id?: string;
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Site to which the matched price applies.
|
|
279
|
+
*/
|
|
280
|
+
site?: {
|
|
281
|
+
/**
|
|
282
|
+
* Code of the site to which the matched price applies.
|
|
283
|
+
*/
|
|
284
|
+
code?: string;
|
|
285
|
+
/**
|
|
286
|
+
* Flag indicating whether prices assigned to the site are expressed as net or gross.
|
|
287
|
+
*
|
|
288
|
+
* | Value | Description |
|
|
289
|
+
* | --- | --- |
|
|
290
|
+
* | `true` | Prices are expressed as gross values. |
|
|
291
|
+
* | `false` | Prices are expressed as net values. |
|
|
292
|
+
*
|
|
293
|
+
* **Note**: If not specified, the retrieved price is net or gross depending on the `includesTax` field in the price's model.
|
|
294
|
+
*/
|
|
295
|
+
includesTax?: boolean;
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* Currency related to the price.
|
|
299
|
+
*/
|
|
300
|
+
currency?: string;
|
|
301
|
+
/**
|
|
302
|
+
* Location for which the matched price is defined.
|
|
303
|
+
*/
|
|
304
|
+
location?: {
|
|
305
|
+
/**
|
|
306
|
+
* Code of the country to which the matched price applies.
|
|
307
|
+
*/
|
|
308
|
+
countryCode?: string;
|
|
309
|
+
};
|
|
310
|
+
/**
|
|
311
|
+
* Represents an original value without any discounts for a single unit of the requested item (PRODUCT or SKU). The value is a gross price (if includesTax is true) or net price (if includesTax is false).
|
|
312
|
+
*
|
|
313
|
+
* It's worth to mention that the cent part is not limited just to two digits. For example, if the price is for one piece of screw, it could look like this: 0.0000317
|
|
314
|
+
*/
|
|
315
|
+
originalValue?: number;
|
|
316
|
+
/**
|
|
317
|
+
* Represents a value with a discount (if applicable) for a single unit of the requested item (PRODUCT or SKU). The value is a gross price (if includesTax is true) or net price (if includesTax is false).
|
|
318
|
+
*
|
|
319
|
+
* It's worth to mention that the cent part is not limited just to two digits. For example, if the price is for one piece of screw, it could look like this: 0.0000317
|
|
320
|
+
*/
|
|
321
|
+
effectiveValue?: number;
|
|
322
|
+
/**
|
|
323
|
+
* Represents a total value with a discount (if applicable) for all units of the requested item (PRODUCT or SKU). The value is a gross price (if includesTax is true) or net price (if includesTax is false).
|
|
324
|
+
*
|
|
325
|
+
* It's worth to mention that the cent part is not limited just to two digits. For example, if the price is for one piece of screw, it could look like this: 0.0000317
|
|
326
|
+
*/
|
|
327
|
+
totalValue?: number;
|
|
328
|
+
quantity?: MeasurementUnitV2;
|
|
329
|
+
salePrice?: SalePrice;
|
|
330
|
+
/**
|
|
331
|
+
* Flag indicating whether prices assigned to the price model are expressed as net or gross.
|
|
332
|
+
*
|
|
333
|
+
* | Value | Description |
|
|
334
|
+
* | --- | --- |
|
|
335
|
+
* | `true` | Prices are expressed as gross values. |
|
|
336
|
+
* | `false` | Prices are expressed as net values. |
|
|
337
|
+
*/
|
|
338
|
+
includesTax?: boolean;
|
|
339
|
+
priceModel?: PriceModelRetrieval;
|
|
340
|
+
/**
|
|
341
|
+
* Sales tax applicable to the product.
|
|
342
|
+
*/
|
|
343
|
+
tax?: {
|
|
344
|
+
/**
|
|
345
|
+
* Tax class's code, as defined in the Tax Service.
|
|
346
|
+
*
|
|
347
|
+
*/
|
|
348
|
+
taxClass?: string;
|
|
349
|
+
/**
|
|
350
|
+
* Tax rate expressed as a number.
|
|
351
|
+
*/
|
|
352
|
+
taxRate?: number;
|
|
353
|
+
/**
|
|
354
|
+
* Tax details containing all prices with tax.
|
|
355
|
+
*/
|
|
356
|
+
prices?: {
|
|
357
|
+
/**
|
|
358
|
+
* Original price with taxes.
|
|
359
|
+
*/
|
|
360
|
+
originalValue?: {
|
|
361
|
+
netValue?: number;
|
|
362
|
+
grossValue?: number;
|
|
363
|
+
taxValue?: number;
|
|
364
|
+
};
|
|
365
|
+
/**
|
|
366
|
+
* Effective price with taxes.
|
|
367
|
+
*/
|
|
368
|
+
effectiveValue?: {
|
|
369
|
+
netValue?: number;
|
|
370
|
+
grossValue?: number;
|
|
371
|
+
taxValue?: number;
|
|
372
|
+
};
|
|
373
|
+
/**
|
|
374
|
+
* Total price with taxes.
|
|
375
|
+
*/
|
|
376
|
+
totalValue?: {
|
|
377
|
+
netValue?: number;
|
|
378
|
+
grossValue?: number;
|
|
379
|
+
taxValue?: number;
|
|
380
|
+
};
|
|
381
|
+
};
|
|
382
|
+
};
|
|
383
|
+
/**
|
|
384
|
+
* Custom price attributes.
|
|
385
|
+
*/
|
|
386
|
+
mixins?: {
|
|
387
|
+
[key: string]: unknown;
|
|
388
|
+
};
|
|
389
|
+
metadata?: {
|
|
390
|
+
/**
|
|
391
|
+
* Version of the price object.
|
|
392
|
+
*/
|
|
393
|
+
version?: string;
|
|
394
|
+
/**
|
|
395
|
+
* Date and time when the matched price was created.
|
|
396
|
+
*/
|
|
397
|
+
createdAt?: string;
|
|
398
|
+
/**
|
|
399
|
+
* Date and time when the matched price was last modified.
|
|
400
|
+
*/
|
|
401
|
+
modifiedAt?: string;
|
|
402
|
+
};
|
|
403
|
+
/**
|
|
404
|
+
* A price tiers values for a matched price
|
|
405
|
+
*/
|
|
406
|
+
tierValues?: Array<{
|
|
407
|
+
/**
|
|
408
|
+
* Identifier of a tier
|
|
409
|
+
*/
|
|
410
|
+
id?: string;
|
|
411
|
+
/**
|
|
412
|
+
* A price value for a particular tier
|
|
413
|
+
*/
|
|
414
|
+
priceValue?: number;
|
|
415
|
+
}>;
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
/** Session-context match request body (generated). */
|
|
419
|
+
type PriceMatchByContextInput = MatchByContext;
|
|
420
|
+
/** Explicit-context match request body (generated). */
|
|
421
|
+
type PriceMatchInput = Match;
|
|
422
|
+
/** A resolved price (full generated match-response schema). */
|
|
423
|
+
type PriceMatch = MatchResponse;
|
|
424
|
+
/**
|
|
425
|
+
* Price matching. The Cart service does not resolve prices — call this
|
|
426
|
+
* explicitly before rendering money and again right before placing an order.
|
|
427
|
+
* The SDK is stateless: it never caches or revalidates prices.
|
|
428
|
+
*/
|
|
429
|
+
declare class PriceService {
|
|
430
|
+
private readonly ctx;
|
|
431
|
+
constructor(ctx: ClientContext);
|
|
432
|
+
/**
|
|
433
|
+
* Resolves prices using the session context bound to the bearer token
|
|
434
|
+
* (currency/site/country were set at anonymous-login time). Default auth:
|
|
435
|
+
* anonymous; pass a customer/raw context for personalized pricing.
|
|
436
|
+
*/
|
|
437
|
+
matchByContext(input: PriceMatchByContextInput, auth?: AuthContext): Promise<PriceMatch[]>;
|
|
438
|
+
/**
|
|
439
|
+
* Resolves prices from an explicit context. Default auth: service
|
|
440
|
+
* (requires `price.price_read` / `price.price_manage`).
|
|
441
|
+
*/
|
|
442
|
+
match(input: PriceMatchInput, auth?: AuthContext): Promise<PriceMatch[]>;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export { type PriceMatch, type PriceMatchByContextInput, type PriceMatchInput, PriceService };
|