@colixsystems/widget-sdk 0.240.0 → 0.241.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
@@ -84,7 +84,18 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
84
84
 
85
85
  ## Status
86
86
 
87
- `v0.240.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**.
87
+ `v0.241.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.241.0 (contract 1.195.0)
90
+
91
+ **A signing round can include people without an account in the app.** `useSigningRound(fileId).prepare(signers)` takes, beside account ids, `{ name, email }` entries, mixed in the order of the places on the signature page. When the round is confirmed, each of those people is emailed a personal BankID signing link that is valid for 24 hours. Anyone who holds the link can sign, so tell the person sending the document before they send it. In the round a manager sees each place's `id`, `kind` (`"app_user"` or `"email"`), `email`, `signed_as` (the name BankID verified, which can differ from the name you entered) and, for an email place, `link`: `{ status, sent_at, expires_at, used_at, links_sent, can_resend }`, where `status` is `"sending"`, `"sent"`, `"delivery_failed"`, `"expired"`, `"used"` or `"cancelled"`. `resendLink(signerId, { email })` replaces the place's link with a new one (the old link stops working), sent to a corrected address when you pass one. Offer it only where `link.can_resend` is true. A refused signer's `errors` entry now carries `index`, its position in the list you sent, so you can mark the right entry. A new link sent too soon is refused with `SIGNING_LINK_RESEND_TOO_SOON` and a `retryAfter` in seconds. A list of account ids alone works exactly as before. **One type changes:** `SigningRoundSigner.app_user_id` widens from `string` to `string | null`, because an email place has no account; TypeScript code that read it as a string must check for null. `resendLink` needs `@colixsystems/filestore-client@0.14.0`; with an older client it is refused with code `NOT_SUPPORTED`.
92
+
93
+ ```jsx
94
+ const { round, prepare, resendLink } = useSigningRound(fileId);
95
+ await prepare(["user_1", { name: "Bo Ek", email: "bo@example.se" }]);
96
+ // later, for an email place whose link.can_resend is true:
97
+ await resendLink(place.id, { email: "bo.ek@example.se" });
98
+ ```
88
99
 
89
100
  ### What's new in 0.240.0 (contract 1.194.0)
90
101
 
package/dist/contract.cjs CHANGED
@@ -1747,15 +1747,27 @@ const HOOKS = [
1747
1747
  signature: "useSigningRound(fileId)",
1748
1748
  description:
1749
1749
  "One file's current signing round, and the actions of someone who " +
1750
- "manages the file's folder. prepare(signerIds) drafts a round for those " +
1751
- "users, their places on the signature page in the order given (take the " +
1752
- "ids from useFileRoster()); it can take " +
1750
+ "manages the file's folder. prepare(signers) drafts a round for those " +
1751
+ "people, their places on the signature page in the order given: each " +
1752
+ "entry is an account id from useFileRoster() (or { app_user_id }), or " +
1753
+ "{ name, email } for someone without an account, who is emailed a " +
1754
+ "personal BankID signing link valid for 24 hours once the round is " +
1755
+ "confirmed (anyone holding that link can sign, so say so before " +
1756
+ "sending); it can take " +
1753
1757
  "up to a minute. preparedFile() returns a five-minute link to the " +
1754
1758
  "prepared document; show it to the user before confirming. confirm() " +
1755
1759
  "opens the round for exactly the document preparedFile() last returned, " +
1756
1760
  "and rejects with code PREVIEW_REQUIRED when it was not called first. " +
1757
1761
  "cancel() ends a draft or an open round and resolves to the cancelled " +
1758
- "round (status 'CANCELLED'); round is then null. ONE ACTION RUNS AT A " +
1762
+ "round (status 'CANCELLED'); round is then null. " +
1763
+ "resendLink(signerId, { email }) replaces an email place's link with " +
1764
+ "a new one (the old one stops working), sent to the corrected email " +
1765
+ "when given, and resolves to the round; offer it only where the " +
1766
+ "place's link.can_resend is true. A manager sees each place's id, kind " +
1767
+ "('app_user' | 'email'), email, signed_as (the name BankID verified) " +
1768
+ "and link ({ status: 'sending' | 'sent' | 'delivery_failed' | " +
1769
+ "'expired' | 'used' | 'cancelled', sent_at, expires_at, used_at, " +
1770
+ "links_sent, can_resend }, null for an account place). ONE ACTION RUNS AT A " +
1759
1771
  "TIME: while busy is true any other action is refused at once with code " +
1760
1772
  "ACTION_IN_PROGRESS (it is not queued), so disable your buttons on busy. " +
1761
1773
  "round is the full round as the " +
@@ -1763,8 +1775,15 @@ const HOOKS = [
1763
1775
  "every signer's name and position and their own progress only, anyone " +
1764
1776
  "else sees null. A refused action sets error and rejects with it: code " +
1765
1777
  "and message come from the server (show message as it is), errors has " +
1766
- "one entry per refused signer ({ app_user_id, message, reason, " +
1767
- "characters }), retryAfter is the seconds to wait. The hook's own " +
1778
+ "one entry per refused signer ({ index, app_user_id, message, reason, " +
1779
+ "characters }; index is the entry's place in the list sent), " +
1780
+ "retryAfter is the seconds to wait. resendLink is refused with " +
1781
+ "SIGNING_LINK_RESEND_TOO_SOON (with retryAfter), " +
1782
+ "SIGNING_LINK_RESEND_IN_PROGRESS, SIGNING_LINK_LIMIT_REACHED, " +
1783
+ "SIGNING_LINK_BUDGET_EXCEEDED, SIGNING_LINK_PLATFORM_LIMIT, " +
1784
+ "INVALID_EMAIL, DUPLICATE_SIGNER, SIGNING_ROUND_NOT_OPEN, " +
1785
+ "SIGNING_ROUND_CLOSED or ALREADY_SIGNED, and by the hook itself with " +
1786
+ "NOT_SUPPORTED when the host's filestore client cannot send links. The hook's own " +
1768
1787
  "refusals (PREVIEW_REQUIRED, ACTION_IN_PROGRESS, NO_SIGNING_ROUND) carry " +
1769
1788
  "a message that can be shown the same way. When a refusal means the " +
1770
1789
  "round is no longer what was shown (it expired, was closed, or the " +
@@ -1776,14 +1795,16 @@ const HOOKS = [
1776
1795
  returnShape: {
1777
1796
  round:
1778
1797
  "{ id, file_id, status: 'DRAFT' | 'OPEN' | 'COMPLETED', created_at, confirmed_at, completed_at, expires_at, " +
1779
- "signers: { name, position, app_user_id?, signed?, signed_at?, signed_as? }[] } | null",
1798
+ "signers: { name, position, app_user_id?, signed?, signed_at?, signed_as?, id?, kind?: 'app_user' | 'email', email?, " +
1799
+ "link?: { status: 'sending' | 'sent' | 'delivery_failed' | 'expired' | 'used' | 'cancelled', sent_at, expires_at, used_at, links_sent, can_resend } | null }[] } | null",
1780
1800
  loading: "boolean",
1781
1801
  error: "PermissionError | null // { code, message, retryable, errors, retryAfter }",
1782
1802
  refresh: "() => Promise<void>",
1783
- prepare: "(signerIds: string[]) => Promise<round> // status 'DRAFT'",
1803
+ prepare: "(signers: (string | { app_user_id } | { name, email })[]) => Promise<round> // status 'DRAFT'",
1784
1804
  preparedFile: "() => Promise<{ url, sha256, expires_at, size_bytes }>",
1785
1805
  confirm: "() => Promise<round> // status 'OPEN'",
1786
1806
  cancel: "() => Promise<round> // the round it ended, status 'CANCELLED'",
1807
+ resendLink: "(signerId: string, options?: { email?: string }) => Promise<round> // a new link for an email place",
1787
1808
  busy: "boolean // an action is running; another one is refused with ACTION_IN_PROGRESS",
1788
1809
  },
1789
1810
  requiredContextSlice: ["filestore.signingRounds"],
@@ -3892,7 +3913,7 @@ const WIDGET_CONTEXT_SHAPE = {
3892
3913
  "{ files: { list(query) -> Promise<{ data, meta }>, get(id), upload(formData), update(id, body), copy(id, body), remove(id), preview(id) }, " +
3893
3914
  "folders: { list, create, update, remove }, shares: { ... }, trash: { ... }, " +
3894
3915
  "signatures: { list(fileIds), roster(fileId, query), initiate(fileId), status(id), cancel(id), verify(id) }, " +
3895
- "signingRounds: { overview(fileIds), list(fileId, query), get(roundId), prepare(fileId, signerIds), preparedFile(roundId), confirm(roundId, preparedSha256), cancel(roundId) }, " +
3916
+ "signingRounds: { overview(fileIds), list(fileId, query), get(roundId), prepare(fileId, signers), preparedFile(roundId), confirm(roundId, preparedSha256), cancel(roundId), resendLink(roundId, signerId, { email }) }, " +
3896
3917
  "objectUrl(token), fetchObject(token) }. " +
3897
3918
  "Backs useFilestoreFiles() + useFilestoreFolders() + useFilestoreCreateFolder() + useFilestoreCopy() + useFileSignature() + useFileSignatures() + useFileRoster() + useSigningRounds() + useSigningRound(). Optional — a host without an end-user filestore omits it and those hooks throw a clear error.",
3898
3919
  required: false,
@@ -6092,7 +6113,11 @@ const CONTRACT = deepFreeze({
6092
6113
  // `sectionRef` propertySchema type gives the author a section picker.
6093
6114
  // 1.194.0: more permissive (sc-11945) — a datastoreTemplate takes 100
6094
6115
  // tables, 200 columns, 100 rows per table, 20000 cells and 32 roles.
6095
- version: "1.194.0",
6116
+ // 1.195.0: additive (sc-11879) — `useSigningRound().prepare` takes
6117
+ // `{ name, email }` entries for signers without an account, and
6118
+ // `resendLink(signerId, { email })` sends such a signer a new link.
6119
+ // The manager's places carry id, kind, email and link.
6120
+ version: "1.195.0",
6096
6121
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6097
6122
  hooks: HOOKS,
6098
6123
  primitives: PRIMITIVES,
package/dist/contract.js CHANGED
@@ -1747,15 +1747,27 @@ const HOOKS = [
1747
1747
  signature: "useSigningRound(fileId)",
1748
1748
  description:
1749
1749
  "One file's current signing round, and the actions of someone who " +
1750
- "manages the file's folder. prepare(signerIds) drafts a round for those " +
1751
- "users, their places on the signature page in the order given (take the " +
1752
- "ids from useFileRoster()); it can take " +
1750
+ "manages the file's folder. prepare(signers) drafts a round for those " +
1751
+ "people, their places on the signature page in the order given: each " +
1752
+ "entry is an account id from useFileRoster() (or { app_user_id }), or " +
1753
+ "{ name, email } for someone without an account, who is emailed a " +
1754
+ "personal BankID signing link valid for 24 hours once the round is " +
1755
+ "confirmed (anyone holding that link can sign, so say so before " +
1756
+ "sending); it can take " +
1753
1757
  "up to a minute. preparedFile() returns a five-minute link to the " +
1754
1758
  "prepared document; show it to the user before confirming. confirm() " +
1755
1759
  "opens the round for exactly the document preparedFile() last returned, " +
1756
1760
  "and rejects with code PREVIEW_REQUIRED when it was not called first. " +
1757
1761
  "cancel() ends a draft or an open round and resolves to the cancelled " +
1758
- "round (status 'CANCELLED'); round is then null. ONE ACTION RUNS AT A " +
1762
+ "round (status 'CANCELLED'); round is then null. " +
1763
+ "resendLink(signerId, { email }) replaces an email place's link with " +
1764
+ "a new one (the old one stops working), sent to the corrected email " +
1765
+ "when given, and resolves to the round; offer it only where the " +
1766
+ "place's link.can_resend is true. A manager sees each place's id, kind " +
1767
+ "('app_user' | 'email'), email, signed_as (the name BankID verified) " +
1768
+ "and link ({ status: 'sending' | 'sent' | 'delivery_failed' | " +
1769
+ "'expired' | 'used' | 'cancelled', sent_at, expires_at, used_at, " +
1770
+ "links_sent, can_resend }, null for an account place). ONE ACTION RUNS AT A " +
1759
1771
  "TIME: while busy is true any other action is refused at once with code " +
1760
1772
  "ACTION_IN_PROGRESS (it is not queued), so disable your buttons on busy. " +
1761
1773
  "round is the full round as the " +
@@ -1763,8 +1775,15 @@ const HOOKS = [
1763
1775
  "every signer's name and position and their own progress only, anyone " +
1764
1776
  "else sees null. A refused action sets error and rejects with it: code " +
1765
1777
  "and message come from the server (show message as it is), errors has " +
1766
- "one entry per refused signer ({ app_user_id, message, reason, " +
1767
- "characters }), retryAfter is the seconds to wait. The hook's own " +
1778
+ "one entry per refused signer ({ index, app_user_id, message, reason, " +
1779
+ "characters }; index is the entry's place in the list sent), " +
1780
+ "retryAfter is the seconds to wait. resendLink is refused with " +
1781
+ "SIGNING_LINK_RESEND_TOO_SOON (with retryAfter), " +
1782
+ "SIGNING_LINK_RESEND_IN_PROGRESS, SIGNING_LINK_LIMIT_REACHED, " +
1783
+ "SIGNING_LINK_BUDGET_EXCEEDED, SIGNING_LINK_PLATFORM_LIMIT, " +
1784
+ "INVALID_EMAIL, DUPLICATE_SIGNER, SIGNING_ROUND_NOT_OPEN, " +
1785
+ "SIGNING_ROUND_CLOSED or ALREADY_SIGNED, and by the hook itself with " +
1786
+ "NOT_SUPPORTED when the host's filestore client cannot send links. The hook's own " +
1768
1787
  "refusals (PREVIEW_REQUIRED, ACTION_IN_PROGRESS, NO_SIGNING_ROUND) carry " +
1769
1788
  "a message that can be shown the same way. When a refusal means the " +
1770
1789
  "round is no longer what was shown (it expired, was closed, or the " +
@@ -1776,14 +1795,16 @@ const HOOKS = [
1776
1795
  returnShape: {
1777
1796
  round:
1778
1797
  "{ id, file_id, status: 'DRAFT' | 'OPEN' | 'COMPLETED', created_at, confirmed_at, completed_at, expires_at, " +
1779
- "signers: { name, position, app_user_id?, signed?, signed_at?, signed_as? }[] } | null",
1798
+ "signers: { name, position, app_user_id?, signed?, signed_at?, signed_as?, id?, kind?: 'app_user' | 'email', email?, " +
1799
+ "link?: { status: 'sending' | 'sent' | 'delivery_failed' | 'expired' | 'used' | 'cancelled', sent_at, expires_at, used_at, links_sent, can_resend } | null }[] } | null",
1780
1800
  loading: "boolean",
1781
1801
  error: "PermissionError | null // { code, message, retryable, errors, retryAfter }",
1782
1802
  refresh: "() => Promise<void>",
1783
- prepare: "(signerIds: string[]) => Promise<round> // status 'DRAFT'",
1803
+ prepare: "(signers: (string | { app_user_id } | { name, email })[]) => Promise<round> // status 'DRAFT'",
1784
1804
  preparedFile: "() => Promise<{ url, sha256, expires_at, size_bytes }>",
1785
1805
  confirm: "() => Promise<round> // status 'OPEN'",
1786
1806
  cancel: "() => Promise<round> // the round it ended, status 'CANCELLED'",
1807
+ resendLink: "(signerId: string, options?: { email?: string }) => Promise<round> // a new link for an email place",
1787
1808
  busy: "boolean // an action is running; another one is refused with ACTION_IN_PROGRESS",
1788
1809
  },
1789
1810
  requiredContextSlice: ["filestore.signingRounds"],
@@ -3888,7 +3909,7 @@ const WIDGET_CONTEXT_SHAPE = {
3888
3909
  "{ files: { list(query) -> Promise<{ data, meta }>, get(id), upload(formData), update(id, body), copy(id, body), remove(id), preview(id) }, " +
3889
3910
  "folders: { list, create, update, remove }, shares: { ... }, trash: { ... }, " +
3890
3911
  "signatures: { list(fileIds), roster(fileId, query), initiate(fileId), status(id), cancel(id), verify(id) }, " +
3891
- "signingRounds: { overview(fileIds), list(fileId, query), get(roundId), prepare(fileId, signerIds), preparedFile(roundId), confirm(roundId, preparedSha256), cancel(roundId) }, " +
3912
+ "signingRounds: { overview(fileIds), list(fileId, query), get(roundId), prepare(fileId, signers), preparedFile(roundId), confirm(roundId, preparedSha256), cancel(roundId), resendLink(roundId, signerId, { email }) }, " +
3892
3913
  "objectUrl(token), fetchObject(token) }. " +
3893
3914
  "Backs useFilestoreFiles() + useFilestoreFolders() + useFilestoreCreateFolder() + useFilestoreCopy() + useFileSignature() + useFileSignatures() + useFileRoster() + useSigningRounds() + useSigningRound(). Optional — a host without an end-user filestore omits it and those hooks throw a clear error.",
3894
3915
  required: false,
@@ -6088,7 +6109,11 @@ const CONTRACT = deepFreeze({
6088
6109
  // `sectionRef` propertySchema type gives the author a section picker.
6089
6110
  // 1.194.0: more permissive (sc-11945) — a datastoreTemplate takes 100
6090
6111
  // tables, 200 columns, 100 rows per table, 20000 cells and 32 roles.
6091
- version: "1.194.0",
6112
+ // 1.195.0: additive (sc-11879) — `useSigningRound().prepare` takes
6113
+ // `{ name, email }` entries for signers without an account, and
6114
+ // `resendLink(signerId, { email })` sends such a signer a new link.
6115
+ // The manager's places carry id, kind, email and link.
6116
+ version: "1.195.0",
6092
6117
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6093
6118
  hooks: HOOKS,
6094
6119
  primitives: PRIMITIVES,
package/dist/index.d.ts CHANGED
@@ -5111,6 +5111,9 @@ export interface SigningRefusalEntry {
5111
5111
  field?: string;
5112
5112
  message: string;
5113
5113
  code?: string;
5114
+ /** The entry's place in the list of signers that was sent. */
5115
+ index?: number;
5116
+ /** Set when the entry names an account. */
5114
5117
  app_user_id?: string;
5115
5118
  reason?: SignatureNameRefusal["reason"];
5116
5119
  characters?: string[];
@@ -5171,14 +5174,43 @@ export function useSigningRounds(fileIds: string[] | null | undefined): {
5171
5174
  export interface SigningRoundSigner {
5172
5175
  name: string;
5173
5176
  position: number;
5174
- /** Present for every place when the user manages the folder; otherwise for their own place only. */
5175
- app_user_id?: string;
5177
+ /**
5178
+ * Present for every place when the user manages the folder; otherwise for
5179
+ * their own place only. Null for a place held by someone without an account.
5180
+ */
5181
+ app_user_id?: string | null;
5176
5182
  signed?: boolean;
5177
5183
  signed_at?: string | null;
5178
5184
  /** The name BankID verified on this place. Managers only. */
5179
5185
  signed_as?: string | null;
5186
+ /** The place, as `resendLink` names it. Managers only. */
5187
+ id?: string;
5188
+ /** Who holds the place: an account, or someone signing through an emailed link. Managers only. */
5189
+ kind?: "app_user" | "email";
5190
+ /** An email place's address; null once the round has closed. Managers only. */
5191
+ email?: string | null;
5192
+ /** An email place's current link; null for an account place. Managers only. */
5193
+ link?: SigningRoundSignerLink | null;
5194
+ }
5195
+
5196
+ export interface SigningRoundSignerLink {
5197
+ status: "sending" | "sent" | "delivery_failed" | "expired" | "used" | "cancelled";
5198
+ sent_at: string | null;
5199
+ expires_at: string | null;
5200
+ used_at: string | null;
5201
+ links_sent: number;
5202
+ /** A new link may be sent now. */
5203
+ can_resend: boolean;
5180
5204
  }
5181
5205
 
5206
+ /**
5207
+ * One signer to prepare, in the order of the places: an account id (or
5208
+ * `{ app_user_id }`), or someone without an account, who is emailed a
5209
+ * personal signing link valid for 24 hours when the round is confirmed.
5210
+ * Anyone holding that link can sign.
5211
+ */
5212
+ export type SigningRoundSignerInput = string | { app_user_id: string } | { name: string; email: string };
5213
+
5182
5214
  export interface SigningRound {
5183
5215
  id: string;
5184
5216
  file_id: string;
@@ -5221,13 +5253,25 @@ export function useSigningRound(fileId: string | null | undefined): {
5221
5253
  loading: boolean;
5222
5254
  error: SigningRoundError | null;
5223
5255
  refresh(): Promise<void>;
5224
- /** `signerIds` in the order their places appear on the signature page. Resolves to the DRAFT. */
5225
- prepare(signerIds: string[]): Promise<SigningRound>;
5256
+ /** `signers` in the order their places appear on the signature page. Resolves to the DRAFT. */
5257
+ prepare(signers: SigningRoundSignerInput[]): Promise<SigningRound>;
5226
5258
  preparedFile(): Promise<SigningRoundPreparedFile>;
5227
5259
  /** Resolves to the OPEN round. */
5228
5260
  confirm(): Promise<SigningRound>;
5229
5261
  /** Resolves to the round it ended, with status "CANCELLED". */
5230
5262
  cancel(): Promise<SigningRound>;
5263
+ /**
5264
+ * Replace an email place's link with a new one, sent to `email` when given
5265
+ * (a corrected address). Offer it only where `link.can_resend` is true.
5266
+ * Resolves to the round. Refusals: `SIGNING_LINK_RESEND_TOO_SOON` (with
5267
+ * `retryAfter`), `SIGNING_LINK_RESEND_IN_PROGRESS`,
5268
+ * `SIGNING_LINK_LIMIT_REACHED`, `SIGNING_LINK_BUDGET_EXCEEDED`,
5269
+ * `SIGNING_LINK_PLATFORM_LIMIT`, `INVALID_EMAIL`, `DUPLICATE_SIGNER`,
5270
+ * `SIGNING_ROUND_NOT_OPEN`, `SIGNING_ROUND_CLOSED`, `ALREADY_SIGNED`, and
5271
+ * the hook's own `NOT_SUPPORTED` when the host's filestore client predates
5272
+ * sending links.
5273
+ */
5274
+ resendLink(signerId: string, options?: { email?: string }): Promise<SigningRound>;
5231
5275
  /** An action is running; another one is refused with `ACTION_IN_PROGRESS`. */
5232
5276
  busy: boolean;
5233
5277
  };
@@ -15,11 +15,13 @@ import {
15
15
  indexOverview,
16
16
  readRefusalDetail,
17
17
  reportedRoundId,
18
+ resendLinkOptions,
18
19
  roundChangedUnderneath,
19
20
  signOrderStateAfterAnswer,
20
21
  signOrderStateAfterCancel,
21
22
  signOrderStateAfterInitiate,
22
23
  signedOrderState,
24
+ signerListForPrepare,
23
25
  uniqueFileIds,
24
26
  } from "./signing-state.js";
25
27
 
@@ -209,6 +211,10 @@ const previewRequired = () =>
209
211
  const actionInProgress = () =>
210
212
  localRefusal("ACTION_IN_PROGRESS", "Another change to this signing round is still in progress. Try again in a moment.");
211
213
  const noFile = () => localRefusal("VALIDATION", "Choose a document first.");
214
+ const noResend = () =>
215
+ localRefusal("NOT_SUPPORTED", "Sending a new link is not available in this version of the app.");
216
+ const badSignerList = () =>
217
+ localRefusal("VALIDATION", "Each signer needs to be a person in the app, or a name and an email address.");
212
218
 
213
219
  function signingRoundsClientOrThrow(ctx, hookName) {
214
220
  const rounds = ctx.filestore && ctx.filestore.signingRounds;
@@ -289,19 +295,24 @@ export function useSigningRounds(fileIds) {
289
295
  /**
290
296
  * One file's current signing round and the actions of whoever manages the
291
297
  * file's folder. Returns `{ round, loading, error, refresh, prepare,
292
- * preparedFile, confirm, cancel, busy }`.
298
+ * preparedFile, confirm, cancel, resendLink, busy }`.
293
299
  *
294
- * `prepare(signerIds)` drafts a round for those people, in the order their
295
- * places appear on the signature page; `preparedFile()` answers `{ url,
296
- * sha256, expires_at, size_bytes }` for the draft's document; `confirm()`
297
- * opens the round for the document that `preparedFile()` last returned, so it
298
- * needs no argument; `cancel()` ends a draft or an open round and resolves to
299
- * the cancelled round. One action runs at a time: while `busy` is true another
300
- * one is refused with code `ACTION_IN_PROGRESS`, never queued. A refused
301
- * action sets `error` and rejects with it: `code` and `message` come from the
302
- * server, `errors` has one entry per refused signer, `retryAfter` is the
303
- * seconds to wait. When the refusal means the round is no longer what was
304
- * shown, the round is read again.
300
+ * `prepare(signers)` drafts a round for those people, in the order their
301
+ * places appear on the signature page: each is an account id (or
302
+ * `{ app_user_id }`), or `{ name, email }` for someone without an account,
303
+ * who is emailed a 24-hour signing link once the round is confirmed;
304
+ * `preparedFile()` answers `{ url, sha256, expires_at, size_bytes }` for the
305
+ * draft's document; `confirm()` opens the round for the document that
306
+ * `preparedFile()` last returned, so it needs no argument; `cancel()` ends a
307
+ * draft or an open round and resolves to the cancelled round;
308
+ * `resendLink(signerId, { email })` replaces an email place's link with a new
309
+ * one, sent to the corrected address when given. One action runs at a time:
310
+ * while `busy` is true another one is refused with code `ACTION_IN_PROGRESS`,
311
+ * never queued. A refused action sets `error` and rejects with it: `code` and
312
+ * `message` come from the server, `errors` has one entry per refused signer
313
+ * (with `index`, its place in the list sent), `retryAfter` is the seconds to
314
+ * wait. When the refusal means the round is no longer what was shown, the
315
+ * round is read again.
305
316
  */
306
317
  export function useSigningRound(fileId) {
307
318
  const ctx = useWidgetContextOrThrow("useSigningRound");
@@ -395,10 +406,12 @@ export function useSigningRound(fileId) {
395
406
  );
396
407
 
397
408
  const prepare = useCallback(
398
- (signerIds) =>
409
+ (signers) =>
399
410
  run(async (rounds, _round, forFile) => {
400
411
  if (!forFile) throw noFile();
401
- const draft = await rounds.prepare(forFile, signerIds);
412
+ const list = signerListForPrepare(signers);
413
+ if (!list) throw badSignerList();
414
+ const draft = await rounds.prepare(forFile, list);
402
415
  return { value: draft, round: draft };
403
416
  }),
404
417
  [run],
@@ -438,6 +451,18 @@ export function useSigningRound(fileId) {
438
451
  [run],
439
452
  );
440
453
 
454
+ const resendLink = useCallback(
455
+ (signerId, options) =>
456
+ run(async (rounds, round) => {
457
+ if (!round) throw noRound();
458
+ // A filestore client older than 0.14.0 has no resendLink.
459
+ if (typeof rounds.resendLink !== "function") throw noResend();
460
+ const resent = await rounds.resendLink(round.id, signerId, resendLinkOptions(options));
461
+ return { value: resent, round: resent };
462
+ }),
463
+ [run],
464
+ );
465
+
441
466
  return {
442
467
  round: current.round,
443
468
  loading: Boolean(fileId) && (!current.settled || reading),
@@ -447,6 +472,7 @@ export function useSigningRound(fileId) {
447
472
  preparedFile,
448
473
  confirm,
449
474
  cancel,
475
+ resendLink,
450
476
  busy,
451
477
  };
452
478
  }
@@ -71,8 +71,9 @@ export function signOrderStateAfterCancel(previous, answer) {
71
71
 
72
72
  /**
73
73
  * The parts of a refusal a widget shows beside its message, as the filestore
74
- * client put them on its error: one entry per refused signer (`app_user_id`,
75
- * `message`, and for a name `reason` and `characters`), and how many seconds
74
+ * client put them on its error: one entry per refused signer (`index`, its
75
+ * place in the list that was sent, `app_user_id` for an account, `message`,
76
+ * and for a name `reason` and `characters`), and how many seconds
76
77
  * to wait before trying again. An error from anywhere else has neither.
77
78
  */
78
79
  export function readRefusalDetail(err) {
@@ -81,6 +82,39 @@ export function readRefusalDetail(err) {
81
82
  return { errors, retryAfter: typeof wait === "number" && Number.isFinite(wait) && wait >= 0 ? wait : null };
82
83
  }
83
84
 
85
+ const nonEmptyString = (value) => typeof value === "string" && value.trim() !== "";
86
+ const isObject = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
87
+
88
+ /** One prepare entry as the filestore client takes it, or null when it is neither form. */
89
+ function signerForPrepare(signer) {
90
+ if (nonEmptyString(signer)) return signer;
91
+ if (!isObject(signer)) return null;
92
+ const keys = Object.keys(signer).sort().join(",");
93
+ if (keys === "app_user_id" && nonEmptyString(signer.app_user_id)) return signer.app_user_id;
94
+ if (keys === "email,name" && nonEmptyString(signer.name) && nonEmptyString(signer.email)) {
95
+ return { name: signer.name.trim(), email: signer.email.trim() };
96
+ }
97
+ return null;
98
+ }
99
+
100
+ /**
101
+ * The signers of a prepare, in their order, as the filestore client takes
102
+ * them: an account as its id (a list of ids alone keeps the request older
103
+ * servers read), someone without an account as `{ name, email }` trimmed.
104
+ * Null when an entry is neither an id, `{ app_user_id }` nor `{ name, email }`.
105
+ */
106
+ export function signerListForPrepare(signers) {
107
+ if (!Array.isArray(signers)) return null;
108
+ const list = signers.map(signerForPrepare);
109
+ return list.includes(null) ? null : list;
110
+ }
111
+
112
+ /** The body of a new link: a corrected `email` when one is given, otherwise nothing. */
113
+ export function resendLinkOptions(options) {
114
+ const email = isObject(options) && typeof options.email === "string" ? options.email.trim() : "";
115
+ return email ? { email } : {};
116
+ }
117
+
84
118
  // The round is no longer what the widget is showing: read it again.
85
119
  const ROUND_CHANGED_CODES = new Set([
86
120
  "SIGNING_ROUND_EXPIRED",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colixsystems/widget-sdk",
3
- "version": "0.240.0",
3
+ "version": "0.241.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
@@ -1747,15 +1747,27 @@ const HOOKS = [
1747
1747
  signature: "useSigningRound(fileId)",
1748
1748
  description:
1749
1749
  "One file's current signing round, and the actions of someone who " +
1750
- "manages the file's folder. prepare(signerIds) drafts a round for those " +
1751
- "users, their places on the signature page in the order given (take the " +
1752
- "ids from useFileRoster()); it can take " +
1750
+ "manages the file's folder. prepare(signers) drafts a round for those " +
1751
+ "people, their places on the signature page in the order given: each " +
1752
+ "entry is an account id from useFileRoster() (or { app_user_id }), or " +
1753
+ "{ name, email } for someone without an account, who is emailed a " +
1754
+ "personal BankID signing link valid for 24 hours once the round is " +
1755
+ "confirmed (anyone holding that link can sign, so say so before " +
1756
+ "sending); it can take " +
1753
1757
  "up to a minute. preparedFile() returns a five-minute link to the " +
1754
1758
  "prepared document; show it to the user before confirming. confirm() " +
1755
1759
  "opens the round for exactly the document preparedFile() last returned, " +
1756
1760
  "and rejects with code PREVIEW_REQUIRED when it was not called first. " +
1757
1761
  "cancel() ends a draft or an open round and resolves to the cancelled " +
1758
- "round (status 'CANCELLED'); round is then null. ONE ACTION RUNS AT A " +
1762
+ "round (status 'CANCELLED'); round is then null. " +
1763
+ "resendLink(signerId, { email }) replaces an email place's link with " +
1764
+ "a new one (the old one stops working), sent to the corrected email " +
1765
+ "when given, and resolves to the round; offer it only where the " +
1766
+ "place's link.can_resend is true. A manager sees each place's id, kind " +
1767
+ "('app_user' | 'email'), email, signed_as (the name BankID verified) " +
1768
+ "and link ({ status: 'sending' | 'sent' | 'delivery_failed' | " +
1769
+ "'expired' | 'used' | 'cancelled', sent_at, expires_at, used_at, " +
1770
+ "links_sent, can_resend }, null for an account place). ONE ACTION RUNS AT A " +
1759
1771
  "TIME: while busy is true any other action is refused at once with code " +
1760
1772
  "ACTION_IN_PROGRESS (it is not queued), so disable your buttons on busy. " +
1761
1773
  "round is the full round as the " +
@@ -1763,8 +1775,15 @@ const HOOKS = [
1763
1775
  "every signer's name and position and their own progress only, anyone " +
1764
1776
  "else sees null. A refused action sets error and rejects with it: code " +
1765
1777
  "and message come from the server (show message as it is), errors has " +
1766
- "one entry per refused signer ({ app_user_id, message, reason, " +
1767
- "characters }), retryAfter is the seconds to wait. The hook's own " +
1778
+ "one entry per refused signer ({ index, app_user_id, message, reason, " +
1779
+ "characters }; index is the entry's place in the list sent), " +
1780
+ "retryAfter is the seconds to wait. resendLink is refused with " +
1781
+ "SIGNING_LINK_RESEND_TOO_SOON (with retryAfter), " +
1782
+ "SIGNING_LINK_RESEND_IN_PROGRESS, SIGNING_LINK_LIMIT_REACHED, " +
1783
+ "SIGNING_LINK_BUDGET_EXCEEDED, SIGNING_LINK_PLATFORM_LIMIT, " +
1784
+ "INVALID_EMAIL, DUPLICATE_SIGNER, SIGNING_ROUND_NOT_OPEN, " +
1785
+ "SIGNING_ROUND_CLOSED or ALREADY_SIGNED, and by the hook itself with " +
1786
+ "NOT_SUPPORTED when the host's filestore client cannot send links. The hook's own " +
1768
1787
  "refusals (PREVIEW_REQUIRED, ACTION_IN_PROGRESS, NO_SIGNING_ROUND) carry " +
1769
1788
  "a message that can be shown the same way. When a refusal means the " +
1770
1789
  "round is no longer what was shown (it expired, was closed, or the " +
@@ -1776,14 +1795,16 @@ const HOOKS = [
1776
1795
  returnShape: {
1777
1796
  round:
1778
1797
  "{ id, file_id, status: 'DRAFT' | 'OPEN' | 'COMPLETED', created_at, confirmed_at, completed_at, expires_at, " +
1779
- "signers: { name, position, app_user_id?, signed?, signed_at?, signed_as? }[] } | null",
1798
+ "signers: { name, position, app_user_id?, signed?, signed_at?, signed_as?, id?, kind?: 'app_user' | 'email', email?, " +
1799
+ "link?: { status: 'sending' | 'sent' | 'delivery_failed' | 'expired' | 'used' | 'cancelled', sent_at, expires_at, used_at, links_sent, can_resend } | null }[] } | null",
1780
1800
  loading: "boolean",
1781
1801
  error: "PermissionError | null // { code, message, retryable, errors, retryAfter }",
1782
1802
  refresh: "() => Promise<void>",
1783
- prepare: "(signerIds: string[]) => Promise<round> // status 'DRAFT'",
1803
+ prepare: "(signers: (string | { app_user_id } | { name, email })[]) => Promise<round> // status 'DRAFT'",
1784
1804
  preparedFile: "() => Promise<{ url, sha256, expires_at, size_bytes }>",
1785
1805
  confirm: "() => Promise<round> // status 'OPEN'",
1786
1806
  cancel: "() => Promise<round> // the round it ended, status 'CANCELLED'",
1807
+ resendLink: "(signerId: string, options?: { email?: string }) => Promise<round> // a new link for an email place",
1787
1808
  busy: "boolean // an action is running; another one is refused with ACTION_IN_PROGRESS",
1788
1809
  },
1789
1810
  requiredContextSlice: ["filestore.signingRounds"],
@@ -3888,7 +3909,7 @@ const WIDGET_CONTEXT_SHAPE = {
3888
3909
  "{ files: { list(query) -> Promise<{ data, meta }>, get(id), upload(formData), update(id, body), copy(id, body), remove(id), preview(id) }, " +
3889
3910
  "folders: { list, create, update, remove }, shares: { ... }, trash: { ... }, " +
3890
3911
  "signatures: { list(fileIds), roster(fileId, query), initiate(fileId), status(id), cancel(id), verify(id) }, " +
3891
- "signingRounds: { overview(fileIds), list(fileId, query), get(roundId), prepare(fileId, signerIds), preparedFile(roundId), confirm(roundId, preparedSha256), cancel(roundId) }, " +
3912
+ "signingRounds: { overview(fileIds), list(fileId, query), get(roundId), prepare(fileId, signers), preparedFile(roundId), confirm(roundId, preparedSha256), cancel(roundId), resendLink(roundId, signerId, { email }) }, " +
3892
3913
  "objectUrl(token), fetchObject(token) }. " +
3893
3914
  "Backs useFilestoreFiles() + useFilestoreFolders() + useFilestoreCreateFolder() + useFilestoreCopy() + useFileSignature() + useFileSignatures() + useFileRoster() + useSigningRounds() + useSigningRound(). Optional — a host without an end-user filestore omits it and those hooks throw a clear error.",
3894
3915
  required: false,
@@ -6088,7 +6109,11 @@ const CONTRACT = deepFreeze({
6088
6109
  // `sectionRef` propertySchema type gives the author a section picker.
6089
6110
  // 1.194.0: more permissive (sc-11945) — a datastoreTemplate takes 100
6090
6111
  // tables, 200 columns, 100 rows per table, 20000 cells and 32 roles.
6091
- version: "1.194.0",
6112
+ // 1.195.0: additive (sc-11879) — `useSigningRound().prepare` takes
6113
+ // `{ name, email }` entries for signers without an account, and
6114
+ // `resendLink(signerId, { email })` sends such a signer a new link.
6115
+ // The manager's places carry id, kind, email and link.
6116
+ version: "1.195.0",
6092
6117
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6093
6118
  hooks: HOOKS,
6094
6119
  primitives: PRIMITIVES,