alchemy 0.29.1 → 0.29.3

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 (41) hide show
  1. package/lib/cloudflare/bindings.d.ts +16 -3
  2. package/lib/cloudflare/bindings.d.ts.map +1 -1
  3. package/lib/cloudflare/bound.d.ts +3 -7
  4. package/lib/cloudflare/bound.d.ts.map +1 -1
  5. package/lib/cloudflare/secret.d.ts +4 -0
  6. package/lib/cloudflare/secret.d.ts.map +1 -1
  7. package/lib/cloudflare/secret.js +46 -7
  8. package/lib/cloudflare/secret.js.map +1 -1
  9. package/lib/cloudflare/secrets-store.d.ts +1 -7
  10. package/lib/cloudflare/secrets-store.d.ts.map +1 -1
  11. package/lib/cloudflare/secrets-store.js +2 -9
  12. package/lib/cloudflare/secrets-store.js.map +1 -1
  13. package/lib/cloudflare/worker-metadata.js +4 -4
  14. package/lib/cloudflare/worker-metadata.js.map +1 -1
  15. package/lib/cloudflare/wrangler.json.js +6 -10
  16. package/lib/cloudflare/wrangler.json.js.map +1 -1
  17. package/lib/destroy.d.ts.map +1 -1
  18. package/lib/destroy.js +2 -2
  19. package/lib/destroy.js.map +1 -1
  20. package/lib/scope.d.ts +5 -0
  21. package/lib/scope.d.ts.map +1 -1
  22. package/lib/scope.js +6 -1
  23. package/lib/scope.js.map +1 -1
  24. package/lib/secret.d.ts +8 -0
  25. package/lib/secret.d.ts.map +1 -1
  26. package/lib/secret.js +4 -2
  27. package/lib/secret.js.map +1 -1
  28. package/lib/serde.d.ts.map +1 -1
  29. package/lib/serde.js +5 -5
  30. package/lib/serde.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/cloudflare/bindings.ts +17 -2
  33. package/src/cloudflare/bound.ts +15 -23
  34. package/src/cloudflare/secret.ts +87 -7
  35. package/src/cloudflare/secrets-store.ts +3 -20
  36. package/src/cloudflare/worker-metadata.ts +4 -4
  37. package/src/cloudflare/wrangler.json.ts +6 -10
  38. package/src/destroy.ts +2 -2
  39. package/src/scope.ts +10 -1
  40. package/src/secret.ts +12 -2
  41. package/src/serde.ts +5 -5
package/src/secret.ts CHANGED
@@ -1,15 +1,23 @@
1
1
  import { alchemy } from "./alchemy.ts";
2
2
 
3
+ declare global {
4
+ var __ALCHEMY_SECRETS__: {
5
+ [name: string]: Secret;
6
+ };
7
+ }
8
+
3
9
  // a global registry of all secrets that we will use when serializing an application
4
10
  const globalSecrets: {
5
11
  [name: string]: Secret;
6
- } = {};
12
+ } = (globalThis.__ALCHEMY_SECRETS__ ??= {});
7
13
 
8
14
  let i = 0;
9
15
  function nextName() {
10
16
  return `alchemy:anonymous-secret-${i++}`;
11
17
  }
12
18
 
19
+ const SecretSymbol = Symbol.for("alchemy::Secret");
20
+
13
21
  /**
14
22
  * Internal wrapper for sensitive values like API keys and credentials.
15
23
  * When stored in alchemy state files, the value is automatically encrypted
@@ -46,6 +54,8 @@ function nextName() {
46
54
  * }
47
55
  */
48
56
  export class Secret {
57
+ [SecretSymbol] = true;
58
+
49
59
  /**
50
60
  * @internal
51
61
  */
@@ -68,7 +78,7 @@ export class Secret {
68
78
  export function isSecret(binding: any): binding is Secret {
69
79
  return (
70
80
  binding instanceof Secret ||
71
- (typeof binding === "object" && binding.type === "secret_text")
81
+ (typeof binding === "object" && binding?.type === "secret")
72
82
  );
73
83
  }
74
84
 
package/src/serde.ts CHANGED
@@ -5,8 +5,8 @@ import {
5
5
  ResourceKind,
6
6
  type Resource,
7
7
  } from "./resource.ts";
8
- import { Scope } from "./scope.ts";
9
- import { Secret } from "./secret.ts";
8
+ import { isScope, Scope } from "./scope.ts";
9
+ import { isSecret, Secret } from "./secret.ts";
10
10
 
11
11
  import type { Type } from "arktype";
12
12
 
@@ -76,7 +76,7 @@ export async function serializeScope(scope: Scope): Promise<SerializedScope> {
76
76
  }
77
77
  map[resource[ResourceFQN]] = await serialize(scope, await resource, {
78
78
  transform: (value) => {
79
- if (value instanceof Secret) {
79
+ if (isSecret(value)) {
80
80
  return {
81
81
  "@secret-env": value.name,
82
82
  };
@@ -111,7 +111,7 @@ export async function serialize(
111
111
 
112
112
  if (Array.isArray(value)) {
113
113
  return Promise.all(value.map((value) => serialize(scope, value, options)));
114
- } else if (value instanceof Secret) {
114
+ } else if (isSecret(value)) {
115
115
  if (!scope.password) {
116
116
  throw new Error(
117
117
  "Cannot serialize secret without password, did you forget to set password when initializing your alchemy app?\n" +
@@ -137,7 +137,7 @@ export async function serialize(
137
137
  return {
138
138
  "@symbol": value.toString(),
139
139
  };
140
- } else if (value instanceof Scope) {
140
+ } else if (isScope(value)) {
141
141
  return {
142
142
  "@scope": null,
143
143
  };