@atproto/oauth-client-browser 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE.txt +7 -0
- package/dist/browser-oauth-client.d.ts +58 -0
- package/dist/browser-oauth-client.d.ts.map +1 -0
- package/dist/browser-oauth-client.js +353 -0
- package/dist/browser-oauth-client.js.map +1 -0
- package/dist/browser-oauth-database.d.ts +61 -0
- package/dist/browser-oauth-database.d.ts.map +1 -0
- package/dist/browser-oauth-database.js +175 -0
- package/dist/browser-oauth-database.js.map +1 -0
- package/dist/browser-runtime-implementation.d.ts +10 -0
- package/dist/browser-runtime-implementation.d.ts.map +1 -0
- package/dist/browser-runtime-implementation.js +56 -0
- package/dist/browser-runtime-implementation.js.map +1 -0
- package/dist/disposable-polyfill/index.d.ts +1 -0
- package/dist/disposable-polyfill/index.d.ts.map +1 -0
- package/dist/disposable-polyfill/index.js +11 -0
- package/dist/disposable-polyfill/index.js.map +1 -0
- package/dist/errors.d.ts +9 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/indexed-db/db-index.d.ts +12 -0
- package/dist/indexed-db/db-index.d.ts.map +1 -0
- package/dist/indexed-db/db-index.js +49 -0
- package/dist/indexed-db/db-index.js.map +1 -0
- package/dist/indexed-db/db-object-store.d.ts +17 -0
- package/dist/indexed-db/db-object-store.d.ts.map +1 -0
- package/dist/indexed-db/db-object-store.js +47 -0
- package/dist/indexed-db/db-object-store.js.map +1 -0
- package/dist/indexed-db/db-transaction.d.ts +13 -0
- package/dist/indexed-db/db-transaction.d.ts.map +1 -0
- package/dist/indexed-db/db-transaction.js +60 -0
- package/dist/indexed-db/db-transaction.js.map +1 -0
- package/dist/indexed-db/db.d.ts +17 -0
- package/dist/indexed-db/db.d.ts.map +1 -0
- package/dist/indexed-db/db.js +114 -0
- package/dist/indexed-db/db.js.map +1 -0
- package/dist/indexed-db/index.d.ts +6 -0
- package/dist/indexed-db/index.d.ts.map +1 -0
- package/dist/indexed-db/index.js +22 -0
- package/dist/indexed-db/index.js.map +1 -0
- package/dist/indexed-db/schema.d.ts +3 -0
- package/dist/indexed-db/schema.d.ts.map +1 -0
- package/dist/indexed-db/schema.js +3 -0
- package/dist/indexed-db/schema.js.map +1 -0
- package/dist/indexed-db/util.d.ts +2 -0
- package/dist/indexed-db/util.d.ts.map +1 -0
- package/dist/indexed-db/util.js +24 -0
- package/dist/indexed-db/util.js.map +1 -0
- package/dist/indexed-db-store.d.ts +18 -0
- package/dist/indexed-db-store.d.ts.map +1 -0
- package/dist/indexed-db-store.js +68 -0
- package/dist/indexed-db-store.js.map +1 -0
- package/dist/util.d.ts +18 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +19 -0
- package/dist/util.js.map +1 -0
- package/package.json +72 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/indexed-db/db.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,qBAAa,EAAE,CAAC,MAAM,SAAS,cAAc,CAAE,YAAW,UAAU;;IAqChE,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC;WApClB,IAAI,CAAC,MAAM,SAAS,cAAc,GAAG,cAAc,EAC9D,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,aAAa,CAAC,CAAC,EAAE,EAAE,WAAW,KAAK,IAAI,CAAC,EACpD,SAAS,CAAC,EAAE,qBAAqB;gBAgCjC,EAAE,EAAE,WAAW,EACI,SAAS,CAAC,mCAAuB;IAetD,SAAS,KAAK,EAAE,IAAI,WAAW,CAG9B;IAED,IAAI,IAAI,WAEP;IAED,IAAI,gBAAgB,kBAEnB;IAED,IAAI,OAAO,WAEV;IAEK,WAAW,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,EAAE,EAAE,CAAC,EAC/D,UAAU,EAAE,CAAC,EACb,IAAI,EAAE,kBAAkB,EACxB,GAAG,EAAE,CAAC,EAAE,EAAE,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GACtE,OAAO,CAAC,CAAC,CAAC;IA4Bb,KAAK;IAML,CAAC,MAAM,CAAC,OAAO,CAAC;CAGjB"}
|
@@ -0,0 +1,114 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
7
|
+
};
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
12
|
+
};
|
13
|
+
var _DB_db;
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.DB = void 0;
|
16
|
+
const db_transaction_js_1 = require("./db-transaction.js");
|
17
|
+
class DB {
|
18
|
+
static async open(dbName, migrations, txOptions) {
|
19
|
+
const db = await new Promise((resolve, reject) => {
|
20
|
+
const request = indexedDB.open(dbName, migrations.length);
|
21
|
+
request.onerror = () => reject(request.error);
|
22
|
+
request.onsuccess = () => resolve(request.result);
|
23
|
+
request.onupgradeneeded = ({ oldVersion, newVersion }) => {
|
24
|
+
const db = request.result;
|
25
|
+
try {
|
26
|
+
for (let version = oldVersion; version < (newVersion ?? migrations.length); ++version) {
|
27
|
+
const migration = migrations[version];
|
28
|
+
if (migration)
|
29
|
+
migration(db);
|
30
|
+
else
|
31
|
+
throw new Error(`Missing migration for version ${version}`);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
catch (err) {
|
35
|
+
db.close();
|
36
|
+
reject(err);
|
37
|
+
}
|
38
|
+
};
|
39
|
+
});
|
40
|
+
return new DB(db, txOptions);
|
41
|
+
}
|
42
|
+
constructor(db, txOptions) {
|
43
|
+
Object.defineProperty(this, "txOptions", {
|
44
|
+
enumerable: true,
|
45
|
+
configurable: true,
|
46
|
+
writable: true,
|
47
|
+
value: txOptions
|
48
|
+
});
|
49
|
+
_DB_db.set(this, void 0);
|
50
|
+
__classPrivateFieldSet(this, _DB_db, db, "f");
|
51
|
+
const cleanup = () => {
|
52
|
+
__classPrivateFieldSet(this, _DB_db, null, "f");
|
53
|
+
db.removeEventListener('versionchange', cleanup);
|
54
|
+
db.removeEventListener('close', cleanup);
|
55
|
+
db.close(); // Can we call close on a "closed" database?
|
56
|
+
};
|
57
|
+
db.addEventListener('versionchange', cleanup);
|
58
|
+
db.addEventListener('close', cleanup);
|
59
|
+
}
|
60
|
+
get db() {
|
61
|
+
if (!__classPrivateFieldGet(this, _DB_db, "f"))
|
62
|
+
throw new Error('Database closed');
|
63
|
+
return __classPrivateFieldGet(this, _DB_db, "f");
|
64
|
+
}
|
65
|
+
get name() {
|
66
|
+
return this.db.name;
|
67
|
+
}
|
68
|
+
get objectStoreNames() {
|
69
|
+
return this.db.objectStoreNames;
|
70
|
+
}
|
71
|
+
get version() {
|
72
|
+
return this.db.version;
|
73
|
+
}
|
74
|
+
async transaction(storeNames, mode, run) {
|
75
|
+
// eslint-disable-next-line no-async-promise-executor
|
76
|
+
return new Promise(async (resolve, reject) => {
|
77
|
+
try {
|
78
|
+
const tx = this.db.transaction(storeNames, mode, this.txOptions);
|
79
|
+
let result = { done: false };
|
80
|
+
tx.oncomplete = () => {
|
81
|
+
if (result.done)
|
82
|
+
resolve(result.value);
|
83
|
+
else
|
84
|
+
reject(new Error('Transaction completed without result'));
|
85
|
+
};
|
86
|
+
tx.onerror = () => reject(tx.error);
|
87
|
+
tx.onabort = () => reject(tx.error || new Error('Transaction aborted'));
|
88
|
+
try {
|
89
|
+
const value = await run(new db_transaction_js_1.DBTransaction(tx));
|
90
|
+
result = { done: true, value };
|
91
|
+
tx.commit();
|
92
|
+
}
|
93
|
+
catch (err) {
|
94
|
+
tx.abort();
|
95
|
+
throw err;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
catch (err) {
|
99
|
+
reject(err);
|
100
|
+
}
|
101
|
+
});
|
102
|
+
}
|
103
|
+
close() {
|
104
|
+
const { db } = this;
|
105
|
+
__classPrivateFieldSet(this, _DB_db, null, "f");
|
106
|
+
db.close();
|
107
|
+
}
|
108
|
+
[(_DB_db = new WeakMap(), Symbol.dispose)]() {
|
109
|
+
if (__classPrivateFieldGet(this, _DB_db, "f"))
|
110
|
+
return this.close();
|
111
|
+
}
|
112
|
+
}
|
113
|
+
exports.DB = DB;
|
114
|
+
//# sourceMappingURL=db.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/indexed-db/db.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,2DAAmD;AAEnD,MAAa,EAAE;IACb,MAAM,CAAC,KAAK,CAAC,IAAI,CACf,MAAc,EACd,UAAoD,EACpD,SAAiC;QAEjC,MAAM,EAAE,GAAG,MAAM,IAAI,OAAO,CAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC5D,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,MAAM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,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,IAAI,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAAA;gBAEvE,IAAI,CAAC;oBACH,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,IAAI,iCAAa,CAAC,EAAE,CAAC,CAAC,CAAA;oBAC9C,MAAM,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;oBAC9B,EAAE,CAAC,MAAM,EAAE,CAAA;gBACb,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,EAAE,CAAC,KAAK,EAAE,CAAA;oBACV,MAAM,GAAG,CAAA;gBACX,CAAC;YACH,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,CAAC,GAAG,CAAC,CAAA;YACb,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK;QACH,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAA;QACnB,uBAAA,IAAI,UAAO,IAAI,MAAA,CAAA;QACf,EAAE,CAAC,KAAK,EAAE,CAAA;IACZ,CAAC;IAED,0BAAC,MAAM,CAAC,OAAO,EAAC;QACd,IAAI,uBAAA,IAAI,cAAI;YAAE,OAAO,IAAI,CAAC,KAAK,EAAE,CAAA;IACnC,CAAC;CACF;AA9GD,gBA8GC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/indexed-db/index.ts"],"names":[],"mappings":"AAAA,OAAO,iCAAiC,CAAA;AAExC,cAAc,SAAS,CAAA;AACvB,cAAc,eAAe,CAAA;AAC7B,cAAc,sBAAsB,CAAA;AACpC,cAAc,qBAAqB,CAAA"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
require("../disposable-polyfill/index.js");
|
18
|
+
__exportStar(require("./db.js"), exports);
|
19
|
+
__exportStar(require("./db-index.js"), exports);
|
20
|
+
__exportStar(require("./db-object-store.js"), exports);
|
21
|
+
__exportStar(require("./db-transaction.js"), exports);
|
22
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/indexed-db/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwC;AAExC,0CAAuB;AACvB,gDAA6B;AAC7B,uDAAoC;AACpC,sDAAmC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/indexed-db/schema.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;AACpD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/indexed-db/schema.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/indexed-db/util.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,cAmBlD"}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.promisify = void 0;
|
4
|
+
function promisify(request) {
|
5
|
+
const promise = new Promise((resolve, reject) => {
|
6
|
+
const cleanup = () => {
|
7
|
+
request.removeEventListener('success', success);
|
8
|
+
request.removeEventListener('error', error);
|
9
|
+
};
|
10
|
+
const success = () => {
|
11
|
+
resolve(request.result);
|
12
|
+
cleanup();
|
13
|
+
};
|
14
|
+
const error = () => {
|
15
|
+
reject(request.error);
|
16
|
+
cleanup();
|
17
|
+
};
|
18
|
+
request.addEventListener('success', success);
|
19
|
+
request.addEventListener('error', error);
|
20
|
+
});
|
21
|
+
return promise;
|
22
|
+
}
|
23
|
+
exports.promisify = promisify;
|
24
|
+
//# sourceMappingURL=util.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/indexed-db/util.ts"],"names":[],"mappings":";;;AAAA,SAAgB,SAAS,CAAI,OAAsB;IACjD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACjD,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,OAAO,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;YAC/C,OAAO,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QAC7C,CAAC,CAAA;QACD,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;YACvB,OAAO,EAAE,CAAA;QACX,CAAC,CAAA;QACD,MAAM,KAAK,GAAG,GAAG,EAAE;YACjB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;YACrB,OAAO,EAAE,CAAA;QACX,CAAC,CAAA;QACD,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;QAC5C,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC1C,CAAC,CAAC,CAAA;IAEF,OAAO,OAAO,CAAA;AAChB,CAAC;AAnBD,8BAmBC"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { SimpleStore, Key, Value } from '@atproto-labs/simple-store';
|
2
|
+
import { DBObjectStore } from './indexed-db/index.js';
|
3
|
+
type Item<V> = {
|
4
|
+
value: V;
|
5
|
+
createdAt: Date;
|
6
|
+
};
|
7
|
+
export declare class IndexedDBStore<K extends Extract<IDBValidKey, Key>, V extends Value> implements SimpleStore<K, V> {
|
8
|
+
private dbName;
|
9
|
+
protected maxAge: number;
|
10
|
+
constructor(dbName: string, maxAge?: number);
|
11
|
+
protected run<R>(mode: 'readonly' | 'readwrite', fn: (s: DBObjectStore<Item<V>>) => R | Promise<R>): Promise<R>;
|
12
|
+
get(key: K): Promise<V | undefined>;
|
13
|
+
set(key: K, value: V): Promise<void>;
|
14
|
+
del(key: K): Promise<void>;
|
15
|
+
deleteOutdated(): Promise<void>;
|
16
|
+
}
|
17
|
+
export {};
|
18
|
+
//# sourceMappingURL=indexed-db-store.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"indexed-db-store.d.ts","sourceRoot":"","sources":["../src/indexed-db-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAA;AACpE,OAAO,EAAM,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAGzD,KAAK,IAAI,CAAC,CAAC,IAAI;IACb,KAAK,EAAE,CAAC,CAAA;IACR,SAAS,EAAE,IAAI,CAAA;CAChB,CAAA;AAED,qBAAa,cAAc,CACzB,CAAC,SAAS,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC,EACnC,CAAC,SAAS,KAAK,CACf,YAAW,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC;IAG1B,OAAO,CAAC,MAAM;IACd,SAAS,CAAC,MAAM;gBADR,MAAM,EAAE,MAAM,EACZ,MAAM,SAAQ;cAGV,GAAG,CAAC,CAAC,EACnB,IAAI,EAAE,UAAU,GAAG,WAAW,EAC9B,EAAE,EAAE,CAAC,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAChD,OAAO,CAAC,CAAC,CAAC;IAoBP,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAcnC,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAMpC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAM1B,cAAc;CAUrB"}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.IndexedDBStore = void 0;
|
4
|
+
const index_js_1 = require("./indexed-db/index.js");
|
5
|
+
const storeName = 'store';
|
6
|
+
class IndexedDBStore {
|
7
|
+
constructor(dbName, maxAge = 600e3) {
|
8
|
+
Object.defineProperty(this, "dbName", {
|
9
|
+
enumerable: true,
|
10
|
+
configurable: true,
|
11
|
+
writable: true,
|
12
|
+
value: dbName
|
13
|
+
});
|
14
|
+
Object.defineProperty(this, "maxAge", {
|
15
|
+
enumerable: true,
|
16
|
+
configurable: true,
|
17
|
+
writable: true,
|
18
|
+
value: maxAge
|
19
|
+
});
|
20
|
+
}
|
21
|
+
async run(mode, fn) {
|
22
|
+
const db = await index_js_1.DB.open(this.dbName, [
|
23
|
+
(db) => {
|
24
|
+
const store = db.createObjectStore(storeName);
|
25
|
+
store.createIndex('createdAt', 'createdAt', { unique: false });
|
26
|
+
},
|
27
|
+
], { durability: 'strict' });
|
28
|
+
try {
|
29
|
+
return await db.transaction([storeName], mode, (tx) => fn(tx.objectStore(storeName)));
|
30
|
+
}
|
31
|
+
finally {
|
32
|
+
await db[Symbol.dispose]();
|
33
|
+
}
|
34
|
+
}
|
35
|
+
async get(key) {
|
36
|
+
const item = await this.run('readonly', (store) => store.get(key));
|
37
|
+
if (!item)
|
38
|
+
return undefined;
|
39
|
+
const age = Date.now() - item.createdAt.getTime();
|
40
|
+
if (age > this.maxAge) {
|
41
|
+
await this.del(key);
|
42
|
+
return undefined;
|
43
|
+
}
|
44
|
+
return item?.value;
|
45
|
+
}
|
46
|
+
async set(key, value) {
|
47
|
+
await this.run('readwrite', (store) => {
|
48
|
+
store.put({ value, createdAt: new Date() }, key);
|
49
|
+
});
|
50
|
+
}
|
51
|
+
async del(key) {
|
52
|
+
await this.run('readwrite', (store) => {
|
53
|
+
store.delete(key);
|
54
|
+
});
|
55
|
+
}
|
56
|
+
async deleteOutdated() {
|
57
|
+
const upperBound = new Date(Date.now() - this.maxAge);
|
58
|
+
const query = IDBKeyRange.upperBound(upperBound);
|
59
|
+
await this.run('readwrite', async (store) => {
|
60
|
+
const index = store.index('createdAt');
|
61
|
+
const keys = await index.getAllKeys(query);
|
62
|
+
for (const key of keys)
|
63
|
+
store.delete(key);
|
64
|
+
});
|
65
|
+
}
|
66
|
+
}
|
67
|
+
exports.IndexedDBStore = IndexedDBStore;
|
68
|
+
//# 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,oDAAyD;AAEzD,MAAM,SAAS,GAAG,OAAO,CAAA;AAMzB,MAAa,cAAc;IAKzB,YACU,MAAc,EACZ,SAAS,KAAK;QADxB;;;;mBAAQ,MAAM;WAAQ;QACtB;;;;m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AC;IAED,KAAK,CAAC,GAAG,CAAC,GAAM,EAAE,KAAQ;QACxB,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE;YACpC,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,EAAE,GAAG,CAAC,CAAA;QAClD,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAM;QACd,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE;YACpC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QACnB,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,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;AArED,wCAqEC"}
|
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,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.buildLoopbackClientId = void 0;
|
4
|
+
const oauth_types_1 = require("@atproto/oauth-types");
|
5
|
+
/**
|
6
|
+
* @example
|
7
|
+
* ```ts
|
8
|
+
* const clientId = buildLoopbackClientId(window.location)
|
9
|
+
* ```
|
10
|
+
*/
|
11
|
+
function buildLoopbackClientId(location, localhost = '127.0.0.1') {
|
12
|
+
if (!(0, oauth_types_1.isLoopbackHost)(location.hostname)) {
|
13
|
+
throw new TypeError(`Expected a loopback host, got ${location.hostname}`);
|
14
|
+
}
|
15
|
+
const redirectUri = `http://${location.hostname === 'localhost' ? localhost : location.hostname}${location.port && !location.port.startsWith(':') ? `:${location.port}` : location.port}${location.pathname}`;
|
16
|
+
return `http://localhost${location.pathname === '/' ? '' : location.pathname}?redirect_uri=${encodeURIComponent(redirectUri)}`;
|
17
|
+
}
|
18
|
+
exports.buildLoopbackClientId = buildLoopbackClientId;
|
19
|
+
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;AAAA,sDAAqD;AASrD;;;;;GAKG;AACH,SAAgB,qBAAqB,CACnC,QAIC,EACD,SAAS,GAAG,WAAW;IAEvB,IAAI,CAAC,IAAA,4BAAc,EAAC,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;AAjBD,sDAiBC"}
|
package/package.json
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
{
|
2
|
+
"name": "@atproto/oauth-client-browser",
|
3
|
+
"version": "0.1.0",
|
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
|
+
"type": "commonjs",
|
22
|
+
"main": "dist/index.js",
|
23
|
+
"types": "dist/index.d.ts",
|
24
|
+
"exports": {
|
25
|
+
".": {
|
26
|
+
"types": "./dist/index.d.ts",
|
27
|
+
"default": "./dist/index.js"
|
28
|
+
}
|
29
|
+
},
|
30
|
+
"files": [
|
31
|
+
"dist"
|
32
|
+
],
|
33
|
+
"dependencies": {
|
34
|
+
"@atproto-labs/did-resolver": "0.1.0",
|
35
|
+
"@atproto-labs/handle-resolver": "0.1.0",
|
36
|
+
"@atproto-labs/simple-store": "0.1.0",
|
37
|
+
"@atproto/did": "0.1.0",
|
38
|
+
"@atproto/jwk": "0.1.0",
|
39
|
+
"@atproto/jwk-webcrypto": "0.1.0",
|
40
|
+
"@atproto/oauth-client": "0.1.0",
|
41
|
+
"@atproto/oauth-types": "0.1.0"
|
42
|
+
},
|
43
|
+
"devDependencies": {
|
44
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
45
|
+
"@rollup/plugin-html": "^1.0.3",
|
46
|
+
"@rollup/plugin-json": "^6.1.0",
|
47
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
48
|
+
"@rollup/plugin-replace": "^5.0.5",
|
49
|
+
"@rollup/plugin-terser": "^0.4.4",
|
50
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
51
|
+
"@types/react": "^18.2.50",
|
52
|
+
"@types/react-dom": "^18.2.18",
|
53
|
+
"autoprefixer": "^10.4.17",
|
54
|
+
"postcss": "^8.4.33",
|
55
|
+
"react": "^18.2.0",
|
56
|
+
"react-dom": "^18.2.0",
|
57
|
+
"rollup": "^4.13.0",
|
58
|
+
"rollup-plugin-postcss": "^4.0.2",
|
59
|
+
"rollup-plugin-serve": "^1.1.1",
|
60
|
+
"tailwindcss": "^3.4.1",
|
61
|
+
"typescript": "^5.3.3",
|
62
|
+
"@atproto/api": "0.12.19",
|
63
|
+
"@atproto/oauth-client": "0.1.0",
|
64
|
+
"@atproto/oauth-client-browser": "0.1.0",
|
65
|
+
"@atproto/oauth-types": "0.1.0",
|
66
|
+
"@atproto/xrpc": "0.5.0"
|
67
|
+
},
|
68
|
+
"scripts": {
|
69
|
+
"build": "tsc --build tsconfig.build.json",
|
70
|
+
"dev": "cd ./example && rollup --config rollup.config.js --watch"
|
71
|
+
}
|
72
|
+
}
|