everything-dev 0.1.1 → 0.1.3
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/package.json +1 -1
- package/src/lib/nova.ts +11 -11
- package/src/lib/process.ts +50 -5
- package/src/plugin.ts +15 -8
- package/src/types.ts +8 -0
package/package.json
CHANGED
package/src/lib/nova.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface UploadResult {
|
|
|
20
20
|
|
|
21
21
|
export const getNovaConfig = Effect.gen(function* () {
|
|
22
22
|
const accountId = process.env.NOVA_ACCOUNT_ID;
|
|
23
|
-
const sessionToken = process.env.
|
|
23
|
+
const sessionToken = process.env.NOVA_API_KEY;
|
|
24
24
|
|
|
25
25
|
if (!accountId || !sessionToken) {
|
|
26
26
|
return yield* Effect.fail(
|
|
@@ -46,7 +46,7 @@ export function getSecretsGroupId(nearAccount: string): string {
|
|
|
46
46
|
export const registerSecretsGroup = (
|
|
47
47
|
nova: NovaSdk,
|
|
48
48
|
nearAccount: string,
|
|
49
|
-
|
|
49
|
+
novaAccount: string
|
|
50
50
|
) =>
|
|
51
51
|
Effect.gen(function* () {
|
|
52
52
|
const groupId = getSecretsGroupId(nearAccount);
|
|
@@ -57,8 +57,8 @@ export const registerSecretsGroup = (
|
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
yield* Effect.tryPromise({
|
|
60
|
-
try: () => nova.addGroupMember(groupId,
|
|
61
|
-
catch: (e) => new Error(`Failed to add gateway to
|
|
60
|
+
try: () => nova.addGroupMember(groupId, novaAccount),
|
|
61
|
+
catch: (e) => new Error(`Failed to add gateway Nova account to group: ${e}`),
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
return groupId;
|
|
@@ -150,7 +150,7 @@ export function filterSecretsToRequired(
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
export function hasNovaCredentials(): boolean {
|
|
153
|
-
return !!(process.env.NOVA_ACCOUNT_ID && process.env.
|
|
153
|
+
return !!(process.env.NOVA_ACCOUNT_ID && process.env.NOVA_API_KEY);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
function getBosEnvPath(): string {
|
|
@@ -182,8 +182,8 @@ export const saveNovaCredentials = (accountId: string, sessionToken: string) =>
|
|
|
182
182
|
if (trimmed.startsWith("NOVA_ACCOUNT_ID=")) {
|
|
183
183
|
newLines.push(`NOVA_ACCOUNT_ID=${accountId}`);
|
|
184
184
|
foundAccountId = true;
|
|
185
|
-
} else if (trimmed.startsWith("
|
|
186
|
-
newLines.push(`
|
|
185
|
+
} else if (trimmed.startsWith("NOVA_API_KEY=")) {
|
|
186
|
+
newLines.push(`NOVA_API_KEY=${sessionToken}`);
|
|
187
187
|
foundSessionToken = true;
|
|
188
188
|
} else {
|
|
189
189
|
newLines.push(line);
|
|
@@ -198,7 +198,7 @@ export const saveNovaCredentials = (accountId: string, sessionToken: string) =>
|
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
if (!foundSessionToken) {
|
|
201
|
-
newLines.push(`
|
|
201
|
+
newLines.push(`NOVA_API_KEY=${sessionToken}`);
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
yield* Effect.tryPromise({
|
|
@@ -207,7 +207,7 @@ export const saveNovaCredentials = (accountId: string, sessionToken: string) =>
|
|
|
207
207
|
});
|
|
208
208
|
|
|
209
209
|
process.env.NOVA_ACCOUNT_ID = accountId;
|
|
210
|
-
process.env.
|
|
210
|
+
process.env.NOVA_API_KEY = sessionToken;
|
|
211
211
|
});
|
|
212
212
|
|
|
213
213
|
export const removeNovaCredentials = Effect.gen(function* () {
|
|
@@ -226,7 +226,7 @@ export const removeNovaCredentials = Effect.gen(function* () {
|
|
|
226
226
|
const lines = content.split("\n");
|
|
227
227
|
const newLines = lines.filter((line) => {
|
|
228
228
|
const trimmed = line.trim();
|
|
229
|
-
return !trimmed.startsWith("NOVA_ACCOUNT_ID=") && !trimmed.startsWith("
|
|
229
|
+
return !trimmed.startsWith("NOVA_ACCOUNT_ID=") && !trimmed.startsWith("NOVA_API_KEY=");
|
|
230
230
|
});
|
|
231
231
|
|
|
232
232
|
yield* Effect.tryPromise({
|
|
@@ -235,7 +235,7 @@ export const removeNovaCredentials = Effect.gen(function* () {
|
|
|
235
235
|
});
|
|
236
236
|
|
|
237
237
|
delete process.env.NOVA_ACCOUNT_ID;
|
|
238
|
-
delete process.env.
|
|
238
|
+
delete process.env.NOVA_API_KEY;
|
|
239
239
|
});
|
|
240
240
|
|
|
241
241
|
export const verifyNovaCredentials = (accountId: string, sessionToken: string) =>
|
package/src/lib/process.ts
CHANGED
|
@@ -117,6 +117,46 @@ const detectStatus = (
|
|
|
117
117
|
return null;
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
+
const killProcessTree = (pid: number) =>
|
|
121
|
+
Effect.gen(function* () {
|
|
122
|
+
const killSignal = (signal: NodeJS.Signals) =>
|
|
123
|
+
Effect.try({
|
|
124
|
+
try: () => {
|
|
125
|
+
process.kill(-pid, signal);
|
|
126
|
+
},
|
|
127
|
+
catch: () => null,
|
|
128
|
+
}).pipe(Effect.ignore);
|
|
129
|
+
|
|
130
|
+
const killDirect = (signal: NodeJS.Signals) =>
|
|
131
|
+
Effect.try({
|
|
132
|
+
try: () => {
|
|
133
|
+
process.kill(pid, signal);
|
|
134
|
+
},
|
|
135
|
+
catch: () => null,
|
|
136
|
+
}).pipe(Effect.ignore);
|
|
137
|
+
|
|
138
|
+
const isRunning = () =>
|
|
139
|
+
Effect.try({
|
|
140
|
+
try: () => {
|
|
141
|
+
process.kill(pid, 0);
|
|
142
|
+
return true;
|
|
143
|
+
},
|
|
144
|
+
catch: () => false,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
yield* killSignal("SIGTERM");
|
|
148
|
+
yield* killDirect("SIGTERM");
|
|
149
|
+
|
|
150
|
+
yield* Effect.sleep("200 millis");
|
|
151
|
+
|
|
152
|
+
const stillRunning = yield* isRunning();
|
|
153
|
+
if (stillRunning) {
|
|
154
|
+
yield* killSignal("SIGKILL");
|
|
155
|
+
yield* killDirect("SIGKILL");
|
|
156
|
+
yield* Effect.sleep("100 millis");
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
120
160
|
export const spawnDevProcess = (
|
|
121
161
|
config: DevProcess,
|
|
122
162
|
callbacks: ProcessCallbacks
|
|
@@ -181,11 +221,16 @@ export const spawnDevProcess = (
|
|
|
181
221
|
name: config.name,
|
|
182
222
|
pid: proc.pid,
|
|
183
223
|
kill: async () => {
|
|
184
|
-
proc.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
224
|
+
const pid = proc.pid;
|
|
225
|
+
if (pid) {
|
|
226
|
+
await Effect.runPromise(killProcessTree(pid));
|
|
227
|
+
} else {
|
|
228
|
+
proc.kill("SIGTERM");
|
|
229
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
230
|
+
try {
|
|
231
|
+
proc.kill("SIGKILL");
|
|
232
|
+
} catch { }
|
|
233
|
+
}
|
|
189
234
|
},
|
|
190
235
|
waitForReady: Deferred.await(readyDeferred),
|
|
191
236
|
waitForExit: Effect.gen(function* () {
|
package/src/plugin.ts
CHANGED
|
@@ -47,7 +47,10 @@ interface BosDeps {
|
|
|
47
47
|
nearPrivateKey?: string;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
const DEFAULT_GATEWAY = "everything.dev";
|
|
51
|
+
|
|
52
|
+
function getGatewayDomain(config: BosConfigType | null): string {
|
|
53
|
+
if (!config) return DEFAULT_GATEWAY;
|
|
51
54
|
const gateway = config.gateway as string | { production: string } | undefined;
|
|
52
55
|
if (typeof gateway === "string") {
|
|
53
56
|
return gateway.replace(/^https?:\/\//, "");
|
|
@@ -55,7 +58,7 @@ function getGatewayDomain(config: BosConfigType): string {
|
|
|
55
58
|
if (gateway && typeof gateway === "object" && "production" in gateway) {
|
|
56
59
|
return gateway.production.replace(/^https?:\/\//, "");
|
|
57
60
|
}
|
|
58
|
-
|
|
61
|
+
return DEFAULT_GATEWAY;
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
function getAccountForNetwork(config: BosConfigType, network: "mainnet" | "testnet"): string {
|
|
@@ -753,7 +756,12 @@ export default createPlugin({
|
|
|
753
756
|
const novaConfig = yield* getNovaConfig;
|
|
754
757
|
const nova = createNovaClient(novaConfig);
|
|
755
758
|
|
|
756
|
-
|
|
759
|
+
const gatewayNovaAccount = bosConfig.gateway?.nova?.account;
|
|
760
|
+
if (!gatewayNovaAccount) {
|
|
761
|
+
return yield* Effect.fail(new Error("gateway.nova.account is required for secrets registration"));
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
yield* registerSecretsGroup(nova, fullAccount, gatewayNovaAccount);
|
|
757
765
|
|
|
758
766
|
return {
|
|
759
767
|
status: "registered" as const,
|
|
@@ -1098,7 +1106,7 @@ export default createPlugin({
|
|
|
1098
1106
|
|
|
1099
1107
|
try {
|
|
1100
1108
|
const gatewayDomain = getGatewayDomain(bosConfig);
|
|
1101
|
-
const gatewayAccount = bosConfig.account;
|
|
1109
|
+
const gatewayAccount = bosConfig.gateway?.account || bosConfig.account;
|
|
1102
1110
|
|
|
1103
1111
|
const wranglerContent = await Bun.file(wranglerPath).text();
|
|
1104
1112
|
|
|
@@ -1284,11 +1292,10 @@ export default createPlugin({
|
|
|
1284
1292
|
sync: builder.sync.handler(async ({ input }) => {
|
|
1285
1293
|
const { configDir, bosConfig } = deps;
|
|
1286
1294
|
|
|
1287
|
-
const
|
|
1288
|
-
const DEFAULT_SYNC_GATEWAY = "everything.dev";
|
|
1295
|
+
const DEFAULT_ACCOUNT = "every.near";
|
|
1289
1296
|
|
|
1290
|
-
const account = input.account || bosConfig?.account ||
|
|
1291
|
-
const gateway = input.gateway ||
|
|
1297
|
+
const account = input.account || bosConfig?.account || DEFAULT_ACCOUNT;
|
|
1298
|
+
const gateway = input.gateway || getGatewayDomain(bosConfig);
|
|
1292
1299
|
const socialUrl = `https://near.social/mob.near/widget/State.Inspector?key=${account}/bos/gateways/${gateway}`;
|
|
1293
1300
|
|
|
1294
1301
|
if (!bosConfig) {
|
package/src/types.ts
CHANGED
|
@@ -30,9 +30,16 @@ export const RemoteConfigSchema = z.object({
|
|
|
30
30
|
});
|
|
31
31
|
export type RemoteConfig = z.infer<typeof RemoteConfigSchema>;
|
|
32
32
|
|
|
33
|
+
export const NovaConfigSchema = z.object({
|
|
34
|
+
account: z.string(),
|
|
35
|
+
});
|
|
36
|
+
export type NovaConfig = z.infer<typeof NovaConfigSchema>;
|
|
37
|
+
|
|
33
38
|
export const GatewayConfigSchema = z.object({
|
|
34
39
|
development: z.string(),
|
|
35
40
|
production: z.string(),
|
|
41
|
+
account: z.string().optional(),
|
|
42
|
+
nova: NovaConfigSchema.optional(),
|
|
36
43
|
});
|
|
37
44
|
export type GatewayConfig = z.infer<typeof GatewayConfigSchema>;
|
|
38
45
|
|
|
@@ -54,6 +61,7 @@ export type SyncConfig = z.infer<typeof SyncConfigSchema>;
|
|
|
54
61
|
export const BosConfigSchema = z.object({
|
|
55
62
|
account: z.string(),
|
|
56
63
|
testnet: z.string().optional(),
|
|
64
|
+
nova: NovaConfigSchema.optional(),
|
|
57
65
|
gateway: GatewayConfigSchema,
|
|
58
66
|
template: z.string().optional(),
|
|
59
67
|
cli: z.object({
|