@atproto/api 0.18.2 → 0.18.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 CHANGED
@@ -1,5 +1,24 @@
1
1
  # @atproto/api
2
2
 
3
+ ## 0.18.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#4407](https://github.com/bluesky-social/atproto/pull/4407) [`90f1569`](https://github.com/bluesky-social/atproto/commit/90f15698ee63d9a7374f1206754eda5d530873d7) Thanks [@estrattonbailey](https://github.com/estrattonbailey)! - Adds ageassurance namespace, methods, and utils for Age Assurance V2
8
+
9
+ - Updated dependencies [[`bcae2b7`](https://github.com/bluesky-social/atproto/commit/bcae2b77b68da6dc2ec202651c8bf41fd5769f69)]:
10
+ - @atproto/syntax@0.4.2
11
+ - @atproto/common-web@0.4.6
12
+
13
+ ## 0.18.3
14
+
15
+ ### Patch Changes
16
+
17
+ - [#4347](https://github.com/bluesky-social/atproto/pull/4347) [`69f53d6`](https://github.com/bluesky-social/atproto/commit/69f53d632d84f255cafa8b10698184048a71b97b) Thanks [@bnewbold](https://github.com/bnewbold)! - lexicon updates to have fully-qualified token refs in knownValue lists
18
+
19
+ - Updated dependencies []:
20
+ - @atproto/common-web@0.4.5
21
+
3
22
  ## 0.18.2
4
23
 
5
24
  ### Patch Changes
@@ -866,7 +885,7 @@
866
885
  `AtpAgent`.
867
886
 
868
887
  ```ts
869
- import { Agent, AtpAgent } from "@atproto/api";
888
+ import { Agent, AtpAgent } from '@atproto/api'
870
889
 
871
890
  async function setupAgent(
872
891
  service: string,
@@ -878,30 +897,30 @@
878
897
  persistSession: (evt, session) => {
879
898
  // handle session update
880
899
  },
881
- });
900
+ })
882
901
 
883
- await agent.login(username, password);
902
+ await agent.login(username, password)
884
903
 
885
- return agent;
904
+ return agent
886
905
  }
887
906
  ```
888
907
 
889
908
  ```ts
890
- import { Agent } from "@atproto/api";
909
+ import { Agent } from '@atproto/api'
891
910
 
892
911
  async function doStuffWithAgent(agent: Agent, arg: string) {
893
- return agent.resolveHandle(arg);
912
+ return agent.resolveHandle(arg)
894
913
  }
895
914
  ```
896
915
 
897
916
  ```ts
898
- import { Agent, AtpAgent } from "@atproto/api";
917
+ import { Agent, AtpAgent } from '@atproto/api'
899
918
 
900
919
  class MyClass {
901
- agent: Agent;
920
+ agent: Agent
902
921
 
903
922
  constructor() {
904
- this.agent = new AtpAgent();
923
+ this.agent = new AtpAgent()
905
924
  }
906
925
  }
907
926
  ```
@@ -979,24 +998,24 @@
979
998
  <td>
980
999
 
981
1000
  ```ts
982
- import { AtpBaseClient, ComAtprotoSyncSubscribeRepos } from "@atproto/api";
1001
+ import { AtpBaseClient, ComAtprotoSyncSubscribeRepos } from '@atproto/api'
983
1002
 
984
- const baseClient = new AtpBaseClient();
1003
+ const baseClient = new AtpBaseClient()
985
1004
 
986
- baseClient.xrpc.lex.assertValidXrpcMessage("io.example.doStuff", {
1005
+ baseClient.xrpc.lex.assertValidXrpcMessage('io.example.doStuff', {
987
1006
  // ...
988
- });
1007
+ })
989
1008
  ```
990
1009
 
991
1010
  </td>
992
1011
  <td>
993
1012
 
994
1013
  ```ts
995
- import { lexicons } from "@atproto/api";
1014
+ import { lexicons } from '@atproto/api'
996
1015
 
997
- lexicons.assertValidXrpcMessage("io.example.doStuff", {
1016
+ lexicons.assertValidXrpcMessage('io.example.doStuff', {
998
1017
  // ...
999
- });
1018
+ })
1000
1019
  ```
1001
1020
 
1002
1021
  </td>
@@ -1013,23 +1032,23 @@
1013
1032
  <td>
1014
1033
 
1015
1034
  ```ts
1016
- import { BskyAgent } from "@atproto/api";
1035
+ import { BskyAgent } from '@atproto/api'
1017
1036
 
1018
1037
  class MyAgent extends BskyAgent {
1019
- private accessToken?: string;
1038
+ private accessToken?: string
1020
1039
 
1021
1040
  async createOrRefreshSession(identifier: string, password: string) {
1022
1041
  // custom logic here
1023
1042
 
1024
- this.accessToken = "my-access-jwt";
1043
+ this.accessToken = 'my-access-jwt'
1025
1044
  }
1026
1045
 
1027
1046
  async doStuff() {
1028
- return this.call("io.example.doStuff", {
1047
+ return this.call('io.example.doStuff', {
1029
1048
  headers: {
1030
1049
  Authorization: this.accessToken && `Bearer ${this.accessToken}`,
1031
1050
  },
1032
- });
1051
+ })
1033
1052
  }
1034
1053
  }
1035
1054
  ```
@@ -1038,11 +1057,11 @@
1038
1057
  <td>
1039
1058
 
1040
1059
  ```ts
1041
- import { Agent } from "@atproto/api";
1060
+ import { Agent } from '@atproto/api'
1042
1061
 
1043
1062
  class MyAgent extends Agent {
1044
- private accessToken?: string;
1045
- public did?: string;
1063
+ private accessToken?: string
1064
+ public did?: string
1046
1065
 
1047
1066
  constructor(private readonly service: string | URL) {
1048
1067
  super({
@@ -1051,21 +1070,21 @@
1051
1070
  Authorization: () =>
1052
1071
  this.accessToken ? `Bearer ${this.accessToken}` : null,
1053
1072
  },
1054
- });
1073
+ })
1055
1074
  }
1056
1075
 
1057
1076
  clone(): MyAgent {
1058
- const agent = new MyAgent(this.service);
1059
- agent.accessToken = this.accessToken;
1060
- agent.did = this.did;
1061
- return this.copyInto(agent);
1077
+ const agent = new MyAgent(this.service)
1078
+ agent.accessToken = this.accessToken
1079
+ agent.did = this.did
1080
+ return this.copyInto(agent)
1062
1081
  }
1063
1082
 
1064
1083
  async createOrRefreshSession(identifier: string, password: string) {
1065
1084
  // custom logic here
1066
1085
 
1067
- this.did = "did:example:123";
1068
- this.accessToken = "my-access-jwt";
1086
+ this.did = 'did:example:123'
1087
+ this.accessToken = 'my-access-jwt'
1069
1088
  }
1070
1089
  }
1071
1090
  ```
@@ -1084,38 +1103,38 @@
1084
1103
  <td>
1085
1104
 
1086
1105
  ```ts
1087
- import { BskyAgent } from "@atproto/api";
1088
- import { RateLimitThreshold } from "rate-limit-threshold";
1106
+ import { BskyAgent } from '@atproto/api'
1107
+ import { RateLimitThreshold } from 'rate-limit-threshold'
1089
1108
 
1090
- const agent = new BskyAgent();
1091
- const limiter = new RateLimitThreshold(3000, 300_000);
1109
+ const agent = new BskyAgent()
1110
+ const limiter = new RateLimitThreshold(3000, 300_000)
1092
1111
 
1093
- const origCall = agent.api.xrpc.call;
1112
+ const origCall = agent.api.xrpc.call
1094
1113
  agent.api.xrpc.call = async function (...args) {
1095
- await limiter.wait();
1096
- return origCall.call(this, ...args);
1097
- };
1114
+ await limiter.wait()
1115
+ return origCall.call(this, ...args)
1116
+ }
1098
1117
  ```
1099
1118
 
1100
1119
  </td>
1101
1120
  <td>
1102
1121
 
1103
1122
  ```ts
1104
- import { AtpAgent } from "@atproto/api";
1105
- import { RateLimitThreshold } from "rate-limit-threshold";
1123
+ import { AtpAgent } from '@atproto/api'
1124
+ import { RateLimitThreshold } from 'rate-limit-threshold'
1106
1125
 
1107
1126
  class LimitedAtpAgent extends AtpAgent {
1108
1127
  constructor(options: AtpAgentOptions) {
1109
- const fetch: typeof globalThis.fetch = options.fetch ?? globalThis.fetch;
1110
- const limiter = new RateLimitThreshold(3000, 300_000);
1128
+ const fetch: typeof globalThis.fetch = options.fetch ?? globalThis.fetch
1129
+ const limiter = new RateLimitThreshold(3000, 300_000)
1111
1130
 
1112
1131
  super({
1113
1132
  ...options,
1114
1133
  fetch: async (...args) => {
1115
- await limiter.wait();
1116
- return fetch(...args);
1134
+ await limiter.wait()
1135
+ return fetch(...args)
1117
1136
  },
1118
- });
1137
+ })
1119
1138
  }
1120
1139
  }
1121
1140
  ```
@@ -1136,40 +1155,40 @@
1136
1155
  <td>
1137
1156
 
1138
1157
  ```ts
1139
- import { BskyAgent, defaultFetchHandler } from "@atproto/api";
1158
+ import { BskyAgent, defaultFetchHandler } from '@atproto/api'
1140
1159
 
1141
1160
  BskyAgent.configure({
1142
1161
  fetch: async (httpUri, httpMethod, httpHeaders, httpReqBody) => {
1143
- const ua = httpHeaders["User-Agent"];
1162
+ const ua = httpHeaders['User-Agent']
1144
1163
 
1145
- httpHeaders["User-Agent"] = ua ? `${ua} ${userAgent}` : userAgent;
1164
+ httpHeaders['User-Agent'] = ua ? `${ua} ${userAgent}` : userAgent
1146
1165
 
1147
- return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody);
1166
+ return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody)
1148
1167
  },
1149
- });
1168
+ })
1150
1169
  ```
1151
1170
 
1152
1171
  </td>
1153
1172
  <td>
1154
1173
 
1155
1174
  ```ts
1156
- import { AtpAgent } from "@atproto/api";
1175
+ import { AtpAgent } from '@atproto/api'
1157
1176
 
1158
1177
  class MyAtpAgent extends AtpAgent {
1159
1178
  constructor(options: AtpAgentOptions) {
1160
- const fetch = options.fetch ?? globalThis.fetch;
1179
+ const fetch = options.fetch ?? globalThis.fetch
1161
1180
 
1162
1181
  super({
1163
1182
  ...options,
1164
1183
  fetch: async (url, init) => {
1165
- const headers = new Headers(init.headers);
1184
+ const headers = new Headers(init.headers)
1166
1185
 
1167
- const ua = headersList.get("User-Agent");
1168
- headersList.set("User-Agent", ua ? `${ua} ${userAgent}` : userAgent);
1186
+ const ua = headersList.get('User-Agent')
1187
+ headersList.set('User-Agent', ua ? `${ua} ${userAgent}` : userAgent)
1169
1188
 
1170
- return fetch(url, { ...init, headers });
1189
+ return fetch(url, { ...init, headers })
1171
1190
  },
1172
- });
1191
+ })
1173
1192
  }
1174
1193
  }
1175
1194
  ```
@@ -1228,7 +1247,7 @@
1228
1247
  */
1229
1248
  url: string,
1230
1249
  init: RequestInit,
1231
- ) => Promise<Response>;
1250
+ ) => Promise<Response>
1232
1251
  ```
1233
1252
 
1234
1253
  A noticeable change that has been introduced is that the `uri` field of the
@@ -1266,7 +1285,7 @@
1266
1285
  <td>
1267
1286
 
1268
1287
  ```ts
1269
- import client, { defaultFetchHandler } from "@atproto/xrpc";
1288
+ import client, { defaultFetchHandler } from '@atproto/xrpc'
1270
1289
 
1271
1290
  client.fetch = function (
1272
1291
  httpUri: string,
@@ -1275,50 +1294,50 @@
1275
1294
  httpReqBody: unknown,
1276
1295
  ) {
1277
1296
  // Custom logic here
1278
- return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody);
1279
- };
1297
+ return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody)
1298
+ }
1280
1299
 
1281
1300
  client.addLexicon({
1282
1301
  lexicon: 1,
1283
- id: "io.example.doStuff",
1302
+ id: 'io.example.doStuff',
1284
1303
  defs: {},
1285
- });
1304
+ })
1286
1305
 
1287
- const instance = client.service("http://my-service.com");
1306
+ const instance = client.service('http://my-service.com')
1288
1307
 
1289
- instance.setHeader("my-header", "my-value");
1308
+ instance.setHeader('my-header', 'my-value')
1290
1309
 
1291
- await instance.call("io.example.doStuff");
1310
+ await instance.call('io.example.doStuff')
1292
1311
  ```
1293
1312
 
1294
1313
  </td>
1295
1314
  <td>
1296
1315
 
1297
1316
  ```ts
1298
- import { XrpcClient } from "@atproto/xrpc";
1317
+ import { XrpcClient } from '@atproto/xrpc'
1299
1318
 
1300
1319
  const instance = new XrpcClient(
1301
1320
  async (url, init) => {
1302
- const headers = new Headers(init.headers);
1321
+ const headers = new Headers(init.headers)
1303
1322
 
1304
- headers.set("my-header", "my-value");
1323
+ headers.set('my-header', 'my-value')
1305
1324
 
1306
1325
  // Custom logic here
1307
1326
 
1308
- const fullUrl = new URL(url, "http://my-service.com");
1327
+ const fullUrl = new URL(url, 'http://my-service.com')
1309
1328
 
1310
- return fetch(fullUrl, { ...init, headers });
1329
+ return fetch(fullUrl, { ...init, headers })
1311
1330
  },
1312
1331
  [
1313
1332
  {
1314
1333
  lexicon: 1,
1315
- id: "io.example.doStuff",
1334
+ id: 'io.example.doStuff',
1316
1335
  defs: {},
1317
1336
  },
1318
1337
  ],
1319
- );
1338
+ )
1320
1339
 
1321
- await instance.call("io.example.doStuff");
1340
+ await instance.call('io.example.doStuff')
1322
1341
  ```
1323
1342
 
1324
1343
  </td>
@@ -1330,62 +1349,62 @@
1330
1349
  previous example can be simplified to:
1331
1350
 
1332
1351
  ```ts
1333
- import { XrpcClient } from "@atproto/xrpc";
1352
+ import { XrpcClient } from '@atproto/xrpc'
1334
1353
 
1335
- const instance = new XrpcClient("http://my-service.com", [
1354
+ const instance = new XrpcClient('http://my-service.com', [
1336
1355
  {
1337
1356
  lexicon: 1,
1338
- id: "io.example.doStuff",
1357
+ id: 'io.example.doStuff',
1339
1358
  defs: {},
1340
1359
  },
1341
- ]);
1360
+ ])
1342
1361
  ```
1343
1362
 
1344
1363
  If you need to add static headers to all requests, you can instead instantiate
1345
1364
  the `XrpcClient` as follows:
1346
1365
 
1347
1366
  ```ts
1348
- import { XrpcClient } from "@atproto/xrpc";
1367
+ import { XrpcClient } from '@atproto/xrpc'
1349
1368
 
1350
1369
  const instance = new XrpcClient(
1351
1370
  {
1352
- service: "http://my-service.com",
1371
+ service: 'http://my-service.com',
1353
1372
  headers: {
1354
- "my-header": "my-value",
1373
+ 'my-header': 'my-value',
1355
1374
  },
1356
1375
  },
1357
1376
  [
1358
1377
  {
1359
1378
  lexicon: 1,
1360
- id: "io.example.doStuff",
1379
+ id: 'io.example.doStuff',
1361
1380
  defs: {},
1362
1381
  },
1363
1382
  ],
1364
- );
1383
+ )
1365
1384
  ```
1366
1385
 
1367
1386
  If you need the headers or service url to be dynamic, you can define them using
1368
1387
  functions:
1369
1388
 
1370
1389
  ```ts
1371
- import { XrpcClient } from "@atproto/xrpc";
1390
+ import { XrpcClient } from '@atproto/xrpc'
1372
1391
 
1373
1392
  const instance = new XrpcClient(
1374
1393
  {
1375
- service: () => "http://my-service.com",
1394
+ service: () => 'http://my-service.com',
1376
1395
  headers: {
1377
- "my-header": () => "my-value",
1378
- "my-ignored-header": () => null, // ignored
1396
+ 'my-header': () => 'my-value',
1397
+ 'my-ignored-header': () => null, // ignored
1379
1398
  },
1380
1399
  },
1381
1400
  [
1382
1401
  {
1383
1402
  lexicon: 1,
1384
- id: "io.example.doStuff",
1403
+ id: 'io.example.doStuff',
1385
1404
  defs: {},
1386
1405
  },
1387
1406
  ],
1388
- );
1407
+ )
1389
1408
  ```
1390
1409
 
1391
1410
  - [#2483](https://github.com/bluesky-social/atproto/pull/2483) [`b934b396b`](https://github.com/bluesky-social/atproto/commit/b934b396b13ba32bf2bf7e75ecdf6871e5f310dd) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add the ability to use `fetch()` compatible `BodyInit` body when making XRPC calls.
@@ -0,0 +1,29 @@
1
+ import { AppBskyAgeassuranceDefs } from './client';
2
+ export type AgeAssuranceRuleID = Exclude<AppBskyAgeassuranceDefs.ConfigRegionRuleDefault['$type'] | AppBskyAgeassuranceDefs.ConfigRegionRuleIfDeclaredOverAge['$type'] | AppBskyAgeassuranceDefs.ConfigRegionRuleIfDeclaredUnderAge['$type'] | AppBskyAgeassuranceDefs.ConfigRegionRuleIfAssuredOverAge['$type'] | AppBskyAgeassuranceDefs.ConfigRegionRuleIfAssuredUnderAge['$type'] | AppBskyAgeassuranceDefs.ConfigRegionRuleIfAccountNewerThan['$type'] | AppBskyAgeassuranceDefs.ConfigRegionRuleIfAccountOlderThan['$type'], undefined>;
3
+ export declare const ageAssuranceRuleIDs: Record<string, AgeAssuranceRuleID>;
4
+ /**
5
+ * Returns the first matched region configuration based on the provided geolocation.
6
+ */
7
+ export declare function getAgeAssuranceRegionConfig(config: AppBskyAgeassuranceDefs.Config, geolocation: {
8
+ countryCode: string;
9
+ regionCode?: string;
10
+ }): AppBskyAgeassuranceDefs.ConfigRegion | undefined;
11
+ export declare function computeAgeAssuranceRegionAccess(region: AppBskyAgeassuranceDefs.ConfigRegion, data: {
12
+ /**
13
+ * The account creation date in ISO 8601 format. Only checked if we
14
+ * don't have an assured age, such as on the client.
15
+ */
16
+ accountCreatedAt?: string;
17
+ /**
18
+ * The user's declared age
19
+ */
20
+ declaredAge?: number;
21
+ /**
22
+ * The user's minimum age as assured by a trusted third party.
23
+ */
24
+ assuredAge?: number;
25
+ } | undefined): {
26
+ access: AppBskyAgeassuranceDefs.Access;
27
+ reason: AgeAssuranceRuleID;
28
+ } | undefined;
29
+ //# sourceMappingURL=age-assurance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"age-assurance.d.ts","sourceRoot":"","sources":["../src/age-assurance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAGlD,MAAM,MAAM,kBAAkB,GAAG,OAAO,CACpC,uBAAuB,CAAC,uBAAuB,CAAC,OAAO,CAAC,GACxD,uBAAuB,CAAC,iCAAiC,CAAC,OAAO,CAAC,GAClE,uBAAuB,CAAC,kCAAkC,CAAC,OAAO,CAAC,GACnE,uBAAuB,CAAC,gCAAgC,CAAC,OAAO,CAAC,GACjE,uBAAuB,CAAC,iCAAiC,CAAC,OAAO,CAAC,GAClE,uBAAuB,CAAC,kCAAkC,CAAC,OAAO,CAAC,GACnE,uBAAuB,CAAC,kCAAkC,CAAC,OAAO,CAAC,EACrE,SAAS,CACV,CAAA;AAED,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAQlE,CAAA;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,uBAAuB,CAAC,MAAM,EACtC,WAAW,EAAE;IACX,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,GACA,uBAAuB,CAAC,YAAY,GAAG,SAAS,CAOlD;AAED,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,uBAAuB,CAAC,YAAY,EAC5C,IAAI,EACA;IACE;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,GACD,SAAS,GAEX;IACE,MAAM,EAAE,uBAAuB,CAAC,MAAM,CAAA;IACtC,MAAM,EAAE,kBAAkB,CAAA;CAC3B,GACD,SAAS,CAsEZ"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ageAssuranceRuleIDs = void 0;
4
+ exports.getAgeAssuranceRegionConfig = getAgeAssuranceRegionConfig;
5
+ exports.computeAgeAssuranceRegionAccess = computeAgeAssuranceRegionAccess;
6
+ const client_1 = require("./client");
7
+ const lexicons_1 = require("./client/lexicons");
8
+ exports.ageAssuranceRuleIDs = {
9
+ Default: `${lexicons_1.ids.AppBskyAgeassuranceDefs}#configRegionRuleDefault`,
10
+ IfDeclaredOverAge: `${lexicons_1.ids.AppBskyAgeassuranceDefs}#configRegionRuleIfDeclaredOverAge`,
11
+ IfDeclaredUnderAge: `${lexicons_1.ids.AppBskyAgeassuranceDefs}#configRegionRuleIfDeclaredUnderAge`,
12
+ IfAssuredOverAge: `${lexicons_1.ids.AppBskyAgeassuranceDefs}#configRegionRuleIfAssuredOverAge`,
13
+ IfAssuredUnderAge: `${lexicons_1.ids.AppBskyAgeassuranceDefs}#configRegionRuleIfAssuredUnderAge`,
14
+ IfAccountNewerThan: `${lexicons_1.ids.AppBskyAgeassuranceDefs}#configRegionRuleIfAccountNewerThan`,
15
+ IfAccountOlderThan: `${lexicons_1.ids.AppBskyAgeassuranceDefs}#configRegionRuleIfAccountOlderThan`,
16
+ };
17
+ /**
18
+ * Returns the first matched region configuration based on the provided geolocation.
19
+ */
20
+ function getAgeAssuranceRegionConfig(config, geolocation) {
21
+ const { regions } = config;
22
+ return regions.find(({ countryCode, regionCode }) => {
23
+ if (countryCode === geolocation.countryCode) {
24
+ return !regionCode || regionCode === geolocation.regionCode;
25
+ }
26
+ });
27
+ }
28
+ function computeAgeAssuranceRegionAccess(region, data) {
29
+ // first match wins
30
+ for (const rule of region.rules) {
31
+ if (client_1.AppBskyAgeassuranceDefs.isConfigRegionRuleIfAccountNewerThan(rule)) {
32
+ if (data?.accountCreatedAt && !data?.assuredAge) {
33
+ const accountCreatedAt = new Date(data.accountCreatedAt);
34
+ const threshold = new Date(rule.date);
35
+ if (accountCreatedAt >= threshold) {
36
+ return {
37
+ access: rule.access,
38
+ reason: rule.$type,
39
+ };
40
+ }
41
+ }
42
+ }
43
+ else if (client_1.AppBskyAgeassuranceDefs.isConfigRegionRuleIfAccountOlderThan(rule)) {
44
+ if (data?.accountCreatedAt && !data?.assuredAge) {
45
+ const accountCreatedAt = new Date(data.accountCreatedAt);
46
+ const threshold = new Date(rule.date);
47
+ if (accountCreatedAt < threshold) {
48
+ return {
49
+ access: rule.access,
50
+ reason: rule.$type,
51
+ };
52
+ }
53
+ }
54
+ }
55
+ else if (client_1.AppBskyAgeassuranceDefs.isConfigRegionRuleIfDeclaredOverAge(rule)) {
56
+ if (data?.declaredAge !== undefined && data.declaredAge >= rule.age) {
57
+ return {
58
+ access: rule.access,
59
+ reason: rule.$type,
60
+ };
61
+ }
62
+ }
63
+ else if (client_1.AppBskyAgeassuranceDefs.isConfigRegionRuleIfDeclaredUnderAge(rule)) {
64
+ if (data?.declaredAge !== undefined && data.declaredAge < rule.age) {
65
+ return {
66
+ access: rule.access,
67
+ reason: rule.$type,
68
+ };
69
+ }
70
+ }
71
+ else if (client_1.AppBskyAgeassuranceDefs.isConfigRegionRuleIfAssuredOverAge(rule)) {
72
+ if (data?.assuredAge && data.assuredAge >= rule.age) {
73
+ return {
74
+ access: rule.access,
75
+ reason: rule.$type,
76
+ };
77
+ }
78
+ }
79
+ else if (client_1.AppBskyAgeassuranceDefs.isConfigRegionRuleIfAssuredUnderAge(rule)) {
80
+ if (data?.assuredAge && data.assuredAge < rule.age) {
81
+ return {
82
+ access: rule.access,
83
+ reason: rule.$type,
84
+ };
85
+ }
86
+ }
87
+ else if (client_1.AppBskyAgeassuranceDefs.isConfigRegionRuleDefault(rule)) {
88
+ return {
89
+ access: rule.access,
90
+ reason: rule.$type,
91
+ };
92
+ }
93
+ }
94
+ }
95
+ //# sourceMappingURL=age-assurance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"age-assurance.js","sourceRoot":"","sources":["../src/age-assurance.ts"],"names":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AA;YACH,CAAC;QACH,CAAC;aAAM,IACL,gCAAuB,CAAC,kCAAkC,CAAC,IAAI,CAAC,EAChE,CAAC;YACD,IAAI,IAAI,EAAE,UAAU,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;gBACpD,OAAO;oBACL,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,MAAM,EAAE,IAAI,CAAC,KAAK;iBACnB,CAAA;YACH,CAAC;QACH,CAAC;aAAM,IACL,gCAAuB,CAAC,mCAAmC,CAAC,IAAI,CAAC,EACjE,CAAC;YACD,IAAI,IAAI,EAAE,UAAU,IAAI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;gBACnD,OAAO;oBACL,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,MAAM,EAAE,IAAI,CAAC,KAAK;iBACnB,CAAA;YACH,CAAC;QACH,CAAC;aAAM,IAAI,gCAAuB,CAAC,yBAAyB,CAAC,IAAI,CAAC,EAAE,CAAC;YACnE,OAAO;gBACL,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,MAAM,EAAE,IAAI,CAAC,KAAK;aACnB,CAAA;QACH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { AppBskyAgeassuranceDefs } from './client'\nimport { ids } from './client/lexicons'\n\nexport type AgeAssuranceRuleID = Exclude<\n | AppBskyAgeassuranceDefs.ConfigRegionRuleDefault['$type']\n | AppBskyAgeassuranceDefs.ConfigRegionRuleIfDeclaredOverAge['$type']\n | AppBskyAgeassuranceDefs.ConfigRegionRuleIfDeclaredUnderAge['$type']\n | AppBskyAgeassuranceDefs.ConfigRegionRuleIfAssuredOverAge['$type']\n | AppBskyAgeassuranceDefs.ConfigRegionRuleIfAssuredUnderAge['$type']\n | AppBskyAgeassuranceDefs.ConfigRegionRuleIfAccountNewerThan['$type']\n | AppBskyAgeassuranceDefs.ConfigRegionRuleIfAccountOlderThan['$type'],\n undefined\n>\n\nexport const ageAssuranceRuleIDs: Record<string, AgeAssuranceRuleID> = {\n Default: `${ids.AppBskyAgeassuranceDefs}#configRegionRuleDefault`,\n IfDeclaredOverAge: `${ids.AppBskyAgeassuranceDefs}#configRegionRuleIfDeclaredOverAge`,\n IfDeclaredUnderAge: `${ids.AppBskyAgeassuranceDefs}#configRegionRuleIfDeclaredUnderAge`,\n IfAssuredOverAge: `${ids.AppBskyAgeassuranceDefs}#configRegionRuleIfAssuredOverAge`,\n IfAssuredUnderAge: `${ids.AppBskyAgeassuranceDefs}#configRegionRuleIfAssuredUnderAge`,\n IfAccountNewerThan: `${ids.AppBskyAgeassuranceDefs}#configRegionRuleIfAccountNewerThan`,\n IfAccountOlderThan: `${ids.AppBskyAgeassuranceDefs}#configRegionRuleIfAccountOlderThan`,\n}\n\n/**\n * Returns the first matched region configuration based on the provided geolocation.\n */\nexport function getAgeAssuranceRegionConfig(\n config: AppBskyAgeassuranceDefs.Config,\n geolocation: {\n countryCode: string\n regionCode?: string\n },\n): AppBskyAgeassuranceDefs.ConfigRegion | undefined {\n const { regions } = config\n return regions.find(({ countryCode, regionCode }) => {\n if (countryCode === geolocation.countryCode) {\n return !regionCode || regionCode === geolocation.regionCode\n }\n })\n}\n\nexport function computeAgeAssuranceRegionAccess(\n region: AppBskyAgeassuranceDefs.ConfigRegion,\n data:\n | {\n /**\n * The account creation date in ISO 8601 format. Only checked if we\n * don't have an assured age, such as on the client.\n */\n accountCreatedAt?: string\n /**\n * The user's declared age\n */\n declaredAge?: number\n /**\n * The user's minimum age as assured by a trusted third party.\n */\n assuredAge?: number\n }\n | undefined,\n):\n | {\n access: AppBskyAgeassuranceDefs.Access\n reason: AgeAssuranceRuleID\n }\n | undefined {\n // first match wins\n for (const rule of region.rules) {\n if (AppBskyAgeassuranceDefs.isConfigRegionRuleIfAccountNewerThan(rule)) {\n if (data?.accountCreatedAt && !data?.assuredAge) {\n const accountCreatedAt = new Date(data.accountCreatedAt)\n const threshold = new Date(rule.date)\n if (accountCreatedAt >= threshold) {\n return {\n access: rule.access,\n reason: rule.$type,\n }\n }\n }\n } else if (\n AppBskyAgeassuranceDefs.isConfigRegionRuleIfAccountOlderThan(rule)\n ) {\n if (data?.accountCreatedAt && !data?.assuredAge) {\n const accountCreatedAt = new Date(data.accountCreatedAt)\n const threshold = new Date(rule.date)\n if (accountCreatedAt < threshold) {\n return {\n access: rule.access,\n reason: rule.$type,\n }\n }\n }\n } else if (\n AppBskyAgeassuranceDefs.isConfigRegionRuleIfDeclaredOverAge(rule)\n ) {\n if (data?.declaredAge !== undefined && data.declaredAge >= rule.age) {\n return {\n access: rule.access,\n reason: rule.$type,\n }\n }\n } else if (\n AppBskyAgeassuranceDefs.isConfigRegionRuleIfDeclaredUnderAge(rule)\n ) {\n if (data?.declaredAge !== undefined && data.declaredAge < rule.age) {\n return {\n access: rule.access,\n reason: rule.$type,\n }\n }\n } else if (\n AppBskyAgeassuranceDefs.isConfigRegionRuleIfAssuredOverAge(rule)\n ) {\n if (data?.assuredAge && data.assuredAge >= rule.age) {\n return {\n access: rule.access,\n reason: rule.$type,\n }\n }\n } else if (\n AppBskyAgeassuranceDefs.isConfigRegionRuleIfAssuredUnderAge(rule)\n ) {\n if (data?.assuredAge && data.assuredAge < rule.age) {\n return {\n access: rule.access,\n reason: rule.$type,\n }\n }\n } else if (AppBskyAgeassuranceDefs.isConfigRegionRuleDefault(rule)) {\n return {\n access: rule.access,\n reason: rule.$type,\n }\n }\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=age-assurance.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"age-assurance.test.d.ts","sourceRoot":"","sources":["../src/age-assurance.test.ts"],"names":[],"mappings":""}