@decocms/runtime 0.28.1 → 1.0.0-alpha-candy.2

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.
Files changed (97) hide show
  1. package/package.json +12 -78
  2. package/scripts/generate-json-schema.ts +24 -0
  3. package/src/asset-server/dev-server-proxy.ts +16 -0
  4. package/src/asset-server/index.ts +44 -0
  5. package/src/bindings/README.md +1 -1
  6. package/src/bindings/binder.ts +2 -5
  7. package/src/bindings/channels.ts +1 -1
  8. package/src/bindings/index.ts +0 -33
  9. package/src/bindings/language-model/utils.ts +0 -91
  10. package/src/bindings.ts +30 -108
  11. package/src/client.ts +1 -145
  12. package/src/index.ts +46 -175
  13. package/src/mcp.ts +8 -165
  14. package/src/proxy.ts +3 -62
  15. package/src/state.ts +1 -30
  16. package/src/tools.ts +336 -0
  17. package/src/wrangler.ts +5 -5
  18. package/tsconfig.json +8 -0
  19. package/dist/admin.d.ts +0 -5
  20. package/dist/admin.js +0 -21
  21. package/dist/admin.js.map +0 -1
  22. package/dist/bindings/deconfig/index.d.ts +0 -12
  23. package/dist/bindings/deconfig/index.js +0 -10
  24. package/dist/bindings/deconfig/index.js.map +0 -1
  25. package/dist/bindings/index.d.ts +0 -2315
  26. package/dist/bindings/index.js +0 -156
  27. package/dist/bindings/index.js.map +0 -1
  28. package/dist/chunk-3AWMDSOH.js +0 -96
  29. package/dist/chunk-3AWMDSOH.js.map +0 -1
  30. package/dist/chunk-4XSQKJLU.js +0 -105
  31. package/dist/chunk-4XSQKJLU.js.map +0 -1
  32. package/dist/chunk-5EYZ2LVM.js +0 -158
  33. package/dist/chunk-5EYZ2LVM.js.map +0 -1
  34. package/dist/chunk-7ITSLORK.js +0 -128
  35. package/dist/chunk-7ITSLORK.js.map +0 -1
  36. package/dist/chunk-I7BWSAN6.js +0 -49
  37. package/dist/chunk-I7BWSAN6.js.map +0 -1
  38. package/dist/chunk-L4OT2YDO.js +0 -27
  39. package/dist/chunk-L4OT2YDO.js.map +0 -1
  40. package/dist/chunk-SHQSNOFL.js +0 -769
  41. package/dist/chunk-SHQSNOFL.js.map +0 -1
  42. package/dist/chunk-UHR3BLMF.js +0 -92
  43. package/dist/chunk-UHR3BLMF.js.map +0 -1
  44. package/dist/chunk-UIJGM3NV.js +0 -518
  45. package/dist/chunk-UIJGM3NV.js.map +0 -1
  46. package/dist/chunk-ZPUT6RN6.js +0 -32
  47. package/dist/chunk-ZPUT6RN6.js.map +0 -1
  48. package/dist/client.d.ts +0 -28
  49. package/dist/client.js +0 -5
  50. package/dist/client.js.map +0 -1
  51. package/dist/d1-store.d.ts +0 -9
  52. package/dist/d1-store.js +0 -4
  53. package/dist/d1-store.js.map +0 -1
  54. package/dist/drizzle.d.ts +0 -49
  55. package/dist/drizzle.js +0 -121
  56. package/dist/drizzle.js.map +0 -1
  57. package/dist/index-LOfgE9a_.d.ts +0 -471
  58. package/dist/index-xKtm7A7B.d.ts +0 -530
  59. package/dist/index.d.ts +0 -10
  60. package/dist/index.js +0 -637
  61. package/dist/index.js.map +0 -1
  62. package/dist/mastra.d.ts +0 -10
  63. package/dist/mastra.js +0 -6
  64. package/dist/mastra.js.map +0 -1
  65. package/dist/mcp-87iLaW9V.d.ts +0 -105
  66. package/dist/mcp-client.d.ts +0 -232
  67. package/dist/mcp-client.js +0 -4
  68. package/dist/mcp-client.js.map +0 -1
  69. package/dist/proxy.d.ts +0 -11
  70. package/dist/proxy.js +0 -5
  71. package/dist/proxy.js.map +0 -1
  72. package/dist/resources.d.ts +0 -362
  73. package/dist/resources.js +0 -4
  74. package/dist/resources.js.map +0 -1
  75. package/dist/views.d.ts +0 -72
  76. package/dist/views.js +0 -4
  77. package/dist/views.js.map +0 -1
  78. package/src/admin.ts +0 -16
  79. package/src/auth.ts +0 -233
  80. package/src/bindings/deconfig/helpers.ts +0 -107
  81. package/src/bindings/deconfig/index.ts +0 -1
  82. package/src/bindings/deconfig/resources.ts +0 -659
  83. package/src/bindings/deconfig/types.ts +0 -106
  84. package/src/bindings/language-model/ai-sdk.ts +0 -87
  85. package/src/bindings/language-model/index.ts +0 -4
  86. package/src/bindings/resources/bindings.ts +0 -99
  87. package/src/bindings/resources/helpers.ts +0 -95
  88. package/src/bindings/resources/schemas.ts +0 -265
  89. package/src/bindings/views.ts +0 -14
  90. package/src/cf-imports.ts +0 -1
  91. package/src/d1-store.ts +0 -34
  92. package/src/deprecated.ts +0 -59
  93. package/src/drizzle.ts +0 -201
  94. package/src/mastra.ts +0 -898
  95. package/src/resources.ts +0 -168
  96. package/src/views.ts +0 -26
  97. package/src/workflow.ts +0 -193
@@ -1,362 +0,0 @@
1
- import { z } from 'zod/v3';
2
-
3
- declare const ResourcesReadInputSchema: z.ZodObject<{
4
- name: z.ZodString;
5
- uri: z.ZodString;
6
- }, "strip", z.ZodTypeAny, {
7
- name: string;
8
- uri: string;
9
- }, {
10
- name: string;
11
- uri: string;
12
- }>;
13
- declare const ResourcesReadOutputSchema: z.ZodObject<{
14
- name: z.ZodString;
15
- title: z.ZodOptional<z.ZodString>;
16
- description: z.ZodOptional<z.ZodString>;
17
- uri: z.ZodString;
18
- mimeType: z.ZodOptional<z.ZodString>;
19
- thumbnail: z.ZodOptional<z.ZodString>;
20
- timestamp: z.ZodOptional<z.ZodString>;
21
- size: z.ZodOptional<z.ZodNumber>;
22
- annotations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
23
- } & {
24
- data: z.ZodString;
25
- type: z.ZodEnum<["text", "blob"]>;
26
- }, "strip", z.ZodTypeAny, {
27
- type: "text" | "blob";
28
- name: string;
29
- data: string;
30
- uri: string;
31
- description?: string | undefined;
32
- mimeType?: string | undefined;
33
- title?: string | undefined;
34
- annotations?: Record<string, string> | undefined;
35
- thumbnail?: string | undefined;
36
- timestamp?: string | undefined;
37
- size?: number | undefined;
38
- }, {
39
- type: "text" | "blob";
40
- name: string;
41
- data: string;
42
- uri: string;
43
- description?: string | undefined;
44
- mimeType?: string | undefined;
45
- title?: string | undefined;
46
- annotations?: Record<string, string> | undefined;
47
- thumbnail?: string | undefined;
48
- timestamp?: string | undefined;
49
- size?: number | undefined;
50
- }>;
51
- declare const ResourceSearchInputSchema: z.ZodObject<{
52
- name: z.ZodString;
53
- term: z.ZodString;
54
- cursor: z.ZodOptional<z.ZodString>;
55
- limit: z.ZodOptional<z.ZodNumber>;
56
- }, "strip", z.ZodTypeAny, {
57
- name: string;
58
- term: string;
59
- cursor?: string | undefined;
60
- limit?: number | undefined;
61
- }, {
62
- name: string;
63
- term: string;
64
- cursor?: string | undefined;
65
- limit?: number | undefined;
66
- }>;
67
- declare const ResourceSearchOutputSchema: z.ZodObject<{
68
- items: z.ZodArray<z.ZodObject<{
69
- name: z.ZodString;
70
- title: z.ZodOptional<z.ZodString>;
71
- description: z.ZodOptional<z.ZodString>;
72
- uri: z.ZodString;
73
- mimeType: z.ZodOptional<z.ZodString>;
74
- thumbnail: z.ZodOptional<z.ZodString>;
75
- timestamp: z.ZodOptional<z.ZodString>;
76
- size: z.ZodOptional<z.ZodNumber>;
77
- annotations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
78
- }, "strip", z.ZodTypeAny, {
79
- name: string;
80
- uri: string;
81
- description?: string | undefined;
82
- mimeType?: string | undefined;
83
- title?: string | undefined;
84
- annotations?: Record<string, string> | undefined;
85
- thumbnail?: string | undefined;
86
- timestamp?: string | undefined;
87
- size?: number | undefined;
88
- }, {
89
- name: string;
90
- uri: string;
91
- description?: string | undefined;
92
- mimeType?: string | undefined;
93
- title?: string | undefined;
94
- annotations?: Record<string, string> | undefined;
95
- thumbnail?: string | undefined;
96
- timestamp?: string | undefined;
97
- size?: number | undefined;
98
- }>, "many">;
99
- hasMore: z.ZodBoolean;
100
- nextCursor: z.ZodOptional<z.ZodString>;
101
- }, "strip", z.ZodTypeAny, {
102
- items: {
103
- name: string;
104
- uri: string;
105
- description?: string | undefined;
106
- mimeType?: string | undefined;
107
- title?: string | undefined;
108
- annotations?: Record<string, string> | undefined;
109
- thumbnail?: string | undefined;
110
- timestamp?: string | undefined;
111
- size?: number | undefined;
112
- }[];
113
- hasMore: boolean;
114
- nextCursor?: string | undefined;
115
- }, {
116
- items: {
117
- name: string;
118
- uri: string;
119
- description?: string | undefined;
120
- mimeType?: string | undefined;
121
- title?: string | undefined;
122
- annotations?: Record<string, string> | undefined;
123
- thumbnail?: string | undefined;
124
- timestamp?: string | undefined;
125
- size?: number | undefined;
126
- }[];
127
- hasMore: boolean;
128
- nextCursor?: string | undefined;
129
- }>;
130
- declare const ResourceCreateInputSchema: z.ZodObject<{
131
- name: z.ZodString;
132
- resourceName: z.ZodString;
133
- title: z.ZodOptional<z.ZodString>;
134
- description: z.ZodOptional<z.ZodString>;
135
- content: z.ZodObject<{
136
- data: z.ZodString;
137
- type: z.ZodEnum<["text", "blob"]>;
138
- mimeType: z.ZodOptional<z.ZodString>;
139
- }, "strip", z.ZodTypeAny, {
140
- type: "text" | "blob";
141
- data: string;
142
- mimeType?: string | undefined;
143
- }, {
144
- type: "text" | "blob";
145
- data: string;
146
- mimeType?: string | undefined;
147
- }>;
148
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
149
- }, "strip", z.ZodTypeAny, {
150
- name: string;
151
- resourceName: string;
152
- content: {
153
- type: "text" | "blob";
154
- data: string;
155
- mimeType?: string | undefined;
156
- };
157
- description?: string | undefined;
158
- metadata?: Record<string, any> | undefined;
159
- title?: string | undefined;
160
- }, {
161
- name: string;
162
- resourceName: string;
163
- content: {
164
- type: "text" | "blob";
165
- data: string;
166
- mimeType?: string | undefined;
167
- };
168
- description?: string | undefined;
169
- metadata?: Record<string, any> | undefined;
170
- title?: string | undefined;
171
- }>;
172
- declare const ResourceCreateOutputSchema: z.ZodObject<{
173
- name: z.ZodString;
174
- title: z.ZodOptional<z.ZodString>;
175
- description: z.ZodOptional<z.ZodString>;
176
- uri: z.ZodString;
177
- mimeType: z.ZodOptional<z.ZodString>;
178
- thumbnail: z.ZodOptional<z.ZodString>;
179
- timestamp: z.ZodOptional<z.ZodString>;
180
- size: z.ZodOptional<z.ZodNumber>;
181
- annotations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
182
- }, "strip", z.ZodTypeAny, {
183
- name: string;
184
- uri: string;
185
- description?: string | undefined;
186
- mimeType?: string | undefined;
187
- title?: string | undefined;
188
- annotations?: Record<string, string> | undefined;
189
- thumbnail?: string | undefined;
190
- timestamp?: string | undefined;
191
- size?: number | undefined;
192
- }, {
193
- name: string;
194
- uri: string;
195
- description?: string | undefined;
196
- mimeType?: string | undefined;
197
- title?: string | undefined;
198
- annotations?: Record<string, string> | undefined;
199
- thumbnail?: string | undefined;
200
- timestamp?: string | undefined;
201
- size?: number | undefined;
202
- }>;
203
- declare const ResourceUpdateInputSchema: z.ZodObject<{
204
- name: z.ZodString;
205
- uri: z.ZodString;
206
- resourceName: z.ZodOptional<z.ZodString>;
207
- title: z.ZodOptional<z.ZodString>;
208
- description: z.ZodOptional<z.ZodString>;
209
- content: z.ZodOptional<z.ZodObject<{
210
- data: z.ZodString;
211
- type: z.ZodEnum<["text", "blob"]>;
212
- mimeType: z.ZodOptional<z.ZodString>;
213
- }, "strip", z.ZodTypeAny, {
214
- type: "text" | "blob";
215
- data: string;
216
- mimeType?: string | undefined;
217
- }, {
218
- type: "text" | "blob";
219
- data: string;
220
- mimeType?: string | undefined;
221
- }>>;
222
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
223
- }, "strip", z.ZodTypeAny, {
224
- name: string;
225
- uri: string;
226
- description?: string | undefined;
227
- resourceName?: string | undefined;
228
- metadata?: Record<string, any> | undefined;
229
- content?: {
230
- type: "text" | "blob";
231
- data: string;
232
- mimeType?: string | undefined;
233
- } | undefined;
234
- title?: string | undefined;
235
- }, {
236
- name: string;
237
- uri: string;
238
- description?: string | undefined;
239
- resourceName?: string | undefined;
240
- metadata?: Record<string, any> | undefined;
241
- content?: {
242
- type: "text" | "blob";
243
- data: string;
244
- mimeType?: string | undefined;
245
- } | undefined;
246
- title?: string | undefined;
247
- }>;
248
- declare const ResourceUpdateOutputSchema: z.ZodObject<{
249
- name: z.ZodString;
250
- title: z.ZodOptional<z.ZodString>;
251
- description: z.ZodOptional<z.ZodString>;
252
- uri: z.ZodString;
253
- mimeType: z.ZodOptional<z.ZodString>;
254
- thumbnail: z.ZodOptional<z.ZodString>;
255
- timestamp: z.ZodOptional<z.ZodString>;
256
- size: z.ZodOptional<z.ZodNumber>;
257
- annotations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
258
- }, "strip", z.ZodTypeAny, {
259
- name: string;
260
- uri: string;
261
- description?: string | undefined;
262
- mimeType?: string | undefined;
263
- title?: string | undefined;
264
- annotations?: Record<string, string> | undefined;
265
- thumbnail?: string | undefined;
266
- timestamp?: string | undefined;
267
- size?: number | undefined;
268
- }, {
269
- name: string;
270
- uri: string;
271
- description?: string | undefined;
272
- mimeType?: string | undefined;
273
- title?: string | undefined;
274
- annotations?: Record<string, string> | undefined;
275
- thumbnail?: string | undefined;
276
- timestamp?: string | undefined;
277
- size?: number | undefined;
278
- }>;
279
- declare const ResourceDeleteInputSchema: z.ZodObject<{
280
- name: z.ZodString;
281
- uri: z.ZodString;
282
- force: z.ZodOptional<z.ZodBoolean>;
283
- }, "strip", z.ZodTypeAny, {
284
- name: string;
285
- uri: string;
286
- force?: boolean | undefined;
287
- }, {
288
- name: string;
289
- uri: string;
290
- force?: boolean | undefined;
291
- }>;
292
- declare const ResourceDeleteOutputSchema: z.ZodObject<{
293
- deletedUri: z.ZodString;
294
- }, "strip", z.ZodTypeAny, {
295
- deletedUri: string;
296
- }, {
297
- deletedUri: string;
298
- }>;
299
- declare const ResourcesListInputSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
300
- declare const ResourcesListOutputSchema: z.ZodObject<{
301
- resources: z.ZodArray<z.ZodObject<{
302
- name: z.ZodString;
303
- icon: z.ZodString;
304
- title: z.ZodString;
305
- description: z.ZodString;
306
- hasCreate: z.ZodOptional<z.ZodBoolean>;
307
- hasUpdate: z.ZodOptional<z.ZodBoolean>;
308
- hasDelete: z.ZodOptional<z.ZodBoolean>;
309
- }, "strip", z.ZodTypeAny, {
310
- name: string;
311
- description: string;
312
- title: string;
313
- icon: string;
314
- hasCreate?: boolean | undefined;
315
- hasUpdate?: boolean | undefined;
316
- hasDelete?: boolean | undefined;
317
- }, {
318
- name: string;
319
- description: string;
320
- title: string;
321
- icon: string;
322
- hasCreate?: boolean | undefined;
323
- hasUpdate?: boolean | undefined;
324
- hasDelete?: boolean | undefined;
325
- }>, "many">;
326
- }, "strip", z.ZodTypeAny, {
327
- resources: {
328
- name: string;
329
- description: string;
330
- title: string;
331
- icon: string;
332
- hasCreate?: boolean | undefined;
333
- hasUpdate?: boolean | undefined;
334
- hasDelete?: boolean | undefined;
335
- }[];
336
- }, {
337
- resources: {
338
- name: string;
339
- description: string;
340
- title: string;
341
- icon: string;
342
- hasCreate?: boolean | undefined;
343
- hasUpdate?: boolean | undefined;
344
- hasDelete?: boolean | undefined;
345
- }[];
346
- }>;
347
- type Resource = z.infer<typeof ResourceCreateOutputSchema>;
348
- type ResourcesReadInput = z.infer<typeof ResourcesReadInputSchema>;
349
- type ResourcesReadOutput = z.infer<typeof ResourcesReadOutputSchema>;
350
- type ResourcesSearchInput = z.infer<typeof ResourceSearchInputSchema>;
351
- type ResourcesSearchOutput = z.infer<typeof ResourceSearchOutputSchema>;
352
- type ResourceCreateInput = z.infer<typeof ResourceCreateInputSchema>;
353
- type ResourceCreateOutput = z.infer<typeof ResourceCreateOutputSchema>;
354
- type ResourceUpdateInput = z.infer<typeof ResourceUpdateInputSchema>;
355
- type ResourceUpdateOutput = z.infer<typeof ResourceUpdateOutputSchema>;
356
- type ResourceDeleteInput = z.infer<typeof ResourceDeleteInputSchema>;
357
- type ResourceDeleteOutput = z.infer<typeof ResourceDeleteOutputSchema>;
358
- type ResourcesListInput = z.infer<typeof ResourcesListInputSchema>;
359
- type ResourcesListOutput = z.infer<typeof ResourcesListOutputSchema>;
360
- declare const mimeType: (filePathOrExtension: string) => string;
361
-
362
- export { type Resource, type ResourceCreateInput, ResourceCreateInputSchema, type ResourceCreateOutput, ResourceCreateOutputSchema, type ResourceDeleteInput, ResourceDeleteInputSchema, type ResourceDeleteOutput, ResourceDeleteOutputSchema, ResourceSearchInputSchema, ResourceSearchOutputSchema, type ResourceUpdateInput, ResourceUpdateInputSchema, type ResourceUpdateOutput, ResourceUpdateOutputSchema, type ResourcesListInput, ResourcesListInputSchema, type ResourcesListOutput, ResourcesListOutputSchema, type ResourcesReadInput, ResourcesReadInputSchema, type ResourcesReadOutput, ResourcesReadOutputSchema, type ResourcesSearchInput, type ResourcesSearchOutput, mimeType };
package/dist/resources.js DELETED
@@ -1,4 +0,0 @@
1
- export { ResourceCreateInputSchema, ResourceCreateOutputSchema, ResourceDeleteInputSchema, ResourceDeleteOutputSchema, ResourceSearchInputSchema, ResourceSearchOutputSchema, ResourceUpdateInputSchema, ResourceUpdateOutputSchema, ResourcesListInputSchema, ResourcesListOutputSchema, ResourcesReadInputSchema, ResourcesReadOutputSchema, mimeType } from './chunk-7ITSLORK.js';
2
- import './chunk-I7BWSAN6.js';
3
- //# sourceMappingURL=resources.js.map
4
- //# sourceMappingURL=resources.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"resources.js"}
package/dist/views.d.ts DELETED
@@ -1,72 +0,0 @@
1
- import { z } from 'zod/v3';
2
-
3
- declare const ViewsListOutputSchema: z.ZodObject<{
4
- views: z.ZodArray<z.ZodObject<{
5
- id: z.ZodOptional<z.ZodString>;
6
- name: z.ZodOptional<z.ZodString>;
7
- title: z.ZodString;
8
- description: z.ZodOptional<z.ZodString>;
9
- icon: z.ZodString;
10
- url: z.ZodOptional<z.ZodString>;
11
- mimeTypePattern: z.ZodOptional<z.ZodString>;
12
- resourceName: z.ZodOptional<z.ZodString>;
13
- tools: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
14
- prompt: z.ZodOptional<z.ZodString>;
15
- installBehavior: z.ZodOptional<z.ZodEnum<["none", "open", "autoPin"]>>;
16
- }, "strip", z.ZodTypeAny, {
17
- tools: string[];
18
- title: string;
19
- icon: string;
20
- id?: string | undefined;
21
- name?: string | undefined;
22
- url?: string | undefined;
23
- description?: string | undefined;
24
- resourceName?: string | undefined;
25
- mimeTypePattern?: string | undefined;
26
- prompt?: string | undefined;
27
- installBehavior?: "open" | "none" | "autoPin" | undefined;
28
- }, {
29
- title: string;
30
- icon: string;
31
- id?: string | undefined;
32
- name?: string | undefined;
33
- url?: string | undefined;
34
- description?: string | undefined;
35
- resourceName?: string | undefined;
36
- tools?: string[] | undefined;
37
- mimeTypePattern?: string | undefined;
38
- prompt?: string | undefined;
39
- installBehavior?: "open" | "none" | "autoPin" | undefined;
40
- }>, "many">;
41
- }, "strip", z.ZodTypeAny, {
42
- views: {
43
- tools: string[];
44
- title: string;
45
- icon: string;
46
- id?: string | undefined;
47
- name?: string | undefined;
48
- url?: string | undefined;
49
- description?: string | undefined;
50
- resourceName?: string | undefined;
51
- mimeTypePattern?: string | undefined;
52
- prompt?: string | undefined;
53
- installBehavior?: "open" | "none" | "autoPin" | undefined;
54
- }[];
55
- }, {
56
- views: {
57
- title: string;
58
- icon: string;
59
- id?: string | undefined;
60
- name?: string | undefined;
61
- url?: string | undefined;
62
- description?: string | undefined;
63
- resourceName?: string | undefined;
64
- tools?: string[] | undefined;
65
- mimeTypePattern?: string | undefined;
66
- prompt?: string | undefined;
67
- installBehavior?: "open" | "none" | "autoPin" | undefined;
68
- }[];
69
- }>;
70
- type ViewsListOutput = z.infer<typeof ViewsListOutputSchema>;
71
-
72
- export { type ViewsListOutput, ViewsListOutputSchema };
package/dist/views.js DELETED
@@ -1,4 +0,0 @@
1
- export { ViewsListOutputSchema } from './chunk-L4OT2YDO.js';
2
- import './chunk-I7BWSAN6.js';
3
- //# sourceMappingURL=views.js.map
4
- //# sourceMappingURL=views.js.map
package/dist/views.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"views.js"}
package/src/admin.ts DELETED
@@ -1,16 +0,0 @@
1
- import { createChannel } from "bidc";
2
-
3
- export const requestMissingScopes = ({ scopes }: { scopes: string[] }) => {
4
- try {
5
- const channel = createChannel();
6
- channel.send({
7
- type: "request_missing_scopes",
8
- payload: {
9
- scopes,
10
- },
11
- });
12
- channel.cleanup();
13
- } catch (error) {
14
- console.error("Failed to request missing scopes", error);
15
- }
16
- };
package/src/auth.ts DELETED
@@ -1,233 +0,0 @@
1
- import { JWK, jwtVerify } from "jose";
2
- import type { DefaultEnv } from "./index.ts";
3
-
4
- const DECO_APP_AUTH_COOKIE_NAME = "deco_page_auth";
5
- const MAX_COOKIE_SIZE = 4000; // Leave some buffer below the 4096 limit
6
-
7
- export interface State {
8
- next?: string;
9
- }
10
-
11
- export const StateParser = {
12
- parse: (state: string) => {
13
- return JSON.parse(decodeURIComponent(atob(state))) as State;
14
- },
15
- stringify: (state: State) => {
16
- return btoa(encodeURIComponent(JSON.stringify(state)));
17
- },
18
- };
19
-
20
- // Helper function to chunk a value into multiple cookies
21
- const chunkValue = (value: string): string[] => {
22
- if (value.length <= MAX_COOKIE_SIZE) {
23
- return [value];
24
- }
25
-
26
- const chunks: string[] = [];
27
- for (let i = 0; i < value.length; i += MAX_COOKIE_SIZE) {
28
- chunks.push(value.slice(i, i + MAX_COOKIE_SIZE));
29
- }
30
- return chunks;
31
- };
32
-
33
- // Helper function to reassemble chunked cookies
34
- const reassembleChunkedCookies = (
35
- cookies: Record<string, string>,
36
- baseName: string,
37
- ): string | undefined => {
38
- // First try the base cookie (non-chunked)
39
- if (cookies[baseName]) {
40
- return cookies[baseName];
41
- }
42
-
43
- // Try to reassemble from chunks
44
- const chunks: string[] = [];
45
- let index = 0;
46
-
47
- while (true) {
48
- const chunkName = `${baseName}_${index}`;
49
- if (!cookies[chunkName]) {
50
- break;
51
- }
52
- chunks.push(cookies[chunkName]);
53
- index++;
54
- }
55
-
56
- return chunks.length > 0 ? chunks.join("") : undefined;
57
- };
58
-
59
- // Helper function to parse cookies from request
60
- const parseCookies = (cookieHeader: string): Record<string, string> => {
61
- const cookies: Record<string, string> = {};
62
- if (!cookieHeader) return cookies;
63
-
64
- cookieHeader.split(";").forEach((cookie) => {
65
- const [name, ...rest] = cookie.trim().split("=");
66
- if (name && rest.length > 0) {
67
- cookies[name] = decodeURIComponent(rest.join("="));
68
- }
69
- });
70
-
71
- return cookies;
72
- };
73
-
74
- const parseJWK = (jwk: string): JWK => JSON.parse(atob(jwk)) as JWK;
75
-
76
- export const getReqToken = async (req: Request, env: DefaultEnv) => {
77
- const token = () => {
78
- // First try to get token from Authorization header
79
- const authHeader = req.headers.get("Authorization");
80
- if (authHeader) {
81
- return authHeader.split(" ")[1];
82
- }
83
-
84
- // If not found, try to get from cookie
85
- const cookieHeader = req.headers.get("Cookie");
86
- if (cookieHeader) {
87
- const cookies = parseCookies(cookieHeader);
88
- return reassembleChunkedCookies(cookies, DECO_APP_AUTH_COOKIE_NAME);
89
- }
90
-
91
- return undefined;
92
- };
93
-
94
- const authToken = token();
95
- if (!authToken) {
96
- return undefined;
97
- }
98
-
99
- env.DECO_API_JWT_PUBLIC_KEY &&
100
- (await jwtVerify(authToken, parseJWK(env.DECO_API_JWT_PUBLIC_KEY), {
101
- issuer: "https://api.decocms.com",
102
- algorithms: ["RS256"],
103
- typ: "JWT",
104
- }).catch((err) => {
105
- console.error(
106
- `[auth-token]: error validating: ${err} ${env.DECO_API_JWT_PUBLIC_KEY}`,
107
- );
108
- }));
109
-
110
- return authToken;
111
- };
112
-
113
- export interface AuthCallbackOptions {
114
- apiUrl?: string;
115
- appName: string;
116
- }
117
-
118
- export const handleAuthCallback = async (
119
- req: Request,
120
- options: AuthCallbackOptions,
121
- ): Promise<Response> => {
122
- const url = new URL(req.url);
123
- const code = url.searchParams.get("code");
124
- const state = url.searchParams.get("state");
125
-
126
- if (!code) {
127
- return new Response("Missing authorization code", { status: 400 });
128
- }
129
-
130
- // Parse state to get the next URL
131
- let next = "/";
132
- if (state) {
133
- try {
134
- const parsedState = StateParser.parse(state);
135
- next = parsedState.next || "/";
136
- } catch {
137
- // ignore parse errors
138
- }
139
- }
140
-
141
- try {
142
- // Exchange code for token
143
- const apiUrl = options.apiUrl ?? "https://api.decocms.com";
144
- const exchangeResponse = await fetch(`${apiUrl}/apps/code-exchange`, {
145
- method: "POST",
146
- headers: {
147
- "Content-Type": "application/json",
148
- },
149
- body: JSON.stringify({
150
- code,
151
- client_id: options.appName,
152
- }),
153
- });
154
-
155
- if (!exchangeResponse.ok) {
156
- console.error(
157
- "authentication failed",
158
- code,
159
- options.appName,
160
- await exchangeResponse.text().catch((_) => ""),
161
- );
162
- return new Response("Authentication failed", { status: 401 });
163
- }
164
-
165
- const { access_token } = (await exchangeResponse.json()) as {
166
- access_token: string;
167
- };
168
-
169
- if (!access_token) {
170
- return new Response("No access token received", { status: 401 });
171
- }
172
-
173
- // Chunk the token if it's too large
174
- const chunks = chunkValue(access_token);
175
- const headers = new Headers();
176
- headers.set("Location", next);
177
-
178
- // Set cookies for each chunk
179
- if (chunks.length === 1) {
180
- // Single cookie for small tokens
181
- headers.set(
182
- "Set-Cookie",
183
- `${DECO_APP_AUTH_COOKIE_NAME}=${access_token}; HttpOnly; SameSite=None; Secure; Path=/`,
184
- );
185
- } else {
186
- // Multiple cookies for large tokens
187
- chunks.forEach((chunk, index) => {
188
- headers.append(
189
- "Set-Cookie",
190
- `${DECO_APP_AUTH_COOKIE_NAME}_${index}=${chunk}; HttpOnly; SameSite=None; Secure; Path=/`,
191
- );
192
- });
193
- }
194
-
195
- return new Response(null, {
196
- status: 302,
197
- headers,
198
- });
199
- } catch (err) {
200
- return new Response(`Authentication failed ${err}`, { status: 500 });
201
- }
202
- };
203
-
204
- const removeAuthCookie = (headers: Headers) => {
205
- // Clear the base cookie
206
- headers.append(
207
- "Set-Cookie",
208
- `${DECO_APP_AUTH_COOKIE_NAME}=; HttpOnly; SameSite=None; Secure; Path=/; Max-Age=0`,
209
- );
210
-
211
- // Clear all potential chunked cookies
212
- // We'll try to clear up to 10 chunks (which would support tokens up to 40KB)
213
- // This is a reasonable upper limit
214
- for (let i = 0; i < 10; i++) {
215
- headers.append(
216
- "Set-Cookie",
217
- `${DECO_APP_AUTH_COOKIE_NAME}_${i}=; HttpOnly; SameSite=None; Secure; Path=/; Max-Age=0`,
218
- );
219
- }
220
- };
221
-
222
- export const handleLogout = (req: Request) => {
223
- const url = new URL(req.url);
224
- const next = url.searchParams.get("next");
225
- const redirectTo = new URL("/", url);
226
- const headers = new Headers();
227
- removeAuthCookie(headers);
228
- headers.set("Location", next ?? redirectTo.href);
229
- return new Response(null, {
230
- status: 302,
231
- headers,
232
- });
233
- };