History

Fix beta distribution release flow

Rhys Sullivan committed 7 months ago

Commit ab58a3e1 parent 17ab9314 files · +209 −54Browse files

Showing the changes to plugins (1 of 4 files). Show all

Unified · Split

plugins/keychain-secret-store/sdk/index.ts+28−11
@@ -1,7 +1,4 @@
11 import { randomUUID } from "node:crypto";
2−import {
3− Entry,
4−} from "@napi-rs/keyring";
52
63 import * as Effect from "effect/Effect";
74
@@ -51,12 +48,13 @@ const keychainDisplayName = () => · 43 unmodified lines
5148 ? "Windows Credential Manager"
5249 : "Desktop Keyring";
5350
54−const createKeyringEntry = (input: {
55− providerHandle: string;
56− keychainServiceName: string;
57−}) =>
58− Effect.try({
59− try: () => {
51+let keyringEntryConstructorPromise: Promise<
52+ (typeof import("@napi-rs/keyring"))["Entry"]
53+> | null = null;
54+
55+const loadKeyringEntryConstructor = () =>
56+ Effect.tryPromise({
57+ try: async () => {
6058 if (!isSupportedPlatform()) {
6159 throw runtimeEffectError(
6260 "plugin-keychain-secret-store",
@@ -64,11 +62,30 @@ const createKeyringEntry = (input: { · 1 unmodified line
6462 );
6563 }
6664
67− return new Entry(input.keychainServiceName, input.providerHandle);
65+ keyringEntryConstructorPromise ??= import("@napi-rs/keyring").then(
66+ ({ Entry }) => Entry,
67+ );
68+
69+ return await keyringEntryConstructorPromise;
6870 },
69− catch: toError,
71+ catch: (cause) =>
72+ runtimeEffectError(
73+ "plugin-keychain-secret-store",
74+ `system-keyring: failed loading native keyring support: ${toError(cause).message}`,
75+ ),
7076 });
7177
78+const createKeyringEntry = (input: {
79+ providerHandle: string;
80+ keychainServiceName: string;
81+}) =>
82+ Effect.flatMap(loadKeyringEntryConstructor(), (Entry) =>
83+ Effect.try({
84+ try: () => new Entry(input.keychainServiceName, input.providerHandle),
85+ catch: toError,
86+ })
87+ );
88+
7289 const readKeychainSecretValue = (input: {
7390 providerHandle: string;
7491 keychainServiceName: string;