alchemy 2.0.0-beta.15 → 2.0.0-beta.16

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 (85) hide show
  1. package/bin/alchemy.js +1585 -707
  2. package/bin/alchemy.js.map +1 -1
  3. package/bin/alchemy.ts +2 -0
  4. package/bin/commands/login.ts +6 -3
  5. package/bin/commands/profile.ts +86 -0
  6. package/lib/Cloudflare/ApiToken/AccountApiToken.d.ts +2 -3
  7. package/lib/Cloudflare/ApiToken/AccountApiToken.d.ts.map +1 -1
  8. package/lib/Cloudflare/ApiToken/AccountApiToken.js +12 -8
  9. package/lib/Cloudflare/ApiToken/AccountApiToken.js.map +1 -1
  10. package/lib/Cloudflare/ApiToken/Common.d.ts +6 -1
  11. package/lib/Cloudflare/ApiToken/Common.d.ts.map +1 -1
  12. package/lib/Cloudflare/ApiToken/Common.js.map +1 -1
  13. package/lib/Cloudflare/ApiToken/UserApiToken.d.ts +2 -3
  14. package/lib/Cloudflare/ApiToken/UserApiToken.d.ts.map +1 -1
  15. package/lib/Cloudflare/ApiToken/UserApiToken.js +4 -4
  16. package/lib/Cloudflare/ApiToken/UserApiToken.js.map +1 -1
  17. package/lib/Cloudflare/Artifacts/Artifacts.d.ts +101 -0
  18. package/lib/Cloudflare/Artifacts/Artifacts.d.ts.map +1 -0
  19. package/lib/Cloudflare/Artifacts/Artifacts.js +92 -0
  20. package/lib/Cloudflare/Artifacts/Artifacts.js.map +1 -0
  21. package/lib/Cloudflare/Artifacts/ArtifactsBinding.d.ts +83 -0
  22. package/lib/Cloudflare/Artifacts/ArtifactsBinding.d.ts.map +1 -0
  23. package/lib/Cloudflare/Artifacts/ArtifactsBinding.js +65 -0
  24. package/lib/Cloudflare/Artifacts/ArtifactsBinding.js.map +1 -0
  25. package/lib/Cloudflare/Artifacts/index.d.ts +3 -0
  26. package/lib/Cloudflare/Artifacts/index.d.ts.map +1 -0
  27. package/lib/Cloudflare/Artifacts/index.js +3 -0
  28. package/lib/Cloudflare/Artifacts/index.js.map +1 -0
  29. package/lib/Cloudflare/Container/ContainerBinding.d.ts +1 -1
  30. package/lib/Cloudflare/Providers.d.ts.map +1 -1
  31. package/lib/Cloudflare/Providers.js +3 -1
  32. package/lib/Cloudflare/Providers.js.map +1 -1
  33. package/lib/Cloudflare/Workers/InferEnv.d.ts +1 -1
  34. package/lib/Cloudflare/Workers/InferEnv.d.ts.map +1 -1
  35. package/lib/Cloudflare/Workers/InferEnv.js +0 -1
  36. package/lib/Cloudflare/Workers/InferEnv.js.map +1 -1
  37. package/lib/Cloudflare/Workers/Worker.d.ts +2 -1
  38. package/lib/Cloudflare/Workers/Worker.d.ts.map +1 -1
  39. package/lib/Cloudflare/Workers/Worker.js +25 -18
  40. package/lib/Cloudflare/Workers/Worker.js.map +1 -1
  41. package/lib/Cloudflare/index.d.ts +1 -0
  42. package/lib/Cloudflare/index.d.ts.map +1 -1
  43. package/lib/Cloudflare/index.js +1 -0
  44. package/lib/Cloudflare/index.js.map +1 -1
  45. package/lib/GitHub/AuthProvider.d.ts +37 -0
  46. package/lib/GitHub/AuthProvider.d.ts.map +1 -0
  47. package/lib/GitHub/AuthProvider.js +154 -0
  48. package/lib/GitHub/AuthProvider.js.map +1 -0
  49. package/lib/GitHub/Credentials.d.ts +29 -0
  50. package/lib/GitHub/Credentials.d.ts.map +1 -0
  51. package/lib/GitHub/Credentials.js +54 -0
  52. package/lib/GitHub/Credentials.js.map +1 -0
  53. package/lib/GitHub/Providers.d.ts +12 -1
  54. package/lib/GitHub/Providers.d.ts.map +1 -1
  55. package/lib/GitHub/Providers.js +13 -3
  56. package/lib/GitHub/Providers.js.map +1 -1
  57. package/lib/GitHub/Secret.d.ts +8 -10
  58. package/lib/GitHub/Secret.d.ts.map +1 -1
  59. package/lib/GitHub/Secret.js +16 -14
  60. package/lib/GitHub/Secret.js.map +1 -1
  61. package/lib/GitHub/Variable.d.ts +8 -10
  62. package/lib/GitHub/Variable.d.ts.map +1 -1
  63. package/lib/GitHub/Variable.js +12 -13
  64. package/lib/GitHub/Variable.js.map +1 -1
  65. package/lib/GitHub/index.d.ts +2 -0
  66. package/lib/GitHub/index.d.ts.map +1 -1
  67. package/lib/GitHub/index.js +2 -0
  68. package/lib/GitHub/index.js.map +1 -1
  69. package/package.json +4 -4
  70. package/src/Cloudflare/ApiToken/AccountApiToken.ts +21 -11
  71. package/src/Cloudflare/ApiToken/Common.ts +6 -1
  72. package/src/Cloudflare/ApiToken/UserApiToken.ts +6 -8
  73. package/src/Cloudflare/Artifacts/Artifacts.ts +139 -0
  74. package/src/Cloudflare/Artifacts/ArtifactsBinding.ts +188 -0
  75. package/src/Cloudflare/Artifacts/index.ts +2 -0
  76. package/src/Cloudflare/Providers.ts +3 -0
  77. package/src/Cloudflare/Workers/InferEnv.ts +5 -4
  78. package/src/Cloudflare/Workers/Worker.ts +12 -1
  79. package/src/Cloudflare/index.ts +1 -0
  80. package/src/GitHub/AuthProvider.ts +309 -0
  81. package/src/GitHub/Credentials.ts +99 -0
  82. package/src/GitHub/Providers.ts +23 -3
  83. package/src/GitHub/Secret.ts +22 -24
  84. package/src/GitHub/Variable.ts +16 -23
  85. package/src/GitHub/index.ts +2 -0
@@ -1,6 +1,26 @@
1
1
  import * as Layer from "effect/Layer";
2
- import { SecretProvider } from "./Secret.ts";
3
- import { VariableProvider } from "./Variable.ts";
2
+ import * as Provider from "../Provider.ts";
3
+ import { GitHubAuth } from "./AuthProvider.ts";
4
+ import * as Credentials from "./Credentials.ts";
5
+ import { Secret, SecretProvider } from "./Secret.ts";
6
+ import { Variable, VariableProvider } from "./Variable.ts";
4
7
 
8
+ export { GitHubCredentials } from "./Credentials.ts";
9
+
10
+ export class Providers extends Provider.ProviderCollection<Providers>()(
11
+ "GitHub",
12
+ ) {}
13
+
14
+ export type ProviderRequirements = Layer.Services<ReturnType<typeof providers>>;
15
+
16
+ /**
17
+ * GitHub providers (Secret, Variable) plus the GitHub AuthProvider that
18
+ * `alchemy login` discovers.
19
+ */
5
20
  export const providers = () =>
6
- Layer.mergeAll(SecretProvider(), VariableProvider());
21
+ Layer.effect(Providers, Provider.collection([Secret, Variable])).pipe(
22
+ Layer.provide(Layer.mergeAll(SecretProvider(), VariableProvider())),
23
+ Layer.provideMerge(Credentials.fromAuthProvider()),
24
+ Layer.provideMerge(GitHubAuth),
25
+ Layer.orDie,
26
+ );
@@ -1,8 +1,10 @@
1
- import { Octokit } from "@octokit/rest";
1
+ import type { Octokit } from "@octokit/rest";
2
2
  import * as Effect from "effect/Effect";
3
3
  import * as Redacted from "effect/Redacted";
4
4
  import * as Provider from "../Provider.ts";
5
5
  import { Resource } from "../Resource.ts";
6
+ import { GitHubCredentials } from "./Credentials.ts";
7
+ import type { Providers } from "./Providers.ts";
6
8
 
7
9
  export interface SecretProps {
8
10
  /**
@@ -31,12 +33,6 @@ export interface SecretProps {
31
33
  * GitHub Actions environment instead of the whole repository.
32
34
  */
33
35
  environment?: string;
34
-
35
- /**
36
- * GitHub API token. If not provided, falls back to
37
- * `GITHUB_ACCESS_TOKEN` or `GITHUB_TOKEN` environment variables.
38
- */
39
- token?: string;
40
36
  }
41
37
 
42
38
  export interface Secret extends Resource<
@@ -47,7 +43,9 @@ export interface Secret extends Resource<
47
43
  * ISO-8601 timestamp of the last update.
48
44
  */
49
45
  updatedAt: string;
50
- }
46
+ },
47
+ never,
48
+ Providers
51
49
  > {}
52
50
 
53
51
  /**
@@ -58,9 +56,10 @@ export interface Secret extends Resource<
58
56
  * key via `libsodium` before being stored. The resource is idempotent —
59
57
  * calling it with the same name will update the secret value in place.
60
58
  *
61
- * Authentication is resolved in order: explicit `token` prop,
62
- * `GITHUB_ACCESS_TOKEN` env var, `GITHUB_TOKEN` env var. The token needs
63
- * `repo` scope for private repositories or `public_repo` for public ones.
59
+ * Authentication is resolved via the `GitHubCredentials` service supplied
60
+ * by `GitHub.providers()` (which uses the Alchemy AuthProvider — env,
61
+ * stored PAT, `gh` CLI, or OAuth). The token needs `repo` scope for
62
+ * private repositories or `public_repo` for public ones.
64
63
  *
65
64
  * @section Repository Secrets
66
65
  * Store secrets accessible to all GitHub Actions workflows in the
@@ -130,21 +129,20 @@ export interface Secret extends Resource<
130
129
  */
131
130
  export const Secret = Resource<Secret>("GitHub.Secret");
132
131
 
133
- function resolveToken(props: SecretProps): string | undefined {
134
- return (
135
- props.token ?? process.env.GITHUB_ACCESS_TOKEN ?? process.env.GITHUB_TOKEN
136
- );
137
- }
138
-
139
- function createClient(props: SecretProps): Octokit {
140
- return new Octokit({ auth: resolveToken(props) });
141
- }
132
+ const getOctokit = Effect.gen(function* () {
133
+ const creds = yield* GitHubCredentials;
134
+ return creds.octokit();
135
+ });
142
136
 
143
137
  async function encryptValue(
144
138
  plaintext: string,
145
139
  publicKey: string,
146
140
  ): Promise<string> {
147
- const sodium = await import("libsodium-wrappers");
141
+ const mod = await import("libsodium-wrappers");
142
+ // Bun/ESM interop: the actual sodium API lives on `.default` when the
143
+ // CJS module is wrapped, but is the module itself under other loaders.
144
+ const sodium: typeof import("libsodium-wrappers") =
145
+ (mod as any).default ?? mod;
148
146
  await sodium.ready;
149
147
  const binKey = sodium.from_base64(publicKey, sodium.base64_variants.ORIGINAL);
150
148
  const binMessage = sodium.from_string(plaintext);
@@ -155,13 +153,13 @@ async function encryptValue(
155
153
  export const SecretProvider = () =>
156
154
  Provider.succeed(Secret, {
157
155
  create: Effect.fn(function* ({ news }) {
158
- const octokit = createClient(news);
156
+ const octokit = yield* getOctokit;
159
157
  yield* upsertSecret(octokit, news);
160
158
  return { updatedAt: new Date().toISOString() };
161
159
  }),
162
160
 
163
161
  update: Effect.fn(function* ({ news, olds }) {
164
- const octokit = createClient(news);
162
+ const octokit = yield* getOctokit;
165
163
 
166
164
  const wasEnv = !!olds.environment;
167
165
  const isEnv = !!news.environment;
@@ -174,7 +172,7 @@ export const SecretProvider = () =>
174
172
  }),
175
173
 
176
174
  delete: Effect.fn(function* ({ olds }) {
177
- const octokit = createClient(olds);
175
+ const octokit = yield* getOctokit;
178
176
  yield* deleteSecret(octokit, olds);
179
177
  }),
180
178
  });
@@ -1,7 +1,8 @@
1
- import { Octokit } from "@octokit/rest";
2
1
  import * as Effect from "effect/Effect";
3
2
  import * as Provider from "../Provider.ts";
4
3
  import { Resource } from "../Resource.ts";
4
+ import { GitHubCredentials } from "./Credentials.ts";
5
+ import type { Providers } from "./Providers.ts";
5
6
 
6
7
  export interface VariableProps {
7
8
  /**
@@ -23,12 +24,6 @@ export interface VariableProps {
23
24
  * Variable value.
24
25
  */
25
26
  value: string;
26
-
27
- /**
28
- * GitHub API token. If not provided, falls back to
29
- * `GITHUB_ACCESS_TOKEN` or `GITHUB_TOKEN` environment variables.
30
- */
31
- token?: string;
32
27
  }
33
28
 
34
29
  export interface Variable extends Resource<
@@ -39,7 +34,9 @@ export interface Variable extends Resource<
39
34
  * ISO-8601 timestamp of the last update.
40
35
  */
41
36
  updatedAt: string;
42
- }
37
+ },
38
+ never,
39
+ Providers
43
40
  > {}
44
41
 
45
42
  /**
@@ -51,9 +48,10 @@ export interface Variable extends Resource<
51
48
  * labels, or feature flags. For sensitive values, use `GitHub.Secret`
52
49
  * instead.
53
50
  *
54
- * Authentication is resolved in order: explicit `token` prop,
55
- * `GITHUB_ACCESS_TOKEN` env var, `GITHUB_TOKEN` env var. The token needs
56
- * `repo` scope for private repositories or `public_repo` for public ones.
51
+ * Authentication is resolved via the `GitHubCredentials` service supplied
52
+ * by `GitHub.providers()` (which uses the Alchemy AuthProvider — env,
53
+ * stored PAT, `gh` CLI, or OAuth). The token needs `repo` scope for
54
+ * private repositories or `public_repo` for public ones.
57
55
  *
58
56
  * @section Repository Variables
59
57
  * Store variables accessible to all GitHub Actions workflows in the
@@ -104,20 +102,15 @@ export interface Variable extends Resource<
104
102
  */
105
103
  export const Variable = Resource<Variable>("GitHub.Variable");
106
104
 
107
- function resolveToken(props: VariableProps): string | undefined {
108
- return (
109
- props.token ?? process.env.GITHUB_ACCESS_TOKEN ?? process.env.GITHUB_TOKEN
110
- );
111
- }
112
-
113
- function createClient(props: VariableProps): Octokit {
114
- return new Octokit({ auth: resolveToken(props) });
115
- }
105
+ const getOctokit = Effect.gen(function* () {
106
+ const creds = yield* GitHubCredentials;
107
+ return creds.octokit();
108
+ });
116
109
 
117
110
  export const VariableProvider = () =>
118
111
  Provider.succeed(Variable, {
119
112
  create: Effect.fn(function* ({ news }) {
120
- const octokit = createClient(news);
113
+ const octokit = yield* getOctokit;
121
114
 
122
115
  yield* Effect.tryPromise(() =>
123
116
  octokit.rest.actions.createRepoVariable({
@@ -132,7 +125,7 @@ export const VariableProvider = () =>
132
125
  }),
133
126
 
134
127
  update: Effect.fn(function* ({ news }) {
135
- const octokit = createClient(news);
128
+ const octokit = yield* getOctokit;
136
129
 
137
130
  yield* Effect.tryPromise(() =>
138
131
  octokit.rest.actions.updateRepoVariable({
@@ -147,7 +140,7 @@ export const VariableProvider = () =>
147
140
  }),
148
141
 
149
142
  delete: Effect.fn(function* ({ olds }) {
150
- const octokit = createClient(olds);
143
+ const octokit = yield* getOctokit;
151
144
 
152
145
  yield* Effect.tryPromise(async () => {
153
146
  try {
@@ -1,4 +1,6 @@
1
+ export * as Auth from "./AuthProvider.ts";
1
2
  export * from "./Comment.ts";
3
+ export { GitHubCredentials, fromEnv, fromToken } from "./Credentials.ts";
2
4
  export * from "./Providers.ts";
3
5
  export * from "./Secret.ts";
4
6
  export * from "./Variable.ts";