@snapshot-labs/snapshot.js 0.8.3 → 0.9.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/index.d.ts +4 -0
- package/dist/schemas/index.d.ts +4 -0
- package/dist/snapshot.cjs.js +35 -5
- package/dist/snapshot.esm.js +35 -5
- package/dist/snapshot.min.js +2 -2
- package/dist/utils.d.ts +3 -1
- package/package.json +1 -1
- package/src/schemas/space.json +4 -1
- package/src/schemas/zodiac.json +2 -1
- package/src/utils.ts +36 -3
package/dist/utils.d.ts
CHANGED
|
@@ -31,7 +31,9 @@ export declare function sendTransaction(web3: any, contractAddress: string, abi:
|
|
|
31
31
|
export declare function getScores(space: string, strategies: Strategy[], network: string, addresses: string[], snapshot?: number | string, scoreApiUrl?: string, options?: any): Promise<any>;
|
|
32
32
|
export declare function getVp(address: string, network: string, strategies: Strategy[], snapshot: number | 'latest', space: string, delegation: boolean, options?: Options): Promise<any>;
|
|
33
33
|
export declare function validate(validation: string, author: string, space: string, network: string, snapshot: number | 'latest', params: any, options: any): Promise<any>;
|
|
34
|
-
export declare function validateSchema(schema: any, data: any
|
|
34
|
+
export declare function validateSchema(schema: any, data: any, options?: {
|
|
35
|
+
snapshotEnv: string;
|
|
36
|
+
}): true | import("ajv").ErrorObject<string, Record<string, any>, unknown>[] | null | undefined;
|
|
35
37
|
export declare function getEnsTextRecord(ens: string, record: string, network?: string, options?: any): Promise<any>;
|
|
36
38
|
export declare function getSpaceUri(id: string, network?: string, options?: any): Promise<string | null>;
|
|
37
39
|
export declare function getEnsOwner(ens: string, network?: string, options?: any): Promise<string | null>;
|
package/package.json
CHANGED
package/src/schemas/space.json
CHANGED
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
},
|
|
80
80
|
"network": {
|
|
81
81
|
"type": "string",
|
|
82
|
+
"snapshotNetwork": true,
|
|
82
83
|
"title": "network",
|
|
83
84
|
"minLength": 1,
|
|
84
85
|
"maxLength": 32
|
|
@@ -114,7 +115,8 @@
|
|
|
114
115
|
"network": {
|
|
115
116
|
"type": "string",
|
|
116
117
|
"maxLength": 12,
|
|
117
|
-
"title": "network"
|
|
118
|
+
"title": "network",
|
|
119
|
+
"snapshotNetwork": true
|
|
118
120
|
},
|
|
119
121
|
"params": {
|
|
120
122
|
"type": "object",
|
|
@@ -346,6 +348,7 @@
|
|
|
346
348
|
},
|
|
347
349
|
"network": {
|
|
348
350
|
"type": "string",
|
|
351
|
+
"snapshotNetwork": true,
|
|
349
352
|
"title": "Network",
|
|
350
353
|
"maxLength": 12
|
|
351
354
|
}
|
package/src/schemas/zodiac.json
CHANGED
package/src/utils.ts
CHANGED
|
@@ -37,7 +37,12 @@ const scoreApiHeaders = {
|
|
|
37
37
|
'Content-Type': 'application/json'
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
const ajv = new Ajv({
|
|
40
|
+
const ajv = new Ajv({
|
|
41
|
+
allErrors: true,
|
|
42
|
+
allowUnionTypes: true,
|
|
43
|
+
$data: true,
|
|
44
|
+
passContext: true
|
|
45
|
+
});
|
|
41
46
|
// @ts-ignore
|
|
42
47
|
addFormats(ajv);
|
|
43
48
|
|
|
@@ -68,6 +73,28 @@ ajv.addFormat('ethValue', {
|
|
|
68
73
|
}
|
|
69
74
|
});
|
|
70
75
|
|
|
76
|
+
const networksIds = Object.keys(networks);
|
|
77
|
+
const mainnetNetworkIds = Object.keys(networks).filter(
|
|
78
|
+
(id) => !networks[id].testnet
|
|
79
|
+
);
|
|
80
|
+
const testnetNetworkIds = Object.keys(networks).filter(
|
|
81
|
+
(id) => networks[id].testnet
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
ajv.addKeyword({
|
|
85
|
+
keyword: 'snapshotNetwork',
|
|
86
|
+
validate: function (schema, data) {
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
const snapshotEnv = this.snapshotEnv || 'default';
|
|
89
|
+
if (snapshotEnv === 'mainnet') return mainnetNetworkIds.includes(data);
|
|
90
|
+
if (snapshotEnv === 'testnet') return testnetNetworkIds.includes(data);
|
|
91
|
+
return networksIds.includes(data);
|
|
92
|
+
},
|
|
93
|
+
error: {
|
|
94
|
+
message: 'must be a valid network used by snapshot'
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
71
98
|
// Custom URL format to allow empty string values
|
|
72
99
|
// https://github.com/snapshot-labs/snapshot.js/pull/541/files
|
|
73
100
|
ajv.addFormat('customUrl', {
|
|
@@ -338,9 +365,15 @@ export async function validate(
|
|
|
338
365
|
}
|
|
339
366
|
}
|
|
340
367
|
|
|
341
|
-
export function validateSchema(
|
|
368
|
+
export function validateSchema(
|
|
369
|
+
schema,
|
|
370
|
+
data,
|
|
371
|
+
options = {
|
|
372
|
+
snapshotEnv: 'default'
|
|
373
|
+
}
|
|
374
|
+
) {
|
|
342
375
|
const ajvValidate = ajv.compile(schema);
|
|
343
|
-
const valid = ajvValidate(data);
|
|
376
|
+
const valid = ajvValidate.call(options, data);
|
|
344
377
|
return valid ? valid : ajvValidate.errors;
|
|
345
378
|
}
|
|
346
379
|
|