@samebase/alchemy-convex 0.36.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.
- package/README.md +25 -19
- package/lib/IdentityHub-CvtrHlaK.js +324 -0
- package/lib/IdentityHub-CvtrHlaK.js.map +1 -0
- package/lib/IdentityHub.d.ts +122 -0
- package/lib/IdentityHub.d.ts.map +1 -0
- package/lib/IdentityHub.js +1 -0
- package/lib/Providers-Bq-4JsdP.d.ts +58 -0
- package/lib/Providers-Bq-4JsdP.d.ts.map +1 -0
- package/lib/{State-DVC61yrQ.js → State-CfIbfbVv.js} +20 -6
- package/lib/State-CfIbfbVv.js.map +1 -0
- package/lib/cli.js +3 -2
- package/lib/cli.js.map +1 -1
- package/lib/index.d.ts +2 -163
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -312
- package/lib/index.js.map +1 -1
- package/package.json +5 -1
- package/src/Deployment.ts +2 -1
- package/src/{SharedHubClient.ts → IdentityHub.ts} +60 -56
- package/src/Providers.ts +3 -3
- package/src/Push.ts +34 -7
- package/src/StackComment.ts +4 -1
- package/src/index.ts +0 -6
- package/lib/State-DVC61yrQ.js.map +0 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
//
|
|
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 `
|
|
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 `
|
|
105
|
+
* asks with the app's initial access token, which `IdentityHub.Client.read` gives from stage `prod`.
|
|
104
106
|
*/
|
|
105
|
-
export type
|
|
107
|
+
export type ClientProps =
|
|
106
108
|
| (CommonProps & {
|
|
107
109
|
readonly deploymentType: "production" | "preview";
|
|
108
110
|
readonly initialAccessToken?: never;
|
|
@@ -142,9 +144,9 @@ 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
|
-
* `
|
|
147
|
+
* `IdentityHub.Client.variables` gives the values that the app gets.
|
|
146
148
|
*/
|
|
147
|
-
export interface
|
|
149
|
+
export interface ClientAttributes extends Schema.Schema.Type<typeof Attributes> {}
|
|
148
150
|
|
|
149
151
|
/**
|
|
150
152
|
* The attributes of a saved row. A row that does not have this version's shape, or any other
|
|
@@ -153,13 +155,11 @@ export interface SharedHubClientAttributes extends Schema.Schema.Type<typeof Att
|
|
|
153
155
|
*/
|
|
154
156
|
const savedAttributes = (value: unknown, reason: string) =>
|
|
155
157
|
Schema.decodeUnknownEffect(Attributes)(value).pipe(
|
|
156
|
-
Effect.catchCause(() => Effect.die(new
|
|
158
|
+
Effect.catchCause(() => Effect.die(new IdentityHubClientFailed({ reason }))),
|
|
157
159
|
);
|
|
158
160
|
|
|
159
161
|
/** The attributes of no client. */
|
|
160
|
-
const offAttributes = (
|
|
161
|
-
deploymentType: SharedHubClientAttributes["deploymentType"],
|
|
162
|
-
): SharedHubClientAttributes => ({
|
|
162
|
+
const offAttributes = (deploymentType: ClientAttributes["deploymentType"]): ClientAttributes => ({
|
|
163
163
|
status: "off",
|
|
164
164
|
issuer: OFF_VALUES.issuer,
|
|
165
165
|
clientId: OFF_VALUES.clientId,
|
|
@@ -180,12 +180,12 @@ const sameSet = (a: readonly string[], b: readonly string[]) =>
|
|
|
180
180
|
a.length === b.length && a.every((name, index) => name === b[index]);
|
|
181
181
|
|
|
182
182
|
/** One request gave no usable answer. The reason holds no secret. */
|
|
183
|
-
class
|
|
184
|
-
"
|
|
183
|
+
class IdentityHubClientFailed extends Schema.TaggedError<IdentityHubClientFailed>()(
|
|
184
|
+
"IdentityHubClientFailed",
|
|
185
185
|
{ reason: Schema.String },
|
|
186
186
|
) {
|
|
187
187
|
override get message() {
|
|
188
|
-
return `
|
|
188
|
+
return `IdentityHub.Client: ${this.reason}.`;
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
|
|
@@ -290,14 +290,14 @@ const send = (who: string, url: string, token: string, init: { method: string; b
|
|
|
290
290
|
const body: unknown = await response.json().catch(() => undefined);
|
|
291
291
|
return { status: response.status, body };
|
|
292
292
|
},
|
|
293
|
-
catch: () => new
|
|
293
|
+
catch: () => new IdentityHubClientFailed({ reason: `${who} gave no answer` }),
|
|
294
294
|
});
|
|
295
295
|
|
|
296
296
|
const decode =
|
|
297
297
|
<S extends Schema.Codec<unknown, unknown>>(schema: S, who: string) =>
|
|
298
298
|
(value: unknown) =>
|
|
299
299
|
Schema.decodeUnknownEffect(schema)(value).pipe(
|
|
300
|
-
Effect.mapError(() => new
|
|
300
|
+
Effect.mapError(() => new IdentityHubClientFailed({ reason: `${who} gave a bad answer` })),
|
|
301
301
|
);
|
|
302
302
|
|
|
303
303
|
/**
|
|
@@ -313,7 +313,7 @@ const readOidcToken = (requestUrl: string, requestToken: string, audience: strin
|
|
|
313
313
|
{ method: "GET" },
|
|
314
314
|
);
|
|
315
315
|
if (status !== 200) {
|
|
316
|
-
return yield* new
|
|
316
|
+
return yield* new IdentityHubClientFailed({
|
|
317
317
|
reason: `GitHub gave no OIDC token (HTTP ${status})`,
|
|
318
318
|
});
|
|
319
319
|
}
|
|
@@ -321,11 +321,7 @@ const readOidcToken = (requestUrl: string, requestToken: string, audience: strin
|
|
|
321
321
|
});
|
|
322
322
|
|
|
323
323
|
/** `POST /hub-clients` with `bearer`: the GitHub OIDC token, or the app's initial access token. */
|
|
324
|
-
const requestNewClient = (
|
|
325
|
-
props: SharedHubClientProps,
|
|
326
|
-
connectors: readonly string[],
|
|
327
|
-
bearer: string,
|
|
328
|
-
) =>
|
|
324
|
+
const requestNewClient = (props: ClientProps, connectors: readonly string[], bearer: string) =>
|
|
329
325
|
Effect.gen(function* () {
|
|
330
326
|
const { hub } = props;
|
|
331
327
|
const { body, status } = yield* send("The identity hub", `${hub.issuer}/hub-clients`, bearer, {
|
|
@@ -342,7 +338,7 @@ const requestNewClient = (
|
|
|
342
338
|
status === 401 && props.deploymentType === "development"
|
|
343
339
|
? "the identity hub refused the initial access token"
|
|
344
340
|
: refusalOf(status, body);
|
|
345
|
-
return yield* new
|
|
341
|
+
return yield* new IdentityHubClientFailed({ reason: `${reason} (HTTP ${status})` });
|
|
346
342
|
}
|
|
347
343
|
const client = yield* decode(NewClient, "The identity hub")(body);
|
|
348
344
|
// The hub registers the address and the connectors that the request sent, under its own issuer
|
|
@@ -354,10 +350,10 @@ const requestNewClient = (
|
|
|
354
350
|
!sameSet(client.connectors, connectors) ||
|
|
355
351
|
client.terms !== hub.terms
|
|
356
352
|
) {
|
|
357
|
-
return yield* new
|
|
353
|
+
return yield* new IdentityHubClientFailed({ reason: "The identity hub gave a bad answer" });
|
|
358
354
|
}
|
|
359
355
|
yield* Effect.logInfo(
|
|
360
|
-
`
|
|
356
|
+
`IdentityHub.Client: ${props.app} on ${props.redirectUri} has a new client of the identity hub. Its use is under ${hub.terms}.`,
|
|
361
357
|
);
|
|
362
358
|
// Only a production registration gives the app's token (RFC 7591); any other answer's is dropped.
|
|
363
359
|
const production = props.deploymentType === "production";
|
|
@@ -377,13 +373,13 @@ const requestNewClient = (
|
|
|
377
373
|
});
|
|
378
374
|
|
|
379
375
|
/** A new client, or the off values. */
|
|
380
|
-
const newClient = (props:
|
|
381
|
-
const label = `
|
|
376
|
+
const newClient = (props: ClientProps, connectors: readonly string[]) => {
|
|
377
|
+
const label = `IdentityHub.Client: ${props.app} on ${props.redirectUri} deploys without the hub`;
|
|
382
378
|
const off = offAttributes(props.deploymentType);
|
|
383
|
-
const request = (bearer: Effect.Effect<string,
|
|
379
|
+
const request = (bearer: Effect.Effect<string, IdentityHubClientFailed>) =>
|
|
384
380
|
bearer.pipe(
|
|
385
381
|
Effect.flatMap((token) => requestNewClient(props, connectors, token)),
|
|
386
|
-
Effect.catchTag("
|
|
382
|
+
Effect.catchTag("IdentityHubClientFailed", (error) =>
|
|
387
383
|
Effect.logWarning(`${label}: ${error.reason}. The next deploy asks again.`).pipe(
|
|
388
384
|
Effect.as(off),
|
|
389
385
|
),
|
|
@@ -394,7 +390,7 @@ const newClient = (props: SharedHubClientProps, connectors: readonly string[]) =
|
|
|
394
390
|
const token = Redacted.value(props.initialAccessToken);
|
|
395
391
|
return token === ""
|
|
396
392
|
? Effect.logInfo(
|
|
397
|
-
"
|
|
393
|
+
"IdentityHub.Client: deploy to main once for hub sign-in in development.",
|
|
398
394
|
).pipe(Effect.as(off))
|
|
399
395
|
: request(Effect.succeed(token));
|
|
400
396
|
}
|
|
@@ -419,7 +415,7 @@ const newClient = (props: SharedHubClientProps, connectors: readonly string[]) =
|
|
|
419
415
|
* passes a run only when the hub confirms it in that run, so a suspension that an earlier run saw,
|
|
420
416
|
* and did not save because that run failed, cannot pass a run that the hub does not answer.
|
|
421
417
|
*/
|
|
422
|
-
const renew = (saved:
|
|
418
|
+
const renew = (saved: ClientAttributes, required: boolean) =>
|
|
423
419
|
Effect.gen(function* () {
|
|
424
420
|
const { status } = yield* send(
|
|
425
421
|
"The identity hub",
|
|
@@ -434,31 +430,38 @@ const renew = (saved: SharedHubClientAttributes, required: boolean) =>
|
|
|
434
430
|
return undefined;
|
|
435
431
|
case 403:
|
|
436
432
|
yield* Effect.logWarning(
|
|
437
|
-
`
|
|
433
|
+
`IdentityHub.Client: the hub suspended the client of ${saved.redirectUri}. It keeps its values, and nobody can sign in with it.`,
|
|
438
434
|
);
|
|
439
435
|
return { ...saved, status: "suspended" as const };
|
|
440
436
|
default:
|
|
441
|
-
return yield* new
|
|
437
|
+
return yield* new IdentityHubClientFailed({
|
|
442
438
|
reason: `The identity hub answered HTTP ${status}`,
|
|
443
439
|
});
|
|
444
440
|
}
|
|
445
441
|
}).pipe(
|
|
446
|
-
Effect.catchTag("
|
|
442
|
+
Effect.catchTag("IdentityHubClientFailed", (error) =>
|
|
447
443
|
required
|
|
448
444
|
? Effect.fail(
|
|
449
|
-
new
|
|
445
|
+
new IdentityHubClientFailed({
|
|
450
446
|
reason: `${saved.redirectUri} is required, and the hub did not confirm its client: ${error.reason}`,
|
|
451
447
|
}),
|
|
452
448
|
)
|
|
453
449
|
: Effect.logWarning(
|
|
454
|
-
`
|
|
450
|
+
`IdentityHub.Client: ${saved.redirectUri} keeps the saved client: ${error.reason}.`,
|
|
455
451
|
).pipe(Effect.as(saved)),
|
|
456
452
|
),
|
|
457
453
|
);
|
|
458
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
|
+
|
|
459
462
|
/** A saved row of this resource, whose `attr` `savedAttributes` reads. */
|
|
460
463
|
const SavedRow = Schema.Struct({
|
|
461
|
-
resourceType: Schema.
|
|
464
|
+
resourceType: Schema.Literals(["IdentityHub.Client", OLD_TYPE]),
|
|
462
465
|
attr: Schema.Unknown,
|
|
463
466
|
});
|
|
464
467
|
|
|
@@ -468,7 +471,7 @@ const SavedRow = Schema.Struct({
|
|
|
468
471
|
* `initialAccessToken` and the `repository` of the production client. Without that row, the off
|
|
469
472
|
* attributes, with `deploymentType: "production"`.
|
|
470
473
|
*
|
|
471
|
-
* `
|
|
474
|
+
* `IdentityHub.Client.ref` is not enough: Alchemy fails the plan with `InvalidReferenceError` when the
|
|
472
475
|
* row is missing, and a development stage before the first deploy to main has none. This read runs
|
|
473
476
|
* when the plan resolves it, with the State service of the running stack and its `get`, so it never
|
|
474
477
|
* creates or upgrades a store. The store revives each secret as `Redacted`, as it does for every
|
|
@@ -486,8 +489,8 @@ const read = (id: string, options: { readonly stage: string }) =>
|
|
|
486
489
|
const { attr } = yield* Schema.decodeUnknownEffect(SavedRow)(row).pipe(
|
|
487
490
|
Effect.catchCause(() =>
|
|
488
491
|
Effect.die(
|
|
489
|
-
new
|
|
490
|
-
reason: `the row ${id} of stage ${options.stage} is not
|
|
492
|
+
new IdentityHubClientFailed({
|
|
493
|
+
reason: `the row ${id} of stage ${options.stage} is not an IdentityHub.Client`,
|
|
491
494
|
}),
|
|
492
495
|
),
|
|
493
496
|
),
|
|
@@ -500,11 +503,12 @@ const read = (id: string, options: { readonly stage: string }) =>
|
|
|
500
503
|
);
|
|
501
504
|
|
|
502
505
|
/**
|
|
503
|
-
* The three values that the app's deployment gets, such as `
|
|
504
|
-
* `
|
|
505
|
-
* so that a suspended client gives guest sign-in and keeps
|
|
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.
|
|
506
510
|
*/
|
|
507
|
-
const variables = (client:
|
|
511
|
+
const variables = (client: Client) =>
|
|
508
512
|
Output.map(Output.of(client), (attributes) =>
|
|
509
513
|
attributes.status === "on"
|
|
510
514
|
? {
|
|
@@ -519,20 +523,20 @@ const variables = (client: SharedHubClient) =>
|
|
|
519
523
|
},
|
|
520
524
|
);
|
|
521
525
|
|
|
522
|
-
export type
|
|
523
|
-
"IdentityHub.
|
|
524
|
-
|
|
525
|
-
|
|
526
|
+
export type Client = Resource<
|
|
527
|
+
"IdentityHub.Client",
|
|
528
|
+
ClientProps,
|
|
529
|
+
ClientAttributes,
|
|
526
530
|
never,
|
|
527
531
|
Providers
|
|
528
532
|
>;
|
|
529
|
-
export const
|
|
533
|
+
export const Client = Resource<Client>("IdentityHub.Client", { aliases: [OLD_TYPE] })({
|
|
530
534
|
read,
|
|
531
535
|
variables,
|
|
532
536
|
});
|
|
533
537
|
|
|
534
|
-
export const
|
|
535
|
-
Provider.succeed(
|
|
538
|
+
export const ClientProvider = () =>
|
|
539
|
+
Provider.succeed(Client, {
|
|
536
540
|
// Always an update, so that each deploy reaches the hub. No attribute is stable, so a push
|
|
537
541
|
// reads the values that this run ended with. The same values cause no other push.
|
|
538
542
|
diff: ({ news }) =>
|
|
@@ -548,7 +552,7 @@ export const SharedHubClientProvider = () =>
|
|
|
548
552
|
news.connectors.length === 0 ||
|
|
549
553
|
!news.connectors.every((name) => CONNECTOR_NAME.test(name))
|
|
550
554
|
) {
|
|
551
|
-
return yield* new
|
|
555
|
+
return yield* new IdentityHubClientFailed({
|
|
552
556
|
reason: `${news.app} on ${news.redirectUri} needs connectors: one or more names of [a-z0-9-]{1,64}`,
|
|
553
557
|
});
|
|
554
558
|
}
|
|
@@ -569,7 +573,7 @@ export const SharedHubClientProvider = () =>
|
|
|
569
573
|
: undefined;
|
|
570
574
|
const client = renewed ?? (yield* newClient(news, connectors));
|
|
571
575
|
if (news.required === true && client.status !== "on") {
|
|
572
|
-
return yield* new
|
|
576
|
+
return yield* new IdentityHubClientFailed({
|
|
573
577
|
reason: `${news.app} on ${news.redirectUri} is required and has no working client (${client.status}). The warning above names the reason`,
|
|
574
578
|
});
|
|
575
579
|
}
|
|
@@ -590,14 +594,14 @@ export const SharedHubClientProvider = () =>
|
|
|
590
594
|
);
|
|
591
595
|
// 401: the client is gone already.
|
|
592
596
|
if (status !== 204 && status !== 401) {
|
|
593
|
-
return yield* new
|
|
597
|
+
return yield* new IdentityHubClientFailed({
|
|
594
598
|
reason: `The identity hub answered HTTP ${status}`,
|
|
595
599
|
});
|
|
596
600
|
}
|
|
597
601
|
}).pipe(
|
|
598
|
-
Effect.catchTag("
|
|
602
|
+
Effect.catchTag("IdentityHubClientFailed", (error) =>
|
|
599
603
|
Effect.logWarning(
|
|
600
|
-
`
|
|
604
|
+
`IdentityHub.Client: the client of ${output.redirectUri} stays on the hub until its removal date: ${error.reason}.`,
|
|
601
605
|
),
|
|
602
606
|
),
|
|
603
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,
|
|
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
|
-
|
|
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`.
|
|
515
|
-
*
|
|
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 &&
|
|
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
|
-
...
|
|
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
|
-
|
|
605
|
-
|
|
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. */
|
package/src/StackComment.ts
CHANGED
|
@@ -53,7 +53,9 @@ const Resource = Schema.Union([
|
|
|
53
53
|
}),
|
|
54
54
|
}),
|
|
55
55
|
Schema.Struct({
|
|
56
|
-
|
|
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,
|