@tolgamorf/env2op-cli 0.1.5 → 0.2.1

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.
@@ -0,0 +1,222 @@
1
+ /**
2
+ * Represents a single environment variable parsed from a .env file
3
+ */
4
+ interface EnvVariable {
5
+ /** The variable name/key */
6
+ key: string;
7
+ /** The variable value */
8
+ value: string;
9
+ /** Optional comment from preceding line */
10
+ comment?: string;
11
+ /** Line number in source file */
12
+ line: number;
13
+ }
14
+ /**
15
+ * Represents a line in the .env file (preserves structure)
16
+ */
17
+ type EnvLine = {
18
+ type: "comment";
19
+ content: string;
20
+ } | {
21
+ type: "empty";
22
+ } | {
23
+ type: "variable";
24
+ key: string;
25
+ value: string;
26
+ };
27
+ /**
28
+ * Result of parsing an .env file
29
+ */
30
+ interface ParseResult {
31
+ /** Successfully parsed variables */
32
+ variables: EnvVariable[];
33
+ /** All lines preserving structure */
34
+ lines: EnvLine[];
35
+ /** Any parse errors encountered */
36
+ errors: string[];
37
+ }
38
+ /**
39
+ * Options for creating a 1Password Secure Note
40
+ */
41
+ interface CreateItemOptions {
42
+ /** Vault name */
43
+ vault: string;
44
+ /** Item title */
45
+ title: string;
46
+ /** Fields to store */
47
+ fields: EnvVariable[];
48
+ /** Store as password type (hidden) instead of text (visible) */
49
+ secret: boolean;
50
+ }
51
+ /**
52
+ * Options for editing a 1Password Secure Note
53
+ */
54
+ interface EditItemOptions extends CreateItemOptions {
55
+ /** Item ID for reliable lookup (more robust than using title) */
56
+ itemId: string;
57
+ }
58
+ /**
59
+ * Result of creating a 1Password item
60
+ */
61
+ interface CreateItemResult {
62
+ /** 1Password item ID */
63
+ id: string;
64
+ /** Item title */
65
+ title: string;
66
+ /** Vault name */
67
+ vault: string;
68
+ /** Vault ID */
69
+ vaultId: string;
70
+ /** Field IDs mapped by field label */
71
+ fieldIds: Record<string, string>;
72
+ }
73
+ /**
74
+ * Options for the convert command (env2op)
75
+ */
76
+ interface ConvertOptions {
77
+ /** Path to .env file */
78
+ envFile: string;
79
+ /** 1Password vault name */
80
+ vault: string;
81
+ /** Secure Note title */
82
+ itemName: string;
83
+ /** Custom output path for template file */
84
+ output?: string;
85
+ /** Preview mode - don't make changes */
86
+ dryRun: boolean;
87
+ /** Store all fields as password type */
88
+ secret: boolean;
89
+ /** Skip confirmation prompts */
90
+ force: boolean;
91
+ /** Show op CLI output */
92
+ verbose: boolean;
93
+ }
94
+ /**
95
+ * Options for template generation
96
+ */
97
+ interface TemplateOptions {
98
+ /** Vault ID */
99
+ vaultId: string;
100
+ /** Item ID in 1Password */
101
+ itemId: string;
102
+ /** Variables to include */
103
+ variables: EnvVariable[];
104
+ /** All lines preserving structure */
105
+ lines: EnvLine[];
106
+ /** Field IDs mapped by field label */
107
+ fieldIds: Record<string, string>;
108
+ }
109
+ /**
110
+ * Parse an .env file and extract environment variables
111
+ *
112
+ * @param filePath - Path to the .env file
113
+ * @returns ParseResult containing variables and any errors
114
+ * @throws Env2OpError if file not found
115
+ */
116
+ declare function parseEnvFile(filePath: string): Promise<ParseResult>;
117
+ /**
118
+ * Validate that the parsed result has variables
119
+ *
120
+ * @param result - ParseResult from parseEnvFile
121
+ * @param filePath - Original file path for error message
122
+ * @throws Env2OpError if no variables found
123
+ */
124
+ declare function validateParseResult(result: ParseResult, filePath: string): void;
125
+ interface VerboseOption {
126
+ verbose?: boolean;
127
+ }
128
+ /**
129
+ * Check if the 1Password CLI is installed
130
+ */
131
+ declare function checkOpCli(options?: VerboseOption): Promise<boolean>;
132
+ /**
133
+ * Check if user is signed in to 1Password CLI
134
+ */
135
+ declare function checkSignedIn(options?: VerboseOption): Promise<boolean>;
136
+ /**
137
+ * Sign in to 1Password CLI (opens system auth dialog)
138
+ */
139
+ declare function signIn(options?: VerboseOption): Promise<boolean>;
140
+ /**
141
+ * Check if an item exists in a vault, return its ID if found
142
+ */
143
+ declare function itemExists2(vault: string, title: string, options?: VerboseOption): Promise<string | null>;
144
+ /**
145
+ * Check if a vault exists
146
+ */
147
+ declare function vaultExists(vault: string, options?: VerboseOption): Promise<boolean>;
148
+ /**
149
+ * Create a new vault
150
+ */
151
+ declare function createVault(name: string, options?: VerboseOption): Promise<void>;
152
+ /**
153
+ * Create a Secure Note in 1Password with the given fields
154
+ */
155
+ declare function createSecureNote(options: CreateItemOptions & VerboseOption): Promise<CreateItemResult>;
156
+ /**
157
+ * Edit an existing Secure Note in 1Password - updates fields in place
158
+ * This preserves the item UUID and doesn't add to trash
159
+ * JSON piping completely replaces fields - no need for manual deletion
160
+ */
161
+ declare function editSecureNote(options: EditItemOptions & VerboseOption): Promise<CreateItemResult>;
162
+ /**
163
+ * Generate op:// reference template content
164
+ *
165
+ * Format: KEY=op://vault/item/field
166
+ *
167
+ * This template can be used with:
168
+ * - `op2env template.tpl` to generate .env
169
+ * - `op run --env-file template.tpl -- command`
170
+ */
171
+ declare function generateTemplateContent(options: TemplateOptions, templateFileName: string): string;
172
+ /**
173
+ * Write template to file
174
+ */
175
+ declare function writeTemplate(content: string, outputPath: string): void;
176
+ /**
177
+ * Generate usage instructions for display
178
+ */
179
+ declare function generateUsageInstructions(templatePath: string): string;
180
+ /**
181
+ * Custom error class for env2op with error codes and suggestions
182
+ */
183
+ declare class Env2OpError extends Error {
184
+ code: ErrorCode;
185
+ suggestion?: string | undefined;
186
+ constructor(message: string, code: ErrorCode, suggestion?: string | undefined);
187
+ }
188
+ /**
189
+ * Error codes for different failure scenarios
190
+ */
191
+ declare const ErrorCodes: {
192
+ readonly ENV_FILE_NOT_FOUND: "ENV_FILE_NOT_FOUND";
193
+ readonly ENV_FILE_EMPTY: "ENV_FILE_EMPTY";
194
+ readonly OP_CLI_NOT_INSTALLED: "OP_CLI_NOT_INSTALLED";
195
+ readonly OP_NOT_SIGNED_IN: "OP_NOT_SIGNED_IN";
196
+ readonly OP_SIGNIN_FAILED: "OP_SIGNIN_FAILED";
197
+ readonly VAULT_NOT_FOUND: "VAULT_NOT_FOUND";
198
+ readonly VAULT_CREATE_FAILED: "VAULT_CREATE_FAILED";
199
+ readonly ITEM_EXISTS: "ITEM_EXISTS";
200
+ readonly ITEM_CREATE_FAILED: "ITEM_CREATE_FAILED";
201
+ readonly ITEM_EDIT_FAILED: "ITEM_EDIT_FAILED";
202
+ readonly PARSE_ERROR: "PARSE_ERROR";
203
+ readonly TEMPLATE_NOT_FOUND: "TEMPLATE_NOT_FOUND";
204
+ readonly INJECT_FAILED: "INJECT_FAILED";
205
+ };
206
+ type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
207
+ /**
208
+ * Error factory functions for common scenarios
209
+ */
210
+ declare const errors: {
211
+ envFileNotFound: (path: string) => Env2OpError;
212
+ envFileEmpty: (path: string) => Env2OpError;
213
+ opCliNotInstalled: () => Env2OpError;
214
+ opNotSignedIn: () => Env2OpError;
215
+ vaultNotFound: (vault: string) => Env2OpError;
216
+ vaultCreateFailed: (message: string) => Env2OpError;
217
+ itemExists: (title: string, vault: string) => Env2OpError;
218
+ itemCreateFailed: (message: string) => Env2OpError;
219
+ itemEditFailed: (message: string) => Env2OpError;
220
+ parseError: (line: number, message: string) => Env2OpError;
221
+ };
222
+ export { writeTemplate, vaultExists, validateParseResult, signIn, parseEnvFile, itemExists2 as itemExists, generateUsageInstructions, generateTemplateContent, errors, editSecureNote, createVault, createSecureNote, checkSignedIn, checkOpCli, TemplateOptions, ParseResult, ErrorCodes, EnvVariable, EnvLine, Env2OpError, CreateItemResult, CreateItemOptions, ConvertOptions };