@colixsystems/widget-sdk 0.317.0 → 0.319.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 +11 -3
- package/dist/contract.cjs +8 -4
- package/dist/contract.js +8 -4
- package/dist/hooks.js +2 -2
- package/dist/index.d.ts +6 -2
- package/dist/linter.cjs +92 -0
- package/dist/linter.js +92 -0
- package/dist/people-picker-view.js +1 -0
- package/package.json +1 -1
- package/src/contract.js +8 -4
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,15 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
90
90
|
|
|
91
91
|
## Status
|
|
92
92
|
|
|
93
|
-
`v0.
|
|
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.319.0 (contract 1.259.0)
|
|
96
|
+
|
|
97
|
+
**You can show other people's profile photos.** Every `useDirectory()` and `useUsers()` row now carries `photo_url`: the person's profile photo as an absolute URL, or `null` when they have none or their account is deactivated. Pass it straight to `<Avatar name={row.name} seed={row.id} url={row.photo_url} />`, which falls back to the initials when it is `null` or cannot load. `<PeoplePicker>` shows it on user rows by itself. Anyone who can see a person's name in the directory sees their photo. Additive: a widget that ignores the field is unchanged.
|
|
98
|
+
|
|
99
|
+
### What's new in 0.318.0 (contract 1.258.0)
|
|
100
|
+
|
|
101
|
+
**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
102
|
|
|
95
103
|
### What's new in 0.317.0 (contract 1.257.0)
|
|
96
104
|
|
|
@@ -1601,7 +1609,7 @@ function ProfileHeader() {
|
|
|
1601
1609
|
- **`useUserPhoto()`** returns `{ url, canEdit, upload, remove, uploading, error }`. `url` is the same value as `useUser().photoUrl`. `upload(file)` takes the file `<FilePicker>` gives you, or `asset.file` from `useCamera()` / `useImageEditor()` — never the asset itself (a browser `File` on web, expo-file-system's `File` in the exported app) and resolves `{ photoUrl }`; `remove()` resolves `{ photoUrl: null }`. Once either resolves, every widget on the page reads the new `useUser().photoUrl`.
|
|
1602
1610
|
- **The server crops the image to a square and resizes it.** PNG, JPEG or WebP, 10 MB at most. A refusal carries `err.status`: `413` too large, `415` unsupported type, `400` unreadable image.
|
|
1603
1611
|
- **Check `canEdit` before offering the control.** It is false when nobody is signed in and on a host that cannot change the photo, such as the Builder canvas preview. `upload()` and `remove()` then reject (`"Sign in to change your photo"` / `"Changing your photo is not available here"`) and set `error`; the hook itself never throws at render.
|
|
1604
|
-
- **
|
|
1612
|
+
- **Other people's photos come from the directory.** Each `useUsers()` / `useDirectory()` row carries `photo_url`, an absolute URL or `null`: `<Avatar name={row.name} seed={row.id} url={row.photo_url} />`. `useUserPhoto()` only ever changes the caller's own.
|
|
1605
1613
|
- **No new scope.** The hook only ever touches the caller's own account.
|
|
1606
1614
|
|
|
1607
1615
|
A host backs the hook with the new optional `WidgetContext.account` slice, `{ setPhoto(file), removePhoto() }`. A host without it needs no change: `photoUrl` reads `null` and `canEdit` is false.
|
package/dist/contract.cjs
CHANGED
|
@@ -1052,8 +1052,8 @@ const HOOKS = [
|
|
|
1052
1052
|
"url update in every widget on the page. canEdit is false when nobody is signed in and on a host that cannot change " +
|
|
1053
1053
|
"the photo (the Builder canvas preview): hide or disable the control then — upload() / remove() reject with an Error and " +
|
|
1054
1054
|
"set error rather than the hook throwing at render, as does upload() with no file. uploading is true while any call is in flight; error holds the last " +
|
|
1055
|
-
"failure and clears on the next attempt. Needs no scope: it only ever touches the caller's own account.
|
|
1056
|
-
"
|
|
1055
|
+
"failure and clears on the next attempt. Needs no scope: it only ever touches the caller's own account. Another " +
|
|
1056
|
+
"user's photo is photo_url on their useUsers() / useDirectory() row; this hook only changes your own. Identical on web (Player) and the Expo export.",
|
|
1057
1057
|
returnShape: {
|
|
1058
1058
|
url: "string | null // same value as useUser().photoUrl",
|
|
1059
1059
|
canEdit: "boolean // signed in AND the host can change the photo",
|
|
@@ -2410,7 +2410,7 @@ const HOOKS = [
|
|
|
2410
2410
|
description:
|
|
2411
2411
|
"Read-only roster of app users. query is { q?, role?, is_active?, group_id?, ids?, limit?, offset? }; ids (1 to 100) resolves the names behind ids a widget already holds.",
|
|
2412
2412
|
returnShape: {
|
|
2413
|
-
users: "Array<{ id, name, role }> // snake_case rows; unwrapped from { data, meta }",
|
|
2413
|
+
users: "Array<{ id, name, role, photo_url }> // snake_case rows; photo_url absolute or null; unwrapped from { data, meta }",
|
|
2414
2414
|
loading: "boolean",
|
|
2415
2415
|
error: "DatastoreError | null",
|
|
2416
2416
|
refetch: "() => Promise<void>",
|
|
@@ -6971,7 +6971,11 @@ 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
|
-
|
|
6974
|
+
// 1.258.0: stricter lint (sc-15497) — `requestPayment` without `kind` is
|
|
6975
|
+
// the publish-blocking `payment-kind-required` finding.
|
|
6976
|
+
// 1.259.0: `useDirectory()` / `useUsers()` rows carry `photo_url`, the
|
|
6977
|
+
// person's profile photo as an absolute URL or null.
|
|
6978
|
+
version: "1.259.0",
|
|
6975
6979
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6976
6980
|
hooks: HOOKS,
|
|
6977
6981
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -1047,8 +1047,8 @@ const HOOKS = [
|
|
|
1047
1047
|
"url update in every widget on the page. canEdit is false when nobody is signed in and on a host that cannot change " +
|
|
1048
1048
|
"the photo (the Builder canvas preview): hide or disable the control then — upload() / remove() reject with an Error and " +
|
|
1049
1049
|
"set error rather than the hook throwing at render, as does upload() with no file. uploading is true while any call is in flight; error holds the last " +
|
|
1050
|
-
"failure and clears on the next attempt. Needs no scope: it only ever touches the caller's own account.
|
|
1051
|
-
"
|
|
1050
|
+
"failure and clears on the next attempt. Needs no scope: it only ever touches the caller's own account. Another " +
|
|
1051
|
+
"user's photo is photo_url on their useUsers() / useDirectory() row; this hook only changes your own. Identical on web (Player) and the Expo export.",
|
|
1052
1052
|
returnShape: {
|
|
1053
1053
|
url: "string | null // same value as useUser().photoUrl",
|
|
1054
1054
|
canEdit: "boolean // signed in AND the host can change the photo",
|
|
@@ -2405,7 +2405,7 @@ const HOOKS = [
|
|
|
2405
2405
|
description:
|
|
2406
2406
|
"Read-only roster of app users. query is { q?, role?, is_active?, group_id?, ids?, limit?, offset? }; ids (1 to 100) resolves the names behind ids a widget already holds.",
|
|
2407
2407
|
returnShape: {
|
|
2408
|
-
users: "Array<{ id, name, role }> // snake_case rows; unwrapped from { data, meta }",
|
|
2408
|
+
users: "Array<{ id, name, role, photo_url }> // snake_case rows; photo_url absolute or null; unwrapped from { data, meta }",
|
|
2409
2409
|
loading: "boolean",
|
|
2410
2410
|
error: "DatastoreError | null",
|
|
2411
2411
|
refetch: "() => Promise<void>",
|
|
@@ -6966,7 +6966,11 @@ 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
|
-
|
|
6969
|
+
// 1.258.0: stricter lint (sc-15497) — `requestPayment` without `kind` is
|
|
6970
|
+
// the publish-blocking `payment-kind-required` finding.
|
|
6971
|
+
// 1.259.0: `useDirectory()` / `useUsers()` rows carry `photo_url`, the
|
|
6972
|
+
// person's profile photo as an absolute URL or null.
|
|
6973
|
+
version: "1.259.0",
|
|
6970
6974
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6971
6975
|
hooks: HOOKS,
|
|
6972
6976
|
primitives: PRIMITIVES,
|
package/dist/hooks.js
CHANGED
|
@@ -353,8 +353,8 @@ const USER_PHOTO_NO_FILE = "useUserPhoto: file is required";
|
|
|
353
353
|
* signed in, `canEdit` is false and `upload` / `remove` reject instead of the
|
|
354
354
|
* hook throwing at render.
|
|
355
355
|
*
|
|
356
|
-
*
|
|
357
|
-
* `useDirectory()`
|
|
356
|
+
* Another user's photo is the `photo_url` on their `useUsers()` /
|
|
357
|
+
* `useDirectory()` row; this hook only changes the caller's own.
|
|
358
358
|
*/
|
|
359
359
|
export function useUserPhoto() {
|
|
360
360
|
const ctx = useWidgetContextOrThrow("useUserPhoto");
|
package/dist/index.d.ts
CHANGED
|
@@ -1491,6 +1491,8 @@ export interface DirectoryUser {
|
|
|
1491
1491
|
id: string;
|
|
1492
1492
|
name: string;
|
|
1493
1493
|
role: "USER" | "INTEGRATION";
|
|
1494
|
+
/** Their profile photo as an absolute URL, ready for `<Avatar url>`; null when none is set. */
|
|
1495
|
+
photo_url?: string | null;
|
|
1494
1496
|
}
|
|
1495
1497
|
|
|
1496
1498
|
export interface DirectoryQuery {
|
|
@@ -2541,8 +2543,8 @@ export interface UserPhotoApi {
|
|
|
2541
2543
|
* render: where nobody is signed in, or the host cannot change the photo,
|
|
2542
2544
|
* `canEdit` is false and `upload` / `remove` reject. Pass `upload` the
|
|
2543
2545
|
* file `<FilePicker>` gives you, or `asset.file` from `useCamera()` /
|
|
2544
|
-
* `useImageEditor()`.
|
|
2545
|
-
* `useUsers()`
|
|
2546
|
+
* `useImageEditor()`. Another user's photo is the `photo_url` on their
|
|
2547
|
+
* `useUsers()` / `useDirectory()` row; this hook only changes your own.
|
|
2546
2548
|
*/
|
|
2547
2549
|
export function useUserPhoto(): UserPhotoApi;
|
|
2548
2550
|
|
|
@@ -3725,6 +3727,8 @@ export interface AppUserRow {
|
|
|
3725
3727
|
email?: string;
|
|
3726
3728
|
role: "USER" | "INTEGRATION";
|
|
3727
3729
|
is_active: boolean;
|
|
3730
|
+
/** Their profile photo as an absolute URL, ready for `<Avatar url>`; null when none is set. */
|
|
3731
|
+
photo_url?: string | null;
|
|
3728
3732
|
}
|
|
3729
3733
|
|
|
3730
3734
|
export interface UsersQuery {
|
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
package/src/contract.js
CHANGED
|
@@ -1047,8 +1047,8 @@ const HOOKS = [
|
|
|
1047
1047
|
"url update in every widget on the page. canEdit is false when nobody is signed in and on a host that cannot change " +
|
|
1048
1048
|
"the photo (the Builder canvas preview): hide or disable the control then — upload() / remove() reject with an Error and " +
|
|
1049
1049
|
"set error rather than the hook throwing at render, as does upload() with no file. uploading is true while any call is in flight; error holds the last " +
|
|
1050
|
-
"failure and clears on the next attempt. Needs no scope: it only ever touches the caller's own account.
|
|
1051
|
-
"
|
|
1050
|
+
"failure and clears on the next attempt. Needs no scope: it only ever touches the caller's own account. Another " +
|
|
1051
|
+
"user's photo is photo_url on their useUsers() / useDirectory() row; this hook only changes your own. Identical on web (Player) and the Expo export.",
|
|
1052
1052
|
returnShape: {
|
|
1053
1053
|
url: "string | null // same value as useUser().photoUrl",
|
|
1054
1054
|
canEdit: "boolean // signed in AND the host can change the photo",
|
|
@@ -2405,7 +2405,7 @@ const HOOKS = [
|
|
|
2405
2405
|
description:
|
|
2406
2406
|
"Read-only roster of app users. query is { q?, role?, is_active?, group_id?, ids?, limit?, offset? }; ids (1 to 100) resolves the names behind ids a widget already holds.",
|
|
2407
2407
|
returnShape: {
|
|
2408
|
-
users: "Array<{ id, name, role }> // snake_case rows; unwrapped from { data, meta }",
|
|
2408
|
+
users: "Array<{ id, name, role, photo_url }> // snake_case rows; photo_url absolute or null; unwrapped from { data, meta }",
|
|
2409
2409
|
loading: "boolean",
|
|
2410
2410
|
error: "DatastoreError | null",
|
|
2411
2411
|
refetch: "() => Promise<void>",
|
|
@@ -6966,7 +6966,11 @@ 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
|
-
|
|
6969
|
+
// 1.258.0: stricter lint (sc-15497) — `requestPayment` without `kind` is
|
|
6970
|
+
// the publish-blocking `payment-kind-required` finding.
|
|
6971
|
+
// 1.259.0: `useDirectory()` / `useUsers()` rows carry `photo_url`, the
|
|
6972
|
+
// person's profile photo as an absolute URL or null.
|
|
6973
|
+
version: "1.259.0",
|
|
6970
6974
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6971
6975
|
hooks: HOOKS,
|
|
6972
6976
|
primitives: PRIMITIVES,
|