@party-stack/node-runtime 0.3.0 → 0.3.2

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 (37) hide show
  1. package/lib/NodeFileSystemBlobBytesStore.d.ts +10 -8
  2. package/lib/NodeFileSystemBlobBytesStore.d.ts.map +1 -1
  3. package/lib/NodeFileSystemBlobBytesStore.js +42 -41
  4. package/lib/NodeFileSystemBlobBytesStore.js.map +1 -1
  5. package/lib/NodeSecretStore.d.ts +9 -7
  6. package/lib/NodeSecretStore.d.ts.map +1 -1
  7. package/lib/NodeSecretStore.js +38 -40
  8. package/lib/NodeSecretStore.js.map +1 -1
  9. package/lib/createNodeBrowserAuthentication.d.ts +5 -3
  10. package/lib/createNodeBrowserAuthentication.d.ts.map +1 -1
  11. package/lib/createNodeBrowserAuthentication.js +91 -102
  12. package/lib/createNodeBrowserAuthentication.js.map +1 -1
  13. package/lib/createNodeRuntime.d.ts +4 -2
  14. package/lib/createNodeRuntime.d.ts.map +1 -1
  15. package/lib/createNodeRuntime.js +41 -55
  16. package/lib/createNodeRuntime.js.map +1 -1
  17. package/lib/index.d.ts +2 -2
  18. package/lib/index.js +1 -2
  19. package/package.json +12 -18
  20. package/lib/NodeFileSystemBlobBytesStore.test.d.ts +0 -2
  21. package/lib/NodeFileSystemBlobBytesStore.test.d.ts.map +0 -1
  22. package/lib/NodeFileSystemBlobBytesStore.test.js +0 -38
  23. package/lib/NodeFileSystemBlobBytesStore.test.js.map +0 -1
  24. package/lib/NodeSecretStore.test.d.ts +0 -2
  25. package/lib/NodeSecretStore.test.d.ts.map +0 -1
  26. package/lib/NodeSecretStore.test.js +0 -69
  27. package/lib/NodeSecretStore.test.js.map +0 -1
  28. package/lib/createNodeBrowserAuthentication.test.d.ts +0 -2
  29. package/lib/createNodeBrowserAuthentication.test.d.ts.map +0 -1
  30. package/lib/createNodeBrowserAuthentication.test.js +0 -74
  31. package/lib/createNodeBrowserAuthentication.test.js.map +0 -1
  32. package/lib/createNodeRuntime.test.d.ts +0 -2
  33. package/lib/createNodeRuntime.test.d.ts.map +0 -1
  34. package/lib/createNodeRuntime.test.js +0 -172
  35. package/lib/createNodeRuntime.test.js.map +0 -1
  36. package/lib/index.d.ts.map +0 -1
  37. package/lib/index.js.map +0 -1
@@ -1,13 +1,15 @@
1
- import type { BlobBytesStore } from "@party-stack/runtime";
1
+ import { BlobBytesStore } from "@party-stack/runtime";
2
+ //#region src/NodeFileSystemBlobBytesStore.d.ts
2
3
  export interface NodeFileSystemBlobBytesStoreOptions {
3
- directory: string;
4
+ directory: string;
4
5
  }
5
6
  export declare class NodeFileSystemBlobBytesStore implements BlobBytesStore {
6
- #private;
7
- constructor(options: NodeFileSystemBlobBytesStoreOptions);
8
- write(id: string, blob: Blob): Promise<void>;
9
- read(id: string): Promise<Blob>;
10
- delete(id: string): Promise<void>;
11
- clear(): Promise<void>;
7
+ #private;
8
+ constructor(options: NodeFileSystemBlobBytesStoreOptions);
9
+ write(id: string, blob: Blob): Promise<void>;
10
+ read(id: string): Promise<Blob>;
11
+ delete(id: string): Promise<void>;
12
+ clear(): Promise<void>;
12
13
  }
14
+ //#endregion
13
15
  //# sourceMappingURL=NodeFileSystemBlobBytesStore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NodeFileSystemBlobBytesStore.d.ts","sourceRoot":"","sources":["../src/NodeFileSystemBlobBytesStore.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,MAAM,WAAW,mCAAmC;IAChD,SAAS,EAAE,MAAM,CAAC;CACrB;AAMD,qBAAa,4BAA6B,YAAW,cAAc;;gBAGnD,OAAO,EAAE,mCAAmC;IAIlD,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5C,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAa/B,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAO/B"}
1
+ {"version":3,"file":"NodeFileSystemBlobBytesStore.d.ts","names":[],"sources":["../src/NodeFileSystemBlobBytesStore.ts"],"mappings":";;iBAKiB;EACb;;qBAOS,wCAAwC;;EAGjD,YAAY,SAAS;EAIf,MAAM,YAAY,MAAM,OAAO;EAY/B,KAAK,aAAa,QAAQ;EAa1B,OAAO,aAAa;EAIpB,SAAS"}
@@ -1,47 +1,48 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
2
  import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
+ //#region src/NodeFileSystemBlobBytesStore.ts
4
5
  function fileName(id) {
5
- return createHash("sha256").update(id).digest("hex");
6
- }
7
- export class NodeFileSystemBlobBytesStore {
8
- #directory;
9
- constructor(options) {
10
- this.#directory = options.directory;
11
- }
12
- async write(id, blob) {
13
- await mkdir(this.#directory, { recursive: true });
14
- const target = this.#path(id);
15
- const temporary = join(this.#directory, `.${fileName(id)}.${randomUUID()}.tmp`);
16
- try {
17
- await writeFile(temporary, new Uint8Array(await blob.arrayBuffer()));
18
- await rename(temporary, target);
19
- }
20
- finally {
21
- await rm(temporary, { force: true });
22
- }
23
- }
24
- async read(id) {
25
- try {
26
- return new Blob([await readFile(this.#path(id))]);
27
- }
28
- catch (error) {
29
- if (error instanceof Error && "code" in error && error.code === "ENOENT") {
30
- throw new Error(`Blob bytes not found for "${id}".`, {
31
- cause: error,
32
- });
33
- }
34
- throw error;
35
- }
36
- }
37
- async delete(id) {
38
- await rm(this.#path(id), { force: true });
39
- }
40
- async clear() {
41
- await rm(this.#directory, { recursive: true, force: true });
42
- }
43
- #path(id) {
44
- return join(this.#directory, fileName(id));
45
- }
6
+ return createHash("sha256").update(id).digest("hex");
46
7
  }
8
+ var NodeFileSystemBlobBytesStore = class {
9
+ #directory;
10
+ constructor(options) {
11
+ this.#directory = options.directory;
12
+ }
13
+ async write(id, blob) {
14
+ await mkdir(this.#directory, { recursive: true });
15
+ const target = this.#path(id);
16
+ const temporary = join(this.#directory, `.${fileName(id)}.${randomUUID()}.tmp`);
17
+ try {
18
+ await writeFile(temporary, new Uint8Array(await blob.arrayBuffer()));
19
+ await rename(temporary, target);
20
+ } finally {
21
+ await rm(temporary, { force: true });
22
+ }
23
+ }
24
+ async read(id) {
25
+ try {
26
+ return new Blob([await readFile(this.#path(id))]);
27
+ } catch (error) {
28
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") throw new Error(`Blob bytes not found for "${id}".`, { cause: error });
29
+ throw error;
30
+ }
31
+ }
32
+ async delete(id) {
33
+ await rm(this.#path(id), { force: true });
34
+ }
35
+ async clear() {
36
+ await rm(this.#directory, {
37
+ recursive: true,
38
+ force: true
39
+ });
40
+ }
41
+ #path(id) {
42
+ return join(this.#directory, fileName(id));
43
+ }
44
+ };
45
+ //#endregion
46
+ export { NodeFileSystemBlobBytesStore };
47
+
47
48
  //# sourceMappingURL=NodeFileSystemBlobBytesStore.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"NodeFileSystemBlobBytesStore.js","sourceRoot":"","sources":["../src/NodeFileSystemBlobBytesStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAOjC,SAAS,QAAQ,CAAC,EAAU;IACxB,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,OAAO,4BAA4B;IAC5B,UAAU,CAAS;IAE5B,YA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AAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,KAAK;QACP,MAAM,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,EAAU;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC;CACJ"}
1
+ {"version":3,"file":"NodeFileSystemBlobBytesStore.js","names":[],"sources":["../src/NodeFileSystemBlobBytesStore.ts"],"sourcesContent":["import { createHash, randomUUID } from \"node:crypto\";\nimport { mkdir, readFile, rename, rm, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport type { BlobBytesStore } from \"@party-stack/runtime\";\n\nexport interface NodeFileSystemBlobBytesStoreOptions {\n directory: string;\n}\n\nfunction fileName(id: string): string {\n return createHash(\"sha256\").update(id).digest(\"hex\");\n}\n\nexport class NodeFileSystemBlobBytesStore implements BlobBytesStore {\n readonly #directory: string;\n\n constructor(options: NodeFileSystemBlobBytesStoreOptions) {\n this.#directory = options.directory;\n }\n\n async write(id: string, blob: Blob): Promise<void> {\n await mkdir(this.#directory, { recursive: true });\n const target = this.#path(id);\n const temporary = join(this.#directory, `.${fileName(id)}.${randomUUID()}.tmp`);\n try {\n await writeFile(temporary, new Uint8Array(await blob.arrayBuffer()));\n await rename(temporary, target);\n } finally {\n await rm(temporary, { force: true });\n }\n }\n\n async read(id: string): Promise<Blob> {\n try {\n return new Blob([await readFile(this.#path(id))]);\n } catch (error) {\n if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n throw new Error(`Blob bytes not found for \"${id}\".`, {\n cause: error,\n });\n }\n throw error;\n }\n }\n\n async delete(id: string): Promise<void> {\n await rm(this.#path(id), { force: true });\n }\n\n async clear(): Promise<void> {\n await rm(this.#directory, { recursive: true, force: true });\n }\n\n #path(id: string): string {\n return join(this.#directory, fileName(id));\n }\n}\n"],"mappings":";;;;AASA,SAAS,SAAS,IAAoB;CAClC,OAAO,WAAW,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,KAAK;AACvD;AAEA,IAAa,+BAAb,MAAoE;CAChE;CAEA,YAAY,SAA8C;EACtD,KAAK,aAAa,QAAQ;CAC9B;CAEA,MAAM,MAAM,IAAY,MAA2B;EAC/C,MAAM,MAAM,KAAK,YAAY,EAAE,WAAW,KAAK,CAAC;EAChD,MAAM,SAAS,KAAK,MAAM,EAAE;EAC5B,MAAM,YAAY,KAAK,KAAK,YAAY,IAAI,SAAS,EAAE,EAAE,GAAG,WAAW,EAAE,KAAK;EAC9E,IAAI;GACA,MAAM,UAAU,WAAW,IAAI,WAAW,MAAM,KAAK,YAAY,CAAC,CAAC;GACnE,MAAM,OAAO,WAAW,MAAM;EAClC,UAAU;GACN,MAAM,GAAG,WAAW,EAAE,OAAO,KAAK,CAAC;EACvC;CACJ;CAEA,MAAM,KAAK,IAA2B;EAClC,IAAI;GACA,OAAO,IAAI,KAAK,CAAC,MAAM,SAAS,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC;EACpD,SAAS,OAAO;GACZ,IAAI,iBAAiB,SAAS,UAAU,SAAS,MAAM,SAAS,UAC5D,MAAM,IAAI,MAAM,6BAA6B,GAAG,KAAK,EACjD,OAAO,MACX,CAAC;GAEL,MAAM;EACV;CACJ;CAEA,MAAM,OAAO,IAA2B;EACpC,MAAM,GAAG,KAAK,MAAM,EAAE,GAAG,EAAE,OAAO,KAAK,CAAC;CAC5C;CAEA,MAAM,QAAuB;EACzB,MAAM,GAAG,KAAK,YAAY;GAAE,WAAW;GAAM,OAAO;EAAK,CAAC;CAC9D;CAEA,MAAM,IAAoB;EACtB,OAAO,KAAK,KAAK,YAAY,SAAS,EAAE,CAAC;CAC7C;AACJ"}
@@ -1,12 +1,14 @@
1
- import type { SecretStore } from "@party-stack/runtime";
1
+ import { SecretStore } from "@party-stack/runtime";
2
+ //#region src/NodeSecretStore.d.ts
2
3
  export interface NodeSecretStoreOptions {
3
- service: string;
4
+ service: string;
4
5
  }
5
6
  export declare class NodeSecretStore implements SecretStore {
6
- #private;
7
- constructor(options: NodeSecretStoreOptions);
8
- get(key: string): Promise<string | undefined>;
9
- set(key: string, value: string): Promise<void>;
10
- delete(key: string): Promise<void>;
7
+ #private;
8
+ constructor(options: NodeSecretStoreOptions);
9
+ get(key: string): Promise<string | undefined>;
10
+ set(key: string, value: string): Promise<void>;
11
+ delete(key: string): Promise<void>;
11
12
  }
13
+ //#endregion
12
14
  //# sourceMappingURL=NodeSecretStore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NodeSecretStore.d.ts","sourceRoot":"","sources":["../src/NodeSecretStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAWxD,MAAM,WAAW,sBAAsB;IACnC,OAAO,EAAE,MAAM,CAAC;CACnB;AAkBD,qBAAa,eAAgB,YAAW,WAAW;;gBAInC,OAAO,EAAE,sBAAsB;IAIrC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAK7C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK9C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAa3C"}
1
+ {"version":3,"file":"NodeSecretStore.d.ts","names":[],"sources":["../src/NodeSecretStore.ts"],"mappings":";;iBAaiB;EACb;;qBAmBS,2BAA2B;;EAIpC,YAAY,SAAS;EAIf,IAAI,cAAc;EAKlB,IAAI,aAAa,gBAAgB;EAKjC,OAAO,cAAc"}
@@ -1,48 +1,46 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { getAllBackends } from "cross-keychain";
3
- const ALLOWED_BACKEND_IDS = new Set([
4
- "native-macos",
5
- "macos",
6
- "native-linux",
7
- "secret-service",
8
- "native-windows",
9
- "windows",
3
+ //#region src/NodeSecretStore.ts
4
+ const ALLOWED_BACKEND_IDS = /* @__PURE__ */ new Set([
5
+ "native-macos",
6
+ "macos",
7
+ "native-linux",
8
+ "secret-service",
9
+ "native-windows",
10
+ "windows"
10
11
  ]);
11
12
  async function selectOSKeychainBackend() {
12
- const candidates = (await getAllBackends()).filter((backend) => ALLOWED_BACKEND_IDS.has(backend.id));
13
- if (candidates.length === 0) {
14
- throw new Error("No OS keychain is available. Install or enable macOS Keychain, Windows Credential Manager, or a Linux Secret Service provider.");
15
- }
16
- return candidates.reduce((selected, candidate) => candidate.priority > selected.priority ? candidate : selected);
13
+ const candidates = (await getAllBackends()).filter((backend) => ALLOWED_BACKEND_IDS.has(backend.id));
14
+ if (candidates.length === 0) throw new Error("No OS keychain is available. Install or enable macOS Keychain, Windows Credential Manager, or a Linux Secret Service provider.");
15
+ return candidates.reduce((selected, candidate) => candidate.priority > selected.priority ? candidate : selected);
17
16
  }
18
17
  function encodeIdentifier(value) {
19
- return `party-stack.${createHash("sha256").update(value).digest("hex")}`;
20
- }
21
- export class NodeSecretStore {
22
- #service;
23
- #backend;
24
- constructor(options) {
25
- this.#service = encodeIdentifier(options.service);
26
- }
27
- async get(key) {
28
- const backend = await this.#getBackend();
29
- return (await backend.getPassword(this.#service, encodeIdentifier(key))) ?? undefined;
30
- }
31
- async set(key, value) {
32
- const backend = await this.#getBackend();
33
- await backend.setPassword(this.#service, encodeIdentifier(key), value);
34
- }
35
- async delete(key) {
36
- const backend = await this.#getBackend();
37
- const account = encodeIdentifier(key);
38
- if ((await backend.getPassword(this.#service, account)) === null) {
39
- return;
40
- }
41
- await backend.deletePassword(this.#service, account);
42
- }
43
- #getBackend() {
44
- this.#backend ??= selectOSKeychainBackend();
45
- return this.#backend;
46
- }
18
+ return `party-stack.${createHash("sha256").update(value).digest("hex")}`;
47
19
  }
20
+ var NodeSecretStore = class {
21
+ #service;
22
+ #backend;
23
+ constructor(options) {
24
+ this.#service = encodeIdentifier(options.service);
25
+ }
26
+ async get(key) {
27
+ return await (await this.#getBackend()).getPassword(this.#service, encodeIdentifier(key)) ?? void 0;
28
+ }
29
+ async set(key, value) {
30
+ await (await this.#getBackend()).setPassword(this.#service, encodeIdentifier(key), value);
31
+ }
32
+ async delete(key) {
33
+ const backend = await this.#getBackend();
34
+ const account = encodeIdentifier(key);
35
+ if (await backend.getPassword(this.#service, account) === null) return;
36
+ await backend.deletePassword(this.#service, account);
37
+ }
38
+ #getBackend() {
39
+ this.#backend ??= selectOSKeychainBackend();
40
+ return this.#backend;
41
+ }
42
+ };
43
+ //#endregion
44
+ export { NodeSecretStore };
45
+
48
46
  //# sourceMappingURL=NodeSecretStore.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"NodeSecretStore.js","sourceRoot":"","sources":["../src/NodeSecretStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAA6B,MAAM,gBAAgB,CAAC;AAG3E,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAChC,cAAc;IACd,OAAO;IACP,cAAc;IACd,gBAAgB;IAChB,gBAAgB;IAChB,SAAS;CACZ,CAAC,CAAC;AAMH,KAAK,UAAU,uBAAuB;IAClC,MAAM,UAAU,GAAG,CAAC,MAAM,cAAc,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IACrG,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACX,gIAAgI,CACnI,CAAC;IACN,CAAC;IACD,OAAO,UAAU,CAAC,MAAM,CAAC,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AC/D,OAAO;QACX,CAAC;QACD,MAAM,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;IAED,WAAW;QACP,IAAI,CAAC,QAAQ,KAAK,uBAAuB,EAAE,CAAC;QAC5C,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;CACJ"}
1
+ {"version":3,"file":"NodeSecretStore.js","names":[],"sources":["../src/NodeSecretStore.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { getAllBackends, type SecretStorageBackend } from \"cross-keychain\";\nimport type { SecretStore } from \"@party-stack/runtime\";\n\nconst ALLOWED_BACKEND_IDS = new Set([\n \"native-macos\",\n \"macos\",\n \"native-linux\",\n \"secret-service\",\n \"native-windows\",\n \"windows\",\n]);\n\nexport interface NodeSecretStoreOptions {\n service: string;\n}\n\nasync function selectOSKeychainBackend(): Promise<SecretStorageBackend> {\n const candidates = (await getAllBackends()).filter((backend) => ALLOWED_BACKEND_IDS.has(backend.id));\n if (candidates.length === 0) {\n throw new Error(\n \"No OS keychain is available. Install or enable macOS Keychain, Windows Credential Manager, or a Linux Secret Service provider.\"\n );\n }\n return candidates.reduce((selected, candidate) =>\n candidate.priority > selected.priority ? candidate : selected\n );\n}\n\nfunction encodeIdentifier(value: string): string {\n return `party-stack.${createHash(\"sha256\").update(value).digest(\"hex\")}`;\n}\n\nexport class NodeSecretStore implements SecretStore {\n readonly #service: string;\n #backend?: Promise<SecretStorageBackend>;\n\n constructor(options: NodeSecretStoreOptions) {\n this.#service = encodeIdentifier(options.service);\n }\n\n async get(key: string): Promise<string | undefined> {\n const backend = await this.#getBackend();\n return (await backend.getPassword(this.#service, encodeIdentifier(key))) ?? undefined;\n }\n\n async set(key: string, value: string): Promise<void> {\n const backend = await this.#getBackend();\n await backend.setPassword(this.#service, encodeIdentifier(key), value);\n }\n\n async delete(key: string): Promise<void> {\n const backend = await this.#getBackend();\n const account = encodeIdentifier(key);\n if ((await backend.getPassword(this.#service, account)) === null) {\n return;\n }\n await backend.deletePassword(this.#service, account);\n }\n\n #getBackend(): Promise<SecretStorageBackend> {\n this.#backend ??= selectOSKeychainBackend();\n return this.#backend;\n }\n}\n"],"mappings":";;;AAIA,MAAM,sCAAsB,IAAI,IAAI;CAChC;CACA;CACA;CACA;CACA;CACA;AACJ,CAAC;AAMD,eAAe,0BAAyD;CACpE,MAAM,cAAc,MAAM,eAAe,EAAA,CAAG,QAAQ,YAAY,oBAAoB,IAAI,QAAQ,EAAE,CAAC;CACnG,IAAI,WAAW,WAAW,GACtB,MAAM,IAAI,MACN,gIACJ;CAEJ,OAAO,WAAW,QAAQ,UAAU,cAChC,UAAU,WAAW,SAAS,WAAW,YAAY,QACzD;AACJ;AAEA,SAAS,iBAAiB,OAAuB;CAC7C,OAAO,eAAe,WAAW,QAAQ,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO,KAAK;AACzE;AAEA,IAAa,kBAAb,MAAoD;CAChD;CACA;CAEA,YAAY,SAAiC;EACzC,KAAK,WAAW,iBAAiB,QAAQ,OAAO;CACpD;CAEA,MAAM,IAAI,KAA0C;EAEhD,OAAQ,OAAM,MADQ,KAAK,YAAY,EAAA,CACjB,YAAY,KAAK,UAAU,iBAAiB,GAAG,CAAC,KAAM,KAAA;CAChF;CAEA,MAAM,IAAI,KAAa,OAA8B;EAEjD,OAAM,MADgB,KAAK,YAAY,EAAA,CACzB,YAAY,KAAK,UAAU,iBAAiB,GAAG,GAAG,KAAK;CACzE;CAEA,MAAM,OAAO,KAA4B;EACrC,MAAM,UAAU,MAAM,KAAK,YAAY;EACvC,MAAM,UAAU,iBAAiB,GAAG;EACpC,IAAK,MAAM,QAAQ,YAAY,KAAK,UAAU,OAAO,MAAO,MACxD;EAEJ,MAAM,QAAQ,eAAe,KAAK,UAAU,OAAO;CACvD;CAEA,cAA6C;EACzC,KAAK,aAAa,wBAAwB;EAC1C,OAAO,KAAK;CAChB;AACJ"}
@@ -1,7 +1,9 @@
1
- import { type BrowserAuthentication } from "@party-stack/runtime";
1
+ import { BrowserAuthentication } from "@party-stack/runtime";
2
+ //#region src/createNodeBrowserAuthentication.d.ts
2
3
  export interface CreateNodeBrowserAuthenticationOptions {
3
- openUrl?: (url: string) => Promise<unknown>;
4
- timeoutMs?: number;
4
+ openUrl?: (url: string) => Promise<unknown>;
5
+ timeoutMs?: number;
5
6
  }
6
7
  export declare function createNodeBrowserAuthentication(options?: CreateNodeBrowserAuthenticationOptions): BrowserAuthentication;
8
+ //#endregion
7
9
  //# sourceMappingURL=createNodeBrowserAuthentication.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createNodeBrowserAuthentication.d.ts","sourceRoot":"","sources":["../src/createNodeBrowserAuthentication.ts"],"names":[],"mappings":"AACA,OAAO,EAAuC,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAQvG,MAAM,WAAW,sCAAsC;IACnD,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAsBD,wBAAgB,+BAA+B,CAC3C,OAAO,GAAE,sCAA2C,GACrD,qBAAqB,CAuGvB"}
1
+ {"version":3,"file":"createNodeBrowserAuthentication.d.ts","names":[],"sources":["../src/createNodeBrowserAuthentication.ts"],"mappings":";;iBASiB;EACb,WAAW,gBAAgB;EAC3B;;wBAuBY,gCACZ,UAAS,yCACV"}
@@ -2,117 +2,106 @@ import { serve } from "@hono/node-server";
2
2
  import { BrowserAuthenticationCancelledError } from "@party-stack/runtime";
3
3
  import { Hono } from "hono";
4
4
  import open from "open";
5
- const DEFAULT_TIMEOUT_MS = 5 * 60 * 1000;
6
- const LOOPBACK_HOSTS = new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
5
+ //#region src/createNodeBrowserAuthentication.ts
6
+ const DEFAULT_TIMEOUT_MS = 3e5;
7
+ const LOOPBACK_HOSTS = /* @__PURE__ */ new Set([
8
+ "localhost",
9
+ "127.0.0.1",
10
+ "::1",
11
+ "[::1]"
12
+ ]);
7
13
  function closeServer(server) {
8
- if (!server?.listening)
9
- return Promise.resolve();
10
- return new Promise((resolve, reject) => {
11
- server.close((error) => {
12
- if (error)
13
- reject(error);
14
- else
15
- resolve();
16
- });
17
- });
14
+ if (!server?.listening) return Promise.resolve();
15
+ return new Promise((resolve, reject) => {
16
+ server.close((error) => {
17
+ if (error) reject(error);
18
+ else resolve();
19
+ });
20
+ });
18
21
  }
19
22
  function validateRedirectUrl(redirectUrl) {
20
- const url = new URL(redirectUrl);
21
- if (url.protocol !== "http:" || !LOOPBACK_HOSTS.has(url.hostname) || !url.port) {
22
- throw new Error("Node browser authentication requires an http:// loopback redirect URL with an explicit port.");
23
- }
24
- return url;
23
+ const url = new URL(redirectUrl);
24
+ if (url.protocol !== "http:" || !LOOPBACK_HOSTS.has(url.hostname) || !url.port) throw new Error("Node browser authentication requires an http:// loopback redirect URL with an explicit port.");
25
+ return url;
25
26
  }
26
- export function createNodeBrowserAuthentication(options = {}) {
27
- const openUrl = options.openUrl ?? ((url) => open(url));
28
- const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
29
- return {
30
- start({ redirectUrl }) {
31
- const redirect = validateRedirectUrl(redirectUrl);
32
- let server;
33
- let rejectPending;
34
- let timer;
35
- let settled = false;
36
- const finish = async () => {
37
- if (timer)
38
- clearTimeout(timer);
39
- timer = undefined;
40
- rejectPending = undefined;
41
- await closeServer(server);
42
- server = undefined;
43
- };
44
- return {
45
- open(authorizationUrl) {
46
- if (server || settled) {
47
- return Promise.reject(new Error("This browser authentication session has already been used."));
48
- }
49
- return new Promise((resolve, reject) => {
50
- rejectPending = reject;
51
- const app = new Hono();
52
- app.get(redirect.pathname, (context) => {
53
- if (settled) {
54
- return context.text("Authentication session is already complete.", 409);
55
- }
56
- settled = true;
57
- const callbackUrl = context.req.url;
58
- setImmediate(() => {
59
- void finish().then(() => resolve({
60
- callbackUrl,
61
- }), reject);
62
- });
63
- return context.html(`<!doctype html>
27
+ function createNodeBrowserAuthentication(options = {}) {
28
+ const openUrl = options.openUrl ?? ((url) => open(url));
29
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
30
+ return { start({ redirectUrl }) {
31
+ const redirect = validateRedirectUrl(redirectUrl);
32
+ let server;
33
+ let rejectPending;
34
+ let timer;
35
+ let settled = false;
36
+ const finish = async () => {
37
+ if (timer) clearTimeout(timer);
38
+ timer = void 0;
39
+ rejectPending = void 0;
40
+ await closeServer(server);
41
+ server = void 0;
42
+ };
43
+ return {
44
+ open(authorizationUrl) {
45
+ if (server || settled) return Promise.reject(/* @__PURE__ */ new Error("This browser authentication session has already been used."));
46
+ return new Promise((resolve, reject) => {
47
+ rejectPending = reject;
48
+ const app = new Hono();
49
+ app.get(redirect.pathname, (context) => {
50
+ if (settled) return context.text("Authentication session is already complete.", 409);
51
+ settled = true;
52
+ const callbackUrl = context.req.url;
53
+ setImmediate(() => {
54
+ finish().then(() => resolve({ callbackUrl }), reject);
55
+ });
56
+ return context.html(`<!doctype html>
64
57
  <html lang="en">
65
58
  <head><meta charset="utf-8"><title>Authentication complete</title></head>
66
59
  <body>
67
60
  <p>Authentication complete. Returning to the terminal…</p>
68
- <script>window.close()</script>
61
+ <script>window.close()<\/script>
69
62
  </body>
70
63
  </html>`);
71
- });
72
- server = serve({
73
- fetch: app.fetch,
74
- hostname: redirect.hostname.replace(/^\[|\]$/g, ""),
75
- port: Number(redirect.port),
76
- });
77
- server.once("error", (error) => {
78
- if (settled)
79
- return;
80
- settled = true;
81
- void finish().finally(() => reject(error));
82
- });
83
- server.once("listening", () => {
84
- if (settled)
85
- return;
86
- void Promise.resolve()
87
- .then(() => openUrl(authorizationUrl))
88
- .catch((error) => {
89
- if (settled)
90
- return;
91
- settled = true;
92
- const reason = error instanceof Error ? error : new Error(String(error));
93
- void finish().finally(() => reject(reason));
94
- });
95
- });
96
- timer = setTimeout(() => {
97
- if (settled)
98
- return;
99
- settled = true;
100
- void finish().finally(() => reject(new BrowserAuthenticationCancelledError("Browser authentication timed out.")));
101
- }, timeoutMs);
102
- });
103
- },
104
- async close() {
105
- if (settled) {
106
- await finish();
107
- return;
108
- }
109
- settled = true;
110
- const reject = rejectPending;
111
- await finish();
112
- reject?.(new BrowserAuthenticationCancelledError());
113
- },
114
- };
115
- },
116
- };
64
+ });
65
+ server = serve({
66
+ fetch: app.fetch,
67
+ hostname: redirect.hostname.replace(/^\[|\]$/g, ""),
68
+ port: Number(redirect.port)
69
+ });
70
+ server.once("error", (error) => {
71
+ if (settled) return;
72
+ settled = true;
73
+ finish().finally(() => reject(error));
74
+ });
75
+ server.once("listening", () => {
76
+ if (settled) return;
77
+ Promise.resolve().then(() => openUrl(authorizationUrl)).catch((error) => {
78
+ if (settled) return;
79
+ settled = true;
80
+ const reason = error instanceof Error ? error : new Error(String(error));
81
+ finish().finally(() => reject(reason));
82
+ });
83
+ });
84
+ timer = setTimeout(() => {
85
+ if (settled) return;
86
+ settled = true;
87
+ finish().finally(() => reject(new BrowserAuthenticationCancelledError("Browser authentication timed out.")));
88
+ }, timeoutMs);
89
+ });
90
+ },
91
+ async close() {
92
+ if (settled) {
93
+ await finish();
94
+ return;
95
+ }
96
+ settled = true;
97
+ const reject = rejectPending;
98
+ await finish();
99
+ reject?.(new BrowserAuthenticationCancelledError());
100
+ }
101
+ };
102
+ } };
117
103
  }
104
+ //#endregion
105
+ export { createNodeBrowserAuthentication };
106
+
118
107
  //# sourceMappingURL=createNodeBrowserAuthentication.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createNodeBrowserAuthentication.js","sourceRoot":"","sources":["../src/createNodeBrowserAuthentication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,mCAAmC,EAA8B,MAAM,sBAAsB,CAAC;AACvG,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM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AAE,CAAC,OAAO,CAAC,GAAG,EAAE,CACvB,MAAM,CACF,IAAI,mCAAmC,CACnC,mCAAmC,CACtC,CACJ,CACJ,CAAC;wBACN,CAAC,EAAE,SAAS,CAAC,CAAC;oBAClB,CAAC,CAAC,CAAC;gBACP,CAAC;gBACD,KAAK,CAAC,KAAK;oBACP,IAAI,OAAO,EAAE,CAAC;wBACV,MAAM,MAAM,EAAE,CAAC;wBACf,OAAO;oBACX,CAAC;oBACD,OAAO,GAAG,IAAI,CAAC;oBACf,MAAM,MAAM,GAAG,aAAa,CAAC;oBAC7B,MAAM,MAAM,EAAE,CAAC;oBACf,MAAM,EAAE,CAAC,IAAI,mCAAmC,EAAE,CAAC,CAAC;gBACxD,CAAC;aACJ,CAAC;QACN,CAAC;KACJ,CAAC;AACN,CAAC"}
1
+ {"version":3,"file":"createNodeBrowserAuthentication.js","names":[],"sources":["../src/createNodeBrowserAuthentication.ts"],"sourcesContent":["import { serve } from \"@hono/node-server\";\nimport { BrowserAuthenticationCancelledError, type BrowserAuthentication } from \"@party-stack/runtime\";\nimport { Hono } from \"hono\";\nimport open from \"open\";\nimport type { Server } from \"node:http\";\n\nconst DEFAULT_TIMEOUT_MS = 5 * 60 * 1000;\nconst LOOPBACK_HOSTS = new Set([\"localhost\", \"127.0.0.1\", \"::1\", \"[::1]\"]);\n\nexport interface CreateNodeBrowserAuthenticationOptions {\n openUrl?: (url: string) => Promise<unknown>;\n timeoutMs?: number;\n}\n\nfunction closeServer(server: Server | undefined): Promise<void> {\n if (!server?.listening) return Promise.resolve();\n return new Promise((resolve, reject) => {\n server.close((error) => {\n if (error) reject(error);\n else resolve();\n });\n });\n}\n\nfunction validateRedirectUrl(redirectUrl: string): URL {\n const url = new URL(redirectUrl);\n if (url.protocol !== \"http:\" || !LOOPBACK_HOSTS.has(url.hostname) || !url.port) {\n throw new Error(\n \"Node browser authentication requires an http:// loopback redirect URL with an explicit port.\"\n );\n }\n return url;\n}\n\nexport function createNodeBrowserAuthentication(\n options: CreateNodeBrowserAuthenticationOptions = {}\n): BrowserAuthentication {\n const openUrl = options.openUrl ?? ((url: string) => open(url));\n const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n\n return {\n start({ redirectUrl }) {\n const redirect = validateRedirectUrl(redirectUrl);\n let server: Server | undefined;\n let rejectPending: ((error: Error) => void) | undefined;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let settled = false;\n\n const finish = async () => {\n if (timer) clearTimeout(timer);\n timer = undefined;\n rejectPending = undefined;\n await closeServer(server);\n server = undefined;\n };\n\n return {\n open(authorizationUrl) {\n if (server || settled) {\n return Promise.reject(\n new Error(\"This browser authentication session has already been used.\")\n );\n }\n\n return new Promise<{ callbackUrl: string }>((resolve, reject) => {\n rejectPending = reject;\n const app = new Hono();\n app.get(redirect.pathname, (context) => {\n if (settled) {\n return context.text(\"Authentication session is already complete.\", 409);\n }\n settled = true;\n const callbackUrl = context.req.url;\n setImmediate(() => {\n void finish().then(\n () =>\n resolve({\n callbackUrl,\n }),\n reject\n );\n });\n return context.html(`<!doctype html>\n<html lang=\"en\">\n<head><meta charset=\"utf-8\"><title>Authentication complete</title></head>\n<body>\n<p>Authentication complete. Returning to the terminal…</p>\n<script>window.close()</script>\n</body>\n</html>`);\n });\n\n server = serve({\n fetch: app.fetch,\n hostname: redirect.hostname.replace(/^\\[|\\]$/g, \"\"),\n port: Number(redirect.port),\n }) as Server;\n server.once(\"error\", (error) => {\n if (settled) return;\n settled = true;\n void finish().finally(() => reject(error));\n });\n server.once(\"listening\", () => {\n if (settled) return;\n void Promise.resolve()\n .then(() => openUrl(authorizationUrl))\n .catch((error: unknown) => {\n if (settled) return;\n settled = true;\n const reason = error instanceof Error ? error : new Error(String(error));\n void finish().finally(() => reject(reason));\n });\n });\n timer = setTimeout(() => {\n if (settled) return;\n settled = true;\n void finish().finally(() =>\n reject(\n new BrowserAuthenticationCancelledError(\n \"Browser authentication timed out.\"\n )\n )\n );\n }, timeoutMs);\n });\n },\n async close() {\n if (settled) {\n await finish();\n return;\n }\n settled = true;\n const reject = rejectPending;\n await finish();\n reject?.(new BrowserAuthenticationCancelledError());\n },\n };\n },\n };\n}\n"],"mappings":";;;;;AAMA,MAAM,qBAAqB;AAC3B,MAAM,iCAAiB,IAAI,IAAI;CAAC;CAAa;CAAa;CAAO;AAAO,CAAC;AAOzE,SAAS,YAAY,QAA2C;CAC5D,IAAI,CAAC,QAAQ,WAAW,OAAO,QAAQ,QAAQ;CAC/C,OAAO,IAAI,SAAS,SAAS,WAAW;EACpC,OAAO,OAAO,UAAU;GACpB,IAAI,OAAO,OAAO,KAAK;QAClB,QAAQ;EACjB,CAAC;CACL,CAAC;AACL;AAEA,SAAS,oBAAoB,aAA0B;CACnD,MAAM,MAAM,IAAI,IAAI,WAAW;CAC/B,IAAI,IAAI,aAAa,WAAW,CAAC,eAAe,IAAI,IAAI,QAAQ,KAAK,CAAC,IAAI,MACtE,MAAM,IAAI,MACN,8FACJ;CAEJ,OAAO;AACX;AAEA,SAAgB,gCACZ,UAAkD,CAAC,GAC9B;CACrB,MAAM,UAAU,QAAQ,aAAa,QAAgB,KAAK,GAAG;CAC7D,MAAM,YAAY,QAAQ,aAAa;CAEvC,OAAO,EACH,MAAM,EAAE,eAAe;EACnB,MAAM,WAAW,oBAAoB,WAAW;EAChD,IAAI;EACJ,IAAI;EACJ,IAAI;EACJ,IAAI,UAAU;EAEd,MAAM,SAAS,YAAY;GACvB,IAAI,OAAO,aAAa,KAAK;GAC7B,QAAQ,KAAA;GACR,gBAAgB,KAAA;GAChB,MAAM,YAAY,MAAM;GACxB,SAAS,KAAA;EACb;EAEA,OAAO;GACH,KAAK,kBAAkB;IACnB,IAAI,UAAU,SACV,OAAO,QAAQ,uBACX,IAAI,MAAM,4DAA4D,CAC1E;IAGJ,OAAO,IAAI,SAAkC,SAAS,WAAW;KAC7D,gBAAgB;KAChB,MAAM,MAAM,IAAI,KAAK;KACrB,IAAI,IAAI,SAAS,WAAW,YAAY;MACpC,IAAI,SACA,OAAO,QAAQ,KAAK,+CAA+C,GAAG;MAE1E,UAAU;MACV,MAAM,cAAc,QAAQ,IAAI;MAChC,mBAAmB;OACf,OAAY,CAAC,CAAC,WAEN,QAAQ,EACJ,YACJ,CAAC,GACL,MACJ;MACJ,CAAC;MACD,OAAO,QAAQ,KAAK;;;;;;;QAOxC;KACgB,CAAC;KAED,SAAS,MAAM;MACX,OAAO,IAAI;MACX,UAAU,SAAS,SAAS,QAAQ,YAAY,EAAE;MAClD,MAAM,OAAO,SAAS,IAAI;KAC9B,CAAC;KACD,OAAO,KAAK,UAAU,UAAU;MAC5B,IAAI,SAAS;MACb,UAAU;MACV,OAAY,CAAC,CAAC,cAAc,OAAO,KAAK,CAAC;KAC7C,CAAC;KACD,OAAO,KAAK,mBAAmB;MAC3B,IAAI,SAAS;MACb,QAAa,QAAQ,CAAC,CACjB,WAAW,QAAQ,gBAAgB,CAAC,CAAC,CACrC,OAAO,UAAmB;OACvB,IAAI,SAAS;OACb,UAAU;OACV,MAAM,SAAS,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;OACvE,OAAY,CAAC,CAAC,cAAc,OAAO,MAAM,CAAC;MAC9C,CAAC;KACT,CAAC;KACD,QAAQ,iBAAiB;MACrB,IAAI,SAAS;MACb,UAAU;MACV,OAAY,CAAC,CAAC,cACV,OACI,IAAI,oCACA,mCACJ,CACJ,CACJ;KACJ,GAAG,SAAS;IAChB,CAAC;GACL;GACA,MAAM,QAAQ;IACV,IAAI,SAAS;KACT,MAAM,OAAO;KACb;IACJ;IACA,UAAU;IACV,MAAM,SAAS;IACf,MAAM,OAAO;IACb,SAAS,IAAI,oCAAoC,CAAC;GACtD;EACJ;CACJ,EACJ;AACJ"}
@@ -1,8 +1,10 @@
1
+ import { RuntimeAdapterProvider } from "@party-stack/runtime";
1
2
  import "temporal-polyfill/global";
2
- import { type RuntimeAdapterProvider } from "@party-stack/runtime";
3
+ //#region src/createNodeRuntime.d.ts
3
4
  export interface CreateNodeRuntimeOptions {
4
- dataDirectory?: string;
5
+ dataDirectory?: string;
5
6
  }
6
7
  export declare function createNodeRuntimeWithOptions(options: CreateNodeRuntimeOptions): RuntimeAdapterProvider;
7
8
  export declare const createNodeRuntime: RuntimeAdapterProvider;
9
+ //#endregion
8
10
  //# sourceMappingURL=createNodeRuntime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createNodeRuntime.d.ts","sourceRoot":"","sources":["../src/createNodeRuntime.ts"],"names":[],"mappings":"AACA,OAAO,0BAA0B,CAAC;AAMlC,OAAO,EAAiB,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAOlF,MAAM,WAAW,wBAAwB;IACrC,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AAkBD,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,wBAAwB,GAAG,sBAAsB,CAwCtG;AAED,eAAO,MAAM,iBAAiB,wBAAmC,CAAC"}
1
+ {"version":3,"file":"createNodeRuntime.d.ts","names":[],"sources":["../src/createNodeRuntime.ts"],"mappings":";;;iBAciB;EACb;;wBAmBY,6BAA6B,SAAS,2BAA2B;qBA0CpE,mBAAiB"}