@23blocks/block-sales 5.1.0 → 5.2.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/dist/index.esm.js +47 -14
- package/dist/src/lib/mappers/order.mapper.d.ts.map +1 -1
- package/dist/src/lib/services/orders.service.d.ts +3 -1
- package/dist/src/lib/services/orders.service.d.ts.map +1 -1
- package/dist/src/lib/types/order.d.ts +52 -2
- package/dist/src/lib/types/order.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -114,17 +114,31 @@ const orderMapper = {
|
|
|
114
114
|
type: 'Order',
|
|
115
115
|
map: (resource)=>({
|
|
116
116
|
id: resource.id,
|
|
117
|
-
uniqueId: parseString(resource.attributes['unique_id']),
|
|
117
|
+
uniqueId: parseString(resource.attributes['unique_id']) || '',
|
|
118
118
|
createdAt: parseDate(resource.attributes['created_at']) || new Date(),
|
|
119
119
|
updatedAt: parseDate(resource.attributes['updated_at']) || new Date(),
|
|
120
120
|
displayId: parseString(resource.attributes['display_id']),
|
|
121
121
|
userUniqueId: parseString(resource.attributes['user_unique_id']) || '',
|
|
122
|
+
customerUniqueId: parseString(resource.attributes['customer_unique_id']),
|
|
122
123
|
status: parseOrderStatus(resource.attributes['status']),
|
|
123
124
|
subtotal: parseNumber(resource.attributes['subtotal']),
|
|
124
125
|
tax: parseNumber(resource.attributes['tax']),
|
|
125
126
|
shipping: parseNumber(resource.attributes['shipping']),
|
|
126
127
|
discount: parseNumber(resource.attributes['discount']),
|
|
127
128
|
total: parseNumber(resource.attributes['total']),
|
|
129
|
+
source: parseString(resource.attributes['source']),
|
|
130
|
+
sourceAlias: parseString(resource.attributes['source_alias']),
|
|
131
|
+
sourceId: parseString(resource.attributes['source_id']),
|
|
132
|
+
sourceType: parseString(resource.attributes['source_type']),
|
|
133
|
+
code: parseString(resource.attributes['code']),
|
|
134
|
+
discountValue: parseNumber(resource.attributes['discount_value']) || undefined,
|
|
135
|
+
taxValue: parseNumber(resource.attributes['tax_value']) || undefined,
|
|
136
|
+
fees: parseNumber(resource.attributes['fees']) || undefined,
|
|
137
|
+
feesValue: parseNumber(resource.attributes['fees_value']) || undefined,
|
|
138
|
+
promoCode: parseString(resource.attributes['promo_code']),
|
|
139
|
+
internalNotes: parseString(resource.attributes['internal_notes']),
|
|
140
|
+
cartUniqueId: parseString(resource.attributes['cart_unique_id']),
|
|
141
|
+
referredBy: parseString(resource.attributes['referred_by']),
|
|
128
142
|
shippingAddressUniqueId: parseString(resource.attributes['shipping_address_unique_id']),
|
|
129
143
|
billingAddressUniqueId: parseString(resource.attributes['billing_address_unique_id']),
|
|
130
144
|
notes: parseString(resource.attributes['notes']),
|
|
@@ -156,20 +170,39 @@ function createOrdersService(transport, _config) {
|
|
|
156
170
|
return decodeOne(response, orderMapper);
|
|
157
171
|
},
|
|
158
172
|
async create (data) {
|
|
173
|
+
const order = {};
|
|
174
|
+
if (data.customerUniqueId) order['customer_unique_id'] = data.customerUniqueId;
|
|
175
|
+
if (data.userUniqueId) order['user_unique_id'] = data.userUniqueId;
|
|
176
|
+
if (data.subtotal !== undefined) order['subtotal'] = data.subtotal;
|
|
177
|
+
if (data.source) order['source'] = data.source;
|
|
178
|
+
if (data.sourceAlias) order['source_alias'] = data.sourceAlias;
|
|
179
|
+
if (data.sourceId) order['source_id'] = data.sourceId;
|
|
180
|
+
if (data.sourceType) order['source_type'] = data.sourceType;
|
|
181
|
+
if (data.code) order['code'] = data.code;
|
|
182
|
+
if (data.discount !== undefined) order['discount'] = data.discount;
|
|
183
|
+
if (data.discountValue !== undefined) order['discount_value'] = data.discountValue;
|
|
184
|
+
if (data.tax !== undefined) order['tax'] = data.tax;
|
|
185
|
+
if (data.taxValue !== undefined) order['tax_value'] = data.taxValue;
|
|
186
|
+
if (data.fees !== undefined) order['fees'] = data.fees;
|
|
187
|
+
if (data.feesValue !== undefined) order['fees_value'] = data.feesValue;
|
|
188
|
+
if (data.promoCode) order['promo_code'] = data.promoCode;
|
|
189
|
+
if (data.internalNotes) order['internal_notes'] = data.internalNotes;
|
|
190
|
+
if (data.cartUniqueId) order['cart_unique_id'] = data.cartUniqueId;
|
|
191
|
+
if (data.referredBy) order['referred_by'] = data.referredBy;
|
|
192
|
+
if (data.items) {
|
|
193
|
+
order['items'] = data.items.map((item)=>({
|
|
194
|
+
product_unique_id: item.productUniqueId,
|
|
195
|
+
product_variation_unique_id: item.productVariationUniqueId,
|
|
196
|
+
quantity: item.quantity,
|
|
197
|
+
unit_price: item.unitPrice
|
|
198
|
+
}));
|
|
199
|
+
}
|
|
200
|
+
if (data.shippingAddressUniqueId) order['shipping_address_unique_id'] = data.shippingAddressUniqueId;
|
|
201
|
+
if (data.billingAddressUniqueId) order['billing_address_unique_id'] = data.billingAddressUniqueId;
|
|
202
|
+
if (data.notes) order['notes'] = data.notes;
|
|
203
|
+
if (data.payload) order['payload'] = data.payload;
|
|
159
204
|
const response = await transport.post('/orders', {
|
|
160
|
-
order
|
|
161
|
-
user_unique_id: data.userUniqueId,
|
|
162
|
-
items: data.items.map((item)=>({
|
|
163
|
-
product_unique_id: item.productUniqueId,
|
|
164
|
-
product_variation_unique_id: item.productVariationUniqueId,
|
|
165
|
-
quantity: item.quantity,
|
|
166
|
-
unit_price: item.unitPrice
|
|
167
|
-
})),
|
|
168
|
-
shipping_address_unique_id: data.shippingAddressUniqueId,
|
|
169
|
-
billing_address_unique_id: data.billingAddressUniqueId,
|
|
170
|
-
notes: data.notes,
|
|
171
|
-
payload: data.payload
|
|
172
|
-
}
|
|
205
|
+
order
|
|
173
206
|
});
|
|
174
207
|
return decodeOne(response, orderMapper);
|
|
175
208
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.mapper.d.ts","sourceRoot":"","sources":["../../../../src/lib/mappers/order.mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG/C,eAAO,MAAM,WAAW,EAAE,cAAc,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"order.mapper.d.ts","sourceRoot":"","sources":["../../../../src/lib/mappers/order.mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG/C,eAAO,MAAM,WAAW,EAAE,cAAc,CAAC,KAAK,CAsC7C,CAAC"}
|
|
@@ -12,7 +12,9 @@ export interface OrdersService {
|
|
|
12
12
|
*/
|
|
13
13
|
get(uniqueId: string): Promise<Order>;
|
|
14
14
|
/**
|
|
15
|
-
* Create a new order
|
|
15
|
+
* Create a new order. Supports two formats:
|
|
16
|
+
* - Flat: customerUniqueId + subtotal + source fields (items added later via orderDetails)
|
|
17
|
+
* - With items: userUniqueId + items[] array with line items
|
|
16
18
|
* @returns The newly created Order record.
|
|
17
19
|
*/
|
|
18
20
|
create(data: CreateOrderRequest): Promise<Order>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orders.service.d.ts","sourceRoot":"","sources":["../../../../src/lib/services/orders.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAO,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAGzG,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,IAAI,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IAE5D;;;OAGG;IACH,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAEtC
|
|
1
|
+
{"version":3,"file":"orders.service.d.ts","s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AO,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,aAAa,CA4GnG"}
|
|
@@ -3,12 +3,26 @@ export type OrderStatus = 'pending' | 'confirmed' | 'processing' | 'shipped' | '
|
|
|
3
3
|
export interface Order extends IdentityCore {
|
|
4
4
|
displayId: string;
|
|
5
5
|
userUniqueId: string;
|
|
6
|
+
customerUniqueId?: string;
|
|
6
7
|
status: OrderStatus;
|
|
7
8
|
subtotal: number;
|
|
8
9
|
tax: number;
|
|
9
10
|
shipping: number;
|
|
10
11
|
discount: number;
|
|
11
12
|
total: number;
|
|
13
|
+
source?: string;
|
|
14
|
+
sourceAlias?: string;
|
|
15
|
+
sourceId?: string;
|
|
16
|
+
sourceType?: string;
|
|
17
|
+
code?: string;
|
|
18
|
+
discountValue?: number;
|
|
19
|
+
taxValue?: number;
|
|
20
|
+
fees?: number;
|
|
21
|
+
feesValue?: number;
|
|
22
|
+
promoCode?: string;
|
|
23
|
+
internalNotes?: string;
|
|
24
|
+
cartUniqueId?: string;
|
|
25
|
+
referredBy?: string;
|
|
12
26
|
shippingAddressUniqueId?: string;
|
|
13
27
|
billingAddressUniqueId?: string;
|
|
14
28
|
notes?: string;
|
|
@@ -18,8 +32,44 @@ export interface Order extends IdentityCore {
|
|
|
18
32
|
payload?: Record<string, unknown>;
|
|
19
33
|
}
|
|
20
34
|
export interface CreateOrderRequest {
|
|
21
|
-
|
|
22
|
-
|
|
35
|
+
/** Customer unique ID (flat order format) */
|
|
36
|
+
customerUniqueId?: string;
|
|
37
|
+
/** User unique ID (alternative to customerUniqueId) */
|
|
38
|
+
userUniqueId?: string;
|
|
39
|
+
/** Order subtotal amount */
|
|
40
|
+
subtotal?: number;
|
|
41
|
+
/** Source identifier (e.g., 'ppm', 'web', 'mobile') */
|
|
42
|
+
source?: string;
|
|
43
|
+
/** Source alias */
|
|
44
|
+
sourceAlias?: string;
|
|
45
|
+
/** Source ID */
|
|
46
|
+
sourceId?: string;
|
|
47
|
+
/** Source type */
|
|
48
|
+
sourceType?: string;
|
|
49
|
+
/** Order code */
|
|
50
|
+
code?: string;
|
|
51
|
+
/** Discount percentage or fixed */
|
|
52
|
+
discount?: number;
|
|
53
|
+
/** Discount value */
|
|
54
|
+
discountValue?: number;
|
|
55
|
+
/** Tax percentage or fixed */
|
|
56
|
+
tax?: number;
|
|
57
|
+
/** Tax value */
|
|
58
|
+
taxValue?: number;
|
|
59
|
+
/** Fees percentage or fixed */
|
|
60
|
+
fees?: number;
|
|
61
|
+
/** Fees value */
|
|
62
|
+
feesValue?: number;
|
|
63
|
+
/** Promo code */
|
|
64
|
+
promoCode?: string;
|
|
65
|
+
/** Internal notes (not visible to customer) */
|
|
66
|
+
internalNotes?: string;
|
|
67
|
+
/** Cart unique ID */
|
|
68
|
+
cartUniqueId?: string;
|
|
69
|
+
/** Referred by */
|
|
70
|
+
referredBy?: string;
|
|
71
|
+
/** Line items (optional - order details can be added separately via orderDetails.create) */
|
|
72
|
+
items?: Array<{
|
|
23
73
|
productUniqueId: string;
|
|
24
74
|
productVariationUniqueId?: string;
|
|
25
75
|
quantity: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order.d.ts","sourceRoot":"","sources":["../../../../src/lib/types/order.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,WAAW,GAAG,YAAY,GAAG,SAAS,GAAG,WAAW,GAAG,WAAW,CAAC;AAEzG,MAAM,WAAW,KAAM,SAAQ,YAAY;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd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