@colixsystems/widget-sdk 0.321.1 → 0.323.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 +5 -1
- package/dist/contract.js +5 -1
- package/dist/linter.cjs +131 -0
- package/dist/linter.js +131 -0
- package/package.json +1 -1
- package/src/contract.js +5 -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.323.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.323.0 (contract 1.263.0)
|
|
97
|
+
|
|
98
|
+
**The linter refuses a setting that takes group ids as typed text.** A maker cannot see which groups a pasted id names, and Copy Workspace swaps a group id only when the setting holds exactly that id, so a list of ids in one string still points at the old workspace's groups after a copy. A `propertySchema` field of type `string` (or an array of strings), at the top level or inside an object or an array item, whose name contains `group` (not a display-text name such as `groupLabel` / `groupTitle`, nor `groupBy`), or whose label or description pairs group with id, uuid, list or comma wording, is now the publish-blocking `group-ids-as-text` finding, in a widget that works with the app's user groups (its source reads `groupIds`, as in `useUser().groupIds`, or calls `useGroups(`). Declare `{ type: "groupRef", label }` for one group, or `{ type: "array", label, items: { type: "groupRef", label } }` for several: the Studio renders a group picker per item, and the widget receives the id or an array of ids. Settings saved before the change still hold the old comma-separated string, so read both forms (split a string on commas), and the maker re-picks the groups in the Studio. Widgets already published keep working; the check runs on their next submit.
|
|
99
|
+
|
|
100
|
+
### What's new in 0.322.0 (contract 1.262.0)
|
|
101
|
+
|
|
102
|
+
**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
103
|
|
|
96
104
|
### What's new in 0.321.1 (contract 1.261.0)
|
|
97
105
|
|
package/dist/contract.cjs
CHANGED
|
@@ -7023,7 +7023,11 @@ 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
|
+
// 1.263.0: stricter lint — in a widget reading groupIds or useGroups(), a
|
|
7029
|
+
// propertySchema text field holding group ids is `group-ids-as-text`.
|
|
7030
|
+
version: "1.263.0",
|
|
7027
7031
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7028
7032
|
hooks: HOOKS,
|
|
7029
7033
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -7018,7 +7018,11 @@ 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
|
+
// 1.263.0: stricter lint — in a widget reading groupIds or useGroups(), a
|
|
7024
|
+
// propertySchema text field holding group ids is `group-ids-as-text`.
|
|
7025
|
+
version: "1.263.0",
|
|
7022
7026
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7023
7027
|
hooks: HOOKS,
|
|
7024
7028
|
primitives: PRIMITIVES,
|
package/dist/linter.cjs
CHANGED
|
@@ -1035,6 +1035,48 @@ function _manifestActionRules(manifest) {
|
|
|
1035
1035
|
return findings;
|
|
1036
1036
|
}
|
|
1037
1037
|
|
|
1038
|
+
// Typed group ids hide the groups and break on Copy Workspace.
|
|
1039
|
+
const READS_USER_GROUPS = /\bgroupIds\b|\buseGroups\s*\(/;
|
|
1040
|
+
const GROUP_WORD = /group|grupp/i;
|
|
1041
|
+
const ID_LIST_WORDING = /\b(?:ids?|uuids?|list)\b|comma|komma/i;
|
|
1042
|
+
const NOT_A_GROUP_REF_NAME = /group(?:by|ing|ed)|(?:label|title|heading|header|caption|text)$/i;
|
|
1043
|
+
|
|
1044
|
+
function _holdsGroupIds(name, def) {
|
|
1045
|
+
if (GROUP_WORD.test(name) && !NOT_A_GROUP_REF_NAME.test(name)) return true;
|
|
1046
|
+
const wording = `${def.label ?? ""} ${def.description ?? ""}`;
|
|
1047
|
+
return GROUP_WORD.test(wording) && ID_LIST_WORDING.test(wording);
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
function _groupIdTextFields(schema, prefix, out) {
|
|
1051
|
+
if (!schema || typeof schema !== "object") return out;
|
|
1052
|
+
for (const [name, def] of Object.entries(schema)) {
|
|
1053
|
+
if (!def || typeof def !== "object") continue;
|
|
1054
|
+
const path = prefix + name;
|
|
1055
|
+
const items = def.items && typeof def.items === "object" ? def.items : null;
|
|
1056
|
+
const isText = def.type === "string" || (def.type === "array" && items !== null && items.type === "string");
|
|
1057
|
+
if (isText && _holdsGroupIds(name, def)) out.push(path);
|
|
1058
|
+
if (def.type === "object") _groupIdTextFields(def.properties, `${path}.`, out);
|
|
1059
|
+
if (items !== null && items.type === "object") _groupIdTextFields(items.properties, `${path}[].`, out);
|
|
1060
|
+
}
|
|
1061
|
+
return out;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
function _groupIdTextRules(source, manifest) {
|
|
1065
|
+
if (!manifest || typeof manifest !== "object") return [];
|
|
1066
|
+
if (!READS_USER_GROUPS.test(_stripNonCode(source))) return [];
|
|
1067
|
+
return _groupIdTextFields(manifest.propertySchema, "", []).map((path) => ({
|
|
1068
|
+
rule: "group-ids-as-text",
|
|
1069
|
+
severity: "error",
|
|
1070
|
+
label:
|
|
1071
|
+
`propertySchema.${path} takes the app's user groups as typed text: makers cannot see which groups they chose, ` +
|
|
1072
|
+
"and a workspace copy cannot carry them over. Declare { type: \"groupRef\", label } for one group, or " +
|
|
1073
|
+
"{ type: \"array\", label, items: { type: \"groupRef\", label } } for several. Saved settings keep the old text, " +
|
|
1074
|
+
"so read both forms (split a string on commas); the maker re-picks the groups in the Studio.",
|
|
1075
|
+
line: 0,
|
|
1076
|
+
snippet: "",
|
|
1077
|
+
}));
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1038
1080
|
// sc-1366 — invalid lucide icon import gate. lucide-react-native is a vetted
|
|
1039
1081
|
// import that the bundler EXTERNALISES, so esbuild never checks the named
|
|
1040
1082
|
// imports; a name that does not exist in the pinned version (`House` was added
|
|
@@ -1611,6 +1653,93 @@ function _paymentKindRules(source) {
|
|
|
1611
1653
|
return findings;
|
|
1612
1654
|
}
|
|
1613
1655
|
|
|
1656
|
+
// sc-16000 — payment-status-written.
|
|
1657
|
+
//
|
|
1658
|
+
// Only the server may mark an order paid: `requestPayment({ …, order })` names
|
|
1659
|
+
// the order, and the payment's settlement writes its payment-status column. A
|
|
1660
|
+
// charging widget that writes "paid" itself lets any buyer who may edit the
|
|
1661
|
+
// row mark it paid without paying. Reads the arguments of the widget's own
|
|
1662
|
+
// `create` / `update` calls for a paid value or a payment-status key. A
|
|
1663
|
+
// warning: the scan cannot see which column the workspace made the payment
|
|
1664
|
+
// status, nor a value built away from the call.
|
|
1665
|
+
const PAYMENT_CHARGE_CALL_RE = /(?<![\w$])request(?:Guest)?Payment\s*\(/;
|
|
1666
|
+
const _WRITE_VERBS = new Set(["create", "update"]);
|
|
1667
|
+
const _PAID_WRITE_RES = [
|
|
1668
|
+
/(?<![\w$])(['"]?)(?:payment_?status|is_?paid|paid)\1\s*:/gi,
|
|
1669
|
+
/:\s*(['"`])paid\1/gi,
|
|
1670
|
+
];
|
|
1671
|
+
|
|
1672
|
+
/** Local names the widget's create/update calls go through, and named mutation objects. */
|
|
1673
|
+
function _writeCallees(code) {
|
|
1674
|
+
const verbs = [];
|
|
1675
|
+
const objects = [];
|
|
1676
|
+
for (const call of _mutationHookCalls(code)) {
|
|
1677
|
+
if (!call.destructured) {
|
|
1678
|
+
objects.push(call.name);
|
|
1679
|
+
continue;
|
|
1680
|
+
}
|
|
1681
|
+
for (const entry of call.destructured.split(",")) {
|
|
1682
|
+
const [key, local] = entry.split(":").map((part) => part.trim());
|
|
1683
|
+
if (_WRITE_VERBS.has(key)) verbs.push(local || key);
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
return { verbs, objects };
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
/** Index of the parenthesis closing the one opening at `open`, or -1. */
|
|
1690
|
+
function _closingParen(masked, open) {
|
|
1691
|
+
let depth = 0;
|
|
1692
|
+
const end = Math.min(masked.length, open + PAYMENT_OPTIONS_MAX_CHARS);
|
|
1693
|
+
for (let i = open; i < end; i += 1) {
|
|
1694
|
+
if (_OPENERS.includes(masked[i])) depth += 1;
|
|
1695
|
+
if (_CLOSERS.includes(masked[i])) depth -= 1;
|
|
1696
|
+
if (depth === 0) return i;
|
|
1697
|
+
}
|
|
1698
|
+
return -1;
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
function _paymentStatusWrittenRules(source) {
|
|
1702
|
+
const masked = _stripNonCode(source);
|
|
1703
|
+
if (!PAYMENT_CHARGE_CALL_RE.test(masked)) return [];
|
|
1704
|
+
const { verbs, objects } = _writeCallees(masked);
|
|
1705
|
+
const escape = (name) => name.replace(/\$/g, "\\$");
|
|
1706
|
+
const callees = [
|
|
1707
|
+
...verbs.map((v) => `(?<![\\w$.])${escape(v)}`),
|
|
1708
|
+
...objects.map((o) => `(?<![\\w$])${escape(o)}\\s*\\.\\s*(?:create|update)`),
|
|
1709
|
+
];
|
|
1710
|
+
if (callees.length === 0) return [];
|
|
1711
|
+
const kept = _stripNonCode(source, { keepStrings: true });
|
|
1712
|
+
const sourceLines = source.split(/\r?\n/);
|
|
1713
|
+
const lineAt = _lineCounter(masked);
|
|
1714
|
+
const findings = [];
|
|
1715
|
+
const reported = new Set();
|
|
1716
|
+
for (const call of masked.matchAll(new RegExp(`(?:${callees.join("|")})\\s*\\(`, "g"))) {
|
|
1717
|
+
const open = call.index + call[0].length - 1;
|
|
1718
|
+
const close = _closingParen(masked, open);
|
|
1719
|
+
if (close === -1) continue;
|
|
1720
|
+
const args = kept.slice(open, close);
|
|
1721
|
+
for (const re of _PAID_WRITE_RES) {
|
|
1722
|
+
for (const hit of args.matchAll(re)) {
|
|
1723
|
+
const line = lineAt(open + hit.index);
|
|
1724
|
+
if (reported.has(line)) continue;
|
|
1725
|
+
reported.add(line);
|
|
1726
|
+
findings.push({
|
|
1727
|
+
rule: "payment-status-written",
|
|
1728
|
+
severity: "warning",
|
|
1729
|
+
label:
|
|
1730
|
+
`this charging widget writes a paid status itself, so a buyer ` +
|
|
1731
|
+
`who may edit the row can mark it paid without paying. Pass ` +
|
|
1732
|
+
`order: { table_id, record_id } to requestPayment: the server ` +
|
|
1733
|
+
`marks the order paid when the payment settles.`,
|
|
1734
|
+
line,
|
|
1735
|
+
snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
|
|
1736
|
+
});
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
return findings;
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1614
1743
|
// sc-4686 — no-hardcoded-currency-label.
|
|
1615
1744
|
//
|
|
1616
1745
|
// The charge is safe once `currency` is omitted, but the DISPLAY is not: a "kr"
|
|
@@ -3560,6 +3689,7 @@ function lintSource(source, options) {
|
|
|
3560
3689
|
// sc-4650 — soft warning: every payment refusal reported as "try again".
|
|
3561
3690
|
findings.push(..._paymentCurrencyRules(source));
|
|
3562
3691
|
findings.push(..._paymentKindRules(source));
|
|
3692
|
+
findings.push(..._paymentStatusWrittenRules(source));
|
|
3563
3693
|
findings.push(..._hardcodedCurrencyLabelRules(source));
|
|
3564
3694
|
findings.push(..._paymentErrorHandlingRules(source));
|
|
3565
3695
|
findings.push(..._datastoreErrorHandlingRules(source));
|
|
@@ -3581,6 +3711,7 @@ function lintSource(source, options) {
|
|
|
3581
3711
|
);
|
|
3582
3712
|
// REQ-WIDGET-ACTION — structural validation of manifest-declared actions.
|
|
3583
3713
|
findings.push(..._manifestActionRules(options && options.manifest));
|
|
3714
|
+
findings.push(..._groupIdTextRules(source, options && options.manifest));
|
|
3584
3715
|
findings.push(..._badgeCounterRules(source, options && options.manifest));
|
|
3585
3716
|
const hasErrors = findings.some((f) => f.severity !== "warning");
|
|
3586
3717
|
return { ok: !hasErrors, findings };
|
package/dist/linter.js
CHANGED
|
@@ -1030,6 +1030,48 @@ function _manifestActionRules(manifest) {
|
|
|
1030
1030
|
return findings;
|
|
1031
1031
|
}
|
|
1032
1032
|
|
|
1033
|
+
// Typed group ids hide the groups and break on Copy Workspace.
|
|
1034
|
+
const READS_USER_GROUPS = /\bgroupIds\b|\buseGroups\s*\(/;
|
|
1035
|
+
const GROUP_WORD = /group|grupp/i;
|
|
1036
|
+
const ID_LIST_WORDING = /\b(?:ids?|uuids?|list)\b|comma|komma/i;
|
|
1037
|
+
const NOT_A_GROUP_REF_NAME = /group(?:by|ing|ed)|(?:label|title|heading|header|caption|text)$/i;
|
|
1038
|
+
|
|
1039
|
+
function _holdsGroupIds(name, def) {
|
|
1040
|
+
if (GROUP_WORD.test(name) && !NOT_A_GROUP_REF_NAME.test(name)) return true;
|
|
1041
|
+
const wording = `${def.label ?? ""} ${def.description ?? ""}`;
|
|
1042
|
+
return GROUP_WORD.test(wording) && ID_LIST_WORDING.test(wording);
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
function _groupIdTextFields(schema, prefix, out) {
|
|
1046
|
+
if (!schema || typeof schema !== "object") return out;
|
|
1047
|
+
for (const [name, def] of Object.entries(schema)) {
|
|
1048
|
+
if (!def || typeof def !== "object") continue;
|
|
1049
|
+
const path = prefix + name;
|
|
1050
|
+
const items = def.items && typeof def.items === "object" ? def.items : null;
|
|
1051
|
+
const isText = def.type === "string" || (def.type === "array" && items !== null && items.type === "string");
|
|
1052
|
+
if (isText && _holdsGroupIds(name, def)) out.push(path);
|
|
1053
|
+
if (def.type === "object") _groupIdTextFields(def.properties, `${path}.`, out);
|
|
1054
|
+
if (items !== null && items.type === "object") _groupIdTextFields(items.properties, `${path}[].`, out);
|
|
1055
|
+
}
|
|
1056
|
+
return out;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
function _groupIdTextRules(source, manifest) {
|
|
1060
|
+
if (!manifest || typeof manifest !== "object") return [];
|
|
1061
|
+
if (!READS_USER_GROUPS.test(_stripNonCode(source))) return [];
|
|
1062
|
+
return _groupIdTextFields(manifest.propertySchema, "", []).map((path) => ({
|
|
1063
|
+
rule: "group-ids-as-text",
|
|
1064
|
+
severity: "error",
|
|
1065
|
+
label:
|
|
1066
|
+
`propertySchema.${path} takes the app's user groups as typed text: makers cannot see which groups they chose, ` +
|
|
1067
|
+
"and a workspace copy cannot carry them over. Declare { type: \"groupRef\", label } for one group, or " +
|
|
1068
|
+
"{ type: \"array\", label, items: { type: \"groupRef\", label } } for several. Saved settings keep the old text, " +
|
|
1069
|
+
"so read both forms (split a string on commas); the maker re-picks the groups in the Studio.",
|
|
1070
|
+
line: 0,
|
|
1071
|
+
snippet: "",
|
|
1072
|
+
}));
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1033
1075
|
// sc-1366 — invalid lucide icon import gate. lucide-react-native is a vetted
|
|
1034
1076
|
// import that the bundler EXTERNALISES, so esbuild never checks the named
|
|
1035
1077
|
// imports; a name that does not exist in the pinned version (`House` was added
|
|
@@ -1606,6 +1648,93 @@ function _paymentKindRules(source) {
|
|
|
1606
1648
|
return findings;
|
|
1607
1649
|
}
|
|
1608
1650
|
|
|
1651
|
+
// sc-16000 — payment-status-written.
|
|
1652
|
+
//
|
|
1653
|
+
// Only the server may mark an order paid: `requestPayment({ …, order })` names
|
|
1654
|
+
// the order, and the payment's settlement writes its payment-status column. A
|
|
1655
|
+
// charging widget that writes "paid" itself lets any buyer who may edit the
|
|
1656
|
+
// row mark it paid without paying. Reads the arguments of the widget's own
|
|
1657
|
+
// `create` / `update` calls for a paid value or a payment-status key. A
|
|
1658
|
+
// warning: the scan cannot see which column the workspace made the payment
|
|
1659
|
+
// status, nor a value built away from the call.
|
|
1660
|
+
const PAYMENT_CHARGE_CALL_RE = /(?<![\w$])request(?:Guest)?Payment\s*\(/;
|
|
1661
|
+
const _WRITE_VERBS = new Set(["create", "update"]);
|
|
1662
|
+
const _PAID_WRITE_RES = [
|
|
1663
|
+
/(?<![\w$])(['"]?)(?:payment_?status|is_?paid|paid)\1\s*:/gi,
|
|
1664
|
+
/:\s*(['"`])paid\1/gi,
|
|
1665
|
+
];
|
|
1666
|
+
|
|
1667
|
+
/** Local names the widget's create/update calls go through, and named mutation objects. */
|
|
1668
|
+
function _writeCallees(code) {
|
|
1669
|
+
const verbs = [];
|
|
1670
|
+
const objects = [];
|
|
1671
|
+
for (const call of _mutationHookCalls(code)) {
|
|
1672
|
+
if (!call.destructured) {
|
|
1673
|
+
objects.push(call.name);
|
|
1674
|
+
continue;
|
|
1675
|
+
}
|
|
1676
|
+
for (const entry of call.destructured.split(",")) {
|
|
1677
|
+
const [key, local] = entry.split(":").map((part) => part.trim());
|
|
1678
|
+
if (_WRITE_VERBS.has(key)) verbs.push(local || key);
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
return { verbs, objects };
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
/** Index of the parenthesis closing the one opening at `open`, or -1. */
|
|
1685
|
+
function _closingParen(masked, open) {
|
|
1686
|
+
let depth = 0;
|
|
1687
|
+
const end = Math.min(masked.length, open + PAYMENT_OPTIONS_MAX_CHARS);
|
|
1688
|
+
for (let i = open; i < end; i += 1) {
|
|
1689
|
+
if (_OPENERS.includes(masked[i])) depth += 1;
|
|
1690
|
+
if (_CLOSERS.includes(masked[i])) depth -= 1;
|
|
1691
|
+
if (depth === 0) return i;
|
|
1692
|
+
}
|
|
1693
|
+
return -1;
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
function _paymentStatusWrittenRules(source) {
|
|
1697
|
+
const masked = _stripNonCode(source);
|
|
1698
|
+
if (!PAYMENT_CHARGE_CALL_RE.test(masked)) return [];
|
|
1699
|
+
const { verbs, objects } = _writeCallees(masked);
|
|
1700
|
+
const escape = (name) => name.replace(/\$/g, "\\$");
|
|
1701
|
+
const callees = [
|
|
1702
|
+
...verbs.map((v) => `(?<![\\w$.])${escape(v)}`),
|
|
1703
|
+
...objects.map((o) => `(?<![\\w$])${escape(o)}\\s*\\.\\s*(?:create|update)`),
|
|
1704
|
+
];
|
|
1705
|
+
if (callees.length === 0) return [];
|
|
1706
|
+
const kept = _stripNonCode(source, { keepStrings: true });
|
|
1707
|
+
const sourceLines = source.split(/\r?\n/);
|
|
1708
|
+
const lineAt = _lineCounter(masked);
|
|
1709
|
+
const findings = [];
|
|
1710
|
+
const reported = new Set();
|
|
1711
|
+
for (const call of masked.matchAll(new RegExp(`(?:${callees.join("|")})\\s*\\(`, "g"))) {
|
|
1712
|
+
const open = call.index + call[0].length - 1;
|
|
1713
|
+
const close = _closingParen(masked, open);
|
|
1714
|
+
if (close === -1) continue;
|
|
1715
|
+
const args = kept.slice(open, close);
|
|
1716
|
+
for (const re of _PAID_WRITE_RES) {
|
|
1717
|
+
for (const hit of args.matchAll(re)) {
|
|
1718
|
+
const line = lineAt(open + hit.index);
|
|
1719
|
+
if (reported.has(line)) continue;
|
|
1720
|
+
reported.add(line);
|
|
1721
|
+
findings.push({
|
|
1722
|
+
rule: "payment-status-written",
|
|
1723
|
+
severity: "warning",
|
|
1724
|
+
label:
|
|
1725
|
+
`this charging widget writes a paid status itself, so a buyer ` +
|
|
1726
|
+
`who may edit the row can mark it paid without paying. Pass ` +
|
|
1727
|
+
`order: { table_id, record_id } to requestPayment: the server ` +
|
|
1728
|
+
`marks the order paid when the payment settles.`,
|
|
1729
|
+
line,
|
|
1730
|
+
snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
|
|
1731
|
+
});
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
return findings;
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1609
1738
|
// sc-4686 — no-hardcoded-currency-label.
|
|
1610
1739
|
//
|
|
1611
1740
|
// The charge is safe once `currency` is omitted, but the DISPLAY is not: a "kr"
|
|
@@ -3555,6 +3684,7 @@ export function lintSource(source, options) {
|
|
|
3555
3684
|
// sc-4650 — soft warning: every payment refusal reported as "try again".
|
|
3556
3685
|
findings.push(..._paymentCurrencyRules(source));
|
|
3557
3686
|
findings.push(..._paymentKindRules(source));
|
|
3687
|
+
findings.push(..._paymentStatusWrittenRules(source));
|
|
3558
3688
|
findings.push(..._hardcodedCurrencyLabelRules(source));
|
|
3559
3689
|
findings.push(..._paymentErrorHandlingRules(source));
|
|
3560
3690
|
findings.push(..._datastoreErrorHandlingRules(source));
|
|
@@ -3576,6 +3706,7 @@ export function lintSource(source, options) {
|
|
|
3576
3706
|
);
|
|
3577
3707
|
// REQ-WIDGET-ACTION — structural validation of manifest-declared actions.
|
|
3578
3708
|
findings.push(..._manifestActionRules(options && options.manifest));
|
|
3709
|
+
findings.push(..._groupIdTextRules(source, options && options.manifest));
|
|
3579
3710
|
findings.push(..._badgeCounterRules(source, options && options.manifest));
|
|
3580
3711
|
const hasErrors = findings.some((f) => f.severity !== "warning");
|
|
3581
3712
|
return { ok: !hasErrors, findings };
|
package/package.json
CHANGED
package/src/contract.js
CHANGED
|
@@ -7018,7 +7018,11 @@ 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
|
+
// 1.263.0: stricter lint — in a widget reading groupIds or useGroups(), a
|
|
7024
|
+
// propertySchema text field holding group ids is `group-ids-as-text`.
|
|
7025
|
+
version: "1.263.0",
|
|
7022
7026
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
7023
7027
|
hooks: HOOKS,
|
|
7024
7028
|
primitives: PRIMITIVES,
|