@atproto/oauth-client-browser 0.0.0-spaces-alpha-20260818163953

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +702 -0
  2. package/LICENSE.txt +7 -0
  3. package/README.md +339 -0
  4. package/dist/browser-oauth-client.d.ts +58 -0
  5. package/dist/browser-oauth-client.d.ts.map +1 -0
  6. package/dist/browser-oauth-client.js +358 -0
  7. package/dist/browser-oauth-client.js.map +1 -0
  8. package/dist/browser-oauth-database.d.ts +54 -0
  9. package/dist/browser-oauth-database.d.ts.map +1 -0
  10. package/dist/browser-oauth-database.js +160 -0
  11. package/dist/browser-oauth-database.js.map +1 -0
  12. package/dist/browser-runtime-implementation.d.ts +9 -0
  13. package/dist/browser-runtime-implementation.d.ts.map +1 -0
  14. package/dist/browser-runtime-implementation.js +40 -0
  15. package/dist/browser-runtime-implementation.js.map +1 -0
  16. package/dist/errors.d.ts +9 -0
  17. package/dist/errors.d.ts.map +1 -0
  18. package/dist/errors.js +11 -0
  19. package/dist/errors.js.map +1 -0
  20. package/dist/index.d.ts +8 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +8 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/indexed-db/db-index.d.ts +12 -0
  25. package/dist/indexed-db/db-index.d.ts.map +1 -0
  26. package/dist/indexed-db/db-index.js +40 -0
  27. package/dist/indexed-db/db-index.js.map +1 -0
  28. package/dist/indexed-db/db-object-store.d.ts +17 -0
  29. package/dist/indexed-db/db-object-store.d.ts.map +1 -0
  30. package/dist/indexed-db/db-object-store.js +38 -0
  31. package/dist/indexed-db/db-object-store.js.map +1 -0
  32. package/dist/indexed-db/db-transaction.d.ts +13 -0
  33. package/dist/indexed-db/db-transaction.d.ts.map +1 -0
  34. package/dist/indexed-db/db-transaction.js +45 -0
  35. package/dist/indexed-db/db-transaction.js.map +1 -0
  36. package/dist/indexed-db/db.d.ts +17 -0
  37. package/dist/indexed-db/db.d.ts.map +1 -0
  38. package/dist/indexed-db/db.js +94 -0
  39. package/dist/indexed-db/db.js.map +1 -0
  40. package/dist/indexed-db/index.d.ts +5 -0
  41. package/dist/indexed-db/index.d.ts.map +1 -0
  42. package/dist/indexed-db/index.js +5 -0
  43. package/dist/indexed-db/index.js.map +1 -0
  44. package/dist/indexed-db/schema.d.ts +3 -0
  45. package/dist/indexed-db/schema.d.ts.map +1 -0
  46. package/dist/indexed-db/schema.js +2 -0
  47. package/dist/indexed-db/schema.js.map +1 -0
  48. package/dist/indexed-db/util.d.ts +3 -0
  49. package/dist/indexed-db/util.d.ts.map +1 -0
  50. package/dist/indexed-db/util.js +22 -0
  51. package/dist/indexed-db/util.js.map +1 -0
  52. package/dist/indexed-db-store.d.ts +18 -0
  53. package/dist/indexed-db-store.d.ts.map +1 -0
  54. package/dist/indexed-db-store.js +54 -0
  55. package/dist/indexed-db-store.js.map +1 -0
  56. package/dist/util.d.ts +18 -0
  57. package/dist/util.d.ts.map +1 -0
  58. package/dist/util.js +15 -0
  59. package/dist/util.js.map +1 -0
  60. package/package.json +50 -0
@@ -0,0 +1,54 @@
1
+ import { DB } from './indexed-db/index.js';
2
+ const storeName = 'store';
3
+ export class IndexedDBStore {
4
+ constructor(dbName, maxAge = 600e3) {
5
+ this.dbName = dbName;
6
+ this.maxAge = maxAge;
7
+ }
8
+ async run(mode, fn) {
9
+ const db = await DB.open(this.dbName, [
10
+ (db) => {
11
+ const store = db.createObjectStore(storeName);
12
+ store.createIndex('createdAt', 'createdAt', { unique: false });
13
+ },
14
+ ], { durability: 'strict' });
15
+ try {
16
+ return await db.transaction([storeName], mode, (tx) => fn(tx.objectStore(storeName)));
17
+ }
18
+ finally {
19
+ await db[Symbol.asyncDispose]();
20
+ }
21
+ }
22
+ async get(key) {
23
+ const item = await this.run('readonly', (store) => store.get(key));
24
+ if (!item)
25
+ return undefined;
26
+ const age = Date.now() - item.createdAt.getTime();
27
+ if (age > this.maxAge) {
28
+ await this.del(key);
29
+ return undefined;
30
+ }
31
+ return item?.value;
32
+ }
33
+ async set(key, value) {
34
+ await this.run('readwrite', (store) => {
35
+ store.put({ value, createdAt: new Date() }, key);
36
+ });
37
+ }
38
+ async del(key) {
39
+ await this.run('readwrite', (store) => {
40
+ store.delete(key);
41
+ });
42
+ }
43
+ async deleteOutdated() {
44
+ const upperBound = new Date(Date.now() - this.maxAge);
45
+ const query = IDBKeyRange.upperBound(upperBound);
46
+ await this.run('readwrite', async (store) => {
47
+ const index = store.index('createdAt');
48
+ const keys = await index.getAllKeys(query);
49
+ for (const key of keys)
50
+ store.delete(key);
51
+ });
52
+ }
53
+ }
54
+ //# sourceMappingURL=indexed-db-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexed-db-store.js","sourceRoot":"","sources":["../src/indexed-db-store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAsB,MAAM,uBAAuB,CAAA;AAE9D,MAAM,SAAS,GAAG,OAAO,CAAA;AAMzB,MAAM,OAAO,cAAc;IAIzB,YACU,MAAc,EACZ,MAAM,GAAG,KAAK;sBADhB,MAAM;sBACJ,MAAM;IACf,CAAC;IAEM,KAAK,CAAC,GAAG,CACjB,IAA8B,EAC9B,EAAiD;QAEjD,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,IAAI,CACtB,IAAI,CAAC,MAAM,EACX;YACE,CAAC,EAAE,EAAE,EAAE;gBACL,MAAM,KAAK,GAAG,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAA;gBAC7C,KAAK,CAAC,WAAW,CAAC,WAAW,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;YAChE,CAAC;SACF,EACD,EAAE,UAAU,EAAE,QAAQ,EAAE,CACzB,CAAA;QACD,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAA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C,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;QACrD,MAAM,KAAK,GAAG,WAAW,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;QAEhD,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;YAC1C,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;YACtC,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;YAC1C,KAAK,MAAM,GAAG,IAAI,IAAI;gBAAE,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC3C,CAAC,CAAC,CAAA;IACJ,CAAC;CACF","sourcesContent":["import type { Key, SimpleStore, Value } from '@atproto-labs/simple-store'\nimport { DB, type DBObjectStore } from './indexed-db/index.js'\n\nconst storeName = 'store'\ntype Item<V> = {\n value: V\n createdAt: Date\n}\n\nexport class IndexedDBStore<\n K extends Extract<IDBValidKey, Key>,\n V extends Value,\n> implements SimpleStore<K, V> {\n constructor(\n private dbName: string,\n protected maxAge = 600e3,\n ) {}\n\n protected async run<R>(\n mode: 'readonly' | 'readwrite',\n fn: (s: DBObjectStore<Item<V>>) => R | Promise<R>,\n ): Promise<R> {\n const db = await DB.open<{ store: Item<V> }>(\n this.dbName,\n [\n (db) => {\n const store = db.createObjectStore(storeName)\n store.createIndex('createdAt', 'createdAt', { unique: false })\n },\n ],\n { durability: 'strict' },\n )\n try {\n return await db.transaction([storeName], mode, (tx) =>\n fn(tx.objectStore(storeName)),\n )\n } finally {\n await db[Symbol.asyncDispose]()\n }\n }\n\n async get(key: K): Promise<V | undefined> {\n const item = await this.run('readonly', (store) => store.get(key))\n\n if (!item) return undefined\n\n const age = Date.now() - item.createdAt.getTime()\n if (age > this.maxAge) {\n await this.del(key)\n return undefined\n }\n\n return item?.value\n }\n\n async set(key: K, value: V): Promise<void> {\n await this.run('readwrite', (store) => {\n store.put({ value, createdAt: new Date() }, key)\n })\n }\n\n async del(key: K): Promise<void> {\n await this.run('readwrite', (store) => {\n store.delete(key)\n })\n }\n\n async deleteOutdated() {\n const upperBound = new Date(Date.now() - this.maxAge)\n const query = IDBKeyRange.upperBound(upperBound)\n\n await this.run('readwrite', async (store) => {\n const index = store.index('createdAt')\n const keys = await index.getAllKeys(query)\n for (const key of keys) store.delete(key)\n })\n }\n}\n"]}
package/dist/util.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ export type Simplify<T> = {
2
+ [K in keyof T]: T[K];
3
+ } & NonNullable<unknown>;
4
+ export type TupleUnion<U extends string, R extends any[] = []> = {
5
+ [S in U]: Exclude<U, S> extends never ? [...R, S] : TupleUnion<Exclude<U, S>, [...R, S]>;
6
+ }[U];
7
+ /**
8
+ * @example
9
+ * ```ts
10
+ * const clientId = buildLoopbackClientId(window.location)
11
+ * ```
12
+ */
13
+ export declare function buildLoopbackClientId(location: {
14
+ hostname: string;
15
+ pathname: string;
16
+ port: string;
17
+ }, localhost?: string): string;
18
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;AACzE,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,GAAG,EAAE,GAAG,EAAE,IAAI;KAC9D,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,KAAK,GACjC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GACT,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;CACzC,CAAC,CAAC,CAAC,CAAA;AAEJ;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE;IACR,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;CACb,EACD,SAAS,SAAc,GACtB,MAAM,CAUR"}
package/dist/util.js ADDED
@@ -0,0 +1,15 @@
1
+ import { isLoopbackHost } from '@atproto/oauth-types';
2
+ /**
3
+ * @example
4
+ * ```ts
5
+ * const clientId = buildLoopbackClientId(window.location)
6
+ * ```
7
+ */
8
+ export function buildLoopbackClientId(location, localhost = '127.0.0.1') {
9
+ if (!isLoopbackHost(location.hostname)) {
10
+ throw new TypeError(`Expected a loopback host, got ${location.hostname}`);
11
+ }
12
+ const redirectUri = `http://${location.hostname === 'localhost' ? localhost : location.hostname}${location.port && !location.port.startsWith(':') ? `:${location.port}` : location.port}${location.pathname}`;
13
+ return `http://localhost${location.pathname === '/' ? '' : location.pathname}?redirect_uri=${encodeURIComponent(redirectUri)}`;
14
+ }
15
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AASrD;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAIC,EACD,SAAS,GAAG,WAAW;IAEvB,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,SAAS,CAAC,iCAAiC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAA;IAC3E,CAAC;IAED,MAAM,WAAW,GAAG,UAAU,QAAQ,CAAC,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAA;IAE7M,OAAO,mBACL,QAAQ,CAAC,QAAQ,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,QAC5C,iBAAiB,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAA;AACpD,CAAC","sourcesContent":["import { isLoopbackHost } from '@atproto/oauth-types'\n\nexport type Simplify<T> = { [K in keyof T]: T[K] } & NonNullable<unknown>\nexport type TupleUnion<U extends string, R extends any[] = []> = {\n [S in U]: Exclude<U, S> extends never\n ? [...R, S]\n : TupleUnion<Exclude<U, S>, [...R, S]>\n}[U]\n\n/**\n * @example\n * ```ts\n * const clientId = buildLoopbackClientId(window.location)\n * ```\n */\nexport function buildLoopbackClientId(\n location: {\n hostname: string\n pathname: string\n port: string\n },\n localhost = '127.0.0.1',\n): string {\n if (!isLoopbackHost(location.hostname)) {\n throw new TypeError(`Expected a loopback host, got ${location.hostname}`)\n }\n\n const redirectUri = `http://${location.hostname === 'localhost' ? localhost : location.hostname}${location.port && !location.port.startsWith(':') ? `:${location.port}` : location.port}${location.pathname}`\n\n return `http://localhost${\n location.pathname === '/' ? '' : location.pathname\n }?redirect_uri=${encodeURIComponent(redirectUri)}`\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@atproto/oauth-client-browser",
3
+ "version": "0.0.0-spaces-alpha-20260818163953",
4
+ "license": "MIT",
5
+ "description": "ATPROTO OAuth client for the browser (relies on WebCrypto & Indexed DB)",
6
+ "keywords": [
7
+ "atproto",
8
+ "oauth",
9
+ "client",
10
+ "browser",
11
+ "webcrypto",
12
+ "indexed",
13
+ "db"
14
+ ],
15
+ "homepage": "https://atproto.com",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/bluesky-social/atproto",
19
+ "directory": "packages/oauth/oauth-client-browser"
20
+ },
21
+ "files": [
22
+ "./dist",
23
+ "./README.md",
24
+ "./CHANGELOG.md"
25
+ ],
26
+ "type": "module",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.js"
31
+ }
32
+ },
33
+ "engines": {
34
+ "node": ">=22"
35
+ },
36
+ "dependencies": {
37
+ "core-js": "^3",
38
+ "@atproto-labs/did-resolver": "^0.3.7",
39
+ "@atproto-labs/handle-resolver": "^0.4.8",
40
+ "@atproto/did": "^0.5.4",
41
+ "@atproto-labs/simple-store": "^0.5.1",
42
+ "@atproto/jwk": "^0.7.4",
43
+ "@atproto/oauth-types": "^0.7.5",
44
+ "@atproto/jwk-webcrypto": "^0.3.4",
45
+ "@atproto/oauth-client": "^0.0.0-spaces-alpha-20260818163953"
46
+ },
47
+ "scripts": {
48
+ "build": "tsc --build tsconfig.build.json"
49
+ }
50
+ }