@colixsystems/widget-sdk 0.219.1 → 0.220.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 +45 -1
- package/dist/contract.cjs +55 -11
- package/dist/contract.js +55 -11
- package/dist/hooks.js +74 -0
- package/dist/index.d.ts +63 -6
- package/dist/index.js +1 -0
- package/dist/index.native.js +1 -0
- package/package.json +1 -1
- package/src/contract.js +55 -11
package/README.md
CHANGED
|
@@ -23,6 +23,7 @@ The data layer lives in **four separate domain-client packages**, each instantia
|
|
|
23
23
|
| **CORE** | `useWidgetStyle()` | `{ [styleField]: value }` | `ctx.props.style` — no scope. The author-set per-widget style values declared in `manifest.styleSchema`; apply each onto whatever element you choose. |
|
|
24
24
|
| **CORE** | `useUser()` | `{ id, email, displayName, photoUrl, roles, groupIds }` | `ctx.user` (host-built context, **camelCase** — not a wire payload; `id` null when anonymous) — no scope. `photoUrl` is the user's own profile photo as an absolute URL, or `null`. |
|
|
25
25
|
| **CORE** | `useUserPhoto()` | `{ url, canEdit, upload, remove, uploading, error }` | `ctx.user` + the optional `ctx.account` — no scope. Changes the signed-in user's OWN profile photo. `canEdit` is false when nobody is signed in or the host cannot change it; `upload` / `remove` then reject. |
|
|
26
|
+
| **CORE** | `useAnonymousAccount()` | `{ supported, canCreate, creating, error, create }` | The optional `ctx.account.anonymous` — no scope. Offers an account with a generated login code and password and no email. `create()` opens the app's own dialog, which confirms, creates the account, shows the pair once and signs the visitor in; the widget never receives the pair and `create()` resolves `{ created: true }`. `supported` is false where the workspace has not turned anonymous accounts on, on the Builder canvas, in a preview and for a badge counter; `canCreate` is false while someone is signed in. |
|
|
26
27
|
| **CORE** | `useNavigation()` | `{ goTo, goBack, push, replace, back, currentRoute, openLink }` | `ctx.navigation` — no scope. `goTo(pageIdOrSlug, params?)` accepts a page UUID (a `pageRef` prop) **or its slug** (a row's page-key field) — both hosts resolve either (`openLink` for a link of unknown shape; a known external URL can also use the `Linking` primitive) |
|
|
27
28
|
| **CORE** | `useFilePreview(file)` | `{ uri }` | No scope. A temporary address an `<Image>` can show for a file the person picked but has not uploaded yet (a photo in a composer). Native picks use their own uri; on the web the SDK creates and releases an object URL, which widgets may not do themselves. `uri` is null for no file. |
|
|
28
29
|
| **CORE** | `usePageBadge(count)` | `{ supported }` | `ctx.navigation.setBadge` — no scope. Puts `count` on the menu entry or tab of the page the widget is on (a chat's unread messages). The host sums the page's widgets and keeps the last count after the widget leaves the screen, until it reports again; `0` clears this widget's share. `supported` is false where the host draws no page badges (the Builder canvas). |
|
|
@@ -83,7 +84,50 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
83
84
|
|
|
84
85
|
## Status
|
|
85
86
|
|
|
86
|
-
`v0.
|
|
87
|
+
`v0.220.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**.
|
|
88
|
+
|
|
89
|
+
### What's new in 0.220.0 (contract 1.176.0)
|
|
90
|
+
|
|
91
|
+
**An app can let a visitor continue without an email — `useAnonymousAccount()`.** Some apps must let a person act without identifying themselves and still come back later: someone files a report and returns to follow it. The new hook lets a widget offer an account that has no email address. The server generates a login code and a password, and the visitor signs in again later with that pair on the app's sign-in screen ("Sign in with a login code").
|
|
92
|
+
|
|
93
|
+
```jsx
|
|
94
|
+
import { useAnonymousAccount, useUser, Button, Text, View } from "@colixsystems/widget-sdk";
|
|
95
|
+
|
|
96
|
+
export default function ContinueWithoutEmail() {
|
|
97
|
+
const user = useUser();
|
|
98
|
+
const { supported, canCreate, creating, error, create } = useAnonymousAccount();
|
|
99
|
+
|
|
100
|
+
if (!supported) {
|
|
101
|
+
return <Text>Continuing without an email is not available here.</Text>;
|
|
102
|
+
}
|
|
103
|
+
if (user.id) {
|
|
104
|
+
return <Text>You are signed in.</Text>;
|
|
105
|
+
}
|
|
106
|
+
if (!canCreate) return null;
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<View>
|
|
110
|
+
<Button
|
|
111
|
+
title="Continue without an email"
|
|
112
|
+
disabled={creating}
|
|
113
|
+
onPress={() => create().catch(() => {})}
|
|
114
|
+
/>
|
|
115
|
+
{error && error.code !== "CANCELLED" ? (
|
|
116
|
+
<Text>Could not create the account. Try again.</Text>
|
|
117
|
+
) : null}
|
|
118
|
+
</View>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
- **The widget only asks; the app does the rest.** `create()` takes no arguments and opens the app's own dialog. It asks the visitor to confirm, shows the captcha notice when a captcha will run, creates the account, shows the login code and password once with the warning that a lost password cannot be recovered, and signs the visitor in when they confirm they saved them (or opens the sign-in screen's two-factor step when the workspace requires one). Do not build a confirmation, a captcha notice or a credentials screen of your own.
|
|
124
|
+
- **The widget never receives the login code or the password.** `create()` resolves `{ created: true }` and nothing else. Widgets on a page share one context, so a credential that cannot be reset is kept out of it altogether. This is a contract boundary, not a sandbox: the SDK never hands the pair to a widget, but every widget on a page still runs inside the app.
|
|
125
|
+
- **Call `create()` from a user action.** A button's `onPress`, never on mount or in an effect. Nothing is created until the visitor confirms in the dialog.
|
|
126
|
+
- **Failures carry a `code`.** `create()` rejects with an Error whose `code` is the server's refusal (`ANONYMOUS_ACCOUNT_LIMIT_REACHED`, `RATE_LIMITED`, `CAPTCHA_FAILED`, …), `CAPTCHA_UNAVAILABLE` when the captcha could not run (there is no fallback), `ALREADY_SIGNED_IN`, `CANCELLED` when the visitor closes the dialog, or `UNSUPPORTED`. The dialog shows a failure itself and lets the visitor retry, so a rejection means they gave up; treat `CANCELLED` as no error. `error` holds the last one.
|
|
127
|
+
- **`supported` and `canCreate`.** `supported` is false where the workspace has not turned anonymous accounts on, on the Builder canvas, in a preview and for a badge counter: render a visible "not available" state. `canCreate` is false while someone is signed in. The hook never throws at render and needs no scope.
|
|
128
|
+
- **What the account can do.** It is not treated as a signed-in member: it gets only what the workspace grants to everyone or to the group chosen for these accounts, plus the records it owns. `useUser().email` is `null` for it.
|
|
129
|
+
|
|
130
|
+
A host backs the hook with the new optional `WidgetContext.account.anonymous` member, `{ canCreate, create() }`. `account`'s photo actions are now optional members, so a host may publish `account` with either or both. Additive.
|
|
87
131
|
|
|
88
132
|
### What's new in 0.219.1
|
|
89
133
|
|
package/dist/contract.cjs
CHANGED
|
@@ -938,6 +938,38 @@ const HOOKS = [
|
|
|
938
938
|
requiredContextSlice: ["user", "account.setPhoto", "account.removePhoto"],
|
|
939
939
|
scopes: null,
|
|
940
940
|
},
|
|
941
|
+
{
|
|
942
|
+
name: "useAnonymousAccount",
|
|
943
|
+
signature: "useAnonymousAccount()",
|
|
944
|
+
description:
|
|
945
|
+
"Offer an account that needs NO email address: the server generates a login code and a password, and the person signs in " +
|
|
946
|
+
"later with that pair on the app's sign-in screen. For apps where a visitor must be able to act without identifying " +
|
|
947
|
+
"themselves and still come back (a whistleblower report). The widget ONLY ASKS: create() takes NO arguments and opens the APP'S " +
|
|
948
|
+
"OWN dialog, which asks the visitor to confirm, runs the captcha, creates the account, shows the login code and password " +
|
|
949
|
+
"ONCE with the warning that a lost password cannot be recovered, and signs the visitor in when they confirm they saved " +
|
|
950
|
+
"them (or opens the sign-in screen's two-factor step when the workspace requires one). The widget NEVER receives the " +
|
|
951
|
+
"login code or the password: create() resolves { created: true } and nothing else. Do NOT build your own confirmation, " +
|
|
952
|
+
"captcha notice or credentials screen, and never call an endpoint yourself. Call create() from a user action (a button's " +
|
|
953
|
+
"onPress), never on mount or in an effect. It rejects with an Error carrying code: the server's refusal " +
|
|
954
|
+
"(ANONYMOUS_ACCOUNT_LIMIT_REACHED, RATE_LIMITED, CAPTCHA_FAILED, …), CAPTCHA_UNAVAILABLE when the " +
|
|
955
|
+
"captcha could not run (there is no fallback), ALREADY_SIGNED_IN, CANCELLED when the visitor closes the dialog, or " +
|
|
956
|
+
"UNSUPPORTED. The dialog already shows a failure and lets the visitor retry, so a rejection means they gave up: treat " +
|
|
957
|
+
"CANCELLED as no error. supported is false — and create() rejects with UNSUPPORTED instead of the hook throwing at " +
|
|
958
|
+
"render — where the workspace has not turned anonymous accounts on, on the Builder canvas, in a preview pane, in a draft " +
|
|
959
|
+
"preview and for a badge counter: render a visible 'not available' state then. canCreate is false while someone is " +
|
|
960
|
+
"signed in: hide the button then. After create() resolves the visitor is signed in and the page re-renders, so read " +
|
|
961
|
+
"useUser() for the new state. Needs no scope. Identical on web (Player) and the Expo export.",
|
|
962
|
+
returnShape: {
|
|
963
|
+
supported: "boolean // the host offers anonymous accounts here",
|
|
964
|
+
canCreate: "boolean // supported AND nobody is signed in",
|
|
965
|
+
creating: "boolean // a create() call is in flight: the app's dialog is open",
|
|
966
|
+
error: "(Error & { code?: string, status?: number }) | null // the last create() failure; cleared by the next attempt",
|
|
967
|
+
create:
|
|
968
|
+
"() => Promise<{ created: true }> // takes no arguments; opens the app's dialog; never returns the login code or password",
|
|
969
|
+
},
|
|
970
|
+
requiredContextSlice: ["account.anonymous"],
|
|
971
|
+
scopes: null,
|
|
972
|
+
},
|
|
941
973
|
{
|
|
942
974
|
name: "useFill",
|
|
943
975
|
signature: "useFill()",
|
|
@@ -3565,26 +3597,31 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
3565
3597
|
},
|
|
3566
3598
|
user: {
|
|
3567
3599
|
description:
|
|
3568
|
-
"Signed-in user, host-built context object (camelCase: { id, email, displayName, photoUrl, roles, groupIds }) — NOT a wire payload, so it is the one camelCase island among the hooks. photoUrl is the user's own profile photo as an absolute URL, or null. Not a data-client.",
|
|
3600
|
+
"Signed-in user, host-built context object (camelCase: { id, email, displayName, photoUrl, roles, groupIds }) — NOT a wire payload, so it is the one camelCase island among the hooks. photoUrl is the user's own profile photo as an absolute URL, or null. email is null for an account created without one. Not a data-client.",
|
|
3569
3601
|
required: true,
|
|
3570
3602
|
fields: {
|
|
3571
3603
|
id: "string",
|
|
3572
|
-
email: "string",
|
|
3604
|
+
email: "string | null",
|
|
3573
3605
|
displayName: "string",
|
|
3574
3606
|
photoUrl: "string | null",
|
|
3575
3607
|
},
|
|
3576
3608
|
},
|
|
3577
|
-
// Optional so a host
|
|
3578
|
-
// useUserPhoto() reports canEdit false when it is absent.
|
|
3609
|
+
// Optional, and so is every member: a host publishes only what it can do.
|
|
3579
3610
|
account: {
|
|
3580
3611
|
description:
|
|
3581
|
-
"Optional self-service account actions
|
|
3582
|
-
"{ setPhoto(file) -> Promise<{ photoUrl }>, removePhoto() -> Promise<{ photoUrl: null }> }
|
|
3583
|
-
"
|
|
3584
|
-
"widget. setPhoto takes a browser File on web and expo-file-system's File on native.
|
|
3585
|
-
"
|
|
3612
|
+
"Optional self-service account actions; every member is optional too. " +
|
|
3613
|
+
"{ setPhoto(file) -> Promise<{ photoUrl }>, removePhoto() -> Promise<{ photoUrl: null }> } back useUserPhoto() and are " +
|
|
3614
|
+
"present only while a user is signed in. The host performs the request AND updates its own session, so user.photoUrl " +
|
|
3615
|
+
"changes for every widget. setPhoto takes a browser File on web and expo-file-system's File on native. " +
|
|
3616
|
+
"anonymous backs useAnonymousAccount() and is present only where the workspace offers accounts without an email: " +
|
|
3617
|
+
"{ canCreate: boolean, create() -> Promise<{ created: true }> }. create() opens the HOST'S OWN dialog: " +
|
|
3618
|
+
"it asks the visitor to confirm, runs the captcha, calls the server, shows the login code and password once, and signs " +
|
|
3619
|
+
"the visitor in when they confirm they saved them. The pair lives only in that dialog and never reaches the slice, a " +
|
|
3620
|
+
"widget, an error or storage. " +
|
|
3621
|
+
"The whole slice is absent on the Builder canvas, in the preview panes and for a badge counter, where both hooks " +
|
|
3622
|
+
"degrade (canEdit: false, supported: false) rather than throwing.",
|
|
3586
3623
|
required: false,
|
|
3587
|
-
fields: { setPhoto: "function", removePhoto: "function" },
|
|
3624
|
+
fields: { setPhoto: "function", removePhoto: "function", anonymous: "object" },
|
|
3588
3625
|
},
|
|
3589
3626
|
workspace: {
|
|
3590
3627
|
description:
|
|
@@ -5812,7 +5849,14 @@ const CONTRACT = deepFreeze({
|
|
|
5812
5849
|
// new `ctx.filestore.signingRounds`. `useFileSignature` also returns
|
|
5813
5850
|
// `hintCode` and `nameRefusal`, and its `cancel()` resolves to what
|
|
5814
5851
|
// became of the order instead of always reporting "cancelled".
|
|
5815
|
-
|
|
5852
|
+
// 1.176.0: additive (sc-10934) — `useAnonymousAccount()` asks the host to
|
|
5853
|
+
// create an account with a generated login code and password and no
|
|
5854
|
+
// email, through the new optional `ctx.account.anonymous`
|
|
5855
|
+
// (`{ canCreate, create }`). The host shows the pair in its own dialog;
|
|
5856
|
+
// a widget never receives it. `account`'s photo actions are now
|
|
5857
|
+
// optional members, and `user.email` is documented as nullable: an
|
|
5858
|
+
// account without an email has none.
|
|
5859
|
+
version: "1.176.0",
|
|
5816
5860
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
5817
5861
|
hooks: HOOKS,
|
|
5818
5862
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -938,6 +938,38 @@ const HOOKS = [
|
|
|
938
938
|
requiredContextSlice: ["user", "account.setPhoto", "account.removePhoto"],
|
|
939
939
|
scopes: null,
|
|
940
940
|
},
|
|
941
|
+
{
|
|
942
|
+
name: "useAnonymousAccount",
|
|
943
|
+
signature: "useAnonymousAccount()",
|
|
944
|
+
description:
|
|
945
|
+
"Offer an account that needs NO email address: the server generates a login code and a password, and the person signs in " +
|
|
946
|
+
"later with that pair on the app's sign-in screen. For apps where a visitor must be able to act without identifying " +
|
|
947
|
+
"themselves and still come back (a whistleblower report). The widget ONLY ASKS: create() takes NO arguments and opens the APP'S " +
|
|
948
|
+
"OWN dialog, which asks the visitor to confirm, runs the captcha, creates the account, shows the login code and password " +
|
|
949
|
+
"ONCE with the warning that a lost password cannot be recovered, and signs the visitor in when they confirm they saved " +
|
|
950
|
+
"them (or opens the sign-in screen's two-factor step when the workspace requires one). The widget NEVER receives the " +
|
|
951
|
+
"login code or the password: create() resolves { created: true } and nothing else. Do NOT build your own confirmation, " +
|
|
952
|
+
"captcha notice or credentials screen, and never call an endpoint yourself. Call create() from a user action (a button's " +
|
|
953
|
+
"onPress), never on mount or in an effect. It rejects with an Error carrying code: the server's refusal " +
|
|
954
|
+
"(ANONYMOUS_ACCOUNT_LIMIT_REACHED, RATE_LIMITED, CAPTCHA_FAILED, …), CAPTCHA_UNAVAILABLE when the " +
|
|
955
|
+
"captcha could not run (there is no fallback), ALREADY_SIGNED_IN, CANCELLED when the visitor closes the dialog, or " +
|
|
956
|
+
"UNSUPPORTED. The dialog already shows a failure and lets the visitor retry, so a rejection means they gave up: treat " +
|
|
957
|
+
"CANCELLED as no error. supported is false — and create() rejects with UNSUPPORTED instead of the hook throwing at " +
|
|
958
|
+
"render — where the workspace has not turned anonymous accounts on, on the Builder canvas, in a preview pane, in a draft " +
|
|
959
|
+
"preview and for a badge counter: render a visible 'not available' state then. canCreate is false while someone is " +
|
|
960
|
+
"signed in: hide the button then. After create() resolves the visitor is signed in and the page re-renders, so read " +
|
|
961
|
+
"useUser() for the new state. Needs no scope. Identical on web (Player) and the Expo export.",
|
|
962
|
+
returnShape: {
|
|
963
|
+
supported: "boolean // the host offers anonymous accounts here",
|
|
964
|
+
canCreate: "boolean // supported AND nobody is signed in",
|
|
965
|
+
creating: "boolean // a create() call is in flight: the app's dialog is open",
|
|
966
|
+
error: "(Error & { code?: string, status?: number }) | null // the last create() failure; cleared by the next attempt",
|
|
967
|
+
create:
|
|
968
|
+
"() => Promise<{ created: true }> // takes no arguments; opens the app's dialog; never returns the login code or password",
|
|
969
|
+
},
|
|
970
|
+
requiredContextSlice: ["account.anonymous"],
|
|
971
|
+
scopes: null,
|
|
972
|
+
},
|
|
941
973
|
{
|
|
942
974
|
name: "useFill",
|
|
943
975
|
signature: "useFill()",
|
|
@@ -3561,26 +3593,31 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
3561
3593
|
},
|
|
3562
3594
|
user: {
|
|
3563
3595
|
description:
|
|
3564
|
-
"Signed-in user, host-built context object (camelCase: { id, email, displayName, photoUrl, roles, groupIds }) — NOT a wire payload, so it is the one camelCase island among the hooks. photoUrl is the user's own profile photo as an absolute URL, or null. Not a data-client.",
|
|
3596
|
+
"Signed-in user, host-built context object (camelCase: { id, email, displayName, photoUrl, roles, groupIds }) — NOT a wire payload, so it is the one camelCase island among the hooks. photoUrl is the user's own profile photo as an absolute URL, or null. email is null for an account created without one. Not a data-client.",
|
|
3565
3597
|
required: true,
|
|
3566
3598
|
fields: {
|
|
3567
3599
|
id: "string",
|
|
3568
|
-
email: "string",
|
|
3600
|
+
email: "string | null",
|
|
3569
3601
|
displayName: "string",
|
|
3570
3602
|
photoUrl: "string | null",
|
|
3571
3603
|
},
|
|
3572
3604
|
},
|
|
3573
|
-
// Optional so a host
|
|
3574
|
-
// useUserPhoto() reports canEdit false when it is absent.
|
|
3605
|
+
// Optional, and so is every member: a host publishes only what it can do.
|
|
3575
3606
|
account: {
|
|
3576
3607
|
description:
|
|
3577
|
-
"Optional self-service account actions
|
|
3578
|
-
"{ setPhoto(file) -> Promise<{ photoUrl }>, removePhoto() -> Promise<{ photoUrl: null }> }
|
|
3579
|
-
"
|
|
3580
|
-
"widget. setPhoto takes a browser File on web and expo-file-system's File on native.
|
|
3581
|
-
"
|
|
3608
|
+
"Optional self-service account actions; every member is optional too. " +
|
|
3609
|
+
"{ setPhoto(file) -> Promise<{ photoUrl }>, removePhoto() -> Promise<{ photoUrl: null }> } back useUserPhoto() and are " +
|
|
3610
|
+
"present only while a user is signed in. The host performs the request AND updates its own session, so user.photoUrl " +
|
|
3611
|
+
"changes for every widget. setPhoto takes a browser File on web and expo-file-system's File on native. " +
|
|
3612
|
+
"anonymous backs useAnonymousAccount() and is present only where the workspace offers accounts without an email: " +
|
|
3613
|
+
"{ canCreate: boolean, create() -> Promise<{ created: true }> }. create() opens the HOST'S OWN dialog: " +
|
|
3614
|
+
"it asks the visitor to confirm, runs the captcha, calls the server, shows the login code and password once, and signs " +
|
|
3615
|
+
"the visitor in when they confirm they saved them. The pair lives only in that dialog and never reaches the slice, a " +
|
|
3616
|
+
"widget, an error or storage. " +
|
|
3617
|
+
"The whole slice is absent on the Builder canvas, in the preview panes and for a badge counter, where both hooks " +
|
|
3618
|
+
"degrade (canEdit: false, supported: false) rather than throwing.",
|
|
3582
3619
|
required: false,
|
|
3583
|
-
fields: { setPhoto: "function", removePhoto: "function" },
|
|
3620
|
+
fields: { setPhoto: "function", removePhoto: "function", anonymous: "object" },
|
|
3584
3621
|
},
|
|
3585
3622
|
workspace: {
|
|
3586
3623
|
description:
|
|
@@ -5808,7 +5845,14 @@ const CONTRACT = deepFreeze({
|
|
|
5808
5845
|
// new `ctx.filestore.signingRounds`. `useFileSignature` also returns
|
|
5809
5846
|
// `hintCode` and `nameRefusal`, and its `cancel()` resolves to what
|
|
5810
5847
|
// became of the order instead of always reporting "cancelled".
|
|
5811
|
-
|
|
5848
|
+
// 1.176.0: additive (sc-10934) — `useAnonymousAccount()` asks the host to
|
|
5849
|
+
// create an account with a generated login code and password and no
|
|
5850
|
+
// email, through the new optional `ctx.account.anonymous`
|
|
5851
|
+
// (`{ canCreate, create }`). The host shows the pair in its own dialog;
|
|
5852
|
+
// a widget never receives it. `account`'s photo actions are now
|
|
5853
|
+
// optional members, and `user.email` is documented as nullable: an
|
|
5854
|
+
// account without an email has none.
|
|
5855
|
+
version: "1.176.0",
|
|
5812
5856
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
5813
5857
|
hooks: HOOKS,
|
|
5814
5858
|
primitives: PRIMITIVES,
|
package/dist/hooks.js
CHANGED
|
@@ -391,6 +391,80 @@ export function useUserPhoto() {
|
|
|
391
391
|
return { url, canEdit, upload, remove, uploading, error };
|
|
392
392
|
}
|
|
393
393
|
|
|
394
|
+
const ANONYMOUS_ACCOUNT_UNSUPPORTED =
|
|
395
|
+
"Creating an account without an email is not available here";
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Offer an account that needs no email address. The server generates a login
|
|
399
|
+
* code and a password; the person signs in later with that pair. Returns
|
|
400
|
+
* `{ supported, canCreate, creating, error, create }`.
|
|
401
|
+
*
|
|
402
|
+
* A widget only asks. `create()` takes no arguments and opens the app's own dialog
|
|
403
|
+
* (`ctx.account.anonymous`), which asks the visitor to confirm, runs the
|
|
404
|
+
* captcha, creates the account, shows the login code and password once and
|
|
405
|
+
* signs the visitor in when they confirm they saved them. The widget never
|
|
406
|
+
* receives the pair: `create()` resolves `{ created: true }`. It rejects with
|
|
407
|
+
* an Error carrying `code` — the server's refusal, `CAPTCHA_UNAVAILABLE`,
|
|
408
|
+
* `ALREADY_SIGNED_IN`, `CANCELLED` when the visitor closes the dialog, or
|
|
409
|
+
* `UNSUPPORTED`.
|
|
410
|
+
*
|
|
411
|
+
* Call `create()` from a user action (a button press), never on mount.
|
|
412
|
+
* `ctx.account.anonymous` is optional: where it is absent (the workspace has
|
|
413
|
+
* the feature off, the Builder canvas, a preview, a badge counter)
|
|
414
|
+
* `supported` is false and `create()` rejects instead of the hook throwing at
|
|
415
|
+
* render. `canCreate` is false while someone is signed in.
|
|
416
|
+
*/
|
|
417
|
+
export function useAnonymousAccount() {
|
|
418
|
+
const ctx = useWidgetContextOrThrow("useAnonymousAccount");
|
|
419
|
+
const member = ctx.account ? ctx.account.anonymous : null;
|
|
420
|
+
const supported = Boolean(member) && typeof member.create === "function";
|
|
421
|
+
|
|
422
|
+
const hostRef = useRef(null);
|
|
423
|
+
hostRef.current = supported ? member : null;
|
|
424
|
+
const inFlightRef = useRef(null);
|
|
425
|
+
const [creating, setCreating] = useState(false);
|
|
426
|
+
const [error, setError] = useState(null);
|
|
427
|
+
|
|
428
|
+
const create = useCallback(() => {
|
|
429
|
+
if (inFlightRef.current) return inFlightRef.current;
|
|
430
|
+
const host = hostRef.current;
|
|
431
|
+
if (!host) {
|
|
432
|
+
const err = Object.assign(new Error(ANONYMOUS_ACCOUNT_UNSUPPORTED), {
|
|
433
|
+
code: "UNSUPPORTED",
|
|
434
|
+
});
|
|
435
|
+
setError(err);
|
|
436
|
+
return Promise.reject(err);
|
|
437
|
+
}
|
|
438
|
+
setCreating(true);
|
|
439
|
+
setError(null);
|
|
440
|
+
const attempt = Promise.resolve()
|
|
441
|
+
.then(() => host.create())
|
|
442
|
+
.then(
|
|
443
|
+
() => {
|
|
444
|
+
inFlightRef.current = null;
|
|
445
|
+
setCreating(false);
|
|
446
|
+
return { created: true };
|
|
447
|
+
},
|
|
448
|
+
(err) => {
|
|
449
|
+
inFlightRef.current = null;
|
|
450
|
+
setCreating(false);
|
|
451
|
+
setError(err);
|
|
452
|
+
throw err;
|
|
453
|
+
},
|
|
454
|
+
);
|
|
455
|
+
inFlightRef.current = attempt;
|
|
456
|
+
return attempt;
|
|
457
|
+
}, []);
|
|
458
|
+
|
|
459
|
+
return {
|
|
460
|
+
supported,
|
|
461
|
+
canCreate: supported && member.canCreate === true,
|
|
462
|
+
creating,
|
|
463
|
+
error,
|
|
464
|
+
create,
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
|
|
394
468
|
/**
|
|
395
469
|
* Returns `true` when the host has sized this widget to fill a box of
|
|
396
470
|
* definite height — a widget in the section a fit-to-screen page stretches to
|
package/dist/index.d.ts
CHANGED
|
@@ -744,14 +744,18 @@ export interface WidgetContext<TProps = unknown> {
|
|
|
744
744
|
groupIds: string[];
|
|
745
745
|
};
|
|
746
746
|
/**
|
|
747
|
-
* Optional self-service account actions
|
|
748
|
-
*
|
|
749
|
-
*
|
|
750
|
-
*
|
|
747
|
+
* Optional self-service account actions; every member is optional too.
|
|
748
|
+
* `setPhoto` / `removePhoto` back `useUserPhoto()` and are present only
|
|
749
|
+
* while a user is signed in: the host performs the request and updates its
|
|
750
|
+
* own session, so `user.photoUrl` changes for every widget. `anonymous`
|
|
751
|
+
* backs `useAnonymousAccount()` and is present only where the workspace
|
|
752
|
+
* offers accounts without an email. The whole slice is absent on the
|
|
753
|
+
* Builder canvas, in the preview panes and for a badge counter.
|
|
751
754
|
*/
|
|
752
755
|
account?: {
|
|
753
|
-
setPhoto(file: UserPhotoFile): Promise<{ photoUrl: string | null }>;
|
|
754
|
-
removePhoto(): Promise<{ photoUrl: null }>;
|
|
756
|
+
setPhoto?(file: UserPhotoFile): Promise<{ photoUrl: string | null }>;
|
|
757
|
+
removePhoto?(): Promise<{ photoUrl: null }>;
|
|
758
|
+
anonymous?: AnonymousAccountHost;
|
|
755
759
|
};
|
|
756
760
|
workspace: {
|
|
757
761
|
id: string;
|
|
@@ -1947,6 +1951,59 @@ export interface UserPhotoApi {
|
|
|
1947
1951
|
*/
|
|
1948
1952
|
export function useUserPhoto(): UserPhotoApi;
|
|
1949
1953
|
|
|
1954
|
+
/** A `create()` failure. `code` names the refusal. */
|
|
1955
|
+
export type AnonymousAccountError = Error & {
|
|
1956
|
+
/**
|
|
1957
|
+
* The server's refusal (`ANONYMOUS_ACCOUNT_LIMIT_REACHED`, `RATE_LIMITED`,
|
|
1958
|
+
* `CAPTCHA_FAILED`, …), or `CAPTCHA_UNAVAILABLE`
|
|
1959
|
+
* (the captcha could not run), `ALREADY_SIGNED_IN`, `CANCELLED` (the
|
|
1960
|
+
* visitor closed the dialog) or `UNSUPPORTED`. Absent when the failure has
|
|
1961
|
+
* no code.
|
|
1962
|
+
*/
|
|
1963
|
+
code?: string;
|
|
1964
|
+
/** The HTTP status of a server refusal; 0 when there was no response. */
|
|
1965
|
+
status?: number;
|
|
1966
|
+
};
|
|
1967
|
+
|
|
1968
|
+
/** `WidgetContext.account.anonymous`: what a host provides for `useAnonymousAccount()`. */
|
|
1969
|
+
export interface AnonymousAccountHost {
|
|
1970
|
+
/** True only while nobody is signed in and no two-factor step is pending. */
|
|
1971
|
+
canCreate: boolean;
|
|
1972
|
+
/**
|
|
1973
|
+
* Opens the host's own dialog, which confirms, creates the account, shows
|
|
1974
|
+
* the login code and password once and signs the visitor in. The pair
|
|
1975
|
+
* never leaves that dialog.
|
|
1976
|
+
*/
|
|
1977
|
+
create(): Promise<{ created: true }>;
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1980
|
+
export interface AnonymousAccountApi {
|
|
1981
|
+
/** False where the host does not offer accounts without an email. */
|
|
1982
|
+
supported: boolean;
|
|
1983
|
+
/** True when `supported` and nobody is signed in. */
|
|
1984
|
+
canCreate: boolean;
|
|
1985
|
+
/** True while a `create()` call is in flight: the app's dialog is open. */
|
|
1986
|
+
creating: boolean;
|
|
1987
|
+
/** The last `create()` failure; cleared by the next attempt. */
|
|
1988
|
+
error: AnonymousAccountError | null;
|
|
1989
|
+
/**
|
|
1990
|
+
* Ask the app to create the account. Call it from a user action. The app
|
|
1991
|
+
* shows the login code and password itself; the widget never receives
|
|
1992
|
+
* them. Rejects with an `AnonymousAccountError`.
|
|
1993
|
+
*/
|
|
1994
|
+
create(): Promise<{ created: true }>;
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
/**
|
|
1998
|
+
* Offer an account that needs no email address: the server generates a
|
|
1999
|
+
* login code and a password, and the person signs in later with that pair.
|
|
2000
|
+
* The app confirms, shows the pair once and signs the visitor in, all in its
|
|
2001
|
+
* own dialog. Never throws at render: where the host does not offer it (the
|
|
2002
|
+
* workspace has it off, the Builder canvas, a preview, a badge counter)
|
|
2003
|
+
* `supported` is false and `create()` rejects with `code: "UNSUPPORTED"`.
|
|
2004
|
+
*/
|
|
2005
|
+
export function useAnonymousAccount(): AnonymousAccountApi;
|
|
2006
|
+
|
|
1950
2007
|
/**
|
|
1951
2008
|
* REQ-LAY-08 — returns `true` when the host has sized this widget to fill a
|
|
1952
2009
|
* box of definite height (a widget in the section a fit-to-screen page
|
package/dist/index.js
CHANGED
package/dist/index.native.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colixsystems/widget-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.220.0",
|
|
4
4
|
"description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
|
|
5
5
|
"homepage": "https://github.com/Colix-AB/AppStudio",
|
|
6
6
|
"type": "module",
|
package/src/contract.js
CHANGED
|
@@ -938,6 +938,38 @@ const HOOKS = [
|
|
|
938
938
|
requiredContextSlice: ["user", "account.setPhoto", "account.removePhoto"],
|
|
939
939
|
scopes: null,
|
|
940
940
|
},
|
|
941
|
+
{
|
|
942
|
+
name: "useAnonymousAccount",
|
|
943
|
+
signature: "useAnonymousAccount()",
|
|
944
|
+
description:
|
|
945
|
+
"Offer an account that needs NO email address: the server generates a login code and a password, and the person signs in " +
|
|
946
|
+
"later with that pair on the app's sign-in screen. For apps where a visitor must be able to act without identifying " +
|
|
947
|
+
"themselves and still come back (a whistleblower report). The widget ONLY ASKS: create() takes NO arguments and opens the APP'S " +
|
|
948
|
+
"OWN dialog, which asks the visitor to confirm, runs the captcha, creates the account, shows the login code and password " +
|
|
949
|
+
"ONCE with the warning that a lost password cannot be recovered, and signs the visitor in when they confirm they saved " +
|
|
950
|
+
"them (or opens the sign-in screen's two-factor step when the workspace requires one). The widget NEVER receives the " +
|
|
951
|
+
"login code or the password: create() resolves { created: true } and nothing else. Do NOT build your own confirmation, " +
|
|
952
|
+
"captcha notice or credentials screen, and never call an endpoint yourself. Call create() from a user action (a button's " +
|
|
953
|
+
"onPress), never on mount or in an effect. It rejects with an Error carrying code: the server's refusal " +
|
|
954
|
+
"(ANONYMOUS_ACCOUNT_LIMIT_REACHED, RATE_LIMITED, CAPTCHA_FAILED, …), CAPTCHA_UNAVAILABLE when the " +
|
|
955
|
+
"captcha could not run (there is no fallback), ALREADY_SIGNED_IN, CANCELLED when the visitor closes the dialog, or " +
|
|
956
|
+
"UNSUPPORTED. The dialog already shows a failure and lets the visitor retry, so a rejection means they gave up: treat " +
|
|
957
|
+
"CANCELLED as no error. supported is false — and create() rejects with UNSUPPORTED instead of the hook throwing at " +
|
|
958
|
+
"render — where the workspace has not turned anonymous accounts on, on the Builder canvas, in a preview pane, in a draft " +
|
|
959
|
+
"preview and for a badge counter: render a visible 'not available' state then. canCreate is false while someone is " +
|
|
960
|
+
"signed in: hide the button then. After create() resolves the visitor is signed in and the page re-renders, so read " +
|
|
961
|
+
"useUser() for the new state. Needs no scope. Identical on web (Player) and the Expo export.",
|
|
962
|
+
returnShape: {
|
|
963
|
+
supported: "boolean // the host offers anonymous accounts here",
|
|
964
|
+
canCreate: "boolean // supported AND nobody is signed in",
|
|
965
|
+
creating: "boolean // a create() call is in flight: the app's dialog is open",
|
|
966
|
+
error: "(Error & { code?: string, status?: number }) | null // the last create() failure; cleared by the next attempt",
|
|
967
|
+
create:
|
|
968
|
+
"() => Promise<{ created: true }> // takes no arguments; opens the app's dialog; never returns the login code or password",
|
|
969
|
+
},
|
|
970
|
+
requiredContextSlice: ["account.anonymous"],
|
|
971
|
+
scopes: null,
|
|
972
|
+
},
|
|
941
973
|
{
|
|
942
974
|
name: "useFill",
|
|
943
975
|
signature: "useFill()",
|
|
@@ -3561,26 +3593,31 @@ const WIDGET_CONTEXT_SHAPE = {
|
|
|
3561
3593
|
},
|
|
3562
3594
|
user: {
|
|
3563
3595
|
description:
|
|
3564
|
-
"Signed-in user, host-built context object (camelCase: { id, email, displayName, photoUrl, roles, groupIds }) — NOT a wire payload, so it is the one camelCase island among the hooks. photoUrl is the user's own profile photo as an absolute URL, or null. Not a data-client.",
|
|
3596
|
+
"Signed-in user, host-built context object (camelCase: { id, email, displayName, photoUrl, roles, groupIds }) — NOT a wire payload, so it is the one camelCase island among the hooks. photoUrl is the user's own profile photo as an absolute URL, or null. email is null for an account created without one. Not a data-client.",
|
|
3565
3597
|
required: true,
|
|
3566
3598
|
fields: {
|
|
3567
3599
|
id: "string",
|
|
3568
|
-
email: "string",
|
|
3600
|
+
email: "string | null",
|
|
3569
3601
|
displayName: "string",
|
|
3570
3602
|
photoUrl: "string | null",
|
|
3571
3603
|
},
|
|
3572
3604
|
},
|
|
3573
|
-
// Optional so a host
|
|
3574
|
-
// useUserPhoto() reports canEdit false when it is absent.
|
|
3605
|
+
// Optional, and so is every member: a host publishes only what it can do.
|
|
3575
3606
|
account: {
|
|
3576
3607
|
description:
|
|
3577
|
-
"Optional self-service account actions
|
|
3578
|
-
"{ setPhoto(file) -> Promise<{ photoUrl }>, removePhoto() -> Promise<{ photoUrl: null }> }
|
|
3579
|
-
"
|
|
3580
|
-
"widget. setPhoto takes a browser File on web and expo-file-system's File on native.
|
|
3581
|
-
"
|
|
3608
|
+
"Optional self-service account actions; every member is optional too. " +
|
|
3609
|
+
"{ setPhoto(file) -> Promise<{ photoUrl }>, removePhoto() -> Promise<{ photoUrl: null }> } back useUserPhoto() and are " +
|
|
3610
|
+
"present only while a user is signed in. The host performs the request AND updates its own session, so user.photoUrl " +
|
|
3611
|
+
"changes for every widget. setPhoto takes a browser File on web and expo-file-system's File on native. " +
|
|
3612
|
+
"anonymous backs useAnonymousAccount() and is present only where the workspace offers accounts without an email: " +
|
|
3613
|
+
"{ canCreate: boolean, create() -> Promise<{ created: true }> }. create() opens the HOST'S OWN dialog: " +
|
|
3614
|
+
"it asks the visitor to confirm, runs the captcha, calls the server, shows the login code and password once, and signs " +
|
|
3615
|
+
"the visitor in when they confirm they saved them. The pair lives only in that dialog and never reaches the slice, a " +
|
|
3616
|
+
"widget, an error or storage. " +
|
|
3617
|
+
"The whole slice is absent on the Builder canvas, in the preview panes and for a badge counter, where both hooks " +
|
|
3618
|
+
"degrade (canEdit: false, supported: false) rather than throwing.",
|
|
3582
3619
|
required: false,
|
|
3583
|
-
fields: { setPhoto: "function", removePhoto: "function" },
|
|
3620
|
+
fields: { setPhoto: "function", removePhoto: "function", anonymous: "object" },
|
|
3584
3621
|
},
|
|
3585
3622
|
workspace: {
|
|
3586
3623
|
description:
|
|
@@ -5808,7 +5845,14 @@ const CONTRACT = deepFreeze({
|
|
|
5808
5845
|
// new `ctx.filestore.signingRounds`. `useFileSignature` also returns
|
|
5809
5846
|
// `hintCode` and `nameRefusal`, and its `cancel()` resolves to what
|
|
5810
5847
|
// became of the order instead of always reporting "cancelled".
|
|
5811
|
-
|
|
5848
|
+
// 1.176.0: additive (sc-10934) — `useAnonymousAccount()` asks the host to
|
|
5849
|
+
// create an account with a generated login code and password and no
|
|
5850
|
+
// email, through the new optional `ctx.account.anonymous`
|
|
5851
|
+
// (`{ canCreate, create }`). The host shows the pair in its own dialog;
|
|
5852
|
+
// a widget never receives it. `account`'s photo actions are now
|
|
5853
|
+
// optional members, and `user.email` is documented as nullable: an
|
|
5854
|
+
// account without an email has none.
|
|
5855
|
+
version: "1.176.0",
|
|
5812
5856
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
5813
5857
|
hooks: HOOKS,
|
|
5814
5858
|
primitives: PRIMITIVES,
|