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.
- package/bin/alchemy.js +3883 -3906
- package/bin/alchemy.ts +2 -0
- package/bin/commands/telemetry.ts +33 -0
- package/bin/services/execute-alchemy.ts +7 -0
- package/bin/trpc.ts +4 -9
- package/lib/alchemy.d.ts +7 -3
- package/lib/alchemy.d.ts.map +1 -1
- package/lib/alchemy.js +3 -15
- package/lib/alchemy.js.map +1 -1
- package/lib/apply.js +24 -9
- package/lib/apply.js.map +1 -1
- package/lib/aws/utils.d.ts +2 -1
- package/lib/aws/utils.d.ts.map +1 -1
- package/lib/aws/utils.js.map +1 -1
- package/lib/clickhouse/api/client.gen.d.ts +13 -0
- package/lib/clickhouse/api/client.gen.d.ts.map +1 -0
- package/lib/clickhouse/api/client.gen.js +7 -0
- package/lib/clickhouse/api/client.gen.js.map +1 -0
- package/lib/clickhouse/api/sdk.gen.d.ts +322 -0
- package/lib/clickhouse/api/sdk.gen.d.ts.map +1 -0
- package/lib/clickhouse/api/sdk.gen.js +683 -0
- package/lib/clickhouse/api/sdk.gen.js.map +1 -0
- package/lib/clickhouse/api/types.gen.d.ts +5030 -0
- package/lib/clickhouse/api/types.gen.d.ts.map +1 -0
- package/lib/clickhouse/api/types.gen.js +2 -0
- package/lib/clickhouse/api/types.gen.js.map +1 -0
- package/lib/clickhouse/api-key.d.ts +29 -0
- package/lib/clickhouse/api-key.d.ts.map +1 -0
- package/lib/clickhouse/api-key.js +83 -0
- package/lib/clickhouse/api-key.js.map +1 -0
- package/lib/clickhouse/api.d.ts +36 -0
- package/lib/clickhouse/api.d.ts.map +1 -0
- package/lib/clickhouse/api.js +48 -0
- package/lib/clickhouse/api.js.map +1 -0
- package/lib/clickhouse/index.d.ts +4 -0
- package/lib/clickhouse/index.d.ts.map +1 -0
- package/lib/clickhouse/index.js +4 -0
- package/lib/clickhouse/index.js.map +1 -0
- package/lib/clickhouse/organization.d.ts +16 -0
- package/lib/clickhouse/organization.d.ts.map +1 -0
- package/lib/clickhouse/organization.js +21 -0
- package/lib/clickhouse/organization.js.map +1 -0
- package/lib/clickhouse/service.d.ts +275 -0
- package/lib/clickhouse/service.d.ts.map +1 -0
- package/lib/clickhouse/service.js +274 -0
- package/lib/clickhouse/service.js.map +1 -0
- package/lib/cloudflare/account-api-token.d.ts.map +1 -1
- package/lib/cloudflare/account-api-token.js +1 -1
- package/lib/cloudflare/account-api-token.js.map +1 -1
- package/lib/cloudflare/api.d.ts.map +1 -1
- package/lib/cloudflare/api.js +2 -0
- package/lib/cloudflare/api.js.map +1 -1
- package/lib/cloudflare/bun-spa/bun-spa.d.ts +13 -0
- package/lib/cloudflare/bun-spa/bun-spa.d.ts.map +1 -0
- package/lib/cloudflare/bun-spa/bun-spa.js +95 -0
- package/lib/cloudflare/bun-spa/bun-spa.js.map +1 -0
- package/lib/cloudflare/compatibility-date.gen.d.ts +1 -1
- package/lib/cloudflare/compatibility-date.gen.js +1 -1
- package/lib/cloudflare/container.d.ts +11 -1
- package/lib/cloudflare/container.d.ts.map +1 -1
- package/lib/cloudflare/container.js.map +1 -1
- package/lib/cloudflare/index.d.ts +1 -0
- package/lib/cloudflare/index.d.ts.map +1 -1
- package/lib/cloudflare/index.js +1 -0
- package/lib/cloudflare/index.js.map +1 -1
- package/lib/cloudflare/miniflare/build-worker-options.d.ts.map +1 -1
- package/lib/cloudflare/miniflare/build-worker-options.js +33 -6
- package/lib/cloudflare/miniflare/build-worker-options.js.map +1 -1
- package/lib/cloudflare/miniflare/miniflare-controller.d.ts.map +1 -1
- package/lib/cloudflare/miniflare/miniflare-controller.js +2 -0
- package/lib/cloudflare/miniflare/miniflare-controller.js.map +1 -1
- package/lib/cloudflare/miniflare/miniflare-worker-proxy.d.ts +1 -1
- package/lib/cloudflare/miniflare/miniflare-worker-proxy.d.ts.map +1 -1
- package/lib/cloudflare/miniflare/miniflare-worker-proxy.js +36 -49
- package/lib/cloudflare/miniflare/miniflare-worker-proxy.js.map +1 -1
- package/lib/cloudflare/permission-groups.d.ts +2 -3
- package/lib/cloudflare/permission-groups.d.ts.map +1 -1
- package/lib/cloudflare/permission-groups.js +10 -15
- package/lib/cloudflare/permission-groups.js.map +1 -1
- package/lib/cloudflare/redwood/redwood.d.ts +1 -1
- package/lib/cloudflare/redwood/redwood.js +1 -1
- package/lib/cloudflare/util/filter-env-bindings.d.ts +62 -0
- package/lib/cloudflare/util/filter-env-bindings.d.ts.map +1 -0
- package/lib/cloudflare/util/filter-env-bindings.js +81 -0
- package/lib/cloudflare/util/filter-env-bindings.js.map +1 -0
- package/lib/cloudflare/website.d.ts +2 -2
- package/lib/cloudflare/website.d.ts.map +1 -1
- package/lib/cloudflare/website.js +6 -18
- package/lib/cloudflare/website.js.map +1 -1
- package/lib/cloudflare/worker-metadata.d.ts +1 -0
- package/lib/cloudflare/worker-metadata.d.ts.map +1 -1
- package/lib/cloudflare/worker-metadata.js +1 -0
- package/lib/cloudflare/worker-metadata.js.map +1 -1
- package/lib/cloudflare/worker.d.ts +11 -1
- package/lib/cloudflare/worker.d.ts.map +1 -1
- package/lib/cloudflare/worker.js.map +1 -1
- package/lib/cloudflare/wrangler.json.d.ts +8 -0
- package/lib/cloudflare/wrangler.json.d.ts.map +1 -1
- package/lib/cloudflare/wrangler.json.js +3 -4
- package/lib/cloudflare/wrangler.json.js.map +1 -1
- package/lib/coinbase/client.d.ts +54 -0
- package/lib/coinbase/client.d.ts.map +1 -0
- package/lib/coinbase/client.js +89 -0
- package/lib/coinbase/client.js.map +1 -0
- package/lib/coinbase/evm-account.d.ts +118 -0
- package/lib/coinbase/evm-account.d.ts.map +1 -0
- package/lib/coinbase/evm-account.js +198 -0
- package/lib/coinbase/evm-account.js.map +1 -0
- package/lib/coinbase/evm-smart-account.d.ts +122 -0
- package/lib/coinbase/evm-smart-account.d.ts.map +1 -0
- package/lib/coinbase/evm-smart-account.js +213 -0
- package/lib/coinbase/evm-smart-account.js.map +1 -0
- package/lib/coinbase/faucet.d.ts +11 -0
- package/lib/coinbase/faucet.d.ts.map +1 -0
- package/lib/coinbase/faucet.js +146 -0
- package/lib/coinbase/faucet.js.map +1 -0
- package/lib/coinbase/index.d.ts +4 -0
- package/lib/coinbase/index.d.ts.map +1 -0
- package/lib/coinbase/index.js +4 -0
- package/lib/coinbase/index.js.map +1 -0
- package/lib/coinbase/types.d.ts +28 -0
- package/lib/coinbase/types.d.ts.map +1 -0
- package/lib/coinbase/types.js +4 -0
- package/lib/{util/telemetry → coinbase}/types.js.map +1 -1
- package/lib/coinbase/utils.d.ts +13 -0
- package/lib/coinbase/utils.d.ts.map +1 -0
- package/lib/coinbase/utils.js +17 -0
- package/lib/coinbase/utils.js.map +1 -0
- package/lib/neon/api/types.gen.d.ts +7 -2
- package/lib/neon/api/types.gen.d.ts.map +1 -1
- package/lib/planetscale/api/types.gen.d.ts +20 -4
- package/lib/planetscale/api/types.gen.d.ts.map +1 -1
- package/lib/planetscale/api.d.ts.map +1 -1
- package/lib/planetscale/api.js +1 -0
- package/lib/planetscale/api.js.map +1 -1
- package/lib/planetscale/password.d.ts.map +1 -1
- package/lib/planetscale/password.js +1 -13
- package/lib/planetscale/password.js.map +1 -1
- package/lib/resource.d.ts.map +1 -1
- package/lib/resource.js +7 -3
- package/lib/resource.js.map +1 -1
- package/lib/scope.d.ts +9 -9
- package/lib/scope.d.ts.map +1 -1
- package/lib/scope.js +18 -37
- package/lib/scope.js.map +1 -1
- package/lib/state/instrumented-state-store.d.ts +1 -3
- package/lib/state/instrumented-state-store.d.ts.map +1 -1
- package/lib/state/instrumented-state-store.js +19 -21
- package/lib/state/instrumented-state-store.js.map +1 -1
- package/lib/test/bun.d.ts.map +1 -1
- package/lib/test/bun.js +1 -2
- package/lib/test/bun.js.map +1 -1
- package/lib/test/vitest.d.ts.map +1 -1
- package/lib/test/vitest.js +1 -2
- package/lib/test/vitest.js.map +1 -1
- package/lib/util/diff.d.ts +5 -0
- package/lib/util/diff.d.ts.map +1 -0
- package/lib/util/diff.js +14 -0
- package/lib/util/diff.js.map +1 -0
- package/lib/util/idempotent-spawn.js +1 -1
- package/lib/util/idempotent-spawn.js.map +1 -1
- package/lib/util/telemetry.d.ts +53 -0
- package/lib/util/telemetry.d.ts.map +1 -0
- package/lib/util/telemetry.js +215 -0
- package/lib/util/telemetry.js.map +1 -0
- package/package.json +19 -1
- package/src/alchemy.ts +10 -20
- package/src/apply.ts +29 -12
- package/src/aws/utils.ts +2 -1
- package/src/clickhouse/api/client.gen.ts +28 -0
- package/src/clickhouse/api/sdk.gen.ts +1286 -0
- package/src/clickhouse/api/types.gen.ts +5898 -0
- package/src/clickhouse/api-key.ts +136 -0
- package/src/clickhouse/api.ts +84 -0
- package/src/clickhouse/index.ts +3 -0
- package/src/clickhouse/organization.ts +31 -0
- package/src/clickhouse/service.ts +668 -0
- package/src/cloudflare/account-api-token.ts +1 -4
- package/src/cloudflare/api.ts +2 -0
- package/src/cloudflare/bun-spa/bun-spa.ts +136 -0
- package/src/cloudflare/compatibility-date.gen.ts +1 -1
- package/src/cloudflare/container.ts +20 -1
- package/src/cloudflare/index.ts +1 -0
- package/src/cloudflare/miniflare/build-worker-options.ts +38 -8
- package/src/cloudflare/miniflare/miniflare-controller.ts +2 -0
- package/src/cloudflare/miniflare/miniflare-worker-proxy.ts +41 -58
- package/src/cloudflare/permission-groups.ts +21 -49
- package/src/cloudflare/redwood/redwood.ts +1 -1
- package/src/cloudflare/util/filter-env-bindings.ts +96 -0
- package/src/cloudflare/website.ts +11 -24
- package/src/cloudflare/worker-metadata.ts +2 -0
- package/src/cloudflare/worker.ts +12 -1
- package/src/cloudflare/wrangler.json.ts +12 -8
- package/src/coinbase/client.ts +146 -0
- package/src/coinbase/evm-account.ts +317 -0
- package/src/coinbase/evm-smart-account.ts +339 -0
- package/src/coinbase/faucet.ts +173 -0
- package/src/coinbase/index.ts +3 -0
- package/src/coinbase/types.ts +33 -0
- package/src/coinbase/utils.ts +19 -0
- package/src/neon/api/types.gen.ts +13 -1
- package/src/planetscale/api/types.gen.ts +22 -2
- package/src/planetscale/api.ts +1 -0
- package/src/planetscale/password.ts +1 -14
- package/src/resource.ts +11 -4
- package/src/scope.ts +29 -45
- package/src/state/instrumented-state-store.ts +27 -26
- package/src/test/bun.ts +1 -2
- package/src/test/vitest.ts +1 -2
- package/src/util/diff.ts +14 -0
- package/src/util/idempotent-spawn.ts +1 -1
- package/src/util/telemetry.ts +328 -0
- package/templates/tanstack-start/package.json +2 -2
- package/workers/tunnel-proxy.js +1 -1
- package/lib/util/telemetry/client.d.ts +0 -31
- package/lib/util/telemetry/client.d.ts.map +0 -1
- package/lib/util/telemetry/client.js +0 -121
- package/lib/util/telemetry/client.js.map +0 -1
- package/lib/util/telemetry/constants.d.ts +0 -5
- package/lib/util/telemetry/constants.d.ts.map +0 -1
- package/lib/util/telemetry/constants.js +0 -8
- package/lib/util/telemetry/constants.js.map +0 -1
- package/lib/util/telemetry/context.d.ts +0 -15
- package/lib/util/telemetry/context.d.ts.map +0 -1
- package/lib/util/telemetry/context.js +0 -128
- package/lib/util/telemetry/context.js.map +0 -1
- package/lib/util/telemetry/index.d.ts +0 -3
- package/lib/util/telemetry/index.d.ts.map +0 -1
- package/lib/util/telemetry/index.js +0 -3
- package/lib/util/telemetry/index.js.map +0 -1
- package/lib/util/telemetry/types.d.ts +0 -68
- package/lib/util/telemetry/types.d.ts.map +0 -1
- package/lib/util/telemetry/types.js +0 -1
- package/src/util/telemetry/client.ts +0 -156
- package/src/util/telemetry/constants.ts +0 -13
- package/src/util/telemetry/context.ts +0 -154
- package/src/util/telemetry/index.ts +0 -2
- 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,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
|
+
}
|