ras-stack 5.5.6 → 6.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 +32 -34
- package/dist/cli.d.ts +0 -27
- package/dist/cli.js +4 -32
- package/dist/cli.js.map +1 -1
- package/package.json +12 -228
- package/config/vite.mjs +0 -3
- package/dist/auth/client.d.ts +0 -11
- package/dist/auth/client.js +0 -57
- package/dist/auth/client.js.map +0 -1
- package/dist/auth/index.d.ts +0 -9
- package/dist/auth/index.js +0 -6
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/origins.d.ts +0 -13
- package/dist/auth/origins.js +0 -41
- package/dist/auth/origins.js.map +0 -1
- package/dist/auth/providers.d.ts +0 -11
- package/dist/auth/providers.js +0 -26
- package/dist/auth/providers.js.map +0 -1
- package/dist/auth/random.d.ts +0 -2
- package/dist/auth/random.js +0 -10
- package/dist/auth/random.js.map +0 -1
- package/dist/auth/react.d.ts +0 -18
- package/dist/auth/react.js +0 -34
- package/dist/auth/react.js.map +0 -1
- package/dist/auth/secret.d.ts +0 -8
- package/dist/auth/secret.js +0 -44
- package/dist/auth/secret.js.map +0 -1
- package/dist/auth/settings.d.ts +0 -54
- package/dist/auth/settings.js +0 -37
- package/dist/auth/settings.js.map +0 -1
- package/dist/build/cli.d.ts +0 -1
- package/dist/build/cli.js +0 -24
- package/dist/build/cli.js.map +0 -1
- package/dist/build/index.d.ts +0 -17
- package/dist/build/index.js +0 -93
- package/dist/build/index.js.map +0 -1
- package/dist/changesets/cli.d.ts +0 -1
- package/dist/changesets/cli.js +0 -14
- package/dist/changesets/cli.js.map +0 -1
- package/dist/changesets/index.d.ts +0 -1
- package/dist/changesets/index.js +0 -38
- package/dist/changesets/index.js.map +0 -1
- package/dist/config.d.ts +0 -3
- package/dist/config.js +0 -3
- package/dist/config.js.map +0 -1
- package/dist/conformance/index.d.ts +0 -9
- package/dist/conformance/index.js +0 -92
- package/dist/conformance/index.js.map +0 -1
- package/dist/database/index.d.ts +0 -19
- package/dist/database/index.js +0 -21
- package/dist/database/index.js.map +0 -1
- package/dist/database/libsql.d.ts +0 -14
- package/dist/database/libsql.js +0 -31
- package/dist/database/libsql.js.map +0 -1
- package/dist/database/postgres.d.ts +0 -13
- package/dist/database/postgres.js +0 -16
- package/dist/database/postgres.js.map +0 -1
- package/dist/database/pragmas.d.ts +0 -7
- package/dist/database/pragmas.js +0 -12
- package/dist/database/pragmas.js.map +0 -1
- package/dist/database/sqlite.d.ts +0 -20
- package/dist/database/sqlite.js +0 -45
- package/dist/database/sqlite.js.map +0 -1
- package/dist/email/index.d.ts +0 -63
- package/dist/email/index.js +0 -95
- package/dist/email/index.js.map +0 -1
- package/dist/managed/catalog.d.ts +0 -40
- package/dist/managed/catalog.js +0 -114
- package/dist/managed/catalog.js.map +0 -1
- package/dist/managed/cli.d.ts +0 -1
- package/dist/managed/cli.js +0 -54
- package/dist/managed/cli.js.map +0 -1
- package/dist/managed/environment.d.ts +0 -5
- package/dist/managed/environment.js +0 -52
- package/dist/managed/environment.js.map +0 -1
- package/dist/managed/files.d.ts +0 -4
- package/dist/managed/files.js +0 -30
- package/dist/managed/files.js.map +0 -1
- package/dist/managed/install.d.ts +0 -4
- package/dist/managed/install.js +0 -62
- package/dist/managed/install.js.map +0 -1
- package/dist/managed/model.d.ts +0 -24
- package/dist/managed/model.js +0 -30
- package/dist/managed/model.js.map +0 -1
- package/dist/managed/plan.d.ts +0 -13
- package/dist/managed/plan.js +0 -99
- package/dist/managed/plan.js.map +0 -1
- package/dist/managed/pnpm.d.ts +0 -23
- package/dist/managed/pnpm.js +0 -2808
- package/dist/managed/pnpm.js.map +0 -7
- package/dist/managed/process.d.ts +0 -4
- package/dist/managed/process.js +0 -23
- package/dist/managed/process.js.map +0 -1
- package/dist/managed/sync.d.ts +0 -6
- package/dist/managed/sync.js +0 -96
- package/dist/managed/sync.js.map +0 -1
- package/dist/managed/tools.d.ts +0 -1
- package/dist/managed/tools.js +0 -7
- package/dist/managed/tools.js.map +0 -1
- package/dist/posthog/config.d.ts +0 -19
- package/dist/posthog/config.js +0 -51
- package/dist/posthog/config.js.map +0 -1
- package/dist/posthog/index.d.ts +0 -4
- package/dist/posthog/index.js +0 -3
- package/dist/posthog/index.js.map +0 -1
- package/dist/posthog/proxy.d.ts +0 -30
- package/dist/posthog/proxy.js +0 -51
- package/dist/posthog/proxy.js.map +0 -1
- package/dist/posthog/react.d.ts +0 -39
- package/dist/posthog/react.js +0 -81
- package/dist/posthog/react.js.map +0 -1
- package/dist/posthog/request.d.ts +0 -12
- package/dist/posthog/request.js +0 -22
- package/dist/posthog/request.js.map +0 -1
- package/dist/posthog/server.d.ts +0 -67
- package/dist/posthog/server.js +0 -388
- package/dist/posthog/server.js.map +0 -1
- package/dist/query/index.d.ts +0 -8
- package/dist/query/index.js +0 -17
- package/dist/query/index.js.map +0 -1
- package/dist/realtime/client.d.ts +0 -19
- package/dist/realtime/client.js +0 -37
- package/dist/realtime/client.js.map +0 -1
- package/dist/realtime/environment.d.ts +0 -10
- package/dist/realtime/environment.js +0 -28
- package/dist/realtime/environment.js.map +0 -1
- package/dist/realtime/index.d.ts +0 -6
- package/dist/realtime/index.js +0 -4
- package/dist/realtime/index.js.map +0 -1
- package/dist/realtime/publisher.d.ts +0 -37
- package/dist/realtime/publisher.js +0 -195
- package/dist/realtime/publisher.js.map +0 -1
- package/dist/realtime/react.d.ts +0 -13
- package/dist/realtime/react.js +0 -78
- package/dist/realtime/react.js.map +0 -1
- package/dist/realtime/tokens.d.ts +0 -6
- package/dist/realtime/tokens.js +0 -13
- package/dist/realtime/tokens.js.map +0 -1
- package/dist/runtime/dev.d.ts +0 -21
- package/dist/runtime/dev.js +0 -138
- package/dist/runtime/dev.js.map +0 -1
- package/dist/runtime/index.d.ts +0 -2
- package/dist/runtime/index.js +0 -2
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/stack.d.ts +0 -65
- package/dist/runtime/stack.js +0 -226
- package/dist/runtime/stack.js.map +0 -1
- package/dist/server/canonical-host.d.ts +0 -6
- package/dist/server/canonical-host.js +0 -23
- package/dist/server/canonical-host.js.map +0 -1
- package/dist/server/errors.d.ts +0 -1
- package/dist/server/errors.js +0 -20
- package/dist/server/errors.js.map +0 -1
- package/dist/server/health.d.ts +0 -10
- package/dist/server/health.js +0 -12
- package/dist/server/health.js.map +0 -1
- package/dist/server/index.d.ts +0 -7
- package/dist/server/index.js +0 -5
- package/dist/server/index.js.map +0 -1
- package/dist/server/rpc.d.ts +0 -19
- package/dist/server/rpc.js +0 -52
- package/dist/server/rpc.js.map +0 -1
- package/dist/server/server-function.d.ts +0 -8
- package/dist/server/server-function.js +0 -18
- package/dist/server/server-function.js.map +0 -1
- package/dist/server/singleton.d.ts +0 -4
- package/dist/server/singleton.js +0 -48
- package/dist/server/singleton.js.map +0 -1
- package/dist/spacetime/index.d.ts +0 -36
- package/dist/spacetime/index.js +0 -103
- package/dist/spacetime/index.js.map +0 -1
- package/dist/tanstack/client.d.ts +0 -11
- package/dist/tanstack/client.js +0 -33
- package/dist/tanstack/client.js.map +0 -1
- package/dist/tanstack/middleware.d.ts +0 -9
- package/dist/tanstack/middleware.js +0 -32
- package/dist/tanstack/middleware.js.map +0 -1
- package/dist/tanstack/server.d.ts +0 -10
- package/dist/tanstack/server.js +0 -14
- package/dist/tanstack/server.js.map +0 -1
- package/dist/uploads/index.d.ts +0 -29
- package/dist/uploads/index.js +0 -83
- package/dist/uploads/index.js.map +0 -1
- package/dist/vite/config.d.ts +0 -18
- package/dist/vite/config.js +0 -88
- package/dist/vite/config.js.map +0 -1
- package/dist/vite/index.d.ts +0 -2
- package/dist/vite/index.js +0 -2
- package/dist/vite/index.js.map +0 -1
- package/pnpmfile.mjs +0 -1
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export type CentrifugoPublisherOptions = {
|
|
2
|
-
apiUrl: string;
|
|
3
|
-
apiKey: string;
|
|
4
|
-
fetch?: typeof fetch;
|
|
5
|
-
timeoutMs?: number;
|
|
6
|
-
retryMs?: number;
|
|
7
|
-
maxRetries?: number;
|
|
8
|
-
maxConcurrentChannels?: number;
|
|
9
|
-
maxPendingChannels?: number;
|
|
10
|
-
onError: (error: unknown, channel: string) => void;
|
|
11
|
-
onRetry?: (error: unknown, channel: string) => void;
|
|
12
|
-
};
|
|
13
|
-
export declare class CentrifugoPublisher {
|
|
14
|
-
private readonly options;
|
|
15
|
-
private readonly pending;
|
|
16
|
-
private readonly queue;
|
|
17
|
-
private readonly idleWaiters;
|
|
18
|
-
private readonly request;
|
|
19
|
-
private readonly publishUrl;
|
|
20
|
-
private readonly maxConcurrentChannels;
|
|
21
|
-
private readonly maxPendingChannels;
|
|
22
|
-
private active;
|
|
23
|
-
private closed;
|
|
24
|
-
constructor(options: CentrifugoPublisherOptions);
|
|
25
|
-
publish(channel: string, data: unknown): boolean;
|
|
26
|
-
idle(): Promise<void>;
|
|
27
|
-
close(options?: {
|
|
28
|
-
signal?: AbortSignal;
|
|
29
|
-
}): Promise<void>;
|
|
30
|
-
private pump;
|
|
31
|
-
private flush;
|
|
32
|
-
private deliver;
|
|
33
|
-
private deliverOnce;
|
|
34
|
-
private reportError;
|
|
35
|
-
private isIdle;
|
|
36
|
-
private resolveIdle;
|
|
37
|
-
}
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
|
-
export class CentrifugoPublisher {
|
|
3
|
-
options;
|
|
4
|
-
pending = new Map();
|
|
5
|
-
queue = [];
|
|
6
|
-
idleWaiters = new Set();
|
|
7
|
-
request;
|
|
8
|
-
publishUrl;
|
|
9
|
-
maxConcurrentChannels;
|
|
10
|
-
maxPendingChannels;
|
|
11
|
-
active = 0;
|
|
12
|
-
closed = false;
|
|
13
|
-
constructor(options) {
|
|
14
|
-
this.options = options;
|
|
15
|
-
this.request = options.fetch ?? fetch;
|
|
16
|
-
this.publishUrl = `${options.apiUrl.replace(/\/$/, '')}/publish`;
|
|
17
|
-
this.maxConcurrentChannels = positiveInteger(options.maxConcurrentChannels ?? 8, 'maxConcurrentChannels');
|
|
18
|
-
this.maxPendingChannels = positiveInteger(options.maxPendingChannels ?? 1_024, 'maxPendingChannels');
|
|
19
|
-
}
|
|
20
|
-
publish(channel, data) {
|
|
21
|
-
if (!this.options.apiUrl)
|
|
22
|
-
return false;
|
|
23
|
-
if (this.closed) {
|
|
24
|
-
this.reportError(new Error('Realtime publisher is closed'), channel);
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
const pending = this.pending.get(channel);
|
|
28
|
-
if (pending) {
|
|
29
|
-
pending.dirty = true;
|
|
30
|
-
pending.data = data;
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
if (this.pending.size >= this.maxPendingChannels) {
|
|
34
|
-
this.reportError(new Error('Realtime publisher queue is full'), channel);
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
const state = { dirty: true, data, running: false };
|
|
38
|
-
this.pending.set(channel, state);
|
|
39
|
-
this.queue.push(channel);
|
|
40
|
-
this.pump();
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
idle() {
|
|
44
|
-
if (this.isIdle())
|
|
45
|
-
return Promise.resolve();
|
|
46
|
-
return new Promise((resolve) => this.idleWaiters.add(resolve));
|
|
47
|
-
}
|
|
48
|
-
async close(options = {}) {
|
|
49
|
-
this.closed = true;
|
|
50
|
-
const idle = this.idle();
|
|
51
|
-
if (!options.signal)
|
|
52
|
-
return idle;
|
|
53
|
-
await abortable(idle, options.signal);
|
|
54
|
-
}
|
|
55
|
-
pump() {
|
|
56
|
-
while (this.active < this.maxConcurrentChannels) {
|
|
57
|
-
const channel = this.queue.shift();
|
|
58
|
-
if (channel === undefined)
|
|
59
|
-
break;
|
|
60
|
-
// A channel is queued only alongside a fresh, idle pending state.
|
|
61
|
-
const state = this.pending.get(channel);
|
|
62
|
-
state.running = true;
|
|
63
|
-
this.active++;
|
|
64
|
-
void this.flush(channel, state).finally(() => {
|
|
65
|
-
this.active--;
|
|
66
|
-
this.pump();
|
|
67
|
-
this.resolveIdle();
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
async flush(channel, state) {
|
|
72
|
-
let failure;
|
|
73
|
-
try {
|
|
74
|
-
while (state.dirty) {
|
|
75
|
-
state.dirty = false;
|
|
76
|
-
// Publications for one channel must preserve mutation order.
|
|
77
|
-
// oxlint-disable-next-line no-await-in-loop
|
|
78
|
-
await this.deliver(channel, state.data);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
failure = error;
|
|
83
|
-
}
|
|
84
|
-
finally {
|
|
85
|
-
if (this.pending.get(channel) === state)
|
|
86
|
-
this.pending.delete(channel);
|
|
87
|
-
}
|
|
88
|
-
if (failure) {
|
|
89
|
-
if (state.dirty) {
|
|
90
|
-
this.pending.set(channel, { dirty: true, data: state.data, running: false });
|
|
91
|
-
this.queue.push(channel);
|
|
92
|
-
this.pump();
|
|
93
|
-
}
|
|
94
|
-
this.reportError(failure, channel);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
async deliver(channel, data) {
|
|
98
|
-
const maxRetries = this.options.maxRetries ?? 3;
|
|
99
|
-
for (let retries = 0;; retries++) {
|
|
100
|
-
try {
|
|
101
|
-
// Retrying must finish before a later publication can overtake this one.
|
|
102
|
-
// oxlint-disable-next-line no-await-in-loop
|
|
103
|
-
await this.deliverOnce(channel, data);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
if (!(error instanceof TransientPublishError))
|
|
108
|
-
throw error;
|
|
109
|
-
if (retries >= maxRetries)
|
|
110
|
-
throw error;
|
|
111
|
-
this.options.onRetry?.(error, channel);
|
|
112
|
-
// oxlint-disable-next-line no-await-in-loop
|
|
113
|
-
await delay(this.options.retryMs ?? 1_000);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
async deliverOnce(channel, data) {
|
|
118
|
-
let response;
|
|
119
|
-
try {
|
|
120
|
-
response = await this.request(this.publishUrl, {
|
|
121
|
-
method: 'POST',
|
|
122
|
-
headers: { 'Content-Type': 'application/json', 'X-API-Key': this.options.apiKey },
|
|
123
|
-
body: JSON.stringify({ channel, data }),
|
|
124
|
-
signal: AbortSignal.timeout(this.options.timeoutMs ?? 5_000),
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
if (error instanceof TypeError || isTimeout(error))
|
|
129
|
-
throw new TransientPublishError('Realtime publish request failed', { cause: error });
|
|
130
|
-
throw error;
|
|
131
|
-
}
|
|
132
|
-
if (!response.ok) {
|
|
133
|
-
const message = `Realtime publish failed with status ${response.status}`;
|
|
134
|
-
if (response.status >= 500 || response.status === 429)
|
|
135
|
-
throw new TransientPublishError(message);
|
|
136
|
-
throw new Error(message);
|
|
137
|
-
}
|
|
138
|
-
const result = await response.json();
|
|
139
|
-
const error = centrifugoError(result);
|
|
140
|
-
if (!error)
|
|
141
|
-
return;
|
|
142
|
-
const message = `Realtime publish failed: ${error.message ?? `code ${error.code ?? 'unknown'}`}`;
|
|
143
|
-
if (error.code === 100)
|
|
144
|
-
throw new TransientPublishError(message);
|
|
145
|
-
throw new Error(message);
|
|
146
|
-
}
|
|
147
|
-
reportError(error, channel) {
|
|
148
|
-
try {
|
|
149
|
-
this.options.onError(error, channel);
|
|
150
|
-
}
|
|
151
|
-
catch { }
|
|
152
|
-
}
|
|
153
|
-
isIdle() {
|
|
154
|
-
return this.pending.size === 0 && this.active === 0 && this.queue.length === 0;
|
|
155
|
-
}
|
|
156
|
-
resolveIdle() {
|
|
157
|
-
if (!this.isIdle())
|
|
158
|
-
return;
|
|
159
|
-
for (const resolve of this.idleWaiters)
|
|
160
|
-
resolve();
|
|
161
|
-
this.idleWaiters.clear();
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
async function abortable(work, signal) {
|
|
165
|
-
signal.throwIfAborted();
|
|
166
|
-
let abort;
|
|
167
|
-
const aborted = new Promise((_resolve, reject) => {
|
|
168
|
-
abort = () => reject(signal.reason);
|
|
169
|
-
signal.addEventListener('abort', abort, { once: true });
|
|
170
|
-
});
|
|
171
|
-
try {
|
|
172
|
-
await Promise.race([work, aborted]);
|
|
173
|
-
}
|
|
174
|
-
finally {
|
|
175
|
-
signal.removeEventListener('abort', abort);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
class TransientPublishError extends Error {
|
|
179
|
-
}
|
|
180
|
-
function isTimeout(error) {
|
|
181
|
-
return error instanceof DOMException && error.name === 'TimeoutError';
|
|
182
|
-
}
|
|
183
|
-
function centrifugoError(result) {
|
|
184
|
-
if (!result || typeof result !== 'object' || !('error' in result) || !result.error || typeof result.error !== 'object')
|
|
185
|
-
return undefined;
|
|
186
|
-
const code = 'code' in result.error && typeof result.error.code === 'number' ? result.error.code : undefined;
|
|
187
|
-
const message = 'message' in result.error && typeof result.error.message === 'string' ? result.error.message : undefined;
|
|
188
|
-
return { ...(code === undefined ? {} : { code }), ...(message === undefined ? {} : { message }) };
|
|
189
|
-
}
|
|
190
|
-
function positiveInteger(value, name) {
|
|
191
|
-
if (!Number.isSafeInteger(value) || value < 1)
|
|
192
|
-
throw new RangeError(`${name} must be a positive integer`);
|
|
193
|
-
return value;
|
|
194
|
-
}
|
|
195
|
-
//# sourceMappingURL=publisher.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"publisher.js","sourceRoot":"","sources":["../../src/realtime/publisher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAiB1D,MAAM,OAAO,mBAAmB;IAWD,OAAO;IAVnB,OAAO,GAAG,IAAI,GAAG,EAA8B,CAAA;IAC/C,KAAK,GAAa,EAAE,CAAA;IACpB,WAAW,GAAG,IAAI,GAAG,EAAc,CAAA;IACnC,OAAO,CAAc;IACrB,UAAU,CAAQ;IA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M,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;IAC5G,MAAM,OAAO,GAAG,SAAS,IAAI,MAAM,CAAC,KAAK,IAAI,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAA;IACxH,OAAO,EAAE,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAA;AACnG,CAAC;AAED,SAAS,eAAe,CAAC,KAAa,EAAE,IAAY;IAClD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,6BAA6B,CAAC,CAAA;IACzG,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import { setTimeout as delay } from 'node:timers/promises'\n\nexport type CentrifugoPublisherOptions = {\n apiUrl: string\n apiKey: string\n fetch?: typeof fetch\n timeoutMs?: number\n retryMs?: number\n maxRetries?: number\n maxConcurrentChannels?: number\n maxPendingChannels?: number\n onError: (error: unknown, channel: string) => void\n onRetry?: (error: unknown, channel: string) => void\n}\n\ntype PendingPublication = { dirty: boolean; data: unknown; running: boolean }\n\nexport class CentrifugoPublisher {\n private readonly pending = new Map<string, PendingPublication>()\n private readonly queue: string[] = []\n private readonly idleWaiters = new Set<() => void>()\n private readonly request: typeof fetch\n private readonly publishUrl: string\n private readonly maxConcurrentChannels: number\n private readonly maxPendingChannels: number\n private active = 0\n private closed = false\n\n constructor(private readonly options: CentrifugoPublisherOptions) {\n this.request = options.fetch ?? fetch\n this.publishUrl = `${options.apiUrl.replace(/\\/$/, '')}/publish`\n this.maxConcurrentChannels = positiveInteger(options.maxConcurrentChannels ?? 8, 'maxConcurrentChannels')\n this.maxPendingChannels = positiveInteger(options.maxPendingChannels ?? 1_024, 'maxPendingChannels')\n }\n\n publish(channel: string, data: unknown) {\n if (!this.options.apiUrl) return false\n if (this.closed) {\n this.reportError(new Error('Realtime publisher is closed'), channel)\n return false\n }\n const pending = this.pending.get(channel)\n if (pending) {\n pending.dirty = true\n pending.data = data\n return true\n }\n if (this.pending.size >= this.maxPendingChannels) {\n this.reportError(new Error('Realtime publisher queue is full'), channel)\n return false\n }\n\n const state = { dirty: true, data, running: false }\n this.pending.set(channel, state)\n this.queue.push(channel)\n this.pump()\n return true\n }\n\n idle() {\n if (this.isIdle()) return Promise.resolve()\n return new Promise<void>((resolve) => this.idleWaiters.add(resolve))\n }\n\n async close(options: { signal?: AbortSignal } = {}) {\n this.closed = true\n const idle = this.idle()\n if (!options.signal) return idle\n await abortable(idle, options.signal)\n }\n\n private pump() {\n while (this.active < this.maxConcurrentChannels) {\n const channel = this.queue.shift()\n if (channel === undefined) break\n // A channel is queued only alongside a fresh, idle pending state.\n const state = this.pending.get(channel)!\n state.running = true\n this.active++\n void this.flush(channel, state).finally(() => {\n this.active--\n this.pump()\n this.resolveIdle()\n })\n }\n }\n\n private async flush(channel: string, state: PendingPublication) {\n let failure: unknown\n try {\n while (state.dirty) {\n state.dirty = false\n // Publications for one channel must preserve mutation order.\n // oxlint-disable-next-line no-await-in-loop\n await this.deliver(channel, state.data)\n }\n } catch (error) {\n failure = error\n } finally {\n if (this.pending.get(channel) === state) this.pending.delete(channel)\n }\n if (failure) {\n if (state.dirty) {\n this.pending.set(channel, { dirty: true, data: state.data, running: false })\n this.queue.push(channel)\n this.pump()\n }\n this.reportError(failure, channel)\n }\n }\n\n private async deliver(channel: string, data: unknown) {\n const maxRetries = this.options.maxRetries ?? 3\n for (let retries = 0; ; retries++) {\n try {\n // Retrying must finish before a later publication can overtake this one.\n // oxlint-disable-next-line no-await-in-loop\n await this.deliverOnce(channel, data)\n return\n } catch (error) {\n if (!(error instanceof TransientPublishError)) throw error\n if (retries >= maxRetries) throw error\n this.options.onRetry?.(error, channel)\n // oxlint-disable-next-line no-await-in-loop\n await delay(this.options.retryMs ?? 1_000)\n }\n }\n }\n\n private async deliverOnce(channel: string, data: unknown) {\n let response: Response\n try {\n response = await this.request(this.publishUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', 'X-API-Key': this.options.apiKey },\n body: JSON.stringify({ channel, data }),\n signal: AbortSignal.timeout(this.options.timeoutMs ?? 5_000),\n })\n } catch (error) {\n if (error instanceof TypeError || isTimeout(error))\n throw new TransientPublishError('Realtime publish request failed', { cause: error })\n throw error\n }\n\n if (!response.ok) {\n const message = `Realtime publish failed with status ${response.status}`\n if (response.status >= 500 || response.status === 429) throw new TransientPublishError(message)\n throw new Error(message)\n }\n\n const result: unknown = await response.json()\n const error = centrifugoError(result)\n if (!error) return\n const message = `Realtime publish failed: ${error.message ?? `code ${error.code ?? 'unknown'}`}`\n if (error.code === 100) throw new TransientPublishError(message)\n throw new Error(message)\n }\n\n private reportError(error: unknown, channel: string) {\n try {\n this.options.onError(error, channel)\n } catch {}\n }\n\n private isIdle() {\n return this.pending.size === 0 && this.active === 0 && this.queue.length === 0\n }\n\n private resolveIdle() {\n if (!this.isIdle()) return\n for (const resolve of this.idleWaiters) resolve()\n this.idleWaiters.clear()\n }\n}\n\nasync function abortable(work: Promise<void>, signal: AbortSignal) {\n signal.throwIfAborted()\n let abort!: () => void\n const aborted = new Promise<never>((_resolve, reject) => {\n abort = () => reject(signal.reason)\n signal.addEventListener('abort', abort, { once: true })\n })\n try {\n await Promise.race([work, aborted])\n } finally {\n signal.removeEventListener('abort', abort)\n }\n}\n\nclass TransientPublishError extends Error {}\n\nfunction isTimeout(error: unknown) {\n return error instanceof DOMException && error.name === 'TimeoutError'\n}\n\nfunction centrifugoError(result: unknown): { code?: number; message?: string } | undefined {\n if (!result || typeof result !== 'object' || !('error' in result) || !result.error || typeof result.error !== 'object') return undefined\n const code = 'code' in result.error && typeof result.error.code === 'number' ? result.error.code : undefined\n const message = 'message' in result.error && typeof result.error.message === 'string' ? result.error.message : undefined\n return { ...(code === undefined ? {} : { code }), ...(message === undefined ? {} : { message }) }\n}\n\nfunction positiveInteger(value: number, name: string) {\n if (!Number.isSafeInteger(value) || value < 1) throw new RangeError(`${name} must be a positive integer`)\n return value\n}\n"]}
|
package/dist/realtime/react.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Centrifuge, Subscription, SubscriptionOptions } from 'centrifuge';
|
|
2
|
-
export declare function useConnectedRealtimeClient(create: () => Centrifuge | Promise<Centrifuge>, enabled?: boolean, options?: {
|
|
3
|
-
configure?: (client: Centrifuge) => void | (() => void);
|
|
4
|
-
onError?: (error: unknown) => void;
|
|
5
|
-
}): Centrifuge | undefined;
|
|
6
|
-
export type RealtimeSubscriptionHookOptions = {
|
|
7
|
-
client?: Centrifuge;
|
|
8
|
-
channel?: string;
|
|
9
|
-
enabled?: boolean;
|
|
10
|
-
options?: SubscriptionOptions;
|
|
11
|
-
configure?: (subscription: Subscription) => void | (() => void);
|
|
12
|
-
};
|
|
13
|
-
export declare function useRealtimeSubscription(options: RealtimeSubscriptionHookOptions): Subscription | undefined;
|
package/dist/realtime/react.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
export function useConnectedRealtimeClient(create, enabled = true, options = {}) {
|
|
3
|
-
const [client, setClient] = useState();
|
|
4
|
-
const configure = options.configure;
|
|
5
|
-
const onError = options.onError;
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
if (!enabled)
|
|
8
|
-
return undefined;
|
|
9
|
-
let active = true;
|
|
10
|
-
let cleanup;
|
|
11
|
-
let connected;
|
|
12
|
-
const connect = (next) => {
|
|
13
|
-
if (!active) {
|
|
14
|
-
next.disconnect();
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
cleanup = configure?.(next) ?? undefined;
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
next.disconnect();
|
|
22
|
-
onError?.(error);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
setClient(next);
|
|
26
|
-
next.connect();
|
|
27
|
-
connected = next;
|
|
28
|
-
};
|
|
29
|
-
try {
|
|
30
|
-
const created = create();
|
|
31
|
-
if (created instanceof Promise)
|
|
32
|
-
void created.then(connect, (error) => active && onError?.(error));
|
|
33
|
-
else
|
|
34
|
-
connect(created);
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
onError?.(error);
|
|
38
|
-
}
|
|
39
|
-
return () => {
|
|
40
|
-
active = false;
|
|
41
|
-
cleanup?.();
|
|
42
|
-
connected?.disconnect();
|
|
43
|
-
setClient(undefined);
|
|
44
|
-
};
|
|
45
|
-
}, [configure, create, enabled, onError]);
|
|
46
|
-
return client;
|
|
47
|
-
}
|
|
48
|
-
export function useRealtimeSubscription(options) {
|
|
49
|
-
const [subscription, setSubscription] = useState();
|
|
50
|
-
const { channel, client, configure, enabled = true, options: subscriptionOptions } = options;
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
if (!enabled || !client || !channel)
|
|
53
|
-
return undefined;
|
|
54
|
-
const next = client.newSubscription(channel, subscriptionOptions);
|
|
55
|
-
let cleanup;
|
|
56
|
-
try {
|
|
57
|
-
cleanup = configure?.(next);
|
|
58
|
-
next.subscribe();
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
client.removeSubscription(next);
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
// oxlint-disable-next-line react/set-state-in-effect -- The subscription is created by this effect, so state is how it reaches the caller.
|
|
65
|
-
setSubscription(next);
|
|
66
|
-
return () => {
|
|
67
|
-
try {
|
|
68
|
-
cleanup?.();
|
|
69
|
-
}
|
|
70
|
-
finally {
|
|
71
|
-
client.removeSubscription(next);
|
|
72
|
-
setSubscription(undefined);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}, [channel, client, configure, enabled, subscriptionOptions]);
|
|
76
|
-
return subscription;
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=react.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../src/realtime/react.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE3C,MAAM,UAAU,0BAA0B,CACxC,MAA8C,EAC9C,OAAO,GAAG,IAAI,EACd,OAAO,GAAoG,EAAE;IAE7G,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,EAAc,CAAA;IAClD,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;IACnC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;IAC/B,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,OAAO;YAAE,OAAO,SAAS,CAAA;QAC9B,IAAI,MAAM,GAAG,IAAI,CAAA;QACjB,IAAI,OAAiC,CAAA;QACrC,IAAI,SAAiC,CAAA;QACrC,MAAM,OAAO,GAAG,CAAC,IAAgB,EAAE,EAAE;YACnC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,IAAI,CAAC,UAAU,EAAE,CAAA;gBACjB,OAAM;YACR,CAAC;YACD,IAAI,CAAC;gBACH,OAAO,GAAG,SAAS,EAAE,CAAC,IAAI,CAAC,IAAI,SAAS,CAAA;YAC1C,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,UAAU,EAAE,CAAA;gBACjB,OAAO,EAAE,CAAC,KAAK,CAAC,CAAA;gBAChB,OAAM;YACR,CAAC;YACD,SAAS,CAAC,IAAI,CAAC,CAAA;YACf,IAAI,CAAC,OAAO,EAAE,CAAA;YACd,SAAS,GAAG,IAAI,CAAA;QA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AAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAA;YAC/B,MAAM,KAAK,CAAA;QACb,CAAC;QACD,2IAA2I;QAC3I,eAAe,CAAC,IAAI,CAAC,CAAA;QACrB,OAAO,GAAG,EAAE;YACV,IAAI,CAAC;gBACH,OAAO,EAAE,EAAE,CAAA;YACb,CAAC;oBAAS,CAAC;gBACT,MAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAA;gBAC/B,eAAe,CAAC,SAAS,CAAC,CAAA;YAC5B,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) return undefined\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 setClient(undefined)\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) return undefined\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 // oxlint-disable-next-line react/set-state-in-effect -- The subscription is created by this effect, so state is how it reaches the caller.\n setSubscription(next)\n return () => {\n try {\n cleanup?.()\n } finally {\n client.removeSubscription(next)\n setSubscription(undefined)\n }\n }\n }, [channel, client, configure, enabled, subscriptionOptions])\n return subscription\n}\n"]}
|
package/dist/realtime/tokens.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import crypto from 'node:crypto';
|
|
2
|
-
export function signRealtimeToken(subject, claims, options) {
|
|
3
|
-
const now = options.now ?? Math.floor(Date.now() / 1000);
|
|
4
|
-
return sign({ ...claims, sub: subject, exp: now + (options.ttlSeconds ?? 5 * 60) }, options.secret);
|
|
5
|
-
}
|
|
6
|
-
function sign(payload, secret) {
|
|
7
|
-
const header = Buffer.from(JSON.stringify({ alg: 'HS256', typ: 'JWT' })).toString('base64url');
|
|
8
|
-
const claims = Buffer.from(JSON.stringify(payload)).toString('base64url');
|
|
9
|
-
const unsigned = `${header}.${claims}`;
|
|
10
|
-
const signature = crypto.createHmac('sha256', secret).update(unsigned).digest('base64url');
|
|
11
|
-
return `${unsigned}.${signature}`;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=tokens.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/realtime/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAQhC,MAAM,UAAU,iBAAiB,CAAC,OAAe,EAAE,MAA+B,EAAE,OAA6B;IAC/G,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IACxD,OAAO,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;AACrG,CAAC;AAED,SAAS,IAAI,CAAC,OAAgC,EAAE,MAAc;IAC5D,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;IAC9F,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;IACzE,MAAM,QAAQ,GAAG,GAAG,MAAM,IAAI,MAAM,EAAE,CAAA;IACtC,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;IAC1F,OAAO,GAAG,QAAQ,IAAI,SAAS,EAAE,CAAA;AACnC,CAAC","sourcesContent":["import crypto from 'node:crypto'\n\nexport type RealtimeTokenOptions = {\n secret: string\n now?: number\n ttlSeconds?: number\n}\n\nexport function signRealtimeToken(subject: string, claims: Record<string, unknown>, options: RealtimeTokenOptions) {\n const now = options.now ?? Math.floor(Date.now() / 1000)\n return sign({ ...claims, sub: subject, exp: now + (options.ttlSeconds ?? 5 * 60) }, options.secret)\n}\n\nfunction sign(payload: Record<string, unknown>, secret: string) {\n const header = Buffer.from(JSON.stringify({ alg: 'HS256', typ: 'JWT' })).toString('base64url')\n const claims = Buffer.from(JSON.stringify(payload)).toString('base64url')\n const unsigned = `${header}.${claims}`\n const signature = crypto.createHmac('sha256', secret).update(unsigned).digest('base64url')\n return `${unsigned}.${signature}`\n}\n"]}
|
package/dist/runtime/dev.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type StdioOptions } from 'node:child_process';
|
|
2
|
-
export type RealtimeDevOptions = {
|
|
3
|
-
configPath: string;
|
|
4
|
-
containerName: string;
|
|
5
|
-
port: number;
|
|
6
|
-
bindAddress?: string;
|
|
7
|
-
origin: string;
|
|
8
|
-
secret: string;
|
|
9
|
-
detached?: boolean;
|
|
10
|
-
connectProxyEndpoint?: string;
|
|
11
|
-
};
|
|
12
|
-
type CommandResult = {
|
|
13
|
-
code: number;
|
|
14
|
-
};
|
|
15
|
-
type RunCommand = (command: string, args: readonly string[], stdio?: StdioOptions) => Promise<CommandResult>;
|
|
16
|
-
type RealtimeDevDependencies = {
|
|
17
|
-
run?: RunCommand;
|
|
18
|
-
};
|
|
19
|
-
export declare function runRealtimeDev(options: RealtimeDevOptions, dependencies?: RealtimeDevDependencies): Promise<void>;
|
|
20
|
-
export declare function parseRealtimeDevArguments(arguments_: readonly string[]): RealtimeDevOptions;
|
|
21
|
-
export {};
|
package/dist/runtime/dev.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import { once } from 'node:events';
|
|
3
|
-
import { access } from 'node:fs/promises';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { parseArgs } from 'node:util';
|
|
6
|
-
import { errorHasCode } from '../server/errors.js';
|
|
7
|
-
import { centrifugoEnvironment, port, requiredValue } from './stack.js';
|
|
8
|
-
const runtimeImage = 'ghcr.io/richardsolomou/ras-stack-runtime-binaries:runtime-v1.0.4@sha256:183261400ef822d3dfb7ae9391dc3836d343e01de41ab131df6a42751f87288e';
|
|
9
|
-
export async function runRealtimeDev(options, dependencies = {}) {
|
|
10
|
-
const configPath = path.resolve(options.configPath);
|
|
11
|
-
try {
|
|
12
|
-
await access(configPath);
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
throw new Error(`realtime config is unavailable: ${configPath}`, { cause: error });
|
|
16
|
-
}
|
|
17
|
-
const containerName = dockerName(options.containerName);
|
|
18
|
-
const publicPort = port(options.port, 'port');
|
|
19
|
-
const bindAddress = dockerBindAddress(options.bindAddress ?? '127.0.0.1');
|
|
20
|
-
const origin = httpUrl(options.origin, 'origin');
|
|
21
|
-
const secret = requiredValue(options.secret, 'secret');
|
|
22
|
-
const connectProxyEndpoint = options.connectProxyEndpoint ? httpEndpoint(options.connectProxyEndpoint) : undefined;
|
|
23
|
-
const run = dependencies.run ?? runCommand;
|
|
24
|
-
// Docker publishes the port to the container's network interface, which a loopback-only listener would not accept.
|
|
25
|
-
const { CENTRIFUGO_HTTP_SERVER_ADDRESS: _loopback, ...centrifugo } = centrifugoEnvironment({
|
|
26
|
-
apiKey: secret,
|
|
27
|
-
clientTokenSecret: secret,
|
|
28
|
-
subscriptionTokenSecret: secret,
|
|
29
|
-
allowedOrigins: origin,
|
|
30
|
-
});
|
|
31
|
-
const environment = {
|
|
32
|
-
...centrifugo,
|
|
33
|
-
CENTRIFUGO_VAR_PROXY_SECRET: secret,
|
|
34
|
-
...(connectProxyEndpoint ? { CENTRIFUGO_CLIENT_PROXY_CONNECT_ENDPOINT: connectProxyEndpoint } : {}),
|
|
35
|
-
};
|
|
36
|
-
try {
|
|
37
|
-
if (options.detached)
|
|
38
|
-
await run('docker', ['rm', '--force', containerName], 'ignore');
|
|
39
|
-
const result = await run('docker', [
|
|
40
|
-
'run',
|
|
41
|
-
'--rm',
|
|
42
|
-
...(options.detached ? ['-d'] : []),
|
|
43
|
-
'--name',
|
|
44
|
-
containerName,
|
|
45
|
-
'--add-host',
|
|
46
|
-
'host.docker.internal:host-gateway',
|
|
47
|
-
'-p',
|
|
48
|
-
`${bindAddress}:${publicPort}:8000`,
|
|
49
|
-
...Object.entries(environment).flatMap(([name, value]) => ['-e', `${name}=${value}`]),
|
|
50
|
-
'-v',
|
|
51
|
-
`${configPath}:/centrifugo/config.json:ro`,
|
|
52
|
-
runtimeImage,
|
|
53
|
-
'/usr/local/bin/centrifugo',
|
|
54
|
-
'--config=/centrifugo/config.json',
|
|
55
|
-
]);
|
|
56
|
-
if (result.code !== 0)
|
|
57
|
-
throw new Error(`Docker exited with status ${result.code}`);
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
if (errorHasCode(error, 'ENOENT')) {
|
|
61
|
-
throw new Error('Docker is required but was not found', { cause: error });
|
|
62
|
-
}
|
|
63
|
-
throw error;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
export function parseRealtimeDevArguments(arguments_) {
|
|
67
|
-
const { values } = parseArgs({
|
|
68
|
-
args: [...arguments_],
|
|
69
|
-
options: {
|
|
70
|
-
config: { type: 'string' },
|
|
71
|
-
name: { type: 'string' },
|
|
72
|
-
port: { type: 'string' },
|
|
73
|
-
'bind-address': { type: 'string' },
|
|
74
|
-
origin: { type: 'string' },
|
|
75
|
-
secret: { type: 'string' },
|
|
76
|
-
'connect-proxy-endpoint': { type: 'string' },
|
|
77
|
-
detach: { type: 'boolean' },
|
|
78
|
-
},
|
|
79
|
-
strict: true,
|
|
80
|
-
});
|
|
81
|
-
return {
|
|
82
|
-
configPath: requiredValue(values.config, '--config'),
|
|
83
|
-
containerName: requiredValue(values.name, '--name'),
|
|
84
|
-
port: Number(requiredValue(values.port, '--port')),
|
|
85
|
-
...(values['bind-address'] ? { bindAddress: values['bind-address'] } : {}),
|
|
86
|
-
origin: requiredValue(values.origin, '--origin'),
|
|
87
|
-
secret: requiredValue(values.secret, '--secret'),
|
|
88
|
-
...(values.detach ? { detached: true } : {}),
|
|
89
|
-
...(values['connect-proxy-endpoint'] ? { connectProxyEndpoint: values['connect-proxy-endpoint'] } : {}),
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
async function runCommand(command, args, stdio = 'inherit') {
|
|
93
|
-
const [code] = (await once(spawn(command, [...args], { stdio }), 'exit'));
|
|
94
|
-
return { code: code ?? 1 };
|
|
95
|
-
}
|
|
96
|
-
function dockerName(value) {
|
|
97
|
-
const normalized = requiredValue(value, 'containerName');
|
|
98
|
-
if (!/^[A-Za-z0-9][A-Za-z0-9_.-]*$/.test(normalized))
|
|
99
|
-
throw new Error('containerName is invalid');
|
|
100
|
-
return normalized;
|
|
101
|
-
}
|
|
102
|
-
function dockerBindAddress(value) {
|
|
103
|
-
if (value !== '127.0.0.1' && value !== '0.0.0.0')
|
|
104
|
-
throw new Error('bindAddress must be 127.0.0.1 or 0.0.0.0');
|
|
105
|
-
return value;
|
|
106
|
-
}
|
|
107
|
-
function httpUrl(value, name) {
|
|
108
|
-
let parsed;
|
|
109
|
-
try {
|
|
110
|
-
parsed = new URL(value);
|
|
111
|
-
}
|
|
112
|
-
catch {
|
|
113
|
-
throw new Error(`${name} must be an HTTP URL`);
|
|
114
|
-
}
|
|
115
|
-
if (!['http:', 'https:'].includes(parsed.protocol) ||
|
|
116
|
-
parsed.username ||
|
|
117
|
-
parsed.password ||
|
|
118
|
-
parsed.pathname !== '/' ||
|
|
119
|
-
parsed.search ||
|
|
120
|
-
parsed.hash) {
|
|
121
|
-
throw new Error(`${name} must be an HTTP origin`);
|
|
122
|
-
}
|
|
123
|
-
return parsed.origin;
|
|
124
|
-
}
|
|
125
|
-
function httpEndpoint(value) {
|
|
126
|
-
let parsed;
|
|
127
|
-
try {
|
|
128
|
-
parsed = new URL(value);
|
|
129
|
-
}
|
|
130
|
-
catch {
|
|
131
|
-
throw new Error('connectProxyEndpoint must be an HTTP URL');
|
|
132
|
-
}
|
|
133
|
-
if (!['http:', 'https:'].includes(parsed.protocol) || parsed.username || parsed.password || parsed.search || parsed.hash) {
|
|
134
|
-
throw new Error('connectProxyEndpoint must be an HTTP URL without credentials, query, or fragment');
|
|
135
|
-
}
|
|
136
|
-
return parsed.toString();
|
|
137
|
-
}
|
|
138
|
-
//# sourceMappingURL=dev.js.map
|
package/dist/runtime/dev.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../src/runtime/dev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,qBAAqB,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEvE,MAAM,YAAY,GAChB,0IAA0I,CAAA;AAiB5I,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAA2B,EAAE,YAAY,GAA4B,EAAE;IAC1G,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IACnD,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,UAAU,CAAC,CAAA;IAC1B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,mCAAmC,UAAU,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IACpF,CAAC;IACD,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC,CAAA;IACvD,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAC7C,MAAM,WAAW,GAAG,iBAAiB,CAAC,OAAO,CAAC,WAAW,IAAI,WAAW,CAAC,CA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AAM,CAAC,IAAI,EAAE,CAAC;QACzH,MAAM,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAAA;IACrG,CAAC;IACD,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAA;AAC1B,CAAC","sourcesContent":["import { spawn, type StdioOptions } from 'node:child_process'\nimport { once } from 'node:events'\nimport { access } from 'node:fs/promises'\nimport path from 'node:path'\nimport { parseArgs } from 'node:util'\nimport { errorHasCode } from '../server/errors.js'\nimport { centrifugoEnvironment, port, requiredValue } from './stack.js'\n\nconst runtimeImage =\n 'ghcr.io/richardsolomou/ras-stack-runtime-binaries:runtime-v1.0.4@sha256:183261400ef822d3dfb7ae9391dc3836d343e01de41ab131df6a42751f87288e'\n\nexport type RealtimeDevOptions = {\n configPath: string\n containerName: string\n port: number\n bindAddress?: string\n origin: string\n secret: string\n detached?: boolean\n connectProxyEndpoint?: string\n}\n\ntype CommandResult = { code: number }\ntype RunCommand = (command: string, args: readonly string[], stdio?: StdioOptions) => Promise<CommandResult>\ntype RealtimeDevDependencies = { run?: RunCommand }\n\nexport async function runRealtimeDev(options: RealtimeDevOptions, dependencies: RealtimeDevDependencies = {}) {\n const configPath = path.resolve(options.configPath)\n try {\n await access(configPath)\n } catch (error) {\n throw new Error(`realtime config is unavailable: ${configPath}`, { cause: error })\n }\n const containerName = dockerName(options.containerName)\n const publicPort = port(options.port, 'port')\n const bindAddress = dockerBindAddress(options.bindAddress ?? '127.0.0.1')\n const origin = httpUrl(options.origin, 'origin')\n const secret = requiredValue(options.secret, 'secret')\n const connectProxyEndpoint = options.connectProxyEndpoint ? httpEndpoint(options.connectProxyEndpoint) : undefined\n const run = dependencies.run ?? runCommand\n // Docker publishes the port to the container's network interface, which a loopback-only listener would not accept.\n const { CENTRIFUGO_HTTP_SERVER_ADDRESS: _loopback, ...centrifugo } = centrifugoEnvironment({\n apiKey: secret,\n clientTokenSecret: secret,\n subscriptionTokenSecret: secret,\n allowedOrigins: origin,\n })\n const environment = {\n ...centrifugo,\n CENTRIFUGO_VAR_PROXY_SECRET: secret,\n ...(connectProxyEndpoint ? { CENTRIFUGO_CLIENT_PROXY_CONNECT_ENDPOINT: connectProxyEndpoint } : {}),\n }\n\n try {\n if (options.detached) await run('docker', ['rm', '--force', containerName], 'ignore')\n const result = await run('docker', [\n 'run',\n '--rm',\n ...(options.detached ? ['-d'] : []),\n '--name',\n containerName,\n '--add-host',\n 'host.docker.internal:host-gateway',\n '-p',\n `${bindAddress}:${publicPort}:8000`,\n ...Object.entries(environment).flatMap(([name, value]) => ['-e', `${name}=${value}`]),\n '-v',\n `${configPath}:/centrifugo/config.json:ro`,\n runtimeImage,\n '/usr/local/bin/centrifugo',\n '--config=/centrifugo/config.json',\n ])\n if (result.code !== 0) throw new Error(`Docker exited with status ${result.code}`)\n } catch (error) {\n if (errorHasCode(error, 'ENOENT')) {\n throw new Error('Docker is required but was not found', { cause: error })\n }\n throw error\n }\n}\n\nexport function parseRealtimeDevArguments(arguments_: readonly string[]): RealtimeDevOptions {\n const { values } = parseArgs({\n args: [...arguments_],\n options: {\n config: { type: 'string' },\n name: { type: 'string' },\n port: { type: 'string' },\n 'bind-address': { type: 'string' },\n origin: { type: 'string' },\n secret: { type: 'string' },\n 'connect-proxy-endpoint': { type: 'string' },\n detach: { type: 'boolean' },\n },\n strict: true,\n })\n return {\n configPath: requiredValue(values.config, '--config'),\n containerName: requiredValue(values.name, '--name'),\n port: Number(requiredValue(values.port, '--port')),\n ...(values['bind-address'] ? { bindAddress: values['bind-address'] } : {}),\n origin: requiredValue(values.origin, '--origin'),\n secret: requiredValue(values.secret, '--secret'),\n ...(values.detach ? { detached: true } : {}),\n ...(values['connect-proxy-endpoint'] ? { connectProxyEndpoint: values['connect-proxy-endpoint'] } : {}),\n }\n}\n\nasync function runCommand(command: string, args: readonly string[], stdio: StdioOptions = 'inherit') {\n const [code] = (await once(spawn(command, [...args], { stdio }), 'exit')) as [number | null]\n return { code: code ?? 1 }\n}\n\nfunction dockerName(value: string) {\n const normalized = requiredValue(value, 'containerName')\n if (!/^[A-Za-z0-9][A-Za-z0-9_.-]*$/.test(normalized)) throw new Error('containerName is invalid')\n return normalized\n}\n\nfunction dockerBindAddress(value: string) {\n if (value !== '127.0.0.1' && value !== '0.0.0.0') throw new Error('bindAddress must be 127.0.0.1 or 0.0.0.0')\n return value\n}\n\nfunction httpUrl(value: string, name: string) {\n let parsed: URL\n try {\n parsed = new URL(value)\n } catch {\n throw new Error(`${name} must be an HTTP URL`)\n }\n if (\n !['http:', 'https:'].includes(parsed.protocol) ||\n parsed.username ||\n parsed.password ||\n parsed.pathname !== '/' ||\n parsed.search ||\n parsed.hash\n ) {\n throw new Error(`${name} must be an HTTP origin`)\n }\n return parsed.origin\n}\n\nfunction httpEndpoint(value: string) {\n let parsed: URL\n try {\n parsed = new URL(value)\n } catch {\n throw new Error('connectProxyEndpoint must be an HTTP URL')\n }\n if (!['http:', 'https:'].includes(parsed.protocol) || parsed.username || parsed.password || parsed.search || parsed.hash) {\n throw new Error('connectProxyEndpoint must be an HTTP URL without credentials, query, or fragment')\n }\n return parsed.toString()\n}\n"]}
|
package/dist/runtime/index.d.ts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA","sourcesContent":["export { caddyRealtimeProxy, persistedRealtimeSecret, runRealtimeStack } from './stack.js'\nexport type {\n CaddyRealtimeProxyOptions,\n CaddyRuntimeEnvironmentOptions,\n CentrifugoEnvironmentOptions,\n PersistedRealtimeSecretOptions,\n RealtimeStackOptions,\n RuntimeProcess,\n SupervisorOptions,\n} from './stack.js'\n"]}
|