@colixsystems/widget-sdk 0.321.0 → 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 +10 -2
- package/dist/contract.cjs +3 -1
- package/dist/contract.js +3 -1
- package/dist/hooks.js +11 -1
- package/dist/index.d.ts +11 -5
- 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,15 @@ 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.
|
|
99
|
+
|
|
100
|
+
### What's new in 0.321.1 (contract 1.261.0)
|
|
101
|
+
|
|
102
|
+
**A refused plan purchase now says why.** Buying a plan with `useAccessPlans().purchase` is refused with `ALREADY_OWNED` when the user already holds it, and with `PURCHASE_IN_PROGRESS` when their earlier checkout for it is still open (it goes stale after about 15 minutes). Both were reported as retryable, so a widget that follows the usual pattern (show `err.message` only when `retryable` is `false`) showed a generic "did not go through" with a Try again button. They are now non-retryable, so `err.message` ("You already have this plan.", "A payment for this plan is already in progress.") is what the widget shows. Widgets already built to that pattern change without a rebuild.
|
|
95
103
|
|
|
96
104
|
### What's new in 0.321.0 (contract 1.261.0)
|
|
97
105
|
|
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/hooks.js
CHANGED
|
@@ -7077,8 +7077,11 @@ export function useIdentification(options) {
|
|
|
7077
7077
|
// sc-4650 — the refusals that retrying the SAME charge can never clear: the
|
|
7078
7078
|
// workspace, the widget manifest, or the amount has to change first. Everything
|
|
7079
7079
|
// else (a decline, a provider blip, an unknown failure) is worth another
|
|
7080
|
-
// attempt. A widget reads this through `PaymentError.retryable`.
|
|
7080
|
+
// attempt. A widget reads this through `PaymentError.retryable`. The two plan
|
|
7081
|
+
// refusals are here so a widget shows their reason: an immediate retry cannot
|
|
7082
|
+
// clear them (a plan the user already holds; another open checkout for it).
|
|
7081
7083
|
const NON_RETRYABLE_PAYMENT_CODES = new Set([
|
|
7084
|
+
"ALREADY_OWNED",
|
|
7082
7085
|
"AUTH_REQUIRED",
|
|
7083
7086
|
"AMOUNT_TOO_LARGE",
|
|
7084
7087
|
"BUSINESS_IDENTITY_REQUIRED",
|
|
@@ -7095,6 +7098,7 @@ const NON_RETRYABLE_PAYMENT_CODES = new Set([
|
|
|
7095
7098
|
"PAYMENTS_DISABLED",
|
|
7096
7099
|
"PAYMENTS_SCOPE_NOT_GRANTED",
|
|
7097
7100
|
"PAYMENTS_UNAVAILABLE",
|
|
7101
|
+
"PURCHASE_IN_PROGRESS",
|
|
7098
7102
|
"TRIAL_RESTRICTED",
|
|
7099
7103
|
"UNSUPPORTED_CURRENCY",
|
|
7100
7104
|
"VALIDATION",
|
|
@@ -7124,6 +7128,12 @@ const NON_RETRYABLE_PAYMENT_CODES = new Set([
|
|
|
7124
7128
|
* `order` is not one this user can pay for
|
|
7125
7129
|
* - "ORDER_PAYMENT_IN_PROGRESS" — another checkout for the order is open
|
|
7126
7130
|
* (retryable: it clears when that one ends)
|
|
7131
|
+
* - "ALREADY_OWNED" — `useAccessPlans().purchase` for a plan the
|
|
7132
|
+
* user already holds; show the message
|
|
7133
|
+
* - "PURCHASE_IN_PROGRESS" — `useAccessPlans().purchase` while the
|
|
7134
|
+
* user's earlier checkout for that plan is
|
|
7135
|
+
* still open (it goes stale after about 15
|
|
7136
|
+
* minutes); show the message, not a retry
|
|
7127
7137
|
* - "TRIAL_RESTRICTED" — a trial workspace takes no guest payments
|
|
7128
7138
|
* - "GUEST_CHECKOUT_LIMIT_REACHED" — the shop's guest budget is spent for now
|
|
7129
7139
|
* - "CAPTCHA_FAILED" / "CAPTCHA_UNAVAILABLE" — the guest's security check
|
package/dist/index.d.ts
CHANGED
|
@@ -1722,11 +1722,15 @@ export interface AppSubscriptionApi {
|
|
|
1722
1722
|
export function useAppSubscription(): AppSubscriptionApi;
|
|
1723
1723
|
|
|
1724
1724
|
/**
|
|
1725
|
-
* Rejection thrown by both `usePayments()` callbacks
|
|
1726
|
-
*
|
|
1727
|
-
* `
|
|
1728
|
-
*
|
|
1729
|
-
* "try again" that loops the payer
|
|
1725
|
+
* Rejection thrown by both `usePayments()` callbacks and by
|
|
1726
|
+
* `useAccessPlans().purchase`. `code` is the server's own reason when it sent
|
|
1727
|
+
* one; `message` is its user-safe sentence. Branch on `retryable`: false means
|
|
1728
|
+
* the same charge can never succeed until the workspace, the manifest, or the
|
|
1729
|
+
* amount changes — show the reason, not a "try again" that loops the payer
|
|
1730
|
+
* forever. Two plan refusals are also non-retryable so their reason shows:
|
|
1731
|
+
* `ALREADY_OWNED` (the user holds the plan) and `PURCHASE_IN_PROGRESS` (their
|
|
1732
|
+
* earlier checkout for the plan is still open; it goes stale after about 15
|
|
1733
|
+
* minutes).
|
|
1730
1734
|
*/
|
|
1731
1735
|
export class PaymentError extends Error {
|
|
1732
1736
|
code:
|
|
@@ -1746,6 +1750,8 @@ export class PaymentError extends Error {
|
|
|
1746
1750
|
| "ORDER_NOT_PAYABLE"
|
|
1747
1751
|
| "ORDER_ALREADY_PAID"
|
|
1748
1752
|
| "ORDER_PAYMENT_IN_PROGRESS"
|
|
1753
|
+
| "ALREADY_OWNED"
|
|
1754
|
+
| "PURCHASE_IN_PROGRESS"
|
|
1749
1755
|
| "TRIAL_RESTRICTED"
|
|
1750
1756
|
| "GUEST_CHECKOUT_LIMIT_REACHED"
|
|
1751
1757
|
| "CAPTCHA_FAILED"
|
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,
|