ras-stack 3.2.0 β†’ 4.1.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.
Files changed (89) hide show
  1. package/README.md +11 -10
  2. package/dist/auth/index.d.ts +1 -1
  3. package/dist/auth/index.js +1 -1
  4. package/dist/auth/index.js.map +1 -1
  5. package/dist/conformance/index.d.ts +0 -57
  6. package/dist/conformance/index.js +1 -257
  7. package/dist/conformance/index.js.map +1 -1
  8. package/dist/database/postgres.d.ts +0 -5
  9. package/dist/database/postgres.js +0 -34
  10. package/dist/database/postgres.js.map +1 -1
  11. package/dist/database/sqlite.d.ts +0 -3
  12. package/dist/database/sqlite.js +1 -22
  13. package/dist/database/sqlite.js.map +1 -1
  14. package/dist/email/index.d.ts +0 -11
  15. package/dist/email/index.js +6 -9
  16. package/dist/email/index.js.map +1 -1
  17. package/dist/posthog/client.d.ts +0 -6
  18. package/dist/posthog/client.js +1 -11
  19. package/dist/posthog/client.js.map +1 -1
  20. package/dist/posthog/config.d.ts +1 -0
  21. package/dist/posthog/config.js +2 -0
  22. package/dist/posthog/config.js.map +1 -1
  23. package/dist/posthog/index.d.ts +2 -2
  24. package/dist/posthog/index.js +2 -2
  25. package/dist/posthog/index.js.map +1 -1
  26. package/dist/posthog/proxy.d.ts +0 -1
  27. package/dist/posthog/proxy.js +1 -3
  28. package/dist/posthog/proxy.js.map +1 -1
  29. package/dist/posthog/react.d.ts +1 -2
  30. package/dist/posthog/react.js +1 -2
  31. package/dist/posthog/react.js.map +1 -1
  32. package/dist/posthog/request.d.ts +0 -3
  33. package/dist/posthog/request.js +3 -3
  34. package/dist/posthog/request.js.map +1 -1
  35. package/dist/posthog/server.d.ts +1 -3
  36. package/dist/posthog/server.js +2 -2
  37. package/dist/posthog/server.js.map +1 -1
  38. package/dist/preview/cloudflare.js +1 -1
  39. package/dist/preview/cloudflare.js.map +1 -1
  40. package/dist/preview/dokploy-cli.js +1 -1
  41. package/dist/preview/dokploy-cli.js.map +1 -1
  42. package/dist/preview/dokploy-preview.d.ts +102 -0
  43. package/dist/preview/dokploy-preview.js +377 -0
  44. package/dist/preview/dokploy-preview.js.map +1 -0
  45. package/dist/preview/dokploy.d.ts +2 -102
  46. package/dist/preview/dokploy.js +1 -376
  47. package/dist/preview/dokploy.js.map +1 -1
  48. package/dist/preview/github.js +1 -1
  49. package/dist/preview/github.js.map +1 -1
  50. package/dist/realtime/client.d.ts +1 -11
  51. package/dist/realtime/client.js +2 -98
  52. package/dist/realtime/client.js.map +1 -1
  53. package/dist/realtime/index.d.ts +0 -2
  54. package/dist/realtime/index.js +0 -1
  55. package/dist/realtime/index.js.map +1 -1
  56. package/dist/realtime/react.d.ts +1 -4
  57. package/dist/realtime/react.js +22 -26
  58. package/dist/realtime/react.js.map +1 -1
  59. package/dist/runtime/index.d.ts +2 -64
  60. package/dist/runtime/index.js +1 -255
  61. package/dist/runtime/index.js.map +1 -1
  62. package/dist/runtime/stack.d.ts +64 -0
  63. package/dist/runtime/stack.js +252 -0
  64. package/dist/runtime/stack.js.map +1 -0
  65. package/dist/server/errors.d.ts +0 -22
  66. package/dist/server/errors.js +0 -44
  67. package/dist/server/errors.js.map +1 -1
  68. package/dist/server/health.d.ts +7 -4
  69. package/dist/server/health.js +3 -7
  70. package/dist/server/health.js.map +1 -1
  71. package/dist/server/index.d.ts +2 -10
  72. package/dist/server/index.js +1 -5
  73. package/dist/server/index.js.map +1 -1
  74. package/dist/spacetime/index.d.ts +32 -0
  75. package/dist/spacetime/index.js +93 -0
  76. package/dist/spacetime/index.js.map +1 -0
  77. package/dist/tanstack/middleware.d.ts +0 -1
  78. package/dist/tanstack/middleware.js +2 -5
  79. package/dist/tanstack/middleware.js.map +1 -1
  80. package/dist/tanstack/server.d.ts +2 -11
  81. package/dist/tanstack/server.js +2 -6
  82. package/dist/tanstack/server.js.map +1 -1
  83. package/dist/uploads/index.d.ts +0 -6
  84. package/dist/uploads/index.js +0 -25
  85. package/dist/uploads/index.js.map +1 -1
  86. package/package.json +6 -18
  87. package/dist/server/rate-limit.d.ts +0 -30
  88. package/dist/server/rate-limit.js +0 -73
  89. package/dist/server/rate-limit.js.map +0 -1
@@ -1,377 +1,2 @@
1
- import { appendFileSync } from 'node:fs';
2
- import { BlockList, isIP } from 'node:net';
3
- export function dokployPreviewFromEnvironment(environment = process.env) {
4
- const githubOutput = optionalEnvironment(environment, 'GITHUB_OUTPUT');
5
- const username = optionalEnvironment(environment, 'PREVIEW_REGISTRY_USERNAME');
6
- const password = optionalEnvironment(environment, 'PREVIEW_REGISTRY_PASSWORD');
7
- if (Boolean(username) !== Boolean(password))
8
- throw new Error('preview registry username and password must be configured together');
9
- const port = Number(requiredEnvironment(environment, 'PREVIEW_PORT'));
10
- if (!Number.isInteger(port) || port < 1 || port > 65_535)
11
- throw new Error('PREVIEW_PORT must be a valid port');
12
- const applicationPrefix = requiredEnvironment(environment, 'PREVIEW_APPLICATION_PREFIX');
13
- if (!/^[a-z\d](?:[a-z\d-]*[a-z\d])?$/.test(applicationPrefix))
14
- throw new Error('PREVIEW_APPLICATION_PREFIX must be a slug');
15
- const domain = optionalEnvironment(environment, 'PREVIEW_DOMAIN');
16
- const subdomainPrefix = optionalEnvironment(environment, 'PREVIEW_SUBDOMAIN_PREFIX') ?? 'pr';
17
- if (!/^[a-z\d](?:[a-z\d-]*[a-z\d])?$/.test(subdomainPrefix))
18
- throw new Error('PREVIEW_SUBDOMAIN_PREFIX must be a slug');
19
- if (domain)
20
- previewHostname(`${subdomainPrefix}-1.${domain}`);
21
- const config = {
22
- url: requiredEnvironment(environment, 'DOKPLOY_URL'),
23
- apiKey: requiredEnvironment(environment, 'DOKPLOY_API_KEY'),
24
- environmentId: requiredEnvironment(environment, 'DOKPLOY_ENVIRONMENT_ID'),
25
- applicationPrefix,
26
- domain,
27
- subdomainPrefix,
28
- port,
29
- healthPath: optionalEnvironment(environment, 'PREVIEW_HEALTH_PATH'),
30
- ...(username && password ? { registry: { username, password } } : {}),
31
- };
32
- const client = new DokployClient(config);
33
- return {
34
- config,
35
- manager: new DokployPreviewManager({
36
- client,
37
- applicationName: (prNumber) => `${applicationPrefix}-pr-${prNumber}`,
38
- ...(domain ? { hostname: (prNumber) => `${subdomainPrefix}-${prNumber}.${domain}` } : {}),
39
- port,
40
- ...(config.healthPath ? { healthPath: config.healthPath } : {}),
41
- ...(githubOutput ? { onResolved: ({ url }) => appendFileSync(githubOutput, `preview-url=${url}\n`) } : {}),
42
- }),
43
- };
44
- }
45
- export class DokployClient {
46
- options;
47
- request;
48
- log;
49
- constructor(options) {
50
- this.options = options;
51
- this.request = options.fetch ?? fetch;
52
- this.log = options.log ?? console.log;
53
- }
54
- get environmentId() {
55
- return this.options.environmentId;
56
- }
57
- async api(procedure, options = {}) {
58
- const url = new URL(`${this.options.url.replace(/\/$/, '')}/api/${procedure}`);
59
- for (const [key, value] of Object.entries(options.query ?? {}))
60
- url.searchParams.set(key, value);
61
- this.log(`β†’ ${procedure}`);
62
- const response = await this.request(url, {
63
- method: options.body === undefined ? 'GET' : 'POST',
64
- headers: {
65
- 'x-api-key': this.options.apiKey,
66
- ...(options.body === undefined ? {} : { 'content-type': 'application/json' }),
67
- },
68
- ...(options.signal ? { signal: options.signal } : {}),
69
- ...(options.body === undefined ? {} : { body: JSON.stringify(options.body) }),
70
- });
71
- const text = await response.text();
72
- if (!response.ok)
73
- throw new Error(`${procedure} failed with ${response.status}: ${text.slice(0, 500)}`);
74
- if (!text)
75
- return undefined;
76
- try {
77
- return JSON.parse(text);
78
- }
79
- catch {
80
- throw new Error(`${procedure} returned ${response.status} with a non-JSON body: ${text.slice(0, 200)}`);
81
- }
82
- }
83
- async applications() {
84
- const environment = await this.api('environment.one', {
85
- query: { environmentId: this.options.environmentId },
86
- });
87
- if (!environment)
88
- throw new Error('environment.one returned an empty response');
89
- return environment.applications ?? [];
90
- }
91
- async application(name) {
92
- return (await this.applications()).find((application) => application.name === name);
93
- }
94
- async generatedDomain(appName, serverId, existing = []) {
95
- const publicIp = await this.publicIp(serverId);
96
- const current = existing.find((host) => isCurrentGeneratedPreviewHostname(host, appName, publicIp));
97
- if (current)
98
- return current;
99
- const generated = await this.api('domain.generateDomain', {
100
- body: { appName, ...(serverId ? { serverId } : {}) },
101
- });
102
- if (typeof generated !== 'string')
103
- throw new Error('domain.generateDomain returned an invalid hostname');
104
- return generatedPreviewHostname(generated, publicIp, appName);
105
- }
106
- async publicIp(serverId) {
107
- const serverIp = serverId
108
- ? await this.api('domain.canGenerateTraefikMeDomains', { query: { serverId } })
109
- : await this.api('settings.getIp');
110
- return previewServerIp(serverIp);
111
- }
112
- }
113
- export class DokployPreviewManager {
114
- options;
115
- request;
116
- pause;
117
- log;
118
- now;
119
- constructor(options) {
120
- this.options = options;
121
- this.request = options.fetch ?? fetch;
122
- this.pause = options.sleep ?? ((milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)));
123
- this.log = options.log ?? console.log;
124
- this.now = options.now ?? Date.now;
125
- }
126
- async deploy(options) {
127
- const prNumber = pullRequestNumber(options.prNumber);
128
- const name = this.options.applicationName(prNumber);
129
- let application = await this.options.client.application(name);
130
- if (!application) {
131
- await this.options.client.api('application.create', {
132
- body: { name, appName: name, environmentId: this.options.client.environmentId },
133
- });
134
- application = await this.options.client.application(name);
135
- if (!application)
136
- throw new Error(`Dokploy did not report ${name} after creating it`);
137
- }
138
- const applicationId = application.applicationId;
139
- const details = await this.options.client.api('application.one', { query: { applicationId } });
140
- const generated = !this.options.hostname;
141
- const managedDomains = details?.domains?.filter((domain) => isGeneratedPreviewHostname(domain.host, generatedPreviewName)) ?? [];
142
- const host = previewHostname(this.options.hostname
143
- ? this.options.hostname(prNumber)
144
- : await this.options.client.generatedDomain(generatedPreviewName, details?.serverId ?? application.serverId ?? undefined, managedDomains.map((domain) => domain.host)));
145
- const url = `${generated ? 'http' : 'https'}://${host}`;
146
- if (!details?.domains?.some((domain) => domain.host === host)) {
147
- await this.options.client.api('domain.create', {
148
- body: {
149
- applicationId,
150
- host,
151
- path: '/',
152
- port: this.options.port,
153
- https: !generated,
154
- certificateType: generated ? 'none' : 'letsencrypt',
155
- domainType: 'application',
156
- },
157
- });
158
- }
159
- await this.options.onResolved?.({ host, url });
160
- const serverId = details?.serverId || application.serverId || undefined;
161
- await options.configure?.({
162
- applicationId,
163
- client: this.options.client,
164
- host,
165
- url,
166
- ...(serverId ? { serverId } : {}),
167
- });
168
- await this.options.client.api('application.saveDockerProvider', {
169
- body: {
170
- applicationId,
171
- dockerImage: options.image,
172
- username: options.registry?.username ?? null,
173
- password: options.registry?.password ?? null,
174
- registryUrl: options.registry ? options.image.split('/')[0] : null,
175
- },
176
- });
177
- await this.options.client.api('application.saveEnvironment', {
178
- body: {
179
- applicationId,
180
- env: typeof options.environment === 'function' ? options.environment({ host, url }) : options.environment,
181
- buildArgs: null,
182
- buildSecrets: null,
183
- createEnvFile: false,
184
- },
185
- });
186
- await this.options.client.api('application.deploy', { body: { applicationId } });
187
- await this.waitForDeployment(applicationId);
188
- await this.waitForHealth(new URL(this.options.healthPath ?? '/api/health', url).toString());
189
- for (const domain of managedDomains.filter((candidate) => candidate.host !== host)) {
190
- if (!domain.domainId)
191
- throw new Error(`Dokploy did not report an ID for generated domain ${domain.host}`);
192
- // oxlint-disable-next-line no-await-in-loop
193
- await this.options.client.api('domain.delete', { body: { domainId: domain.domainId } });
194
- }
195
- this.log(`Preview ready at ${url}`);
196
- return { applicationId, host, url };
197
- }
198
- async delete(prNumber, beforeDelete) {
199
- const name = this.options.applicationName(pullRequestNumber(prNumber));
200
- const application = await this.options.client.application(name);
201
- await beforeDelete?.(application);
202
- if (!application)
203
- return false;
204
- await this.options.client.api('application.delete', { body: { applicationId: application.applicationId } });
205
- return true;
206
- }
207
- async prune(openPullRequests, beforeDelete) {
208
- const deleted = [];
209
- for (const application of await this.options.client.applications()) {
210
- const prNumber = previewApplicationPrNumber(application.name, this.options.applicationName);
211
- if (!prNumber || openPullRequests.has(prNumber))
212
- continue;
213
- // Dokploy mutations are intentionally ordered to avoid overwhelming one environment.
214
- // oxlint-disable-next-line no-await-in-loop
215
- await beforeDelete?.(prNumber, application);
216
- // oxlint-disable-next-line no-await-in-loop
217
- await this.options.client.api('application.delete', { body: { applicationId: application.applicationId } });
218
- deleted.push(prNumber);
219
- }
220
- return deleted;
221
- }
222
- async waitForDeployment(applicationId) {
223
- const deadline = this.now() + (this.options.deploymentTimeoutMs ?? 600_000);
224
- while (this.now() < deadline) {
225
- // Polling is intentionally sequential; each response determines whether another request is needed.
226
- // oxlint-disable-next-line no-await-in-loop
227
- await this.pause(this.options.pollIntervalMs ?? 5_000);
228
- let applicationStatus;
229
- try {
230
- // Polling is intentionally sequential; each response determines whether another request is needed.
231
- // oxlint-disable-next-line no-await-in-loop
232
- const details = await this.options.client.api('application.one', {
233
- query: { applicationId },
234
- signal: AbortSignal.timeout(Math.max(1, deadline - this.now())),
235
- });
236
- applicationStatus = details.applicationStatus;
237
- }
238
- catch (error) {
239
- if (error instanceof DOMException && error.name === 'TimeoutError')
240
- break;
241
- throw error;
242
- }
243
- if (applicationStatus === 'done')
244
- return;
245
- if (applicationStatus === 'error')
246
- throw new Error('Dokploy reported a failed deployment');
247
- }
248
- throw new Error('Timed out waiting for the Dokploy deployment to finish');
249
- }
250
- async waitForHealth(url) {
251
- const deadline = this.now() + (this.options.healthTimeoutMs ?? 300_000);
252
- let lastFailure = 'no response';
253
- while (this.now() < deadline) {
254
- try {
255
- // Polling is intentionally sequential; each response determines whether another request is needed.
256
- // oxlint-disable-next-line no-await-in-loop
257
- const response = await this.request(url, { signal: AbortSignal.timeout(Math.max(1, deadline - this.now())) });
258
- if (response.status === 200)
259
- return;
260
- lastFailure = `status ${response.status}`;
261
- }
262
- catch (error) {
263
- lastFailure = error instanceof Error ? error.message : String(error);
264
- }
265
- // oxlint-disable-next-line no-await-in-loop
266
- await this.pause(this.options.pollIntervalMs ?? 5_000);
267
- }
268
- throw new Error(`Timed out waiting for ${url} (${lastFailure})`);
269
- }
270
- }
271
- export function pullRequestNumber(value) {
272
- if (!/^\d+$/.test(value))
273
- throw new Error('pull request number must contain only digits');
274
- return value;
275
- }
276
- export function previewHostname(value) {
277
- const parsed = new URL(`https://${value}`);
278
- if (parsed.hostname !== value || parsed.port || parsed.username || parsed.password || parsed.pathname !== '/') {
279
- throw new Error('preview hostname must be a bare hostname');
280
- }
281
- return value;
282
- }
283
- function generatedPreviewHostname(value, serverIp, appName) {
284
- const host = previewHostname(value);
285
- if (!isCurrentGeneratedPreviewHostname(host, appName, serverIp))
286
- throw new Error('domain.generateDomain did not return an sslip.io hostname for the Dokploy server');
287
- return host;
288
- }
289
- function isGeneratedPreviewHostname(host, appName) {
290
- return new RegExp(`^${regularExpressionLiteral(appName.slice(0, 40))}-[a-f\\d]{6}-[a-f\\d-]+\\.sslip\\.io$`).test(host);
291
- }
292
- function isCurrentGeneratedPreviewHostname(host, appName, serverIp) {
293
- return new RegExp(`^${regularExpressionLiteral(appName.slice(0, 40))}-[a-f\\d]{6}-${regularExpressionLiteral(encodedIp(serverIp))}\\.sslip\\.io$`).test(host);
294
- }
295
- function regularExpressionLiteral(value) {
296
- return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
297
- }
298
- function encodedIp(address) {
299
- return address.replaceAll('.', '-').replaceAll(':', '-');
300
- }
301
- const generatedPreviewName = 'ras-preview';
302
- const blockedPreviewAddresses = new BlockList();
303
- for (const [address, prefix, family] of [
304
- ['0.0.0.0', 8, 'ipv4'],
305
- ['10.0.0.0', 8, 'ipv4'],
306
- ['100.64.0.0', 10, 'ipv4'],
307
- ['127.0.0.0', 8, 'ipv4'],
308
- ['169.254.0.0', 16, 'ipv4'],
309
- ['172.16.0.0', 12, 'ipv4'],
310
- ['192.0.0.0', 24, 'ipv4'],
311
- ['192.0.2.0', 24, 'ipv4'],
312
- ['192.88.99.0', 24, 'ipv4'],
313
- ['192.168.0.0', 16, 'ipv4'],
314
- ['198.18.0.0', 15, 'ipv4'],
315
- ['198.51.100.0', 24, 'ipv4'],
316
- ['203.0.113.0', 24, 'ipv4'],
317
- ['224.0.0.0', 4, 'ipv4'],
318
- ['240.0.0.0', 4, 'ipv4'],
319
- ['::', 128, 'ipv6'],
320
- ['::1', 128, 'ipv6'],
321
- ['64:ff9b:1::', 48, 'ipv6'],
322
- ['100::', 64, 'ipv6'],
323
- ['100:0:0:1::', 64, 'ipv6'],
324
- ['2001::', 23, 'ipv6'],
325
- ['2001:db8::', 32, 'ipv6'],
326
- ['2002::', 16, 'ipv6'],
327
- ['3fff::', 20, 'ipv6'],
328
- ['5f00::', 16, 'ipv6'],
329
- ['fc00::', 7, 'ipv6'],
330
- ['fe80::', 10, 'ipv6'],
331
- ['ff00::', 8, 'ipv6'],
332
- ]) {
333
- blockedPreviewAddresses.addSubnet(address, prefix, family);
334
- }
335
- function previewServerIp(value) {
336
- if (typeof value !== 'string')
337
- throw new Error('Dokploy requires a public server IP before it can generate preview domains');
338
- const address = value.trim().toLowerCase();
339
- const version = isIP(address);
340
- const family = version === 4 ? 'ipv4' : version === 6 ? 'ipv6' : undefined;
341
- if (!family || address.startsWith('::ffff:') || blockedPreviewAddresses.check(address, family)) {
342
- throw new Error('Dokploy requires a public server IP before it can generate preview domains');
343
- }
344
- return address;
345
- }
346
- function previewApplicationPrNumber(name, applicationName) {
347
- const match = /^(\d+)$/.exec(name.match(/(\d+)$/)?.[1] ?? '');
348
- const prNumber = match?.[1];
349
- return prNumber && applicationName(prNumber) === name ? prNumber : undefined;
350
- }
351
- function requiredEnvironment(environment, name) {
352
- const value = optionalEnvironment(environment, name);
353
- if (!value)
354
- throw new Error(`${name} is required`);
355
- return value;
356
- }
357
- function optionalEnvironment(environment, name) {
358
- return environment[name]?.trim() || undefined;
359
- }
360
- // Deploy scripts receive product secrets as one JSON object; an unknown key is a mistake, not a passthrough.
361
- export function loadPreviewAppSecrets(allowed, source = process.env, target = process.env) {
362
- const serialized = source.PREVIEW_APP_SECRETS?.trim();
363
- if (!serialized)
364
- return;
365
- const parsed = JSON.parse(serialized);
366
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
367
- throw new Error('PREVIEW_APP_SECRETS must be a JSON object');
368
- const names = new Set(allowed);
369
- for (const [name, value] of Object.entries(parsed)) {
370
- if (!names.has(name))
371
- throw new Error(`PREVIEW_APP_SECRETS contains unsupported key ${name}`);
372
- if (typeof value !== 'string')
373
- throw new Error(`PREVIEW_APP_SECRETS.${name} must be a string`);
374
- target[name] = value;
375
- }
376
- }
1
+ export { DokployClient, dokployPreviewFromEnvironment, loadPreviewAppSecrets, pullRequestNumber } from './dokploy-preview.js';
377
2
  //# sourceMappingURL=dokploy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dokploy.js","sourceRoot":"","sources":["../../src/preview/dokploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAI1C,MAAM,UAAU,6BAA6B,CAAC,WAAW,GAAsB,OAAO,CAAC,GAAG;IACxF,MAAM,YAAY,GAAG,mBAAmB,CAAC,WAAW,EAAE,eAAe,CAAC,CAAA;IACtE,MAAM,QAAQ,GAAG,mBAAmB,CAAC,WAAW,EAAE,2BAA2B,CAAC,CAAA;IAC9E,MAAM,QAAQ,GAAG,mBAAmB,CAAC,WAAW,EAAE,2BAA2B,CAAC,CAAA;IAC9E,IAAI,OAAO,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAA;IAClI,MAAM,IAAI,GAAG,MAAM,CAAC,mBAAmB,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,CAAA;IACrE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,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AM,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAA;IAChI,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAA;IAC9B,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,gDAAgD,IAAI,EAAE,CAAC,CAAA;QAC7F,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,mBAAmB,CAAC,CAAA;QAC9F,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;IACtB,CAAC;AACH,CAAC","sourcesContent":["import { appendFileSync } from 'node:fs'\nimport { BlockList, isIP } from 'node:net'\n\nexport type DokployApplication = { applicationId: string; name: string; serverId?: string | null }\n\nexport function dokployPreviewFromEnvironment(environment: NodeJS.ProcessEnv = process.env) {\n const githubOutput = optionalEnvironment(environment, 'GITHUB_OUTPUT')\n const username = optionalEnvironment(environment, 'PREVIEW_REGISTRY_USERNAME')\n const password = optionalEnvironment(environment, 'PREVIEW_REGISTRY_PASSWORD')\n if (Boolean(username) !== Boolean(password)) throw new Error('preview registry username and password must be configured together')\n const port = Number(requiredEnvironment(environment, 'PREVIEW_PORT'))\n if (!Number.isInteger(port) || port < 1 || port > 65_535) throw new Error('PREVIEW_PORT must be a valid port')\n const applicationPrefix = requiredEnvironment(environment, 'PREVIEW_APPLICATION_PREFIX')\n if (!/^[a-z\\d](?:[a-z\\d-]*[a-z\\d])?$/.test(applicationPrefix)) throw new Error('PREVIEW_APPLICATION_PREFIX must be a slug')\n const domain = optionalEnvironment(environment, 'PREVIEW_DOMAIN')\n const subdomainPrefix = optionalEnvironment(environment, 'PREVIEW_SUBDOMAIN_PREFIX') ?? 'pr'\n if (!/^[a-z\\d](?:[a-z\\d-]*[a-z\\d])?$/.test(subdomainPrefix)) throw new Error('PREVIEW_SUBDOMAIN_PREFIX must be a slug')\n if (domain) previewHostname(`${subdomainPrefix}-1.${domain}`)\n const config = {\n url: requiredEnvironment(environment, 'DOKPLOY_URL'),\n apiKey: requiredEnvironment(environment, 'DOKPLOY_API_KEY'),\n environmentId: requiredEnvironment(environment, 'DOKPLOY_ENVIRONMENT_ID'),\n applicationPrefix,\n domain,\n subdomainPrefix,\n port,\n healthPath: optionalEnvironment(environment, 'PREVIEW_HEALTH_PATH'),\n ...(username && password ? { registry: { username, password } } : {}),\n }\n const client = new DokployClient(config)\n return {\n config,\n manager: new DokployPreviewManager({\n client,\n applicationName: (prNumber) => `${applicationPrefix}-pr-${prNumber}`,\n ...(domain ? { hostname: (prNumber: string) => `${subdomainPrefix}-${prNumber}.${domain}` } : {}),\n port,\n ...(config.healthPath ? { healthPath: config.healthPath } : {}),\n ...(githubOutput ? { onResolved: ({ url }: { url: string }) => appendFileSync(githubOutput, `preview-url=${url}\\n`) } : {}),\n }),\n }\n}\n\nexport type DokployClientOptions = {\n url: string\n apiKey: string\n environmentId: string\n fetch?: typeof fetch\n log?: (message: string) => void\n}\n\nexport class DokployClient {\n private readonly request: typeof fetch\n private readonly log: (message: string) => void\n\n constructor(private readonly options: DokployClientOptions) {\n this.request = options.fetch ?? fetch\n this.log = options.log ?? console.log\n }\n\n get environmentId() {\n return this.options.environmentId\n }\n\n async api<T = unknown>(\n procedure: string,\n options: { query?: Record<string, string>; body?: unknown; signal?: AbortSignal } = {},\n ): Promise<T> {\n const url = new URL(`${this.options.url.replace(/\\/$/, '')}/api/${procedure}`)\n for (const [key, value] of Object.entries(options.query ?? {})) url.searchParams.set(key, value)\n this.log(`β†’ ${procedure}`)\n const response = await this.request(url, {\n method: options.body === undefined ? 'GET' : 'POST',\n headers: {\n 'x-api-key': this.options.apiKey,\n ...(options.body === undefined ? {} : { 'content-type': 'application/json' }),\n },\n ...(options.signal ? { signal: options.signal } : {}),\n ...(options.body === undefined ? {} : { body: JSON.stringify(options.body) }),\n })\n const text = await response.text()\n if (!response.ok) throw new Error(`${procedure} failed with ${response.status}: ${text.slice(0, 500)}`)\n if (!text) return undefined as T\n try {\n return JSON.parse(text) as T\n } catch {\n throw new Error(`${procedure} returned ${response.status} with a non-JSON body: ${text.slice(0, 200)}`)\n }\n }\n\n async applications() {\n const environment = await this.api<{ applications?: DokployApplication[] } | undefined>('environment.one', {\n query: { environmentId: this.options.environmentId },\n })\n if (!environment) throw new Error('environment.one returned an empty response')\n return environment.applications ?? []\n }\n\n async application(name: string) {\n return (await this.applications()).find((application) => application.name === name)\n }\n\n async generatedDomain(appName: string, serverId?: string, existing: string[] = []) {\n const publicIp = await this.publicIp(serverId)\n const current = existing.find((host) => isCurrentGeneratedPreviewHostname(host, appName, publicIp))\n if (current) return current\n const generated = await this.api('domain.generateDomain', {\n body: { appName, ...(serverId ? { serverId } : {}) },\n })\n if (typeof generated !== 'string') throw new Error('domain.generateDomain returned an invalid hostname')\n return generatedPreviewHostname(generated, publicIp, appName)\n }\n\n async publicIp(serverId?: string) {\n const serverIp = serverId\n ? await this.api('domain.canGenerateTraefikMeDomains', { query: { serverId } })\n : await this.api('settings.getIp')\n return previewServerIp(serverIp)\n }\n}\n\nexport type DokployPreviewOptions = {\n client: DokployClient\n applicationName: (prNumber: string) => string\n hostname?: (prNumber: string) => string\n port: number\n healthPath?: string\n deploymentTimeoutMs?: number\n healthTimeoutMs?: number\n pollIntervalMs?: number\n fetch?: typeof fetch\n sleep?: (milliseconds: number) => Promise<void>\n now?: () => number\n log?: (message: string) => void\n onResolved?: (context: { host: string; url: string }) => void | Promise<void>\n}\n\nexport type DeployPreviewOptions = {\n prNumber: string\n image: string\n environment: string | ((context: { host: string; url: string }) => string)\n registry?: { username: string; password: string }\n configure?: (context: {\n applicationId: string\n client: DokployClient\n host: string\n url: string\n serverId?: string\n }) => void | Promise<void>\n}\n\nexport class DokployPreviewManager {\n private readonly request: typeof fetch\n private readonly pause: (milliseconds: number) => Promise<void>\n private readonly log: (message: string) => void\n private readonly now: () => number\n\n constructor(private readonly options: DokployPreviewOptions) {\n this.request = options.fetch ?? fetch\n this.pause = options.sleep ?? ((milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)))\n this.log = options.log ?? console.log\n this.now = options.now ?? Date.now\n }\n\n async deploy(options: DeployPreviewOptions) {\n const prNumber = pullRequestNumber(options.prNumber)\n const name = this.options.applicationName(prNumber)\n let application = await this.options.client.application(name)\n if (!application) {\n await this.options.client.api('application.create', {\n body: { name, appName: name, environmentId: this.options.client.environmentId },\n })\n application = await this.options.client.application(name)\n if (!application) throw new Error(`Dokploy did not report ${name} after creating it`)\n }\n const applicationId = application.applicationId\n const details = await this.options.client.api<\n { domains?: { domainId?: string; host: string }[]; serverId?: string | null } | undefined\n >('application.one', { query: { applicationId } })\n const generated = !this.options.hostname\n const managedDomains = details?.domains?.filter((domain) => isGeneratedPreviewHostname(domain.host, generatedPreviewName)) ?? []\n const host = previewHostname(\n this.options.hostname\n ? this.options.hostname(prNumber)\n : await this.options.client.generatedDomain(\n generatedPreviewName,\n details?.serverId ?? application.serverId ?? undefined,\n managedDomains.map((domain) => domain.host),\n ),\n )\n const url = `${generated ? 'http' : 'https'}://${host}`\n if (!details?.domains?.some((domain) => domain.host === host)) {\n await this.options.client.api('domain.create', {\n body: {\n applicationId,\n host,\n path: '/',\n port: this.options.port,\n https: !generated,\n certificateType: generated ? 'none' : 'letsencrypt',\n domainType: 'application',\n },\n })\n }\n await this.options.onResolved?.({ host, url })\n const serverId = details?.serverId || application.serverId || undefined\n await options.configure?.({\n applicationId,\n client: this.options.client,\n host,\n url,\n ...(serverId ? { serverId } : {}),\n })\n await this.options.client.api('application.saveDockerProvider', {\n body: {\n applicationId,\n dockerImage: options.image,\n username: options.registry?.username ?? null,\n password: options.registry?.password ?? null,\n registryUrl: options.registry ? options.image.split('/')[0] : null,\n },\n })\n await this.options.client.api('application.saveEnvironment', {\n body: {\n applicationId,\n env: typeof options.environment === 'function' ? options.environment({ host, url }) : options.environment,\n buildArgs: null,\n buildSecrets: null,\n createEnvFile: false,\n },\n })\n await this.options.client.api('application.deploy', { body: { applicationId } })\n await this.waitForDeployment(applicationId)\n await this.waitForHealth(new URL(this.options.healthPath ?? '/api/health', url).toString())\n for (const domain of managedDomains.filter((candidate) => candidate.host !== host)) {\n if (!domain.domainId) throw new Error(`Dokploy did not report an ID for generated domain ${domain.host}`)\n // oxlint-disable-next-line no-await-in-loop\n await this.options.client.api('domain.delete', { body: { domainId: domain.domainId } })\n }\n this.log(`Preview ready at ${url}`)\n return { applicationId, host, url }\n }\n\n async delete(prNumber: string, beforeDelete?: (application: DokployApplication | undefined) => void | Promise<void>) {\n const name = this.options.applicationName(pullRequestNumber(prNumber))\n const application = await this.options.client.application(name)\n await beforeDelete?.(application)\n if (!application) return false\n await this.options.client.api('application.delete', { body: { applicationId: application.applicationId } })\n return true\n }\n\n async prune(\n openPullRequests: ReadonlySet<string>,\n beforeDelete?: (prNumber: string, application: DokployApplication) => void | Promise<void>,\n ) {\n const deleted: string[] = []\n for (const application of await this.options.client.applications()) {\n const prNumber = previewApplicationPrNumber(application.name, this.options.applicationName)\n if (!prNumber || openPullRequests.has(prNumber)) continue\n // Dokploy mutations are intentionally ordered to avoid overwhelming one environment.\n // oxlint-disable-next-line no-await-in-loop\n await beforeDelete?.(prNumber, application)\n // oxlint-disable-next-line no-await-in-loop\n await this.options.client.api('application.delete', { body: { applicationId: application.applicationId } })\n deleted.push(prNumber)\n }\n return deleted\n }\n\n private async waitForDeployment(applicationId: string) {\n const deadline = this.now() + (this.options.deploymentTimeoutMs ?? 600_000)\n while (this.now() < deadline) {\n // Polling is intentionally sequential; each response determines whether another request is needed.\n // oxlint-disable-next-line no-await-in-loop\n await this.pause(this.options.pollIntervalMs ?? 5_000)\n let applicationStatus: string\n try {\n // Polling is intentionally sequential; each response determines whether another request is needed.\n // oxlint-disable-next-line no-await-in-loop\n const details = await this.options.client.api<{ applicationStatus: string }>('application.one', {\n query: { applicationId },\n signal: AbortSignal.timeout(Math.max(1, deadline - this.now())),\n })\n applicationStatus = details.applicationStatus\n } catch (error) {\n if (error instanceof DOMException && error.name === 'TimeoutError') break\n throw error\n }\n if (applicationStatus === 'done') return\n if (applicationStatus === 'error') throw new Error('Dokploy reported a failed deployment')\n }\n throw new Error('Timed out waiting for the Dokploy deployment to finish')\n }\n\n private async waitForHealth(url: string) {\n const deadline = this.now() + (this.options.healthTimeoutMs ?? 300_000)\n let lastFailure = 'no response'\n while (this.now() < deadline) {\n try {\n // Polling is intentionally sequential; each response determines whether another request is needed.\n // oxlint-disable-next-line no-await-in-loop\n const response = await this.request(url, { signal: AbortSignal.timeout(Math.max(1, deadline - this.now())) })\n if (response.status === 200) return\n lastFailure = `status ${response.status}`\n } catch (error) {\n lastFailure = error instanceof Error ? error.message : String(error)\n }\n // oxlint-disable-next-line no-await-in-loop\n await this.pause(this.options.pollIntervalMs ?? 5_000)\n }\n throw new Error(`Timed out waiting for ${url} (${lastFailure})`)\n }\n}\n\nexport function pullRequestNumber(value: string) {\n if (!/^\\d+$/.test(value)) throw new Error('pull request number must contain only digits')\n return value\n}\n\nexport function previewHostname(value: string) {\n const parsed = new URL(`https://${value}`)\n if (parsed.hostname !== value || parsed.port || parsed.username || parsed.password || parsed.pathname !== '/') {\n throw new Error('preview hostname must be a bare hostname')\n }\n return value\n}\n\nfunction generatedPreviewHostname(value: string, serverIp: string, appName: string) {\n const host = previewHostname(value)\n if (!isCurrentGeneratedPreviewHostname(host, appName, serverIp))\n throw new Error('domain.generateDomain did not return an sslip.io hostname for the Dokploy server')\n return host\n}\n\nfunction isGeneratedPreviewHostname(host: string, appName: string) {\n return new RegExp(`^${regularExpressionLiteral(appName.slice(0, 40))}-[a-f\\\\d]{6}-[a-f\\\\d-]+\\\\.sslip\\\\.io$`).test(host)\n}\n\nfunction isCurrentGeneratedPreviewHostname(host: string, appName: string, serverIp: string) {\n return new RegExp(\n `^${regularExpressionLiteral(appName.slice(0, 40))}-[a-f\\\\d]{6}-${regularExpressionLiteral(encodedIp(serverIp))}\\\\.sslip\\\\.io$`,\n ).test(host)\n}\n\nfunction regularExpressionLiteral(value: string) {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\nfunction encodedIp(address: string) {\n return address.replaceAll('.', '-').replaceAll(':', '-')\n}\n\nconst generatedPreviewName = 'ras-preview'\n\nconst blockedPreviewAddresses = new BlockList()\nfor (const [address, prefix, family] of [\n ['0.0.0.0', 8, 'ipv4'],\n ['10.0.0.0', 8, 'ipv4'],\n ['100.64.0.0', 10, 'ipv4'],\n ['127.0.0.0', 8, 'ipv4'],\n ['169.254.0.0', 16, 'ipv4'],\n ['172.16.0.0', 12, 'ipv4'],\n ['192.0.0.0', 24, 'ipv4'],\n ['192.0.2.0', 24, 'ipv4'],\n ['192.88.99.0', 24, 'ipv4'],\n ['192.168.0.0', 16, 'ipv4'],\n ['198.18.0.0', 15, 'ipv4'],\n ['198.51.100.0', 24, 'ipv4'],\n ['203.0.113.0', 24, 'ipv4'],\n ['224.0.0.0', 4, 'ipv4'],\n ['240.0.0.0', 4, 'ipv4'],\n ['::', 128, 'ipv6'],\n ['::1', 128, 'ipv6'],\n ['64:ff9b:1::', 48, 'ipv6'],\n ['100::', 64, 'ipv6'],\n ['100:0:0:1::', 64, 'ipv6'],\n ['2001::', 23, 'ipv6'],\n ['2001:db8::', 32, 'ipv6'],\n ['2002::', 16, 'ipv6'],\n ['3fff::', 20, 'ipv6'],\n ['5f00::', 16, 'ipv6'],\n ['fc00::', 7, 'ipv6'],\n ['fe80::', 10, 'ipv6'],\n ['ff00::', 8, 'ipv6'],\n] as const) {\n blockedPreviewAddresses.addSubnet(address, prefix, family)\n}\n\nfunction previewServerIp(value: unknown) {\n if (typeof value !== 'string') throw new Error('Dokploy requires a public server IP before it can generate preview domains')\n const address = value.trim().toLowerCase()\n const version = isIP(address)\n const family = version === 4 ? 'ipv4' : version === 6 ? 'ipv6' : undefined\n if (!family || address.startsWith('::ffff:') || blockedPreviewAddresses.check(address, family)) {\n throw new Error('Dokploy requires a public server IP before it can generate preview domains')\n }\n return address\n}\n\nfunction previewApplicationPrNumber(name: string, applicationName: (prNumber: string) => string) {\n const match = /^(\\d+)$/.exec(name.match(/(\\d+)$/)?.[1] ?? '')\n const prNumber = match?.[1]\n return prNumber && applicationName(prNumber) === name ? prNumber : undefined\n}\n\nfunction requiredEnvironment(environment: NodeJS.ProcessEnv, name: string) {\n const value = optionalEnvironment(environment, name)\n if (!value) throw new Error(`${name} is required`)\n return value\n}\n\nfunction optionalEnvironment(environment: NodeJS.ProcessEnv, name: string) {\n return environment[name]?.trim() || undefined\n}\n\n// Deploy scripts receive product secrets as one JSON object; an unknown key is a mistake, not a passthrough.\nexport function loadPreviewAppSecrets(\n allowed: Iterable<string>,\n source: NodeJS.ProcessEnv = process.env,\n target: NodeJS.ProcessEnv = process.env,\n) {\n const serialized = source.PREVIEW_APP_SECRETS?.trim()\n if (!serialized) return\n const parsed: unknown = JSON.parse(serialized)\n if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) throw new Error('PREVIEW_APP_SECRETS must be a JSON object')\n const names = new Set(allowed)\n for (const [name, value] of Object.entries(parsed)) {\n if (!names.has(name)) throw new Error(`PREVIEW_APP_SECRETS contains unsupported key ${name}`)\n if (typeof value !== 'string') throw new Error(`PREVIEW_APP_SECRETS.${name} must be a string`)\n target[name] = value\n }\n}\n"]}
1
+ {"version":3,"file":"dokploy.js","sourceRoot":"","sources":["../../src/preview/dokploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA","sourcesContent":["export { DokployClient, dokployPreviewFromEnvironment, loadPreviewAppSecrets, pullRequestNumber } from './dokploy-preview.js'\nexport type { DeployPreviewOptions, DokployApplication, DokployClientOptions } from './dokploy-preview.js'\n"]}
@@ -1,4 +1,4 @@
1
- import { pullRequestNumber } from './dokploy.js';
1
+ import { pullRequestNumber } from './dokploy-preview.js';
2
2
  export async function reportPreviewStatus(options, status) {
3
3
  const repository = githubRepository(options.repository);
4
4
  const marker = commentMarker(options.marker);
@@ -1 +1 @@
1
- {"version":3,"file":"github.js","sourceRoot":"","sources":["../../src/preview/github.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AA0BhD,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAA6B,EAAE,MAAqB;IAC5F,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IACvD,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAC5C,IAAI,CAAC,OAAO,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;IAC/D,MAAM,QAAQ,GAAG,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACnD,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAAA;IACtC,MAAM,GAAG,GAAG,CAAI,IAAY,EAAE,IAAkB,EAAE,EAAE,CAAC,MAAM,CAAI,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,UAAU,UAAU,GAAG,IAAI,EAAE,EAAE,IAAI,CAAC,CAAA;IAE3H,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/B,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACjC,IAAI,MAAM,CAAC,KAAK,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU;YAAE,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAA;QACvH,IAAI,MAAM,CAAC,UAAU;YAAE,MAAM,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AE,IAAa;IAC1D,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAA;AAChG,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAa;IACrC,IAAI,CAAC,mCAAmC,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;IACrH,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,aAAa,CAAC,KAAa;IAClC,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;IACxG,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,MAAM,CAAC,KAAa,EAAE,IAAY;IACzC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;IAC1B,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,yBAAyB,CAAC,CAAA;IAC5G,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AAC1C,CAAC;AAED,SAAS,SAAS,CAAC,KAAyB;IAC1C,IAAI,CAAC,KAAK,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAA;IAClH,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import { pullRequestNumber } from './dokploy.js'\n\nexport type PreviewStatusState = 'awaiting' | 'building' | 'ready' | 'failed' | 'deleted'\n\nexport type GitHubPreviewOptions = {\n repository: string\n token: string\n marker: string\n note?: string\n checkName?: string\n fetch?: typeof fetch\n}\n\nexport type PreviewStatus =\n | { state: 'deleted'; prNumber: string }\n | {\n state: Exclude<PreviewStatusState, 'deleted'>\n prNumber: string\n sha: string\n previewUrl?: string\n runUrl?: string\n }\n\ntype Check = { id: number }\ntype Comment = { id: number; body?: string }\n\nexport async function reportPreviewStatus(options: GitHubPreviewOptions, status: PreviewStatus) {\n const repository = githubRepository(options.repository)\n const marker = commentMarker(options.marker)\n if (!options.token) throw new Error('GitHub token is required')\n const prNumber = pullRequestNumber(status.prNumber)\n const request = options.fetch ?? fetch\n const api = <T>(path: string, init?: RequestInit) => github<T>(request, options.token, `/repos/${repository}${path}`, init)\n\n if (status.state !== 'deleted') {\n const sha = commitSha(status.sha)\n if (status.state === 'ready' && !status.previewUrl) throw new Error('preview URL is required for ready preview status')\n if (status.previewUrl) webUrl(status.previewUrl, 'preview URL')\n if (status.runUrl) webUrl(status.runUrl, 'workflow run URL')\n await updateCheck(api, options.checkName ?? 'PR preview deploy', sha, status)\n }\n const comments = await issueComments(api, prNumber)\n const existing = comments.find((comment) => comment.body?.includes(marker))\n const body = previewComment({ ...options, marker }, status, existing?.body)\n if (existing) await api(`/issues/comments/${existing.id}`, jsonRequest('PATCH', { body }))\n else await api(`/issues/${prNumber}/comments`, jsonRequest('POST', { body }))\n}\n\nasync function updateCheck(\n api: <T>(path: string, init?: RequestInit) => Promise<T>,\n name: string,\n sha: string,\n status: Extract<PreviewStatus, { state: Exclude<PreviewStatusState, 'deleted'> }>,\n) {\n const checks = await api<{ check_runs: Check[] }>(`/commits/${sha}/check-runs?check_name=${encodeURIComponent(name)}&filter=latest`)\n const state = checkState(status.state)\n const body = {\n name,\n head_sha: sha,\n status: state.status,\n ...(state.conclusion ? { conclusion: state.conclusion } : {}),\n ...(status.runUrl ? { details_url: webUrl(status.runUrl, 'workflow run URL') } : {}),\n output: { title: name, summary: state.summary },\n }\n const existing = checks.check_runs[0]\n if (existing) await api(`/check-runs/${existing.id}`, jsonRequest('PATCH', body))\n else await api('/check-runs', jsonRequest('POST', body))\n}\n\nasync function issueComments(api: <T>(path: string, init?: RequestInit) => Promise<T>, prNumber: string, page = 1): Promise<Comment[]> {\n if (page > 10) throw new Error('preview comment lookup exceeded 1,000 comments')\n const comments = await api<Comment[]>(`/issues/${prNumber}/comments?per_page=100&page=${page}`)\n return comments.length < 100 ? comments : [...comments, ...(await issueComments(api, prNumber, page + 1))]\n}\n\nfunction previewComment(options: GitHubPreviewOptions, status: PreviewStatus, previous?: string) {\n if (status.state === 'deleted') return `${options.marker}\\nπŸ—‘οΈ Preview deleted because this pull request was closed.`\n const sha = commitSha(status.sha).slice(0, 7)\n const standingSha = previous?.match(/up to date with commit `([0-9a-f]{7})`/)?.[1]\n const standing = standingSha ? ` The preview of \\`${standingSha}\\` stays up until it does.` : ''\n const heading = {\n awaiting: `⏸️ The preview of \\`${sha}\\` is waiting for a maintainer to approve its build.${standing}`,\n building: `πŸ”„ Deploying \\`${sha}\\`.${standing}`,\n ready: `βœ… Preview is up to date with commit \\`${sha}\\`.`,\n failed: `❌ Deploying commit \\`${sha}\\` failed${status.runUrl ? ` ([workflow run](${webUrl(status.runUrl, 'workflow run URL')}))` : ''}. The preview may be stale or unavailable.`,\n }[status.state]\n return [\n options.marker,\n heading,\n ...(status.previewUrl ? ['', `Preview: ${webUrl(status.previewUrl, 'preview URL')}`] : []),\n ...(options.note ? ['', options.note] : []),\n ].join('\\n')\n}\n\nfunction checkState(state: Exclude<PreviewStatusState, 'deleted'>) {\n return {\n awaiting: { status: 'queued', summary: 'The preview build is waiting for workflow approval.' },\n building: { status: 'in_progress', summary: 'A new preview version is deploying.' },\n ready: { status: 'completed', conclusion: 'success', summary: 'The preview is up to date.' },\n failed: { status: 'completed', conclusion: 'failure', summary: 'The preview deployment failed.' },\n }[state]\n}\n\nasync function github<T>(request: typeof fetch, token: string, path: string, init?: RequestInit): Promise<T> {\n const headers = new Headers(init?.headers)\n headers.set('accept', 'application/vnd.github+json')\n headers.set('authorization', `Bearer ${token}`)\n headers.set('x-github-api-version', '2022-11-28')\n const response = await request(`https://api.github.com${path}`, {\n ...init,\n headers,\n })\n const text = await response.text()\n if (!response.ok) throw new Error(`GitHub ${path.split('?')[0]} failed with ${response.status}: ${text.slice(0, 500)}`)\n return text ? (JSON.parse(text) as T) : (undefined as T)\n}\n\nfunction jsonRequest(method: 'POST' | 'PATCH', body: unknown): RequestInit {\n return { method, headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }\n}\n\nfunction githubRepository(value: string) {\n if (!/^[a-z\\d][\\w.-]*\\/[a-z\\d][\\w.-]*$/i.test(value)) throw new Error('repository must use an owner/name identifier')\n return value\n}\n\nfunction commentMarker(value: string) {\n if (!/^<!-- [a-z\\d-]+ -->$/i.test(value)) throw new Error('preview marker must be a named HTML comment')\n return value\n}\n\nfunction webUrl(value: string, name: string) {\n const url = new URL(value)\n if (url.protocol !== 'https:' && url.protocol !== 'http:') throw new Error(`${name} must use HTTP or HTTPS`)\n return url.toString().replace(/\\/$/, '')\n}\n\nfunction commitSha(value: string | undefined) {\n if (!value || !/^[0-9a-f]{40}$/i.test(value)) throw new Error('commit SHA must contain 40 hexadecimal characters')\n return value\n}\n"]}
1
+ {"version":3,"file":"github.js","sourceRoot":"","sources":["../../src/preview/github.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AA0BxD,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAA6B,EAAE,MAAqB;IAC5F,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IACvD,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAC5C,IAAI,CAAC,OAAO,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;IAC/D,MAAM,QAAQ,GAAG,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACnD,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,IA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G,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AAC1C,CAAC;AAED,SAAS,SAAS,CAAC,KAAyB;IAC1C,IAAI,CAAC,KAAK,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAA;IAClH,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import { pullRequestNumber } from './dokploy-preview.js'\n\nexport type PreviewStatusState = 'awaiting' | 'building' | 'ready' | 'failed' | 'deleted'\n\nexport type GitHubPreviewOptions = {\n repository: string\n token: string\n marker: string\n note?: string\n checkName?: string\n fetch?: typeof fetch\n}\n\nexport type PreviewStatus =\n | { state: 'deleted'; prNumber: string }\n | {\n state: Exclude<PreviewStatusState, 'deleted'>\n prNumber: string\n sha: string\n previewUrl?: string\n runUrl?: string\n }\n\ntype Check = { id: number }\ntype Comment = { id: number; body?: string }\n\nexport async function reportPreviewStatus(options: GitHubPreviewOptions, status: PreviewStatus) {\n const repository = githubRepository(options.repository)\n const marker = commentMarker(options.marker)\n if (!options.token) throw new Error('GitHub token is required')\n const prNumber = pullRequestNumber(status.prNumber)\n const request = options.fetch ?? fetch\n const api = <T>(path: string, init?: RequestInit) => github<T>(request, options.token, `/repos/${repository}${path}`, init)\n\n if (status.state !== 'deleted') {\n const sha = commitSha(status.sha)\n if (status.state === 'ready' && !status.previewUrl) throw new Error('preview URL is required for ready preview status')\n if (status.previewUrl) webUrl(status.previewUrl, 'preview URL')\n if (status.runUrl) webUrl(status.runUrl, 'workflow run URL')\n await updateCheck(api, options.checkName ?? 'PR preview deploy', sha, status)\n }\n const comments = await issueComments(api, prNumber)\n const existing = comments.find((comment) => comment.body?.includes(marker))\n const body = previewComment({ ...options, marker }, status, existing?.body)\n if (existing) await api(`/issues/comments/${existing.id}`, jsonRequest('PATCH', { body }))\n else await api(`/issues/${prNumber}/comments`, jsonRequest('POST', { body }))\n}\n\nasync function updateCheck(\n api: <T>(path: string, init?: RequestInit) => Promise<T>,\n name: string,\n sha: string,\n status: Extract<PreviewStatus, { state: Exclude<PreviewStatusState, 'deleted'> }>,\n) {\n const checks = await api<{ check_runs: Check[] }>(`/commits/${sha}/check-runs?check_name=${encodeURIComponent(name)}&filter=latest`)\n const state = checkState(status.state)\n const body = {\n name,\n head_sha: sha,\n status: state.status,\n ...(state.conclusion ? { conclusion: state.conclusion } : {}),\n ...(status.runUrl ? { details_url: webUrl(status.runUrl, 'workflow run URL') } : {}),\n output: { title: name, summary: state.summary },\n }\n const existing = checks.check_runs[0]\n if (existing) await api(`/check-runs/${existing.id}`, jsonRequest('PATCH', body))\n else await api('/check-runs', jsonRequest('POST', body))\n}\n\nasync function issueComments(api: <T>(path: string, init?: RequestInit) => Promise<T>, prNumber: string, page = 1): Promise<Comment[]> {\n if (page > 10) throw new Error('preview comment lookup exceeded 1,000 comments')\n const comments = await api<Comment[]>(`/issues/${prNumber}/comments?per_page=100&page=${page}`)\n return comments.length < 100 ? comments : [...comments, ...(await issueComments(api, prNumber, page + 1))]\n}\n\nfunction previewComment(options: GitHubPreviewOptions, status: PreviewStatus, previous?: string) {\n if (status.state === 'deleted') return `${options.marker}\\nπŸ—‘οΈ Preview deleted because this pull request was closed.`\n const sha = commitSha(status.sha).slice(0, 7)\n const standingSha = previous?.match(/up to date with commit `([0-9a-f]{7})`/)?.[1]\n const standing = standingSha ? ` The preview of \\`${standingSha}\\` stays up until it does.` : ''\n const heading = {\n awaiting: `⏸️ The preview of \\`${sha}\\` is waiting for a maintainer to approve its build.${standing}`,\n building: `πŸ”„ Deploying \\`${sha}\\`.${standing}`,\n ready: `βœ… Preview is up to date with commit \\`${sha}\\`.`,\n failed: `❌ Deploying commit \\`${sha}\\` failed${status.runUrl ? ` ([workflow run](${webUrl(status.runUrl, 'workflow run URL')}))` : ''}. The preview may be stale or unavailable.`,\n }[status.state]\n return [\n options.marker,\n heading,\n ...(status.previewUrl ? ['', `Preview: ${webUrl(status.previewUrl, 'preview URL')}`] : []),\n ...(options.note ? ['', options.note] : []),\n ].join('\\n')\n}\n\nfunction checkState(state: Exclude<PreviewStatusState, 'deleted'>) {\n return {\n awaiting: { status: 'queued', summary: 'The preview build is waiting for workflow approval.' },\n building: { status: 'in_progress', summary: 'A new preview version is deploying.' },\n ready: { status: 'completed', conclusion: 'success', summary: 'The preview is up to date.' },\n failed: { status: 'completed', conclusion: 'failure', summary: 'The preview deployment failed.' },\n }[state]\n}\n\nasync function github<T>(request: typeof fetch, token: string, path: string, init?: RequestInit): Promise<T> {\n const headers = new Headers(init?.headers)\n headers.set('accept', 'application/vnd.github+json')\n headers.set('authorization', `Bearer ${token}`)\n headers.set('x-github-api-version', '2022-11-28')\n const response = await request(`https://api.github.com${path}`, {\n ...init,\n headers,\n })\n const text = await response.text()\n if (!response.ok) throw new Error(`GitHub ${path.split('?')[0]} failed with ${response.status}: ${text.slice(0, 500)}`)\n return text ? (JSON.parse(text) as T) : (undefined as T)\n}\n\nfunction jsonRequest(method: 'POST' | 'PATCH', body: unknown): RequestInit {\n return { method, headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }\n}\n\nfunction githubRepository(value: string) {\n if (!/^[a-z\\d][\\w.-]*\\/[a-z\\d][\\w.-]*$/i.test(value)) throw new Error('repository must use an owner/name identifier')\n return value\n}\n\nfunction commentMarker(value: string) {\n if (!/^<!-- [a-z\\d-]+ -->$/i.test(value)) throw new Error('preview marker must be a named HTML comment')\n return value\n}\n\nfunction webUrl(value: string, name: string) {\n const url = new URL(value)\n if (url.protocol !== 'https:' && url.protocol !== 'http:') throw new Error(`${name} must use HTTP or HTTPS`)\n return url.toString().replace(/\\/$/, '')\n}\n\nfunction commitSha(value: string | undefined) {\n if (!value || !/^[0-9a-f]{40}$/i.test(value)) throw new Error('commit SHA must contain 40 hexadecimal characters')\n return value\n}\n"]}
@@ -1,6 +1,5 @@
1
- import { Centrifuge, type ClientInfo, type Options, type ServerPublicationContext, type ServerSubscribedContext, type Subscription, type SubscriptionOptions } from 'centrifuge';
1
+ import { Centrifuge, type Options, type ServerPublicationContext, type ServerSubscribedContext } from 'centrifuge';
2
2
  type BrowserLocation = Pick<Location, 'host' | 'protocol'>;
3
- export declare function sameOriginWebSocketUrl(location: BrowserLocation, path?: string): string;
4
3
  export type RealtimeTicketOptions<T> = {
5
4
  fetch?: typeof fetch;
6
5
  init?: RequestInit;
@@ -13,17 +12,8 @@ export declare function createSameOriginRealtimeClient(options: Partial<Options>
13
12
  location?: BrowserLocation;
14
13
  path?: string;
15
14
  }): Centrifuge;
16
- export declare function connectRealtimeClient(client: Centrifuge): () => void;
17
- export type RealtimeSubscription = {
18
- subscription: Subscription;
19
- close: () => void;
20
- };
21
- export declare function openRealtimeSubscription(client: Centrifuge, channel: string, options?: SubscriptionOptions, configure?: (subscription: Subscription) => void | (() => void)): RealtimeSubscription;
22
15
  export declare function watchServerChannel(client: Centrifuge, channel: string, handlers: {
23
16
  publication?: (context: ServerPublicationContext) => void;
24
17
  unrecovered?: (context: ServerSubscribedContext) => void;
25
18
  }): () => void;
26
- export declare function watchSubscriptionPresence(subscription: Subscription, update: (clients: Record<string, ClientInfo>) => void, options?: {
27
- onError?: (error: unknown) => void;
28
- }): () => void;
29
19
  export {};