alchemy 2.0.0-beta.16 → 2.0.0-beta.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/bin/alchemy.js +79 -6
  2. package/bin/alchemy.js.map +1 -1
  3. package/bin/cli.js +9 -7
  4. package/bin/commands/deploy.ts +11 -2
  5. package/bin/commands/profile.ts +21 -1
  6. package/bin/commands/state.ts +91 -1
  7. package/lib/AWS/CloudFront/CachePolicy.d.ts +106 -0
  8. package/lib/AWS/CloudFront/CachePolicy.d.ts.map +1 -0
  9. package/lib/AWS/CloudFront/CachePolicy.js +147 -0
  10. package/lib/AWS/CloudFront/CachePolicy.js.map +1 -0
  11. package/lib/AWS/CloudFront/KeyGroup.d.ts +72 -0
  12. package/lib/AWS/CloudFront/KeyGroup.d.ts.map +1 -0
  13. package/lib/AWS/CloudFront/KeyGroup.js +136 -0
  14. package/lib/AWS/CloudFront/KeyGroup.js.map +1 -0
  15. package/lib/AWS/CloudFront/OriginRequestPolicy.d.ts +84 -0
  16. package/lib/AWS/CloudFront/OriginRequestPolicy.d.ts.map +1 -0
  17. package/lib/AWS/CloudFront/OriginRequestPolicy.js +139 -0
  18. package/lib/AWS/CloudFront/OriginRequestPolicy.js.map +1 -0
  19. package/lib/AWS/CloudFront/PublicKey.d.ts +72 -0
  20. package/lib/AWS/CloudFront/PublicKey.d.ts.map +1 -0
  21. package/lib/AWS/CloudFront/PublicKey.js +137 -0
  22. package/lib/AWS/CloudFront/PublicKey.js.map +1 -0
  23. package/lib/AWS/CloudFront/ResponseHeadersPolicy.d.ts +114 -0
  24. package/lib/AWS/CloudFront/ResponseHeadersPolicy.d.ts.map +1 -0
  25. package/lib/AWS/CloudFront/ResponseHeadersPolicy.js +162 -0
  26. package/lib/AWS/CloudFront/ResponseHeadersPolicy.js.map +1 -0
  27. package/lib/AWS/CloudFront/index.d.ts +5 -0
  28. package/lib/AWS/CloudFront/index.d.ts.map +1 -1
  29. package/lib/AWS/CloudFront/index.js +5 -0
  30. package/lib/AWS/CloudFront/index.js.map +1 -1
  31. package/lib/AWS/ECS/CapacityProvider.d.ts +102 -0
  32. package/lib/AWS/ECS/CapacityProvider.d.ts.map +1 -0
  33. package/lib/AWS/ECS/CapacityProvider.js +217 -0
  34. package/lib/AWS/ECS/CapacityProvider.js.map +1 -0
  35. package/lib/AWS/ECS/index.d.ts +1 -0
  36. package/lib/AWS/ECS/index.d.ts.map +1 -1
  37. package/lib/AWS/ECS/index.js +1 -0
  38. package/lib/AWS/ECS/index.js.map +1 -1
  39. package/lib/AWS/Providers.d.ts.map +1 -1
  40. package/lib/AWS/Providers.js +7 -1
  41. package/lib/AWS/Providers.js.map +1 -1
  42. package/lib/Auth/Credentials.d.ts +6 -0
  43. package/lib/Auth/Credentials.d.ts.map +1 -1
  44. package/lib/Auth/Credentials.js +12 -1
  45. package/lib/Auth/Credentials.js.map +1 -1
  46. package/lib/Auth/Profile.d.ts +5 -0
  47. package/lib/Auth/Profile.d.ts.map +1 -1
  48. package/lib/Auth/Profile.js +11 -0
  49. package/lib/Auth/Profile.js.map +1 -1
  50. package/lib/Cloudflare/ApiToken/AccountApiToken.d.ts +2 -1
  51. package/lib/Cloudflare/ApiToken/AccountApiToken.d.ts.map +1 -1
  52. package/lib/Cloudflare/ApiToken/AccountApiToken.js +6 -5
  53. package/lib/Cloudflare/ApiToken/AccountApiToken.js.map +1 -1
  54. package/lib/Cloudflare/ApiToken/Common.d.ts +5 -11
  55. package/lib/Cloudflare/ApiToken/Common.d.ts.map +1 -1
  56. package/lib/Cloudflare/ApiToken/Common.js +4 -14
  57. package/lib/Cloudflare/ApiToken/Common.js.map +1 -1
  58. package/lib/Cloudflare/ApiToken/UserApiToken.js +4 -4
  59. package/lib/Cloudflare/ApiToken/UserApiToken.js.map +1 -1
  60. package/lib/GitHub/Comment.d.ts +2 -1
  61. package/lib/GitHub/Comment.d.ts.map +1 -1
  62. package/lib/GitHub/Comment.js +1 -0
  63. package/lib/GitHub/Comment.js.map +1 -1
  64. package/lib/GitHub/Providers.d.ts.map +1 -1
  65. package/lib/GitHub/Providers.js +2 -1
  66. package/lib/GitHub/Providers.js.map +1 -1
  67. package/lib/GitHub/Secret.d.ts +2 -2
  68. package/lib/GitHub/Secret.d.ts.map +1 -1
  69. package/lib/GitHub/Secrets.d.ts +45 -0
  70. package/lib/GitHub/Secrets.d.ts.map +1 -0
  71. package/lib/GitHub/Secrets.js +30 -0
  72. package/lib/GitHub/Secrets.js.map +1 -0
  73. package/lib/GitHub/Variable.d.ts +2 -2
  74. package/lib/GitHub/Variable.d.ts.map +1 -1
  75. package/lib/GitHub/index.d.ts +1 -0
  76. package/lib/GitHub/index.d.ts.map +1 -1
  77. package/lib/GitHub/index.js +1 -0
  78. package/lib/GitHub/index.js.map +1 -1
  79. package/package.json +1 -1
  80. package/src/AWS/CloudFront/CachePolicy.ts +271 -0
  81. package/src/AWS/CloudFront/KeyGroup.ts +233 -0
  82. package/src/AWS/CloudFront/OriginRequestPolicy.ts +256 -0
  83. package/src/AWS/CloudFront/PublicKey.ts +245 -0
  84. package/src/AWS/CloudFront/ResponseHeadersPolicy.ts +308 -0
  85. package/src/AWS/CloudFront/index.ts +11 -0
  86. package/src/AWS/ECS/CapacityProvider.ts +336 -0
  87. package/src/AWS/ECS/index.ts +4 -0
  88. package/src/AWS/Providers.ts +12 -0
  89. package/src/Auth/Credentials.ts +17 -1
  90. package/src/Auth/Profile.ts +15 -0
  91. package/src/Cloudflare/ApiToken/AccountApiToken.ts +6 -5
  92. package/src/Cloudflare/ApiToken/Common.ts +6 -18
  93. package/src/Cloudflare/ApiToken/UserApiToken.ts +4 -4
  94. package/src/GitHub/Comment.ts +4 -1
  95. package/src/GitHub/Providers.ts +8 -2
  96. package/src/GitHub/Secret.ts +2 -2
  97. package/src/GitHub/Secrets.ts +66 -0
  98. package/src/GitHub/Variable.ts +2 -2
  99. package/src/GitHub/index.ts +1 -0
@@ -0,0 +1,256 @@
1
+ import * as cloudfront from "@distilled.cloud/aws/cloudfront";
2
+ import * as Effect from "effect/Effect";
3
+ import { isResolved } from "../../Diff.ts";
4
+ import { createPhysicalName } from "../../PhysicalName.ts";
5
+ import * as Provider from "../../Provider.ts";
6
+ import { Resource } from "../../Resource.ts";
7
+ import type { Providers } from "../Providers.ts";
8
+
9
+ export interface OriginRequestPolicyProps {
10
+ /**
11
+ * Name of the origin request policy. If omitted, a deterministic name is
12
+ * generated. Names must be unique per AWS account. Changing the name
13
+ * triggers a replacement.
14
+ */
15
+ name?: string;
16
+ /**
17
+ * Optional comment describing the policy.
18
+ */
19
+ comment?: string;
20
+ /**
21
+ * Headers to forward to the origin (in addition to the cache key).
22
+ */
23
+ headersConfig: cloudfront.OriginRequestPolicyHeadersConfig;
24
+ /**
25
+ * Cookies to forward to the origin (in addition to the cache key).
26
+ */
27
+ cookiesConfig: cloudfront.OriginRequestPolicyCookiesConfig;
28
+ /**
29
+ * Query strings to forward to the origin (in addition to the cache key).
30
+ */
31
+ queryStringsConfig: cloudfront.OriginRequestPolicyQueryStringsConfig;
32
+ }
33
+
34
+ export interface OriginRequestPolicy extends Resource<
35
+ "AWS.CloudFront.OriginRequestPolicy",
36
+ OriginRequestPolicyProps,
37
+ {
38
+ /**
39
+ * CloudFront-assigned origin request policy identifier.
40
+ */
41
+ originRequestPolicyId: string;
42
+ /**
43
+ * Name of the origin request policy.
44
+ */
45
+ name: string;
46
+ /**
47
+ * Most recent entity tag for update/delete operations.
48
+ */
49
+ etag: string | undefined;
50
+ /**
51
+ * Current comment on the policy.
52
+ */
53
+ comment: string | undefined;
54
+ /**
55
+ * Current headers configuration.
56
+ */
57
+ headersConfig: cloudfront.OriginRequestPolicyHeadersConfig;
58
+ /**
59
+ * Current cookies configuration.
60
+ */
61
+ cookiesConfig: cloudfront.OriginRequestPolicyCookiesConfig;
62
+ /**
63
+ * Current query strings configuration.
64
+ */
65
+ queryStringsConfig: cloudfront.OriginRequestPolicyQueryStringsConfig;
66
+ },
67
+ never,
68
+ Providers
69
+ > {}
70
+
71
+ /**
72
+ * A CloudFront origin request policy.
73
+ *
74
+ * Origin request policies control which values from the viewer request (in
75
+ * addition to those used in the cache key) CloudFront includes when sending
76
+ * a request to the origin. They are referenced by ID on a Distribution's
77
+ * default behavior or per-path cache behaviors.
78
+ *
79
+ * @section Creating Origin Request Policies
80
+ * @example Forward all viewer headers and cookies
81
+ * ```typescript
82
+ * const originRequestPolicy = yield* OriginRequestPolicy("AppOriginRequest", {
83
+ * comment: "Forward auth + locale",
84
+ * headersConfig: {
85
+ * HeaderBehavior: "whitelist",
86
+ * Headers: { Quantity: 2, Items: ["Authorization", "Accept-Language"] },
87
+ * },
88
+ * cookiesConfig: { CookieBehavior: "all" },
89
+ * queryStringsConfig: { QueryStringBehavior: "all" },
90
+ * });
91
+ * ```
92
+ */
93
+ export const OriginRequestPolicy = Resource<OriginRequestPolicy>(
94
+ "AWS.CloudFront.OriginRequestPolicy",
95
+ );
96
+
97
+ export const OriginRequestPolicyProvider = () =>
98
+ Provider.effect(
99
+ OriginRequestPolicy,
100
+ Effect.gen(function* () {
101
+ const getById = Effect.fn(function* (id: string) {
102
+ const config = yield* cloudfront
103
+ .getOriginRequestPolicyConfig({ Id: id })
104
+ .pipe(
105
+ Effect.catchTag("NoSuchOriginRequestPolicy", () =>
106
+ Effect.succeed(undefined),
107
+ ),
108
+ );
109
+ if (!config?.OriginRequestPolicyConfig) return undefined;
110
+ return { config: config.OriginRequestPolicyConfig, etag: config.ETag };
111
+ });
112
+
113
+ const getByName = Effect.fn(function* (name: string) {
114
+ const listed = yield* cloudfront.listOriginRequestPolicies({
115
+ Type: "custom",
116
+ });
117
+ const summary = listed.OriginRequestPolicyList?.Items?.find(
118
+ (item) =>
119
+ item.OriginRequestPolicy?.OriginRequestPolicyConfig?.Name === name,
120
+ );
121
+ if (!summary?.OriginRequestPolicy?.Id) return undefined;
122
+ return yield* getById(summary.OriginRequestPolicy.Id).pipe(
123
+ Effect.map((found) =>
124
+ found ? { id: summary.OriginRequestPolicy.Id, ...found } : undefined,
125
+ ),
126
+ );
127
+ });
128
+
129
+ const buildConfig = (
130
+ name: string,
131
+ props: OriginRequestPolicyProps,
132
+ ): cloudfront.OriginRequestPolicyConfig => ({
133
+ Name: name,
134
+ Comment: props.comment,
135
+ HeadersConfig: props.headersConfig,
136
+ CookiesConfig: props.cookiesConfig,
137
+ QueryStringsConfig: props.queryStringsConfig,
138
+ });
139
+
140
+ const toAttrs = (
141
+ id: string,
142
+ config: cloudfront.OriginRequestPolicyConfig,
143
+ etag: string | undefined,
144
+ ) => ({
145
+ originRequestPolicyId: id,
146
+ name: config.Name,
147
+ etag,
148
+ comment: config.Comment,
149
+ headersConfig: config.HeadersConfig,
150
+ cookiesConfig: config.CookiesConfig,
151
+ queryStringsConfig: config.QueryStringsConfig,
152
+ });
153
+
154
+ return {
155
+ stables: ["originRequestPolicyId"],
156
+ diff: Effect.fn(function* ({ id, news, olds }) {
157
+ if (!isResolved(news)) return undefined;
158
+ if (
159
+ (yield* createName(id, olds ?? {})) !==
160
+ (yield* createName(id, news))
161
+ ) {
162
+ return { action: "replace" } as const;
163
+ }
164
+ }),
165
+ read: Effect.fn(function* ({ id, olds, output }) {
166
+ if (output?.originRequestPolicyId) {
167
+ const found = yield* getById(output.originRequestPolicyId);
168
+ if (found) {
169
+ return toAttrs(output.originRequestPolicyId, found.config, found.etag);
170
+ }
171
+ }
172
+ const name = yield* createName(id, olds ?? {});
173
+ const found = yield* getByName(name);
174
+ if (!found) return undefined;
175
+ return toAttrs(found.id, found.config, found.etag);
176
+ }),
177
+ create: Effect.fn(function* ({ id, news, session }) {
178
+ const name = yield* createName(id, news);
179
+ const created = yield* cloudfront
180
+ .createOriginRequestPolicy({
181
+ OriginRequestPolicyConfig: buildConfig(name, news),
182
+ })
183
+ .pipe(
184
+ Effect.catchTag("OriginRequestPolicyAlreadyExists", () =>
185
+ getByName(name).pipe(
186
+ Effect.flatMap((existing) =>
187
+ existing
188
+ ? Effect.succeed({
189
+ OriginRequestPolicy: {
190
+ Id: existing.id,
191
+ LastModifiedTime: new Date(),
192
+ OriginRequestPolicyConfig: existing.config,
193
+ },
194
+ ETag: existing.etag,
195
+ Location: undefined,
196
+ })
197
+ : Effect.fail(
198
+ new Error(
199
+ `Origin request policy '${name}' already exists but could not be recovered`,
200
+ ),
201
+ ),
202
+ ),
203
+ ),
204
+ ),
205
+ );
206
+ if (!created.OriginRequestPolicy?.Id) {
207
+ return yield* Effect.fail(
208
+ new Error("createOriginRequestPolicy returned no identifier"),
209
+ );
210
+ }
211
+ yield* session.note(created.OriginRequestPolicy.Id);
212
+ return toAttrs(
213
+ created.OriginRequestPolicy.Id,
214
+ created.OriginRequestPolicy.OriginRequestPolicyConfig,
215
+ created.ETag,
216
+ );
217
+ }),
218
+ update: Effect.fn(function* ({ news, output, session }) {
219
+ const current = yield* getById(output.originRequestPolicyId);
220
+ const updated = yield* cloudfront.updateOriginRequestPolicy({
221
+ Id: output.originRequestPolicyId,
222
+ IfMatch: current?.etag ?? output.etag,
223
+ OriginRequestPolicyConfig: buildConfig(output.name, news),
224
+ });
225
+ if (!updated.OriginRequestPolicy?.Id) {
226
+ return yield* Effect.fail(
227
+ new Error("updateOriginRequestPolicy returned no identifier"),
228
+ );
229
+ }
230
+ yield* session.note(output.originRequestPolicyId);
231
+ return toAttrs(
232
+ updated.OriginRequestPolicy.Id,
233
+ updated.OriginRequestPolicy.OriginRequestPolicyConfig,
234
+ updated.ETag,
235
+ );
236
+ }),
237
+ delete: Effect.fn(function* ({ output }) {
238
+ const current = yield* getById(output.originRequestPolicyId);
239
+ if (!current) return;
240
+ yield* cloudfront
241
+ .deleteOriginRequestPolicy({
242
+ Id: output.originRequestPolicyId,
243
+ IfMatch: current.etag,
244
+ })
245
+ .pipe(
246
+ Effect.catchTag("NoSuchOriginRequestPolicy", () => Effect.void),
247
+ );
248
+ }),
249
+ };
250
+ }),
251
+ );
252
+
253
+ const createName = (id: string, props: OriginRequestPolicyProps) =>
254
+ props.name
255
+ ? Effect.succeed(props.name)
256
+ : createPhysicalName({ id, maxLength: 128, lowercase: true });
@@ -0,0 +1,245 @@
1
+ import * as cloudfront from "@distilled.cloud/aws/cloudfront";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Redacted from "effect/Redacted";
4
+ import { isResolved } from "../../Diff.ts";
5
+ import { createPhysicalName } from "../../PhysicalName.ts";
6
+ import * as Provider from "../../Provider.ts";
7
+ import { Resource } from "../../Resource.ts";
8
+ import type { Providers } from "../Providers.ts";
9
+ import { extractValue } from "./common.ts";
10
+
11
+ export interface PublicKeyProps {
12
+ /**
13
+ * Name of the public key. If omitted, a deterministic name is generated.
14
+ *
15
+ * Names must be unique per AWS account. Changing the name triggers
16
+ * a replacement.
17
+ */
18
+ name?: string;
19
+ /**
20
+ * PEM-encoded public key body. Changing the key material triggers a
21
+ * replacement (CloudFront does not allow rotating an existing public
22
+ * key in place).
23
+ */
24
+ encodedKey: Redacted.Redacted<string> | string;
25
+ /**
26
+ * Optional comment describing the key.
27
+ */
28
+ comment?: string;
29
+ }
30
+
31
+ export interface PublicKey extends Resource<
32
+ "AWS.CloudFront.PublicKey",
33
+ PublicKeyProps,
34
+ {
35
+ /**
36
+ * CloudFront-assigned public key identifier. Used by KeyGroups to
37
+ * reference the key.
38
+ */
39
+ publicKeyId: string;
40
+ /**
41
+ * Name of the public key.
42
+ */
43
+ name: string;
44
+ /**
45
+ * PEM-encoded public key body.
46
+ */
47
+ encodedKey: string;
48
+ /**
49
+ * Caller reference used at create time. Stable across updates.
50
+ */
51
+ callerReference: string;
52
+ /**
53
+ * Most recent entity tag for update/delete operations.
54
+ */
55
+ etag: string | undefined;
56
+ /**
57
+ * Current comment on the key.
58
+ */
59
+ comment: string | undefined;
60
+ },
61
+ never,
62
+ Providers
63
+ > {}
64
+
65
+ /**
66
+ * A CloudFront public key.
67
+ *
68
+ * Public keys are uploaded ahead of being grouped into a {@link KeyGroup} and
69
+ * used by Distributions for signed URL or signed cookie verification.
70
+ *
71
+ * The key body is immutable after creation — changing `encodedKey` triggers
72
+ * a replacement (CloudFront returns no API to rotate a key in place).
73
+ *
74
+ * @section Creating Public Keys
75
+ * @example PEM-encoded RSA public key
76
+ * ```typescript
77
+ * const key = yield* PublicKey("SignedUrlKey", {
78
+ * encodedKey: Redacted.make(yield* fs.readFileString("./public_key.pem")),
79
+ * comment: "RSA-2048 signed URL key for /private",
80
+ * });
81
+ * ```
82
+ */
83
+ export const PublicKey = Resource<PublicKey>("AWS.CloudFront.PublicKey");
84
+
85
+ export const PublicKeyProvider = () =>
86
+ Provider.effect(
87
+ PublicKey,
88
+ Effect.gen(function* () {
89
+ const getById = Effect.fn(function* (id: string) {
90
+ const config = yield* cloudfront
91
+ .getPublicKeyConfig({ Id: id })
92
+ .pipe(
93
+ Effect.catchTag("NoSuchPublicKey", () => Effect.succeed(undefined)),
94
+ );
95
+ if (!config?.PublicKeyConfig) return undefined;
96
+ return { config: config.PublicKeyConfig, etag: config.ETag };
97
+ });
98
+
99
+ const getByName = Effect.fn(function* (name: string) {
100
+ const listed = yield* cloudfront.listPublicKeys({});
101
+ const summary = listed.PublicKeyList?.Items?.find(
102
+ (item) => item.Name === name,
103
+ );
104
+ if (!summary?.Id) return undefined;
105
+ return yield* getById(summary.Id).pipe(
106
+ Effect.map((found) =>
107
+ found ? { id: summary.Id, ...found } : undefined,
108
+ ),
109
+ );
110
+ });
111
+
112
+ const buildConfig = (
113
+ name: string,
114
+ callerReference: string,
115
+ props: PublicKeyProps,
116
+ ): cloudfront.PublicKeyConfig => ({
117
+ Name: name,
118
+ CallerReference: callerReference,
119
+ EncodedKey: extractValue(props.encodedKey),
120
+ Comment: props.comment,
121
+ });
122
+
123
+ const toAttrs = (
124
+ id: string,
125
+ config: cloudfront.PublicKeyConfig,
126
+ etag: string | undefined,
127
+ ) => ({
128
+ publicKeyId: id,
129
+ name: config.Name,
130
+ encodedKey: config.EncodedKey,
131
+ callerReference: config.CallerReference,
132
+ etag,
133
+ comment: config.Comment,
134
+ });
135
+
136
+ return {
137
+ stables: ["publicKeyId", "callerReference"],
138
+ diff: Effect.fn(function* ({ id, news, olds }) {
139
+ if (!isResolved(news)) return undefined;
140
+ if (
141
+ (yield* createName(id, olds ?? {})) !==
142
+ (yield* createName(id, news))
143
+ ) {
144
+ return { action: "replace" } as const;
145
+ }
146
+ if (
147
+ isResolved(olds.encodedKey) &&
148
+ extractValue(olds.encodedKey) !== extractValue(news.encodedKey)
149
+ ) {
150
+ return { action: "replace" } as const;
151
+ }
152
+ }),
153
+ read: Effect.fn(function* ({ id, olds, output }) {
154
+ if (output?.publicKeyId) {
155
+ const found = yield* getById(output.publicKeyId);
156
+ if (found) return toAttrs(output.publicKeyId, found.config, found.etag);
157
+ }
158
+ const name = yield* createName(id, olds ?? {});
159
+ const found = yield* getByName(name);
160
+ if (!found) return undefined;
161
+ return toAttrs(found.id, found.config, found.etag);
162
+ }),
163
+ create: Effect.fn(function* ({ id, news, session }) {
164
+ const name = yield* createName(id, news);
165
+ const callerReference = name;
166
+ const created = yield* cloudfront
167
+ .createPublicKey({
168
+ PublicKeyConfig: buildConfig(name, callerReference, news),
169
+ })
170
+ .pipe(
171
+ Effect.catchTag("PublicKeyAlreadyExists", () =>
172
+ getByName(name).pipe(
173
+ Effect.flatMap((existing) =>
174
+ existing
175
+ ? Effect.succeed({
176
+ PublicKey: {
177
+ Id: existing.id,
178
+ CreatedTime: new Date(),
179
+ PublicKeyConfig: existing.config,
180
+ },
181
+ ETag: existing.etag,
182
+ Location: undefined,
183
+ })
184
+ : Effect.fail(
185
+ new Error(
186
+ `Public key '${name}' already exists but could not be recovered`,
187
+ ),
188
+ ),
189
+ ),
190
+ ),
191
+ ),
192
+ );
193
+ if (!created.PublicKey?.Id) {
194
+ return yield* Effect.fail(
195
+ new Error("createPublicKey returned no identifier"),
196
+ );
197
+ }
198
+ yield* session.note(created.PublicKey.Id);
199
+ return toAttrs(
200
+ created.PublicKey.Id,
201
+ created.PublicKey.PublicKeyConfig,
202
+ created.ETag,
203
+ );
204
+ }),
205
+ update: Effect.fn(function* ({ news, output, session }) {
206
+ const current = yield* getById(output.publicKeyId);
207
+ const updated = yield* cloudfront.updatePublicKey({
208
+ Id: output.publicKeyId,
209
+ IfMatch: current?.etag ?? output.etag,
210
+ PublicKeyConfig: buildConfig(
211
+ output.name,
212
+ output.callerReference,
213
+ news,
214
+ ),
215
+ });
216
+ if (!updated.PublicKey?.Id) {
217
+ return yield* Effect.fail(
218
+ new Error("updatePublicKey returned no identifier"),
219
+ );
220
+ }
221
+ yield* session.note(output.publicKeyId);
222
+ return toAttrs(
223
+ updated.PublicKey.Id,
224
+ updated.PublicKey.PublicKeyConfig,
225
+ updated.ETag,
226
+ );
227
+ }),
228
+ delete: Effect.fn(function* ({ output }) {
229
+ const current = yield* getById(output.publicKeyId);
230
+ if (!current) return;
231
+ yield* cloudfront
232
+ .deletePublicKey({
233
+ Id: output.publicKeyId,
234
+ IfMatch: current.etag,
235
+ })
236
+ .pipe(Effect.catchTag("NoSuchPublicKey", () => Effect.void));
237
+ }),
238
+ };
239
+ }),
240
+ );
241
+
242
+ const createName = (id: string, props: PublicKeyProps) =>
243
+ props.name
244
+ ? Effect.succeed(props.name)
245
+ : createPhysicalName({ id, maxLength: 128, lowercase: true });