@rei-standard/amsg-server 2.6.0-next.2 → 2.6.0-next.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/LICENSE +21 -0
- package/README.md +599 -24
- package/dist/adapters/d1.d.ts +416 -0
- package/dist/adapters/factory.d.ts +39 -0
- package/dist/adapters/interface.d.ts +306 -0
- package/dist/adapters/neon.d.ts +88 -0
- package/dist/adapters/pg-shared.d.ts +161 -0
- package/dist/adapters/pg.d.ts +84 -0
- package/dist/adapters/schema.d.ts +57 -0
- package/dist/adapters/schema.sqlite.d.ts +49 -0
- package/dist/chunk-7NMQFTDJ.cjs +148 -0
- package/dist/chunk-E7OWP3VL.cjs +135 -0
- package/dist/chunk-GN44PST5.mjs +148 -0
- package/dist/chunk-KOJQVOYS.mjs +5847 -0
- package/dist/chunk-QHVID3V2.cjs +5847 -0
- package/dist/chunk-ZGGF4GMA.mjs +135 -0
- package/dist/cloudflare/single-user-worker.d.ts +37 -0
- package/dist/cloudflare.cjs +39 -2
- package/dist/cloudflare.d.ts +10 -2
- package/dist/cloudflare.mjs +40 -3
- package/dist/handlers/cancel-message.d.ts +3 -0
- package/dist/handlers/capabilities.d.ts +4 -0
- package/dist/handlers/client-state.d.ts +7 -0
- package/dist/handlers/get-message.d.ts +3 -0
- package/dist/handlers/get-user-key.d.ts +3 -0
- package/dist/handlers/init-tenant.d.ts +23 -0
- package/dist/handlers/llm-credentials.d.ts +5 -0
- package/dist/handlers/messages.d.ts +3 -0
- package/dist/handlers/outbox.d.ts +7 -0
- package/dist/handlers/push-subscription.d.ts +5 -0
- package/dist/handlers/schedule-message.d.ts +3 -0
- package/dist/handlers/send-notifications.d.ts +3 -0
- package/dist/handlers/single-user-init.d.ts +13 -0
- package/dist/handlers/update-message.d.ts +3 -0
- package/dist/handlers/vapid-public-key.d.ts +19 -0
- package/dist/index.cjs +133 -44
- package/dist/index.d.cts +131 -766
- package/dist/index.d.ts +131 -766
- package/dist/index.mjs +125 -36
- package/dist/lib/agentic-fire.d.ts +108 -0
- package/dist/lib/client-state-store.d.ts +80 -0
- package/dist/lib/constant-time.d.ts +14 -0
- package/dist/lib/db-errors.d.ts +10 -0
- package/dist/lib/encryption.d.ts +48 -0
- package/dist/lib/errors.d.ts +215 -0
- package/dist/lib/llm-credentials-store.d.ts +147 -0
- package/dist/lib/llm.d.ts +1 -0
- package/dist/lib/message-processor.d.ts +73 -0
- package/dist/lib/outbox-store.d.ts +95 -0
- package/dist/lib/push-subscription-store.d.ts +94 -0
- package/dist/lib/recurrence.d.ts +51 -0
- package/dist/lib/request.d.ts +182 -0
- package/dist/lib/result-emitter.d.ts +54 -0
- package/dist/lib/run-tick.d.ts +115 -0
- package/dist/lib/schema-version.d.ts +50 -0
- package/dist/lib/state-accessors.d.ts +70 -0
- package/dist/lib/state-chunks.d.ts +55 -0
- package/dist/lib/task-projection.d.ts +92 -0
- package/dist/lib/validation.d.ts +97 -0
- package/dist/lib/version.d.ts +7 -0
- package/dist/lib/webcrypto-utils.d.ts +1 -0
- package/dist/lib/webpush-webcrypto.d.ts +78 -0
- package/dist/{neon-BFUS25UX.cjs → neon-KP2CPA57.cjs} +110 -10
- package/dist/{neon-CU5N3CSW.mjs → neon-ZIMHALYI.mjs} +106 -6
- package/dist/{pg-QO6NKTGL.mjs → pg-QGC2XHUT.mjs} +94 -5
- package/dist/{pg-IIH3M4OM.cjs → pg-RZPQGXR3.cjs} +98 -9
- package/dist/single-user.d.ts +95 -0
- package/dist/tenant/blob-store.d.ts +30 -0
- package/dist/tenant/context.d.ts +47 -0
- package/dist/tenant/single-user-context.d.ts +29 -0
- package/dist/tenant/token.d.ts +26 -0
- package/package.json +3 -3
- package/dist/chunk-5ENJGVZX.mjs +0 -72
- package/dist/chunk-GN5QTMCL.cjs +0 -1870
- package/dist/chunk-PVNLB6TF.mjs +0 -1870
- package/dist/chunk-RGECD4OH.cjs +0 -72
- package/dist/cloudflare-B-E51VjP.d.cts +0 -2848
- package/dist/cloudflare-B-E51VjP.d.ts +0 -2848
- package/dist/cloudflare.d.cts +0 -2
- package/dist/neon-CJl66EGy.d.cts +0 -251
- package/dist/neon-DYvGnCzx.d.ts +0 -251
- package/dist/pg-07S-u_H4.d.cts +0 -246
- package/dist/pg-Du-pN_UT.d.ts +0 -246
- package/dist/schema-C8OnYk6j.d.cts +0 -74
- package/dist/schema-C8OnYk6j.d.ts +0 -74
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// src/server/adapters/pg-shared.js
|
|
2
|
+
async function claimTask(query, taskId, expectedNextSendAt, leaseUntil, serializeGroup = null) {
|
|
3
|
+
const grouped = typeof serializeGroup === "string" && serializeGroup.length > 0;
|
|
4
|
+
const params = [leaseUntil, taskId, expectedNextSendAt];
|
|
5
|
+
let setClause = "lease_until = $1, updated_at = NOW()";
|
|
6
|
+
let groupGuard = "";
|
|
7
|
+
if (grouped) {
|
|
8
|
+
params.push(serializeGroup);
|
|
9
|
+
setClause = "lease_until = $1, serialize_group = $4, updated_at = NOW()";
|
|
10
|
+
groupGuard = `
|
|
11
|
+
AND NOT EXISTS (
|
|
12
|
+
SELECT 1 FROM scheduled_messages busy
|
|
13
|
+
WHERE busy.serialize_group = $4 AND busy.id <> $2
|
|
14
|
+
AND busy.status = 'pending' AND busy.lease_until > NOW()
|
|
15
|
+
)`;
|
|
16
|
+
}
|
|
17
|
+
const rows = await query(
|
|
18
|
+
`UPDATE scheduled_messages
|
|
19
|
+
SET ${setClause}
|
|
20
|
+
WHERE id = $2 AND status = 'pending'
|
|
21
|
+
AND date_trunc('milliseconds', next_send_at)
|
|
22
|
+
= date_trunc('milliseconds', $3::timestamptz)
|
|
23
|
+
AND (lease_until IS NULL OR lease_until <= NOW())${groupGuard}
|
|
24
|
+
RETURNING id`,
|
|
25
|
+
params
|
|
26
|
+
);
|
|
27
|
+
if (rows.length === 0) return false;
|
|
28
|
+
if (!grouped) return true;
|
|
29
|
+
const conflict = await query(
|
|
30
|
+
`SELECT 1 FROM scheduled_messages busy
|
|
31
|
+
WHERE busy.serialize_group = $1 AND busy.id <> $2
|
|
32
|
+
AND busy.status = 'pending' AND busy.lease_until > NOW()
|
|
33
|
+
LIMIT 1`,
|
|
34
|
+
[serializeGroup, taskId]
|
|
35
|
+
);
|
|
36
|
+
if (conflict.length === 0) return true;
|
|
37
|
+
await query(
|
|
38
|
+
"UPDATE scheduled_messages SET lease_until = NULL, updated_at = NOW() WHERE id = $1",
|
|
39
|
+
[taskId]
|
|
40
|
+
);
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
async function renewTaskLease(query, taskId, leaseUntil) {
|
|
44
|
+
const rows = await query(
|
|
45
|
+
`UPDATE scheduled_messages SET lease_until = $1
|
|
46
|
+
WHERE id = $2 AND status = 'pending' AND lease_until IS NOT NULL
|
|
47
|
+
RETURNING id`,
|
|
48
|
+
[leaseUntil, taskId]
|
|
49
|
+
);
|
|
50
|
+
return rows.length > 0;
|
|
51
|
+
}
|
|
52
|
+
async function getTaskStatusInfo(query, uuid, userId) {
|
|
53
|
+
const rows = await query(
|
|
54
|
+
"SELECT status, last_error FROM scheduled_messages WHERE uuid = $1 AND user_id = $2 LIMIT 1",
|
|
55
|
+
[uuid, userId]
|
|
56
|
+
);
|
|
57
|
+
if (rows.length === 0) return null;
|
|
58
|
+
return { status: rows[0].status, last_error: rows[0].last_error ?? null };
|
|
59
|
+
}
|
|
60
|
+
async function getPushSubscription(query, userId) {
|
|
61
|
+
const rows = await query(
|
|
62
|
+
"SELECT subscription, updated_at FROM push_subscriptions WHERE user_id = $1 LIMIT 1",
|
|
63
|
+
[userId]
|
|
64
|
+
);
|
|
65
|
+
if (rows.length === 0) return null;
|
|
66
|
+
return { subscription: rows[0].subscription, updated_at: Number(rows[0].updated_at) };
|
|
67
|
+
}
|
|
68
|
+
async function upsertPushSubscription(query, userId, encryptedSubscription, updatedAt) {
|
|
69
|
+
const rows = await query(
|
|
70
|
+
`INSERT INTO push_subscriptions (user_id, subscription, updated_at)
|
|
71
|
+
VALUES ($1, $2, $3)
|
|
72
|
+
ON CONFLICT (user_id) DO UPDATE SET
|
|
73
|
+
subscription = EXCLUDED.subscription,
|
|
74
|
+
updated_at = EXCLUDED.updated_at
|
|
75
|
+
RETURNING user_id`,
|
|
76
|
+
[userId, encryptedSubscription, updatedAt]
|
|
77
|
+
);
|
|
78
|
+
return rows.length > 0;
|
|
79
|
+
}
|
|
80
|
+
async function deletePushSubscription(query, userId) {
|
|
81
|
+
const rows = await query(
|
|
82
|
+
"DELETE FROM push_subscriptions WHERE user_id = $1 RETURNING user_id",
|
|
83
|
+
[userId]
|
|
84
|
+
);
|
|
85
|
+
return rows.length > 0;
|
|
86
|
+
}
|
|
87
|
+
async function upsertLlmCredentials(query, userId, entries, now) {
|
|
88
|
+
let upserted = 0;
|
|
89
|
+
for (const entry of entries) {
|
|
90
|
+
const rows = await query(
|
|
91
|
+
`INSERT INTO llm_credentials (user_id, cred_id, encrypted_value, created_at, updated_at)
|
|
92
|
+
VALUES ($1, $2, $3, $4, $4)
|
|
93
|
+
ON CONFLICT (user_id, cred_id) DO UPDATE SET
|
|
94
|
+
encrypted_value = EXCLUDED.encrypted_value,
|
|
95
|
+
updated_at = EXCLUDED.updated_at
|
|
96
|
+
RETURNING cred_id`,
|
|
97
|
+
[userId, entry.credId, entry.encryptedValue, now]
|
|
98
|
+
);
|
|
99
|
+
if (rows.length > 0) upserted++;
|
|
100
|
+
}
|
|
101
|
+
return upserted;
|
|
102
|
+
}
|
|
103
|
+
async function getLlmCredentials(query, userId, credIds) {
|
|
104
|
+
if (!credIds || credIds.length === 0) return [];
|
|
105
|
+
return query(
|
|
106
|
+
`SELECT cred_id, encrypted_value, updated_at
|
|
107
|
+
FROM llm_credentials
|
|
108
|
+
WHERE user_id = $1 AND cred_id = ANY($2)`,
|
|
109
|
+
[userId, credIds]
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
async function listLlmCredentials(query, userId) {
|
|
113
|
+
return query(
|
|
114
|
+
"SELECT cred_id, updated_at FROM llm_credentials WHERE user_id = $1 ORDER BY cred_id ASC",
|
|
115
|
+
[userId]
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
async function deleteLlmCredentials(query, userId, credIds = null) {
|
|
119
|
+
if (credIds !== null && credIds.length === 0) return 0;
|
|
120
|
+
const rows = credIds === null ? await query("DELETE FROM llm_credentials WHERE user_id = $1 RETURNING cred_id", [userId]) : await query("DELETE FROM llm_credentials WHERE user_id = $1 AND cred_id = ANY($2) RETURNING cred_id", [userId, credIds]);
|
|
121
|
+
return rows.length;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export {
|
|
125
|
+
claimTask,
|
|
126
|
+
renewTaskLease,
|
|
127
|
+
getTaskStatusInfo,
|
|
128
|
+
getPushSubscription,
|
|
129
|
+
upsertPushSubscription,
|
|
130
|
+
deletePushSubscription,
|
|
131
|
+
upsertLlmCredentials,
|
|
132
|
+
getLlmCredentials,
|
|
133
|
+
listLlmCredentials,
|
|
134
|
+
deleteLlmCredentials
|
|
135
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {(env: Object) => Object|Promise<Object>} buildConfig
|
|
3
|
+
* @param {{ onError?: (info: { stage: 'config'|'request'|'tick', error: unknown, cause: import('../lib/errors.js').ErrorCause, path: string|null }) => void|Promise<void> }} [options]
|
|
4
|
+
* `onError` 在 fetch 或 cron 出错时调一次(best-effort,自身抛错只记日志)。
|
|
5
|
+
* cron 那条路上没有调用方能看到错误响应,这个 hook 是宿主唯一的出口。
|
|
6
|
+
*/
|
|
7
|
+
export function createSingleUserCloudflareWorker(buildConfig: (env: any) => any | Promise<any>, options?: {
|
|
8
|
+
onError?: (info: {
|
|
9
|
+
stage: "config" | "request" | "tick";
|
|
10
|
+
error: unknown;
|
|
11
|
+
cause: import("../lib/errors.js").ErrorCause;
|
|
12
|
+
path: string | null;
|
|
13
|
+
}) => void | Promise<void>;
|
|
14
|
+
}): {
|
|
15
|
+
fetch: (request: any, env: any) => Promise<Response>;
|
|
16
|
+
scheduled: (event: any, env: any) => Promise<{
|
|
17
|
+
ok: true;
|
|
18
|
+
summary: any;
|
|
19
|
+
} | {
|
|
20
|
+
ok: false;
|
|
21
|
+
cause: import("../lib/errors.js").ErrorCause;
|
|
22
|
+
}>;
|
|
23
|
+
runTask: (uuid: string, env: any) => Promise<{
|
|
24
|
+
ran: false;
|
|
25
|
+
reason: "not_configured" | "not_found" | "already_settled" | "not_due" | "retry_pending";
|
|
26
|
+
status?: string;
|
|
27
|
+
nextSendAt?: string;
|
|
28
|
+
retryAfter?: string;
|
|
29
|
+
} | {
|
|
30
|
+
ran: true;
|
|
31
|
+
summary: any;
|
|
32
|
+
}>;
|
|
33
|
+
getSchemaVersion: (env: any) => Promise<import("../lib/schema-version.js").SchemaVersionResult>;
|
|
34
|
+
ensureSchema: (env: any) => Promise<import("../lib/schema-version.js").EnsureSchemaResult>;
|
|
35
|
+
};
|
|
36
|
+
export const CORS_ALLOW_HEADERS: "Content-Type, X-User-Id, X-Payload-Encrypted, X-Encryption-Version, X-Response-Encrypted, X-Client-Token";
|
|
37
|
+
export const CORS_ALLOW_METHODS: "GET, POST, PUT, DELETE, OPTIONS";
|
package/dist/cloudflare.cjs
CHANGED
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var _chunkGN5QTMCLcjs = require('./chunk-GN5QTMCL.cjs');
|
|
12
11
|
|
|
13
12
|
|
|
14
13
|
|
|
@@ -19,4 +18,42 @@ var _chunkGN5QTMCLcjs = require('./chunk-GN5QTMCL.cjs');
|
|
|
19
18
|
|
|
20
19
|
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
var _chunkQHVID3V2cjs = require('./chunk-QHVID3V2.cjs');
|
|
30
|
+
require('./chunk-7NMQFTDJ.cjs');
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
exports.DEFAULT_MAX_REQUEST_BODY_BYTES = _chunkQHVID3V2cjs.DEFAULT_MAX_REQUEST_BODY_BYTES; exports.MAX_PUSH_PAYLOAD_BYTES = _chunkQHVID3V2cjs.MAX_PUSH_PAYLOAD_BYTES; exports.NonRetryableError = _chunkQHVID3V2cjs.NonRetryableError; exports.PUSH_ENVELOPE_RESERVED_BYTES = _chunkQHVID3V2cjs.PUSH_ENVELOPE_RESERVED_BYTES; exports.SCHEMA_VERSION = _chunkQHVID3V2cjs.SCHEMA_VERSION; exports.WEB_PUSH_ENCRYPTION_OVERHEAD_BYTES = _chunkQHVID3V2cjs.WEB_PUSH_ENCRYPTION_OVERHEAD_BYTES; exports.WEB_PUSH_MAX_BODY_BYTES = _chunkQHVID3V2cjs.WEB_PUSH_MAX_BODY_BYTES; exports.advanceOccurrence = _chunkQHVID3V2cjs.advanceOccurrence; exports.createD1Adapter = _chunkQHVID3V2cjs.createD1Adapter; exports.createSingleUserCloudflareWorker = _chunkQHVID3V2cjs.createSingleUserCloudflareWorker; exports.createSingleUserServer = _chunkQHVID3V2cjs.createSingleUserServer; exports.createWebCryptoWebPush = _chunkQHVID3V2cjs.createWebCryptoWebPush; exports.decryptFromStorage = _chunkQHVID3V2cjs.decryptFromStorage; exports.decryptPayload = _chunkQHVID3V2cjs.decryptPayload; exports.deriveUserEncryptionKey = _chunkQHVID3V2cjs.deriveUserEncryptionKey; exports.encryptForStorage = _chunkQHVID3V2cjs.encryptForStorage; exports.ensureSchema = _chunkQHVID3V2cjs.ensureSchema; exports.getSchemaVersion = _chunkQHVID3V2cjs.getSchemaVersion; exports.isNonRetryableError = _chunkQHVID3V2cjs.isNonRetryableError; exports.isValidTimeZoneId = _chunkQHVID3V2cjs.isValidTimeZoneId; exports.measurePushPayload = _chunkQHVID3V2cjs.measurePushPayload; exports.nextFutureOccurrence = _chunkQHVID3V2cjs.nextFutureOccurrence; exports.planNextOccurrence = _chunkQHVID3V2cjs.planNextOccurrence; exports.readRequestBody = _chunkQHVID3V2cjs.readRequestBody; exports.runScheduledTick = _chunkQHVID3V2cjs.runScheduledTick; exports.runTask = _chunkQHVID3V2cjs.runTask; exports.summarizeErrorCause = _chunkQHVID3V2cjs.summarizeErrorCause;
|
package/dist/cloudflare.d.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
1
|
+
export { createSingleUserCloudflareWorker } from "./cloudflare/single-user-worker.js";
|
|
2
|
+
export { createSingleUserServer } from "./single-user.js";
|
|
3
|
+
export { createD1Adapter } from "./adapters/d1.js";
|
|
4
|
+
export { createWebCryptoWebPush, measurePushPayload, MAX_PUSH_PAYLOAD_BYTES, PUSH_ENVELOPE_RESERVED_BYTES, WEB_PUSH_MAX_BODY_BYTES, WEB_PUSH_ENCRYPTION_OVERHEAD_BYTES } from "./lib/webpush-webcrypto.js";
|
|
5
|
+
export { runScheduledTick, runTask } from "./lib/run-tick.js";
|
|
6
|
+
export { getSchemaVersion, ensureSchema, SCHEMA_VERSION } from "./lib/schema-version.js";
|
|
7
|
+
export { summarizeErrorCause, NonRetryableError, isNonRetryableError } from "./lib/errors.js";
|
|
8
|
+
export { isValidTimeZoneId, advanceOccurrence, nextFutureOccurrence, planNextOccurrence } from "./lib/recurrence.js";
|
|
9
|
+
export { readRequestBody, DEFAULT_MAX_REQUEST_BODY_BYTES } from "./lib/request.js";
|
|
10
|
+
export { deriveUserEncryptionKey, decryptPayload, encryptForStorage, decryptFromStorage } from "./lib/encryption.js";
|
package/dist/cloudflare.mjs
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DEFAULT_MAX_REQUEST_BODY_BYTES,
|
|
3
|
+
MAX_PUSH_PAYLOAD_BYTES,
|
|
4
|
+
NonRetryableError,
|
|
5
|
+
PUSH_ENVELOPE_RESERVED_BYTES,
|
|
6
|
+
SCHEMA_VERSION,
|
|
7
|
+
WEB_PUSH_ENCRYPTION_OVERHEAD_BYTES,
|
|
8
|
+
WEB_PUSH_MAX_BODY_BYTES,
|
|
9
|
+
advanceOccurrence,
|
|
2
10
|
createD1Adapter,
|
|
3
11
|
createSingleUserCloudflareWorker,
|
|
4
12
|
createSingleUserServer,
|
|
@@ -7,9 +15,28 @@ import {
|
|
|
7
15
|
decryptPayload,
|
|
8
16
|
deriveUserEncryptionKey,
|
|
9
17
|
encryptForStorage,
|
|
10
|
-
|
|
11
|
-
|
|
18
|
+
ensureSchema,
|
|
19
|
+
getSchemaVersion,
|
|
20
|
+
isNonRetryableError,
|
|
21
|
+
isValidTimeZoneId,
|
|
22
|
+
measurePushPayload,
|
|
23
|
+
nextFutureOccurrence,
|
|
24
|
+
planNextOccurrence,
|
|
25
|
+
readRequestBody,
|
|
26
|
+
runScheduledTick,
|
|
27
|
+
runTask,
|
|
28
|
+
summarizeErrorCause
|
|
29
|
+
} from "./chunk-KOJQVOYS.mjs";
|
|
30
|
+
import "./chunk-GN44PST5.mjs";
|
|
12
31
|
export {
|
|
32
|
+
DEFAULT_MAX_REQUEST_BODY_BYTES,
|
|
33
|
+
MAX_PUSH_PAYLOAD_BYTES,
|
|
34
|
+
NonRetryableError,
|
|
35
|
+
PUSH_ENVELOPE_RESERVED_BYTES,
|
|
36
|
+
SCHEMA_VERSION,
|
|
37
|
+
WEB_PUSH_ENCRYPTION_OVERHEAD_BYTES,
|
|
38
|
+
WEB_PUSH_MAX_BODY_BYTES,
|
|
39
|
+
advanceOccurrence,
|
|
13
40
|
createD1Adapter,
|
|
14
41
|
createSingleUserCloudflareWorker,
|
|
15
42
|
createSingleUserServer,
|
|
@@ -18,5 +45,15 @@ export {
|
|
|
18
45
|
decryptPayload,
|
|
19
46
|
deriveUserEncryptionKey,
|
|
20
47
|
encryptForStorage,
|
|
21
|
-
|
|
48
|
+
ensureSchema,
|
|
49
|
+
getSchemaVersion,
|
|
50
|
+
isNonRetryableError,
|
|
51
|
+
isValidTimeZoneId,
|
|
52
|
+
measurePushPayload,
|
|
53
|
+
nextFutureOccurrence,
|
|
54
|
+
planNextOccurrence,
|
|
55
|
+
readRequestBody,
|
|
56
|
+
runScheduledTick,
|
|
57
|
+
runTask,
|
|
58
|
+
summarizeErrorCause
|
|
22
59
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function createClientStateHandler(ctx: any): {
|
|
2
|
+
PUT: (headers: any, body: any) => Promise<any>;
|
|
3
|
+
GET: (url: any, headers: any) => Promise<any>;
|
|
4
|
+
DELETE: (url: any, headers: any) => Promise<any>;
|
|
5
|
+
};
|
|
6
|
+
export const MAX_STATE_VALUE_BYTES: number;
|
|
7
|
+
export const MAX_STATE_ENTRIES_PER_REQUEST: 200;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function createInitTenantHandler(ctx: any): {
|
|
2
|
+
POST: (headers: any, body: any) => Promise<{
|
|
3
|
+
status: number;
|
|
4
|
+
body: {
|
|
5
|
+
success: boolean;
|
|
6
|
+
error: any;
|
|
7
|
+
data?: undefined;
|
|
8
|
+
};
|
|
9
|
+
} | {
|
|
10
|
+
status: number;
|
|
11
|
+
body: {
|
|
12
|
+
success: boolean;
|
|
13
|
+
data: {
|
|
14
|
+
tenantId: any;
|
|
15
|
+
tenantToken: any;
|
|
16
|
+
cronToken: any;
|
|
17
|
+
cronWebhookUrl: any;
|
|
18
|
+
masterKeyFingerprint: any;
|
|
19
|
+
};
|
|
20
|
+
error?: undefined;
|
|
21
|
+
};
|
|
22
|
+
}>;
|
|
23
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function createOutboxHandler(ctx: any): {
|
|
2
|
+
GET: (url: any, headers: any) => Promise<any>;
|
|
3
|
+
POST: (headers: any, body: any) => Promise<any>;
|
|
4
|
+
};
|
|
5
|
+
export const MAX_OUTBOX_PAGE_SIZE: 100;
|
|
6
|
+
export const DEFAULT_OUTBOX_PAGE_SIZE: 50;
|
|
7
|
+
export const MAX_OUTBOX_ACK_IDS: 200;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handler: single-user-init
|
|
3
|
+
*
|
|
4
|
+
* Idempotent "just create the tables" endpoint for single-user deployments
|
|
5
|
+
* (the degenerate form of init-tenant). Reuses resolveTenant purely to enforce
|
|
6
|
+
* the optional shared secret, then runs initSchema. Issues no token.
|
|
7
|
+
*
|
|
8
|
+
* @param {Object} ctx - Single-user server context (ctx.tenantManager).
|
|
9
|
+
* @returns {{ POST: function }}
|
|
10
|
+
*/
|
|
11
|
+
export function createSingleUserInitHandler(ctx: any): {
|
|
12
|
+
POST: Function;
|
|
13
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handler: vapid-public-key
|
|
3
|
+
*
|
|
4
|
+
* Exposes this worker's own VAPID public key so a browser frontend can build a
|
|
5
|
+
* Web Push subscription (`applicationServerKey`) at runtime. Each self-hosted
|
|
6
|
+
* worker owns its keypair, so the key can't be baked into the frontend — it
|
|
7
|
+
* pulls it from here.
|
|
8
|
+
*
|
|
9
|
+
* Auth funnels through the same resolveTenant as every other endpoint, so with
|
|
10
|
+
* a serverToken configured this route requires `X-Client-Token` too (the
|
|
11
|
+
* all-or-nothing contract). The public key itself is not a secret; gating it
|
|
12
|
+
* just keeps every endpoint consistent.
|
|
13
|
+
*
|
|
14
|
+
* @param {Object} ctx - Server context ({ vapid, tenantManager, ... }).
|
|
15
|
+
* @returns {{ GET: function }}
|
|
16
|
+
*/
|
|
17
|
+
export function createVapidPublicKeyHandler(ctx: any): {
|
|
18
|
+
GET: Function;
|
|
19
|
+
};
|