summaryrefslogtreecommitdiffhomepage
path: root/packages/console/resource
diff options
context:
space:
mode:
authorDavid Hill <[email protected]>2025-11-10 13:44:12 +0000
committerDavid Hill <[email protected]>2025-11-10 13:44:12 +0000
commitc6e830c954418808dc39284a1c073aa63a6d4d21 (patch)
tree9c3052e0509115188768a553c0be5a8441ebdd96 /packages/console/resource
parent7088bfabd773e2f076aab1c9d2468c04feff0570 (diff)
parentfc78c28df64383a9f99382093f61fc28caf6569f (diff)
downloadopencode-c6e830c954418808dc39284a1c073aa63a6d4d21.tar.gz
opencode-c6e830c954418808dc39284a1c073aa63a6d4d21.zip
Merge branch 'dev' of https://github.com/sst/opencode into dev
Diffstat (limited to 'packages/console/resource')
-rw-r--r--packages/console/resource/package.json5
-rw-r--r--packages/console/resource/resource.node.ts59
-rw-r--r--packages/console/resource/sst-env.d.ts183
3 files changed, 158 insertions, 89 deletions
diff --git a/packages/console/resource/package.json b/packages/console/resource/package.json
index 6553feed1..f110f6c2a 100644
--- a/packages/console/resource/package.json
+++ b/packages/console/resource/package.json
@@ -13,6 +13,9 @@
}
},
"devDependencies": {
- "@tsconfig/node22": "22.0.2"
+ "@cloudflare/workers-types": "catalog:",
+ "@tsconfig/node22": "22.0.2",
+ "@types/node": "catalog:",
+ "cloudflare": "5.2.0"
}
}
diff --git a/packages/console/resource/resource.node.ts b/packages/console/resource/resource.node.ts
index d7dbb6c6d..f63d7bada 100644
--- a/packages/console/resource/resource.node.ts
+++ b/packages/console/resource/resource.node.ts
@@ -1 +1,58 @@
-export { Resource } from "sst"
+import type { KVNamespaceListOptions, KVNamespaceListResult, KVNamespacePutOptions } from "@cloudflare/workers-types"
+import { Resource as ResourceBase } from "sst"
+import Cloudflare from "cloudflare"
+
+export const Resource = new Proxy(
+ {},
+ {
+ get(_target, prop: keyof typeof ResourceBase) {
+ const value = ResourceBase[prop]
+ // @ts-ignore
+ if ("type" in value && value.type === "sst.cloudflare.Kv") {
+ const client = new Cloudflare({
+ apiToken: ResourceBase.CLOUDFLARE_API_TOKEN.value,
+ })
+ // @ts-ignore
+ const namespaceId = value.namespaceId
+ const accountId = ResourceBase.CLOUDFLARE_DEFAULT_ACCOUNT_ID.value
+ return {
+ get: (k: string | string[]) => {
+ const isMulti = Array.isArray(k)
+ return client.kv.namespaces
+ .bulkGet(namespaceId, {
+ keys: Array.isArray(k) ? k : [k],
+ account_id: accountId,
+ })
+ .then((result) => (isMulti ? new Map(Object.entries(result?.values ?? {})) : result?.values?.[k]))
+ },
+ put: (k: string, v: string, opts?: KVNamespacePutOptions) =>
+ client.kv.namespaces.values.update(namespaceId, k, {
+ account_id: accountId,
+ value: v,
+ expiration: opts?.expiration,
+ expiration_ttl: opts?.expirationTtl,
+ metadata: opts?.metadata,
+ }),
+ delete: (k: string) =>
+ client.kv.namespaces.values.delete(namespaceId, k, {
+ account_id: accountId,
+ }),
+ list: (opts?: KVNamespaceListOptions): Promise<KVNamespaceListResult<unknown, string>> =>
+ client.kv.namespaces.keys
+ .list(namespaceId, {
+ account_id: accountId,
+ prefix: opts?.prefix ?? undefined,
+ })
+ .then((result) => {
+ return {
+ keys: result.result,
+ list_complete: true,
+ cacheStatus: null,
+ }
+ }),
+ }
+ }
+ return value
+ },
+ },
+) as Record<string, any>
diff --git a/packages/console/resource/sst-env.d.ts b/packages/console/resource/sst-env.d.ts
index 01407434e..bcd7c2650 100644
--- a/packages/console/resource/sst-env.d.ts
+++ b/packages/console/resource/sst-env.d.ts
@@ -6,99 +6,108 @@
import "sst"
declare module "sst" {
export interface Resource {
- "ADMIN_SECRET": {
- "type": "sst.sst.Secret"
- "value": string
- }
- "AUTH_API_URL": {
- "type": "sst.sst.Linkable"
- "value": string
- }
- "AWS_SES_ACCESS_KEY_ID": {
- "type": "sst.sst.Secret"
- "value": string
- }
- "AWS_SES_SECRET_ACCESS_KEY": {
- "type": "sst.sst.Secret"
- "value": string
- }
- "Console": {
- "type": "sst.cloudflare.SolidStart"
- "url": string
- }
- "Database": {
- "database": string
- "host": string
- "password": string
- "port": number
- "type": "sst.sst.Linkable"
- "username": string
- }
- "Desktop": {
- "type": "sst.cloudflare.StaticSite"
- "url": string
- }
- "EMAILOCTOPUS_API_KEY": {
- "type": "sst.sst.Secret"
- "value": string
- }
- "GITHUB_APP_ID": {
- "type": "sst.sst.Secret"
- "value": string
- }
- "GITHUB_APP_PRIVATE_KEY": {
- "type": "sst.sst.Secret"
- "value": string
- }
- "GITHUB_CLIENT_ID_CONSOLE": {
- "type": "sst.sst.Secret"
- "value": string
- }
- "GITHUB_CLIENT_SECRET_CONSOLE": {
- "type": "sst.sst.Secret"
- "value": string
- }
- "GOOGLE_CLIENT_ID": {
- "type": "sst.sst.Secret"
- "value": string
- }
- "HONEYCOMB_API_KEY": {
- "type": "sst.sst.Secret"
- "value": string
- }
- "STRIPE_SECRET_KEY": {
- "type": "sst.sst.Secret"
- "value": string
- }
- "STRIPE_WEBHOOK_SECRET": {
- "type": "sst.sst.Linkable"
- "value": string
- }
- "Web": {
- "type": "sst.cloudflare.Astro"
- "url": string
- }
- "ZEN_MODELS1": {
- "type": "sst.sst.Secret"
- "value": string
- }
- "ZEN_MODELS2": {
- "type": "sst.sst.Secret"
- "value": string
+ ADMIN_SECRET: {
+ type: "sst.sst.Secret"
+ value: string
+ }
+ AUTH_API_URL: {
+ type: "sst.sst.Linkable"
+ value: string
+ }
+ AWS_SES_ACCESS_KEY_ID: {
+ type: "sst.sst.Secret"
+ value: string
+ }
+ AWS_SES_SECRET_ACCESS_KEY: {
+ type: "sst.sst.Secret"
+ value: string
+ }
+ CLOUDFLARE_API_TOKEN: {
+ type: "sst.sst.Secret"
+ value: string
+ }
+ CLOUDFLARE_DEFAULT_ACCOUNT_ID: {
+ type: "sst.sst.Secret"
+ value: string
+ }
+ Console: {
+ type: "sst.cloudflare.SolidStart"
+ url: string
+ }
+ Database: {
+ database: string
+ host: string
+ password: string
+ port: number
+ type: "sst.sst.Linkable"
+ username: string
+ }
+ Desktop: {
+ type: "sst.cloudflare.StaticSite"
+ url: string
+ }
+ EMAILOCTOPUS_API_KEY: {
+ type: "sst.sst.Secret"
+ value: string
+ }
+ GITHUB_APP_ID: {
+ type: "sst.sst.Secret"
+ value: string
+ }
+ GITHUB_APP_PRIVATE_KEY: {
+ type: "sst.sst.Secret"
+ value: string
+ }
+ GITHUB_CLIENT_ID_CONSOLE: {
+ type: "sst.sst.Secret"
+ value: string
+ }
+ GITHUB_CLIENT_SECRET_CONSOLE: {
+ type: "sst.sst.Secret"
+ value: string
+ }
+ GOOGLE_CLIENT_ID: {
+ type: "sst.sst.Secret"
+ value: string
+ }
+ HONEYCOMB_API_KEY: {
+ type: "sst.sst.Secret"
+ value: string
+ }
+ STRIPE_SECRET_KEY: {
+ type: "sst.sst.Secret"
+ value: string
+ }
+ STRIPE_WEBHOOK_SECRET: {
+ type: "sst.sst.Linkable"
+ value: string
+ }
+ Web: {
+ type: "sst.cloudflare.Astro"
+ url: string
+ }
+ ZEN_MODELS1: {
+ type: "sst.sst.Secret"
+ value: string
+ }
+ ZEN_MODELS2: {
+ type: "sst.sst.Secret"
+ value: string
}
}
}
-// cloudflare
-import * as cloudflare from "@cloudflare/workers-types";
+// cloudflare
+import * as cloudflare from "@cloudflare/workers-types"
declare module "sst" {
export interface Resource {
- "Api": cloudflare.Service
- "AuthApi": cloudflare.Service
- "AuthStorage": cloudflare.KVNamespace
- "Bucket": cloudflare.R2Bucket
- "LogProcessor": cloudflare.Service
+ Api: cloudflare.Service
+ AuthApi: cloudflare.Service
+ AuthStorage: cloudflare.KVNamespace
+ Bucket: cloudflare.R2Bucket
+ GatewayKv: cloudflare.KVNamespace
+ LogProcessor: cloudflare.Service
}
}
import "sst"
-export {} \ No newline at end of file
+export {}