@powerhousedao/switchboard 6.0.0-dev.23 → 6.0.0-dev.231
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/Auth.md +45 -27
- package/CHANGELOG.md +1786 -5
- package/README.md +13 -12
- package/dist/esm-aE6sDAbA.mjs +6481 -0
- package/dist/esm-aE6sDAbA.mjs.map +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +134 -0
- package/dist/index.mjs.map +1 -0
- package/dist/install-packages.d.mts +1 -0
- package/dist/install-packages.mjs +31 -0
- package/dist/install-packages.mjs.map +1 -0
- package/dist/migrate.d.mts +1 -0
- package/dist/migrate.mjs +55 -0
- package/dist/migrate.mjs.map +1 -0
- package/dist/server-UGYERfMo.mjs +762 -0
- package/dist/server-UGYERfMo.mjs.map +1 -0
- package/dist/server.d.mts +113 -0
- package/dist/server.d.mts.map +1 -0
- package/dist/server.mjs +4 -0
- package/dist/utils-DFl0ezBT.mjs +44 -0
- package/dist/utils-DFl0ezBT.mjs.map +1 -0
- package/dist/utils.d.mts +9 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +2 -0
- package/package.json +58 -40
- package/test/attachments/auth.test.ts +219 -0
- package/test/attachments/index.test.ts +119 -0
- package/test/attachments/routes-integration.test.ts +103 -0
- package/test/attachments/routes.test.ts +864 -0
- package/test/metrics.test.ts +202 -0
- package/test/pglite-dialect.test.ts +40 -0
- package/test/pglite-version.test.ts +37 -0
- package/tsconfig.json +12 -3
- package/tsdown.config.ts +16 -0
- package/vitest.config.ts +11 -0
- package/Dockerfile +0 -86
- package/dist/src/clients/redis.d.ts +0 -5
- package/dist/src/clients/redis.d.ts.map +0 -1
- package/dist/src/clients/redis.js +0 -48
- package/dist/src/clients/redis.js.map +0 -1
- package/dist/src/config.d.ts +0 -12
- package/dist/src/config.d.ts.map +0 -1
- package/dist/src/config.js +0 -33
- package/dist/src/config.js.map +0 -1
- package/dist/src/connect-crypto.d.ts +0 -41
- package/dist/src/connect-crypto.d.ts.map +0 -1
- package/dist/src/connect-crypto.js +0 -127
- package/dist/src/connect-crypto.js.map +0 -1
- package/dist/src/feature-flags.d.ts +0 -2
- package/dist/src/feature-flags.d.ts.map +0 -1
- package/dist/src/feature-flags.js +0 -9
- package/dist/src/feature-flags.js.map +0 -1
- package/dist/src/index.d.ts +0 -3
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -21
- package/dist/src/index.js.map +0 -1
- package/dist/src/install-packages.d.ts +0 -2
- package/dist/src/install-packages.d.ts.map +0 -1
- package/dist/src/install-packages.js +0 -36
- package/dist/src/install-packages.js.map +0 -1
- package/dist/src/migrate.d.ts +0 -3
- package/dist/src/migrate.d.ts.map +0 -1
- package/dist/src/migrate.js +0 -65
- package/dist/src/migrate.js.map +0 -1
- package/dist/src/profiler.d.ts +0 -4
- package/dist/src/profiler.d.ts.map +0 -1
- package/dist/src/profiler.js +0 -17
- package/dist/src/profiler.js.map +0 -1
- package/dist/src/server.d.ts +0 -6
- package/dist/src/server.d.ts.map +0 -1
- package/dist/src/server.js +0 -304
- package/dist/src/server.js.map +0 -1
- package/dist/src/types.d.ts +0 -64
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -2
- package/dist/src/types.js.map +0 -1
- package/dist/src/utils.d.ts +0 -6
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/src/utils.js +0 -92
- package/dist/src/utils.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/entrypoint.sh +0 -17
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { MeterProvider } from "@opentelemetry/sdk-metrics";
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { createMeterProviderFromEnv } from "../src/metrics.js";
|
|
4
|
+
|
|
5
|
+
// Stub childLogger so tests don't require the full document-drive runtime
|
|
6
|
+
vi.mock("document-drive", () => ({
|
|
7
|
+
childLogger: () => ({
|
|
8
|
+
info: vi.fn(),
|
|
9
|
+
warn: vi.fn(),
|
|
10
|
+
error: vi.fn(),
|
|
11
|
+
}),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
const providers: MeterProvider[] = [];
|
|
15
|
+
|
|
16
|
+
afterEach(async () => {
|
|
17
|
+
vi.restoreAllMocks();
|
|
18
|
+
// Await shutdown so PeriodicExportingMetricReader timers are cleared
|
|
19
|
+
await Promise.all(providers.map((p) => p.shutdown()));
|
|
20
|
+
providers.length = 0;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function track(provider: MeterProvider | undefined): MeterProvider | undefined {
|
|
24
|
+
if (provider) providers.push(provider);
|
|
25
|
+
return provider;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function trackAsserted(provider: MeterProvider | undefined): MeterProvider {
|
|
29
|
+
expect(provider).toBeInstanceOf(MeterProvider);
|
|
30
|
+
return track(provider) as MeterProvider;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// These helpers access undocumented internal fields of MeterProvider and
|
|
34
|
+
// PeriodicExportingMetricReader. They may break if @opentelemetry/sdk-metrics
|
|
35
|
+
// renames its private state between major versions.
|
|
36
|
+
function getReader(provider: MeterProvider): {
|
|
37
|
+
_exportInterval: number;
|
|
38
|
+
_exportTimeout: number;
|
|
39
|
+
} {
|
|
40
|
+
return (
|
|
41
|
+
provider as unknown as {
|
|
42
|
+
_sharedState: {
|
|
43
|
+
metricCollectors: Array<{
|
|
44
|
+
_metricReader: { _exportInterval: number; _exportTimeout: number };
|
|
45
|
+
}>;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
)._sharedState.metricCollectors[0]._metricReader;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getExporterUrl(provider: MeterProvider): string {
|
|
52
|
+
return (
|
|
53
|
+
provider as unknown as {
|
|
54
|
+
_sharedState: {
|
|
55
|
+
metricCollectors: Array<{
|
|
56
|
+
_metricReader: {
|
|
57
|
+
_exporter: {
|
|
58
|
+
_delegate: {
|
|
59
|
+
_transport: {
|
|
60
|
+
_transport: { _parameters: { url: string } };
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
}>;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
)._sharedState.metricCollectors[0]._metricReader._exporter._delegate
|
|
69
|
+
._transport._transport._parameters.url;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function getResourceAttributes(
|
|
73
|
+
provider: MeterProvider,
|
|
74
|
+
): Record<string, unknown> {
|
|
75
|
+
return (
|
|
76
|
+
provider as unknown as {
|
|
77
|
+
_sharedState: { resource: { attributes: Record<string, unknown> } };
|
|
78
|
+
}
|
|
79
|
+
)._sharedState.resource.attributes;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
describe("createMeterProviderFromEnv", () => {
|
|
83
|
+
describe("when OTEL_EXPORTER_OTLP_ENDPOINT is not set", () => {
|
|
84
|
+
it("returns undefined", () => {
|
|
85
|
+
expect(createMeterProviderFromEnv({})).toBeUndefined();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe("when OTEL_EXPORTER_OTLP_ENDPOINT is set", () => {
|
|
90
|
+
it("returns a MeterProvider", () => {
|
|
91
|
+
expect(
|
|
92
|
+
track(
|
|
93
|
+
createMeterProviderFromEnv({
|
|
94
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: "http://localhost:4318",
|
|
95
|
+
}),
|
|
96
|
+
),
|
|
97
|
+
).toBeInstanceOf(MeterProvider);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("strips trailing slash from endpoint URL without throwing", () => {
|
|
101
|
+
expect(() =>
|
|
102
|
+
track(
|
|
103
|
+
createMeterProviderFromEnv({
|
|
104
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: "http://localhost:4318/",
|
|
105
|
+
}),
|
|
106
|
+
),
|
|
107
|
+
).not.toThrow();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("does not double-append /v1/metrics when endpoint already includes it", () => {
|
|
111
|
+
const provider = trackAsserted(
|
|
112
|
+
createMeterProviderFromEnv({
|
|
113
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: "http://localhost:4318/v1/metrics",
|
|
114
|
+
}),
|
|
115
|
+
);
|
|
116
|
+
expect(getExporterUrl(provider)).toBe("http://localhost:4318/v1/metrics");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("uses 5000ms export interval by default", () => {
|
|
120
|
+
const provider = trackAsserted(
|
|
121
|
+
createMeterProviderFromEnv({
|
|
122
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: "http://localhost:4318",
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
125
|
+
expect(getReader(provider)._exportInterval).toBe(5000);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("honours OTEL_METRIC_EXPORT_INTERVAL", () => {
|
|
129
|
+
const provider = trackAsserted(
|
|
130
|
+
createMeterProviderFromEnv({
|
|
131
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: "http://localhost:4318",
|
|
132
|
+
OTEL_METRIC_EXPORT_INTERVAL: "2000",
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
expect(getReader(provider)._exportInterval).toBe(2000);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("falls back to 5000ms when OTEL_METRIC_EXPORT_INTERVAL is non-numeric", () => {
|
|
139
|
+
const provider = trackAsserted(
|
|
140
|
+
createMeterProviderFromEnv({
|
|
141
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: "http://localhost:4318",
|
|
142
|
+
OTEL_METRIC_EXPORT_INTERVAL: "abc",
|
|
143
|
+
}),
|
|
144
|
+
);
|
|
145
|
+
expect(getReader(provider)._exportInterval).toBe(5000);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("falls back to 5000ms when OTEL_METRIC_EXPORT_INTERVAL is zero", () => {
|
|
149
|
+
const provider = trackAsserted(
|
|
150
|
+
createMeterProviderFromEnv({
|
|
151
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: "http://localhost:4318",
|
|
152
|
+
OTEL_METRIC_EXPORT_INTERVAL: "0",
|
|
153
|
+
}),
|
|
154
|
+
);
|
|
155
|
+
expect(getReader(provider)._exportInterval).toBe(5000);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("falls back to 5000ms when OTEL_METRIC_EXPORT_INTERVAL is negative", () => {
|
|
159
|
+
const provider = trackAsserted(
|
|
160
|
+
createMeterProviderFromEnv({
|
|
161
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: "http://localhost:4318",
|
|
162
|
+
OTEL_METRIC_EXPORT_INTERVAL: "-1000",
|
|
163
|
+
}),
|
|
164
|
+
);
|
|
165
|
+
expect(getReader(provider)._exportInterval).toBe(5000);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("sets exportTimeoutMillis below exportIntervalMillis", () => {
|
|
169
|
+
const provider = trackAsserted(
|
|
170
|
+
createMeterProviderFromEnv({
|
|
171
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: "http://localhost:4318",
|
|
172
|
+
OTEL_METRIC_EXPORT_INTERVAL: "1000",
|
|
173
|
+
}),
|
|
174
|
+
);
|
|
175
|
+
const reader = getReader(provider);
|
|
176
|
+
expect(reader._exportTimeout).toBeLessThan(reader._exportInterval);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("uses 'switchboard' as service name by default", () => {
|
|
180
|
+
const provider = trackAsserted(
|
|
181
|
+
createMeterProviderFromEnv({
|
|
182
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: "http://localhost:4318",
|
|
183
|
+
}),
|
|
184
|
+
);
|
|
185
|
+
expect(getResourceAttributes(provider)["service.name"]).toBe(
|
|
186
|
+
"switchboard",
|
|
187
|
+
);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it("honours OTEL_SERVICE_NAME", () => {
|
|
191
|
+
const provider = trackAsserted(
|
|
192
|
+
createMeterProviderFromEnv({
|
|
193
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: "http://localhost:4318",
|
|
194
|
+
OTEL_SERVICE_NAME: "my-switchboard",
|
|
195
|
+
}),
|
|
196
|
+
);
|
|
197
|
+
expect(getResourceAttributes(provider)["service.name"]).toBe(
|
|
198
|
+
"my-switchboard",
|
|
199
|
+
);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PGlite } from "@electric-sql/pglite";
|
|
2
|
+
import { Kysely, sql } from "kysely";
|
|
3
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
4
|
+
import { ClosablePGliteDialect } from "../src/pglite-dialect.js";
|
|
5
|
+
|
|
6
|
+
describe("ClosablePGliteDialect", () => {
|
|
7
|
+
const created: PGlite[] = [];
|
|
8
|
+
|
|
9
|
+
afterEach(async () => {
|
|
10
|
+
for (const p of created.splice(0)) {
|
|
11
|
+
if (!p.closed) await p.close();
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("closes the underlying PGlite when the Kysely instance is destroyed", async () => {
|
|
16
|
+
const pglite = new PGlite();
|
|
17
|
+
created.push(pglite);
|
|
18
|
+
const db = new Kysely({ dialect: new ClosablePGliteDialect(pglite) });
|
|
19
|
+
|
|
20
|
+
// Kysely lazy-inits the driver on first query; no query means destroy
|
|
21
|
+
// skips the driver, which would defeat the purpose of this test.
|
|
22
|
+
await sql`select 1`.execute(db);
|
|
23
|
+
expect(pglite.closed).toBe(false);
|
|
24
|
+
|
|
25
|
+
await db.destroy();
|
|
26
|
+
expect(pglite.closed).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("is idempotent if the PGlite is already closed", async () => {
|
|
30
|
+
const pglite = new PGlite();
|
|
31
|
+
created.push(pglite);
|
|
32
|
+
const db = new Kysely({ dialect: new ClosablePGliteDialect(pglite) });
|
|
33
|
+
|
|
34
|
+
await sql`select 1`.execute(db);
|
|
35
|
+
await pglite.close();
|
|
36
|
+
expect(pglite.closed).toBe(true);
|
|
37
|
+
|
|
38
|
+
await expect(db.destroy()).resolves.toBeUndefined();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { parseForcePgVersion } from "../src/pglite-version.js";
|
|
3
|
+
|
|
4
|
+
describe("parseForcePgVersion", () => {
|
|
5
|
+
it("returns null for undefined", () => {
|
|
6
|
+
expect(parseForcePgVersion(undefined)).toBeNull();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("returns null for empty string", () => {
|
|
10
|
+
expect(parseForcePgVersion("")).toBeNull();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("returns null for whitespace-only string", () => {
|
|
14
|
+
expect(parseForcePgVersion(" ")).toBeNull();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("returns 16 for '16'", () => {
|
|
18
|
+
expect(parseForcePgVersion("16")).toBe(16);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("returns 17 for '17'", () => {
|
|
22
|
+
expect(parseForcePgVersion("17")).toBe(17);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("throws for unsupported major", () => {
|
|
26
|
+
expect(() => parseForcePgVersion("15")).toThrow(/PH_FORCE_PG_VERSION/);
|
|
27
|
+
expect(() => parseForcePgVersion("15")).toThrow(/got: 15/);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("throws for non-numeric", () => {
|
|
31
|
+
expect(() => parseForcePgVersion("foo")).toThrow(/PH_FORCE_PG_VERSION/);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("throws for non-integer numeric", () => {
|
|
35
|
+
expect(() => parseForcePgVersion("16.5")).toThrow(/PH_FORCE_PG_VERSION/);
|
|
36
|
+
});
|
|
37
|
+
});
|
package/tsconfig.json
CHANGED
|
@@ -10,23 +10,32 @@
|
|
|
10
10
|
"**/*"
|
|
11
11
|
],
|
|
12
12
|
"references": [
|
|
13
|
+
{
|
|
14
|
+
"path": "../../packages/config"
|
|
15
|
+
},
|
|
13
16
|
{
|
|
14
17
|
"path": "../../packages/document-model"
|
|
15
18
|
},
|
|
16
19
|
{
|
|
17
|
-
"path": "../../packages/
|
|
20
|
+
"path": "../../packages/opentelemetry-instrumentation-reactor"
|
|
18
21
|
},
|
|
19
22
|
{
|
|
20
|
-
"path": "../../packages/
|
|
23
|
+
"path": "../../packages/reactor"
|
|
21
24
|
},
|
|
22
25
|
{
|
|
23
26
|
"path": "../../packages/reactor-api"
|
|
24
27
|
},
|
|
28
|
+
{
|
|
29
|
+
"path": "../../packages/reactor-attachments"
|
|
30
|
+
},
|
|
25
31
|
{
|
|
26
32
|
"path": "../../packages/renown"
|
|
27
33
|
},
|
|
28
34
|
{
|
|
29
|
-
"path": "../../packages/
|
|
35
|
+
"path": "../../packages/shared"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"path": "../../packages/vetra"
|
|
30
39
|
}
|
|
31
40
|
]
|
|
32
41
|
}
|
package/tsdown.config.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineConfig } from "tsdown";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
entry: [
|
|
5
|
+
"src/index.mts",
|
|
6
|
+
"src/server.mts",
|
|
7
|
+
"src/utils.mts",
|
|
8
|
+
"src/install-packages.mts",
|
|
9
|
+
"src/migrate.mts",
|
|
10
|
+
],
|
|
11
|
+
platform: "node",
|
|
12
|
+
outDir: "dist",
|
|
13
|
+
clean: true,
|
|
14
|
+
dts: true,
|
|
15
|
+
sourcemap: true,
|
|
16
|
+
});
|
package/vitest.config.ts
ADDED
package/Dockerfile
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
# Build stage
|
|
2
|
-
FROM node:22-alpine AS build
|
|
3
|
-
|
|
4
|
-
WORKDIR /app
|
|
5
|
-
|
|
6
|
-
# Install build dependencies
|
|
7
|
-
RUN apk add --no-cache python3 make g++ git bash \
|
|
8
|
-
&& ln -sf /usr/bin/python3 /usr/bin/python
|
|
9
|
-
|
|
10
|
-
# Setup pnpm
|
|
11
|
-
ENV PNPM_HOME="/pnpm"
|
|
12
|
-
ENV PATH="$PNPM_HOME:$PATH"
|
|
13
|
-
RUN corepack enable && corepack prepare pnpm@latest --activate
|
|
14
|
-
|
|
15
|
-
# Configure JSR registry
|
|
16
|
-
RUN pnpm config set @jsr:registry https://npm.jsr.io
|
|
17
|
-
|
|
18
|
-
# Build arguments
|
|
19
|
-
ARG TAG=latest
|
|
20
|
-
ARG PH_PACKAGES=""
|
|
21
|
-
|
|
22
|
-
# Install ph-cmd, prisma, and prettier
|
|
23
|
-
RUN pnpm add -g ph-cmd@$TAG prisma@5.17.0 prettier
|
|
24
|
-
|
|
25
|
-
# Initialize project based on tag
|
|
26
|
-
RUN case "$TAG" in \
|
|
27
|
-
*dev*) ph init project --dev --package-manager pnpm ;; \
|
|
28
|
-
*staging*) ph init project --staging --package-manager pnpm ;; \
|
|
29
|
-
*) ph init project --package-manager pnpm ;; \
|
|
30
|
-
esac
|
|
31
|
-
|
|
32
|
-
WORKDIR /app/project
|
|
33
|
-
|
|
34
|
-
# Install PH packages if provided
|
|
35
|
-
RUN if [ -n "$PH_PACKAGES" ]; then \
|
|
36
|
-
IFS=',' ; for pkg in $PH_PACKAGES; do \
|
|
37
|
-
echo "Installing package: $pkg"; \
|
|
38
|
-
ph install "$pkg"; \
|
|
39
|
-
done; \
|
|
40
|
-
fi
|
|
41
|
-
|
|
42
|
-
# Regenerate Prisma client for Alpine Linux (linux-musl-openssl-3.0.x)
|
|
43
|
-
# The document-drive package ships with darwin-arm64 binaries, we need to regenerate
|
|
44
|
-
RUN prisma generate --schema node_modules/document-drive/dist/prisma/schema.prisma
|
|
45
|
-
|
|
46
|
-
# Final stage - slim node image
|
|
47
|
-
FROM node:22-alpine
|
|
48
|
-
|
|
49
|
-
WORKDIR /app
|
|
50
|
-
|
|
51
|
-
# Install runtime dependencies (curl for health checks, openssl for Prisma)
|
|
52
|
-
RUN apk add --no-cache curl openssl
|
|
53
|
-
|
|
54
|
-
# Setup pnpm
|
|
55
|
-
ENV PNPM_HOME="/pnpm"
|
|
56
|
-
ENV PATH="$PNPM_HOME:$PATH"
|
|
57
|
-
RUN corepack enable && corepack prepare pnpm@latest --activate
|
|
58
|
-
|
|
59
|
-
# Configure JSR registry
|
|
60
|
-
RUN pnpm config set @jsr:registry https://npm.jsr.io
|
|
61
|
-
|
|
62
|
-
# Install ph-cmd and prisma globally (needed at runtime)
|
|
63
|
-
ARG TAG=latest
|
|
64
|
-
RUN pnpm add -g ph-cmd@$TAG prisma@5.17.0
|
|
65
|
-
|
|
66
|
-
# Copy built project from build stage
|
|
67
|
-
COPY --from=build /app/project /app/project
|
|
68
|
-
|
|
69
|
-
WORKDIR /app/project
|
|
70
|
-
|
|
71
|
-
# Copy entrypoint
|
|
72
|
-
COPY entrypoint.sh /app/entrypoint.sh
|
|
73
|
-
RUN chmod +x /app/entrypoint.sh
|
|
74
|
-
|
|
75
|
-
# Environment variables
|
|
76
|
-
ENV NODE_ENV=production
|
|
77
|
-
ENV PORT=3000
|
|
78
|
-
ENV DATABASE_URL=""
|
|
79
|
-
ENV SKIP_DB_MIGRATIONS="false"
|
|
80
|
-
|
|
81
|
-
EXPOSE ${PORT}
|
|
82
|
-
|
|
83
|
-
HEALTHCHECK --interval=30s --timeout=3s --start-period=30s --retries=3 \
|
|
84
|
-
CMD curl -f http://localhost:${PORT}/health || exit 1
|
|
85
|
-
|
|
86
|
-
ENTRYPOINT ["/app/entrypoint.sh"]
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { RedisClientType } from "redis";
|
|
2
|
-
export declare let redisClient: RedisClientType | undefined;
|
|
3
|
-
export declare const initRedis: (url: string) => Promise<RedisClientType | undefined>;
|
|
4
|
-
export declare const closeRedis: () => Promise<void> | undefined;
|
|
5
|
-
//# sourceMappingURL=redis.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../../src/clients/redis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAG7C,eAAO,IAAI,WAAW,EAAE,eAAe,GAAG,SAAS,CAAC;AACpD,eAAO,MAAM,SAAS,GACpB,KAAK,MAAM,KACV,OAAO,CAAC,eAAe,GAAG,SAAS,CAiCrC,CAAC;AAeF,eAAO,MAAM,UAAU,iCAItB,CAAC"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { createClient } from "redis";
|
|
2
|
-
export let redisClient;
|
|
3
|
-
export const initRedis = async (url) => {
|
|
4
|
-
if (redisClient) {
|
|
5
|
-
return redisClient;
|
|
6
|
-
}
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
const socket = url.includes("rediss")
|
|
9
|
-
? {
|
|
10
|
-
tls: true,
|
|
11
|
-
rejectUnauthorized: false,
|
|
12
|
-
}
|
|
13
|
-
: undefined;
|
|
14
|
-
redisClient = createClient({
|
|
15
|
-
url,
|
|
16
|
-
socket,
|
|
17
|
-
});
|
|
18
|
-
redisClient
|
|
19
|
-
.connect()
|
|
20
|
-
.then((client) => {
|
|
21
|
-
redisClient = client;
|
|
22
|
-
client.on("error", (err) => {
|
|
23
|
-
console.warn("Redis Client Error", err);
|
|
24
|
-
});
|
|
25
|
-
resolve(client);
|
|
26
|
-
})
|
|
27
|
-
.catch(async (e) => {
|
|
28
|
-
reject(e instanceof Error ? e : new Error(JSON.stringify(e)));
|
|
29
|
-
// await redisClient.disconnect();
|
|
30
|
-
// console.warn("Redis Client Error", e);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
const timer = setInterval(async () => {
|
|
35
|
-
try {
|
|
36
|
-
if (redisClient) {
|
|
37
|
-
await redisClient.ping();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
catch (err) {
|
|
41
|
-
console.error("Ping Interval Error", err);
|
|
42
|
-
}
|
|
43
|
-
}, 1000 * 60 * 4);
|
|
44
|
-
export const closeRedis = () => {
|
|
45
|
-
clearInterval(timer);
|
|
46
|
-
return redisClient?.disconnect();
|
|
47
|
-
};
|
|
48
|
-
//# sourceMappingURL=redis.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"redis.js","sourceRoot":"","sources":["../../../src/clients/redis.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErC,MAAM,CAAC,IAAI,WAAwC,CAAC;AACpD,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAC5B,GAAW,EAC2B,EAAE;IACxC,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC;YACnC,CAAC,CAAC;gBACE,GAAG,EAAE,IAAI;gBACT,kBAAkB,EAAE,KAAK;aAC1B;YACH,CAAC,CAAC,SAAS,CAAC;QACd,WAAW,GAAG,YAAY,CAAC;YACzB,GAAG;YACH,MAAM;SACP,CAAC,CAAC;QAEH,WAAW;aACR,OAAO,EAAE;aACT,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YACf,WAAW,GAAG,MAAM,CAAC;YAErB,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;gBACzB,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;YAC1C,CAAC,CAAC,CAAC;YACH,OAAO,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC,CAAC;aACD,KAAK,CAAC,KAAK,EAAE,CAAU,EAAE,EAAE;YAC1B,MAAM,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC9D,kCAAkC;YAClC,yCAAyC;QAC3C,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,KAAK,GAAG,WAAW,CACvB,KAAK,IAAI,EAAE;IACT,IAAI,CAAC;QACH,IAAI,WAAW,EAAE,CAAC;YAChB,MAAM,WAAW,CAAC,IAAI,EAAE,CAAC;QAC3B,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC,EACD,IAAI,GAAG,EAAE,GAAG,CAAC,CACd,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,EAAE;IAC7B,aAAa,CAAC,KAAK,CAAC,CAAC;IAErB,OAAO,WAAW,EAAE,UAAU,EAAE,CAAC;AACnC,CAAC,CAAC"}
|
package/dist/src/config.d.ts
DELETED
package/dist/src/config.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjD,UAAU,MAAM;IACd,QAAQ,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,UAAU,CAAC;CACnB;AACD,eAAO,MAAM,MAAM,EAAE,MA4BpB,CAAC"}
|
package/dist/src/config.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import dotenv from "dotenv";
|
|
2
|
-
dotenv.config();
|
|
3
|
-
import { getConfig } from "@powerhousedao/config/node";
|
|
4
|
-
const phConfig = getConfig();
|
|
5
|
-
const { switchboard } = phConfig;
|
|
6
|
-
export const config = {
|
|
7
|
-
database: {
|
|
8
|
-
// url: process.env.PH_SWITCHBOARD_DATABASE_URL ?? switchboard?.database?.url ?? "dev.db",
|
|
9
|
-
url: process.env.PH_SWITCHBOARD_DATABASE_URL ??
|
|
10
|
-
switchboard?.database?.url ??
|
|
11
|
-
"dev.db",
|
|
12
|
-
},
|
|
13
|
-
port: process.env.PH_SWITCHBOARD_PORT &&
|
|
14
|
-
!isNaN(Number(process.env.PH_SWITCHBOARD_PORT))
|
|
15
|
-
? Number(process.env.PH_SWITCHBOARD_PORT)
|
|
16
|
-
: (switchboard?.port ?? 4001),
|
|
17
|
-
mcp: true,
|
|
18
|
-
drive: {
|
|
19
|
-
id: "powerhouse",
|
|
20
|
-
slug: "powerhouse",
|
|
21
|
-
global: {
|
|
22
|
-
name: "Powerhouse",
|
|
23
|
-
icon: "https://ipfs.io/ipfs/QmcaTDBYn8X2psGaXe7iQ6qd8q6oqHLgxvMX9yXf7f9uP7",
|
|
24
|
-
},
|
|
25
|
-
local: {
|
|
26
|
-
availableOffline: true,
|
|
27
|
-
listeners: [],
|
|
28
|
-
sharingType: "public",
|
|
29
|
-
triggers: [],
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
//# sourceMappingURL=config.js.map
|
package/dist/src/config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEvD,MAAM,QAAQ,GAAG,SAAS,EAAE,CAAC;AAC7B,MAAM,EAAE,WAAW,EAAE,GAAG,QAAQ,CAAC;AASjC,MAAM,CAAC,MAAM,MAAM,GAAW;IAC5B,QAAQ,EAAE;QACR,0FAA0F;QAC1F,GAAG,EACD,OAAO,CAAC,GAAG,CAAC,2BAA2B;YACvC,WAAW,EAAE,QAAQ,EAAE,GAAG;YAC1B,QAAQ;KACX;IACD,IAAI,EACF,OAAO,CAAC,GAAG,CAAC,mBAAmB;QAC/B,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;QAC7C,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;QACzC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,IAAI,IAAI,CAAC;IACjC,GAAG,EAAE,IAAI;IACT,KAAK,EAAE;QACL,EAAE,EAAE,YAAY;QAChB,IAAI,EAAE,YAAY;QAClB,MAAM,EAAE;YACN,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,qEAAqE;SAC5E;QACD,KAAK,EAAE;YACL,gBAAgB,EAAE,IAAI;YACtB,SAAS,EAAE,EAAE;YACb,WAAW,EAAE,QAAQ;YACrB,QAAQ,EAAE,EAAE;SACb;KACF;CACF,CAAC"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { type IConnectCrypto, type JsonWebKeyPairStorage, type JwkKeyPair } from "@renown/sdk";
|
|
2
|
-
/**
|
|
3
|
-
* Key storage that supports:
|
|
4
|
-
* 1. PH_RENOWN_PRIVATE_KEY environment variable (JSON-encoded JwkKeyPair)
|
|
5
|
-
* 2. Custom file path passed via options
|
|
6
|
-
* 3. Falls back to file storage at .keypair.json in current working directory
|
|
7
|
-
*/
|
|
8
|
-
export declare class SwitchboardKeyStorage implements JsonWebKeyPairStorage {
|
|
9
|
-
#private;
|
|
10
|
-
constructor(filePath?: string);
|
|
11
|
-
loadKeyPair(): Promise<JwkKeyPair | undefined>;
|
|
12
|
-
saveKeyPair(keyPair: JwkKeyPair): Promise<void>;
|
|
13
|
-
}
|
|
14
|
-
export interface ConnectCryptoOptions {
|
|
15
|
-
/** Path to the keypair file. Defaults to .keypair.json in cwd */
|
|
16
|
-
keypairPath?: string;
|
|
17
|
-
/** If true, won't generate a new keypair if none exists */
|
|
18
|
-
requireExisting?: boolean;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Initialize ConnectCrypto for the switchboard.
|
|
22
|
-
* This allows the switchboard to authenticate with remote services
|
|
23
|
-
* using the same identity established during `ph login`.
|
|
24
|
-
*/
|
|
25
|
-
export declare function initConnectCrypto(options?: ConnectCryptoOptions): Promise<IConnectCrypto | null>;
|
|
26
|
-
/**
|
|
27
|
-
* Get the current ConnectCrypto instance.
|
|
28
|
-
* Returns null if not initialized.
|
|
29
|
-
*/
|
|
30
|
-
export declare function getConnectCrypto(): IConnectCrypto | null;
|
|
31
|
-
/**
|
|
32
|
-
* Get the DID of the current ConnectCrypto instance.
|
|
33
|
-
* Returns null if not initialized.
|
|
34
|
-
*/
|
|
35
|
-
export declare function getConnectDid(): Promise<string | null>;
|
|
36
|
-
/**
|
|
37
|
-
* Get a bearer token for authenticating with remote services.
|
|
38
|
-
* Returns null if ConnectCrypto is not initialized.
|
|
39
|
-
*/
|
|
40
|
-
export declare function getBearerToken(driveUrl: string, address?: string, refresh?: boolean): Promise<string | null>;
|
|
41
|
-
//# sourceMappingURL=connect-crypto.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connect-crypto.d.ts","sourceRoot":"","sources":["../../src/connect-crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EAChB,MAAM,aAAa,CAAC;AAUrB;;;;;GAKG;AACH,qBAAa,qBAAsB,YAAW,qBAAqB;;gBAGrD,QAAQ,CAAC,EAAE,MAAM;IAUvB,WAAW,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAuB9C,WAAW,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAgCtD;AAKD,MAAM,WAAW,oBAAoB;IACnC,iEAAiE;IACjE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2DAA2D;IAC3D,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CA0BhC;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,cAAc,GAAG,IAAI,CAExD;AAED;;;GAGG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAK5D;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,UAAQ,GACd,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAKxB"}
|