@atproto/common 0.3.1 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atproto/common
2
2
 
3
+ ## 0.3.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1788](https://github.com/bluesky-social/atproto/pull/1788) [`84e2d4d2`](https://github.com/bluesky-social/atproto/commit/84e2d4d2b6694f344d80c18672c78b650189d423) Thanks [@bnewbold](https://github.com/bnewbold)! - update license to "MIT or Apache2"
8
+
9
+ - Updated dependencies [[`84e2d4d2`](https://github.com/bluesky-social/atproto/commit/84e2d4d2b6694f344d80c18672c78b650189d423)]:
10
+ - @atproto/common-web@0.2.3
11
+
12
+ ## 0.3.2
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [[`35d108ce`](https://github.com/bluesky-social/atproto/commit/35d108ce94866ce1b3d147cd0620a0ba1c4ebcd7)]:
17
+ - @atproto/common-web@0.2.2
18
+
3
19
  ## 0.3.1
4
20
 
5
21
  ### Patch Changes
package/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Dual MIT/Apache-2.0 License
2
+
3
+ Copyright (c) 2022-2023 Bluesky PBC, and Contributors
4
+
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
+
7
+ Downstream projects and end users may chose either license individually, or both together, at their discretion. The motivation for this dual-licensing is the additional software patent assurance provided by Apache 2.0.
package/README.md CHANGED
@@ -7,4 +7,9 @@ Shared TypeScript code for other `@atproto/*` packages. This package is oriented
7
7
 
8
8
  ## License
9
9
 
10
- MIT License
10
+ This project is dual-licensed under MIT and Apache 2.0 terms:
11
+
12
+ - MIT license ([LICENSE-MIT.txt](https://github.com/bluesky-social/atproto/blob/main/LICENSE-MIT.txt) or http://opensource.org/licenses/MIT)
13
+ - Apache License, Version 2.0, ([LICENSE-APACHE.txt](https://github.com/bluesky-social/atproto/blob/main/LICENSE-APACHE.txt) or http://www.apache.org/licenses/LICENSE-2.0)
14
+
15
+ Downstream projects and end users may chose either license individually, or both together, at their discretion. The motivation for this dual-licensing is the additional software patent assurance provided by Apache 2.0.
package/dist/index.js CHANGED
@@ -13082,15 +13082,25 @@ __export(src_exports3, {
13082
13082
  dataToCborBlock: () => dataToCborBlock,
13083
13083
  dedupeStrs: () => dedupeStrs,
13084
13084
  def: () => def,
13085
+ didDocument: () => didDocument,
13085
13086
  errHasMsg: () => errHasMsg,
13086
13087
  fileExists: () => fileExists,
13087
13088
  flattenUint8Arrays: () => flattenUint8Arrays,
13088
13089
  forwardStreamErrors: () => forwardStreamErrors,
13090
+ getDid: () => getDid,
13091
+ getFeedGenEndpoint: () => getFeedGenEndpoint,
13092
+ getHandle: () => getHandle,
13093
+ getNotifEndpoint: () => getNotifEndpoint,
13094
+ getPdsEndpoint: () => getPdsEndpoint,
13095
+ getServiceEndpoint: () => getServiceEndpoint,
13096
+ getSigningKey: () => getSigningKey,
13089
13097
  graphemeLen: () => graphemeLen,
13098
+ handleAllSettledErrors: () => handleAllSettledErrors,
13090
13099
  ipldEquals: () => ipldEquals,
13091
13100
  ipldToJson: () => ipldToJson,
13092
13101
  isErrnoException: () => isErrnoException,
13093
13102
  isValidCid: () => isValidCid,
13103
+ isValidDidDoc: () => isValidDidDoc,
13094
13104
  jitter: () => jitter,
13095
13105
  jsonToIpld: () => jsonToIpld,
13096
13106
  lessThanAgoMs: () => lessThanAgoMs,
@@ -13365,6 +13375,19 @@ var AsyncBufferFullError = class extends Error {
13365
13375
  super(`ReachedMaxBufferSize: ${maxSize}`);
13366
13376
  }
13367
13377
  };
13378
+ var handleAllSettledErrors = (results) => {
13379
+ const errors = results.filter(isRejected).map((res) => res.reason);
13380
+ if (errors.length === 0) {
13381
+ return;
13382
+ }
13383
+ if (errors.length === 1) {
13384
+ throw errors[0];
13385
+ }
13386
+ throw new AggregateError(errors, "Multiple errors: " + errors.map((err) => err?.message).join("\n"));
13387
+ };
13388
+ var isRejected = (result) => {
13389
+ return result.status === "rejected";
13390
+ };
13368
13391
 
13369
13392
  // ../common-web/src/tid.ts
13370
13393
  var TID_LEN = 13;
@@ -18325,6 +18348,116 @@ var validateLanguage = (langTag) => {
18325
18348
  };
18326
18349
  var bcp47Regexp = /^((?<grandfathered>(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?<language>([A-Za-z]{2,3}(-(?<extlang>[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-(?<script>[A-Za-z]{4}))?(-(?<region>[A-Za-z]{2}|[0-9]{3}))?(-(?<variant>[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-(?<extension>[0-9A-WY-Za-wy-z](-[A-Za-z0-9]{2,8})+))*(-(?<privateUseA>x(-[A-Za-z0-9]{1,8})+))?)|(?<privateUseB>x(-[A-Za-z0-9]{1,8})+))$/;
18327
18350
 
18351
+ // ../common-web/src/did-doc.ts
18352
+ var isValidDidDoc = (doc) => {
18353
+ return didDocument.safeParse(doc).success;
18354
+ };
18355
+ var getDid = (doc) => {
18356
+ const id = doc.id;
18357
+ if (typeof id !== "string") {
18358
+ throw new Error("No `id` on document");
18359
+ }
18360
+ return id;
18361
+ };
18362
+ var getHandle = (doc) => {
18363
+ const aka = doc.alsoKnownAs;
18364
+ if (!aka)
18365
+ return void 0;
18366
+ const found = aka.find((name3) => name3.startsWith("at://"));
18367
+ if (!found)
18368
+ return void 0;
18369
+ return found.slice(5);
18370
+ };
18371
+ var getSigningKey = (doc) => {
18372
+ const did = getDid(doc);
18373
+ let keys = doc.verificationMethod;
18374
+ if (!keys)
18375
+ return void 0;
18376
+ if (typeof keys !== "object")
18377
+ return void 0;
18378
+ if (!Array.isArray(keys)) {
18379
+ keys = [keys];
18380
+ }
18381
+ const found = keys.find((key) => key.id === "#atproto" || key.id === `${did}#atproto`);
18382
+ if (!found?.publicKeyMultibase)
18383
+ return void 0;
18384
+ return {
18385
+ type: found.type,
18386
+ publicKeyMultibase: found.publicKeyMultibase
18387
+ };
18388
+ };
18389
+ var getPdsEndpoint = (doc) => {
18390
+ return getServiceEndpoint(doc, {
18391
+ id: "#atproto_pds",
18392
+ type: "AtprotoPersonalDataServer"
18393
+ });
18394
+ };
18395
+ var getFeedGenEndpoint = (doc) => {
18396
+ return getServiceEndpoint(doc, {
18397
+ id: "#bsky_fg",
18398
+ type: "BskyFeedGenerator"
18399
+ });
18400
+ };
18401
+ var getNotifEndpoint = (doc) => {
18402
+ return getServiceEndpoint(doc, {
18403
+ id: "#bsky_notif",
18404
+ type: "BskyNotificationService"
18405
+ });
18406
+ };
18407
+ var getServiceEndpoint = (doc, opts) => {
18408
+ const did = getDid(doc);
18409
+ let services = doc.service;
18410
+ if (!services)
18411
+ return void 0;
18412
+ if (typeof services !== "object")
18413
+ return void 0;
18414
+ if (!Array.isArray(services)) {
18415
+ services = [services];
18416
+ }
18417
+ const found = services.find((service2) => service2.id === opts.id || service2.id === `${did}${opts.id}`);
18418
+ if (!found)
18419
+ return void 0;
18420
+ if (found.type !== opts.type) {
18421
+ return void 0;
18422
+ }
18423
+ if (typeof found.serviceEndpoint !== "string") {
18424
+ return void 0;
18425
+ }
18426
+ return validateUrl(found.serviceEndpoint);
18427
+ };
18428
+ var validateUrl = (urlStr) => {
18429
+ let url;
18430
+ try {
18431
+ url = new URL(urlStr);
18432
+ } catch {
18433
+ return void 0;
18434
+ }
18435
+ if (!["http:", "https:"].includes(url.protocol)) {
18436
+ return void 0;
18437
+ } else if (!url.hostname) {
18438
+ return void 0;
18439
+ } else {
18440
+ return urlStr;
18441
+ }
18442
+ };
18443
+ var verificationMethod = z.object({
18444
+ id: z.string(),
18445
+ type: z.string(),
18446
+ controller: z.string(),
18447
+ publicKeyMultibase: z.string().optional()
18448
+ });
18449
+ var service = z.object({
18450
+ id: z.string(),
18451
+ type: z.string(),
18452
+ serviceEndpoint: z.union([z.string(), z.record(z.unknown())])
18453
+ });
18454
+ var didDocument = z.object({
18455
+ id: z.string(),
18456
+ alsoKnownAs: z.array(z.string()).optional(),
18457
+ verificationMethod: z.array(verificationMethod).optional(),
18458
+ service: z.array(service).optional()
18459
+ });
18460
+
18328
18461
  // src/dates.ts
18329
18462
  var import_iso_datestring_validator = __toESM(require_dist());
18330
18463
  function toSimplifiedISOSafe(dateStr) {
@@ -22474,15 +22607,25 @@ function ui8ToArrayBuffer(bytes) {
22474
22607
  dataToCborBlock,
22475
22608
  dedupeStrs,
22476
22609
  def,
22610
+ didDocument,
22477
22611
  errHasMsg,
22478
22612
  fileExists,
22479
22613
  flattenUint8Arrays,
22480
22614
  forwardStreamErrors,
22615
+ getDid,
22616
+ getFeedGenEndpoint,
22617
+ getHandle,
22618
+ getNotifEndpoint,
22619
+ getPdsEndpoint,
22620
+ getServiceEndpoint,
22621
+ getSigningKey,
22481
22622
  graphemeLen,
22623
+ handleAllSettledErrors,
22482
22624
  ipldEquals,
22483
22625
  ipldToJson,
22484
22626
  isErrnoException,
22485
22627
  isValidCid,
22628
+ isValidDidDoc,
22486
22629
  jitter,
22487
22630
  jsonToIpld,
22488
22631
  lessThanAgoMs,