@arcote.tech/arc-host 0.7.6 → 0.7.8
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/index.js +9 -2039
- package/dist/index.js.map +6 -62
- package/dist/src/context-handler.d.ts +8 -1
- package/dist/src/context-handler.d.ts.map +1 -1
- package/dist/src/create-server.d.ts.map +1 -1
- package/dist/src/cron-scheduler.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/context-handler.ts +16 -0
- package/src/create-server.ts +10 -15
- package/src/cron-scheduler.ts +1 -0
|
@@ -27,8 +27,15 @@ export declare class ContextHandler {
|
|
|
27
27
|
* Execute a command. When `telemetry` is wired, the entire dispatch is
|
|
28
28
|
* traced as `command.<name>` with RPC semantic conventions, parented to
|
|
29
29
|
* whatever context is active (HTTP request span, WS message span, etc.).
|
|
30
|
+
*
|
|
31
|
+
* Wire dispatchers (HTTP, WS) MUST omit `options.internal` or pass `false`
|
|
32
|
+
* so that private mutateMethod/command is rejected. Internal callers
|
|
33
|
+
* (cron-scheduler, server-side tasks) pass `{ internal: true }` to bypass
|
|
34
|
+
* the wire-only restriction.
|
|
30
35
|
*/
|
|
31
|
-
executeCommand(commandName: string, params: any, rawToken: string | null
|
|
36
|
+
executeCommand(commandName: string, params: any, rawToken: string | null, options?: {
|
|
37
|
+
internal?: boolean;
|
|
38
|
+
}): Promise<any>;
|
|
32
39
|
/**
|
|
33
40
|
* Persist events from a client and return with host IDs
|
|
34
41
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-handler.d.ts","sourceRoot":"","sources":["../../src/context-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,EAGN,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO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MG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,SAAS,CAAC,CA0PpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cron-scheduler.d.ts","sourceRoot":"","sources":["../../src/cron-scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAOxD,qBAAa,aAAa;IACxB,OAAO,CAAC,IAAI,CAAiB;IAC7B,OAAO,CAAC,cAAc,CAAiB;gBAE3B,cAAc,EAAE,cAAc;IAI1C;;OAEG;IACH,KAAK,IAAI,IAAI;IAuBb;;OAEG;IACH,IAAI,IAAI,IAAI;IAQZ;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAe3B;;OAEG;YACW,iBAAiB;
|
|
1
|
+
{"version":3,"file":"cron-scheduler.d.ts","sourceRoot":"","sources":["../../src/cron-scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAOxD,qBAAa,aAAa;IACxB,OAAO,CAAC,IAAI,CAAiB;IAC7B,OAAO,CAAC,cAAc,CAAiB;gBAE3B,cAAc,EAAE,cAAc;IAI1C;;OAEG;IACH,KAAK,IAAI,IAAI;IAuBb;;OAEG;IACH,IAAI,IAAI,IAAI;IAQZ;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAe3B;;OAEG;YACW,iBAAiB;CAyChC"}
|
package/package.json
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "0.7.
|
|
7
|
+
"version": "0.7.8",
|
|
8
8
|
"private": false,
|
|
9
9
|
"author": "Przemysław Krasiński [arcote.tech]",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@arcote.tech/arc-adapter-db-sqlite": "^0.7.
|
|
11
|
+
"@arcote.tech/arc-adapter-db-sqlite": "^0.7.8",
|
|
12
12
|
"croner": "^9.0.0",
|
|
13
13
|
"jsonwebtoken": "^9.0.2"
|
|
14
14
|
},
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"@types/bun": "^1.2.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@arcote.tech/arc": "^0.7.
|
|
28
|
-
"@arcote.tech/arc-otel": "^0.7.
|
|
27
|
+
"@arcote.tech/arc": "^0.7.8",
|
|
28
|
+
"@arcote.tech/arc-otel": "^0.7.8"
|
|
29
29
|
},
|
|
30
30
|
"peerDependenciesMeta": {
|
|
31
31
|
"@arcote.tech/arc-otel": {
|
package/src/context-handler.ts
CHANGED
|
@@ -93,11 +93,17 @@ export class ContextHandler {
|
|
|
93
93
|
* Execute a command. When `telemetry` is wired, the entire dispatch is
|
|
94
94
|
* traced as `command.<name>` with RPC semantic conventions, parented to
|
|
95
95
|
* whatever context is active (HTTP request span, WS message span, etc.).
|
|
96
|
+
*
|
|
97
|
+
* Wire dispatchers (HTTP, WS) MUST omit `options.internal` or pass `false`
|
|
98
|
+
* so that private mutateMethod/command is rejected. Internal callers
|
|
99
|
+
* (cron-scheduler, server-side tasks) pass `{ internal: true }` to bypass
|
|
100
|
+
* the wire-only restriction.
|
|
96
101
|
*/
|
|
97
102
|
async executeCommand(
|
|
98
103
|
commandName: string,
|
|
99
104
|
params: any,
|
|
100
105
|
rawToken: string | null,
|
|
106
|
+
options?: { internal?: boolean },
|
|
101
107
|
): Promise<any> {
|
|
102
108
|
const includePayloads = this.telemetry?.shouldIncludePayloads() ?? false;
|
|
103
109
|
const baseAttrs = {
|
|
@@ -127,6 +133,16 @@ export class ContextHandler {
|
|
|
127
133
|
throw new Error(`Command '${commandName}' not found`);
|
|
128
134
|
}
|
|
129
135
|
|
|
136
|
+
// Private mutateMethod / command — server-internal only, never callable
|
|
137
|
+
// from a client over the wire. Server-side callers reach the handler
|
|
138
|
+
// directly through `ctx.mutate.*` (bypassing this dispatcher) or pass
|
|
139
|
+
// `{ internal: true }` (e.g. cron-scheduler).
|
|
140
|
+
if (!options?.internal && (command as any).__isPrivate) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
`Command '${commandName}' is private and not callable from a client.`,
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
130
146
|
try {
|
|
131
147
|
return await command(params);
|
|
132
148
|
} catch (error) {
|
package/src/create-server.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { ArcContextAny, DatabaseAdapter } from "@arcote.tech/arc";
|
|
2
|
-
import type {
|
|
3
|
-
ArcTelemetry,
|
|
4
|
-
Span,
|
|
5
|
-
} from "@arcote.tech/arc-otel";
|
|
2
|
+
import type { ArcTelemetry, Span } from "@arcote.tech/arc-otel";
|
|
6
3
|
import type { Server } from "bun";
|
|
7
4
|
import jwt from "jsonwebtoken";
|
|
8
5
|
import { ConnectionManager } from "./connection-manager";
|
|
@@ -65,17 +62,15 @@ export async function createArcServer(
|
|
|
65
62
|
const port = config.port || 5005;
|
|
66
63
|
|
|
67
64
|
// Init context handler — telemetry (if any) flows through so executeCommand
|
|
68
|
-
// emits `command.<name>` spans parented to the active HTTP/WS span.
|
|
69
|
-
// adapter
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
})
|
|
78
|
-
: rawDbAdapter;
|
|
65
|
+
// emits `command.<name>` spans parented to the active HTTP/WS span.
|
|
66
|
+
// DB adapter wrapping (per-transaction spans) is the caller's
|
|
67
|
+
// responsibility: pass an already-wrapped `dbAdapterFactory` if
|
|
68
|
+
// db spans are wanted. We don't `import()` arc-otel from here because
|
|
69
|
+
// doing so bundles its OTel SDK transitively into arc-host's dist,
|
|
70
|
+
// which then duplicates the @opentelemetry/api singleton when the CLI
|
|
71
|
+
// bundles arc-otel directly — leading to two global tracer providers
|
|
72
|
+
// and silent span loss.
|
|
73
|
+
const dbAdapter = config.dbAdapterFactory(config.context);
|
|
79
74
|
const contextHandler = new ContextHandler(
|
|
80
75
|
config.context,
|
|
81
76
|
dbAdapter,
|