@colixsystems/widget-sdk 0.317.0 → 0.318.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 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, 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). |
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 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
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,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
90
90
 
91
91
  ## Status
92
92
 
93
- `v0.317.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**.
93
+ `v0.318.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.318.0 (contract 1.258.0)
96
+
97
+ **The linter refuses a charge that does not say what it sells.** The server has refused every `requestPayment` call without `kind` since 0.279.0, but nothing caught it before publishing, so a widget that left it out passed every check and then failed for every buyer. A `requestPayment` call whose options object omits `kind` is now the publish-blocking `payment-kind-required` finding, in `appstudio-widget lint` and in the platform's publish gate alike. Only the key is checked: `kind: props.kind` passes, and the server validates the value. An options object built in a local (`const body = { … }; requestPayment(body)`) is read where it is declared; an argument the source does not spell out, such as a spread or a function parameter, is left to the server. Fix: `requestPayment({ amount_cents, description, kind: "physical" })`, or `"service"` or `"digital"`.
94
98
 
95
99
  ### What's new in 0.317.0 (contract 1.257.0)
96
100
 
package/dist/contract.cjs CHANGED
@@ -6971,7 +6971,9 @@ const CONTRACT = deepFreeze({
6971
6971
  // refusals: no plan caps how many Actions run, so none is paused.
6972
6972
  // 1.257.0: additive (sc-15531) — `crypto` joins `actionScriptGlobals`:
6973
6973
  // `crypto.hashSecret` / `crypto.verifySecret` hash a PIN or passcode.
6974
- version: "1.257.0",
6974
+ // 1.258.0: stricter lint (sc-15497) — `requestPayment` without `kind` is
6975
+ // the publish-blocking `payment-kind-required` finding.
6976
+ version: "1.258.0",
6975
6977
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6976
6978
  hooks: HOOKS,
6977
6979
  primitives: PRIMITIVES,
package/dist/contract.js CHANGED
@@ -6966,7 +6966,9 @@ const CONTRACT = deepFreeze({
6966
6966
  // refusals: no plan caps how many Actions run, so none is paused.
6967
6967
  // 1.257.0: additive (sc-15531) — `crypto` joins `actionScriptGlobals`:
6968
6968
  // `crypto.hashSecret` / `crypto.verifySecret` hash a PIN or passcode.
6969
- version: "1.257.0",
6969
+ // 1.258.0: stricter lint (sc-15497) — `requestPayment` without `kind` is
6970
+ // the publish-blocking `payment-kind-required` finding.
6971
+ version: "1.258.0",
6970
6972
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6971
6973
  hooks: HOOKS,
6972
6974
  primitives: PRIMITIVES,
package/dist/linter.cjs CHANGED
@@ -1510,6 +1510,97 @@ function _paymentCurrencyRules(source) {
1510
1510
  return findings;
1511
1511
  }
1512
1512
 
1513
+ // sc-15497 — payment-kind-required.
1514
+ //
1515
+ // The server refuses every charge without `kind` (CHARGE_KIND_REQUIRED), so a
1516
+ // widget that omits it publishes cleanly and then fails for every buyer. Only
1517
+ // the presence of the key is judged; its value may be a variable, which the
1518
+ // server validates. An argument the source does not spell out (a spread, a
1519
+ // parameter, a computed key) is not judged: absence cannot be proved there.
1520
+ const REQUEST_PAYMENT_CALL_RE = /(?<![\w$])requestPayment\s*\(/g;
1521
+ // Bounds the scan so an unclosed object cannot run each call to EOF.
1522
+ const PAYMENT_OPTIONS_MAX_CHARS = 4000;
1523
+ const _OPENERS = "{[(";
1524
+ const _CLOSERS = "}])";
1525
+
1526
+ /** Top-level text of the bracket group opening at `open`, nested groups blanked. */
1527
+ function _topLevelGroupText(masked, kept, open) {
1528
+ let depth = 0;
1529
+ let text = "";
1530
+ const end = Math.min(masked.length, open + PAYMENT_OPTIONS_MAX_CHARS);
1531
+ for (let i = open; i < end; i += 1) {
1532
+ const ch = masked[i];
1533
+ // The mask blanks a template hole's closing brace, so skip its `${`.
1534
+ const opens = _OPENERS.includes(ch) && !(ch === "{" && masked[i - 1] === "$");
1535
+ const closes = _CLOSERS.includes(ch);
1536
+ if (closes) depth -= 1;
1537
+ if (closes && depth === 0) return text;
1538
+ text += depth === 1 && !opens && !closes ? kept[i] : " ";
1539
+ if (opens) depth += 1;
1540
+ }
1541
+ return null;
1542
+ }
1543
+
1544
+ /** "present" | "absent" | "unknown" — whether an object literal names `kind`. */
1545
+ function _objectLiteralKind(masked, kept, open) {
1546
+ const body = _topLevelGroupText(masked, kept, open);
1547
+ if (body === null) return "unknown";
1548
+ const entries = body.split(",").map((e) => e.trim());
1549
+ if (entries.some((e) => /^(['"`]?)kind\1\s*(?::|$)/.test(e))) return "present";
1550
+ if (entries.some((e) => e.startsWith("...") || e.startsWith("["))) {
1551
+ return "unknown";
1552
+ }
1553
+ return "absent";
1554
+ }
1555
+
1556
+ /** Where the object a `requestPayment(` argument names opens, or -1. */
1557
+ function _paymentArgumentObject(masked, kept, argStart) {
1558
+ const rest = masked.slice(argStart);
1559
+ const lead = /^\s*/.exec(rest)[0].length;
1560
+ if (rest[lead] === "{") return argStart + lead;
1561
+ const ident = /^\s*([A-Za-z_$][\w$]*)\s*\)/.exec(rest);
1562
+ if (!ident) return -1;
1563
+ const name = ident[1].replace(/\$/g, "\\$");
1564
+ const assignsKind = new RegExp(
1565
+ `(?<![\\w$])${name}\\s*(?:\\.\\s*kind|\\[\\s*(['"\`])kind\\1\\s*\\])\\s*=(?!=)`,
1566
+ );
1567
+ if (assignsKind.test(kept)) return -1;
1568
+ // A body built in a local before the call: `const body = { … }`.
1569
+ const binding = new RegExp(
1570
+ `(?<![\\w$])(?:const|let|var)\\s+${name}\\s*=\\s*\\{`,
1571
+ "g",
1572
+ );
1573
+ const bound = [...masked.slice(0, argStart).matchAll(binding)].pop();
1574
+ return bound ? bound.index + bound[0].length - 1 : -1;
1575
+ }
1576
+
1577
+ function _paymentKindRules(source) {
1578
+ const findings = [];
1579
+ const masked = _stripNonCode(source);
1580
+ const kept = _stripNonCode(source, { keepStrings: true });
1581
+ const sourceLines = source.split(/\r?\n/);
1582
+ const lineAt = _lineCounter(masked);
1583
+ for (const call of masked.matchAll(REQUEST_PAYMENT_CALL_RE)) {
1584
+ if (/\bfunction\s*$/.test(masked.slice(Math.max(0, call.index - 16), call.index))) continue;
1585
+ const argStart = call.index + call[0].length;
1586
+ const open = _paymentArgumentObject(masked, kept, argStart);
1587
+ if (open === -1) continue;
1588
+ if (_objectLiteralKind(masked, kept, open) !== "absent") continue;
1589
+ const line = lineAt(call.index);
1590
+ findings.push({
1591
+ rule: "payment-kind-required",
1592
+ severity: "error",
1593
+ label:
1594
+ `requestPayment omits kind, so the server refuses every charge. ` +
1595
+ `Say what is sold: requestPayment({ amount_cents, description, ` +
1596
+ `kind: "physical" }) — or "service" or "digital".`,
1597
+ line,
1598
+ snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
1599
+ });
1600
+ }
1601
+ return findings;
1602
+ }
1603
+
1513
1604
  // sc-4686 — no-hardcoded-currency-label.
1514
1605
  //
1515
1606
  // The charge is safe once `currency` is omitted, but the DISPLAY is not: a "kr"
@@ -3396,6 +3487,7 @@ function lintSource(source, options) {
3396
3487
  findings.push(..._writeGatedOnUserRules(source));
3397
3488
  // sc-4650 — soft warning: every payment refusal reported as "try again".
3398
3489
  findings.push(..._paymentCurrencyRules(source));
3490
+ findings.push(..._paymentKindRules(source));
3399
3491
  findings.push(..._hardcodedCurrencyLabelRules(source));
3400
3492
  findings.push(..._paymentErrorHandlingRules(source));
3401
3493
  findings.push(..._datastoreErrorHandlingRules(source));
package/dist/linter.js CHANGED
@@ -1505,6 +1505,97 @@ function _paymentCurrencyRules(source) {
1505
1505
  return findings;
1506
1506
  }
1507
1507
 
1508
+ // sc-15497 — payment-kind-required.
1509
+ //
1510
+ // The server refuses every charge without `kind` (CHARGE_KIND_REQUIRED), so a
1511
+ // widget that omits it publishes cleanly and then fails for every buyer. Only
1512
+ // the presence of the key is judged; its value may be a variable, which the
1513
+ // server validates. An argument the source does not spell out (a spread, a
1514
+ // parameter, a computed key) is not judged: absence cannot be proved there.
1515
+ const REQUEST_PAYMENT_CALL_RE = /(?<![\w$])requestPayment\s*\(/g;
1516
+ // Bounds the scan so an unclosed object cannot run each call to EOF.
1517
+ const PAYMENT_OPTIONS_MAX_CHARS = 4000;
1518
+ const _OPENERS = "{[(";
1519
+ const _CLOSERS = "}])";
1520
+
1521
+ /** Top-level text of the bracket group opening at `open`, nested groups blanked. */
1522
+ function _topLevelGroupText(masked, kept, open) {
1523
+ let depth = 0;
1524
+ let text = "";
1525
+ const end = Math.min(masked.length, open + PAYMENT_OPTIONS_MAX_CHARS);
1526
+ for (let i = open; i < end; i += 1) {
1527
+ const ch = masked[i];
1528
+ // The mask blanks a template hole's closing brace, so skip its `${`.
1529
+ const opens = _OPENERS.includes(ch) && !(ch === "{" && masked[i - 1] === "$");
1530
+ const closes = _CLOSERS.includes(ch);
1531
+ if (closes) depth -= 1;
1532
+ if (closes && depth === 0) return text;
1533
+ text += depth === 1 && !opens && !closes ? kept[i] : " ";
1534
+ if (opens) depth += 1;
1535
+ }
1536
+ return null;
1537
+ }
1538
+
1539
+ /** "present" | "absent" | "unknown" — whether an object literal names `kind`. */
1540
+ function _objectLiteralKind(masked, kept, open) {
1541
+ const body = _topLevelGroupText(masked, kept, open);
1542
+ if (body === null) return "unknown";
1543
+ const entries = body.split(",").map((e) => e.trim());
1544
+ if (entries.some((e) => /^(['"`]?)kind\1\s*(?::|$)/.test(e))) return "present";
1545
+ if (entries.some((e) => e.startsWith("...") || e.startsWith("["))) {
1546
+ return "unknown";
1547
+ }
1548
+ return "absent";
1549
+ }
1550
+
1551
+ /** Where the object a `requestPayment(` argument names opens, or -1. */
1552
+ function _paymentArgumentObject(masked, kept, argStart) {
1553
+ const rest = masked.slice(argStart);
1554
+ const lead = /^\s*/.exec(rest)[0].length;
1555
+ if (rest[lead] === "{") return argStart + lead;
1556
+ const ident = /^\s*([A-Za-z_$][\w$]*)\s*\)/.exec(rest);
1557
+ if (!ident) return -1;
1558
+ const name = ident[1].replace(/\$/g, "\\$");
1559
+ const assignsKind = new RegExp(
1560
+ `(?<![\\w$])${name}\\s*(?:\\.\\s*kind|\\[\\s*(['"\`])kind\\1\\s*\\])\\s*=(?!=)`,
1561
+ );
1562
+ if (assignsKind.test(kept)) return -1;
1563
+ // A body built in a local before the call: `const body = { … }`.
1564
+ const binding = new RegExp(
1565
+ `(?<![\\w$])(?:const|let|var)\\s+${name}\\s*=\\s*\\{`,
1566
+ "g",
1567
+ );
1568
+ const bound = [...masked.slice(0, argStart).matchAll(binding)].pop();
1569
+ return bound ? bound.index + bound[0].length - 1 : -1;
1570
+ }
1571
+
1572
+ function _paymentKindRules(source) {
1573
+ const findings = [];
1574
+ const masked = _stripNonCode(source);
1575
+ const kept = _stripNonCode(source, { keepStrings: true });
1576
+ const sourceLines = source.split(/\r?\n/);
1577
+ const lineAt = _lineCounter(masked);
1578
+ for (const call of masked.matchAll(REQUEST_PAYMENT_CALL_RE)) {
1579
+ if (/\bfunction\s*$/.test(masked.slice(Math.max(0, call.index - 16), call.index))) continue;
1580
+ const argStart = call.index + call[0].length;
1581
+ const open = _paymentArgumentObject(masked, kept, argStart);
1582
+ if (open === -1) continue;
1583
+ if (_objectLiteralKind(masked, kept, open) !== "absent") continue;
1584
+ const line = lineAt(call.index);
1585
+ findings.push({
1586
+ rule: "payment-kind-required",
1587
+ severity: "error",
1588
+ label:
1589
+ `requestPayment omits kind, so the server refuses every charge. ` +
1590
+ `Say what is sold: requestPayment({ amount_cents, description, ` +
1591
+ `kind: "physical" }) — or "service" or "digital".`,
1592
+ line,
1593
+ snippet: (sourceLines[line - 1] || "").trim().slice(0, 200),
1594
+ });
1595
+ }
1596
+ return findings;
1597
+ }
1598
+
1508
1599
  // sc-4686 — no-hardcoded-currency-label.
1509
1600
  //
1510
1601
  // The charge is safe once `currency` is omitted, but the DISPLAY is not: a "kr"
@@ -3391,6 +3482,7 @@ export function lintSource(source, options) {
3391
3482
  findings.push(..._writeGatedOnUserRules(source));
3392
3483
  // sc-4650 — soft warning: every payment refusal reported as "try again".
3393
3484
  findings.push(..._paymentCurrencyRules(source));
3485
+ findings.push(..._paymentKindRules(source));
3394
3486
  findings.push(..._hardcodedCurrencyLabelRules(source));
3395
3487
  findings.push(..._paymentErrorHandlingRules(source));
3396
3488
  findings.push(..._datastoreErrorHandlingRules(source));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.317.0",
3
+ "version": "0.318.0",
4
4
  "description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/contract.js CHANGED
@@ -6966,7 +6966,9 @@ const CONTRACT = deepFreeze({
6966
6966
  // refusals: no plan caps how many Actions run, so none is paused.
6967
6967
  // 1.257.0: additive (sc-15531) — `crypto` joins `actionScriptGlobals`:
6968
6968
  // `crypto.hashSecret` / `crypto.verifySecret` hash a PIN or passcode.
6969
- version: "1.257.0",
6969
+ // 1.258.0: stricter lint (sc-15497) — `requestPayment` without `kind` is
6970
+ // the publish-blocking `payment-kind-required` finding.
6971
+ version: "1.258.0",
6970
6972
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6971
6973
  hooks: HOOKS,
6972
6974
  primitives: PRIMITIVES,