summaryrefslogtreecommitdiffhomepage
path: root/packages/console/resource
diff options
context:
space:
mode:
authorFrank <[email protected]>2025-11-08 10:15:35 -0500
committerFrank <[email protected]>2025-11-08 10:18:21 -0500
commit30b1ae5d4b071f5637c1a590a177b5017a28c90b (patch)
treeaf56c9b48a7fa59baab65fa7d1a26dfc8ea1cf79 /packages/console/resource
parent9cd465f9c0702ebedf29b3386c555d9bc4da8306 (diff)
downloadopencode-30b1ae5d4b071f5637c1a590a177b5017a28c90b.tar.gz
opencode-30b1ae5d4b071f5637c1a590a177b5017a28c90b.zip
zen: rate limit
Diffstat (limited to 'packages/console/resource')
-rw-r--r--packages/console/resource/package.json5
-rw-r--r--packages/console/resource/resource.node.ts65
-rw-r--r--packages/console/resource/sst-env.d.ts183
3 files changed, 164 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..2369eab98 100644
--- a/packages/console/resource/resource.node.ts
+++ b/packages/console/resource/resource.node.ts
@@ -1 +1,64 @@
-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 ba4c5a623..63c2af977 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 {}
+export {} \ No newline at end of file