@sixtyninecommerce/admin 0.9.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 +294 -0
- package/dist/catalog/products.d.ts +162 -1
- package/dist/catalog/products.js +94 -1
- package/dist/catalog/variants.d.ts +50 -0
- package/dist/catalog/variants.js +48 -18
- package/dist/client.d.ts +21 -0
- package/dist/client.js +6 -0
- package/dist/fulfillments/index.d.ts +77 -0
- package/dist/fulfillments/index.js +109 -0
- package/dist/index.d.ts +15 -4
- package/dist/index.js +5 -0
- 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 +11 -2
- package/dist/jobs/bulk-action-run.js +4 -5
- package/dist/orders/bulk.d.ts +75 -0
- package/dist/orders/bulk.js +150 -0
- package/dist/orders/deposit-policy.d.ts +103 -0
- package/dist/orders/deposit-policy.js +202 -0
- package/dist/orders/index.d.ts +80 -0
- package/dist/orders/index.js +13 -0
- package/dist/orders/manual-discounts.d.ts +11 -2
- package/dist/orders/manual-discounts.js +2 -0
- package/dist/payments/index.d.ts +7 -0
- package/dist/payments/index.js +2 -0
- package/dist/payments/methods.d.ts +37 -0
- package/dist/payments/methods.js +33 -0
- package/dist/pricing/index.d.ts +3 -0
- package/dist/pricing/index.js +2 -0
- package/dist/pricing/vouchers.d.ts +103 -0
- package/dist/pricing/vouchers.js +69 -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/types.d.ts +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { type Page, type Transport } from '@sixtyninecommerce/core';
|
|
2
|
+
import type { Call, ListOptions } from '../types.js';
|
|
3
|
+
import type { CommittedPipelineDraft, ImportDependency, PipelineDirection, PipelineDraft, PipelineDraftSummary, UpdatePipelineDraftInput, UpdatePipelineDraftSchemaMapInput } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Every key whose VALUE is stored data, not DTO shape: the platform's passthrough set
|
|
6
|
+
* (`credentials`, `public_credentials`, `site_analysis`, `trigger_filter`, …) plus a schema map's
|
|
7
|
+
* jsonb columns, which carry the source's own field names and sample records. Converting them
|
|
8
|
+
* would rename a sample's `date_created` to `dateCreated`, and a `triggerFilter`'s `toState` would
|
|
9
|
+
* reach the reader as `to_state`, which it ignores.
|
|
10
|
+
*/
|
|
11
|
+
export declare const PIPELINE_DRAFT_PRESERVE_KEYS: ReadonlySet<string>;
|
|
12
|
+
/**
|
|
13
|
+
* A creation probes the source over the network, and a commit creates the pipeline and may start
|
|
14
|
+
* its run: both outlast the SDK's 15-second default on a slow source.
|
|
15
|
+
*/
|
|
16
|
+
export declare const PIPELINE_DRAFT_SLOW_TIMEOUT_MS = 60000;
|
|
17
|
+
/**
|
|
18
|
+
* Half-finished import and export set-ups, kept on the server for the store (headless spec §7).
|
|
19
|
+
*
|
|
20
|
+
* - **Any admin of the store with pipeline rights (`UpdateCatalog`) continues a draft, from any
|
|
21
|
+
* device.** Drafts belong to the store, not to the person who started one: the list shows every
|
|
22
|
+
* unfinished set-up of the active store, and another store's draft is `PIPELINE_DRAFT_NOT_FOUND`.
|
|
23
|
+
* - **Kept 7 days after its LAST change.** Every write moves `expiresAt`; reads do not. An expired
|
|
24
|
+
* draft answers `PIPELINE_DRAFT_NOT_FOUND` at once, and the platform then deletes it together
|
|
25
|
+
* with the connection (and its stored password) the draft created, unless a pipeline or another
|
|
26
|
+
* draft uses that connection. A connection that existed before any draft is never deleted; one
|
|
27
|
+
* another draft created is the picking draft's too (`connection.createdByDraft`), and goes when
|
|
28
|
+
* the last draft holding it lets go of it unused.
|
|
29
|
+
* - **A draft never holds a secret.** Credentials go to {@link PipelineDraftsModule.connect} only,
|
|
30
|
+
* which creates the connection and stores them there, encrypted. A set-up resumed before its
|
|
31
|
+
* connection exists asks for the credentials again; the source URL and the other settings are
|
|
32
|
+
* kept.
|
|
33
|
+
* - **Every change names the `version` it was made against** and answers the draft with the next
|
|
34
|
+
* one. A change made on an older version is refused with a `ConflictError` coded
|
|
35
|
+
* `PIPELINE_DRAFT_CONFLICT` (409) and changes nothing: another admin, or another tab, changed it
|
|
36
|
+
* first. Read it again and reapply.
|
|
37
|
+
* - What a step still needs is a `BusinessRuleError` coded `PIPELINE_DRAFT_INCOMPLETE` (422) whose
|
|
38
|
+
* `details[]` name each field; a change the set-up refuses (a step of the other direction, a
|
|
39
|
+
* connector that cannot work in it) is a `ValidationError` coded `PIPELINE_DRAFT_INVALID` (400).
|
|
40
|
+
* - An organization workspace is not a store and is refused every door; an app below
|
|
41
|
+
* `customerData: full` is too, and `connect` refuses every app (`APP_CREDENTIAL_NOT_ALLOWED`).
|
|
42
|
+
*/
|
|
43
|
+
export interface PipelineDraftsModule {
|
|
44
|
+
/** The store's unexpired drafts, newest first. */
|
|
45
|
+
list(options?: ListOptions): Promise<Page<PipelineDraftSummary>>;
|
|
46
|
+
/**
|
|
47
|
+
* One draft with its connection, discovery status, schema maps, the served dependencies and their
|
|
48
|
+
* warnings, and the name the configure step would suggest in the store's zone. Poll it while
|
|
49
|
+
* `discovery.status` is `pending` or `running`.
|
|
50
|
+
*/
|
|
51
|
+
get(id: string, options?: Call): Promise<PipelineDraft>;
|
|
52
|
+
/** Start a set-up. The schedule zone starts as the store's, and the step is `connector`. */
|
|
53
|
+
create(input: {
|
|
54
|
+
direction: PipelineDirection;
|
|
55
|
+
}, options?: Call): Promise<PipelineDraft>;
|
|
56
|
+
/**
|
|
57
|
+
* Change fields. `connectorType` starts the connection over (no source URL, connection,
|
|
58
|
+
* discovery or stock location), even for the same connector; `direction` alone moves to the
|
|
59
|
+
* connector step; entering `configure` with no name gives the default one. A credential is
|
|
60
|
+
* refused here (400): send it to {@link PipelineDraftsModule.connect}.
|
|
61
|
+
*/
|
|
62
|
+
update(id: string, input: UpdatePipelineDraftInput, options?: Call): Promise<PipelineDraft>;
|
|
63
|
+
/**
|
|
64
|
+
* Create the draft's connection from its connector, source URL, throttle and legacy hosts, plus
|
|
65
|
+
* the `credentials` sent now: the source is probed first (a failed probe saves nothing), then
|
|
66
|
+
* the credentials are stored encrypted ON THE CONNECTION, never on the draft. The draft then
|
|
67
|
+
* owns the connection, so discarding or expiring it deletes the connection too. A previous
|
|
68
|
+
* connection the draft created, and its discovery, are let go.
|
|
69
|
+
*/
|
|
70
|
+
connect(id: string, input: {
|
|
71
|
+
version: number;
|
|
72
|
+
credentials: Record<string, string>;
|
|
73
|
+
}, options?: Call): Promise<PipelineDraft>;
|
|
74
|
+
/**
|
|
75
|
+
* Use one of the store's existing connections. Discarding the draft never deletes a connection
|
|
76
|
+
* that existed before any draft; one another draft created and still holds is this draft's too
|
|
77
|
+
* (`connection.createdByDraft` says so), and the last draft to let go of it unused deletes it.
|
|
78
|
+
*/
|
|
79
|
+
useConnection(id: string, input: {
|
|
80
|
+
version: number;
|
|
81
|
+
connectionId: string;
|
|
82
|
+
}, options?: Call): Promise<PipelineDraft>;
|
|
83
|
+
/** Start the discovery of an import draft's connection; poll {@link PipelineDraftsModule.get}. */
|
|
84
|
+
discover(id: string, input: {
|
|
85
|
+
version: number;
|
|
86
|
+
}, options?: Call): Promise<PipelineDraft>;
|
|
87
|
+
/** Change one schema map of the draft's discovery. */
|
|
88
|
+
updateSchemaMap(id: string, entityType: string, input: UpdatePipelineDraftSchemaMapInput, options?: Call): Promise<PipelineDraft>;
|
|
89
|
+
/**
|
|
90
|
+
* Save the draft as a pipeline and delete the draft; with `startRun` also start its first run.
|
|
91
|
+
* A run that does not start leaves the pipeline in place and answers `runError`. Takes an
|
|
92
|
+
* `idempotencyKey`: a commit retried after a lost answer replays the first one.
|
|
93
|
+
*/
|
|
94
|
+
commit(id: string, input: {
|
|
95
|
+
version: number;
|
|
96
|
+
startRun?: boolean;
|
|
97
|
+
}, options?: Call): Promise<CommittedPipelineDraft>;
|
|
98
|
+
/**
|
|
99
|
+
* Delete the draft, and the connection it created with its stored password unless a pipeline
|
|
100
|
+
* or another draft uses it.
|
|
101
|
+
*/
|
|
102
|
+
discard(id: string, options?: Call): Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
/** Data pipelines (imports and exports between the store and another system). */
|
|
105
|
+
export interface IntegrationPipelinesModule {
|
|
106
|
+
drafts: PipelineDraftsModule;
|
|
107
|
+
/**
|
|
108
|
+
* What each importable entity type needs imported first, from the import writers themselves
|
|
109
|
+
* (the warnings' data; the words are yours).
|
|
110
|
+
*/
|
|
111
|
+
importDependencies(options?: Call): Promise<ImportDependency[]>;
|
|
112
|
+
}
|
|
113
|
+
export declare function createIntegrationPipelinesModule(transport: Transport): IntegrationPipelinesModule;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createPage, PLATFORM_PASSTHROUGH_KEYS, readRestPage, } from '@sixtyninecommerce/core';
|
|
2
|
+
/**
|
|
3
|
+
* Every key whose VALUE is stored data, not DTO shape: the platform's passthrough set
|
|
4
|
+
* (`credentials`, `public_credentials`, `site_analysis`, `trigger_filter`, …) plus a schema map's
|
|
5
|
+
* jsonb columns, which carry the source's own field names and sample records. Converting them
|
|
6
|
+
* would rename a sample's `date_created` to `dateCreated`, and a `triggerFilter`'s `toState` would
|
|
7
|
+
* reach the reader as `to_state`, which it ignores.
|
|
8
|
+
*/
|
|
9
|
+
export const PIPELINE_DRAFT_PRESERVE_KEYS = new Set([
|
|
10
|
+
...PLATFORM_PASSTHROUGH_KEYS,
|
|
11
|
+
'source_schema',
|
|
12
|
+
'sourceSchema',
|
|
13
|
+
'target_schema',
|
|
14
|
+
'targetSchema',
|
|
15
|
+
'sub_counts',
|
|
16
|
+
'subCounts',
|
|
17
|
+
]);
|
|
18
|
+
/**
|
|
19
|
+
* A creation probes the source over the network, and a commit creates the pipeline and may start
|
|
20
|
+
* its run: both outlast the SDK's 15-second default on a slow source.
|
|
21
|
+
*/
|
|
22
|
+
export const PIPELINE_DRAFT_SLOW_TIMEOUT_MS = 60_000;
|
|
23
|
+
const DRAFTS = '/pipelines/drafts';
|
|
24
|
+
const segment = (value) => encodeURIComponent(value);
|
|
25
|
+
export function createIntegrationPipelinesModule(transport) {
|
|
26
|
+
const read = (path, options) => transport.rest('plugins', { method: 'GET', path }, { ...options, preserveKeys: PIPELINE_DRAFT_PRESERVE_KEYS });
|
|
27
|
+
const write = (method, path, body, options, timeoutMs) => transport.rest('plugins', { method, path, body }, {
|
|
28
|
+
...options,
|
|
29
|
+
preserveKeys: PIPELINE_DRAFT_PRESERVE_KEYS,
|
|
30
|
+
...(timeoutMs === undefined ? {} : { timeoutMs }),
|
|
31
|
+
});
|
|
32
|
+
async function list(options) {
|
|
33
|
+
const body = await transport.rest('plugins', {
|
|
34
|
+
method: 'GET',
|
|
35
|
+
path: DRAFTS,
|
|
36
|
+
query: { after: options?.after, limit: options?.limit },
|
|
37
|
+
}, { ...options, preserveKeys: PIPELINE_DRAFT_PRESERVE_KEYS });
|
|
38
|
+
const { items, meta } = readRestPage(body);
|
|
39
|
+
return createPage(items, meta, (cursor) => list({ ...options, after: cursor }));
|
|
40
|
+
}
|
|
41
|
+
const drafts = {
|
|
42
|
+
list,
|
|
43
|
+
get: (id, options) => read(`${DRAFTS}/${segment(id)}`, options),
|
|
44
|
+
create: (input, options) => write('POST', DRAFTS, input, options),
|
|
45
|
+
update: (id, input, options) => write('PATCH', `${DRAFTS}/${segment(id)}`, input, options),
|
|
46
|
+
connect: (id, input, options) => write('POST', `${DRAFTS}/${segment(id)}/connection`, input, options, PIPELINE_DRAFT_SLOW_TIMEOUT_MS),
|
|
47
|
+
useConnection: (id, input, options) => write('POST', `${DRAFTS}/${segment(id)}/connection/existing`, input, options),
|
|
48
|
+
discover: (id, input, options) => write('POST', `${DRAFTS}/${segment(id)}/discover`, input, options),
|
|
49
|
+
updateSchemaMap: (id, entityType, input, options) => write('PATCH', `${DRAFTS}/${segment(id)}/schema-maps/${segment(entityType)}`, input, options),
|
|
50
|
+
commit: (id, input, options) => write('POST', `${DRAFTS}/${segment(id)}/commit`, input, options, PIPELINE_DRAFT_SLOW_TIMEOUT_MS),
|
|
51
|
+
async discard(id, options) {
|
|
52
|
+
await transport.rest('plugins', { method: 'DELETE', path: `${DRAFTS}/${segment(id)}`, expect: 'void' }, options);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
drafts,
|
|
57
|
+
async importDependencies(options) {
|
|
58
|
+
const body = await read('/pipelines/import-dependencies', options);
|
|
59
|
+
return body.data;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shapes of `admin.integrations.pipelines` (headless spec §7 `pipelines.drafts`).
|
|
3
|
+
*
|
|
4
|
+
* Kept verbatim (stored data, never renamed): `triggerFilter`'s keys (reader field names such as
|
|
5
|
+
* `toState`), `siteAnalysis` and `publicCredentials` (the connector's own keys), and a schema
|
|
6
|
+
* map's `sourceSchema`, `targetSchema` and `subCounts`.
|
|
7
|
+
*/
|
|
8
|
+
export type PipelineDirection = 'import' | 'export';
|
|
9
|
+
/** The wizard's steps before a commit; `import`/`done` come after one, when no draft exists. */
|
|
10
|
+
export type PipelineDraftStep = 'direction' | 'connector' | 'credentials' | 'discovery' | 'review' | 'entities' | 'trigger' | 'configure' | 'preview';
|
|
11
|
+
export type PipelineSyncPolicy = 'preserve_local' | 'always_source';
|
|
12
|
+
export type PipelineScheduleType = 'one_time' | 'daily' | 'weekly' | 'custom';
|
|
13
|
+
export type PipelineTriggerType = 'manual' | 'scheduled';
|
|
14
|
+
/** One draft in the store's list. */
|
|
15
|
+
export interface PipelineDraftSummary {
|
|
16
|
+
id: string;
|
|
17
|
+
direction: PipelineDirection;
|
|
18
|
+
step: PipelineDraftStep;
|
|
19
|
+
connectorType: string | null;
|
|
20
|
+
/** The pipeline's name, once the configure step gave it one. */
|
|
21
|
+
name: string | null;
|
|
22
|
+
connectionId: string | null;
|
|
23
|
+
discoveryId: string | null;
|
|
24
|
+
/** Send it back with the next change; a change made on an older one is refused 409. */
|
|
25
|
+
version: number;
|
|
26
|
+
/** Vendure User.id of whoever started it (an API token's own administrator for a token). */
|
|
27
|
+
createdByUserId: string;
|
|
28
|
+
updatedByUserId: string;
|
|
29
|
+
createdAt: string;
|
|
30
|
+
updatedAt: string;
|
|
31
|
+
/** 7 days after the last change; the draft answers 404 from then on. */
|
|
32
|
+
expiresAt: string;
|
|
33
|
+
}
|
|
34
|
+
/** The connection a draft holds. Never a credential: `publicCredentials` holds non-password fields only. */
|
|
35
|
+
export interface PipelineDraftConnection {
|
|
36
|
+
id: string;
|
|
37
|
+
name: string;
|
|
38
|
+
connectorType: string;
|
|
39
|
+
sourceUrl: string;
|
|
40
|
+
status: string;
|
|
41
|
+
/** Soft-deleted on the Connections page since the draft took it: connect again. */
|
|
42
|
+
removed: boolean;
|
|
43
|
+
/** The draft (or another draft holding it) created it, so discarding the draft deletes it. */
|
|
44
|
+
createdByDraft: boolean;
|
|
45
|
+
siteAnalysis: Record<string, unknown> | null;
|
|
46
|
+
publicCredentials: Record<string, string> | null;
|
|
47
|
+
lastTestedAt: string | null;
|
|
48
|
+
}
|
|
49
|
+
export interface PipelineDraftDiscovery {
|
|
50
|
+
id: string;
|
|
51
|
+
/** `pending` → `running` → `completed` | `failed`. Poll the draft to follow it. */
|
|
52
|
+
status: 'pending' | 'running' | 'completed' | 'failed';
|
|
53
|
+
source: string;
|
|
54
|
+
errorMessage: string | null;
|
|
55
|
+
warnings: string[];
|
|
56
|
+
detectedPlugins: string[];
|
|
57
|
+
startedAt: string | null;
|
|
58
|
+
completedAt: string | null;
|
|
59
|
+
}
|
|
60
|
+
export interface PipelineDraftFieldMapping {
|
|
61
|
+
sourceField: string;
|
|
62
|
+
sourcePath: string;
|
|
63
|
+
targetField: string;
|
|
64
|
+
targetPath: string;
|
|
65
|
+
transform: string | null;
|
|
66
|
+
confidence: number;
|
|
67
|
+
enabled: boolean;
|
|
68
|
+
}
|
|
69
|
+
export interface PipelineDraftSchemaMap {
|
|
70
|
+
id: string;
|
|
71
|
+
entityType: string;
|
|
72
|
+
enabled: boolean;
|
|
73
|
+
confidence: number;
|
|
74
|
+
entityCount: number;
|
|
75
|
+
subCounts: Record<string, number> | null;
|
|
76
|
+
/** As stored: `{ sourceEntityType, fields: [{ name, path, type, sampleValues, … }], notes }`. */
|
|
77
|
+
sourceSchema: Record<string, unknown>;
|
|
78
|
+
/** As stored: `{ targetEntityType, allowedTargetEntityTypes? }`. */
|
|
79
|
+
targetSchema: Record<string, unknown>;
|
|
80
|
+
fieldMappings: PipelineDraftFieldMapping[];
|
|
81
|
+
}
|
|
82
|
+
/** What an importable entity type needs imported first, from the import writers themselves. */
|
|
83
|
+
export interface ImportDependency {
|
|
84
|
+
entityType: string;
|
|
85
|
+
dependsOn: string[];
|
|
86
|
+
/** It also depends on every type in the run starting with one of these (`cms_`). */
|
|
87
|
+
dependsOnPrefixes: string[];
|
|
88
|
+
}
|
|
89
|
+
/** An enabled entity type whose dependencies were discovered but switched off. */
|
|
90
|
+
export interface ImportDependencyWarning {
|
|
91
|
+
entityType: string;
|
|
92
|
+
missing: string[];
|
|
93
|
+
}
|
|
94
|
+
/** A draft and everything the set-up screen shows, read now. */
|
|
95
|
+
export interface PipelineDraft extends PipelineDraftSummary {
|
|
96
|
+
sourceUrl: string;
|
|
97
|
+
requestDelayMs: number;
|
|
98
|
+
/** As typed: a comma-separated list, parsed when the connection is created. */
|
|
99
|
+
legacyAssetHosts: string;
|
|
100
|
+
syncPolicy: PipelineSyncPolicy;
|
|
101
|
+
scheduleType: PipelineScheduleType;
|
|
102
|
+
cronExpression: string;
|
|
103
|
+
/** The schedule's zone; a new draft starts with the store's. */
|
|
104
|
+
timezone: string;
|
|
105
|
+
/**
|
|
106
|
+
* Whether the source's prices include tax. Until the merchant sets it (`sourcePricesIncludeTaxChosen`)
|
|
107
|
+
* it follows what the source reports when a connection is made, and before that the store's own
|
|
108
|
+
* setting.
|
|
109
|
+
*/
|
|
110
|
+
sourcePricesIncludeTax: boolean;
|
|
111
|
+
sourcePricesIncludeTaxChosen: boolean;
|
|
112
|
+
stockLocationId: string | null;
|
|
113
|
+
triggerType: PipelineTriggerType;
|
|
114
|
+
exportEntityTypes: string[];
|
|
115
|
+
triggerFilter: Record<string, string>;
|
|
116
|
+
connection: PipelineDraftConnection | null;
|
|
117
|
+
discovery: PipelineDraftDiscovery | null;
|
|
118
|
+
schemaMaps: PipelineDraftSchemaMap[];
|
|
119
|
+
dependencies: ImportDependency[];
|
|
120
|
+
dependencyWarnings: ImportDependencyWarning[];
|
|
121
|
+
/** The name the configure step would give it now, in the store's zone. */
|
|
122
|
+
suggestedName: string | null;
|
|
123
|
+
/** The store's business time zone; null when it could not be read just now. */
|
|
124
|
+
storeTimeZone: string | null;
|
|
125
|
+
}
|
|
126
|
+
/** A field change. `version` is the draft's current one. */
|
|
127
|
+
export interface UpdatePipelineDraftInput {
|
|
128
|
+
version: number;
|
|
129
|
+
direction?: PipelineDirection;
|
|
130
|
+
step?: PipelineDraftStep;
|
|
131
|
+
/** Starts the connection over, even for the same connector. */
|
|
132
|
+
connectorType?: string;
|
|
133
|
+
sourceUrl?: string;
|
|
134
|
+
requestDelayMs?: 50 | 100 | 200 | 300 | 500;
|
|
135
|
+
legacyAssetHosts?: string;
|
|
136
|
+
name?: string;
|
|
137
|
+
syncPolicy?: PipelineSyncPolicy;
|
|
138
|
+
scheduleType?: PipelineScheduleType;
|
|
139
|
+
/** A 5-part cron, or '' to clear it. */
|
|
140
|
+
cronExpression?: string;
|
|
141
|
+
timezone?: string;
|
|
142
|
+
sourcePricesIncludeTax?: boolean;
|
|
143
|
+
/** `null` clears it. */
|
|
144
|
+
stockLocationId?: string | null;
|
|
145
|
+
triggerType?: PipelineTriggerType;
|
|
146
|
+
exportEntityTypes?: string[];
|
|
147
|
+
triggerFilter?: Record<string, string>;
|
|
148
|
+
}
|
|
149
|
+
export interface UpdatePipelineDraftSchemaMapInput {
|
|
150
|
+
version: number;
|
|
151
|
+
enabled?: boolean;
|
|
152
|
+
fieldMappings?: PipelineDraftFieldMapping[];
|
|
153
|
+
/** Move a taxonomy to another target its schema map allows. */
|
|
154
|
+
targetEntityType?: string;
|
|
155
|
+
}
|
|
156
|
+
/** `commit`'s answer: the pipeline, and its first run when one was asked for. */
|
|
157
|
+
export interface CommittedPipelineDraft {
|
|
158
|
+
pipeline: {
|
|
159
|
+
id: string;
|
|
160
|
+
name: string;
|
|
161
|
+
direction: PipelineDirection;
|
|
162
|
+
connectionId: string;
|
|
163
|
+
discoveryId: string | null;
|
|
164
|
+
scheduleType: PipelineScheduleType;
|
|
165
|
+
isActive: boolean;
|
|
166
|
+
};
|
|
167
|
+
run: {
|
|
168
|
+
id: string;
|
|
169
|
+
status: string;
|
|
170
|
+
} | null;
|
|
171
|
+
/** The pipeline was saved but its first run did not start; start it from the pipeline. */
|
|
172
|
+
runError: {
|
|
173
|
+
code: string;
|
|
174
|
+
message: string;
|
|
175
|
+
} | null;
|
|
176
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shapes of `admin.integrations.pipelines` (headless spec §7 `pipelines.drafts`).
|
|
3
|
+
*
|
|
4
|
+
* Kept verbatim (stored data, never renamed): `triggerFilter`'s keys (reader field names such as
|
|
5
|
+
* `toState`), `siteAnalysis` and `publicCredentials` (the connector's own keys), and a schema
|
|
6
|
+
* map's `sourceSchema`, `targetSchema` and `subCounts`.
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
@@ -2,7 +2,7 @@ import { type Transport } from '@sixtyninecommerce/core';
|
|
|
2
2
|
import type { Call } from '../types.js';
|
|
3
3
|
import { type JobHandle } from './index.js';
|
|
4
4
|
/**
|
|
5
|
-
* A bulk action run (`catalog.products.bulk`,
|
|
5
|
+
* A bulk action run (`catalog.products.bulk`, `orders.bulk`): one call
|
|
6
6
|
* that acts on many records of the store as a job, each record through its single door and
|
|
7
7
|
* reported on its own. Read back through the Admin API's `bulkActionRun`.
|
|
8
8
|
*/
|
|
@@ -62,4 +62,13 @@ export declare function readBulkActionRun<Action extends string>(transport: Tran
|
|
|
62
62
|
* when waiting itself cannot go on: `JOB_WAIT_TIMEOUT`, an aborted signal, or a read refused for
|
|
63
63
|
* a reason polling cannot fix.
|
|
64
64
|
*/
|
|
65
|
-
export declare function bulkActionHandle<Action extends string
|
|
65
|
+
export declare function bulkActionHandle<Action extends string, Run extends RunProgress = BulkActionRun<Action>>(transport: Transport, runId: string, options?: Call,
|
|
66
|
+
/** How one read is made, when the kind selects more than the shared fields (orders). */
|
|
67
|
+
read?: (runId: string, call: Call) => Promise<Run>): JobHandle<Run>;
|
|
68
|
+
/** What waiting on a run reads of it, whatever its kind. */
|
|
69
|
+
interface RunProgress {
|
|
70
|
+
status: string;
|
|
71
|
+
done: number;
|
|
72
|
+
total: number;
|
|
73
|
+
}
|
|
74
|
+
export {};
|
|
@@ -40,15 +40,14 @@ export function readBulkActionRun(transport, runId, options) {
|
|
|
40
40
|
* when waiting itself cannot go on: `JOB_WAIT_TIMEOUT`, an aborted signal, or a read refused for
|
|
41
41
|
* a reason polling cannot fix.
|
|
42
42
|
*/
|
|
43
|
-
export function bulkActionHandle(transport, runId, options
|
|
43
|
+
export function bulkActionHandle(transport, runId, options,
|
|
44
|
+
/** How one read is made, when the kind selects more than the shared fields (orders). */
|
|
45
|
+
read = (id, call) => readBulkActionRun(transport, id, call)) {
|
|
44
46
|
return {
|
|
45
47
|
runId,
|
|
46
48
|
wait(waitOptions) {
|
|
47
49
|
return pollUntilTerminal({
|
|
48
|
-
read: (signal) =>
|
|
49
|
-
...options,
|
|
50
|
-
...(signal ? { signal } : {}),
|
|
51
|
-
}),
|
|
50
|
+
read: (signal) => read(runId, { ...options, ...(signal ? { signal } : {}) }),
|
|
52
51
|
isTerminal: (run) => TERMINAL_BULK_ACTION_STATUSES.includes(run.status),
|
|
53
52
|
onTimeout: (seen) => bulkWaitTimeout(runId, seen),
|
|
54
53
|
...waitOptions,
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `admin.orders.bulk`, `admin.orders.bulkRun` and `admin.orders.delete` (headless spec §7
|
|
3
|
+
* `orders.bulk`, plan W9-43; rulings G19, G28, G29).
|
|
4
|
+
*/
|
|
5
|
+
import { type Transport } from '@sixtyninecommerce/core';
|
|
6
|
+
import { type BulkActionItem, type BulkActionRun } from '../jobs/bulk-action-run.js';
|
|
7
|
+
import type { JobHandle } from '../jobs/index.js';
|
|
8
|
+
import type { Call } from '../types.js';
|
|
9
|
+
/** What each order of one bulk run gets. */
|
|
10
|
+
export type OrderBulkAction = 'TRANSITION' | 'CANCEL' | 'DELETE' | 'MARK_PAID';
|
|
11
|
+
export declare const ORDER_BULK_ACTIONS: readonly OrderBulkAction[];
|
|
12
|
+
/** The engine's bound on one bulk run (`MAX_BULK_ACTION_ITEMS`). Split a larger selection. */
|
|
13
|
+
export declare const MAX_BULK_ORDERS = 50;
|
|
14
|
+
/**
|
|
15
|
+
* The states a TRANSITION never names, each with its own action or door: `Cancelled` (CANCEL),
|
|
16
|
+
* `PaymentSettled` (MARK_PAID), `Modifying` (the order edit) and `AddingItems`.
|
|
17
|
+
*/
|
|
18
|
+
export declare const ORDER_BULK_TRANSITION_REFUSED: readonly string[];
|
|
19
|
+
export interface OrderBulkInput {
|
|
20
|
+
action: OrderBulkAction;
|
|
21
|
+
/** 1 to {@link MAX_BULK_ORDERS} orders of the store, each named once. */
|
|
22
|
+
orderIds: readonly string[];
|
|
23
|
+
/** TRANSITION only, and required there: the state each order moves to. */
|
|
24
|
+
toState?: string;
|
|
25
|
+
/** CANCEL only: the reason recorded on each cancelled order. */
|
|
26
|
+
reason?: string;
|
|
27
|
+
}
|
|
28
|
+
/** One payment a MARK_PAID item acted on. */
|
|
29
|
+
export interface OrderBulkCapture {
|
|
30
|
+
paymentId: string;
|
|
31
|
+
/** The payment's state after the capture: `Settled`, or what a decline left. */
|
|
32
|
+
state: string;
|
|
33
|
+
/**
|
|
34
|
+
* Why it was not captured, null when it was: `SETTLE_PAYMENT_ERROR` (declined; `message`
|
|
35
|
+
* quotes the provider), `PAYMENT_NOT_AUTHORIZED` (captured by someone else meanwhile),
|
|
36
|
+
* `PAYMENT_METHOD_UNAVAILABLE` (its method is switched off, not on this store, or no longer installed; nothing asked),
|
|
37
|
+
* `IDEMPOTENCY_IN_PROGRESS` (a capture under the same request may still run: check the order
|
|
38
|
+
* before trying again), `IDEMPOTENCY_OUTCOME_UNKNOWN` (the provider was asked and its answer
|
|
39
|
+
* was lost: reconcile with the provider, never retry blind), or a fault's code.
|
|
40
|
+
*/
|
|
41
|
+
code: string | null;
|
|
42
|
+
message: string | null;
|
|
43
|
+
}
|
|
44
|
+
/** One order's outcome. */
|
|
45
|
+
export interface OrderBulkItem extends BulkActionItem {
|
|
46
|
+
/**
|
|
47
|
+
* When `code` is `ORDER_ACTION_UNAVAILABLE`: why the order's own status (`orders.status`) did
|
|
48
|
+
* not offer the action, in that read's vocabulary (`STATE`, `INVOICE_LOCKED`, `SHOPPER_CART`,
|
|
49
|
+
* `HAS_RECORDS`, `UNITS_SHIPPED`, `ACTIVE_FULFILLMENT`, `NOTHING_TO_CANCEL`, …). Null otherwise.
|
|
50
|
+
*/
|
|
51
|
+
reasonCode: string | null;
|
|
52
|
+
/** MARK_PAID: each payment the order's item acted on, in order. Null for other actions. */
|
|
53
|
+
captured: OrderBulkCapture[] | null;
|
|
54
|
+
}
|
|
55
|
+
/** A bulk order run, as `wait()` and `bulkRun()` answer it. */
|
|
56
|
+
export type OrderBulkRun = Omit<BulkActionRun<OrderBulkAction>, 'items'> & {
|
|
57
|
+
items: OrderBulkItem[];
|
|
58
|
+
};
|
|
59
|
+
export declare const BULK_ORDER_ACTION_MUTATION = "\n mutation BulkOrderAction($input: BulkOrderActionInput!, $idempotencyKey: String) {\n bulkOrderAction(input: $input, idempotencyKey: $idempotencyKey) {\n runId\n }\n }\n";
|
|
60
|
+
/**
|
|
61
|
+
* The run read with the order fields. Its own document, so `catalog.products.bulkRun` keeps
|
|
62
|
+
* selecting only what an engine without the orders kind has.
|
|
63
|
+
*/
|
|
64
|
+
export declare const ORDER_BULK_RUN_QUERY = "\n query OrderBulkRun($runId: ID!) {\n bulkActionRun(runId: $runId) {\n id\n kind\n action\n status\n total\n done\n items {\n id\n status\n code\n message\n newId\n reasonCode\n captured {\n paymentId\n state\n code\n message\n }\n }\n failure {\n code\n message\n }\n }\n }\n";
|
|
65
|
+
export declare const DELETE_ORDER_MUTATION = "\n mutation DeleteOrder($orderId: ID!) {\n deleteOrder(orderId: $orderId) {\n result\n message\n }\n }\n";
|
|
66
|
+
/** One read of a bulk order run. A run of another store, or a missing one, is `NotFoundError`. */
|
|
67
|
+
export declare function readOrderBulkRun(transport: Transport, runId: string, options?: Call): Promise<OrderBulkRun>;
|
|
68
|
+
/** `orders.bulk`; see `OrdersModule.bulk`. */
|
|
69
|
+
export declare function bulkOrders(transport: Transport, input: OrderBulkInput, options?: Call): Promise<JobHandle<OrderBulkRun>>;
|
|
70
|
+
/**
|
|
71
|
+
* `orders.delete`; see `OrdersModule.delete`. The engine's `NOT_DELETED` is raised as every other
|
|
72
|
+
* `*_NOT_DELETED` refusal of this SDK is (`assertDeleted`): a `ConflictError` with the engine's own
|
|
73
|
+
* reason.
|
|
74
|
+
*/
|
|
75
|
+
export declare function deleteOrder(transport: Transport, orderId: string, options?: Call): Promise<void>;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `admin.orders.bulk`, `admin.orders.bulkRun` and `admin.orders.delete` (headless spec §7
|
|
3
|
+
* `orders.bulk`, plan W9-43; rulings G19, G28, G29).
|
|
4
|
+
*/
|
|
5
|
+
import { idempotencyKey, ValidationError } from '@sixtyninecommerce/core';
|
|
6
|
+
import { assertDeleted, fieldOf } from '../catalog/types.js';
|
|
7
|
+
import { bulkActionHandle, } from '../jobs/bulk-action-run.js';
|
|
8
|
+
export const ORDER_BULK_ACTIONS = [
|
|
9
|
+
'TRANSITION',
|
|
10
|
+
'CANCEL',
|
|
11
|
+
'DELETE',
|
|
12
|
+
'MARK_PAID',
|
|
13
|
+
];
|
|
14
|
+
/** The engine's bound on one bulk run (`MAX_BULK_ACTION_ITEMS`). Split a larger selection. */
|
|
15
|
+
export const MAX_BULK_ORDERS = 50;
|
|
16
|
+
/**
|
|
17
|
+
* The states a TRANSITION never names, each with its own action or door: `Cancelled` (CANCEL),
|
|
18
|
+
* `PaymentSettled` (MARK_PAID), `Modifying` (the order edit) and `AddingItems`.
|
|
19
|
+
*/
|
|
20
|
+
export const ORDER_BULK_TRANSITION_REFUSED = [
|
|
21
|
+
'Cancelled',
|
|
22
|
+
'PaymentSettled',
|
|
23
|
+
'Modifying',
|
|
24
|
+
'AddingItems',
|
|
25
|
+
];
|
|
26
|
+
export const BULK_ORDER_ACTION_MUTATION = /* GraphQL */ `
|
|
27
|
+
mutation BulkOrderAction($input: BulkOrderActionInput!, $idempotencyKey: String) {
|
|
28
|
+
bulkOrderAction(input: $input, idempotencyKey: $idempotencyKey) {
|
|
29
|
+
runId
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
/**
|
|
34
|
+
* The run read with the order fields. Its own document, so `catalog.products.bulkRun` keeps
|
|
35
|
+
* selecting only what an engine without the orders kind has.
|
|
36
|
+
*/
|
|
37
|
+
export const ORDER_BULK_RUN_QUERY = /* GraphQL */ `
|
|
38
|
+
query OrderBulkRun($runId: ID!) {
|
|
39
|
+
bulkActionRun(runId: $runId) {
|
|
40
|
+
id
|
|
41
|
+
kind
|
|
42
|
+
action
|
|
43
|
+
status
|
|
44
|
+
total
|
|
45
|
+
done
|
|
46
|
+
items {
|
|
47
|
+
id
|
|
48
|
+
status
|
|
49
|
+
code
|
|
50
|
+
message
|
|
51
|
+
newId
|
|
52
|
+
reasonCode
|
|
53
|
+
captured {
|
|
54
|
+
paymentId
|
|
55
|
+
state
|
|
56
|
+
code
|
|
57
|
+
message
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
failure {
|
|
61
|
+
code
|
|
62
|
+
message
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
67
|
+
export const DELETE_ORDER_MUTATION = /* GraphQL */ `
|
|
68
|
+
mutation DeleteOrder($orderId: ID!) {
|
|
69
|
+
deleteOrder(orderId: $orderId) {
|
|
70
|
+
result
|
|
71
|
+
message
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
75
|
+
function refuse(message) {
|
|
76
|
+
return new ValidationError({
|
|
77
|
+
code: 'BULK_ACTION_INPUT_INVALID',
|
|
78
|
+
message,
|
|
79
|
+
status: 400,
|
|
80
|
+
service: 'vendure',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/** The engine's own checks of a submit (`BULK_ACTION_INPUT_INVALID`), before sending. */
|
|
84
|
+
function assertBulkInput(input) {
|
|
85
|
+
if (!ORDER_BULK_ACTIONS.includes(input?.action)) {
|
|
86
|
+
throw refuse(`"${String(input?.action)}" is not a bulk order action: ${ORDER_BULK_ACTIONS.join(', ')}. Nothing was sent.`);
|
|
87
|
+
}
|
|
88
|
+
const ids = input.orderIds;
|
|
89
|
+
if (!Array.isArray(ids) || ids.length === 0) {
|
|
90
|
+
throw refuse('Name at least one order. Nothing was sent.');
|
|
91
|
+
}
|
|
92
|
+
if (ids.length > MAX_BULK_ORDERS) {
|
|
93
|
+
throw refuse(`Name at most ${String(MAX_BULK_ORDERS)} orders in one bulk action; this one named ${String(ids.length)}. Split the selection into several actions. Nothing was sent.`);
|
|
94
|
+
}
|
|
95
|
+
if (new Set(ids.map((id) => String(id).toLowerCase())).size !== ids.length) {
|
|
96
|
+
throw refuse('The selection names an order more than once. Name each order once. Nothing was sent.');
|
|
97
|
+
}
|
|
98
|
+
const toState = input.toState?.trim() ?? '';
|
|
99
|
+
if (input.action === 'TRANSITION') {
|
|
100
|
+
if (toState === '')
|
|
101
|
+
throw refuse('Name the status to move the orders to. Nothing was sent.');
|
|
102
|
+
if (ORDER_BULK_TRANSITION_REFUSED.includes(toState)) {
|
|
103
|
+
throw refuse(`Orders are not moved to "${toState}" by a status change${toState === 'Cancelled'
|
|
104
|
+
? ': use CANCEL'
|
|
105
|
+
: toState === 'PaymentSettled'
|
|
106
|
+
? ': use MARK_PAID'
|
|
107
|
+
: ''}. Nothing was sent.`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (toState !== '') {
|
|
111
|
+
throw refuse(`toState is only for TRANSITION, not ${input.action}. Nothing was sent.`);
|
|
112
|
+
}
|
|
113
|
+
if ((input.reason?.trim() ?? '') !== '' && input.action !== 'CANCEL') {
|
|
114
|
+
throw refuse(`reason is only for CANCEL, not ${input.action}. Nothing was sent.`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** One read of a bulk order run. A run of another store, or a missing one, is `NotFoundError`. */
|
|
118
|
+
export function readOrderBulkRun(transport, runId, options) {
|
|
119
|
+
return fieldOf(transport, ORDER_BULK_RUN_QUERY, 'bulkActionRun', { runId }, options);
|
|
120
|
+
}
|
|
121
|
+
/** `orders.bulk`; see `OrdersModule.bulk`. */
|
|
122
|
+
export async function bulkOrders(transport, input, options) {
|
|
123
|
+
assertBulkInput(input);
|
|
124
|
+
// Minted when the caller gave none, so a retry of THIS call answers the same run instead of
|
|
125
|
+
// starting a second one (and capturing nothing twice).
|
|
126
|
+
const key = options?.idempotencyKey ?? idempotencyKey();
|
|
127
|
+
const toState = input.toState?.trim();
|
|
128
|
+
const reason = input.reason?.trim();
|
|
129
|
+
const { runId } = await fieldOf(transport, BULK_ORDER_ACTION_MUTATION, 'bulkOrderAction', {
|
|
130
|
+
input: {
|
|
131
|
+
action: input.action,
|
|
132
|
+
orderIds: [...input.orderIds],
|
|
133
|
+
// Omitted, never null, when not given: an absent option stays off the wire.
|
|
134
|
+
...(toState ? { toState } : {}),
|
|
135
|
+
...(reason ? { reason } : {}),
|
|
136
|
+
},
|
|
137
|
+
idempotencyKey: key,
|
|
138
|
+
}, { ...options, idempotencyKey: key });
|
|
139
|
+
return bulkActionHandle(transport, runId, options, (id, call) => readOrderBulkRun(transport, id, call));
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* `orders.delete`; see `OrdersModule.delete`. The engine's `NOT_DELETED` is raised as every other
|
|
143
|
+
* `*_NOT_DELETED` refusal of this SDK is (`assertDeleted`): a `ConflictError` with the engine's own
|
|
144
|
+
* reason.
|
|
145
|
+
*/
|
|
146
|
+
export async function deleteOrder(transport, orderId, options) {
|
|
147
|
+
assertDeleted('ORDER_NOT_DELETED', [
|
|
148
|
+
await fieldOf(transport, DELETE_ORDER_MUTATION, 'deleteOrder', { orderId }, options),
|
|
149
|
+
]);
|
|
150
|
+
}
|