prividium 1.3.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands/doctor/probes/authentication/authentication.js +2 -4
- package/dist/cli/commands/doctor/probes/global/input-validation.js +3 -4
- package/dist/cli/commands/doctor/probes/global/well-known.d.ts +2 -0
- package/dist/cli/commands/doctor/probes/global/well-known.js +16 -0
- package/dist/cli/commands/doctor/probes/global.js +9 -1
- package/dist/cli/commands/doctor/report/build.js +3 -1
- package/dist/cli/commands/doctor/types.d.ts +2 -2
- package/dist/cli/commands/doctor/utils.d.ts +1 -1
- package/dist/cli/commands/doctor/utils.js +2 -7
- package/dist/cli/commands/doctor.js +7 -8
- package/dist/cli/commands/proxy.js +12 -74
- package/dist/cli/commands/utils/url-config.d.ts +1 -11
- package/dist/cli/commands/utils/url-config.js +17 -18
- package/dist/cli/server/config-file.d.ts +0 -6
- package/dist/cli/server/config-file.js +2 -9
- package/dist/sdk/admin-api/index.d.ts +1 -1
- package/dist/sdk/admin-api/schemas.d.ts +0 -1
- package/dist/sdk/admin-api/schemas.js +0 -1
- package/dist/sdk/admin-api/types.d.ts +5 -10
- package/dist/sdk/admin-api/users.d.ts +2 -2
- package/dist/sdk/admin-api/users.js +18 -4
- package/dist/sdk/index.d.ts +1 -0
- package/dist/sdk/index.js +1 -0
- package/dist/sdk/siwe.d.ts +1 -1
- package/dist/sdk/well-known.d.ts +30 -0
- package/dist/sdk/well-known.js +58 -0
- package/dist/tsconfig.cli.tsbuildinfo +1 -1
- package/dist/tsconfig.sdk.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const hexSchema = z.templateLiteral(['0x', z.string().regex(/^[0-9a-fA-F]+$/)]);
|
|
3
|
+
const addressSchema = z.templateLiteral(['0x', z.string().regex(/^[0-9a-fA-F]{40}$/)]);
|
|
4
|
+
export const prividiumSystemInfoSchema = z.object({
|
|
5
|
+
blockExplorerUrl: z.url(),
|
|
6
|
+
chainId: hexSchema,
|
|
7
|
+
chainName: z.string(),
|
|
8
|
+
baseToken: z.object({
|
|
9
|
+
name: z.string(),
|
|
10
|
+
symbol: z.string(),
|
|
11
|
+
decimals: z.number(),
|
|
12
|
+
l1Address: addressSchema.nullable()
|
|
13
|
+
}),
|
|
14
|
+
rpcUrl: z.url(),
|
|
15
|
+
userPanelUrl: z.url(),
|
|
16
|
+
version: z.string(),
|
|
17
|
+
l1ChainId: hexSchema,
|
|
18
|
+
l1ChainName: z.string()
|
|
19
|
+
});
|
|
20
|
+
const wellKnownSchema = z.object({
|
|
21
|
+
v1: prividiumSystemInfoSchema
|
|
22
|
+
});
|
|
23
|
+
export class PrividiumWellKnownError extends Error {
|
|
24
|
+
kind;
|
|
25
|
+
constructor(kind, message, options) {
|
|
26
|
+
super(message, options);
|
|
27
|
+
this.name = 'PrividiumWellKnownError';
|
|
28
|
+
this.kind = kind;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const DEFAULT_TIMEOUT_MS = 5000;
|
|
32
|
+
export async function fetchPrividiumConfig(apiUrl, opts) {
|
|
33
|
+
const url = new URL('/.well-known/prividium', apiUrl).toString();
|
|
34
|
+
const doFetch = opts?.fetch ?? fetch;
|
|
35
|
+
const signal = opts?.signal ?? AbortSignal.timeout(DEFAULT_TIMEOUT_MS);
|
|
36
|
+
let response;
|
|
37
|
+
try {
|
|
38
|
+
response = await doFetch(url, { signal });
|
|
39
|
+
}
|
|
40
|
+
catch (cause) {
|
|
41
|
+
throw new PrividiumWellKnownError('network', `Could not reach ${url}: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
42
|
+
}
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
throw new PrividiumWellKnownError('http', `Unexpected HTTP ${response.status} from ${url}`);
|
|
45
|
+
}
|
|
46
|
+
let json;
|
|
47
|
+
try {
|
|
48
|
+
json = await response.json();
|
|
49
|
+
}
|
|
50
|
+
catch (cause) {
|
|
51
|
+
throw new PrividiumWellKnownError('schema', `Response from ${url} was not valid JSON`, { cause });
|
|
52
|
+
}
|
|
53
|
+
const parsed = wellKnownSchema.safeParse(json);
|
|
54
|
+
if (!parsed.success) {
|
|
55
|
+
throw new PrividiumWellKnownError('schema', `Response from ${url} did not match the Prividium well-known shape: ${parsed.error.message}`, { cause: parsed.error });
|
|
56
|
+
}
|
|
57
|
+
return parsed.data.v1;
|
|
58
|
+
}
|