@theholocron/holocron-plugin-1password 5.0.0-alpha.31 → 5.0.0-alpha.326

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/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ <!-- alex disable fire -->
2
+
1
3
  <!-- editorconfig-checker-disable-file -->
2
4
 
3
5
  # `@theholocron/holocron-plugin-1password`
@@ -116,7 +118,7 @@ holocron.
116
118
 
117
119
  ```
118
120
 
119
- - `vault` (required) — the 1Password vault name items live in.
121
+ - `vault` (optional) — the 1Password vault name items live in. Only `list()` needs it (`read` and `write` take the vault from the `op://` reference), and Environments are not in a vault, so a project that only reads an Environment can leave it out.
120
122
  - `account` (optional) — 1P account UUID. Passes `--account <UUID>`
121
123
  on every `op` call so the integration targets a specific account
122
124
  even when the developer has multiple signed in (e.g., work +
@@ -124,13 +126,13 @@ holocron.
124
126
 
125
127
  ## What's implemented
126
128
 
127
- | Method | What it does |
128
- | --------------------- | ---------------------------------------------------------------------------------- |
129
- | `read(reference)` | `op read <reference>` — resolves `op://Vault/Item/field`. `--no-newline`. |
130
- | `write(reference, v)` | Probe + `op item edit` if exists, else `op item create --category=API Credential`. |
131
- | `list()` | `op item list --vault=<vault> --format=json` — names of items in the vault. |
132
- | `environments()` | `op environment list --format=json` — names of 1P Environments. |
133
- | `readEnvironment(id)` | `op environment read <id>` — parses `KEY=VALUE` lines into a record. |
129
+ | Method | What it does |
130
+ | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
131
+ | `read(reference)` | `op read <reference>` — resolves `op://Vault/Item/field`. `--no-newline`. |
132
+ | `write(reference, v)` | Probe + `op item edit` if exists, else `op item create --category=API Credential`. |
133
+ | `list()` | `op item list --vault=<vault> --format=json` — names of items in the vault. |
134
+ | `readSecret(name)` | Reads one variable of the Environment named by the `environment` option, through the same `op environment secret list`; refuses without that option. Lets a caller (the `comlink deliver` probe) ask for a secret by its bare name. |
135
+ | `readEnvironment(name or id)` | `op environment secret list <name or id> --reveal --format=dotenv` — parses the variables into a record. `op environment read` takes only an id, so this reads through `secret list`, which takes either. |
134
136
 
135
137
  Plugin-level exports (not capability methods, per the auth-bootstrap
136
138
  convention):
@@ -145,7 +147,7 @@ convention):
145
147
  `ensureProject` / `ensureEnvironment` — 1Password's data model
146
148
  doesn't have projects with sub-configs the way Doppler / Infisical
147
149
  do. The vault + item hierarchy is created via the 1P UI or `op item
148
- create`, not via `holocron setup`. The methods are omitted;
150
+ create`, not via `holocron repo setup`. The methods are omitted;
149
151
  `runSetup` skips them cleanly (see the [`Vault`
150
152
  interface](../cli/src/capabilities/index.ts)).
151
153
 
package/dist/index.d.mts CHANGED
@@ -1,18 +1,19 @@
1
+ import { Credentials, CredentialsInspection, Vault, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess } from "@theholocron/cli";
1
2
  import { spawnSync } from "node:child_process";
2
- import { Vault } from "@theholocron/cli";
3
- //#region src/auth.d.ts
4
- declare class AuthError extends Error {
3
+ /** Thrown when the 1Password `op` CLI is missing or does not run. */
4
+ export declare class AuthError extends Error {
5
+ /** Error name; always `"AuthError"`. */
5
6
  name: string;
6
7
  }
7
- interface VerifyInput {
8
+ /** Inputs for checking that the `op` binary is installed. */
9
+ export interface VerifyInput {
8
10
  /** Override the spawn function in tests. */
9
11
  spawn?: typeof spawnSync;
10
12
  /** Path to the op binary. Defaults to "op". */
11
13
  binary?: string;
12
14
  }
13
- declare function verifyOpInstalled(input?: VerifyInput): void;
14
- //#endregion
15
- //#region src/shell.d.ts
15
+ /** Runs `op --version` and throws `AuthError` when the binary is not found or exits non-zero. */
16
+ export declare function verifyOpInstalled(input?: VerifyInput): void;
16
17
  interface OpResult {
17
18
  ok: boolean;
18
19
  stdout: string;
@@ -29,10 +30,15 @@ interface OpShellOptions {
29
30
  interface RunOptions {
30
31
  /** Skip `--account` injection for commands that operate above the account level (e.g., `account list`). */
31
32
  skipAccount?: boolean;
33
+ /** Stop waiting for `op` after this many milliseconds. `op` can wait on the desktop app (a Touch ID prompt) without end. */
34
+ timeoutMs?: number;
32
35
  }
33
- declare class OpShell {
36
+ /** Thin wrapper around `spawnSync` that runs the `op` CLI and returns a uniform result. */
37
+ export declare class OpShell {
34
38
  private readonly spawnImpl;
39
+ /** The `op` binary this wrapper runs; defaults to `"op"`. */
35
40
  readonly binary: string;
41
+ /** The 1Password account UUID passed as `--account` on each call, when one is set. */
36
42
  readonly account?: string;
37
43
  constructor(opts?: OpShellOptions);
38
44
  /** Run `op <args>`, returning a uniform result. */
@@ -40,58 +46,100 @@ declare class OpShell {
40
46
  /** Run + throw if non-zero. Mirrors REST clients' `request<T>` ergonomic. */
41
47
  runOrThrow(args: string[], context: string, opts?: RunOptions): string;
42
48
  }
43
- //#endregion
44
- //#region src/capabilities/vault.d.ts
49
+ /** `credentials` capability for 1Password, implemented by shelling out to `op environment secret list`. */
50
+ export declare class OpCredentials implements Credentials {
51
+ private readonly shell;
52
+ /** Capability key; always `"credentials"`. */
53
+ readonly key: "credentials";
54
+ /** Provider name; always `"1password"`. */
55
+ readonly providerName = "1password";
56
+ constructor(shell: OpShell);
57
+ /**
58
+ * Every variable of the Environment, with values. Tries {@link spellings} of the name until `op` finds one;
59
+ * any other failure (not signed in, a prompt that timed out) is thrown at once.
60
+ */
61
+ read(environment: string): Promise<Record<string, string>>;
62
+ /**
63
+ * The Environment as `op` spells it and the names of its variables, asked without `--reveal` so no value is
64
+ * printed or kept: `op` shows a placeholder for each value, which is not read. Tries the same spellings as `read`.
65
+ */
66
+ inspect(environment: string): Promise<CredentialsInspection>;
67
+ private list;
68
+ }
45
69
  interface OpVaultOptions {
46
- /** 1P vault name items live in. Required — list/write default here. */
47
- vault: string;
70
+ /**
71
+ * 1P vault name items live in. `list()` needs it; `read` and `write` take it from the `op://` reference, and
72
+ * Environments are not in a vault, so a project that only reads an Environment can leave it out.
73
+ */
74
+ vault?: string;
75
+ /**
76
+ * The 1Password Environment `readSecret` looks a variable up in. An app keeps its secrets in one Environment, so
77
+ * its config names it here and a caller can ask for a variable by its bare name.
78
+ */
79
+ environment?: string;
48
80
  }
49
- declare class OpVault implements Vault {
81
+ /** `vault` capability for 1Password, implemented by shelling out to the `op` CLI against one vault. */
82
+ export declare class OpVault implements Vault {
50
83
  private readonly shell;
84
+ /** Capability key; always `"vault"`. */
51
85
  readonly key: "vault";
86
+ /** Provider name; always `"1password"`. */
52
87
  readonly providerName = "1password";
53
88
  private readonly vaultName;
54
- constructor(shell: OpShell, opts: OpVaultOptions);
89
+ private readonly environmentName;
90
+ constructor(shell: OpShell, opts?: OpVaultOptions);
55
91
  read(reference: string): Promise<string>;
56
92
  write(reference: string, value: string): Promise<void>;
57
93
  list(): Promise<string[]>;
58
- environments(): Promise<string[]>;
59
- readEnvironment(environmentId: string): Promise<Record<string, string>>;
94
+ /**
95
+ * Every variable of a 1Password Environment, by its name or id. `op environment read` takes only an id, while
96
+ * `op environment secret list` takes either, so this reads through the latter with the values revealed. There is
97
+ * no `op` command that lists Environments, so this vault has no `environments()`.
98
+ */
99
+ readEnvironment(environment: string): Promise<Record<string, string>>;
100
+ /** One variable of the Environment this vault was set up with, by its bare name. */
101
+ readSecret(name: string): Promise<string>;
60
102
  }
61
- //#endregion
62
- //#region src/verify-token.d.ts
63
- interface VerifyTokenSuccess {
64
- ok: true;
65
- subject: string;
66
- }
67
- interface VerifyTokenFailure {
68
- ok: false;
69
- message: string;
70
- }
71
- type VerifyTokenResult = VerifyTokenSuccess | VerifyTokenFailure;
72
103
  interface VerifyTokenOptions {
73
104
  spawn?: typeof spawnSync;
74
105
  binary?: string;
75
106
  }
76
- declare function verifyToken(_token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult>;
77
- //#endregion
78
- //#region src/index.d.ts
79
- interface OpPluginOptions extends VerifyInput {
80
- /** 1P vault name items live in. Required. */
81
- vault: string;
82
- /** Optional 1P account UUID; passed as `--account` on every op call. */
107
+ /** Checks that `op` is installed and signed in by running `op whoami`; the token argument is unused. */
108
+ export declare function verifyToken(_token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult$1>;
109
+ /** Options for the 1Password plugin: the vault and account to use plus the `op` binary overrides. */
110
+ export interface OpPluginOptions extends VerifyInput {
111
+ /**
112
+ * 1P vault name items live in. Only listing a vault's items needs it; Environments are not in a vault, so a
113
+ * project that only reads an Environment can leave it out.
114
+ */
115
+ vault?: string;
116
+ /** The Environment `readSecret` reads a variable from by its bare name; the one an app keeps its secrets in. */
117
+ environment?: string;
118
+ /** Optional 1P account UUID; passed as `--account` on every op call. Useful when several accounts are signed in. */
83
119
  account?: string;
84
120
  }
85
- interface PluginContext {
121
+ /** Shared state for one 1Password plugin instance: its options and the `op` shell wrapper. */
122
+ export interface PluginContext {
123
+ /** The options the plugin was created with. */
86
124
  options: OpPluginOptions;
125
+ /** The wrapper that runs `op` commands. */
87
126
  shell: OpShell;
88
127
  }
89
- declare function createContext(options: OpPluginOptions): PluginContext;
90
- declare function vault(ctx: PluginContext): Vault;
91
- declare function createPlugin(options: OpPluginOptions): {
128
+ /** Builds the plugin context; throws when the `op` binary is not installed. */
129
+ export declare function createContext(options: OpPluginOptions): PluginContext;
130
+ /** Builds the `vault` capability for the configured vault. */
131
+ export declare function vault(ctx: PluginContext): Vault;
132
+ /** Builds the `credentials` capability: the variables of a 1Password Environment, read for the token resolvers. */
133
+ export declare function credentials(ctx: PluginContext): Credentials;
134
+ /** Creates the 1Password plugin: its `connection` probe and the `vault` and `credentials` capabilities. */
135
+ export declare function createPlugin(options?: OpPluginOptions): {
92
136
  name: string;
137
+ probes: {
138
+ connection: import("@theholocron/cli").Probe;
139
+ };
93
140
  capabilities: {
94
141
  vault: () => Vault;
142
+ credentials: () => Credentials;
95
143
  };
96
144
  };
97
145
  /**
@@ -99,6 +147,5 @@ declare function createPlugin(options: OpPluginOptions): {
99
147
  * store a token in the holocron keyring; the `op` CLI manages its own
100
148
  * auth. Directs the operator to the two paths that actually work.
101
149
  */
102
- declare const AUTH_HINT: string;
103
- //#endregion
104
- export { AUTH_HINT, AuthError, OpPluginOptions, OpShell, OpVault, PluginContext, VerifyInput, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createContext, createPlugin, vault, verifyOpInstalled, verifyToken };
150
+ export declare const AUTH_HINT: string;
151
+ export type { VerifyTokenFailure, VerifyTokenResult, VerifyTokenSuccess };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
+ import { ProviderApiError, connectionProbe } from "@theholocron/cli";
1
2
  import { spawnSync } from "node:child_process";
2
- import { ProviderApiError } from "@theholocron/cli";
3
- //#region src/auth.ts
3
+ // src/auth.ts
4
4
  /**
5
5
  * 1Password plugin "auth" is just verifying the `op` binary is on
6
6
  * PATH — the CLI handles its own auth (keychain biometric unlock for
@@ -11,9 +11,12 @@ import { ProviderApiError } from "@theholocron/cli";
11
11
  * a missing binary fails fast and clearly, not as a mystery error when
12
12
  * the first `vault.read()` happens later.
13
13
  */
14
+ /** Thrown when the 1Password `op` CLI is missing or does not run. */
14
15
  var AuthError = class extends Error {
16
+ /** Error name; always `"AuthError"`. */
15
17
  name = "AuthError";
16
18
  };
19
+ /** Runs `op --version` and throws `AuthError` when the binary is not found or exits non-zero. */
17
20
  function verifyOpInstalled(input = {}) {
18
21
  const spawnImpl = input.spawn ?? spawnSync;
19
22
  const binary = input.binary ?? "op";
@@ -28,17 +31,142 @@ function verifyOpInstalled(input = {}) {
28
31
  if (result.error) throw new AuthError(`1Password CLI (\`${binary}\`) not found on PATH. Install via \`brew install 1password-cli\` or see https://developer.1password.com/docs/cli/get-started.`);
29
32
  if (result.status !== 0) throw new AuthError(`\`${binary} --version\` failed: ${(result.stderr ?? "").trim() || `exit ${result.status ?? "?"}`}`);
30
33
  }
31
- //#endregion
32
- //#region src/capabilities/vault.ts
34
+ // src/parse-dotenv.ts
35
+ /**
36
+ * Parse dotenv text (`op environment secret list --format=dotenv`) into a record.
37
+ *
38
+ * Blank lines and `# comment` lines are skipped, as is a line with no `=`. A leading `export ` is dropped. A value
39
+ * in double quotes has `\n`, `\r`, `\t`, `\"` and `\\` unescaped and may run over several lines; a value in single
40
+ * quotes is taken as written; anything else is the rest of the line, trimmed. Inline `#` comments are not stripped,
41
+ * because a token may contain one.
42
+ */
43
+ function parseDotenv(text) {
44
+ const out = {};
45
+ const lines = text.split(/\r?\n/);
46
+ for (let i = 0; i < lines.length; i++) {
47
+ const line = lines[i].trim();
48
+ if (!line || line.startsWith("#")) continue;
49
+ const eq = line.indexOf("=");
50
+ if (eq < 0) continue;
51
+ const key = line.slice(0, eq).trim().replace(/^export\s+/, "");
52
+ if (!key) continue;
53
+ const value = line.slice(eq + 1).trim();
54
+ if (value.startsWith("\"")) {
55
+ let body = value.slice(1);
56
+ while (!hasClosingQuote(body) && i + 1 < lines.length) body += `\n${lines[++i]}`;
57
+ out[key] = unescapeDouble(body.slice(0, closingQuoteAt(body)));
58
+ continue;
59
+ }
60
+ if (value.startsWith("'") && value.endsWith("'") && value.length >= 2) {
61
+ out[key] = value.slice(1, -1);
62
+ continue;
63
+ }
64
+ out[key] = value;
65
+ }
66
+ return out;
67
+ }
68
+ /** The index of the first `"` not preceded by a backslash, or the whole length when there is none. */
69
+ function closingQuoteAt(body) {
70
+ for (let i = 0; i < body.length; i++) if (body[i] === "\\") i++;
71
+ else if (body[i] === "\"") return i;
72
+ return body.length;
73
+ }
74
+ function hasClosingQuote(body) {
75
+ return closingQuoteAt(body) < body.length;
76
+ }
77
+ function unescapeDouble(inner) {
78
+ return inner.replace(/\\([nrt"\\])/g, (_, c) => ({
79
+ n: "\n",
80
+ r: "\r",
81
+ t: " ",
82
+ "\"": "\"",
83
+ "\\": "\\"
84
+ })[c]);
85
+ }
86
+ // src/capabilities/credentials.ts
87
+ /** How long to wait for `op` (a Touch ID prompt included) before giving up on the environment. */
88
+ const READ_TIMEOUT_MS = 6e4;
89
+ /** `op` words a missing Environment as "environment couldn't be found". */
90
+ const NOT_FOUND = /couldn.?t be found|could not be found|not found/i;
91
+ /**
92
+ * The spellings of an Environment name to try, in order: as written, lowercase, Title case, UPPERCASE. `op` finds an
93
+ * Environment by its exact name and has no command that lists them, so the real spelling cannot be looked up.
94
+ */
95
+ function spellings(name) {
96
+ const title = name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
97
+ return [.../* @__PURE__ */ new Set([
98
+ name,
99
+ name.toLowerCase(),
100
+ title,
101
+ name.toUpperCase()
102
+ ])];
103
+ }
104
+ /** `credentials` capability for 1Password, implemented by shelling out to `op environment secret list`. */
105
+ var OpCredentials = class {
106
+ shell;
107
+ /** Capability key; always `"credentials"`. */
108
+ key = "credentials";
109
+ /** Provider name; always `"1password"`. */
110
+ providerName = "1password";
111
+ constructor(shell) {
112
+ this.shell = shell;
113
+ }
114
+ /**
115
+ * Every variable of the Environment, with values. Tries {@link spellings} of the name until `op` finds one;
116
+ * any other failure (not signed in, a prompt that timed out) is thrown at once.
117
+ */
118
+ async read(environment) {
119
+ return parseDotenv((await this.list(environment, ["--reveal"])).stdout);
120
+ }
121
+ /**
122
+ * The Environment as `op` spells it and the names of its variables, asked without `--reveal` so no value is
123
+ * printed or kept: `op` shows a placeholder for each value, which is not read. Tries the same spellings as `read`.
124
+ */
125
+ async inspect(environment) {
126
+ const { name, stdout } = await this.list(environment, []);
127
+ return {
128
+ environment: name,
129
+ names: variableNames(stdout)
130
+ };
131
+ }
132
+ async list(environment, flags) {
133
+ const tried = spellings(environment);
134
+ for (const name of tried) {
135
+ const result = this.shell.run([
136
+ "environment",
137
+ "secret",
138
+ "list",
139
+ name,
140
+ ...flags,
141
+ "--format=dotenv"
142
+ ], { timeoutMs: READ_TIMEOUT_MS });
143
+ if (result.ok) return {
144
+ name,
145
+ stdout: result.stdout
146
+ };
147
+ if (!NOT_FOUND.test(result.stderr)) throw new ProviderApiError(`1Password environment secret list ${name} failed: ${result.stderr || "no stderr"}`, 0, result.stderr);
148
+ }
149
+ throw new ProviderApiError(`1Password has no Environment named "${environment}" (tried ${tried.map((n) => `"${n}"`).join(", ")}). Check the name, or use the Environment's id; names are matched exactly and \`op\` cannot list them.`, 404, void 0);
150
+ }
151
+ };
152
+ /** The variable names in dotenv text, taken from the start of each line so a value is never looked at. */
153
+ function variableNames(text) {
154
+ return text.split(/\r?\n/).map((line) => /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_.-]*)\s*=/.exec(line)?.[1]).filter((name) => name !== void 0);
155
+ }
156
+ // src/capabilities/vault.ts
157
+ /** `vault` capability for 1Password, implemented by shelling out to the `op` CLI against one vault. */
33
158
  var OpVault = class {
34
159
  shell;
160
+ /** Capability key; always `"vault"`. */
35
161
  key = "vault";
162
+ /** Provider name; always `"1password"`. */
36
163
  providerName = "1password";
37
164
  vaultName;
38
- constructor(shell, opts) {
165
+ environmentName;
166
+ constructor(shell, opts = {}) {
39
167
  this.shell = shell;
40
- if (!opts.vault) throw new Error("OpVault requires `vault` (1P vault name) in options");
41
- this.vaultName = opts.vault;
168
+ this.vaultName = opts.vault || void 0;
169
+ this.environmentName = opts.environment || void 0;
42
170
  }
43
171
  async read(reference) {
44
172
  return this.shell.runOrThrow([
@@ -75,6 +203,7 @@ var OpVault = class {
75
203
  ], `item create ${parsed.item}`);
76
204
  }
77
205
  async list() {
206
+ if (!this.vaultName) throw new ProviderApiError("1Password `list` needs a `vault` in the plugin options: it lists the items in one vault", 400, void 0);
78
207
  const stdout = this.shell.runOrThrow([
79
208
  "item",
80
209
  "list",
@@ -84,21 +213,27 @@ var OpVault = class {
84
213
  if (!stdout) return [];
85
214
  return JSON.parse(stdout).map((i) => i.title);
86
215
  }
87
- async environments() {
88
- const stdout = this.shell.runOrThrow([
216
+ /**
217
+ * Every variable of a 1Password Environment, by its name or id. `op environment read` takes only an id, while
218
+ * `op environment secret list` takes either, so this reads through the latter with the values revealed. There is
219
+ * no `op` command that lists Environments, so this vault has no `environments()`.
220
+ */
221
+ async readEnvironment(environment) {
222
+ return parseDotenv(this.shell.runOrThrow([
89
223
  "environment",
224
+ "secret",
90
225
  "list",
91
- "--format=json"
92
- ], "environment list");
93
- if (!stdout) return [];
94
- return JSON.parse(stdout).map((e) => e.name);
226
+ environment,
227
+ "--reveal",
228
+ "--format=dotenv"
229
+ ], `environment secret list ${environment}`));
95
230
  }
96
- async readEnvironment(environmentId) {
97
- return parseEnvironmentDump(this.shell.runOrThrow([
98
- "environment",
99
- "read",
100
- environmentId
101
- ], `environment read ${environmentId}`));
231
+ /** One variable of the Environment this vault was set up with, by its bare name. */
232
+ async readSecret(name) {
233
+ if (!this.environmentName) throw new ProviderApiError("1Password `readSecret` needs an `environment` in the plugin options: it reads one variable of that Environment", 400, void 0);
234
+ const value = (await this.readEnvironment(this.environmentName))[name];
235
+ if (value === void 0) throw new ProviderApiError(`1Password Environment ${this.environmentName} has no variable ${name}`, 404, void 0);
236
+ return value;
102
237
  }
103
238
  };
104
239
  /**
@@ -117,27 +252,7 @@ function parseReference(reference) {
117
252
  field: fieldParts.join("/")
118
253
  };
119
254
  }
120
- /**
121
- * Parse `op environment read`'s stdout (KEY=VALUE per line) into a
122
- * record. Skips blank lines + `# comment` lines. Per-line format is
123
- * intentionally minimal — no quoting, no escaping; if a value contains
124
- * a literal newline, that's a problem for the underlying environment,
125
- * not this parser.
126
- */
127
- function parseEnvironmentDump(stdout) {
128
- const out = {};
129
- for (const line of stdout.split("\n")) {
130
- const trimmed = line.trim();
131
- if (!trimmed || trimmed.startsWith("#")) continue;
132
- const eq = trimmed.indexOf("=");
133
- if (eq < 0) continue;
134
- const key = trimmed.slice(0, eq);
135
- out[key] = trimmed.slice(eq + 1);
136
- }
137
- return out;
138
- }
139
- //#endregion
140
- //#region src/shell.ts
255
+ // src/shell.ts
141
256
  /**
142
257
  * Thin wrapper around `spawnSync` for `op` CLI shell-outs.
143
258
  *
@@ -156,9 +271,12 @@ function parseEnvironmentDump(stdout) {
156
271
  * token). Default spawnSync stdio of `['pipe','pipe','pipe']` would
157
272
  * suppress biometric unlock and return "not signed in" instead.
158
273
  */
274
+ /** Thin wrapper around `spawnSync` that runs the `op` CLI and returns a uniform result. */
159
275
  var OpShell = class {
160
276
  spawnImpl;
277
+ /** The `op` binary this wrapper runs; defaults to `"op"`. */
161
278
  binary;
279
+ /** The 1Password account UUID passed as `--account` on each call, when one is set. */
162
280
  account;
163
281
  constructor(opts = {}) {
164
282
  this.spawnImpl = opts.spawn ?? spawnSync;
@@ -178,7 +296,8 @@ var OpShell = class {
178
296
  "inherit",
179
297
  "pipe",
180
298
  "pipe"
181
- ]
299
+ ],
300
+ ...opts.timeoutMs !== void 0 ? { timeout: opts.timeoutMs } : {}
182
301
  });
183
302
  if (out.error) return {
184
303
  ok: false,
@@ -198,8 +317,7 @@ var OpShell = class {
198
317
  return result.stdout;
199
318
  }
200
319
  };
201
- //#endregion
202
- //#region src/verify-token.ts
320
+ // src/verify-token.ts
203
321
  /**
204
322
  * `verifyToken` — plugin-level export used by `holocron auth check`.
205
323
  *
@@ -213,6 +331,7 @@ var OpShell = class {
213
331
  * will be stored in the keyring but never read by this plugin — the
214
332
  * `AUTH_HINT` below explains that up front.
215
333
  */
334
+ /** Checks that `op` is installed and signed in by running `op whoami`; the token argument is unused. */
216
335
  async function verifyToken(_token, opts = {}) {
217
336
  const spawnImpl = opts.spawn ?? spawnSync;
218
337
  const binary = opts.binary ?? "op";
@@ -245,10 +364,9 @@ async function verifyToken(_token, opts = {}) {
245
364
  };
246
365
  }
247
366
  }
248
- //#endregion
249
- //#region src/index.ts
367
+ // src/index.ts
368
+ /** Builds the plugin context; throws when the `op` binary is not installed. */
250
369
  function createContext(options) {
251
- if (!options.vault) throw new Error("@theholocron/holocron-plugin-1password requires `vault` in options");
252
370
  const verifyOpts = {};
253
371
  if (options.spawn !== void 0) verifyOpts.spawn = options.spawn;
254
372
  if (options.binary !== void 0) verifyOpts.binary = options.binary;
@@ -262,14 +380,31 @@ function createContext(options) {
262
380
  shell: new OpShell(shellOpts)
263
381
  };
264
382
  }
383
+ /** Builds the `vault` capability for the configured vault. */
265
384
  function vault(ctx) {
266
- return new OpVault(ctx.shell, { vault: ctx.options.vault });
385
+ return new OpVault(ctx.shell, {
386
+ ...ctx.options.vault !== void 0 ? { vault: ctx.options.vault } : {},
387
+ ...ctx.options.environment !== void 0 ? { environment: ctx.options.environment } : {}
388
+ });
267
389
  }
268
- function createPlugin(options) {
390
+ /** Builds the `credentials` capability: the variables of a 1Password Environment, read for the token resolvers. */
391
+ function credentials(ctx) {
392
+ return new OpCredentials(ctx.shell);
393
+ }
394
+ /** Creates the 1Password plugin: its `connection` probe and the `vault` and `credentials` capabilities. */
395
+ function createPlugin(options = {}) {
269
396
  const ctx = createContext(options);
270
397
  return {
271
398
  name: "@theholocron/holocron-plugin-1password",
272
- capabilities: { vault: () => vault(ctx) }
399
+ probes: { connection: connectionProbe({
400
+ provider: "1Password",
401
+ token: () => "",
402
+ verify: (token) => verifyToken(token, { spawn: options.spawn })
403
+ }) },
404
+ capabilities: {
405
+ vault: () => vault(ctx),
406
+ credentials: () => credentials(ctx)
407
+ }
273
408
  };
274
409
  }
275
410
  /**
@@ -278,5 +413,4 @@ function createPlugin(options) {
278
413
  * auth. Directs the operator to the two paths that actually work.
279
414
  */
280
415
  const AUTH_HINT = "1Password uses the `op` CLI for auth — no bearer token to store. On laptop: `op signin` (or the desktop app's biometric flow). In CI: set `OP_SERVICE_ACCOUNT_TOKEN` in the workflow env.";
281
- //#endregion
282
- export { AUTH_HINT, AuthError, OpShell, OpVault, createContext, createPlugin, vault, verifyOpInstalled, verifyToken };
416
+ export { AUTH_HINT, AuthError, OpCredentials, OpShell, OpVault, createContext, createPlugin, credentials, vault, verifyOpInstalled, verifyToken };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/holocron-plugin-1password",
3
- "version": "5.0.0-alpha.31",
3
+ "version": "5.0.0-alpha.326",
4
4
  "description": "Holocron plugin for 1Password. Implements the vault capability via shell-out to the `op` CLI (https://developer.1password.com/docs/cli).",
5
5
  "keywords": [
6
6
  "1password",
@@ -8,12 +8,12 @@
8
8
  "plugin",
9
9
  "vault"
10
10
  ],
11
- "homepage": "https://github.com/theholocron/holocron/tree/main/packages/holocron-plugin-1password#readme",
11
+ "homepage": "https://docs.theholocron.dev/holocron/plugins/1password/",
12
12
  "bugs": "https://github.com/theholocron/holocron/issues",
13
13
  "repository": {
14
14
  "type": "git",
15
15
  "url": "git+https://github.com/theholocron/holocron.git",
16
- "directory": "packages/holocron-plugin-1password"
16
+ "directory": "plugins/holocron-plugin-1password"
17
17
  },
18
18
  "license": "MIT",
19
19
  "author": "Newton Koumantzelis",
@@ -30,24 +30,24 @@
30
30
  "dist"
31
31
  ],
32
32
  "devDependencies": {
33
- "@theholocron/eslint-config": "^8.0.0",
34
- "@theholocron/tsconfig": "^8.0.0",
35
- "@theholocron/tsdown-config": "^8.0.0",
36
- "@theholocron/vitest-config": "^8.0.0",
37
33
  "@types/node": "^26",
38
- "@vitest/coverage-v8": "^4.1.11",
34
+ "@vitest/coverage-v8": "^5.0.5",
39
35
  "@vitest/eslint-plugin": "^1.6.27",
40
36
  "eslint": "^10.8.1",
41
37
  "eslint-plugin-n": "^18.3.0",
42
38
  "globals": "^17.11.0",
43
- "tsdown": "^0.22.14",
44
- "tsx": "4.23.12",
39
+ "tsdown": "^0.23.3",
40
+ "tsx": "4.23.15",
45
41
  "typescript": "^5.9.3",
46
- "vitest": "^4.1.11",
47
- "@theholocron/cli": "5.0.0-alpha.31"
42
+ "vitest": "^5.0.5",
43
+ "@theholocron/tsconfig": "^8.9.0-alpha.8",
44
+ "@theholocron/cli": "5.0.0-alpha.326",
45
+ "@theholocron/vitest-config": "^8.9.0-alpha.8",
46
+ "@theholocron/tsdown-config": "^8.9.0-alpha.8",
47
+ "@theholocron/eslint-config": "^8.9.0-alpha.8"
48
48
  },
49
49
  "peerDependencies": {
50
- "@theholocron/cli": "5.0.0-alpha.31"
50
+ "@theholocron/cli": "5.0.0-alpha.326"
51
51
  },
52
52
  "engines": {
53
53
  "node": ">=22"
@@ -56,11 +56,11 @@
56
56
  "access": "public"
57
57
  },
58
58
  "scripts": {
59
- "delivery.build": "tsdown",
60
- "sourceQuality.staticAnalysis": "holocron run sourceQuality.staticAnalysis --",
59
+ "build": "tsdown",
60
+ "lint:code": "eslint .",
61
+ "test:unit": "vitest run --coverage",
61
62
  "test:watch": "vitest",
62
- "validate": "tsx scripts/validate.mjs",
63
- "verification.typeSafety": "holocron run verification.typeSafety --",
64
- "verification.unitTests": "holocron run verification.unitTests --"
63
+ "typecheck": "tsc --noEmit",
64
+ "validate:plugin": "tsx scripts/validate.mjs"
65
65
  }
66
66
  }