@sixtyninecommerce/admin 0.9.0 → 0.11.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 +4598 -128
- package/dist/catalog/assets.d.ts +120 -8
- package/dist/catalog/assets.js +98 -12
- package/dist/catalog/collections.d.ts +279 -14
- package/dist/catalog/collections.js +246 -15
- package/dist/catalog/index.d.ts +9 -2
- package/dist/catalog/index.js +4 -0
- package/dist/catalog/products.d.ts +318 -17
- package/dist/catalog/products.js +182 -14
- package/dist/catalog/properties.d.ts +102 -14
- package/dist/catalog/properties.js +13 -0
- package/dist/catalog/recommendations.d.ts +261 -0
- package/dist/catalog/recommendations.js +145 -0
- package/dist/catalog/reviews.d.ts +368 -0
- package/dist/catalog/reviews.js +318 -0
- package/dist/catalog/types.d.ts +17 -1
- package/dist/catalog/types.js +10 -0
- package/dist/catalog/variant-find.d.ts +136 -0
- package/dist/catalog/variant-find.js +239 -0
- package/dist/catalog/variants.d.ts +282 -25
- package/dist/catalog/variants.js +173 -25
- package/dist/catalog/visibility.d.ts +20 -5
- package/dist/catalog/visibility.js +19 -1
- package/dist/client.d.ts +116 -9
- package/dist/client.js +41 -7
- package/dist/content/assets.d.ts +286 -0
- package/dist/content/assets.js +181 -0
- package/dist/content/items.d.ts +269 -0
- package/dist/content/items.js +170 -0
- package/dist/content/types.d.ts +282 -0
- package/dist/content/types.js +100 -0
- package/dist/customers/age-verification.d.ts +66 -0
- package/dist/customers/age-verification.js +79 -0
- package/dist/customers/credit.d.ts +263 -0
- package/dist/customers/credit.js +244 -0
- package/dist/customers/delivery-preferences.d.ts +120 -0
- package/dist/customers/delivery-preferences.js +97 -0
- package/dist/customers/groups.d.ts +207 -0
- package/dist/customers/groups.js +438 -0
- package/dist/customers/index.d.ts +447 -37
- package/dist/customers/index.js +313 -40
- package/dist/customers/invitation-status.d.ts +57 -0
- package/dist/customers/invitation-status.js +21 -0
- package/dist/customers/notes.d.ts +67 -0
- package/dist/customers/notes.js +51 -0
- package/dist/customers/notification-recipients.d.ts +97 -0
- package/dist/customers/notification-recipients.js +84 -0
- package/dist/customers/saved-lists.d.ts +42 -0
- package/dist/customers/saved-lists.js +61 -0
- package/dist/customers/vat.d.ts +83 -0
- package/dist/customers/vat.js +46 -0
- package/dist/customers/wire.d.ts +20 -0
- package/dist/customers/wire.js +35 -0
- package/dist/documents/ar.d.ts +307 -0
- package/dist/documents/ar.js +254 -0
- package/dist/documents/index.d.ts +731 -21
- package/dist/documents/index.js +436 -24
- package/dist/documents/pdf.d.ts +2 -0
- package/dist/documents/pdf.js +11 -0
- package/dist/fulfillments/create.d.ts +167 -0
- package/dist/fulfillments/create.js +216 -0
- package/dist/fulfillments/index.d.ts +121 -10
- package/dist/fulfillments/index.js +120 -2
- package/dist/fulfillments/payment-policy.d.ts +64 -0
- package/dist/fulfillments/payment-policy.js +140 -0
- package/dist/fulfillments/warehouse.d.ts +724 -0
- package/dist/fulfillments/warehouse.js +914 -0
- package/dist/geo/index.d.ts +119 -0
- package/dist/geo/index.js +107 -0
- package/dist/index.d.ts +129 -30
- package/dist/index.js +47 -9
- package/dist/integrations/afas-actions.d.ts +234 -0
- package/dist/integrations/afas-actions.js +310 -0
- package/dist/integrations/afas-types.d.ts +483 -0
- package/dist/integrations/afas-types.js +5 -0
- package/dist/integrations/afas.d.ts +234 -0
- package/dist/integrations/afas.js +290 -0
- package/dist/integrations/connections.d.ts +103 -0
- package/dist/integrations/connections.js +55 -0
- package/dist/integrations/esp.d.ts +313 -0
- package/dist/integrations/esp.js +169 -0
- package/dist/integrations/exact-online-types.d.ts +423 -0
- package/dist/integrations/exact-online-types.js +6 -0
- package/dist/integrations/exact-online.d.ts +248 -0
- package/dist/integrations/exact-online.js +376 -0
- package/dist/integrations/index.d.ts +40 -0
- package/dist/integrations/index.js +24 -0
- package/dist/integrations/pipeline-keys.d.ts +13 -0
- package/dist/integrations/pipeline-keys.js +22 -0
- package/dist/integrations/pipelines.d.ts +114 -0
- package/dist/integrations/pipelines.js +46 -0
- package/dist/integrations/types.d.ts +322 -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/locations/index.d.ts +66 -0
- package/dist/locations/index.js +31 -0
- package/dist/meta/index.d.ts +162 -0
- package/dist/orders/bulk.d.ts +75 -0
- package/dist/orders/bulk.js +150 -0
- package/dist/orders/cancel-with-money.d.ts +227 -0
- package/dist/orders/cancel-with-money.js +153 -0
- package/dist/orders/commit-edit.d.ts +7 -1
- package/dist/orders/commit-edit.js +5 -1
- package/dist/orders/deposit-policy.d.ts +103 -0
- package/dist/orders/deposit-policy.js +202 -0
- package/dist/orders/drafts.d.ts +800 -0
- package/dist/orders/drafts.js +771 -0
- package/dist/orders/fields.d.ts +245 -0
- package/dist/orders/fields.js +188 -0
- package/dist/orders/get.d.ts +29 -19
- package/dist/orders/get.js +17 -8
- package/dist/orders/index.d.ts +125 -5
- package/dist/orders/index.js +35 -2
- package/dist/orders/lifecycle.d.ts +128 -0
- package/dist/orders/lifecycle.js +158 -0
- package/dist/orders/line-price-preview.d.ts +7 -2
- package/dist/orders/list.d.ts +222 -0
- package/dist/orders/list.js +377 -0
- package/dist/orders/manual-discounts.d.ts +11 -2
- package/dist/orders/manual-discounts.js +2 -0
- package/dist/orders/manual-pricing.d.ts +5 -0
- package/dist/orders/order-entry.d.ts +20 -7
- package/dist/orders/plan-edit.d.ts +1 -1
- package/dist/orders/plan-edit.js +4 -1
- package/dist/orders/settings.d.ts +201 -0
- package/dist/orders/settings.js +325 -0
- package/dist/orders/status.d.ts +159 -13
- package/dist/orders/status.js +21 -0
- package/dist/orders/surcharges.d.ts +8 -1
- package/dist/orders/surcharges.js +3 -2
- package/dist/payments/account-credit.d.ts +30 -0
- package/dist/payments/account-credit.js +19 -0
- package/dist/payments/ar.d.ts +292 -0
- package/dist/payments/ar.js +223 -0
- package/dist/payments/connected-account.d.ts +47 -0
- package/dist/payments/connected-account.js +61 -0
- package/dist/payments/credit-noted-fields.d.ts +12 -0
- package/dist/payments/credit-noted-fields.js +37 -0
- package/dist/payments/index.d.ts +263 -10
- package/dist/payments/index.js +133 -1
- package/dist/payments/methods.d.ts +332 -0
- package/dist/payments/methods.js +363 -0
- package/dist/payments/mollie-methods.d.ts +159 -0
- package/dist/payments/mollie-methods.js +141 -0
- package/dist/payments/payment-links.d.ts +180 -0
- package/dist/payments/payment-links.js +97 -0
- package/dist/payments/provider-keys.d.ts +150 -0
- package/dist/payments/provider-keys.js +118 -0
- package/dist/payments/providers.d.ts +86 -11
- package/dist/payments/providers.js +29 -0
- package/dist/payments/requests.d.ts +144 -0
- package/dist/payments/requests.js +92 -0
- package/dist/payments/store-credit-fields.d.ts +15 -0
- package/dist/payments/store-credit-fields.js +51 -0
- package/dist/pickups/index.d.ts +104 -0
- package/dist/pickups/index.js +105 -0
- package/dist/platform/channels.d.ts +132 -0
- package/dist/platform/channels.js +128 -0
- package/dist/platform/geo.d.ts +123 -0
- package/dist/platform/geo.js +144 -0
- package/dist/platform/tax.d.ts +154 -0
- package/dist/platform/tax.js +139 -0
- package/dist/pos/anomalies.d.ts +158 -0
- package/dist/pos/anomalies.js +64 -0
- package/dist/pos/assisted-selling.d.ts +79 -0
- package/dist/pos/assisted-selling.js +38 -0
- package/dist/pos/exchanges.d.ts +103 -0
- package/dist/pos/exchanges.js +22 -0
- package/dist/pos/gift-cards.d.ts +135 -0
- package/dist/pos/gift-cards.js +47 -0
- package/dist/pos/index.d.ts +2125 -32
- package/dist/pos/index.js +742 -4
- package/dist/pos/no-receipt.d.ts +94 -0
- package/dist/pos/no-receipt.js +25 -0
- package/dist/pos/offline-sales.d.ts +187 -0
- package/dist/pos/offline-sales.js +116 -0
- package/dist/pos/pay-by-link.d.ts +143 -0
- package/dist/pos/pay-by-link.js +57 -0
- package/dist/pos/quick-keys.d.ts +103 -0
- package/dist/pos/quick-keys.js +45 -0
- package/dist/pos/reports.d.ts +360 -0
- package/dist/pos/reports.js +62 -0
- package/dist/pos/returns.d.ts +217 -0
- package/dist/pos/returns.js +53 -0
- package/dist/pricing/bulk-coupons.d.ts +139 -0
- package/dist/pricing/bulk-coupons.js +112 -0
- package/dist/pricing/index.d.ts +177 -4
- package/dist/pricing/index.js +176 -1
- package/dist/pricing/price-lists.d.ts +604 -0
- package/dist/pricing/price-lists.js +600 -0
- package/dist/pricing/vouchers.d.ts +103 -0
- package/dist/pricing/vouchers.js +69 -0
- package/dist/purchasing/alerts.d.ts +89 -0
- package/dist/purchasing/alerts.js +62 -0
- package/dist/purchasing/cost.d.ts +110 -0
- package/dist/purchasing/cost.js +86 -0
- package/dist/purchasing/index.d.ts +36 -0
- package/dist/purchasing/index.js +16 -0
- package/dist/purchasing/purchase-orders.d.ts +548 -0
- package/dist/purchasing/purchase-orders.js +491 -0
- package/dist/purchasing/replenishment.d.ts +281 -0
- package/dist/purchasing/replenishment.js +240 -0
- package/dist/purchasing/settings.d.ts +152 -0
- package/dist/purchasing/settings.js +181 -0
- package/dist/purchasing/suppliers.d.ts +476 -0
- package/dist/purchasing/suppliers.js +438 -0
- package/dist/quotes/index.d.ts +501 -0
- package/dist/quotes/index.js +439 -0
- package/dist/reports/index.d.ts +71 -8
- package/dist/reports/index.js +74 -11
- package/dist/returns/index.d.ts +818 -0
- package/dist/returns/index.js +844 -0
- package/dist/search/index.d.ts +174 -0
- package/dist/search/index.js +125 -0
- package/dist/shipping/definitions.d.ts +29 -0
- package/dist/shipping/definitions.js +47 -0
- package/dist/shipping/fulfillment-profiles.d.ts +174 -0
- package/dist/shipping/fulfillment-profiles.js +104 -0
- package/dist/shipping/hendriks.d.ts +97 -0
- package/dist/shipping/hendriks.js +50 -0
- package/dist/shipping/index.d.ts +48 -0
- package/dist/shipping/index.js +25 -0
- package/dist/shipping/methods.d.ts +198 -0
- package/dist/shipping/methods.js +240 -0
- package/dist/shipping/myparcel.d.ts +254 -0
- package/dist/shipping/myparcel.js +178 -0
- package/dist/shipping/parcel-count-suggestion.d.ts +2 -0
- package/dist/shipping/parcel-rule.d.ts +6 -5
- package/dist/shipping/parcel-rule.js +21 -23
- package/dist/shipping/rate-tables.d.ts +179 -0
- package/dist/shipping/rate-tables.js +184 -0
- package/dist/stock/index.d.ts +10 -3
- package/dist/stock/index.js +3 -0
- package/dist/stock/locations.d.ts +144 -0
- package/dist/stock/locations.js +168 -0
- package/dist/stock/transfers.d.ts +216 -43
- package/dist/stock/transfers.js +140 -13
- package/dist/stored-value/index.d.ts +214 -4
- package/dist/stored-value/index.js +152 -0
- package/dist/subscriptions/index.d.ts +682 -0
- package/dist/subscriptions/index.js +815 -0
- package/dist/tax/index.d.ts +76 -1
- package/dist/tax/index.js +50 -0
- package/dist/tenant/email-style.d.ts +102 -0
- package/dist/tenant/email-style.js +72 -0
- package/dist/tenant/email-templates.d.ts +66 -0
- package/dist/tenant/email-templates.js +54 -0
- package/dist/tenant/notifications.d.ts +23 -17
- package/dist/tenant/settings-sources.d.ts +1 -1
- package/dist/tenant/time-zone.d.ts +17 -0
- package/dist/tenant/time-zone.js +11 -0
- package/dist/types.d.ts +51 -4
- package/dist/users/index.d.ts +3 -0
- package/dist/users/index.js +2 -0
- package/dist/users/warehouses.d.ts +50 -0
- package/dist/users/warehouses.js +51 -0
- package/package.json +2 -2
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import type { Transport } from '@sixtyninecommerce/core';
|
|
2
|
+
import type { Call } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* A store's payment-links connection (Tikkie, ABN AMRO): one record per store. It adds a "pay
|
|
5
|
+
* this invoice" link to the invoice e-mails of orders with something left to pay, and the order
|
|
6
|
+
* settles when the link is paid. The credentials are never read back, only whether one is stored
|
|
7
|
+
* and its mask.
|
|
8
|
+
*/
|
|
9
|
+
export interface PaymentLinksConfig {
|
|
10
|
+
id: string;
|
|
11
|
+
channelId: string;
|
|
12
|
+
/** `tikkie`, the one provider today. */
|
|
13
|
+
provider: string;
|
|
14
|
+
/** Whether new invoice e-mails carry a link. Never true without an app token. */
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
/** Talks to the Tikkie sandbox instead of production. */
|
|
17
|
+
sandboxMode: boolean;
|
|
18
|
+
/** Days a new link stays payable. */
|
|
19
|
+
defaultExpiryDays: number;
|
|
20
|
+
hasApiKey: boolean;
|
|
21
|
+
/** The stored API key, masked (its last four characters); null when none, or unreadable. */
|
|
22
|
+
maskedApiKey: string | null;
|
|
23
|
+
hasAppToken: boolean;
|
|
24
|
+
/** The stored app token, masked; null when none, or unreadable. */
|
|
25
|
+
maskedAppToken: string | null;
|
|
26
|
+
/** Tikkie's id of the store's webhook subscription; null until one is registered. */
|
|
27
|
+
webhookSubscriptionId: string | null;
|
|
28
|
+
/** ISO-8601: when the webhook was registered; null until it is. */
|
|
29
|
+
webhookRegisteredAt: string | null;
|
|
30
|
+
/** ISO-8601. */
|
|
31
|
+
createdAt: string;
|
|
32
|
+
/** ISO-8601. */
|
|
33
|
+
updatedAt: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A PATCH: a key left out keeps the stored value. The first save must carry `apiKey`.
|
|
37
|
+
*
|
|
38
|
+
* A credential is write-only. Absent, null, blank, or the very mask the read answered keeps the
|
|
39
|
+
* stored one; any other value carrying the mask glyph is refused `SECRET_ARG_MASK_INVALID`.
|
|
40
|
+
*/
|
|
41
|
+
export interface UpdatePaymentLinksConfigInput {
|
|
42
|
+
enabled?: boolean;
|
|
43
|
+
sandboxMode?: boolean;
|
|
44
|
+
/** No range is enforced: 0 or less makes links that have already expired. */
|
|
45
|
+
defaultExpiryDays?: number;
|
|
46
|
+
apiKey?: string | null;
|
|
47
|
+
appToken?: string | null;
|
|
48
|
+
}
|
|
49
|
+
/** What `testConnection` found: a result, not a refusal. */
|
|
50
|
+
export interface PaymentLinksTestResult {
|
|
51
|
+
ok: boolean;
|
|
52
|
+
/** A sentence for the person who pressed "Test": the HTTP status at most, never Tikkie's body. */
|
|
53
|
+
message: string;
|
|
54
|
+
}
|
|
55
|
+
/** Every state a payment link takes, in the engine's order (`PaymentRequestStatus`). */
|
|
56
|
+
export declare const PAYMENT_LINK_REQUEST_STATUSES: readonly ["open", "paid", "expired", "superseded"];
|
|
57
|
+
/**
|
|
58
|
+
* `open`, then `paid` or `expired`; `superseded` when a newer link for the same order replaced it.
|
|
59
|
+
* A later engine may add a state: read anything else as "not payable".
|
|
60
|
+
*/
|
|
61
|
+
export type PaymentLinkRequestStatus = (typeof PAYMENT_LINK_REQUEST_STATUSES)[number] | (string & {});
|
|
62
|
+
/**
|
|
63
|
+
* One Tikkie payment link the store sent for an order. Not the engine's own hosted payment
|
|
64
|
+
* request (`payments.requests`): this is the payment-links plugin's, created by the invoice
|
|
65
|
+
* e-mail.
|
|
66
|
+
*/
|
|
67
|
+
export interface PaymentLinkRequest {
|
|
68
|
+
id: string;
|
|
69
|
+
orderId: string;
|
|
70
|
+
/** The invoice whose e-mail carried the link; null for a link sent otherwise. */
|
|
71
|
+
invoiceId: string | null;
|
|
72
|
+
provider: string;
|
|
73
|
+
/** The provider's id of the request (Tikkie's payment request token). */
|
|
74
|
+
externalId: string;
|
|
75
|
+
/** The link the customer pays through. */
|
|
76
|
+
url: string;
|
|
77
|
+
status: PaymentLinkRequestStatus;
|
|
78
|
+
/** Minor units of `currencyCode` the link asks for. */
|
|
79
|
+
amountMinor: number;
|
|
80
|
+
currencyCode: string;
|
|
81
|
+
/** ISO-8601; null when the provider set none. */
|
|
82
|
+
expiresAt: string | null;
|
|
83
|
+
/** ISO-8601; null until paid. */
|
|
84
|
+
paidAt: string | null;
|
|
85
|
+
/** ISO-8601. */
|
|
86
|
+
createdAt: string;
|
|
87
|
+
}
|
|
88
|
+
/** The store's Tikkie settings (`admin.payments.paymentLinks.config`). */
|
|
89
|
+
export interface PaymentLinksConfigModule {
|
|
90
|
+
/**
|
|
91
|
+
* The store's settings, or `null` when it never saved any. Needs `UpdateSettings` (the engine
|
|
92
|
+
* guards the read with the write's permission).
|
|
93
|
+
*
|
|
94
|
+
* @effect read
|
|
95
|
+
* @permission UpdateSettings
|
|
96
|
+
*/
|
|
97
|
+
get(options?: Call): Promise<PaymentLinksConfig | null>;
|
|
98
|
+
/**
|
|
99
|
+
* Save the settings; the first call creates the record (off, sandbox mode, 14-day links,
|
|
100
|
+
* unless given). Needs `UpdateSettings`.
|
|
101
|
+
*
|
|
102
|
+
* Refused, with nothing saved:
|
|
103
|
+
* - `PAYMENT_LINKS_INPUT_INVALID` (`ValidationError`, 400): the first save without `apiKey`, or
|
|
104
|
+
* an explicit null for `enabled`, `sandboxMode` or `defaultExpiryDays` on a saved record.
|
|
105
|
+
* `details[]` names each field;
|
|
106
|
+
* - `PAYMENT_LINKS_APP_TOKEN_REQUIRED` (`BusinessRuleError`, 422): `enabled: true` while no app
|
|
107
|
+
* token is stored or sent in the same call;
|
|
108
|
+
* - `SECRET_ARG_MASK_INVALID` (400): a credential carrying the mask glyph that is not the stored
|
|
109
|
+
* one's mask; `APP_SECRET_ARG_NOT_ALLOWED` (403): an app installation setting a credential;
|
|
110
|
+
* - `ORGANIZATION_WORKSPACE_NOT_A_STORE` (422): switching on, or storing a credential, in an
|
|
111
|
+
* organization's workspace;
|
|
112
|
+
* - `PLUGIN_ACCESS_DENIED` (403): the store does not hold the payment-links plugin (never for a
|
|
113
|
+
* SuperAdmin).
|
|
114
|
+
*
|
|
115
|
+
* @effect write
|
|
116
|
+
* @permission UpdateSettings
|
|
117
|
+
*/
|
|
118
|
+
update(input: UpdatePaymentLinksConfigInput, options?: Call): Promise<PaymentLinksConfig>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The store's payment links: the Tikkie connection's settings, its checks, and the links an
|
|
122
|
+
* order was sent (`admin.payments.paymentLinks`). Always the store the client is scoped to; a
|
|
123
|
+
* SuperAdmin head configures ANOTHER store with `admin.withTenant({ scope: { kind: 'channel',
|
|
124
|
+
* code } })`, or a per-call `tenant`.
|
|
125
|
+
*/
|
|
126
|
+
export interface PaymentLinksModule {
|
|
127
|
+
config: PaymentLinksConfigModule;
|
|
128
|
+
/**
|
|
129
|
+
* Ask Tikkie whether the stored credentials work. Never refuses for what it finds: a store with
|
|
130
|
+
* no settings, no app token, or credentials Tikkie rejects answers `ok: false` with the reason.
|
|
131
|
+
* Needs `UpdateSettings`.
|
|
132
|
+
*
|
|
133
|
+
* @effect read
|
|
134
|
+
* @permission UpdateSettings
|
|
135
|
+
*/
|
|
136
|
+
testConnection(options?: Call): Promise<PaymentLinksTestResult>;
|
|
137
|
+
/**
|
|
138
|
+
* Register the store's webhook with Tikkie, so a paid link settles its order at once instead of
|
|
139
|
+
* at the 5-minute check, and answer the settings with the subscription. Needs `UpdateSettings`.
|
|
140
|
+
*
|
|
141
|
+
* Refused: `PAYMENT_LINKS_NOT_CONFIGURED` (422) without settings;
|
|
142
|
+
* `PAYMENT_LINKS_APP_TOKEN_REQUIRED` (422) with no app token stored;
|
|
143
|
+
* `PAYMENT_LINKS_PROVIDER_UNAVAILABLE` (422, Tikkie failed or refused; nothing stored);
|
|
144
|
+
* `PAYMENT_LINKS_WEBHOOK_HOST_NOT_CONFIGURED` (422, the platform has no public address; its
|
|
145
|
+
* operator's to fix); `ORGANIZATION_WORKSPACE_NOT_A_STORE` (422).
|
|
146
|
+
*
|
|
147
|
+
* @effect write
|
|
148
|
+
* @permission UpdateSettings
|
|
149
|
+
*/
|
|
150
|
+
registerWebhook(options?: Call): Promise<PaymentLinksConfig>;
|
|
151
|
+
/**
|
|
152
|
+
* Sandbox only: have Tikkie mint a test app token with the stored API key, store it, and answer
|
|
153
|
+
* the settings. Needs `UpdateSettings`; an app installation is refused
|
|
154
|
+
* (`APP_SECRET_ARG_NOT_ALLOWED`).
|
|
155
|
+
*
|
|
156
|
+
* Refused: `PAYMENT_LINKS_NOT_CONFIGURED` (422); `PAYMENT_LINKS_SANDBOX_MODE_REQUIRED` (422,
|
|
157
|
+
* the store is in production mode); `PAYMENT_LINKS_PROVIDER_UNAVAILABLE` (422, nothing stored);
|
|
158
|
+
* `ORGANIZATION_WORKSPACE_NOT_A_STORE` (422).
|
|
159
|
+
*
|
|
160
|
+
* @effect write
|
|
161
|
+
* @permission UpdateSettings
|
|
162
|
+
*/
|
|
163
|
+
createSandboxAppToken(options?: Call): Promise<PaymentLinksConfig>;
|
|
164
|
+
/**
|
|
165
|
+
* The payment links the store sent for one order, newest first. Needs `ReadOrder`. Another
|
|
166
|
+
* store's order, or an id that names no order, answers an empty list; a value that is no id
|
|
167
|
+
* at all is refused `ENTITY_NOT_FOUND` (`NotFoundError`, 404).
|
|
168
|
+
*
|
|
169
|
+
* @effect read
|
|
170
|
+
* @permission ReadOrder
|
|
171
|
+
*/
|
|
172
|
+
requests(orderId: string, options?: Call): Promise<PaymentLinkRequest[]>;
|
|
173
|
+
}
|
|
174
|
+
export declare const PAYMENT_LINKS_CONFIG_QUERY = "\n query PaymentLinksConfig {\n paymentLinksConfig { \n id\n channelId\n provider\n enabled\n sandboxMode\n defaultExpiryDays\n hasApiKey\n maskedApiKey\n hasAppToken\n maskedAppToken\n webhookSubscriptionId\n webhookRegisteredAt\n createdAt\n updatedAt\n }\n }\n";
|
|
175
|
+
export declare const UPDATE_PAYMENT_LINKS_CONFIG_MUTATION = "\n mutation UpdatePaymentLinksConfig($input: UpdatePaymentLinksConfigInput!) {\n updatePaymentLinksConfig(input: $input) { \n id\n channelId\n provider\n enabled\n sandboxMode\n defaultExpiryDays\n hasApiKey\n maskedApiKey\n hasAppToken\n maskedAppToken\n webhookSubscriptionId\n webhookRegisteredAt\n createdAt\n updatedAt\n }\n }\n";
|
|
176
|
+
export declare const TEST_PAYMENT_LINKS_CONNECTION_MUTATION = "\n mutation TestPaymentLinksConnection {\n testPaymentLinksConnection { ok message }\n }\n";
|
|
177
|
+
export declare const REGISTER_PAYMENT_LINKS_WEBHOOK_MUTATION = "\n mutation RegisterPaymentLinksWebhook {\n registerPaymentLinksWebhook { \n id\n channelId\n provider\n enabled\n sandboxMode\n defaultExpiryDays\n hasApiKey\n maskedApiKey\n hasAppToken\n maskedAppToken\n webhookSubscriptionId\n webhookRegisteredAt\n createdAt\n updatedAt\n }\n }\n";
|
|
178
|
+
export declare const CREATE_PAYMENT_LINKS_SANDBOX_APP_TOKEN_MUTATION = "\n mutation CreatePaymentLinksSandboxAppToken {\n createPaymentLinksSandboxAppToken { \n id\n channelId\n provider\n enabled\n sandboxMode\n defaultExpiryDays\n hasApiKey\n maskedApiKey\n hasAppToken\n maskedAppToken\n webhookSubscriptionId\n webhookRegisteredAt\n createdAt\n updatedAt\n }\n }\n";
|
|
179
|
+
export declare const ORDER_PAYMENT_LINK_REQUESTS_QUERY = "\n query OrderPaymentLinkRequests($orderId: ID!) {\n orderPaymentLinkRequests(orderId: $orderId) {\n id\n orderId\n invoiceId\n provider\n externalId\n url\n status\n amountMinor\n currencyCode\n expiresAt\n paidAt\n createdAt\n }\n }\n";
|
|
180
|
+
export declare function createPaymentLinksModule(transport: Transport): PaymentLinksModule;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/** Every state a payment link takes, in the engine's order (`PaymentRequestStatus`). */
|
|
2
|
+
export const PAYMENT_LINK_REQUEST_STATUSES = ['open', 'paid', 'expired', 'superseded'];
|
|
3
|
+
const CONFIG_FIELDS = /* GraphQL */ `
|
|
4
|
+
id
|
|
5
|
+
channelId
|
|
6
|
+
provider
|
|
7
|
+
enabled
|
|
8
|
+
sandboxMode
|
|
9
|
+
defaultExpiryDays
|
|
10
|
+
hasApiKey
|
|
11
|
+
maskedApiKey
|
|
12
|
+
hasAppToken
|
|
13
|
+
maskedAppToken
|
|
14
|
+
webhookSubscriptionId
|
|
15
|
+
webhookRegisteredAt
|
|
16
|
+
createdAt
|
|
17
|
+
updatedAt
|
|
18
|
+
`;
|
|
19
|
+
export const PAYMENT_LINKS_CONFIG_QUERY = /* GraphQL */ `
|
|
20
|
+
query PaymentLinksConfig {
|
|
21
|
+
paymentLinksConfig { ${CONFIG_FIELDS} }
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
export const UPDATE_PAYMENT_LINKS_CONFIG_MUTATION = /* GraphQL */ `
|
|
25
|
+
mutation UpdatePaymentLinksConfig($input: UpdatePaymentLinksConfigInput!) {
|
|
26
|
+
updatePaymentLinksConfig(input: $input) { ${CONFIG_FIELDS} }
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
export const TEST_PAYMENT_LINKS_CONNECTION_MUTATION = /* GraphQL */ `
|
|
30
|
+
mutation TestPaymentLinksConnection {
|
|
31
|
+
testPaymentLinksConnection { ok message }
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
export const REGISTER_PAYMENT_LINKS_WEBHOOK_MUTATION = /* GraphQL */ `
|
|
35
|
+
mutation RegisterPaymentLinksWebhook {
|
|
36
|
+
registerPaymentLinksWebhook { ${CONFIG_FIELDS} }
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
export const CREATE_PAYMENT_LINKS_SANDBOX_APP_TOKEN_MUTATION = /* GraphQL */ `
|
|
40
|
+
mutation CreatePaymentLinksSandboxAppToken {
|
|
41
|
+
createPaymentLinksSandboxAppToken { ${CONFIG_FIELDS} }
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
export const ORDER_PAYMENT_LINK_REQUESTS_QUERY = /* GraphQL */ `
|
|
45
|
+
query OrderPaymentLinkRequests($orderId: ID!) {
|
|
46
|
+
orderPaymentLinkRequests(orderId: $orderId) {
|
|
47
|
+
id
|
|
48
|
+
orderId
|
|
49
|
+
invoiceId
|
|
50
|
+
provider
|
|
51
|
+
externalId
|
|
52
|
+
url
|
|
53
|
+
status
|
|
54
|
+
amountMinor
|
|
55
|
+
currencyCode
|
|
56
|
+
expiresAt
|
|
57
|
+
paidAt
|
|
58
|
+
createdAt
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
62
|
+
export function createPaymentLinksModule(transport) {
|
|
63
|
+
return {
|
|
64
|
+
config: {
|
|
65
|
+
async get(options) {
|
|
66
|
+
const data = await transport.graphql({ api: 'admin', query: PAYMENT_LINKS_CONFIG_QUERY }, options);
|
|
67
|
+
return data.paymentLinksConfig ?? null;
|
|
68
|
+
},
|
|
69
|
+
async update(input, options) {
|
|
70
|
+
const data = await transport.graphql({
|
|
71
|
+
api: 'admin',
|
|
72
|
+
query: UPDATE_PAYMENT_LINKS_CONFIG_MUTATION,
|
|
73
|
+
// Sent as given: an absent key keeps the stored value, and the engine names
|
|
74
|
+
// anything it refuses.
|
|
75
|
+
variables: { input },
|
|
76
|
+
}, options);
|
|
77
|
+
return data.updatePaymentLinksConfig;
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
async testConnection(options) {
|
|
81
|
+
const data = await transport.graphql({ api: 'admin', query: TEST_PAYMENT_LINKS_CONNECTION_MUTATION }, options);
|
|
82
|
+
return data.testPaymentLinksConnection;
|
|
83
|
+
},
|
|
84
|
+
async registerWebhook(options) {
|
|
85
|
+
const data = await transport.graphql({ api: 'admin', query: REGISTER_PAYMENT_LINKS_WEBHOOK_MUTATION }, options);
|
|
86
|
+
return data.registerPaymentLinksWebhook;
|
|
87
|
+
},
|
|
88
|
+
async createSandboxAppToken(options) {
|
|
89
|
+
const data = await transport.graphql({ api: 'admin', query: CREATE_PAYMENT_LINKS_SANDBOX_APP_TOKEN_MUTATION }, options);
|
|
90
|
+
return data.createPaymentLinksSandboxAppToken;
|
|
91
|
+
},
|
|
92
|
+
async requests(orderId, options) {
|
|
93
|
+
const data = await transport.graphql({ api: 'admin', query: ORDER_PAYMENT_LINK_REQUESTS_QUERY, variables: { orderId } }, options);
|
|
94
|
+
return data.orderPaymentLinkRequests;
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { type Page, type Transport } from '@sixtyninecommerce/core';
|
|
2
|
+
import type { Call } from '../types.js';
|
|
3
|
+
import type { PaymentMethodCredentialPath } from './methods.js';
|
|
4
|
+
/** Which provider a payment method's key is for, by its handler. */
|
|
5
|
+
export type ProviderKeyProvider = 'mollie' | 'stripe' | 'other';
|
|
6
|
+
/**
|
|
7
|
+
* One payment method's provider key, as the Mollie and Stripe cards show it. A secret is never
|
|
8
|
+
* answered, to anyone: only whether it is set and the API key's last four characters.
|
|
9
|
+
*/
|
|
10
|
+
export interface PaymentProviderKey {
|
|
11
|
+
paymentMethodId: string;
|
|
12
|
+
/** The payment method's code: what {@link ProviderKeysModule.set} and `test` take. */
|
|
13
|
+
paymentMethodCode: string;
|
|
14
|
+
/** `mollie` or `stripe` by the method's handler; `other` for every other handler. */
|
|
15
|
+
provider: ProviderKeyProvider;
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
hasApiKey: boolean;
|
|
18
|
+
/** The API key masked to its last four (`test_••••3a9f`), or null when none is set. */
|
|
19
|
+
maskedApiKey: string | null;
|
|
20
|
+
/** Stripe's webhook signing secret is set (never answered itself). Always false for Mollie. */
|
|
21
|
+
hasWebhookSecret: boolean;
|
|
22
|
+
/** Where the provider sends its webhooks for this method; `''` for any other handler. */
|
|
23
|
+
webhookUrl: string;
|
|
24
|
+
/** Mollie's return URL; null when the method has none. */
|
|
25
|
+
redirectUrl: string | null;
|
|
26
|
+
/**
|
|
27
|
+
* What the method takes payments with: its own key (`api_key`, every non-Mollie method) or
|
|
28
|
+
* the store's Mollie Connect account (`connect`). While it is `connect` the key here is kept
|
|
29
|
+
* but does not take payments, and {@link ProviderKeysModule.test} tests the key, not the
|
|
30
|
+
* Connect account. Changed only with `payments.methods.setCredentialPath`.
|
|
31
|
+
*/
|
|
32
|
+
credentialPath: PaymentMethodCredentialPath;
|
|
33
|
+
}
|
|
34
|
+
/** What the provider's own API said of the stored key. */
|
|
35
|
+
export interface ProviderKeyTest {
|
|
36
|
+
/** The provider accepted the key. */
|
|
37
|
+
ok: boolean;
|
|
38
|
+
/** `Connected`, or why not, in the provider's or the engine's words. */
|
|
39
|
+
message: string;
|
|
40
|
+
/** Mollie only, when `ok`: the checkout methods its account offers. Null otherwise. */
|
|
41
|
+
methods: string[] | null;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A change to one method's key. What is left out, or sent blank, keeps what the method has:
|
|
45
|
+
* this door never clears a key.
|
|
46
|
+
*/
|
|
47
|
+
export interface SetProviderKeyInput {
|
|
48
|
+
paymentMethodCode: string;
|
|
49
|
+
/** A new API key (Mollie `test_…`/`live_…`, Stripe `sk_…`). */
|
|
50
|
+
apiKey?: string;
|
|
51
|
+
/** A new Stripe webhook signing secret (`whsec_…`); ignored for any other provider. */
|
|
52
|
+
webhookSecret?: string;
|
|
53
|
+
redirectUrl?: string;
|
|
54
|
+
enabled?: boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The store's own Mollie and Stripe API keys: the LEGACY credential path, one key per payment
|
|
58
|
+
* method (headless spec §8.9). Deprecated in the schema and supported in the code: a store moves
|
|
59
|
+
* to an account onboarded through the platform (`payments.providers.startOnboarding`) when it
|
|
60
|
+
* chooses to, and `payments.providers.readiness` says which path it is on.
|
|
61
|
+
*
|
|
62
|
+
* Scoped to the store the client is on. No key is ever answered: only whether it is set and a
|
|
63
|
+
* masked preview. A method whose handler belongs to a plugin the store does not hold (Mollie,
|
|
64
|
+
* Stripe) is refused `PLUGIN_ACCESS_DENIED` (`PermissionDeniedError`, 403) by every call that
|
|
65
|
+
* names it; `list` is not.
|
|
66
|
+
*/
|
|
67
|
+
export interface ProviderKeysModule {
|
|
68
|
+
/**
|
|
69
|
+
* Every payment method of the store with its provider key state, Mollie, Stripe and any other
|
|
70
|
+
* handler alike, in one complete page. Needs `ReadPaymentMethod`.
|
|
71
|
+
*
|
|
72
|
+
* @deprecated legacy per-channel keys; use provider onboarding
|
|
73
|
+
* (`payments.providers.startOnboarding`).
|
|
74
|
+
* @effect read
|
|
75
|
+
* @permission ReadPaymentMethod
|
|
76
|
+
*/
|
|
77
|
+
list(options?: Call): Promise<Page<PaymentProviderKey>>;
|
|
78
|
+
/**
|
|
79
|
+
* One method's key state by the method's code, or null when the store has no method with that
|
|
80
|
+
* code. Needs `ReadPaymentMethod`.
|
|
81
|
+
*
|
|
82
|
+
* @deprecated legacy per-channel keys; use provider onboarding
|
|
83
|
+
* (`payments.providers.startOnboarding`).
|
|
84
|
+
* @effect read
|
|
85
|
+
* @permission ReadPaymentMethod
|
|
86
|
+
*/
|
|
87
|
+
get(paymentMethodCode: string, options?: Call): Promise<PaymentProviderKey | null>;
|
|
88
|
+
/**
|
|
89
|
+
* Give the store a Mollie or Stripe payment method to put a key on: disabled, with no key,
|
|
90
|
+
* Mollie's return URL defaulted to its webhook URL. The method is the store's alone. When the
|
|
91
|
+
* store already has a method for that provider, that one is answered and nothing is written,
|
|
92
|
+
* so a repeat is safe. Needs `UpdatePaymentMethod`.
|
|
93
|
+
*
|
|
94
|
+
* Refused, with nothing written: `USER_INPUT_ERROR` (`ValidationError`, 400) for a provider
|
|
95
|
+
* other than `mollie` or `stripe`; `PLUGIN_ACCESS_DENIED` (403) when the store does not hold
|
|
96
|
+
* that provider's plugin; `ORGANIZATION_WORKSPACE_NOT_A_STORE` (`BusinessRuleError`, 422):
|
|
97
|
+
* an organization's workspace takes no payments.
|
|
98
|
+
*
|
|
99
|
+
* @effect write
|
|
100
|
+
* @permission UpdatePaymentMethod
|
|
101
|
+
*/
|
|
102
|
+
create(provider: 'mollie' | 'stripe', options?: Call): Promise<PaymentProviderKey>;
|
|
103
|
+
/**
|
|
104
|
+
* Change one method's key, webhook secret, return URL or `enabled`, and answer its key state
|
|
105
|
+
* as {@link get} reads it. What is left out or blank keeps what is stored (to CLEAR a key, use
|
|
106
|
+
* `payments.methods.update` with the argument empty). Needs `UpdatePaymentMethod` here, and on
|
|
107
|
+
* every other store holding the method: a change reaches each of them.
|
|
108
|
+
*
|
|
109
|
+
* Refused, with nothing saved:
|
|
110
|
+
*
|
|
111
|
+
* - `SECRET_ARG_MASK_INVALID` (`ValidationError`, 400): a key was sent in its masked form and
|
|
112
|
+
* it is not the stored key's mask (the key changed since it was read). Read it again, or
|
|
113
|
+
* send the full key.
|
|
114
|
+
* - `APP_SECRET_ARG_NOT_ALLOWED` (`PermissionDeniedError`, 403): an app installation may not
|
|
115
|
+
* set or replace a key or webhook secret.
|
|
116
|
+
* - `LIVE_CONNECTION_REFUSED` (`BusinessRuleError`, 422): a store that is not live (a sandbox)
|
|
117
|
+
* may hold only a TEST key (`test_…`, `sk_test_…`). Judged on the key the method would hold,
|
|
118
|
+
* so enabling a sandbox method that already holds a live key is refused too.
|
|
119
|
+
* - `SHARED_PAYMENT_METHOD_NOT_ALLOWED` (`PermissionDeniedError`, 403): another store holds the
|
|
120
|
+
* method and the caller may not change it there.
|
|
121
|
+
* - `USER_INPUT_ERROR` (`ValidationError`, 400): the store has no method with that code.
|
|
122
|
+
* - `PLUGIN_ACCESS_DENIED` (403), see the module.
|
|
123
|
+
*
|
|
124
|
+
* @deprecated legacy per-channel keys; use provider onboarding
|
|
125
|
+
* (`payments.providers.startOnboarding`).
|
|
126
|
+
* @effect write
|
|
127
|
+
* @permission UpdatePaymentMethod
|
|
128
|
+
*/
|
|
129
|
+
set(input: SetProviderKeyInput, options?: Call): Promise<PaymentProviderKey>;
|
|
130
|
+
/**
|
|
131
|
+
* Ask the provider whether the method's stored key works (Mollie: its checkout methods;
|
|
132
|
+
* Stripe: the account balance). Changes nothing, here or at the provider.
|
|
133
|
+
*
|
|
134
|
+
* Never throws for the provider's answer: a rejected key, an unreachable provider, a method
|
|
135
|
+
* with no key or a handler that cannot be tested all answer `{ ok: false, message }`. It
|
|
136
|
+
* throws only when the call itself is refused: `USER_INPUT_ERROR` (`ValidationError`, 400)
|
|
137
|
+
* for a code the store has no method for, `PLUGIN_ACCESS_DENIED` (403), and `FORBIDDEN` (403)
|
|
138
|
+
* without `UpdatePaymentMethod`, which it needs because it uses the stored key.
|
|
139
|
+
*
|
|
140
|
+
* @effect read
|
|
141
|
+
* @permission UpdatePaymentMethod
|
|
142
|
+
*/
|
|
143
|
+
test(paymentMethodCode: string, options?: Call): Promise<ProviderKeyTest>;
|
|
144
|
+
}
|
|
145
|
+
export declare const PAYMENT_PROVIDER_KEYS_QUERY = "\n query PaymentProviderKeys {\n paymentProviderConnections { \n paymentMethodId\n paymentMethodCode\n provider\n enabled\n hasApiKey\n maskedApiKey\n hasWebhookSecret\n webhookUrl\n redirectUrl\n credentialPath\n }\n }\n";
|
|
146
|
+
export declare const PAYMENT_PROVIDER_KEY_QUERY = "\n query PaymentProviderKey($paymentMethodCode: String!) {\n paymentProviderConnection(paymentMethodCode: $paymentMethodCode) { \n paymentMethodId\n paymentMethodCode\n provider\n enabled\n hasApiKey\n maskedApiKey\n hasWebhookSecret\n webhookUrl\n redirectUrl\n credentialPath\n }\n }\n";
|
|
147
|
+
export declare const CREATE_PAYMENT_PROVIDER_MUTATION = "\n mutation CreatePaymentProviderKey($provider: String!) {\n createPaymentProvider(provider: $provider) { \n paymentMethodId\n paymentMethodCode\n provider\n enabled\n hasApiKey\n maskedApiKey\n hasWebhookSecret\n webhookUrl\n redirectUrl\n credentialPath\n }\n }\n";
|
|
148
|
+
export declare const SET_PAYMENT_PROVIDER_CREDENTIALS_MUTATION = "\n mutation SetPaymentProviderKey($input: SetPaymentProviderCredentialsInput!) {\n setPaymentProviderCredentials(input: $input) { \n paymentMethodId\n paymentMethodCode\n provider\n enabled\n hasApiKey\n maskedApiKey\n hasWebhookSecret\n webhookUrl\n redirectUrl\n credentialPath\n }\n }\n";
|
|
149
|
+
export declare const TEST_PAYMENT_PROVIDER_CONNECTION_MUTATION = "\n mutation TestPaymentProviderKey($paymentMethodCode: String!) {\n testPaymentProviderConnection(paymentMethodCode: $paymentMethodCode) {\n ok\n message\n methods\n }\n }\n";
|
|
150
|
+
export declare function createProviderKeysModule(transport: Transport): ProviderKeysModule;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { createPage, ValidationError } from '@sixtyninecommerce/core';
|
|
2
|
+
import { fieldOf } from '../catalog/types.js';
|
|
3
|
+
const KEY_FIELDS = /* GraphQL */ `
|
|
4
|
+
paymentMethodId
|
|
5
|
+
paymentMethodCode
|
|
6
|
+
provider
|
|
7
|
+
enabled
|
|
8
|
+
hasApiKey
|
|
9
|
+
maskedApiKey
|
|
10
|
+
hasWebhookSecret
|
|
11
|
+
webhookUrl
|
|
12
|
+
redirectUrl
|
|
13
|
+
credentialPath
|
|
14
|
+
`;
|
|
15
|
+
export const PAYMENT_PROVIDER_KEYS_QUERY = /* GraphQL */ `
|
|
16
|
+
query PaymentProviderKeys {
|
|
17
|
+
paymentProviderConnections { ${KEY_FIELDS} }
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
export const PAYMENT_PROVIDER_KEY_QUERY = /* GraphQL */ `
|
|
21
|
+
query PaymentProviderKey($paymentMethodCode: String!) {
|
|
22
|
+
paymentProviderConnection(paymentMethodCode: $paymentMethodCode) { ${KEY_FIELDS} }
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
export const CREATE_PAYMENT_PROVIDER_MUTATION = /* GraphQL */ `
|
|
26
|
+
mutation CreatePaymentProviderKey($provider: String!) {
|
|
27
|
+
createPaymentProvider(provider: $provider) { ${KEY_FIELDS} }
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
export const SET_PAYMENT_PROVIDER_CREDENTIALS_MUTATION = /* GraphQL */ `
|
|
31
|
+
mutation SetPaymentProviderKey($input: SetPaymentProviderCredentialsInput!) {
|
|
32
|
+
setPaymentProviderCredentials(input: $input) { ${KEY_FIELDS} }
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
export const TEST_PAYMENT_PROVIDER_CONNECTION_MUTATION = /* GraphQL */ `
|
|
36
|
+
mutation TestPaymentProviderKey($paymentMethodCode: String!) {
|
|
37
|
+
testPaymentProviderConnection(paymentMethodCode: $paymentMethodCode) {
|
|
38
|
+
ok
|
|
39
|
+
message
|
|
40
|
+
methods
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
const invalidInput = (message) => new ValidationError({
|
|
45
|
+
code: 'INVALID_PROVIDER_KEY_INPUT',
|
|
46
|
+
message,
|
|
47
|
+
status: 400,
|
|
48
|
+
service: 'vendure',
|
|
49
|
+
});
|
|
50
|
+
const requireCode = (value) => {
|
|
51
|
+
if (typeof value !== 'string' || value === '') {
|
|
52
|
+
throw invalidInput('paymentMethodCode must be the code of a payment method.');
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
55
|
+
};
|
|
56
|
+
const toKey = (wire) => ({
|
|
57
|
+
paymentMethodId: wire.paymentMethodId,
|
|
58
|
+
paymentMethodCode: wire.paymentMethodCode,
|
|
59
|
+
provider: wire.provider === 'mollie' || wire.provider === 'stripe' ? wire.provider : 'other',
|
|
60
|
+
enabled: wire.enabled,
|
|
61
|
+
hasApiKey: wire.hasApiKey,
|
|
62
|
+
maskedApiKey: wire.maskedApiKey ?? null,
|
|
63
|
+
hasWebhookSecret: wire.hasWebhookSecret,
|
|
64
|
+
webhookUrl: wire.webhookUrl,
|
|
65
|
+
redirectUrl: wire.redirectUrl ?? null,
|
|
66
|
+
credentialPath: wire.credentialPath === 'connect' ? 'connect' : 'api_key',
|
|
67
|
+
});
|
|
68
|
+
/** The input as the engine takes it; a field of the wrong type never leaves. */
|
|
69
|
+
function setInput(input) {
|
|
70
|
+
if (typeof input !== 'object' || input === null || Array.isArray(input)) {
|
|
71
|
+
throw invalidInput('A key change must be an object naming the payment method.');
|
|
72
|
+
}
|
|
73
|
+
const value = input;
|
|
74
|
+
const out = { paymentMethodCode: requireCode(value.paymentMethodCode) };
|
|
75
|
+
for (const name of ['apiKey', 'webhookSecret', 'redirectUrl']) {
|
|
76
|
+
const field = value[name];
|
|
77
|
+
if (field === undefined)
|
|
78
|
+
continue;
|
|
79
|
+
if (typeof field !== 'string')
|
|
80
|
+
throw invalidInput(`${name} must be a string.`);
|
|
81
|
+
out[name] = field;
|
|
82
|
+
}
|
|
83
|
+
if (value.enabled !== undefined) {
|
|
84
|
+
if (typeof value.enabled !== 'boolean')
|
|
85
|
+
throw invalidInput('enabled must be true or false.');
|
|
86
|
+
out.enabled = value.enabled;
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
export function createProviderKeysModule(transport) {
|
|
91
|
+
return {
|
|
92
|
+
async list(options) {
|
|
93
|
+
const items = (await fieldOf(transport, PAYMENT_PROVIDER_KEYS_QUERY, 'paymentProviderConnections', {}, options)).map(toKey);
|
|
94
|
+
// The engine answers every method at once: one complete page.
|
|
95
|
+
return createPage(items, { nextCursor: null, hasNext: false, total: items.length }, () => {
|
|
96
|
+
throw new Error('paymentProviderConnections returns a complete list; there is no next page');
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
async get(paymentMethodCode, options) {
|
|
100
|
+
const key = await fieldOf(transport, PAYMENT_PROVIDER_KEY_QUERY, 'paymentProviderConnection', { paymentMethodCode: requireCode(paymentMethodCode) }, options);
|
|
101
|
+
return key ? toKey(key) : null;
|
|
102
|
+
},
|
|
103
|
+
async create(provider, options) {
|
|
104
|
+
// Typed for TypeScript callers; checked for JavaScript ones and MCP tool arguments.
|
|
105
|
+
if (typeof provider !== 'string' || provider === '') {
|
|
106
|
+
throw invalidInput('provider must be `mollie` or `stripe`.');
|
|
107
|
+
}
|
|
108
|
+
return toKey(await fieldOf(transport, CREATE_PAYMENT_PROVIDER_MUTATION, 'createPaymentProvider', { provider }, options));
|
|
109
|
+
},
|
|
110
|
+
async set(input, options) {
|
|
111
|
+
return toKey(await fieldOf(transport, SET_PAYMENT_PROVIDER_CREDENTIALS_MUTATION, 'setPaymentProviderCredentials', { input: setInput(input) }, options));
|
|
112
|
+
},
|
|
113
|
+
async test(paymentMethodCode, options) {
|
|
114
|
+
const result = await fieldOf(transport, TEST_PAYMENT_PROVIDER_CONNECTION_MUTATION, 'testPaymentProviderConnection', { paymentMethodCode: requireCode(paymentMethodCode) }, options);
|
|
115
|
+
return { ok: result.ok, message: result.message, methods: result.methods ?? null };
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|