@unchainedshop/core-orders 4.5.0 → 4.6.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/README.md +2 -2
- package/lib/db/OrdersCollection.d.ts +2 -2
- package/lib/db/OrdersCollection.js +2 -1
- package/lib/module/configureOrderPaymentsModule.d.ts +1 -7
- package/lib/module/configureOrderPaymentsModule.js +2 -23
- package/lib/module/configureOrdersModule-queries.d.ts +1 -1
- package/lib/module/configureOrdersModule.d.ts +2 -7
- package/lib/module/configureOrdersModule.js +6 -8
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -103,7 +103,7 @@ await ordersModule.checkout(orderId, { paymentContext: {} });
|
|
|
103
103
|
|
|
104
104
|
| Export | Description |
|
|
105
105
|
|--------|-------------|
|
|
106
|
-
| `OrderStatus` | Order status values (OPEN, PENDING, CONFIRMED,
|
|
106
|
+
| `OrderStatus` | Order status values (OPEN, PENDING, CONFIRMED, FULFILLED, REJECTED) |
|
|
107
107
|
|
|
108
108
|
### Settings
|
|
109
109
|
|
|
@@ -132,7 +132,7 @@ await ordersModule.checkout(orderId, { paymentContext: {} });
|
|
|
132
132
|
| `ORDER_CHECKOUT` | Order checked out |
|
|
133
133
|
| `ORDER_CONFIRMED` | Order confirmed |
|
|
134
134
|
| `ORDER_REJECTED` | Order rejected |
|
|
135
|
-
| `
|
|
135
|
+
| `ORDER_FULFILLED` | Order fulfilled |
|
|
136
136
|
|
|
137
137
|
## License
|
|
138
138
|
|
|
@@ -3,7 +3,7 @@ import type { DateFilterInput } from '@unchainedshop/utils';
|
|
|
3
3
|
export declare const OrderStatus: {
|
|
4
4
|
readonly PENDING: "PENDING";
|
|
5
5
|
readonly CONFIRMED: "CONFIRMED";
|
|
6
|
-
readonly
|
|
6
|
+
readonly FULFILLED: "FULFILLED";
|
|
7
7
|
readonly REJECTED: "REJECTED";
|
|
8
8
|
};
|
|
9
9
|
export type OrderStatus = (typeof OrderStatus)[keyof typeof OrderStatus];
|
|
@@ -18,7 +18,7 @@ export type Order = {
|
|
|
18
18
|
countryCode: string;
|
|
19
19
|
currencyCode: string;
|
|
20
20
|
deliveryId?: string;
|
|
21
|
-
|
|
21
|
+
fulfilled?: Date;
|
|
22
22
|
ordered?: Date;
|
|
23
23
|
orderNumber?: string;
|
|
24
24
|
originEnrollmentId?: string;
|
|
@@ -2,7 +2,7 @@ import { mongodb, buildDbIndexes, isDocumentDBCompatModeEnabled, } from '@unchai
|
|
|
2
2
|
export const OrderStatus = {
|
|
3
3
|
PENDING: 'PENDING',
|
|
4
4
|
CONFIRMED: 'CONFIRMED',
|
|
5
|
-
|
|
5
|
+
FULFILLED: 'FULFILLED',
|
|
6
6
|
REJECTED: 'REJECTED',
|
|
7
7
|
};
|
|
8
8
|
export const OrdersCollection = async (db) => {
|
|
@@ -33,6 +33,7 @@ export const OrdersCollection = async (db) => {
|
|
|
33
33
|
]);
|
|
34
34
|
}
|
|
35
35
|
await buildDbIndexes(Orders, [
|
|
36
|
+
{ index: { deleted: 1 } },
|
|
36
37
|
{ index: { userId: 1 } },
|
|
37
38
|
{ index: { status: 1 } },
|
|
38
39
|
{ index: { orderNumber: 1 } },
|
|
@@ -2,7 +2,6 @@ import { mongodb } from '@unchainedshop/mongodb';
|
|
|
2
2
|
import type { PricingCalculation } from '@unchainedshop/utils';
|
|
3
3
|
import { type OrderPayment, OrderPaymentStatus } from '../db/OrderPaymentsCollection.ts';
|
|
4
4
|
export declare const buildFindOrderPaymentByIdSelector: (orderPaymentId: string) => mongodb.Filter<OrderPayment>;
|
|
5
|
-
export declare const buildFindByContextDataSelector: (context: any) => mongodb.Filter<OrderPayment> | null;
|
|
6
5
|
export declare const configureOrderPaymentsModule: ({ OrderPayments, }: {
|
|
7
6
|
OrderPayments: mongodb.Collection<OrderPayment>;
|
|
8
7
|
}) => {
|
|
@@ -12,12 +11,7 @@ export declare const configureOrderPaymentsModule: ({ OrderPayments, }: {
|
|
|
12
11
|
findOrderPaymentsByProviderIds: ({ paymentProviderIds, }: {
|
|
13
12
|
paymentProviderIds: string[];
|
|
14
13
|
}, options?: mongodb.FindOptions) => Promise<OrderPayment[]>;
|
|
15
|
-
|
|
16
|
-
context: any;
|
|
17
|
-
}, options?: mongodb.FindOptions) => Promise<OrderPayment | null>;
|
|
18
|
-
countOrderPaymentsByContextData: ({ context, }: {
|
|
19
|
-
context: any;
|
|
20
|
-
}, options?: mongodb.FindOptions) => Promise<number>;
|
|
14
|
+
findOrderPaymentByTransactionId: (transactionId: string) => Promise<mongodb.WithId<OrderPayment> | null>;
|
|
21
15
|
normalizedStatus: (orderPayment: OrderPayment) => OrderPaymentStatus;
|
|
22
16
|
create: (doc: Omit<OrderPayment, "_id" | "created"> & Pick<Partial<OrderPayment>, "_id" | "created">) => Promise<OrderPayment>;
|
|
23
17
|
logEvent: (orderPaymentId: string, event: any) => Promise<boolean>;
|
|
@@ -3,18 +3,6 @@ import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedsho
|
|
|
3
3
|
import { OrderPaymentStatus } from "../db/OrderPaymentsCollection.js";
|
|
4
4
|
const ORDER_PAYMENT_EVENTS = ['ORDER_UPDATE_PAYMENT', 'ORDER_SIGN_PAYMENT', 'ORDER_PAY'];
|
|
5
5
|
export const buildFindOrderPaymentByIdSelector = (orderPaymentId) => generateDbFilterById(orderPaymentId);
|
|
6
|
-
export const buildFindByContextDataSelector = (context) => {
|
|
7
|
-
const contextKeys = Object.keys(context);
|
|
8
|
-
if (contextKeys.length === 0)
|
|
9
|
-
return null;
|
|
10
|
-
const selector = contextKeys.reduce((currentSelector, key) => context[key] !== undefined
|
|
11
|
-
? {
|
|
12
|
-
...currentSelector,
|
|
13
|
-
[`context.${key}`]: context[key],
|
|
14
|
-
}
|
|
15
|
-
: currentSelector, {});
|
|
16
|
-
return selector;
|
|
17
|
-
};
|
|
18
6
|
export const configureOrderPaymentsModule = ({ OrderPayments, }) => {
|
|
19
7
|
registerEvents(ORDER_PAYMENT_EVENTS);
|
|
20
8
|
const normalizedStatus = (orderPayment) => {
|
|
@@ -52,17 +40,8 @@ export const configureOrderPaymentsModule = ({ OrderPayments, }) => {
|
|
|
52
40
|
return [];
|
|
53
41
|
return OrderPayments.find({ paymentProviderId: { $in: paymentProviderIds } }, options).toArray();
|
|
54
42
|
},
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (!selector)
|
|
58
|
-
return null;
|
|
59
|
-
return OrderPayments.findOne(selector, options);
|
|
60
|
-
},
|
|
61
|
-
countOrderPaymentsByContextData: async ({ context, }, options) => {
|
|
62
|
-
const selector = buildFindByContextDataSelector(context);
|
|
63
|
-
if (!selector)
|
|
64
|
-
return 0;
|
|
65
|
-
return OrderPayments.countDocuments(selector, options);
|
|
43
|
+
findOrderPaymentByTransactionId: async (transactionId) => {
|
|
44
|
+
return OrderPayments.findOne({ transactionId });
|
|
66
45
|
},
|
|
67
46
|
normalizedStatus,
|
|
68
47
|
create: async (doc) => {
|
|
@@ -28,7 +28,7 @@ export interface DateRange {
|
|
|
28
28
|
start?: string;
|
|
29
29
|
end?: string;
|
|
30
30
|
}
|
|
31
|
-
export type StatisticsDateField = 'created' | 'ordered' | 'rejected' | 'confirmed' | '
|
|
31
|
+
export type StatisticsDateField = 'created' | 'ordered' | 'rejected' | 'confirmed' | 'fulfilled';
|
|
32
32
|
export interface OrderAggregateParams {
|
|
33
33
|
match?: Record<string, any>;
|
|
34
34
|
matchAfterGroup?: Record<string, any>;
|
|
@@ -87,12 +87,7 @@ export declare const configureOrdersModule: ({ db, migrationRepository, options:
|
|
|
87
87
|
findOrderPaymentsByProviderIds: ({ paymentProviderIds, }: {
|
|
88
88
|
paymentProviderIds: string[];
|
|
89
89
|
}, options?: mongodb.FindOptions) => Promise<import("../db/OrderPaymentsCollection.ts").OrderPayment[]>;
|
|
90
|
-
|
|
91
|
-
context: any;
|
|
92
|
-
}, options?: mongodb.FindOptions) => Promise<import("../db/OrderPaymentsCollection.ts").OrderPayment | null>;
|
|
93
|
-
countOrderPaymentsByContextData: ({ context, }: {
|
|
94
|
-
context: any;
|
|
95
|
-
}, options?: mongodb.FindOptions) => Promise<number>;
|
|
90
|
+
findOrderPaymentByTransactionId: (transactionId: string) => Promise<mongodb.WithId<import("../db/OrderPaymentsCollection.ts").OrderPayment> | null>;
|
|
96
91
|
normalizedStatus: (orderPayment: import("../db/OrderPaymentsCollection.ts").OrderPayment) => import("../db/OrderPaymentsCollection.ts").OrderPaymentStatus;
|
|
97
92
|
create: (doc: Omit<import("../db/OrderPaymentsCollection.ts").OrderPayment, "_id" | "created"> & Pick<Partial<import("../db/OrderPaymentsCollection.ts").OrderPayment>, "_id" | "created">) => Promise<import("../db/OrderPaymentsCollection.ts").OrderPayment>;
|
|
98
93
|
logEvent: (orderPaymentId: string, event: any) => Promise<boolean>;
|
|
@@ -110,7 +105,7 @@ export declare const configureOrdersModule: ({ db, migrationRepository, options:
|
|
|
110
105
|
status: OrderStatus | null;
|
|
111
106
|
info?: string;
|
|
112
107
|
}) => Promise<mongodb.WithId<Order> | null>;
|
|
113
|
-
acquireLock: (orderId: string, identifier: string, timeout?: number) => Promise<
|
|
108
|
+
acquireLock: (orderId: string, identifier: string, timeout?: number) => Promise<import("@kontsedal/locco").Lock>;
|
|
114
109
|
setDeliveryProvider: (orderId: string, deliveryProviderId: string) => Promise<mongodb.WithId<Order> | null>;
|
|
115
110
|
setPaymentProvider: (orderId: string, paymentProviderId: string) => Promise<mongodb.WithId<Order> | null>;
|
|
116
111
|
create: ({ userId, orderNumber, currencyCode, countryCode, billingAddress, contact, context, }: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { Locker, MongoAdapter } from '@kontsedal/locco';
|
|
1
2
|
import { generateDbFilterById, mongodb } from '@unchainedshop/mongodb';
|
|
2
|
-
import { createRequire } from 'node:module';
|
|
3
3
|
import { OrderDeliveriesCollection } from "../db/OrderDeliveriesCollection.js";
|
|
4
4
|
import { OrderDiscountsCollection } from "../db/OrderDiscountsCollection.js";
|
|
5
5
|
import { OrderPaymentsCollection } from "../db/OrderPaymentsCollection.js";
|
|
@@ -14,13 +14,11 @@ import { configureOrderModuleMutations } from "./configureOrdersModule-mutations
|
|
|
14
14
|
import { configureOrdersModuleQueries } from "./configureOrdersModule-queries.js";
|
|
15
15
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
16
16
|
import renameCurrencyCode from "../migrations/20250502111800-currency-code.js";
|
|
17
|
-
const require = createRequire(import.meta.url);
|
|
18
|
-
const { Locker, MongoAdapter } = require('@kontsedal/locco');
|
|
19
17
|
const ORDER_EVENTS = [
|
|
20
18
|
'ORDER_CHECKOUT',
|
|
21
19
|
'ORDER_CONFIRMED',
|
|
22
20
|
'ORDER_REJECTED',
|
|
23
|
-
'
|
|
21
|
+
'ORDER_FULFILLED',
|
|
24
22
|
];
|
|
25
23
|
export const configureOrdersModule = async ({ db, migrationRepository, options: orderOptions = {}, }) => {
|
|
26
24
|
renameCurrencyCode(migrationRepository);
|
|
@@ -84,8 +82,8 @@ export const configureOrdersModule = async ({ db, migrationRepository, options:
|
|
|
84
82
|
updated: new Date(),
|
|
85
83
|
};
|
|
86
84
|
switch (status) {
|
|
87
|
-
case OrderStatus.
|
|
88
|
-
$set.
|
|
85
|
+
case OrderStatus.FULFILLED:
|
|
86
|
+
$set.fulfilled = order.fulfilled || date;
|
|
89
87
|
case OrderStatus.REJECTED:
|
|
90
88
|
case OrderStatus.CONFIRMED:
|
|
91
89
|
if (status === OrderStatus.REJECTED) {
|
|
@@ -123,8 +121,8 @@ export const configureOrdersModule = async ({ db, migrationRepository, options:
|
|
|
123
121
|
await emit('ORDER_CHECKOUT', { order: modificationResult.value, oldStatus: order.status });
|
|
124
122
|
}
|
|
125
123
|
switch (status) {
|
|
126
|
-
case OrderStatus.
|
|
127
|
-
await emit('
|
|
124
|
+
case OrderStatus.FULFILLED:
|
|
125
|
+
await emit('ORDER_FULFILLED', { order: modificationResult.value, oldStatus: order.status });
|
|
128
126
|
break;
|
|
129
127
|
case OrderStatus.REJECTED:
|
|
130
128
|
await emit('ORDER_REJECTED', { order: modificationResult.value, oldStatus: order.status });
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-orders",
|
|
3
|
-
"
|
|
3
|
+
"description": "Order management module for the Unchained Engine",
|
|
4
|
+
"version": "4.6.0",
|
|
4
5
|
"main": "lib/orders-index.js",
|
|
5
6
|
"types": "lib/orders-index.d.ts",
|
|
6
7
|
"type": "module",
|
|
@@ -34,10 +35,10 @@
|
|
|
34
35
|
},
|
|
35
36
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@kontsedal/locco": "
|
|
38
|
-
"@unchainedshop/events": "^4.
|
|
39
|
-
"@unchainedshop/logger": "^4.
|
|
40
|
-
"@unchainedshop/utils": "^4.
|
|
38
|
+
"@kontsedal/locco": "1.0.0",
|
|
39
|
+
"@unchainedshop/events": "^4.6.0",
|
|
40
|
+
"@unchainedshop/logger": "^4.6.0",
|
|
41
|
+
"@unchainedshop/utils": "^4.6.0"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
44
|
"@types/node": "^25.0.0",
|