ras-stack 3.2.0 → 4.0.0
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 +10 -10
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +1 -1
- package/dist/auth/index.js.map +1 -1
- package/dist/conformance/index.d.ts +0 -57
- package/dist/conformance/index.js +1 -257
- package/dist/conformance/index.js.map +1 -1
- package/dist/database/postgres.d.ts +0 -5
- package/dist/database/postgres.js +0 -34
- package/dist/database/postgres.js.map +1 -1
- package/dist/database/sqlite.d.ts +0 -3
- package/dist/database/sqlite.js +1 -22
- package/dist/database/sqlite.js.map +1 -1
- package/dist/email/index.d.ts +0 -11
- package/dist/email/index.js +6 -9
- package/dist/email/index.js.map +1 -1
- package/dist/posthog/client.d.ts +0 -6
- package/dist/posthog/client.js +1 -11
- package/dist/posthog/client.js.map +1 -1
- package/dist/posthog/config.d.ts +1 -0
- package/dist/posthog/config.js +2 -0
- package/dist/posthog/config.js.map +1 -1
- package/dist/posthog/index.d.ts +2 -2
- package/dist/posthog/index.js +2 -2
- package/dist/posthog/index.js.map +1 -1
- package/dist/posthog/proxy.d.ts +0 -1
- package/dist/posthog/proxy.js +1 -3
- package/dist/posthog/proxy.js.map +1 -1
- package/dist/posthog/react.d.ts +1 -2
- package/dist/posthog/react.js +1 -2
- package/dist/posthog/react.js.map +1 -1
- package/dist/posthog/request.d.ts +0 -3
- package/dist/posthog/request.js +3 -3
- package/dist/posthog/request.js.map +1 -1
- package/dist/posthog/server.d.ts +1 -3
- package/dist/posthog/server.js +2 -2
- package/dist/posthog/server.js.map +1 -1
- package/dist/preview/cloudflare.js +1 -1
- package/dist/preview/cloudflare.js.map +1 -1
- package/dist/preview/dokploy-cli.js +1 -1
- package/dist/preview/dokploy-cli.js.map +1 -1
- package/dist/preview/dokploy-preview.d.ts +102 -0
- package/dist/preview/dokploy-preview.js +377 -0
- package/dist/preview/dokploy-preview.js.map +1 -0
- package/dist/preview/dokploy.d.ts +2 -102
- package/dist/preview/dokploy.js +1 -376
- package/dist/preview/dokploy.js.map +1 -1
- package/dist/preview/github.js +1 -1
- package/dist/preview/github.js.map +1 -1
- package/dist/realtime/client.d.ts +1 -11
- package/dist/realtime/client.js +2 -98
- package/dist/realtime/client.js.map +1 -1
- package/dist/realtime/index.d.ts +0 -2
- package/dist/realtime/index.js +0 -1
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime/react.d.ts +1 -4
- package/dist/realtime/react.js +22 -26
- package/dist/realtime/react.js.map +1 -1
- package/dist/runtime/index.d.ts +2 -64
- package/dist/runtime/index.js +1 -255
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/stack.d.ts +64 -0
- package/dist/runtime/stack.js +252 -0
- package/dist/runtime/stack.js.map +1 -0
- package/dist/server/errors.d.ts +0 -22
- package/dist/server/errors.js +0 -44
- package/dist/server/errors.js.map +1 -1
- package/dist/server/health.d.ts +7 -4
- package/dist/server/health.js +3 -7
- package/dist/server/health.js.map +1 -1
- package/dist/server/index.d.ts +2 -10
- package/dist/server/index.js +1 -5
- package/dist/server/index.js.map +1 -1
- package/dist/tanstack/middleware.d.ts +0 -1
- package/dist/tanstack/middleware.js +2 -5
- package/dist/tanstack/middleware.js.map +1 -1
- package/dist/tanstack/server.d.ts +2 -11
- package/dist/tanstack/server.js +2 -6
- package/dist/tanstack/server.js.map +1 -1
- package/dist/uploads/index.d.ts +0 -6
- package/dist/uploads/index.js +0 -25
- package/dist/uploads/index.js.map +1 -1
- package/package.json +2 -18
- package/dist/server/rate-limit.d.ts +0 -30
- package/dist/server/rate-limit.js +0 -73
- package/dist/server/rate-limit.js.map +0 -1
package/dist/realtime/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Centrifuge, UnauthorizedError
|
|
2
|
-
|
|
1
|
+
import { Centrifuge, UnauthorizedError } from 'centrifuge';
|
|
2
|
+
function sameOriginWebSocketUrl(location, path = '/connection/websocket') {
|
|
3
3
|
if (!path.startsWith('/') || path.startsWith('//'))
|
|
4
4
|
throw new Error('WebSocket path must be same-origin');
|
|
5
5
|
const url = new URL(path, `${location.protocol}//${location.host}`);
|
|
@@ -18,37 +18,6 @@ export function createSameOriginRealtimeClient(options, config = {}) {
|
|
|
18
18
|
const location = config.location ?? window.location;
|
|
19
19
|
return new Centrifuge(sameOriginWebSocketUrl(location, config.path), options);
|
|
20
20
|
}
|
|
21
|
-
export function connectRealtimeClient(client) {
|
|
22
|
-
client.connect();
|
|
23
|
-
return () => client.disconnect();
|
|
24
|
-
}
|
|
25
|
-
export function openRealtimeSubscription(client, channel, options = {}, configure) {
|
|
26
|
-
const subscription = client.newSubscription(channel, options);
|
|
27
|
-
let cleanup;
|
|
28
|
-
try {
|
|
29
|
-
cleanup = configure?.(subscription);
|
|
30
|
-
subscription.subscribe();
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
client.removeSubscription(subscription);
|
|
34
|
-
throw error;
|
|
35
|
-
}
|
|
36
|
-
let closed = false;
|
|
37
|
-
return {
|
|
38
|
-
subscription,
|
|
39
|
-
close: () => {
|
|
40
|
-
if (closed)
|
|
41
|
-
return;
|
|
42
|
-
closed = true;
|
|
43
|
-
try {
|
|
44
|
-
cleanup?.();
|
|
45
|
-
}
|
|
46
|
-
finally {
|
|
47
|
-
client.removeSubscription(subscription);
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
21
|
export function watchServerChannel(client, channel, handlers) {
|
|
53
22
|
const publication = (context) => {
|
|
54
23
|
if (context.channel === channel)
|
|
@@ -65,69 +34,4 @@ export function watchServerChannel(client, channel, handlers) {
|
|
|
65
34
|
client.off('subscribed', subscribed);
|
|
66
35
|
};
|
|
67
36
|
}
|
|
68
|
-
export function watchSubscriptionPresence(subscription, update, options = {}) {
|
|
69
|
-
const clients = new Map();
|
|
70
|
-
let active = true;
|
|
71
|
-
let revision = 0;
|
|
72
|
-
let refreshing;
|
|
73
|
-
const render = () => update(Object.fromEntries(clients));
|
|
74
|
-
const sync = async () => {
|
|
75
|
-
const requestedAt = revision;
|
|
76
|
-
try {
|
|
77
|
-
const snapshot = await subscription.presence();
|
|
78
|
-
if (!active)
|
|
79
|
-
return;
|
|
80
|
-
if (revision !== requestedAt)
|
|
81
|
-
return sync();
|
|
82
|
-
clients.clear();
|
|
83
|
-
for (const [id, info] of Object.entries(snapshot.clients))
|
|
84
|
-
clients.set(id, info);
|
|
85
|
-
render();
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
if (!active)
|
|
89
|
-
return;
|
|
90
|
-
if (revision !== requestedAt)
|
|
91
|
-
return sync();
|
|
92
|
-
clients.clear();
|
|
93
|
-
render();
|
|
94
|
-
options.onError?.(error);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
const refresh = () => {
|
|
98
|
-
if (refreshing)
|
|
99
|
-
return refreshing;
|
|
100
|
-
refreshing = sync().finally(() => {
|
|
101
|
-
refreshing = undefined;
|
|
102
|
-
});
|
|
103
|
-
return refreshing;
|
|
104
|
-
};
|
|
105
|
-
const subscribed = () => {
|
|
106
|
-
revision++;
|
|
107
|
-
void refresh();
|
|
108
|
-
};
|
|
109
|
-
const join = ({ info }) => {
|
|
110
|
-
revision++;
|
|
111
|
-
clients.set(info.client, info);
|
|
112
|
-
render();
|
|
113
|
-
};
|
|
114
|
-
const leave = ({ info }) => {
|
|
115
|
-
revision++;
|
|
116
|
-
clients.delete(info.client);
|
|
117
|
-
render();
|
|
118
|
-
};
|
|
119
|
-
subscription.on('subscribed', subscribed);
|
|
120
|
-
subscription.on('join', join);
|
|
121
|
-
subscription.on('leave', leave);
|
|
122
|
-
return () => {
|
|
123
|
-
if (!active)
|
|
124
|
-
return;
|
|
125
|
-
active = false;
|
|
126
|
-
subscription.off('subscribed', subscribed);
|
|
127
|
-
subscription.off('join', join);
|
|
128
|
-
subscription.off('leave', leave);
|
|
129
|
-
clients.clear();
|
|
130
|
-
render();
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
37
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/realtime/client.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/realtime/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAA6E,MAAM,YAAY,CAAA;AAIrI,SAAS,sBAAsB,CAAC,QAAyB,EAAE,IAAI,GAAG,uBAAuB;IACvF,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;IACzG,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,QAAQ,KAAK,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IACnE,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAA;IACzD,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAA;AACvB,CAAC;AAUD,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAI,KAAwB,EAAE,OAAiC;IACxG,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACpE,IAAI,CAAC,OAAO,CAAC,oBAAoB,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,MAAM,IAAI,iBAAiB,CAAC,cAAc,CAAC,CAAA;IACvH,IAAI,CAAC,QAAQ,CAAC,EAAE;QACd,MAAM,IA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, UnauthorizedError, type Options, type ServerPublicationContext, type ServerSubscribedContext } from 'centrifuge'\n\ntype BrowserLocation = Pick<Location, 'host' | 'protocol'>\n\nfunction sameOriginWebSocketUrl(location: BrowserLocation, path = '/connection/websocket') {\n if (!path.startsWith('/') || path.startsWith('//')) throw new Error('WebSocket path must be same-origin')\n const url = new URL(path, `${location.protocol}//${location.host}`)\n url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:'\n return url.toString()\n}\n\nexport type RealtimeTicketOptions<T> = {\n fetch?: typeof fetch\n init?: RequestInit\n parse: (value: unknown) => T\n unauthorizedStatuses?: readonly number[]\n errorMessage?: (status: number) => string\n}\n\nexport async function requestRealtimeTicket<T>(input: RequestInfo | URL, options: RealtimeTicketOptions<T>) {\n const response = await (options.fetch ?? fetch)(input, options.init)\n if ((options.unauthorizedStatuses ?? [401, 403]).includes(response.status)) throw new UnauthorizedError('unauthorized')\n if (!response.ok)\n throw new Error(options.errorMessage?.(response.status) ?? `Realtime authentication failed with status ${response.status}`)\n return options.parse(await response.json())\n}\n\nexport function createSameOriginRealtimeClient(options: Partial<Options>, config: { location?: BrowserLocation; path?: string } = {}) {\n const location = config.location ?? window.location\n return new Centrifuge(sameOriginWebSocketUrl(location, config.path), options)\n}\n\nexport function watchServerChannel(\n client: Centrifuge,\n channel: string,\n handlers: { publication?: (context: ServerPublicationContext) => void; unrecovered?: (context: ServerSubscribedContext) => void },\n) {\n const publication = (context: ServerPublicationContext) => {\n if (context.channel === channel) handlers.publication?.(context)\n }\n const subscribed = (context: ServerSubscribedContext) => {\n if (context.channel === channel && context.wasRecovering && !context.recovered) handlers.unrecovered?.(context)\n }\n client.on('publication', publication)\n client.on('subscribed', subscribed)\n return () => {\n client.off('publication', publication)\n client.off('subscribed', subscribed)\n }\n}\n"]}
|
package/dist/realtime/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { connectRealtimeClient, createSameOriginRealtimeClient, openRealtimeSubscription, requestRealtimeTicket, sameOriginWebSocketUrl, watchServerChannel, watchSubscriptionPresence, } from './client.js';
|
|
2
|
-
export type { RealtimeSubscription, RealtimeTicketOptions } from './client.js';
|
|
3
1
|
export { CentrifugoPublisher } from './publisher.js';
|
|
4
2
|
export type { CentrifugoPublisherOptions } from './publisher.js';
|
|
5
3
|
export { signRealtimeToken } from './tokens.js';
|
package/dist/realtime/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { connectRealtimeClient, createSameOriginRealtimeClient, openRealtimeSubscription, requestRealtimeTicket, sameOriginWebSocketUrl, watchServerChannel, watchSubscriptionPresence, } from './client.js';
|
|
2
1
|
export { CentrifugoPublisher } from './publisher.js';
|
|
3
2
|
export { signRealtimeToken } from './tokens.js';
|
|
4
3
|
export { realtimeEnvironment } from './environment.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/realtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/realtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA","sourcesContent":["export { CentrifugoPublisher } from './publisher.js'\nexport type { CentrifugoPublisherOptions } from './publisher.js'\nexport { signRealtimeToken } from './tokens.js'\nexport type { RealtimeTokenOptions } from './tokens.js'\nexport { realtimeEnvironment } from './environment.js'\nexport type { RealtimeEnvironment, RealtimeEnvironmentOptions } from './environment.js'\n"]}
|
package/dist/realtime/react.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Centrifuge,
|
|
1
|
+
import type { Centrifuge, Subscription, SubscriptionOptions } from 'centrifuge';
|
|
2
2
|
export declare function useConnectedRealtimeClient(create: () => Centrifuge | Promise<Centrifuge>, enabled?: boolean, options?: {
|
|
3
3
|
configure?: (client: Centrifuge) => void | (() => void);
|
|
4
4
|
onError?: (error: unknown) => void;
|
|
@@ -11,6 +11,3 @@ export type RealtimeSubscriptionHookOptions = {
|
|
|
11
11
|
configure?: (subscription: Subscription) => void | (() => void);
|
|
12
12
|
};
|
|
13
13
|
export declare function useRealtimeSubscription(options: RealtimeSubscriptionHookOptions): Subscription | undefined;
|
|
14
|
-
export declare function useRealtimePresence(subscription: Subscription | undefined, options?: {
|
|
15
|
-
onError?: (error: unknown) => void;
|
|
16
|
-
}): Record<string, ClientInfo>;
|
package/dist/realtime/react.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
import { connectRealtimeClient, openRealtimeSubscription, watchSubscriptionPresence } from './client.js';
|
|
3
2
|
export function useConnectedRealtimeClient(create, enabled = true, options = {}) {
|
|
4
3
|
const [client, setClient] = useState();
|
|
5
4
|
const configure = options.configure;
|
|
@@ -11,7 +10,7 @@ export function useConnectedRealtimeClient(create, enabled = true, options = {})
|
|
|
11
10
|
}
|
|
12
11
|
let active = true;
|
|
13
12
|
let cleanup;
|
|
14
|
-
let
|
|
13
|
+
let connected;
|
|
15
14
|
const connect = (next) => {
|
|
16
15
|
if (!active) {
|
|
17
16
|
next.disconnect();
|
|
@@ -26,7 +25,8 @@ export function useConnectedRealtimeClient(create, enabled = true, options = {})
|
|
|
26
25
|
return;
|
|
27
26
|
}
|
|
28
27
|
setClient(next);
|
|
29
|
-
|
|
28
|
+
next.connect();
|
|
29
|
+
connected = next;
|
|
30
30
|
};
|
|
31
31
|
try {
|
|
32
32
|
const created = create();
|
|
@@ -41,7 +41,7 @@ export function useConnectedRealtimeClient(create, enabled = true, options = {})
|
|
|
41
41
|
return () => {
|
|
42
42
|
active = false;
|
|
43
43
|
cleanup?.();
|
|
44
|
-
disconnect
|
|
44
|
+
connected?.disconnect();
|
|
45
45
|
};
|
|
46
46
|
}, [configure, create, enabled, onError]);
|
|
47
47
|
return client;
|
|
@@ -54,30 +54,26 @@ export function useRealtimeSubscription(options) {
|
|
|
54
54
|
setSubscription(undefined);
|
|
55
55
|
return undefined;
|
|
56
56
|
}
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
export function useRealtimePresence(subscription, options = {}) {
|
|
64
|
-
const [clients, setClients] = useState({});
|
|
65
|
-
const onError = options.onError;
|
|
66
|
-
useEffect(() => {
|
|
67
|
-
if (!subscription) {
|
|
68
|
-
setClients({});
|
|
69
|
-
return undefined;
|
|
57
|
+
const next = client.newSubscription(channel, subscriptionOptions);
|
|
58
|
+
let cleanup;
|
|
59
|
+
try {
|
|
60
|
+
cleanup = configure?.(next);
|
|
61
|
+
next.subscribe();
|
|
70
62
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
63
|
+
catch (error) {
|
|
64
|
+
client.removeSubscription(next);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
setSubscription(next);
|
|
76
68
|
return () => {
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
try {
|
|
70
|
+
cleanup?.();
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
client.removeSubscription(next);
|
|
74
|
+
}
|
|
79
75
|
};
|
|
80
|
-
}, [
|
|
81
|
-
return
|
|
76
|
+
}, [channel, client, configure, enabled, subscriptionOptions]);
|
|
77
|
+
return subscription;
|
|
82
78
|
}
|
|
83
79
|
//# sourceMappingURL=react.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../src/realtime/react.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../src/realtime/react.ts"],"names":[],"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AC;gBACH,OAAO,EAAE,EAAE,CAAA;YACb,CAAC;oBAAS,CAAC;gBACT,MAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAA;YACjC,CAAC;QACH,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAA;IAC9D,OAAO,YAAY,CAAA;AACrB,CAAC","sourcesContent":["import type { Centrifuge, Subscription, SubscriptionOptions } from 'centrifuge'\nimport { useEffect, useState } from 'react'\n\nexport function useConnectedRealtimeClient(\n create: () => Centrifuge | Promise<Centrifuge>,\n enabled = true,\n options: { configure?: (client: Centrifuge) => void | (() => void); onError?: (error: unknown) => void } = {},\n) {\n const [client, setClient] = useState<Centrifuge>()\n const configure = options.configure\n const onError = options.onError\n useEffect(() => {\n if (!enabled) {\n setClient(undefined)\n return undefined\n }\n let active = true\n let cleanup: (() => void) | undefined\n let connected: Centrifuge | undefined\n const connect = (next: Centrifuge) => {\n if (!active) {\n next.disconnect()\n return\n }\n try {\n cleanup = configure?.(next) ?? undefined\n } catch (error) {\n next.disconnect()\n onError?.(error)\n return\n }\n setClient(next)\n next.connect()\n connected = next\n }\n try {\n const created = create()\n if (created instanceof Promise) void created.then(connect, (error: unknown) => active && onError?.(error))\n else connect(created)\n } catch (error) {\n onError?.(error)\n }\n return () => {\n active = false\n cleanup?.()\n connected?.disconnect()\n }\n }, [configure, create, enabled, onError])\n return client\n}\n\nexport type RealtimeSubscriptionHookOptions = {\n client?: Centrifuge\n channel?: string\n enabled?: boolean\n options?: SubscriptionOptions\n configure?: (subscription: Subscription) => void | (() => void)\n}\n\nexport function useRealtimeSubscription(options: RealtimeSubscriptionHookOptions) {\n const [subscription, setSubscription] = useState<Subscription>()\n const { channel, client, configure, enabled = true, options: subscriptionOptions } = options\n useEffect(() => {\n if (!enabled || !client || !channel) {\n setSubscription(undefined)\n return undefined\n }\n const next = client.newSubscription(channel, subscriptionOptions)\n let cleanup: void | (() => void)\n try {\n cleanup = configure?.(next)\n next.subscribe()\n } catch (error) {\n client.removeSubscription(next)\n throw error\n }\n setSubscription(next)\n return () => {\n try {\n cleanup?.()\n } finally {\n client.removeSubscription(next)\n }\n }\n }, [channel, client, configure, enabled, subscriptionOptions])\n return subscription\n}\n"]}
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,64 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
export type RuntimeProcess = {
|
|
4
|
-
name: string;
|
|
5
|
-
command: string;
|
|
6
|
-
args?: readonly string[];
|
|
7
|
-
cwd?: string;
|
|
8
|
-
env?: NodeJS.ProcessEnv;
|
|
9
|
-
};
|
|
10
|
-
type SignalSource = Pick<NodeJS.Process, 'off' | 'once'>;
|
|
11
|
-
type SpawnProcess = (process: RuntimeProcess) => ChildProcess;
|
|
12
|
-
export type SupervisorOptions = {
|
|
13
|
-
shutdownTimeoutMs?: number;
|
|
14
|
-
signalSource?: SignalSource;
|
|
15
|
-
spawn?: SpawnProcess;
|
|
16
|
-
};
|
|
17
|
-
export declare function superviseProcesses(processes: readonly RuntimeProcess[], options?: SupervisorOptions): Promise<number>;
|
|
18
|
-
export type CentrifugoEnvironmentOptions = {
|
|
19
|
-
apiKey: string;
|
|
20
|
-
clientTokenSecret?: string;
|
|
21
|
-
subscriptionTokenSecret?: string;
|
|
22
|
-
allowedOrigins?: string;
|
|
23
|
-
redisUrl?: string;
|
|
24
|
-
};
|
|
25
|
-
export type RealtimeStackOptions = {
|
|
26
|
-
app: Omit<RuntimeProcess, 'name'>;
|
|
27
|
-
centrifugo: {
|
|
28
|
-
command?: string;
|
|
29
|
-
configPath: string;
|
|
30
|
-
cwd?: string;
|
|
31
|
-
env?: NodeJS.ProcessEnv;
|
|
32
|
-
environment: CentrifugoEnvironmentOptions;
|
|
33
|
-
};
|
|
34
|
-
caddy: {
|
|
35
|
-
command?: string;
|
|
36
|
-
configPath: string;
|
|
37
|
-
cwd?: string;
|
|
38
|
-
env?: NodeJS.ProcessEnv;
|
|
39
|
-
proxy?: CaddyRealtimeProxyOptions;
|
|
40
|
-
runtime?: CaddyRuntimeEnvironmentOptions;
|
|
41
|
-
};
|
|
42
|
-
supervisor?: SupervisorOptions;
|
|
43
|
-
};
|
|
44
|
-
export declare function runRealtimeStack(options: RealtimeStackOptions): Promise<number>;
|
|
45
|
-
export declare function centrifugoEnvironment(options: CentrifugoEnvironmentOptions): NodeJS.ProcessEnv;
|
|
46
|
-
export type CaddyRuntimeEnvironmentOptions = {
|
|
47
|
-
configHome?: string;
|
|
48
|
-
dataHome?: string;
|
|
49
|
-
};
|
|
50
|
-
export declare function caddyRuntimeEnvironment(options?: CaddyRuntimeEnvironmentOptions): NodeJS.ProcessEnv;
|
|
51
|
-
export type CaddyRealtimeProxyOptions = {
|
|
52
|
-
publicPort?: number;
|
|
53
|
-
appPort?: number;
|
|
54
|
-
realtimePort?: number;
|
|
55
|
-
websocketPath?: string;
|
|
56
|
-
/** Compress responses with zstd and gzip. On unless turned off: Caddy already skips upgrades and incompressible content. */
|
|
57
|
-
encode?: boolean;
|
|
58
|
-
};
|
|
59
|
-
export declare function caddyRealtimeProxy(options?: CaddyRealtimeProxyOptions): string;
|
|
60
|
-
export type PersistedRealtimeSecretOptions = {
|
|
61
|
-
prefix?: string;
|
|
62
|
-
defaultFile?: string;
|
|
63
|
-
};
|
|
64
|
-
export declare function persistedRealtimeSecret(environment?: NodeJS.ProcessEnv, options?: PersistedRealtimeSecretOptions): string;
|
|
1
|
+
export { caddyRealtimeProxy, persistedRealtimeSecret, runRealtimeStack } from './stack.js';
|
|
2
|
+
export type { CaddyRealtimeProxyOptions, CaddyRuntimeEnvironmentOptions, CentrifugoEnvironmentOptions, PersistedRealtimeSecretOptions, RealtimeStackOptions, RuntimeProcess, SupervisorOptions, } from './stack.js';
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,256 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { persistedSecret } from '../auth/secret.js';
|
|
5
|
-
export { runRealtimeDev } from './dev.js';
|
|
6
|
-
export async function superviseProcesses(processes, options = {}) {
|
|
7
|
-
return runSupervisor(processes, options);
|
|
8
|
-
}
|
|
9
|
-
async function runSupervisor(processes, options, shutdownOrder) {
|
|
10
|
-
if (processes.length === 0)
|
|
11
|
-
throw new Error('at least one runtime process is required');
|
|
12
|
-
const names = new Set();
|
|
13
|
-
for (const process of processes) {
|
|
14
|
-
if (!process.name.trim())
|
|
15
|
-
throw new Error('runtime process names must not be empty');
|
|
16
|
-
if (!process.command.trim())
|
|
17
|
-
throw new Error(`runtime process ${process.name} must have a command`);
|
|
18
|
-
if (names.has(process.name))
|
|
19
|
-
throw new Error(`duplicate runtime process name: ${process.name}`);
|
|
20
|
-
names.add(process.name);
|
|
21
|
-
}
|
|
22
|
-
const signalSource = options.signalSource ?? process;
|
|
23
|
-
const shutdownTimeoutMs = options.shutdownTimeoutMs ?? 10_000;
|
|
24
|
-
if (!Number.isSafeInteger(shutdownTimeoutMs) || shutdownTimeoutMs < 0) {
|
|
25
|
-
throw new Error('shutdownTimeoutMs must be a non-negative integer');
|
|
26
|
-
}
|
|
27
|
-
const spawnProcess = options.spawn ??
|
|
28
|
-
((specification) => spawn(specification.command, [...(specification.args ?? [])], {
|
|
29
|
-
cwd: specification.cwd,
|
|
30
|
-
env: specification.env ?? process.env,
|
|
31
|
-
stdio: 'inherit',
|
|
32
|
-
}));
|
|
33
|
-
const children = new Map();
|
|
34
|
-
const exits = new Map();
|
|
35
|
-
let settled = false;
|
|
36
|
-
let phasedShutdown = false;
|
|
37
|
-
let expectedExit;
|
|
38
|
-
let resolveResult;
|
|
39
|
-
const result = new Promise((resolve) => {
|
|
40
|
-
resolveResult = resolve;
|
|
41
|
-
});
|
|
42
|
-
const finishImmediately = async (status) => {
|
|
43
|
-
if (settled)
|
|
44
|
-
return;
|
|
45
|
-
settled = true;
|
|
46
|
-
signalSource.off('SIGINT', onSignal);
|
|
47
|
-
signalSource.off('SIGTERM', onSignal);
|
|
48
|
-
await stopChildren([...children.keys()], shutdownTimeoutMs);
|
|
49
|
-
resolveResult(status);
|
|
50
|
-
};
|
|
51
|
-
const finishInPhases = async () => {
|
|
52
|
-
if (settled || phasedShutdown)
|
|
53
|
-
return;
|
|
54
|
-
phasedShutdown = true;
|
|
55
|
-
signalSource.off('SIGINT', onSignal);
|
|
56
|
-
signalSource.off('SIGTERM', onSignal);
|
|
57
|
-
const deadline = Date.now() + shutdownTimeoutMs;
|
|
58
|
-
for (const name of shutdownOrder ?? []) {
|
|
59
|
-
if (settled)
|
|
60
|
-
return;
|
|
61
|
-
const child = [...children].find(([, childName]) => childName === name)?.[0];
|
|
62
|
-
if (!child || !running(child))
|
|
63
|
-
continue;
|
|
64
|
-
expectedExit = child;
|
|
65
|
-
child.kill('SIGTERM');
|
|
66
|
-
// oxlint-disable-next-line no-await-in-loop -- Shutdown phases must remain dependency-ordered.
|
|
67
|
-
const exited = await beforeDeadline(exits.get(child), Math.max(0, deadline - Date.now()));
|
|
68
|
-
expectedExit = undefined;
|
|
69
|
-
if (settled)
|
|
70
|
-
return;
|
|
71
|
-
if (!exited) {
|
|
72
|
-
settled = true;
|
|
73
|
-
for (const runningChild of children.keys())
|
|
74
|
-
if (running(runningChild))
|
|
75
|
-
runningChild.kill('SIGKILL');
|
|
76
|
-
resolveResult(0);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
settled = true;
|
|
81
|
-
resolveResult(0);
|
|
82
|
-
};
|
|
83
|
-
const onSignal = () => {
|
|
84
|
-
if (shutdownOrder)
|
|
85
|
-
void finishInPhases();
|
|
86
|
-
else
|
|
87
|
-
void finishImmediately(0);
|
|
88
|
-
};
|
|
89
|
-
signalSource.once('SIGINT', onSignal);
|
|
90
|
-
signalSource.once('SIGTERM', onSignal);
|
|
91
|
-
try {
|
|
92
|
-
for (const specification of processes) {
|
|
93
|
-
const child = spawnProcess(specification);
|
|
94
|
-
children.set(child, specification.name);
|
|
95
|
-
let resolveExit;
|
|
96
|
-
exits.set(child, new Promise((resolve) => {
|
|
97
|
-
resolveExit = resolve;
|
|
98
|
-
}));
|
|
99
|
-
child.once('error', () => void finishImmediately(1));
|
|
100
|
-
child.once('exit', (code) => {
|
|
101
|
-
resolveExit();
|
|
102
|
-
if (!phasedShutdown || child !== expectedExit)
|
|
103
|
-
void finishImmediately(code && code > 0 ? code : 1);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
await finishImmediately(1);
|
|
109
|
-
throw error;
|
|
110
|
-
}
|
|
111
|
-
return result;
|
|
112
|
-
}
|
|
113
|
-
async function beforeDeadline(exited, timeoutMs) {
|
|
114
|
-
let timer;
|
|
115
|
-
const timeout = new Promise((resolve) => {
|
|
116
|
-
timer = setTimeout(() => resolve(false), timeoutMs);
|
|
117
|
-
});
|
|
118
|
-
const result = await Promise.race([exited.then(() => true), timeout]);
|
|
119
|
-
if (timer)
|
|
120
|
-
clearTimeout(timer);
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
123
|
-
function running(child) {
|
|
124
|
-
return child.exitCode === null && child.signalCode === null;
|
|
125
|
-
}
|
|
126
|
-
async function stopChildren(children, timeoutMs) {
|
|
127
|
-
const active = children.filter(running);
|
|
128
|
-
if (active.length === 0)
|
|
129
|
-
return;
|
|
130
|
-
const exited = Promise.all(active.map((child) => new Promise((resolve) => child.once('exit', () => resolve())))).then(() => 'exited');
|
|
131
|
-
for (const child of active)
|
|
132
|
-
child.kill('SIGTERM');
|
|
133
|
-
let timer;
|
|
134
|
-
const timeout = new Promise((resolve) => {
|
|
135
|
-
timer = setTimeout(() => resolve('timeout'), timeoutMs);
|
|
136
|
-
});
|
|
137
|
-
const outcome = await Promise.race([exited, timeout]);
|
|
138
|
-
if (timer)
|
|
139
|
-
clearTimeout(timer);
|
|
140
|
-
if (outcome === 'timeout') {
|
|
141
|
-
for (const child of active)
|
|
142
|
-
if (running(child))
|
|
143
|
-
child.kill('SIGKILL');
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
export async function runRealtimeStack(options) {
|
|
147
|
-
const configPath = absolutePath(options.caddy.configPath, 'caddy.configPath');
|
|
148
|
-
const centrifugoConfigPath = absolutePath(options.centrifugo.configPath, 'centrifugo.configPath');
|
|
149
|
-
await mkdir(path.dirname(configPath), { recursive: true });
|
|
150
|
-
await writeFile(configPath, caddyRealtimeProxy(options.caddy.proxy), 'utf8');
|
|
151
|
-
return runSupervisor([
|
|
152
|
-
{ name: 'app', ...options.app },
|
|
153
|
-
{
|
|
154
|
-
name: 'realtime',
|
|
155
|
-
command: options.centrifugo.command ?? 'centrifugo',
|
|
156
|
-
args: [`--config=${centrifugoConfigPath}`],
|
|
157
|
-
...(options.centrifugo.cwd ? { cwd: options.centrifugo.cwd } : {}),
|
|
158
|
-
env: { ...options.centrifugo.env, ...centrifugoEnvironment(options.centrifugo.environment) },
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
name: 'proxy',
|
|
162
|
-
command: options.caddy.command ?? 'caddy',
|
|
163
|
-
args: ['run', '--config', configPath, '--adapter', 'caddyfile'],
|
|
164
|
-
...(options.caddy.cwd ? { cwd: options.caddy.cwd } : {}),
|
|
165
|
-
env: { ...options.caddy.env, ...caddyRuntimeEnvironment(options.caddy.runtime) },
|
|
166
|
-
},
|
|
167
|
-
], options.supervisor ?? {}, ['proxy', 'app', 'realtime']);
|
|
168
|
-
}
|
|
169
|
-
export function centrifugoEnvironment(options) {
|
|
170
|
-
const apiKey = requiredValue(options.apiKey, 'apiKey');
|
|
171
|
-
const clientTokenSecret = options.clientTokenSecret?.trim();
|
|
172
|
-
const subscriptionTokenSecret = options.subscriptionTokenSecret?.trim();
|
|
173
|
-
return {
|
|
174
|
-
CENTRIFUGO_HTTP_API_KEY: apiKey,
|
|
175
|
-
CENTRIFUGO_CLIENT_ALLOWED_ORIGINS: options.allowedOrigins?.trim() || '*',
|
|
176
|
-
CENTRIFUGO_HTTP_SERVER_ADDRESS: '127.0.0.1',
|
|
177
|
-
CENTRIFUGO_HEALTH_ENABLED: 'true',
|
|
178
|
-
...(clientTokenSecret ? { CENTRIFUGO_CLIENT_TOKEN_HMAC_SECRET_KEY: clientTokenSecret } : {}),
|
|
179
|
-
...(subscriptionTokenSecret
|
|
180
|
-
? {
|
|
181
|
-
CENTRIFUGO_CLIENT_SUBSCRIPTION_TOKEN_ENABLED: 'true',
|
|
182
|
-
CENTRIFUGO_CLIENT_SUBSCRIPTION_TOKEN_HMAC_SECRET_KEY: subscriptionTokenSecret,
|
|
183
|
-
}
|
|
184
|
-
: {}),
|
|
185
|
-
...(options.redisUrl
|
|
186
|
-
? { CENTRIFUGO_ENGINE_TYPE: 'redis', CENTRIFUGO_ENGINE_REDIS_ADDRESS: requiredValue(options.redisUrl, 'redisUrl') }
|
|
187
|
-
: {}),
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
export function caddyRuntimeEnvironment(options = {}) {
|
|
191
|
-
const configHome = absolutePath(options.configHome ?? '/tmp/caddy-config', 'configHome');
|
|
192
|
-
const dataHome = absolutePath(options.dataHome ?? '/tmp/caddy-data', 'dataHome');
|
|
193
|
-
return { XDG_CONFIG_HOME: configHome, XDG_DATA_HOME: dataHome };
|
|
194
|
-
}
|
|
195
|
-
export function caddyRealtimeProxy(options = {}) {
|
|
196
|
-
const publicPort = port(options.publicPort ?? 3000, 'publicPort');
|
|
197
|
-
const appPort = port(options.appPort ?? 3001, 'appPort');
|
|
198
|
-
const realtimePort = port(options.realtimePort ?? 8000, 'realtimePort');
|
|
199
|
-
const websocketPath = options.websocketPath ?? '/connection/';
|
|
200
|
-
if (!/^\/[A-Za-z0-9._~/-]+\/$/.test(websocketPath) || websocketPath.includes('//')) {
|
|
201
|
-
throw new Error('websocketPath must be a normalized absolute directory path');
|
|
202
|
-
}
|
|
203
|
-
return `{
|
|
204
|
-
\tservers {
|
|
205
|
-
\t\ttrusted_proxies static private_ranges
|
|
206
|
-
\t\ttrusted_proxies_strict
|
|
207
|
-
\t}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
:${publicPort} {
|
|
211
|
-
${options.encode === false ? '' : '\tencode zstd gzip\n'}\troute {
|
|
212
|
-
\t\t@foreignWebSocketOrigin \`{path}.startsWith('${websocketPath}') && {http.request.header.Origin} != '' && {http.request.header.Origin} != 'http://' + {http.request.hostport} && {http.request.header.Origin} != 'https://' + {http.request.hostport}\`
|
|
213
|
-
\t\trespond @foreignWebSocketOrigin 403
|
|
214
|
-
|
|
215
|
-
\t\thandle ${websocketPath}* {
|
|
216
|
-
\t\t\treverse_proxy 127.0.0.1:${realtimePort}
|
|
217
|
-
\t\t}
|
|
218
|
-
|
|
219
|
-
\t\thandle {
|
|
220
|
-
\t\t\treverse_proxy 127.0.0.1:${appPort}
|
|
221
|
-
\t\t}
|
|
222
|
-
\t}
|
|
223
|
-
}
|
|
224
|
-
`;
|
|
225
|
-
}
|
|
226
|
-
function requiredValue(value, name) {
|
|
227
|
-
const normalized = value.trim();
|
|
228
|
-
if (!normalized)
|
|
229
|
-
throw new Error(`${name} is required`);
|
|
230
|
-
return normalized;
|
|
231
|
-
}
|
|
232
|
-
function port(value, name) {
|
|
233
|
-
if (!Number.isInteger(value) || value < 1 || value > 65_535)
|
|
234
|
-
throw new Error(`${name} must be a valid TCP port`);
|
|
235
|
-
return value;
|
|
236
|
-
}
|
|
237
|
-
function absolutePath(value, name) {
|
|
238
|
-
if (!path.isAbsolute(value))
|
|
239
|
-
throw new Error(`${name} must be an absolute path`);
|
|
240
|
-
return value;
|
|
241
|
-
}
|
|
242
|
-
// The secret lands back in the environment so the supervised application inherits the value Centrifugo was given.
|
|
243
|
-
export function persistedRealtimeSecret(environment = process.env, options = {}) {
|
|
244
|
-
const prefix = options.prefix ?? '';
|
|
245
|
-
const file = environment[`${prefix}REALTIME_SECRET_FILE`]?.trim() || options.defaultFile || '/data/realtime-secret';
|
|
246
|
-
const secret = persistedSecret({
|
|
247
|
-
directory: path.dirname(file),
|
|
248
|
-
filename: path.basename(file),
|
|
249
|
-
environment,
|
|
250
|
-
environmentKey: `${prefix}REALTIME_SECRET`,
|
|
251
|
-
bytes: 48,
|
|
252
|
-
});
|
|
253
|
-
environment[`${prefix}REALTIME_SECRET`] = secret;
|
|
254
|
-
return secret;
|
|
255
|
-
}
|
|
1
|
+
export { caddyRealtimeProxy, persistedRealtimeSecret, runRealtimeStack } from './stack.js';
|
|
256
2
|
//# sourceMappingURL=index.js.map
|