@segmentstream/ontology 0.94.1 → 0.96.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 (58) hide show
  1. package/README.md +52 -7
  2. package/dist/analyze.d.ts +15 -3
  3. package/dist/analyze.js +217 -5
  4. package/dist/authoring.js +3 -0
  5. package/dist/index.d.ts +8 -8
  6. package/dist/index.js +5 -5
  7. package/dist/manifest-compatibility.d.ts +7 -0
  8. package/dist/manifest-compatibility.js +12 -0
  9. package/dist/manifest.d.ts +102 -18
  10. package/dist/manifest.js +41 -2
  11. package/dist/migrate/apply.d.ts +3 -2
  12. package/dist/migrate/apply.js +11 -3
  13. package/dist/migrate/model.d.ts +60 -12
  14. package/dist/migrate/plan.js +9 -1
  15. package/dist/migrate/storage.d.ts +7 -0
  16. package/dist/migrate/storage.js +24 -12
  17. package/dist/ontology.d.ts +2 -2
  18. package/dist/permissions.d.ts +9 -0
  19. package/dist/permissions.js +8 -0
  20. package/dist/runtime/channel-identity-admin.d.ts +41 -0
  21. package/dist/runtime/channel-identity-admin.js +223 -0
  22. package/dist/runtime/generated-actions.d.ts +2 -1
  23. package/dist/runtime/generated-actions.js +71 -3
  24. package/dist/runtime/member-tables.d.ts +7 -2
  25. package/dist/runtime/member-tables.js +18 -3
  26. package/dist/runtime/new-user-hook.d.ts +11 -1
  27. package/dist/runtime/new-user-hook.js +69 -29
  28. package/dist/runtime/pipeline.d.ts +2 -0
  29. package/dist/runtime/pipeline.js +11 -3
  30. package/dist/runtime/principals.d.ts +37 -3
  31. package/dist/runtime/principals.js +140 -36
  32. package/dist/runtime/resolve-agent-identity.js +43 -12
  33. package/dist/runtime/service-binding.js +11 -4
  34. package/dist/runtime/sql-runtime.d.ts +14 -1
  35. package/dist/runtime/sql-runtime.js +9 -0
  36. package/dist/runtime/user-identities.d.ts +5 -3
  37. package/dist/runtime/user-identities.js +9 -4
  38. package/dist/runtime/user-identity-sql.d.ts +4 -1
  39. package/dist/runtime/user-identity-sql.js +5 -2
  40. package/dist/runtime-source.d.ts +6 -0
  41. package/dist/runtime-source.js +11 -0
  42. package/dist/service/agent/attachments.js +4 -0
  43. package/dist/service/agent/authentication.d.ts +74 -2
  44. package/dist/service/agent/authentication.js +93 -11
  45. package/dist/service/agent/files.js +8 -1
  46. package/dist/service/agent/server.js +13 -2
  47. package/dist/service/authentication.js +58 -2
  48. package/dist/service/caller-context.d.ts +16 -0
  49. package/dist/service/chat/envelope.d.ts +20 -2
  50. package/dist/service/chat/envelope.js +10 -0
  51. package/dist/service/runtime-contract.d.ts +9 -0
  52. package/dist/service/schemas.d.ts +12 -0
  53. package/dist/sign-in.d.ts +32 -1
  54. package/dist/sign-in.js +12 -1
  55. package/dist/storage/attachments.d.ts +11 -0
  56. package/dist/user-identity.d.ts +14 -5
  57. package/dist/user-identity.js +25 -5
  58. package/package.json +1 -1
@@ -3,7 +3,7 @@ import { Effect, Schema } from "effect";
3
3
  import type { ResolvedConnection, ResolvedEntity } from "./analyze.js";
4
4
  import type { ResolvedFeedback } from "./feedback-config.js";
5
5
  import type { Role } from "./role.js";
6
- import { type SignInOptions, type SignInPolicy } from "./sign-in.js";
6
+ import { type ResolvedSignInOptions, type SignInPolicy } from "./sign-in.js";
7
7
  /**
8
8
  * The manifest format this SDK writes. Readers accept any version and ignore unknown fields. Version
9
9
  * 2 replaced the actions' `allow` with `permission`, and added the roles' `permissions` and the
@@ -56,6 +56,9 @@ import { type SignInOptions, type SignInPolicy } from "./sign-in.js";
56
56
  * Within version 15, `chat` may carry `slack` and `whatsapp` beside `telegram`: the connections
57
57
  * exact chat posts to Slack chats and to members' WhatsApp chats go through. Older readers ignore
58
58
  * them, and their services post to Telegram alone.
59
+ * Within version 15, `signIn` may carry `signUp`, the wire names of the roles each channel open to
60
+ * sign-up grants, and `onSignUp`, written only when declared. Older readers ignore them and keep
61
+ * every channel closed to sign-up.
59
62
  */
60
63
  export declare const MANIFEST_VERSION = 15;
61
64
  /** The phrase used for a direction the author did not phrase. */
@@ -548,6 +551,10 @@ export declare const BrowserSignInManifest: Schema.encodeKeys<Schema.Struct<{
548
551
  }>, {
549
552
  readonly autoRedirect: "auto_redirect";
550
553
  }>;
554
+ /** Sign-up: the wire names of the roles each open channel grants. Unknown channels stay closed. */
555
+ export declare const SignUpManifest: Schema.Struct<{
556
+ readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
557
+ }>;
551
558
  export declare const SignInManifest: Schema.encodeKeys<Schema.Struct<{
552
559
  readonly browser: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
553
560
  readonly methods: Schema.$Array<Schema.String>;
@@ -563,9 +570,15 @@ export declare const SignInManifest: Schema.encodeKeys<Schema.Struct<{
563
570
  readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
564
571
  readonly onNewUser: Schema.optionalKey<Schema.String>;
565
572
  readonly codeLink: Schema.optionalKey<Schema.Boolean>;
573
+ readonly signUp: Schema.optionalKey<Schema.Struct<{
574
+ readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
575
+ }>>;
576
+ readonly onSignUp: Schema.optionalKey<Schema.String>;
566
577
  }>, {
567
578
  readonly onNewUser: "on_new_user";
568
579
  readonly codeLink: "code_link";
580
+ readonly signUp: "sign_up";
581
+ readonly onSignUp: "on_sign_up";
569
582
  }>;
570
583
  export type SignInManifest = typeof SignInManifest.Type;
571
584
  /** One of the workspace's emails, as `defineOntology({ emails })` declares it; see `EmailTemplate`. */
@@ -837,9 +850,15 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
837
850
  readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
838
851
  readonly onNewUser: Schema.optionalKey<Schema.String>;
839
852
  readonly codeLink: Schema.optionalKey<Schema.Boolean>;
853
+ readonly signUp: Schema.optionalKey<Schema.Struct<{
854
+ readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
855
+ }>>;
856
+ readonly onSignUp: Schema.optionalKey<Schema.String>;
840
857
  }>, {
841
858
  readonly onNewUser: "on_new_user";
842
859
  readonly codeLink: "code_link";
860
+ readonly signUp: "sign_up";
861
+ readonly onSignUp: "on_sign_up";
843
862
  }>>;
844
863
  /** The workspace's own emails by wire name. Written only when there are some; absent reads as none. */
845
864
  readonly emails: Schema.optionalKey<Schema.$Record<Schema.String, Schema.encodeKeys<Schema.Struct<{
@@ -1067,10 +1086,10 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1067
1086
  readonly telegram?: {
1068
1087
  readonly connection: string;
1069
1088
  } | undefined;
1070
- readonly slack?: {
1089
+ readonly whatsapp?: {
1071
1090
  readonly connection: string;
1072
1091
  } | undefined;
1073
- readonly whatsapp?: {
1092
+ readonly slack?: {
1074
1093
  readonly connection: string;
1075
1094
  } | undefined;
1076
1095
  readonly attribution?: {
@@ -1158,6 +1177,12 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1158
1177
  } | undefined;
1159
1178
  readonly onNewUser?: string | undefined;
1160
1179
  readonly codeLink?: boolean | undefined;
1180
+ readonly signUp?: {
1181
+ readonly channels: {
1182
+ readonly [x: string]: unknown;
1183
+ };
1184
+ } | undefined;
1185
+ readonly onSignUp?: string | undefined;
1161
1186
  } | undefined;
1162
1187
  readonly emails?: {
1163
1188
  readonly [x: string]: {
@@ -1294,10 +1319,10 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1294
1319
  readonly telegram?: {
1295
1320
  readonly connection: string;
1296
1321
  } | undefined;
1297
- readonly slack?: {
1322
+ readonly whatsapp?: {
1298
1323
  readonly connection: string;
1299
1324
  } | undefined;
1300
- readonly whatsapp?: {
1325
+ readonly slack?: {
1301
1326
  readonly connection: string;
1302
1327
  } | undefined;
1303
1328
  readonly attribution?: {
@@ -1385,6 +1410,12 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1385
1410
  } | undefined;
1386
1411
  readonly onNewUser?: string | undefined;
1387
1412
  readonly codeLink?: boolean | undefined;
1413
+ readonly signUp?: {
1414
+ readonly channels: {
1415
+ readonly [x: string]: unknown;
1416
+ };
1417
+ } | undefined;
1418
+ readonly onSignUp?: string | undefined;
1388
1419
  } | undefined;
1389
1420
  readonly emails?: {
1390
1421
  readonly [x: string]: {
@@ -1521,10 +1552,10 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1521
1552
  readonly telegram?: {
1522
1553
  readonly connection: string;
1523
1554
  } | undefined;
1524
- readonly slack?: {
1555
+ readonly whatsapp?: {
1525
1556
  readonly connection: string;
1526
1557
  } | undefined;
1527
- readonly whatsapp?: {
1558
+ readonly slack?: {
1528
1559
  readonly connection: string;
1529
1560
  } | undefined;
1530
1561
  readonly attribution?: {
@@ -1628,6 +1659,12 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1628
1659
  } | undefined;
1629
1660
  readonly on_new_user?: string | undefined;
1630
1661
  readonly code_link?: boolean | undefined;
1662
+ readonly sign_up?: {
1663
+ readonly channels: {
1664
+ readonly [x: string]: unknown;
1665
+ };
1666
+ } | undefined;
1667
+ readonly on_sign_up?: string | undefined;
1631
1668
  } | undefined;
1632
1669
  } | {
1633
1670
  readonly version: number;
@@ -1748,10 +1785,10 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1748
1785
  readonly telegram?: {
1749
1786
  readonly connection: string;
1750
1787
  } | undefined;
1751
- readonly slack?: {
1788
+ readonly whatsapp?: {
1752
1789
  readonly connection: string;
1753
1790
  } | undefined;
1754
- readonly whatsapp?: {
1791
+ readonly slack?: {
1755
1792
  readonly connection: string;
1756
1793
  } | undefined;
1757
1794
  readonly attribution?: {
@@ -1839,6 +1876,12 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1839
1876
  } | undefined;
1840
1877
  readonly on_new_user?: string | undefined;
1841
1878
  readonly code_link?: boolean | undefined;
1879
+ readonly sign_up?: {
1880
+ readonly channels: {
1881
+ readonly [x: string]: unknown;
1882
+ };
1883
+ } | undefined;
1884
+ readonly on_sign_up?: string | undefined;
1842
1885
  } | undefined;
1843
1886
  readonly emails?: {
1844
1887
  readonly [x: string]: {
@@ -2052,9 +2095,15 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2052
2095
  readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
2053
2096
  readonly onNewUser: Schema.optionalKey<Schema.String>;
2054
2097
  readonly codeLink: Schema.optionalKey<Schema.Boolean>;
2098
+ readonly signUp: Schema.optionalKey<Schema.Struct<{
2099
+ readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
2100
+ }>>;
2101
+ readonly onSignUp: Schema.optionalKey<Schema.String>;
2055
2102
  }>, {
2056
2103
  readonly onNewUser: "on_new_user";
2057
2104
  readonly codeLink: "code_link";
2105
+ readonly signUp: "sign_up";
2106
+ readonly onSignUp: "on_sign_up";
2058
2107
  }>>;
2059
2108
  /** The workspace's own emails by wire name. Written only when there are some; absent reads as none. */
2060
2109
  readonly emails: Schema.optionalKey<Schema.$Record<Schema.String, Schema.encodeKeys<Schema.Struct<{
@@ -2346,9 +2395,15 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2346
2395
  readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
2347
2396
  readonly onNewUser: Schema.optionalKey<Schema.String>;
2348
2397
  readonly codeLink: Schema.optionalKey<Schema.Boolean>;
2398
+ readonly signUp: Schema.optionalKey<Schema.Struct<{
2399
+ readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
2400
+ }>>;
2401
+ readonly onSignUp: Schema.optionalKey<Schema.String>;
2349
2402
  }>, {
2350
2403
  readonly onNewUser: "on_new_user";
2351
2404
  readonly codeLink: "code_link";
2405
+ readonly signUp: "sign_up";
2406
+ readonly onSignUp: "on_sign_up";
2352
2407
  }>>;
2353
2408
  /** The workspace's own emails by wire name. Written only when there are some; absent reads as none. */
2354
2409
  readonly emails: Schema.optionalKey<Schema.$Record<Schema.String, Schema.encodeKeys<Schema.Struct<{
@@ -2568,10 +2623,10 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2568
2623
  readonly telegram?: {
2569
2624
  readonly connection: string;
2570
2625
  } | undefined;
2571
- readonly slack?: {
2626
+ readonly whatsapp?: {
2572
2627
  readonly connection: string;
2573
2628
  } | undefined;
2574
- readonly whatsapp?: {
2629
+ readonly slack?: {
2575
2630
  readonly connection: string;
2576
2631
  } | undefined;
2577
2632
  readonly attribution?: {
@@ -2659,6 +2714,12 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2659
2714
  } | undefined;
2660
2715
  readonly onNewUser?: string | undefined;
2661
2716
  readonly codeLink?: boolean | undefined;
2717
+ readonly signUp?: {
2718
+ readonly channels: {
2719
+ readonly [x: string]: unknown;
2720
+ };
2721
+ } | undefined;
2722
+ readonly onSignUp?: string | undefined;
2662
2723
  } | undefined;
2663
2724
  readonly emails?: {
2664
2725
  readonly [x: string]: {
@@ -2795,10 +2856,10 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2795
2856
  readonly telegram?: {
2796
2857
  readonly connection: string;
2797
2858
  } | undefined;
2798
- readonly slack?: {
2859
+ readonly whatsapp?: {
2799
2860
  readonly connection: string;
2800
2861
  } | undefined;
2801
- readonly whatsapp?: {
2862
+ readonly slack?: {
2802
2863
  readonly connection: string;
2803
2864
  } | undefined;
2804
2865
  readonly attribution?: {
@@ -2886,6 +2947,12 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2886
2947
  } | undefined;
2887
2948
  readonly onNewUser?: string | undefined;
2888
2949
  readonly codeLink?: boolean | undefined;
2950
+ readonly signUp?: {
2951
+ readonly channels: {
2952
+ readonly [x: string]: unknown;
2953
+ };
2954
+ } | undefined;
2955
+ readonly onSignUp?: string | undefined;
2889
2956
  } | undefined;
2890
2957
  readonly emails?: {
2891
2958
  readonly [x: string]: {
@@ -3028,10 +3095,10 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
3028
3095
  readonly telegram?: {
3029
3096
  readonly connection: string;
3030
3097
  } | undefined;
3031
- readonly slack?: {
3098
+ readonly whatsapp?: {
3032
3099
  readonly connection: string;
3033
3100
  } | undefined;
3034
- readonly whatsapp?: {
3101
+ readonly slack?: {
3035
3102
  readonly connection: string;
3036
3103
  } | undefined;
3037
3104
  readonly attribution?: {
@@ -3119,6 +3186,12 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
3119
3186
  } | undefined;
3120
3187
  readonly onNewUser?: string | undefined;
3121
3188
  readonly codeLink?: boolean | undefined;
3189
+ readonly signUp?: {
3190
+ readonly channels: {
3191
+ readonly [x: string]: unknown;
3192
+ };
3193
+ } | undefined;
3194
+ readonly onSignUp?: string | undefined;
3122
3195
  } | undefined;
3123
3196
  readonly emails?: {
3124
3197
  readonly [x: string]: {
@@ -3255,10 +3328,10 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
3255
3328
  readonly telegram?: {
3256
3329
  readonly connection: string;
3257
3330
  } | undefined;
3258
- readonly slack?: {
3331
+ readonly whatsapp?: {
3259
3332
  readonly connection: string;
3260
3333
  } | undefined;
3261
- readonly whatsapp?: {
3334
+ readonly slack?: {
3262
3335
  readonly connection: string;
3263
3336
  } | undefined;
3264
3337
  readonly attribution?: {
@@ -3346,6 +3419,12 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
3346
3419
  } | undefined;
3347
3420
  readonly onNewUser?: string | undefined;
3348
3421
  readonly codeLink?: boolean | undefined;
3422
+ readonly signUp?: {
3423
+ readonly channels: {
3424
+ readonly [x: string]: unknown;
3425
+ };
3426
+ } | undefined;
3427
+ readonly onSignUp?: string | undefined;
3349
3428
  } | undefined;
3350
3429
  readonly emails?: {
3351
3430
  readonly [x: string]: {
@@ -3371,6 +3450,11 @@ export declare function encodeManifest(manifest: OntologyManifest): Readonly<Rec
3371
3450
  * not know, reads as `invited`: the closed choice, so that a misread never lets strangers in.
3372
3451
  */
3373
3452
  export declare function signInPolicyOf(manifest: Pick<OntologyManifest, "signIn">): SignInPolicy;
3453
+ /**
3454
+ * The wire names of the roles a stranger who signs up on this channel is given, or `undefined` when
3455
+ * the channel is closed to sign-up: not a channel this reader knows, or no well-formed entry.
3456
+ */
3457
+ export declare function signUpRolesOf(manifest: Pick<OntologyManifest, "signIn">, channel: string): ReadonlyArray<string> | undefined;
3374
3458
  /** Unsupported providers and missing or unknown channel policies require invitation. */
3375
3459
  export declare function channelPolicyOf(manifest: Pick<OntologyManifest, "signIn">, provider: string): SignInPolicy;
3376
3460
  /** JSON with object keys sorted at every level and no whitespace: the input of the manifest hash. */
@@ -3403,7 +3487,7 @@ export declare function buildManifest(input: {
3403
3487
  };
3404
3488
  readonly entities: ReadonlyArray<ResolvedEntity>;
3405
3489
  readonly roles: ReadonlyArray<Role>;
3406
- readonly signIn: SignInOptions;
3490
+ readonly signIn: ResolvedSignInOptions;
3407
3491
  /** The workspace's own emails by wire name. */
3408
3492
  readonly emails?: Readonly<Record<string, EmailTemplateManifest>>;
3409
3493
  readonly connections?: ReadonlyArray<ResolvedConnection>;
package/dist/manifest.js CHANGED
@@ -4,7 +4,7 @@ import { acceptingEarlierManifestNames, withEarlierManifestNames } from "./legac
4
4
  import { humanize, MEMBER_ROLE, FEEDBACK_REPORTER_ROLE } from "./names.js";
5
5
  import { PROPERTY_TYPES } from "./property.js";
6
6
  import { ON_DELETE } from "./relationship.js";
7
- import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isSignInPolicy, } from "./sign-in.js";
7
+ import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isSignInPolicy, isSignUpChannel, } from "./sign-in.js";
8
8
  /**
9
9
  * The manifest format this SDK writes. Readers accept any version and ignore unknown fields. Version
10
10
  * 2 replaced the actions' `allow` with `permission`, and added the roles' `permissions` and the
@@ -57,6 +57,9 @@ import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isSignInPolicy, } from "./si
57
57
  * Within version 15, `chat` may carry `slack` and `whatsapp` beside `telegram`: the connections
58
58
  * exact chat posts to Slack chats and to members' WhatsApp chats go through. Older readers ignore
59
59
  * them, and their services post to Telegram alone.
60
+ * Within version 15, `signIn` may carry `signUp`, the wire names of the roles each channel open to
61
+ * sign-up grants, and `onSignUp`, written only when declared. Older readers ignore them and keep
62
+ * every channel closed to sign-up.
60
63
  */
61
64
  export const MANIFEST_VERSION = 15;
62
65
  /** The first version whose documents use snake_case names on the wire. */
@@ -366,13 +369,24 @@ export const BrowserSignInManifest = Schema.Struct({
366
369
  autoRedirect: Schema.Boolean,
367
370
  local: Schema.optionalKey(Schema.Struct({ port: Schema.Int })),
368
371
  }).pipe(Schema.encodeKeys({ autoRedirect: "auto_redirect" }));
372
+ /** Sign-up: the wire names of the roles each open channel grants. Unknown channels stay closed. */
373
+ export const SignUpManifest = Schema.Struct({
374
+ channels: Schema.Record(Schema.String, Schema.Unknown),
375
+ });
369
376
  export const SignInManifest = Schema.Struct({
370
377
  browser: Schema.optionalKey(BrowserSignInManifest),
371
378
  policy: Schema.String,
372
379
  channels: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)),
373
380
  onNewUser: Schema.optionalKey(Schema.String),
374
381
  codeLink: Schema.optionalKey(Schema.Boolean),
375
- }).pipe(Schema.encodeKeys({ onNewUser: "on_new_user", codeLink: "code_link" }));
382
+ signUp: Schema.optionalKey(SignUpManifest),
383
+ onSignUp: Schema.optionalKey(Schema.String),
384
+ }).pipe(Schema.encodeKeys({
385
+ onNewUser: "on_new_user",
386
+ codeLink: "code_link",
387
+ signUp: "sign_up",
388
+ onSignUp: "on_sign_up",
389
+ }));
376
390
  /** One of the workspace's emails, as `defineOntology({ emails })` declares it; see `EmailTemplate`. */
377
391
  export const EmailTemplateManifest = Schema.Struct({
378
392
  subject: Schema.String,
@@ -503,6 +517,20 @@ export function signInPolicyOf(manifest) {
503
517
  const policy = manifest.signIn?.policy;
504
518
  return isSignInPolicy(policy) ? policy : DEFAULT_SIGN_IN_POLICY;
505
519
  }
520
+ /**
521
+ * The wire names of the roles a stranger who signs up on this channel is given, or `undefined` when
522
+ * the channel is closed to sign-up: not a channel this reader knows, or no well-formed entry.
523
+ */
524
+ export function signUpRolesOf(manifest, channel) {
525
+ if (!isSignUpChannel(channel)) {
526
+ return undefined;
527
+ }
528
+ const roles = manifest.signIn?.signUp?.channels[channel];
529
+ return Array.isArray(roles) && roles.every((role) => typeof role === "string")
530
+ ? roles
531
+ : undefined;
532
+ }
533
+ // @legacy ontology.legacy-channel-admission
506
534
  /** Unsupported providers and missing or unknown channel policies require invitation. */
507
535
  export function channelPolicyOf(manifest, provider) {
508
536
  if (!CHANNEL_PROVIDERS.some((supported) => supported === provider)) {
@@ -741,6 +769,17 @@ export function buildManifest(input) {
741
769
  ...(Object.keys(input.signIn.channels ?? {}).length > 0
742
770
  ? { channels: input.signIn.channels }
743
771
  : {}),
772
+ ...(input.signIn.signUp === undefined
773
+ ? {}
774
+ : {
775
+ signUp: {
776
+ channels: Object.fromEntries(Object.entries(input.signIn.signUp.channels).map(([channel, roles]) => [
777
+ channel,
778
+ [...(roles ?? [])],
779
+ ])),
780
+ },
781
+ }),
782
+ ...(input.signIn.onSignUp === undefined ? {} : { onSignUp: input.signIn.onSignUp }),
744
783
  },
745
784
  ...(Object.keys(emails).length > 0 ? { emails } : {}),
746
785
  ...(input.chat === undefined ? {} : { chat: input.chat }),
@@ -82,8 +82,9 @@ export declare const RUNTIME_TABLES: ReadonlyArray<string>;
82
82
  * The runtime tables the database has, for `planMigration`'s `existingTables`: a database that an
83
83
  * earlier SDK migrated lacks the tables added since.
84
84
  * A grants table without app-session binding is reported incomplete so the idempotent OAuth DDL
85
- * also upgrades an unchanged manifest, and so is an attachments table whose source check predates
86
- * one of {@link ATTACHMENT_SOURCES}, which the idempotent attachment DDL widens.
85
+ * also upgrades an unchanged manifest, and so is an API keys table without `delegation` and an
86
+ * attachments table whose source check predates one of {@link ATTACHMENT_SOURCES}, which the
87
+ * idempotent API key and attachment DDL add and widen.
87
88
  */
88
89
  export declare const readRuntimeTables: (input: CatalogInput) => Effect.Effect<ReadonlySet<string>, SqlError>;
89
90
  /** Only valid, complete covering indexes satisfy the upgrade; failed builds are retried. */
@@ -19,7 +19,7 @@ import { principalsOntology, reconcileWorkflowUsers } from "../runtime/principal
19
19
  import { FEDERATION_TABLES } from "../runtime/federation-tables.js";
20
20
  import { syncUserIdentities, USER_IDENTITY_ENTITY_ID } from "../runtime/user-identities.js";
21
21
  import { resolveReplicationSelection, } from "../replication/model.js";
22
- import { ACTION_ATTRIBUTION_TABLE, AGENT_TABLES, API_KEYS_TABLE, CATALOG_TABLE, OAUTH_TABLES, USER_ROLES_TABLE, quoteIdentifier, quoteLiteral, historyTableName, } from "./storage.js";
22
+ import { ACTION_ATTRIBUTION_TABLE, AGENT_TABLES, API_KEYS_TABLE, CATALOG_TABLE, CHANNEL_USERS_TABLE, OAUTH_TABLES, USER_ROLES_TABLE, quoteIdentifier, quoteLiteral, historyTableName, } from "./storage.js";
23
23
  const CATALOG = quoteIdentifier(CATALOG_TABLE);
24
24
  const IDENTITY_SYNC = "Copy members' sign-in identities the legacy identity stores hold.";
25
25
  /**
@@ -478,8 +478,9 @@ export const RUNTIME_TABLES = [
478
478
  * The runtime tables the database has, for `planMigration`'s `existingTables`: a database that an
479
479
  * earlier SDK migrated lacks the tables added since.
480
480
  * A grants table without app-session binding is reported incomplete so the idempotent OAuth DDL
481
- * also upgrades an unchanged manifest, and so is an attachments table whose source check predates
482
- * one of {@link ATTACHMENT_SOURCES}, which the idempotent attachment DDL widens.
481
+ * also upgrades an unchanged manifest, and so is an API keys table without `delegation` and an
482
+ * attachments table whose source check predates one of {@link ATTACHMENT_SOURCES}, which the
483
+ * idempotent API key and attachment DDL add and widen.
483
484
  */
484
485
  export const readRuntimeTables = (input) => input.sql
485
486
  .unsafe(`SELECT "tablename" AS "name" FROM "pg_catalog"."pg_tables" ` +
@@ -488,6 +489,13 @@ export const readRuntimeTables = (input) => input.sql
488
489
  `AND ("tablename" <> '_oauth_grants' OR EXISTS (` +
489
490
  `SELECT 1 FROM information_schema.columns WHERE table_schema = current_schema() ` +
490
491
  `AND table_name = '_oauth_grants' AND column_name = 'identity_id')) ` +
492
+ // Without `signed_up` the agent tables' idempotent DDL runs again and adds it.
493
+ `AND ("tablename" <> ${quoteLiteral(CHANNEL_USERS_TABLE)} OR EXISTS (` +
494
+ `SELECT 1 FROM information_schema.columns WHERE table_schema = current_schema() ` +
495
+ `AND table_name = ${quoteLiteral(CHANNEL_USERS_TABLE)} AND column_name = 'signed_up')) ` +
496
+ `AND ("tablename" <> ${quoteLiteral(API_KEYS_TABLE)} OR EXISTS (` +
497
+ `SELECT 1 FROM information_schema.columns WHERE table_schema = current_schema() ` +
498
+ `AND table_name = ${quoteLiteral(API_KEYS_TABLE)} AND column_name = 'delegation')) ` +
491
499
  `AND ("tablename" <> ${quoteLiteral(ATTACHMENTS_TABLE)} OR EXISTS (` +
492
500
  `SELECT 1 FROM pg_catalog.pg_constraint c ` +
493
501
  `JOIN pg_catalog.pg_class t ON t.oid = c.conrelid ` +
@@ -400,10 +400,10 @@ export declare const MigrationPlan: Schema.Struct<{
400
400
  readonly telegram?: {
401
401
  readonly connection: string;
402
402
  } | undefined;
403
- readonly slack?: {
403
+ readonly whatsapp?: {
404
404
  readonly connection: string;
405
405
  } | undefined;
406
- readonly whatsapp?: {
406
+ readonly slack?: {
407
407
  readonly connection: string;
408
408
  } | undefined;
409
409
  readonly attribution?: {
@@ -491,6 +491,12 @@ export declare const MigrationPlan: Schema.Struct<{
491
491
  } | undefined;
492
492
  readonly onNewUser?: string | undefined;
493
493
  readonly codeLink?: boolean | undefined;
494
+ readonly signUp?: {
495
+ readonly channels: {
496
+ readonly [x: string]: unknown;
497
+ };
498
+ } | undefined;
499
+ readonly onSignUp?: string | undefined;
494
500
  } | undefined;
495
501
  readonly emails?: {
496
502
  readonly [x: string]: {
@@ -627,10 +633,10 @@ export declare const MigrationPlan: Schema.Struct<{
627
633
  readonly telegram?: {
628
634
  readonly connection: string;
629
635
  } | undefined;
630
- readonly slack?: {
636
+ readonly whatsapp?: {
631
637
  readonly connection: string;
632
638
  } | undefined;
633
- readonly whatsapp?: {
639
+ readonly slack?: {
634
640
  readonly connection: string;
635
641
  } | undefined;
636
642
  readonly attribution?: {
@@ -718,6 +724,12 @@ export declare const MigrationPlan: Schema.Struct<{
718
724
  } | undefined;
719
725
  readonly onNewUser?: string | undefined;
720
726
  readonly codeLink?: boolean | undefined;
727
+ readonly signUp?: {
728
+ readonly channels: {
729
+ readonly [x: string]: unknown;
730
+ };
731
+ } | undefined;
732
+ readonly onSignUp?: string | undefined;
721
733
  } | undefined;
722
734
  readonly emails?: {
723
735
  readonly [x: string]: {
@@ -854,10 +866,10 @@ export declare const MigrationPlan: Schema.Struct<{
854
866
  readonly telegram?: {
855
867
  readonly connection: string;
856
868
  } | undefined;
857
- readonly slack?: {
869
+ readonly whatsapp?: {
858
870
  readonly connection: string;
859
871
  } | undefined;
860
- readonly whatsapp?: {
872
+ readonly slack?: {
861
873
  readonly connection: string;
862
874
  } | undefined;
863
875
  readonly attribution?: {
@@ -961,6 +973,12 @@ export declare const MigrationPlan: Schema.Struct<{
961
973
  } | undefined;
962
974
  readonly on_new_user?: string | undefined;
963
975
  readonly code_link?: boolean | undefined;
976
+ readonly sign_up?: {
977
+ readonly channels: {
978
+ readonly [x: string]: unknown;
979
+ };
980
+ } | undefined;
981
+ readonly on_sign_up?: string | undefined;
964
982
  } | undefined;
965
983
  } | {
966
984
  readonly version: number;
@@ -1081,10 +1099,10 @@ export declare const MigrationPlan: Schema.Struct<{
1081
1099
  readonly telegram?: {
1082
1100
  readonly connection: string;
1083
1101
  } | undefined;
1084
- readonly slack?: {
1102
+ readonly whatsapp?: {
1085
1103
  readonly connection: string;
1086
1104
  } | undefined;
1087
- readonly whatsapp?: {
1105
+ readonly slack?: {
1088
1106
  readonly connection: string;
1089
1107
  } | undefined;
1090
1108
  readonly attribution?: {
@@ -1172,6 +1190,12 @@ export declare const MigrationPlan: Schema.Struct<{
1172
1190
  } | undefined;
1173
1191
  readonly on_new_user?: string | undefined;
1174
1192
  readonly code_link?: boolean | undefined;
1193
+ readonly sign_up?: {
1194
+ readonly channels: {
1195
+ readonly [x: string]: unknown;
1196
+ };
1197
+ } | undefined;
1198
+ readonly on_sign_up?: string | undefined;
1175
1199
  } | undefined;
1176
1200
  readonly emails?: {
1177
1201
  readonly [x: string]: {
@@ -1341,9 +1365,15 @@ export declare const MigrationPlan: Schema.Struct<{
1341
1365
  readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
1342
1366
  readonly onNewUser: Schema.optionalKey<Schema.String>;
1343
1367
  readonly codeLink: Schema.optionalKey<Schema.Boolean>;
1368
+ readonly signUp: Schema.optionalKey<Schema.Struct<{
1369
+ readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
1370
+ }>>;
1371
+ readonly onSignUp: Schema.optionalKey<Schema.String>;
1344
1372
  }>, {
1345
1373
  readonly onNewUser: "on_new_user";
1346
1374
  readonly codeLink: "code_link";
1375
+ readonly signUp: "sign_up";
1376
+ readonly onSignUp: "on_sign_up";
1347
1377
  }>>;
1348
1378
  readonly emails: Schema.optionalKey<Schema.$Record<Schema.String, Schema.encodeKeys<Schema.Struct<{
1349
1379
  readonly subject: Schema.String;
@@ -1563,9 +1593,15 @@ export declare const MigrationPlan: Schema.Struct<{
1563
1593
  readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
1564
1594
  readonly onNewUser: Schema.optionalKey<Schema.String>;
1565
1595
  readonly codeLink: Schema.optionalKey<Schema.Boolean>;
1596
+ readonly signUp: Schema.optionalKey<Schema.Struct<{
1597
+ readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
1598
+ }>>;
1599
+ readonly onSignUp: Schema.optionalKey<Schema.String>;
1566
1600
  }>, {
1567
1601
  readonly onNewUser: "on_new_user";
1568
1602
  readonly codeLink: "code_link";
1603
+ readonly signUp: "sign_up";
1604
+ readonly onSignUp: "on_sign_up";
1569
1605
  }>>;
1570
1606
  readonly emails: Schema.optionalKey<Schema.$Record<Schema.String, Schema.encodeKeys<Schema.Struct<{
1571
1607
  readonly subject: Schema.String;
@@ -1765,10 +1801,10 @@ export declare const MigrationPlan: Schema.Struct<{
1765
1801
  readonly telegram?: {
1766
1802
  readonly connection: string;
1767
1803
  } | undefined;
1768
- readonly slack?: {
1804
+ readonly whatsapp?: {
1769
1805
  readonly connection: string;
1770
1806
  } | undefined;
1771
- readonly whatsapp?: {
1807
+ readonly slack?: {
1772
1808
  readonly connection: string;
1773
1809
  } | undefined;
1774
1810
  readonly attribution?: {
@@ -1856,6 +1892,12 @@ export declare const MigrationPlan: Schema.Struct<{
1856
1892
  } | undefined;
1857
1893
  readonly onNewUser?: string | undefined;
1858
1894
  readonly codeLink?: boolean | undefined;
1895
+ readonly signUp?: {
1896
+ readonly channels: {
1897
+ readonly [x: string]: unknown;
1898
+ };
1899
+ } | undefined;
1900
+ readonly onSignUp?: string | undefined;
1859
1901
  } | undefined;
1860
1902
  readonly emails?: {
1861
1903
  readonly [x: string]: {
@@ -1992,10 +2034,10 @@ export declare const MigrationPlan: Schema.Struct<{
1992
2034
  readonly telegram?: {
1993
2035
  readonly connection: string;
1994
2036
  } | undefined;
1995
- readonly slack?: {
2037
+ readonly whatsapp?: {
1996
2038
  readonly connection: string;
1997
2039
  } | undefined;
1998
- readonly whatsapp?: {
2040
+ readonly slack?: {
1999
2041
  readonly connection: string;
2000
2042
  } | undefined;
2001
2043
  readonly attribution?: {
@@ -2083,6 +2125,12 @@ export declare const MigrationPlan: Schema.Struct<{
2083
2125
  } | undefined;
2084
2126
  readonly onNewUser?: string | undefined;
2085
2127
  readonly codeLink?: boolean | undefined;
2128
+ readonly signUp?: {
2129
+ readonly channels: {
2130
+ readonly [x: string]: unknown;
2131
+ };
2132
+ } | undefined;
2133
+ readonly onSignUp?: string | undefined;
2086
2134
  } | undefined;
2087
2135
  readonly emails?: {
2088
2136
  readonly [x: string]: {
@@ -4,7 +4,7 @@ import { EMAIL_LINK_FENCE_SQL, SEGMENTSTREAM_LINK_FENCE_SQL, USER_IDENTITY_ENTIT
4
4
  import { AGENT_TASKS_DDL, AGENT_TASKS_TABLE, SIGN_IN_EMAILS_DDL, SIGN_IN_EMAILS_TABLE, ATTACHMENTS_TABLE, ATTACHMENT_TABLES_DDL, BLOB_TABLES_DDL, WORKFLOW_STARTS_DDL, WORKFLOW_STARTS_TABLE, } from "../storage/tables.js";
5
5
  import { SNAKE_CASE_NAME, isSystemProperty, toSnakeCase } from "../names.js";
6
6
  import { NO_RETAINED_STORAGE, retainedEntityManifest, } from "./model.js";
7
- import { ACTION_ATTRIBUTION_TABLE, ACTION_ATTRIBUTION_DDL, AGENT_TABLES, AGENT_TABLES_DDL, CATALOG_TABLE_DDL, MAX_IDENTIFIER_LENGTH, OAUTH_TABLES, OAUTH_TABLES_DDL, USER_TABLE, addConstraintStatement, columnName, columnDefinition, constraintDefinition, createEnumStatement, createIndexStatement, createTableStatement, defaultExpression, entityStorage, historyActivityIndex, enumTypeName, isStoredProperty, fieldColumnName, joinTable, propertyCheck, blobForeignKey, propertyColumn, propertyEnum, quoteIdentifier, quoteLiteral, relationshipColumn, relationshipColumnName, RUNTIME_TABLES_DDL, relationshipForeignKey, SYSTEM_COLUMNS, storedEntity, tableName, } from "./storage.js";
7
+ import { ACTION_ATTRIBUTION_TABLE, ACTION_ATTRIBUTION_DDL, AGENT_TABLES, AGENT_TABLES_DDL, API_KEYS_DDL, API_KEYS_TABLE, CATALOG_TABLE_DDL, MAX_IDENTIFIER_LENGTH, OAUTH_TABLES, OAUTH_TABLES_DDL, USER_TABLE, addConstraintStatement, columnName, columnDefinition, constraintDefinition, createEnumStatement, createIndexStatement, createTableStatement, defaultExpression, entityStorage, historyActivityIndex, enumTypeName, isStoredProperty, fieldColumnName, joinTable, propertyCheck, blobForeignKey, propertyColumn, propertyEnum, quoteIdentifier, quoteLiteral, relationshipColumn, relationshipColumnName, RUNTIME_TABLES_DDL, relationshipForeignKey, SYSTEM_COLUMNS, storedEntity, tableName, } from "./storage.js";
8
8
  const NO_MEMBERS = { properties: new Set(), relationships: new Set() };
9
9
  const GLOBAL_KINDS = new Set(["table", "type", "index"]);
10
10
  function step(input) {
@@ -169,6 +169,14 @@ export function planMigration(input) {
169
169
  sql: FEDERATION_TABLES_DDL,
170
170
  }));
171
171
  }
172
+ if (lacks([API_KEYS_TABLE])) {
173
+ draft.runtimeTables.push(step({
174
+ kind: "createCatalog",
175
+ classification: "additive",
176
+ description: "Let API keys act for members with delegation, beside the keys that act with roles.",
177
+ sql: API_KEYS_DDL,
178
+ }));
179
+ }
172
180
  if (lacks(OAUTH_TABLES)) {
173
181
  draft.runtimeTables.push(step({
174
182
  kind: "createCatalog",