dcl-catalyst-client 15.0.1 → 17.0.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/.eslintignore +2 -1
- package/README.md +50 -44
- package/coverage/clover.xml +352 -442
- package/coverage/coverage-final.json +9 -14
- package/coverage/lcov-report/index.html +47 -32
- package/coverage/lcov.info +656 -892
- package/dist/package.json +77 -0
- package/package.json +16 -19
- package/scripts/generate-snapshots.ts +49 -0
- package/dist/CatalystAPI.d.ts +0 -5
- package/dist/CatalystAPI.js +0 -3
- package/dist/CatalystAPI.js.map +0 -1
- package/dist/CatalystClient.d.ts +0 -46
- package/dist/CatalystClient.js +0 -93
- package/dist/CatalystClient.js.map +0 -1
- package/dist/CatalystsList.d.ts +0 -13
- package/dist/CatalystsList.js +0 -78
- package/dist/CatalystsList.js.map +0 -1
- package/dist/ContentAPI.d.ts +0 -30
- package/dist/ContentAPI.js +0 -3
- package/dist/ContentAPI.js.map +0 -1
- package/dist/ContentClient.d.ts +0 -53
- package/dist/ContentClient.js +0 -175
- package/dist/ContentClient.js.map +0 -1
- package/dist/LambdasAPI.d.ts +0 -38
- package/dist/LambdasAPI.js +0 -3
- package/dist/LambdasAPI.js.map +0 -1
- package/dist/LambdasClient.d.ts +0 -25
- package/dist/LambdasClient.js +0 -112
- package/dist/LambdasClient.js.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -24
- package/dist/index.js.map +0 -1
- package/dist/utils/CatalystClientBuilder.d.ts +0 -5
- package/dist/utils/CatalystClientBuilder.js +0 -53
- package/dist/utils/CatalystClientBuilder.js.map +0 -1
- package/dist/utils/DeploymentBuilder.d.ts +0 -48
- package/dist/utils/DeploymentBuilder.js +0 -180
- package/dist/utils/DeploymentBuilder.js.map +0 -1
- package/dist/utils/Environment.d.ts +0 -1
- package/dist/utils/Environment.js +0 -5
- package/dist/utils/Environment.js.map +0 -1
- package/dist/utils/Helper.d.ts +0 -63
- package/dist/utils/Helper.js +0 -276
- package/dist/utils/Helper.js.map +0 -1
- package/dist/utils/catalystList.d.ts +0 -11
- package/dist/utils/catalystList.js +0 -81
- package/dist/utils/catalystList.js.map +0 -1
- package/dist/utils/common.d.ts +0 -1
- package/dist/utils/common.js +0 -12
- package/dist/utils/common.js.map +0 -1
- package/dist/utils/fetcher.d.ts +0 -11
- package/dist/utils/fetcher.js +0 -57
- package/dist/utils/fetcher.js.map +0 -1
- package/dist/utils/index.d.ts +0 -4
- package/dist/utils/index.js +0 -21
- package/dist/utils/index.js.map +0 -1
- package/scripts/generate-catalysts-list.ts +0 -32
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.DeploymentBuilder = void 0;
|
|
27
|
-
const hashing = __importStar(require("@dcl/hashing"));
|
|
28
|
-
const hashing_1 = require("@dcl/hashing");
|
|
29
|
-
const schemas_1 = require("@dcl/schemas");
|
|
30
|
-
const dcl_catalyst_commons_1 = require("dcl-catalyst-commons");
|
|
31
|
-
class DeploymentBuilder {
|
|
32
|
-
/**
|
|
33
|
-
* Take all the entity's data, build the entity file with it, and calculate its id
|
|
34
|
-
*/
|
|
35
|
-
static async buildEntityAndFile({ type, pointers, timestamp, content, metadata }) {
|
|
36
|
-
var _a;
|
|
37
|
-
// Make sure that there is at least one pointer
|
|
38
|
-
if (pointers.length === 0)
|
|
39
|
-
throw new Error(`All entities must have at least one pointer.`);
|
|
40
|
-
const entity = {
|
|
41
|
-
// default version is V3
|
|
42
|
-
version: 'v3',
|
|
43
|
-
type,
|
|
44
|
-
pointers,
|
|
45
|
-
timestamp,
|
|
46
|
-
content,
|
|
47
|
-
metadata
|
|
48
|
-
};
|
|
49
|
-
// prevent duplicated file names
|
|
50
|
-
if (content) {
|
|
51
|
-
const usedFilenames = new Set();
|
|
52
|
-
for (const a of content) {
|
|
53
|
-
const lowerCasedFileName = a.file.toLowerCase();
|
|
54
|
-
if (usedFilenames.has(lowerCasedFileName)) {
|
|
55
|
-
throw new Error(`Error creating the deployable entity: Decentraland's file system is case insensitive, the file ${JSON.stringify(a.file)} is repeated`);
|
|
56
|
-
}
|
|
57
|
-
usedFilenames.add(lowerCasedFileName);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const entityFile = new TextEncoder().encode(JSON.stringify(entity));
|
|
61
|
-
const entityId = await (0, hashing_1.hashV1)(entityFile);
|
|
62
|
-
const entityWithId = {
|
|
63
|
-
id: entityId,
|
|
64
|
-
...entity
|
|
65
|
-
};
|
|
66
|
-
if (!schemas_1.Entity.validate(entityWithId)) {
|
|
67
|
-
throw new Error('Generated entity is not valid:\n' + ((_a = schemas_1.Entity.validate.errors) === null || _a === void 0 ? void 0 : _a.map(($) => $.message).join('\n')));
|
|
68
|
-
}
|
|
69
|
-
return { entity: entityWithId, entityFile };
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* As part of the deployment process, an entity has to be built. In this method, we are building it, based on the data provided.
|
|
73
|
-
* After the entity is built, the user will have to sign the entity id, to prove they are actually who they say they are.
|
|
74
|
-
*/
|
|
75
|
-
static async buildEntity({ type, pointers, files, metadata, timestamp }) {
|
|
76
|
-
// Reorder input
|
|
77
|
-
const contentFiles = Array.from(files ? files : []).map(([key, content]) => ({
|
|
78
|
-
key,
|
|
79
|
-
content
|
|
80
|
-
}));
|
|
81
|
-
// Calculate hashes
|
|
82
|
-
const allInfo = await Promise.all(contentFiles.map(async ({ key, content }) => ({ key, content, hash: await hashing.hashV1(content) })));
|
|
83
|
-
const hashesByKey = new Map(allInfo.map(({ hash, key }) => [key, hash]));
|
|
84
|
-
const filesByHash = new Map(allInfo.map(({ hash, content }) => [hash, content]));
|
|
85
|
-
return DeploymentBuilder.buildEntityInternal(type, pointers, {
|
|
86
|
-
hashesByKey,
|
|
87
|
-
filesByHash,
|
|
88
|
-
metadata,
|
|
89
|
-
timestamp
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* In cases where we don't need upload content files, we can simply generate the new entity.
|
|
94
|
-
* We can still use already uploaded hashes on this new entity.
|
|
95
|
-
*/
|
|
96
|
-
static async buildEntityWithoutNewFiles({ contentUrl, type, pointers, hashesByKey, metadata, timestamp }) {
|
|
97
|
-
const givenFilesMaps = (hashesByKey !== null && hashesByKey !== void 0 ? hashesByKey : metadata) ? getHashesByKey(metadata) : undefined;
|
|
98
|
-
// When the old entity has the old hashing algorithm, then the full entity with new hash will need to be deployed.
|
|
99
|
-
if (!!givenFilesMaps && isObsoleteProfile(type, givenFilesMaps)) {
|
|
100
|
-
const files = await downloadAllFiles(contentUrl, givenFilesMaps);
|
|
101
|
-
const metadataWithNewHash = await updateMetadata(files, metadata);
|
|
102
|
-
return DeploymentBuilder.buildEntity({
|
|
103
|
-
type,
|
|
104
|
-
pointers,
|
|
105
|
-
files,
|
|
106
|
-
metadata: metadataWithNewHash,
|
|
107
|
-
timestamp
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
return DeploymentBuilder.buildEntityInternal(type, pointers, { hashesByKey, metadata, timestamp });
|
|
111
|
-
}
|
|
112
|
-
static async buildEntityInternal(type, pointers, options) {
|
|
113
|
-
// Make sure that there is at least one pointer
|
|
114
|
-
if (pointers.length === 0) {
|
|
115
|
-
throw new Error(`All entities must have at least one pointer.`);
|
|
116
|
-
}
|
|
117
|
-
// Re-organize the hashes
|
|
118
|
-
const hashesByKey = (options === null || options === void 0 ? void 0 : options.hashesByKey) ? options === null || options === void 0 ? void 0 : options.hashesByKey : new Map();
|
|
119
|
-
const entityContent = Array.from(hashesByKey.entries()).map(([key, hash]) => ({
|
|
120
|
-
file: key,
|
|
121
|
-
hash
|
|
122
|
-
}));
|
|
123
|
-
// Calculate timestamp if necessary
|
|
124
|
-
const timestamp = (options === null || options === void 0 ? void 0 : options.timestamp) ? options === null || options === void 0 ? void 0 : options.timestamp : Date.now();
|
|
125
|
-
// Build entity file
|
|
126
|
-
const { entity, entityFile } = await DeploymentBuilder.buildEntityAndFile({
|
|
127
|
-
type,
|
|
128
|
-
pointers,
|
|
129
|
-
timestamp,
|
|
130
|
-
content: entityContent,
|
|
131
|
-
metadata: options === null || options === void 0 ? void 0 : options.metadata
|
|
132
|
-
});
|
|
133
|
-
// Add entity file to content files
|
|
134
|
-
const filesByHash = (options === null || options === void 0 ? void 0 : options.filesByHash) ? options.filesByHash : new Map();
|
|
135
|
-
filesByHash.set(entity.id, entityFile);
|
|
136
|
-
return { files: filesByHash, entityId: entity.id };
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
exports.DeploymentBuilder = DeploymentBuilder;
|
|
140
|
-
function isObsoleteProfile(type, hashesByKey) {
|
|
141
|
-
return type === schemas_1.EntityType.PROFILE && Array.from(hashesByKey).some(([, hash]) => hash.toLowerCase().startsWith('qm'));
|
|
142
|
-
}
|
|
143
|
-
async function downloadAllFiles(contentUrl, hashes) {
|
|
144
|
-
const oldBodyHash = hashes.get('body.png');
|
|
145
|
-
const bodyUrl = new URL(`${contentUrl}/contents/${oldBodyHash}`).toString();
|
|
146
|
-
const bodyFileContent = await (0, dcl_catalyst_commons_1.fetchArrayBuffer)(bodyUrl);
|
|
147
|
-
const oldFaceHash = hashes.get('face256.png');
|
|
148
|
-
const faceUrl = new URL(`${contentUrl}/contents/${oldFaceHash}`).toString();
|
|
149
|
-
const faceFileContent = await (0, dcl_catalyst_commons_1.fetchArrayBuffer)(faceUrl);
|
|
150
|
-
return new Map([
|
|
151
|
-
['body.png', bodyFileContent],
|
|
152
|
-
['face256.png', faceFileContent]
|
|
153
|
-
]);
|
|
154
|
-
}
|
|
155
|
-
async function updateMetadata(files, metadata) {
|
|
156
|
-
if (!metadata)
|
|
157
|
-
return metadata;
|
|
158
|
-
metadata.avatars = await Promise.all(metadata.avatars.map(async (avatar) => {
|
|
159
|
-
const newSnapshots = { face256: '', body: '' };
|
|
160
|
-
const face256Content = files.get('face256.png');
|
|
161
|
-
if (!!face256Content) {
|
|
162
|
-
newSnapshots['face256'] = await (0, hashing_1.hashV1)(face256Content);
|
|
163
|
-
}
|
|
164
|
-
const bodyContent = files.get('body.png');
|
|
165
|
-
if (!!bodyContent) {
|
|
166
|
-
newSnapshots['body'] = await (0, hashing_1.hashV1)(bodyContent);
|
|
167
|
-
}
|
|
168
|
-
avatar.avatar.snapshots = newSnapshots;
|
|
169
|
-
return avatar;
|
|
170
|
-
}));
|
|
171
|
-
return metadata;
|
|
172
|
-
}
|
|
173
|
-
function getHashesByKey(metadata) {
|
|
174
|
-
const avatar = metadata.avatars[0];
|
|
175
|
-
return new Map([
|
|
176
|
-
['body.png', avatar.avatar.snapshots.body],
|
|
177
|
-
['face256.png', avatar.avatar.snapshots.face256]
|
|
178
|
-
]);
|
|
179
|
-
}
|
|
180
|
-
//# sourceMappingURL=DeploymentBuilder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DeploymentBuilder.js","sourceRoot":"","sources":["../../src/utils/DeploymentBuilder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAuC;AACvC,0CAAqC;AACrC,0CAAqF;AACrF,+DAAuD;AAEvD,MAAa,iBAAiB;IAC5B;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAC9B,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,OAAO,EACP,QAAQ,EAOT;;QACC,+CAA+C;QAC/C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;QAE1F,MAAM,MAAM,GAAG;YACb,wBAAwB;YACxB,OAAO,EAAE,IAAI;YACb,IAAI;YACJ,QAAQ;YACR,SAAS;YACT,OAAO;YACP,QAAQ;SACT,CAAA;QAED,gCAAgC;QAChC,IAAI,OAAO,EAAE;YACX,MAAM,aAAa,GAAG,IAAI,GAAG,EAAU,CAAA;YACvC,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE;gBACvB,MAAM,kBAAkB,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAA;gBAC/C,IAAI,aAAa,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE;oBACzC,MAAM,IAAI,KAAK,CACb,kGAAkG,IAAI,CAAC,SAAS,CAC9G,CAAC,CAAC,IAAI,CACP,cAAc,CAChB,CAAA;iBACF;gBACD,aAAa,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;aACtC;SACF;QAED,MAAM,UAAU,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;QAEnE,MAAM,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AO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QACjD,MAAM,YAAY,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAA;QAE9C,MAAM,cAAc,GAAG,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;QAC/C,IAAI,CAAC,CAAC,cAAc,EAAE;YACpB,YAAY,CAAC,SAAS,CAAC,GAAG,MAAM,IAAA,gBAAM,EAAC,cAAc,CAAC,CAAA;SACvD;QACD,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QACzC,IAAI,CAAC,CAAC,WAAW,EAAE;YACjB,YAAY,CAAC,MAAM,CAAC,GAAG,MAAM,IAAA,gBAAM,EAAC,WAAW,CAAC,CAAA;SACjD;QACD,MAAM,CAAC,MAAM,CAAC,SAAS,GAAG,YAAY,CAAA;QACtC,OAAO,MAAM,CAAA;IACf,CAAC,CAAC,CACH,CAAA;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC;AACD,SAAS,cAAc,CAAC,QAAa;IACnC,MAAM,MAAM,GAAI,QAAoB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IAC/C,OAAO,IAAI,GAAG,CAAC;QACb,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;QAC1C,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC;KACjD,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const RUNNING_VERSION: string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Environment.js","sourceRoot":"","sources":["../../src/utils/Environment.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAA"}
|
package/dist/utils/Helper.d.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type FormData from 'form-data';
|
|
2
|
-
import { IFetchComponent, RequestOptions } from './fetcher';
|
|
3
|
-
export declare function addModelToFormData(model: any, form: FormData, namespace?: string): FormData;
|
|
4
|
-
/**
|
|
5
|
-
* This method performs one or more fetches to the given server, splitting query params into different queries to avoid exceeding the max length of urls
|
|
6
|
-
*/
|
|
7
|
-
export declare const MAX_URL_LENGTH: number;
|
|
8
|
-
export declare function splitAndFetch<E>({ baseUrl, path, queryParams, fetcher, uniqueBy, options }: Omit<SplitAndFetchParams<E>, 'elementsProperty'>): Promise<E[]>;
|
|
9
|
-
/**
|
|
10
|
-
* This method performs one or more fetches to the given server, splitting query params into different queries to avoid exceeding the max length of urls
|
|
11
|
-
* This method should be used if the result is paginated, and needs to be queries many times
|
|
12
|
-
*/
|
|
13
|
-
export declare function splitAndFetchPaginated<E>({ baseUrl, path, queryParams, elementsProperty, uniqueBy, options, fetcher }: RequiredOne<SplitAndFetchParams<E>, 'uniqueBy'>): Promise<E[]>;
|
|
14
|
-
export declare function splitValuesIntoManyQueryBuilders({ queryParams, baseUrl, path, reservedParams }: SplitIntoQueriesParams): QueryBuilder[];
|
|
15
|
-
export declare function splitValuesIntoManyQueries(parameters: SplitIntoQueriesParams): string[];
|
|
16
|
-
export declare function convertFiltersToQueryParams(filters?: Record<string, any>): Map<string, string[]>;
|
|
17
|
-
export declare function isNode(): boolean;
|
|
18
|
-
export declare function getHeadersWithUserAgent(client: string): {
|
|
19
|
-
'User-Agent': string;
|
|
20
|
-
} | undefined;
|
|
21
|
-
export declare function mergeRequestOptions(target: RequestOptions, source?: RequestOptions): RequestOptions;
|
|
22
|
-
/** Remove white spaces and add https if no protocol is specified */
|
|
23
|
-
export declare function sanitizeUrl(url: string): string;
|
|
24
|
-
type RequiredOne<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
25
|
-
type QueryParams = {
|
|
26
|
-
name: string;
|
|
27
|
-
values: string[];
|
|
28
|
-
} | Map<string, string[]>;
|
|
29
|
-
type SplitIntoQueriesParams = {
|
|
30
|
-
baseUrl: string;
|
|
31
|
-
path: string;
|
|
32
|
-
queryParams: QueryParams;
|
|
33
|
-
reservedParams?: Map<string, number>;
|
|
34
|
-
};
|
|
35
|
-
type SplitAndFetchParams<E> = {
|
|
36
|
-
baseUrl: string;
|
|
37
|
-
path: string;
|
|
38
|
-
queryParams: QueryParams;
|
|
39
|
-
elementsProperty: string;
|
|
40
|
-
uniqueBy?: keyof E;
|
|
41
|
-
fetcher?: IFetchComponent;
|
|
42
|
-
options?: RequestOptions;
|
|
43
|
-
};
|
|
44
|
-
export declare class QueryBuilder {
|
|
45
|
-
private readonly baseUrl;
|
|
46
|
-
private readonly queryParams;
|
|
47
|
-
private readonly reservedParams;
|
|
48
|
-
private length;
|
|
49
|
-
constructor(baseUrl: string, queryParams?: Map<string, string[]>, reservedParams?: Map<string, number>);
|
|
50
|
-
canAddParam(paramName: string, paramValue: string): boolean;
|
|
51
|
-
addParam(paramName: string, paramValue: string): this;
|
|
52
|
-
canSetParams(paramName: string, paramValues: any[]): boolean;
|
|
53
|
-
/** This action will override whatever configuration there was previously for the given query parameter */
|
|
54
|
-
setParams(paramName: string, paramValues: (string | number)[]): this;
|
|
55
|
-
/** This action will override whatever configuration there was previously for the given query parameter */
|
|
56
|
-
setParam(paramName: string, paramValue: string | number): this;
|
|
57
|
-
toString(): string;
|
|
58
|
-
private calculateUrlLength;
|
|
59
|
-
static clone(queryBuilder: QueryBuilder): QueryBuilder;
|
|
60
|
-
private calculateAddedLength;
|
|
61
|
-
private calculateArrayLength;
|
|
62
|
-
}
|
|
63
|
-
export {};
|
package/dist/utils/Helper.js
DELETED
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QueryBuilder = exports.sanitizeUrl = exports.mergeRequestOptions = exports.getHeadersWithUserAgent = exports.isNode = exports.convertFiltersToQueryParams = exports.splitValuesIntoManyQueries = exports.splitValuesIntoManyQueryBuilders = exports.splitAndFetchPaginated = exports.splitAndFetch = exports.MAX_URL_LENGTH = exports.addModelToFormData = void 0;
|
|
4
|
-
const Environment_1 = require("./Environment");
|
|
5
|
-
const fetcher_1 = require("./fetcher");
|
|
6
|
-
function addModelToFormData(model, form, namespace = '') {
|
|
7
|
-
for (const propertyName in model) {
|
|
8
|
-
if (!model.hasOwnProperty(propertyName) || model[propertyName] === null || model[propertyName] === undefined)
|
|
9
|
-
continue;
|
|
10
|
-
const formKey = namespace ? `${namespace}[${propertyName}]` : propertyName;
|
|
11
|
-
if (model[propertyName] instanceof Date) {
|
|
12
|
-
form.append(formKey, model[propertyName].toISOString());
|
|
13
|
-
}
|
|
14
|
-
else if (model[propertyName] instanceof Array) {
|
|
15
|
-
model[propertyName].forEach((element, index) => {
|
|
16
|
-
const tempFormKey = `${formKey}[${index}]`;
|
|
17
|
-
addModelToFormData(element, form, tempFormKey);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
else if (typeof model[propertyName] === 'object') {
|
|
21
|
-
addModelToFormData(model[propertyName], form, formKey);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
form.append(formKey, model[propertyName].toString());
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return form;
|
|
28
|
-
}
|
|
29
|
-
exports.addModelToFormData = addModelToFormData;
|
|
30
|
-
function removeDuplicates(array) {
|
|
31
|
-
return Array.from(new Set(array));
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* This method performs one or more fetches to the given server, splitting query params into different queries to avoid exceeding the max length of urls
|
|
35
|
-
*/
|
|
36
|
-
exports.MAX_URL_LENGTH = 2048;
|
|
37
|
-
async function splitAndFetch({ baseUrl, path, queryParams, fetcher, uniqueBy, options }) {
|
|
38
|
-
// Adding default
|
|
39
|
-
fetcher = fetcher ? fetcher : (0, fetcher_1.createFetchComponent)();
|
|
40
|
-
// Split values into different queries
|
|
41
|
-
const queries = splitValuesIntoManyQueries({ baseUrl, path, queryParams });
|
|
42
|
-
const results = new Map();
|
|
43
|
-
for (const query of queries) {
|
|
44
|
-
// Perform the different queries
|
|
45
|
-
const elements = (await (await fetcher.fetch(query, { ...options, headers: { 'Content-Type': 'application/json' } })).json());
|
|
46
|
-
// Group by unique property (if set), or add all of them to the map
|
|
47
|
-
elements.forEach((element) => results.set(uniqueBy ? element[uniqueBy] : results.size, element));
|
|
48
|
-
}
|
|
49
|
-
// Return results
|
|
50
|
-
return Array.from(results.values());
|
|
51
|
-
}
|
|
52
|
-
exports.splitAndFetch = splitAndFetch;
|
|
53
|
-
const CHARS_LEFT_FOR_OFFSET = 7;
|
|
54
|
-
/**
|
|
55
|
-
* This method performs one or more fetches to the given server, splitting query params into different queries to avoid exceeding the max length of urls
|
|
56
|
-
* This method should be used if the result is paginated, and needs to be queries many times
|
|
57
|
-
*/
|
|
58
|
-
async function splitAndFetchPaginated({ baseUrl, path, queryParams, elementsProperty, uniqueBy, options, fetcher }) {
|
|
59
|
-
// Set default
|
|
60
|
-
fetcher = fetcher ? fetcher : (0, fetcher_1.createFetchComponent)();
|
|
61
|
-
// Reserve a few chars to send the offset
|
|
62
|
-
const reservedParams = new Map([['offset', CHARS_LEFT_FOR_OFFSET]]);
|
|
63
|
-
// Split values into different queries
|
|
64
|
-
const queries = splitValuesIntoManyQueries({ baseUrl, path, queryParams, reservedParams });
|
|
65
|
-
// Perform the different queries
|
|
66
|
-
const foundElements = new Map();
|
|
67
|
-
let exit = false;
|
|
68
|
-
for (let i = 0; i < queries.length && !exit; i++) {
|
|
69
|
-
let url = queries[i];
|
|
70
|
-
while (url && !exit) {
|
|
71
|
-
try {
|
|
72
|
-
const response = (await fetcher.fetch(url, options)).json();
|
|
73
|
-
const elements = response[elementsProperty];
|
|
74
|
-
elements.forEach((element) => foundElements.set(element[uniqueBy], element));
|
|
75
|
-
const nextRelative = response.pagination.next;
|
|
76
|
-
url = nextRelative ? new URL(nextRelative, url).toString() : undefined;
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
exit = true;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return Array.from(foundElements.values());
|
|
84
|
-
}
|
|
85
|
-
exports.splitAndFetchPaginated = splitAndFetchPaginated;
|
|
86
|
-
function splitValuesIntoManyQueryBuilders({ queryParams, baseUrl, path, reservedParams }) {
|
|
87
|
-
const queryParamsMap = 'name' in queryParams ? new Map([[queryParams.name, queryParams.values]]) : queryParams;
|
|
88
|
-
// Check that it makes sent to apply the algorithm
|
|
89
|
-
if (queryParamsMap.size === 0) {
|
|
90
|
-
return [new QueryBuilder(baseUrl + path, queryParamsMap, reservedParams)];
|
|
91
|
-
}
|
|
92
|
-
// Remove duplicates
|
|
93
|
-
const withoutDuplicates = Array.from(queryParamsMap.entries()).map(([name, values]) => [
|
|
94
|
-
name,
|
|
95
|
-
removeDuplicates(values)
|
|
96
|
-
]);
|
|
97
|
-
// Sort params by amount of values
|
|
98
|
-
const sortedByValues = withoutDuplicates.sort(([_, values1], [__, values2]) => values1.length - values2.length);
|
|
99
|
-
// Add all params (except the last one that is the one with the most values) into the url
|
|
100
|
-
const defaultQueryBuilder = new QueryBuilder(baseUrl + path, new Map(), reservedParams);
|
|
101
|
-
for (let i = 0; i < sortedByValues.length - 1; i++) {
|
|
102
|
-
const [paramName, paramValues] = sortedByValues[i];
|
|
103
|
-
if (!defaultQueryBuilder.canSetParams(paramName, paramValues)) {
|
|
104
|
-
throw new Error(`This library can split one query param into many HTTP requests, but it can't split more than one. You will need to do that on the client side.`);
|
|
105
|
-
}
|
|
106
|
-
defaultQueryBuilder.setParams(paramName, paramValues);
|
|
107
|
-
}
|
|
108
|
-
// Prepare everything
|
|
109
|
-
let queryBuilder = QueryBuilder.clone(defaultQueryBuilder);
|
|
110
|
-
const [lastParamName, lastParamValues] = sortedByValues[sortedByValues.length - 1];
|
|
111
|
-
const result = [];
|
|
112
|
-
for (const value of lastParamValues) {
|
|
113
|
-
// Check url length
|
|
114
|
-
if (!queryBuilder.canAddParam(lastParamName, value)) {
|
|
115
|
-
result.push(queryBuilder);
|
|
116
|
-
queryBuilder = QueryBuilder.clone(defaultQueryBuilder);
|
|
117
|
-
}
|
|
118
|
-
queryBuilder.addParam(lastParamName, value);
|
|
119
|
-
}
|
|
120
|
-
// Add current builder one last time
|
|
121
|
-
result.push(queryBuilder);
|
|
122
|
-
return result;
|
|
123
|
-
}
|
|
124
|
-
exports.splitValuesIntoManyQueryBuilders = splitValuesIntoManyQueryBuilders;
|
|
125
|
-
function splitValuesIntoManyQueries(parameters) {
|
|
126
|
-
const builders = splitValuesIntoManyQueryBuilders(parameters);
|
|
127
|
-
return builders.map((builder) => builder.toString());
|
|
128
|
-
}
|
|
129
|
-
exports.splitValuesIntoManyQueries = splitValuesIntoManyQueries;
|
|
130
|
-
function convertFiltersToQueryParams(filters) {
|
|
131
|
-
if (!filters) {
|
|
132
|
-
return new Map();
|
|
133
|
-
}
|
|
134
|
-
const entries = Object.entries(filters)
|
|
135
|
-
.filter(([_, value]) => !!value)
|
|
136
|
-
.map(([name, value]) => {
|
|
137
|
-
const newName = name.endsWith('s') ? name.slice(0, -1) : name;
|
|
138
|
-
let newValues;
|
|
139
|
-
// Force coersion of number, boolean, or string into string
|
|
140
|
-
if (Array.isArray(value)) {
|
|
141
|
-
newValues = [...value].filter(isValidQueryParamValue).map((_) => `${_}`);
|
|
142
|
-
}
|
|
143
|
-
else if (isValidQueryParamValue(value)) {
|
|
144
|
-
newValues = [`${value}`];
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
throw new Error('Query params must be either a string, a number, a boolean or an array of the types just mentioned');
|
|
148
|
-
}
|
|
149
|
-
return [newName, newValues];
|
|
150
|
-
})
|
|
151
|
-
.filter(([_, values]) => values.length > 0);
|
|
152
|
-
return new Map(entries);
|
|
153
|
-
}
|
|
154
|
-
exports.convertFiltersToQueryParams = convertFiltersToQueryParams;
|
|
155
|
-
function isNode() {
|
|
156
|
-
return Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
|
|
157
|
-
}
|
|
158
|
-
exports.isNode = isNode;
|
|
159
|
-
function getHeadersWithUserAgent(client) {
|
|
160
|
-
return isNode()
|
|
161
|
-
? { 'User-Agent': `${client}/${Environment_1.RUNNING_VERSION} (+https://github.com/decentraland/catalyst-client)` }
|
|
162
|
-
: undefined;
|
|
163
|
-
}
|
|
164
|
-
exports.getHeadersWithUserAgent = getHeadersWithUserAgent;
|
|
165
|
-
function mergeRequestOptions(target, source) {
|
|
166
|
-
const combinedHeaders = {
|
|
167
|
-
...target === null || target === void 0 ? void 0 : target.headers,
|
|
168
|
-
...source === null || source === void 0 ? void 0 : source.headers
|
|
169
|
-
};
|
|
170
|
-
return {
|
|
171
|
-
...target,
|
|
172
|
-
...source,
|
|
173
|
-
headers: combinedHeaders
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
exports.mergeRequestOptions = mergeRequestOptions;
|
|
177
|
-
function isValidQueryParamValue(value) {
|
|
178
|
-
return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean';
|
|
179
|
-
}
|
|
180
|
-
/** Remove white spaces and add https if no protocol is specified */
|
|
181
|
-
function sanitizeUrl(url) {
|
|
182
|
-
// Remove empty spaces
|
|
183
|
-
url = url.trim();
|
|
184
|
-
// Add protocol if necessary
|
|
185
|
-
if (!url.startsWith('https://') && !url.startsWith('http://')) {
|
|
186
|
-
url = 'https://' + url;
|
|
187
|
-
}
|
|
188
|
-
// Remove trailing slash if present
|
|
189
|
-
if (url.endsWith('/')) {
|
|
190
|
-
url = url.slice(0, -1);
|
|
191
|
-
}
|
|
192
|
-
return url;
|
|
193
|
-
}
|
|
194
|
-
exports.sanitizeUrl = sanitizeUrl;
|
|
195
|
-
class QueryBuilder {
|
|
196
|
-
constructor(baseUrl, queryParams = new Map(), reservedParams = new Map()) {
|
|
197
|
-
this.baseUrl = baseUrl;
|
|
198
|
-
this.queryParams = queryParams;
|
|
199
|
-
this.reservedParams = reservedParams;
|
|
200
|
-
this.length = this.calculateUrlLength(queryParams, reservedParams);
|
|
201
|
-
}
|
|
202
|
-
canAddParam(paramName, paramValue) {
|
|
203
|
-
return this.length + paramName.length + paramValue.length + 2 < exports.MAX_URL_LENGTH;
|
|
204
|
-
}
|
|
205
|
-
addParam(paramName, paramValue) {
|
|
206
|
-
if (!this.canAddParam(paramName, paramValue)) {
|
|
207
|
-
throw new Error(`You can't add this parameter '${paramName}', since it would exceed the max url length`);
|
|
208
|
-
}
|
|
209
|
-
const queryParam = this.queryParams.get(paramName);
|
|
210
|
-
const values = queryParam ? queryParam : [];
|
|
211
|
-
values.push(paramValue);
|
|
212
|
-
this.queryParams.set(paramName, values);
|
|
213
|
-
this.length += this.calculateAddedLength(paramName, [paramValue]);
|
|
214
|
-
return this;
|
|
215
|
-
}
|
|
216
|
-
canSetParams(paramName, paramValues) {
|
|
217
|
-
const newQueryParams = new Map([...this.queryParams, [paramName, paramValues]]);
|
|
218
|
-
const newLength = this.calculateUrlLength(newQueryParams, this.reservedParams);
|
|
219
|
-
return newLength < exports.MAX_URL_LENGTH;
|
|
220
|
-
}
|
|
221
|
-
/** This action will override whatever configuration there was previously for the given query parameter */
|
|
222
|
-
setParams(paramName, paramValues) {
|
|
223
|
-
if (!this.canSetParams(paramName, paramValues)) {
|
|
224
|
-
throw new Error(`You can't add this parameter '${paramName}', since it would exceed the max url length`);
|
|
225
|
-
}
|
|
226
|
-
this.queryParams.set(paramName, paramValues.map((value) => `${value}`));
|
|
227
|
-
this.length = this.calculateUrlLength(this.queryParams, this.reservedParams);
|
|
228
|
-
return this;
|
|
229
|
-
}
|
|
230
|
-
/** This action will override whatever configuration there was previously for the given query parameter */
|
|
231
|
-
setParam(paramName, paramValue) {
|
|
232
|
-
this.setParams(paramName, [paramValue]);
|
|
233
|
-
return this;
|
|
234
|
-
}
|
|
235
|
-
toString() {
|
|
236
|
-
let url = this.baseUrl;
|
|
237
|
-
let addedParamAlready = false;
|
|
238
|
-
for (const [paramName, paramValues] of this.queryParams) {
|
|
239
|
-
for (const paramValue of paramValues) {
|
|
240
|
-
if (addedParamAlready) {
|
|
241
|
-
url += `&${paramName}=${paramValue}`;
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
url += `?${paramName}=${paramValue}`;
|
|
245
|
-
addedParamAlready = true;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
return url;
|
|
250
|
-
}
|
|
251
|
-
calculateUrlLength(queryParams, reservedParams) {
|
|
252
|
-
let length = this.baseUrl.length;
|
|
253
|
-
for (const [paramName, reserved] of reservedParams) {
|
|
254
|
-
if (!this.queryParams.has(paramName)) {
|
|
255
|
-
// We will avoid the reserved parameters that already have a value set
|
|
256
|
-
length += paramName.length + 2 + reserved;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
for (const [paramName, paramValues] of queryParams) {
|
|
260
|
-
length += this.calculateAddedLength(paramName, paramValues);
|
|
261
|
-
}
|
|
262
|
-
return length;
|
|
263
|
-
}
|
|
264
|
-
static clone(queryBuilder) {
|
|
265
|
-
return new QueryBuilder(queryBuilder.baseUrl, new Map(queryBuilder.queryParams), queryBuilder.reservedParams);
|
|
266
|
-
}
|
|
267
|
-
calculateAddedLength(paramName, paramValues) {
|
|
268
|
-
const valuesLength = this.calculateArrayLength(paramValues);
|
|
269
|
-
return valuesLength + (paramName.length + 2) * paramValues.length;
|
|
270
|
-
}
|
|
271
|
-
calculateArrayLength(array) {
|
|
272
|
-
return array.map((value) => `${value}`).reduce((accum, curr) => accum + curr.length, 0);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
exports.QueryBuilder = QueryBuilder;
|
|
276
|
-
//# sourceMappingURL=Helper.js.map
|
package/dist/utils/Helper.js.map
DELETED
|
@@ -1 +0,0 @@
|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
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { CatalystConnectOptions } from '../CatalystClient';
|
|
2
|
-
export type KnownServersOptions = {
|
|
3
|
-
preKnownServers: {
|
|
4
|
-
list: {
|
|
5
|
-
address: string;
|
|
6
|
-
}[];
|
|
7
|
-
} | CatalystConnectOptions;
|
|
8
|
-
requiredLists?: number;
|
|
9
|
-
fetchApprovedCatalysts?: (catalystUrl: string) => Promise<string[] | undefined>;
|
|
10
|
-
};
|
|
11
|
-
export declare function getUpdatedApprovedListWithoutQueryingContract(options: KnownServersOptions): Promise<string[] | undefined>;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getUpdatedApprovedListWithoutQueryingContract = void 0;
|
|
7
|
-
const CatalystClient_1 = require("../CatalystClient");
|
|
8
|
-
const CatalystsList_1 = __importDefault(require("../CatalystsList"));
|
|
9
|
-
const common_1 = require("./common");
|
|
10
|
-
/**
|
|
11
|
-
* The idea here is to build an updated list of the catalysts approved by the DAO, without actually querying the DAO's contract
|
|
12
|
-
* directly. This is because that query is both slow and expensive, so the idea is to use a list of known servers and ask them
|
|
13
|
-
* for the updated list. The thing is this known server list might be outdated, so we need to take that into account. We will
|
|
14
|
-
* take N (defined by REQUIRED_LISTS below) random servers from this known list, and ask them for the currently approved ones. We will then use the intersection of those
|
|
15
|
-
* N lists as the updated list.
|
|
16
|
-
*/
|
|
17
|
-
const REQUIRED_LISTS = 3;
|
|
18
|
-
async function getUpdatedApprovedListWithoutQueryingContract(options) {
|
|
19
|
-
// Set defaults if needed
|
|
20
|
-
const catalystListFetch = options.fetchApprovedCatalysts
|
|
21
|
-
? options.fetchApprovedCatalysts
|
|
22
|
-
: (catalystUrl) => fetchCatalystsApprovedByDAO(catalystUrl);
|
|
23
|
-
const requiredAmountOfLists = options.requiredLists ? options.requiredLists : REQUIRED_LISTS;
|
|
24
|
-
// Get the list of known servers
|
|
25
|
-
const knownServers = 'list' in options.preKnownServers ? options.preKnownServers.list : CatalystsList_1.default[options.preKnownServers.network];
|
|
26
|
-
// If I don't know enough servers, then it doesn't make sense to continue
|
|
27
|
-
if (knownServers.length < requiredAmountOfLists) {
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
// Shuffle the list
|
|
31
|
-
const shuffledPreKnownServers = (0, common_1.shuffleArray)(knownServers);
|
|
32
|
-
// Ask N of them for their list
|
|
33
|
-
const approvedServersList = await Promise.all(shuffledPreKnownServers
|
|
34
|
-
.slice(0, requiredAmountOfLists + 3)
|
|
35
|
-
.map((server) => server.address)
|
|
36
|
-
.map((address) => catalystListFetch(address)));
|
|
37
|
-
// Removed any failures
|
|
38
|
-
const allLists = approvedServersList.filter((approvedServerList) => !!approvedServerList);
|
|
39
|
-
// Check if we need to ask for anyone else's list
|
|
40
|
-
let i = requiredAmountOfLists + 3;
|
|
41
|
-
while (i < shuffledPreKnownServers.length && allLists.length < requiredAmountOfLists) {
|
|
42
|
-
const list = await catalystListFetch(shuffledPreKnownServers[i].address);
|
|
43
|
-
if (list) {
|
|
44
|
-
allLists.push(list);
|
|
45
|
-
}
|
|
46
|
-
i++;
|
|
47
|
-
}
|
|
48
|
-
// If I didn't manage to get al least N lists from different sources, then abort
|
|
49
|
-
if (allLists.length < requiredAmountOfLists) {
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
// Calculate the intersection
|
|
53
|
-
const intersection = calculateIntersection(allLists);
|
|
54
|
-
return intersection.length > 0 ? intersection : undefined;
|
|
55
|
-
}
|
|
56
|
-
exports.getUpdatedApprovedListWithoutQueryingContract = getUpdatedApprovedListWithoutQueryingContract;
|
|
57
|
-
function calculateIntersection(lists) {
|
|
58
|
-
const count = new Map();
|
|
59
|
-
for (const list of lists) {
|
|
60
|
-
for (const element of list) {
|
|
61
|
-
const i = count.get(element);
|
|
62
|
-
count.set(element, (i ? i : 0) + 1);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return Array.from(count.entries())
|
|
66
|
-
.filter(([_, count]) => count === lists.length)
|
|
67
|
-
.map(([element]) => element);
|
|
68
|
-
}
|
|
69
|
-
async function fetchCatalystsApprovedByDAO(catalystUrl) {
|
|
70
|
-
const client = new CatalystClient_1.CatalystClient({
|
|
71
|
-
catalystUrl
|
|
72
|
-
});
|
|
73
|
-
try {
|
|
74
|
-
const servers = await client.fetchCatalystsApprovedByDAO({ timeout: 10000 });
|
|
75
|
-
return servers.map(({ baseUrl }) => baseUrl);
|
|
76
|
-
}
|
|
77
|
-
catch (_a) {
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=catalystList.js.map
|