@colixsystems/widget-sdk 0.321.1 → 0.322.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 +6 -2
- package/dist/contract.cjs +3 -1
- package/dist/contract.js +3 -1
- package/dist/linter.cjs +88 -0
- package/dist/linter.js +88 -0
- package/package.json +1 -1
- package/src/contract.js +3 -1
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ The data layer lives in **four separate domain-client packages**, each instantia
|
|
|
77
77
|
| **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. |
|
|
78
78
|
| **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. |
|
|
79
79
|
| **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`. |
|
|
80
|
-
| **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 call without it is a publish-blocking `payment-kind-required` finding. 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
|
+
| **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 call without it is a publish-blocking `payment-kind-required` finding. A `"digital"` charge is refused in an iOS or Android build (`DIGITAL_SALE_NEEDS_STORE_BILLING`). Selling an order (goods, a booking, a ticket)? Create its row first and pass `order: { table_id, record_id }`, in a table with a payment-status column: only the payment marks the order paid, so never write a paid status yourself (a `payment-status-written` finding). The server refuses an order it cannot settle with `ORDER_NOT_FOUND`, `ORDER_NOT_PAYABLE` or `ORDER_ALREADY_PAID`, none retryable. 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). |
|
|
81
81
|
| **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`. |
|
|
82
82
|
| **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. |
|
|
83
83
|
| **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). |
|
|
@@ -91,7 +91,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
91
91
|
|
|
92
92
|
## Status
|
|
93
93
|
|
|
94
|
-
`v0.
|
|
94
|
+
`v0.322.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**.
|
|
95
|
+
|
|
96
|
+
### What's new in 0.322.0 (contract 1.262.0)
|
|
97
|
+
|
|
98
|
+
**The linter warns when a charging widget marks an order paid itself.** Only the payment marks an order paid: pass `order: { table_id, record_id }` to `requestPayment` and the server writes the order's payment-status column when the payment settles. A widget that charges and then writes "paid" to a row lets any buyer who may edit that row mark it paid without paying. In a widget that calls `requestPayment` or `requestGuestPayment`, a `create` or `update` from `useDatastoreMutation` whose values carry `"paid"` (any case) or a `paid`, `isPaid`, `is_paid`, `paymentStatus` or `payment_status` key is now the `payment-status-written` warning. A value built away from the call is beyond the scan. The `usePayments()` hook row now names the `order` field and its refusals.
|
|
95
99
|
|
|
96
100
|
### What's new in 0.321.1 (contract 1.261.0)
|
|
97
101
|
|
package/dist/contract.cjs
CHANGED
|
@@ -7023,7 +7023,9 @@ const CONTRACT = deepFreeze({
|
|
|
7023
7023
|
// useIdentification / useFileSignature / useBankIdLink without rendering
|
|
7024
7024
|
// its qr (and, where it exists, the autoStartToken button) is the
|
|
7025
7025
|
// publish-blocking `bankid-order-not-shown` finding.
|
|
7026
|
-
|
|
7026
|
+
// 1.262.0: stricter lint (sc-16000) — a charging widget whose create or
|
|
7027
|
+
// update writes a paid status is the `payment-status-written` warning.
|
|
7028
|
+
version: "1.262.0",
|
|
7027
7029
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7028
7030
|
hooks: HOOKS,
|
|
7029
7031
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -7018,7 +7018,9 @@ const CONTRACT = deepFreeze({
|
|
|
7018
7018
|
// useIdentification / useFileSignature / useBankIdLink without rendering
|
|
7019
7019
|
// its qr (and, where it exists, the autoStartToken button) is the
|
|
7020
7020
|
// publish-blocking `bankid-order-not-shown` finding.
|
|
7021
|
-
|
|
7021
|
+
// 1.262.0: stricter lint (sc-16000) — a charging widget whose create or
|
|
7022
|
+
// update writes a paid status is the `payment-status-written` warning.
|
|
7023
|
+
version: "1.262.0",
|
|
7022
7024
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7023
7025
|
hooks: HOOKS,
|
|
7024
7026
|
primitives: PRIMITIVES,
|
package/dist/linter.cjs
CHANGED
|
@@ -1611,6 +1611,93 @@ function _paymentKindRules(source) {
|
|
|
1611
1611
|
return findings;
|
|
1612
1612
|
}
|
|
1613
1613
|
|
|
1614
|
+
// sc-16000 — payment-status-written.
|
|
1615
|
+
//
|
|
1616
|
+
// Only the server may mark an order paid: `requestPayment({ …, order })` names
|
|
1617
|
+
// the order, and the payment's settlement writes its payment-status column. A
|
|
1618
|
+
// charging widget that writes "paid" itself lets any buyer who may edit the
|
|
1619
|
+
// row mark it paid without paying. Reads the arguments of the widget's own
|
|
1620
|
+
// `create` / `update` calls for a paid value or a payment-status key. A
|
|
1621
|
+
// warning: the scan cannot see which column the workspace made the payment
|
|
1622
|
+
// status, nor a value built away from the call.
|
|
1623
|
+
const PAYMENT_CHARGE_CALL_RE = /(?<![\w$])request(?:Guest)?Payment\s*\(/;
|
|
1624
|
+
const _WRITE_VERBS = new Set(["create", "update"]);
|
|
1625
|
+
const _PAID_WRITE_RES = [
|
|
1626
|
+
/(?<![\w$])(['"]?)(?:payment_?status|is_?paid|paid)\1\s*:/gi,
|
|
1627
|
+
/:\s*(['"`])paid\1/gi,
|
|
1628
|
+
];
|
|
1629
|
+
|
|
1630
|
+
/** Local names the widget's create/update calls go through, and named mutation objects. */
|
|
1631
|
+
function _writeCallees(code) {
|
|
1632
|
+
const verbs = [];
|
|
1633
|
+
const objects = [];
|
|
1634
|
+
for (const call of _mutationHookCalls(code)) {
|
|
1635
|
+
if (!call.destructured) {
|
|
1636
|
+
objects.push(call.name);
|
|
1637
|
+
continue;
|
|
1638
|
+
}
|
|
1639
|
+
for (const entry of call.destructured.split(",")) {
|
|
1640
|
+
const [key, local] = entry.split(":").map((part) => part.trim());
|
|
1641
|
+
if (_WRITE_VERBS.has(key)) verbs.push(local || key);
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
return { verbs, objects };
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
/** Index of the parenthesis closing the one opening at `open`, or -1. */
|
|
1648
|
+
function _closingParen(masked, open) {
|
|
1649
|
+
let depth = 0;
|
|
1650
|
+
const end = Math.min(masked.length, open + PAYMENT_OPTIONS_MAX_CHARS);
|
|
1651
|
+
for (let i = open; i < end; i += 1) {
|
|
1652
|
+
if (_OPENERS.includes(masked[i])) depth += 1;
|
|
1653
|
+
if (_CLOSERS.includes(masked[i])) depth -= 1;
|
|
1654
|
+
if (depth === 0) return i;
|
|
1655
|
+
}
|
|
1656
|
+
return -1;
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
function _paymentStatusWrittenRules(source) {
|
|
1660
|
+
const masked = _stripNonCode(source);
|
|
1661
|
+
if (!PAYMENT_CHARGE_CALL_RE.test(masked)) return [];
|
|
1662
|
+
const { verbs, objects } = _writeCallees(masked);
|
|
1663
|
+
const escape = (name) => name.replace(/\$/g, "\\$");
|
|
1664
|
+
const callees = [
|
|
1665
|
+
...verbs.map((v) => `(?<![\\w$.])${escape(v)}`),
|
|
1666
|
+
...objects.map((o) => `(?<![\\w$])${escape(o)}\\s*\\.\\s*(?:create|update)`),
|
|
1667
|
+
];
|
|
1668
|
+
if (callees.length === 0) return [];
|
|
1669
|
+
const kept = _stripNonCode(source, { keepStrings: true });
|
|
1670
|
+
const sourceLines = source.split(/\r?\n/);
|
|
1671
|
+
const lineAt = _lineCounter(masked);
|
|
1672
|
+
const findings = [];
|
|
1673
|
+
const reported = new Set();
|
|
1674
|
+
for (const call of masked.matchAll(new RegExp(`(?:${callees.join("|")})\\s*\\(`, "g"))) {
|
|
1675
|
+
const open = call.index + call[0].length - 1;
|
|
1676
|
+
const close = _closingParen(masked, open);
|
|
1677
|
+
if (close === -1) continue;
|
|
1678
|
+
const args = kept.slice(open, close);
|
|
1679
|
+
for (const re of _PAID_WRITE_RES) {
|
|
1680
|
+
for (const hit of args.matchAll(re)) {
|
|
1681
|
+
const line = lineAt(open + hit.index);
|
|
1682
|
+
if (reported.has(line)) continue;
|
|
1683
|
+
reported.add(line);
|
|
1684
|
+
findings.push({
|
|
1685
|
+
rule: "payment-status-written",
|
|
1686
|
+
severity: "warning",
|
|
1687
|
+
label:
|
|
1688
|
+
`this charging widget writes a paid status itself, so a buyer ` +
|
|
1689
|
+
`who may edit the row can mark it paid without paying. Pass ` +
|
|
1690
|
+
`order: { table_id, record_id } to requestPayment: the server ` +
|
|
1691
|
+
`marks the order paid when the payment settles.`,
|
|
1692
|
+
line,
|
|
1693
|
+
snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
return findings;
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1614
1701
|
// sc-4686 — no-hardcoded-currency-label.
|
|
1615
1702
|
//
|
|
1616
1703
|
// The charge is safe once `currency` is omitted, but the DISPLAY is not: a "kr"
|
|
@@ -3560,6 +3647,7 @@ function lintSource(source, options) {
|
|
|
3560
3647
|
// sc-4650 — soft warning: every payment refusal reported as "try again".
|
|
3561
3648
|
findings.push(..._paymentCurrencyRules(source));
|
|
3562
3649
|
findings.push(..._paymentKindRules(source));
|
|
3650
|
+
findings.push(..._paymentStatusWrittenRules(source));
|
|
3563
3651
|
findings.push(..._hardcodedCurrencyLabelRules(source));
|
|
3564
3652
|
findings.push(..._paymentErrorHandlingRules(source));
|
|
3565
3653
|
findings.push(..._datastoreErrorHandlingRules(source));
|
package/dist/linter.js
CHANGED
|
@@ -1606,6 +1606,93 @@ function _paymentKindRules(source) {
|
|
|
1606
1606
|
return findings;
|
|
1607
1607
|
}
|
|
1608
1608
|
|
|
1609
|
+
// sc-16000 — payment-status-written.
|
|
1610
|
+
//
|
|
1611
|
+
// Only the server may mark an order paid: `requestPayment({ …, order })` names
|
|
1612
|
+
// the order, and the payment's settlement writes its payment-status column. A
|
|
1613
|
+
// charging widget that writes "paid" itself lets any buyer who may edit the
|
|
1614
|
+
// row mark it paid without paying. Reads the arguments of the widget's own
|
|
1615
|
+
// `create` / `update` calls for a paid value or a payment-status key. A
|
|
1616
|
+
// warning: the scan cannot see which column the workspace made the payment
|
|
1617
|
+
// status, nor a value built away from the call.
|
|
1618
|
+
const PAYMENT_CHARGE_CALL_RE = /(?<![\w$])request(?:Guest)?Payment\s*\(/;
|
|
1619
|
+
const _WRITE_VERBS = new Set(["create", "update"]);
|
|
1620
|
+
const _PAID_WRITE_RES = [
|
|
1621
|
+
/(?<![\w$])(['"]?)(?:payment_?status|is_?paid|paid)\1\s*:/gi,
|
|
1622
|
+
/:\s*(['"`])paid\1/gi,
|
|
1623
|
+
];
|
|
1624
|
+
|
|
1625
|
+
/** Local names the widget's create/update calls go through, and named mutation objects. */
|
|
1626
|
+
function _writeCallees(code) {
|
|
1627
|
+
const verbs = [];
|
|
1628
|
+
const objects = [];
|
|
1629
|
+
for (const call of _mutationHookCalls(code)) {
|
|
1630
|
+
if (!call.destructured) {
|
|
1631
|
+
objects.push(call.name);
|
|
1632
|
+
continue;
|
|
1633
|
+
}
|
|
1634
|
+
for (const entry of call.destructured.split(",")) {
|
|
1635
|
+
const [key, local] = entry.split(":").map((part) => part.trim());
|
|
1636
|
+
if (_WRITE_VERBS.has(key)) verbs.push(local || key);
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
return { verbs, objects };
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
/** Index of the parenthesis closing the one opening at `open`, or -1. */
|
|
1643
|
+
function _closingParen(masked, open) {
|
|
1644
|
+
let depth = 0;
|
|
1645
|
+
const end = Math.min(masked.length, open + PAYMENT_OPTIONS_MAX_CHARS);
|
|
1646
|
+
for (let i = open; i < end; i += 1) {
|
|
1647
|
+
if (_OPENERS.includes(masked[i])) depth += 1;
|
|
1648
|
+
if (_CLOSERS.includes(masked[i])) depth -= 1;
|
|
1649
|
+
if (depth === 0) return i;
|
|
1650
|
+
}
|
|
1651
|
+
return -1;
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
function _paymentStatusWrittenRules(source) {
|
|
1655
|
+
const masked = _stripNonCode(source);
|
|
1656
|
+
if (!PAYMENT_CHARGE_CALL_RE.test(masked)) return [];
|
|
1657
|
+
const { verbs, objects } = _writeCallees(masked);
|
|
1658
|
+
const escape = (name) => name.replace(/\$/g, "\\$");
|
|
1659
|
+
const callees = [
|
|
1660
|
+
...verbs.map((v) => `(?<![\\w$.])${escape(v)}`),
|
|
1661
|
+
...objects.map((o) => `(?<![\\w$])${escape(o)}\\s*\\.\\s*(?:create|update)`),
|
|
1662
|
+
];
|
|
1663
|
+
if (callees.length === 0) return [];
|
|
1664
|
+
const kept = _stripNonCode(source, { keepStrings: true });
|
|
1665
|
+
const sourceLines = source.split(/\r?\n/);
|
|
1666
|
+
const lineAt = _lineCounter(masked);
|
|
1667
|
+
const findings = [];
|
|
1668
|
+
const reported = new Set();
|
|
1669
|
+
for (const call of masked.matchAll(new RegExp(`(?:${callees.join("|")})\\s*\\(`, "g"))) {
|
|
1670
|
+
const open = call.index + call[0].length - 1;
|
|
1671
|
+
const close = _closingParen(masked, open);
|
|
1672
|
+
if (close === -1) continue;
|
|
1673
|
+
const args = kept.slice(open, close);
|
|
1674
|
+
for (const re of _PAID_WRITE_RES) {
|
|
1675
|
+
for (const hit of args.matchAll(re)) {
|
|
1676
|
+
const line = lineAt(open + hit.index);
|
|
1677
|
+
if (reported.has(line)) continue;
|
|
1678
|
+
reported.add(line);
|
|
1679
|
+
findings.push({
|
|
1680
|
+
rule: "payment-status-written",
|
|
1681
|
+
severity: "warning",
|
|
1682
|
+
label:
|
|
1683
|
+
`this charging widget writes a paid status itself, so a buyer ` +
|
|
1684
|
+
`who may edit the row can mark it paid without paying. Pass ` +
|
|
1685
|
+
`order: { table_id, record_id } to requestPayment: the server ` +
|
|
1686
|
+
`marks the order paid when the payment settles.`,
|
|
1687
|
+
line,
|
|
1688
|
+
snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
|
|
1689
|
+
});
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
return findings;
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1609
1696
|
// sc-4686 — no-hardcoded-currency-label.
|
|
1610
1697
|
//
|
|
1611
1698
|
// The charge is safe once `currency` is omitted, but the DISPLAY is not: a "kr"
|
|
@@ -3555,6 +3642,7 @@ export function lintSource(source, options) {
|
|
|
3555
3642
|
// sc-4650 — soft warning: every payment refusal reported as "try again".
|
|
3556
3643
|
findings.push(..._paymentCurrencyRules(source));
|
|
3557
3644
|
findings.push(..._paymentKindRules(source));
|
|
3645
|
+
findings.push(..._paymentStatusWrittenRules(source));
|
|
3558
3646
|
findings.push(..._hardcodedCurrencyLabelRules(source));
|
|
3559
3647
|
findings.push(..._paymentErrorHandlingRules(source));
|
|
3560
3648
|
findings.push(..._datastoreErrorHandlingRules(source));
|
package/package.json
CHANGED
package/src/contract.js
CHANGED
|
@@ -7018,7 +7018,9 @@ const CONTRACT = deepFreeze({
|
|
|
7018
7018
|
// useIdentification / useFileSignature / useBankIdLink without rendering
|
|
7019
7019
|
// its qr (and, where it exists, the autoStartToken button) is the
|
|
7020
7020
|
// publish-blocking `bankid-order-not-shown` finding.
|
|
7021
|
-
|
|
7021
|
+
// 1.262.0: stricter lint (sc-16000) — a charging widget whose create or
|
|
7022
|
+
// update writes a paid status is the `payment-status-written` warning.
|
|
7023
|
+
version: "1.262.0",
|
|
7022
7024
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7023
7025
|
hooks: HOOKS,
|
|
7024
7026
|
primitives: PRIMITIVES,
|