@endora-commerce/contracts 0.110.0 → 0.111.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accept-language.d.ts +31 -0
- package/dist/accept-language.js +64 -0
- package/dist/admin-actions.d.ts +2 -0
- package/dist/admin-actions.js +18 -0
- package/dist/admin-contributions.d.ts +37 -5
- package/dist/admin-contributions.js +9 -2
- package/dist/admin-roles.d.ts +9 -0
- package/dist/admin.d.ts +37 -0
- package/dist/admin.js +19 -0
- package/dist/api-keys.d.ts +22 -0
- package/dist/api-keys.js +4 -0
- package/dist/assets-library.d.ts +19 -0
- package/dist/assets-library.js +14 -0
- package/dist/auth.d.ts +9 -0
- package/dist/auth.js +9 -0
- package/dist/carts.d.ts +30 -1
- package/dist/carts.js +20 -5
- package/dist/catalog.d.ts +61 -22
- package/dist/catalog.js +32 -6
- package/dist/cms.d.ts +33 -3
- package/dist/cms.js +15 -0
- package/dist/command-hooks.d.ts +301 -0
- package/dist/command-hooks.js +248 -0
- package/dist/comparisons.d.ts +14 -14
- package/dist/credit-limits.d.ts +21 -0
- package/dist/credit-limits.js +21 -0
- package/dist/crm.d.ts +81 -55
- package/dist/crm.js +15 -5
- package/dist/custom-fields.d.ts +403 -49
- package/dist/custom-fields.js +127 -0
- package/dist/customer-accounts.d.ts +138 -0
- package/dist/customer-accounts.js +4 -0
- package/dist/customer-notifications.d.ts +143 -0
- package/dist/customer-notifications.js +41 -0
- package/dist/customers.d.ts +52 -0
- package/dist/customers.js +53 -0
- package/dist/dictionary.d.ts +53 -0
- package/dist/dictionary.js +25 -0
- package/dist/document-templates.d.ts +4 -4
- package/dist/email.d.ts +34 -0
- package/dist/email.js +6 -0
- package/dist/errors.d.ts +312 -2
- package/dist/errors.js +377 -2
- package/dist/forms.d.ts +88 -88
- package/dist/i18n.d.ts +34 -0
- package/dist/i18n.js +15 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +12 -1
- package/dist/invoice-ledger.d.ts +6 -6
- package/dist/invoices.d.ts +126 -0
- package/dist/invoices.js +49 -0
- package/dist/line-bounds.d.ts +53 -0
- package/dist/line-bounds.js +65 -0
- package/dist/megamenu.d.ts +27 -27
- package/dist/mfa.d.ts +86 -0
- package/dist/mfa.js +90 -0
- package/dist/modules.d.ts +21 -5
- package/dist/modules.js +60 -3
- package/dist/orders.d.ts +141 -0
- package/dist/orders.js +80 -3
- package/dist/organization-hooks.d.ts +99 -0
- package/dist/organization-hooks.js +22 -0
- package/dist/organization-registry-lookup.d.ts +5 -5
- package/dist/organization-roles.d.ts +1 -0
- package/dist/organization-roles.js +7 -0
- package/dist/organizations.d.ts +954 -17
- package/dist/organizations.js +229 -8
- package/dist/price-books.d.ts +173 -25
- package/dist/price-books.js +41 -0
- package/dist/price-lists.d.ts +5 -2
- package/dist/product-feeds.d.ts +157 -8
- package/dist/product-feeds.js +41 -2
- package/dist/product-scopes.d.ts +17 -0
- package/dist/product-scopes.js +31 -5
- package/dist/projects.d.ts +61 -28
- package/dist/projects.js +47 -9
- package/dist/promotions.d.ts +157 -5
- package/dist/promotions.js +23 -1
- package/dist/pwa.d.ts +39 -0
- package/dist/quick-order.d.ts +9 -3
- package/dist/quick-order.js +4 -3
- package/dist/quote-requests.d.ts +168 -5
- package/dist/quote-requests.js +69 -8
- package/dist/record-references.d.ts +15 -15
- package/dist/returns.d.ts +6 -0
- package/dist/returns.js +4 -2
- package/dist/sales-channels.d.ts +34 -3
- package/dist/sales-channels.js +16 -1
- package/dist/schema-extensions.d.ts +36 -0
- package/dist/schema-extensions.js +29 -0
- package/dist/seo.d.ts +2 -2
- package/dist/settings.d.ts +44 -2
- package/dist/settings.js +17 -2
- package/dist/shopping-lists.d.ts +39 -1
- package/dist/shopping-lists.js +37 -3
- package/dist/storefront-cache-tags.d.ts +10 -0
- package/dist/tasks.d.ts +21 -21
- package/dist/taxes.d.ts +27 -0
- package/dist/taxes.js +4 -0
- package/dist/transactional-emails.d.ts +39 -13
- package/dist/webhooks.d.ts +75 -0
- package/dist/webhooks.js +24 -0
- package/package.json +4 -2
- package/dist/actor.d.ts.map +0 -1
- package/dist/actor.js.map +0 -1
- package/dist/addresses.d.ts.map +0 -1
- package/dist/addresses.js.map +0 -1
- package/dist/admin-actions.d.ts.map +0 -1
- package/dist/admin-actions.js.map +0 -1
- package/dist/admin-contributions.d.ts.map +0 -1
- package/dist/admin-contributions.js.map +0 -1
- package/dist/admin-feedback.d.ts.map +0 -1
- package/dist/admin-feedback.js.map +0 -1
- package/dist/admin-i18n.d.ts.map +0 -1
- package/dist/admin-i18n.js.map +0 -1
- package/dist/admin-name.d.ts.map +0 -1
- package/dist/admin-name.js.map +0 -1
- package/dist/admin-notifications.d.ts.map +0 -1
- package/dist/admin-notifications.js.map +0 -1
- package/dist/admin-preferences.d.ts.map +0 -1
- package/dist/admin-preferences.js.map +0 -1
- package/dist/admin-roles.d.ts.map +0 -1
- package/dist/admin-roles.js.map +0 -1
- package/dist/admin-search.d.ts.map +0 -1
- package/dist/admin-search.js.map +0 -1
- package/dist/admin-users.d.ts.map +0 -1
- package/dist/admin-users.js.map +0 -1
- package/dist/admin.d.ts.map +0 -1
- package/dist/admin.js.map +0 -1
- package/dist/analytics.d.ts.map +0 -1
- package/dist/analytics.js.map +0 -1
- package/dist/api-keys.d.ts.map +0 -1
- package/dist/api-keys.js.map +0 -1
- package/dist/assets-library.d.ts.map +0 -1
- package/dist/assets-library.js.map +0 -1
- package/dist/audit-logs.d.ts.map +0 -1
- package/dist/audit-logs.js.map +0 -1
- package/dist/auth.d.ts.map +0 -1
- package/dist/auth.js.map +0 -1
- package/dist/blog.d.ts.map +0 -1
- package/dist/blog.js.map +0 -1
- package/dist/capabilities.d.ts.map +0 -1
- package/dist/capabilities.js.map +0 -1
- package/dist/carts.d.ts.map +0 -1
- package/dist/carts.js.map +0 -1
- package/dist/catalog.d.ts.map +0 -1
- package/dist/catalog.js.map +0 -1
- package/dist/cms-brand.d.ts.map +0 -1
- package/dist/cms-brand.js.map +0 -1
- package/dist/cms-contact-form.d.ts.map +0 -1
- package/dist/cms-contact-form.js.map +0 -1
- package/dist/cms.d.ts.map +0 -1
- package/dist/cms.js.map +0 -1
- package/dist/common.d.ts.map +0 -1
- package/dist/common.js.map +0 -1
- package/dist/comparisons.d.ts.map +0 -1
- package/dist/comparisons.js.map +0 -1
- package/dist/credentials.d.ts.map +0 -1
- package/dist/credentials.js.map +0 -1
- package/dist/credit-limits.d.ts.map +0 -1
- package/dist/credit-limits.js.map +0 -1
- package/dist/crm-rich-text.d.ts.map +0 -1
- package/dist/crm-rich-text.js.map +0 -1
- package/dist/crm.d.ts.map +0 -1
- package/dist/crm.js.map +0 -1
- package/dist/currencies.d.ts.map +0 -1
- package/dist/currencies.js.map +0 -1
- package/dist/custom-fields.d.ts.map +0 -1
- package/dist/custom-fields.js.map +0 -1
- package/dist/customer-accounts.d.ts.map +0 -1
- package/dist/customer-accounts.js.map +0 -1
- package/dist/customers.d.ts.map +0 -1
- package/dist/customers.js.map +0 -1
- package/dist/dictionary.d.ts.map +0 -1
- package/dist/dictionary.js.map +0 -1
- package/dist/document-templates.d.ts.map +0 -1
- package/dist/document-templates.js.map +0 -1
- package/dist/document-values.d.ts.map +0 -1
- package/dist/document-values.js.map +0 -1
- package/dist/email-address.d.ts.map +0 -1
- package/dist/email-address.js.map +0 -1
- package/dist/email.d.ts.map +0 -1
- package/dist/email.js.map +0 -1
- package/dist/envelopes.d.ts.map +0 -1
- package/dist/envelopes.js.map +0 -1
- package/dist/environment-inputs.d.ts.map +0 -1
- package/dist/environment-inputs.js.map +0 -1
- package/dist/erp-connector.d.ts.map +0 -1
- package/dist/erp-connector.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/forms-logic.d.ts.map +0 -1
- package/dist/forms-logic.fixtures.d.ts.map +0 -1
- package/dist/forms-logic.fixtures.js.map +0 -1
- package/dist/forms-logic.js.map +0 -1
- package/dist/forms.d.ts.map +0 -1
- package/dist/forms.js.map +0 -1
- package/dist/google-analytics.d.ts.map +0 -1
- package/dist/google-analytics.js.map +0 -1
- package/dist/google-tag-manager.d.ts.map +0 -1
- package/dist/google-tag-manager.js.map +0 -1
- package/dist/i18n.d.ts.map +0 -1
- package/dist/i18n.js.map +0 -1
- package/dist/import-export.d.ts.map +0 -1
- package/dist/import-export.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/inventory.d.ts.map +0 -1
- package/dist/inventory.js.map +0 -1
- package/dist/invoice-ledger.d.ts.map +0 -1
- package/dist/invoice-ledger.js.map +0 -1
- package/dist/invoices.d.ts.map +0 -1
- package/dist/invoices.js.map +0 -1
- package/dist/kernel.d.ts.map +0 -1
- package/dist/kernel.js.map +0 -1
- package/dist/languages.d.ts.map +0 -1
- package/dist/languages.js.map +0 -1
- package/dist/line-groups.d.ts.map +0 -1
- package/dist/line-groups.js.map +0 -1
- package/dist/linkedin-ads.d.ts.map +0 -1
- package/dist/linkedin-ads.js.map +0 -1
- package/dist/localized-name.d.ts.map +0 -1
- package/dist/localized-name.js.map +0 -1
- package/dist/megamenu.d.ts.map +0 -1
- package/dist/megamenu.js.map +0 -1
- package/dist/meta-ads.d.ts.map +0 -1
- package/dist/meta-ads.js.map +0 -1
- package/dist/mfa.d.ts.map +0 -1
- package/dist/mfa.js.map +0 -1
- package/dist/modules.d.ts.map +0 -1
- package/dist/modules.js.map +0 -1
- package/dist/money-decimal.d.ts.map +0 -1
- package/dist/money-decimal.js.map +0 -1
- package/dist/money-input.d.ts.map +0 -1
- package/dist/money-input.js.map +0 -1
- package/dist/newsletter.d.ts.map +0 -1
- package/dist/newsletter.js.map +0 -1
- package/dist/order-minimums.d.ts.map +0 -1
- package/dist/order-minimums.js.map +0 -1
- package/dist/orders.d.ts.map +0 -1
- package/dist/orders.js.map +0 -1
- package/dist/organization-registry-lookup.d.ts.map +0 -1
- package/dist/organization-registry-lookup.js.map +0 -1
- package/dist/organization-roles.d.ts.map +0 -1
- package/dist/organization-roles.js.map +0 -1
- package/dist/organizations.d.ts.map +0 -1
- package/dist/organizations.js.map +0 -1
- package/dist/page-builder-props.d.ts.map +0 -1
- package/dist/page-builder-props.js.map +0 -1
- package/dist/page-builder-values.d.ts.map +0 -1
- package/dist/page-builder-values.js.map +0 -1
- package/dist/pagination.d.ts.map +0 -1
- package/dist/pagination.js.map +0 -1
- package/dist/payment-methods.d.ts.map +0 -1
- package/dist/payment-methods.js.map +0 -1
- package/dist/payment-return-url.d.ts.map +0 -1
- package/dist/payment-return-url.js.map +0 -1
- package/dist/payments.d.ts.map +0 -1
- package/dist/payments.js.map +0 -1
- package/dist/pim-connector.d.ts.map +0 -1
- package/dist/pim-connector.js.map +0 -1
- package/dist/pim-field-path.d.ts.map +0 -1
- package/dist/pim-field-path.js.map +0 -1
- package/dist/pim-locale-mapping.d.ts.map +0 -1
- package/dist/pim-locale-mapping.js.map +0 -1
- package/dist/platform-info.d.ts.map +0 -1
- package/dist/platform-info.js.map +0 -1
- package/dist/platform-language.d.ts.map +0 -1
- package/dist/platform-language.js.map +0 -1
- package/dist/price-book-decimal.d.ts.map +0 -1
- package/dist/price-book-decimal.js.map +0 -1
- package/dist/price-books.d.ts.map +0 -1
- package/dist/price-books.js.map +0 -1
- package/dist/price-lists.d.ts.map +0 -1
- package/dist/price-lists.js.map +0 -1
- package/dist/product-feeds.d.ts.map +0 -1
- package/dist/product-feeds.js.map +0 -1
- package/dist/product-scope-model.d.ts.map +0 -1
- package/dist/product-scope-model.js.map +0 -1
- package/dist/product-scope-overrides.d.ts.map +0 -1
- package/dist/product-scope-overrides.js.map +0 -1
- package/dist/product-scoped-values.d.ts.map +0 -1
- package/dist/product-scoped-values.js.map +0 -1
- package/dist/product-scopes.d.ts.map +0 -1
- package/dist/product-scopes.js.map +0 -1
- package/dist/product-summary-text.d.ts.map +0 -1
- package/dist/product-summary-text.js.map +0 -1
- package/dist/product-tax-rates.d.ts.map +0 -1
- package/dist/product-tax-rates.js.map +0 -1
- package/dist/product-url-keys.d.ts.map +0 -1
- package/dist/product-url-keys.js.map +0 -1
- package/dist/product-value-resolver.d.ts.map +0 -1
- package/dist/product-value-resolver.js.map +0 -1
- package/dist/projects.d.ts.map +0 -1
- package/dist/projects.js.map +0 -1
- package/dist/promotions.d.ts.map +0 -1
- package/dist/promotions.js.map +0 -1
- package/dist/prompt-actions.d.ts.map +0 -1
- package/dist/prompt-actions.js.map +0 -1
- package/dist/pwa.d.ts.map +0 -1
- package/dist/pwa.js.map +0 -1
- package/dist/quick-order.d.ts.map +0 -1
- package/dist/quick-order.js.map +0 -1
- package/dist/quote-requests.d.ts.map +0 -1
- package/dist/quote-requests.js.map +0 -1
- package/dist/record-references.d.ts.map +0 -1
- package/dist/record-references.js.map +0 -1
- package/dist/record-rich-text.d.ts.map +0 -1
- package/dist/record-rich-text.js.map +0 -1
- package/dist/returns.d.ts.map +0 -1
- package/dist/returns.js.map +0 -1
- package/dist/sales-channels.d.ts.map +0 -1
- package/dist/sales-channels.js.map +0 -1
- package/dist/saved-list-views.d.ts.map +0 -1
- package/dist/saved-list-views.js.map +0 -1
- package/dist/scope-notice.d.ts.map +0 -1
- package/dist/scope-notice.js.map +0 -1
- package/dist/scoped-write-encoding.d.ts.map +0 -1
- package/dist/scoped-write-encoding.js.map +0 -1
- package/dist/search.d.ts.map +0 -1
- package/dist/search.js.map +0 -1
- package/dist/seo.d.ts.map +0 -1
- package/dist/seo.js.map +0 -1
- package/dist/settings.d.ts.map +0 -1
- package/dist/settings.js.map +0 -1
- package/dist/shipments.d.ts.map +0 -1
- package/dist/shipments.js.map +0 -1
- package/dist/shipping-methods.d.ts.map +0 -1
- package/dist/shipping-methods.js.map +0 -1
- package/dist/shopping-lists.d.ts.map +0 -1
- package/dist/shopping-lists.js.map +0 -1
- package/dist/storefront-cache-tags.d.ts.map +0 -1
- package/dist/storefront-cache-tags.js.map +0 -1
- package/dist/storefront-language-path.d.ts.map +0 -1
- package/dist/storefront-language-path.js.map +0 -1
- package/dist/storefront-value-overrides.d.ts.map +0 -1
- package/dist/storefront-value-overrides.js.map +0 -1
- package/dist/tasks.d.ts.map +0 -1
- package/dist/tasks.js.map +0 -1
- package/dist/taxes.d.ts.map +0 -1
- package/dist/taxes.js.map +0 -1
- package/dist/text-normalization.d.ts.map +0 -1
- package/dist/text-normalization.js.map +0 -1
- package/dist/transactional-emails.d.ts.map +0 -1
- package/dist/transactional-emails.js.map +0 -1
- package/dist/webhooks.d.ts.map +0 -1
- package/dist/webhooks.js.map +0 -1
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** When a hook runs relative to the Command's commit. */
|
|
3
|
+
export type CommandHookPhase = 'beforeCommit' | 'afterCommit';
|
|
4
|
+
export declare const COMMAND_HOOK_PHASES: readonly ["beforeCommit", "afterCommit"];
|
|
5
|
+
/**
|
|
6
|
+
* A scalar allowed in outbox data: `specs/conventions/audit-state.md` list 1
|
|
7
|
+
* only — ids, codes, booleans, counts and dates. Never free text, money,
|
|
8
|
+
* personal data or a custom-field value (FR-031).
|
|
9
|
+
*/
|
|
10
|
+
export type OutboxScalar = string | number | boolean | null;
|
|
11
|
+
/** The data an `afterCommit` row carries. Stored in `command_outbox` (P3). */
|
|
12
|
+
export type OutboxData = Readonly<Record<string, OutboxScalar | readonly OutboxScalar[]>>;
|
|
13
|
+
/**
|
|
14
|
+
* The longest string an outbox value may be. Long enough for a UUID, an ISO
|
|
15
|
+
* timestamp, a dictionary code and a dotted field name
|
|
16
|
+
* (`extensions.<moduleId>.changedFields`); short of anything a sentence needs.
|
|
17
|
+
*/
|
|
18
|
+
export declare const OUTBOX_STRING_MAX_LENGTH = 128;
|
|
19
|
+
/** One outbox data key that is not `audit-state.md` list 1, and why. Never carries the value. */
|
|
20
|
+
export interface OutboxDataViolation {
|
|
21
|
+
readonly key: string;
|
|
22
|
+
readonly issue: 'nested' | 'too-long' | 'not-code-shaped' | 'not-finite' | 'not-a-scalar';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The keys of `data` that an outbox row may not store (FR-031): a nested
|
|
26
|
+
* object, a string longer than {@link OUTBOX_STRING_MAX_LENGTH} or with
|
|
27
|
+
* whitespace or an `@` in it, a non-finite number, anything that is not a scalar. An
|
|
28
|
+
* array is allowed when every member is. Sorted by key, and the value is never
|
|
29
|
+
* repeated: the answer is what an error message may print.
|
|
30
|
+
*
|
|
31
|
+
* A **structural** guard — it cannot tell a one-word name from a code, and the
|
|
32
|
+
* owner's `outboxData` remains the place list 1 is decided. What it refuses is
|
|
33
|
+
* the shape free text, an address or a snapshot has, so the common mistake
|
|
34
|
+
* fails the Command (and the owner's `expectHookableCommand`) instead of
|
|
35
|
+
* landing in a platform-global table.
|
|
36
|
+
*/
|
|
37
|
+
export declare function outboxDataViolations(data: Readonly<Record<string, unknown>>): OutboxDataViolation[];
|
|
38
|
+
/**
|
|
39
|
+
* A hookable action, published by the module that owns the Command.
|
|
40
|
+
*
|
|
41
|
+
* `TData` is what a `beforeCommit` hook receives (in memory, never stored);
|
|
42
|
+
* `TOutbox` is what an `afterCommit` handler receives (stored, list 1 only).
|
|
43
|
+
* Both are carried by the phantom `__types` member, which is never set at run
|
|
44
|
+
* time — it exists so a hook registered with this ref is typed by it.
|
|
45
|
+
*/
|
|
46
|
+
export interface HookableActionRef<TData = unknown, TOutbox extends OutboxData = OutboxData> {
|
|
47
|
+
/** The Command's audit action, e.g. `organization.create`. */
|
|
48
|
+
readonly action: string;
|
|
49
|
+
/** The Command's audit object type, e.g. `organization`. */
|
|
50
|
+
readonly objectType: string;
|
|
51
|
+
/** The phases the owner offers. A hook for any other phase fails composition. */
|
|
52
|
+
readonly phases: readonly CommandHookPhase[];
|
|
53
|
+
/** Phantom carrier for the two data types; never set at run time. */
|
|
54
|
+
readonly __types?: {
|
|
55
|
+
readonly data: TData;
|
|
56
|
+
readonly outbox: TOutbox;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** A Command action: dot-separated lower-case segments, at least two. */
|
|
60
|
+
export declare const hookableActionRe: RegExp;
|
|
61
|
+
/**
|
|
62
|
+
* Declare a hookable action. The owner calls this once per action, in
|
|
63
|
+
* `@endora-commerce/contracts`, and exports the result.
|
|
64
|
+
*
|
|
65
|
+
* Refuses a malformed action or object type, and an empty or repeated phase
|
|
66
|
+
* list, at module load — a ref is a public contract and is never built at run
|
|
67
|
+
* time from data.
|
|
68
|
+
*/
|
|
69
|
+
export declare function hookableAction<TData, TOutbox extends OutboxData = OutboxData>(action: string, objectType: string, phases: readonly CommandHookPhase[]): HookableActionRef<TData, TOutbox>;
|
|
70
|
+
/** The manifest entry for one hookable action, derived from its ref. */
|
|
71
|
+
export declare const HookableActionDeclarationSchema: z.ZodObject<{
|
|
72
|
+
action: z.ZodString;
|
|
73
|
+
objectType: z.ZodString;
|
|
74
|
+
phases: z.ZodArray<z.ZodEnum<{
|
|
75
|
+
beforeCommit: "beforeCommit";
|
|
76
|
+
afterCommit: "afterCommit";
|
|
77
|
+
}>>;
|
|
78
|
+
}, z.core.$strict>;
|
|
79
|
+
export type HookableActionDeclaration = z.infer<typeof HookableActionDeclarationSchema>;
|
|
80
|
+
/** What an owner writes in its manifest's `hookableActions`. */
|
|
81
|
+
export declare function toHookableActionDeclaration(ref: HookableActionRef<unknown, OutboxData>): HookableActionDeclaration;
|
|
82
|
+
/**
|
|
83
|
+
* The codes the platform answers a command-hook misuse with. Owned by the
|
|
84
|
+
* platform vocabulary (`_i18n`, translated pl + en under `errors.<CODE>`).
|
|
85
|
+
*
|
|
86
|
+
* - `COMMAND_EXTENSION_UNCLAIMED` (422) — a Command's `extensions` carries a
|
|
87
|
+
* key no present hook module on that action claims; refused before any
|
|
88
|
+
* write, `details: [{ path: 'extensions.<key>', issue }]` (FR-019).
|
|
89
|
+
* - `COMMAND_HOOK_CYCLE` (500) — a hookable action reappears in its own
|
|
90
|
+
* ancestor chain, or hook-induced nesting passed its bound (FR-022).
|
|
91
|
+
* - `COMMAND_HOOK_DATA_MISSING` (500) — a Command declared hookable did not
|
|
92
|
+
* supply its hook data (FR-023).
|
|
93
|
+
*/
|
|
94
|
+
export declare const COMMAND_HOOK_ERROR_CODES: {
|
|
95
|
+
readonly EXTENSION_UNCLAIMED: "COMMAND_EXTENSION_UNCLAIMED";
|
|
96
|
+
readonly CYCLE: "COMMAND_HOOK_CYCLE";
|
|
97
|
+
readonly DATA_MISSING: "COMMAND_HOOK_DATA_MISSING";
|
|
98
|
+
};
|
|
99
|
+
/** How deep hook-induced Command nesting may go: the ninth Command in one chain is refused. */
|
|
100
|
+
export declare const COMMAND_HOOK_MAX_DEPTH = 8;
|
|
101
|
+
/**
|
|
102
|
+
* One registered hook. A `beforeCommit` hook carries its position in its
|
|
103
|
+
* action's execution order; an `afterCommit` handler carries `null`, because
|
|
104
|
+
* each one is an outbox row of its own and the outbox promises no order across
|
|
105
|
+
* rows (`contracts/outbox-and-admin-api.md`, amendment 3). Handlers are listed
|
|
106
|
+
* by module id, then registration order — for a stable screen, not a sequence.
|
|
107
|
+
*/
|
|
108
|
+
export declare const CommandHookPlanItemSchema: z.ZodObject<{
|
|
109
|
+
action: z.ZodString;
|
|
110
|
+
phase: z.ZodEnum<{
|
|
111
|
+
beforeCommit: "beforeCommit";
|
|
112
|
+
afterCommit: "afterCommit";
|
|
113
|
+
}>;
|
|
114
|
+
position: z.ZodNullable<z.ZodNumber>;
|
|
115
|
+
module: z.ZodString;
|
|
116
|
+
id: z.ZodString;
|
|
117
|
+
moduleEnabled: z.ZodBoolean;
|
|
118
|
+
}, z.core.$strip>;
|
|
119
|
+
export type CommandHookPlanItem = z.infer<typeof CommandHookPlanItemSchema>;
|
|
120
|
+
/** One action some module declares hookable, whether or not anything hooks it. */
|
|
121
|
+
export declare const CommandHookPlanActionSchema: z.ZodObject<{
|
|
122
|
+
action: z.ZodString;
|
|
123
|
+
objectType: z.ZodString;
|
|
124
|
+
owner: z.ZodString;
|
|
125
|
+
phases: z.ZodArray<z.ZodEnum<{
|
|
126
|
+
beforeCommit: "beforeCommit";
|
|
127
|
+
afterCommit: "afterCommit";
|
|
128
|
+
}>>;
|
|
129
|
+
}, z.core.$strip>;
|
|
130
|
+
export type CommandHookPlanAction = z.infer<typeof CommandHookPlanActionSchema>;
|
|
131
|
+
export declare const CommandHookPlanResponseSchema: z.ZodObject<{
|
|
132
|
+
actions: z.ZodArray<z.ZodObject<{
|
|
133
|
+
action: z.ZodString;
|
|
134
|
+
objectType: z.ZodString;
|
|
135
|
+
owner: z.ZodString;
|
|
136
|
+
phases: z.ZodArray<z.ZodEnum<{
|
|
137
|
+
beforeCommit: "beforeCommit";
|
|
138
|
+
afterCommit: "afterCommit";
|
|
139
|
+
}>>;
|
|
140
|
+
}, z.core.$strip>>;
|
|
141
|
+
items: z.ZodArray<z.ZodObject<{
|
|
142
|
+
action: z.ZodString;
|
|
143
|
+
phase: z.ZodEnum<{
|
|
144
|
+
beforeCommit: "beforeCommit";
|
|
145
|
+
afterCommit: "afterCommit";
|
|
146
|
+
}>;
|
|
147
|
+
position: z.ZodNullable<z.ZodNumber>;
|
|
148
|
+
module: z.ZodString;
|
|
149
|
+
id: z.ZodString;
|
|
150
|
+
moduleEnabled: z.ZodBoolean;
|
|
151
|
+
}, z.core.$strip>>;
|
|
152
|
+
}, z.core.$strip>;
|
|
153
|
+
export type CommandHookPlanResponse = z.infer<typeof CommandHookPlanResponseSchema>;
|
|
154
|
+
/** Where an outbox row is in its delivery (`data-model.md` §4). */
|
|
155
|
+
export declare const COMMAND_OUTBOX_STATUSES: readonly ["pending", "in_flight", "delivered", "dead"];
|
|
156
|
+
export declare const CommandOutboxStatusSchema: z.ZodEnum<{
|
|
157
|
+
pending: "pending";
|
|
158
|
+
in_flight: "in_flight";
|
|
159
|
+
delivered: "delivered";
|
|
160
|
+
dead: "dead";
|
|
161
|
+
}>;
|
|
162
|
+
export type CommandOutboxStatus = z.infer<typeof CommandOutboxStatusSchema>;
|
|
163
|
+
/**
|
|
164
|
+
* The statuses an operator lists. A delivered row needs nobody's attention and
|
|
165
|
+
* is purged after seven days, so the list does not offer it.
|
|
166
|
+
*/
|
|
167
|
+
export declare const COMMAND_OUTBOX_LISTED_STATUSES: readonly ["dead", "pending", "in_flight"];
|
|
168
|
+
/** The largest page `GET /api/v1/admin/command-outbox` serves. */
|
|
169
|
+
export declare const COMMAND_OUTBOX_PAGE_MAX = 100;
|
|
170
|
+
/**
|
|
171
|
+
* `GET /api/v1/admin/command-outbox` — filtered by status (dead rows by
|
|
172
|
+
* default: they are the ones an operator acts on), keyset-paginated by the
|
|
173
|
+
* row's `sequence`, newest first. `cursor` is the previous page's
|
|
174
|
+
* `nextCursor`, opaque to the client.
|
|
175
|
+
*/
|
|
176
|
+
export declare const CommandOutboxListQuerySchema: z.ZodObject<{
|
|
177
|
+
status: z.ZodDefault<z.ZodEnum<{
|
|
178
|
+
pending: "pending";
|
|
179
|
+
in_flight: "in_flight";
|
|
180
|
+
dead: "dead";
|
|
181
|
+
}>>;
|
|
182
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
183
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
184
|
+
}, z.core.$strip>;
|
|
185
|
+
export type CommandOutboxListQuery = z.infer<typeof CommandOutboxListQuerySchema>;
|
|
186
|
+
/**
|
|
187
|
+
* One outbox row as an operator sees it: names, ids, codes, counts and dates
|
|
188
|
+
* only. The row's `data` is **never** served, and neither is anything a
|
|
189
|
+
* failure said — only its code and the error's class are stored — so this list
|
|
190
|
+
* shows nothing the audit log would not (FR-040).
|
|
191
|
+
*
|
|
192
|
+
* `lastErrorCode` is the raw stored string; the screen translates it when the
|
|
193
|
+
* hook module or the platform has a sentence for it, and shows it as it is
|
|
194
|
+
* otherwise.
|
|
195
|
+
*/
|
|
196
|
+
export declare const CommandOutboxListItemSchema: z.ZodObject<{
|
|
197
|
+
id: z.ZodString;
|
|
198
|
+
action: z.ZodString;
|
|
199
|
+
objectType: z.ZodString;
|
|
200
|
+
objectId: z.ZodString;
|
|
201
|
+
organizationId: z.ZodNullable<z.ZodString>;
|
|
202
|
+
hookModule: z.ZodString;
|
|
203
|
+
hookId: z.ZodString;
|
|
204
|
+
status: z.ZodEnum<{
|
|
205
|
+
pending: "pending";
|
|
206
|
+
in_flight: "in_flight";
|
|
207
|
+
delivered: "delivered";
|
|
208
|
+
dead: "dead";
|
|
209
|
+
}>;
|
|
210
|
+
attempts: z.ZodNumber;
|
|
211
|
+
lastErrorCode: z.ZodNullable<z.ZodString>;
|
|
212
|
+
lastErrorClass: z.ZodNullable<z.ZodString>;
|
|
213
|
+
createdAt: z.ZodString;
|
|
214
|
+
availableAt: z.ZodString;
|
|
215
|
+
deadAt: z.ZodNullable<z.ZodString>;
|
|
216
|
+
}, z.core.$strip>;
|
|
217
|
+
export type CommandOutboxListItem = z.infer<typeof CommandOutboxListItemSchema>;
|
|
218
|
+
/** One page; `nextCursor` is `null` on the last. */
|
|
219
|
+
export declare const CommandOutboxListResponseSchema: z.ZodObject<{
|
|
220
|
+
items: z.ZodArray<z.ZodObject<{
|
|
221
|
+
id: z.ZodString;
|
|
222
|
+
action: z.ZodString;
|
|
223
|
+
objectType: z.ZodString;
|
|
224
|
+
objectId: z.ZodString;
|
|
225
|
+
organizationId: z.ZodNullable<z.ZodString>;
|
|
226
|
+
hookModule: z.ZodString;
|
|
227
|
+
hookId: z.ZodString;
|
|
228
|
+
status: z.ZodEnum<{
|
|
229
|
+
pending: "pending";
|
|
230
|
+
in_flight: "in_flight";
|
|
231
|
+
delivered: "delivered";
|
|
232
|
+
dead: "dead";
|
|
233
|
+
}>;
|
|
234
|
+
attempts: z.ZodNumber;
|
|
235
|
+
lastErrorCode: z.ZodNullable<z.ZodString>;
|
|
236
|
+
lastErrorClass: z.ZodNullable<z.ZodString>;
|
|
237
|
+
createdAt: z.ZodString;
|
|
238
|
+
availableAt: z.ZodString;
|
|
239
|
+
deadAt: z.ZodNullable<z.ZodString>;
|
|
240
|
+
}, z.core.$strip>>;
|
|
241
|
+
nextCursor: z.ZodNullable<z.ZodString>;
|
|
242
|
+
}, z.core.$strip>;
|
|
243
|
+
export type CommandOutboxListResponse = z.infer<typeof CommandOutboxListResponseSchema>;
|
|
244
|
+
/**
|
|
245
|
+
* `POST /api/v1/admin/command-outbox/:id/retry` — the path parameter. Any
|
|
246
|
+
* string, on purpose: a value that is not a uuid names no row, so the route
|
|
247
|
+
* answers it with the same `404` as an unknown id (issue #781, owner ruling of
|
|
248
|
+
* 2026-11-05), where a uuid params schema would answer `400` (issue #1269).
|
|
249
|
+
*/
|
|
250
|
+
export declare const CommandOutboxRetryParamsSchema: z.ZodObject<{
|
|
251
|
+
id: z.ZodString;
|
|
252
|
+
}, z.core.$strip>;
|
|
253
|
+
/** `POST /api/v1/admin/command-outbox/:id/retry` — the row, now pending. */
|
|
254
|
+
export declare const CommandOutboxRetryResponseSchema: z.ZodObject<{
|
|
255
|
+
item: z.ZodObject<{
|
|
256
|
+
id: z.ZodString;
|
|
257
|
+
action: z.ZodString;
|
|
258
|
+
objectType: z.ZodString;
|
|
259
|
+
objectId: z.ZodString;
|
|
260
|
+
organizationId: z.ZodNullable<z.ZodString>;
|
|
261
|
+
hookModule: z.ZodString;
|
|
262
|
+
hookId: z.ZodString;
|
|
263
|
+
status: z.ZodEnum<{
|
|
264
|
+
pending: "pending";
|
|
265
|
+
in_flight: "in_flight";
|
|
266
|
+
delivered: "delivered";
|
|
267
|
+
dead: "dead";
|
|
268
|
+
}>;
|
|
269
|
+
attempts: z.ZodNumber;
|
|
270
|
+
lastErrorCode: z.ZodNullable<z.ZodString>;
|
|
271
|
+
lastErrorClass: z.ZodNullable<z.ZodString>;
|
|
272
|
+
createdAt: z.ZodString;
|
|
273
|
+
availableAt: z.ZodString;
|
|
274
|
+
deadAt: z.ZodNullable<z.ZodString>;
|
|
275
|
+
}, z.core.$strip>;
|
|
276
|
+
}, z.core.$strip>;
|
|
277
|
+
export type CommandOutboxRetryResponse = z.infer<typeof CommandOutboxRetryResponseSchema>;
|
|
278
|
+
/**
|
|
279
|
+
* The failure codes the platform's own drain stores in `last_error_code`
|
|
280
|
+
* (`contracts/outbox-and-admin-api.md`, amendment 4). Lower-kebab, because
|
|
281
|
+
* they are delivery outcomes and not HTTP error codes; translated by the
|
|
282
|
+
* platform vocabulary under {@link commandOutboxFailureKey}.
|
|
283
|
+
*/
|
|
284
|
+
export declare const COMMAND_OUTBOX_FAILURE_CODES: {
|
|
285
|
+
readonly HOOK_UNREGISTERED: "hook-unregistered";
|
|
286
|
+
readonly PERMANENT_FAILURE: "permanent-failure";
|
|
287
|
+
readonly HANDLER_FAILED: "handler-failed";
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* The bundle key a stored failure code may be translated under, besides
|
|
291
|
+
* `errors.<CODE>`: `commandOutbox.failure.<code>`, the code verbatim.
|
|
292
|
+
*
|
|
293
|
+
* Two families because a stored code has two shapes. An `HttpError`'s code is
|
|
294
|
+
* SCREAMING_SNAKE and already has its `errors.<CODE>` sentence wherever it is
|
|
295
|
+
* declared; a `PermanentOutboxFailure` code may be any code-shaped string
|
|
296
|
+
* (`acme-erp-rejected`), which `errors.*` cannot hold — that family is read by
|
|
297
|
+
* the error envelope and refuses any other key grammar
|
|
298
|
+
* (`check-error-translations`, `malformed-key`).
|
|
299
|
+
*/
|
|
300
|
+
export declare function commandOutboxFailureKey(code: string): string;
|
|
301
|
+
//# sourceMappingURL=command-hooks.d.ts.map
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
// Command hooks — `specs/176-command-hooks-outbox/` P2 (US2),
|
|
2
|
+
// `contracts/command-hooks-api.md` §1.
|
|
3
|
+
//
|
|
4
|
+
// The platform-free half of the command-hook API: the typed reference an owner
|
|
5
|
+
// publishes for each Command action it opens to hooks, the manifest
|
|
6
|
+
// declaration derived from it, and the error codes the platform answers a
|
|
7
|
+
// misuse with. The platform half — `ctx.commandHooks`, the bus dispatch, the
|
|
8
|
+
// hook context — is `@endora-commerce/platform/commands` and `./kernel`.
|
|
9
|
+
//
|
|
10
|
+
// One constant serves both readers (FR-010): the owner lists the ref in its
|
|
11
|
+
// manifest through `toHookableActionDeclaration`, and a hook author imports the
|
|
12
|
+
// same ref so the hook's `data` is typed by the owner's declaration.
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
export const COMMAND_HOOK_PHASES = ['beforeCommit', 'afterCommit'];
|
|
15
|
+
/**
|
|
16
|
+
* The longest string an outbox value may be. Long enough for a UUID, an ISO
|
|
17
|
+
* timestamp, a dictionary code and a dotted field name
|
|
18
|
+
* (`extensions.<moduleId>.changedFields`); short of anything a sentence needs.
|
|
19
|
+
*/
|
|
20
|
+
export const OUTBOX_STRING_MAX_LENGTH = 128;
|
|
21
|
+
/**
|
|
22
|
+
* Printable ASCII without a space and without `@`: what an id, a code, a date
|
|
23
|
+
* and a field name are made of. `@` is refused because an e-mail address is the
|
|
24
|
+
* one personal datum that otherwise has a code's shape.
|
|
25
|
+
*/
|
|
26
|
+
const OUTBOX_STRING_RE = /^[\x21-\x3f\x41-\x7e]*$/;
|
|
27
|
+
function scalarIssue(value) {
|
|
28
|
+
if (value === null || typeof value === 'boolean')
|
|
29
|
+
return null;
|
|
30
|
+
if (typeof value === 'number')
|
|
31
|
+
return Number.isFinite(value) ? null : 'not-finite';
|
|
32
|
+
if (typeof value === 'string') {
|
|
33
|
+
if (value.length > OUTBOX_STRING_MAX_LENGTH)
|
|
34
|
+
return 'too-long';
|
|
35
|
+
return OUTBOX_STRING_RE.test(value) ? null : 'not-code-shaped';
|
|
36
|
+
}
|
|
37
|
+
if (typeof value === 'object')
|
|
38
|
+
return 'nested';
|
|
39
|
+
return 'not-a-scalar';
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The keys of `data` that an outbox row may not store (FR-031): a nested
|
|
43
|
+
* object, a string longer than {@link OUTBOX_STRING_MAX_LENGTH} or with
|
|
44
|
+
* whitespace or an `@` in it, a non-finite number, anything that is not a scalar. An
|
|
45
|
+
* array is allowed when every member is. Sorted by key, and the value is never
|
|
46
|
+
* repeated: the answer is what an error message may print.
|
|
47
|
+
*
|
|
48
|
+
* A **structural** guard — it cannot tell a one-word name from a code, and the
|
|
49
|
+
* owner's `outboxData` remains the place list 1 is decided. What it refuses is
|
|
50
|
+
* the shape free text, an address or a snapshot has, so the common mistake
|
|
51
|
+
* fails the Command (and the owner's `expectHookableCommand`) instead of
|
|
52
|
+
* landing in a platform-global table.
|
|
53
|
+
*/
|
|
54
|
+
export function outboxDataViolations(data) {
|
|
55
|
+
const violations = [];
|
|
56
|
+
for (const key of Object.keys(data).sort()) {
|
|
57
|
+
const value = data[key];
|
|
58
|
+
const issue = Array.isArray(value)
|
|
59
|
+
? (value.map(scalarIssue).find((found) => found !== null) ?? null)
|
|
60
|
+
: scalarIssue(value);
|
|
61
|
+
if (issue !== null)
|
|
62
|
+
violations.push({ key, issue });
|
|
63
|
+
}
|
|
64
|
+
return violations;
|
|
65
|
+
}
|
|
66
|
+
/** A Command action: dot-separated lower-case segments, at least two. */
|
|
67
|
+
export const hookableActionRe = /^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$/;
|
|
68
|
+
const objectTypeRe = /^[a-z][a-z0-9_]*$/;
|
|
69
|
+
/**
|
|
70
|
+
* Declare a hookable action. The owner calls this once per action, in
|
|
71
|
+
* `@endora-commerce/contracts`, and exports the result.
|
|
72
|
+
*
|
|
73
|
+
* Refuses a malformed action or object type, and an empty or repeated phase
|
|
74
|
+
* list, at module load — a ref is a public contract and is never built at run
|
|
75
|
+
* time from data.
|
|
76
|
+
*/
|
|
77
|
+
export function hookableAction(action, objectType, phases) {
|
|
78
|
+
const parsed = HookableActionDeclarationSchema.parse({ action, objectType, phases: [...phases] });
|
|
79
|
+
return Object.freeze({
|
|
80
|
+
action: parsed.action,
|
|
81
|
+
objectType: parsed.objectType,
|
|
82
|
+
phases: Object.freeze([...parsed.phases]),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/** The manifest entry for one hookable action, derived from its ref. */
|
|
86
|
+
export const HookableActionDeclarationSchema = z
|
|
87
|
+
.object({
|
|
88
|
+
action: z.string().regex(hookableActionRe),
|
|
89
|
+
objectType: z.string().regex(objectTypeRe),
|
|
90
|
+
phases: z.array(z.enum(COMMAND_HOOK_PHASES)).min(1),
|
|
91
|
+
})
|
|
92
|
+
.strict()
|
|
93
|
+
.superRefine((value, ctx) => {
|
|
94
|
+
if (new Set(value.phases).size !== value.phases.length) {
|
|
95
|
+
ctx.addIssue({
|
|
96
|
+
code: 'custom',
|
|
97
|
+
path: ['phases'],
|
|
98
|
+
message: `hookable action "${value.action}" lists a phase twice`,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
/** What an owner writes in its manifest's `hookableActions`. */
|
|
103
|
+
export function toHookableActionDeclaration(ref) {
|
|
104
|
+
return { action: ref.action, objectType: ref.objectType, phases: [...ref.phases] };
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The codes the platform answers a command-hook misuse with. Owned by the
|
|
108
|
+
* platform vocabulary (`_i18n`, translated pl + en under `errors.<CODE>`).
|
|
109
|
+
*
|
|
110
|
+
* - `COMMAND_EXTENSION_UNCLAIMED` (422) — a Command's `extensions` carries a
|
|
111
|
+
* key no present hook module on that action claims; refused before any
|
|
112
|
+
* write, `details: [{ path: 'extensions.<key>', issue }]` (FR-019).
|
|
113
|
+
* - `COMMAND_HOOK_CYCLE` (500) — a hookable action reappears in its own
|
|
114
|
+
* ancestor chain, or hook-induced nesting passed its bound (FR-022).
|
|
115
|
+
* - `COMMAND_HOOK_DATA_MISSING` (500) — a Command declared hookable did not
|
|
116
|
+
* supply its hook data (FR-023).
|
|
117
|
+
*/
|
|
118
|
+
export const COMMAND_HOOK_ERROR_CODES = {
|
|
119
|
+
EXTENSION_UNCLAIMED: 'COMMAND_EXTENSION_UNCLAIMED',
|
|
120
|
+
CYCLE: 'COMMAND_HOOK_CYCLE',
|
|
121
|
+
DATA_MISSING: 'COMMAND_HOOK_DATA_MISSING',
|
|
122
|
+
};
|
|
123
|
+
/** How deep hook-induced Command nesting may go: the ninth Command in one chain is refused. */
|
|
124
|
+
export const COMMAND_HOOK_MAX_DEPTH = 8;
|
|
125
|
+
// ---------------------------------------------------------------------------
|
|
126
|
+
// The read-only execution plan (`GET /api/v1/admin/command-hooks`, FR-026/FR-040)
|
|
127
|
+
// ---------------------------------------------------------------------------
|
|
128
|
+
/**
|
|
129
|
+
* One registered hook. A `beforeCommit` hook carries its position in its
|
|
130
|
+
* action's execution order; an `afterCommit` handler carries `null`, because
|
|
131
|
+
* each one is an outbox row of its own and the outbox promises no order across
|
|
132
|
+
* rows (`contracts/outbox-and-admin-api.md`, amendment 3). Handlers are listed
|
|
133
|
+
* by module id, then registration order — for a stable screen, not a sequence.
|
|
134
|
+
*/
|
|
135
|
+
export const CommandHookPlanItemSchema = z.object({
|
|
136
|
+
action: z.string(),
|
|
137
|
+
phase: z.enum(COMMAND_HOOK_PHASES),
|
|
138
|
+
/** 1-based position within the action's `beforeCommit` hooks; `null` for an `afterCommit` handler. */
|
|
139
|
+
position: z.number().int().positive().nullable(),
|
|
140
|
+
module: z.string(),
|
|
141
|
+
id: z.string(),
|
|
142
|
+
/** Whether the hook's module is present on the effective state right now. */
|
|
143
|
+
moduleEnabled: z.boolean(),
|
|
144
|
+
});
|
|
145
|
+
/** One action some module declares hookable, whether or not anything hooks it. */
|
|
146
|
+
export const CommandHookPlanActionSchema = z.object({
|
|
147
|
+
action: z.string(),
|
|
148
|
+
objectType: z.string(),
|
|
149
|
+
owner: z.string(),
|
|
150
|
+
phases: z.array(z.enum(COMMAND_HOOK_PHASES)),
|
|
151
|
+
});
|
|
152
|
+
export const CommandHookPlanResponseSchema = z.object({
|
|
153
|
+
actions: z.array(CommandHookPlanActionSchema),
|
|
154
|
+
items: z.array(CommandHookPlanItemSchema),
|
|
155
|
+
});
|
|
156
|
+
// ---------------------------------------------------------------------------
|
|
157
|
+
// The command outbox operator API (`specs/176-command-hooks-outbox/` P4, FR-040)
|
|
158
|
+
// ---------------------------------------------------------------------------
|
|
159
|
+
/** Where an outbox row is in its delivery (`data-model.md` §4). */
|
|
160
|
+
export const COMMAND_OUTBOX_STATUSES = ['pending', 'in_flight', 'delivered', 'dead'];
|
|
161
|
+
export const CommandOutboxStatusSchema = z.enum(COMMAND_OUTBOX_STATUSES);
|
|
162
|
+
/**
|
|
163
|
+
* The statuses an operator lists. A delivered row needs nobody's attention and
|
|
164
|
+
* is purged after seven days, so the list does not offer it.
|
|
165
|
+
*/
|
|
166
|
+
export const COMMAND_OUTBOX_LISTED_STATUSES = ['dead', 'pending', 'in_flight'];
|
|
167
|
+
/** The largest page `GET /api/v1/admin/command-outbox` serves. */
|
|
168
|
+
export const COMMAND_OUTBOX_PAGE_MAX = 100;
|
|
169
|
+
/**
|
|
170
|
+
* `GET /api/v1/admin/command-outbox` — filtered by status (dead rows by
|
|
171
|
+
* default: they are the ones an operator acts on), keyset-paginated by the
|
|
172
|
+
* row's `sequence`, newest first. `cursor` is the previous page's
|
|
173
|
+
* `nextCursor`, opaque to the client.
|
|
174
|
+
*/
|
|
175
|
+
export const CommandOutboxListQuerySchema = z.object({
|
|
176
|
+
status: z.enum(COMMAND_OUTBOX_LISTED_STATUSES).default('dead'),
|
|
177
|
+
limit: z.coerce.number().int().min(1).max(COMMAND_OUTBOX_PAGE_MAX).default(50),
|
|
178
|
+
cursor: z
|
|
179
|
+
.string()
|
|
180
|
+
.regex(/^[1-9][0-9]{0,18}$/)
|
|
181
|
+
.optional(),
|
|
182
|
+
});
|
|
183
|
+
/**
|
|
184
|
+
* One outbox row as an operator sees it: names, ids, codes, counts and dates
|
|
185
|
+
* only. The row's `data` is **never** served, and neither is anything a
|
|
186
|
+
* failure said — only its code and the error's class are stored — so this list
|
|
187
|
+
* shows nothing the audit log would not (FR-040).
|
|
188
|
+
*
|
|
189
|
+
* `lastErrorCode` is the raw stored string; the screen translates it when the
|
|
190
|
+
* hook module or the platform has a sentence for it, and shows it as it is
|
|
191
|
+
* otherwise.
|
|
192
|
+
*/
|
|
193
|
+
export const CommandOutboxListItemSchema = z.object({
|
|
194
|
+
id: z.string().uuid(),
|
|
195
|
+
action: z.string(),
|
|
196
|
+
objectType: z.string(),
|
|
197
|
+
objectId: z.string(),
|
|
198
|
+
organizationId: z.string().uuid().nullable(),
|
|
199
|
+
hookModule: z.string(),
|
|
200
|
+
hookId: z.string(),
|
|
201
|
+
status: CommandOutboxStatusSchema,
|
|
202
|
+
attempts: z.number().int().nonnegative(),
|
|
203
|
+
lastErrorCode: z.string().nullable(),
|
|
204
|
+
lastErrorClass: z.string().nullable(),
|
|
205
|
+
createdAt: z.string(),
|
|
206
|
+
availableAt: z.string(),
|
|
207
|
+
deadAt: z.string().nullable(),
|
|
208
|
+
});
|
|
209
|
+
/** One page; `nextCursor` is `null` on the last. */
|
|
210
|
+
export const CommandOutboxListResponseSchema = z.object({
|
|
211
|
+
items: z.array(CommandOutboxListItemSchema),
|
|
212
|
+
nextCursor: z.string().nullable(),
|
|
213
|
+
});
|
|
214
|
+
/**
|
|
215
|
+
* `POST /api/v1/admin/command-outbox/:id/retry` — the path parameter. Any
|
|
216
|
+
* string, on purpose: a value that is not a uuid names no row, so the route
|
|
217
|
+
* answers it with the same `404` as an unknown id (issue #781, owner ruling of
|
|
218
|
+
* 2026-11-05), where a uuid params schema would answer `400` (issue #1269).
|
|
219
|
+
*/
|
|
220
|
+
export const CommandOutboxRetryParamsSchema = z.object({ id: z.string() });
|
|
221
|
+
/** `POST /api/v1/admin/command-outbox/:id/retry` — the row, now pending. */
|
|
222
|
+
export const CommandOutboxRetryResponseSchema = z.object({ item: CommandOutboxListItemSchema });
|
|
223
|
+
/**
|
|
224
|
+
* The failure codes the platform's own drain stores in `last_error_code`
|
|
225
|
+
* (`contracts/outbox-and-admin-api.md`, amendment 4). Lower-kebab, because
|
|
226
|
+
* they are delivery outcomes and not HTTP error codes; translated by the
|
|
227
|
+
* platform vocabulary under {@link commandOutboxFailureKey}.
|
|
228
|
+
*/
|
|
229
|
+
export const COMMAND_OUTBOX_FAILURE_CODES = {
|
|
230
|
+
HOOK_UNREGISTERED: 'hook-unregistered',
|
|
231
|
+
PERMANENT_FAILURE: 'permanent-failure',
|
|
232
|
+
HANDLER_FAILED: 'handler-failed',
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* The bundle key a stored failure code may be translated under, besides
|
|
236
|
+
* `errors.<CODE>`: `commandOutbox.failure.<code>`, the code verbatim.
|
|
237
|
+
*
|
|
238
|
+
* Two families because a stored code has two shapes. An `HttpError`'s code is
|
|
239
|
+
* SCREAMING_SNAKE and already has its `errors.<CODE>` sentence wherever it is
|
|
240
|
+
* declared; a `PermanentOutboxFailure` code may be any code-shaped string
|
|
241
|
+
* (`acme-erp-rejected`), which `errors.*` cannot hold — that family is read by
|
|
242
|
+
* the error envelope and refuses any other key grammar
|
|
243
|
+
* (`check-error-translations`, `malformed-key`).
|
|
244
|
+
*/
|
|
245
|
+
export function commandOutboxFailureKey(code) {
|
|
246
|
+
return `commandOutbox.failure.${code}`;
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=command-hooks.js.map
|
package/dist/comparisons.d.ts
CHANGED
|
@@ -51,10 +51,10 @@ export declare const comparisonAttributeRowSchema: z.ZodObject<{
|
|
|
51
51
|
boolean: "boolean";
|
|
52
52
|
date: "date";
|
|
53
53
|
enum: "enum";
|
|
54
|
-
multiselect: "multiselect";
|
|
55
|
-
price: "price";
|
|
56
54
|
select: "select";
|
|
55
|
+
multiselect: "multiselect";
|
|
57
56
|
page_builder: "page_builder";
|
|
57
|
+
price: "price";
|
|
58
58
|
}>;
|
|
59
59
|
values: z.ZodArray<z.ZodNullable<z.ZodString>>;
|
|
60
60
|
rowClass: z.ZodEnum<{
|
|
@@ -117,10 +117,10 @@ export declare const comparisonOwnerViewSchema: z.ZodObject<{
|
|
|
117
117
|
boolean: "boolean";
|
|
118
118
|
date: "date";
|
|
119
119
|
enum: "enum";
|
|
120
|
-
multiselect: "multiselect";
|
|
121
|
-
price: "price";
|
|
122
120
|
select: "select";
|
|
121
|
+
multiselect: "multiselect";
|
|
123
122
|
page_builder: "page_builder";
|
|
123
|
+
price: "price";
|
|
124
124
|
}>;
|
|
125
125
|
values: z.ZodArray<z.ZodNullable<z.ZodString>>;
|
|
126
126
|
rowClass: z.ZodEnum<{
|
|
@@ -185,10 +185,10 @@ export declare const comparisonDocumentDataSchema: z.ZodObject<{
|
|
|
185
185
|
boolean: "boolean";
|
|
186
186
|
date: "date";
|
|
187
187
|
enum: "enum";
|
|
188
|
-
multiselect: "multiselect";
|
|
189
|
-
price: "price";
|
|
190
188
|
select: "select";
|
|
189
|
+
multiselect: "multiselect";
|
|
191
190
|
page_builder: "page_builder";
|
|
191
|
+
price: "price";
|
|
192
192
|
}>;
|
|
193
193
|
values: z.ZodArray<z.ZodNullable<z.ZodString>>;
|
|
194
194
|
rowClass: z.ZodEnum<{
|
|
@@ -252,10 +252,10 @@ export declare const comparisonOwnerResponseSchema: z.ZodObject<{
|
|
|
252
252
|
boolean: "boolean";
|
|
253
253
|
date: "date";
|
|
254
254
|
enum: "enum";
|
|
255
|
-
multiselect: "multiselect";
|
|
256
|
-
price: "price";
|
|
257
255
|
select: "select";
|
|
256
|
+
multiselect: "multiselect";
|
|
258
257
|
page_builder: "page_builder";
|
|
258
|
+
price: "price";
|
|
259
259
|
}>;
|
|
260
260
|
values: z.ZodArray<z.ZodNullable<z.ZodString>>;
|
|
261
261
|
rowClass: z.ZodEnum<{
|
|
@@ -330,10 +330,10 @@ export declare const comparisonSharedViewSchema: z.ZodObject<{
|
|
|
330
330
|
boolean: "boolean";
|
|
331
331
|
date: "date";
|
|
332
332
|
enum: "enum";
|
|
333
|
-
multiselect: "multiselect";
|
|
334
|
-
price: "price";
|
|
335
333
|
select: "select";
|
|
334
|
+
multiselect: "multiselect";
|
|
336
335
|
page_builder: "page_builder";
|
|
336
|
+
price: "price";
|
|
337
337
|
}>;
|
|
338
338
|
values: z.ZodArray<z.ZodNullable<z.ZodString>>;
|
|
339
339
|
rowClass: z.ZodEnum<{
|
|
@@ -389,10 +389,10 @@ export declare const comparisonSharedResponseSchema: z.ZodObject<{
|
|
|
389
389
|
boolean: "boolean";
|
|
390
390
|
date: "date";
|
|
391
391
|
enum: "enum";
|
|
392
|
-
multiselect: "multiselect";
|
|
393
|
-
price: "price";
|
|
394
392
|
select: "select";
|
|
393
|
+
multiselect: "multiselect";
|
|
395
394
|
page_builder: "page_builder";
|
|
395
|
+
price: "price";
|
|
396
396
|
}>;
|
|
397
397
|
values: z.ZodArray<z.ZodNullable<z.ZodString>>;
|
|
398
398
|
rowClass: z.ZodEnum<{
|
|
@@ -556,10 +556,10 @@ export declare const comparisonAdminDetailSchema: z.ZodObject<{
|
|
|
556
556
|
boolean: "boolean";
|
|
557
557
|
date: "date";
|
|
558
558
|
enum: "enum";
|
|
559
|
-
multiselect: "multiselect";
|
|
560
|
-
price: "price";
|
|
561
559
|
select: "select";
|
|
560
|
+
multiselect: "multiselect";
|
|
562
561
|
page_builder: "page_builder";
|
|
562
|
+
price: "price";
|
|
563
563
|
}>;
|
|
564
564
|
values: z.ZodArray<z.ZodNullable<z.ZodString>>;
|
|
565
565
|
rowClass: z.ZodEnum<{
|
package/dist/credit-limits.d.ts
CHANGED
|
@@ -16,18 +16,39 @@ export declare const creditLimitReservationReleaseReasonSchema: z.ZodEnum<{
|
|
|
16
16
|
export type CreditLimitReservationReleaseReason = z.infer<typeof creditLimitReservationReleaseReasonSchema>;
|
|
17
17
|
export declare const creditLimitViewSchema: z.ZodObject<{
|
|
18
18
|
organizationId: z.ZodString;
|
|
19
|
+
organizationName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
19
20
|
grantedAmount: z.ZodNumber;
|
|
20
21
|
availableAmount: z.ZodNumber;
|
|
21
22
|
currency: z.ZodString;
|
|
22
23
|
activeReservationCount: z.ZodNumber;
|
|
23
24
|
activeReservations: z.ZodArray<z.ZodObject<{
|
|
24
25
|
orderId: z.ZodString;
|
|
26
|
+
orderBusinessId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
25
27
|
amount: z.ZodNumber;
|
|
26
28
|
createdAt: z.ZodString;
|
|
27
29
|
}, z.core.$strip>>;
|
|
28
30
|
grantedAt: z.ZodString;
|
|
29
31
|
}, z.core.$strip>;
|
|
30
32
|
export type CreditLimitView = z.infer<typeof creditLimitViewSchema>;
|
|
33
|
+
/** `GET /api/v1/admin/credit-limits` — every granted credit limit (issue #599). */
|
|
34
|
+
export declare const creditLimitListResponseSchema: z.ZodObject<{
|
|
35
|
+
data: z.ZodArray<z.ZodObject<{
|
|
36
|
+
organizationId: z.ZodString;
|
|
37
|
+
organizationName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
38
|
+
grantedAmount: z.ZodNumber;
|
|
39
|
+
availableAmount: z.ZodNumber;
|
|
40
|
+
currency: z.ZodString;
|
|
41
|
+
activeReservationCount: z.ZodNumber;
|
|
42
|
+
activeReservations: z.ZodArray<z.ZodObject<{
|
|
43
|
+
orderId: z.ZodString;
|
|
44
|
+
orderBusinessId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
45
|
+
amount: z.ZodNumber;
|
|
46
|
+
createdAt: z.ZodString;
|
|
47
|
+
}, z.core.$strip>>;
|
|
48
|
+
grantedAt: z.ZodString;
|
|
49
|
+
}, z.core.$strip>>;
|
|
50
|
+
}, z.core.$strip>;
|
|
51
|
+
export type CreditLimitListResponse = z.infer<typeof creditLimitListResponseSchema>;
|
|
31
52
|
export declare const grantCreditLimitRequestSchema: z.ZodObject<{
|
|
32
53
|
grantedAmount: z.ZodNumber;
|
|
33
54
|
currency: z.ZodString;
|