@colixsystems/widget-sdk 0.292.0 → 0.295.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 +10 -2
- package/dist/contract.cjs +88 -6
- package/dist/contract.js +88 -6
- package/dist/hooks.js +34 -26
- package/dist/index.d.ts +48 -1
- package/dist/index.js +1 -0
- package/dist/index.native.js +1 -0
- package/package.json +1 -1
- package/src/contract.js +88 -6
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ The data layer lives in **four separate domain-client packages**, each instantia
|
|
|
76
76
|
| **FILESTORE** (`ctx.filestore`) | `usePdfExport({ spaceType, folderId })` (optional: spaceType, folderId) | `{ openPdf, opening, canOpenPdf, exportToPdf, exporting, error, lastExported }` | `ctx.filestore.files.renderPdf` + `ctx.device.pdfViewer`, `ctx.filestore.files.exportPdf` — `files.write:*`. `openPdf(html, { fileName? })` renders the HTML to a PDF server-side and OPENS it (web: PDF tab; native: print / share sheet) without saving. `exportToPdf(html, { fileName?, folderId? })` renders it and saves it as a file (`application/pdf`). Same server-side renderer on web + native. |
|
|
77
77
|
| **PAYMENTS** (`ctx.payments`) | `useAccessPlans()` | `{ plans, loading, error, purchaseAvailable, purchase, cancel, refresh }` | `ctx.payments.{listAccessPlans,purchaseAccessPlan,cancelAccessPlan}` — `payments.charge:appUser`. Plans selling access to restricted pages; `purchase(planId)` names only the plan, the server sets price and group. `purchaseAvailable` is `false` in an iOS / Android build (digital goods need store billing): show a visible not-available state. |
|
|
78
78
|
| **PAYMENTS** (`ctx.payments`) | `useAppSubscription()` | `{ subscription, loading, error, cancel, refresh }` | `ctx.payments.{getAppSubscription,cancelAppSubscription}` — `payments.charge:appUser`. The signed-in user's subscription to a paid app (`{ active, renews, access_ends_at }`); `cancel()` stops it renewing, and access runs to `access_ends_at`. |
|
|
79
|
-
| **PAYMENTS** (`ctx.payments`) | `usePayments()` | `{ requestPayment, getPayment }` | `ctx.payments.*` — `payments.charge:appUser`. `requestPayment` requires `kind` (`"physical"` \| `"service"` \| `"digital"`): what is sold. A `"digital"` charge is refused in an iOS or Android build (`DIGITAL_SALE_NEEDS_STORE_BILLING`). Rejects with `PaymentError { code, message, retryable }`; when `retryable` is `false` show `message` and drop the retry. Charges are accepted ONLY in the currency the workspace sells in — omit `currency` and the platform applies it (a disagreeing literal is a publish-blocking `payment-currency` finding). |
|
|
79
|
+
| **PAYMENTS** (`ctx.payments`) | `usePayments()` | `{ requestPayment, getPayment, requestGuestPayment, getGuestPayment }` | `ctx.payments.*` — `payments.charge:appUser`; guest checkout (`requestGuestPayment`, a visitor with no account buying physical goods for an order they created) also `payments.charge:guest`. `requestPayment` requires `kind` (`"physical"` \| `"service"` \| `"digital"`): what is sold. A `"digital"` charge is refused in an iOS or Android build (`DIGITAL_SALE_NEEDS_STORE_BILLING`). Rejects with `PaymentError { code, message, retryable }`; when `retryable` is `false` show `message` and drop the retry. Charges are accepted ONLY in the currency the workspace sells in — omit `currency` and the platform applies it (a disagreeing literal is a publish-blocking `payment-currency` finding). |
|
|
80
80
|
| **NOTIFICATIONS** (`ctx.notifications`) | `useSendNotification()` | `{ send, sending, error }` | `ctx.notifications.send` — `notifications.send:appUser`. `send({ recipient_user_id, title, body, link?, payload? })` notifies one app user in the same workspace; call from an event handler (never render); rejects with `NotificationError`. |
|
|
81
81
|
| **NOTIFICATIONS** (`ctx.notifications`) | `useRecordMutes(tableId)` | `{ isMuted, loading, error, refetch }` | `ctx.notifications.mutes` — no scope. Which records of one table the signed-in user has muted, in one request for a whole list; `isMuted(recordId)` turns false when a timed mute lapses, and a `useRecordMute` write shows at once. |
|
|
82
82
|
| **NOTIFICATIONS** (`ctx.notifications`) | `useRecordMute(tableId, recordId)` | `{ muted, mutedUntil, loading, error, mute, unmute, refetch }` | `ctx.notifications.mutes` — no scope. Mutes one record's notifications for the signed-in user, `mute(until)` with an ISO time, a `Date`, or `null` for until unmuted. Needs read access to the record (`RECORD_NOT_FOUND` otherwise). |
|
|
@@ -90,7 +90,15 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
90
90
|
|
|
91
91
|
## Status
|
|
92
92
|
|
|
93
|
-
`v0.
|
|
93
|
+
`v0.295.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
|
|
94
|
+
|
|
95
|
+
### What's new in 0.295.0 (contract 1.242.0)
|
|
96
|
+
|
|
97
|
+
**Guest checkout: a visitor who is not signed in can pay for physical goods.** `usePayments()` gains `requestGuestPayment({ amount_cents, currency?, description, return_path?, order })` and `getGuestPayment(paymentId)`. There is no `kind`: a guest buys physical goods only, and the shipping address and contact live on the order. So `order` is required, and it must be a row the visitor created with `useDatastoreMutation().create` in the last 15 minutes, in a table with a payment-status column that the maker lets everyone add rows to (and nobody read). Only that visitor can pay for it. The host runs a security check, opens hosted Checkout as for `requestPayment`, and keeps the guest's one-time credential; `getGuestPayment(id)` reads the payment back with it, so a widget passes only the id. The widget also needs the `payments.charge:guest` scope, and the workspace must offer guest checkout. New `PaymentError` codes: `TRIAL_RESTRICTED` (non-retryable), and the retryable `GUEST_CHECKOUT_LIMIT_REACHED`, `CAPTCHA_FAILED` and `CAPTCHA_UNAVAILABLE`. The injected payments client gains `requestGuestPayment()` and `getGuestPayment()` (`@colixsystems/payments-client` 0.7.0). Additive.
|
|
98
|
+
|
|
99
|
+
### What's new in 0.293.0 (contract 1.240.0)
|
|
100
|
+
|
|
101
|
+
**Status colours follow the app's look.** `theme.colors.success`, `danger`, `warning` and `info` used to be the same four colours in every app, so a warm editorial palette showed a saturated green "Completed" chip and a bright blue "Booked" one. Each tone now keeps its hue family (green, red, amber, blue) but takes the app's accent saturation and lightness, stepped until it reads as text on the surface — and a dark palette derives its own lighter set. `<Badge>`, `<Banner>`, `<Progress>`, `<Stat>` deltas and toasts pick this up with no change on your side, and a badge's soft fill and label stay WCAG AA. A colour the workspace sets in the Alerts section of Design still wins. The derivation is `deriveStatusColors(primary, surface, onSurface)`, a host-side helper like `deriveAccentTints`; the four default literals are that derivation on the default palette, so an untouched theme renders as before.
|
|
94
102
|
|
|
95
103
|
### What's new in 0.292.0 (contract 1.239.0)
|
|
96
104
|
|
package/dist/contract.cjs
CHANGED
|
@@ -87,10 +87,13 @@ const DEFAULT_THEME_TOKENS = Object.freeze({
|
|
|
87
87
|
// background — so a dark theme gets a visible spinner with no new maths.
|
|
88
88
|
loader: "#475569",
|
|
89
89
|
border: "#e2e8f0",
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
// The four status tones are re-derived per tenant by `deriveStatusColors`
|
|
91
|
+
// (their hue families on the accent's saturation and lightness); these
|
|
92
|
+
// literals are that derivation applied to the default palette.
|
|
93
|
+
danger: "#e90b0b",
|
|
94
|
+
success: "#067e56",
|
|
95
|
+
warning: "#9b6507",
|
|
96
|
+
info: "#0877af",
|
|
94
97
|
}),
|
|
95
98
|
elevation: ELEVATION,
|
|
96
99
|
interaction: INTERACTION,
|
|
@@ -2425,6 +2428,10 @@ const HOOKS = [
|
|
|
2425
2428
|
"({ amount_cents, currency?, description, kind, return_path?, order? }) => Promise<{ id, status, order }> // kind is REQUIRED: \"physical\" | \"service\" | \"digital\" — what is sold; a digital charge is refused in an iOS/Android build (DIGITAL_SALE_NEEDS_STORE_BILLING); order: { table_id, record_id } — the order row this pays for, in a table with a payment-status column; the SERVER marks it paid when the payment settles, so never write \"paid\" yourself (refused: ORDER_NOT_FOUND, ORDER_NOT_PAYABLE, ORDER_ALREADY_PAID; ORDER_PAYMENT_IN_PROGRESS is retryable while another checkout for the order is open); host opens hosted Checkout; rejects with PaymentError { code, message, retryable } — render the message when retryable is false, never \"try again\"",
|
|
2426
2429
|
getPayment:
|
|
2427
2430
|
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // order: { table_id, record_id } | null — read it after returning from Checkout",
|
|
2431
|
+
requestGuestPayment:
|
|
2432
|
+
"({ amount_cents, currency?, description, return_path?, order }) => Promise<{ id, status, order }> // a visitor who is NOT signed in buys physical goods (no kind). order is REQUIRED: create the order row first with useDatastoreMutation().create (the maker lets everyone add rows to the orders table and nobody read them; collect the shipping address and contact there), then pay for it within 15 minutes — only the visitor who created it can. Needs the payments.charge:guest scope too. The host runs a security check and opens hosted Checkout. Refused: TRIAL_RESTRICTED, GUEST_CHECKOUT_LIMIT_REACHED (retryable), CAPTCHA_FAILED / CAPTCHA_UNAVAILABLE (retryable), NOT_FOUND where the shop does not offer guest checkout, plus the requestPayment refusals",
|
|
2433
|
+
getGuestPayment:
|
|
2434
|
+
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // a guest's status read; the host holds the guest's one-time credential, so pass only the id",
|
|
2428
2435
|
},
|
|
2429
2436
|
requiredContextSlice: ["payments.requestPayment"],
|
|
2430
2437
|
scopes: ["payments.charge:appUser"],
|
|
@@ -4528,11 +4535,13 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
4528
4535
|
},
|
|
4529
4536
|
payments: {
|
|
4530
4537
|
description:
|
|
4531
|
-
"Injected @colixsystems/payments-client instance (REQ-BILL-07-WIDGETPAY). { requestPayment(body) -> Promise<{ id, status }>, getPayment(id) -> Promise<payment>, listAccessPlans() -> Promise<{ data, meta }>, purchaseAccessPlan({ plan_id, return_path? }) -> Promise<{ plan_id, status }>, cancelAccessPlan(planId) -> Promise<{ plan_id, renews, access_ends_at }>, getAppSubscription() -> Promise<{ active, renews, access_ends_at }>, cancelAppSubscription() -> Promise<{ active, renews, access_ends_at }> }; wire is snake_case (amount_cents, return_path, order). Backs usePayments(), useAccessPlans() and useAppSubscription(); requires the payments.charge:appUser scope. The host opens hosted Checkout itself — same-tab on web, in-app browser on native (or auto-confirms under the mock provider); the charge settles to the workspace owner.",
|
|
4538
|
+
"Injected @colixsystems/payments-client instance (REQ-BILL-07-WIDGETPAY). { requestPayment(body) -> Promise<{ id, status }>, getPayment(id) -> Promise<payment>, requestGuestPayment(body) -> Promise<{ id, status }>, getGuestPayment(id) -> Promise<payment>, listAccessPlans() -> Promise<{ data, meta }>, purchaseAccessPlan({ plan_id, return_path? }) -> Promise<{ plan_id, status }>, cancelAccessPlan(planId) -> Promise<{ plan_id, renews, access_ends_at }>, getAppSubscription() -> Promise<{ active, renews, access_ends_at }>, cancelAppSubscription() -> Promise<{ active, renews, access_ends_at }> }; wire is snake_case (amount_cents, return_path, order). Backs usePayments(), useAccessPlans() and useAppSubscription(); requires the payments.charge:appUser scope, and guest checkout (requestGuestPayment, a visitor with no account buying physical goods) also payments.charge:guest. The host opens hosted Checkout itself — same-tab on web, in-app browser on native (or auto-confirms under the mock provider); the charge settles to the workspace owner.",
|
|
4532
4539
|
required: true,
|
|
4533
4540
|
fields: {
|
|
4534
4541
|
requestPayment: "function",
|
|
4535
4542
|
getPayment: "function",
|
|
4543
|
+
requestGuestPayment: "function",
|
|
4544
|
+
getGuestPayment: "function",
|
|
4536
4545
|
listAccessPlans: "function",
|
|
4537
4546
|
purchaseAccessPlan: "function",
|
|
4538
4547
|
cancelAccessPlan: "function",
|
|
@@ -6808,13 +6817,21 @@ const CONTRACT = deepFreeze({
|
|
|
6808
6817
|
// PaymentError codes.
|
|
6809
6818
|
// 1.237.0: widening — `manifest.translations` may declare up to 500 keys
|
|
6810
6819
|
// (was 200).
|
|
6820
|
+
// 1.239.0: additive — `deriveStatusColors`; the four status tokens follow the
|
|
6821
|
+
// palette, and their default literals are that derivation on the default.
|
|
6811
6822
|
// 1.238.0: additive (sc-15659) — `useConnector(connectorRef)` + the
|
|
6812
6823
|
// `connectors` host client + the `connectorRef` propertySchema type + the
|
|
6813
6824
|
// `connectors.call:*` scope. A widget calls a REST connector's listed operations.
|
|
6825
|
+
// 1.240.0: additive — `deriveStatusColors`; the four status tokens follow the
|
|
6826
|
+
// palette, and their default literals are that derivation on the default.
|
|
6814
6827
|
// 1.239.0: additive (sc-15658) — an app-triggered run must finish within 250 ms
|
|
6815
6828
|
// of the press; `useAction` errors carry the new code ACTION_TIMEOUT
|
|
6816
6829
|
// (504), whose outcome is unknown.
|
|
6817
|
-
|
|
6830
|
+
// 1.242.0: additive (sc-15359) — `usePayments()` gains
|
|
6831
|
+
// `requestGuestPayment` / `getGuestPayment` (a visitor with no account
|
|
6832
|
+
// pays for an order they created), the payments slice gains both, the
|
|
6833
|
+
// `payments.charge:guest` scope, and four new PaymentError codes.
|
|
6834
|
+
version: "1.242.0",
|
|
6818
6835
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6819
6836
|
hooks: HOOKS,
|
|
6820
6837
|
primitives: PRIMITIVES,
|
|
@@ -7051,6 +7068,70 @@ function deriveAccentTints(primary, surface, onSurface) {
|
|
|
7051
7068
|
};
|
|
7052
7069
|
}
|
|
7053
7070
|
|
|
7071
|
+
// The hue family each status tone keeps whatever the palette.
|
|
7072
|
+
const STATUS_HUES = Object.freeze({ success: 160, danger: 0, warning: 38, info: 200 });
|
|
7073
|
+
// Below this saturation a tone loses its hue, so a grey accent still reads as a colour.
|
|
7074
|
+
const STATUS_MIN_SATURATION = 0.35;
|
|
7075
|
+
// The lightness band a tone starts in, so a near-black or pastel accent keeps a visible hue.
|
|
7076
|
+
const STATUS_LIGHTNESS = Object.freeze({ min: 0.28, max: 0.62 });
|
|
7077
|
+
const STATUS_LIGHTNESS_STEP = 0.02;
|
|
7078
|
+
|
|
7079
|
+
/** `[hue 0-360, saturation 0-1, lightness 0-1]` of a hex colour. */
|
|
7080
|
+
function hexToHsl(hex) {
|
|
7081
|
+
const [r, g, b] = hexChannels(hex).map((v) => v / 255);
|
|
7082
|
+
const max = Math.max(r, g, b);
|
|
7083
|
+
const min = Math.min(r, g, b);
|
|
7084
|
+
const l = (max + min) / 2;
|
|
7085
|
+
if (max === min) return [0, 0, l];
|
|
7086
|
+
const d = max - min;
|
|
7087
|
+
const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
7088
|
+
let h;
|
|
7089
|
+
if (max === r) h = (g - b) / d + (g < b ? 6 : 0);
|
|
7090
|
+
else if (max === g) h = (b - r) / d + 2;
|
|
7091
|
+
else h = (r - g) / d + 4;
|
|
7092
|
+
return [h * 60, s, l];
|
|
7093
|
+
}
|
|
7094
|
+
|
|
7095
|
+
function hslToHex(h, s, l) {
|
|
7096
|
+
const k = (n) => (n + h / 30) % 12;
|
|
7097
|
+
const a = s * Math.min(l, 1 - l);
|
|
7098
|
+
const f = (n) => l - a * Math.max(-1, Math.min(k(n) - 3, 9 - k(n), 1));
|
|
7099
|
+
const hex = (v) => Math.round(v * 255).toString(16).padStart(2, "0");
|
|
7100
|
+
return `#${hex(f(0))}${hex(f(8))}${hex(f(4))}`;
|
|
7101
|
+
}
|
|
7102
|
+
|
|
7103
|
+
/**
|
|
7104
|
+
* Derive the four status colours from a resolved palette. Each tone keeps its
|
|
7105
|
+
* hue family (green, red, amber, blue) and takes the accent's saturation and
|
|
7106
|
+
* lightness, then is stepped toward `onSurface` until it clears WCAG AA against
|
|
7107
|
+
* the surface, so a status mark reads as text on every look, light or dark.
|
|
7108
|
+
* Returns `{ success, danger, warning, info }`, or `null` when the inputs
|
|
7109
|
+
* aren't usable hex, letting the caller keep the default tokens.
|
|
7110
|
+
*/
|
|
7111
|
+
function deriveStatusColors(primary, surface, onSurface) {
|
|
7112
|
+
if (!isHexColor(primary) || !isHexColor(surface) || !isHexColor(onSurface)) {
|
|
7113
|
+
return null;
|
|
7114
|
+
}
|
|
7115
|
+
const [, accentS, accentL] = hexToHsl(primary);
|
|
7116
|
+
const targetL = hexToHsl(onSurface)[2];
|
|
7117
|
+
const s = Math.max(accentS, STATUS_MIN_SATURATION);
|
|
7118
|
+
const out = {};
|
|
7119
|
+
for (const [tone, hue] of Object.entries(STATUS_HUES)) {
|
|
7120
|
+
let l = Math.min(STATUS_LIGHTNESS.max, Math.max(STATUS_LIGHTNESS.min, accentL));
|
|
7121
|
+
let color = hslToHex(hue, s, l);
|
|
7122
|
+
const step = targetL < l ? -STATUS_LIGHTNESS_STEP : STATUS_LIGHTNESS_STEP;
|
|
7123
|
+
while (
|
|
7124
|
+
contrastRatio(color, surface) < ACCENT_TEXT_MIN_CONTRAST &&
|
|
7125
|
+
Math.abs(targetL - l) > STATUS_LIGHTNESS_STEP
|
|
7126
|
+
) {
|
|
7127
|
+
l += step;
|
|
7128
|
+
color = hslToHex(hue, s, l);
|
|
7129
|
+
}
|
|
7130
|
+
out[tone] = color;
|
|
7131
|
+
}
|
|
7132
|
+
return out;
|
|
7133
|
+
}
|
|
7134
|
+
|
|
7054
7135
|
// REQ-THEME-SURFACE: how far a derived surface travels toward white, and the
|
|
7055
7136
|
// light-on-dark text pair a dark surface carries.
|
|
7056
7137
|
const SURFACE_LIFT = Object.freeze({ surface: 0.1, surfaceMuted: 0.05, border: 0.18 });
|
|
@@ -7248,6 +7329,7 @@ module.exports = {
|
|
|
7248
7329
|
contrastRatio,
|
|
7249
7330
|
readableTextColor,
|
|
7250
7331
|
deriveAccentTints,
|
|
7332
|
+
deriveStatusColors,
|
|
7251
7333
|
deriveSurfaceTokens,
|
|
7252
7334
|
inkForBackdrop,
|
|
7253
7335
|
INK_CONTRAST,
|
package/dist/contract.js
CHANGED
|
@@ -83,10 +83,13 @@ const DEFAULT_THEME_TOKENS = Object.freeze({
|
|
|
83
83
|
// background — so a dark theme gets a visible spinner with no new maths.
|
|
84
84
|
loader: "#475569",
|
|
85
85
|
border: "#e2e8f0",
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
// The four status tones are re-derived per tenant by `deriveStatusColors`
|
|
87
|
+
// (their hue families on the accent's saturation and lightness); these
|
|
88
|
+
// literals are that derivation applied to the default palette.
|
|
89
|
+
danger: "#e90b0b",
|
|
90
|
+
success: "#067e56",
|
|
91
|
+
warning: "#9b6507",
|
|
92
|
+
info: "#0877af",
|
|
90
93
|
}),
|
|
91
94
|
elevation: ELEVATION,
|
|
92
95
|
interaction: INTERACTION,
|
|
@@ -2421,6 +2424,10 @@ const HOOKS = [
|
|
|
2421
2424
|
"({ amount_cents, currency?, description, kind, return_path?, order? }) => Promise<{ id, status, order }> // kind is REQUIRED: \"physical\" | \"service\" | \"digital\" — what is sold; a digital charge is refused in an iOS/Android build (DIGITAL_SALE_NEEDS_STORE_BILLING); order: { table_id, record_id } — the order row this pays for, in a table with a payment-status column; the SERVER marks it paid when the payment settles, so never write \"paid\" yourself (refused: ORDER_NOT_FOUND, ORDER_NOT_PAYABLE, ORDER_ALREADY_PAID; ORDER_PAYMENT_IN_PROGRESS is retryable while another checkout for the order is open); host opens hosted Checkout; rejects with PaymentError { code, message, retryable } — render the message when retryable is false, never \"try again\"",
|
|
2422
2425
|
getPayment:
|
|
2423
2426
|
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // order: { table_id, record_id } | null — read it after returning from Checkout",
|
|
2427
|
+
requestGuestPayment:
|
|
2428
|
+
"({ amount_cents, currency?, description, return_path?, order }) => Promise<{ id, status, order }> // a visitor who is NOT signed in buys physical goods (no kind). order is REQUIRED: create the order row first with useDatastoreMutation().create (the maker lets everyone add rows to the orders table and nobody read them; collect the shipping address and contact there), then pay for it within 15 minutes — only the visitor who created it can. Needs the payments.charge:guest scope too. The host runs a security check and opens hosted Checkout. Refused: TRIAL_RESTRICTED, GUEST_CHECKOUT_LIMIT_REACHED (retryable), CAPTCHA_FAILED / CAPTCHA_UNAVAILABLE (retryable), NOT_FOUND where the shop does not offer guest checkout, plus the requestPayment refusals",
|
|
2429
|
+
getGuestPayment:
|
|
2430
|
+
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // a guest's status read; the host holds the guest's one-time credential, so pass only the id",
|
|
2424
2431
|
},
|
|
2425
2432
|
requiredContextSlice: ["payments.requestPayment"],
|
|
2426
2433
|
scopes: ["payments.charge:appUser"],
|
|
@@ -4524,11 +4531,13 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
4524
4531
|
},
|
|
4525
4532
|
payments: {
|
|
4526
4533
|
description:
|
|
4527
|
-
"Injected @colixsystems/payments-client instance (REQ-BILL-07-WIDGETPAY). { requestPayment(body) -> Promise<{ id, status }>, getPayment(id) -> Promise<payment>, listAccessPlans() -> Promise<{ data, meta }>, purchaseAccessPlan({ plan_id, return_path? }) -> Promise<{ plan_id, status }>, cancelAccessPlan(planId) -> Promise<{ plan_id, renews, access_ends_at }>, getAppSubscription() -> Promise<{ active, renews, access_ends_at }>, cancelAppSubscription() -> Promise<{ active, renews, access_ends_at }> }; wire is snake_case (amount_cents, return_path, order). Backs usePayments(), useAccessPlans() and useAppSubscription(); requires the payments.charge:appUser scope. The host opens hosted Checkout itself — same-tab on web, in-app browser on native (or auto-confirms under the mock provider); the charge settles to the workspace owner.",
|
|
4534
|
+
"Injected @colixsystems/payments-client instance (REQ-BILL-07-WIDGETPAY). { requestPayment(body) -> Promise<{ id, status }>, getPayment(id) -> Promise<payment>, requestGuestPayment(body) -> Promise<{ id, status }>, getGuestPayment(id) -> Promise<payment>, listAccessPlans() -> Promise<{ data, meta }>, purchaseAccessPlan({ plan_id, return_path? }) -> Promise<{ plan_id, status }>, cancelAccessPlan(planId) -> Promise<{ plan_id, renews, access_ends_at }>, getAppSubscription() -> Promise<{ active, renews, access_ends_at }>, cancelAppSubscription() -> Promise<{ active, renews, access_ends_at }> }; wire is snake_case (amount_cents, return_path, order). Backs usePayments(), useAccessPlans() and useAppSubscription(); requires the payments.charge:appUser scope, and guest checkout (requestGuestPayment, a visitor with no account buying physical goods) also payments.charge:guest. The host opens hosted Checkout itself — same-tab on web, in-app browser on native (or auto-confirms under the mock provider); the charge settles to the workspace owner.",
|
|
4528
4535
|
required: true,
|
|
4529
4536
|
fields: {
|
|
4530
4537
|
requestPayment: "function",
|
|
4531
4538
|
getPayment: "function",
|
|
4539
|
+
requestGuestPayment: "function",
|
|
4540
|
+
getGuestPayment: "function",
|
|
4532
4541
|
listAccessPlans: "function",
|
|
4533
4542
|
purchaseAccessPlan: "function",
|
|
4534
4543
|
cancelAccessPlan: "function",
|
|
@@ -6804,13 +6813,21 @@ const CONTRACT = deepFreeze({
|
|
|
6804
6813
|
// PaymentError codes.
|
|
6805
6814
|
// 1.237.0: widening — `manifest.translations` may declare up to 500 keys
|
|
6806
6815
|
// (was 200).
|
|
6816
|
+
// 1.239.0: additive — `deriveStatusColors`; the four status tokens follow the
|
|
6817
|
+
// palette, and their default literals are that derivation on the default.
|
|
6807
6818
|
// 1.238.0: additive (sc-15659) — `useConnector(connectorRef)` + the
|
|
6808
6819
|
// `connectors` host client + the `connectorRef` propertySchema type + the
|
|
6809
6820
|
// `connectors.call:*` scope. A widget calls a REST connector's listed operations.
|
|
6821
|
+
// 1.240.0: additive — `deriveStatusColors`; the four status tokens follow the
|
|
6822
|
+
// palette, and their default literals are that derivation on the default.
|
|
6810
6823
|
// 1.239.0: additive (sc-15658) — an app-triggered run must finish within 250 ms
|
|
6811
6824
|
// of the press; `useAction` errors carry the new code ACTION_TIMEOUT
|
|
6812
6825
|
// (504), whose outcome is unknown.
|
|
6813
|
-
|
|
6826
|
+
// 1.242.0: additive (sc-15359) — `usePayments()` gains
|
|
6827
|
+
// `requestGuestPayment` / `getGuestPayment` (a visitor with no account
|
|
6828
|
+
// pays for an order they created), the payments slice gains both, the
|
|
6829
|
+
// `payments.charge:guest` scope, and four new PaymentError codes.
|
|
6830
|
+
version: "1.242.0",
|
|
6814
6831
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6815
6832
|
hooks: HOOKS,
|
|
6816
6833
|
primitives: PRIMITIVES,
|
|
@@ -7047,6 +7064,70 @@ function deriveAccentTints(primary, surface, onSurface) {
|
|
|
7047
7064
|
};
|
|
7048
7065
|
}
|
|
7049
7066
|
|
|
7067
|
+
// The hue family each status tone keeps whatever the palette.
|
|
7068
|
+
const STATUS_HUES = Object.freeze({ success: 160, danger: 0, warning: 38, info: 200 });
|
|
7069
|
+
// Below this saturation a tone loses its hue, so a grey accent still reads as a colour.
|
|
7070
|
+
const STATUS_MIN_SATURATION = 0.35;
|
|
7071
|
+
// The lightness band a tone starts in, so a near-black or pastel accent keeps a visible hue.
|
|
7072
|
+
const STATUS_LIGHTNESS = Object.freeze({ min: 0.28, max: 0.62 });
|
|
7073
|
+
const STATUS_LIGHTNESS_STEP = 0.02;
|
|
7074
|
+
|
|
7075
|
+
/** `[hue 0-360, saturation 0-1, lightness 0-1]` of a hex colour. */
|
|
7076
|
+
function hexToHsl(hex) {
|
|
7077
|
+
const [r, g, b] = hexChannels(hex).map((v) => v / 255);
|
|
7078
|
+
const max = Math.max(r, g, b);
|
|
7079
|
+
const min = Math.min(r, g, b);
|
|
7080
|
+
const l = (max + min) / 2;
|
|
7081
|
+
if (max === min) return [0, 0, l];
|
|
7082
|
+
const d = max - min;
|
|
7083
|
+
const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
7084
|
+
let h;
|
|
7085
|
+
if (max === r) h = (g - b) / d + (g < b ? 6 : 0);
|
|
7086
|
+
else if (max === g) h = (b - r) / d + 2;
|
|
7087
|
+
else h = (r - g) / d + 4;
|
|
7088
|
+
return [h * 60, s, l];
|
|
7089
|
+
}
|
|
7090
|
+
|
|
7091
|
+
function hslToHex(h, s, l) {
|
|
7092
|
+
const k = (n) => (n + h / 30) % 12;
|
|
7093
|
+
const a = s * Math.min(l, 1 - l);
|
|
7094
|
+
const f = (n) => l - a * Math.max(-1, Math.min(k(n) - 3, 9 - k(n), 1));
|
|
7095
|
+
const hex = (v) => Math.round(v * 255).toString(16).padStart(2, "0");
|
|
7096
|
+
return `#${hex(f(0))}${hex(f(8))}${hex(f(4))}`;
|
|
7097
|
+
}
|
|
7098
|
+
|
|
7099
|
+
/**
|
|
7100
|
+
* Derive the four status colours from a resolved palette. Each tone keeps its
|
|
7101
|
+
* hue family (green, red, amber, blue) and takes the accent's saturation and
|
|
7102
|
+
* lightness, then is stepped toward `onSurface` until it clears WCAG AA against
|
|
7103
|
+
* the surface, so a status mark reads as text on every look, light or dark.
|
|
7104
|
+
* Returns `{ success, danger, warning, info }`, or `null` when the inputs
|
|
7105
|
+
* aren't usable hex, letting the caller keep the default tokens.
|
|
7106
|
+
*/
|
|
7107
|
+
function deriveStatusColors(primary, surface, onSurface) {
|
|
7108
|
+
if (!isHexColor(primary) || !isHexColor(surface) || !isHexColor(onSurface)) {
|
|
7109
|
+
return null;
|
|
7110
|
+
}
|
|
7111
|
+
const [, accentS, accentL] = hexToHsl(primary);
|
|
7112
|
+
const targetL = hexToHsl(onSurface)[2];
|
|
7113
|
+
const s = Math.max(accentS, STATUS_MIN_SATURATION);
|
|
7114
|
+
const out = {};
|
|
7115
|
+
for (const [tone, hue] of Object.entries(STATUS_HUES)) {
|
|
7116
|
+
let l = Math.min(STATUS_LIGHTNESS.max, Math.max(STATUS_LIGHTNESS.min, accentL));
|
|
7117
|
+
let color = hslToHex(hue, s, l);
|
|
7118
|
+
const step = targetL < l ? -STATUS_LIGHTNESS_STEP : STATUS_LIGHTNESS_STEP;
|
|
7119
|
+
while (
|
|
7120
|
+
contrastRatio(color, surface) < ACCENT_TEXT_MIN_CONTRAST &&
|
|
7121
|
+
Math.abs(targetL - l) > STATUS_LIGHTNESS_STEP
|
|
7122
|
+
) {
|
|
7123
|
+
l += step;
|
|
7124
|
+
color = hslToHex(hue, s, l);
|
|
7125
|
+
}
|
|
7126
|
+
out[tone] = color;
|
|
7127
|
+
}
|
|
7128
|
+
return out;
|
|
7129
|
+
}
|
|
7130
|
+
|
|
7050
7131
|
// REQ-THEME-SURFACE: how far a derived surface travels toward white, and the
|
|
7051
7132
|
// light-on-dark text pair a dark surface carries.
|
|
7052
7133
|
const SURFACE_LIFT = Object.freeze({ surface: 0.1, surfaceMuted: 0.05, border: 0.18 });
|
|
@@ -7244,6 +7325,7 @@ export {
|
|
|
7244
7325
|
contrastRatio,
|
|
7245
7326
|
readableTextColor,
|
|
7246
7327
|
deriveAccentTints,
|
|
7328
|
+
deriveStatusColors,
|
|
7247
7329
|
deriveSurfaceTokens,
|
|
7248
7330
|
inkForBackdrop,
|
|
7249
7331
|
INK_CONTRAST,
|
package/dist/hooks.js
CHANGED
|
@@ -7008,6 +7008,7 @@ const NON_RETRYABLE_PAYMENT_CODES = new Set([
|
|
|
7008
7008
|
"PAYMENTS_DISABLED",
|
|
7009
7009
|
"PAYMENTS_SCOPE_NOT_GRANTED",
|
|
7010
7010
|
"PAYMENTS_UNAVAILABLE",
|
|
7011
|
+
"TRIAL_RESTRICTED",
|
|
7011
7012
|
"UNSUPPORTED_CURRENCY",
|
|
7012
7013
|
"VALIDATION",
|
|
7013
7014
|
]);
|
|
@@ -7036,6 +7037,9 @@ const NON_RETRYABLE_PAYMENT_CODES = new Set([
|
|
|
7036
7037
|
* `order` is not one this user can pay for
|
|
7037
7038
|
* - "ORDER_PAYMENT_IN_PROGRESS" — another checkout for the order is open
|
|
7038
7039
|
* (retryable: it clears when that one ends)
|
|
7040
|
+
* - "TRIAL_RESTRICTED" — a trial workspace takes no guest payments
|
|
7041
|
+
* - "GUEST_CHECKOUT_LIMIT_REACHED" — the shop's guest budget is spent for now
|
|
7042
|
+
* - "CAPTCHA_FAILED" / "CAPTCHA_UNAVAILABLE" — the guest's security check
|
|
7039
7043
|
* - "CONNECT_NOT_READY" / "PAYMENTS_DISABLED" — provider not ready
|
|
7040
7044
|
* - "DECLINED" — the charge was declined
|
|
7041
7045
|
* - "INTERNAL" — anything else
|
|
@@ -7135,6 +7139,23 @@ function toPaymentError(err) {
|
|
|
7135
7139
|
* Mollie webhook may land a moment after the redirect; if it is still `PENDING`
|
|
7136
7140
|
* when you give up, show a "still processing" state rather than "paid".
|
|
7137
7141
|
*
|
|
7142
|
+
* GUEST CHECKOUT — a visitor who is NOT signed in buys physical goods:
|
|
7143
|
+
* requestGuestPayment({ amount_cents, currency?, description, return_path?,
|
|
7144
|
+
* order }) → Promise<{ id, status, order, ... }>. Create the order row
|
|
7145
|
+
* first with `useDatastoreMutation().create` (the maker gives everyone
|
|
7146
|
+
* permission to add rows to the orders table, and no permission to read
|
|
7147
|
+
* them), then pass its `{ table_id, record_id }` as `order` within 15
|
|
7148
|
+
* minutes — it is REQUIRED, and only the visitor who created it can pay for
|
|
7149
|
+
* it. Collect the shipping address and contact on that order row. There is
|
|
7150
|
+
* no `kind`: guest checkout sells physical goods only. The host runs a
|
|
7151
|
+
* security check and opens hosted Checkout exactly as for requestPayment.
|
|
7152
|
+
* getGuestPayment(paymentId) → Promise<payment> — the same read for a guest;
|
|
7153
|
+
* the host holds the guest's one-time credential, so pass only the id.
|
|
7154
|
+
* Requires the `payments.charge:guest` scope as well. Refusals beyond the
|
|
7155
|
+
* charge refusals: TRIAL_RESTRICTED, GUEST_CHECKOUT_LIMIT_REACHED (retryable),
|
|
7156
|
+
* CAPTCHA_FAILED / CAPTCHA_UNAVAILABLE (retryable), and NOT_FOUND where the
|
|
7157
|
+
* workspace does not offer guest checkout.
|
|
7158
|
+
*
|
|
7138
7159
|
* Requires the `payments.charge:appUser` scope in the manifest's
|
|
7139
7160
|
* `requestedScopes`. The charge settles to the workspace owner; the app user
|
|
7140
7161
|
* confirms the amount in hosted Checkout. No card data touches the widget —
|
|
@@ -7149,39 +7170,26 @@ export function usePayments() {
|
|
|
7149
7170
|
"workspace whose host supports payments.",
|
|
7150
7171
|
);
|
|
7151
7172
|
}
|
|
7152
|
-
const
|
|
7153
|
-
|
|
7154
|
-
typeof ctx.payments.getPayment === "function"
|
|
7155
|
-
? ctx.payments.getPayment
|
|
7156
|
-
: null,
|
|
7157
|
-
);
|
|
7158
|
-
requestRef.current = ctx.payments.requestPayment;
|
|
7159
|
-
getRef.current =
|
|
7160
|
-
typeof ctx.payments.getPayment === "function"
|
|
7161
|
-
? ctx.payments.getPayment
|
|
7162
|
-
: null;
|
|
7173
|
+
const paymentsRef = useRef(ctx.payments);
|
|
7174
|
+
paymentsRef.current = ctx.payments;
|
|
7163
7175
|
|
|
7164
|
-
|
|
7165
|
-
|
|
7166
|
-
|
|
7167
|
-
|
|
7168
|
-
throw
|
|
7169
|
-
}
|
|
7170
|
-
}, []);
|
|
7171
|
-
const getPayment = useCallback(async (paymentId) => {
|
|
7172
|
-
if (!getRef.current) {
|
|
7173
|
-
throw new PaymentError(
|
|
7174
|
-
"INTERNAL",
|
|
7175
|
-
"getPayment is not supported by this host.",
|
|
7176
|
-
);
|
|
7176
|
+
// Read the host's method at call time: the host may rebuild its slice.
|
|
7177
|
+
const call = useCallback(async (name, args) => {
|
|
7178
|
+
const method = paymentsRef.current[name];
|
|
7179
|
+
if (typeof method !== "function") {
|
|
7180
|
+
throw new PaymentError("INTERNAL", `${name} is not supported by this host.`);
|
|
7177
7181
|
}
|
|
7178
7182
|
try {
|
|
7179
|
-
return await
|
|
7183
|
+
return await method(...args);
|
|
7180
7184
|
} catch (err) {
|
|
7181
7185
|
throw toPaymentError(err);
|
|
7182
7186
|
}
|
|
7183
7187
|
}, []);
|
|
7184
|
-
|
|
7188
|
+
const requestPayment = useCallback((args) => call("requestPayment", [args]), [call]);
|
|
7189
|
+
const getPayment = useCallback((paymentId) => call("getPayment", [paymentId]), [call]);
|
|
7190
|
+
const requestGuestPayment = useCallback((args) => call("requestGuestPayment", [args]), [call]);
|
|
7191
|
+
const getGuestPayment = useCallback((paymentId) => call("getGuestPayment", [paymentId]), [call]);
|
|
7192
|
+
return { requestPayment, getPayment, requestGuestPayment, getGuestPayment };
|
|
7185
7193
|
}
|
|
7186
7194
|
|
|
7187
7195
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1569,9 +1569,34 @@ export interface PaymentResult {
|
|
|
1569
1569
|
order?: PaymentOrder | null;
|
|
1570
1570
|
}
|
|
1571
1571
|
|
|
1572
|
+
/**
|
|
1573
|
+
* A visitor who is not signed in paying for physical goods. There is no
|
|
1574
|
+
* `kind`: guest checkout sells physical goods only.
|
|
1575
|
+
*/
|
|
1576
|
+
export interface GuestPaymentRequest {
|
|
1577
|
+
amount_cents: number;
|
|
1578
|
+
currency?: string;
|
|
1579
|
+
description: string;
|
|
1580
|
+
return_path?: string;
|
|
1581
|
+
/**
|
|
1582
|
+
* Required. The order row the visitor created with
|
|
1583
|
+
* `useDatastoreMutation().create` in the last 15 minutes, in a table with a
|
|
1584
|
+
* payment-status column that everyone may add rows to. Collect the shipping
|
|
1585
|
+
* address and contact on it.
|
|
1586
|
+
*/
|
|
1587
|
+
order: PaymentOrder;
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1572
1590
|
export interface PaymentsApi {
|
|
1573
1591
|
requestPayment(args: PaymentRequest): Promise<PaymentResult>;
|
|
1574
1592
|
getPayment(paymentId: string): Promise<PaymentResult>;
|
|
1593
|
+
/**
|
|
1594
|
+
* Guest checkout. Requires the `payments.charge:guest` scope as well. The
|
|
1595
|
+
* host runs a security check and opens hosted Checkout.
|
|
1596
|
+
*/
|
|
1597
|
+
requestGuestPayment(args: GuestPaymentRequest): Promise<PaymentResult>;
|
|
1598
|
+
/** A guest's status read; the host holds their credential, so pass only the id. */
|
|
1599
|
+
getGuestPayment(paymentId: string): Promise<PaymentResult>;
|
|
1575
1600
|
}
|
|
1576
1601
|
|
|
1577
1602
|
/**
|
|
@@ -1581,7 +1606,8 @@ export interface PaymentsApi {
|
|
|
1581
1606
|
* redirect on web, the in-app browser on native) — you never open a URL and
|
|
1582
1607
|
* never collect card data. Confirm completion from server state (the webhook
|
|
1583
1608
|
* flips your record) or poll `getPayment(id)`. The charge settles to the
|
|
1584
|
-
* workspace owner.
|
|
1609
|
+
* workspace owner. A visitor who is not signed in pays with
|
|
1610
|
+
* `requestGuestPayment`, which also needs the `payments.charge:guest` scope.
|
|
1585
1611
|
*/
|
|
1586
1612
|
export function usePayments(): PaymentsApi;
|
|
1587
1613
|
|
|
@@ -1682,6 +1708,10 @@ export class PaymentError extends Error {
|
|
|
1682
1708
|
| "ORDER_NOT_PAYABLE"
|
|
1683
1709
|
| "ORDER_ALREADY_PAID"
|
|
1684
1710
|
| "ORDER_PAYMENT_IN_PROGRESS"
|
|
1711
|
+
| "TRIAL_RESTRICTED"
|
|
1712
|
+
| "GUEST_CHECKOUT_LIMIT_REACHED"
|
|
1713
|
+
| "CAPTCHA_FAILED"
|
|
1714
|
+
| "CAPTCHA_UNAVAILABLE"
|
|
1685
1715
|
| "PAYMENTS_DISABLED"
|
|
1686
1716
|
| "DECLINED"
|
|
1687
1717
|
| "FORBIDDEN"
|
|
@@ -6067,6 +6097,23 @@ export function deriveAccentTints(
|
|
|
6067
6097
|
primaryStrong: string;
|
|
6068
6098
|
} | null;
|
|
6069
6099
|
|
|
6100
|
+
/**
|
|
6101
|
+
* Derive the four status colours from a resolved palette: each keeps its hue
|
|
6102
|
+
* family and takes the accent's saturation and lightness, stepped toward
|
|
6103
|
+
* `onSurface` until it clears WCAG AA against the surface. `null` when the
|
|
6104
|
+
* inputs aren't hex.
|
|
6105
|
+
*/
|
|
6106
|
+
export function deriveStatusColors(
|
|
6107
|
+
primary: string,
|
|
6108
|
+
surface: string,
|
|
6109
|
+
onSurface: string,
|
|
6110
|
+
): {
|
|
6111
|
+
success: string;
|
|
6112
|
+
danger: string;
|
|
6113
|
+
warning: string;
|
|
6114
|
+
info: string;
|
|
6115
|
+
} | null;
|
|
6116
|
+
|
|
6070
6117
|
/**
|
|
6071
6118
|
* Map a CSS gradient angle (0 = to top, 90 = to right) to the `{ start, end }`
|
|
6072
6119
|
* unit vectors expo-linear-gradient expects.
|
package/dist/index.js
CHANGED
package/dist/index.native.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colixsystems/widget-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.295.0",
|
|
4
4
|
"description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
|
|
5
5
|
"homepage": "https://github.com/Colix-AB/AppStudio",
|
|
6
6
|
"type": "module",
|
package/src/contract.js
CHANGED
|
@@ -83,10 +83,13 @@ const DEFAULT_THEME_TOKENS = Object.freeze({
|
|
|
83
83
|
// background — so a dark theme gets a visible spinner with no new maths.
|
|
84
84
|
loader: "#475569",
|
|
85
85
|
border: "#e2e8f0",
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
// The four status tones are re-derived per tenant by `deriveStatusColors`
|
|
87
|
+
// (their hue families on the accent's saturation and lightness); these
|
|
88
|
+
// literals are that derivation applied to the default palette.
|
|
89
|
+
danger: "#e90b0b",
|
|
90
|
+
success: "#067e56",
|
|
91
|
+
warning: "#9b6507",
|
|
92
|
+
info: "#0877af",
|
|
90
93
|
}),
|
|
91
94
|
elevation: ELEVATION,
|
|
92
95
|
interaction: INTERACTION,
|
|
@@ -2421,6 +2424,10 @@ const HOOKS = [
|
|
|
2421
2424
|
"({ amount_cents, currency?, description, kind, return_path?, order? }) => Promise<{ id, status, order }> // kind is REQUIRED: \"physical\" | \"service\" | \"digital\" — what is sold; a digital charge is refused in an iOS/Android build (DIGITAL_SALE_NEEDS_STORE_BILLING); order: { table_id, record_id } — the order row this pays for, in a table with a payment-status column; the SERVER marks it paid when the payment settles, so never write \"paid\" yourself (refused: ORDER_NOT_FOUND, ORDER_NOT_PAYABLE, ORDER_ALREADY_PAID; ORDER_PAYMENT_IN_PROGRESS is retryable while another checkout for the order is open); host opens hosted Checkout; rejects with PaymentError { code, message, retryable } — render the message when retryable is false, never \"try again\"",
|
|
2422
2425
|
getPayment:
|
|
2423
2426
|
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // order: { table_id, record_id } | null — read it after returning from Checkout",
|
|
2427
|
+
requestGuestPayment:
|
|
2428
|
+
"({ amount_cents, currency?, description, return_path?, order }) => Promise<{ id, status, order }> // a visitor who is NOT signed in buys physical goods (no kind). order is REQUIRED: create the order row first with useDatastoreMutation().create (the maker lets everyone add rows to the orders table and nobody read them; collect the shipping address and contact there), then pay for it within 15 minutes — only the visitor who created it can. Needs the payments.charge:guest scope too. The host runs a security check and opens hosted Checkout. Refused: TRIAL_RESTRICTED, GUEST_CHECKOUT_LIMIT_REACHED (retryable), CAPTCHA_FAILED / CAPTCHA_UNAVAILABLE (retryable), NOT_FOUND where the shop does not offer guest checkout, plus the requestPayment refusals",
|
|
2429
|
+
getGuestPayment:
|
|
2430
|
+
"(paymentId) => Promise<{ id, status, amount_cents, currency, description, order }> // a guest's status read; the host holds the guest's one-time credential, so pass only the id",
|
|
2424
2431
|
},
|
|
2425
2432
|
requiredContextSlice: ["payments.requestPayment"],
|
|
2426
2433
|
scopes: ["payments.charge:appUser"],
|
|
@@ -4524,11 +4531,13 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
4524
4531
|
},
|
|
4525
4532
|
payments: {
|
|
4526
4533
|
description:
|
|
4527
|
-
"Injected @colixsystems/payments-client instance (REQ-BILL-07-WIDGETPAY). { requestPayment(body) -> Promise<{ id, status }>, getPayment(id) -> Promise<payment>, listAccessPlans() -> Promise<{ data, meta }>, purchaseAccessPlan({ plan_id, return_path? }) -> Promise<{ plan_id, status }>, cancelAccessPlan(planId) -> Promise<{ plan_id, renews, access_ends_at }>, getAppSubscription() -> Promise<{ active, renews, access_ends_at }>, cancelAppSubscription() -> Promise<{ active, renews, access_ends_at }> }; wire is snake_case (amount_cents, return_path, order). Backs usePayments(), useAccessPlans() and useAppSubscription(); requires the payments.charge:appUser scope. The host opens hosted Checkout itself — same-tab on web, in-app browser on native (or auto-confirms under the mock provider); the charge settles to the workspace owner.",
|
|
4534
|
+
"Injected @colixsystems/payments-client instance (REQ-BILL-07-WIDGETPAY). { requestPayment(body) -> Promise<{ id, status }>, getPayment(id) -> Promise<payment>, requestGuestPayment(body) -> Promise<{ id, status }>, getGuestPayment(id) -> Promise<payment>, listAccessPlans() -> Promise<{ data, meta }>, purchaseAccessPlan({ plan_id, return_path? }) -> Promise<{ plan_id, status }>, cancelAccessPlan(planId) -> Promise<{ plan_id, renews, access_ends_at }>, getAppSubscription() -> Promise<{ active, renews, access_ends_at }>, cancelAppSubscription() -> Promise<{ active, renews, access_ends_at }> }; wire is snake_case (amount_cents, return_path, order). Backs usePayments(), useAccessPlans() and useAppSubscription(); requires the payments.charge:appUser scope, and guest checkout (requestGuestPayment, a visitor with no account buying physical goods) also payments.charge:guest. The host opens hosted Checkout itself — same-tab on web, in-app browser on native (or auto-confirms under the mock provider); the charge settles to the workspace owner.",
|
|
4528
4535
|
required: true,
|
|
4529
4536
|
fields: {
|
|
4530
4537
|
requestPayment: "function",
|
|
4531
4538
|
getPayment: "function",
|
|
4539
|
+
requestGuestPayment: "function",
|
|
4540
|
+
getGuestPayment: "function",
|
|
4532
4541
|
listAccessPlans: "function",
|
|
4533
4542
|
purchaseAccessPlan: "function",
|
|
4534
4543
|
cancelAccessPlan: "function",
|
|
@@ -6804,13 +6813,21 @@ const CONTRACT = deepFreeze({
|
|
|
6804
6813
|
// PaymentError codes.
|
|
6805
6814
|
// 1.237.0: widening — `manifest.translations` may declare up to 500 keys
|
|
6806
6815
|
// (was 200).
|
|
6816
|
+
// 1.239.0: additive — `deriveStatusColors`; the four status tokens follow the
|
|
6817
|
+
// palette, and their default literals are that derivation on the default.
|
|
6807
6818
|
// 1.238.0: additive (sc-15659) — `useConnector(connectorRef)` + the
|
|
6808
6819
|
// `connectors` host client + the `connectorRef` propertySchema type + the
|
|
6809
6820
|
// `connectors.call:*` scope. A widget calls a REST connector's listed operations.
|
|
6821
|
+
// 1.240.0: additive — `deriveStatusColors`; the four status tokens follow the
|
|
6822
|
+
// palette, and their default literals are that derivation on the default.
|
|
6810
6823
|
// 1.239.0: additive (sc-15658) — an app-triggered run must finish within 250 ms
|
|
6811
6824
|
// of the press; `useAction` errors carry the new code ACTION_TIMEOUT
|
|
6812
6825
|
// (504), whose outcome is unknown.
|
|
6813
|
-
|
|
6826
|
+
// 1.242.0: additive (sc-15359) — `usePayments()` gains
|
|
6827
|
+
// `requestGuestPayment` / `getGuestPayment` (a visitor with no account
|
|
6828
|
+
// pays for an order they created), the payments slice gains both, the
|
|
6829
|
+
// `payments.charge:guest` scope, and four new PaymentError codes.
|
|
6830
|
+
version: "1.242.0",
|
|
6814
6831
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6815
6832
|
hooks: HOOKS,
|
|
6816
6833
|
primitives: PRIMITIVES,
|
|
@@ -7047,6 +7064,70 @@ function deriveAccentTints(primary, surface, onSurface) {
|
|
|
7047
7064
|
};
|
|
7048
7065
|
}
|
|
7049
7066
|
|
|
7067
|
+
// The hue family each status tone keeps whatever the palette.
|
|
7068
|
+
const STATUS_HUES = Object.freeze({ success: 160, danger: 0, warning: 38, info: 200 });
|
|
7069
|
+
// Below this saturation a tone loses its hue, so a grey accent still reads as a colour.
|
|
7070
|
+
const STATUS_MIN_SATURATION = 0.35;
|
|
7071
|
+
// The lightness band a tone starts in, so a near-black or pastel accent keeps a visible hue.
|
|
7072
|
+
const STATUS_LIGHTNESS = Object.freeze({ min: 0.28, max: 0.62 });
|
|
7073
|
+
const STATUS_LIGHTNESS_STEP = 0.02;
|
|
7074
|
+
|
|
7075
|
+
/** `[hue 0-360, saturation 0-1, lightness 0-1]` of a hex colour. */
|
|
7076
|
+
function hexToHsl(hex) {
|
|
7077
|
+
const [r, g, b] = hexChannels(hex).map((v) => v / 255);
|
|
7078
|
+
const max = Math.max(r, g, b);
|
|
7079
|
+
const min = Math.min(r, g, b);
|
|
7080
|
+
const l = (max + min) / 2;
|
|
7081
|
+
if (max === min) return [0, 0, l];
|
|
7082
|
+
const d = max - min;
|
|
7083
|
+
const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
7084
|
+
let h;
|
|
7085
|
+
if (max === r) h = (g - b) / d + (g < b ? 6 : 0);
|
|
7086
|
+
else if (max === g) h = (b - r) / d + 2;
|
|
7087
|
+
else h = (r - g) / d + 4;
|
|
7088
|
+
return [h * 60, s, l];
|
|
7089
|
+
}
|
|
7090
|
+
|
|
7091
|
+
function hslToHex(h, s, l) {
|
|
7092
|
+
const k = (n) => (n + h / 30) % 12;
|
|
7093
|
+
const a = s * Math.min(l, 1 - l);
|
|
7094
|
+
const f = (n) => l - a * Math.max(-1, Math.min(k(n) - 3, 9 - k(n), 1));
|
|
7095
|
+
const hex = (v) => Math.round(v * 255).toString(16).padStart(2, "0");
|
|
7096
|
+
return `#${hex(f(0))}${hex(f(8))}${hex(f(4))}`;
|
|
7097
|
+
}
|
|
7098
|
+
|
|
7099
|
+
/**
|
|
7100
|
+
* Derive the four status colours from a resolved palette. Each tone keeps its
|
|
7101
|
+
* hue family (green, red, amber, blue) and takes the accent's saturation and
|
|
7102
|
+
* lightness, then is stepped toward `onSurface` until it clears WCAG AA against
|
|
7103
|
+
* the surface, so a status mark reads as text on every look, light or dark.
|
|
7104
|
+
* Returns `{ success, danger, warning, info }`, or `null` when the inputs
|
|
7105
|
+
* aren't usable hex, letting the caller keep the default tokens.
|
|
7106
|
+
*/
|
|
7107
|
+
function deriveStatusColors(primary, surface, onSurface) {
|
|
7108
|
+
if (!isHexColor(primary) || !isHexColor(surface) || !isHexColor(onSurface)) {
|
|
7109
|
+
return null;
|
|
7110
|
+
}
|
|
7111
|
+
const [, accentS, accentL] = hexToHsl(primary);
|
|
7112
|
+
const targetL = hexToHsl(onSurface)[2];
|
|
7113
|
+
const s = Math.max(accentS, STATUS_MIN_SATURATION);
|
|
7114
|
+
const out = {};
|
|
7115
|
+
for (const [tone, hue] of Object.entries(STATUS_HUES)) {
|
|
7116
|
+
let l = Math.min(STATUS_LIGHTNESS.max, Math.max(STATUS_LIGHTNESS.min, accentL));
|
|
7117
|
+
let color = hslToHex(hue, s, l);
|
|
7118
|
+
const step = targetL < l ? -STATUS_LIGHTNESS_STEP : STATUS_LIGHTNESS_STEP;
|
|
7119
|
+
while (
|
|
7120
|
+
contrastRatio(color, surface) < ACCENT_TEXT_MIN_CONTRAST &&
|
|
7121
|
+
Math.abs(targetL - l) > STATUS_LIGHTNESS_STEP
|
|
7122
|
+
) {
|
|
7123
|
+
l += step;
|
|
7124
|
+
color = hslToHex(hue, s, l);
|
|
7125
|
+
}
|
|
7126
|
+
out[tone] = color;
|
|
7127
|
+
}
|
|
7128
|
+
return out;
|
|
7129
|
+
}
|
|
7130
|
+
|
|
7050
7131
|
// REQ-THEME-SURFACE: how far a derived surface travels toward white, and the
|
|
7051
7132
|
// light-on-dark text pair a dark surface carries.
|
|
7052
7133
|
const SURFACE_LIFT = Object.freeze({ surface: 0.1, surfaceMuted: 0.05, border: 0.18 });
|
|
@@ -7244,6 +7325,7 @@ export {
|
|
|
7244
7325
|
contrastRatio,
|
|
7245
7326
|
readableTextColor,
|
|
7246
7327
|
deriveAccentTints,
|
|
7328
|
+
deriveStatusColors,
|
|
7247
7329
|
deriveSurfaceTokens,
|
|
7248
7330
|
inkForBackdrop,
|
|
7249
7331
|
INK_CONTRAST,
|