@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.
- package/lib/NodeFileSystemBlobBytesStore.d.ts +10 -8
- package/lib/NodeFileSystemBlobBytesStore.d.ts.map +1 -1
- package/lib/NodeFileSystemBlobBytesStore.js +42 -41
- package/lib/NodeFileSystemBlobBytesStore.js.map +1 -1
- package/lib/NodeSecretStore.d.ts +9 -7
- package/lib/NodeSecretStore.d.ts.map +1 -1
- package/lib/NodeSecretStore.js +38 -40
- package/lib/NodeSecretStore.js.map +1 -1
- package/lib/createNodeBrowserAuthentication.d.ts +5 -3
- package/lib/createNodeBrowserAuthentication.d.ts.map +1 -1
- package/lib/createNodeBrowserAuthentication.js +91 -102
- package/lib/createNodeBrowserAuthentication.js.map +1 -1
- package/lib/createNodeRuntime.d.ts +4 -2
- package/lib/createNodeRuntime.d.ts.map +1 -1
- package/lib/createNodeRuntime.js +41 -55
- package/lib/createNodeRuntime.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +1 -2
- package/package.json +12 -18
- package/lib/NodeFileSystemBlobBytesStore.test.d.ts +0 -2
- package/lib/NodeFileSystemBlobBytesStore.test.d.ts.map +0 -1
- package/lib/NodeFileSystemBlobBytesStore.test.js +0 -38
- package/lib/NodeFileSystemBlobBytesStore.test.js.map +0 -1
- package/lib/NodeSecretStore.test.d.ts +0 -2
- package/lib/NodeSecretStore.test.d.ts.map +0 -1
- package/lib/NodeSecretStore.test.js +0 -69
- package/lib/NodeSecretStore.test.js.map +0 -1
- package/lib/createNodeBrowserAuthentication.test.d.ts +0 -2
- package/lib/createNodeBrowserAuthentication.test.d.ts.map +0 -1
- package/lib/createNodeBrowserAuthentication.test.js +0 -74
- package/lib/createNodeBrowserAuthentication.test.js.map +0 -1
- package/lib/createNodeRuntime.test.d.ts +0 -2
- package/lib/createNodeRuntime.test.d.ts.map +0 -1
- package/lib/createNodeRuntime.test.js +0 -172
- package/lib/createNodeRuntime.test.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { BlobBytesStore } from "@party-stack/runtime";
|
|
2
|
+
//#region src/NodeFileSystemBlobBytesStore.d.ts
|
|
2
3
|
export interface NodeFileSystemBlobBytesStoreOptions {
|
|
3
|
-
|
|
4
|
+
directory: string;
|
|
4
5
|
}
|
|
5
6
|
export declare class NodeFileSystemBlobBytesStore implements BlobBytesStore {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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","
|
|
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
|
-
|
|
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","
|
|
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"}
|
package/lib/NodeSecretStore.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SecretStore } from "@party-stack/runtime";
|
|
2
|
+
//#region src/NodeSecretStore.d.ts
|
|
2
3
|
export interface NodeSecretStoreOptions {
|
|
3
|
-
|
|
4
|
+
service: string;
|
|
4
5
|
}
|
|
5
6
|
export declare class NodeSecretStore implements SecretStore {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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","
|
|
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"}
|
package/lib/NodeSecretStore.js
CHANGED
|
@@ -1,48 +1,46 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { getAllBackends } from "cross-keychain";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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","
|
|
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 {
|
|
1
|
+
import { BrowserAuthentication } from "@party-stack/runtime";
|
|
2
|
+
//#region src/createNodeBrowserAuthentication.d.ts
|
|
2
3
|
export interface CreateNodeBrowserAuthenticationOptions {
|
|
3
|
-
|
|
4
|
-
|
|
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","
|
|
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
|
-
|
|
6
|
-
const
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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()
|
|
61
|
+
<script>window.close()<\/script>
|
|
69
62
|
</body>
|
|
70
63
|
</html>`);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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","
|
|
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
|
-
|
|
3
|
+
//#region src/createNodeRuntime.d.ts
|
|
3
4
|
export interface CreateNodeRuntimeOptions {
|
|
4
|
-
|
|
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","
|
|
1
|
+
{"version":3,"file":"createNodeRuntime.d.ts","names":[],"sources":["../src/createNodeRuntime.ts"],"mappings":";;;iBAciB;EACb;;wBAmBY,6BAA6B,SAAS,2BAA2B;qBA0CpE,mBAAiB"}
|