@didcid/gatekeeper 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/LICENSE +21 -0
- package/README.md +65 -0
- package/dist/cjs/abstract-json-BJMq-iEa.cjs +216 -0
- package/dist/cjs/db/json-cache.cjs +75 -0
- package/dist/cjs/db/json-memory.cjs +29 -0
- package/dist/cjs/db/json.cjs +36 -0
- package/dist/cjs/db/mongo.cjs +242 -0
- package/dist/cjs/db/redis.cjs +291 -0
- package/dist/cjs/db/sqlite.cjs +330 -0
- package/dist/cjs/errors-DQaog-FG.cjs +34 -0
- package/dist/cjs/gatekeeper-client.cjs +369 -0
- package/dist/cjs/gatekeeper.cjs +42212 -0
- package/dist/cjs/index.cjs +12 -0
- package/dist/cjs/node.cjs +40 -0
- package/dist/esm/db/abstract-json.js +212 -0
- package/dist/esm/db/abstract-json.js.map +1 -0
- package/dist/esm/db/json-cache.js +68 -0
- package/dist/esm/db/json-cache.js.map +1 -0
- package/dist/esm/db/json-memory.js +22 -0
- package/dist/esm/db/json-memory.js.map +1 -0
- package/dist/esm/db/json.js +29 -0
- package/dist/esm/db/json.js.map +1 -0
- package/dist/esm/db/mongo.js +236 -0
- package/dist/esm/db/mongo.js.map +1 -0
- package/dist/esm/db/redis.js +285 -0
- package/dist/esm/db/redis.js.map +1 -0
- package/dist/esm/db/sqlite.js +305 -0
- package/dist/esm/db/sqlite.js.map +1 -0
- package/dist/esm/gatekeeper-client.js +363 -0
- package/dist/esm/gatekeeper-client.js.map +1 -0
- package/dist/esm/gatekeeper.js +1090 -0
- package/dist/esm/gatekeeper.js.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/node.js +8 -0
- package/dist/esm/node.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/types/db/abstract-json.d.ts +26 -0
- package/dist/types/db/json-cache.d.ts +14 -0
- package/dist/types/db/json-memory.d.ts +9 -0
- package/dist/types/db/json.d.ts +8 -0
- package/dist/types/db/mongo.d.ts +23 -0
- package/dist/types/db/redis.d.ts +29 -0
- package/dist/types/db/sqlite.d.ts +30 -0
- package/dist/types/gatekeeper-client.d.ts +40 -0
- package/dist/types/gatekeeper.d.ts +67 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/node.d.ts +7 -0
- package/dist/types/types.d.ts +226 -0
- package/package.json +128 -0
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var axiosModule = require('axios');
|
|
6
|
+
|
|
7
|
+
const VERSION = '/api/v1';
|
|
8
|
+
function throwError(error) {
|
|
9
|
+
if (error.response) {
|
|
10
|
+
throw error.response.data;
|
|
11
|
+
}
|
|
12
|
+
throw error.message;
|
|
13
|
+
}
|
|
14
|
+
class GatekeeperClient {
|
|
15
|
+
API;
|
|
16
|
+
axios;
|
|
17
|
+
// Factory method
|
|
18
|
+
static async create(options) {
|
|
19
|
+
const gatekeeper = new GatekeeperClient();
|
|
20
|
+
await gatekeeper.connect(options);
|
|
21
|
+
return gatekeeper;
|
|
22
|
+
}
|
|
23
|
+
constructor() {
|
|
24
|
+
const axios = axiosModule?.default ??
|
|
25
|
+
axiosModule;
|
|
26
|
+
this.API = VERSION;
|
|
27
|
+
this.axios = axios.create();
|
|
28
|
+
}
|
|
29
|
+
addCustomHeader(header, value) {
|
|
30
|
+
this.axios.defaults.headers.common[header] = value;
|
|
31
|
+
}
|
|
32
|
+
removeCustomHeader(header) {
|
|
33
|
+
delete this.axios.defaults.headers.common[header];
|
|
34
|
+
}
|
|
35
|
+
async connect(options) {
|
|
36
|
+
if (options?.url) {
|
|
37
|
+
this.API = `${options.url}${VERSION}`;
|
|
38
|
+
}
|
|
39
|
+
// Only used for unit testing
|
|
40
|
+
// TBD replace console with a real logging package
|
|
41
|
+
if (options?.console) {
|
|
42
|
+
// eslint-disable-next-line
|
|
43
|
+
console = options.console;
|
|
44
|
+
}
|
|
45
|
+
if (options?.waitUntilReady) {
|
|
46
|
+
await this.waitUntilReady(options);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async waitUntilReady(options) {
|
|
50
|
+
let { intervalSeconds = 5, chatty = false, becomeChattyAfter = 0, maxRetries = 0 } = options;
|
|
51
|
+
let ready = false;
|
|
52
|
+
let retries = 0;
|
|
53
|
+
if (chatty) {
|
|
54
|
+
console.log(`Connecting to gatekeeper at ${this.API}`);
|
|
55
|
+
}
|
|
56
|
+
while (!ready) {
|
|
57
|
+
ready = await this.isReady();
|
|
58
|
+
if (!ready) {
|
|
59
|
+
if (chatty) {
|
|
60
|
+
console.log('Waiting for Gatekeeper to be ready...');
|
|
61
|
+
}
|
|
62
|
+
// wait for 1 second before checking again
|
|
63
|
+
await new Promise(resolve => setTimeout(resolve, intervalSeconds * 1000));
|
|
64
|
+
}
|
|
65
|
+
retries += 1;
|
|
66
|
+
if (maxRetries > 0 && retries > maxRetries) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (!chatty && becomeChattyAfter > 0 && retries > becomeChattyAfter) {
|
|
70
|
+
console.log(`Connecting to gatekeeper at ${this.API}`);
|
|
71
|
+
chatty = true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (chatty) {
|
|
75
|
+
console.log('Gatekeeper service is ready!');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async listRegistries() {
|
|
79
|
+
try {
|
|
80
|
+
const response = await this.axios.get(`${this.API}/registries`);
|
|
81
|
+
return response.data;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
throwError(error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async resetDb() {
|
|
88
|
+
try {
|
|
89
|
+
const response = await this.axios.get(`${this.API}/db/reset`);
|
|
90
|
+
return response.data;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
throwError(error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async verifyDb() {
|
|
97
|
+
try {
|
|
98
|
+
const response = await this.axios.get(`${this.API}/db/verify`);
|
|
99
|
+
return response.data;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
throwError(error);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async isReady() {
|
|
106
|
+
try {
|
|
107
|
+
const response = await this.axios.get(`${this.API}/ready`);
|
|
108
|
+
return response.data;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async getVersion() {
|
|
115
|
+
try {
|
|
116
|
+
const response = await this.axios.get(`${this.API}/version`);
|
|
117
|
+
return response.data;
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
throwError(error);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async getStatus() {
|
|
124
|
+
try {
|
|
125
|
+
const response = await this.axios.get(`${this.API}/status`);
|
|
126
|
+
return response.data;
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
throwError(error);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async createDID(operation) {
|
|
133
|
+
try {
|
|
134
|
+
const response = await this.axios.post(`${this.API}/did`, operation);
|
|
135
|
+
return response.data;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
throwError(error);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async resolveDID(did, options) {
|
|
142
|
+
try {
|
|
143
|
+
if (options) {
|
|
144
|
+
const queryParams = new URLSearchParams(options);
|
|
145
|
+
const response = await this.axios.get(`${this.API}/did/${did}?${queryParams.toString()}`);
|
|
146
|
+
return response.data;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
const response = await this.axios.get(`${this.API}/did/${did}`);
|
|
150
|
+
return response.data;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
throwError(error);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// eslint-disable-next-line sonarjs/no-identical-functions
|
|
158
|
+
async updateDID(operation) {
|
|
159
|
+
try {
|
|
160
|
+
const response = await this.axios.post(`${this.API}/did`, operation);
|
|
161
|
+
return response.data;
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
throwError(error);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// eslint-disable-next-line sonarjs/no-identical-functions
|
|
168
|
+
async deleteDID(operation) {
|
|
169
|
+
try {
|
|
170
|
+
const response = await this.axios.post(`${this.API}/did`, operation);
|
|
171
|
+
return response.data;
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
throwError(error);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async getDIDs(options) {
|
|
178
|
+
try {
|
|
179
|
+
const response = await this.axios.post(`${this.API}/dids`, options);
|
|
180
|
+
return response.data;
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
throwError(error);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async exportDIDs(dids) {
|
|
187
|
+
try {
|
|
188
|
+
const response = await this.axios.post(`${this.API}/dids/export`, { dids });
|
|
189
|
+
return response.data;
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
throwError(error);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async importDIDs(dids) {
|
|
196
|
+
try {
|
|
197
|
+
const response = await this.axios.post(`${this.API}/dids/import`, dids);
|
|
198
|
+
return response.data;
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
throwError(error);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
async exportBatch(dids) {
|
|
205
|
+
try {
|
|
206
|
+
const response = await this.axios.post(`${this.API}/batch/export`, { dids });
|
|
207
|
+
return response.data;
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
throwError(error);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
async importBatch(batch) {
|
|
214
|
+
try {
|
|
215
|
+
const response = await this.axios.post(`${this.API}/batch/import`, batch);
|
|
216
|
+
return response.data;
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
throwError(error);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
async importBatchByCids(cids, metadata) {
|
|
223
|
+
try {
|
|
224
|
+
const response = await this.axios.post(`${this.API}/batch/import/cids`, { cids, metadata });
|
|
225
|
+
return response.data;
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
throwError(error);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
async removeDIDs(dids) {
|
|
232
|
+
try {
|
|
233
|
+
const response = await this.axios.post(`${this.API}/dids/remove`, dids);
|
|
234
|
+
return response.data;
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
throwError(error);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
async getQueue(registry) {
|
|
241
|
+
try {
|
|
242
|
+
const response = await this.axios.get(`${this.API}/queue/${registry}`);
|
|
243
|
+
return response.data;
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
throwError(error);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
async clearQueue(registry, events) {
|
|
250
|
+
try {
|
|
251
|
+
const response = await this.axios.post(`${this.API}/queue/${registry}/clear`, events);
|
|
252
|
+
return response.data;
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
throwError(error);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
async processEvents() {
|
|
259
|
+
try {
|
|
260
|
+
const response = await this.axios.post(`${this.API}/events/process`);
|
|
261
|
+
return response.data;
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
throwError(error);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
async addJSON(data) {
|
|
268
|
+
try {
|
|
269
|
+
const response = await this.axios.post(`${this.API}/ipfs/json`, data);
|
|
270
|
+
return response.data;
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
throwError(error);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
async getJSON(cid) {
|
|
277
|
+
try {
|
|
278
|
+
const response = await this.axios.get(`${this.API}/ipfs/json/${cid}`);
|
|
279
|
+
return response.data;
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
throwError(error);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
async addText(data) {
|
|
286
|
+
try {
|
|
287
|
+
const response = await this.axios.post(`${this.API}/ipfs/text`, data, {
|
|
288
|
+
headers: {
|
|
289
|
+
'Content-Type': 'text/plain'
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
return response.data;
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
throwError(error);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
async getText(cid) {
|
|
299
|
+
try {
|
|
300
|
+
const response = await this.axios.get(`${this.API}/ipfs/text/${cid}`);
|
|
301
|
+
return response.data;
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
throwError(error);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
async addData(data) {
|
|
308
|
+
try {
|
|
309
|
+
const response = await this.axios.post(`${this.API}/ipfs/data`, data, {
|
|
310
|
+
headers: {
|
|
311
|
+
'Content-Type': 'application/octet-stream'
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
return response.data;
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
throwError(error);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
async getData(cid) {
|
|
321
|
+
try {
|
|
322
|
+
const response = await this.axios.get(`${this.API}/ipfs/data/${cid}`, {
|
|
323
|
+
responseType: 'arraybuffer'
|
|
324
|
+
});
|
|
325
|
+
return Buffer.from(response.data);
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
const axiosError = error;
|
|
329
|
+
if (axiosError.response && axiosError.response.data instanceof Uint8Array) {
|
|
330
|
+
const textDecoder = new TextDecoder();
|
|
331
|
+
const errorMessage = textDecoder.decode(axiosError.response.data);
|
|
332
|
+
axiosError.response.data = JSON.parse(errorMessage);
|
|
333
|
+
}
|
|
334
|
+
throwError(axiosError);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
async getBlock(registry, block) {
|
|
338
|
+
try {
|
|
339
|
+
const url = block
|
|
340
|
+
? `${this.API}/block/${registry}/${block}`
|
|
341
|
+
: `${this.API}/block/${registry}/latest`;
|
|
342
|
+
const response = await this.axios.get(url);
|
|
343
|
+
return response.data;
|
|
344
|
+
}
|
|
345
|
+
catch (error) {
|
|
346
|
+
throwError(error);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
async addBlock(registry, block) {
|
|
350
|
+
try {
|
|
351
|
+
const response = await this.axios.post(`${this.API}/block/${registry}`, block);
|
|
352
|
+
return response.data;
|
|
353
|
+
}
|
|
354
|
+
catch (error) {
|
|
355
|
+
throwError(error);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
async generateDID(operation) {
|
|
359
|
+
try {
|
|
360
|
+
const response = await this.axios.post(`${this.API}/did/generate`, operation);
|
|
361
|
+
return response.data;
|
|
362
|
+
}
|
|
363
|
+
catch (error) {
|
|
364
|
+
throwError(error);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
exports.default = GatekeeperClient;
|