@pellux/goodvibes-sdk 0.25.10 → 0.25.11
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/dist/_internal/contracts/artifacts/operator-contract.json +178 -6
- package/dist/_internal/contracts/generated/foundation-client-types.d.ts +16 -1
- package/dist/_internal/contracts/generated/foundation-client-types.d.ts.map +1 -1
- package/dist/_internal/contracts/generated/foundation-metadata.d.ts +2 -2
- package/dist/_internal/contracts/generated/foundation-metadata.js +2 -2
- package/dist/_internal/contracts/generated/operator-contract.d.ts.map +1 -1
- package/dist/_internal/contracts/generated/operator-contract.js +178 -6
- package/dist/_internal/contracts/generated/operator-method-ids.d.ts +1 -1
- package/dist/_internal/contracts/generated/operator-method-ids.d.ts.map +1 -1
- package/dist/_internal/contracts/generated/operator-method-ids.js +1 -0
- package/dist/_internal/daemon/context.d.ts +1 -0
- package/dist/_internal/daemon/context.d.ts.map +1 -1
- package/dist/_internal/daemon/integration-route-types.d.ts +1 -0
- package/dist/_internal/daemon/integration-route-types.d.ts.map +1 -1
- package/dist/_internal/daemon/integration-routes.d.ts +1 -1
- package/dist/_internal/daemon/integration-routes.d.ts.map +1 -1
- package/dist/_internal/daemon/integration-routes.js +3 -0
- package/dist/_internal/daemon/operator.d.ts +1 -1
- package/dist/_internal/daemon/operator.d.ts.map +1 -1
- package/dist/_internal/daemon/operator.js +2 -0
- package/dist/_internal/daemon/runtime-route-types.d.ts +1 -1
- package/dist/_internal/daemon/runtime-route-types.d.ts.map +1 -1
- package/dist/_internal/platform/adapters/discord/index.d.ts.map +1 -1
- package/dist/_internal/platform/adapters/discord/index.js +4 -5
- package/dist/_internal/platform/adapters/github/index.d.ts.map +1 -1
- package/dist/_internal/platform/adapters/github/index.js +4 -5
- package/dist/_internal/platform/adapters/google-chat/index.d.ts.map +1 -1
- package/dist/_internal/platform/adapters/google-chat/index.js +7 -5
- package/dist/_internal/platform/adapters/helpers.d.ts +2 -1
- package/dist/_internal/platform/adapters/helpers.d.ts.map +1 -1
- package/dist/_internal/platform/adapters/helpers.js +3 -34
- package/dist/_internal/platform/adapters/homeassistant/index.d.ts +3 -0
- package/dist/_internal/platform/adapters/homeassistant/index.d.ts.map +1 -0
- package/dist/_internal/platform/adapters/homeassistant/index.js +177 -0
- package/dist/_internal/platform/adapters/index.d.ts +1 -0
- package/dist/_internal/platform/adapters/index.d.ts.map +1 -1
- package/dist/_internal/platform/adapters/index.js +1 -0
- package/dist/_internal/platform/adapters/mattermost/index.d.ts.map +1 -1
- package/dist/_internal/platform/adapters/mattermost/index.js +6 -2
- package/dist/_internal/platform/adapters/slack/index.d.ts.map +1 -1
- package/dist/_internal/platform/adapters/slack/index.js +4 -5
- package/dist/_internal/platform/adapters/telegram/index.d.ts.map +1 -1
- package/dist/_internal/platform/adapters/telegram/index.js +7 -5
- package/dist/_internal/platform/adapters/types.d.ts +1 -1
- package/dist/_internal/platform/adapters/types.d.ts.map +1 -1
- package/dist/_internal/platform/adapters/webhook/index.d.ts.map +1 -1
- package/dist/_internal/platform/adapters/webhook/index.js +4 -1
- package/dist/_internal/platform/automation/types.d.ts +1 -1
- package/dist/_internal/platform/automation/types.d.ts.map +1 -1
- package/dist/_internal/platform/channels/builtin/accounts.d.ts.map +1 -1
- package/dist/_internal/platform/channels/builtin/accounts.js +22 -0
- package/dist/_internal/platform/channels/builtin/contracts.d.ts.map +1 -1
- package/dist/_internal/platform/channels/builtin/contracts.js +9 -0
- package/dist/_internal/platform/channels/builtin/descriptors.d.ts.map +1 -1
- package/dist/_internal/platform/channels/builtin/descriptors.js +9 -2
- package/dist/_internal/platform/channels/builtin/homeassistant.d.ts +64 -0
- package/dist/_internal/platform/channels/builtin/homeassistant.d.ts.map +1 -0
- package/dist/_internal/platform/channels/builtin/homeassistant.js +380 -0
- package/dist/_internal/platform/channels/builtin/plugins.d.ts.map +1 -1
- package/dist/_internal/platform/channels/builtin/plugins.js +2 -1
- package/dist/_internal/platform/channels/builtin/presentation.d.ts.map +1 -1
- package/dist/_internal/platform/channels/builtin/presentation.js +4 -0
- package/dist/_internal/platform/channels/builtin/setup-schema.d.ts.map +1 -1
- package/dist/_internal/platform/channels/builtin/setup-schema.js +46 -0
- package/dist/_internal/platform/channels/builtin/shared.d.ts +1 -1
- package/dist/_internal/platform/channels/builtin/shared.d.ts.map +1 -1
- package/dist/_internal/platform/channels/builtin/shared.js +2 -0
- package/dist/_internal/platform/channels/builtin/surfaces.d.ts.map +1 -1
- package/dist/_internal/platform/channels/builtin/surfaces.js +1 -0
- package/dist/_internal/platform/channels/builtin/targets.d.ts.map +1 -1
- package/dist/_internal/platform/channels/builtin/targets.js +24 -0
- package/dist/_internal/platform/channels/builtin-runtime.d.ts.map +1 -1
- package/dist/_internal/platform/channels/builtin-runtime.js +6 -0
- package/dist/_internal/platform/channels/delivery/strategies-core.d.ts +1 -0
- package/dist/_internal/platform/channels/delivery/strategies-core.d.ts.map +1 -1
- package/dist/_internal/platform/channels/delivery/strategies-core.js +41 -1
- package/dist/_internal/platform/channels/delivery-router.d.ts.map +1 -1
- package/dist/_internal/platform/channels/delivery-router.js +2 -1
- package/dist/_internal/platform/channels/reply-pipeline.d.ts.map +1 -1
- package/dist/_internal/platform/channels/reply-pipeline.js +9 -0
- package/dist/_internal/platform/channels/route-manager.d.ts.map +1 -1
- package/dist/_internal/platform/channels/route-manager.js +1 -0
- package/dist/_internal/platform/channels/surface-registry.d.ts.map +1 -1
- package/dist/_internal/platform/channels/surface-registry.js +4 -0
- package/dist/_internal/platform/channels/types.d.ts +1 -1
- package/dist/_internal/platform/channels/types.d.ts.map +1 -1
- package/dist/_internal/platform/cloudflare/manager.d.ts +1 -1
- package/dist/_internal/platform/cloudflare/manager.d.ts.map +1 -1
- package/dist/_internal/platform/cloudflare/manager.js +27 -24
- package/dist/_internal/platform/cloudflare/types.d.ts +5 -0
- package/dist/_internal/platform/cloudflare/types.d.ts.map +1 -1
- package/dist/_internal/platform/cloudflare/utils.d.ts.map +1 -1
- package/dist/_internal/platform/cloudflare/utils.js +4 -10
- package/dist/_internal/platform/companion/companion-chat-manager.d.ts +24 -4
- package/dist/_internal/platform/companion/companion-chat-manager.d.ts.map +1 -1
- package/dist/_internal/platform/companion/companion-chat-manager.js +128 -78
- package/dist/_internal/platform/config/schema-domain-surfaces.d.ts +11 -0
- package/dist/_internal/platform/config/schema-domain-surfaces.d.ts.map +1 -1
- package/dist/_internal/platform/config/schema-domain-surfaces.js +59 -0
- package/dist/_internal/platform/config/schema-types.d.ts +14 -2
- package/dist/_internal/platform/config/schema-types.d.ts.map +1 -1
- package/dist/_internal/platform/control-plane/gateway-utils.d.ts +37 -0
- package/dist/_internal/platform/control-plane/gateway-utils.d.ts.map +1 -0
- package/dist/_internal/platform/control-plane/gateway-utils.js +97 -0
- package/dist/_internal/platform/control-plane/gateway.d.ts +4 -9
- package/dist/_internal/platform/control-plane/gateway.d.ts.map +1 -1
- package/dist/_internal/platform/control-plane/gateway.js +26 -61
- package/dist/_internal/platform/control-plane/method-catalog-runtime.d.ts.map +1 -1
- package/dist/_internal/platform/control-plane/method-catalog-runtime.js +11 -1
- package/dist/_internal/platform/control-plane/operator-contract-schemas-admin.d.ts.map +1 -1
- package/dist/_internal/platform/control-plane/operator-contract-schemas-admin.js +3 -2
- package/dist/_internal/platform/control-plane/operator-contract-schemas-control.d.ts +1 -0
- package/dist/_internal/platform/control-plane/operator-contract-schemas-control.d.ts.map +1 -1
- package/dist/_internal/platform/control-plane/operator-contract-schemas-control.js +26 -0
- package/dist/_internal/platform/control-plane/routes/operator.d.ts +1 -1
- package/dist/_internal/platform/control-plane/routes/operator.d.ts.map +1 -1
- package/dist/_internal/platform/control-plane/routes/operator.js +2 -0
- package/dist/_internal/platform/control-plane/types.d.ts +1 -1
- package/dist/_internal/platform/control-plane/types.d.ts.map +1 -1
- package/dist/_internal/platform/daemon/control-plane.d.ts.map +1 -1
- package/dist/_internal/platform/daemon/control-plane.js +50 -6
- package/dist/_internal/platform/daemon/facade-composition.d.ts.map +1 -1
- package/dist/_internal/platform/daemon/facade-composition.js +30 -2
- package/dist/_internal/platform/daemon/facade-types.d.ts +1 -1
- package/dist/_internal/platform/daemon/facade-types.d.ts.map +1 -1
- package/dist/_internal/platform/daemon/http/router.d.ts +2 -2
- package/dist/_internal/platform/daemon/http/router.d.ts.map +1 -1
- package/dist/_internal/platform/daemon/http/router.js +7 -16
- package/dist/_internal/platform/daemon/http/runtime-route-types.d.ts +1 -1
- package/dist/_internal/platform/daemon/http/runtime-route-types.d.ts.map +1 -1
- package/dist/_internal/platform/daemon/http-listener.d.ts.map +1 -1
- package/dist/_internal/platform/daemon/http-listener.js +4 -8
- package/dist/_internal/platform/daemon/surface-actions.d.ts +1 -1
- package/dist/_internal/platform/daemon/surface-actions.d.ts.map +1 -1
- package/dist/_internal/platform/daemon/surface-delivery.d.ts +1 -1
- package/dist/_internal/platform/daemon/surface-delivery.d.ts.map +1 -1
- package/dist/_internal/platform/daemon/surface-delivery.js +1 -0
- package/dist/_internal/platform/daemon/surface-policy.d.ts +1 -1
- package/dist/_internal/platform/daemon/surface-policy.d.ts.map +1 -1
- package/dist/_internal/platform/daemon/surface-policy.js +8 -0
- package/dist/_internal/platform/daemon/types.d.ts +2 -2
- package/dist/_internal/platform/daemon/types.d.ts.map +1 -1
- package/dist/_internal/platform/integrations/homeassistant.d.ts +58 -0
- package/dist/_internal/platform/integrations/homeassistant.d.ts.map +1 -0
- package/dist/_internal/platform/integrations/homeassistant.js +174 -0
- package/dist/_internal/platform/integrations/index.d.ts +2 -0
- package/dist/_internal/platform/integrations/index.d.ts.map +1 -1
- package/dist/_internal/platform/integrations/index.js +1 -0
- package/dist/_internal/platform/runtime/events/control-plane.d.ts +1 -1
- package/dist/_internal/platform/runtime/events/control-plane.d.ts.map +1 -1
- package/dist/_internal/platform/runtime/events/control-plane.js +1 -0
- package/dist/_internal/platform/runtime/events/routes.d.ts +1 -1
- package/dist/_internal/platform/runtime/events/routes.d.ts.map +1 -1
- package/dist/_internal/platform/runtime/events/routes.js +1 -0
- package/dist/_internal/platform/runtime/feature-flags/flags.d.ts.map +1 -1
- package/dist/_internal/platform/runtime/feature-flags/flags.js +9 -0
- package/dist/_internal/platform/runtime/feature-flags/gates.d.ts.map +1 -1
- package/dist/_internal/platform/runtime/feature-flags/gates.js +2 -0
- package/dist/_internal/platform/runtime/index.d.ts +2 -0
- package/dist/_internal/platform/runtime/index.d.ts.map +1 -1
- package/dist/_internal/platform/runtime/index.js +1 -0
- package/dist/_internal/platform/runtime/integration/helpers.d.ts +4 -0
- package/dist/_internal/platform/runtime/integration/helpers.d.ts.map +1 -1
- package/dist/_internal/platform/runtime/integration/helpers.js +4 -0
- package/dist/_internal/platform/runtime/security-settings.d.ts +19 -0
- package/dist/_internal/platform/runtime/security-settings.d.ts.map +1 -0
- package/dist/_internal/platform/runtime/security-settings.js +187 -0
- package/dist/_internal/platform/runtime/services.d.ts.map +1 -1
- package/dist/_internal/platform/runtime/services.js +1 -0
- package/dist/_internal/platform/security/user-auth.d.ts +1 -1
- package/dist/_internal/platform/security/user-auth.d.ts.map +1 -1
- package/dist/_internal/platform/security/user-auth.js +18 -3
- package/dist/_internal/platform/tools/edit/core.d.ts.map +1 -1
- package/dist/_internal/platform/tools/edit/core.js +4 -47
- package/dist/_internal/platform/tools/exec/runtime.d.ts.map +1 -1
- package/dist/_internal/platform/tools/exec/runtime.js +7 -1
- package/dist/_internal/platform/tools/exec/schema.d.ts +1 -0
- package/dist/_internal/platform/tools/exec/schema.d.ts.map +1 -1
- package/dist/_internal/platform/tools/exec/schema.js +1 -0
- package/dist/_internal/platform/tools/fetch/runtime.d.ts.map +1 -1
- package/dist/_internal/platform/tools/fetch/runtime.js +140 -19
- package/dist/_internal/platform/tools/fetch/schema.d.ts +1 -0
- package/dist/_internal/platform/tools/fetch/schema.d.ts.map +1 -1
- package/dist/_internal/platform/tools/fetch/schema.js +1 -0
- package/dist/_internal/platform/tools/find/executor.d.ts.map +1 -1
- package/dist/_internal/platform/tools/find/executor.js +7 -1
- package/dist/_internal/platform/tools/find/schema.d.ts.map +1 -1
- package/dist/_internal/platform/tools/find/schema.js +2 -0
- package/dist/_internal/platform/tools/read/index.d.ts.map +1 -1
- package/dist/_internal/platform/tools/read/index.js +7 -1
- package/dist/_internal/platform/tools/read/schema.d.ts +1 -0
- package/dist/_internal/platform/tools/read/schema.d.ts.map +1 -1
- package/dist/_internal/platform/tools/read/schema.js +1 -0
- package/dist/_internal/platform/tools/shared/process-manager.d.ts +2 -0
- package/dist/_internal/platform/tools/shared/process-manager.d.ts.map +1 -1
- package/dist/_internal/platform/tools/shared/process-manager.js +67 -5
- package/dist/_internal/platform/tools/write/index.d.ts.map +1 -1
- package/dist/_internal/platform/tools/write/index.js +3 -36
- package/dist/_internal/platform/utils/concurrency.d.ts +3 -0
- package/dist/_internal/platform/utils/concurrency.d.ts.map +1 -0
- package/dist/_internal/platform/utils/concurrency.js +17 -0
- package/dist/_internal/platform/utils/logger.d.ts.map +1 -1
- package/dist/_internal/platform/utils/logger.js +19 -1
- package/dist/_internal/platform/utils/request-body.d.ts +4 -0
- package/dist/_internal/platform/utils/request-body.d.ts.map +1 -0
- package/dist/_internal/platform/utils/request-body.js +45 -0
- package/dist/_internal/platform/version.js +1 -1
- package/dist/workers.d.ts +6 -0
- package/dist/workers.d.ts.map +1 -1
- package/dist/workers.js +55 -3
- package/package.json +1 -1
|
@@ -5,6 +5,8 @@ import { join } from 'path';
|
|
|
5
5
|
const LOG_BUFFER_MAX = 10;
|
|
6
6
|
/** Flush interval in milliseconds when buffer is below max. */
|
|
7
7
|
const LOG_FLUSH_INTERVAL_MS = 100;
|
|
8
|
+
const REDACTED = '[REDACTED]';
|
|
9
|
+
const SENSITIVE_KEY_PATTERN = /(authorization|api[-_]?key|token|password|passwd|secret|credential|cookie|set-cookie)/i;
|
|
8
10
|
/**
|
|
9
11
|
* ActivityLogger — Persistent debug logger for GoodVibes.
|
|
10
12
|
* Writes to .goodvibes/logs/activity.md
|
|
@@ -30,6 +32,7 @@ class ActivityLogger {
|
|
|
30
32
|
if (this.flushTimer !== null)
|
|
31
33
|
return;
|
|
32
34
|
this.flushTimer = setTimeout(() => this.flush(), LOG_FLUSH_INTERVAL_MS);
|
|
35
|
+
this.flushTimer.unref?.();
|
|
33
36
|
}
|
|
34
37
|
flush() {
|
|
35
38
|
this.flushTimer = null;
|
|
@@ -49,7 +52,7 @@ class ActivityLogger {
|
|
|
49
52
|
const timestamp = new Date().toISOString();
|
|
50
53
|
let entry = `[${timestamp}] [${level}] ${message}\n`;
|
|
51
54
|
if (data) {
|
|
52
|
-
entry += '```json\n' + JSON.stringify(data, null, 2) + '\n```\n';
|
|
55
|
+
entry += '```json\n' + JSON.stringify(redactLogData(data), null, 2) + '\n```\n';
|
|
53
56
|
}
|
|
54
57
|
this.buffer.push(entry);
|
|
55
58
|
if (this.buffer.length >= LOG_BUFFER_MAX) {
|
|
@@ -73,3 +76,18 @@ export const logger = new ActivityLogger();
|
|
|
73
76
|
export function configureActivityLogger(logDir) {
|
|
74
77
|
logger.configure(logDir);
|
|
75
78
|
}
|
|
79
|
+
function redactLogData(value, seen = new WeakSet()) {
|
|
80
|
+
if (value === null || typeof value !== 'object')
|
|
81
|
+
return value;
|
|
82
|
+
if (seen.has(value))
|
|
83
|
+
return '[Circular]';
|
|
84
|
+
seen.add(value);
|
|
85
|
+
if (Array.isArray(value)) {
|
|
86
|
+
return value.map((item) => redactLogData(item, seen));
|
|
87
|
+
}
|
|
88
|
+
const out = {};
|
|
89
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
90
|
+
out[key] = SENSITIVE_KEY_PATTERN.test(key) ? REDACTED : redactLogData(nested, seen);
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const DEFAULT_MAX_REQUEST_BODY_BYTES = 1000000;
|
|
2
|
+
export declare function readTextBodyWithinLimit(req: Request, maxBytes?: number): Promise<string | Response>;
|
|
3
|
+
export declare function readJsonBodyWithinLimit(req: Request, maxBytes?: number): Promise<unknown | Response>;
|
|
4
|
+
//# sourceMappingURL=request-body.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-body.d.ts","sourceRoot":"","sources":["../../../../src/_internal/platform/utils/request-body.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,8BAA8B,UAAY,CAAC;AAMxD,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,OAAO,EACZ,QAAQ,SAAiC,GACxC,OAAO,CAAC,MAAM,GAAG,QAAQ,CAAC,CA4B5B;AAED,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,OAAO,EACZ,QAAQ,SAAiC,GACxC,OAAO,CAAC,OAAO,GAAG,QAAQ,CAAC,CAQ7B"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const DEFAULT_MAX_REQUEST_BODY_BYTES = 1_000_000;
|
|
2
|
+
function ignoreCancelError() {
|
|
3
|
+
// Best-effort stream cancellation.
|
|
4
|
+
}
|
|
5
|
+
export async function readTextBodyWithinLimit(req, maxBytes = DEFAULT_MAX_REQUEST_BODY_BYTES) {
|
|
6
|
+
const contentLength = Number.parseInt(req.headers.get('content-length') ?? '0', 10);
|
|
7
|
+
if (Number.isFinite(contentLength) && contentLength > maxBytes) {
|
|
8
|
+
return Response.json({ error: 'Payload too large' }, { status: 413 });
|
|
9
|
+
}
|
|
10
|
+
if (!req.body)
|
|
11
|
+
return '';
|
|
12
|
+
const reader = req.body.getReader();
|
|
13
|
+
const decoder = new TextDecoder();
|
|
14
|
+
let total = 0;
|
|
15
|
+
let body = '';
|
|
16
|
+
try {
|
|
17
|
+
for (;;) {
|
|
18
|
+
const { done, value } = await reader.read();
|
|
19
|
+
if (done)
|
|
20
|
+
break;
|
|
21
|
+
total += value.byteLength;
|
|
22
|
+
if (total > maxBytes) {
|
|
23
|
+
await reader.cancel('Payload too large').catch(ignoreCancelError);
|
|
24
|
+
return Response.json({ error: 'Payload too large' }, { status: 413 });
|
|
25
|
+
}
|
|
26
|
+
body += decoder.decode(value, { stream: true });
|
|
27
|
+
}
|
|
28
|
+
body += decoder.decode();
|
|
29
|
+
return body;
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
reader.releaseLock();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export async function readJsonBodyWithinLimit(req, maxBytes = DEFAULT_MAX_REQUEST_BODY_BYTES) {
|
|
36
|
+
const raw = await readTextBodyWithinLimit(req, maxBytes);
|
|
37
|
+
if (raw instanceof Response)
|
|
38
|
+
return raw;
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(raw);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return Response.json({ error: 'Invalid JSON body' }, { status: 400 });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
let version = '0.25.
|
|
3
|
+
let version = '0.25.11';
|
|
4
4
|
try {
|
|
5
5
|
const pkg = JSON.parse(readFileSync(join(import.meta.dir, '..', '..', 'package.json'), 'utf-8'));
|
|
6
6
|
version = pkg.version ?? version;
|
package/dist/workers.d.ts
CHANGED
|
@@ -33,6 +33,12 @@ export interface GoodVibesCloudflareWorkerOptions {
|
|
|
33
33
|
readonly authToken?: string;
|
|
34
34
|
readonly workerAuthToken?: string;
|
|
35
35
|
readonly queueJobPayloads?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Explicitly allow unauthenticated non-health endpoints.
|
|
38
|
+
* Default is false: GOODVIBES_WORKER_TOKEN or workerAuthToken is required.
|
|
39
|
+
*/
|
|
40
|
+
readonly allowUnauthenticated?: boolean;
|
|
41
|
+
readonly maxRequestBodyBytes?: number;
|
|
36
42
|
}
|
|
37
43
|
export interface GoodVibesCloudflareWorker {
|
|
38
44
|
fetch(request: Request, env: GoodVibesCloudflareWorkerEnv, ctx: GoodVibesCloudflareExecutionContext): Promise<Response>;
|
package/dist/workers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workers.d.ts","sourceRoot":"","sources":["../src/workers.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB,CAAC,IAAI,GAAG,OAAO;IACtD,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,+BAA+B,CAAC,IAAI,GAAG,OAAO;IAC7D,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,GAAG,CAAC,IAAI,IAAI,CAAC;IACb,KAAK,CAAC,IAAI,IAAI,CAAC;CAChB;AAED,MAAM,WAAW,+BAA+B,CAAC,IAAI,GAAG,OAAO;IAC7D,QAAQ,CAAC,QAAQ,EAAE,SAAS,+BAA+B,CAAC,IAAI,CAAC,EAAE,CAAC;CACrE;AAED,MAAM,WAAW,mCAAmC;IAClD,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,4BAA4B;IAC3C,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,4BAA4B,CAAC,EAAE,MAAM,CAAC;IACtC,qBAAqB,CAAC,EAAE,wBAAwB,CAAC,+BAA+B,CAAC,CAAC;CACnF;AAED,MAAM,MAAM,+BAA+B,GACvC;IACE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE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(options = {}) {
|
|
|
13
13
|
if (!queue)
|
|
14
14
|
return json({ error: 'GOODVIBES_BATCH_QUEUE is not bound', code: 'QUEUE_NOT_CONFIGURED' }, 503);
|
|
15
15
|
const body = await optionalJson(request);
|
|
16
|
+
if (body instanceof Response)
|
|
17
|
+
return body;
|
|
16
18
|
await queue.send({
|
|
17
19
|
type: 'batch.tick',
|
|
18
20
|
force: toRecord(body)['force'] === true,
|
|
@@ -34,6 +36,8 @@ export function createGoodVibesCloudflareWorker(options = {}) {
|
|
|
34
36
|
if (!queue)
|
|
35
37
|
return json({ error: 'GOODVIBES_BATCH_QUEUE is not bound', code: 'QUEUE_NOT_CONFIGURED' }, 503);
|
|
36
38
|
const body = await optionalJson(request);
|
|
39
|
+
if (body instanceof Response)
|
|
40
|
+
return body;
|
|
37
41
|
await queue.send({
|
|
38
42
|
type: 'batch.job.create',
|
|
39
43
|
body: toRecord(body),
|
|
@@ -86,7 +90,17 @@ async function handleQueuePayload(payload, env, options) {
|
|
|
86
90
|
});
|
|
87
91
|
}
|
|
88
92
|
async function proxyDaemonBatch(request, env, options, daemonPath) {
|
|
89
|
-
|
|
93
|
+
if (request.method !== 'GET' && request.method !== 'HEAD') {
|
|
94
|
+
const contentType = request.headers.get('content-type') ?? '';
|
|
95
|
+
if (contentType && !contentType.toLowerCase().includes('application/json')) {
|
|
96
|
+
return json({ error: 'Only application/json batch payloads are supported', code: 'UNSUPPORTED_MEDIA_TYPE' }, 415);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const body = request.method === 'GET' || request.method === 'HEAD'
|
|
100
|
+
? undefined
|
|
101
|
+
: await readTextBodyWithinLimit(request, options.maxRequestBodyBytes);
|
|
102
|
+
if (body instanceof Response)
|
|
103
|
+
return body;
|
|
90
104
|
return proxyDaemonJson(env, options, daemonPath, {
|
|
91
105
|
method: request.method,
|
|
92
106
|
body,
|
|
@@ -121,8 +135,14 @@ function toDaemonBatchPath(pathname) {
|
|
|
121
135
|
}
|
|
122
136
|
function requireWorkerAuth(request, env, options) {
|
|
123
137
|
const expected = options.workerAuthToken ?? env.GOODVIBES_WORKER_TOKEN ?? '';
|
|
124
|
-
if (!expected)
|
|
138
|
+
if (!expected && options.allowUnauthenticated === true)
|
|
125
139
|
return null;
|
|
140
|
+
if (!expected) {
|
|
141
|
+
return json({
|
|
142
|
+
error: 'GOODVIBES_WORKER_TOKEN is required for non-health endpoints',
|
|
143
|
+
code: 'WORKER_AUTH_TOKEN_REQUIRED',
|
|
144
|
+
}, 503);
|
|
145
|
+
}
|
|
126
146
|
const auth = request.headers.get('authorization') ?? '';
|
|
127
147
|
if (auth === `Bearer ${expected}`)
|
|
128
148
|
return null;
|
|
@@ -133,7 +153,9 @@ function resolveDaemonUrl(env, options) {
|
|
|
133
153
|
return raw.replace(/\/+$/, '');
|
|
134
154
|
}
|
|
135
155
|
async function optionalJson(request) {
|
|
136
|
-
const text = await request
|
|
156
|
+
const text = await readTextBodyWithinLimit(request);
|
|
157
|
+
if (text instanceof Response)
|
|
158
|
+
return text;
|
|
137
159
|
if (!text.trim())
|
|
138
160
|
return {};
|
|
139
161
|
try {
|
|
@@ -143,6 +165,36 @@ async function optionalJson(request) {
|
|
|
143
165
|
return {};
|
|
144
166
|
}
|
|
145
167
|
}
|
|
168
|
+
async function readTextBodyWithinLimit(request, maxBytes = 1_000_000) {
|
|
169
|
+
const contentLength = Number.parseInt(request.headers.get('content-length') ?? '0', 10);
|
|
170
|
+
if (Number.isFinite(contentLength) && contentLength > maxBytes) {
|
|
171
|
+
return json({ error: 'Payload too large', code: 'PAYLOAD_TOO_LARGE' }, 413);
|
|
172
|
+
}
|
|
173
|
+
if (!request.body)
|
|
174
|
+
return '';
|
|
175
|
+
const reader = request.body.getReader();
|
|
176
|
+
const decoder = new TextDecoder();
|
|
177
|
+
let total = 0;
|
|
178
|
+
let body = '';
|
|
179
|
+
try {
|
|
180
|
+
for (;;) {
|
|
181
|
+
const { done, value } = await reader.read();
|
|
182
|
+
if (done)
|
|
183
|
+
break;
|
|
184
|
+
total += value.byteLength;
|
|
185
|
+
if (total > maxBytes) {
|
|
186
|
+
await reader.cancel('Payload too large').catch(() => { });
|
|
187
|
+
return json({ error: 'Payload too large', code: 'PAYLOAD_TOO_LARGE' }, 413);
|
|
188
|
+
}
|
|
189
|
+
body += decoder.decode(value, { stream: true });
|
|
190
|
+
}
|
|
191
|
+
body += decoder.decode();
|
|
192
|
+
return body;
|
|
193
|
+
}
|
|
194
|
+
finally {
|
|
195
|
+
reader.releaseLock();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
146
198
|
function json(body, status = 200) {
|
|
147
199
|
return new Response(JSON.stringify(body), {
|
|
148
200
|
status,
|