@samebase/alchemy-convex 0.35.0 → 0.37.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.
@@ -1,6 +1,8 @@
1
- // Convex.SharedHubClient: one deployment of an app as a client of the identity hub that the stack
1
+ // IdentityHub.Client: one deployment of an app as a client of the identity hub that the stack
2
2
  // names, for an app that deploys in its own GitHub Actions run, on any host, and in development as a
3
- // stage of the same stack.
3
+ // stage of the same stack. Import it as
4
+ // `import * as IdentityHub from "@samebase/alchemy-convex/identity-hub"`; `Convex.providers()`
5
+ // registers its provider.
4
6
  //
5
7
  // A run in GitHub Actions asks the hub for a new client with a GitHub OIDC token, so the stack needs
6
8
  // no key and no Samebase account. The token names the repository. The hub reads
@@ -12,7 +14,7 @@
12
14
  //
13
15
  // The answer to a production registration also holds the app's initial access token (RFC 7591
14
16
  // section 1.2) and the repository id. The state of stage `prod` keeps them. A development checkout
15
- // runs the stack as a stage `dev-<name>`: it reads them with `SharedHubClient.read`, and a client
17
+ // runs the stack as a stage `dev-<name>`: it reads them with `IdentityHub.Client.read`, and a client
16
18
  // with `deploymentType: "development"` asks the hub with the token in place of the GitHub token
17
19
  // (RFC 133).
18
20
  //
@@ -100,9 +102,9 @@ interface CommonProps {
100
102
 
101
103
  /**
102
104
  * A production or preview client asks with the GitHub OIDC token of the run. A development client
103
- * asks with the app's initial access token, which `SharedHubClient.read` gives from stage `prod`.
105
+ * asks with the app's initial access token, which `IdentityHub.Client.read` gives from stage `prod`.
104
106
  */
105
- export type SharedHubClientProps =
107
+ export type ClientProps =
106
108
  | (CommonProps & {
107
109
  readonly deploymentType: "production" | "preview";
108
110
  readonly initialAccessToken?: never;
@@ -142,33 +144,22 @@ const Attributes = Schema.Struct({
142
144
 
143
145
  /**
144
146
  * The attributes keep the real values of a suspended client, so that an unblock needs no new client.
145
- * `SharedHubClient.variables` gives the values that the app gets.
147
+ * `IdentityHub.Client.variables` gives the values that the app gets.
146
148
  */
147
- export interface SharedHubClientAttributes extends Schema.Schema.Type<typeof Attributes> {}
149
+ export interface ClientAttributes extends Schema.Schema.Type<typeof Attributes> {}
148
150
 
149
151
  /**
150
- * The attributes of a saved row, or undefined when the row does not have this version's shape, such
151
- * as a row that 0.26 or earlier saved without the token fields. Only a schema issue gives undefined;
152
- * any other failure of the decoder stops the run with a fixed message. The text of a schema issue
153
- * can quote a value of the row, so it is never kept.
152
+ * The attributes of a saved row. A row that does not have this version's shape, or any other
153
+ * failure of the decoder, stops the run with `reason`. The text of a schema issue can quote a value
154
+ * of the row, so it is never kept.
154
155
  */
155
- const savedAttributes = (value: unknown) =>
156
+ const savedAttributes = (value: unknown, reason: string) =>
156
157
  Schema.decodeUnknownEffect(Attributes)(value).pipe(
157
- Effect.map((attributes): SharedHubClientAttributes | undefined => attributes),
158
- Effect.catch(() => Effect.succeed(undefined)),
159
- Effect.catchDefect(() =>
160
- Effect.die(
161
- new SharedHubClientFailed({
162
- reason: "the state holds attributes of Convex.SharedHubClient that it cannot read",
163
- }),
164
- ),
165
- ),
158
+ Effect.catchCause(() => Effect.die(new IdentityHubClientFailed({ reason }))),
166
159
  );
167
160
 
168
161
  /** The attributes of no client. */
169
- const offAttributes = (
170
- deploymentType: SharedHubClientAttributes["deploymentType"],
171
- ): SharedHubClientAttributes => ({
162
+ const offAttributes = (deploymentType: ClientAttributes["deploymentType"]): ClientAttributes => ({
172
163
  status: "off",
173
164
  issuer: OFF_VALUES.issuer,
174
165
  clientId: OFF_VALUES.clientId,
@@ -189,12 +180,12 @@ const sameSet = (a: readonly string[], b: readonly string[]) =>
189
180
  a.length === b.length && a.every((name, index) => name === b[index]);
190
181
 
191
182
  /** One request gave no usable answer. The reason holds no secret. */
192
- class SharedHubClientFailed extends Schema.TaggedError<SharedHubClientFailed>()(
193
- "SharedHubClientFailed",
183
+ class IdentityHubClientFailed extends Schema.TaggedError<IdentityHubClientFailed>()(
184
+ "IdentityHubClientFailed",
194
185
  { reason: Schema.String },
195
186
  ) {
196
187
  override get message() {
197
- return `Convex.SharedHubClient: ${this.reason}.`;
188
+ return `IdentityHub.Client: ${this.reason}.`;
198
189
  }
199
190
  }
200
191
 
@@ -299,14 +290,14 @@ const send = (who: string, url: string, token: string, init: { method: string; b
299
290
  const body: unknown = await response.json().catch(() => undefined);
300
291
  return { status: response.status, body };
301
292
  },
302
- catch: () => new SharedHubClientFailed({ reason: `${who} gave no answer` }),
293
+ catch: () => new IdentityHubClientFailed({ reason: `${who} gave no answer` }),
303
294
  });
304
295
 
305
296
  const decode =
306
297
  <S extends Schema.Codec<unknown, unknown>>(schema: S, who: string) =>
307
298
  (value: unknown) =>
308
299
  Schema.decodeUnknownEffect(schema)(value).pipe(
309
- Effect.mapError(() => new SharedHubClientFailed({ reason: `${who} gave a bad answer` })),
300
+ Effect.mapError(() => new IdentityHubClientFailed({ reason: `${who} gave a bad answer` })),
310
301
  );
311
302
 
312
303
  /**
@@ -322,7 +313,7 @@ const readOidcToken = (requestUrl: string, requestToken: string, audience: strin
322
313
  { method: "GET" },
323
314
  );
324
315
  if (status !== 200) {
325
- return yield* new SharedHubClientFailed({
316
+ return yield* new IdentityHubClientFailed({
326
317
  reason: `GitHub gave no OIDC token (HTTP ${status})`,
327
318
  });
328
319
  }
@@ -330,11 +321,7 @@ const readOidcToken = (requestUrl: string, requestToken: string, audience: strin
330
321
  });
331
322
 
332
323
  /** `POST /hub-clients` with `bearer`: the GitHub OIDC token, or the app's initial access token. */
333
- const requestNewClient = (
334
- props: SharedHubClientProps,
335
- connectors: readonly string[],
336
- bearer: string,
337
- ) =>
324
+ const requestNewClient = (props: ClientProps, connectors: readonly string[], bearer: string) =>
338
325
  Effect.gen(function* () {
339
326
  const { hub } = props;
340
327
  const { body, status } = yield* send("The identity hub", `${hub.issuer}/hub-clients`, bearer, {
@@ -351,7 +338,7 @@ const requestNewClient = (
351
338
  status === 401 && props.deploymentType === "development"
352
339
  ? "the identity hub refused the initial access token"
353
340
  : refusalOf(status, body);
354
- return yield* new SharedHubClientFailed({ reason: `${reason} (HTTP ${status})` });
341
+ return yield* new IdentityHubClientFailed({ reason: `${reason} (HTTP ${status})` });
355
342
  }
356
343
  const client = yield* decode(NewClient, "The identity hub")(body);
357
344
  // The hub registers the address and the connectors that the request sent, under its own issuer
@@ -363,10 +350,10 @@ const requestNewClient = (
363
350
  !sameSet(client.connectors, connectors) ||
364
351
  client.terms !== hub.terms
365
352
  ) {
366
- return yield* new SharedHubClientFailed({ reason: "The identity hub gave a bad answer" });
353
+ return yield* new IdentityHubClientFailed({ reason: "The identity hub gave a bad answer" });
367
354
  }
368
355
  yield* Effect.logInfo(
369
- `Convex.SharedHubClient: ${props.app} on ${props.redirectUri} has a new client of the identity hub. Its use is under ${hub.terms}.`,
356
+ `IdentityHub.Client: ${props.app} on ${props.redirectUri} has a new client of the identity hub. Its use is under ${hub.terms}.`,
370
357
  );
371
358
  // Only a production registration gives the app's token (RFC 7591); any other answer's is dropped.
372
359
  const production = props.deploymentType === "production";
@@ -386,13 +373,13 @@ const requestNewClient = (
386
373
  });
387
374
 
388
375
  /** A new client, or the off values. */
389
- const newClient = (props: SharedHubClientProps, connectors: readonly string[]) => {
390
- const label = `Convex.SharedHubClient: ${props.app} on ${props.redirectUri} deploys without the hub`;
376
+ const newClient = (props: ClientProps, connectors: readonly string[]) => {
377
+ const label = `IdentityHub.Client: ${props.app} on ${props.redirectUri} deploys without the hub`;
391
378
  const off = offAttributes(props.deploymentType);
392
- const request = (bearer: Effect.Effect<string, SharedHubClientFailed>) =>
379
+ const request = (bearer: Effect.Effect<string, IdentityHubClientFailed>) =>
393
380
  bearer.pipe(
394
381
  Effect.flatMap((token) => requestNewClient(props, connectors, token)),
395
- Effect.catchTag("SharedHubClientFailed", (error) =>
382
+ Effect.catchTag("IdentityHubClientFailed", (error) =>
396
383
  Effect.logWarning(`${label}: ${error.reason}. The next deploy asks again.`).pipe(
397
384
  Effect.as(off),
398
385
  ),
@@ -403,7 +390,7 @@ const newClient = (props: SharedHubClientProps, connectors: readonly string[]) =
403
390
  const token = Redacted.value(props.initialAccessToken);
404
391
  return token === ""
405
392
  ? Effect.logInfo(
406
- "Convex.SharedHubClient: deploy to main once for hub sign-in in development.",
393
+ "IdentityHub.Client: deploy to main once for hub sign-in in development.",
407
394
  ).pipe(Effect.as(off))
408
395
  : request(Effect.succeed(token));
409
396
  }
@@ -428,7 +415,7 @@ const newClient = (props: SharedHubClientProps, connectors: readonly string[]) =
428
415
  * passes a run only when the hub confirms it in that run, so a suspension that an earlier run saw,
429
416
  * and did not save because that run failed, cannot pass a run that the hub does not answer.
430
417
  */
431
- const renew = (saved: SharedHubClientAttributes, required: boolean) =>
418
+ const renew = (saved: ClientAttributes, required: boolean) =>
432
419
  Effect.gen(function* () {
433
420
  const { status } = yield* send(
434
421
  "The identity hub",
@@ -443,31 +430,38 @@ const renew = (saved: SharedHubClientAttributes, required: boolean) =>
443
430
  return undefined;
444
431
  case 403:
445
432
  yield* Effect.logWarning(
446
- `Convex.SharedHubClient: the hub suspended the client of ${saved.redirectUri}. It keeps its values, and nobody can sign in with it.`,
433
+ `IdentityHub.Client: the hub suspended the client of ${saved.redirectUri}. It keeps its values, and nobody can sign in with it.`,
447
434
  );
448
435
  return { ...saved, status: "suspended" as const };
449
436
  default:
450
- return yield* new SharedHubClientFailed({
437
+ return yield* new IdentityHubClientFailed({
451
438
  reason: `The identity hub answered HTTP ${status}`,
452
439
  });
453
440
  }
454
441
  }).pipe(
455
- Effect.catchTag("SharedHubClientFailed", (error) =>
442
+ Effect.catchTag("IdentityHubClientFailed", (error) =>
456
443
  required
457
444
  ? Effect.fail(
458
- new SharedHubClientFailed({
445
+ new IdentityHubClientFailed({
459
446
  reason: `${saved.redirectUri} is required, and the hub did not confirm its client: ${error.reason}`,
460
447
  }),
461
448
  )
462
449
  : Effect.logWarning(
463
- `Convex.SharedHubClient: ${saved.redirectUri} keeps the saved client: ${error.reason}.`,
450
+ `IdentityHub.Client: ${saved.redirectUri} keeps the saved client: ${error.reason}.`,
464
451
  ).pipe(Effect.as(saved)),
465
452
  ),
466
453
  );
467
454
 
455
+ /**
456
+ * The type of this resource before 0.37.0. Alchemy finds this provider for a row of that type, and
457
+ * the next write of the row gives it the new type, with the same client. Remove it, here and in
458
+ * `SavedRow`, once no saved row has the old type.
459
+ */
460
+ const OLD_TYPE = "IdentityHub.SharedClient";
461
+
468
462
  /** A saved row of this resource, whose `attr` `savedAttributes` reads. */
469
463
  const SavedRow = Schema.Struct({
470
- resourceType: Schema.Literal("IdentityHub.SharedClient"),
464
+ resourceType: Schema.Literals(["IdentityHub.Client", OLD_TYPE]),
471
465
  attr: Schema.Unknown,
472
466
  });
473
467
 
@@ -477,7 +471,7 @@ const SavedRow = Schema.Struct({
477
471
  * `initialAccessToken` and the `repository` of the production client. Without that row, the off
478
472
  * attributes, with `deploymentType: "production"`.
479
473
  *
480
- * `SharedHubClient.ref` is not enough: Alchemy fails the plan with `InvalidReferenceError` when the
474
+ * `IdentityHub.Client.ref` is not enough: Alchemy fails the plan with `InvalidReferenceError` when the
481
475
  * row is missing, and a development stage before the first deploy to main has none. This read runs
482
476
  * when the plan resolves it, with the State service of the running stack and its `get`, so it never
483
477
  * creates or upgrades a store. The store revives each secret as `Redacted`, as it does for every
@@ -495,30 +489,26 @@ const read = (id: string, options: { readonly stage: string }) =>
495
489
  const { attr } = yield* Schema.decodeUnknownEffect(SavedRow)(row).pipe(
496
490
  Effect.catchCause(() =>
497
491
  Effect.die(
498
- new SharedHubClientFailed({
499
- reason: `the row ${id} of stage ${options.stage} is not a Convex.SharedHubClient`,
492
+ new IdentityHubClientFailed({
493
+ reason: `the row ${id} of stage ${options.stage} is not an IdentityHub.Client`,
500
494
  }),
501
495
  ),
502
496
  ),
503
497
  );
504
- const saved = yield* savedAttributes(attr);
505
- if (saved === undefined) {
506
- return yield* Effect.die(
507
- new SharedHubClientFailed({
508
- reason: `the row ${id} of stage ${options.stage} holds attributes that this version cannot read`,
509
- }),
510
- );
511
- }
512
- return saved;
498
+ return yield* savedAttributes(
499
+ attr,
500
+ `the row ${id} of stage ${options.stage} holds attributes that this version cannot read`,
501
+ );
513
502
  }),
514
503
  );
515
504
 
516
505
  /**
517
- * The three values that the app's deployment gets, such as `HUB_ISSUER`, `HUB_CLIENT_ID`, and
518
- * `HUB_CLIENT_SECRET`, as Outputs: the client's values when `status` is `on`, else the off values,
519
- * so that a suspended client gives guest sign-in and keeps its values in state.
506
+ * The three values that the app's deployment gets, such as `IDENTITY_HUB_ISSUER`,
507
+ * `IDENTITY_HUB_CLIENT_ID`, and `IDENTITY_HUB_CLIENT_SECRET`, as Outputs: the client's values when
508
+ * `status` is `on`, else the off values, so that a suspended client gives guest sign-in and keeps
509
+ * its values in state.
520
510
  */
521
- const variables = (client: SharedHubClient) =>
511
+ const variables = (client: Client) =>
522
512
  Output.map(Output.of(client), (attributes) =>
523
513
  attributes.status === "on"
524
514
  ? {
@@ -533,20 +523,20 @@ const variables = (client: SharedHubClient) =>
533
523
  },
534
524
  );
535
525
 
536
- export type SharedHubClient = Resource<
537
- "IdentityHub.SharedClient",
538
- SharedHubClientProps,
539
- SharedHubClientAttributes,
526
+ export type Client = Resource<
527
+ "IdentityHub.Client",
528
+ ClientProps,
529
+ ClientAttributes,
540
530
  never,
541
531
  Providers
542
532
  >;
543
- export const SharedHubClient = Resource<SharedHubClient>("IdentityHub.SharedClient")({
533
+ export const Client = Resource<Client>("IdentityHub.Client", { aliases: [OLD_TYPE] })({
544
534
  read,
545
535
  variables,
546
536
  });
547
537
 
548
- export const SharedHubClientProvider = () =>
549
- Provider.succeed(SharedHubClient, {
538
+ export const ClientProvider = () =>
539
+ Provider.succeed(Client, {
550
540
  // Always an update, so that each deploy reaches the hub. No attribute is stable, so a push
551
541
  // reads the values that this run ended with. The same values cause no other push.
552
542
  diff: ({ news }) =>
@@ -555,16 +545,14 @@ export const SharedHubClientProvider = () =>
555
545
  read: ({ output }) => Effect.succeed(output),
556
546
 
557
547
  // Only a client of the same hub (its issuer), return address, type, and connector set is
558
- // renewed. A saved row without this version's shape, such as one that 0.32 or earlier saved, is
559
- // no client: the run asks for a new one, which replaces the saved client, and for a production
560
- // client also replaces the app's initial access token.
548
+ // renewed. A saved row without this version's shape stops the run with a fixed message.
561
549
  reconcile: Effect.fn(function* ({ news, output }) {
562
550
  // A bad prop is a mistake of the stack, not of the hub: the run fails, with no request.
563
551
  if (
564
552
  news.connectors.length === 0 ||
565
553
  !news.connectors.every((name) => CONNECTOR_NAME.test(name))
566
554
  ) {
567
- return yield* new SharedHubClientFailed({
555
+ return yield* new IdentityHubClientFailed({
568
556
  reason: `${news.app} on ${news.redirectUri} needs connectors: one or more names of [a-z0-9-]{1,64}`,
569
557
  });
570
558
  }
@@ -572,12 +560,10 @@ export const SharedHubClientProvider = () =>
572
560
  const saved =
573
561
  output === undefined || output.status === "off"
574
562
  ? undefined
575
- : yield* savedAttributes(output);
576
- if (output !== undefined && output.status !== "off" && saved === undefined) {
577
- yield* Effect.logWarning(
578
- `Convex.SharedHubClient: the saved attributes of ${news.app} on ${news.redirectUri} cannot be read by this version, so this run registers a new client, which replaces the saved one.`,
579
- );
580
- }
563
+ : yield* savedAttributes(
564
+ output,
565
+ `the saved attributes of ${news.app} on ${news.redirectUri} cannot be read by this version`,
566
+ );
581
567
  const renewed =
582
568
  saved?.issuer === news.hub.issuer &&
583
569
  saved.redirectUri === news.redirectUri &&
@@ -587,7 +573,7 @@ export const SharedHubClientProvider = () =>
587
573
  : undefined;
588
574
  const client = renewed ?? (yield* newClient(news, connectors));
589
575
  if (news.required === true && client.status !== "on") {
590
- return yield* new SharedHubClientFailed({
576
+ return yield* new IdentityHubClientFailed({
591
577
  reason: `${news.app} on ${news.redirectUri} is required and has no working client (${client.status}). The warning above names the reason`,
592
578
  });
593
579
  }
@@ -608,14 +594,14 @@ export const SharedHubClientProvider = () =>
608
594
  );
609
595
  // 401: the client is gone already.
610
596
  if (status !== 204 && status !== 401) {
611
- return yield* new SharedHubClientFailed({
597
+ return yield* new IdentityHubClientFailed({
612
598
  reason: `The identity hub answered HTTP ${status}`,
613
599
  });
614
600
  }
615
601
  }).pipe(
616
- Effect.catchTag("SharedHubClientFailed", (error) =>
602
+ Effect.catchTag("IdentityHubClientFailed", (error) =>
617
603
  Effect.logWarning(
618
- `Convex.SharedHubClient: the client of ${output.redirectUri} stays on the hub until its removal date: ${error.reason}.`,
604
+ `IdentityHub.Client: the client of ${output.redirectUri} stays on the hub until its removal date: ${error.reason}.`,
619
605
  ),
620
606
  ),
621
607
  ),
package/src/Providers.ts CHANGED
@@ -4,10 +4,10 @@ import * as Provider from "alchemy/Provider";
4
4
  import * as Layer from "effect/Layer";
5
5
  import { type Credentials, fromConfig } from "./Credentials.ts";
6
6
  import { DeploymentProvider, DeploymentResource } from "./Deployment.ts";
7
+ import * as IdentityHub from "./IdentityHub.ts";
7
8
  import { LocalDeployment, LocalDeploymentProvider } from "./LocalDeployment.ts";
8
9
  import { ManagementApiLive } from "./ManagementApi.ts";
9
10
  import { Project, ProjectProvider } from "./Project.ts";
10
- import { SharedHubClient, SharedHubClientProvider } from "./SharedHubClient.ts";
11
11
 
12
12
  export class Providers extends Provider.ProviderCollection<Providers>()("Convex") {}
13
13
 
@@ -19,14 +19,14 @@ export class Providers extends Provider.ProviderCollection<Providers>()("Convex"
19
19
  export const providers = (credentials: Layer.Layer<Credentials> = fromConfig()) =>
20
20
  Layer.effect(
21
21
  Providers,
22
- Provider.collection([Project, DeploymentResource, LocalDeployment, SharedHubClient]),
22
+ Provider.collection([Project, DeploymentResource, LocalDeployment, IdentityHub.Client]),
23
23
  ).pipe(
24
24
  Layer.provide(
25
25
  Layer.mergeAll(
26
26
  ProjectProvider(),
27
27
  DeploymentProvider(),
28
28
  LocalDeploymentProvider(),
29
- SharedHubClientProvider(),
29
+ IdentityHub.ClientProvider(),
30
30
  ),
31
31
  ),
32
32
  Layer.provide(ManagementApiLive()),
package/src/Push.ts CHANGED
@@ -511,8 +511,10 @@ export const checkSource = (rootDir: string, input: Source) =>
511
511
  /**
512
512
  * Sets the `env` variables and pushes the functions of `source` to one
513
513
  * deployment with `key`: a deploy key of the deployment, or a preview deploy
514
- * key of its project with `previewName`. Returns the URL that the CLI
515
- * printed, or undefined without `source`.
514
+ * key of its project with `previewName`. A name of `previousEnvNames` that
515
+ * left `env` is removed after a successful push, or, without `source`, in the
516
+ * same write as the new values. Returns the URL that the CLI printed, or
517
+ * undefined without `source`.
516
518
  */
517
519
  export const push = (
518
520
  spawner: ChildProcessSpawner.ChildProcessSpawner["Service"],
@@ -529,6 +531,10 @@ export const push = (
529
531
  const program = resolved?.program;
530
532
  const env = Object.entries(options.env).sort(([a], [b]) => (a < b ? -1 : 1));
531
533
  const removed = options.previousEnvNames.filter((name) => !Object.hasOwn(options.env, name));
534
+ // The code on the deployment can require a name that left `env`, and Convex refuses a write
535
+ // that removes a variable the running code requires. With a push, such names go only after the
536
+ // push succeeded, so a renamed variable reaches the new code first; a failed push keeps them.
537
+ const removedBeforePush = source === undefined ? removed : [];
532
538
 
533
539
  // 1. Variables before the push, so the push sees them. Each attempt
534
540
  // reads the current values first, so a retry after a write conflict never
@@ -536,7 +542,7 @@ export const push = (
536
542
  // changed values are written, and the earlier ones are kept for a
537
543
  // rollback.
538
544
  const written =
539
- env.length === 0 && removed.length === 0
545
+ env.length === 0 && removedBeforePush.length === 0
540
546
  ? { current: {}, changes: [] }
541
547
  : yield* retryIdempotentWrite(
542
548
  Effect.gen(function* () {
@@ -563,7 +569,7 @@ export const push = (
563
569
  ...env
564
570
  .filter(([name, value]) => current[name] !== valueOf(value))
565
571
  .map(([name, value]) => ({ name, value: valueOf(value) })),
566
- ...removed
572
+ ...removedBeforePush
567
573
  .filter((name) => Object.hasOwn(current, name))
568
574
  .map((name) => ({ name, value: null })),
569
575
  ];
@@ -572,6 +578,20 @@ export const push = (
572
578
  }),
573
579
  );
574
580
 
581
+ /** After a successful push: removes the names that left `env`, as the variables are now. */
582
+ const removeAfterPush =
583
+ removedBeforePush.length === removed.length
584
+ ? Effect.void
585
+ : retryIdempotentWrite(
586
+ Effect.gen(function* () {
587
+ const current = yield* listVariables(options.url, key);
588
+ const changes = removed
589
+ .filter((name) => Object.hasOwn(current, name))
590
+ .map((name) => ({ name, value: null }));
591
+ if (changes.length > 0) yield* writeVariables(options.url, key, changes);
592
+ }),
593
+ );
594
+
575
595
  /**
576
596
  * After a failed push, the variables go back to their earlier values, so
577
597
  * that the deployment matches the hash in state. A failed rollback is
@@ -601,9 +621,16 @@ export const push = (
601
621
 
602
622
  // 2. The push, with the key only in the env file.
603
623
  if (source === undefined || cwd === undefined || program === undefined) return undefined;
604
- return yield* runPush(spawner, key, { ...options, cwd, program, command: source.command }).pipe(
605
- Effect.onError(() => rollback),
606
- );
624
+ const url = yield* runPush(spawner, key, {
625
+ ...options,
626
+ cwd,
627
+ program,
628
+ command: source.command,
629
+ }).pipe(Effect.onError(() => rollback));
630
+ // 3. The names that left `env`, now that the new code runs. A failure here fails the run with
631
+ // the earlier state, which still lists these names, so the next run removes them.
632
+ yield* removeAfterPush;
633
+ return url;
607
634
  });
608
635
 
609
636
  /** Runs the installed CLI or the push command once, and checks the deployment that it names. */
@@ -53,7 +53,9 @@ const Resource = Schema.Union([
53
53
  }),
54
54
  }),
55
55
  Schema.Struct({
56
- resourceType: Schema.Literal("IdentityHub.SharedClient"),
56
+ // A row keeps the type before 0.37.0 until its next write. Remove the old type once no saved
57
+ // row has it.
58
+ resourceType: Schema.Literals(["IdentityHub.Client", "IdentityHub.SharedClient"]),
57
59
  attr: Schema.Struct({
58
60
  status: Schema.Literals(["on", "off", "suspended"]),
59
61
  connectors: Schema.Array(Schema.String),
@@ -190,6 +192,7 @@ const resourceRow = (resource: Resource, address: string | null) => {
190
192
  bucketName,
191
193
  );
192
194
  }
195
+ case "IdentityHub.Client":
193
196
  case "IdentityHub.SharedClient": {
194
197
  const { status, connectors } = resource.attr;
195
198
  return status === "off"
package/src/index.ts CHANGED
@@ -44,12 +44,6 @@ export {
44
44
  runRecord,
45
45
  withRunRecord,
46
46
  } from "./RunRecord.ts";
47
- export {
48
- type Hub,
49
- SharedHubClient,
50
- type SharedHubClientAttributes,
51
- type SharedHubClientProps,
52
- } from "./SharedHubClient.ts";
53
47
  export { state, STORE_PROJECT_NAME } from "./State.ts";
54
48
  export {
55
49
  CodePushFailed,
@@ -78,12 +78,6 @@ export const newKeyId = (): string =>
78
78
  /** A random key of 32 bytes in base64. It needs real randomness, like `sealSecret`. */
79
79
  export const newKey = (): string => toBase64(crypto.getRandomValues(new Uint8Array(32)));
80
80
 
81
- /** The text of a new key ring with one random key. */
82
- export const newKeyRing = (): string => {
83
- const keyId = newKeyId();
84
- return JSON.stringify({ current: keyId, keys: { [keyId]: newKey() } });
85
- };
86
-
87
81
  const importKey = (ring: KeyRing, keyId: string) => {
88
82
  const bytes = ring.keys.get(keyId);
89
83
  if (bytes === undefined) throw new Error(`The key ring has no key "${keyId}".`);