@theholocron/holocron-plugin-1password 5.0.0-alpha.37 → 5.0.0-alpha.371

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. `list()` needs it, or an `environment` (see below) (`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; with only an `environment` set, the variable names of that Environment (`repo setup` calls it). Neither is an error. |
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 (a multi-line PEM key, which `op` prints unquoted, is read whole). `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,104 @@ 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>;
93
+ /**
94
+ * The names this vault holds: the item titles of its `vault`, or, when only an `environment` is set (an Environment
95
+ * is not in a vault), that Environment's variable names. Values are read in memory and never returned.
96
+ */
57
97
  list(): Promise<string[]>;
58
- environments(): Promise<string[]>;
59
- readEnvironment(environmentId: string): Promise<Record<string, string>>;
98
+ /**
99
+ * Every variable of a 1Password Environment, by its name or id. `op environment read` takes only an id, while
100
+ * `op environment secret list` takes either, so this reads through the latter with the values revealed. There is
101
+ * no `op` command that lists Environments, so this vault has no `environments()`.
102
+ */
103
+ readEnvironment(environment: string): Promise<Record<string, string>>;
104
+ /** One variable of the Environment this vault was set up with, by its bare name. */
105
+ readSecret(name: string): Promise<string>;
60
106
  }
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
107
  interface VerifyTokenOptions {
73
108
  spawn?: typeof spawnSync;
74
109
  binary?: string;
75
110
  }
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. */
111
+ /** Checks that `op` is installed and signed in by running `op whoami`; the token argument is unused. */
112
+ export declare function verifyToken(_token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult$1>;
113
+ /** Options for the 1Password plugin: the vault and account to use plus the `op` binary overrides. */
114
+ export interface OpPluginOptions extends VerifyInput {
115
+ /**
116
+ * 1P vault name items live in. Only listing a vault's items needs it; Environments are not in a vault, so a
117
+ * project that only reads an Environment can leave it out.
118
+ */
119
+ vault?: string;
120
+ /** The Environment `readSecret` reads a variable from by its bare name; the one an app keeps its secrets in. */
121
+ environment?: string;
122
+ /** Optional 1P account UUID; passed as `--account` on every op call. Useful when several accounts are signed in. */
83
123
  account?: string;
84
124
  }
85
- interface PluginContext {
125
+ /** Shared state for one 1Password plugin instance: its options and the `op` shell wrapper. */
126
+ export interface PluginContext {
127
+ /** The options the plugin was created with. */
86
128
  options: OpPluginOptions;
129
+ /** The wrapper that runs `op` commands. */
87
130
  shell: OpShell;
88
131
  }
89
- declare function createContext(options: OpPluginOptions): PluginContext;
90
- declare function vault(ctx: PluginContext): Vault;
91
- declare function createPlugin(options: OpPluginOptions): {
132
+ /** Builds the plugin context; throws when the `op` binary is not installed. */
133
+ export declare function createContext(options: OpPluginOptions): PluginContext;
134
+ /** Builds the `vault` capability for the configured vault. */
135
+ export declare function vault(ctx: PluginContext): Vault;
136
+ /** Builds the `credentials` capability: the variables of a 1Password Environment, read for the token resolvers. */
137
+ export declare function credentials(ctx: PluginContext): Credentials;
138
+ /** Creates the 1Password plugin: its `connection` probe and the `vault` and `credentials` capabilities. */
139
+ export declare function createPlugin(options?: OpPluginOptions): {
92
140
  name: string;
141
+ probes: {
142
+ connection: import("@theholocron/cli").Probe;
143
+ };
93
144
  capabilities: {
94
145
  vault: () => Vault;
146
+ credentials: () => Credentials;
95
147
  };
96
148
  };
97
149
  /**
@@ -99,6 +151,5 @@ declare function createPlugin(options: OpPluginOptions): {
99
151
  * store a token in the holocron keyring; the `op` CLI manages its own
100
152
  * auth. Directs the operator to the two paths that actually work.
101
153
  */
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 };
154
+ export declare const AUTH_HINT: string;
155
+ 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,149 @@ 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; an unquoted value that opens a PEM block (`-----BEGIN …-----`) runs to its `-----END …-----`
41
+ * line, because `op` prints a multi-line key that way; anything else is the rest of the line, trimmed. Inline `#`
42
+ * comments are not stripped, because a token may contain one.
43
+ */
44
+ function parseDotenv(text) {
45
+ const out = {};
46
+ const lines = text.split(/\r?\n/);
47
+ for (let i = 0; i < lines.length; i++) {
48
+ const line = lines[i].trim();
49
+ if (!line || line.startsWith("#")) continue;
50
+ const eq = line.indexOf("=");
51
+ if (eq < 0) continue;
52
+ const key = line.slice(0, eq).trim().replace(/^export\s+/, "");
53
+ if (!key) continue;
54
+ const value = line.slice(eq + 1).trim();
55
+ if (value.startsWith("\"")) {
56
+ let body = value.slice(1);
57
+ while (!hasClosingQuote(body) && i + 1 < lines.length) body += `\n${lines[++i]}`;
58
+ out[key] = unescapeDouble(body.slice(0, closingQuoteAt(body)));
59
+ continue;
60
+ }
61
+ if (value.startsWith("'") && value.endsWith("'") && value.length >= 2) {
62
+ out[key] = value.slice(1, -1);
63
+ continue;
64
+ }
65
+ if (/^-----BEGIN [^-]+-----/.test(value)) {
66
+ let block = value;
67
+ while (!/-----END [^-]+-----\s*$/.test(block) && i + 1 < lines.length) block += `\n${lines[++i].trim()}`;
68
+ out[key] = block;
69
+ continue;
70
+ }
71
+ out[key] = value;
72
+ }
73
+ return out;
74
+ }
75
+ /** The index of the first `"` not preceded by a backslash, or the whole length when there is none. */
76
+ function closingQuoteAt(body) {
77
+ for (let i = 0; i < body.length; i++) if (body[i] === "\\") i++;
78
+ else if (body[i] === "\"") return i;
79
+ return body.length;
80
+ }
81
+ function hasClosingQuote(body) {
82
+ return closingQuoteAt(body) < body.length;
83
+ }
84
+ function unescapeDouble(inner) {
85
+ return inner.replace(/\\([nrt"\\])/g, (_, c) => ({
86
+ n: "\n",
87
+ r: "\r",
88
+ t: " ",
89
+ "\"": "\"",
90
+ "\\": "\\"
91
+ })[c]);
92
+ }
93
+ // src/capabilities/credentials.ts
94
+ /** How long to wait for `op` (a Touch ID prompt included) before giving up on the environment. */
95
+ const READ_TIMEOUT_MS = 6e4;
96
+ /** `op` words a missing Environment as "environment couldn't be found". */
97
+ const NOT_FOUND = /couldn.?t be found|could not be found|not found/i;
98
+ /**
99
+ * The spellings of an Environment name to try, in order: as written, lowercase, Title case, UPPERCASE. `op` finds an
100
+ * Environment by its exact name and has no command that lists them, so the real spelling cannot be looked up.
101
+ */
102
+ function spellings(name) {
103
+ const title = name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
104
+ return [.../* @__PURE__ */ new Set([
105
+ name,
106
+ name.toLowerCase(),
107
+ title,
108
+ name.toUpperCase()
109
+ ])];
110
+ }
111
+ /** `credentials` capability for 1Password, implemented by shelling out to `op environment secret list`. */
112
+ var OpCredentials = class {
113
+ shell;
114
+ /** Capability key; always `"credentials"`. */
115
+ key = "credentials";
116
+ /** Provider name; always `"1password"`. */
117
+ providerName = "1password";
118
+ constructor(shell) {
119
+ this.shell = shell;
120
+ }
121
+ /**
122
+ * Every variable of the Environment, with values. Tries {@link spellings} of the name until `op` finds one;
123
+ * any other failure (not signed in, a prompt that timed out) is thrown at once.
124
+ */
125
+ async read(environment) {
126
+ return parseDotenv((await this.list(environment, ["--reveal"])).stdout);
127
+ }
128
+ /**
129
+ * The Environment as `op` spells it and the names of its variables, asked without `--reveal` so no value is
130
+ * printed or kept: `op` shows a placeholder for each value, which is not read. Tries the same spellings as `read`.
131
+ */
132
+ async inspect(environment) {
133
+ const { name, stdout } = await this.list(environment, []);
134
+ return {
135
+ environment: name,
136
+ names: variableNames(stdout)
137
+ };
138
+ }
139
+ async list(environment, flags) {
140
+ const tried = spellings(environment);
141
+ for (const name of tried) {
142
+ const result = this.shell.run([
143
+ "environment",
144
+ "secret",
145
+ "list",
146
+ name,
147
+ ...flags,
148
+ "--format=dotenv"
149
+ ], { timeoutMs: READ_TIMEOUT_MS });
150
+ if (result.ok) return {
151
+ name,
152
+ stdout: result.stdout
153
+ };
154
+ if (!NOT_FOUND.test(result.stderr)) throw new ProviderApiError(`1Password environment secret list ${name} failed: ${result.stderr || "no stderr"}`, 0, result.stderr);
155
+ }
156
+ 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);
157
+ }
158
+ };
159
+ /** The variable names in dotenv text, taken from the start of each line so a value is never looked at. */
160
+ function variableNames(text) {
161
+ 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);
162
+ }
163
+ // src/capabilities/vault.ts
164
+ /** `vault` capability for 1Password, implemented by shelling out to the `op` CLI against one vault. */
33
165
  var OpVault = class {
34
166
  shell;
167
+ /** Capability key; always `"vault"`. */
35
168
  key = "vault";
169
+ /** Provider name; always `"1password"`. */
36
170
  providerName = "1password";
37
171
  vaultName;
38
- constructor(shell, opts) {
172
+ environmentName;
173
+ constructor(shell, opts = {}) {
39
174
  this.shell = shell;
40
- if (!opts.vault) throw new Error("OpVault requires `vault` (1P vault name) in options");
41
- this.vaultName = opts.vault;
175
+ this.vaultName = opts.vault || void 0;
176
+ this.environmentName = opts.environment || void 0;
42
177
  }
43
178
  async read(reference) {
44
179
  return this.shell.runOrThrow([
@@ -74,7 +209,13 @@ var OpVault = class {
74
209
  `${parsed.field}=${value}`
75
210
  ], `item create ${parsed.item}`);
76
211
  }
212
+ /**
213
+ * The names this vault holds: the item titles of its `vault`, or, when only an `environment` is set (an Environment
214
+ * is not in a vault), that Environment's variable names. Values are read in memory and never returned.
215
+ */
77
216
  async list() {
217
+ if (!this.vaultName && this.environmentName) return Object.keys(await this.readEnvironment(this.environmentName));
218
+ if (!this.vaultName) throw new ProviderApiError("1Password `list` needs a `vault` or an `environment` in the plugin options: it lists the items in one vault, or the variable names of one Environment", 400, void 0);
78
219
  const stdout = this.shell.runOrThrow([
79
220
  "item",
80
221
  "list",
@@ -84,21 +225,27 @@ var OpVault = class {
84
225
  if (!stdout) return [];
85
226
  return JSON.parse(stdout).map((i) => i.title);
86
227
  }
87
- async environments() {
88
- const stdout = this.shell.runOrThrow([
228
+ /**
229
+ * Every variable of a 1Password Environment, by its name or id. `op environment read` takes only an id, while
230
+ * `op environment secret list` takes either, so this reads through the latter with the values revealed. There is
231
+ * no `op` command that lists Environments, so this vault has no `environments()`.
232
+ */
233
+ async readEnvironment(environment) {
234
+ return parseDotenv(this.shell.runOrThrow([
89
235
  "environment",
236
+ "secret",
90
237
  "list",
91
- "--format=json"
92
- ], "environment list");
93
- if (!stdout) return [];
94
- return JSON.parse(stdout).map((e) => e.name);
238
+ environment,
239
+ "--reveal",
240
+ "--format=dotenv"
241
+ ], `environment secret list ${environment}`));
95
242
  }
96
- async readEnvironment(environmentId) {
97
- return parseEnvironmentDump(this.shell.runOrThrow([
98
- "environment",
99
- "read",
100
- environmentId
101
- ], `environment read ${environmentId}`));
243
+ /** One variable of the Environment this vault was set up with, by its bare name. */
244
+ async readSecret(name) {
245
+ 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);
246
+ const value = (await this.readEnvironment(this.environmentName))[name];
247
+ if (value === void 0) throw new ProviderApiError(`1Password Environment ${this.environmentName} has no variable ${name}`, 404, void 0);
248
+ return value;
102
249
  }
103
250
  };
104
251
  /**
@@ -117,27 +264,7 @@ function parseReference(reference) {
117
264
  field: fieldParts.join("/")
118
265
  };
119
266
  }
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
267
+ // src/shell.ts
141
268
  /**
142
269
  * Thin wrapper around `spawnSync` for `op` CLI shell-outs.
143
270
  *
@@ -156,9 +283,12 @@ function parseEnvironmentDump(stdout) {
156
283
  * token). Default spawnSync stdio of `['pipe','pipe','pipe']` would
157
284
  * suppress biometric unlock and return "not signed in" instead.
158
285
  */
286
+ /** Thin wrapper around `spawnSync` that runs the `op` CLI and returns a uniform result. */
159
287
  var OpShell = class {
160
288
  spawnImpl;
289
+ /** The `op` binary this wrapper runs; defaults to `"op"`. */
161
290
  binary;
291
+ /** The 1Password account UUID passed as `--account` on each call, when one is set. */
162
292
  account;
163
293
  constructor(opts = {}) {
164
294
  this.spawnImpl = opts.spawn ?? spawnSync;
@@ -178,7 +308,8 @@ var OpShell = class {
178
308
  "inherit",
179
309
  "pipe",
180
310
  "pipe"
181
- ]
311
+ ],
312
+ ...opts.timeoutMs !== void 0 ? { timeout: opts.timeoutMs } : {}
182
313
  });
183
314
  if (out.error) return {
184
315
  ok: false,
@@ -198,8 +329,7 @@ var OpShell = class {
198
329
  return result.stdout;
199
330
  }
200
331
  };
201
- //#endregion
202
- //#region src/verify-token.ts
332
+ // src/verify-token.ts
203
333
  /**
204
334
  * `verifyToken` — plugin-level export used by `holocron auth check`.
205
335
  *
@@ -213,6 +343,7 @@ var OpShell = class {
213
343
  * will be stored in the keyring but never read by this plugin — the
214
344
  * `AUTH_HINT` below explains that up front.
215
345
  */
346
+ /** Checks that `op` is installed and signed in by running `op whoami`; the token argument is unused. */
216
347
  async function verifyToken(_token, opts = {}) {
217
348
  const spawnImpl = opts.spawn ?? spawnSync;
218
349
  const binary = opts.binary ?? "op";
@@ -245,10 +376,9 @@ async function verifyToken(_token, opts = {}) {
245
376
  };
246
377
  }
247
378
  }
248
- //#endregion
249
- //#region src/index.ts
379
+ // src/index.ts
380
+ /** Builds the plugin context; throws when the `op` binary is not installed. */
250
381
  function createContext(options) {
251
- if (!options.vault) throw new Error("@theholocron/holocron-plugin-1password requires `vault` in options");
252
382
  const verifyOpts = {};
253
383
  if (options.spawn !== void 0) verifyOpts.spawn = options.spawn;
254
384
  if (options.binary !== void 0) verifyOpts.binary = options.binary;
@@ -262,14 +392,31 @@ function createContext(options) {
262
392
  shell: new OpShell(shellOpts)
263
393
  };
264
394
  }
395
+ /** Builds the `vault` capability for the configured vault. */
265
396
  function vault(ctx) {
266
- return new OpVault(ctx.shell, { vault: ctx.options.vault });
397
+ return new OpVault(ctx.shell, {
398
+ ...ctx.options.vault !== void 0 ? { vault: ctx.options.vault } : {},
399
+ ...ctx.options.environment !== void 0 ? { environment: ctx.options.environment } : {}
400
+ });
267
401
  }
268
- function createPlugin(options) {
402
+ /** Builds the `credentials` capability: the variables of a 1Password Environment, read for the token resolvers. */
403
+ function credentials(ctx) {
404
+ return new OpCredentials(ctx.shell);
405
+ }
406
+ /** Creates the 1Password plugin: its `connection` probe and the `vault` and `credentials` capabilities. */
407
+ function createPlugin(options = {}) {
269
408
  const ctx = createContext(options);
270
409
  return {
271
410
  name: "@theholocron/holocron-plugin-1password",
272
- capabilities: { vault: () => vault(ctx) }
411
+ probes: { connection: connectionProbe({
412
+ provider: "1Password",
413
+ token: () => "",
414
+ verify: (token) => verifyToken(token, { spawn: options.spawn })
415
+ }) },
416
+ capabilities: {
417
+ vault: () => vault(ctx),
418
+ credentials: () => credentials(ctx)
419
+ }
273
420
  };
274
421
  }
275
422
  /**
@@ -278,5 +425,4 @@ function createPlugin(options) {
278
425
  * auth. Directs the operator to the two paths that actually work.
279
426
  */
280
427
  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 };
428
+ 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.37",
3
+ "version": "5.0.0-alpha.371",
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",
39
- "@vitest/eslint-plugin": "^1.6.27",
40
- "eslint": "^10.8.1",
41
- "eslint-plugin-n": "^18.3.0",
42
- "globals": "^17.11.0",
43
- "tsdown": "^0.22.14",
44
- "tsx": "4.23.12",
34
+ "@vitest/coverage-v8": "^5.1.0",
35
+ "@vitest/eslint-plugin": "^1.6.28",
36
+ "eslint": "^10.14.0",
37
+ "eslint-plugin-n": "^18.5.0",
38
+ "globals": "^17.14.0",
39
+ "tsdown": "^0.23.5",
40
+ "tsx": "4.23.15",
45
41
  "typescript": "^5.9.3",
46
- "vitest": "^4.1.11",
47
- "@theholocron/cli": "5.0.0-alpha.37"
42
+ "vitest": "^5.1.0",
43
+ "@theholocron/cli": "5.0.0-alpha.371",
44
+ "@theholocron/tsdown-config": "^8.9.0-alpha.11",
45
+ "@theholocron/tsconfig": "^8.9.0-alpha.11",
46
+ "@theholocron/vitest-config": "^8.9.0-alpha.11",
47
+ "@theholocron/eslint-config": "^8.9.0-alpha.11"
48
48
  },
49
49
  "peerDependencies": {
50
- "@theholocron/cli": "5.0.0-alpha.37"
50
+ "@theholocron/cli": "5.0.0-alpha.371"
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
  }