alchemy 2.0.0-beta.14 → 2.0.0-beta.15

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 (127) hide show
  1. package/bin/alchemy.js +602 -596
  2. package/bin/alchemy.js.map +1 -1
  3. package/bin/alchemy.ts +2 -0
  4. package/bin/commands/deploy.ts +0 -1
  5. package/bin/commands/state.ts +8 -5
  6. package/lib/AWS/Lambda/BucketEventSource.d.ts +1 -1
  7. package/lib/AWS/Lambda/BucketEventSource.d.ts.map +1 -1
  8. package/lib/AWS/Lambda/EventBridgeEventSource.d.ts +1 -1
  9. package/lib/AWS/Lambda/EventBridgeEventSource.d.ts.map +1 -1
  10. package/lib/AWS/Lambda/QueueEventSource.d.ts +1 -1
  11. package/lib/AWS/Lambda/QueueEventSource.d.ts.map +1 -1
  12. package/lib/AWS/Lambda/StreamEventSource.d.ts +1 -1
  13. package/lib/AWS/Lambda/StreamEventSource.d.ts.map +1 -1
  14. package/lib/AWS/Lambda/TableEventSource.d.ts +1 -1
  15. package/lib/AWS/Lambda/TableEventSource.d.ts.map +1 -1
  16. package/lib/AWS/Lambda/TopicEventSource.d.ts +1 -1
  17. package/lib/AWS/Lambda/TopicEventSource.d.ts.map +1 -1
  18. package/lib/Agent/lsp/client.d.ts +2 -2
  19. package/lib/Cli/InkCLI.d.ts +0 -1
  20. package/lib/Cli/InkCLI.d.ts.map +1 -1
  21. package/lib/Cli/InkCLI.js +0 -5
  22. package/lib/Cli/InkCLI.js.map +1 -1
  23. package/lib/Cli/index.d.ts +0 -1
  24. package/lib/Cli/index.d.ts.map +1 -1
  25. package/lib/Cli/index.js +4 -1
  26. package/lib/Cli/index.js.map +1 -1
  27. package/lib/Cloudflare/ApiToken/AccountApiToken.d.ts +58 -0
  28. package/lib/Cloudflare/ApiToken/AccountApiToken.d.ts.map +1 -0
  29. package/lib/Cloudflare/ApiToken/AccountApiToken.js +137 -0
  30. package/lib/Cloudflare/ApiToken/AccountApiToken.js.map +1 -0
  31. package/lib/Cloudflare/ApiToken/Common.d.ts +91 -0
  32. package/lib/Cloudflare/ApiToken/Common.d.ts.map +1 -0
  33. package/lib/Cloudflare/ApiToken/Common.js +61 -0
  34. package/lib/Cloudflare/ApiToken/Common.js.map +1 -0
  35. package/lib/Cloudflare/ApiToken/PermissionGroups.d.ts +1549 -0
  36. package/lib/Cloudflare/ApiToken/PermissionGroups.d.ts.map +1 -0
  37. package/lib/Cloudflare/ApiToken/PermissionGroups.js +1856 -0
  38. package/lib/Cloudflare/ApiToken/PermissionGroups.js.map +1 -0
  39. package/lib/Cloudflare/ApiToken/UserApiToken.d.ts +49 -0
  40. package/lib/Cloudflare/ApiToken/UserApiToken.d.ts.map +1 -0
  41. package/lib/Cloudflare/ApiToken/UserApiToken.js +113 -0
  42. package/lib/Cloudflare/ApiToken/UserApiToken.js.map +1 -0
  43. package/lib/Cloudflare/ApiToken/index.d.ts +5 -0
  44. package/lib/Cloudflare/ApiToken/index.d.ts.map +1 -0
  45. package/lib/Cloudflare/ApiToken/index.js +5 -0
  46. package/lib/Cloudflare/ApiToken/index.js.map +1 -0
  47. package/lib/Cloudflare/Auth/AuthProvider.js +2 -2
  48. package/lib/Cloudflare/Auth/AuthProvider.js.map +1 -1
  49. package/lib/Cloudflare/Providers.d.ts.map +1 -1
  50. package/lib/Cloudflare/Providers.js +4 -1
  51. package/lib/Cloudflare/Providers.js.map +1 -1
  52. package/lib/Cloudflare/StateStore/Api.d.ts +7 -8
  53. package/lib/Cloudflare/StateStore/Api.d.ts.map +1 -1
  54. package/lib/Cloudflare/StateStore/Api.js +6 -4
  55. package/lib/Cloudflare/StateStore/Api.js.map +1 -1
  56. package/lib/Cloudflare/StateStore/State.d.ts +1 -1
  57. package/lib/Cloudflare/StateStore/State.d.ts.map +1 -1
  58. package/lib/Cloudflare/StateStore/Store.d.ts +2 -2
  59. package/lib/Cloudflare/StateStore/Store.d.ts.map +1 -1
  60. package/lib/Cloudflare/StateStore/Store.js +6 -4
  61. package/lib/Cloudflare/StateStore/Store.js.map +1 -1
  62. package/lib/Cloudflare/StateStore/Token.d.ts +6 -4
  63. package/lib/Cloudflare/StateStore/Token.d.ts.map +1 -1
  64. package/lib/Cloudflare/StateStore/Token.js +8 -4
  65. package/lib/Cloudflare/StateStore/Token.js.map +1 -1
  66. package/lib/Cloudflare/index.d.ts +1 -0
  67. package/lib/Cloudflare/index.d.ts.map +1 -1
  68. package/lib/Cloudflare/index.js +1 -0
  69. package/lib/Cloudflare/index.js.map +1 -1
  70. package/lib/Deploy.d.ts +1 -1
  71. package/lib/Deploy.d.ts.map +1 -1
  72. package/lib/Destroy.d.ts +1 -1
  73. package/lib/Destroy.d.ts.map +1 -1
  74. package/lib/GitHub/Providers.d.ts +3 -0
  75. package/lib/GitHub/Providers.d.ts.map +1 -0
  76. package/lib/GitHub/Providers.js +5 -0
  77. package/lib/GitHub/Providers.js.map +1 -0
  78. package/lib/GitHub/index.d.ts +1 -0
  79. package/lib/GitHub/index.d.ts.map +1 -1
  80. package/lib/GitHub/index.js +1 -0
  81. package/lib/GitHub/index.js.map +1 -1
  82. package/lib/Output.d.ts.map +1 -1
  83. package/lib/Output.js +4 -0
  84. package/lib/Output.js.map +1 -1
  85. package/lib/Plan.d.ts.map +1 -1
  86. package/lib/Plan.js +4 -0
  87. package/lib/Plan.js.map +1 -1
  88. package/lib/Stack.d.ts +5 -4
  89. package/lib/Stack.d.ts.map +1 -1
  90. package/lib/Stack.js +27 -8
  91. package/lib/Stack.js.map +1 -1
  92. package/lib/State/HttpStateStore.js +1 -1
  93. package/lib/State/HttpStateStore.js.map +1 -1
  94. package/lib/Test/Bun.d.ts +2 -2
  95. package/lib/Test/Bun.d.ts.map +1 -1
  96. package/lib/Test/Bun.js +2 -4
  97. package/lib/Test/Bun.js.map +1 -1
  98. package/lib/Test/Vitest.d.ts +1 -1
  99. package/lib/Test/Vitest.d.ts.map +1 -1
  100. package/lib/Test/Vitest.js +11 -7
  101. package/lib/Test/Vitest.js.map +1 -1
  102. package/lib/cli/index.d.ts +2 -6
  103. package/lib/cli/index.d.ts.map +1 -1
  104. package/lib/cli/index.js +2 -43050
  105. package/lib/cli/index.js.map +1 -1
  106. package/package.json +5 -5
  107. package/src/Cli/InkCLI.tsx +0 -10
  108. package/src/Cli/index.ts +4 -1
  109. package/src/Cloudflare/ApiToken/AccountApiToken.ts +197 -0
  110. package/src/Cloudflare/ApiToken/Common.ts +148 -0
  111. package/src/Cloudflare/ApiToken/PermissionGroups.ts +1910 -0
  112. package/src/Cloudflare/ApiToken/UserApiToken.ts +168 -0
  113. package/src/Cloudflare/ApiToken/index.ts +4 -0
  114. package/src/Cloudflare/Auth/AuthProvider.ts +2 -2
  115. package/src/Cloudflare/Providers.ts +5 -0
  116. package/src/Cloudflare/StateStore/Api.ts +6 -4
  117. package/src/Cloudflare/StateStore/Store.ts +6 -4
  118. package/src/Cloudflare/StateStore/Token.ts +10 -4
  119. package/src/Cloudflare/index.ts +1 -0
  120. package/src/GitHub/Providers.ts +6 -0
  121. package/src/GitHub/index.ts +1 -0
  122. package/src/Output.ts +3 -0
  123. package/src/Plan.ts +3 -0
  124. package/src/Stack.ts +33 -7
  125. package/src/State/HttpStateStore.ts +1 -0
  126. package/src/Test/Bun.ts +2 -2
  127. package/src/Test/Vitest.ts +11 -7
@@ -0,0 +1,168 @@
1
+ import * as user from "@distilled.cloud/cloudflare/user";
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 {
10
+ buildConditionPayload,
11
+ conditionFingerprint,
12
+ policyFingerprint,
13
+ resolvePolicies,
14
+ type BaseApiTokenProps,
15
+ } from "./Common.ts";
16
+
17
+ export type UserApiTokenProps = BaseApiTokenProps;
18
+
19
+ export type UserApiToken = Resource<
20
+ "Cloudflare.UserApiToken",
21
+ UserApiTokenProps,
22
+ {
23
+ tokenId: string;
24
+ name: string;
25
+ status: "active" | "disabled" | "expired";
26
+ /**
27
+ * The plaintext token value. Cloudflare returns this only once, on
28
+ * creation, so we persist it here for downstream consumers.
29
+ */
30
+ value: Redacted.Redacted<string>;
31
+ },
32
+ never,
33
+ Providers
34
+ >;
35
+
36
+ /**
37
+ * A Cloudflare user-owned API token (`POST /user/tokens`).
38
+ *
39
+ * User-owned tokens are tied to the authenticated user's identity. They can
40
+ * be created by any authenticated user (including OAuth-derived sessions
41
+ * from `alchemy login`) without needing the account-level
42
+ * `API Tokens > Write` permission, but they are also revoked if the user
43
+ * leaves the account.
44
+ *
45
+ * For CI tokens, prefer {@link AccountApiToken} so the token survives
46
+ * personnel changes.
47
+ *
48
+ * Policy `resources` are passed through verbatim — no `accountId` rewriting
49
+ * is performed because user tokens aren't bound to a single account.
50
+ *
51
+ * @section Creating a Token
52
+ * @example A token bound to the authenticated user
53
+ * ```typescript
54
+ * const token = yield* Cloudflare.UserApiToken("personal-token", {
55
+ * name: "my-personal-token",
56
+ * policies: [
57
+ * {
58
+ * effect: "allow",
59
+ * permissionGroups: ["Workers Scripts Read"],
60
+ * resources: { [`com.cloudflare.api.account.${accountId}`]: "*" },
61
+ * },
62
+ * ],
63
+ * });
64
+ * ```
65
+ */
66
+ export const UserApiToken = Resource<UserApiToken>("Cloudflare.UserApiToken");
67
+
68
+ type UserApiTokenAttributes = UserApiToken["Attributes"];
69
+
70
+ const resolveName = (id: string, name: string | undefined) =>
71
+ Effect.gen(function* () {
72
+ return name ?? (yield* createPhysicalName({ id }));
73
+ });
74
+
75
+ export const UserApiTokenProvider = () =>
76
+ Provider.effect(
77
+ UserApiToken,
78
+ Effect.gen(function* () {
79
+ const createToken = yield* user.createToken;
80
+ const updateToken = yield* user.updateToken;
81
+ const deleteToken = yield* user.deleteToken;
82
+ const getToken = yield* user.getToken;
83
+
84
+ const buildAttributes = (
85
+ tokenData: {
86
+ id?: string | null;
87
+ name?: string | null;
88
+ status?: "active" | "disabled" | "expired" | null;
89
+ },
90
+ value: Redacted.Redacted<string>,
91
+ ): UserApiTokenAttributes => ({
92
+ tokenId: tokenData.id ?? "",
93
+ name: tokenData.name ?? "",
94
+ status: tokenData.status ?? "active",
95
+ value,
96
+ });
97
+
98
+ return {
99
+ stables: ["tokenId"],
100
+ diff: Effect.fn(function* ({ id, olds, news, output }) {
101
+ if (!isResolved(news)) return undefined;
102
+ const oldName = output?.name ?? (yield* resolveName(id, olds?.name));
103
+ const newName = yield* resolveName(id, news.name);
104
+ const oldPolicyFp = policyFingerprint(
105
+ resolvePolicies(olds?.policies ?? [], undefined),
106
+ );
107
+ const newPolicyFp = policyFingerprint(
108
+ resolvePolicies(news.policies, undefined),
109
+ );
110
+ const oldCondFp = conditionFingerprint(olds?.condition);
111
+ const newCondFp = conditionFingerprint(news.condition);
112
+ if (
113
+ oldName !== newName ||
114
+ oldPolicyFp !== newPolicyFp ||
115
+ oldCondFp !== newCondFp ||
116
+ (olds?.expiresOn ?? undefined) !== (news.expiresOn ?? undefined) ||
117
+ (olds?.notBefore ?? undefined) !== (news.notBefore ?? undefined)
118
+ ) {
119
+ return { action: "update" } as const;
120
+ }
121
+ }),
122
+ create: Effect.fn(function* ({ id, news }) {
123
+ const name = yield* resolveName(id, news.name);
124
+ const policies = resolvePolicies(news.policies, undefined);
125
+ const result = yield* createToken({
126
+ name,
127
+ policies,
128
+ condition: buildConditionPayload(news.condition),
129
+ expiresOn: news.expiresOn,
130
+ notBefore: news.notBefore,
131
+ });
132
+ if (!result.value) {
133
+ return yield* Effect.die(
134
+ `Cloudflare did not return a value for token "${name}".`,
135
+ );
136
+ }
137
+ return buildAttributes(result, Redacted.make(result.value));
138
+ }),
139
+ update: Effect.fn(function* ({ id, news, output }) {
140
+ const name = yield* resolveName(id, news.name);
141
+ const policies = resolvePolicies(news.policies, undefined);
142
+ const result = yield* updateToken({
143
+ tokenId: output.tokenId,
144
+ name,
145
+ policies,
146
+ condition: buildConditionPayload(news.condition),
147
+ expiresOn: news.expiresOn,
148
+ notBefore: news.notBefore,
149
+ });
150
+ // Cloudflare doesn't return the value on update; preserve the
151
+ // value captured at creation.
152
+ return buildAttributes(result, output.value);
153
+ }),
154
+ delete: Effect.fn(function* ({ output }) {
155
+ yield* deleteToken({ tokenId: output.tokenId }).pipe(
156
+ Effect.catchTag("TokenNotFound", () => Effect.void),
157
+ );
158
+ }),
159
+ read: Effect.fn(function* ({ output }) {
160
+ if (!output?.tokenId) return undefined;
161
+ return yield* getToken({ tokenId: output.tokenId }).pipe(
162
+ Effect.map((token) => buildAttributes(token, output.value)),
163
+ Effect.catchTag("TokenNotFound", () => Effect.succeed(undefined)),
164
+ );
165
+ }),
166
+ };
167
+ }),
168
+ );
@@ -0,0 +1,4 @@
1
+ export * from "./AccountApiToken.ts";
2
+ export * from "./Common.ts";
3
+ export * from "./PermissionGroups.ts";
4
+ export * from "./UserApiToken.ts";
@@ -46,8 +46,8 @@ const options: Array<{
46
46
  },
47
47
  {
48
48
  value: "stored",
49
- label: "Stored",
50
- hint: "stored in ~/.alchemy/credentials",
49
+ label: "API Token or API Key",
50
+ hint: "enter credentials interactively, stored in ~/.alchemy/credentials",
51
51
  },
52
52
  ];
53
53
 
@@ -3,6 +3,7 @@ import { Command } from "../Build/Command.ts";
3
3
  import * as Build from "../Build/index.ts";
4
4
  import * as Provider from "../Provider.ts";
5
5
  import { Random, RandomProvider } from "../Random.ts";
6
+ import * as ApiToken from "./ApiToken/index.ts";
6
7
  import { CloudflareAuth } from "./Auth/AuthProvider.ts";
7
8
  import * as CloudflareEnvironment from "./CloudflareEnvironment.ts";
8
9
  import * as Containers from "./Container/index.ts";
@@ -30,6 +31,8 @@ export const providers = () =>
30
31
  Layer.effect(
31
32
  Providers,
32
33
  Provider.collection([
34
+ ApiToken.AccountApiToken,
35
+ ApiToken.UserApiToken,
33
36
  Command,
34
37
  Containers.Container,
35
38
  D1.D1ConnectionPolicy,
@@ -53,6 +56,8 @@ export const providers = () =>
53
56
  ).pipe(
54
57
  Layer.provide(
55
58
  Layer.mergeAll(
59
+ ApiToken.AccountApiTokenProvider(),
60
+ ApiToken.UserApiTokenProvider(),
56
61
  Containers.ContainerProvider(),
57
62
  D1.D1ConnectionPolicyLive,
58
63
  D1.DatabaseProvider(),
@@ -1,4 +1,3 @@
1
- import * as Cloudflare from "alchemy/Cloudflare";
2
1
  import {
3
2
  BearerTokenValidator,
4
3
  StateApi,
@@ -13,12 +12,15 @@ import * as HttpRouter from "effect/unstable/http/HttpRouter";
13
12
  import * as HttpApiBuilder from "effect/unstable/httpapi/HttpApiBuilder";
14
13
  import * as HttpApiError from "effect/unstable/httpapi/HttpApiError";
15
14
  import crypto from "node:crypto";
15
+ import { SecretBindingLive } from "../SecretsStore/SecretBinding.ts";
16
+ import * as Secret from "../SecretsStore/Secret.ts";
17
+ import { Worker } from "../Workers/Worker.ts";
16
18
  import Store from "./Store.ts";
17
19
  import { AuthToken } from "./Token.ts";
18
20
 
19
21
  export const STATE_STORE_SCRIPT_NAME = "alchemy-state-store" as const;
20
22
 
21
- export default Cloudflare.Worker(
23
+ export default Worker(
22
24
  "Api",
23
25
  {
24
26
  name: STATE_STORE_SCRIPT_NAME,
@@ -30,7 +32,7 @@ export default Cloudflare.Worker(
30
32
  },
31
33
  },
32
34
  Effect.gen(function* () {
33
- const secret = yield* Cloudflare.Secret.bind(AuthToken);
35
+ const secret = yield* Secret.Secret.bind(AuthToken);
34
36
  const store = yield* Store;
35
37
 
36
38
  const bearerTokenValidator = Layer.effect(
@@ -126,7 +128,7 @@ export default Cloudflare.Worker(
126
128
  HttpRouter.toHttpEffect,
127
129
  ),
128
130
  };
129
- }).pipe(Effect.provide(Layer.mergeAll(Cloudflare.SecretBindingLive))),
131
+ }).pipe(Effect.provide(Layer.mergeAll(SecretBindingLive))),
130
132
  );
131
133
 
132
134
  /**
@@ -1,22 +1,24 @@
1
- import * as Cloudflare from "alchemy/Cloudflare";
2
1
  import type { ReplacedResourceState, ResourceState } from "alchemy/State";
3
2
  import { encodeState } from "alchemy/State";
4
3
  import * as Effect from "effect/Effect";
5
4
  import { pipe } from "effect/Function";
5
+ import * as Secret from "../SecretsStore/Secret.ts";
6
+ import { DurableObjectNamespace } from "../Workers/DurableObjectNamespace.ts";
7
+ import { DurableObjectState } from "../Workers/DurableObjectState.ts";
6
8
  import { EncryptionKey } from "./Token.ts";
7
9
 
8
- export default class Store extends Cloudflare.DurableObjectNamespace<Store>()(
10
+ export default class Store extends DurableObjectNamespace<Store>()(
9
11
  "Store",
10
12
  Effect.gen(function* () {
11
13
  // Outer (class-level) phase — resolve the binding factory once.
12
14
  // The actual secret read happens inside each DO instance below,
13
15
  // since `SecretClient.get()` needs the per-instance worker env.
14
- const encryptionSecret = yield* Cloudflare.Secret.bind(EncryptionKey);
16
+ const encryptionSecret = yield* Secret.Secret.bind(EncryptionKey);
15
17
 
16
18
  return Effect.gen(function* () {
17
19
  // Inner (per-instance) phase — set up storage and the AES key.
18
20
  // The key is imported once per DO boot and reused thereafter.
19
- const doState = yield* Cloudflare.DurableObjectState;
21
+ const doState = yield* DurableObjectState;
20
22
  const storage = doState.storage;
21
23
 
22
24
  const keyHex = yield* encryptionSecret.get().pipe(Effect.orDie);
@@ -1,13 +1,14 @@
1
1
  import { Random } from "alchemy";
2
- import * as Cloudflare from "alchemy/Cloudflare";
3
2
  import * as Effect from "effect/Effect";
3
+ import * as Secret from "../SecretsStore/Secret.ts";
4
+ import { SecretsStore } from "../SecretsStore/SecretsStore.ts";
4
5
 
5
6
  /**
6
7
  * The account-wide Secrets Store that backs every secret used by the
7
8
  * state store worker. `SecretsStore` adopts the single store that
8
9
  * already exists on the account, or creates one if none exists.
9
10
  */
10
- export const Store = Cloudflare.SecretsStore("StateStoreSecrets");
11
+ export const Store = SecretsStore("StateStoreSecrets");
11
12
 
12
13
  /**
13
14
  * The randomly generated bearer token value. Generated once on create
@@ -30,7 +31,8 @@ export const AuthTokenSecretName = "AlchemyStateStoreToken" as const;
30
31
  export const AuthToken = Effect.gen(function* () {
31
32
  const store = yield* Store;
32
33
  const random = yield* TokenValue;
33
- return yield* Cloudflare.Secret(AuthTokenSecretName, {
34
+ return yield* Secret.Secret(AuthTokenSecretName, {
35
+ name: AuthTokenSecretName,
34
36
  store,
35
37
  value: random.text,
36
38
  });
@@ -46,6 +48,9 @@ export const EncryptionKeyValue = Random("StateStoreEncryptionKeyValue", {
46
48
  bytes: 32,
47
49
  });
48
50
 
51
+ export const EncryptionKeySecretName =
52
+ "AlchemyStateStoreEncryptionKey" as const;
53
+
49
54
  /**
50
55
  * The encryption key secret. The raw hex-encoded bytes live inside
51
56
  * Cloudflare's Secrets Store; the Durable Object binds to it at
@@ -55,7 +60,8 @@ export const EncryptionKeyValue = Random("StateStoreEncryptionKeyValue", {
55
60
  export const EncryptionKey = Effect.gen(function* () {
56
61
  const store = yield* Store;
57
62
  const random = yield* EncryptionKeyValue;
58
- return yield* Cloudflare.Secret("StateStoreEncryptionKey", {
63
+ return yield* Secret.Secret("StateStoreEncryptionKey", {
64
+ name: EncryptionKeySecretName,
59
65
  store,
60
66
  value: random.text,
61
67
  });
@@ -1,3 +1,4 @@
1
+ export * from "./ApiToken/index.ts";
1
2
  export * from "./CloudflareEnvironment.ts";
2
3
  export * from "./Container/index.ts";
3
4
  export * from "./D1/index.ts";
@@ -0,0 +1,6 @@
1
+ import * as Layer from "effect/Layer";
2
+ import { SecretProvider } from "./Secret.ts";
3
+ import { VariableProvider } from "./Variable.ts";
4
+
5
+ export const providers = () =>
6
+ Layer.mergeAll(SecretProvider(), VariableProvider());
@@ -1,3 +1,4 @@
1
1
  export * from "./Comment.ts";
2
+ export * from "./Providers.ts";
2
3
  export * from "./Secret.ts";
3
4
  export * from "./Variable.ts";
package/src/Output.ts CHANGED
@@ -3,6 +3,7 @@ import type { Yieldable } from "effect/Effect";
3
3
  import * as Effect from "effect/Effect";
4
4
  import { pipe } from "effect/Function";
5
5
  import type { Pipeable } from "effect/Pipeable";
6
+ import * as Redacted from "effect/Redacted";
6
7
  import { SingleShotGen } from "effect/Utils";
7
8
  import { ExecutionContext } from "./ExecutionContext.ts";
8
9
  import { getRefMetadata, isRef, ref as stageRef, type Ref } from "./Ref.ts";
@@ -468,6 +469,8 @@ export const evaluate: <A, Req = never>(
468
469
  }
469
470
  if (Array.isArray(expr)) {
470
471
  return yield* Effect.all(expr.map((item) => evaluate(item, upstream)));
472
+ } else if (Redacted.isRedacted(expr)) {
473
+ return expr;
471
474
  } else if (typeof expr === "object" && expr !== null) {
472
475
  return Object.fromEntries(
473
476
  yield* Effect.all(
package/src/Plan.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as Data from "effect/Data";
2
2
  import * as Effect from "effect/Effect";
3
3
  import * as Option from "effect/Option";
4
+ import * as Redacted from "effect/Redacted";
4
5
  import { asEffect } from ".//Util/types.ts";
5
6
  import {
6
7
  Artifacts,
@@ -271,6 +272,8 @@ export const make = <A>(
271
272
  return input;
272
273
  } else if (Output.isExpr(input)) {
273
274
  return yield* resolveOutput(input);
275
+ } else if (Redacted.isRedacted(input)) {
276
+ return input;
274
277
  } else if (Array.isArray(input)) {
275
278
  return yield* Effect.all(input.map(resolveInput), {
276
279
  concurrency: "unbounded",
package/src/Stack.ts CHANGED
@@ -13,7 +13,7 @@ import type { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSp
13
13
  import { AlchemyContext, AlchemyContextLive } from "./AlchemyContext.ts";
14
14
  import { provideFreshArtifactStore } from "./Artifacts.ts";
15
15
  import { AuthProviders } from "./Auth/AuthProvider.ts";
16
- import { inkCLIAutoApprove } from "./Cli/InkCLI.tsx";
16
+ import { Cli } from "./Cli/Cli.ts";
17
17
  import type { Input, InputProps } from "./Input.ts";
18
18
  import * as Output from "./Output.ts";
19
19
  import { ref } from "./Ref.ts";
@@ -34,7 +34,8 @@ export type StackServices =
34
34
  | AlchemyContext
35
35
  | HttpClient
36
36
  | ChildProcessSpawner
37
- | AuthProviders;
37
+ | AuthProviders
38
+ | Cli;
38
39
 
39
40
  export type StackEffect<A, Err = never, Req = never> = Effect.Effect<
40
41
  A,
@@ -44,6 +45,7 @@ export type StackEffect<A, Err = never, Req = never> = Effect.Effect<
44
45
  | Scope
45
46
  | AuthProviders
46
47
  | AlchemyContext
48
+ | Cli
47
49
  | State
48
50
  | Req
49
51
  >;
@@ -172,8 +174,33 @@ export const make =
172
174
  effect: Effect.Effect<A, Err, Req>,
173
175
  ) =>
174
176
  Effect.scope.pipe(
175
- Effect.flatMap((scope) =>
176
- options.providers.pipe(
177
+ Effect.flatMap((scope) => {
178
+ if (options.state == null) {
179
+ return Effect.die(
180
+ new Error(
181
+ `Stack "${options.name}" is missing a state store. ` +
182
+ `Add a \`state\` layer to the stack options, e.g.:\n` +
183
+ ` Alchemy.Stack("${options.name}", {\n` +
184
+ ` providers: Cloudflare.providers(),\n` +
185
+ ` state: Cloudflare.state(), // <-- required\n` +
186
+ ` }, ...)\n` +
187
+ `See https://alchemy.run/concepts/state-store for available state stores.`,
188
+ ),
189
+ );
190
+ }
191
+ if (options.providers == null) {
192
+ return Effect.die(
193
+ new Error(
194
+ `Stack "${options.name}" is missing a providers layer. ` +
195
+ `Add a \`providers\` layer to the stack options, e.g.:\n` +
196
+ ` Alchemy.Stack("${options.name}", {\n` +
197
+ ` providers: Cloudflare.providers(), // <-- required\n` +
198
+ ` state: Cloudflare.state(),\n` +
199
+ ` }, ...)`,
200
+ ),
201
+ );
202
+ }
203
+ return options.providers.pipe(
177
204
  Layer.provideMerge(options.state),
178
205
  Layer.provideMerge(
179
206
  Layer.effect(
@@ -192,8 +219,8 @@ export const make =
192
219
  ),
193
220
  ),
194
221
  Layer.buildWithScope(scope),
195
- ),
196
- ),
222
+ );
223
+ }),
197
224
  Effect.flatMap((context) =>
198
225
  Effect.all([
199
226
  effect,
@@ -257,7 +284,6 @@ export const evalStack = <A, B, Err, Req>(
257
284
  ),
258
285
  ),
259
286
  Effect.provide(Layer.succeed(Stage, options.stage)),
260
- Effect.provide(inkCLIAutoApprove()),
261
287
  Effect.provide(Layer.provideMerge(alchemy, platform)),
262
288
  Effect.scoped,
263
289
  );
@@ -143,6 +143,7 @@ const retryTransient = <A, Err, Req>(eff: Effect.Effect<A, Err, Req>) =>
143
143
  /** Collapse any client failure into a {@link StateStoreError}. */
144
144
  const mapStateStoreError = <A, E, R>(eff: Effect.Effect<A, E, R>) =>
145
145
  eff.pipe(
146
+ Effect.tapError(Effect.log),
146
147
  retryTransient,
147
148
  Effect.catch((e: E) =>
148
149
  Effect.fail(
package/src/Test/Bun.ts CHANGED
@@ -9,6 +9,7 @@ import type { HookOptions } from "node:test";
9
9
  import { AlchemyContext, AlchemyContextLive } from "../AlchemyContext.ts";
10
10
  import { provideFreshArtifactStore } from "../Artifacts.ts";
11
11
  import { AuthProviders } from "../Auth/AuthProvider.ts";
12
+ import { inkCLI } from "../Cli/InkCLI.tsx";
12
13
  import { deploy as _deploy } from "../Deploy.ts";
13
14
  import { destroy as _destroy } from "../Destroy.ts";
14
15
  import {
@@ -28,8 +29,7 @@ const platform = Layer.mergeAll(PlatformServices, FetchHttpClient.layer);
28
29
 
29
30
  // override alchemy state store, CLI/reporting, state, and dotAlchemy
30
31
  const alchemy = Layer.mergeAll(
31
- // CLI.inkCLI(),
32
- // optional
32
+ inkCLI(),
33
33
  Logger.layer([Logger.consolePretty()]),
34
34
  AlchemyContextLive,
35
35
  );
@@ -359,13 +359,17 @@ export namespace test {
359
359
  ): Effect.Effect<Input.Resolve<A>, Err, Req | Stack.Stack> =>
360
360
  Stack.Stack.use((stack) =>
361
361
  effect.pipe(
362
- // Effect.tap(Effect.logInfo),
363
- // @ts-expect-error
364
- Stack.make(stack.name, Layer.effectContext(Effect.context<never>()), {
365
- ...stack,
366
- resources: {},
367
- bindings: {},
368
- output: {},
362
+ // @ts-expect-error - test harness reuses ambient runtime context
363
+ Stack.make({
364
+ name: stack.name,
365
+ providers: Layer.effectContext(Effect.context<never>()),
366
+ state: State.localState(),
367
+ stack: {
368
+ ...stack,
369
+ resources: {},
370
+ bindings: {},
371
+ output: {},
372
+ },
369
373
  }),
370
374
  Effect.flatMap(Plan.make),
371
375
  Effect.tap((plan) => Effect.logInfo(formatPlan(plan))),