@sixtyninecommerce/admin 0.8.0 → 0.10.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 +2739 -17
- package/dist/api-tokens/index.d.ts +15 -5
- package/dist/api-tokens/index.js +1 -0
- package/dist/apps/event-subscription.d.ts +59 -0
- package/dist/apps/event-subscription.js +32 -0
- package/dist/apps/hook-secret.d.ts +22 -0
- package/dist/apps/hook-secret.js +36 -0
- package/dist/apps/index.d.ts +54 -3
- package/dist/apps/index.js +17 -0
- package/dist/audit/index.d.ts +7 -0
- package/dist/auth/queries.d.ts +5 -1
- package/dist/auth/queries.js +6 -0
- package/dist/bulk/index.d.ts +323 -0
- package/dist/bulk/index.js +162 -0
- package/dist/catalog/assets.d.ts +147 -0
- package/dist/catalog/assets.js +164 -0
- package/dist/catalog/collections.d.ts +109 -0
- package/dist/catalog/collections.js +91 -0
- package/dist/catalog/facets.d.ts +103 -0
- package/dist/catalog/facets.js +100 -0
- package/dist/catalog/index.d.ts +115 -0
- package/dist/catalog/index.js +21 -0
- package/dist/catalog/options.d.ts +89 -0
- package/dist/catalog/options.js +88 -0
- package/dist/catalog/products-bulk.d.ts +21 -0
- package/dist/catalog/products-bulk.js +58 -0
- package/dist/catalog/products.d.ts +650 -0
- package/dist/catalog/products.js +458 -0
- package/dist/catalog/properties.d.ts +234 -0
- package/dist/catalog/properties.js +158 -0
- package/dist/catalog/types.d.ts +174 -0
- package/dist/catalog/types.js +141 -0
- package/dist/catalog/variants.d.ts +324 -0
- package/dist/catalog/variants.js +288 -0
- package/dist/catalog/visibility.d.ts +57 -0
- package/dist/catalog/visibility.js +59 -0
- package/dist/client.d.ts +192 -3
- package/dist/client.js +87 -12
- package/dist/compliance/index.d.ts +88 -0
- package/dist/compliance/index.js +88 -0
- package/dist/customer-data-redaction.d.ts +14 -0
- package/dist/customer-data-redaction.js +22 -0
- package/dist/customers/index.d.ts +428 -17
- package/dist/customers/index.js +322 -15
- package/dist/documents/index.d.ts +513 -16
- package/dist/documents/index.js +229 -3
- package/dist/events/index.d.ts +259 -0
- package/dist/events/index.js +147 -0
- package/dist/feeds/ai.d.ts +46 -0
- package/dist/feeds/ai.js +43 -0
- package/dist/feeds/categories.d.ts +50 -0
- package/dist/feeds/categories.js +56 -0
- package/dist/feeds/configs.d.ts +54 -0
- package/dist/feeds/configs.js +85 -0
- package/dist/feeds/identifier-fields.d.ts +25 -0
- package/dist/feeds/identifier-fields.js +29 -0
- package/dist/feeds/index.d.ts +54 -0
- package/dist/feeds/index.js +46 -0
- package/dist/feeds/preserve.d.ts +38 -0
- package/dist/feeds/preserve.js +74 -0
- package/dist/feeds/rules.d.ts +42 -0
- package/dist/feeds/rules.js +56 -0
- package/dist/feeds/types.d.ts +654 -0
- package/dist/feeds/types.js +135 -0
- package/dist/fulfillments/index.d.ts +437 -0
- package/dist/fulfillments/index.js +534 -0
- package/dist/heads/index.d.ts +60 -0
- package/dist/heads/index.js +45 -0
- package/dist/hooks/assignments.d.ts +90 -0
- package/dist/hooks/assignments.js +53 -0
- package/dist/hooks/index.d.ts +97 -0
- package/dist/hooks/index.js +76 -0
- package/dist/index.d.ts +95 -9
- package/dist/index.js +21 -1
- package/dist/integrations/index.d.ts +14 -0
- package/dist/integrations/index.js +9 -0
- package/dist/integrations/pipelines.d.ts +113 -0
- package/dist/integrations/pipelines.js +62 -0
- package/dist/integrations/types.d.ts +176 -0
- package/dist/integrations/types.js +8 -0
- package/dist/jobs/bulk-action-run.d.ts +74 -0
- package/dist/jobs/bulk-action-run.js +69 -0
- package/dist/locations/index.d.ts +6 -2
- package/dist/meta/index.d.ts +32 -0
- package/dist/orders/bulk.d.ts +75 -0
- package/dist/orders/bulk.js +150 -0
- package/dist/orders/commit-edit.d.ts +123 -0
- package/dist/orders/commit-edit.js +142 -0
- package/dist/orders/deposit-policy.d.ts +103 -0
- package/dist/orders/deposit-policy.js +202 -0
- package/dist/orders/get.d.ts +722 -0
- package/dist/orders/get.js +530 -0
- package/dist/orders/index.d.ts +186 -21
- package/dist/orders/index.js +57 -0
- package/dist/orders/line-price-preview.d.ts +297 -0
- package/dist/orders/line-price-preview.js +50 -0
- package/dist/orders/manual-discounts.d.ts +141 -0
- package/dist/orders/manual-discounts.js +97 -0
- package/dist/orders/manual-pricing.d.ts +192 -0
- package/dist/orders/manual-pricing.js +72 -0
- package/dist/orders/order-entry.d.ts +566 -0
- package/dist/orders/order-entry.js +129 -0
- package/dist/orders/parcel-charge.d.ts +45 -0
- package/dist/orders/parcel-charge.js +55 -0
- package/dist/orders/plan-edit.d.ts +489 -0
- package/dist/orders/plan-edit.js +93 -0
- package/dist/orders/status.d.ts +235 -0
- package/dist/orders/status.js +96 -0
- package/dist/orders/surcharges.d.ts +75 -2
- package/dist/orders/surcharges.js +110 -4
- package/dist/payments/account-credit.d.ts +171 -0
- package/dist/payments/account-credit.js +107 -0
- package/dist/payments/index.d.ts +241 -9
- package/dist/payments/index.js +92 -0
- package/dist/payments/methods.d.ts +37 -0
- package/dist/payments/methods.js +33 -0
- package/dist/platform/catalog.d.ts +148 -0
- package/dist/platform/catalog.js +74 -0
- package/dist/platform/entitlements.d.ts +111 -0
- package/dist/platform/entitlements.js +86 -0
- package/dist/platform/legal-entities.d.ts +139 -0
- package/dist/platform/legal-entities.js +126 -0
- package/dist/platform/legal-entity-numbering.d.ts +103 -0
- package/dist/platform/legal-entity-numbering.js +101 -0
- package/dist/platform/organization-membership.d.ts +80 -0
- package/dist/platform/organization-membership.js +71 -0
- package/dist/platform/organization-settings.d.ts +33 -0
- package/dist/platform/organization-settings.js +42 -0
- package/dist/platform/organization-sharing.d.ts +172 -0
- package/dist/platform/organization-sharing.js +120 -0
- package/dist/platform/organizations.d.ts +205 -0
- package/dist/platform/organizations.js +180 -0
- package/dist/platform/provision-store.d.ts +88 -8
- package/dist/platform/provision-store.js +12 -0
- package/dist/platform/reports.d.ts +46 -0
- package/dist/platform/reports.js +31 -0
- package/dist/platform/server-metrics.d.ts +58 -0
- package/dist/platform/server-metrics.js +11 -0
- package/dist/pos/index.d.ts +567 -0
- package/dist/pos/index.js +205 -0
- package/dist/pricing/index.d.ts +408 -0
- package/dist/pricing/index.js +353 -0
- package/dist/pricing/vouchers.d.ts +103 -0
- package/dist/pricing/vouchers.js +69 -0
- package/dist/provenance/index.d.ts +93 -0
- package/dist/provenance/index.js +53 -0
- package/dist/reports/index.d.ts +199 -0
- package/dist/reports/index.js +154 -0
- package/dist/returns/index.d.ts +225 -0
- package/dist/returns/index.js +160 -0
- package/dist/search/index.d.ts +99 -0
- package/dist/search/index.js +62 -0
- package/dist/shipping/parcel-count-suggestion.d.ts +52 -0
- package/dist/shipping/parcel-count-suggestion.js +73 -0
- package/dist/shipping/parcel-rule.d.ts +48 -0
- package/dist/shipping/parcel-rule.js +91 -0
- package/dist/stock/index.d.ts +166 -0
- package/dist/stock/index.js +115 -0
- package/dist/stock/transfers.d.ts +520 -0
- package/dist/stock/transfers.js +437 -0
- package/dist/stored-value/index.d.ts +154 -0
- package/dist/stored-value/index.js +130 -0
- package/dist/tenant/capabilities.d.ts +10 -0
- package/dist/tenant/entitlements.d.ts +35 -0
- package/dist/tenant/entitlements.js +15 -0
- package/dist/tenant/field-groups.d.ts +64 -0
- package/dist/tenant/field-groups.js +34 -0
- package/dist/tenant/legal-entity.d.ts +32 -0
- package/dist/tenant/legal-entity.js +41 -0
- package/dist/tenant/notifications.d.ts +148 -0
- package/dist/tenant/notifications.js +79 -0
- package/dist/tenant/retention.d.ts +10 -4
- package/dist/tenant/settings-sources.d.ts +103 -0
- package/dist/tenant/settings-sources.js +92 -0
- package/dist/types.d.ts +86 -11
- package/dist/uploads/index.d.ts +11 -7
- package/dist/users/index.d.ts +104 -0
- package/dist/users/index.js +80 -0
- package/package.json +3 -2
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { type Page, type Transport } from '@sixtyninecommerce/core';
|
|
2
|
+
import type { Call, ListOptions } from '../types.js';
|
|
3
|
+
import { type StockTransfersModule } from './transfers.js';
|
|
4
|
+
/**
|
|
5
|
+
* One variant's stock at one location, in integer units.
|
|
6
|
+
*
|
|
7
|
+
* - `onHand` / `allocated` — what the location holds, and how much of it is
|
|
8
|
+
* reserved for orders.
|
|
9
|
+
* - `reserved` — what the location's out-of-stock threshold holds back from
|
|
10
|
+
* sale (the location's own threshold when it sets one, else the variant's or
|
|
11
|
+
* the store's): `max(0, threshold)`.
|
|
12
|
+
* - `available` — `onHand − allocated − threshold`, exactly what the allocator
|
|
13
|
+
* can still reserve here. NOT floored at zero: an order allowed to backorder
|
|
14
|
+
* allocates past on-hand, and that shortfall shows as a negative figure. A
|
|
15
|
+
* negative threshold (an oversell allowance) raises it above
|
|
16
|
+
* `onHand − allocated`.
|
|
17
|
+
* - `incoming` — open units expected at this location (purchase orders).
|
|
18
|
+
* - `trackInventory: false` — the variant does not track stock, so none of
|
|
19
|
+
* these figures gates a sale.
|
|
20
|
+
*/
|
|
21
|
+
export interface StockPosition {
|
|
22
|
+
locationId: string;
|
|
23
|
+
locationName: string | null;
|
|
24
|
+
onHand: number;
|
|
25
|
+
allocated: number;
|
|
26
|
+
available: number;
|
|
27
|
+
incoming: number;
|
|
28
|
+
reserved: number;
|
|
29
|
+
trackInventory: boolean;
|
|
30
|
+
}
|
|
31
|
+
export type StockMovementType = 'ADJUSTMENT' | 'ALLOCATION' | 'RELEASE' | 'SALE' | 'CANCELLATION' | 'RETURN';
|
|
32
|
+
/** One line of a variant's stock ledger. */
|
|
33
|
+
export interface StockMovement {
|
|
34
|
+
id: string;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
type: StockMovementType;
|
|
37
|
+
/**
|
|
38
|
+
* The movement's own signed quantity as the engine stores it. A `SALE` is
|
|
39
|
+
* negative; a `RELEASE` is stored positive although it lowers `allocated`.
|
|
40
|
+
*/
|
|
41
|
+
quantity: number;
|
|
42
|
+
stockLocation: {
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
} | null;
|
|
46
|
+
/**
|
|
47
|
+
* Why it moved, in the store's own words. Null for movements made anywhere
|
|
48
|
+
* but `stock.adjust` (orders, imports, the dashboard's variant form) — and
|
|
49
|
+
* for a reason another store recorded at a location you share.
|
|
50
|
+
*/
|
|
51
|
+
reason: string | null;
|
|
52
|
+
referenceDocumentRef: string | null;
|
|
53
|
+
/** The staff member a machine credential vouched for (`actor.staffRef`). */
|
|
54
|
+
actorRef: string | null;
|
|
55
|
+
}
|
|
56
|
+
export interface StockMovementFilter extends ListOptions {
|
|
57
|
+
/**
|
|
58
|
+
* One location of this store; omitted → the tenant's `location`, else every
|
|
59
|
+
* location the credential may use.
|
|
60
|
+
*/
|
|
61
|
+
locationId?: string;
|
|
62
|
+
type?: StockMovementType;
|
|
63
|
+
}
|
|
64
|
+
export interface StockPositionOptions extends Call {
|
|
65
|
+
/**
|
|
66
|
+
* One location of this store; omitted → the tenant's `location`, else every
|
|
67
|
+
* location the credential may use.
|
|
68
|
+
*/
|
|
69
|
+
locationId?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface AdjustStockInput {
|
|
72
|
+
variantId: string;
|
|
73
|
+
/** Omitted → the tenant's `location` (`x-location`). One of the two is required. */
|
|
74
|
+
locationId?: string;
|
|
75
|
+
/** Units to add (positive) or remove (negative). Never zero. */
|
|
76
|
+
delta: number;
|
|
77
|
+
/**
|
|
78
|
+
* REQUIRED — 1 to 255 printable characters, in your own vocabulary
|
|
79
|
+
* (`cycle count`, `damaged`, `found in aisle 4`). The platform never
|
|
80
|
+
* interprets it; it exists so no adjustment is ever unexplained.
|
|
81
|
+
*/
|
|
82
|
+
reason: string;
|
|
83
|
+
/** The document behind it — a count sheet, a PO, a damage report. Up to 255 characters. */
|
|
84
|
+
referenceDocumentRef?: string;
|
|
85
|
+
}
|
|
86
|
+
export interface ReleasedAllocation {
|
|
87
|
+
orderId: string;
|
|
88
|
+
/** Units handed back to the stock they were reserved from. */
|
|
89
|
+
releasedQuantity: number;
|
|
90
|
+
}
|
|
91
|
+
export interface StockAllocationsModule {
|
|
92
|
+
/**
|
|
93
|
+
* Hand back every unit an order has reserved, WITHOUT changing the order's
|
|
94
|
+
* state — for an order stuck before fulfilment whose stock is needed.
|
|
95
|
+
* Refused (`BusinessRuleError`) with `ORDER_NOT_IN_RELEASABLE_STATE_ERROR`
|
|
96
|
+
* once anything has shipped, `ORDER_INVOICE_LOCKED` for an invoiced order
|
|
97
|
+
* (no caller releases one), and `NO_ALLOCATIONS_TO_RELEASE_ERROR` when
|
|
98
|
+
* nothing is reserved; `NotFoundError` for an order of another store.
|
|
99
|
+
* A token or app restricted with `locationIds` is refused
|
|
100
|
+
* `LOCATION_NOT_ALLOWED` (→ `PermissionDeniedError`) unless it holds every
|
|
101
|
+
* location the order's reservation sits at: the release is all-or-nothing.
|
|
102
|
+
* Needs `UpdateOrder`.
|
|
103
|
+
*/
|
|
104
|
+
release(orderId: string, options?: Call): Promise<ReleasedAllocation>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Stock per location (spec §9.2 `stock`, §8.7).
|
|
108
|
+
*
|
|
109
|
+
* Reads need `ReadStockLocation`; `adjust` needs `AdjustStock` (the `stock` API-token
|
|
110
|
+
* template). `UpdateStockLocation` still admits `adjust` for credentials minted before
|
|
111
|
+
* `AdjustStock` existed; a later release ends that, announced in the changelog first.
|
|
112
|
+
* Everything is scoped to the store the client is on: a location another store
|
|
113
|
+
* owns is refused, never read — and a location SHARED with another store shows
|
|
114
|
+
* the same levels and movements to both, but each store's reasons only to
|
|
115
|
+
* itself.
|
|
116
|
+
*
|
|
117
|
+
* **The tenant's `location` is the default place.** Set it once
|
|
118
|
+
* (`withTenant({ location })`) and `position`, `movements` and `adjust` act at
|
|
119
|
+
* that location unless a call names another.
|
|
120
|
+
*
|
|
121
|
+
* **Coded refusals**, as GraphQL errors with `extensions.code`:
|
|
122
|
+
* `STOCK_REASON_INVALID`, `STOCK_REFERENCE_INVALID` and `STOCK_DELTA_INVALID`
|
|
123
|
+
* (→ `ValidationError`); `STOCK_VARIANT_NOT_FOUND` (→ `NotFoundError`, also the
|
|
124
|
+
* answer for another store's variant); `LOCATION_NOT_IN_CHANNEL`
|
|
125
|
+
* (→ `ValidationError`, a location of another store); `LOCATION_NOT_ALLOWED`
|
|
126
|
+
* (→ `PermissionDeniedError`, a location of this store that a token or app
|
|
127
|
+
* restricted with `locationIds` may not use — reads without a location are
|
|
128
|
+
* narrowed to that list instead); `STOCK_LOCATION_REQUIRED` and
|
|
129
|
+
* `STOCK_WOULD_GO_NEGATIVE` (→ `BusinessRuleError`).
|
|
130
|
+
*/
|
|
131
|
+
export interface StockModule {
|
|
132
|
+
/** The variant's stock at every location of this store (or one). A location that never held it has no entry. */
|
|
133
|
+
position(variantId: string, options?: StockPositionOptions): Promise<StockPosition[]>;
|
|
134
|
+
/** The variant's ledger at this store's locations, with each movement's reason. */
|
|
135
|
+
movements(variantId: string, filter?: StockMovementFilter): Promise<Page<StockMovement>>;
|
|
136
|
+
/**
|
|
137
|
+
* Add or remove stock at one location, with the reason, and get the
|
|
138
|
+
* location's position back.
|
|
139
|
+
*
|
|
140
|
+
* `options.idempotencyKey` is honoured: a retry under the same key answers
|
|
141
|
+
* the FIRST call's position and moves nothing — that position is the stock as
|
|
142
|
+
* it stood right after the first call, not as it stands now. A decrease may
|
|
143
|
+
* not take on-hand below zero (`STOCK_WOULD_GO_NEGATIVE`); an increase is
|
|
144
|
+
* always allowed, so a level that has drifted negative can be corrected.
|
|
145
|
+
*
|
|
146
|
+
* The movement also reaches event subscribers twice: as `stock.level_changed`
|
|
147
|
+
* with `cause: 'adjustment'` (the levels, no reason), and as `stock.adjusted`
|
|
148
|
+
* (the delta, resulting on-hand, `reason` and `reference_document_ref`). The
|
|
149
|
+
* second is flagged as personal data because the text is yours and free; a
|
|
150
|
+
* subscription on it cannot ask for customer-identity redaction.
|
|
151
|
+
*
|
|
152
|
+
* While an app or API token owns Stock on the store, an adjustment by anyone else is refused
|
|
153
|
+
* `FIELD_GROUP_LOCKED` (`BusinessRuleError`), as are stock levels set through
|
|
154
|
+
* `catalog.variants.update` and the stock moves of a transfer. Moves that follow an order
|
|
155
|
+
* (sales, reservations, fulfilments, a return put back in stock) always pass.
|
|
156
|
+
*/
|
|
157
|
+
adjust(input: AdjustStockInput, options?: Call): Promise<StockPosition>;
|
|
158
|
+
/** Stock transfers between this store's locations, and consumptions at one. */
|
|
159
|
+
transfers: StockTransfersModule;
|
|
160
|
+
allocations: StockAllocationsModule;
|
|
161
|
+
}
|
|
162
|
+
export declare const STOCK_POSITION_QUERY = "\n query StockPosition($variantId: ID!, $locationId: ID) {\n stockPosition(variantId: $variantId, locationId: $locationId) { \n locationId\n locationName\n onHand\n allocated\n available\n incoming\n reserved\n trackInventory\n }\n }\n";
|
|
163
|
+
export declare const STOCK_MOVEMENTS_QUERY: string;
|
|
164
|
+
export declare const ADJUST_STOCK_MUTATION = "\n mutation AdjustStock($input: AdjustStockInput!, $idempotencyKey: String) {\n adjustStock(input: $input, idempotencyKey: $idempotencyKey) { \n locationId\n locationName\n onHand\n allocated\n available\n incoming\n reserved\n trackInventory\n }\n }\n";
|
|
165
|
+
export declare const RELEASE_ORDER_ALLOCATION_MUTATION = "\n mutation ReleaseOrderAllocation($orderId: ID!) {\n releaseOrderAllocation(orderId: $orderId) {\n __typename\n ... on ReleaseOrderAllocationSuccess { orderId releasedQuantity }\n ... on ErrorResult { errorCode message }\n }\n }\n";
|
|
166
|
+
export declare function createStockModule(transport: Transport): StockModule;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { errorFromErrorResult, isErrorResult, pageFromVendureList, readOffsetCursor, } from '@sixtyninecommerce/core';
|
|
2
|
+
import { createStockTransfersModule } from './transfers.js';
|
|
3
|
+
const POSITION_FIELDS = /* GraphQL */ `
|
|
4
|
+
locationId
|
|
5
|
+
locationName
|
|
6
|
+
onHand
|
|
7
|
+
allocated
|
|
8
|
+
available
|
|
9
|
+
incoming
|
|
10
|
+
reserved
|
|
11
|
+
trackInventory
|
|
12
|
+
`;
|
|
13
|
+
const MOVEMENT_TYPES = [
|
|
14
|
+
'StockAdjustment',
|
|
15
|
+
'Allocation',
|
|
16
|
+
'Sale',
|
|
17
|
+
'Cancellation',
|
|
18
|
+
'Return',
|
|
19
|
+
'Release',
|
|
20
|
+
];
|
|
21
|
+
// `stockLocation` is declared per concrete type, not on the `StockMovement`
|
|
22
|
+
// interface, so it is selected through one fragment per type.
|
|
23
|
+
const MOVEMENT_FIELDS = /* GraphQL */ `
|
|
24
|
+
... on StockMovement {
|
|
25
|
+
id
|
|
26
|
+
createdAt
|
|
27
|
+
type
|
|
28
|
+
quantity
|
|
29
|
+
reason
|
|
30
|
+
referenceDocumentRef
|
|
31
|
+
actorRef
|
|
32
|
+
}
|
|
33
|
+
${MOVEMENT_TYPES.map((type) => `... on ${type} { stockLocation { id name } }`).join('\n ')}
|
|
34
|
+
`;
|
|
35
|
+
export const STOCK_POSITION_QUERY = /* GraphQL */ `
|
|
36
|
+
query StockPosition($variantId: ID!, $locationId: ID) {
|
|
37
|
+
stockPosition(variantId: $variantId, locationId: $locationId) { ${POSITION_FIELDS} }
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
export const STOCK_MOVEMENTS_QUERY = /* GraphQL */ `
|
|
41
|
+
query StockMovements($variantId: ID!, $locationId: ID, $options: StockMovementListOptions) {
|
|
42
|
+
stockMovements(variantId: $variantId, locationId: $locationId, options: $options) {
|
|
43
|
+
items { ${MOVEMENT_FIELDS} }
|
|
44
|
+
totalItems
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
export const ADJUST_STOCK_MUTATION = /* GraphQL */ `
|
|
49
|
+
mutation AdjustStock($input: AdjustStockInput!, $idempotencyKey: String) {
|
|
50
|
+
adjustStock(input: $input, idempotencyKey: $idempotencyKey) { ${POSITION_FIELDS} }
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
export const RELEASE_ORDER_ALLOCATION_MUTATION = /* GraphQL */ `
|
|
54
|
+
mutation ReleaseOrderAllocation($orderId: ID!) {
|
|
55
|
+
releaseOrderAllocation(orderId: $orderId) {
|
|
56
|
+
__typename
|
|
57
|
+
... on ReleaseOrderAllocationSuccess { orderId releasedQuantity }
|
|
58
|
+
... on ErrorResult { errorCode message }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
62
|
+
const DEFAULT_PAGE_SIZE = 50;
|
|
63
|
+
export function createStockModule(transport) {
|
|
64
|
+
const movementsPage = async (variantId, skip, take, filter) => {
|
|
65
|
+
const data = await transport.graphql({
|
|
66
|
+
api: 'admin',
|
|
67
|
+
query: STOCK_MOVEMENTS_QUERY,
|
|
68
|
+
variables: {
|
|
69
|
+
variantId,
|
|
70
|
+
locationId: filter?.locationId ?? null,
|
|
71
|
+
options: { skip, take, ...(filter?.type ? { type: filter.type } : {}) },
|
|
72
|
+
},
|
|
73
|
+
}, filter);
|
|
74
|
+
const items = data.stockMovements.items.map((item) => ({
|
|
75
|
+
...item,
|
|
76
|
+
stockLocation: item.stockLocation ?? null,
|
|
77
|
+
}));
|
|
78
|
+
return pageFromVendureList({ items, totalItems: data.stockMovements.totalItems }, skip, take, (cursor) => movementsPage(variantId, readOffsetCursor(cursor), take, filter));
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
async position(variantId, options) {
|
|
82
|
+
const data = await transport.graphql({
|
|
83
|
+
api: 'admin',
|
|
84
|
+
query: STOCK_POSITION_QUERY,
|
|
85
|
+
variables: { variantId, locationId: options?.locationId ?? null },
|
|
86
|
+
}, options);
|
|
87
|
+
return data.stockPosition;
|
|
88
|
+
},
|
|
89
|
+
movements(variantId, filter) {
|
|
90
|
+
// Offset-paged underneath; the offset rides inside the cursor (spec §9.3).
|
|
91
|
+
const take = filter?.limit ?? DEFAULT_PAGE_SIZE;
|
|
92
|
+
const skip = filter?.after === undefined ? 0 : readOffsetCursor(filter.after);
|
|
93
|
+
return movementsPage(variantId, skip, take, filter);
|
|
94
|
+
},
|
|
95
|
+
async adjust(input, options) {
|
|
96
|
+
const data = await transport.graphql({
|
|
97
|
+
api: 'admin',
|
|
98
|
+
query: ADJUST_STOCK_MUTATION,
|
|
99
|
+
variables: { input, idempotencyKey: options?.idempotencyKey },
|
|
100
|
+
}, options);
|
|
101
|
+
return data.adjustStock;
|
|
102
|
+
},
|
|
103
|
+
transfers: createStockTransfersModule(transport),
|
|
104
|
+
allocations: {
|
|
105
|
+
async release(orderId, options) {
|
|
106
|
+
const data = await transport.graphql({ api: 'admin', query: RELEASE_ORDER_ALLOCATION_MUTATION, variables: { orderId } }, options);
|
|
107
|
+
const result = data.releaseOrderAllocation;
|
|
108
|
+
if (isErrorResult(result))
|
|
109
|
+
throw errorFromErrorResult(result);
|
|
110
|
+
const released = result;
|
|
111
|
+
return { orderId: released.orderId, releasedQuantity: released.releasedQuantity };
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|