From 0b61af5a5203674ea9c4f9a5618877b4ea747397 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 8 Jul 2025 10:47:21 -0600 Subject: [PATCH] Update examples, provide new format --- example-input.json => example-input-1.jsonl | 0 example-input-2.jsonl | 2 ++ src/password-store/index.ts | 19 +++++++++++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) rename example-input.json => example-input-1.jsonl (100%) create mode 100644 example-input-2.jsonl diff --git a/example-input.json b/example-input-1.jsonl similarity index 100% rename from example-input.json rename to example-input-1.jsonl diff --git a/example-input-2.jsonl b/example-input-2.jsonl new file mode 100644 index 0000000..88eacd0 --- /dev/null +++ b/example-input-2.jsonl @@ -0,0 +1,2 @@ +{ "_id": "64db9dba7f18450dc250234", "firstName": "Mickey", "lastName": "Mouse", "email":"jason+test8@foo-corp.com", "emailVerified": true, "passwordHash":"$2b$10$.qHPp/srqo1NAAAAAvlkmOdqAbH2Rg0qPv2Txj3ZwXfjJnewSjc4m" } +{ "_id": "64db9dba7f18450dc250567", "firstName": "Donald", "lastName": "Duck", "email":"jason+test9@foo-corp.com", "emailVerified": false, "passwordHash":"$2b$10$.qHPp/srqo1NAAAAAvlkmOdqAbH2Rg0qPv2Txj3ZwXfjJnewSjc4m" } diff --git a/src/password-store/index.ts b/src/password-store/index.ts index 5b9120e..27599e0 100644 --- a/src/password-store/index.ts +++ b/src/password-store/index.ts @@ -5,9 +5,12 @@ import SQLite from "better-sqlite3"; import { Database, Password } from "./database"; const ExportedPassword = z.object({ - _id: z.object({ - $oid: z.string(), - }), + _id: z.union([ + z.string(), + z.object({ + $oid: z.string(), + }), + ]), passwordHash: z.string(), }); @@ -30,10 +33,18 @@ export class PasswordStore { for await (const line of ndjsonStream(passwordExportFilePath)) { const exportedPassword = ExportedPassword.parse(line); + let auth0Id = typeof exportedPassword._id === 'string' + ? exportedPassword._id + : exportedPassword._id.$oid; + + if (!auth0Id.startsWith('auth0|')) { + auth0Id = `auth0|${auth0Id}`; + } + await this.db .insertInto("passwords") .values({ - auth0_id: exportedPassword._id.$oid, + auth0_id: auth0Id, password_hash: exportedPassword.passwordHash, }) .onConflict((oc) => oc.doNothing())