@townco/secret 0.1.32 → 0.1.34
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/dist/env-file.d.ts +96 -98
- package/dist/env-file.js +199 -199
- package/dist/index.d.ts +5 -8
- package/dist/index.js +107 -114
- package/dist/onepassword.d.ts +92 -98
- package/dist/onepassword.js +197 -197
- package/package.json +2 -2
package/dist/env-file.d.ts
CHANGED
|
@@ -1,107 +1,105 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Represents a line in an .env file
|
|
3
3
|
*/
|
|
4
|
-
type EnvLine =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
value: string;
|
|
16
|
-
raw: string;
|
|
17
|
-
};
|
|
4
|
+
type EnvLine = {
|
|
5
|
+
type: "comment";
|
|
6
|
+
content: string;
|
|
7
|
+
} | {
|
|
8
|
+
type: "blank";
|
|
9
|
+
} | {
|
|
10
|
+
type: "entry";
|
|
11
|
+
key: string;
|
|
12
|
+
value: string;
|
|
13
|
+
raw: string;
|
|
14
|
+
};
|
|
18
15
|
/**
|
|
19
16
|
* A data structure that represents a parsed .env file while preserving
|
|
20
17
|
* all original content including comments, blank lines, and order.
|
|
21
18
|
*/
|
|
22
19
|
export declare class EnvFile {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
20
|
+
private lines;
|
|
21
|
+
constructor(lines?: EnvLine[]);
|
|
22
|
+
/**
|
|
23
|
+
* Parse a .env file string into an EnvFile structure
|
|
24
|
+
*/
|
|
25
|
+
static parse(content: string): EnvFile;
|
|
26
|
+
/**
|
|
27
|
+
* Serialize the EnvFile back to a string
|
|
28
|
+
*/
|
|
29
|
+
toString(): string;
|
|
30
|
+
/**
|
|
31
|
+
* Get all entries as a key-value record
|
|
32
|
+
*/
|
|
33
|
+
toRecord(): Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* Find an entry line by key
|
|
36
|
+
*/
|
|
37
|
+
private findEntry;
|
|
38
|
+
/**
|
|
39
|
+
* Find the index of an entry by key
|
|
40
|
+
*/
|
|
41
|
+
private findEntryIndex;
|
|
42
|
+
/**
|
|
43
|
+
* Create an entry line from key and value
|
|
44
|
+
*/
|
|
45
|
+
private createEntry;
|
|
46
|
+
/**
|
|
47
|
+
* Normalize a value by ensuring it's properly quoted
|
|
48
|
+
*/
|
|
49
|
+
private normalizeValue;
|
|
50
|
+
/**
|
|
51
|
+
* Find the insertion index for a new entry (before the final blank line if present)
|
|
52
|
+
*/
|
|
53
|
+
private findInsertionIndex;
|
|
54
|
+
/**
|
|
55
|
+
* Get the value for a specific key
|
|
56
|
+
*/
|
|
57
|
+
get(key: string): string | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Set a value for a key. If the key exists, updates it in place.
|
|
60
|
+
* If it doesn't exist, appends it above the final newline (if present).
|
|
61
|
+
* Values are always double quoted.
|
|
62
|
+
*/
|
|
63
|
+
set(key: string, value: string): this;
|
|
64
|
+
/**
|
|
65
|
+
* Delete a key-value entry
|
|
66
|
+
*/
|
|
67
|
+
delete(key: string): this;
|
|
68
|
+
/**
|
|
69
|
+
* Check if a key exists
|
|
70
|
+
*/
|
|
71
|
+
has(key: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Get all keys
|
|
74
|
+
*/
|
|
75
|
+
keys(): string[];
|
|
76
|
+
/**
|
|
77
|
+
* Iterate over all entries
|
|
78
|
+
*/
|
|
79
|
+
entries(): IterableIterator<[string, string]>;
|
|
80
|
+
/**
|
|
81
|
+
* Apply a function to all entries and return a new EnvFile
|
|
82
|
+
*/
|
|
83
|
+
map(fn: (key: string, value: string) => [string, string]): EnvFile;
|
|
84
|
+
/**
|
|
85
|
+
* Filter entries based on a predicate
|
|
86
|
+
*/
|
|
87
|
+
filter(fn: (key: string, value: string) => boolean): EnvFile;
|
|
88
|
+
/**
|
|
89
|
+
* Add a comment line
|
|
90
|
+
*/
|
|
91
|
+
addComment(content: string): this;
|
|
92
|
+
/**
|
|
93
|
+
* Add a blank line
|
|
94
|
+
*/
|
|
95
|
+
addBlank(): this;
|
|
96
|
+
/**
|
|
97
|
+
* Get the raw lines array for custom operations
|
|
98
|
+
*/
|
|
99
|
+
getLines(): readonly EnvLine[];
|
|
100
|
+
/**
|
|
101
|
+
* Create a clone of this EnvFile
|
|
102
|
+
*/
|
|
103
|
+
clone(): EnvFile;
|
|
107
104
|
}
|
|
105
|
+
export {};
|
package/dist/env-file.js
CHANGED
|
@@ -3,203 +3,203 @@
|
|
|
3
3
|
* all original content including comments, blank lines, and order.
|
|
4
4
|
*/
|
|
5
5
|
export class EnvFile {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
6
|
+
lines;
|
|
7
|
+
constructor(lines = []) {
|
|
8
|
+
this.lines = lines;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Parse a .env file string into an EnvFile structure
|
|
12
|
+
*/
|
|
13
|
+
static parse(content) {
|
|
14
|
+
const lines = content.split("\n").map((line) => {
|
|
15
|
+
const trimmed = line.trim();
|
|
16
|
+
if (trimmed === "") {
|
|
17
|
+
return { type: "blank" };
|
|
18
|
+
}
|
|
19
|
+
if (trimmed.startsWith("#")) {
|
|
20
|
+
return { type: "comment", content: line };
|
|
21
|
+
}
|
|
22
|
+
const equalsIndex = line.indexOf("=");
|
|
23
|
+
if (equalsIndex === -1) {
|
|
24
|
+
// Malformed line, treat as comment
|
|
25
|
+
return { type: "comment", content: line };
|
|
26
|
+
}
|
|
27
|
+
const key = line.substring(0, equalsIndex).trim();
|
|
28
|
+
const value = line.substring(equalsIndex + 1);
|
|
29
|
+
return { type: "entry", key, value, raw: line };
|
|
30
|
+
});
|
|
31
|
+
return new EnvFile(lines);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Serialize the EnvFile back to a string
|
|
35
|
+
*/
|
|
36
|
+
toString() {
|
|
37
|
+
return this.lines
|
|
38
|
+
.map((line) => {
|
|
39
|
+
switch (line.type) {
|
|
40
|
+
case "blank":
|
|
41
|
+
return "";
|
|
42
|
+
case "comment":
|
|
43
|
+
return line.content;
|
|
44
|
+
case "entry":
|
|
45
|
+
return line.raw;
|
|
46
|
+
default:
|
|
47
|
+
throw new Error(`Unknown line type`);
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
.join("\n");
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get all entries as a key-value record
|
|
54
|
+
*/
|
|
55
|
+
toRecord() {
|
|
56
|
+
return Object.fromEntries(this.entries());
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Find an entry line by key
|
|
60
|
+
*/
|
|
61
|
+
findEntry(key) {
|
|
62
|
+
const line = this.lines.find((l) => l.type === "entry" && l.key === key);
|
|
63
|
+
return line;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Find the index of an entry by key
|
|
67
|
+
*/
|
|
68
|
+
findEntryIndex(key) {
|
|
69
|
+
return this.lines.findIndex((l) => l.type === "entry" && l.key === key);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create an entry line from key and value
|
|
73
|
+
*/
|
|
74
|
+
createEntry(key, value) {
|
|
75
|
+
const quotedValue = this.normalizeValue(value);
|
|
76
|
+
return {
|
|
77
|
+
type: "entry",
|
|
78
|
+
key,
|
|
79
|
+
value: quotedValue,
|
|
80
|
+
raw: `${key}=${quotedValue}`,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Normalize a value by ensuring it's properly quoted
|
|
85
|
+
*/
|
|
86
|
+
normalizeValue(value) {
|
|
87
|
+
// Strip existing quotes if present, then add quotes
|
|
88
|
+
const unquoted = value.startsWith('"') && value.endsWith('"') ? value.slice(1, -1) : value;
|
|
89
|
+
return `"${unquoted}"`;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Find the insertion index for a new entry (before the final blank line if present)
|
|
93
|
+
*/
|
|
94
|
+
findInsertionIndex() {
|
|
95
|
+
const lastLine = this.lines[this.lines.length - 1];
|
|
96
|
+
return lastLine?.type === "blank"
|
|
97
|
+
? this.lines.length - 1
|
|
98
|
+
: this.lines.length;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get the value for a specific key
|
|
102
|
+
*/
|
|
103
|
+
get(key) {
|
|
104
|
+
return this.findEntry(key)?.value;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Set a value for a key. If the key exists, updates it in place.
|
|
108
|
+
* If it doesn't exist, appends it above the final newline (if present).
|
|
109
|
+
* Values are always double quoted.
|
|
110
|
+
*/
|
|
111
|
+
set(key, value) {
|
|
112
|
+
const index = this.findEntryIndex(key);
|
|
113
|
+
const entry = this.createEntry(key, value);
|
|
114
|
+
if (index !== -1) {
|
|
115
|
+
this.lines[index] = entry;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
this.lines.splice(this.findInsertionIndex(), 0, entry);
|
|
119
|
+
}
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Delete a key-value entry
|
|
124
|
+
*/
|
|
125
|
+
delete(key) {
|
|
126
|
+
this.lines = this.lines.filter((l) => !(l.type === "entry" && l.key === key));
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Check if a key exists
|
|
131
|
+
*/
|
|
132
|
+
has(key) {
|
|
133
|
+
return this.findEntry(key) !== undefined;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get all keys
|
|
137
|
+
*/
|
|
138
|
+
keys() {
|
|
139
|
+
return this.lines
|
|
140
|
+
.filter((l) => l.type === "entry")
|
|
141
|
+
.map((l) => l.key);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Iterate over all entries
|
|
145
|
+
*/
|
|
146
|
+
*entries() {
|
|
147
|
+
for (const line of this.lines) {
|
|
148
|
+
if (line.type === "entry") {
|
|
149
|
+
yield [line.key, line.value];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Apply a function to all entries and return a new EnvFile
|
|
155
|
+
*/
|
|
156
|
+
map(fn) {
|
|
157
|
+
const newLines = this.lines.map((line) => {
|
|
158
|
+
if (line.type === "entry") {
|
|
159
|
+
const [newKey, newValue] = fn(line.key, line.value);
|
|
160
|
+
return this.createEntry(newKey, newValue);
|
|
161
|
+
}
|
|
162
|
+
return line;
|
|
163
|
+
});
|
|
164
|
+
return new EnvFile(newLines);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Filter entries based on a predicate
|
|
168
|
+
*/
|
|
169
|
+
filter(fn) {
|
|
170
|
+
const newLines = this.lines.filter((line) => {
|
|
171
|
+
if (line.type === "entry") {
|
|
172
|
+
return fn(line.key, line.value);
|
|
173
|
+
}
|
|
174
|
+
return true; // Keep comments and blank lines
|
|
175
|
+
});
|
|
176
|
+
return new EnvFile(newLines);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Add a comment line
|
|
180
|
+
*/
|
|
181
|
+
addComment(content) {
|
|
182
|
+
const comment = content.startsWith("#") ? content : `# ${content}`;
|
|
183
|
+
this.lines.push({ type: "comment", content: comment });
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Add a blank line
|
|
188
|
+
*/
|
|
189
|
+
addBlank() {
|
|
190
|
+
this.lines.push({ type: "blank" });
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Get the raw lines array for custom operations
|
|
195
|
+
*/
|
|
196
|
+
getLines() {
|
|
197
|
+
return this.lines;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Create a clone of this EnvFile
|
|
201
|
+
*/
|
|
202
|
+
clone() {
|
|
203
|
+
return new EnvFile([...this.lines]);
|
|
204
|
+
}
|
|
205
205
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
export { EnvFile } from "./env-file";
|
|
2
2
|
export { type OnePassword, OnePassword as OpItem } from "./onepassword";
|
|
3
3
|
export type SecretValidation = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
key: string;
|
|
5
|
+
value: string;
|
|
6
|
+
valid: boolean;
|
|
7
|
+
error?: string;
|
|
8
8
|
};
|
|
9
9
|
export declare const listSecrets: () => Promise<Promise<SecretValidation[]>>;
|
|
10
|
-
export declare const createSecret: (
|
|
11
|
-
name: string,
|
|
12
|
-
value: string,
|
|
13
|
-
) => Promise<Promise<void>>;
|
|
10
|
+
export declare const createSecret: (name: string, value: string) => Promise<Promise<void>>;
|
|
14
11
|
export declare const deleteSecret: (name: string) => Promise<Promise<void>>;
|
|
15
12
|
export declare const genenv: () => Promise<Promise<void>>;
|