Skip to content

Commit 037e8d4

Browse files
author
Frank
committed
wip: zen
1 parent 08a366c commit 037e8d4

File tree

24 files changed

+579
-511
lines changed

24 files changed

+579
-511
lines changed

github/sst-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
/// <reference path="../sst-env.d.ts" />
77

88
import "sst"
9-
export {}
9+
export {}

infra/console.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,12 @@ export const stripeWebhook = new stripe.WebhookEndpoint("StripeWebhookEndpoint",
9797
],
9898
})
9999

100-
const ZEN_MODELS1 = new sst.Secret("ZEN_MODELS1")
101-
const ZEN_MODELS2 = new sst.Secret("ZEN_MODELS2")
100+
const ZEN_MODELS = [
101+
new sst.Secret("ZEN_MODELS1"),
102+
new sst.Secret("ZEN_MODELS2"),
103+
new sst.Secret("ZEN_MODELS3"),
104+
new sst.Secret("ZEN_MODELS4"),
105+
]
102106
const STRIPE_SECRET_KEY = new sst.Secret("STRIPE_SECRET_KEY")
103107
const AUTH_API_URL = new sst.Linkable("AUTH_API_URL", {
104108
properties: { value: auth.url.apply((url) => url!) },
@@ -132,11 +136,10 @@ new sst.cloudflare.x.SolidStart("Console", {
132136
AUTH_API_URL,
133137
STRIPE_WEBHOOK_SECRET,
134138
STRIPE_SECRET_KEY,
135-
ZEN_MODELS1,
136-
ZEN_MODELS2,
137139
EMAILOCTOPUS_API_KEY,
138140
AWS_SES_ACCESS_KEY_ID,
139141
AWS_SES_SECRET_ACCESS_KEY,
142+
...ZEN_MODELS,
140143
...($dev
141144
? [
142145
new sst.Secret("CLOUDFLARE_DEFAULT_ACCOUNT_ID", process.env.CLOUDFLARE_DEFAULT_ACCOUNT_ID!),

packages/console/app/sst-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
/// <reference path="../../../sst-env.d.ts" />
77

88
import "sst"
9-
export {}
9+
export {}

packages/console/core/script/promote-models.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,21 @@ const root = path.resolve(process.cwd(), "..", "..", "..")
1111

1212
// read the secret
1313
const ret = await $`bun sst secret list`.cwd(root).text()
14-
const value1 = ret
15-
.split("\n")
16-
.find((line) => line.startsWith("ZEN_MODELS1"))
17-
?.split("=")[1]
18-
const value2 = ret
19-
.split("\n")
20-
.find((line) => line.startsWith("ZEN_MODELS2"))
21-
?.split("=")[1]
14+
const lines = ret.split("\n")
15+
const value1 = lines.find((line) => line.startsWith("ZEN_MODELS1"))?.split("=")[1]
16+
const value2 = lines.find((line) => line.startsWith("ZEN_MODELS2"))?.split("=")[1]
17+
const value3 = lines.find((line) => line.startsWith("ZEN_MODELS3"))?.split("=")[1]
18+
const value4 = lines.find((line) => line.startsWith("ZEN_MODELS4"))?.split("=")[1]
2219
if (!value1) throw new Error("ZEN_MODELS1 not found")
2320
if (!value2) throw new Error("ZEN_MODELS2 not found")
21+
if (!value3) throw new Error("ZEN_MODELS3 not found")
22+
if (!value4) throw new Error("ZEN_MODELS4 not found")
2423

2524
// validate value
26-
ZenData.validate(JSON.parse(value1 + value2))
25+
ZenData.validate(JSON.parse(value1 + value2 + value3 + value4))
2726

2827
// update the secret
2928
await $`bun sst secret set ZEN_MODELS1 ${value1} --stage ${stage}`
3029
await $`bun sst secret set ZEN_MODELS2 ${value2} --stage ${stage}`
30+
await $`bun sst secret set ZEN_MODELS3 ${value3} --stage ${stage}`
31+
await $`bun sst secret set ZEN_MODELS4 ${value4} --stage ${stage}`

packages/console/core/script/update-models.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@ const root = path.resolve(process.cwd(), "..", "..", "..")
99
const models = await $`bun sst secret list`.cwd(root).text()
1010

1111
// read the line starting with "ZEN_MODELS"
12-
const oldValue1 = models
13-
.split("\n")
14-
.find((line) => line.startsWith("ZEN_MODELS1"))
15-
?.split("=")[1]
16-
const oldValue2 = models
17-
.split("\n")
18-
.find((line) => line.startsWith("ZEN_MODELS2"))
19-
?.split("=")[1]
12+
const lines = models.split("\n")
13+
const oldValue1 = lines.find((line) => line.startsWith("ZEN_MODELS1"))?.split("=")[1]
14+
const oldValue2 = lines.find((line) => line.startsWith("ZEN_MODELS2"))?.split("=")[1]
15+
const oldValue3 = lines.find((line) => line.startsWith("ZEN_MODELS3"))?.split("=")[1]
16+
const oldValue4 = lines.find((line) => line.startsWith("ZEN_MODELS4"))?.split("=")[1]
2017
if (!oldValue1) throw new Error("ZEN_MODELS1 not found")
2118
if (!oldValue2) throw new Error("ZEN_MODELS2 not found")
19+
if (!oldValue3) throw new Error("ZEN_MODELS3 not found")
20+
if (!oldValue4) throw new Error("ZEN_MODELS4 not found")
2221

2322
// store the prettified json to a temp file
2423
const filename = `models-${Date.now()}.json`
2524
const tempFile = Bun.file(path.join(os.tmpdir(), filename))
26-
await tempFile.write(JSON.stringify(JSON.parse(oldValue1 + oldValue2), null, 2))
25+
await tempFile.write(JSON.stringify(JSON.parse(oldValue1 + oldValue2 + oldValue3 + oldValue4), null, 2))
2726
console.log("tempFile", tempFile.name)
2827

2928
// open temp file in vim and read the file on close
@@ -32,6 +31,12 @@ const newValue = JSON.stringify(JSON.parse(await tempFile.text()))
3231
ZenData.validate(JSON.parse(newValue))
3332

3433
// update the secret
35-
const mid = Math.floor(newValue.length / 2)
36-
await $`bun sst secret set ZEN_MODELS1 ${newValue.slice(0, mid)}`
37-
await $`bun sst secret set ZEN_MODELS2 ${newValue.slice(mid)}`
34+
const chunk = Math.ceil(newValue.length / 4)
35+
const newValue1 = newValue.slice(0, chunk)
36+
const newValue2 = newValue.slice(chunk, chunk * 2)
37+
const newValue3 = newValue.slice(chunk * 2, chunk * 3)
38+
const newValue4 = newValue.slice(chunk * 3)
39+
await $`bun sst secret set ZEN_MODELS1 ${newValue1}`
40+
await $`bun sst secret set ZEN_MODELS2 ${newValue2}`
41+
await $`bun sst secret set ZEN_MODELS3 ${newValue3}`
42+
await $`bun sst secret set ZEN_MODELS4 ${newValue4}`

packages/console/core/src/model.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export namespace ZenData {
5353
})
5454

5555
export const list = fn(z.void(), () => {
56-
const json = JSON.parse(Resource.ZEN_MODELS1.value + Resource.ZEN_MODELS2.value)
56+
const json = JSON.parse(
57+
Resource.ZEN_MODELS1.value + Resource.ZEN_MODELS2.value + Resource.ZEN_MODELS3.value + Resource.ZEN_MODELS4.value,
58+
)
5759
return ModelsSchema.parse(json)
5860
})
5961
}

packages/console/core/sst-env.d.ts

Lines changed: 104 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -6,108 +6,116 @@
66
import "sst"
77
declare module "sst" {
88
export interface Resource {
9-
ADMIN_SECRET: {
10-
type: "sst.sst.Secret"
11-
value: string
12-
}
13-
AUTH_API_URL: {
14-
type: "sst.sst.Linkable"
15-
value: string
16-
}
17-
AWS_SES_ACCESS_KEY_ID: {
18-
type: "sst.sst.Secret"
19-
value: string
20-
}
21-
AWS_SES_SECRET_ACCESS_KEY: {
22-
type: "sst.sst.Secret"
23-
value: string
24-
}
25-
CLOUDFLARE_API_TOKEN: {
26-
type: "sst.sst.Secret"
27-
value: string
28-
}
29-
CLOUDFLARE_DEFAULT_ACCOUNT_ID: {
30-
type: "sst.sst.Secret"
31-
value: string
32-
}
33-
Console: {
34-
type: "sst.cloudflare.SolidStart"
35-
url: string
36-
}
37-
Database: {
38-
database: string
39-
host: string
40-
password: string
41-
port: number
42-
type: "sst.sst.Linkable"
43-
username: string
44-
}
45-
Desktop: {
46-
type: "sst.cloudflare.StaticSite"
47-
url: string
48-
}
49-
EMAILOCTOPUS_API_KEY: {
50-
type: "sst.sst.Secret"
51-
value: string
52-
}
53-
GITHUB_APP_ID: {
54-
type: "sst.sst.Secret"
55-
value: string
56-
}
57-
GITHUB_APP_PRIVATE_KEY: {
58-
type: "sst.sst.Secret"
59-
value: string
60-
}
61-
GITHUB_CLIENT_ID_CONSOLE: {
62-
type: "sst.sst.Secret"
63-
value: string
64-
}
65-
GITHUB_CLIENT_SECRET_CONSOLE: {
66-
type: "sst.sst.Secret"
67-
value: string
68-
}
69-
GOOGLE_CLIENT_ID: {
70-
type: "sst.sst.Secret"
71-
value: string
72-
}
73-
HONEYCOMB_API_KEY: {
74-
type: "sst.sst.Secret"
75-
value: string
76-
}
77-
STRIPE_SECRET_KEY: {
78-
type: "sst.sst.Secret"
79-
value: string
80-
}
81-
STRIPE_WEBHOOK_SECRET: {
82-
type: "sst.sst.Linkable"
83-
value: string
84-
}
85-
Web: {
86-
type: "sst.cloudflare.Astro"
87-
url: string
88-
}
89-
ZEN_MODELS1: {
90-
type: "sst.sst.Secret"
91-
value: string
92-
}
93-
ZEN_MODELS2: {
94-
type: "sst.sst.Secret"
95-
value: string
9+
"ADMIN_SECRET": {
10+
"type": "sst.sst.Secret"
11+
"value": string
12+
}
13+
"AUTH_API_URL": {
14+
"type": "sst.sst.Linkable"
15+
"value": string
16+
}
17+
"AWS_SES_ACCESS_KEY_ID": {
18+
"type": "sst.sst.Secret"
19+
"value": string
20+
}
21+
"AWS_SES_SECRET_ACCESS_KEY": {
22+
"type": "sst.sst.Secret"
23+
"value": string
24+
}
25+
"CLOUDFLARE_API_TOKEN": {
26+
"type": "sst.sst.Secret"
27+
"value": string
28+
}
29+
"CLOUDFLARE_DEFAULT_ACCOUNT_ID": {
30+
"type": "sst.sst.Secret"
31+
"value": string
32+
}
33+
"Console": {
34+
"type": "sst.cloudflare.SolidStart"
35+
"url": string
36+
}
37+
"Database": {
38+
"database": string
39+
"host": string
40+
"password": string
41+
"port": number
42+
"type": "sst.sst.Linkable"
43+
"username": string
44+
}
45+
"Desktop": {
46+
"type": "sst.cloudflare.StaticSite"
47+
"url": string
48+
}
49+
"EMAILOCTOPUS_API_KEY": {
50+
"type": "sst.sst.Secret"
51+
"value": string
52+
}
53+
"GITHUB_APP_ID": {
54+
"type": "sst.sst.Secret"
55+
"value": string
56+
}
57+
"GITHUB_APP_PRIVATE_KEY": {
58+
"type": "sst.sst.Secret"
59+
"value": string
60+
}
61+
"GITHUB_CLIENT_ID_CONSOLE": {
62+
"type": "sst.sst.Secret"
63+
"value": string
64+
}
65+
"GITHUB_CLIENT_SECRET_CONSOLE": {
66+
"type": "sst.sst.Secret"
67+
"value": string
68+
}
69+
"GOOGLE_CLIENT_ID": {
70+
"type": "sst.sst.Secret"
71+
"value": string
72+
}
73+
"HONEYCOMB_API_KEY": {
74+
"type": "sst.sst.Secret"
75+
"value": string
76+
}
77+
"STRIPE_SECRET_KEY": {
78+
"type": "sst.sst.Secret"
79+
"value": string
80+
}
81+
"STRIPE_WEBHOOK_SECRET": {
82+
"type": "sst.sst.Linkable"
83+
"value": string
84+
}
85+
"Web": {
86+
"type": "sst.cloudflare.Astro"
87+
"url": string
88+
}
89+
"ZEN_MODELS1": {
90+
"type": "sst.sst.Secret"
91+
"value": string
92+
}
93+
"ZEN_MODELS2": {
94+
"type": "sst.sst.Secret"
95+
"value": string
96+
}
97+
"ZEN_MODELS3": {
98+
"type": "sst.sst.Secret"
99+
"value": string
100+
}
101+
"ZEN_MODELS4": {
102+
"type": "sst.sst.Secret"
103+
"value": string
96104
}
97105
}
98106
}
99-
// cloudflare
100-
import * as cloudflare from "@cloudflare/workers-types"
107+
// cloudflare
108+
import * as cloudflare from "@cloudflare/workers-types";
101109
declare module "sst" {
102110
export interface Resource {
103-
Api: cloudflare.Service
104-
AuthApi: cloudflare.Service
105-
AuthStorage: cloudflare.KVNamespace
106-
Bucket: cloudflare.R2Bucket
107-
GatewayKv: cloudflare.KVNamespace
108-
LogProcessor: cloudflare.Service
111+
"Api": cloudflare.Service
112+
"AuthApi": cloudflare.Service
113+
"AuthStorage": cloudflare.KVNamespace
114+
"Bucket": cloudflare.R2Bucket
115+
"GatewayKv": cloudflare.KVNamespace
116+
"LogProcessor": cloudflare.Service
109117
}
110118
}
111119

112120
import "sst"
113-
export {}
121+
export {}

0 commit comments

Comments
 (0)