diff --git a/client/src/client_builder.ts b/client/src/client_builder.ts index 5f2a423..fa9360a 100644 --- a/client/src/client_builder.ts +++ b/client/src/client_builder.ts @@ -19,7 +19,9 @@ export const createClientWithCore = async ( ): Promise => { const authConfig = clientAuthConfig(config); if (authConfig.accountName) { - core.setInner(new SharedLibCore(authConfig.accountName)); + core.setInner( + new SharedLibCore(authConfig.accountName, config.sharedLibraryPath), + ); } const clientId = await core.initClient(authConfig); const inner = new InnerClient(parseInt(clientId, 10), core, authConfig); diff --git a/client/src/configuration.ts b/client/src/configuration.ts index 6e08f52..03f1605 100644 --- a/client/src/configuration.ts +++ b/client/src/configuration.ts @@ -11,6 +11,7 @@ export interface ClientConfiguration { auth: Auth; integrationName: string; integrationVersion: string; + sharedLibraryPath?: string; } // Sets the authentication method. Use a token as a `string` to authenticate with a service account token. diff --git a/client/src/shared_lib_core.ts b/client/src/shared_lib_core.ts index 780d191..0de6b34 100644 --- a/client/src/shared_lib_core.ts +++ b/client/src/shared_lib_core.ts @@ -8,7 +8,7 @@ import { throwError } from "./errors"; /** * Find the 1Password shared lib path by asking an the wasm core synchronously. */ -const find1PasswordLibPath = (): string => { +const find1PasswordLibPath = (customLocation?: string): string => { const platform: NodeJS.Platform = os.platform(); const appRoot: string = path.dirname(process.execPath); let searchPaths: string[] = []; @@ -47,11 +47,14 @@ const find1PasswordLibPath = (): string => { ), ]; break; - default: throw new Error(`Unsupported platform: ${platform}`); } + if (typeof customLocation === "string" && customLocation.length > 0) { + searchPaths.unshift(customLocation); + } + // Iterate through the possible paths and return the first one that exists. for (const addonPath of searchPaths) { if (fs.existsSync(addonPath)) { @@ -85,9 +88,9 @@ export class SharedLibCore implements Core { private lib: DesktopIPCClient | null = null; private acccountName: string; - public constructor(accountName: string) { + public constructor(accountName: string, libraryPath?: string) { try { - const libPath = find1PasswordLibPath(); + const libPath = find1PasswordLibPath(libraryPath); const moduleStub = { exports: {} }; process.dlopen(moduleStub, libPath);