Skip to content

Commit

Permalink
feat: auth-client stores identities in indexeddb (#605)
Browse files Browse the repository at this point in the history
* feat: adds IdbStorage as new default for auth-client
* Adds IdbKeyVal interface
  • Loading branch information
krpeacock committed Aug 4, 2022
1 parent 02b790f commit f79ae86
Show file tree
Hide file tree
Showing 9 changed files with 501 additions and 74 deletions.
10 changes: 10 additions & 0 deletions docs/generated/changelog.html
Expand Up @@ -10,6 +10,16 @@
<h1>Agent-JS Changelog</h1>

<section>
<h2>Version 0.12.3</h2>
<ul>
<li>
AuthClient now uses IndexedDb by default. To use localStorage, import LocalStorage
provider and pass it during AuthClient.create().
</li>
<ul>
<li>Also offers a generic Indexed Db keyval store, IdbKeyVal</li>
</ul>
</ul>
<h2>Version 0.12.2</h2>
<ul>
<li>
Expand Down
213 changes: 210 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/auth-client/package.json
Expand Up @@ -51,11 +51,12 @@
"@dfinity/principal": "^0.12.2"
},
"devDependencies": {
"@trust/webcrypto": "^0.9.2",
"@peculiar/webcrypto": "^1.4.0",
"@typescript-eslint/eslint-plugin": "^5.30.5",
"@typescript-eslint/parser": "^5.30.5",
"eslint": "^8.19.0",
"eslint-plugin-jsdoc": "^39.3.3",
"fake-indexeddb": "^4.0.0",
"jest-environment-jsdom": "^28.1.2",
"text-encoding": "^0.7.0",
"tslint": "^5.20.0",
Expand All @@ -65,6 +66,7 @@
},
"dependencies": {
"@types/jest": "^28.1.4",
"idb": "^7.0.2",
"jest": "^28.1.2",
"ts-jest": "^28.0.5",
"ts-node": "^10.8.2"
Expand Down
35 changes: 35 additions & 0 deletions packages/auth-client/src/db.test.ts
@@ -0,0 +1,35 @@
import 'fake-indexeddb/auto';
import { IdbKeyVal } from './db';

let testCounter = 0;

const testDb = async () => {
return await IdbKeyVal.create({
dbName: 'db-' + testCounter,
storeName: 'store-' + testCounter,
});
};

beforeEach(() => {
testCounter += 1;
});

describe('indexeddb wrapper', () => {
it('should store a basic key value', async () => {
const db = await testDb();
const shouldSet = async () => await db.set('testKey', 'testValue');
expect(shouldSet).not.toThrow();

expect(await db.get('testKey')).toBe('testValue');
});
it('should support removing a value', async () => {
const db = await testDb();
await db.set('testKey', 'testValue');

expect(await db.get('testKey')).toBe('testValue');

await db.remove('testKey');

expect(await db.get('testKey')).toBe(null);
});
});

0 comments on commit f79ae86

Please sign in to comment.