@samebase/alchemy-convex 0.38.0 → 0.39.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/lib/{IdentityHub-XSCxmYoN.js → IdentityHub-BfZnP37H.js} +53 -27
- package/lib/IdentityHub-BfZnP37H.js.map +1 -0
- package/lib/IdentityHub.d.ts +27 -12
- package/lib/IdentityHub.d.ts.map +1 -1
- package/lib/IdentityHub.js +1 -1
- package/lib/{Providers-Bq-4JsdP.d.ts → Providers-zL1fUs0r.d.ts} +2 -2
- package/lib/{Providers-Bq-4JsdP.d.ts.map → Providers-zL1fUs0r.d.ts.map} +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/package.json +1 -1
- package/src/IdentityHub.ts +114 -48
- package/lib/IdentityHub-XSCxmYoN.js.map +0 -1
|
@@ -19,6 +19,17 @@ const OFF_VALUES = {
|
|
|
19
19
|
};
|
|
20
20
|
/** The name of a connector on the hub. */
|
|
21
21
|
const CONNECTOR_NAME = /^[a-z0-9-]{1,64}$/;
|
|
22
|
+
/** The return addresses of one client, as the hub caps them. */
|
|
23
|
+
const MAX_REDIRECT_URIS = 8;
|
|
24
|
+
/**
|
|
25
|
+
* The app's default name: the stack's path below `owner/repo`, or `app` for a stack named after
|
|
26
|
+
* the repository. Undefined for a stack whose name is not `owner/repo` or `owner/repo/<path>`.
|
|
27
|
+
*/
|
|
28
|
+
const defaultApp = (stackName) => {
|
|
29
|
+
const segments = stackName.split("/");
|
|
30
|
+
if (segments.length < 2 || segments.some((segment) => segment === "")) return;
|
|
31
|
+
return segments.slice(2).join("/") || "app";
|
|
32
|
+
};
|
|
22
33
|
const DeploymentType = Schema.Literals([
|
|
23
34
|
"production",
|
|
24
35
|
"preview",
|
|
@@ -40,8 +51,10 @@ const Attributes = Schema.Struct({
|
|
|
40
51
|
registrationAccessToken: Schema.Redacted(Schema.String),
|
|
41
52
|
registrationClientUri: Schema.String,
|
|
42
53
|
deploymentType: DeploymentType,
|
|
43
|
-
/** The
|
|
44
|
-
|
|
54
|
+
/** The app's name on the hub, as sent. Empty for the off values. */
|
|
55
|
+
app: Schema.String,
|
|
56
|
+
/** The return addresses the client serves, sorted, each once. Empty for the off values. */
|
|
57
|
+
redirectUris: Schema.Array(Schema.String),
|
|
45
58
|
/** The connectors the client is enrolled in, sorted, each once. Empty for the off values. */
|
|
46
59
|
connectors: Schema.Array(Schema.String),
|
|
47
60
|
/**
|
|
@@ -67,14 +80,17 @@ const offAttributes = (deploymentType) => ({
|
|
|
67
80
|
registrationAccessToken: Redacted.make(""),
|
|
68
81
|
registrationClientUri: "",
|
|
69
82
|
deploymentType,
|
|
70
|
-
|
|
83
|
+
app: "",
|
|
84
|
+
redirectUris: [],
|
|
71
85
|
connectors: [],
|
|
72
86
|
initialAccessToken: Redacted.make(""),
|
|
73
87
|
repository: ""
|
|
74
88
|
});
|
|
75
|
-
/** The set of `
|
|
76
|
-
const
|
|
89
|
+
/** The set of `values`: sorted, each once. */
|
|
90
|
+
const sortedSet = (values) => [...new Set(values)].sort();
|
|
77
91
|
const sameSet = (a, b) => a.length === b.length && a.every((name, index) => name === b[index]);
|
|
92
|
+
/** The app and its return addresses, as every log line names a client: no secret, no answer. */
|
|
93
|
+
const where = (client) => `${client.app} on ${client.redirectUris.join(", ")}`;
|
|
78
94
|
/** One request gave no usable answer. The reason holds no secret. */
|
|
79
95
|
var IdentityHubClientFailed = class extends Schema.TaggedError()("IdentityHubClientFailed", { reason: Schema.String }) {
|
|
80
96
|
get message() {
|
|
@@ -89,8 +105,8 @@ const NewClient = Schema.Struct({
|
|
|
89
105
|
client_secret: Schema.NonEmptyString,
|
|
90
106
|
registration_access_token: Schema.NonEmptyString,
|
|
91
107
|
registration_client_uri: Schema.NonEmptyString,
|
|
92
|
-
|
|
93
|
-
|
|
108
|
+
/** The sets the hub recorded, which must be the sets the request sent. */
|
|
109
|
+
redirect_uris: Schema.Array(Schema.String),
|
|
94
110
|
connectors: Schema.Array(Schema.String),
|
|
95
111
|
/** Only in the answer to a production registration with the GitHub token. */
|
|
96
112
|
initial_access_token: Schema.optionalKey(Schema.NonEmptyString),
|
|
@@ -98,7 +114,7 @@ const NewClient = Schema.Struct({
|
|
|
98
114
|
});
|
|
99
115
|
/** The other answers of `POST /hub-clients`, by status. */
|
|
100
116
|
const REFUSALS = {
|
|
101
|
-
400: "the identity hub refused the request:
|
|
117
|
+
400: "the identity hub refused the request: one to eight return addresses, each https on a DNS name, and the app name at most 64 characters",
|
|
102
118
|
401: "the identity hub refused the GitHub OIDC token",
|
|
103
119
|
403: "the identity hub does not allow this repository or return address",
|
|
104
120
|
404: "the identity hub has no /hub-clients",
|
|
@@ -180,21 +196,22 @@ const readOidcToken = (requestUrl, requestToken, audience) => Effect.gen(functio
|
|
|
180
196
|
return (yield* decode(OidcToken, "GitHub")(body)).value;
|
|
181
197
|
});
|
|
182
198
|
/** `POST /hub-clients` with `bearer`: the GitHub OIDC token, or the app's initial access token. */
|
|
183
|
-
const requestNewClient = (props,
|
|
199
|
+
const requestNewClient = (props, enrollment, bearer) => Effect.gen(function* () {
|
|
184
200
|
const { hub } = props;
|
|
201
|
+
const { app, connectors, redirectUris } = enrollment;
|
|
185
202
|
const { body, status } = yield* send("The identity hub", `${hub.issuer}/hub-clients`, bearer, {
|
|
186
203
|
method: "POST",
|
|
187
204
|
body: JSON.stringify({
|
|
188
|
-
app
|
|
189
|
-
|
|
205
|
+
app,
|
|
206
|
+
redirectUris,
|
|
190
207
|
softwareVersion: props.softwareVersion ?? "unknown",
|
|
191
208
|
connectors
|
|
192
209
|
})
|
|
193
210
|
});
|
|
194
211
|
if (status !== 201) return yield* new IdentityHubClientFailed({ reason: `${status === 401 && props.deploymentType === "development" ? "the identity hub refused the initial access token" : refusalOf(status, body)} (HTTP ${status})` });
|
|
195
212
|
const client = yield* decode(NewClient, "The identity hub")(body);
|
|
196
|
-
if (client.issuer !== hub.issuer || client.
|
|
197
|
-
yield* Effect.logInfo(`IdentityHub.Client: ${
|
|
213
|
+
if (client.issuer !== hub.issuer || !sameSet(sortedSet(client.redirect_uris), redirectUris) || !sameSet(client.connectors, connectors)) return yield* new IdentityHubClientFailed({ reason: "The identity hub gave a bad answer" });
|
|
214
|
+
yield* Effect.logInfo(`IdentityHub.Client: ${where(enrollment)} has a new client of the identity hub ${hub.issuer}.`);
|
|
198
215
|
const production = props.deploymentType === "production";
|
|
199
216
|
return {
|
|
200
217
|
status: "on",
|
|
@@ -204,17 +221,18 @@ const requestNewClient = (props, connectors, bearer) => Effect.gen(function* ()
|
|
|
204
221
|
registrationAccessToken: Redacted.make(client.registration_access_token),
|
|
205
222
|
registrationClientUri: client.registration_client_uri,
|
|
206
223
|
deploymentType: props.deploymentType,
|
|
207
|
-
|
|
224
|
+
app,
|
|
225
|
+
redirectUris,
|
|
208
226
|
connectors,
|
|
209
227
|
initialAccessToken: Redacted.make(production ? client.initial_access_token ?? "" : ""),
|
|
210
228
|
repository: production ? client.repository ?? "" : ""
|
|
211
229
|
};
|
|
212
230
|
});
|
|
213
231
|
/** A new client, or the off values. */
|
|
214
|
-
const newClient = (props,
|
|
215
|
-
const label = `IdentityHub.Client: ${
|
|
232
|
+
const newClient = (props, enrollment) => {
|
|
233
|
+
const label = `IdentityHub.Client: ${where(enrollment)} deploys without the hub`;
|
|
216
234
|
const off = offAttributes(props.deploymentType);
|
|
217
|
-
const request = (bearer) => bearer.pipe(Effect.flatMap((token) => requestNewClient(props,
|
|
235
|
+
const request = (bearer) => bearer.pipe(Effect.flatMap((token) => requestNewClient(props, enrollment, token)), Effect.catchTag("IdentityHubClientFailed", (error) => Effect.logWarning(`${label}: ${error.reason}. The next deploy asks again.`).pipe(Effect.as(off))));
|
|
218
236
|
if (props.deploymentType === "development") {
|
|
219
237
|
const token = Redacted.value(props.initialAccessToken);
|
|
220
238
|
return token === "" ? Effect.logInfo("IdentityHub.Client: deploy to main once for hub sign-in in development.").pipe(Effect.as(off)) : request(Effect.succeed(token));
|
|
@@ -239,14 +257,14 @@ const renew = (saved, required) => Effect.gen(function* () {
|
|
|
239
257
|
};
|
|
240
258
|
case 401: return;
|
|
241
259
|
case 403:
|
|
242
|
-
yield* Effect.logWarning(`IdentityHub.Client: the hub suspended the client of ${saved
|
|
260
|
+
yield* Effect.logWarning(`IdentityHub.Client: the hub suspended the client of ${where(saved)}. It keeps its values, and nobody can sign in with it.`);
|
|
243
261
|
return {
|
|
244
262
|
...saved,
|
|
245
263
|
status: "suspended"
|
|
246
264
|
};
|
|
247
265
|
default: return yield* new IdentityHubClientFailed({ reason: `The identity hub answered HTTP ${status}` });
|
|
248
266
|
}
|
|
249
|
-
}).pipe(Effect.catchTag("IdentityHubClientFailed", (error) => required ? Effect.fail(new IdentityHubClientFailed({ reason: `${saved
|
|
267
|
+
}).pipe(Effect.catchTag("IdentityHubClientFailed", (error) => required ? Effect.fail(new IdentityHubClientFailed({ reason: `${where(saved)} is required, and the hub did not confirm its client: ${error.reason}` })) : Effect.logWarning(`IdentityHub.Client: ${where(saved)} keeps the saved client: ${error.reason}.`).pipe(Effect.as(saved))));
|
|
250
268
|
/**
|
|
251
269
|
* The type of this resource before 0.37.0. Alchemy finds this provider for a row of that type, and
|
|
252
270
|
* the next write of the row gives it the new type, with the same client. Remove it, here and in
|
|
@@ -304,19 +322,27 @@ const ClientProvider = () => Provider.succeed(Client, {
|
|
|
304
322
|
diff: ({ news }) => Effect.succeed(isResolved(news) ? { action: "update" } : void 0),
|
|
305
323
|
read: ({ output }) => Effect.succeed(output),
|
|
306
324
|
reconcile: Effect.fn(function* ({ news, output }) {
|
|
307
|
-
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
const
|
|
311
|
-
|
|
325
|
+
const stack = yield* Stack;
|
|
326
|
+
const app = news.app ?? defaultApp(stack.name);
|
|
327
|
+
if (app === void 0) return yield* new IdentityHubClientFailed({ reason: `the stack ${stack.name} is not named owner/repo or owner/repo/<path>, so set app` });
|
|
328
|
+
const enrollment = {
|
|
329
|
+
app,
|
|
330
|
+
connectors: sortedSet(news.connectors),
|
|
331
|
+
redirectUris: sortedSet(news.redirectUris)
|
|
332
|
+
};
|
|
333
|
+
if (enrollment.connectors.length === 0 || !enrollment.connectors.every((name) => CONNECTOR_NAME.test(name))) return yield* new IdentityHubClientFailed({ reason: `${where(enrollment)} needs connectors: one or more names of [a-z0-9-]{1,64}` });
|
|
334
|
+
if (enrollment.redirectUris.length === 0 || enrollment.redirectUris.length > MAX_REDIRECT_URIS || !enrollment.redirectUris.every((uri) => URL.canParse(uri))) return yield* new IdentityHubClientFailed({ reason: `${app} needs redirectUris: one to ${MAX_REDIRECT_URIS} absolute URLs` });
|
|
335
|
+
const saved = output === void 0 || output.status === "off" ? void 0 : yield* savedAttributes(output, `the saved attributes of ${where(enrollment)} cannot be read by this version`);
|
|
336
|
+
const client = (saved?.issuer === news.hub.issuer && saved.app === app && sameSet(saved.redirectUris, enrollment.redirectUris) && saved.deploymentType === news.deploymentType && sameSet(saved.connectors, enrollment.connectors) ? yield* renew(saved, news.required === true) : void 0) ?? (yield* newClient(news, enrollment));
|
|
337
|
+
if (news.required === true && client.status !== "on") return yield* new IdentityHubClientFailed({ reason: `${where(enrollment)} is required and has no working client (${client.status}). The warning above names the reason` });
|
|
312
338
|
return client;
|
|
313
339
|
}),
|
|
314
340
|
delete: ({ output }) => output.deploymentType === "production" || output.status === "off" ? Effect.void : Effect.gen(function* () {
|
|
315
341
|
const { status } = yield* send("The identity hub", output.registrationClientUri, Redacted.value(output.registrationAccessToken), { method: "DELETE" });
|
|
316
342
|
if (status !== 204 && status !== 401) return yield* new IdentityHubClientFailed({ reason: `The identity hub answered HTTP ${status}` });
|
|
317
|
-
}).pipe(Effect.catchTag("IdentityHubClientFailed", (error) => Effect.logWarning(`IdentityHub.Client: the client of ${output
|
|
343
|
+
}).pipe(Effect.catchTag("IdentityHubClientFailed", (error) => Effect.logWarning(`IdentityHub.Client: the client of ${where(output)} stays on the hub until its removal date: ${error.reason}.`)))
|
|
318
344
|
});
|
|
319
345
|
//#endregion
|
|
320
|
-
export { ClientProvider as n, Client as t };
|
|
346
|
+
export { ClientProvider as n, defaultApp as r, Client as t };
|
|
321
347
|
|
|
322
|
-
//# sourceMappingURL=IdentityHub-
|
|
348
|
+
//# sourceMappingURL=IdentityHub-BfZnP37H.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IdentityHub-BfZnP37H.js","names":[],"sources":["../src/IdentityHub.ts"],"sourcesContent":["// IdentityHub.Client: one deployment of an app as a client of the identity hub that the stack\n// names, for an app that deploys in its own GitHub Actions run, on any host, and in development as a\n// stage of the same stack. Import it as\n// `import * as IdentityHub from \"@samebase/alchemy-convex/identity-hub\"`; `Convex.providers()`\n// registers its provider.\n//\n// A run in GitHub Actions asks the hub for a new client with a GitHub OIDC token, so the stack needs\n// no key and no Samebase account. The token names the repository. The hub reads\n// `/samebase-verification.json` at the origin of the return address, which must name the same\n// repository, and registers the client on that address. The answer holds the client's own\n// registration access token (RFC 7591), and each later deploy reads the client on the hub with that\n// token (RFC 7592). The hub keeps only hashes, so the state is the only record of the secret and the\n// token.\n//\n// The answer to a production registration also holds the app's initial access token (RFC 7591\n// section 1.2) and the repository id. The state of stage `prod` keeps them. A development checkout\n// runs the stack as a stage `dev-<name>`: it reads them with `IdentityHub.Client.read`, and a client\n// with `deploymentType: \"development\"` asks the hub with the token in place of the GitHub token\n// (RFC 133).\n//\n// A client is enrolled in the connectors it signs in through, such as `google` and `github`, at\n// registration (RFC 137), and holds the return addresses its requests may name, one per handler of\n// the app, such as the sign-in callback and the connections callback. The hub records both sets on\n// the client and never changes them: a stack with another set registers a new client.\n//\n// The app is the stack: its name on the hub defaults to the stack's path in the repository, as the\n// state store groups stacks (`owner/repo/<path>`), and `app` for a stack named after the repository.\n// `app` overrides it. The name groups the clients, their budgets, and the initial access token; it\n// plays no part in user ids, which the hub derives from the provider's own id.\n//\n// A push removes a variable that a deploy stops passing, so a failure here must not drop working\n// variables or stop the deploy. A renewal that fails keeps the saved values. Only a client that\n// cannot work asks for a new one: it is gone, or it has another app name, return address set, type,\n// or connector set. If that request fails, the run gives the off values, so the app has guest\n// sign-in and not a broken button. The off values are the `no-hub` variables of a checkout without\n// a hub: Convex needs the variables, and the app hides the button for this client ID.\n//\n// No text in this file quotes an answer or a fetch error, so no log line can hold a secret. The one\n// exception is the connector names of an `invalid_connectors` refusal, each checked against the\n// grammar of a connector name before it is printed.\nimport { Resource } from \"alchemy\";\nimport { isResolved } from \"alchemy/Diff\";\nimport * as Output from \"alchemy/Output\";\nimport * as Provider from \"alchemy/Provider\";\nimport { Stack } from \"alchemy/Stack\";\nimport { State } from \"alchemy/State\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Redacted from \"effect/Redacted\";\nimport * as Schema from \"effect/Schema\";\nimport type { Providers } from \"./Providers.ts\";\n\n/** A hung service must not hold a deploy: the time limit of one request. */\nconst REQUEST_TIMEOUT_MS = 30_000;\n\n/** The variables of a deployment without a hub client, as the starter writes them. */\nconst OFF_VALUES = { issuer: \"http://127.0.0.1:1\", clientId: \"no-hub\", clientSecret: \"no-hub\" };\n\n/** The name of a connector on the hub. */\nconst CONNECTOR_NAME = /^[a-z0-9-]{1,64}$/;\n\n/** The return addresses of one client, as the hub caps them. */\nconst MAX_REDIRECT_URIS = 8;\n\n/**\n * The app's default name: the stack's path below `owner/repo`, or `app` for a stack named after\n * the repository. Undefined for a stack whose name is not `owner/repo` or `owner/repo/<path>`.\n */\nexport const defaultApp = (stackName: string): string | undefined => {\n const segments = stackName.split(\"/\");\n if (segments.length < 2 || segments.some((segment) => segment === \"\")) {\n return undefined;\n }\n return segments.slice(2).join(\"/\") || \"app\";\n};\n\n/**\n * An identity hub of @samebase/identity-broker, such as Samebase's public hub:\n * `{ issuer: \"https://id.samebase.com\" }`.\n */\nexport interface Hub {\n /**\n * The hub's issuer, such as `https://auth.example.com`. The run asks at `<issuer>/hub-clients`,\n * with a GitHub token whose audience is the issuer, so no other hub can use that token.\n */\n readonly issuer: string;\n}\n\ninterface CommonProps {\n /**\n * The app's name in its repository. Default: the stack's path in the repository, `apps/samebase`\n * for the stack `samebase/samebase/apps/samebase`, and `app` for a stack named after the\n * repository. A changed name registers a new client under the new name.\n */\n readonly app?: string;\n /** The hub to register at. A changed hub registers a new client there; the old one stays. */\n readonly hub: Hub;\n /**\n * The connectors the client signs in through, by their names on the hub, such as\n * `[\"google\", \"github\"]`: at least one, each of `[a-z0-9-]{1,64}`. The hub refuses a name it does\n * not offer, or does not allow this repository, and the log then names the allowed ones. The set\n * is recorded on the client for good: a changed set registers a new client.\n */\n readonly connectors: readonly string[];\n /**\n * The return addresses of this deployment, one to eight, such as\n * `[`${site.siteUrl}/auth/hub/callback`]`: each an https URL whose origin serves\n * `/samebase-verification.json` with the numeric GitHub id of this repository,\n * `{ \"repository\": \"123\" }`. They can come from a resource that this run creates. A development\n * client can also have http on a loopback host, which needs no file. Every request of the client\n * names one of them. The set is recorded on the client for good: a changed set registers a new\n * client.\n */\n readonly redirectUris: string[];\n /** Recorded on the hub's client, such as the commit. The hub records \"unknown\" without it. */\n readonly softwareVersion?: string;\n /**\n * The run fails unless the hub confirms the client in this run: it fails when the hub refuses or\n * does not answer a registration or a renewal, and when it suspended the client. Without it, such\n * a run gives the off values or keeps the saved client, so the app deploys anyway. Set it where\n * sign-in is the product. A failed run saves nothing, so the next run asks the hub again.\n */\n readonly required?: boolean;\n}\n\n/**\n * A production or preview client asks with the GitHub OIDC token of the run. A development client\n * asks with the app's initial access token, which `IdentityHub.Client.read` gives from stage `prod`.\n */\nexport type ClientProps =\n | (CommonProps & {\n readonly deploymentType: \"production\" | \"preview\";\n readonly initialAccessToken?: never;\n })\n | (CommonProps & {\n readonly deploymentType: \"development\";\n /** Empty before the first production registration: the client gets the off values. */\n readonly initialAccessToken: Redacted.Redacted<string>;\n });\n\nconst DeploymentType = Schema.Literals([\"production\", \"preview\", \"development\"]);\n\nconst Attributes = Schema.Struct({\n /** `off`: no client, and the values below are the off values. */\n status: Schema.Literals([\"on\", \"off\", \"suspended\"]),\n /** The issuer of the hub, which the deployment names to sign in. */\n issuer: Schema.String,\n clientId: Schema.String,\n /** Returned only at registration. */\n clientSecret: Schema.Redacted(Schema.String),\n /** Returned only at registration. It reads and deletes this client on the hub, and nothing else. */\n registrationAccessToken: Schema.Redacted(Schema.String),\n registrationClientUri: Schema.String,\n deploymentType: DeploymentType,\n /** The app's name on the hub, as sent. Empty for the off values. */\n app: Schema.String,\n /** The return addresses the client serves, sorted, each once. Empty for the off values. */\n redirectUris: Schema.Array(Schema.String),\n /** The connectors the client is enrolled in, sorted, each once. Empty for the off values. */\n connectors: Schema.Array(Schema.String),\n /**\n * Returned only at a production registration (RFC 7591 section 1.2). It registers development\n * clients of this app. Empty for a preview, for a development client, and for the off values.\n */\n initialAccessToken: Schema.Redacted(Schema.String),\n /** The numeric GitHub id of the repository, with the initial access token. Empty without it. */\n repository: Schema.String,\n});\n\n/**\n * The attributes keep the real values of a suspended client, so that an unblock needs no new client.\n * `IdentityHub.Client.variables` gives the values that the app gets.\n */\nexport interface ClientAttributes extends Schema.Schema.Type<typeof Attributes> {}\n\n/**\n * The attributes of a saved row. A row that does not have this version's shape, or any other\n * failure of the decoder, stops the run with `reason`. The text of a schema issue can quote a value\n * of the row, so it is never kept.\n */\nconst savedAttributes = (value: unknown, reason: string) =>\n Schema.decodeUnknownEffect(Attributes)(value).pipe(\n Effect.catchCause(() => Effect.die(new IdentityHubClientFailed({ reason }))),\n );\n\n/** The attributes of no client. */\nconst offAttributes = (deploymentType: ClientAttributes[\"deploymentType\"]): ClientAttributes => ({\n status: \"off\",\n issuer: OFF_VALUES.issuer,\n clientId: OFF_VALUES.clientId,\n clientSecret: Redacted.make(OFF_VALUES.clientSecret),\n registrationAccessToken: Redacted.make(\"\"),\n registrationClientUri: \"\",\n deploymentType,\n app: \"\",\n redirectUris: [],\n connectors: [],\n initialAccessToken: Redacted.make(\"\"),\n repository: \"\",\n});\n\n/** The set of `values`: sorted, each once. */\nconst sortedSet = (values: readonly string[]) => [...new Set(values)].sort();\n\nconst sameSet = (a: readonly string[], b: readonly string[]) =>\n a.length === b.length && a.every((name, index) => name === b[index]);\n\n/** The app and its return addresses, as every log line names a client: no secret, no answer. */\nconst where = (client: { app: string; redirectUris: readonly string[] }) =>\n `${client.app} on ${client.redirectUris.join(\", \")}`;\n\n/** What one registration sends, resolved from the props: the app's name and both sets. */\ninterface Enrollment {\n readonly app: string;\n readonly connectors: readonly string[];\n readonly redirectUris: readonly string[];\n}\n\n/** One request gave no usable answer. The reason holds no secret. */\nclass IdentityHubClientFailed extends Schema.TaggedError<IdentityHubClientFailed>()(\n \"IdentityHubClientFailed\",\n { reason: Schema.String },\n) {\n override get message() {\n return `IdentityHub.Client: ${this.reason}.`;\n }\n}\n\nconst OidcToken = Schema.Struct({ value: Schema.NonEmptyString });\n\n/** The 201 answer of `POST /hub-clients`. */\nconst NewClient = Schema.Struct({\n issuer: Schema.NonEmptyString,\n client_id: Schema.NonEmptyString,\n client_secret: Schema.NonEmptyString,\n registration_access_token: Schema.NonEmptyString,\n registration_client_uri: Schema.NonEmptyString,\n /** The sets the hub recorded, which must be the sets the request sent. */\n redirect_uris: Schema.Array(Schema.String),\n connectors: Schema.Array(Schema.String),\n /** Only in the answer to a production registration with the GitHub token. */\n initial_access_token: Schema.optionalKey(Schema.NonEmptyString),\n repository: Schema.optionalKey(Schema.String.check(Schema.isPattern(/^\\d+$/))),\n});\n\n/** The other answers of `POST /hub-clients`, by status. */\nconst REFUSALS: Readonly<Record<number, string>> = {\n 400: \"the identity hub refused the request: one to eight return addresses, each https on a DNS name, and the app name at most 64 characters\",\n 401: \"the identity hub refused the GitHub OIDC token\",\n 403: \"the identity hub does not allow this repository or return address\",\n 404: \"the identity hub has no /hub-clients\",\n 429: \"the identity hub limits new clients\",\n 502: \"GitHub's keys are not available to the identity hub\",\n};\n\n/** The reasons of a 403 that a log line shows. Any other text of the answer is never logged. */\nconst NOT_ALLOWED = new Map([\n [\"paused\", \"this app is paused on the identity hub\"],\n [\"run_not_allowed\", \"the identity hub gives clients only to runs of main and of pull requests\"],\n [\"blocked\", \"Samebase blocked this repository or its owner\"],\n [\"suspended\", \"the identity hub suspended this repository\"],\n [\"too_many_apps\", \"the repository has as many apps on the identity hub as it may\"],\n [\"too_many_clients\", \"the app has as many clients on the identity hub as it may\"],\n [\"app_taken\", \"the app's name belongs to another app on the identity hub\"],\n [\"host_unreachable\", \"the identity hub could not reach the host of the return address\"],\n [\n \"verification_file_missing\",\n \"the host of the return address does not serve /samebase-verification.json\",\n ],\n [\"verification_file_invalid\", \"/samebase-verification.json on the host holds no repository id\"],\n [\"repository_mismatch\", \"/samebase-verification.json on the host names another repository\"],\n [\"app_mismatch\", \"the initial access token belongs to another app on the identity hub\"],\n]);\n\n/** The windows of a 429, by the name that the answer gives. */\nconst RATE_LIMITED = new Map([\n [\"repository\", \"the identity hub gives one repository at most 30 new clients an hour\"],\n [\"owner\", \"the identity hub gives one owner at most 100 new clients an hour\"],\n [\"new_owners\", \"the identity hub takes at most 50 new owners an hour\"],\n]);\n\nconst Refusal = Schema.Struct({ reason: Schema.String });\nconst RateLimited = Schema.Struct({ window: Schema.String });\n/** A 400 for a connector the hub does not offer or allow, with the names it allows. */\nconst InvalidConnectors = Schema.Struct({\n error: Schema.Literal(\"invalid_connectors\"),\n allowed: Schema.Array(Schema.String),\n});\n\n/**\n * The text of a refusal: a known reason of a 403 or window of a 429, the allowed connectors of an\n * `invalid_connectors` 400 (only names of the connector grammar, so no other text of the answer is\n * printed), else the text of its status.\n */\nconst refusalOf = (status: number, body: unknown): string => {\n const decoded = <S extends Schema.Codec<unknown, unknown>>(schema: S) =>\n Option.getOrUndefined(Schema.decodeUnknownOption(schema)(body));\n const ofStatus = () => REFUSALS[status] ?? \"the identity hub refused the request\";\n switch (status) {\n case 400: {\n const allowed = decoded(InvalidConnectors)?.allowed.filter((name) =>\n CONNECTOR_NAME.test(name),\n );\n return allowed === undefined\n ? ofStatus()\n : `the identity hub does not offer or allow one of the connectors; it allows ${allowed.length === 0 ? \"none for this app\" : allowed.join(\", \")}`;\n }\n case 403:\n return NOT_ALLOWED.get(decoded(Refusal)?.reason ?? \"\") ?? ofStatus();\n case 429:\n return RATE_LIMITED.get(decoded(RateLimited)?.window ?? \"\") ?? ofStatus();\n default:\n return ofStatus();\n }\n};\n\nconst send = (who: string, url: string, token: string, init: { method: string; body?: string }) =>\n Effect.tryPromise({\n try: async () => {\n const response = await fetch(url, {\n ...init,\n headers: { Authorization: `Bearer ${token}`, \"Content-Type\": \"application/json\" },\n signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),\n });\n const body: unknown = await response.json().catch(() => undefined);\n return { status: response.status, body };\n },\n catch: () => new IdentityHubClientFailed({ reason: `${who} gave no answer` }),\n });\n\nconst decode =\n <S extends Schema.Codec<unknown, unknown>>(schema: S, who: string) =>\n (value: unknown) =>\n Schema.decodeUnknownEffect(schema)(value).pipe(\n Effect.mapError(() => new IdentityHubClientFailed({ reason: `${who} gave a bad answer` })),\n );\n\n/**\n * The OIDC token of this run for `audience`, read right before the call, because it lives for\n * minutes only.\n */\nconst readOidcToken = (requestUrl: string, requestToken: string, audience: string) =>\n Effect.gen(function* () {\n const { body, status } = yield* send(\n \"GitHub\",\n `${requestUrl}&audience=${encodeURIComponent(audience)}`,\n requestToken,\n { method: \"GET\" },\n );\n if (status !== 200) {\n return yield* new IdentityHubClientFailed({\n reason: `GitHub gave no OIDC token (HTTP ${status})`,\n });\n }\n return (yield* decode(OidcToken, \"GitHub\")(body)).value;\n });\n\n/** `POST /hub-clients` with `bearer`: the GitHub OIDC token, or the app's initial access token. */\nconst requestNewClient = (props: ClientProps, enrollment: Enrollment, bearer: string) =>\n Effect.gen(function* () {\n const { hub } = props;\n const { app, connectors, redirectUris } = enrollment;\n const { body, status } = yield* send(\"The identity hub\", `${hub.issuer}/hub-clients`, bearer, {\n method: \"POST\",\n body: JSON.stringify({\n app,\n redirectUris,\n softwareVersion: props.softwareVersion ?? \"unknown\",\n connectors,\n }),\n });\n if (status !== 201) {\n const reason =\n status === 401 && props.deploymentType === \"development\"\n ? \"the identity hub refused the initial access token\"\n : refusalOf(status, body);\n return yield* new IdentityHubClientFailed({ reason: `${reason} (HTTP ${status})` });\n }\n const client = yield* decode(NewClient, \"The identity hub\")(body);\n // The hub registers the addresses and the connectors that the request sent, under its own\n // issuer. The log and the state hold the stack's values, so no value that the answer chose is\n // printed or kept.\n if (\n client.issuer !== hub.issuer ||\n !sameSet(sortedSet(client.redirect_uris), redirectUris) ||\n !sameSet(client.connectors, connectors)\n ) {\n return yield* new IdentityHubClientFailed({ reason: \"The identity hub gave a bad answer\" });\n }\n yield* Effect.logInfo(\n `IdentityHub.Client: ${where(enrollment)} has a new client of the identity hub ${hub.issuer}.`,\n );\n // Only a production registration gives the app's token (RFC 7591); any other answer's is dropped.\n const production = props.deploymentType === \"production\";\n return {\n status: \"on\" as const,\n issuer: hub.issuer,\n clientId: client.client_id,\n clientSecret: Redacted.make(client.client_secret),\n registrationAccessToken: Redacted.make(client.registration_access_token),\n registrationClientUri: client.registration_client_uri,\n deploymentType: props.deploymentType,\n app,\n redirectUris,\n connectors,\n initialAccessToken: Redacted.make(production ? (client.initial_access_token ?? \"\") : \"\"),\n repository: production ? (client.repository ?? \"\") : \"\",\n };\n });\n\n/** A new client, or the off values. */\nconst newClient = (props: ClientProps, enrollment: Enrollment) => {\n const label = `IdentityHub.Client: ${where(enrollment)} deploys without the hub`;\n const off = offAttributes(props.deploymentType);\n const request = (bearer: Effect.Effect<string, IdentityHubClientFailed>) =>\n bearer.pipe(\n Effect.flatMap((token) => requestNewClient(props, enrollment, token)),\n Effect.catchTag(\"IdentityHubClientFailed\", (error) =>\n Effect.logWarning(`${label}: ${error.reason}. The next deploy asks again.`).pipe(\n Effect.as(off),\n ),\n ),\n );\n\n if (props.deploymentType === \"development\") {\n const token = Redacted.value(props.initialAccessToken);\n return token === \"\"\n ? Effect.logInfo(\n \"IdentityHub.Client: deploy to main once for hub sign-in in development.\",\n ).pipe(Effect.as(off))\n : request(Effect.succeed(token));\n }\n\n const requestUrl = process.env[\"ACTIONS_ID_TOKEN_REQUEST_URL\"];\n const requestToken = process.env[\"ACTIONS_ID_TOKEN_REQUEST_TOKEN\"];\n // A development machine, or another CI. In a workflow, `id-token: write` gives both, so a\n // workflow without them is a mistake to show, not a normal run.\n if (!requestUrl || !requestToken) {\n return (\n process.env[\"GITHUB_ACTIONS\"] === \"true\"\n ? Effect.logWarning(`${label}: this workflow needs the permission id-token: write.`)\n : Effect.logInfo(`${label}: this run has no GitHub OIDC token.`)\n ).pipe(Effect.as(off));\n }\n return request(readOidcToken(requestUrl, requestToken, props.hub.issuer));\n};\n\n/**\n * The client after a read on the hub, or undefined when the hub says that the client is gone. A\n * read with no usable answer keeps the saved client, except for a required one: a required client\n * passes a run only when the hub confirms it in that run, so a suspension that an earlier run saw,\n * and did not save because that run failed, cannot pass a run that the hub does not answer.\n */\nconst renew = (saved: ClientAttributes, required: boolean) =>\n Effect.gen(function* () {\n const { status } = yield* send(\n \"The identity hub\",\n saved.registrationClientUri,\n Redacted.value(saved.registrationAccessToken),\n { method: \"GET\" },\n );\n switch (status) {\n case 200:\n return { ...saved, status: \"on\" as const };\n case 401:\n return undefined;\n case 403:\n yield* Effect.logWarning(\n `IdentityHub.Client: the hub suspended the client of ${where(saved)}. It keeps its values, and nobody can sign in with it.`,\n );\n return { ...saved, status: \"suspended\" as const };\n default:\n return yield* new IdentityHubClientFailed({\n reason: `The identity hub answered HTTP ${status}`,\n });\n }\n }).pipe(\n Effect.catchTag(\"IdentityHubClientFailed\", (error) =>\n required\n ? Effect.fail(\n new IdentityHubClientFailed({\n reason: `${where(saved)} is required, and the hub did not confirm its client: ${error.reason}`,\n }),\n )\n : Effect.logWarning(\n `IdentityHub.Client: ${where(saved)} keeps the saved client: ${error.reason}.`,\n ).pipe(Effect.as(saved)),\n ),\n );\n\n/**\n * The type of this resource before 0.37.0. Alchemy finds this provider for a row of that type, and\n * the next write of the row gives it the new type, with the same client. Remove it, here and in\n * `SavedRow`, once no saved row has the old type.\n */\nconst OLD_TYPE = \"IdentityHub.SharedClient\";\n\n/** A saved row of this resource, whose `attr` `savedAttributes` reads. */\nconst SavedRow = Schema.Struct({\n resourceType: Schema.Literals([\"IdentityHub.Client\", OLD_TYPE]),\n attr: Schema.Unknown,\n});\n\n/**\n * The attributes of the client `id` in another stage of this stack, such as\n * `read(\"HubClient\", { stage: \"prod\" })` in a development stage, as Outputs: the\n * `initialAccessToken` and the `repository` of the production client. Without that row, the off\n * attributes, with `deploymentType: \"production\"`.\n *\n * `IdentityHub.Client.ref` is not enough: Alchemy fails the plan with `InvalidReferenceError` when the\n * row is missing, and a development stage before the first deploy to main has none. This read runs\n * when the plan resolves it, with the State service of the running stack and its `get`, so it never\n * creates or upgrades a store. The store revives each secret as `Redacted`, as it does for every\n * read.\n */\nconst read = (id: string, options: { readonly stage: string }) =>\n Output.fromEffect(\n Effect.gen(function* () {\n const stack = yield* Stack;\n const state = yield* yield* State;\n const row = yield* state\n .get({ stack: stack.name, stage: options.stage, fqn: id })\n .pipe(Effect.orDie);\n if (row === undefined) return offAttributes(\"production\");\n const { attr } = yield* Schema.decodeUnknownEffect(SavedRow)(row).pipe(\n Effect.catchCause(() =>\n Effect.die(\n new IdentityHubClientFailed({\n reason: `the row ${id} of stage ${options.stage} is not an IdentityHub.Client`,\n }),\n ),\n ),\n );\n return yield* savedAttributes(\n attr,\n `the row ${id} of stage ${options.stage} holds attributes that this version cannot read`,\n );\n }),\n );\n\n/**\n * The three values that the app's deployment gets, such as `IDENTITY_HUB_ISSUER`,\n * `IDENTITY_HUB_CLIENT_ID`, and `IDENTITY_HUB_CLIENT_SECRET`, as Outputs: the client's values when\n * `status` is `on`, else the off values, so that a suspended client gives guest sign-in and keeps\n * its values in state.\n */\nconst variables = (client: Client) =>\n Output.map(Output.of(client), (attributes) =>\n attributes.status === \"on\"\n ? {\n issuer: attributes.issuer,\n clientId: attributes.clientId,\n clientSecret: attributes.clientSecret,\n }\n : {\n issuer: OFF_VALUES.issuer,\n clientId: OFF_VALUES.clientId,\n clientSecret: Redacted.make(OFF_VALUES.clientSecret),\n },\n );\n\nexport type Client = Resource<\n \"IdentityHub.Client\",\n ClientProps,\n ClientAttributes,\n never,\n Providers\n>;\nexport const Client = Resource<Client>(\"IdentityHub.Client\", { aliases: [OLD_TYPE] })({\n read,\n variables,\n});\n\nexport const ClientProvider = () =>\n Provider.succeed(Client, {\n // Always an update, so that each deploy reaches the hub. No attribute is stable, so a push\n // reads the values that this run ended with. The same values cause no other push.\n diff: ({ news }) =>\n Effect.succeed(isResolved(news) ? ({ action: \"update\" } as const) : undefined),\n\n read: ({ output }) => Effect.succeed(output),\n\n // Only a client of the same hub (its issuer), app name, return address set, type, and\n // connector set is renewed. A saved row without this version's shape stops the run with a\n // fixed message.\n reconcile: Effect.fn(function* ({ news, output }) {\n // A bad prop is a mistake of the stack, not of the hub: the run fails, with no request.\n const stack = yield* Stack;\n const app = news.app ?? defaultApp(stack.name);\n if (app === undefined) {\n return yield* new IdentityHubClientFailed({\n reason: `the stack ${stack.name} is not named owner/repo or owner/repo/<path>, so set app`,\n });\n }\n const enrollment: Enrollment = {\n app,\n connectors: sortedSet(news.connectors),\n redirectUris: sortedSet(news.redirectUris),\n };\n if (\n enrollment.connectors.length === 0 ||\n !enrollment.connectors.every((name) => CONNECTOR_NAME.test(name))\n ) {\n return yield* new IdentityHubClientFailed({\n reason: `${where(enrollment)} needs connectors: one or more names of [a-z0-9-]{1,64}`,\n });\n }\n if (\n enrollment.redirectUris.length === 0 ||\n enrollment.redirectUris.length > MAX_REDIRECT_URIS ||\n !enrollment.redirectUris.every((uri) => URL.canParse(uri))\n ) {\n return yield* new IdentityHubClientFailed({\n reason: `${app} needs redirectUris: one to ${MAX_REDIRECT_URIS} absolute URLs`,\n });\n }\n const saved =\n output === undefined || output.status === \"off\"\n ? undefined\n : yield* savedAttributes(\n output,\n `the saved attributes of ${where(enrollment)} cannot be read by this version`,\n );\n const renewed =\n saved?.issuer === news.hub.issuer &&\n saved.app === app &&\n sameSet(saved.redirectUris, enrollment.redirectUris) &&\n saved.deploymentType === news.deploymentType &&\n sameSet(saved.connectors, enrollment.connectors)\n ? yield* renew(saved, news.required === true)\n : undefined;\n const client = renewed ?? (yield* newClient(news, enrollment));\n if (news.required === true && client.status !== \"on\") {\n return yield* new IdentityHubClientFailed({\n reason: `${where(enrollment)} is required and has no working client (${client.status}). The warning above names the reason`,\n });\n }\n return client;\n }),\n\n // A failed delete does not stop a destroy: the removal date of a preview or development client\n // cleans it up. A destroy can leave a production deployment running, so its client stays.\n delete: ({ output }) =>\n output.deploymentType === \"production\" || output.status === \"off\"\n ? Effect.void\n : Effect.gen(function* () {\n const { status } = yield* send(\n \"The identity hub\",\n output.registrationClientUri,\n Redacted.value(output.registrationAccessToken),\n { method: \"DELETE\" },\n );\n // 401: the client is gone already.\n if (status !== 204 && status !== 401) {\n return yield* new IdentityHubClientFailed({\n reason: `The identity hub answered HTTP ${status}`,\n });\n }\n }).pipe(\n Effect.catchTag(\"IdentityHubClientFailed\", (error) =>\n Effect.logWarning(\n `IdentityHub.Client: the client of ${where(output)} stays on the hub until its removal date: ${error.reason}.`,\n ),\n ),\n ),\n });\n"],"mappings":";;;;;;;;;;;;AAqDA,MAAM,qBAAqB;;AAG3B,MAAM,aAAa;CAAE,QAAQ;CAAsB,UAAU;CAAU,cAAc;AAAS;;AAG9F,MAAM,iBAAiB;;AAGvB,MAAM,oBAAoB;;;;;AAM1B,MAAa,cAAc,cAA0C;CACnE,MAAM,WAAW,UAAU,MAAM,GAAG;CACpC,IAAI,SAAS,SAAS,KAAK,SAAS,MAAM,YAAY,YAAY,EAAE,GAClE;CAEF,OAAO,SAAS,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,KAAK;AACxC;AAkEA,MAAM,iBAAiB,OAAO,SAAS;CAAC;CAAc;CA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I,wBAAwB,EACxC,QAAQ,GAAG,IAAI,8BAA8B,kBAAkB,gBACjE,CAAC;EAEH,MAAM,QACJ,WAAW,KAAA,KAAa,OAAO,WAAW,QACtC,KAAA,IACA,OAAO,gBACL,QACA,2BAA2B,MAAM,UAAU,EAAE,gCAC/C;EASN,MAAM,UAPJ,OAAO,WAAW,KAAK,IAAI,UAC3B,MAAM,QAAQ,OACd,QAAQ,MAAM,cAAc,WAAW,YAAY,KACnD,MAAM,mBAAmB,KAAK,kBAC9B,QAAQ,MAAM,YAAY,WAAW,UAAU,IAC3C,OAAO,MAAM,OAAO,KAAK,aAAa,IAAI,IAC1C,KAAA,OACqB,OAAO,UAAU,MAAM,UAAU;EAC5D,IAAI,KAAK,aAAa,QAAQ,OAAO,WAAW,MAC9C,OAAO,OAAO,IAAI,wBAAwB,EACxC,QAAQ,GAAG,MAAM,UAAU,EAAE,0CAA0C,OAAO,OAAO,uCACvF,CAAC;EAEH,OAAO;CACT,CAAC;CAID,SAAS,EAAE,aACT,OAAO,mBAAmB,gBAAgB,OAAO,WAAW,QACxD,OAAO,OACP,OAAO,IAAI,aAAa;EACtB,MAAM,EAAE,WAAW,OAAO,KACxB,oBACA,OAAO,uBACP,SAAS,MAAM,OAAO,uBAAuB,GAC7C,EAAE,QAAQ,SAAS,CACrB;EAEA,IAAI,WAAW,OAAO,WAAW,KAC/B,OAAO,OAAO,IAAI,wBAAwB,EACxC,QAAQ,kCAAkC,SAC5C,CAAC;CAEL,CAAC,CAAC,CAAC,KACD,OAAO,SAAS,4BAA4B,UAC1C,OAAO,WACL,qCAAqC,MAAM,MAAM,EAAE,4CAA4C,MAAM,OAAO,EAC9G,CACF,CACF;AACR,CAAC"}
|
package/lib/IdentityHub.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Providers } from "./Providers-
|
|
1
|
+
import { t as Providers } from "./Providers-zL1fUs0r.js";
|
|
2
2
|
import { Stack } from "alchemy/Stack";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
4
|
import * as Redacted from "effect/Redacted";
|
|
@@ -7,6 +7,11 @@ import * as Provider from "alchemy/Provider";
|
|
|
7
7
|
import * as Output from "alchemy/Output";
|
|
8
8
|
import { State } from "alchemy/State";
|
|
9
9
|
//#region src/IdentityHub.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* The app's default name: the stack's path below `owner/repo`, or `app` for a stack named after
|
|
12
|
+
* the repository. Undefined for a stack whose name is not `owner/repo` or `owner/repo/<path>`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const defaultApp: (stackName: string) => string | undefined;
|
|
10
15
|
/**
|
|
11
16
|
* An identity hub of @samebase/identity-broker, such as Samebase's public hub:
|
|
12
17
|
* `{ issuer: "https://id.samebase.com" }`.
|
|
@@ -19,8 +24,12 @@ export interface Hub {
|
|
|
19
24
|
readonly issuer: string;
|
|
20
25
|
}
|
|
21
26
|
interface CommonProps {
|
|
22
|
-
/**
|
|
23
|
-
|
|
27
|
+
/**
|
|
28
|
+
* The app's name in its repository. Default: the stack's path in the repository, `apps/samebase`
|
|
29
|
+
* for the stack `samebase/samebase/apps/samebase`, and `app` for a stack named after the
|
|
30
|
+
* repository. A changed name registers a new client under the new name.
|
|
31
|
+
*/
|
|
32
|
+
readonly app?: string;
|
|
24
33
|
/** The hub to register at. A changed hub registers a new client there; the old one stays. */
|
|
25
34
|
readonly hub: Hub;
|
|
26
35
|
/**
|
|
@@ -31,12 +40,15 @@ interface CommonProps {
|
|
|
31
40
|
*/
|
|
32
41
|
readonly connectors: readonly string[];
|
|
33
42
|
/**
|
|
34
|
-
* The return
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
43
|
+
* The return addresses of this deployment, one to eight, such as
|
|
44
|
+
* `[`${site.siteUrl}/auth/hub/callback`]`: each an https URL whose origin serves
|
|
45
|
+
* `/samebase-verification.json` with the numeric GitHub id of this repository,
|
|
46
|
+
* `{ "repository": "123" }`. They can come from a resource that this run creates. A development
|
|
47
|
+
* client can also have http on a loopback host, which needs no file. Every request of the client
|
|
48
|
+
* names one of them. The set is recorded on the client for good: a changed set registers a new
|
|
49
|
+
* client.
|
|
38
50
|
*/
|
|
39
|
-
readonly
|
|
51
|
+
readonly redirectUris: string[];
|
|
40
52
|
/** Recorded on the hub's client, such as the commit. The hub records "unknown" without it. */
|
|
41
53
|
readonly softwareVersion?: string;
|
|
42
54
|
/**
|
|
@@ -71,8 +83,10 @@ declare const Attributes: Schema.Struct<{
|
|
|
71
83
|
readonly registrationAccessToken: Schema.Redacted<Schema.String>;
|
|
72
84
|
readonly registrationClientUri: Schema.String;
|
|
73
85
|
readonly deploymentType: Schema.Literals<readonly ["production", "preview", "development"]>;
|
|
74
|
-
/** The
|
|
75
|
-
readonly
|
|
86
|
+
/** The app's name on the hub, as sent. Empty for the off values. */
|
|
87
|
+
readonly app: Schema.String;
|
|
88
|
+
/** The return addresses the client serves, sorted, each once. Empty for the off values. */
|
|
89
|
+
readonly redirectUris: Schema.$Array<Schema.String>;
|
|
76
90
|
/** The connectors the client is enrolled in, sorted, each once. Empty for the off values. */
|
|
77
91
|
readonly connectors: Schema.$Array<Schema.String>;
|
|
78
92
|
/**
|
|
@@ -100,7 +114,8 @@ export declare const Client: import("alchemy").ResourceClassWithMethods<Client,
|
|
|
100
114
|
readonly registrationAccessToken: Redacted.Redacted<string>;
|
|
101
115
|
readonly registrationClientUri: string;
|
|
102
116
|
readonly deploymentType: "production" | "preview" | "development";
|
|
103
|
-
readonly
|
|
117
|
+
readonly app: string;
|
|
118
|
+
readonly redirectUris: readonly string[];
|
|
104
119
|
readonly connectors: readonly string[];
|
|
105
120
|
readonly initialAccessToken: Redacted.Redacted<string>;
|
|
106
121
|
readonly repository: string;
|
|
@@ -111,7 +126,7 @@ export declare const Client: import("alchemy").ResourceClassWithMethods<Client,
|
|
|
111
126
|
clientSecret: Redacted.Redacted<string>;
|
|
112
127
|
}, never>;
|
|
113
128
|
}>;
|
|
114
|
-
export declare const ClientProvider: () => import("effect/Layer").Layer<Provider.Provider<Client>, never,
|
|
129
|
+
export declare const ClientProvider: () => import("effect/Layer").Layer<Provider.Provider<Client>, never, Stack>;
|
|
115
130
|
//#endregion
|
|
116
131
|
export {};
|
|
117
132
|
//# sourceMappingURL=IdentityHub.d.ts.map
|
package/lib/IdentityHub.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IdentityHub.d.ts","names":[],"sources":["../src/IdentityHub.ts"],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"IdentityHub.d.ts","names":[],"sources":["../src/IdentityHub.ts"],"mappings":";;;;;;;;;;;;;qBAoEa,aAAc;;;;;iBAYV;;;;;WAKN;;UAGD;;;;;;WAMC;;WAEA,KAAK;;;;;;;WAOL;;;;;;;;;;WAUA;;WAEA;;;;;;;WAOA;;;;;;YAOC,eACP;WACU;WACA;MAEV;WACU;;WAEA,oBAAoB,SAAS;;cAKtC,YAAU,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+BC,yBAAyB,OAAO,OAAO,YAAY;YAoYxD,SAAS,+BAEnB,aACA,yBAEA;qBAEW,0BAAM,yBAAA;WArDD,OAAA,YAAM;aAAsB;QAAe,OAAA;;;;;;;;;;;;;;WA+BlC,YAAA,QAAA,WAAM,OAAA;;;;;;qBA2BpB,6CAAc,MAAA,SAAA,SAAA,gBAAA"}
|
package/lib/IdentityHub.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as Client, n as ClientProvider } from "./IdentityHub-
|
|
1
|
+
export { t as Client, n as ClientProvider, r as defaultApp } from "./IdentityHub-BfZnP37H.js";
|
|
@@ -52,7 +52,7 @@ declare class Providers extends Providers_base {}
|
|
|
52
52
|
* default lookup (`CONVEX_ACCESS_TOKEN`, then the Convex CLI login, and
|
|
53
53
|
* `CONVEX_DEPLOY_KEY`).
|
|
54
54
|
*/
|
|
55
|
-
declare const providers: (credentials?: Layer.Layer<Credentials>) => Layer.Layer<Providers, never, import("effect/process/ChildProcessSpawner").ChildProcessSpawner | import("effect/FileSystem").FileSystem | import("effect/Path").Path>;
|
|
55
|
+
declare const providers: (credentials?: Layer.Layer<Credentials>) => Layer.Layer<Providers, never, import("alchemy").Stack | import("effect/process/ChildProcessSpawner").ChildProcessSpawner | import("effect/FileSystem").FileSystem | import("effect/Path").Path>;
|
|
56
56
|
//#endregion
|
|
57
57
|
export { CredentialsError as a, fromValues as c, Credentials as i, providers as n, DEPLOY_KEY_ENV as o, ACCESS_TOKEN_ENV as r, fromConfig as s, Providers as t };
|
|
58
|
-
//# sourceMappingURL=Providers-
|
|
58
|
+
//# sourceMappingURL=Providers-zL1fUs0r.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Providers-
|
|
1
|
+
{"version":3,"file":"Providers-zL1fUs0r.d.ts","names":[],"sources":["../src/Credentials.ts","../src/Providers.ts"],"mappings":";;;;;;;UA6BiB;;WAEN,aAAa,SAAS;;WAEtB;;UAGM;;WAEN,aAAa,OAAO,OAAO;;WAE3B,gBAAgB,OAAO;;WAEvB,WAAW,OAAO,OAAO,SAAS;;;cAGhC,oBAAoB;;cAKpB;;cAGA;;;;cAOA,yBAAyB;;;;;;;;;cAiCzB,kBAAiB,MAAM,MAAM;;cA0B7B,aAAc;WAChB,cAAc,SAAS;WACvB,YAAY,SAAS;MAC5B,MAAM,MAAM;;;;cC/GH,kBAAkB;;;;;;cAOlB,YAAa,cAAa,MAAM,MAAM,iBAA2B,MAAA,MAAA,oCAAA,qDAAA,kDAAA,mCAAA"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as CredentialsError, c as fromValues, i as Credentials, n as providers, o as DEPLOY_KEY_ENV, r as ACCESS_TOKEN_ENV, s as fromConfig, t as Providers } from "./Providers-
|
|
1
|
+
import { a as CredentialsError, c as fromValues, i as Credentials, n as providers, o as DEPLOY_KEY_ENV, r as ACCESS_TOKEN_ENV, s as fromConfig, t as Providers } from "./Providers-zL1fUs0r.js";
|
|
2
2
|
import { Stack } from "alchemy/Stack";
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
4
|
import * as Schema from "effect/Schema";
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { A as ManagementApi, C as ConvexCliNotFound, D as parseDeployOutput, E as VariablesOwnedBySomeoneElse, F as CredentialsError, I as DEPLOY_KEY_ENV, L as fromConfig, M as readLocalDeployment, N as ACCESS_TOKEN_ENV, O as push, P as Credentials, R as fromValues, S as ConvexAppNotFound, T as PushTargetMismatch, _ as DeploymentIdentityChange, a as runRecord, b as ProductionDeploymentNotFound, c as CreatedProjectNotFound, d as ProjectNotFound, f as ProjectProvider, g as Deployment, h as AmbiguousDeployment, i as RunRecordError, j as ManagementApiLive, k as ConvexApiError, l as Project, m as AbsoluteRootDir, n as state, o as withRunRecord, p as ProjectTeamChange, r as RUN_RECORD_KEY, s as AmbiguousProject, t as STORE_PROJECT_NAME, u as ProjectDeploymentChange, v as DeploymentProvider, w as EnvironmentNeedsDeployKey, x as CodePushFailed, y as DeploymentResource } from "./State-CfIbfbVv.js";
|
|
2
|
-
import { n as ClientProvider, t as Client } from "./IdentityHub-
|
|
2
|
+
import { n as ClientProvider, t as Client } from "./IdentityHub-BfZnP37H.js";
|
|
3
3
|
import { toPath } from "alchemy/FQN";
|
|
4
4
|
import { Stack } from "alchemy/Stack";
|
|
5
5
|
import * as Effect from "effect/Effect";
|
package/package.json
CHANGED
package/src/IdentityHub.ts
CHANGED
|
@@ -19,15 +19,21 @@
|
|
|
19
19
|
// (RFC 133).
|
|
20
20
|
//
|
|
21
21
|
// A client is enrolled in the connectors it signs in through, such as `google` and `github`, at
|
|
22
|
-
// registration (RFC 137)
|
|
23
|
-
//
|
|
22
|
+
// registration (RFC 137), and holds the return addresses its requests may name, one per handler of
|
|
23
|
+
// the app, such as the sign-in callback and the connections callback. The hub records both sets on
|
|
24
|
+
// the client and never changes them: a stack with another set registers a new client.
|
|
25
|
+
//
|
|
26
|
+
// The app is the stack: its name on the hub defaults to the stack's path in the repository, as the
|
|
27
|
+
// state store groups stacks (`owner/repo/<path>`), and `app` for a stack named after the repository.
|
|
28
|
+
// `app` overrides it. The name groups the clients, their budgets, and the initial access token; it
|
|
29
|
+
// plays no part in user ids, which the hub derives from the provider's own id.
|
|
24
30
|
//
|
|
25
31
|
// A push removes a variable that a deploy stops passing, so a failure here must not drop working
|
|
26
32
|
// variables or stop the deploy. A renewal that fails keeps the saved values. Only a client that
|
|
27
|
-
// cannot work asks for a new one: it is gone, or it has another return address, type,
|
|
28
|
-
// set. If that request fails, the run gives the off values, so the app has guest
|
|
29
|
-
// broken button. The off values are the `no-hub` variables of a checkout without
|
|
30
|
-
// needs the variables, and the app hides the button for this client ID.
|
|
33
|
+
// cannot work asks for a new one: it is gone, or it has another app name, return address set, type,
|
|
34
|
+
// or connector set. If that request fails, the run gives the off values, so the app has guest
|
|
35
|
+
// sign-in and not a broken button. The off values are the `no-hub` variables of a checkout without
|
|
36
|
+
// a hub: Convex needs the variables, and the app hides the button for this client ID.
|
|
31
37
|
//
|
|
32
38
|
// No text in this file quotes an answer or a fetch error, so no log line can hold a secret. The one
|
|
33
39
|
// exception is the connector names of an `invalid_connectors` refusal, each checked against the
|
|
@@ -53,6 +59,21 @@ const OFF_VALUES = { issuer: "http://127.0.0.1:1", clientId: "no-hub", clientSec
|
|
|
53
59
|
/** The name of a connector on the hub. */
|
|
54
60
|
const CONNECTOR_NAME = /^[a-z0-9-]{1,64}$/;
|
|
55
61
|
|
|
62
|
+
/** The return addresses of one client, as the hub caps them. */
|
|
63
|
+
const MAX_REDIRECT_URIS = 8;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The app's default name: the stack's path below `owner/repo`, or `app` for a stack named after
|
|
67
|
+
* the repository. Undefined for a stack whose name is not `owner/repo` or `owner/repo/<path>`.
|
|
68
|
+
*/
|
|
69
|
+
export const defaultApp = (stackName: string): string | undefined => {
|
|
70
|
+
const segments = stackName.split("/");
|
|
71
|
+
if (segments.length < 2 || segments.some((segment) => segment === "")) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
return segments.slice(2).join("/") || "app";
|
|
75
|
+
};
|
|
76
|
+
|
|
56
77
|
/**
|
|
57
78
|
* An identity hub of @samebase/identity-broker, such as Samebase's public hub:
|
|
58
79
|
* `{ issuer: "https://id.samebase.com" }`.
|
|
@@ -66,8 +87,12 @@ export interface Hub {
|
|
|
66
87
|
}
|
|
67
88
|
|
|
68
89
|
interface CommonProps {
|
|
69
|
-
/**
|
|
70
|
-
|
|
90
|
+
/**
|
|
91
|
+
* The app's name in its repository. Default: the stack's path in the repository, `apps/samebase`
|
|
92
|
+
* for the stack `samebase/samebase/apps/samebase`, and `app` for a stack named after the
|
|
93
|
+
* repository. A changed name registers a new client under the new name.
|
|
94
|
+
*/
|
|
95
|
+
readonly app?: string;
|
|
71
96
|
/** The hub to register at. A changed hub registers a new client there; the old one stays. */
|
|
72
97
|
readonly hub: Hub;
|
|
73
98
|
/**
|
|
@@ -78,12 +103,15 @@ interface CommonProps {
|
|
|
78
103
|
*/
|
|
79
104
|
readonly connectors: readonly string[];
|
|
80
105
|
/**
|
|
81
|
-
* The return
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
106
|
+
* The return addresses of this deployment, one to eight, such as
|
|
107
|
+
* `[`${site.siteUrl}/auth/hub/callback`]`: each an https URL whose origin serves
|
|
108
|
+
* `/samebase-verification.json` with the numeric GitHub id of this repository,
|
|
109
|
+
* `{ "repository": "123" }`. They can come from a resource that this run creates. A development
|
|
110
|
+
* client can also have http on a loopback host, which needs no file. Every request of the client
|
|
111
|
+
* names one of them. The set is recorded on the client for good: a changed set registers a new
|
|
112
|
+
* client.
|
|
85
113
|
*/
|
|
86
|
-
readonly
|
|
114
|
+
readonly redirectUris: string[];
|
|
87
115
|
/** Recorded on the hub's client, such as the commit. The hub records "unknown" without it. */
|
|
88
116
|
readonly softwareVersion?: string;
|
|
89
117
|
/**
|
|
@@ -124,8 +152,10 @@ const Attributes = Schema.Struct({
|
|
|
124
152
|
registrationAccessToken: Schema.Redacted(Schema.String),
|
|
125
153
|
registrationClientUri: Schema.String,
|
|
126
154
|
deploymentType: DeploymentType,
|
|
127
|
-
/** The
|
|
128
|
-
|
|
155
|
+
/** The app's name on the hub, as sent. Empty for the off values. */
|
|
156
|
+
app: Schema.String,
|
|
157
|
+
/** The return addresses the client serves, sorted, each once. Empty for the off values. */
|
|
158
|
+
redirectUris: Schema.Array(Schema.String),
|
|
129
159
|
/** The connectors the client is enrolled in, sorted, each once. Empty for the off values. */
|
|
130
160
|
connectors: Schema.Array(Schema.String),
|
|
131
161
|
/**
|
|
@@ -162,18 +192,30 @@ const offAttributes = (deploymentType: ClientAttributes["deploymentType"]): Clie
|
|
|
162
192
|
registrationAccessToken: Redacted.make(""),
|
|
163
193
|
registrationClientUri: "",
|
|
164
194
|
deploymentType,
|
|
165
|
-
|
|
195
|
+
app: "",
|
|
196
|
+
redirectUris: [],
|
|
166
197
|
connectors: [],
|
|
167
198
|
initialAccessToken: Redacted.make(""),
|
|
168
199
|
repository: "",
|
|
169
200
|
});
|
|
170
201
|
|
|
171
|
-
/** The set of `
|
|
172
|
-
const
|
|
202
|
+
/** The set of `values`: sorted, each once. */
|
|
203
|
+
const sortedSet = (values: readonly string[]) => [...new Set(values)].sort();
|
|
173
204
|
|
|
174
205
|
const sameSet = (a: readonly string[], b: readonly string[]) =>
|
|
175
206
|
a.length === b.length && a.every((name, index) => name === b[index]);
|
|
176
207
|
|
|
208
|
+
/** The app and its return addresses, as every log line names a client: no secret, no answer. */
|
|
209
|
+
const where = (client: { app: string; redirectUris: readonly string[] }) =>
|
|
210
|
+
`${client.app} on ${client.redirectUris.join(", ")}`;
|
|
211
|
+
|
|
212
|
+
/** What one registration sends, resolved from the props: the app's name and both sets. */
|
|
213
|
+
interface Enrollment {
|
|
214
|
+
readonly app: string;
|
|
215
|
+
readonly connectors: readonly string[];
|
|
216
|
+
readonly redirectUris: readonly string[];
|
|
217
|
+
}
|
|
218
|
+
|
|
177
219
|
/** One request gave no usable answer. The reason holds no secret. */
|
|
178
220
|
class IdentityHubClientFailed extends Schema.TaggedError<IdentityHubClientFailed>()(
|
|
179
221
|
"IdentityHubClientFailed",
|
|
@@ -193,8 +235,8 @@ const NewClient = Schema.Struct({
|
|
|
193
235
|
client_secret: Schema.NonEmptyString,
|
|
194
236
|
registration_access_token: Schema.NonEmptyString,
|
|
195
237
|
registration_client_uri: Schema.NonEmptyString,
|
|
196
|
-
|
|
197
|
-
|
|
238
|
+
/** The sets the hub recorded, which must be the sets the request sent. */
|
|
239
|
+
redirect_uris: Schema.Array(Schema.String),
|
|
198
240
|
connectors: Schema.Array(Schema.String),
|
|
199
241
|
/** Only in the answer to a production registration with the GitHub token. */
|
|
200
242
|
initial_access_token: Schema.optionalKey(Schema.NonEmptyString),
|
|
@@ -203,7 +245,7 @@ const NewClient = Schema.Struct({
|
|
|
203
245
|
|
|
204
246
|
/** The other answers of `POST /hub-clients`, by status. */
|
|
205
247
|
const REFUSALS: Readonly<Record<number, string>> = {
|
|
206
|
-
400: "the identity hub refused the request:
|
|
248
|
+
400: "the identity hub refused the request: one to eight return addresses, each https on a DNS name, and the app name at most 64 characters",
|
|
207
249
|
401: "the identity hub refused the GitHub OIDC token",
|
|
208
250
|
403: "the identity hub does not allow this repository or return address",
|
|
209
251
|
404: "the identity hub has no /hub-clients",
|
|
@@ -314,14 +356,15 @@ const readOidcToken = (requestUrl: string, requestToken: string, audience: strin
|
|
|
314
356
|
});
|
|
315
357
|
|
|
316
358
|
/** `POST /hub-clients` with `bearer`: the GitHub OIDC token, or the app's initial access token. */
|
|
317
|
-
const requestNewClient = (props: ClientProps,
|
|
359
|
+
const requestNewClient = (props: ClientProps, enrollment: Enrollment, bearer: string) =>
|
|
318
360
|
Effect.gen(function* () {
|
|
319
361
|
const { hub } = props;
|
|
362
|
+
const { app, connectors, redirectUris } = enrollment;
|
|
320
363
|
const { body, status } = yield* send("The identity hub", `${hub.issuer}/hub-clients`, bearer, {
|
|
321
364
|
method: "POST",
|
|
322
365
|
body: JSON.stringify({
|
|
323
|
-
app
|
|
324
|
-
|
|
366
|
+
app,
|
|
367
|
+
redirectUris,
|
|
325
368
|
softwareVersion: props.softwareVersion ?? "unknown",
|
|
326
369
|
connectors,
|
|
327
370
|
}),
|
|
@@ -334,18 +377,18 @@ const requestNewClient = (props: ClientProps, connectors: readonly string[], bea
|
|
|
334
377
|
return yield* new IdentityHubClientFailed({ reason: `${reason} (HTTP ${status})` });
|
|
335
378
|
}
|
|
336
379
|
const client = yield* decode(NewClient, "The identity hub")(body);
|
|
337
|
-
// The hub registers the
|
|
338
|
-
// The log and the state hold the stack's values, so no value that the answer chose is
|
|
339
|
-
// or kept.
|
|
380
|
+
// The hub registers the addresses and the connectors that the request sent, under its own
|
|
381
|
+
// issuer. The log and the state hold the stack's values, so no value that the answer chose is
|
|
382
|
+
// printed or kept.
|
|
340
383
|
if (
|
|
341
384
|
client.issuer !== hub.issuer ||
|
|
342
|
-
client.
|
|
385
|
+
!sameSet(sortedSet(client.redirect_uris), redirectUris) ||
|
|
343
386
|
!sameSet(client.connectors, connectors)
|
|
344
387
|
) {
|
|
345
388
|
return yield* new IdentityHubClientFailed({ reason: "The identity hub gave a bad answer" });
|
|
346
389
|
}
|
|
347
390
|
yield* Effect.logInfo(
|
|
348
|
-
`IdentityHub.Client: ${
|
|
391
|
+
`IdentityHub.Client: ${where(enrollment)} has a new client of the identity hub ${hub.issuer}.`,
|
|
349
392
|
);
|
|
350
393
|
// Only a production registration gives the app's token (RFC 7591); any other answer's is dropped.
|
|
351
394
|
const production = props.deploymentType === "production";
|
|
@@ -357,7 +400,8 @@ const requestNewClient = (props: ClientProps, connectors: readonly string[], bea
|
|
|
357
400
|
registrationAccessToken: Redacted.make(client.registration_access_token),
|
|
358
401
|
registrationClientUri: client.registration_client_uri,
|
|
359
402
|
deploymentType: props.deploymentType,
|
|
360
|
-
|
|
403
|
+
app,
|
|
404
|
+
redirectUris,
|
|
361
405
|
connectors,
|
|
362
406
|
initialAccessToken: Redacted.make(production ? (client.initial_access_token ?? "") : ""),
|
|
363
407
|
repository: production ? (client.repository ?? "") : "",
|
|
@@ -365,12 +409,12 @@ const requestNewClient = (props: ClientProps, connectors: readonly string[], bea
|
|
|
365
409
|
});
|
|
366
410
|
|
|
367
411
|
/** A new client, or the off values. */
|
|
368
|
-
const newClient = (props: ClientProps,
|
|
369
|
-
const label = `IdentityHub.Client: ${
|
|
412
|
+
const newClient = (props: ClientProps, enrollment: Enrollment) => {
|
|
413
|
+
const label = `IdentityHub.Client: ${where(enrollment)} deploys without the hub`;
|
|
370
414
|
const off = offAttributes(props.deploymentType);
|
|
371
415
|
const request = (bearer: Effect.Effect<string, IdentityHubClientFailed>) =>
|
|
372
416
|
bearer.pipe(
|
|
373
|
-
Effect.flatMap((token) => requestNewClient(props,
|
|
417
|
+
Effect.flatMap((token) => requestNewClient(props, enrollment, token)),
|
|
374
418
|
Effect.catchTag("IdentityHubClientFailed", (error) =>
|
|
375
419
|
Effect.logWarning(`${label}: ${error.reason}. The next deploy asks again.`).pipe(
|
|
376
420
|
Effect.as(off),
|
|
@@ -422,7 +466,7 @@ const renew = (saved: ClientAttributes, required: boolean) =>
|
|
|
422
466
|
return undefined;
|
|
423
467
|
case 403:
|
|
424
468
|
yield* Effect.logWarning(
|
|
425
|
-
`IdentityHub.Client: the hub suspended the client of ${saved
|
|
469
|
+
`IdentityHub.Client: the hub suspended the client of ${where(saved)}. It keeps its values, and nobody can sign in with it.`,
|
|
426
470
|
);
|
|
427
471
|
return { ...saved, status: "suspended" as const };
|
|
428
472
|
default:
|
|
@@ -435,11 +479,11 @@ const renew = (saved: ClientAttributes, required: boolean) =>
|
|
|
435
479
|
required
|
|
436
480
|
? Effect.fail(
|
|
437
481
|
new IdentityHubClientFailed({
|
|
438
|
-
reason: `${saved
|
|
482
|
+
reason: `${where(saved)} is required, and the hub did not confirm its client: ${error.reason}`,
|
|
439
483
|
}),
|
|
440
484
|
)
|
|
441
485
|
: Effect.logWarning(
|
|
442
|
-
`IdentityHub.Client: ${saved
|
|
486
|
+
`IdentityHub.Client: ${where(saved)} keeps the saved client: ${error.reason}.`,
|
|
443
487
|
).pipe(Effect.as(saved)),
|
|
444
488
|
),
|
|
445
489
|
);
|
|
@@ -536,37 +580,59 @@ export const ClientProvider = () =>
|
|
|
536
580
|
|
|
537
581
|
read: ({ output }) => Effect.succeed(output),
|
|
538
582
|
|
|
539
|
-
// Only a client of the same hub (its issuer), return address, type, and
|
|
540
|
-
// renewed. A saved row without this version's shape stops the run with a
|
|
583
|
+
// Only a client of the same hub (its issuer), app name, return address set, type, and
|
|
584
|
+
// connector set is renewed. A saved row without this version's shape stops the run with a
|
|
585
|
+
// fixed message.
|
|
541
586
|
reconcile: Effect.fn(function* ({ news, output }) {
|
|
542
587
|
// A bad prop is a mistake of the stack, not of the hub: the run fails, with no request.
|
|
588
|
+
const stack = yield* Stack;
|
|
589
|
+
const app = news.app ?? defaultApp(stack.name);
|
|
590
|
+
if (app === undefined) {
|
|
591
|
+
return yield* new IdentityHubClientFailed({
|
|
592
|
+
reason: `the stack ${stack.name} is not named owner/repo or owner/repo/<path>, so set app`,
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
const enrollment: Enrollment = {
|
|
596
|
+
app,
|
|
597
|
+
connectors: sortedSet(news.connectors),
|
|
598
|
+
redirectUris: sortedSet(news.redirectUris),
|
|
599
|
+
};
|
|
600
|
+
if (
|
|
601
|
+
enrollment.connectors.length === 0 ||
|
|
602
|
+
!enrollment.connectors.every((name) => CONNECTOR_NAME.test(name))
|
|
603
|
+
) {
|
|
604
|
+
return yield* new IdentityHubClientFailed({
|
|
605
|
+
reason: `${where(enrollment)} needs connectors: one or more names of [a-z0-9-]{1,64}`,
|
|
606
|
+
});
|
|
607
|
+
}
|
|
543
608
|
if (
|
|
544
|
-
|
|
545
|
-
|
|
609
|
+
enrollment.redirectUris.length === 0 ||
|
|
610
|
+
enrollment.redirectUris.length > MAX_REDIRECT_URIS ||
|
|
611
|
+
!enrollment.redirectUris.every((uri) => URL.canParse(uri))
|
|
546
612
|
) {
|
|
547
613
|
return yield* new IdentityHubClientFailed({
|
|
548
|
-
reason: `${
|
|
614
|
+
reason: `${app} needs redirectUris: one to ${MAX_REDIRECT_URIS} absolute URLs`,
|
|
549
615
|
});
|
|
550
616
|
}
|
|
551
|
-
const connectors = connectorSet(news.connectors);
|
|
552
617
|
const saved =
|
|
553
618
|
output === undefined || output.status === "off"
|
|
554
619
|
? undefined
|
|
555
620
|
: yield* savedAttributes(
|
|
556
621
|
output,
|
|
557
|
-
`the saved attributes of ${
|
|
622
|
+
`the saved attributes of ${where(enrollment)} cannot be read by this version`,
|
|
558
623
|
);
|
|
559
624
|
const renewed =
|
|
560
625
|
saved?.issuer === news.hub.issuer &&
|
|
561
|
-
saved.
|
|
626
|
+
saved.app === app &&
|
|
627
|
+
sameSet(saved.redirectUris, enrollment.redirectUris) &&
|
|
562
628
|
saved.deploymentType === news.deploymentType &&
|
|
563
|
-
sameSet(saved.connectors, connectors)
|
|
629
|
+
sameSet(saved.connectors, enrollment.connectors)
|
|
564
630
|
? yield* renew(saved, news.required === true)
|
|
565
631
|
: undefined;
|
|
566
|
-
const client = renewed ?? (yield* newClient(news,
|
|
632
|
+
const client = renewed ?? (yield* newClient(news, enrollment));
|
|
567
633
|
if (news.required === true && client.status !== "on") {
|
|
568
634
|
return yield* new IdentityHubClientFailed({
|
|
569
|
-
reason: `${
|
|
635
|
+
reason: `${where(enrollment)} is required and has no working client (${client.status}). The warning above names the reason`,
|
|
570
636
|
});
|
|
571
637
|
}
|
|
572
638
|
return client;
|
|
@@ -593,7 +659,7 @@ export const ClientProvider = () =>
|
|
|
593
659
|
}).pipe(
|
|
594
660
|
Effect.catchTag("IdentityHubClientFailed", (error) =>
|
|
595
661
|
Effect.logWarning(
|
|
596
|
-
`IdentityHub.Client: the client of ${output
|
|
662
|
+
`IdentityHub.Client: the client of ${where(output)} stays on the hub until its removal date: ${error.reason}.`,
|
|
597
663
|
),
|
|
598
664
|
),
|
|
599
665
|
),
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IdentityHub-XSCxmYoN.js","names":[],"sources":["../src/IdentityHub.ts"],"sourcesContent":["// IdentityHub.Client: one deployment of an app as a client of the identity hub that the stack\n// names, for an app that deploys in its own GitHub Actions run, on any host, and in development as a\n// stage of the same stack. Import it as\n// `import * as IdentityHub from \"@samebase/alchemy-convex/identity-hub\"`; `Convex.providers()`\n// registers its provider.\n//\n// A run in GitHub Actions asks the hub for a new client with a GitHub OIDC token, so the stack needs\n// no key and no Samebase account. The token names the repository. The hub reads\n// `/samebase-verification.json` at the origin of the return address, which must name the same\n// repository, and registers the client on that address. The answer holds the client's own\n// registration access token (RFC 7591), and each later deploy reads the client on the hub with that\n// token (RFC 7592). The hub keeps only hashes, so the state is the only record of the secret and the\n// token.\n//\n// The answer to a production registration also holds the app's initial access token (RFC 7591\n// section 1.2) and the repository id. The state of stage `prod` keeps them. A development checkout\n// runs the stack as a stage `dev-<name>`: it reads them with `IdentityHub.Client.read`, and a client\n// with `deploymentType: \"development\"` asks the hub with the token in place of the GitHub token\n// (RFC 133).\n//\n// A client is enrolled in the connectors it signs in through, such as `google` and `github`, at\n// registration (RFC 137). The hub records the set on the client and never changes it: a stack with\n// another set registers a new client.\n//\n// A push removes a variable that a deploy stops passing, so a failure here must not drop working\n// variables or stop the deploy. A renewal that fails keeps the saved values. Only a client that\n// cannot work asks for a new one: it is gone, or it has another return address, type, or connector\n// set. If that request fails, the run gives the off values, so the app has guest sign-in and not a\n// broken button. The off values are the `no-hub` variables of a checkout without a hub: Convex\n// needs the variables, and the app hides the button for this client ID.\n//\n// No text in this file quotes an answer or a fetch error, so no log line can hold a secret. The one\n// exception is the connector names of an `invalid_connectors` refusal, each checked against the\n// grammar of a connector name before it is printed.\nimport { Resource } from \"alchemy\";\nimport { isResolved } from \"alchemy/Diff\";\nimport * as Output from \"alchemy/Output\";\nimport * as Provider from \"alchemy/Provider\";\nimport { Stack } from \"alchemy/Stack\";\nimport { State } from \"alchemy/State\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Redacted from \"effect/Redacted\";\nimport * as Schema from \"effect/Schema\";\nimport type { Providers } from \"./Providers.ts\";\n\n/** A hung service must not hold a deploy: the time limit of one request. */\nconst REQUEST_TIMEOUT_MS = 30_000;\n\n/** The variables of a deployment without a hub client, as the starter writes them. */\nconst OFF_VALUES = { issuer: \"http://127.0.0.1:1\", clientId: \"no-hub\", clientSecret: \"no-hub\" };\n\n/** The name of a connector on the hub. */\nconst CONNECTOR_NAME = /^[a-z0-9-]{1,64}$/;\n\n/**\n * An identity hub of @samebase/identity-broker, such as Samebase's public hub:\n * `{ issuer: \"https://id.samebase.com\" }`.\n */\nexport interface Hub {\n /**\n * The hub's issuer, such as `https://auth.example.com`. The run asks at `<issuer>/hub-clients`,\n * with a GitHub token whose audience is the issuer, so no other hub can use that token.\n */\n readonly issuer: string;\n}\n\ninterface CommonProps {\n /** The stable name of the app, set once in the stack. */\n readonly app: string;\n /** The hub to register at. A changed hub registers a new client there; the old one stays. */\n readonly hub: Hub;\n /**\n * The connectors the client signs in through, by their names on the hub, such as\n * `[\"google\", \"github\"]`: at least one, each of `[a-z0-9-]{1,64}`. The hub refuses a name it does\n * not offer, or does not allow this repository, and the log then names the allowed ones. The set\n * is recorded on the client for good: a changed set registers a new client.\n */\n readonly connectors: readonly string[];\n /**\n * The return address of the hub's sign-ins, such as `${site.siteUrl}/auth/hub/callback`: an https\n * URL whose origin serves `/samebase-verification.json` with the numeric GitHub id of this\n * repository, `{ \"repository\": \"123\" }`. It can come from a resource that this run creates. A\n * development client can also have http on a loopback host, which needs no file.\n */\n readonly redirectUri: string;\n /** Recorded on the hub's client, such as the commit. The hub records \"unknown\" without it. */\n readonly softwareVersion?: string;\n /**\n * The run fails unless the hub confirms the client in this run: it fails when the hub refuses or\n * does not answer a registration or a renewal, and when it suspended the client. Without it, such\n * a run gives the off values or keeps the saved client, so the app deploys anyway. Set it where\n * sign-in is the product. A failed run saves nothing, so the next run asks the hub again.\n */\n readonly required?: boolean;\n}\n\n/**\n * A production or preview client asks with the GitHub OIDC token of the run. A development client\n * asks with the app's initial access token, which `IdentityHub.Client.read` gives from stage `prod`.\n */\nexport type ClientProps =\n | (CommonProps & {\n readonly deploymentType: \"production\" | \"preview\";\n readonly initialAccessToken?: never;\n })\n | (CommonProps & {\n readonly deploymentType: \"development\";\n /** Empty before the first production registration: the client gets the off values. */\n readonly initialAccessToken: Redacted.Redacted<string>;\n });\n\nconst DeploymentType = Schema.Literals([\"production\", \"preview\", \"development\"]);\n\nconst Attributes = Schema.Struct({\n /** `off`: no client, and the values below are the off values. */\n status: Schema.Literals([\"on\", \"off\", \"suspended\"]),\n /** The issuer of the hub, which the deployment names to sign in. */\n issuer: Schema.String,\n clientId: Schema.String,\n /** Returned only at registration. */\n clientSecret: Schema.Redacted(Schema.String),\n /** Returned only at registration. It reads and deletes this client on the hub, and nothing else. */\n registrationAccessToken: Schema.Redacted(Schema.String),\n registrationClientUri: Schema.String,\n deploymentType: DeploymentType,\n /** The return address that the client serves. Empty for the off values. */\n redirectUri: Schema.String,\n /** The connectors the client is enrolled in, sorted, each once. Empty for the off values. */\n connectors: Schema.Array(Schema.String),\n /**\n * Returned only at a production registration (RFC 7591 section 1.2). It registers development\n * clients of this app. Empty for a preview, for a development client, and for the off values.\n */\n initialAccessToken: Schema.Redacted(Schema.String),\n /** The numeric GitHub id of the repository, with the initial access token. Empty without it. */\n repository: Schema.String,\n});\n\n/**\n * The attributes keep the real values of a suspended client, so that an unblock needs no new client.\n * `IdentityHub.Client.variables` gives the values that the app gets.\n */\nexport interface ClientAttributes extends Schema.Schema.Type<typeof Attributes> {}\n\n/**\n * The attributes of a saved row. A row that does not have this version's shape, or any other\n * failure of the decoder, stops the run with `reason`. The text of a schema issue can quote a value\n * of the row, so it is never kept.\n */\nconst savedAttributes = (value: unknown, reason: string) =>\n Schema.decodeUnknownEffect(Attributes)(value).pipe(\n Effect.catchCause(() => Effect.die(new IdentityHubClientFailed({ reason }))),\n );\n\n/** The attributes of no client. */\nconst offAttributes = (deploymentType: ClientAttributes[\"deploymentType\"]): ClientAttributes => ({\n status: \"off\",\n issuer: OFF_VALUES.issuer,\n clientId: OFF_VALUES.clientId,\n clientSecret: Redacted.make(OFF_VALUES.clientSecret),\n registrationAccessToken: Redacted.make(\"\"),\n registrationClientUri: \"\",\n deploymentType,\n redirectUri: \"\",\n connectors: [],\n initialAccessToken: Redacted.make(\"\"),\n repository: \"\",\n});\n\n/** The set of `names`: sorted, each once. */\nconst connectorSet = (names: readonly string[]) => [...new Set(names)].sort();\n\nconst sameSet = (a: readonly string[], b: readonly string[]) =>\n a.length === b.length && a.every((name, index) => name === b[index]);\n\n/** One request gave no usable answer. The reason holds no secret. */\nclass IdentityHubClientFailed extends Schema.TaggedError<IdentityHubClientFailed>()(\n \"IdentityHubClientFailed\",\n { reason: Schema.String },\n) {\n override get message() {\n return `IdentityHub.Client: ${this.reason}.`;\n }\n}\n\nconst OidcToken = Schema.Struct({ value: Schema.NonEmptyString });\n\n/** The 201 answer of `POST /hub-clients`. */\nconst NewClient = Schema.Struct({\n issuer: Schema.NonEmptyString,\n client_id: Schema.NonEmptyString,\n client_secret: Schema.NonEmptyString,\n registration_access_token: Schema.NonEmptyString,\n registration_client_uri: Schema.NonEmptyString,\n redirect_uri: Schema.NonEmptyString,\n /** The set the hub recorded, which must be the set the request sent. */\n connectors: Schema.Array(Schema.String),\n /** Only in the answer to a production registration with the GitHub token. */\n initial_access_token: Schema.optionalKey(Schema.NonEmptyString),\n repository: Schema.optionalKey(Schema.String.check(Schema.isPattern(/^\\d+$/))),\n});\n\n/** The other answers of `POST /hub-clients`, by status. */\nconst REFUSALS: Readonly<Record<number, string>> = {\n 400: \"the identity hub refused the request: the return address must be https on a DNS name, and the app name at most 64 characters\",\n 401: \"the identity hub refused the GitHub OIDC token\",\n 403: \"the identity hub does not allow this repository or return address\",\n 404: \"the identity hub has no /hub-clients\",\n 429: \"the identity hub limits new clients\",\n 502: \"GitHub's keys are not available to the identity hub\",\n};\n\n/** The reasons of a 403 that a log line shows. Any other text of the answer is never logged. */\nconst NOT_ALLOWED = new Map([\n [\"paused\", \"this app is paused on the identity hub\"],\n [\"run_not_allowed\", \"the identity hub gives clients only to runs of main and of pull requests\"],\n [\"blocked\", \"Samebase blocked this repository or its owner\"],\n [\"suspended\", \"the identity hub suspended this repository\"],\n [\"too_many_apps\", \"the repository has as many apps on the identity hub as it may\"],\n [\"too_many_clients\", \"the app has as many clients on the identity hub as it may\"],\n [\"app_taken\", \"the app's name belongs to another app on the identity hub\"],\n [\"host_unreachable\", \"the identity hub could not reach the host of the return address\"],\n [\n \"verification_file_missing\",\n \"the host of the return address does not serve /samebase-verification.json\",\n ],\n [\"verification_file_invalid\", \"/samebase-verification.json on the host holds no repository id\"],\n [\"repository_mismatch\", \"/samebase-verification.json on the host names another repository\"],\n [\"app_mismatch\", \"the initial access token belongs to another app on the identity hub\"],\n]);\n\n/** The windows of a 429, by the name that the answer gives. */\nconst RATE_LIMITED = new Map([\n [\"repository\", \"the identity hub gives one repository at most 30 new clients an hour\"],\n [\"owner\", \"the identity hub gives one owner at most 100 new clients an hour\"],\n [\"new_owners\", \"the identity hub takes at most 50 new owners an hour\"],\n]);\n\nconst Refusal = Schema.Struct({ reason: Schema.String });\nconst RateLimited = Schema.Struct({ window: Schema.String });\n/** A 400 for a connector the hub does not offer or allow, with the names it allows. */\nconst InvalidConnectors = Schema.Struct({\n error: Schema.Literal(\"invalid_connectors\"),\n allowed: Schema.Array(Schema.String),\n});\n\n/**\n * The text of a refusal: a known reason of a 403 or window of a 429, the allowed connectors of an\n * `invalid_connectors` 400 (only names of the connector grammar, so no other text of the answer is\n * printed), else the text of its status.\n */\nconst refusalOf = (status: number, body: unknown): string => {\n const decoded = <S extends Schema.Codec<unknown, unknown>>(schema: S) =>\n Option.getOrUndefined(Schema.decodeUnknownOption(schema)(body));\n const ofStatus = () => REFUSALS[status] ?? \"the identity hub refused the request\";\n switch (status) {\n case 400: {\n const allowed = decoded(InvalidConnectors)?.allowed.filter((name) =>\n CONNECTOR_NAME.test(name),\n );\n return allowed === undefined\n ? ofStatus()\n : `the identity hub does not offer or allow one of the connectors; it allows ${allowed.length === 0 ? \"none for this app\" : allowed.join(\", \")}`;\n }\n case 403:\n return NOT_ALLOWED.get(decoded(Refusal)?.reason ?? \"\") ?? ofStatus();\n case 429:\n return RATE_LIMITED.get(decoded(RateLimited)?.window ?? \"\") ?? ofStatus();\n default:\n return ofStatus();\n }\n};\n\nconst send = (who: string, url: string, token: string, init: { method: string; body?: string }) =>\n Effect.tryPromise({\n try: async () => {\n const response = await fetch(url, {\n ...init,\n headers: { Authorization: `Bearer ${token}`, \"Content-Type\": \"application/json\" },\n signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),\n });\n const body: unknown = await response.json().catch(() => undefined);\n return { status: response.status, body };\n },\n catch: () => new IdentityHubClientFailed({ reason: `${who} gave no answer` }),\n });\n\nconst decode =\n <S extends Schema.Codec<unknown, unknown>>(schema: S, who: string) =>\n (value: unknown) =>\n Schema.decodeUnknownEffect(schema)(value).pipe(\n Effect.mapError(() => new IdentityHubClientFailed({ reason: `${who} gave a bad answer` })),\n );\n\n/**\n * The OIDC token of this run for `audience`, read right before the call, because it lives for\n * minutes only.\n */\nconst readOidcToken = (requestUrl: string, requestToken: string, audience: string) =>\n Effect.gen(function* () {\n const { body, status } = yield* send(\n \"GitHub\",\n `${requestUrl}&audience=${encodeURIComponent(audience)}`,\n requestToken,\n { method: \"GET\" },\n );\n if (status !== 200) {\n return yield* new IdentityHubClientFailed({\n reason: `GitHub gave no OIDC token (HTTP ${status})`,\n });\n }\n return (yield* decode(OidcToken, \"GitHub\")(body)).value;\n });\n\n/** `POST /hub-clients` with `bearer`: the GitHub OIDC token, or the app's initial access token. */\nconst requestNewClient = (props: ClientProps, connectors: readonly string[], bearer: string) =>\n Effect.gen(function* () {\n const { hub } = props;\n const { body, status } = yield* send(\"The identity hub\", `${hub.issuer}/hub-clients`, bearer, {\n method: \"POST\",\n body: JSON.stringify({\n app: props.app,\n redirectUri: props.redirectUri,\n softwareVersion: props.softwareVersion ?? \"unknown\",\n connectors,\n }),\n });\n if (status !== 201) {\n const reason =\n status === 401 && props.deploymentType === \"development\"\n ? \"the identity hub refused the initial access token\"\n : refusalOf(status, body);\n return yield* new IdentityHubClientFailed({ reason: `${reason} (HTTP ${status})` });\n }\n const client = yield* decode(NewClient, \"The identity hub\")(body);\n // The hub registers the address and the connectors that the request sent, under its own issuer.\n // The log and the state hold the stack's values, so no value that the answer chose is printed\n // or kept.\n if (\n client.issuer !== hub.issuer ||\n client.redirect_uri !== props.redirectUri ||\n !sameSet(client.connectors, connectors)\n ) {\n return yield* new IdentityHubClientFailed({ reason: \"The identity hub gave a bad answer\" });\n }\n yield* Effect.logInfo(\n `IdentityHub.Client: ${props.app} on ${props.redirectUri} has a new client of the identity hub ${hub.issuer}.`,\n );\n // Only a production registration gives the app's token (RFC 7591); any other answer's is dropped.\n const production = props.deploymentType === \"production\";\n return {\n status: \"on\" as const,\n issuer: hub.issuer,\n clientId: client.client_id,\n clientSecret: Redacted.make(client.client_secret),\n registrationAccessToken: Redacted.make(client.registration_access_token),\n registrationClientUri: client.registration_client_uri,\n deploymentType: props.deploymentType,\n redirectUri: props.redirectUri,\n connectors,\n initialAccessToken: Redacted.make(production ? (client.initial_access_token ?? \"\") : \"\"),\n repository: production ? (client.repository ?? \"\") : \"\",\n };\n });\n\n/** A new client, or the off values. */\nconst newClient = (props: ClientProps, connectors: readonly string[]) => {\n const label = `IdentityHub.Client: ${props.app} on ${props.redirectUri} deploys without the hub`;\n const off = offAttributes(props.deploymentType);\n const request = (bearer: Effect.Effect<string, IdentityHubClientFailed>) =>\n bearer.pipe(\n Effect.flatMap((token) => requestNewClient(props, connectors, token)),\n Effect.catchTag(\"IdentityHubClientFailed\", (error) =>\n Effect.logWarning(`${label}: ${error.reason}. The next deploy asks again.`).pipe(\n Effect.as(off),\n ),\n ),\n );\n\n if (props.deploymentType === \"development\") {\n const token = Redacted.value(props.initialAccessToken);\n return token === \"\"\n ? Effect.logInfo(\n \"IdentityHub.Client: deploy to main once for hub sign-in in development.\",\n ).pipe(Effect.as(off))\n : request(Effect.succeed(token));\n }\n\n const requestUrl = process.env[\"ACTIONS_ID_TOKEN_REQUEST_URL\"];\n const requestToken = process.env[\"ACTIONS_ID_TOKEN_REQUEST_TOKEN\"];\n // A development machine, or another CI. In a workflow, `id-token: write` gives both, so a\n // workflow without them is a mistake to show, not a normal run.\n if (!requestUrl || !requestToken) {\n return (\n process.env[\"GITHUB_ACTIONS\"] === \"true\"\n ? Effect.logWarning(`${label}: this workflow needs the permission id-token: write.`)\n : Effect.logInfo(`${label}: this run has no GitHub OIDC token.`)\n ).pipe(Effect.as(off));\n }\n return request(readOidcToken(requestUrl, requestToken, props.hub.issuer));\n};\n\n/**\n * The client after a read on the hub, or undefined when the hub says that the client is gone. A\n * read with no usable answer keeps the saved client, except for a required one: a required client\n * passes a run only when the hub confirms it in that run, so a suspension that an earlier run saw,\n * and did not save because that run failed, cannot pass a run that the hub does not answer.\n */\nconst renew = (saved: ClientAttributes, required: boolean) =>\n Effect.gen(function* () {\n const { status } = yield* send(\n \"The identity hub\",\n saved.registrationClientUri,\n Redacted.value(saved.registrationAccessToken),\n { method: \"GET\" },\n );\n switch (status) {\n case 200:\n return { ...saved, status: \"on\" as const };\n case 401:\n return undefined;\n case 403:\n yield* Effect.logWarning(\n `IdentityHub.Client: the hub suspended the client of ${saved.redirectUri}. It keeps its values, and nobody can sign in with it.`,\n );\n return { ...saved, status: \"suspended\" as const };\n default:\n return yield* new IdentityHubClientFailed({\n reason: `The identity hub answered HTTP ${status}`,\n });\n }\n }).pipe(\n Effect.catchTag(\"IdentityHubClientFailed\", (error) =>\n required\n ? Effect.fail(\n new IdentityHubClientFailed({\n reason: `${saved.redirectUri} is required, and the hub did not confirm its client: ${error.reason}`,\n }),\n )\n : Effect.logWarning(\n `IdentityHub.Client: ${saved.redirectUri} keeps the saved client: ${error.reason}.`,\n ).pipe(Effect.as(saved)),\n ),\n );\n\n/**\n * The type of this resource before 0.37.0. Alchemy finds this provider for a row of that type, and\n * the next write of the row gives it the new type, with the same client. Remove it, here and in\n * `SavedRow`, once no saved row has the old type.\n */\nconst OLD_TYPE = \"IdentityHub.SharedClient\";\n\n/** A saved row of this resource, whose `attr` `savedAttributes` reads. */\nconst SavedRow = Schema.Struct({\n resourceType: Schema.Literals([\"IdentityHub.Client\", OLD_TYPE]),\n attr: Schema.Unknown,\n});\n\n/**\n * The attributes of the client `id` in another stage of this stack, such as\n * `read(\"HubClient\", { stage: \"prod\" })` in a development stage, as Outputs: the\n * `initialAccessToken` and the `repository` of the production client. Without that row, the off\n * attributes, with `deploymentType: \"production\"`.\n *\n * `IdentityHub.Client.ref` is not enough: Alchemy fails the plan with `InvalidReferenceError` when the\n * row is missing, and a development stage before the first deploy to main has none. This read runs\n * when the plan resolves it, with the State service of the running stack and its `get`, so it never\n * creates or upgrades a store. The store revives each secret as `Redacted`, as it does for every\n * read.\n */\nconst read = (id: string, options: { readonly stage: string }) =>\n Output.fromEffect(\n Effect.gen(function* () {\n const stack = yield* Stack;\n const state = yield* yield* State;\n const row = yield* state\n .get({ stack: stack.name, stage: options.stage, fqn: id })\n .pipe(Effect.orDie);\n if (row === undefined) return offAttributes(\"production\");\n const { attr } = yield* Schema.decodeUnknownEffect(SavedRow)(row).pipe(\n Effect.catchCause(() =>\n Effect.die(\n new IdentityHubClientFailed({\n reason: `the row ${id} of stage ${options.stage} is not an IdentityHub.Client`,\n }),\n ),\n ),\n );\n return yield* savedAttributes(\n attr,\n `the row ${id} of stage ${options.stage} holds attributes that this version cannot read`,\n );\n }),\n );\n\n/**\n * The three values that the app's deployment gets, such as `IDENTITY_HUB_ISSUER`,\n * `IDENTITY_HUB_CLIENT_ID`, and `IDENTITY_HUB_CLIENT_SECRET`, as Outputs: the client's values when\n * `status` is `on`, else the off values, so that a suspended client gives guest sign-in and keeps\n * its values in state.\n */\nconst variables = (client: Client) =>\n Output.map(Output.of(client), (attributes) =>\n attributes.status === \"on\"\n ? {\n issuer: attributes.issuer,\n clientId: attributes.clientId,\n clientSecret: attributes.clientSecret,\n }\n : {\n issuer: OFF_VALUES.issuer,\n clientId: OFF_VALUES.clientId,\n clientSecret: Redacted.make(OFF_VALUES.clientSecret),\n },\n );\n\nexport type Client = Resource<\n \"IdentityHub.Client\",\n ClientProps,\n ClientAttributes,\n never,\n Providers\n>;\nexport const Client = Resource<Client>(\"IdentityHub.Client\", { aliases: [OLD_TYPE] })({\n read,\n variables,\n});\n\nexport const ClientProvider = () =>\n Provider.succeed(Client, {\n // Always an update, so that each deploy reaches the hub. No attribute is stable, so a push\n // reads the values that this run ended with. The same values cause no other push.\n diff: ({ news }) =>\n Effect.succeed(isResolved(news) ? ({ action: \"update\" } as const) : undefined),\n\n read: ({ output }) => Effect.succeed(output),\n\n // Only a client of the same hub (its issuer), return address, type, and connector set is\n // renewed. A saved row without this version's shape stops the run with a fixed message.\n reconcile: Effect.fn(function* ({ news, output }) {\n // A bad prop is a mistake of the stack, not of the hub: the run fails, with no request.\n if (\n news.connectors.length === 0 ||\n !news.connectors.every((name) => CONNECTOR_NAME.test(name))\n ) {\n return yield* new IdentityHubClientFailed({\n reason: `${news.app} on ${news.redirectUri} needs connectors: one or more names of [a-z0-9-]{1,64}`,\n });\n }\n const connectors = connectorSet(news.connectors);\n const saved =\n output === undefined || output.status === \"off\"\n ? undefined\n : yield* savedAttributes(\n output,\n `the saved attributes of ${news.app} on ${news.redirectUri} cannot be read by this version`,\n );\n const renewed =\n saved?.issuer === news.hub.issuer &&\n saved.redirectUri === news.redirectUri &&\n saved.deploymentType === news.deploymentType &&\n sameSet(saved.connectors, connectors)\n ? yield* renew(saved, news.required === true)\n : undefined;\n const client = renewed ?? (yield* newClient(news, connectors));\n if (news.required === true && client.status !== \"on\") {\n return yield* new IdentityHubClientFailed({\n reason: `${news.app} on ${news.redirectUri} is required and has no working client (${client.status}). The warning above names the reason`,\n });\n }\n return client;\n }),\n\n // A failed delete does not stop a destroy: the removal date of a preview or development client\n // cleans it up. A destroy can leave a production deployment running, so its client stays.\n delete: ({ output }) =>\n output.deploymentType === \"production\" || output.status === \"off\"\n ? Effect.void\n : Effect.gen(function* () {\n const { status } = yield* send(\n \"The identity hub\",\n output.registrationClientUri,\n Redacted.value(output.registrationAccessToken),\n { method: \"DELETE\" },\n );\n // 401: the client is gone already.\n if (status !== 204 && status !== 401) {\n return yield* new IdentityHubClientFailed({\n reason: `The identity hub answered HTTP ${status}`,\n });\n }\n }).pipe(\n Effect.catchTag(\"IdentityHubClientFailed\", (error) =>\n Effect.logWarning(\n `IdentityHub.Client: the client of ${output.redirectUri} stays on the hub until its removal date: ${error.reason}.`,\n ),\n ),\n ),\n });\n"],"mappings":";;;;;;;;;;;;AA+CA,MAAM,qBAAqB;;AAG3B,MAAM,aAAa;CAAE,QAAQ;CAAsB,UAAU;CAAU,cAAc;AAAS;;AAG9F,MAAM,iBAAiB;AA2DvB,MAAM,iBAAiB,OAAO,SAAS;CAAC;CAAc;CAAW;AAAa,CAAC;AAE/E,MAAM,aAAa,OAAO,OAAO;;CAE/B,QAAQ,OAAO,SAAS;EAAC;EAAM;EAAO;CAAW,CAAC;;CAElD,QAAQ,OAAO;CACf,UAAU,OAAO;;CAEjB,cAAc,OAAO,SAAS,OAAO,MAAM;;CAE3C,yBAAyB,OAAO,SAAS,OAAO,MAAM;CACtD,uBAAuB,OAAO;CAC9B,gBAAgB;;CAEhB,aAAa,OAAO;;CAEpB,YAAY,OAAO,MAAM,OAAO,MAAM;;;;;CAKtC,oBAAoB,OAAO,SAA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