alchemy 2.0.0-beta.29 → 2.0.0-beta.30

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alchemy",
3
- "version": "2.0.0-beta.29",
3
+ "version": "2.0.0-beta.30",
4
4
  "homepage": "https://alchemy.run",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Sam Goodwin <sam@alchemy.run>",
package/src/Apply.ts CHANGED
@@ -274,9 +274,7 @@ const executePlan = Effect.fnUntraced(function* (
274
274
  // Aggregate every collected lifecycle failure into a single parallel Cause
275
275
  // so the apply ends with one combined error containing every distinct
276
276
  // failure / defect that occurred across the concurrent fibers.
277
- yield* Effect.failCause(
278
- failures.map((f) => f.cause).reduce(Cause.combine),
279
- );
277
+ yield* Effect.failCause(failures.map((f) => f.cause).reduce(Cause.combine));
280
278
  }
281
279
  });
282
280
 
@@ -882,10 +880,7 @@ const executeNode = (
882
880
  type: node.resource.Type,
883
881
  cause,
884
882
  });
885
- yield* Deferred.failCause(
886
- ready[fqn],
887
- cause as Cause.Cause<never>,
888
- );
883
+ yield* Deferred.failCause(ready[fqn], cause as Cause.Cause<never>);
889
884
  yield* session.emit({
890
885
  kind: "status-change",
891
886
  id: node.resource.LogicalId,
@@ -5,6 +5,7 @@ import * as Effect from "effect/Effect";
5
5
  import * as Layer from "effect/Layer";
6
6
  import * as Redacted from "effect/Redacted";
7
7
  import * as HttpClient from "effect/unstable/http/HttpClient";
8
+ import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
8
9
  import * as HttpApiClient from "effect/unstable/httpapi/HttpApiClient";
9
10
 
10
11
  import * as Config from "effect/Config";
@@ -204,7 +205,7 @@ export const state = (props?: {
204
205
  });
205
206
  if (fresh) return fresh;
206
207
 
207
- const httpState = yield* makeHttpStateStore(credentials);
208
+ const httpState = yield* makeCloudflareStateStore(credentials);
208
209
 
209
210
  if (alchemyContext.updateStateStore) {
210
211
  yield* deployStateStore(scriptName, httpState);
@@ -245,7 +246,7 @@ export const state = (props?: {
245
246
  });
246
247
  if (fresh) return fresh;
247
248
 
248
- const httpState = yield* makeHttpStateStore(credentials);
249
+ const httpState = yield* makeCloudflareStateStore(credentials);
249
250
 
250
251
  if (alchemyContext.updateStateStore) {
251
252
  yield* deployStateStore(scriptName, httpState);
@@ -287,6 +288,22 @@ export const state = (props?: {
287
288
  Layer.orDie,
288
289
  );
289
290
 
291
+ const makeCloudflareStateStore = Effect.fnUntraced(function* ({
292
+ url,
293
+ authToken,
294
+ }: {
295
+ url: string;
296
+ authToken: string;
297
+ }) {
298
+ const access = yield* Access.Access;
299
+ const accessHeaders = yield* access.getAccessHeaders(new URL(url).host);
300
+ return yield* makeHttpStateStore({
301
+ url,
302
+ authToken,
303
+ transformClient: HttpClientRequest.setHeaders(accessHeaders),
304
+ });
305
+ });
306
+
290
307
  /**
291
308
  * Non-destructively copy every resource in the
292
309
  * `CloudflareStateStore/<scriptName>` stack from `source` into
@@ -350,7 +367,7 @@ const finishBootstrap = ({
350
367
  // credentials file (skipping the write in CI), so we don't need
351
368
  // to do that explicitly here.
352
369
  const { url, authToken } = yield* loginWithCloudflare();
353
- const httpState = yield* makeHttpStateStore({ url, authToken });
370
+ const httpState = yield* makeCloudflareStateStore({ url, authToken });
354
371
  // `profileName` is intentionally unused here — `loginWithCloudflare`
355
372
  // resolves it itself. Reference it to keep the surrounding API
356
373
  // explicit and to avoid an unused-parameter lint.
@@ -1,4 +1,5 @@
1
1
  import * as Effect from "effect/Effect";
2
+ import { identity } from "effect/Function";
2
3
  import * as Schedule from "effect/Schedule";
3
4
  import * as HttpClient from "effect/unstable/http/HttpClient";
4
5
  import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
@@ -13,14 +14,24 @@ export interface HttpStateStoreProps {
13
14
  url: string;
14
15
  /** Bearer token used to authenticate every request. */
15
16
  authToken: string;
17
+ transformClient?: (
18
+ client: HttpClientRequest.HttpClientRequest,
19
+ ) => HttpClientRequest.HttpClientRequest;
16
20
  }
17
21
 
18
- export const makeHttpStateStore = ({ url, authToken }: HttpStateStoreProps) =>
22
+ export const makeHttpStateStore = ({
23
+ url,
24
+ authToken,
25
+ transformClient,
26
+ }: HttpStateStoreProps) =>
19
27
  Effect.gen(function* () {
20
28
  const apiClient = yield* HttpApiClient.make(StateApi, {
21
29
  baseUrl: url,
22
- transformClient: HttpClient.mapRequest(
23
- HttpClientRequest.bearerToken(authToken),
30
+ transformClient: HttpClient.mapRequest((req) =>
31
+ req.pipe(
32
+ HttpClientRequest.bearerToken(authToken),
33
+ transformClient ?? identity,
34
+ ),
24
35
  ),
25
36
  });
26
37
  const state = apiClient.state;