@voyant-travel/commerce 0.1.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/LICENSE +201 -0
- package/README.md +145 -0
- package/dist/accepted-quote-version-reservation-golden-flow.test.d.ts +2 -0
- package/dist/accepted-quote-version-reservation-golden-flow.test.d.ts.map +1 -0
- package/dist/accepted-quote-version-reservation-golden-flow.test.js +398 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/interface.d.ts +18 -0
- package/dist/interface.d.ts.map +1 -0
- package/dist/interface.js +246 -0
- package/dist/interface.test.d.ts +2 -0
- package/dist/interface.test.d.ts.map +1 -0
- package/dist/interface.test.js +357 -0
- package/dist/markets/index.d.ts +11 -0
- package/dist/markets/index.d.ts.map +1 -0
- package/dist/markets/index.js +12 -0
- package/dist/markets/routes.d.ts +1182 -0
- package/dist/markets/routes.d.ts.map +1 -0
- package/dist/markets/routes.js +209 -0
- package/dist/markets/schema.d.ts +1527 -0
- package/dist/markets/schema.d.ts.map +1 -0
- package/dist/markets/schema.js +240 -0
- package/dist/markets/service-core.d.ts +253 -0
- package/dist/markets/service-core.d.ts.map +1 -0
- package/dist/markets/service-core.js +242 -0
- package/dist/markets/service-rules.d.ts +191 -0
- package/dist/markets/service-rules.d.ts.map +1 -0
- package/dist/markets/service-rules.js +155 -0
- package/dist/markets/service-shared.d.ts +36 -0
- package/dist/markets/service-shared.d.ts.map +1 -0
- package/dist/markets/service-shared.js +7 -0
- package/dist/markets/service.d.ts +43 -0
- package/dist/markets/service.d.ts.map +1 -0
- package/dist/markets/service.js +42 -0
- package/dist/markets/validation.d.ts +451 -0
- package/dist/markets/validation.d.ts.map +1 -0
- package/dist/markets/validation.js +160 -0
- package/dist/pricing/events.d.ts +53 -0
- package/dist/pricing/events.d.ts.map +1 -0
- package/dist/pricing/events.js +28 -0
- package/dist/pricing/index.d.ts +15 -0
- package/dist/pricing/index.d.ts.map +1 -0
- package/dist/pricing/index.js +18 -0
- package/dist/pricing/routes-core.d.ts +981 -0
- package/dist/pricing/routes-core.d.ts.map +1 -0
- package/dist/pricing/routes-core.js +102 -0
- package/dist/pricing/routes-public.d.ts +136 -0
- package/dist/pricing/routes-public.d.ts.map +1 -0
- package/dist/pricing/routes-public.js +14 -0
- package/dist/pricing/routes-rules.d.ts +1339 -0
- package/dist/pricing/routes-rules.d.ts.map +1 -0
- package/dist/pricing/routes-rules.js +138 -0
- package/dist/pricing/routes-shared.d.ts +14 -0
- package/dist/pricing/routes-shared.d.ts.map +1 -0
- package/dist/pricing/routes-shared.js +3 -0
- package/dist/pricing/routes.d.ts +7 -0
- package/dist/pricing/routes.d.ts.map +1 -0
- package/dist/pricing/routes.js +6 -0
- package/dist/pricing/schema-catalogs.d.ts +467 -0
- package/dist/pricing/schema-catalogs.d.ts.map +1 -0
- package/dist/pricing/schema-catalogs.js +47 -0
- package/dist/pricing/schema-categories.d.ts +497 -0
- package/dist/pricing/schema-categories.d.ts.map +1 -0
- package/dist/pricing/schema-categories.js +54 -0
- package/dist/pricing/schema-departure-overrides.d.ts +228 -0
- package/dist/pricing/schema-departure-overrides.d.ts.map +1 -0
- package/dist/pricing/schema-departure-overrides.js +36 -0
- package/dist/pricing/schema-option-rules.d.ts +1770 -0
- package/dist/pricing/schema-option-rules.d.ts.map +1 -0
- package/dist/pricing/schema-option-rules.js +181 -0
- package/dist/pricing/schema-policies.d.ts +395 -0
- package/dist/pricing/schema-policies.d.ts.map +1 -0
- package/dist/pricing/schema-policies.js +41 -0
- package/dist/pricing/schema-relations.d.ts +59 -0
- package/dist/pricing/schema-relations.d.ts.map +1 -0
- package/dist/pricing/schema-relations.js +111 -0
- package/dist/pricing/schema-shared.d.ts +11 -0
- package/dist/pricing/schema-shared.d.ts.map +1 -0
- package/dist/pricing/schema-shared.js +67 -0
- package/dist/pricing/schema.d.ts +8 -0
- package/dist/pricing/schema.d.ts.map +1 -0
- package/dist/pricing/schema.js +7 -0
- package/dist/pricing/service-catalog-plane-pricing.d.ts +95 -0
- package/dist/pricing/service-catalog-plane-pricing.d.ts.map +1 -0
- package/dist/pricing/service-catalog-plane-pricing.js +382 -0
- package/dist/pricing/service-catalogs.d.ts +139 -0
- package/dist/pricing/service-catalogs.d.ts.map +1 -0
- package/dist/pricing/service-catalogs.js +89 -0
- package/dist/pricing/service-categories.d.ts +147 -0
- package/dist/pricing/service-categories.d.ts.map +1 -0
- package/dist/pricing/service-categories.js +105 -0
- package/dist/pricing/service-departure-overrides.d.ts +67 -0
- package/dist/pricing/service-departure-overrides.d.ts.map +1 -0
- package/dist/pricing/service-departure-overrides.js +54 -0
- package/dist/pricing/service-option-rules.d.ts +321 -0
- package/dist/pricing/service-option-rules.d.ts.map +1 -0
- package/dist/pricing/service-option-rules.js +340 -0
- package/dist/pricing/service-policies.d.ts +123 -0
- package/dist/pricing/service-policies.d.ts.map +1 -0
- package/dist/pricing/service-policies.js +95 -0
- package/dist/pricing/service-public.d.ts +89 -0
- package/dist/pricing/service-public.d.ts.map +1 -0
- package/dist/pricing/service-public.js +473 -0
- package/dist/pricing/service-rule-resolver.d.ts +67 -0
- package/dist/pricing/service-rule-resolver.d.ts.map +1 -0
- package/dist/pricing/service-rule-resolver.js +204 -0
- package/dist/pricing/service-shared.d.ts +53 -0
- package/dist/pricing/service-shared.d.ts.map +1 -0
- package/dist/pricing/service-shared.js +4 -0
- package/dist/pricing/service-transfer-rules.d.ts +211 -0
- package/dist/pricing/service-transfer-rules.d.ts.map +1 -0
- package/dist/pricing/service-transfer-rules.js +139 -0
- package/dist/pricing/service.d.ts +79 -0
- package/dist/pricing/service.d.ts.map +1 -0
- package/dist/pricing/service.js +78 -0
- package/dist/pricing/validation-public.d.ts +412 -0
- package/dist/pricing/validation-public.d.ts.map +1 -0
- package/dist/pricing/validation-public.js +111 -0
- package/dist/pricing/validation-shared.d.ts +71 -0
- package/dist/pricing/validation-shared.d.ts.map +1 -0
- package/dist/pricing/validation-shared.js +63 -0
- package/dist/pricing/validation.d.ts +987 -0
- package/dist/pricing/validation.d.ts.map +1 -0
- package/dist/pricing/validation.js +307 -0
- package/dist/promotions/events.d.ts +38 -0
- package/dist/promotions/events.d.ts.map +1 -0
- package/dist/promotions/events.js +25 -0
- package/dist/promotions/index.d.ts +12 -0
- package/dist/promotions/index.d.ts.map +1 -0
- package/dist/promotions/index.js +17 -0
- package/dist/promotions/routes-shared.d.ts +14 -0
- package/dist/promotions/routes-shared.d.ts.map +1 -0
- package/dist/promotions/routes-shared.js +3 -0
- package/dist/promotions/routes.d.ts +395 -0
- package/dist/promotions/routes.d.ts.map +1 -0
- package/dist/promotions/routes.js +55 -0
- package/dist/promotions/schema.d.ts +675 -0
- package/dist/promotions/schema.d.ts.map +1 -0
- package/dist/promotions/schema.js +126 -0
- package/dist/promotions/service-booking-confirmed.d.ts +77 -0
- package/dist/promotions/service-booking-confirmed.d.ts.map +1 -0
- package/dist/promotions/service-booking-confirmed.js +134 -0
- package/dist/promotions/service-boundary-scheduler.d.ts +85 -0
- package/dist/promotions/service-boundary-scheduler.d.ts.map +1 -0
- package/dist/promotions/service-boundary-scheduler.js +141 -0
- package/dist/promotions/service-catalog-evaluator.d.ts +22 -0
- package/dist/promotions/service-catalog-evaluator.d.ts.map +1 -0
- package/dist/promotions/service-catalog-evaluator.js +33 -0
- package/dist/promotions/service-catalog-plane-promotions.d.ts +73 -0
- package/dist/promotions/service-catalog-plane-promotions.d.ts.map +1 -0
- package/dist/promotions/service-catalog-plane-promotions.js +118 -0
- package/dist/promotions/service-evaluator.d.ts +134 -0
- package/dist/promotions/service-evaluator.d.ts.map +1 -0
- package/dist/promotions/service-evaluator.js +302 -0
- package/dist/promotions/service-storefront.d.ts +147 -0
- package/dist/promotions/service-storefront.d.ts.map +1 -0
- package/dist/promotions/service-storefront.js +326 -0
- package/dist/promotions/service.d.ts +143 -0
- package/dist/promotions/service.d.ts.map +1 -0
- package/dist/promotions/service.js +359 -0
- package/dist/promotions/validation.d.ts +195 -0
- package/dist/promotions/validation.d.ts.map +1 -0
- package/dist/promotions/validation.js +167 -0
- package/dist/promotions/workflow-bulk-reindex.d.ts +36 -0
- package/dist/promotions/workflow-bulk-reindex.d.ts.map +1 -0
- package/dist/promotions/workflow-bulk-reindex.js +53 -0
- package/dist/promotions/workflow-runtime.d.ts +17 -0
- package/dist/promotions/workflow-runtime.d.ts.map +1 -0
- package/dist/promotions/workflow-runtime.js +9 -0
- package/dist/runtime.d.ts +18 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +27 -0
- package/dist/runtime.test.d.ts +2 -0
- package/dist/runtime.test.d.ts.map +1 -0
- package/dist/runtime.test.js +25 -0
- package/dist/schema.d.ts +5 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +4 -0
- package/dist/sellability/index.d.ts +13 -0
- package/dist/sellability/index.d.ts.map +1 -0
- package/dist/sellability/index.js +17 -0
- package/dist/sellability/routes.d.ts +2332 -0
- package/dist/sellability/routes.d.ts.map +1 -0
- package/dist/sellability/routes.js +166 -0
- package/dist/sellability/schema.d.ts +1716 -0
- package/dist/sellability/schema.d.ts.map +1 -0
- package/dist/sellability/schema.js +278 -0
- package/dist/sellability/service-records.d.ts +316 -0
- package/dist/sellability/service-records.d.ts.map +1 -0
- package/dist/sellability/service-records.js +253 -0
- package/dist/sellability/service-resolve.d.ts +72 -0
- package/dist/sellability/service-resolve.d.ts.map +1 -0
- package/dist/sellability/service-resolve.js +580 -0
- package/dist/sellability/service-shared.d.ts +124 -0
- package/dist/sellability/service-shared.d.ts.map +1 -0
- package/dist/sellability/service-shared.js +96 -0
- package/dist/sellability/service-snapshots.d.ts +191 -0
- package/dist/sellability/service-snapshots.d.ts.map +1 -0
- package/dist/sellability/service-snapshots.js +153 -0
- package/dist/sellability/service.d.ts +1038 -0
- package/dist/sellability/service.d.ts.map +1 -0
- package/dist/sellability/service.js +17 -0
- package/dist/sellability/validation.d.ts +477 -0
- package/dist/sellability/validation.d.ts.map +1 -0
- package/dist/sellability/validation.js +192 -0
- package/dist/types.d.ts +239 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { insertOfferExpirationEventSchema, insertOfferRefreshRunSchema, insertSellabilityExplanationSchema, insertSellabilityPolicyResultSchema, insertSellabilityPolicySchema, offerExpirationEventListQuerySchema, offerRefreshRunListQuerySchema, SellabilityResolveQuery, sellabilityExplanationListQuerySchema, sellabilityPolicyListQuerySchema, sellabilityPolicyResultListQuerySchema, updateOfferExpirationEventSchema, updateOfferRefreshRunSchema, updateSellabilityExplanationSchema, updateSellabilityPolicyResultSchema, updateSellabilityPolicySchema } from "./validation.js";
|
|
3
|
+
export type { SellabilityResolveQuery } from "./validation.js";
|
|
4
|
+
export type RequestedUnit = SellabilityResolveQuery["requestedUnits"][number];
|
|
5
|
+
export type SellabilitySnapshotListQuery = {
|
|
6
|
+
limit: number;
|
|
7
|
+
offset: number;
|
|
8
|
+
offerId?: string;
|
|
9
|
+
marketId?: string;
|
|
10
|
+
channelId?: string;
|
|
11
|
+
productId?: string;
|
|
12
|
+
optionId?: string;
|
|
13
|
+
slotId?: string;
|
|
14
|
+
status?: "resolved" | "offer_constructed" | "expired";
|
|
15
|
+
};
|
|
16
|
+
export type SellabilitySnapshotItemListQuery = {
|
|
17
|
+
limit: number;
|
|
18
|
+
offset: number;
|
|
19
|
+
snapshotId?: string;
|
|
20
|
+
productId?: string;
|
|
21
|
+
optionId?: string;
|
|
22
|
+
slotId?: string;
|
|
23
|
+
unitId?: string;
|
|
24
|
+
};
|
|
25
|
+
export type SellabilityPolicyListQuery = z.infer<typeof sellabilityPolicyListQuerySchema>;
|
|
26
|
+
export type CreateSellabilityPolicyInput = z.infer<typeof insertSellabilityPolicySchema>;
|
|
27
|
+
export type UpdateSellabilityPolicyInput = z.infer<typeof updateSellabilityPolicySchema>;
|
|
28
|
+
export type SellabilityPolicyResultListQuery = z.infer<typeof sellabilityPolicyResultListQuerySchema>;
|
|
29
|
+
export type CreateSellabilityPolicyResultInput = z.infer<typeof insertSellabilityPolicyResultSchema>;
|
|
30
|
+
export type UpdateSellabilityPolicyResultInput = z.infer<typeof updateSellabilityPolicyResultSchema>;
|
|
31
|
+
export type OfferRefreshRunListQuery = z.infer<typeof offerRefreshRunListQuerySchema>;
|
|
32
|
+
export type CreateOfferRefreshRunInput = z.infer<typeof insertOfferRefreshRunSchema>;
|
|
33
|
+
export type UpdateOfferRefreshRunInput = z.infer<typeof updateOfferRefreshRunSchema>;
|
|
34
|
+
export type OfferExpirationEventListQuery = z.infer<typeof offerExpirationEventListQuerySchema>;
|
|
35
|
+
export type CreateOfferExpirationEventInput = z.infer<typeof insertOfferExpirationEventSchema>;
|
|
36
|
+
export type UpdateOfferExpirationEventInput = z.infer<typeof updateOfferExpirationEventSchema>;
|
|
37
|
+
export type SellabilityExplanationListQuery = z.infer<typeof sellabilityExplanationListQuerySchema>;
|
|
38
|
+
export type CreateSellabilityExplanationInput = z.infer<typeof insertSellabilityExplanationSchema>;
|
|
39
|
+
export type UpdateSellabilityExplanationInput = z.infer<typeof updateSellabilityExplanationSchema>;
|
|
40
|
+
export type ResolvedPriceBreakdown = {
|
|
41
|
+
requestRef: string | null;
|
|
42
|
+
unitId: string | null;
|
|
43
|
+
unitName: string | null;
|
|
44
|
+
unitType: string | null;
|
|
45
|
+
pricingCategoryId: string | null;
|
|
46
|
+
pricingCategoryName: string | null;
|
|
47
|
+
quantity: number;
|
|
48
|
+
pricingMode: string;
|
|
49
|
+
sellAmountCents: number;
|
|
50
|
+
costAmountCents: number;
|
|
51
|
+
sourceRuleId: string | null;
|
|
52
|
+
tierId: string | null;
|
|
53
|
+
};
|
|
54
|
+
export type ResolvedPriceComponent = {
|
|
55
|
+
kind: "base" | "unit" | "pickup" | "start_time_adjustment";
|
|
56
|
+
title: string;
|
|
57
|
+
quantity: number;
|
|
58
|
+
pricingMode: string;
|
|
59
|
+
sellAmountCents: number;
|
|
60
|
+
costAmountCents: number;
|
|
61
|
+
unitId: string | null;
|
|
62
|
+
unitName: string | null;
|
|
63
|
+
unitType: string | null;
|
|
64
|
+
pricingCategoryId: string | null;
|
|
65
|
+
pricingCategoryName: string | null;
|
|
66
|
+
requestRef: string | null;
|
|
67
|
+
sourceRuleId: string | null;
|
|
68
|
+
tierId: string | null;
|
|
69
|
+
};
|
|
70
|
+
export declare function weekdayCandidates(dateLocal: string): (string | undefined)[];
|
|
71
|
+
export declare function scheduleMatches(schedule: {
|
|
72
|
+
validFrom: string | null;
|
|
73
|
+
validTo: string | null;
|
|
74
|
+
weekdays: string[] | null;
|
|
75
|
+
}, dateLocal?: string): boolean;
|
|
76
|
+
export declare function applyAdjustment(total: {
|
|
77
|
+
sellAmountCents: number;
|
|
78
|
+
costAmountCents: number;
|
|
79
|
+
}, adjustment: {
|
|
80
|
+
adjustmentType: "fixed" | "percentage" | null;
|
|
81
|
+
sellAdjustmentCents: number | null;
|
|
82
|
+
costAdjustmentCents: number | null;
|
|
83
|
+
adjustmentBasisPoints: number | null;
|
|
84
|
+
}): {
|
|
85
|
+
sellAmountCents: number;
|
|
86
|
+
costAmountCents: number;
|
|
87
|
+
};
|
|
88
|
+
export declare function computeUnitAmounts(request: RequestedUnit, details: {
|
|
89
|
+
unitName: string | null;
|
|
90
|
+
unitType: string | null;
|
|
91
|
+
pricingCategoryName: string | null;
|
|
92
|
+
}, unitRule: {
|
|
93
|
+
id: string;
|
|
94
|
+
pricingMode: string;
|
|
95
|
+
sellAmountCents: number | null;
|
|
96
|
+
costAmountCents: number | null;
|
|
97
|
+
} | null, tier: {
|
|
98
|
+
id: string;
|
|
99
|
+
sellAmountCents: number | null;
|
|
100
|
+
costAmountCents: number | null;
|
|
101
|
+
} | null, override: {
|
|
102
|
+
sellAmountCents: number;
|
|
103
|
+
costAmountCents: number | null;
|
|
104
|
+
} | null): ResolvedPriceBreakdown;
|
|
105
|
+
export declare function chooseBestScheduledRule<T extends {
|
|
106
|
+
isDefault?: boolean | null;
|
|
107
|
+
priceScheduleId?: string | null;
|
|
108
|
+
}>(rows: T[]): T | null;
|
|
109
|
+
export declare function chooseBestSpecificRule<T extends {
|
|
110
|
+
optionId?: string | null;
|
|
111
|
+
}>(rows: T[]): T | null;
|
|
112
|
+
export declare function toNumeric(value: string | number | null | undefined): number | null;
|
|
113
|
+
export declare function compactObject<T extends Record<string, unknown>>(value: T): T;
|
|
114
|
+
export declare function paginate<T extends object>(rowsQuery: Promise<T[]>, countQuery: Promise<Array<{
|
|
115
|
+
count: number;
|
|
116
|
+
}>>, limit: number, offset: number): Promise<{
|
|
117
|
+
data: T[];
|
|
118
|
+
total: number;
|
|
119
|
+
limit: number;
|
|
120
|
+
offset: number;
|
|
121
|
+
}>;
|
|
122
|
+
export declare function normalizeDateTime(value: string | null | undefined): Date | null;
|
|
123
|
+
export type PaginatedResult<T extends object> = Awaited<ReturnType<typeof paginate<T>>>;
|
|
124
|
+
//# sourceMappingURL=service-shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-shared.d.ts","sourceRoot":"","sources":["../../src/sellability/service-shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,KAAK,EACV,gCAAgC,EAChC,2BAA2B,EAC3B,kCAAkC,EAClC,mCAAmC,EACnC,6BAA6B,EAC7B,mCAAmC,EACnC,8BAA8B,EAC9B,uBAAuB,EACvB,qCAAqC,EACrC,gCAAgC,EAChC,sCAAsC,EACtC,gCAAgC,EAChC,2BAA2B,EAC3B,kCAAkC,EAClC,mCAAmC,EACnC,6BAA6B,EAC9B,MAAM,iBAAiB,CAAA;AAExB,YAAY,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AAE9D,MAAM,MAAM,aAAa,GAAG,uBAAuB,CAAC,gBAAgB,CAAC,CAAC,MAAM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EAAE,CAAC,EACvB,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,EAC7C,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM;;;;;GAIf;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,eAEjE;AAED,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
export function weekdayCandidates(dateLocal) {
|
|
2
|
+
const weekday = new Date(`${dateLocal}T00:00:00Z`).getUTCDay();
|
|
3
|
+
const names = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
|
|
4
|
+
const longNames = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
5
|
+
return [String(weekday), names[weekday], longNames[weekday]];
|
|
6
|
+
}
|
|
7
|
+
export function scheduleMatches(schedule, dateLocal) {
|
|
8
|
+
if (!dateLocal)
|
|
9
|
+
return true;
|
|
10
|
+
if (schedule.validFrom && dateLocal < schedule.validFrom)
|
|
11
|
+
return false;
|
|
12
|
+
if (schedule.validTo && dateLocal > schedule.validTo)
|
|
13
|
+
return false;
|
|
14
|
+
if (!schedule.weekdays || schedule.weekdays.length === 0)
|
|
15
|
+
return true;
|
|
16
|
+
const candidates = weekdayCandidates(dateLocal);
|
|
17
|
+
return schedule.weekdays.some((entry) => candidates.includes(entry.toLowerCase()));
|
|
18
|
+
}
|
|
19
|
+
export function applyAdjustment(total, adjustment) {
|
|
20
|
+
if (adjustment.adjustmentType === "fixed") {
|
|
21
|
+
return {
|
|
22
|
+
sellAmountCents: total.sellAmountCents + (adjustment.sellAdjustmentCents ?? 0),
|
|
23
|
+
costAmountCents: total.costAmountCents + (adjustment.costAdjustmentCents ?? 0),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (adjustment.adjustmentType === "percentage" && adjustment.adjustmentBasisPoints) {
|
|
27
|
+
return {
|
|
28
|
+
sellAmountCents: total.sellAmountCents +
|
|
29
|
+
Math.round((total.sellAmountCents * adjustment.adjustmentBasisPoints) / 10_000),
|
|
30
|
+
costAmountCents: total.costAmountCents +
|
|
31
|
+
Math.round((total.costAmountCents * adjustment.adjustmentBasisPoints) / 10_000),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return total;
|
|
35
|
+
}
|
|
36
|
+
export function computeUnitAmounts(request, details, unitRule, tier, override) {
|
|
37
|
+
const pricingMode = unitRule?.pricingMode ?? "per_unit";
|
|
38
|
+
const baseSell = override?.sellAmountCents ?? tier?.sellAmountCents ?? unitRule?.sellAmountCents ?? 0;
|
|
39
|
+
const baseCost = override?.costAmountCents ?? tier?.costAmountCents ?? unitRule?.costAmountCents ?? 0;
|
|
40
|
+
if (pricingMode === "included" || pricingMode === "free") {
|
|
41
|
+
return {
|
|
42
|
+
requestRef: request.requestRef ?? null,
|
|
43
|
+
unitId: request.unitId ?? null,
|
|
44
|
+
unitName: details.unitName,
|
|
45
|
+
unitType: details.unitType,
|
|
46
|
+
pricingCategoryId: request.pricingCategoryId ?? null,
|
|
47
|
+
pricingCategoryName: details.pricingCategoryName,
|
|
48
|
+
quantity: request.quantity,
|
|
49
|
+
pricingMode,
|
|
50
|
+
sellAmountCents: 0,
|
|
51
|
+
costAmountCents: 0,
|
|
52
|
+
sourceRuleId: unitRule?.id ?? null,
|
|
53
|
+
tierId: tier?.id ?? null,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const multiplier = pricingMode === "per_booking" ? 1 : request.quantity;
|
|
57
|
+
return {
|
|
58
|
+
requestRef: request.requestRef ?? null,
|
|
59
|
+
unitId: request.unitId ?? null,
|
|
60
|
+
unitName: details.unitName,
|
|
61
|
+
unitType: details.unitType,
|
|
62
|
+
pricingCategoryId: request.pricingCategoryId ?? null,
|
|
63
|
+
pricingCategoryName: details.pricingCategoryName,
|
|
64
|
+
quantity: request.quantity,
|
|
65
|
+
pricingMode,
|
|
66
|
+
sellAmountCents: baseSell * multiplier,
|
|
67
|
+
costAmountCents: baseCost * multiplier,
|
|
68
|
+
sourceRuleId: unitRule?.id ?? null,
|
|
69
|
+
tierId: tier?.id ?? null,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export function chooseBestScheduledRule(rows) {
|
|
73
|
+
return ([...rows].sort((a, b) => {
|
|
74
|
+
const scoreA = Number(Boolean(a.priceScheduleId)) * 10 + Number(Boolean(a.isDefault));
|
|
75
|
+
const scoreB = Number(Boolean(b.priceScheduleId)) * 10 + Number(Boolean(b.isDefault));
|
|
76
|
+
return scoreB - scoreA;
|
|
77
|
+
})[0] ?? null);
|
|
78
|
+
}
|
|
79
|
+
export function chooseBestSpecificRule(rows) {
|
|
80
|
+
return ([...rows].sort((a, b) => Number(Boolean(b.optionId)) - Number(Boolean(a.optionId)))[0] ?? null);
|
|
81
|
+
}
|
|
82
|
+
export function toNumeric(value) {
|
|
83
|
+
if (value === null || value === undefined)
|
|
84
|
+
return null;
|
|
85
|
+
return typeof value === "number" ? value : Number(value);
|
|
86
|
+
}
|
|
87
|
+
export function compactObject(value) {
|
|
88
|
+
return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined));
|
|
89
|
+
}
|
|
90
|
+
export async function paginate(rowsQuery, countQuery, limit, offset) {
|
|
91
|
+
const [data, countResult] = await Promise.all([rowsQuery, countQuery]);
|
|
92
|
+
return { data, total: countResult[0]?.count ?? 0, limit, offset };
|
|
93
|
+
}
|
|
94
|
+
export function normalizeDateTime(value) {
|
|
95
|
+
return value ? new Date(value) : null;
|
|
96
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
2
|
+
import { resolve } from "./service-resolve.js";
|
|
3
|
+
import { type ResolvedPriceComponent, type SellabilityResolveQuery, type SellabilitySnapshotItemListQuery, type SellabilitySnapshotListQuery } from "./service-shared.js";
|
|
4
|
+
import type { SellabilityPersistSnapshotInput } from "./validation.js";
|
|
5
|
+
type SellabilityResolver = typeof resolve;
|
|
6
|
+
export declare function persistResolvedSnapshot(db: PostgresJsDatabase, input: {
|
|
7
|
+
query: SellabilityResolveQuery;
|
|
8
|
+
resolved: Awaited<ReturnType<typeof resolve>>;
|
|
9
|
+
selectedCandidateIndex?: number;
|
|
10
|
+
offerId?: string | null;
|
|
11
|
+
status?: "resolved" | "offer_constructed" | "expired";
|
|
12
|
+
expiresAt?: string | null;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
id: string;
|
|
15
|
+
status: "expired" | "resolved" | "offer_constructed";
|
|
16
|
+
createdAt: Date;
|
|
17
|
+
updatedAt: Date;
|
|
18
|
+
marketId: string | null;
|
|
19
|
+
fxRateSetId: string | null;
|
|
20
|
+
productId: string | null;
|
|
21
|
+
optionId: string | null;
|
|
22
|
+
channelId: string | null;
|
|
23
|
+
offerId: string | null;
|
|
24
|
+
slotId: string | null;
|
|
25
|
+
expiresAt: Date | null;
|
|
26
|
+
requestedCurrencyCode: string | null;
|
|
27
|
+
sourceCurrencyCode: string | null;
|
|
28
|
+
queryPayload: Record<string, unknown>;
|
|
29
|
+
pricingSummary: Record<string, unknown>;
|
|
30
|
+
}>;
|
|
31
|
+
export declare function persistSnapshot(db: PostgresJsDatabase, input: SellabilityPersistSnapshotInput, resolver?: SellabilityResolver): Promise<{
|
|
32
|
+
snapshot: {
|
|
33
|
+
id: string;
|
|
34
|
+
status: "expired" | "resolved" | "offer_constructed";
|
|
35
|
+
createdAt: Date;
|
|
36
|
+
updatedAt: Date;
|
|
37
|
+
marketId: string | null;
|
|
38
|
+
fxRateSetId: string | null;
|
|
39
|
+
productId: string | null;
|
|
40
|
+
optionId: string | null;
|
|
41
|
+
channelId: string | null;
|
|
42
|
+
offerId: string | null;
|
|
43
|
+
slotId: string | null;
|
|
44
|
+
expiresAt: Date | null;
|
|
45
|
+
requestedCurrencyCode: string | null;
|
|
46
|
+
sourceCurrencyCode: string | null;
|
|
47
|
+
queryPayload: Record<string, unknown>;
|
|
48
|
+
pricingSummary: Record<string, unknown>;
|
|
49
|
+
};
|
|
50
|
+
resolved: {
|
|
51
|
+
data: {
|
|
52
|
+
product: {
|
|
53
|
+
id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
};
|
|
56
|
+
option: {
|
|
57
|
+
id: string;
|
|
58
|
+
name: string;
|
|
59
|
+
code: string | null;
|
|
60
|
+
};
|
|
61
|
+
slot: {
|
|
62
|
+
id: string;
|
|
63
|
+
productId: string;
|
|
64
|
+
optionId: string | null;
|
|
65
|
+
startTimeId: string | null;
|
|
66
|
+
dateLocal: string;
|
|
67
|
+
startsAt: Date | string;
|
|
68
|
+
timezone: string;
|
|
69
|
+
unlimited: boolean;
|
|
70
|
+
remainingPax: number | null;
|
|
71
|
+
remainingPickups: number | null;
|
|
72
|
+
pastCutoff: boolean;
|
|
73
|
+
tooEarly: boolean;
|
|
74
|
+
};
|
|
75
|
+
market: {
|
|
76
|
+
id: string;
|
|
77
|
+
code: string;
|
|
78
|
+
name: string;
|
|
79
|
+
} | null;
|
|
80
|
+
channel: {
|
|
81
|
+
id: string;
|
|
82
|
+
kind: "direct" | "reseller" | "affiliate" | "ota" | "marketplace" | "api_partner" | "connect";
|
|
83
|
+
} | null;
|
|
84
|
+
sellability: {
|
|
85
|
+
mode: "unavailable" | "sellable" | "on_request";
|
|
86
|
+
onRequest: boolean;
|
|
87
|
+
allotmentStatus: "sellable" | "not_applicable";
|
|
88
|
+
};
|
|
89
|
+
pricing: {
|
|
90
|
+
currencyCode: string;
|
|
91
|
+
sellAmountCents: number;
|
|
92
|
+
costAmountCents: number;
|
|
93
|
+
marginAmountCents: number;
|
|
94
|
+
breakdown: import("./service-shared.js").ResolvedPriceBreakdown[];
|
|
95
|
+
components: ResolvedPriceComponent[];
|
|
96
|
+
fx: {
|
|
97
|
+
fxRateSetId: string;
|
|
98
|
+
baseCurrency: string;
|
|
99
|
+
quoteCurrency: string;
|
|
100
|
+
rateDecimal: number;
|
|
101
|
+
} | null;
|
|
102
|
+
};
|
|
103
|
+
sources: {
|
|
104
|
+
marketProductRuleId: string | null;
|
|
105
|
+
marketChannelRuleId: string | null;
|
|
106
|
+
marketPriceCatalogId: string | null;
|
|
107
|
+
optionPriceRuleId: string;
|
|
108
|
+
optionStartTimeRuleId: string | null;
|
|
109
|
+
channelInventoryAllotmentIds: string[];
|
|
110
|
+
channelInventoryReleaseRuleId: string | null;
|
|
111
|
+
};
|
|
112
|
+
}[];
|
|
113
|
+
meta: {
|
|
114
|
+
total: number;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
}>;
|
|
118
|
+
export declare function listSnapshots(db: PostgresJsDatabase, query: SellabilitySnapshotListQuery): Promise<{
|
|
119
|
+
data: {
|
|
120
|
+
id: string;
|
|
121
|
+
offerId: string | null;
|
|
122
|
+
marketId: string | null;
|
|
123
|
+
channelId: string | null;
|
|
124
|
+
productId: string | null;
|
|
125
|
+
optionId: string | null;
|
|
126
|
+
slotId: string | null;
|
|
127
|
+
requestedCurrencyCode: string | null;
|
|
128
|
+
sourceCurrencyCode: string | null;
|
|
129
|
+
fxRateSetId: string | null;
|
|
130
|
+
status: "expired" | "resolved" | "offer_constructed";
|
|
131
|
+
queryPayload: Record<string, unknown>;
|
|
132
|
+
pricingSummary: Record<string, unknown>;
|
|
133
|
+
expiresAt: Date | null;
|
|
134
|
+
createdAt: Date;
|
|
135
|
+
updatedAt: Date;
|
|
136
|
+
}[];
|
|
137
|
+
total: number;
|
|
138
|
+
limit: number;
|
|
139
|
+
offset: number;
|
|
140
|
+
}>;
|
|
141
|
+
export declare function getSnapshotById(db: PostgresJsDatabase, id: string): Promise<{
|
|
142
|
+
id: string;
|
|
143
|
+
offerId: string | null;
|
|
144
|
+
marketId: string | null;
|
|
145
|
+
channelId: string | null;
|
|
146
|
+
productId: string | null;
|
|
147
|
+
optionId: string | null;
|
|
148
|
+
slotId: string | null;
|
|
149
|
+
requestedCurrencyCode: string | null;
|
|
150
|
+
sourceCurrencyCode: string | null;
|
|
151
|
+
fxRateSetId: string | null;
|
|
152
|
+
status: "expired" | "resolved" | "offer_constructed";
|
|
153
|
+
queryPayload: Record<string, unknown>;
|
|
154
|
+
pricingSummary: Record<string, unknown>;
|
|
155
|
+
expiresAt: Date | null;
|
|
156
|
+
createdAt: Date;
|
|
157
|
+
updatedAt: Date;
|
|
158
|
+
} | null>;
|
|
159
|
+
export declare function listSnapshotItems(db: PostgresJsDatabase, query: SellabilitySnapshotItemListQuery): Promise<{
|
|
160
|
+
data: {
|
|
161
|
+
id: string;
|
|
162
|
+
snapshotId: string;
|
|
163
|
+
candidateIndex: number;
|
|
164
|
+
componentIndex: number;
|
|
165
|
+
productId: string | null;
|
|
166
|
+
optionId: string | null;
|
|
167
|
+
slotId: string | null;
|
|
168
|
+
unitId: string | null;
|
|
169
|
+
requestRef: string | null;
|
|
170
|
+
componentKind: "base" | "unit" | "pickup" | "start_time_adjustment";
|
|
171
|
+
title: string;
|
|
172
|
+
quantity: number;
|
|
173
|
+
pricingMode: string;
|
|
174
|
+
pricingCategoryId: string | null;
|
|
175
|
+
pricingCategoryName: string | null;
|
|
176
|
+
unitName: string | null;
|
|
177
|
+
unitType: string | null;
|
|
178
|
+
currencyCode: string;
|
|
179
|
+
sellAmountCents: number;
|
|
180
|
+
costAmountCents: number;
|
|
181
|
+
sourceRuleId: string | null;
|
|
182
|
+
tierId: string | null;
|
|
183
|
+
isSelected: boolean;
|
|
184
|
+
createdAt: Date;
|
|
185
|
+
}[];
|
|
186
|
+
total: number;
|
|
187
|
+
limit: number;
|
|
188
|
+
offset: number;
|
|
189
|
+
}>;
|
|
190
|
+
export {};
|
|
191
|
+
//# sourceMappingURL=service-snapshots.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-snapshots.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BAAiB,CACrC,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,gCAAgC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwBxC"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { and, asc, desc, eq, sql } from "drizzle-orm";
|
|
2
|
+
import { sellabilitySnapshotItems, sellabilitySnapshots } from "./schema.js";
|
|
3
|
+
import { resolve } from "./service-resolve.js";
|
|
4
|
+
import { paginate, } from "./service-shared.js";
|
|
5
|
+
function normalizeDateTime(value) {
|
|
6
|
+
return value ? new Date(value) : null;
|
|
7
|
+
}
|
|
8
|
+
export async function persistResolvedSnapshot(db, input) {
|
|
9
|
+
const primaryCandidate = input.resolved.data[0] ?? null;
|
|
10
|
+
const [snapshot] = await db
|
|
11
|
+
.insert(sellabilitySnapshots)
|
|
12
|
+
.values({
|
|
13
|
+
offerId: input.offerId ?? null,
|
|
14
|
+
marketId: primaryCandidate?.market?.id ?? input.query.marketId ?? null,
|
|
15
|
+
channelId: primaryCandidate?.channel?.id ?? input.query.channelId ?? null,
|
|
16
|
+
productId: primaryCandidate?.product.id ?? input.query.productId ?? null,
|
|
17
|
+
optionId: primaryCandidate?.option.id ?? input.query.optionId ?? null,
|
|
18
|
+
slotId: primaryCandidate?.slot.id ?? input.query.slotId ?? null,
|
|
19
|
+
requestedCurrencyCode: input.query.currencyCode ?? null,
|
|
20
|
+
sourceCurrencyCode: primaryCandidate?.pricing.currencyCode ?? null,
|
|
21
|
+
fxRateSetId: primaryCandidate?.pricing.fx?.fxRateSetId ?? null,
|
|
22
|
+
status: input.status ?? "resolved",
|
|
23
|
+
queryPayload: { ...input.query },
|
|
24
|
+
pricingSummary: {
|
|
25
|
+
totalCandidates: input.resolved.meta.total,
|
|
26
|
+
selectedCandidateIndex: input.selectedCandidateIndex ?? null,
|
|
27
|
+
},
|
|
28
|
+
expiresAt: normalizeDateTime(input.expiresAt ?? null),
|
|
29
|
+
})
|
|
30
|
+
.returning();
|
|
31
|
+
if (!snapshot) {
|
|
32
|
+
throw new Error("Failed to persist sellability snapshot");
|
|
33
|
+
}
|
|
34
|
+
const itemValues = input.resolved.data.flatMap((candidate, candidateIndex) => {
|
|
35
|
+
const components = candidate.pricing.components ?? [];
|
|
36
|
+
const normalizedComponents = components.length > 0
|
|
37
|
+
? components
|
|
38
|
+
: [
|
|
39
|
+
{
|
|
40
|
+
kind: "base",
|
|
41
|
+
title: candidate.option.name,
|
|
42
|
+
quantity: 1,
|
|
43
|
+
pricingMode: "per_booking",
|
|
44
|
+
sellAmountCents: candidate.pricing.sellAmountCents,
|
|
45
|
+
costAmountCents: candidate.pricing.costAmountCents,
|
|
46
|
+
unitId: null,
|
|
47
|
+
unitName: null,
|
|
48
|
+
unitType: null,
|
|
49
|
+
pricingCategoryId: null,
|
|
50
|
+
pricingCategoryName: null,
|
|
51
|
+
requestRef: null,
|
|
52
|
+
sourceRuleId: candidate.sources.optionPriceRuleId,
|
|
53
|
+
tierId: null,
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
return normalizedComponents.map((component, componentIndex) => ({
|
|
57
|
+
snapshotId: snapshot.id,
|
|
58
|
+
candidateIndex,
|
|
59
|
+
componentIndex,
|
|
60
|
+
productId: candidate.product.id,
|
|
61
|
+
optionId: candidate.option.id,
|
|
62
|
+
slotId: candidate.slot.id,
|
|
63
|
+
unitId: component.unitId,
|
|
64
|
+
requestRef: component.requestRef,
|
|
65
|
+
componentKind: component.kind,
|
|
66
|
+
title: component.title,
|
|
67
|
+
quantity: component.quantity,
|
|
68
|
+
pricingMode: component.pricingMode,
|
|
69
|
+
pricingCategoryId: component.pricingCategoryId,
|
|
70
|
+
pricingCategoryName: component.pricingCategoryName,
|
|
71
|
+
unitName: component.unitName,
|
|
72
|
+
unitType: component.unitType,
|
|
73
|
+
currencyCode: candidate.pricing.currencyCode,
|
|
74
|
+
sellAmountCents: component.sellAmountCents,
|
|
75
|
+
costAmountCents: component.costAmountCents,
|
|
76
|
+
sourceRuleId: component.sourceRuleId,
|
|
77
|
+
tierId: component.tierId,
|
|
78
|
+
isSelected: input.selectedCandidateIndex === candidateIndex,
|
|
79
|
+
}));
|
|
80
|
+
});
|
|
81
|
+
if (itemValues.length > 0) {
|
|
82
|
+
await db.insert(sellabilitySnapshotItems).values(itemValues);
|
|
83
|
+
}
|
|
84
|
+
return snapshot;
|
|
85
|
+
}
|
|
86
|
+
export async function persistSnapshot(db, input, resolver = resolve) {
|
|
87
|
+
const resolvedQuery = {
|
|
88
|
+
...input.query,
|
|
89
|
+
limit: input.query.limit ?? 25,
|
|
90
|
+
};
|
|
91
|
+
const resolved = await resolver(db, resolvedQuery);
|
|
92
|
+
const snapshot = await persistResolvedSnapshot(db, {
|
|
93
|
+
query: resolvedQuery,
|
|
94
|
+
resolved,
|
|
95
|
+
status: "resolved",
|
|
96
|
+
expiresAt: input.expiresAt ?? null,
|
|
97
|
+
});
|
|
98
|
+
return { snapshot, resolved };
|
|
99
|
+
}
|
|
100
|
+
export async function listSnapshots(db, query) {
|
|
101
|
+
const conditions = [];
|
|
102
|
+
if (query.offerId)
|
|
103
|
+
conditions.push(eq(sellabilitySnapshots.offerId, query.offerId));
|
|
104
|
+
if (query.marketId)
|
|
105
|
+
conditions.push(eq(sellabilitySnapshots.marketId, query.marketId));
|
|
106
|
+
if (query.channelId)
|
|
107
|
+
conditions.push(eq(sellabilitySnapshots.channelId, query.channelId));
|
|
108
|
+
if (query.productId)
|
|
109
|
+
conditions.push(eq(sellabilitySnapshots.productId, query.productId));
|
|
110
|
+
if (query.optionId)
|
|
111
|
+
conditions.push(eq(sellabilitySnapshots.optionId, query.optionId));
|
|
112
|
+
if (query.slotId)
|
|
113
|
+
conditions.push(eq(sellabilitySnapshots.slotId, query.slotId));
|
|
114
|
+
if (query.status)
|
|
115
|
+
conditions.push(eq(sellabilitySnapshots.status, query.status));
|
|
116
|
+
const where = conditions.length > 0 ? and(...conditions) : undefined;
|
|
117
|
+
return paginate(db
|
|
118
|
+
.select()
|
|
119
|
+
.from(sellabilitySnapshots)
|
|
120
|
+
.where(where)
|
|
121
|
+
.limit(query.limit)
|
|
122
|
+
.offset(query.offset)
|
|
123
|
+
.orderBy(desc(sellabilitySnapshots.updatedAt)), db.select({ count: sql `count(*)::int` }).from(sellabilitySnapshots).where(where), query.limit, query.offset);
|
|
124
|
+
}
|
|
125
|
+
export async function getSnapshotById(db, id) {
|
|
126
|
+
const [row] = await db
|
|
127
|
+
.select()
|
|
128
|
+
.from(sellabilitySnapshots)
|
|
129
|
+
.where(eq(sellabilitySnapshots.id, id))
|
|
130
|
+
.limit(1);
|
|
131
|
+
return row ?? null;
|
|
132
|
+
}
|
|
133
|
+
export async function listSnapshotItems(db, query) {
|
|
134
|
+
const conditions = [];
|
|
135
|
+
if (query.snapshotId)
|
|
136
|
+
conditions.push(eq(sellabilitySnapshotItems.snapshotId, query.snapshotId));
|
|
137
|
+
if (query.productId)
|
|
138
|
+
conditions.push(eq(sellabilitySnapshotItems.productId, query.productId));
|
|
139
|
+
if (query.optionId)
|
|
140
|
+
conditions.push(eq(sellabilitySnapshotItems.optionId, query.optionId));
|
|
141
|
+
if (query.slotId)
|
|
142
|
+
conditions.push(eq(sellabilitySnapshotItems.slotId, query.slotId));
|
|
143
|
+
if (query.unitId)
|
|
144
|
+
conditions.push(eq(sellabilitySnapshotItems.unitId, query.unitId));
|
|
145
|
+
const where = conditions.length > 0 ? and(...conditions) : undefined;
|
|
146
|
+
return paginate(db
|
|
147
|
+
.select()
|
|
148
|
+
.from(sellabilitySnapshotItems)
|
|
149
|
+
.where(where)
|
|
150
|
+
.limit(query.limit)
|
|
151
|
+
.offset(query.offset)
|
|
152
|
+
.orderBy(asc(sellabilitySnapshotItems.candidateIndex), asc(sellabilitySnapshotItems.componentIndex)), db.select({ count: sql `count(*)::int` }).from(sellabilitySnapshotItems).where(where), query.limit, query.offset);
|
|
153
|
+
}
|