qarpeo 0.1.18 → 0.1.21
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 +96 -96
- package/dist/chunks/auth-schema.mjs +3 -1
- package/dist/chunks/wrangler.mjs +22 -3
- package/dist/cli/index.mjs +448 -221
- package/dist/fate/index.d.ts +29 -22
- package/dist/fate/index.mjs +1 -3
- package/dist/module.d.ts +1 -1
- package/dist/module.mjs +103 -82
- package/dist/runtime/ai.d.ts +2 -2
- package/dist/runtime/app/components/BlobImage.vue +119 -107
- package/dist/runtime/app/components/CMSBlocks.vue +104 -93
- package/dist/runtime/app/components/CMSContent.vue +24 -23
- package/dist/runtime/app/components/CMSImage.vue +49 -49
- package/dist/runtime/app/components/CMSLocaleSwitcher.vue +110 -110
- package/dist/runtime/app/components/CMSPreviewBanner.vue +83 -79
- package/dist/runtime/app/components/CMSVersionBanner.vue +53 -49
- package/dist/runtime/app/components/CMSVersionSwitcher.vue +140 -140
- package/dist/runtime/app/components/ContentRenderer.vue +83 -80
- package/dist/runtime/app/components/FileUpload.vue +200 -196
- package/dist/runtime/app/components/ImpersonationBanner.vue +61 -57
- package/dist/runtime/app/components/QarpeoWelcome.vue +84 -84
- package/dist/runtime/app/components/SignedIn.vue +13 -13
- package/dist/runtime/app/components/SignedOut.vue +13 -13
- package/dist/runtime/app/components/shiki.css +34 -34
- package/dist/runtime/app/composables/ai.d.ts +22 -22
- package/dist/runtime/app/composables/ai.mjs +3 -7
- package/dist/runtime/app/composables/analytics.mjs +1 -1
- package/dist/runtime/app/composables/api-tokens.mjs +1 -1
- package/dist/runtime/app/composables/auth.d.ts +6 -7
- package/dist/runtime/app/composables/auth.mjs +6 -3
- package/dist/runtime/app/composables/chat.mjs +3 -7
- package/dist/runtime/app/composables/cms-preview.d.ts +3 -3
- package/dist/runtime/app/composables/cms-preview.mjs +1 -1
- package/dist/runtime/app/composables/cms.d.ts +3 -5
- package/dist/runtime/app/composables/cms.mjs +2 -2
- package/dist/runtime/app/composables/docs-version.d.ts +8 -7
- package/dist/runtime/app/composables/docs-version.mjs +3 -3
- package/dist/runtime/app/composables/impersonation.mjs +1 -1
- package/dist/runtime/app/composables/notifications.d.ts +5 -5
- package/dist/runtime/app/composables/notifications.mjs +4 -5
- package/dist/runtime/app/composables/organization.mjs +1 -1
- package/dist/runtime/app/composables/passkey.mjs +1 -1
- package/dist/runtime/app/composables/passwordless.mjs +1 -1
- package/dist/runtime/app/composables/payments.d.ts +2 -1
- package/dist/runtime/app/composables/payments.mjs +1 -1
- package/dist/runtime/app/composables/realtime.d.ts +13 -13
- package/dist/runtime/app/composables/realtime.mjs +2 -2
- package/dist/runtime/app/composables/resumable-upload.d.ts +11 -11
- package/dist/runtime/app/composables/resumable-upload.mjs +1 -1
- package/dist/runtime/app/composables/site.mjs +1 -1
- package/dist/runtime/app/composables/storage.d.ts +151 -11
- package/dist/runtime/app/composables/storage.mjs +291 -33
- package/dist/runtime/app/composables/turnstile.mjs +1 -1
- package/dist/runtime/app/composables/two-factor.mjs +1 -1
- package/dist/runtime/app/pages/devtools/agents.vue +716 -716
- package/dist/runtime/app/pages/devtools/analytics.vue +616 -616
- package/dist/runtime/app/pages/devtools/auth.vue +381 -350
- package/dist/runtime/app/pages/devtools/blob.vue +743 -744
- package/dist/runtime/app/pages/devtools/db.vue +545 -545
- package/dist/runtime/app/pages/devtools/domains.vue +771 -771
- package/dist/runtime/app/pages/devtools/kv.vue +827 -828
- package/dist/runtime/app/pages/devtools/logs.vue +649 -653
- package/dist/runtime/app/pages/devtools/mail.vue +388 -388
- package/dist/runtime/app/pages/devtools/overview.vue +391 -389
- package/dist/runtime/app/pages/devtools/realtime.vue +89 -27
- package/dist/runtime/app/pages/devtools/security.vue +20 -5
- package/dist/runtime/app/pages/devtools/settings.vue +559 -559
- package/dist/runtime/app/pages/devtools/tasks.vue +26 -10
- package/dist/runtime/app/pages/devtools.vue +176 -176
- package/dist/runtime/app/plugins/seo.mjs +1 -1
- package/dist/runtime/app/plugins/shortcuts.client.d.ts +1 -4
- package/dist/runtime/app/public/sw-notifications.mjs +47 -52
- package/dist/runtime/blob.mjs +11 -4
- package/dist/runtime/browser.d.ts +1 -1
- package/dist/runtime/browser.mjs +12 -2
- package/dist/runtime/cache.d.ts +2 -1
- package/dist/runtime/kv.mjs +4 -1
- package/dist/runtime/providers/qarpeo.d.ts +3 -3
- package/dist/runtime/server/durable-objects/agent.mjs +1 -1
- package/dist/runtime/server/durable-objects/room.d.ts +2 -2
- package/dist/runtime/server/durable-objects/room.mjs +5 -5
- package/dist/runtime/server/middleware/devtools.mjs +6 -2
- package/dist/runtime/server/plugins/cms.d.ts +4 -2
- package/dist/runtime/server/plugins/dev-proxy.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/agents/chat.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/agents/chat.post.mjs +4 -1
- package/dist/runtime/server/routes/__qarpeo/analytics/events.get.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.mjs +5 -1
- package/dist/runtime/server/routes/__qarpeo/db/tables.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/db/tables.get.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/logs.get.d.ts +4 -1
- package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/mail/track/open/[id].get.mjs +2 -2
- package/dist/runtime/server/routes/__qarpeo/overview.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/realtime/room.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/realtime/rooms.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/security/analytics.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/security/ban.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/security/clear.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/security/unban.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/settings.get.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/tasks/run.post.mjs +3 -1
- package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +8 -2
- package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +8 -2
- package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +8 -2
- package/dist/runtime/server/routes/ai/embed.post.d.ts +1 -4
- package/dist/runtime/server/routes/ai/search.post.d.ts +2 -2
- package/dist/runtime/server/routes/auth/account.delete.mjs +1 -1
- package/dist/runtime/server/routes/auth/handler.mjs +6 -1
- package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +1 -1
- package/dist/runtime/server/routes/auth/organization/members/[id].delete.mjs +7 -1
- package/dist/runtime/server/routes/auth/otp/verify.post.mjs +1 -1
- package/dist/runtime/server/routes/auth/sso/login.get.mjs +7 -1
- package/dist/runtime/server/routes/auth/sso/oidc/callback.get.mjs +8 -2
- package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +7 -2
- package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +1 -1
- package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +7 -2
- package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +6 -1
- package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +6 -1
- package/dist/runtime/server/routes/browser/crawl.post.d.ts +1 -2
- package/dist/runtime/server/routes/browser/invoice.post.d.ts +1 -2
- package/dist/runtime/server/routes/browser/og-image.post.d.ts +2 -2
- package/dist/runtime/server/routes/browser/pdf.post.d.ts +1 -2
- package/dist/runtime/server/routes/browser/pdf.post.mjs +6 -1
- package/dist/runtime/server/routes/browser/screenshot.post.d.ts +2 -2
- package/dist/runtime/server/routes/browser/screenshot.post.mjs +5 -1
- package/dist/runtime/server/routes/cms/components/index.get.d.ts +2 -2
- package/dist/runtime/server/routes/cms/preview/disable.get.d.ts +4 -3
- package/dist/runtime/server/routes/cms/preview/enable.get.d.ts +8 -8
- package/dist/runtime/server/routes/cms/search.get.mjs +1 -1
- package/dist/runtime/server/routes/cms/webhooks/[provider].post.d.ts +7 -7
- package/dist/runtime/server/routes/cms/webhooks/[provider].post.mjs +9 -2
- package/dist/runtime/server/routes/docs/search.get.d.ts +9 -9
- package/dist/runtime/server/routes/fate.mjs +5 -8
- package/dist/runtime/server/routes/mail/bounce.post.d.ts +2 -2
- package/dist/runtime/server/routes/mail/unsubscribe.d.ts +2 -2
- package/dist/runtime/server/routes/mail/webhooks.post.d.ts +2 -2
- package/dist/runtime/server/routes/mail/webhooks.post.mjs +7 -1
- package/dist/runtime/server/routes/payments/usage.get.d.ts +8 -8
- package/dist/runtime/server/routes/payments/usage.post.d.ts +2 -2
- package/dist/runtime/server/routes/realtime/history.delete.d.ts +4 -3
- package/dist/runtime/server/routes/realtime/history.get.d.ts +7 -6
- package/dist/runtime/server/routes/realtime/ws.get.mjs +6 -1
- package/dist/runtime/server/routes/robots.txt.get.mjs +1 -1
- package/dist/runtime/server/routes/sitemap.xml.get.mjs +2 -1
- package/dist/runtime/server/routes/storage/multipart/abort.post.d.ts +2 -2
- package/dist/runtime/server/routes/storage/multipart/complete.post.d.ts +2 -2
- package/dist/runtime/server/routes/storage/multipart/complete.post.mjs +2 -2
- package/dist/runtime/server/routes/storage/multipart/create.post.d.ts +2 -2
- package/dist/runtime/server/routes/storage/multipart/create.post.mjs +7 -3
- package/dist/runtime/server/routes/storage/multipart/part.put.d.ts +2 -2
- package/dist/runtime/server/routes/storage/multipart/part.put.mjs +1 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +2 -4
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +2 -4
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.get.mjs +1 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.mjs +2 -4
- package/dist/runtime/server/tasks/cms/publish.mjs +1 -1
- package/dist/runtime/server/utils/ai.d.ts +9 -9
- package/dist/runtime/server/utils/ai.mjs +3 -3
- package/dist/runtime/server/utils/auth.d.ts +12 -16
- package/dist/runtime/server/utils/auth.mjs +15 -9
- package/dist/runtime/server/utils/bots.mjs +21 -7
- package/dist/runtime/server/utils/browser-utils.d.ts +44 -41
- package/dist/runtime/server/utils/browser-utils.mjs +14 -4
- package/dist/runtime/server/utils/cache.d.ts +5 -5
- package/dist/runtime/server/utils/cms/common.d.ts +26 -0
- package/dist/runtime/server/utils/cms/common.mjs +68 -0
- package/dist/runtime/server/utils/cms/git.d.ts +24 -0
- package/dist/runtime/server/utils/cms/git.mjs +240 -0
- package/dist/runtime/server/utils/cms/markdown.d.ts +22 -0
- package/dist/runtime/server/utils/cms/markdown.mjs +92 -0
- package/dist/runtime/server/utils/cms/path.d.ts +51 -0
- package/dist/runtime/server/utils/cms/path.mjs +127 -0
- package/dist/runtime/server/utils/cms/search.d.ts +22 -0
- package/dist/runtime/server/utils/cms/search.mjs +221 -0
- package/dist/runtime/server/utils/cms-events.d.ts +1 -1
- package/dist/runtime/server/utils/cms-events.mjs +2 -2
- package/dist/runtime/server/utils/cms-filter.mjs +2 -2
- package/dist/runtime/server/utils/cms.d.ts +17 -149
- package/dist/runtime/server/utils/cms.mjs +52 -761
- package/dist/runtime/server/utils/config.d.ts +5 -4
- package/dist/runtime/server/utils/domains.mjs +7 -4
- package/dist/runtime/server/utils/email-templates.d.ts +10 -7
- package/dist/runtime/server/utils/email-templates.mjs +20 -5
- package/dist/runtime/server/utils/feed.d.ts +2 -2
- package/dist/runtime/server/utils/feed.mjs +3 -1
- package/dist/runtime/server/utils/mail-suppression.d.ts +8 -24
- package/dist/runtime/server/utils/mail-suppression.mjs +2 -2
- package/dist/runtime/server/utils/mail.d.ts +7 -8
- package/dist/runtime/server/utils/mail.mjs +17 -12
- package/dist/runtime/server/utils/multipart-store.d.ts +2 -2
- package/dist/runtime/server/utils/notifications.d.ts +9 -23
- package/dist/runtime/server/utils/organization.mjs +4 -12
- package/dist/runtime/server/utils/passwordless.mjs +1 -1
- package/dist/runtime/server/utils/payments.d.ts +2 -6
- package/dist/runtime/server/utils/payments.mjs +1 -1
- package/dist/runtime/server/utils/queue.d.ts +21 -31
- package/dist/runtime/server/utils/rag.d.ts +4 -4
- package/dist/runtime/server/utils/rag.mjs +8 -8
- package/dist/runtime/server/utils/realtime-store.d.ts +2 -2
- package/dist/runtime/server/utils/realtime.d.ts +26 -28
- package/dist/runtime/server/utils/scheduled-task.d.ts +1 -3
- package/dist/runtime/server/utils/security-store.d.ts +2 -2
- package/dist/runtime/server/utils/session.d.ts +9 -11
- package/dist/runtime/server/utils/sso.d.ts +9 -15
- package/dist/runtime/server/utils/sso.mjs +4 -8
- package/dist/runtime/server/utils/storage.d.ts +19 -2
- package/dist/runtime/server/utils/storage.mjs +36 -7
- package/dist/runtime/server/utils/tenant.mjs +3 -1
- package/dist/runtime/server/utils/turnstile.d.ts +3 -5
- package/dist/runtime/server/utils/vapid.d.ts +5 -8
- package/dist/runtime/server/utils/vapid.mjs +26 -13
- package/dist/runtime/service.d.ts +13 -13
- package/dist/runtime/service.mjs +4 -2
- package/dist/runtime/test-utils.d.ts +20 -30
- package/dist/runtime/test-utils.mjs +5 -4
- package/dist/runtime/types/auth-globals.d.ts +14 -14
- package/dist/runtime/types/imports.d.ts +82 -82
- package/dist/runtime/types/index.d.ts +2 -2
- package/dist/runtime/types/r2.d.ts +5 -0
- package/dist/runtime/types/service.d.ts +11 -18
- package/dist/types.d.ts +100 -107
- package/dist/utils/auth-schema.d.ts +2 -2
- package/dist/utils/cms-sources.d.ts +3 -3
- package/dist/utils/local-db.d.ts +3 -3
- package/dist/utils/notifications-schema.d.ts +1 -3
- package/dist/utils/pkg.d.ts +7 -0
- package/dist/utils/queue.d.ts +3 -3
- package/dist/utils/tasks.d.ts +3 -2
- package/package.json +11 -8
|
@@ -15,7 +15,7 @@ export interface DevRealtimeRoom {
|
|
|
15
15
|
}
|
|
16
16
|
export declare function getDevRealtimeRoomsStore(): Map<string, DevRealtimeRoom>;
|
|
17
17
|
/**
|
|
18
|
-
* Updates or touches a room record in the development store whenever
|
|
19
|
-
*
|
|
18
|
+
* Updates or touches a room record in the development store whenever real room interactions or live
|
|
19
|
+
* events occur.
|
|
20
20
|
*/
|
|
21
21
|
export declare function trackRoomActivity(roomId: string, updater: (room: DevRealtimeRoom) => void): DevRealtimeRoom;
|
|
@@ -4,16 +4,16 @@ export type { RealtimePeer, RealtimeHandlerOptions, RealtimeHandlerRegistration,
|
|
|
4
4
|
* Creates a type-safe room state schema definition helper.
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
7
|
+
* ;```ts
|
|
8
|
+
* interface ChatRoomState {
|
|
9
|
+
* topic: string
|
|
10
|
+
* isLocked: boolean
|
|
11
|
+
* }
|
|
12
|
+
* export const chatSchema = defineRoomState<ChatRoomState>({
|
|
13
|
+
* name: "chat",
|
|
14
|
+
* initialState: { topic: "General", isLocked: false },
|
|
15
|
+
* })
|
|
16
|
+
* ```
|
|
17
17
|
*/
|
|
18
18
|
export declare function defineRoomState<T extends Record<string, any>>(schema: RoomStateSchema<T>): RoomStateSchema<T>;
|
|
19
19
|
/**
|
|
@@ -22,23 +22,21 @@ export declare function defineRoomState<T extends Record<string, any>>(schema: R
|
|
|
22
22
|
* @example
|
|
23
23
|
* ```ts
|
|
24
24
|
* export default defineRealtimeHandler("chat:*", {
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
25
|
+
* async message(peer, event, payload) {
|
|
26
|
+
* await broadcastToRoom(peer.roomId, "message", {
|
|
27
|
+
* from: peer.ctx.user?.name ?? "Anonymous",
|
|
28
|
+
* text: payload.text,
|
|
29
|
+
* ts: Date.now(),
|
|
30
|
+
* })
|
|
31
|
+
* },
|
|
32
|
+
* connect(peer) {
|
|
33
|
+
* console.log(`User connected to ${peer.roomId}`)
|
|
34
|
+
* },
|
|
35
35
|
* })
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
38
|
export declare function defineRealtimeHandler(roomPattern: string, handlers: RealtimeHandlerOptions): RealtimeHandlerRegistration;
|
|
39
|
-
/**
|
|
40
|
-
* Retrieves all registered realtime handlers matching a given room ID.
|
|
41
|
-
*/
|
|
39
|
+
/** Retrieves all registered realtime handlers matching a given room ID. */
|
|
42
40
|
export declare function getRealtimeHandlersForRoom(roomId: string): RealtimeHandlerOptions[];
|
|
43
41
|
/**
|
|
44
42
|
* Retrieves the Durable Object stub for a specific room name.
|
|
@@ -77,7 +75,7 @@ export declare function getRoomPresence(eventOrRoom: any, maybeRoom?: string): P
|
|
|
77
75
|
* Retrieves the message history replay buffer for a room from Durable Object storage.
|
|
78
76
|
*
|
|
79
77
|
* @example
|
|
80
|
-
*
|
|
78
|
+
* ;```ts
|
|
81
79
|
* const messages = await getRoomHistory(event, "chat:support")
|
|
82
80
|
* ```
|
|
83
81
|
*/
|
|
@@ -90,7 +88,7 @@ export declare function getRoomHistory(eventOrRoom: any, maybeRoom?: string, opt
|
|
|
90
88
|
* Clears the persistent message history replay buffer for a room from Durable Object storage.
|
|
91
89
|
*
|
|
92
90
|
* @example
|
|
93
|
-
*
|
|
91
|
+
* ;```ts
|
|
94
92
|
* await clearRoomHistory(event, "chat:support")
|
|
95
93
|
* ```
|
|
96
94
|
*/
|
|
@@ -101,7 +99,7 @@ export declare function disconnectRoomUser(eventOrRoom: any, roomOrUserId: strin
|
|
|
101
99
|
* Retrieves the synchronized state of a room.
|
|
102
100
|
*
|
|
103
101
|
* @example
|
|
104
|
-
*
|
|
102
|
+
* ;```ts
|
|
105
103
|
* const state = await getRoomState(event, "doc:456")
|
|
106
104
|
* ```
|
|
107
105
|
*/
|
|
@@ -110,7 +108,7 @@ export declare function getRoomState<T extends Record<string, any> = Record<stri
|
|
|
110
108
|
* Replaces the entire synchronized state of a room and broadcasts to all connected clients.
|
|
111
109
|
*
|
|
112
110
|
* @example
|
|
113
|
-
*
|
|
111
|
+
* ;```ts
|
|
114
112
|
* await setRoomState(event, "doc:456", { title: "New Document", locked: false })
|
|
115
113
|
* ```
|
|
116
114
|
*/
|
|
@@ -119,7 +117,7 @@ export declare function setRoomState<T extends Record<string, any> = Record<stri
|
|
|
119
117
|
* Merges a partial patch into the synchronized state of a room and broadcasts the delta.
|
|
120
118
|
*
|
|
121
119
|
* @example
|
|
122
|
-
*
|
|
120
|
+
* ;```ts
|
|
123
121
|
* await patchRoomState(event, "doc:456", { locked: true })
|
|
124
122
|
* ```
|
|
125
123
|
*/
|
|
@@ -23,7 +23,5 @@ export interface ScheduledTaskDefinition<TPayload = ScheduledTaskPayload, TResul
|
|
|
23
23
|
context?: ScheduledTaskContext;
|
|
24
24
|
}): Promise<TResult> | TResult;
|
|
25
25
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Defines an edge-native scheduled task or cron job for Cloudflare Workers.
|
|
28
|
-
*/
|
|
26
|
+
/** Defines an edge-native scheduled task or cron job for Cloudflare Workers. */
|
|
29
27
|
export declare function defineScheduledTask<TPayload = ScheduledTaskPayload, TResult = any>(def: ScheduledTaskDefinition<TPayload, TResult>): ScheduledTaskDefinition<TPayload, TResult>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* In-memory telemetry and security event store for local development and DevTools.
|
|
3
|
-
*
|
|
2
|
+
* In-memory telemetry and security event store for local development and DevTools. Tracks rate
|
|
3
|
+
* limit buckets, blocked requests, Turnstile challenges, and bot scores.
|
|
4
4
|
*/
|
|
5
5
|
export interface SecurityEvent {
|
|
6
6
|
id: string;
|
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
import { useSession, type RequestEvent } from "nuxt/server";
|
|
2
2
|
import type { QarpeoUser } from "../../types/auth";
|
|
3
3
|
/**
|
|
4
|
-
* Returns the current authenticated user session data from sealed cookie.
|
|
5
|
-
*
|
|
4
|
+
* Returns the current authenticated user session data from sealed cookie. Powered by Nuxt 4.6+
|
|
5
|
+
* native session, with fallback to global session helpers.
|
|
6
6
|
*/
|
|
7
7
|
export declare function getAuthSession<T = any>(event: RequestEvent): Promise<T>;
|
|
8
8
|
/**
|
|
9
|
-
* Updates the sealed session cookie with user session data.
|
|
10
|
-
*
|
|
9
|
+
* Updates the sealed session cookie with user session data. Powered by Nuxt 4.6+ native session,
|
|
10
|
+
* and syncs with global session helpers if present.
|
|
11
11
|
*/
|
|
12
12
|
export declare function setAuthSession(event: RequestEvent, sessionData: any, config?: any): Promise<any>;
|
|
13
13
|
/**
|
|
14
|
-
* Clears the session cookie.
|
|
15
|
-
*
|
|
14
|
+
* Clears the session cookie. Powered by Nuxt 4.6+ native session, and syncs with global session
|
|
15
|
+
* helpers if present.
|
|
16
16
|
*/
|
|
17
17
|
export declare function clearAuthSession(event: RequestEvent, config?: any): Promise<boolean>;
|
|
18
|
-
/**
|
|
19
|
-
* Requires an active user session, throwing 401 Unauthorized if not authenticated.
|
|
20
|
-
*/
|
|
18
|
+
/** Requires an active user session, throwing 401 Unauthorized if not authenticated. */
|
|
21
19
|
export declare function requireAuthSession<T = any>(event: RequestEvent, opts?: any): Promise<T>;
|
|
22
20
|
export declare const getUserSession: typeof getAuthSession;
|
|
23
21
|
export declare const setUserSession: typeof setAuthSession;
|
|
@@ -47,8 +45,8 @@ export interface DeviceSessionRecord {
|
|
|
47
45
|
*/
|
|
48
46
|
export declare function createDeviceSession(event: RequestEvent, user: QarpeoUser, options?: CreateDeviceSessionOptions): Promise<DeviceSessionRecord>;
|
|
49
47
|
/**
|
|
50
|
-
* Throttled sliding-window update of last_active. Runs at most once every 15 minutes
|
|
51
|
-
*
|
|
48
|
+
* Throttled sliding-window update of last_active. Runs at most once every 15 minutes to preserve D1
|
|
49
|
+
* write quotas.
|
|
52
50
|
*/
|
|
53
51
|
export declare function touchDeviceSession(event: RequestEvent, session: any): Promise<void>;
|
|
54
52
|
export interface SessionListItem {
|
|
@@ -13,28 +13,24 @@ export interface SAMLAssertionResult {
|
|
|
13
13
|
attributes: Record<string, string>;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* Verifies the XML digital signature on a SAML Response using the IdP's signing
|
|
17
|
-
*
|
|
16
|
+
* Verifies the XML digital signature on a SAML Response using the IdP's signing certificate stored
|
|
17
|
+
* in `_qarpeo_sso_connections.cert`.
|
|
18
18
|
*
|
|
19
|
-
* Returns `true` if the signature is valid, `false` if it fails verification,
|
|
20
|
-
*
|
|
19
|
+
* Returns `true` if the signature is valid, `false` if it fails verification, and `null` if no
|
|
20
|
+
* signature is present (allowing callers to decide policy).
|
|
21
21
|
*
|
|
22
22
|
* @param xml - The decoded SAML Response XML string
|
|
23
23
|
* @param certPem - The IdP's signing certificate (PEM format, with or without header)
|
|
24
24
|
*/
|
|
25
25
|
export declare function verifySAMLSignature(xml: string, certPem: string): Promise<boolean | null>;
|
|
26
|
-
/**
|
|
27
|
-
* Builds a SAML 2.0 AuthnRequest URL for HTTP-Redirect binding.
|
|
28
|
-
*/
|
|
26
|
+
/** Builds a SAML 2.0 AuthnRequest URL for HTTP-Redirect binding. */
|
|
29
27
|
export declare function buildSAMLAuthnRequestUrl(options: SAMLAuthnRequestOptions): string;
|
|
30
28
|
/**
|
|
31
|
-
* Parses and verifies a SAML 2.0 Response XML assertion.
|
|
32
|
-
*
|
|
29
|
+
* Parses and verifies a SAML 2.0 Response XML assertion. Extracts NameID (email) and user profile
|
|
30
|
+
* attributes.
|
|
33
31
|
*/
|
|
34
32
|
export declare function parseSAMLResponse(base64Response: string): SAMLAssertionResult;
|
|
35
|
-
/**
|
|
36
|
-
* Builds an Enterprise OIDC authorization redirect URL.
|
|
37
|
-
*/
|
|
33
|
+
/** Builds an Enterprise OIDC authorization redirect URL. */
|
|
38
34
|
export declare function buildOIDCAuthUrl(options: {
|
|
39
35
|
authorizationUrl: string;
|
|
40
36
|
clientId: string;
|
|
@@ -42,9 +38,7 @@ export declare function buildOIDCAuthUrl(options: {
|
|
|
42
38
|
state: string;
|
|
43
39
|
scope?: string;
|
|
44
40
|
}): string;
|
|
45
|
-
/**
|
|
46
|
-
* Exchanges authorization code for tokens and retrieves user profile from Enterprise OIDC provider.
|
|
47
|
-
*/
|
|
41
|
+
/** Exchanges authorization code for tokens and retrieves user profile from Enterprise OIDC provider. */
|
|
48
42
|
export declare function exchangeOIDCCode(options: {
|
|
49
43
|
tokenUrl: string;
|
|
50
44
|
userinfoUrl?: string;
|
|
@@ -13,13 +13,7 @@ async function importCertPublicKey(certPem) {
|
|
|
13
13
|
${certPem}
|
|
14
14
|
-----END CERTIFICATE-----`;
|
|
15
15
|
const der = pemToDer(normalized);
|
|
16
|
-
const cert = await crypto.subtle.importKey(
|
|
17
|
-
"raw",
|
|
18
|
-
der,
|
|
19
|
-
{ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" },
|
|
20
|
-
false,
|
|
21
|
-
["verify"]
|
|
22
|
-
).catch(() => null);
|
|
16
|
+
const cert = await crypto.subtle.importKey("raw", der, { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, false, ["verify"]).catch(() => null);
|
|
23
17
|
if (cert) return cert;
|
|
24
18
|
return await crypto.subtle.importKey(
|
|
25
19
|
"spki",
|
|
@@ -33,7 +27,9 @@ ${certPem}
|
|
|
33
27
|
}
|
|
34
28
|
}
|
|
35
29
|
function extractXmlSignature(xml) {
|
|
36
|
-
const sigValueMatch = xml.match(
|
|
30
|
+
const sigValueMatch = xml.match(
|
|
31
|
+
/<(?:\w+:)?SignatureValue[^>]*>([^<]+)<\/(?:\w+:)?SignatureValue>/i
|
|
32
|
+
);
|
|
37
33
|
const signedInfoMatch = xml.match(/<(?:\w+:)?SignedInfo[\s\S]*?<\/(?:\w+:)?SignedInfo>/i);
|
|
38
34
|
if (!sigValueMatch || !signedInfoMatch) return null;
|
|
39
35
|
const sigB64 = sigValueMatch[1].replace(/\s+/g, "");
|
|
@@ -111,6 +111,22 @@ export declare function listStorageFiles(event: RequestEvent, options?: {
|
|
|
111
111
|
*/
|
|
112
112
|
export declare function serveStorageFile(event: RequestEvent, key: string): Promise<Response | null>;
|
|
113
113
|
export interface HandleUploadOptions {
|
|
114
|
+
/** Form key in multipart form-data (e.g. 'file' or 'files') */
|
|
115
|
+
formKey?: string;
|
|
116
|
+
/** Whether multiple files should be returned as array (defaults to true if multiple files present) */
|
|
117
|
+
multiple?: boolean;
|
|
118
|
+
/** NuxtHub-compatible ensure options */
|
|
119
|
+
ensure?: {
|
|
120
|
+
maxSize?: string | number;
|
|
121
|
+
types?: string[];
|
|
122
|
+
};
|
|
123
|
+
/** NuxtHub-compatible put options */
|
|
124
|
+
put?: {
|
|
125
|
+
prefix?: string;
|
|
126
|
+
addRandomSuffix?: boolean;
|
|
127
|
+
customMetadata?: Record<string, string>;
|
|
128
|
+
access?: BlobAccessTier;
|
|
129
|
+
};
|
|
114
130
|
/** Target key in R2 bucket (or key generator function) */
|
|
115
131
|
key?: string | ((file: {
|
|
116
132
|
filename: string;
|
|
@@ -135,7 +151,8 @@ export declare function readEventMultipartFormData(event: RequestEvent | any): P
|
|
|
135
151
|
data: Uint8Array;
|
|
136
152
|
}>>;
|
|
137
153
|
/**
|
|
138
|
-
* High-level server utility to handle file uploads in custom API routes (e.g.
|
|
139
|
-
* Parses incoming multipart form data, validates, uploads to
|
|
154
|
+
* High-level server utility to handle file uploads in custom API routes (e.g.
|
|
155
|
+
* server/api/avatars.post.ts). Parses incoming multipart form data, validates, uploads to
|
|
156
|
+
* Cloudflare R2, and returns uploaded file metadata.
|
|
140
157
|
*/
|
|
141
158
|
export declare function handleUpload(event: RequestEvent, options?: HandleUploadOptions): Promise<any>;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createError,
|
|
3
|
+
getRequestURL,
|
|
4
|
+
getRequestHeader,
|
|
5
|
+
getQuery
|
|
6
|
+
} from "nuxt/server";
|
|
2
7
|
import { getR2Binding, parseByteSize } from "../../blob.mjs";
|
|
3
8
|
import { getDevMockBlobStore } from "./blob-store.mjs";
|
|
4
9
|
import { getQarpeoConfig, getSessionSecret } from "./config.mjs";
|
|
@@ -620,7 +625,11 @@ export async function serveStorageFile(event, key) {
|
|
|
620
625
|
const ifNoneMatch = getRequestHeader(event, "if-none-match");
|
|
621
626
|
if (ifNoneMatch && (ifNoneMatch === object.etag || ifNoneMatch === `W/"${object.etag}"`)) {
|
|
622
627
|
const ev = event;
|
|
623
|
-
ev.node?.res
|
|
628
|
+
if (ev.node?.res) {
|
|
629
|
+
ev.node.res.statusCode = 304;
|
|
630
|
+
} else {
|
|
631
|
+
ev.status = 304;
|
|
632
|
+
}
|
|
624
633
|
return null;
|
|
625
634
|
}
|
|
626
635
|
const headers = {
|
|
@@ -701,8 +710,22 @@ export async function handleUpload(event, options = {}) {
|
|
|
701
710
|
message: "No files provided in upload request"
|
|
702
711
|
});
|
|
703
712
|
}
|
|
713
|
+
const targetFiles = options.formKey ? files.filter((f) => !f.name || f.name === options.formKey) : files;
|
|
714
|
+
if (targetFiles.length === 0) {
|
|
715
|
+
throw createError({
|
|
716
|
+
statusCode: 400,
|
|
717
|
+
statusMessage: "Bad Request",
|
|
718
|
+
message: `No file found matching formKey "${options.formKey}"`
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
const effectivePrefix = options.put?.prefix ?? options.dir;
|
|
722
|
+
const effectiveAccess = options.put?.access ?? options.access;
|
|
723
|
+
const effectiveMetadata = {
|
|
724
|
+
...options.customMetadata,
|
|
725
|
+
...options.put?.customMetadata
|
|
726
|
+
};
|
|
704
727
|
const results = [];
|
|
705
|
-
for (const file of
|
|
728
|
+
for (const file of targetFiles) {
|
|
706
729
|
let targetKey;
|
|
707
730
|
if (typeof options.key === "function") {
|
|
708
731
|
targetKey = options.key({
|
|
@@ -712,8 +735,8 @@ export async function handleUpload(event, options = {}) {
|
|
|
712
735
|
});
|
|
713
736
|
} else if (typeof options.key === "string") {
|
|
714
737
|
targetKey = options.key;
|
|
715
|
-
} else if (
|
|
716
|
-
const cleanDir =
|
|
738
|
+
} else if (effectivePrefix) {
|
|
739
|
+
const cleanDir = effectivePrefix.replace(/^\/+|\/+$/g, "");
|
|
717
740
|
const rawName = file.filename || `file-${Date.now()}`;
|
|
718
741
|
const cleanName = sanitizeFilename(rawName);
|
|
719
742
|
const uniqueId = `${Date.now()}-${crypto.randomUUID().slice(0, 8)}`;
|
|
@@ -729,11 +752,17 @@ export async function handleUpload(event, options = {}) {
|
|
|
729
752
|
},
|
|
730
753
|
{
|
|
731
754
|
key: targetKey,
|
|
732
|
-
access:
|
|
733
|
-
customMetadata:
|
|
755
|
+
access: effectiveAccess,
|
|
756
|
+
customMetadata: effectiveMetadata
|
|
734
757
|
}
|
|
735
758
|
);
|
|
736
759
|
results.push(uploaded);
|
|
737
760
|
}
|
|
761
|
+
if (options.multiple === false) {
|
|
762
|
+
return results[0];
|
|
763
|
+
}
|
|
764
|
+
if (options.multiple === true) {
|
|
765
|
+
return results;
|
|
766
|
+
}
|
|
738
767
|
return results.length === 1 ? results[0] : results;
|
|
739
768
|
}
|
|
@@ -215,7 +215,9 @@ export async function resolveTenant(event) {
|
|
|
215
215
|
const req = event.node?.req;
|
|
216
216
|
const headers = req?.headers || {};
|
|
217
217
|
const config = getMultitenantConfig(event);
|
|
218
|
-
const isDev = Boolean(
|
|
218
|
+
const isDev = Boolean(
|
|
219
|
+
import.meta.dev || globalThis.process?.env?.NODE_ENV === "development"
|
|
220
|
+
);
|
|
219
221
|
const allowHeader = isDev || Boolean(config.allowHeaderOverrideInProduction);
|
|
220
222
|
if (allowHeader) {
|
|
221
223
|
const headerName = (config.headerName || "x-tenant-id").toLowerCase();
|
|
@@ -8,11 +8,9 @@ export interface TurnstileVerificationResult {
|
|
|
8
8
|
cdata?: string;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Validates a Cloudflare Turnstile token using Cloudflare's siteverify API.
|
|
12
|
-
*
|
|
11
|
+
* Validates a Cloudflare Turnstile token using Cloudflare's siteverify API. Reads secret key from
|
|
12
|
+
* NUXT_TURNSTILE_SECRET_KEY, TURNSTILE_SECRET_KEY, or qarpeo.auth.turnstile.secretKey.
|
|
13
13
|
*/
|
|
14
14
|
export declare function verifyTurnstileToken(event: RequestEvent, token?: string, remoteIp?: string): Promise<TurnstileVerificationResult>;
|
|
15
|
-
/**
|
|
16
|
-
* Enforces Cloudflare Turnstile verification. Throws 403 Forbidden if invalid.
|
|
17
|
-
*/
|
|
15
|
+
/** Enforces Cloudflare Turnstile verification. Throws 403 Forbidden if invalid. */
|
|
18
16
|
export declare function requireTurnstile(event: RequestEvent, token?: string): Promise<void>;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Qarpeo VAPID Web Push helper — RFC 8292 & RFC 8291
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Generate a new VAPID P-256 key pair.
|
|
7
|
-
* Returns base64url-encoded public and private keys.
|
|
2
|
+
* Qarpeo VAPID Web Push helper — RFC 8292 & RFC 8291 Uses only native crypto.subtle (zero external
|
|
3
|
+
* dependencies).
|
|
8
4
|
*/
|
|
5
|
+
/** Generate a new VAPID P-256 key pair. Returns base64url-encoded public and private keys. */
|
|
9
6
|
export declare function generateVapidKeys(): Promise<{
|
|
10
7
|
publicKey: string;
|
|
11
8
|
privateKey: string;
|
|
@@ -20,8 +17,8 @@ export declare function generateVapidKeys(): Promise<{
|
|
|
20
17
|
*/
|
|
21
18
|
export declare function signVapidHeader(endpoint: string, subject: string, publicKey: string, privateKey: string): Promise<string>;
|
|
22
19
|
/**
|
|
23
|
-
* Encrypt a Web Push payload using ECDH + HKDF + AES-128-GCM.
|
|
24
|
-
*
|
|
20
|
+
* Encrypt a Web Push payload using ECDH + HKDF + AES-128-GCM. Returns the encrypted body and
|
|
21
|
+
* required headers.
|
|
25
22
|
*/
|
|
26
23
|
export declare function encryptWebPushPayload(subscription: {
|
|
27
24
|
endpoint: string;
|
|
@@ -31,11 +31,10 @@ function encodeUint16BE(n) {
|
|
|
31
31
|
return new Uint8Array([n >> 8 & 255, n & 255]);
|
|
32
32
|
}
|
|
33
33
|
export async function generateVapidKeys() {
|
|
34
|
-
const keyPair = await crypto.subtle.generateKey(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
);
|
|
34
|
+
const keyPair = await crypto.subtle.generateKey({ name: "ECDH", namedCurve: "P-256" }, true, [
|
|
35
|
+
"deriveKey",
|
|
36
|
+
"deriveBits"
|
|
37
|
+
]);
|
|
39
38
|
const publicKeyRaw = await crypto.subtle.exportKey("raw", keyPair.publicKey);
|
|
40
39
|
const privateKeyPkcs8 = await crypto.subtle.exportKey("pkcs8", keyPair.privateKey);
|
|
41
40
|
const privateKeyBytes = new Uint8Array(privateKeyPkcs8).slice(-32);
|
|
@@ -152,11 +151,7 @@ export async function encryptWebPushPayload(subscription, payload) {
|
|
|
152
151
|
const cek = await hkdf(
|
|
153
152
|
salt,
|
|
154
153
|
prk,
|
|
155
|
-
buildInfo(
|
|
156
|
-
"Content-Encoding: aesgcm\0",
|
|
157
|
-
receiverPublicKeyBytes,
|
|
158
|
-
senderPublicKey
|
|
159
|
-
),
|
|
154
|
+
buildInfo("Content-Encoding: aesgcm\0", receiverPublicKeyBytes, senderPublicKey),
|
|
160
155
|
16
|
|
161
156
|
);
|
|
162
157
|
const nonce = await hkdf(
|
|
@@ -192,11 +187,29 @@ export async function encryptWebPushPayload(subscription, payload) {
|
|
|
192
187
|
};
|
|
193
188
|
}
|
|
194
189
|
async function hkdf(salt, ikm, info, length) {
|
|
195
|
-
const saltKey = await crypto.subtle.importKey(
|
|
190
|
+
const saltKey = await crypto.subtle.importKey(
|
|
191
|
+
"raw",
|
|
192
|
+
salt,
|
|
193
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
194
|
+
false,
|
|
195
|
+
["sign"]
|
|
196
|
+
);
|
|
196
197
|
const prk = new Uint8Array(await crypto.subtle.sign("HMAC", saltKey, ikm));
|
|
197
|
-
const prkKey = await crypto.subtle.importKey(
|
|
198
|
+
const prkKey = await crypto.subtle.importKey(
|
|
199
|
+
"raw",
|
|
200
|
+
prk,
|
|
201
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
202
|
+
false,
|
|
203
|
+
["sign"]
|
|
204
|
+
);
|
|
198
205
|
const counter = new Uint8Array([1]);
|
|
199
|
-
const okm = new Uint8Array(
|
|
206
|
+
const okm = new Uint8Array(
|
|
207
|
+
await crypto.subtle.sign(
|
|
208
|
+
"HMAC",
|
|
209
|
+
prkKey,
|
|
210
|
+
concatBuffers(info.buffer, counter.buffer)
|
|
211
|
+
)
|
|
212
|
+
);
|
|
200
213
|
return okm.slice(0, length);
|
|
201
214
|
}
|
|
202
215
|
function buildInfo(encoding, receiverKey, senderKey) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ServiceBindingFetcher, QarpeoServiceClient } from "./types/service";
|
|
2
1
|
import type { CFEvent } from "./types/index";
|
|
2
|
+
import type { ServiceBindingFetcher, QarpeoServiceClient } from "./types/service";
|
|
3
3
|
export type * from "./types/service";
|
|
4
4
|
/**
|
|
5
5
|
* Returns the raw Cloudflare Worker Service Fetcher binding from the environment.
|
|
@@ -9,23 +9,23 @@ export type * from "./types/service";
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function getServiceBinding(serviceName: string, event?: CFEvent): ServiceBindingFetcher;
|
|
11
11
|
/**
|
|
12
|
-
* Creates a typed Service Binding client for calling another Cloudflare Worker.
|
|
13
|
-
*
|
|
12
|
+
* Creates a typed Service Binding client for calling another Cloudflare Worker. Supports both
|
|
13
|
+
* HTTP-style fetch/JSON requests and Cloudflare Workers RPC direct method calls.
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* ;```ts
|
|
17
|
+
* interface AuthService {
|
|
18
|
+
* verifyToken(token: string): Promise<{ userId: string }>
|
|
19
|
+
* }
|
|
20
20
|
*
|
|
21
|
-
*
|
|
21
|
+
* const auth = useServiceBinding<AuthService>("AUTH_SERVICE")
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
23
|
+
* // RPC style (zero HTTP serialization overhead)
|
|
24
|
+
* const user = await auth.rpc.verifyToken("jwt-xyz")
|
|
25
25
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* // HTTP style
|
|
27
|
+
* const profile = await auth.get("/api/profile", { userId: user.userId })
|
|
28
|
+
* ```
|
|
29
29
|
*/
|
|
30
30
|
export declare function createServiceClient<TRpc = Record<string, any>>(serviceName: string, event?: CFEvent): QarpeoServiceClient<TRpc>;
|
|
31
31
|
/**
|
package/dist/runtime/service.mjs
CHANGED
|
@@ -84,12 +84,14 @@ export function createServiceClient(serviceName, event) {
|
|
|
84
84
|
method: "POST",
|
|
85
85
|
headers: {
|
|
86
86
|
"Content-Type": "application/json",
|
|
87
|
-
|
|
87
|
+
Accept: "application/json"
|
|
88
88
|
},
|
|
89
89
|
body: JSON.stringify({ args })
|
|
90
90
|
});
|
|
91
91
|
if (!res.ok) {
|
|
92
|
-
throw new Error(
|
|
92
|
+
throw new Error(
|
|
93
|
+
`RPC call "${prop}" to service "${serviceName}" failed with status ${res.status}`
|
|
94
|
+
);
|
|
93
95
|
}
|
|
94
96
|
const data = await res.json();
|
|
95
97
|
return data?.result !== void 0 ? data.result : data;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cloudflare Edge Test Harness & Mock Factory for Qarpeo.
|
|
3
3
|
*
|
|
4
|
-
* Provides in-memory simulated Cloudflare Workers primitives (D1, KV, R2 Blob,
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Provides in-memory simulated Cloudflare Workers primitives (D1, KV, R2 Blob, Durable Objects, AI
|
|
5
|
+
* Gateway) so developers can write unit and integration tests without needing remote Cloudflare
|
|
6
|
+
* deployments or separate heavy dependencies.
|
|
7
7
|
*/
|
|
8
8
|
export interface MockD1PreparedStatement {
|
|
9
9
|
bind(...values: any[]): MockD1PreparedStatement;
|
|
@@ -145,46 +145,36 @@ export interface EdgeTestContext {
|
|
|
145
145
|
body?: any;
|
|
146
146
|
}) => any;
|
|
147
147
|
}
|
|
148
|
-
/**
|
|
149
|
-
* Creates an in-memory mock Cloudflare D1 database.
|
|
150
|
-
*/
|
|
148
|
+
/** Creates an in-memory mock Cloudflare D1 database. */
|
|
151
149
|
export declare function createMockD1Database(): MockD1Database;
|
|
152
|
-
/**
|
|
153
|
-
* Creates an in-memory mock Cloudflare KV namespace.
|
|
154
|
-
*/
|
|
150
|
+
/** Creates an in-memory mock Cloudflare KV namespace. */
|
|
155
151
|
export declare function createMockKVNamespace(): MockKVNamespace;
|
|
156
|
-
/**
|
|
157
|
-
* Creates an in-memory mock Cloudflare R2 bucket.
|
|
158
|
-
*/
|
|
152
|
+
/** Creates an in-memory mock Cloudflare R2 bucket. */
|
|
159
153
|
export declare function createMockR2Bucket(): MockR2Bucket;
|
|
160
|
-
/**
|
|
161
|
-
* Creates an in-memory mock Cloudflare Vectorize index for semantic vector search.
|
|
162
|
-
*/
|
|
154
|
+
/** Creates an in-memory mock Cloudflare Vectorize index for semantic vector search. */
|
|
163
155
|
export declare function createMockVectorizeIndex(options?: {
|
|
164
156
|
dimensions?: number;
|
|
165
157
|
metric?: import("./types/vectorize").VectorizeDistanceMetric;
|
|
166
158
|
}): MockVectorizeIndex;
|
|
167
|
-
/**
|
|
168
|
-
* Creates an in-memory mock Cloudflare Queue client for publishing and simulating consumer batches.
|
|
169
|
-
*/
|
|
159
|
+
/** Creates an in-memory mock Cloudflare Queue client for publishing and simulating consumer batches. */
|
|
170
160
|
export declare function createMockQueue<T = any>(queueName?: string): MockQueue<T>;
|
|
171
161
|
/**
|
|
172
|
-
* Initializes an edge test context with simulated Cloudflare Worker bindings.
|
|
173
|
-
*
|
|
162
|
+
* Initializes an edge test context with simulated Cloudflare Worker bindings. Automatically mounts
|
|
163
|
+
* mock bindings onto `getCloudflareEnv()`.
|
|
174
164
|
*
|
|
175
165
|
* @example
|
|
176
|
-
*
|
|
177
|
-
*
|
|
166
|
+
* ;```ts
|
|
167
|
+
* import { createEdgeTestContext } from "qarpeo/test-utils"
|
|
178
168
|
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
169
|
+
* describe("My Edge Route", () => {
|
|
170
|
+
* const edge = createEdgeTestContext()
|
|
171
|
+
* afterEach(() => edge.cleanup())
|
|
182
172
|
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
173
|
+
* it("interacts with D1 and KV", async () => {
|
|
174
|
+
* await edge.kv.put("user:1", { name: "Alice" })
|
|
175
|
+
* expect(await edge.kv.get("user:1", "json")).toEqual({ name: "Alice" })
|
|
176
|
+
* })
|
|
186
177
|
* })
|
|
187
|
-
*
|
|
188
|
-
* ```
|
|
178
|
+
* ```
|
|
189
179
|
*/
|
|
190
180
|
export declare function createEdgeTestContext(options?: EdgeTestContextOptions): EdgeTestContext;
|
|
@@ -29,7 +29,7 @@ export function createMockServiceBinding(handlerOrRpc) {
|
|
|
29
29
|
if (typeof fn === "function") {
|
|
30
30
|
let bodyArgs = [];
|
|
31
31
|
try {
|
|
32
|
-
const bodyStr = init?.body ?
|
|
32
|
+
const bodyStr = init?.body ? typeof init.body === "string" ? init.body : JSON.stringify(init.body) : "{}";
|
|
33
33
|
const parsed = JSON.parse(bodyStr);
|
|
34
34
|
bodyArgs = parsed.args || [];
|
|
35
35
|
} catch {
|
|
@@ -59,7 +59,7 @@ export function createMockServiceBinding(handlerOrRpc) {
|
|
|
59
59
|
export function createMockD1Database() {
|
|
60
60
|
const tables = /* @__PURE__ */ new Map();
|
|
61
61
|
const queries = [];
|
|
62
|
-
const createStatement = (sql,
|
|
62
|
+
const createStatement = (sql, _boundValues = []) => {
|
|
63
63
|
return {
|
|
64
64
|
bind(...values) {
|
|
65
65
|
return createStatement(sql, values);
|
|
@@ -142,7 +142,8 @@ export function createMockKVNamespace() {
|
|
|
142
142
|
async put(key, value, options) {
|
|
143
143
|
let expiration;
|
|
144
144
|
if (options?.expiration) expiration = Number(options.expiration);
|
|
145
|
-
else if (options?.expirationTtl)
|
|
145
|
+
else if (options?.expirationTtl)
|
|
146
|
+
expiration = Math.floor(Date.now() / 1e3) + Number(options.expirationTtl);
|
|
146
147
|
store.set(key, {
|
|
147
148
|
value: typeof value === "object" ? JSON.stringify(value) : String(value),
|
|
148
149
|
metadata: options?.metadata,
|
|
@@ -415,7 +416,7 @@ export function createEdgeTestContext(options = {}) {
|
|
|
415
416
|
const texts = Array.isArray(input.text) ? input.text : [input.text];
|
|
416
417
|
return {
|
|
417
418
|
data: texts.map((t) => {
|
|
418
|
-
const vec =
|
|
419
|
+
const vec = Array.from({ length: 768 }, () => 0);
|
|
419
420
|
for (let i = 0; i < t.length; i++) {
|
|
420
421
|
vec[i % 768] = (vec[i % 768] + t.charCodeAt(i)) / 1e3;
|
|
421
422
|
}
|