@vibesdotdev/infra-cloudflare 0.0.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/README.md +107 -0
- package/SPEC.md +166 -0
- package/dist/cloudflare.plugin.d.ts +73 -0
- package/dist/cloudflare.plugin.d.ts.map +1 -0
- package/dist/cloudflare.plugin.js +334 -0
- package/dist/cloudflare.plugin.js.map +1 -0
- package/dist/implementations/alerts.descriptor.d.ts +13 -0
- package/dist/implementations/alerts.descriptor.d.ts.map +1 -0
- package/dist/implementations/alerts.descriptor.js +30 -0
- package/dist/implementations/alerts.descriptor.js.map +1 -0
- package/dist/implementations/alerts.impl.d.ts +35 -0
- package/dist/implementations/alerts.impl.d.ts.map +1 -0
- package/dist/implementations/alerts.impl.js +283 -0
- package/dist/implementations/alerts.impl.js.map +1 -0
- package/dist/implementations/kv.impl.d.ts +29 -0
- package/dist/implementations/kv.impl.d.ts.map +1 -0
- package/dist/implementations/kv.impl.js +36 -0
- package/dist/implementations/kv.impl.js.map +1 -0
- package/dist/implementations/logs.descriptor.d.ts +15 -0
- package/dist/implementations/logs.descriptor.d.ts.map +1 -0
- package/dist/implementations/logs.descriptor.js +26 -0
- package/dist/implementations/logs.descriptor.js.map +1 -0
- package/dist/implementations/logs.impl.d.ts +108 -0
- package/dist/implementations/logs.impl.d.ts.map +1 -0
- package/dist/implementations/logs.impl.js +154 -0
- package/dist/implementations/logs.impl.js.map +1 -0
- package/dist/implementations/observability.descriptor.d.ts +9 -0
- package/dist/implementations/observability.descriptor.d.ts.map +1 -0
- package/dist/implementations/observability.descriptor.js +22 -0
- package/dist/implementations/observability.descriptor.js.map +1 -0
- package/dist/implementations/observability.impl.d.ts +35 -0
- package/dist/implementations/observability.impl.d.ts.map +1 -0
- package/dist/implementations/observability.impl.js +229 -0
- package/dist/implementations/observability.impl.js.map +1 -0
- package/dist/implementations/pages.impl.d.ts +98 -0
- package/dist/implementations/pages.impl.d.ts.map +1 -0
- package/dist/implementations/pages.impl.js +132 -0
- package/dist/implementations/pages.impl.js.map +1 -0
- package/dist/implementations/queues.impl.d.ts +29 -0
- package/dist/implementations/queues.impl.d.ts.map +1 -0
- package/dist/implementations/queues.impl.js +34 -0
- package/dist/implementations/queues.impl.js.map +1 -0
- package/dist/implementations/r2.impl.d.ts +31 -0
- package/dist/implementations/r2.impl.d.ts.map +1 -0
- package/dist/implementations/r2.impl.js +41 -0
- package/dist/implementations/r2.impl.js.map +1 -0
- package/dist/implementations/rum.descriptor.d.ts +13 -0
- package/dist/implementations/rum.descriptor.d.ts.map +1 -0
- package/dist/implementations/rum.descriptor.js +32 -0
- package/dist/implementations/rum.descriptor.js.map +1 -0
- package/dist/implementations/rum.impl.d.ts +34 -0
- package/dist/implementations/rum.impl.d.ts.map +1 -0
- package/dist/implementations/rum.impl.js +153 -0
- package/dist/implementations/rum.impl.js.map +1 -0
- package/dist/implementations/web-app.impl.d.ts +294 -0
- package/dist/implementations/web-app.impl.d.ts.map +1 -0
- package/dist/implementations/web-app.impl.js +208 -0
- package/dist/implementations/web-app.impl.js.map +1 -0
- package/dist/implementations/workers.impl.d.ts +157 -0
- package/dist/implementations/workers.impl.d.ts.map +1 -0
- package/dist/implementations/workers.impl.js +247 -0
- package/dist/implementations/workers.impl.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/pages.d.ts +9 -0
- package/dist/pages.d.ts.map +1 -0
- package/dist/pages.js +9 -0
- package/dist/pages.js.map +1 -0
- package/dist/regen.d.ts +58 -0
- package/dist/regen.d.ts.map +1 -0
- package/dist/regen.js +69 -0
- package/dist/regen.js.map +1 -0
- package/dist/secrets/cloudflare-api.descriptor.d.ts +18 -0
- package/dist/secrets/cloudflare-api.descriptor.d.ts.map +1 -0
- package/dist/secrets/cloudflare-api.descriptor.js +32 -0
- package/dist/secrets/cloudflare-api.descriptor.js.map +1 -0
- package/dist/secrets/cloudflare-api.impl.d.ts +30 -0
- package/dist/secrets/cloudflare-api.impl.d.ts.map +1 -0
- package/dist/secrets/cloudflare-api.impl.js +111 -0
- package/dist/secrets/cloudflare-api.impl.js.map +1 -0
- package/dist/secrets/cloudflare-secrets-store.descriptor.d.ts +10 -0
- package/dist/secrets/cloudflare-secrets-store.descriptor.d.ts.map +1 -0
- package/dist/secrets/cloudflare-secrets-store.descriptor.js +24 -0
- package/dist/secrets/cloudflare-secrets-store.descriptor.js.map +1 -0
- package/dist/secrets/cloudflare-secrets-store.impl.d.ts +27 -0
- package/dist/secrets/cloudflare-secrets-store.impl.d.ts.map +1 -0
- package/dist/secrets/cloudflare-secrets-store.impl.js +72 -0
- package/dist/secrets/cloudflare-secrets-store.impl.js.map +1 -0
- package/dist/secrets/index.d.ts +6 -0
- package/dist/secrets/index.d.ts.map +1 -0
- package/dist/secrets/index.js +6 -0
- package/dist/secrets/index.js.map +1 -0
- package/dist/secrets/resolve-cf-credentials.d.ts +18 -0
- package/dist/secrets/resolve-cf-credentials.d.ts.map +1 -0
- package/dist/secrets/resolve-cf-credentials.js +57 -0
- package/dist/secrets/resolve-cf-credentials.js.map +1 -0
- package/dist/web-app.d.ts +11 -0
- package/dist/web-app.d.ts.map +1 -0
- package/dist/web-app.js +11 -0
- package/dist/web-app.js.map +1 -0
- package/package.json +153 -0
- package/src/cloudflare.plugin.ts +477 -0
- package/src/implementations/alerts.descriptor.ts +33 -0
- package/src/implementations/alerts.impl.ts +332 -0
- package/src/implementations/kv.impl.ts +51 -0
- package/src/implementations/logs.descriptor.ts +29 -0
- package/src/implementations/logs.impl.ts +201 -0
- package/src/implementations/observability.descriptor.ts +25 -0
- package/src/implementations/observability.impl.ts +307 -0
- package/src/implementations/pages.impl.ts +189 -0
- package/src/implementations/queues.impl.ts +48 -0
- package/src/implementations/r2.impl.ts +58 -0
- package/src/implementations/rum.descriptor.ts +35 -0
- package/src/implementations/rum.impl.ts +192 -0
- package/src/implementations/web-app.impl.ts +494 -0
- package/src/implementations/workers.impl.ts +336 -0
- package/src/index.ts +60 -0
- package/src/pages.ts +18 -0
- package/src/regen.ts +87 -0
- package/src/secrets/cloudflare-api.descriptor.ts +35 -0
- package/src/secrets/cloudflare-api.impl.ts +131 -0
- package/src/secrets/cloudflare-secrets-store.descriptor.ts +27 -0
- package/src/secrets/cloudflare-secrets-store.impl.ts +87 -0
- package/src/secrets/index.ts +13 -0
- package/src/secrets/resolve-cf-credentials.ts +63 -0
- package/src/web-app.ts +32 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Secrets Store Backend Implementation
|
|
3
|
+
*
|
|
4
|
+
* Manages secrets at the Cloudflare account level. Workers consume them via
|
|
5
|
+
* wrangler `secrets_store_secrets` bindings, generated by pages.impl.ts.
|
|
6
|
+
*
|
|
7
|
+
* Like the per-Worker secrets API, store secrets are write-only — get() / getAll()
|
|
8
|
+
* always return empty results. List() returns names only.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { createRuntimeImplementation } from '@vibesdotdev/runtime/factory/implementation';
|
|
12
|
+
import { getVibesRuntime } from '@vibesdotdev/runtime';
|
|
13
|
+
import type { SecretsStoreDescriptor } from '@vibesdotdev/secrets/kinds/store.schema';
|
|
14
|
+
import type { SecretsStoreImplementation, SecretEntry } from '@vibesdotdev/secrets/kinds/store.interface';
|
|
15
|
+
import { CloudflareSecretsManagerConnector } from '@vibesdotdev/connector-cloudflare';
|
|
16
|
+
import descriptor from './cloudflare-secrets-store.descriptor';
|
|
17
|
+
import { resolveCfCredentialKeys } from './resolve-cf-credentials';
|
|
18
|
+
|
|
19
|
+
class CloudflareSecretsStore implements SecretsStoreImplementation {
|
|
20
|
+
readonly id = 'cloudflare-secrets-store';
|
|
21
|
+
readonly descriptor: SecretsStoreDescriptor;
|
|
22
|
+
private connector: CloudflareSecretsManagerConnector | null = null;
|
|
23
|
+
|
|
24
|
+
constructor(desc: SecretsStoreDescriptor) {
|
|
25
|
+
this.descriptor = desc;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private async getConnector(): Promise<CloudflareSecretsManagerConnector> {
|
|
29
|
+
if (this.connector) return this.connector;
|
|
30
|
+
|
|
31
|
+
const tokenVar = this.descriptor.config?.apiTokenEnvVar ?? 'CLOUDFLARE_API_TOKEN';
|
|
32
|
+
const accountVar = this.descriptor.config?.accountIdEnvVar ?? 'CLOUDFLARE_ACCOUNT_ID';
|
|
33
|
+
const storeVar = this.descriptor.config?.storeIdEnvVar ?? 'CLOUDFLARE_SECRETS_STORE_ID';
|
|
34
|
+
|
|
35
|
+
const envReader = await resolveCfCredentialKeys([tokenVar, accountVar, storeVar]);
|
|
36
|
+
|
|
37
|
+
this.connector = await CloudflareSecretsManagerConnector.create({
|
|
38
|
+
accountId: { source: 'env', key: accountVar },
|
|
39
|
+
apiToken: { source: 'env', key: tokenVar },
|
|
40
|
+
storeId: { source: 'env', key: storeVar }
|
|
41
|
+
}, {
|
|
42
|
+
environment: 'production',
|
|
43
|
+
envReader
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return this.connector;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async list(_environment: string): Promise<SecretEntry[]> {
|
|
50
|
+
const connector = await this.getConnector();
|
|
51
|
+
const names = await connector.listStore();
|
|
52
|
+
return names.map((key) => ({ key, hasValue: true, source: this.id }));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async get(_environment: string, _key: string): Promise<string | undefined> {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async set(environment: string, key: string, value: string): Promise<void> {
|
|
60
|
+
const connector = await this.getConnector();
|
|
61
|
+
await connector.setStore({ [key]: value });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async unset(_environment: string, key: string): Promise<void> {
|
|
65
|
+
const connector = await this.getConnector();
|
|
66
|
+
await connector.unsetStore(key);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async getAll(_environment: string): Promise<Record<string, string>> {
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async setAll(environment: string, secrets: Record<string, string>): Promise<void> {
|
|
74
|
+
const connector = await this.getConnector();
|
|
75
|
+
await connector.setStore(secrets);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function createCloudflareSecretsStore() {
|
|
80
|
+
const store = new CloudflareSecretsStore(descriptor);
|
|
81
|
+
return createRuntimeImplementation({
|
|
82
|
+
id: 'cloudflare-secrets-store',
|
|
83
|
+
kind: 'secrets/store',
|
|
84
|
+
priority: 30,
|
|
85
|
+
implementation: store
|
|
86
|
+
});
|
|
87
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { default as cloudflareApiDescriptor } from './cloudflare-api.descriptor';
|
|
2
|
+
export { createCloudflareApiStore } from './cloudflare-api.impl';
|
|
3
|
+
|
|
4
|
+
export { default as cloudflareSecretsStoreDescriptor } from './cloudflare-secrets-store.descriptor';
|
|
5
|
+
export { createCloudflareSecretsStore } from './cloudflare-secrets-store.impl';
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
type CFClientConfig,
|
|
9
|
+
listPagesSecrets,
|
|
10
|
+
setPagesSecrets,
|
|
11
|
+
listWorkerSecrets,
|
|
12
|
+
setWorkerSecrets
|
|
13
|
+
} from '@vibesdotdev/connector-cloudflare/api';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CF credential resolver shared by the `cloudflare-api` and
|
|
3
|
+
* `cloudflare-secrets-store` backends.
|
|
4
|
+
*
|
|
5
|
+
* `CloudflareSecretsManagerConnector.create({ source: 'env', ... })` only
|
|
6
|
+
* reads `process.env` (or an `envReader` override) — it doesn't know how to
|
|
7
|
+
* peek at the runtime's secret backends. That's painful for the secrets CLI:
|
|
8
|
+
* a user who already ran `vibes secrets set CLOUDFLARE_API_TOKEN ...` still
|
|
9
|
+
* has to manually re-export the same values in their shell before
|
|
10
|
+
* `vibes secrets push --to cloudflare-secrets-store` will succeed.
|
|
11
|
+
*
|
|
12
|
+
* `resolveCfCredentialKeys` builds an `envReader` map that prefers
|
|
13
|
+
* `process.env` (so CI / explicit overrides still win) and falls back to
|
|
14
|
+
* the first available local-tier `secrets/store` backend. Pass the returned
|
|
15
|
+
* map to the connector via `opts.envReader`.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { getVibesRuntime } from '@vibesdotdev/runtime';
|
|
19
|
+
|
|
20
|
+
const LOCAL_BACKEND_IDS = ['encrypted-local', 'env-file'] as const;
|
|
21
|
+
|
|
22
|
+
export async function resolveCfCredentialKeys(
|
|
23
|
+
keys: string[],
|
|
24
|
+
environment: string = 'local'
|
|
25
|
+
): Promise<Record<string, string | undefined>> {
|
|
26
|
+
const resolved: Record<string, string | undefined> = {};
|
|
27
|
+
const runtime = getVibesRuntime();
|
|
28
|
+
let localStore: { get(env: string, key: string): Promise<string | undefined> } | null = null;
|
|
29
|
+
|
|
30
|
+
if (runtime.hasKind('secrets/store')) {
|
|
31
|
+
for (const id of LOCAL_BACKEND_IDS) {
|
|
32
|
+
try {
|
|
33
|
+
const impl = (await runtime
|
|
34
|
+
.query('secrets/store')
|
|
35
|
+
.withId(id)
|
|
36
|
+
.resolve()) as { get?: (env: string, key: string) => Promise<string | undefined> };
|
|
37
|
+
if (impl && typeof impl.get === 'function') {
|
|
38
|
+
localStore = { get: impl.get.bind(impl) };
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
} catch {
|
|
42
|
+
// next candidate
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
for (const key of keys) {
|
|
48
|
+
const envValue = process.env[key];
|
|
49
|
+
if (envValue && envValue !== '') {
|
|
50
|
+
resolved[key] = envValue;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (localStore) {
|
|
54
|
+
try {
|
|
55
|
+
resolved[key] = await localStore.get(environment, key);
|
|
56
|
+
} catch {
|
|
57
|
+
resolved[key] = undefined;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return resolved;
|
|
63
|
+
}
|
package/src/web-app.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Workers + Static Assets Web App Deployment Module
|
|
3
|
+
*
|
|
4
|
+
* Public entrypoint for the canonical Vibes deploy target: Cloudflare Workers
|
|
5
|
+
* with a Static Assets binding (the @sveltejs/adapter-cloudflare shape).
|
|
6
|
+
* Pages-targeting consumers should import from `./pages` instead.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
createCloudflareWebAppDeployment,
|
|
11
|
+
generateCloudflareWebAppDescriptor,
|
|
12
|
+
CloudflareWebAppDescriptorSchema,
|
|
13
|
+
SHARED_BANDWIDTH_TELEMETRY_DATASET,
|
|
14
|
+
type CloudflareWebAppDeployment,
|
|
15
|
+
type CloudflareWebAppDescriptor,
|
|
16
|
+
type CloudflareWebAppDescriptorInput,
|
|
17
|
+
type WranglerWebAppConfig,
|
|
18
|
+
type WranglerWebAppRoute,
|
|
19
|
+
type WranglerWebAppAssets,
|
|
20
|
+
type WranglerSecretsStoreBinding,
|
|
21
|
+
type WranglerAnalyticsEngineBinding
|
|
22
|
+
} from './implementations/web-app.impl';
|
|
23
|
+
|
|
24
|
+
export { renderWranglerJson } from './implementations/pages.impl';
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
WEB_APP_HEADER_LINES,
|
|
28
|
+
isCloudflareWebAppDeployment,
|
|
29
|
+
renderManagedWranglerJsonc,
|
|
30
|
+
renderWranglerJsoncFromDefaultExport,
|
|
31
|
+
type WranglerRenderResult
|
|
32
|
+
} from './regen.ts';
|