@flipstream/sdk 0.10.1 → 0.12.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.
Files changed (94) hide show
  1. package/CHANGELOG.md +75 -0
  2. package/README.md +98 -348
  3. package/dist/api/account.d.ts +50 -0
  4. package/dist/api/account.js +102 -0
  5. package/dist/api/account.js.map +1 -0
  6. package/dist/api/backend.d.ts +18 -0
  7. package/dist/api/backend.js +35 -4
  8. package/dist/api/backend.js.map +1 -1
  9. package/dist/api/created.d.ts +1 -1
  10. package/dist/api/created.js +3 -2
  11. package/dist/api/created.js.map +1 -1
  12. package/dist/api/credentials.js +4 -4
  13. package/dist/api/credentials.js.map +1 -1
  14. package/dist/api/datasets.d.ts +94 -14
  15. package/dist/api/datasets.js +210 -59
  16. package/dist/api/datasets.js.map +1 -1
  17. package/dist/api/index.d.ts +4 -3
  18. package/dist/api/log.d.ts +45 -24
  19. package/dist/api/log.js +113 -40
  20. package/dist/api/log.js.map +1 -1
  21. package/dist/api/me.d.ts +2 -0
  22. package/dist/api/me.js +9 -5
  23. package/dist/api/me.js.map +1 -1
  24. package/dist/api/members.d.ts +69 -7
  25. package/dist/api/members.js +110 -32
  26. package/dist/api/members.js.map +1 -1
  27. package/dist/api/time.js +4 -3
  28. package/dist/api/time.js.map +1 -1
  29. package/dist/api/wallet.d.ts +8 -5
  30. package/dist/api/wallet.js +36 -24
  31. package/dist/api/wallet.js.map +1 -1
  32. package/dist/api/workspaces.d.ts +42 -7
  33. package/dist/api/workspaces.js +80 -20
  34. package/dist/api/workspaces.js.map +1 -1
  35. package/dist/auth/discovery.d.ts +19 -6
  36. package/dist/auth/discovery.js +25 -4
  37. package/dist/auth/discovery.js.map +1 -1
  38. package/dist/auth/signIn.d.ts +18 -14
  39. package/dist/auth/signIn.js +29 -22
  40. package/dist/auth/signIn.js.map +1 -1
  41. package/dist/core/call.d.ts +4 -1
  42. package/dist/core/call.js +26 -6
  43. package/dist/core/call.js.map +1 -1
  44. package/dist/core/deadline.d.ts +30 -0
  45. package/dist/core/deadline.js +51 -0
  46. package/dist/core/deadline.js.map +1 -0
  47. package/dist/core/invalid.d.ts +7 -0
  48. package/dist/core/invalid.js +22 -0
  49. package/dist/core/invalid.js.map +1 -0
  50. package/dist/core/names.d.ts +31 -3
  51. package/dist/core/names.js +26 -6
  52. package/dist/core/names.js.map +1 -1
  53. package/dist/core/notFound.d.ts +8 -0
  54. package/dist/core/notFound.js +8 -0
  55. package/dist/core/notFound.js.map +1 -0
  56. package/dist/core/result.d.ts +17 -12
  57. package/dist/core/result.js +5 -5
  58. package/dist/core/result.js.map +1 -1
  59. package/dist/core/retry.d.ts +5 -2
  60. package/dist/core/retry.js +6 -3
  61. package/dist/core/retry.js.map +1 -1
  62. package/dist/core/scope.d.ts +20 -0
  63. package/dist/core/scope.js +54 -0
  64. package/dist/core/scope.js.map +1 -0
  65. package/dist/flipstream.d.ts +151 -70
  66. package/dist/flipstream.js +67 -45
  67. package/dist/flipstream.js.map +1 -1
  68. package/dist/node/clientSecret.js +5 -5
  69. package/dist/node/clientSecret.js.map +1 -1
  70. package/dist/node/headless.d.ts +14 -6
  71. package/dist/node/headless.js +8 -6
  72. package/dist/node/headless.js.map +1 -1
  73. package/dist/node/index.d.ts +1 -1
  74. package/dist/node/index.js +1 -1
  75. package/dist/node/index.js.map +1 -1
  76. package/dist/node/keychainChild.js +27 -10
  77. package/dist/node/keychainChild.js.map +1 -1
  78. package/dist/node/keychainError.d.ts +3 -3
  79. package/dist/node/keychainStore.d.ts +16 -12
  80. package/dist/node/keychainStore.js +50 -28
  81. package/dist/node/keychainStore.js.map +1 -1
  82. package/dist/node/loopback.d.ts +8 -1
  83. package/dist/node/loopback.js +19 -2
  84. package/dist/node/loopback.js.map +1 -1
  85. package/dist/node/session.d.ts +17 -9
  86. package/dist/node/session.js +55 -44
  87. package/dist/node/session.js.map +1 -1
  88. package/dist/node/store.d.ts +35 -2
  89. package/dist/node/store.js +56 -12
  90. package/dist/node/store.js.map +1 -1
  91. package/dist/version.gen.js +1 -1
  92. package/docs/admin.md +503 -0
  93. package/docs/node-sign-in.md +60 -35
  94. package/package.json +1 -1
@@ -1,16 +1,49 @@
1
1
  import { z } from 'zod';
2
+ import { parseJson } from '../core/body.js';
3
+ import { invalidAnswer, invalidStatusUnknown } from '../core/invalid.js';
4
+ import { notFound } from '../core/notFound.js';
2
5
  import { needsPerson, zHandOffOrganization } from './handoff.js';
3
6
  import { sameUuid } from './ids.js';
7
+ import { readUser } from './me.js';
8
+ import { opensWorkspace } from './members.js';
4
9
  import { pageQuery } from './page.js';
5
10
  import { unsent } from './unsent.js';
6
11
  const id = z.string().min(1);
12
+ // #291: the console's own rule, os's servicesFrom (packages/platform/auth/src/core/services.ts, at
13
+ // os 3a6990c3), mirrored rule for rule, so an app and the console never disagree. `meta` is JSON in
14
+ // a string; an empty one, or one with no `cloud`, has nothing on; one that isn't JSON, isn't an
15
+ // object, or whose `cloud` fails this shape can't be read. `v` and any other key are ignored.
16
+ const zCloud = z.looseObject({ services: z.record(z.string(), z.looseObject({ on: z.boolean() })).optional() });
17
+ /**
18
+ * The services on in a workspace, from its `meta`, as servicesFrom reads it. A `meta` left out is
19
+ * `''`, as os's zClient defaults it. One part from os: zClient types `meta` as a string, so one that
20
+ * isn't fails the whole workspace there; here the workspace still reads, and its services are
21
+ * unreadable. Each answer is a new object, so no caller's change to one reaches another.
22
+ */
23
+ function servicesOf(meta = '') {
24
+ if (typeof meta !== 'string')
25
+ return { status: 'unreadable' };
26
+ const parsed = meta.trim() === '' ? { ok: true, value: {} } : parseJson(meta);
27
+ if (!parsed.ok)
28
+ return { status: 'unreadable' };
29
+ const json = parsed.value;
30
+ if (typeof json !== 'object' || json === null || Array.isArray(json))
31
+ return { status: 'unreadable' };
32
+ if (!('cloud' in json))
33
+ return { status: 'known', on: [] };
34
+ const cloud = zCloud.safeParse(json.cloud);
35
+ if (!cloud.success)
36
+ return { status: 'unreadable' };
37
+ return { status: 'known', on: Object.entries(cloud.data.services ?? {}).flatMap(([key, service]) => (service.on ? [key] : [])) };
38
+ }
7
39
  // A workspace as read, with the organisation it's in, so a record of another one is caught; the
8
- // public Workspace drops it. An object schema keeps only the fields it names, so `meta`,
9
- // `settings`, `account_id` and the embedded `organization` and `owner` never reach a caller.
10
- const zRecord = z.object({ id, name: z.string(), slug: z.string(), organization_id: id });
40
+ // public Workspace drops it. An object schema keeps only the fields it names, so `settings`,
41
+ // `account_id` and the embedded `organization` and `owner` never reach a caller. `meta` is kept as
42
+ // it came, and only the public Workspace reads its services (#291), so a read of a workspace for
43
+ // another call's sake (readOwnWorkspace) never parses it.
44
+ const zRecord = z.object({ id, name: z.string(), slug: z.string(), organization_id: id, meta: z.unknown().optional() });
11
45
  const zOrganizationId = z.object({ id });
12
- const publicOf = ({ id: workspaceId, name, slug }) => ({ id: workspaceId, name, slug });
13
- const invalid = (issues) => ({ ok: false, error: { kind: 'invalid', issues } });
46
+ const publicOf = ({ id: workspaceId, name, slug, meta }) => ({ id: workspaceId, name, slug, services: servicesOf(meta) });
14
47
  /**
15
48
  * `flipstream.workspaces.list()`: one page of your organisation's workspaces. Your organisation is
16
49
  * read first, every time, with no cache, for its id. A workspace of another organisation makes the
@@ -27,9 +60,9 @@ export async function readWorkspaces(seam, read, page) {
27
60
  if (!organization.ok)
28
61
  return organization;
29
62
  const ours = organization.data.id;
30
- const spec = seam.workspacesOf(ours, sent, zRecord, (workspace) => workspace.organization_id === ours);
63
+ const spec = seam.workspacesOf(ours, sent, zRecord, (workspace) => sameUuid(workspace.organization_id, ours));
31
64
  if (spec === null)
32
- return invalid("the organisation's id can't name its workspaces");
65
+ return invalidAnswer("the organisation's id can't name its workspaces");
33
66
  const listed = await read(spec);
34
67
  return listed.ok ? { ok: true, data: { ...listed.data, items: listed.data.items.map(publicOf) } } : listed;
35
68
  }
@@ -60,33 +93,59 @@ export async function createWorkspace(seam, send, request) {
60
93
  if (!made.ok)
61
94
  return made;
62
95
  if (!sameUuid(made.data.organization_id, organization.data.id))
63
- return invalid("the workspace made is another organisation's");
96
+ return invalidStatusUnknown("the workspace made is another organisation's");
64
97
  return { ok: true, data: publicOf(made.data) };
65
98
  }
99
+ // pulse-admin's own 404 for a workspace nobody has, as recorded (test/recorded/admin/error-404.json;
100
+ // dff6bf9b, domain/client/__init__.py:122-129): a workspace you don't open answers exactly this, so it
101
+ // says no more than one nobody has (D571, #372).
102
+ const noSuchWorkspace = () => notFound('CLIENT_NOT_FOUND', 'Client not found!');
66
103
  /**
67
- * One of your organisation's workspaces, read beside your organisation. A workspace of another
68
- * organisation is invalid, as a staff token could otherwise reach it, and so is an answer that isn't
69
- * the workspace asked for. The organisation's failure, then the workspace's, is the answer. A read
70
- * under a workspace uses it too, so the workspace itself is proved, never only its records (D556,
71
- * as amended): pulse-admin answers an empty list for any workspace id.
104
+ * One of your organisation's workspaces, as `readOwnWorkspaceWith` reads it, with nothing beside it:
105
+ * for a call that reads or writes only after its workspace is proved.
72
106
  */
73
107
  export async function readOwnWorkspace(seam, read, workspaceId, organizationSchema) {
108
+ const own = await readOwnWorkspaceWith(seam, read, workspaceId, organizationSchema, () => Promise.resolve(null));
109
+ return own.ok ? { ok: true, data: { organization: own.data.organization, workspace: own.data.workspace } } : own;
110
+ }
111
+ /**
112
+ * One of your organisation's workspaces, and `alongside`'s answer, read once you're known to open
113
+ * it. Every call under one workspace known up front uses it (D556, as amended; D571), so the
114
+ * workspace itself is proved, never only its records: pulse-admin answers an empty list for any
115
+ * workspace id, and doesn't hold a limited member to their workspaces on every route.
116
+ * - **First, your organisation and you** (`readUser`), side by side. A workspace you don't open
117
+ * (`opensWorkspace`, D560) is then `not_found`, exactly as one nobody has, before anything under
118
+ * it is sent: no workspace read and no `alongside`, so its records, a dataset's embedded sign-in
119
+ * among them, are never fetched, and a refusal of them can't tell it apart (#373's code review, 3
120
+ * and 4).
121
+ * - **Then the workspace and `alongside`** (a list under it), side by side. A workspace of another
122
+ * organisation is invalid, as a staff token could otherwise reach it, and so is an answer that
123
+ * isn't the workspace asked for.
124
+ * The organisation's failure, then yours, then the workspace's, is the answer; `alongside`'s answer
125
+ * comes back as it is, for the caller to read after.
126
+ */
127
+ export async function readOwnWorkspaceWith(seam, read, workspaceId, organizationSchema, alongside) {
74
128
  const spec = seam.workspace(workspaceId, zRecord);
75
129
  if (spec === null)
76
130
  return { ok: false, error: { kind: 'refused', reason: 'path' } };
77
- const [organization, workspace] = await Promise.all([read(seam.myOrganization(organizationSchema)), read(spec)]);
131
+ const [organization, you] = await Promise.all([read(seam.myOrganization(organizationSchema)), readUser(seam, read)]);
78
132
  if (!organization.ok)
79
133
  return organization;
134
+ if (!you.ok)
135
+ return you;
136
+ if (!opensWorkspace(you.data, workspaceId))
137
+ return noSuchWorkspace();
138
+ const [workspace, beside] = await Promise.all([read(spec), alongside()]);
80
139
  if (!workspace.ok)
81
140
  return workspace;
82
141
  // Another workspace than the one asked for is never answered as it, as me() holds its user to
83
142
  // userinfo's sub; neither id is echoed. The caller's id may be any form pulse-admin reads as the
84
- // same UUID (sameUuid).
143
+ // same UUID (sameUuid), and so may the organisation's id the workspace names (#363).
85
144
  if (!sameUuid(workspace.data.id, workspaceId))
86
- return invalid("the workspace read isn't the one asked for");
87
- if (workspace.data.organization_id !== organization.data.id)
88
- return invalid("the workspace read is another organisation's");
89
- return { ok: true, data: { organization: organization.data, workspace: workspace.data } };
145
+ return invalidAnswer("the workspace read isn't the one asked for");
146
+ if (!sameUuid(workspace.data.organization_id, organization.data.id))
147
+ return invalidAnswer("the workspace read is another organisation's");
148
+ return { ok: true, data: { organization: organization.data, workspace: workspace.data, alongside: beside } };
90
149
  }
91
150
  /** `flipstream.workspaces.get()`: one workspace, by `readOwnWorkspace`'s rules. */
92
151
  export async function readWorkspace(seam, read, workspaceId) {
@@ -96,7 +155,8 @@ export async function readWorkspace(seam, read, workspaceId) {
96
155
  /**
97
156
  * `flipstream.workspaces.rename()` and `delete()`: a person's to do in the console (D542), so they
98
157
  * answer `needs_person` and never write. The workspace is read first, by `readOwnWorkspace`'s
99
- * rules, so one that isn't yours is `not_found` or `invalid`, never handed off. The address names
158
+ * rules, so one that isn't yours, or that you don't open, is `not_found` or `invalid`, never
159
+ * handed off. The address names
100
160
  * the organisation's short name and the workspace's canonical id, as the backend answered it.
101
161
  */
102
162
  export async function handOffWorkspace(seam, read, workspaceId, action) {
@@ -1 +1 @@
1
- {"version":3,"file":"workspaces.js","sourceRoot":"","sources":["../../src/api/workspaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAyB,MAAM,cAAc,CAAA;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC,OAAO,EAAE,SAAS,EAA+B,MAAM,WAAW,CAAA;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAUpC,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AAE5B,gGAAgG;AAChG,yFAAyF;AACzF,6FAA6F;AAC7F,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,CAAA;AAEzF,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;AAExC,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAmB,EAAa,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;AACnH,MAAM,OAAO,GAAG,CAAC,MAAc,EAAoB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,K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EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAA;AACxE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,IAAa,EAAE,IAAU,EAAE,WAAmB,EAAE,MAAwB;IAC7G,MAAM,GAAG,GAAG,MAAM,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,oBAAoB,CAAC,CAAA;IACjF,IAAI,CAAC,GAAG,CAAC,EAAE;QAAE,OAAO,GAAG,CAAA;IACvB,OAAO,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAA;AACvG,CAAC"}
@@ -1,18 +1,31 @@
1
1
  import type { ApiResult } from '../core/result.js';
2
2
  import { type AuthCallOptions } from './transport.js';
3
- /** What sign-in needs from an authorization server's metadata (RFC 8414), and nothing more. */
3
+ /**
4
+ * What sign-in needs from an authorization server's metadata (RFC 8414), and nothing more, in the
5
+ * metadata's own names (#353, D569).
6
+ */
4
7
  export interface AuthServer {
5
8
  /** The issuer as its metadata names it: what a redirect's `iss` must equal (RFC 9207). */
6
9
  readonly issuer: string;
7
10
  /** Where the person is sent to sign in. */
8
- readonly authorizationEndpoint: string;
11
+ readonly authorization_endpoint: string;
9
12
  /** Where the code is exchanged for tokens. */
10
- readonly tokenEndpoint: string;
13
+ readonly token_endpoint: string;
11
14
  /** Where a session is ended (RFC 7009), when the server has one. */
12
- readonly revocationEndpoint?: string;
13
- /** The server puts `iss` on every redirect (RFC 9207), so a redirect without one is refused. */
14
- readonly issuerOnRedirect: boolean;
15
+ readonly revocation_endpoint?: string;
16
+ /**
17
+ * The server puts `iss` on every redirect (RFC 9207), so a redirect without one is refused. False
18
+ * when its metadata doesn't say so.
19
+ */
20
+ readonly authorization_response_iss_parameter_supported: boolean;
15
21
  }
22
+ /**
23
+ * What a `server` given in place of discovery lacks, as `server.<field>` with what it must be, or
24
+ * null when it's an AuthServer's shape (#355's code review, 3): a discover() answer an app kept
25
+ * from a release before the snake rename (D569) holds camelCase names, and would otherwise be used
26
+ * as a server with no endpoints. Its values are checked where they're used.
27
+ */
28
+ export declare function serverProblem(server: unknown): string | null;
16
29
  /**
17
30
  * The authorization server at `issuer`, from its RFC 8414 metadata. `refused`, with nothing sent,
18
31
  * when `issuer` isn't an https URL, or with `allowLocalhostHttp`, an http one on this machine.
@@ -1,6 +1,27 @@
1
1
  import { z } from 'zod';
2
2
  import { call } from '../core/call.js';
3
3
  import { authTransport, endpointProblem, isSignInUrl } from './transport.js';
4
+ /**
5
+ * What a `server` given in place of discovery lacks, as `server.<field>` with what it must be, or
6
+ * null when it's an AuthServer's shape (#355's code review, 3): a discover() answer an app kept
7
+ * from a release before the snake rename (D569) holds camelCase names, and would otherwise be used
8
+ * as a server with no endpoints. Its values are checked where they're used.
9
+ */
10
+ export function serverProblem(server) {
11
+ if (typeof server !== 'object' || server === null)
12
+ return 'server must be discover()\'s answer';
13
+ const field = (name) => (Object.hasOwn(server, name) ? Reflect.get(server, name) : undefined);
14
+ for (const name of ['issuer', 'authorization_endpoint', 'token_endpoint']) {
15
+ if (typeof field(name) !== 'string')
16
+ return `server.${name} must be a string`;
17
+ }
18
+ const revocation = field('revocation_endpoint');
19
+ if (revocation !== undefined && typeof revocation !== 'string')
20
+ return 'server.revocation_endpoint must be a string, or left out';
21
+ if (typeof field('authorization_response_iss_parameter_supported') !== 'boolean')
22
+ return 'server.authorization_response_iss_parameter_supported must be a boolean';
23
+ return null;
24
+ }
4
25
  // Unknown fields are kept and never read: `first_party_client_id` among them, which the SDK never
5
26
  // uses in place of the app's own client ID (D421).
6
27
  const zMetadata = z.looseObject({
@@ -41,10 +62,10 @@ export async function discover(issuer, options = {}) {
41
62
  ok: true,
42
63
  data: {
43
64
  issuer: doc.issuer,
44
- authorizationEndpoint: doc.authorization_endpoint,
45
- tokenEndpoint: doc.token_endpoint,
46
- ...(doc.revocation_endpoint === undefined ? {} : { revocationEndpoint: doc.revocation_endpoint }),
47
- issuerOnRedirect: doc.authorization_response_iss_parameter_supported === true,
65
+ authorization_endpoint: doc.authorization_endpoint,
66
+ token_endpoint: doc.token_endpoint,
67
+ ...(doc.revocation_endpoint === undefined ? {} : { revocation_endpoint: doc.revocation_endpoint }),
68
+ authorization_response_iss_parameter_supported: doc.authorization_response_iss_parameter_supported === true,
48
69
  },
49
70
  };
50
71
  }
@@ -1 +1 @@
1
- {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/auth/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAEtC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAwB,MAAM,gBAAgB,CAAA;AAgBlG,kGAAkG;AAClG,mDAAmD;AACnD,MAAM,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;IAC9B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,sBAAsB,EAAE,CAAC,CAAC,MAAM,EAAE;IAClC,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;IAC1B,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,aAAa,EAAE;IAC/C,gCAAgC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,aAAa,EAAE;IACrE,8CAA8C,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,aAAa,EAAE;CAC5E,CAAC,CAAA;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,MAAc,EAAE,UAA2B,EAAE;IAC1E,IAAI,OAAO,MAAM,KAAK,QAAQ,IA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CAAC,MAAM,CAAC,KAAK,IAAI;QAAE,OAAO,oCAAoC,CAAA;IAChH,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { ApiError } from '../core/result.js';
2
- import type { AuthServer } from './discovery.js';
2
+ import { type AuthServer } from './discovery.js';
3
3
  import { type AuthCallOptions } from './transport.js';
4
4
  /** What `startSignIn` takes. */
5
5
  export interface SignInRequest {
@@ -14,30 +14,32 @@ export interface SignInRequest {
14
14
  }
15
15
  /**
16
16
  * What finishing needs, held by the app between the two halves: only strings and a flag, so it
17
- * survives a page load in the app's own storage. The verifier is a secret: never log it.
17
+ * survives a page load in the app's own storage. The verifier is a secret: never log it. Its
18
+ * fields are snake_case since the snake rename (#353, D569): a pending that a release before it
19
+ * made isn't one, so `finishSignIn` refuses it, and the person starts the sign-in again.
18
20
  */
19
21
  export interface PendingSignIn {
20
22
  /** What the redirect must carry back (CSRF). */
21
23
  readonly state: string;
22
24
  /** The PKCE code verifier: the secret the code is exchanged with. */
23
25
  readonly verifier: string;
24
- readonly clientId: string;
25
- readonly redirectUri: string;
26
+ readonly client_id: string;
27
+ readonly redirect_uri: string;
26
28
  /** The scopes asked for, space-separated (RFC 6749 §3.3). */
27
29
  readonly scope: string;
28
- /** The server's issuer, its token endpoint, and whether it puts `iss` on every redirect. */
30
+ /** The server's issuer, its token endpoint, and whether it puts `iss` on every redirect (RFC 9207). */
29
31
  readonly issuer: string;
30
- readonly tokenEndpoint: string;
31
- readonly issuerOnRedirect: boolean;
32
+ readonly token_endpoint: string;
33
+ readonly authorization_response_iss_parameter_supported: boolean;
32
34
  }
33
- /** What a sign-in gives. The app stores them; the SDK keeps no copy. */
35
+ /** What a sign-in gives, in snake_case (#353, D569). The app stores them; the SDK keeps no copy. */
34
36
  export interface Tokens {
35
37
  /** For the transport's token function: never log it. */
36
- readonly accessToken: string;
38
+ readonly access_token: string;
37
39
  /** Absent when the server issued none. */
38
- readonly refreshToken?: string;
40
+ readonly refresh_token?: string;
39
41
  /** When the access token expires, in ms since the epoch; absent when the server didn't say. */
40
- readonly expiresAt?: number;
42
+ readonly expires_at?: number;
41
43
  /** The scopes granted, space-separated. */
42
44
  readonly scope: string;
43
45
  }
@@ -73,8 +75,9 @@ export type SignInResult = {
73
75
  };
74
76
  /**
75
77
  * The URL to send the person to, and what finishing will need. Rejects with a TypeError, before
76
- * anything is made, when the client ID is missing or empty, the redirect URI isn't absolute, or
77
- * the scopes are empty or one holds a space: from TypeScript, none of these compiles. Always S256;
78
+ * anything is made, when the client ID is missing or empty, the redirect URI isn't absolute, the
79
+ * scopes are empty or one holds a space, or `server` isn't discover()'s answer in its snake_case
80
+ * names, naming the field it lacks: from TypeScript, none of these compiles. Always S256;
78
81
  * no `resource` is sent, since the hosts share one audience.
79
82
  */
80
83
  export declare function startSignIn(request: SignInRequest): Promise<{
@@ -94,7 +97,8 @@ export declare const isPendingSignIn: (value: unknown) => value is PendingSignIn
94
97
  /**
95
98
  * Finishes a sign-in: the redirect is read (`readCallback`), and only then is its code exchanged
96
99
  * for tokens, once (`tokenCall`). A `pending` that isn't one (from
97
- * storage the app couldn't read back) is `refused`, with nothing sent. A public client's: an app
100
+ * storage the app couldn't read back, or one an earlier version made, in camelCase) is `refused`,
101
+ * with nothing sent. A public client's: an app
98
102
  * with a server signs in as a confidential client with `@flipstream/sdk/node`'s `finishSignIn`.
99
103
  */
100
104
  export declare function finishSignIn(callbackUrl: string | URL, pending: PendingSignIn, options?: AuthCallOptions): Promise<SignInResult>;
@@ -1,13 +1,16 @@
1
1
  import { z } from 'zod';
2
2
  import { call } from '../core/call.js';
3
+ import { wallClock } from '../core/deadline.js';
4
+ import { serverProblem } from './discovery.js';
3
5
  import { challengeOf, randomValue } from './pkce.js';
4
6
  import { tokenCall } from './tokenEndpoint.js';
5
7
  import { authTransport, endpointProblem, isSignInUrl } from './transport.js';
6
8
  const nonEmpty = (value) => typeof value === 'string' && value !== '';
7
9
  /**
8
10
  * The URL to send the person to, and what finishing will need. Rejects with a TypeError, before
9
- * anything is made, when the client ID is missing or empty, the redirect URI isn't absolute, or
10
- * the scopes are empty or one holds a space: from TypeScript, none of these compiles. Always S256;
11
+ * anything is made, when the client ID is missing or empty, the redirect URI isn't absolute, the
12
+ * scopes are empty or one holds a space, or `server` isn't discover()'s answer in its snake_case
13
+ * names, naming the field it lacks: from TypeScript, none of these compiles. Always S256;
11
14
  * no `resource` is sent, since the hosts share one audience.
12
15
  */
13
16
  export async function startSignIn(request) {
@@ -19,10 +22,13 @@ export async function startSignIn(request) {
19
22
  if (!Array.isArray(scopes) || scopes.length === 0 || !scopes.every((scope) => nonEmpty(scope) && !/\s/.test(scope))) {
20
23
  throw new TypeError('startSignIn: scopes must be one or more scope names, none with a space');
21
24
  }
25
+ const problem = serverProblem(server);
26
+ if (problem !== null)
27
+ throw new TypeError(`startSignIn: ${problem}: pass discover()'s answer, in its snake_case names (D569)`);
22
28
  const state = randomValue(32);
23
29
  const verifier = randomValue(64);
24
30
  const scope = scopes.join(' ');
25
- const url = new URL(server.authorizationEndpoint);
31
+ const url = new URL(server.authorization_endpoint);
26
32
  url.searchParams.set('response_type', 'code');
27
33
  url.searchParams.set('client_id', clientId);
28
34
  url.searchParams.set('redirect_uri', redirectUri);
@@ -35,12 +41,12 @@ export async function startSignIn(request) {
35
41
  pending: {
36
42
  state,
37
43
  verifier,
38
- clientId,
39
- redirectUri,
44
+ client_id: clientId,
45
+ redirect_uri: redirectUri,
40
46
  scope,
41
47
  issuer: server.issuer,
42
- tokenEndpoint: server.tokenEndpoint,
43
- issuerOnRedirect: server.issuerOnRedirect,
48
+ token_endpoint: server.token_endpoint,
49
+ authorization_response_iss_parameter_supported: server.authorization_response_iss_parameter_supported,
44
50
  },
45
51
  };
46
52
  }
@@ -54,7 +60,7 @@ export function readCallback(callbackUrl, pending) {
54
60
  return { kind: 'wrong_state' };
55
61
  const iss = params.get('iss');
56
62
  // Compared as strings, as RFC 9207 §2.4 says: the issuer exactly as its metadata names it.
57
- if (iss === null ? pending.issuerOnRedirect : iss !== pending.issuer)
63
+ if (iss === null ? pending.authorization_response_iss_parameter_supported : iss !== pending.issuer)
58
64
  return { kind: 'wrong_issuer' };
59
65
  const error = params.get('error');
60
66
  if (error !== null) {
@@ -68,23 +74,24 @@ const zPending = z
68
74
  .object({
69
75
  state: z.string().min(1),
70
76
  verifier: z.string().min(43).max(128),
71
- clientId: z.string().min(1),
72
- redirectUri: z.string().min(1),
77
+ client_id: z.string().min(1),
78
+ redirect_uri: z.string().min(1),
73
79
  scope: z.string().min(1),
74
80
  issuer: z.string().min(1),
75
- tokenEndpoint: z.string(),
76
- issuerOnRedirect: z.boolean(),
81
+ token_endpoint: z.string(),
82
+ authorization_response_iss_parameter_supported: z.boolean(),
77
83
  })
78
84
  // A pending from storage may have been edited. Its token endpoint is held to the issuer's rule:
79
85
  // https for an https issuer; for an http one on this machine, its own origin, which `finishSignIn`
80
86
  // then sends to only with `allowLocalhostHttp` (#164).
81
- .refine((pending) => endpointProblem(pending.issuer, [pending.tokenEndpoint]) === null);
87
+ .refine((pending) => endpointProblem(pending.issuer, [pending.token_endpoint]) === null);
82
88
  /** A pending sign-in as `startSignIn` makes one, checked: it comes back from the app's storage. */
83
89
  export const isPendingSignIn = (value) => zPending.safeParse(value).success;
84
90
  /**
85
91
  * Finishes a sign-in: the redirect is read (`readCallback`), and only then is its code exchanged
86
92
  * for tokens, once (`tokenCall`). A `pending` that isn't one (from
87
- * storage the app couldn't read back) is `refused`, with nothing sent. A public client's: an app
93
+ * storage the app couldn't read back, or one an earlier version made, in camelCase) is `refused`,
94
+ * with nothing sent. A public client's: an app
88
95
  * with a server signs in as a confidential client with `@flipstream/sdk/node`'s `finishSignIn`.
89
96
  */
90
97
  export function finishSignIn(callbackUrl, pending, options = {}) {
@@ -99,7 +106,7 @@ export async function exchangeCode(callbackUrl, pending, options, authorization)
99
106
  // Refused with nothing sent, each for its own reason (#199): what it refuses is as before.
100
107
  if (!isPendingSignIn(pending))
101
108
  return { ok: false, error: { kind: 'refused', reason: 'pending' } };
102
- if (!isSignInUrl(pending.tokenEndpoint, options.allowLocalhostHttp))
109
+ if (!isSignInUrl(pending.token_endpoint, options.allowLocalhostHttp))
103
110
  return { ok: false, error: { kind: 'refused', reason: 'destination' } };
104
111
  if (!URL.canParse(callbackUrl))
105
112
  return { ok: false, error: { kind: 'refused', reason: 'callback' } };
@@ -109,23 +116,23 @@ export async function exchangeCode(callbackUrl, pending, options, authorization)
109
116
  const form = {
110
117
  grant_type: 'authorization_code',
111
118
  code: callback.code,
112
- redirect_uri: pending.redirectUri,
113
- client_id: pending.clientId,
119
+ redirect_uri: pending.redirect_uri,
120
+ client_id: pending.client_id,
114
121
  code_verifier: pending.verifier,
115
122
  };
116
123
  // Before the request, so the expiry is never later than the server's own.
117
- const sentAt = Date.now();
118
- const answer = await call(authTransport(options), tokenCall('auth.token', pending.tokenEndpoint, form, 30_000, authorization), options.signal);
124
+ const sentAt = wallClock();
125
+ const answer = await call(authTransport(options), tokenCall('auth.token', pending.token_endpoint, form, 30_000, authorization), options.signal);
119
126
  if (!answer.ok)
120
127
  return answer;
121
128
  const { access_token, expires_in, refresh_token, scope } = answer.data;
122
129
  return {
123
130
  ok: true,
124
131
  data: {
125
- accessToken: access_token,
132
+ access_token,
126
133
  // pulse-auth sends "" for "no refresh token" (its model's default): that is none, not a token.
127
- ...(nonEmpty(refresh_token) ? { refreshToken: refresh_token } : {}),
128
- ...(expires_in === undefined ? {} : { expiresAt: sentAt + expires_in * 1000 }),
134
+ ...(nonEmpty(refresh_token) ? { refresh_token } : {}),
135
+ ...(expires_in === undefined ? {} : { expires_at: sentAt + expires_in * 1000 }),
129
136
  // RFC 6749 §5.1: a server leaves `scope` out when it granted what was asked. pulse-auth
130
137
  // always leaves it out.
131
138
  scope: scope ?? pending.scope,
@@ -1 +1 @@
1
- {"version":3,"file":"signIn.js","sourceRoot":"","sources":["../../src/auth/signIn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAA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AC,MAAM,CAAC,CAAA;IAC/I,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,MAAM,CAAA;IAC7B,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC,IAAI,CAAA;IACtE,OAAO;QACL,EAAE,EAAE,IAAI;QACR,IAAI,EAAE;YACJ,YAAY;YACZ,+FAA+F;YAC/F,GAAG,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACrD,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,EAAE,CAAC;YAC/E,wFAAwF;YACxF,wBAAwB;YACxB,KAAK,EAAE,KAAK,IAAI,OAAO,CAAC,KAAK;SAC9B;KACF,CAAA;AACH,CAAC"}
@@ -19,5 +19,8 @@ export interface CallSpec<T> extends Omit<ApiRequest, 'signal'> {
19
19
  * One call: attempts under its rule, every attempt, wait and read under one signal that joins the
20
20
  * caller's with the deadline. Whichever fires first decides the answer, `timeout` or `aborted`
21
21
  * (#15), never mixed. The call ends when it fires, whatever the transport does with the signal.
22
+ * `callEnd` is the SDK call's own end, for a read (#349): it ends the request as the caller's abort
23
+ * does, `aborted`, and one already ended sends nothing. It's the SDK's own signal, kept apart from
24
+ * the caller's, so a caller's signal gets one listener a request, as before, and never one more.
22
25
  */
23
- export declare function call<T>(transport: Transport, spec: CallSpec<T>, signal?: AbortSignal): Promise<ApiResult<T>>;
26
+ export declare function call<T>(transport: Transport, spec: CallSpec<T>, signal?: AbortSignal, callEnd?: AbortSignal): Promise<ApiResult<T>>;
package/dist/core/call.js CHANGED
@@ -1,15 +1,32 @@
1
1
  import { readJson } from './read.js';
2
+ import { deadlineIn, MAX_TIMER_MS } from './deadline.js';
2
3
  import { classifyStatus } from './result.js';
3
4
  import { decide, parseRetryAfterMs } from './retry.js';
4
5
  /**
5
6
  * One call: attempts under its rule, every attempt, wait and read under one signal that joins the
6
7
  * caller's with the deadline. Whichever fires first decides the answer, `timeout` or `aborted`
7
8
  * (#15), never mixed. The call ends when it fires, whatever the transport does with the signal.
9
+ * `callEnd` is the SDK call's own end, for a read (#349): it ends the request as the caller's abort
10
+ * does, `aborted`, and one already ended sends nothing. It's the SDK's own signal, kept apart from
11
+ * the caller's, so a caller's signal gets one listener a request, as before, and never one more.
8
12
  */
9
- export async function call(transport, spec, signal) {
10
- if (signal?.aborted === true)
13
+ export async function call(transport, spec, signal, callEnd) {
14
+ if (signal?.aborted === true || callEnd?.aborted === true)
11
15
  return failed({ kind: 'aborted' });
12
- const deadline = Date.now() + spec.deadlineMs;
16
+ // A call with no time for it is over before it starts: nothing is sent, as nothing is for a caller
17
+ // that has already aborted (#339). No time is what a deadline's passed() calls it (#337): under
18
+ // 1 ms, or not a number. A caller that checked its own deadline a moment before may still hand on
19
+ // under 1 ms, the time left read again. It's read off the value handed, as passed() reads it the
20
+ // moment the deadline is set: a microsecond later, a deadline of 1 ms already reads passed, and a
21
+ // call given 1 ms would never go out. A deadline past what a timer holds would fire after 1 ms,
22
+ // so it's none either; the public `deadlineMs` is refused before it gets here (#340's code
23
+ // review, 1-3).
24
+ if (!(spec.deadlineMs >= 1) || spec.deadlineMs > MAX_TIMER_MS)
25
+ return failed({ kind: 'timeout' });
26
+ // On the monotonic clock, as the timer below is, so whether a wait fits is read as the timer
27
+ // counts: a wall clock stepped back would start waits past it, one stepped forward refuse waits
28
+ // that fit (#333).
29
+ const deadline = deadlineIn(spec.deadlineMs);
13
30
  // Owned here, strongly: the timer and the caller's listener each hold `stop`, so the deadline
14
31
  // reaches every attempt, however weakly a transport or its fetch keeps the signal (#57).
15
32
  const stop = new AbortController();
@@ -17,6 +34,8 @@ export async function call(transport, spec, signal) {
17
34
  const timer = setTimeout(() => stop.abort(timedOut), spec.deadlineMs);
18
35
  const onAbort = () => stop.abort(signal?.reason);
19
36
  signal?.addEventListener('abort', onAbort, { once: true });
37
+ const onEnd = () => stop.abort(callEnd?.reason);
38
+ callEnd?.addEventListener('abort', onEnd, { once: true });
20
39
  // The first abort's reason stays: that is how the call knows which came first.
21
40
  const ended = () => failed(stop.signal.reason === timedOut ? { kind: 'timeout' } : { kind: 'aborted' });
22
41
  const fired = new Promise((resolve) => stop.signal.addEventListener('abort', () => resolve(ENDED), { once: true }));
@@ -31,7 +50,7 @@ export async function call(transport, spec, signal) {
31
50
  letGo(sent);
32
51
  return ended();
33
52
  }
34
- let decision = decide(spec.retry, attempt, outcomeOf(sent), Date.now(), deadline);
53
+ let decision = decide(spec.retry, attempt, outcomeOf(sent), deadline.left());
35
54
  if (decision.kind === 'stop') {
36
55
  const result = await unlessFired(readJson(sent, spec.schema, stop.signal, spec.service, spec.keepsNoText === true), fired, () => undefined);
37
56
  if (result === ENDED || stop.signal.aborted)
@@ -39,7 +58,7 @@ export async function call(transport, spec, signal) {
39
58
  // A success whose body broke off is a transport failure too, so a read tries again under
40
59
  // its rule. Any other status already decided: its answer stands, however its body ended.
41
60
  if (brokeOff(sent, result))
42
- decision = decide(spec.retry, attempt, { kind: 'unavailable' }, Date.now(), deadline);
61
+ decision = decide(spec.retry, attempt, { kind: 'unavailable' }, deadline.left());
43
62
  if (decision.kind === 'stop')
44
63
  return withRetryAfter(result, sent);
45
64
  }
@@ -57,6 +76,7 @@ export async function call(transport, spec, signal) {
57
76
  // A minimal polyfill signal may have no removeEventListener; it keeps its one listener.
58
77
  if (typeof signal?.removeEventListener === 'function')
59
78
  signal.removeEventListener('abort', onAbort);
79
+ callEnd?.removeEventListener('abort', onEnd);
60
80
  }
61
81
  }
62
82
  const ENDED = Symbol('ended');
@@ -91,7 +111,7 @@ function withRetryAfter(result, sent) {
91
111
  if (result.ok || sent.kind !== 'response' || !answered(result.error))
92
112
  return result;
93
113
  const retryAfterMs = parseRetryAfterMs(sent.response.headers.get('retry-after'));
94
- return retryAfterMs === undefined ? result : failed({ ...result.error, retryAfterMs });
114
+ return retryAfterMs === undefined ? result : failed({ ...result.error, retry_after_ms: retryAfterMs });
95
115
  }
96
116
  // Of what readJson gives for a response, only a failure status's answer has a kind other than
97
117
  // `invalid` and a status.