@atproto/common-web 0.2.3 → 0.2.4
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/CHANGELOG.md +6 -0
- package/LICENSE.txt +1 -1
- package/dist/arrays.d.ts +1 -0
- package/dist/async.d.ts +6 -1
- package/dist/did-doc.d.ts +7 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +88 -2
- package/dist/index.js.map +3 -3
- package/dist/ipld.d.ts +2 -2
- package/dist/retry.d.ts +7 -0
- package/dist/strings.d.ts +1 -1
- package/dist/times.d.ts +1 -0
- package/dist/types.d.ts +2 -2
- package/dist/util.d.ts +2 -2
- package/package.json +1 -1
- package/src/arrays.ts +7 -0
- package/src/async.ts +27 -0
- package/src/did-doc.ts +16 -3
- package/src/index.ts +1 -0
- package/src/retry.ts +52 -0
- package/src/times.ts +7 -0
- package/src/util.ts +2 -2
- package/tests/retry.test.ts +93 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atproto/common-web
|
|
2
2
|
|
|
3
|
+
## 0.2.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2302](https://github.com/bluesky-social/atproto/pull/2302) [`4eaadc0ac`](https://github.com/bluesky-social/atproto/commit/4eaadc0acb6b73b9745dd7a2b929d02e58083ab0) Thanks [@dholms](https://github.com/dholms)! - Added methods for parsing labeler verification methods and services in DID Documents
|
|
8
|
+
|
|
3
9
|
## 0.2.3
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/LICENSE.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Dual MIT/Apache-2.0 License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2022-
|
|
3
|
+
Copyright (c) 2022-2024 Bluesky PBC, and Contributors
|
|
4
4
|
|
|
5
5
|
Except as otherwise noted in individual files, this software is licensed under the MIT license (<http://opensource.org/licenses/MIT>), or the Apache License, Version 2.0 (<http://www.apache.org/licenses/LICENSE-2.0>).
|
|
6
6
|
|
package/dist/arrays.d.ts
CHANGED
package/dist/async.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const readFromGenerator: <T>(gen: AsyncGenerator<T, any, unknown>, isDone: (last?: T | undefined) => Promise<boolean> | boolean, waitFor?: Promise<unknown>, maxLength?: number) => Promise<T[]>;
|
|
2
|
-
export
|
|
2
|
+
export type Deferrable = {
|
|
3
3
|
resolve: () => void;
|
|
4
4
|
complete: Promise<void>;
|
|
5
5
|
};
|
|
@@ -11,13 +11,18 @@ export declare class AsyncBuffer<T> {
|
|
|
11
11
|
private buffer;
|
|
12
12
|
private promise;
|
|
13
13
|
private resolve;
|
|
14
|
+
private closed;
|
|
15
|
+
private toThrow;
|
|
14
16
|
constructor(maxSize?: number | undefined);
|
|
15
17
|
get curr(): T[];
|
|
16
18
|
get size(): number;
|
|
19
|
+
get isClosed(): boolean;
|
|
17
20
|
resetPromise(): void;
|
|
18
21
|
push(item: T): void;
|
|
19
22
|
pushMany(items: T[]): void;
|
|
20
23
|
events(): AsyncGenerator<T>;
|
|
24
|
+
throw(err: unknown): void;
|
|
25
|
+
close(): void;
|
|
21
26
|
}
|
|
22
27
|
export declare class AsyncBufferFullError extends Error {
|
|
23
28
|
constructor(maxSize: number);
|
package/dist/did-doc.d.ts
CHANGED
|
@@ -20,12 +20,17 @@ export declare const getSigningKey: (doc: DidDocument) => {
|
|
|
20
20
|
type: string;
|
|
21
21
|
publicKeyMultibase: string;
|
|
22
22
|
} | undefined;
|
|
23
|
+
export declare const getVerificationMaterial: (doc: DidDocument, keyId: string) => {
|
|
24
|
+
type: string;
|
|
25
|
+
publicKeyMultibase: string;
|
|
26
|
+
} | undefined;
|
|
27
|
+
export declare const getSigningDidKey: (doc: DidDocument) => string | undefined;
|
|
23
28
|
export declare const getPdsEndpoint: (doc: DidDocument) => string | undefined;
|
|
24
29
|
export declare const getFeedGenEndpoint: (doc: DidDocument) => string | undefined;
|
|
25
30
|
export declare const getNotifEndpoint: (doc: DidDocument) => string | undefined;
|
|
26
31
|
export declare const getServiceEndpoint: (doc: DidDocument, opts: {
|
|
27
32
|
id: string;
|
|
28
|
-
type
|
|
33
|
+
type?: string;
|
|
29
34
|
}) => string | undefined;
|
|
30
35
|
export declare const didDocument: z.ZodObject<{
|
|
31
36
|
id: z.ZodString;
|
|
@@ -88,4 +93,4 @@ export declare const didDocument: z.ZodObject<{
|
|
|
88
93
|
serviceEndpoint: (string | Record<string, unknown>) & (string | Record<string, unknown> | undefined);
|
|
89
94
|
}[] | undefined;
|
|
90
95
|
}>;
|
|
91
|
-
export
|
|
96
|
+
export type DidDocument = z.infer<typeof didDocument>;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -8827,9 +8827,11 @@ __export(src_exports2, {
|
|
|
8827
8827
|
MINUTE: () => MINUTE,
|
|
8828
8828
|
SECOND: () => SECOND,
|
|
8829
8829
|
TID: () => TID,
|
|
8830
|
+
addHoursToDate: () => addHoursToDate,
|
|
8830
8831
|
allComplete: () => allComplete,
|
|
8831
8832
|
asyncFilter: () => asyncFilter,
|
|
8832
8833
|
b64UrlToUtf8: () => b64UrlToUtf8,
|
|
8834
|
+
backoffMs: () => backoffMs,
|
|
8833
8835
|
bailableWait: () => bailableWait,
|
|
8834
8836
|
check: () => check_exports,
|
|
8835
8837
|
chunkArray: () => chunkArray,
|
|
@@ -8846,7 +8848,9 @@ __export(src_exports2, {
|
|
|
8846
8848
|
getNotifEndpoint: () => getNotifEndpoint,
|
|
8847
8849
|
getPdsEndpoint: () => getPdsEndpoint,
|
|
8848
8850
|
getServiceEndpoint: () => getServiceEndpoint,
|
|
8851
|
+
getSigningDidKey: () => getSigningDidKey,
|
|
8849
8852
|
getSigningKey: () => getSigningKey,
|
|
8853
|
+
getVerificationMaterial: () => getVerificationMaterial,
|
|
8850
8854
|
graphemeLen: () => graphemeLen,
|
|
8851
8855
|
handleAllSettledErrors: () => handleAllSettledErrors,
|
|
8852
8856
|
ipldEquals: () => ipldEquals,
|
|
@@ -8855,6 +8859,7 @@ __export(src_exports2, {
|
|
|
8855
8859
|
isValidDidDoc: () => isValidDidDoc,
|
|
8856
8860
|
jitter: () => jitter,
|
|
8857
8861
|
jsonToIpld: () => jsonToIpld,
|
|
8862
|
+
keyBy: () => keyBy,
|
|
8858
8863
|
lessThanAgoMs: () => lessThanAgoMs,
|
|
8859
8864
|
mapDefined: () => mapDefined,
|
|
8860
8865
|
noUndefinedVals: () => noUndefinedVals,
|
|
@@ -8862,6 +8867,7 @@ __export(src_exports2, {
|
|
|
8862
8867
|
parseLanguage: () => parseLanguage,
|
|
8863
8868
|
range: () => range,
|
|
8864
8869
|
readFromGenerator: () => readFromGenerator,
|
|
8870
|
+
retry: () => retry,
|
|
8865
8871
|
s32decode: () => s32decode,
|
|
8866
8872
|
s32encode: () => s32encode,
|
|
8867
8873
|
schema: () => schema,
|
|
@@ -9007,6 +9013,12 @@ var parseIntWithFallback = (value, fallback) => {
|
|
|
9007
9013
|
};
|
|
9008
9014
|
|
|
9009
9015
|
// src/arrays.ts
|
|
9016
|
+
var keyBy = (arr, key) => {
|
|
9017
|
+
return arr.reduce((acc, cur) => {
|
|
9018
|
+
acc[cur[key]] = cur;
|
|
9019
|
+
return acc;
|
|
9020
|
+
}, {});
|
|
9021
|
+
};
|
|
9010
9022
|
var mapDefined = (arr, fn) => {
|
|
9011
9023
|
const output = [];
|
|
9012
9024
|
for (const item of arr) {
|
|
@@ -9076,6 +9088,7 @@ var AsyncBuffer = class {
|
|
|
9076
9088
|
constructor(maxSize) {
|
|
9077
9089
|
this.maxSize = maxSize;
|
|
9078
9090
|
this.buffer = [];
|
|
9091
|
+
this.closed = false;
|
|
9079
9092
|
this.promise = Promise.resolve();
|
|
9080
9093
|
this.resolve = () => null;
|
|
9081
9094
|
this.resetPromise();
|
|
@@ -9086,6 +9099,9 @@ var AsyncBuffer = class {
|
|
|
9086
9099
|
get size() {
|
|
9087
9100
|
return this.buffer.length;
|
|
9088
9101
|
}
|
|
9102
|
+
get isClosed() {
|
|
9103
|
+
return this.closed;
|
|
9104
|
+
}
|
|
9089
9105
|
resetPromise() {
|
|
9090
9106
|
this.promise = new Promise((r) => this.resolve = r);
|
|
9091
9107
|
}
|
|
@@ -9099,7 +9115,17 @@ var AsyncBuffer = class {
|
|
|
9099
9115
|
}
|
|
9100
9116
|
async *events() {
|
|
9101
9117
|
while (true) {
|
|
9118
|
+
if (this.closed && this.buffer.length === 0) {
|
|
9119
|
+
if (this.toThrow) {
|
|
9120
|
+
throw this.toThrow;
|
|
9121
|
+
} else {
|
|
9122
|
+
return;
|
|
9123
|
+
}
|
|
9124
|
+
}
|
|
9102
9125
|
await this.promise;
|
|
9126
|
+
if (this.toThrow) {
|
|
9127
|
+
throw this.toThrow;
|
|
9128
|
+
}
|
|
9103
9129
|
if (this.maxSize && this.size > this.maxSize) {
|
|
9104
9130
|
throw new AsyncBufferFullError(this.maxSize);
|
|
9105
9131
|
}
|
|
@@ -9112,6 +9138,15 @@ var AsyncBuffer = class {
|
|
|
9112
9138
|
}
|
|
9113
9139
|
}
|
|
9114
9140
|
}
|
|
9141
|
+
throw(err) {
|
|
9142
|
+
this.toThrow = err;
|
|
9143
|
+
this.closed = true;
|
|
9144
|
+
this.resolve();
|
|
9145
|
+
}
|
|
9146
|
+
close() {
|
|
9147
|
+
this.closed = true;
|
|
9148
|
+
this.resolve();
|
|
9149
|
+
}
|
|
9115
9150
|
};
|
|
9116
9151
|
var AsyncBufferFullError = class extends Error {
|
|
9117
9152
|
constructor(maxSize) {
|
|
@@ -10415,6 +10450,43 @@ var ipldEquals = (a, b) => {
|
|
|
10415
10450
|
return a === b;
|
|
10416
10451
|
};
|
|
10417
10452
|
|
|
10453
|
+
// src/retry.ts
|
|
10454
|
+
async function retry(fn, opts = {}) {
|
|
10455
|
+
const { maxRetries = 3, retryable = () => true, getWaitMs = backoffMs } = opts;
|
|
10456
|
+
let retries = 0;
|
|
10457
|
+
let doneError;
|
|
10458
|
+
while (!doneError) {
|
|
10459
|
+
try {
|
|
10460
|
+
return await fn();
|
|
10461
|
+
} catch (err) {
|
|
10462
|
+
const waitMs = getWaitMs(retries);
|
|
10463
|
+
const willRetry = retries < maxRetries && waitMs !== null && retryable(err);
|
|
10464
|
+
if (willRetry) {
|
|
10465
|
+
retries += 1;
|
|
10466
|
+
if (waitMs !== 0) {
|
|
10467
|
+
await wait(waitMs);
|
|
10468
|
+
}
|
|
10469
|
+
} else {
|
|
10470
|
+
doneError = err;
|
|
10471
|
+
}
|
|
10472
|
+
}
|
|
10473
|
+
}
|
|
10474
|
+
throw doneError;
|
|
10475
|
+
}
|
|
10476
|
+
function backoffMs(n, multiplier = 100, max = 1e3) {
|
|
10477
|
+
const exponentialMs = Math.pow(2, n) * multiplier;
|
|
10478
|
+
const ms = Math.min(exponentialMs, max);
|
|
10479
|
+
return jitter2(ms);
|
|
10480
|
+
}
|
|
10481
|
+
function jitter2(value) {
|
|
10482
|
+
const delta = value * 0.15;
|
|
10483
|
+
return value + randomRange(-delta, delta);
|
|
10484
|
+
}
|
|
10485
|
+
function randomRange(from3, to) {
|
|
10486
|
+
const rand = Math.random() * (to - from3);
|
|
10487
|
+
return rand + from3;
|
|
10488
|
+
}
|
|
10489
|
+
|
|
10418
10490
|
// ../../node_modules/.pnpm/zod@3.21.4/node_modules/zod/lib/index.mjs
|
|
10419
10491
|
var util;
|
|
10420
10492
|
(function(util2) {
|
|
@@ -14042,6 +14114,11 @@ var DAY = HOUR * 24;
|
|
|
14042
14114
|
var lessThanAgoMs = (time, range2) => {
|
|
14043
14115
|
return Date.now() < time.getTime() + range2;
|
|
14044
14116
|
};
|
|
14117
|
+
var addHoursToDate = (hours, startingDate) => {
|
|
14118
|
+
const currentDate = startingDate ? new Date(startingDate) : new Date();
|
|
14119
|
+
currentDate.setHours(currentDate.getHours() + hours);
|
|
14120
|
+
return currentDate;
|
|
14121
|
+
};
|
|
14045
14122
|
|
|
14046
14123
|
// src/strings.ts
|
|
14047
14124
|
var import_graphemer = __toESM(require_lib());
|
|
@@ -14100,6 +14177,9 @@ var getHandle = (doc) => {
|
|
|
14100
14177
|
return found.slice(5);
|
|
14101
14178
|
};
|
|
14102
14179
|
var getSigningKey = (doc) => {
|
|
14180
|
+
return getVerificationMaterial(doc, "atproto");
|
|
14181
|
+
};
|
|
14182
|
+
var getVerificationMaterial = (doc, keyId) => {
|
|
14103
14183
|
const did = getDid(doc);
|
|
14104
14184
|
let keys = doc.verificationMethod;
|
|
14105
14185
|
if (!keys)
|
|
@@ -14109,7 +14189,7 @@ var getSigningKey = (doc) => {
|
|
|
14109
14189
|
if (!Array.isArray(keys)) {
|
|
14110
14190
|
keys = [keys];
|
|
14111
14191
|
}
|
|
14112
|
-
const found = keys.find((key) => key.id ===
|
|
14192
|
+
const found = keys.find((key) => key.id === `#${keyId}` || key.id === `${did}#${keyId}`);
|
|
14113
14193
|
if (!found?.publicKeyMultibase)
|
|
14114
14194
|
return void 0;
|
|
14115
14195
|
return {
|
|
@@ -14117,6 +14197,12 @@ var getSigningKey = (doc) => {
|
|
|
14117
14197
|
publicKeyMultibase: found.publicKeyMultibase
|
|
14118
14198
|
};
|
|
14119
14199
|
};
|
|
14200
|
+
var getSigningDidKey = (doc) => {
|
|
14201
|
+
const parsed = getSigningKey(doc);
|
|
14202
|
+
if (!parsed)
|
|
14203
|
+
return;
|
|
14204
|
+
return `did:key:${parsed.publicKeyMultibase}`;
|
|
14205
|
+
};
|
|
14120
14206
|
var getPdsEndpoint = (doc) => {
|
|
14121
14207
|
return getServiceEndpoint(doc, {
|
|
14122
14208
|
id: "#atproto_pds",
|
|
@@ -14148,7 +14234,7 @@ var getServiceEndpoint = (doc, opts) => {
|
|
|
14148
14234
|
const found = services.find((service2) => service2.id === opts.id || service2.id === `${did}${opts.id}`);
|
|
14149
14235
|
if (!found)
|
|
14150
14236
|
return void 0;
|
|
14151
|
-
if (found.type !== opts.type) {
|
|
14237
|
+
if (opts.type && found.type !== opts.type) {
|
|
14152
14238
|
return void 0;
|
|
14153
14239
|
}
|
|
14154
14240
|
if (typeof found.serviceEndpoint !== "string") {
|