alchemy 0.69.1 → 0.70.1

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 (238) hide show
  1. package/bin/alchemy.js +3883 -3906
  2. package/bin/alchemy.ts +2 -0
  3. package/bin/commands/telemetry.ts +33 -0
  4. package/bin/services/execute-alchemy.ts +7 -0
  5. package/bin/trpc.ts +4 -9
  6. package/lib/alchemy.d.ts +7 -3
  7. package/lib/alchemy.d.ts.map +1 -1
  8. package/lib/alchemy.js +3 -15
  9. package/lib/alchemy.js.map +1 -1
  10. package/lib/apply.js +24 -9
  11. package/lib/apply.js.map +1 -1
  12. package/lib/aws/utils.d.ts +2 -1
  13. package/lib/aws/utils.d.ts.map +1 -1
  14. package/lib/aws/utils.js.map +1 -1
  15. package/lib/clickhouse/api/client.gen.d.ts +13 -0
  16. package/lib/clickhouse/api/client.gen.d.ts.map +1 -0
  17. package/lib/clickhouse/api/client.gen.js +7 -0
  18. package/lib/clickhouse/api/client.gen.js.map +1 -0
  19. package/lib/clickhouse/api/sdk.gen.d.ts +322 -0
  20. package/lib/clickhouse/api/sdk.gen.d.ts.map +1 -0
  21. package/lib/clickhouse/api/sdk.gen.js +683 -0
  22. package/lib/clickhouse/api/sdk.gen.js.map +1 -0
  23. package/lib/clickhouse/api/types.gen.d.ts +5030 -0
  24. package/lib/clickhouse/api/types.gen.d.ts.map +1 -0
  25. package/lib/clickhouse/api/types.gen.js +2 -0
  26. package/lib/clickhouse/api/types.gen.js.map +1 -0
  27. package/lib/clickhouse/api-key.d.ts +29 -0
  28. package/lib/clickhouse/api-key.d.ts.map +1 -0
  29. package/lib/clickhouse/api-key.js +83 -0
  30. package/lib/clickhouse/api-key.js.map +1 -0
  31. package/lib/clickhouse/api.d.ts +36 -0
  32. package/lib/clickhouse/api.d.ts.map +1 -0
  33. package/lib/clickhouse/api.js +48 -0
  34. package/lib/clickhouse/api.js.map +1 -0
  35. package/lib/clickhouse/index.d.ts +4 -0
  36. package/lib/clickhouse/index.d.ts.map +1 -0
  37. package/lib/clickhouse/index.js +4 -0
  38. package/lib/clickhouse/index.js.map +1 -0
  39. package/lib/clickhouse/organization.d.ts +16 -0
  40. package/lib/clickhouse/organization.d.ts.map +1 -0
  41. package/lib/clickhouse/organization.js +21 -0
  42. package/lib/clickhouse/organization.js.map +1 -0
  43. package/lib/clickhouse/service.d.ts +275 -0
  44. package/lib/clickhouse/service.d.ts.map +1 -0
  45. package/lib/clickhouse/service.js +274 -0
  46. package/lib/clickhouse/service.js.map +1 -0
  47. package/lib/cloudflare/account-api-token.d.ts.map +1 -1
  48. package/lib/cloudflare/account-api-token.js +1 -1
  49. package/lib/cloudflare/account-api-token.js.map +1 -1
  50. package/lib/cloudflare/api.d.ts.map +1 -1
  51. package/lib/cloudflare/api.js +2 -0
  52. package/lib/cloudflare/api.js.map +1 -1
  53. package/lib/cloudflare/bun-spa/bun-spa.d.ts +13 -0
  54. package/lib/cloudflare/bun-spa/bun-spa.d.ts.map +1 -0
  55. package/lib/cloudflare/bun-spa/bun-spa.js +95 -0
  56. package/lib/cloudflare/bun-spa/bun-spa.js.map +1 -0
  57. package/lib/cloudflare/compatibility-date.gen.d.ts +1 -1
  58. package/lib/cloudflare/compatibility-date.gen.js +1 -1
  59. package/lib/cloudflare/container.d.ts +11 -1
  60. package/lib/cloudflare/container.d.ts.map +1 -1
  61. package/lib/cloudflare/container.js.map +1 -1
  62. package/lib/cloudflare/index.d.ts +1 -0
  63. package/lib/cloudflare/index.d.ts.map +1 -1
  64. package/lib/cloudflare/index.js +1 -0
  65. package/lib/cloudflare/index.js.map +1 -1
  66. package/lib/cloudflare/miniflare/build-worker-options.d.ts.map +1 -1
  67. package/lib/cloudflare/miniflare/build-worker-options.js +33 -6
  68. package/lib/cloudflare/miniflare/build-worker-options.js.map +1 -1
  69. package/lib/cloudflare/miniflare/miniflare-controller.d.ts.map +1 -1
  70. package/lib/cloudflare/miniflare/miniflare-controller.js +2 -0
  71. package/lib/cloudflare/miniflare/miniflare-controller.js.map +1 -1
  72. package/lib/cloudflare/miniflare/miniflare-worker-proxy.d.ts +1 -1
  73. package/lib/cloudflare/miniflare/miniflare-worker-proxy.d.ts.map +1 -1
  74. package/lib/cloudflare/miniflare/miniflare-worker-proxy.js +36 -49
  75. package/lib/cloudflare/miniflare/miniflare-worker-proxy.js.map +1 -1
  76. package/lib/cloudflare/permission-groups.d.ts +2 -3
  77. package/lib/cloudflare/permission-groups.d.ts.map +1 -1
  78. package/lib/cloudflare/permission-groups.js +10 -15
  79. package/lib/cloudflare/permission-groups.js.map +1 -1
  80. package/lib/cloudflare/redwood/redwood.d.ts +1 -1
  81. package/lib/cloudflare/redwood/redwood.js +1 -1
  82. package/lib/cloudflare/util/filter-env-bindings.d.ts +62 -0
  83. package/lib/cloudflare/util/filter-env-bindings.d.ts.map +1 -0
  84. package/lib/cloudflare/util/filter-env-bindings.js +81 -0
  85. package/lib/cloudflare/util/filter-env-bindings.js.map +1 -0
  86. package/lib/cloudflare/website.d.ts +2 -2
  87. package/lib/cloudflare/website.d.ts.map +1 -1
  88. package/lib/cloudflare/website.js +6 -18
  89. package/lib/cloudflare/website.js.map +1 -1
  90. package/lib/cloudflare/worker-metadata.d.ts +1 -0
  91. package/lib/cloudflare/worker-metadata.d.ts.map +1 -1
  92. package/lib/cloudflare/worker-metadata.js +1 -0
  93. package/lib/cloudflare/worker-metadata.js.map +1 -1
  94. package/lib/cloudflare/worker.d.ts +11 -1
  95. package/lib/cloudflare/worker.d.ts.map +1 -1
  96. package/lib/cloudflare/worker.js.map +1 -1
  97. package/lib/cloudflare/wrangler.json.d.ts +8 -0
  98. package/lib/cloudflare/wrangler.json.d.ts.map +1 -1
  99. package/lib/cloudflare/wrangler.json.js +3 -4
  100. package/lib/cloudflare/wrangler.json.js.map +1 -1
  101. package/lib/coinbase/client.d.ts +54 -0
  102. package/lib/coinbase/client.d.ts.map +1 -0
  103. package/lib/coinbase/client.js +89 -0
  104. package/lib/coinbase/client.js.map +1 -0
  105. package/lib/coinbase/evm-account.d.ts +118 -0
  106. package/lib/coinbase/evm-account.d.ts.map +1 -0
  107. package/lib/coinbase/evm-account.js +198 -0
  108. package/lib/coinbase/evm-account.js.map +1 -0
  109. package/lib/coinbase/evm-smart-account.d.ts +122 -0
  110. package/lib/coinbase/evm-smart-account.d.ts.map +1 -0
  111. package/lib/coinbase/evm-smart-account.js +213 -0
  112. package/lib/coinbase/evm-smart-account.js.map +1 -0
  113. package/lib/coinbase/faucet.d.ts +11 -0
  114. package/lib/coinbase/faucet.d.ts.map +1 -0
  115. package/lib/coinbase/faucet.js +146 -0
  116. package/lib/coinbase/faucet.js.map +1 -0
  117. package/lib/coinbase/index.d.ts +4 -0
  118. package/lib/coinbase/index.d.ts.map +1 -0
  119. package/lib/coinbase/index.js +4 -0
  120. package/lib/coinbase/index.js.map +1 -0
  121. package/lib/coinbase/types.d.ts +28 -0
  122. package/lib/coinbase/types.d.ts.map +1 -0
  123. package/lib/coinbase/types.js +4 -0
  124. package/lib/{util/telemetry → coinbase}/types.js.map +1 -1
  125. package/lib/coinbase/utils.d.ts +13 -0
  126. package/lib/coinbase/utils.d.ts.map +1 -0
  127. package/lib/coinbase/utils.js +17 -0
  128. package/lib/coinbase/utils.js.map +1 -0
  129. package/lib/neon/api/types.gen.d.ts +7 -2
  130. package/lib/neon/api/types.gen.d.ts.map +1 -1
  131. package/lib/planetscale/api/types.gen.d.ts +20 -4
  132. package/lib/planetscale/api/types.gen.d.ts.map +1 -1
  133. package/lib/planetscale/api.d.ts.map +1 -1
  134. package/lib/planetscale/api.js +1 -0
  135. package/lib/planetscale/api.js.map +1 -1
  136. package/lib/planetscale/password.d.ts.map +1 -1
  137. package/lib/planetscale/password.js +1 -13
  138. package/lib/planetscale/password.js.map +1 -1
  139. package/lib/resource.d.ts.map +1 -1
  140. package/lib/resource.js +7 -3
  141. package/lib/resource.js.map +1 -1
  142. package/lib/scope.d.ts +9 -9
  143. package/lib/scope.d.ts.map +1 -1
  144. package/lib/scope.js +18 -37
  145. package/lib/scope.js.map +1 -1
  146. package/lib/state/instrumented-state-store.d.ts +1 -3
  147. package/lib/state/instrumented-state-store.d.ts.map +1 -1
  148. package/lib/state/instrumented-state-store.js +19 -21
  149. package/lib/state/instrumented-state-store.js.map +1 -1
  150. package/lib/test/bun.d.ts.map +1 -1
  151. package/lib/test/bun.js +1 -2
  152. package/lib/test/bun.js.map +1 -1
  153. package/lib/test/vitest.d.ts.map +1 -1
  154. package/lib/test/vitest.js +1 -2
  155. package/lib/test/vitest.js.map +1 -1
  156. package/lib/util/diff.d.ts +5 -0
  157. package/lib/util/diff.d.ts.map +1 -0
  158. package/lib/util/diff.js +14 -0
  159. package/lib/util/diff.js.map +1 -0
  160. package/lib/util/idempotent-spawn.js +1 -1
  161. package/lib/util/idempotent-spawn.js.map +1 -1
  162. package/lib/util/telemetry.d.ts +53 -0
  163. package/lib/util/telemetry.d.ts.map +1 -0
  164. package/lib/util/telemetry.js +215 -0
  165. package/lib/util/telemetry.js.map +1 -0
  166. package/package.json +19 -1
  167. package/src/alchemy.ts +10 -20
  168. package/src/apply.ts +29 -12
  169. package/src/aws/utils.ts +2 -1
  170. package/src/clickhouse/api/client.gen.ts +28 -0
  171. package/src/clickhouse/api/sdk.gen.ts +1286 -0
  172. package/src/clickhouse/api/types.gen.ts +5898 -0
  173. package/src/clickhouse/api-key.ts +136 -0
  174. package/src/clickhouse/api.ts +84 -0
  175. package/src/clickhouse/index.ts +3 -0
  176. package/src/clickhouse/organization.ts +31 -0
  177. package/src/clickhouse/service.ts +668 -0
  178. package/src/cloudflare/account-api-token.ts +1 -4
  179. package/src/cloudflare/api.ts +2 -0
  180. package/src/cloudflare/bun-spa/bun-spa.ts +136 -0
  181. package/src/cloudflare/compatibility-date.gen.ts +1 -1
  182. package/src/cloudflare/container.ts +20 -1
  183. package/src/cloudflare/index.ts +1 -0
  184. package/src/cloudflare/miniflare/build-worker-options.ts +38 -8
  185. package/src/cloudflare/miniflare/miniflare-controller.ts +2 -0
  186. package/src/cloudflare/miniflare/miniflare-worker-proxy.ts +41 -58
  187. package/src/cloudflare/permission-groups.ts +21 -49
  188. package/src/cloudflare/redwood/redwood.ts +1 -1
  189. package/src/cloudflare/util/filter-env-bindings.ts +96 -0
  190. package/src/cloudflare/website.ts +11 -24
  191. package/src/cloudflare/worker-metadata.ts +2 -0
  192. package/src/cloudflare/worker.ts +12 -1
  193. package/src/cloudflare/wrangler.json.ts +12 -8
  194. package/src/coinbase/client.ts +146 -0
  195. package/src/coinbase/evm-account.ts +317 -0
  196. package/src/coinbase/evm-smart-account.ts +339 -0
  197. package/src/coinbase/faucet.ts +173 -0
  198. package/src/coinbase/index.ts +3 -0
  199. package/src/coinbase/types.ts +33 -0
  200. package/src/coinbase/utils.ts +19 -0
  201. package/src/neon/api/types.gen.ts +13 -1
  202. package/src/planetscale/api/types.gen.ts +22 -2
  203. package/src/planetscale/api.ts +1 -0
  204. package/src/planetscale/password.ts +1 -14
  205. package/src/resource.ts +11 -4
  206. package/src/scope.ts +29 -45
  207. package/src/state/instrumented-state-store.ts +27 -26
  208. package/src/test/bun.ts +1 -2
  209. package/src/test/vitest.ts +1 -2
  210. package/src/util/diff.ts +14 -0
  211. package/src/util/idempotent-spawn.ts +1 -1
  212. package/src/util/telemetry.ts +328 -0
  213. package/templates/tanstack-start/package.json +2 -2
  214. package/workers/tunnel-proxy.js +1 -1
  215. package/lib/util/telemetry/client.d.ts +0 -31
  216. package/lib/util/telemetry/client.d.ts.map +0 -1
  217. package/lib/util/telemetry/client.js +0 -121
  218. package/lib/util/telemetry/client.js.map +0 -1
  219. package/lib/util/telemetry/constants.d.ts +0 -5
  220. package/lib/util/telemetry/constants.d.ts.map +0 -1
  221. package/lib/util/telemetry/constants.js +0 -8
  222. package/lib/util/telemetry/constants.js.map +0 -1
  223. package/lib/util/telemetry/context.d.ts +0 -15
  224. package/lib/util/telemetry/context.d.ts.map +0 -1
  225. package/lib/util/telemetry/context.js +0 -128
  226. package/lib/util/telemetry/context.js.map +0 -1
  227. package/lib/util/telemetry/index.d.ts +0 -3
  228. package/lib/util/telemetry/index.d.ts.map +0 -1
  229. package/lib/util/telemetry/index.js +0 -3
  230. package/lib/util/telemetry/index.js.map +0 -1
  231. package/lib/util/telemetry/types.d.ts +0 -68
  232. package/lib/util/telemetry/types.d.ts.map +0 -1
  233. package/lib/util/telemetry/types.js +0 -1
  234. package/src/util/telemetry/client.ts +0 -156
  235. package/src/util/telemetry/constants.ts +0 -13
  236. package/src/util/telemetry/context.ts +0 -154
  237. package/src/util/telemetry/index.ts +0 -2
  238. package/src/util/telemetry/types.ts +0 -105
@@ -0,0 +1,136 @@
1
+ import type { Context } from "../context.ts";
2
+ import { Resource } from "../resource.ts";
3
+ import { secret, type Secret } from "../secret.ts";
4
+ import { diff } from "../util/diff.ts";
5
+ import { createClickhouseApi } from "./api.ts";
6
+ import type { ApiKey as ApiApiKey, Organization } from "./api/types.gen.ts";
7
+
8
+ export interface ApiKeyProps {
9
+ keyId?: string | Secret<string>;
10
+ secret?: string | Secret<string>;
11
+ organization: string | Organization;
12
+ name?: ApiApiKey["name"];
13
+ expireAt?: ApiApiKey["expireAt"];
14
+ roles?: ApiApiKey["roles"];
15
+ ipAccessList?: ApiApiKey["ipAccessList"];
16
+ state?: ApiApiKey["state"];
17
+ }
18
+
19
+ export interface ApiKey {
20
+ organizationId: string;
21
+ name: string;
22
+ clickhouseId: NonNullable<ApiApiKey["id"]>;
23
+ keyId: string;
24
+ secret: Secret<string>;
25
+ state: NonNullable<ApiApiKey["state"]>;
26
+ roles: NonNullable<ApiApiKey["roles"]>;
27
+ keySuffix: NonNullable<ApiApiKey["keySuffix"]>;
28
+ createdAt: NonNullable<ApiApiKey["createdAt"]>;
29
+ expireAt?: ApiApiKey["expireAt"];
30
+ usedAt?: ApiApiKey["usedAt"];
31
+ ipAccessList: ApiApiKey["ipAccessList"];
32
+ }
33
+
34
+ export const ApiKey = Resource(
35
+ "clickhouse::ApiKey",
36
+ async function (
37
+ this: Context<ApiKey>,
38
+ id: string,
39
+ props: ApiKeyProps,
40
+ ): Promise<ApiKey> {
41
+ const api = createClickhouseApi({
42
+ keyId: props.keyId,
43
+ secret: props.secret,
44
+ });
45
+
46
+ const name =
47
+ props.name ?? this.output?.name ?? this.scope.createPhysicalName(id);
48
+ const state = props.state ?? this.output?.state ?? "enabled";
49
+
50
+ const organizationId =
51
+ typeof props.organization === "string"
52
+ ? props.organization
53
+ : props.organization.id!;
54
+
55
+ if (this.phase === "delete") {
56
+ await api.deleteKey({
57
+ path: {
58
+ organizationId: organizationId,
59
+ keyId: this.output.clickhouseId,
60
+ },
61
+ });
62
+ return this.destroy();
63
+ }
64
+ if (this.phase === "update") {
65
+ if (
66
+ diff(
67
+ { ...props, name },
68
+ { ...this.output, organization: props.organization },
69
+ ).some(
70
+ (prop) =>
71
+ prop !== "name" &&
72
+ prop !== "roles" &&
73
+ prop !== "ipAccessList" &&
74
+ prop !== "expireAt" &&
75
+ prop !== "state",
76
+ )
77
+ ) {
78
+ return this.replace();
79
+ }
80
+ const updatedKey = await api.updateKey({
81
+ path: {
82
+ organizationId: organizationId!,
83
+ keyId: this.output.clickhouseId!,
84
+ },
85
+ body: {
86
+ name,
87
+ roles: props.roles,
88
+ ipAccessList: props.ipAccessList,
89
+ expireAt: props.expireAt,
90
+ state,
91
+ },
92
+ });
93
+
94
+ return {
95
+ ...this.output,
96
+ ...updatedKey,
97
+ name,
98
+ };
99
+ }
100
+
101
+ const key = (
102
+ await api.createKey({
103
+ path: {
104
+ organizationId: organizationId!,
105
+ },
106
+ body: {
107
+ name,
108
+ expireAt: props.expireAt ?? "2999-12-31T00:00:00.000Z",
109
+ ipAccessList: props.ipAccessList ?? [
110
+ {
111
+ description: "Anywhere",
112
+ source: "0.0.0.0/0",
113
+ },
114
+ ],
115
+ roles: props.roles ?? ["admin"],
116
+ state,
117
+ },
118
+ })
119
+ ).data.result!;
120
+
121
+ return {
122
+ organizationId: organizationId,
123
+ name: key!.key!.name!,
124
+ clickhouseId: key!.key!.id!,
125
+ state: key!.key!.state!,
126
+ roles: key!.key!.roles!,
127
+ keySuffix: key!.key!.keySuffix!,
128
+ createdAt: key!.key!.createdAt!,
129
+ expireAt: key!.key!.expireAt!,
130
+ usedAt: key!.key!.usedAt,
131
+ ipAccessList: key!.key!.ipAccessList!,
132
+ keyId: key!.keyId!,
133
+ secret: secret(key.keySecret),
134
+ };
135
+ },
136
+ );
@@ -0,0 +1,84 @@
1
+ import type { Secret } from "../secret.ts";
2
+ import { createClient } from "../util/api/client/client.gen.ts";
3
+ import type { ClientOptions } from "../util/api/client/types.gen.ts";
4
+ import { createConfig } from "../util/api/client/utils.gen.ts";
5
+ import { ClickhouseClient } from "./api/sdk.gen.ts";
6
+
7
+ /**
8
+ * Options for Neon API requests
9
+ */
10
+ export interface ClickhouseApiOptions {
11
+ /**
12
+ * The key ID for the Clickhouse API
13
+ */
14
+ keyId?: string | Secret<string>;
15
+
16
+ /**
17
+ * The secret for the Clickhouse API
18
+ */
19
+ secret?: string | Secret<string>;
20
+ }
21
+
22
+ export class ClickhouseError extends Error {
23
+ status: number;
24
+ method: string;
25
+ url: string;
26
+ code: string;
27
+
28
+ constructor(props: {
29
+ error: {
30
+ status?: number;
31
+ error?: string;
32
+ };
33
+ request: Request;
34
+ response: Response;
35
+ }) {
36
+ const { status, error } = props.error;
37
+ super(
38
+ `A request to the Clickhouse API failed (${props.response.status}): ${error}`,
39
+ );
40
+ this.status = props.response.status;
41
+ this.method = props.request.method;
42
+ this.url = props.request.url;
43
+ this.code = status?.toString() ?? "";
44
+ Object.assign(this, props.error);
45
+ }
46
+ }
47
+
48
+ /**
49
+ * Create a ClickhouseApi instance with environment variable fallback
50
+ * @param options API options
51
+ * @returns ClickhouseApi instance
52
+ */
53
+ export function createClickhouseApi(
54
+ options: Partial<ClickhouseApiOptions> = {},
55
+ ): ClickhouseClient {
56
+ const keyId = options?.keyId ?? process.env.CLICKHOUSE_KEY_ID;
57
+ const secret = options?.secret ?? process.env.CLICKHOUSE_KEY_SECRET;
58
+
59
+ const client = createClient(
60
+ createConfig<ClientOptions>({
61
+ baseUrl: "https://api.clickhouse.cloud",
62
+ throwOnError: true,
63
+ headers: {
64
+ Authorization: `Basic ${btoa(`${keyId}:${secret}`)}`,
65
+ },
66
+ }),
67
+ );
68
+ client.interceptors.error.use((error, response, request, options) => {
69
+ if (options.throwOnError !== false) {
70
+ throw new ClickhouseError({
71
+ error: error as {
72
+ status?: number;
73
+ error?: string;
74
+ },
75
+ request,
76
+ response,
77
+ });
78
+ }
79
+ return error;
80
+ });
81
+ return new ClickhouseClient({
82
+ client,
83
+ });
84
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./api-key.ts";
2
+ export * from "./organization.ts";
3
+ export * from "./service.ts";
@@ -0,0 +1,31 @@
1
+ import type { Secret } from "../secret.ts";
2
+ import { createClickhouseApi } from "./api.ts";
3
+
4
+ /**
5
+ * Get an organization by name.
6
+ *
7
+ * @example
8
+ * const organization = await getOrganizationByName("Alchemy's Organization");
9
+ *
10
+ * @param name The name of the organization to get.
11
+ * @param options The api credentials to use.
12
+ * @returns The organization.
13
+ */
14
+ export async function OrganizationRef(
15
+ name: string,
16
+ options?: {
17
+ keyId?: string | Secret<string>;
18
+ secret?: string | Secret<string>;
19
+ },
20
+ ) {
21
+ const api = createClickhouseApi(options);
22
+
23
+ const organizations = await api.listAvailableOrganizations();
24
+ const organization = organizations.data.result?.find(
25
+ (organization) => organization.name === name,
26
+ );
27
+ if (!organization) {
28
+ throw new Error(`Organization ${name} not found`);
29
+ }
30
+ return organization;
31
+ }