@revenexx/cover 0.2.44 → 0.3.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/package.json +2 -2
- package/server/api/auth/register.post.ts +1 -1
- package/server/api/cart/calculate.post.ts +1 -1
- package/server/api/orders/index.post.ts +3 -3
- package/server/api/payment/methods.post.ts +1 -1
- package/server/api/quotes/request.post.ts +6 -6
- package/server/api/shipping/rates.post.ts +1 -1
- package/server/services/ApiAddressBookService.ts +8 -9
- package/server/services/ApiCartService.ts +9 -7
- package/server/services/ApiOrganizationService.ts +2 -2
- package/server/services/ApiTeamService.ts +5 -6
- package/server/utils/liveCatalog.ts +1 -1
- package/server/utils/liveInventories.ts +1 -1
- package/server/utils/liveOrderLists.ts +23 -2
- package/server/utils/locale.ts +28 -0
- package/server/utils/promotionsService.ts +43 -41
- package/server/utils/quotesService.ts +41 -24
- package/server/utils/revenexxSdk.ts +33 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Cover \u2014 revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./nuxt.config.ts",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@formkit/vue": "^1.6.0",
|
|
41
41
|
"@iconify-json/lucide": "^1.2.111",
|
|
42
42
|
"@internationalized/date": "^3.12.0",
|
|
43
|
-
"@revenexx/sdk": "^0.0
|
|
43
|
+
"@revenexx/sdk": "^0.2.0",
|
|
44
44
|
"@revenexx/storage-model-viewer": "^0.3.0",
|
|
45
45
|
"@vueuse/core": "^14.3.0",
|
|
46
46
|
"typesense": "^3.0.5"
|
|
@@ -81,7 +81,7 @@ export default defineEventHandler(async (event) => {
|
|
|
81
81
|
...(firstName ? { firstName } : {}),
|
|
82
82
|
...(lastName ? { lastName } : {}),
|
|
83
83
|
...(profile?.company ? { organizationName: profile.company } : {}),
|
|
84
|
-
locale:
|
|
84
|
+
locale: await resolveStoreLocale(event),
|
|
85
85
|
}) as unknown as {
|
|
86
86
|
contact: { id: string; email: string };
|
|
87
87
|
user_id: string;
|
|
@@ -101,7 +101,7 @@ async function resolveLiveOverrides(
|
|
|
101
101
|
if (resolveShippingServiceKey(event) === "api") {
|
|
102
102
|
const method = body.deliveryMethod ?? "standard";
|
|
103
103
|
try {
|
|
104
|
-
const { rates } = await useRevenexxSdk().
|
|
104
|
+
const { rates } = await useRevenexxSdk().shippingMethods.shippingRates({
|
|
105
105
|
orderValue: subtotal,
|
|
106
106
|
country: "",
|
|
107
107
|
...(currency ? { currency } : {}),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OrderPaymentStatus } from "@revenexx/sdk";
|
|
1
|
+
import { OrderPaymentStatus, PromotionsRedemptionsReleaseReason } from "@revenexx/sdk";
|
|
2
2
|
import type { Models } from "@revenexx/sdk";
|
|
3
3
|
|
|
4
4
|
// Method codes are generic — live mode validates them against the
|
|
@@ -181,7 +181,7 @@ export default defineEventHandler(async (event) => {
|
|
|
181
181
|
if (liveShipping && body.deliveryMethod) {
|
|
182
182
|
const address = body.address as Record<string, unknown> | undefined;
|
|
183
183
|
try {
|
|
184
|
-
const { rates } = await useRevenexxSdk().
|
|
184
|
+
const { rates } = await useRevenexxSdk().shippingMethods.shippingRates({
|
|
185
185
|
orderValue: calculation.totals.find(row => row.key === "subtotal")?.amount
|
|
186
186
|
?? calculation.totals.find(row => row.key === "total")?.amount ?? 0,
|
|
187
187
|
country: String(address?.country ?? ""),
|
|
@@ -400,7 +400,7 @@ export default defineEventHandler(async (event) => {
|
|
|
400
400
|
// waiting out the expiry — the next buyer should find the code
|
|
401
401
|
// usable, not blocked by an attempt that failed.
|
|
402
402
|
if (reserved === "held" && cartId) {
|
|
403
|
-
await releaseRedemption(event, { cartId, reason:
|
|
403
|
+
await releaseRedemption(event, { cartId, reason: PromotionsRedemptionsReleaseReason.CartReleased });
|
|
404
404
|
}
|
|
405
405
|
if (err instanceof RevenexxException && (err.code === 400 || err.code === 422)) {
|
|
406
406
|
throw createError({ status: 422, message: err.message });
|
|
@@ -38,7 +38,7 @@ export default defineEventHandler(async (event) => {
|
|
|
38
38
|
|
|
39
39
|
const locale: Locale = resolveLocale(event);
|
|
40
40
|
try {
|
|
41
|
-
const { methods } = await useRevenexxSdk().
|
|
41
|
+
const { methods } = await useRevenexxSdk().paymentsMethods.paymentsMethodsEligible({
|
|
42
42
|
amount,
|
|
43
43
|
country,
|
|
44
44
|
currency,
|
|
@@ -104,13 +104,13 @@ export default defineEventHandler(async (event): Promise<QuoteRequestResult> =>
|
|
|
104
104
|
const quote = await liveQuoteRequest({
|
|
105
105
|
currency,
|
|
106
106
|
items,
|
|
107
|
-
...(cartId ? {
|
|
108
|
-
...(actor.contactId ? {
|
|
109
|
-
...(actor.organizationId ? {
|
|
107
|
+
...(cartId ? { cartId } : {}),
|
|
108
|
+
...(actor.contactId ? { contactId: actor.contactId } : {}),
|
|
109
|
+
...(actor.organizationId ? { organizationId: actor.organizationId } : {}),
|
|
110
110
|
buyer,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
...(body.note?.trim() ? {
|
|
111
|
+
shippingAddress,
|
|
112
|
+
billingAddress,
|
|
113
|
+
...(body.note?.trim() ? { buyerNote: body.note.trim() } : {}),
|
|
114
114
|
...(body.reason ? { reason: body.reason } : {}),
|
|
115
115
|
});
|
|
116
116
|
created = { id: quote.id, number: quote.number };
|
|
@@ -47,7 +47,7 @@ export default defineEventHandler(async (event) => {
|
|
|
47
47
|
|
|
48
48
|
const locale: Locale = resolveLocale(event);
|
|
49
49
|
try {
|
|
50
|
-
const { rates } = await useRevenexxSdk().
|
|
50
|
+
const { rates } = await useRevenexxSdk().shippingMethods.shippingRates({
|
|
51
51
|
orderValue: amount,
|
|
52
52
|
country,
|
|
53
53
|
...(weight !== undefined ? { weight } : {}),
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { H3Event } from "h3";
|
|
2
|
-
import { AddressType } from "@revenexx/sdk";
|
|
3
2
|
|
|
4
3
|
import type { AccountAddress, AccountAddressFormState } from "../../app/interfaces/account/address-list";
|
|
5
4
|
|
|
@@ -76,7 +75,7 @@ export class ApiAddressBookService implements IAddressBookService {
|
|
|
76
75
|
return "";
|
|
77
76
|
}
|
|
78
77
|
try {
|
|
79
|
-
const org = await useRevenexxSdk().
|
|
78
|
+
const org = await useRevenexxSdk().customersOrganizations.customersOrganizationsGet({
|
|
80
79
|
id: organizationId,
|
|
81
80
|
}) as unknown as { name?: string };
|
|
82
81
|
return org?.name ?? "";
|
|
@@ -122,10 +121,10 @@ export class ApiAddressBookService implements IAddressBookService {
|
|
|
122
121
|
const sdk = useRevenexxSdk();
|
|
123
122
|
const [own, company] = await Promise.all([
|
|
124
123
|
contact_id
|
|
125
|
-
? sdk.
|
|
124
|
+
? sdk.customersOrganizations.customersAddressesList({ contactId: contact_id, limit: 200 }) as unknown as Promise<{ items: ApiAddressRow[] }>
|
|
126
125
|
: Promise.resolve({ items: [] as ApiAddressRow[] }),
|
|
127
126
|
organization_id
|
|
128
|
-
? sdk.
|
|
127
|
+
? sdk.customersOrganizations.customersAddressesList({ organizationId: organization_id, limit: 200 }) as unknown as Promise<{ items: ApiAddressRow[] }>
|
|
129
128
|
: Promise.resolve({ items: [] as ApiAddressRow[] }),
|
|
130
129
|
]);
|
|
131
130
|
const seen = new Set<string>();
|
|
@@ -152,10 +151,10 @@ export class ApiAddressBookService implements IAddressBookService {
|
|
|
152
151
|
const contactId = this.requireContact(event);
|
|
153
152
|
const { organization_id } = this.contactRef(event);
|
|
154
153
|
try {
|
|
155
|
-
const row = await useRevenexxSdk().
|
|
154
|
+
const row = await useRevenexxSdk().customersOrganizations.customersAddressesCreate({
|
|
156
155
|
contactId,
|
|
157
156
|
...(organization_id ? { organizationId: organization_id } : {}),
|
|
158
|
-
type: input.type === "billing" ?
|
|
157
|
+
type: input.type === "billing" ? "billing" : "shipping",
|
|
159
158
|
company: input.company || undefined,
|
|
160
159
|
name: `${input.firstName} ${input.lastName}`.trim(),
|
|
161
160
|
street: `${input.street} ${input.streetNumber}`.trim(),
|
|
@@ -178,9 +177,9 @@ export class ApiAddressBookService implements IAddressBookService {
|
|
|
178
177
|
async update(event: H3Event, id: string, input: AccountAddressFormState): Promise<AccountAddress> {
|
|
179
178
|
this.requireContact(event);
|
|
180
179
|
try {
|
|
181
|
-
const row = await useRevenexxSdk().
|
|
180
|
+
const row = await useRevenexxSdk().customersOrganizations.customersAddressesUpdate({
|
|
182
181
|
id,
|
|
183
|
-
type: input.type === "billing" ?
|
|
182
|
+
type: input.type === "billing" ? "billing" : "shipping",
|
|
184
183
|
company: input.company || undefined,
|
|
185
184
|
name: `${input.firstName} ${input.lastName}`.trim(),
|
|
186
185
|
street: `${input.street} ${input.streetNumber}`.trim(),
|
|
@@ -203,7 +202,7 @@ export class ApiAddressBookService implements IAddressBookService {
|
|
|
203
202
|
async remove(event: H3Event, id: string): Promise<AccountAddress[]> {
|
|
204
203
|
this.requireContact(event);
|
|
205
204
|
try {
|
|
206
|
-
await useRevenexxSdk().
|
|
205
|
+
await useRevenexxSdk().customersOrganizations.customersAddressesDelete({ id });
|
|
207
206
|
}
|
|
208
207
|
catch (err) {
|
|
209
208
|
getLogService().error("API request failed: addresses/delete", apiErrorContext(err));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CartStatus } from "@revenexx/sdk";
|
|
2
2
|
import type { Models } from "@revenexx/sdk";
|
|
3
|
+
import type { H3Event } from "h3";
|
|
3
4
|
|
|
4
5
|
import type { CartItem } from "../../app/interfaces/cart-item";
|
|
5
6
|
import type { StoredSession } from "../../app/interfaces/auth";
|
|
@@ -141,10 +142,11 @@ function toSummary(cart: ApiCart): CartSummaryRow {
|
|
|
141
142
|
*/
|
|
142
143
|
export class ApiCartService implements ICartService, ICartManager {
|
|
143
144
|
private async listActive(owner: CartOwner): Promise<ApiCart[]> {
|
|
144
|
-
// Typed list filter (carts.list declares its query params
|
|
145
|
+
// Typed list filter (carts.list declares its query params, and its status
|
|
146
|
+
// is the app's own enum since @revenexx/sdk 0.2.0).
|
|
145
147
|
const { items } = await useRevenexxSdk().carts.cartsList({
|
|
146
148
|
...(owner.contactId ? { contactId: owner.contactId } : { sessionKey: owner.sessionKey }),
|
|
147
|
-
status:
|
|
149
|
+
status: CartStatus.Active,
|
|
148
150
|
limit: 100,
|
|
149
151
|
order: "updated_at.desc",
|
|
150
152
|
}) as unknown as { items: ApiCart[] };
|
|
@@ -173,14 +175,14 @@ export class ApiCartService implements ICartService, ICartManager {
|
|
|
173
175
|
if (!current) {
|
|
174
176
|
return [];
|
|
175
177
|
}
|
|
176
|
-
const { items } = await useRevenexxSdk().
|
|
178
|
+
const { items } = await useRevenexxSdk().cartsItems.cartsItemsList({ cartId: current.id }) as unknown as { items: ApiCartLine[] };
|
|
177
179
|
return items.map(toCartItem);
|
|
178
180
|
}
|
|
179
181
|
|
|
180
182
|
async saveItems(event: H3Event, items: CartItem[]): Promise<void> {
|
|
181
183
|
const owner = resolveOwner(event);
|
|
182
184
|
const cart = await this.ensureActiveCart(owner);
|
|
183
|
-
await useRevenexxSdk().
|
|
185
|
+
await useRevenexxSdk().cartsItems.cartsItemsReplace({
|
|
184
186
|
cartId: cart.id,
|
|
185
187
|
items: items.map((item, index) => toApiLine(item, index)) as unknown as Models.CartItemCreateRequest[],
|
|
186
188
|
});
|
|
@@ -222,13 +224,13 @@ export class ApiCartService implements ICartService, ICartManager {
|
|
|
222
224
|
|
|
223
225
|
async activateCart(event: H3Event, id: string): Promise<CartItem[]> {
|
|
224
226
|
await useRevenexxSdk().carts.cartsActivate({ id });
|
|
225
|
-
const { items } = await useRevenexxSdk().
|
|
227
|
+
const { items } = await useRevenexxSdk().cartsItems.cartsItemsList({ cartId: id }) as unknown as { items: ApiCartLine[] };
|
|
226
228
|
return items.map(toCartItem);
|
|
227
229
|
}
|
|
228
230
|
|
|
229
231
|
async addItemToCart(event: H3Event, id: string, item: CartItem): Promise<void> {
|
|
230
232
|
const line = toApiLine(item, 0);
|
|
231
|
-
await useRevenexxSdk().
|
|
233
|
+
await useRevenexxSdk().cartsItems.cartsItemsCreate({
|
|
232
234
|
cartId: id,
|
|
233
235
|
...(line.product_id ? { productId: String(line.product_id) } : {}),
|
|
234
236
|
...(line.sku ? { sku: String(line.sku) } : {}),
|
|
@@ -33,7 +33,7 @@ export class ApiOrganizationService implements IOrganizationService {
|
|
|
33
33
|
return null;
|
|
34
34
|
}
|
|
35
35
|
try {
|
|
36
|
-
const row = await useRevenexxSdk().
|
|
36
|
+
const row = await useRevenexxSdk().customersOrganizations.customersOrganizationsGet({
|
|
37
37
|
id: organization_id,
|
|
38
38
|
}) as unknown as ApiOrgRow;
|
|
39
39
|
return toAccountOrganization(row);
|
|
@@ -50,7 +50,7 @@ export class ApiOrganizationService implements IOrganizationService {
|
|
|
50
50
|
throw createError({ statusCode: 401, statusMessage: "No organization in session" });
|
|
51
51
|
}
|
|
52
52
|
try {
|
|
53
|
-
const row = await useRevenexxSdk().
|
|
53
|
+
const row = await useRevenexxSdk().customersOrganizations.customersOrganizationsUpdate({
|
|
54
54
|
id: organization_id,
|
|
55
55
|
name: input.name,
|
|
56
56
|
vatId: input.vatId || undefined,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ContactRole } from "@revenexx/sdk";
|
|
2
1
|
import type { H3Event } from "h3";
|
|
3
2
|
|
|
4
3
|
import type { AccountTeamMember, AccountTeamMemberFormState, AccountTeamRole, AccountTeamStatus } from "../../app/interfaces/account/team";
|
|
@@ -54,7 +53,7 @@ export class ApiTeamService implements ITeamService {
|
|
|
54
53
|
try {
|
|
55
54
|
// Typed list filter (customers.contacts.list declares its query
|
|
56
55
|
// params — @revenexx/sdk >= 0.0.12), so org scoping is server-side.
|
|
57
|
-
const { items } = await useRevenexxSdk().
|
|
56
|
+
const { items } = await useRevenexxSdk().customersContacts.customersContactsList({
|
|
58
57
|
organizationId: organization_id,
|
|
59
58
|
limit: 200,
|
|
60
59
|
}) as unknown as { items: ApiContactRow[] };
|
|
@@ -72,11 +71,11 @@ export class ApiTeamService implements ITeamService {
|
|
|
72
71
|
throw createError({ statusCode: 401, statusMessage: "No organization in session" });
|
|
73
72
|
}
|
|
74
73
|
try {
|
|
75
|
-
const row = await useRevenexxSdk().
|
|
74
|
+
const row = await useRevenexxSdk().customersContacts.customersContactsCreate({
|
|
76
75
|
email: input.email,
|
|
77
76
|
firstName: input.firstName || undefined,
|
|
78
77
|
lastName: input.lastName || undefined,
|
|
79
|
-
role: input.role
|
|
78
|
+
role: input.role,
|
|
80
79
|
organizationId: organization_id,
|
|
81
80
|
}) as unknown as ApiContactRow;
|
|
82
81
|
return toAccountTeamMember(row);
|
|
@@ -92,9 +91,9 @@ export class ApiTeamService implements ITeamService {
|
|
|
92
91
|
|
|
93
92
|
async update(_event: H3Event, id: string, patch: { role: AccountTeamRole }): Promise<AccountTeamMember> {
|
|
94
93
|
try {
|
|
95
|
-
const row = await useRevenexxSdk().
|
|
94
|
+
const row = await useRevenexxSdk().customersContacts.customersContactsUpdate({
|
|
96
95
|
id,
|
|
97
|
-
role: patch.role
|
|
96
|
+
role: patch.role,
|
|
98
97
|
}) as unknown as ApiContactRow;
|
|
99
98
|
return toAccountTeamMember(row);
|
|
100
99
|
}
|
|
@@ -412,7 +412,7 @@ async function loadLiveCategoryRows(): Promise<LiveCategoryRow[]> {
|
|
|
412
412
|
// Typed list (products.categories.list declares limit/offset/order —
|
|
413
413
|
// @revenexx/sdk >= 0.0.11).
|
|
414
414
|
for (let pageIndex = 0; pageIndex < 25; pageIndex++) {
|
|
415
|
-
const page = await sdk.
|
|
415
|
+
const page = await sdk.productsCategories.productsCategoriesList({
|
|
416
416
|
limit: CATEGORY_PAGE_LIMIT,
|
|
417
417
|
offset,
|
|
418
418
|
}) as unknown as LiveCategoryPage;
|
|
@@ -29,7 +29,7 @@ function toStock(entry: ItemAvailability): { quantity: number; maxOrderQuantity:
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
async function fetchAvailability(items: Array<{ product_id?: string; sku?: string }>): Promise<Map<string, ItemAvailability>> {
|
|
32
|
-
const { availability } = await useRevenexxSdk().
|
|
32
|
+
const { availability } = await useRevenexxSdk().inventoriesStock.inventoriesAvailability({
|
|
33
33
|
items: items as Models.InventoryAvailabilityItem[],
|
|
34
34
|
}) as unknown as { availability: ItemAvailability[] };
|
|
35
35
|
const byKey = new Map<string, ItemAvailability>();
|
|
@@ -120,7 +120,28 @@ function toItemInput(position: OrderListPosition): Models.OrderListItemInput {
|
|
|
120
120
|
* — spreading the snake_case shape there silently dropped product_id/tax_rate/
|
|
121
121
|
* the *_slug fields (the SDK only reads its declared camelCase params).
|
|
122
122
|
*/
|
|
123
|
-
|
|
123
|
+
/**
|
|
124
|
+
* A position as `orderlists.items.create` takes it. Spelled out rather than
|
|
125
|
+
* widened to a record: the generated method types its parameters, and a
|
|
126
|
+
* record would drop `name` on the way in.
|
|
127
|
+
*/
|
|
128
|
+
interface OrderListItemCreateInput {
|
|
129
|
+
name: string;
|
|
130
|
+
quantity: number;
|
|
131
|
+
productId?: string;
|
|
132
|
+
sku?: string;
|
|
133
|
+
image?: string;
|
|
134
|
+
unit?: string;
|
|
135
|
+
price?: number;
|
|
136
|
+
taxRate?: number;
|
|
137
|
+
costCenterId?: string;
|
|
138
|
+
positionTexts?: string[];
|
|
139
|
+
customSku?: string;
|
|
140
|
+
categorySlug?: string;
|
|
141
|
+
subcategorySlug?: string;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function toItemCreateParams(position: OrderListPosition): OrderListItemCreateInput {
|
|
124
145
|
return {
|
|
125
146
|
name: position.name,
|
|
126
147
|
quantity: Number(position.quantity) || 1,
|
|
@@ -208,7 +229,7 @@ export async function updateOrderList(
|
|
|
208
229
|
await sdk.orderlists.orderlistsItemsReplace({ listId: id, items: body.positions.map(toItemInput) });
|
|
209
230
|
}
|
|
210
231
|
for (const position of body.appendPositions ?? []) {
|
|
211
|
-
await sdk.orderlists.orderlistsItemsCreate({ listId: id, ...toItemCreateParams(position) }
|
|
232
|
+
await sdk.orderlists.orderlistsItemsCreate({ listId: id, ...toItemCreateParams(position) });
|
|
212
233
|
}
|
|
213
234
|
|
|
214
235
|
return toCoverList(await sdk.orderlists.orderlistsGet({ id }) as unknown as AppList);
|
package/server/utils/locale.ts
CHANGED
|
@@ -37,3 +37,31 @@ export function resolveLocale(event: H3Event): Locale {
|
|
|
37
37
|
const configDefault = useRuntimeConfig().public.defaultLocale;
|
|
38
38
|
return (SUPPORTED.has(configDefault as Locale) ? configDefault : "de") as Locale;
|
|
39
39
|
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The locale a CONTACT is stored under, which is not the locale the UI
|
|
43
|
+
* speaks. The storefront works in a language ("de"); the customers app keeps
|
|
44
|
+
* one of the store's own locales ("de-DE") and refuses anything else — and
|
|
45
|
+
* its refusal is a 400 whose message never reaches the form, so a bare
|
|
46
|
+
* language reads to the buyer as a registration that silently breaks.
|
|
47
|
+
*
|
|
48
|
+
* The market is the source of truth for which locales a store has. Falls back
|
|
49
|
+
* to the bare language when markets cannot be read: a registration that
|
|
50
|
+
* reaches the app and may be refused beats one that never leaves.
|
|
51
|
+
*/
|
|
52
|
+
export async function resolveStoreLocale(event: H3Event): Promise<string> {
|
|
53
|
+
const language = resolveLocale(event);
|
|
54
|
+
try {
|
|
55
|
+
const markets = await getMarketService(event).listMarkets();
|
|
56
|
+
const selected = resolveSelectedMarket(event);
|
|
57
|
+
const market = markets.find(m => m.code === selected) ?? markets.find(m => m.isDefault) ?? markets[0];
|
|
58
|
+
const locales = market?.locales ?? [];
|
|
59
|
+
const match = locales.find(l => l.language === language)
|
|
60
|
+
?? locales.find(l => l.isDefault)
|
|
61
|
+
?? locales[0];
|
|
62
|
+
return match?.code ?? language;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return language;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PromotionsRedemptionsReleaseReason } from "@revenexx/sdk";
|
|
1
2
|
import type { H3Event } from "h3";
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -16,6 +17,18 @@ export function resolvePromotionsServiceKey(event?: H3Event): string {
|
|
|
16
17
|
});
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
/**
|
|
21
|
+
* What `promotions/evaluate` answers, in the part the storefront reads. The
|
|
22
|
+
* app declares no response schema yet, so the generated method's return type
|
|
23
|
+
* is empty and this is the contract we hold it to.
|
|
24
|
+
*/
|
|
25
|
+
interface PromotionEvaluationAnswer {
|
|
26
|
+
lines?: Array<{ position?: number; discount?: number }>;
|
|
27
|
+
totals?: { discount_total?: number };
|
|
28
|
+
applied?: Array<Record<string, unknown>>;
|
|
29
|
+
rejected_codes?: string[];
|
|
30
|
+
}
|
|
31
|
+
|
|
19
32
|
/** One line as the promotions app wants to see it: priced, and numbered. */
|
|
20
33
|
interface PricedLine {
|
|
21
34
|
position: number;
|
|
@@ -77,24 +90,16 @@ export async function evaluatePromotions(
|
|
|
77
90
|
return null;
|
|
78
91
|
}
|
|
79
92
|
try {
|
|
80
|
-
// The
|
|
81
|
-
// the
|
|
82
|
-
//
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
lines
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
body: {
|
|
91
|
-
currency: input.currency,
|
|
92
|
-
lines: input.lines,
|
|
93
|
-
...(input.codes?.length ? { codes: input.codes } : {}),
|
|
94
|
-
...(input.contactId ? { contact_id: input.contactId } : {}),
|
|
95
|
-
...(input.organizationId ? { organization_id: input.organizationId } : {}),
|
|
96
|
-
},
|
|
97
|
-
});
|
|
93
|
+
// The app declares no response schema yet, so the generated method
|
|
94
|
+
// answers `{}` — the request side is typed, the answer is read through
|
|
95
|
+
// the shape this file documents.
|
|
96
|
+
const answer = await useRevenexxSdk().promotionsEvaluation.promotionsEvaluationEvaluate({
|
|
97
|
+
currency: input.currency ?? "",
|
|
98
|
+
lines: input.lines,
|
|
99
|
+
...(input.codes?.length ? { codes: input.codes } : {}),
|
|
100
|
+
...(input.contactId ? { contactId: input.contactId } : {}),
|
|
101
|
+
...(input.organizationId ? { organizationId: input.organizationId } : {}),
|
|
102
|
+
}) as PromotionEvaluationAnswer;
|
|
98
103
|
|
|
99
104
|
const lineDiscounts: Record<number, number> = {};
|
|
100
105
|
for (const line of answer.lines ?? []) {
|
|
@@ -191,14 +196,12 @@ export async function reserveRedemption(
|
|
|
191
196
|
return "not_applicable";
|
|
192
197
|
}
|
|
193
198
|
try {
|
|
194
|
-
await useRevenexxSdk().
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
...(input.organizationId ? { organization_id: input.organizationId } : {}),
|
|
201
|
-
},
|
|
199
|
+
await useRevenexxSdk().promotionsRedemptions.promotionsRedemptionsReserve({
|
|
200
|
+
cartId: input.cartId,
|
|
201
|
+
promotions,
|
|
202
|
+
...(input.currency ? { currency: input.currency } : {}),
|
|
203
|
+
...(input.contactId ? { contactId: input.contactId } : {}),
|
|
204
|
+
...(input.organizationId ? { organizationId: input.organizationId } : {}),
|
|
202
205
|
});
|
|
203
206
|
return "held";
|
|
204
207
|
}
|
|
@@ -235,18 +238,16 @@ export async function commitRedemption(
|
|
|
235
238
|
return;
|
|
236
239
|
}
|
|
237
240
|
try {
|
|
238
|
-
await useRevenexxSdk().
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
...(input.organizationId ? { organization_id: input.organizationId } : {}),
|
|
249
|
-
},
|
|
241
|
+
await useRevenexxSdk().promotionsRedemptions.promotionsRedemptionsCommit({
|
|
242
|
+
orderId: input.orderId,
|
|
243
|
+
// Commit promotes the cart's held rows; the list is what it falls
|
|
244
|
+
// back to when a hold has expired or was never taken, and it is
|
|
245
|
+
// what moves a promotion's budget and a voucher's usage_count.
|
|
246
|
+
promotions: heldPromotions(input.promotions),
|
|
247
|
+
...(input.cartId ? { cartId: input.cartId } : {}),
|
|
248
|
+
...(input.currency ? { currency: input.currency } : {}),
|
|
249
|
+
...(input.contactId ? { contactId: input.contactId } : {}),
|
|
250
|
+
...(input.organizationId ? { organizationId: input.organizationId } : {}),
|
|
250
251
|
});
|
|
251
252
|
}
|
|
252
253
|
catch (err) {
|
|
@@ -259,14 +260,15 @@ export async function commitRedemption(
|
|
|
259
260
|
|
|
260
261
|
export async function releaseRedemption(
|
|
261
262
|
event: H3Event,
|
|
262
|
-
input: { cartId: string; reason:
|
|
263
|
+
input: { cartId: string; reason: PromotionsRedemptionsReleaseReason },
|
|
263
264
|
): Promise<void> {
|
|
264
265
|
if (resolvePromotionsServiceKey(event) !== "api") {
|
|
265
266
|
return;
|
|
266
267
|
}
|
|
267
268
|
try {
|
|
268
|
-
await useRevenexxSdk().
|
|
269
|
-
|
|
269
|
+
await useRevenexxSdk().promotionsRedemptions.promotionsRedemptionsRelease({
|
|
270
|
+
cartId: input.cartId,
|
|
271
|
+
reason: input.reason,
|
|
270
272
|
});
|
|
271
273
|
}
|
|
272
274
|
catch (err) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Audience } from "@revenexx/sdk";
|
|
2
|
+
import type { Models } from "@revenexx/sdk";
|
|
1
3
|
import type { H3Event } from "h3";
|
|
2
4
|
|
|
3
5
|
import type { AccountQuote, AccountQuoteLine, AccountQuoteStatus } from "../../app/interfaces/account/quotes";
|
|
@@ -184,47 +186,62 @@ export function mapQuote(quote: LiveQuote): AccountQuote {
|
|
|
184
186
|
|
|
185
187
|
/* ---- live -------------------------------------------------------------- */
|
|
186
188
|
|
|
189
|
+
/**
|
|
190
|
+
* What the quotes app takes for a request. The positions keep the app's own
|
|
191
|
+
* field names (the generated line model is snake_case); everything around
|
|
192
|
+
* them is named as the SDK method declares it.
|
|
193
|
+
*/
|
|
194
|
+
export interface LiveQuoteRequestInput {
|
|
195
|
+
currency: string;
|
|
196
|
+
items: Models.QuoteLineInput[];
|
|
197
|
+
billingAddress?: object;
|
|
198
|
+
buyer?: object;
|
|
199
|
+
buyerNote?: string;
|
|
200
|
+
cartId?: string;
|
|
201
|
+
contactId?: string;
|
|
202
|
+
organizationId?: string;
|
|
203
|
+
reason?: string;
|
|
204
|
+
shippingAddress?: object;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// The generated models describe every field as optional — the gateway only
|
|
208
|
+
// promises what it sends. LiveQuote is the shape this BFF relies on, so each
|
|
209
|
+
// typed answer is narrowed to it once, here, instead of at every reader.
|
|
187
210
|
export async function liveQuoteList(organizationId: string | undefined, contactId: string | undefined): Promise<LiveQuote[]> {
|
|
188
|
-
|
|
189
|
-
if (organizationId) {
|
|
190
|
-
query.organization_id = organizationId;
|
|
191
|
-
}
|
|
192
|
-
else if (contactId) {
|
|
193
|
-
query.contact_id = contactId;
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
211
|
+
if (!organizationId && !contactId) {
|
|
196
212
|
return [];
|
|
197
213
|
}
|
|
198
|
-
const { items } = await useRevenexxSdk().
|
|
199
|
-
|
|
214
|
+
const { items } = await useRevenexxSdk().quotes.quotesQuotesList({
|
|
215
|
+
limit: 100,
|
|
216
|
+
order: "created_at.desc",
|
|
217
|
+
// An organisation sees the whole company's quotes; a contact without
|
|
218
|
+
// one sees only their own.
|
|
219
|
+
...(organizationId ? { organizationId } : { contactId }),
|
|
220
|
+
});
|
|
221
|
+
return (items ?? []) as LiveQuote[];
|
|
200
222
|
}
|
|
201
223
|
|
|
202
224
|
export async function liveQuoteDetail(id: string): Promise<LiveQuote> {
|
|
203
|
-
return await useRevenexxSdk().
|
|
204
|
-
|
|
205
|
-
|
|
225
|
+
return await useRevenexxSdk().quotes.quotesQuotesDetail({
|
|
226
|
+
id,
|
|
227
|
+
audience: Audience.Customer,
|
|
228
|
+
}) as LiveQuote;
|
|
206
229
|
}
|
|
207
230
|
|
|
208
|
-
export async function liveQuoteRequest(body:
|
|
209
|
-
return await useRevenexxSdk().
|
|
231
|
+
export async function liveQuoteRequest(body: LiveQuoteRequestInput): Promise<LiveQuote> {
|
|
232
|
+
return await useRevenexxSdk().quotes.quotesQuotesRequest(body) as LiveQuote;
|
|
210
233
|
}
|
|
211
234
|
|
|
212
235
|
export async function liveQuoteAccept(id: string): Promise<LiveQuote & { order_draft: LiveOrderDraft }> {
|
|
213
|
-
return await useRevenexxSdk().
|
|
214
|
-
"POST", `/v1/quotes/quotes/${encodeURIComponent(id)}/accept`, { body: {} },
|
|
215
|
-
);
|
|
236
|
+
return await useRevenexxSdk().quotesAcceptance.quotesAcceptanceAccept({ id }) as LiveQuote & { order_draft: LiveOrderDraft };
|
|
216
237
|
}
|
|
217
238
|
|
|
218
239
|
export async function liveQuoteOrdered(id: string, orderId: string): Promise<void> {
|
|
219
|
-
await useRevenexxSdk().
|
|
220
|
-
body: { order_id: orderId },
|
|
221
|
-
});
|
|
240
|
+
await useRevenexxSdk().quotesAcceptance.quotesAcceptanceOrdered({ id, orderId });
|
|
222
241
|
}
|
|
223
242
|
|
|
224
243
|
export async function liveQuoteDecline(id: string, reason?: string): Promise<void> {
|
|
225
|
-
await useRevenexxSdk().
|
|
226
|
-
body: reason ? { reason } : {},
|
|
227
|
-
});
|
|
244
|
+
await useRevenexxSdk().quotesAcceptance.quotesAcceptanceDecline({ id, ...(reason ? { reason } : {}) });
|
|
228
245
|
}
|
|
229
246
|
|
|
230
247
|
/**
|
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Carts,
|
|
3
|
+
CartsItems,
|
|
3
4
|
Client,
|
|
4
5
|
Customers,
|
|
5
|
-
|
|
6
|
+
CustomersContacts,
|
|
7
|
+
CustomersOrganizations,
|
|
8
|
+
InventoriesStock,
|
|
6
9
|
Markets,
|
|
7
10
|
Orderlists,
|
|
8
11
|
Orders,
|
|
9
|
-
|
|
12
|
+
PaymentsMethods,
|
|
10
13
|
Prices,
|
|
11
14
|
Products,
|
|
15
|
+
ProductsCategories,
|
|
16
|
+
PromotionsEvaluation,
|
|
17
|
+
PromotionsRedemptions,
|
|
18
|
+
QuotesAcceptance,
|
|
19
|
+
QuotesQuotes,
|
|
12
20
|
RevenexxException,
|
|
13
21
|
Search,
|
|
14
22
|
Settings,
|
|
15
|
-
|
|
23
|
+
ShippingMethods,
|
|
16
24
|
} from "@revenexx/sdk";
|
|
17
25
|
|
|
18
26
|
/**
|
|
@@ -43,17 +51,25 @@ export interface RevenexxSdkCallOptions {
|
|
|
43
51
|
export interface RevenexxSdk {
|
|
44
52
|
readonly client: Client;
|
|
45
53
|
readonly carts: Carts;
|
|
54
|
+
readonly cartsItems: CartsItems;
|
|
46
55
|
readonly customers: Customers;
|
|
47
|
-
readonly
|
|
56
|
+
readonly customersContacts: CustomersContacts;
|
|
57
|
+
readonly customersOrganizations: CustomersOrganizations;
|
|
58
|
+
readonly inventoriesStock: InventoriesStock;
|
|
48
59
|
readonly markets: Markets;
|
|
49
60
|
readonly orderlists: Orderlists;
|
|
50
61
|
readonly orders: Orders;
|
|
51
|
-
readonly
|
|
62
|
+
readonly paymentsMethods: PaymentsMethods;
|
|
52
63
|
readonly prices: Prices;
|
|
53
64
|
readonly products: Products;
|
|
65
|
+
readonly productsCategories: ProductsCategories;
|
|
66
|
+
readonly promotionsEvaluation: PromotionsEvaluation;
|
|
67
|
+
readonly promotionsRedemptions: PromotionsRedemptions;
|
|
68
|
+
readonly quotes: QuotesQuotes;
|
|
69
|
+
readonly quotesAcceptance: QuotesAcceptance;
|
|
54
70
|
readonly search: Search;
|
|
55
71
|
readonly settings: Settings;
|
|
56
|
-
readonly
|
|
72
|
+
readonly shippingMethods: ShippingMethods;
|
|
57
73
|
/**
|
|
58
74
|
* Low-level escape hatch over the SDK transport (same auth, same error
|
|
59
75
|
* type) for the few operations whose gateway contracts are not complete
|
|
@@ -253,17 +269,25 @@ export function useRevenexxSdk(): RevenexxSdk {
|
|
|
253
269
|
const instance: RevenexxSdk = {
|
|
254
270
|
client,
|
|
255
271
|
carts: new Carts(client),
|
|
272
|
+
cartsItems: new CartsItems(client),
|
|
256
273
|
customers: new Customers(client),
|
|
257
|
-
|
|
274
|
+
customersContacts: new CustomersContacts(client),
|
|
275
|
+
customersOrganizations: new CustomersOrganizations(client),
|
|
276
|
+
inventoriesStock: new InventoriesStock(client),
|
|
258
277
|
markets: new Markets(client),
|
|
259
278
|
orderlists: new Orderlists(client),
|
|
260
279
|
orders: new Orders(client),
|
|
261
|
-
|
|
280
|
+
paymentsMethods: new PaymentsMethods(client),
|
|
262
281
|
prices: new Prices(client),
|
|
263
282
|
products: new Products(client),
|
|
283
|
+
productsCategories: new ProductsCategories(client),
|
|
284
|
+
promotionsEvaluation: new PromotionsEvaluation(client),
|
|
285
|
+
promotionsRedemptions: new PromotionsRedemptions(client),
|
|
286
|
+
quotes: new QuotesQuotes(client),
|
|
287
|
+
quotesAcceptance: new QuotesAcceptance(client),
|
|
264
288
|
search: new Search(client),
|
|
265
289
|
settings: new Settings(client),
|
|
266
|
-
|
|
290
|
+
shippingMethods: new ShippingMethods(client),
|
|
267
291
|
call,
|
|
268
292
|
};
|
|
269
293
|
if (isCacheable) {
|