@zintrust/socket 2.4.0 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +22 -4
- package/dist/index.js +33 -2
- package/package.json +2 -2
- package/dist/build-manifest.json +0 -41
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type IRequest, type IRouter } from '@zintrust/core/http';
|
|
2
|
-
import { type SocketRouteRegistrar } from '@zintrust/core/runtime';
|
|
2
|
+
import { type SocketNodeUpgradeInput, type SocketRouteRegistrar, type SocketRuntimeDiagnostics, type SocketWorkerContext } from '@zintrust/core/runtime';
|
|
3
3
|
type ServerSideSocketPublishInput = Readonly<{
|
|
4
4
|
channels: readonly string[];
|
|
5
5
|
event: string;
|
|
@@ -15,12 +15,30 @@ declare const publishSocketEventFromServer: (input: ServerSideSocketPublishInput
|
|
|
15
15
|
event: string;
|
|
16
16
|
deliveries: number;
|
|
17
17
|
}>;
|
|
18
|
-
declare const socketRuntime:
|
|
18
|
+
declare const socketRuntime: Readonly<{
|
|
19
|
+
name: string;
|
|
20
|
+
isEnabled: () => boolean;
|
|
21
|
+
describe: () => SocketRuntimeDiagnostics;
|
|
22
|
+
canHandleNodeUpgrade: (input: SocketNodeUpgradeInput) => boolean;
|
|
23
|
+
handleNodeUpgrade: (input: SocketNodeUpgradeInput) => Promise<boolean>;
|
|
24
|
+
canHandleWorkerRequest: (request: Request) => boolean;
|
|
25
|
+
handleWorkerRequest: (request: Request, context: SocketWorkerContext) => Promise<Response | null>;
|
|
26
|
+
}>;
|
|
19
27
|
declare const registerSocketRoutes: (router: IRouter) => void;
|
|
20
28
|
declare const socketRouteRegistrar: SocketRouteRegistrar;
|
|
21
29
|
export declare const SocketPackage: Readonly<{
|
|
22
|
-
runtime:
|
|
23
|
-
|
|
30
|
+
runtime: Readonly<{
|
|
31
|
+
name: string;
|
|
32
|
+
isEnabled: () => boolean;
|
|
33
|
+
describe: () => SocketRuntimeDiagnostics;
|
|
34
|
+
canHandleNodeUpgrade: (input: SocketNodeUpgradeInput) => boolean;
|
|
35
|
+
handleNodeUpgrade: (input: SocketNodeUpgradeInput) => Promise<boolean>;
|
|
36
|
+
canHandleWorkerRequest: (request: Request) => boolean;
|
|
37
|
+
handleWorkerRequest: (request: Request, context: SocketWorkerContext) => Promise<Response | null>;
|
|
38
|
+
}>;
|
|
39
|
+
routeRegistrar: Readonly<{
|
|
40
|
+
registerRoutes: (router: IRouter) => void;
|
|
41
|
+
}>;
|
|
24
42
|
publish: (channels: string[], event: string, data: unknown, excludeSocketId?: string) => number;
|
|
25
43
|
registerRoutes: (router: IRouter) => void;
|
|
26
44
|
}>;
|
package/dist/index.js
CHANGED
|
@@ -73,9 +73,31 @@ const resolveTransport = (value) => {
|
|
|
73
73
|
}
|
|
74
74
|
return 'auto';
|
|
75
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* Keys that indicate an env source actually carries socket configuration.
|
|
78
|
+
* The Workers bindings env exposed during an HTTP request carries these; the
|
|
79
|
+
* partial `globalThis.env` available inside the worker-runtime job context does
|
|
80
|
+
* not. When none are present the source is not authoritative for socket config.
|
|
81
|
+
*/
|
|
82
|
+
const SOCKET_CONFIG_KEYS = [
|
|
83
|
+
'SOCKET_ENABLED',
|
|
84
|
+
'PUSHER_APP_KEY',
|
|
85
|
+
'BROADCAST_AUTH_KEY',
|
|
86
|
+
'BROADCAST_APP_KEY',
|
|
87
|
+
];
|
|
88
|
+
const sourceCarriesSocketConfig = (source) => SOCKET_CONFIG_KEYS.some((key) => {
|
|
89
|
+
const value = source[key];
|
|
90
|
+
return value !== undefined && value !== null && String(value).trim() !== '';
|
|
91
|
+
});
|
|
76
92
|
const getSocketRuntimeSettings = (envSource) => {
|
|
77
93
|
const source = toEnvRecord(envSource);
|
|
78
|
-
|
|
94
|
+
// Fall back to the process-level Env when there is no env source, or when the
|
|
95
|
+
// provided source is non-null but does not carry socket config. The latter is
|
|
96
|
+
// the worker-runtime job context: `Cloudflare.getWorkersEnv()` is non-null but
|
|
97
|
+
// omits SOCKET_ENABLED / PUSHER_APP_KEY, which would otherwise report
|
|
98
|
+
// `enabled: false` and drop forced socket broadcasts. `SocketFeature.getSettings()`
|
|
99
|
+
// reads the authoritative process-level Env (.env / .dev.vars / merged bindings).
|
|
100
|
+
if (source === null || !sourceCarriesSocketConfig(source)) {
|
|
79
101
|
const settings = SocketFeature.getSettings();
|
|
80
102
|
return Object.freeze({
|
|
81
103
|
...settings,
|
|
@@ -497,7 +519,16 @@ const shouldUseCloudflareHub = (settings) => {
|
|
|
497
519
|
if (settings.transport === 'node') {
|
|
498
520
|
return false;
|
|
499
521
|
}
|
|
500
|
-
|
|
522
|
+
if (settings.transport === 'cloudflare') {
|
|
523
|
+
// Explicitly requested: a missing DO binding is a real misconfiguration and
|
|
524
|
+
// is surfaced downstream via createMissingHubResponse().
|
|
525
|
+
return Cloudflare.getWorkersEnv() !== null;
|
|
526
|
+
}
|
|
527
|
+
// auto: only route to the Cloudflare hub when the socket-hub Durable Object
|
|
528
|
+
// binding is actually present. The worker-runtime job context exposes a
|
|
529
|
+
// non-null but partial globalThis.env without that binding; there the node
|
|
530
|
+
// transport is the correct choice rather than a 503.
|
|
531
|
+
return getSocketHubNamespace() !== null;
|
|
501
532
|
};
|
|
502
533
|
const parseJsonResponse = async (response) => {
|
|
503
534
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/socket",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.2",
|
|
4
4
|
"description": "Unified socket runtime for ZinTrust.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -38,4 +38,4 @@
|
|
|
38
38
|
"build": "tsc -p tsconfig.json",
|
|
39
39
|
"prepublishOnly": "npm run build"
|
|
40
40
|
}
|
|
41
|
-
}
|
|
41
|
+
}
|
package/dist/build-manifest.json
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@zintrust/socket",
|
|
3
|
-
"version": "2.4.0",
|
|
4
|
-
"buildDate": "2026-05-30T23:30:34.528Z",
|
|
5
|
-
"buildEnvironment": {
|
|
6
|
-
"node": "v20.20.2",
|
|
7
|
-
"platform": "linux",
|
|
8
|
-
"arch": "x64"
|
|
9
|
-
},
|
|
10
|
-
"git": {
|
|
11
|
-
"commit": "8357ba1a",
|
|
12
|
-
"branch": "master"
|
|
13
|
-
},
|
|
14
|
-
"package": {
|
|
15
|
-
"engines": {
|
|
16
|
-
"node": ">=20.0.0"
|
|
17
|
-
},
|
|
18
|
-
"dependencies": [],
|
|
19
|
-
"peerDependencies": [
|
|
20
|
-
"@zintrust/core"
|
|
21
|
-
]
|
|
22
|
-
},
|
|
23
|
-
"files": {
|
|
24
|
-
"index.d.ts": {
|
|
25
|
-
"size": 1439,
|
|
26
|
-
"sha256": "e97c3363ccc1d324bef9eef1b295174656bbd02f8d79e6b049e92196b2fa4497"
|
|
27
|
-
},
|
|
28
|
-
"index.js": {
|
|
29
|
-
"size": 38670,
|
|
30
|
-
"sha256": "bb65f00e195203486c85acd63250619650c0e0bececee5101eac19c1dd137677"
|
|
31
|
-
},
|
|
32
|
-
"register.d.ts": {
|
|
33
|
-
"size": 16,
|
|
34
|
-
"sha256": "71d366165dd36f1675aa253a76262b226fb6c62e5ab632746b8aea61c0c625fc"
|
|
35
|
-
},
|
|
36
|
-
"register.js": {
|
|
37
|
-
"size": 935,
|
|
38
|
-
"sha256": "182877f0147808ef835d989c405a857447911c7ccfcfd03e5a077314efecdb27"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|