@ekanos/cli 0.34.0 → 0.35.0
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 +2 -1
- package/dist/commands/index-experience.js +2 -0
- package/dist/commands/index-experience.js.map +1 -1
- package/dist/commands/migrate.d.ts +2 -0
- package/dist/commands/migrate.js +180 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/status.js +18 -2
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/team-agents.d.ts +1 -1
- package/dist/commands/team-agents.js +6 -0
- package/dist/commands/team-agents.js.map +1 -1
- package/dist/commands/team-api-keys.d.ts +4 -0
- package/dist/commands/team-api-keys.js +277 -0
- package/dist/commands/team-api-keys.js.map +1 -0
- package/dist/commands/teams.js +1 -1
- package/dist/commands/teams.js.map +1 -1
- package/dist/host-load.d.ts +8 -0
- package/dist/host-load.js +115 -0
- package/dist/host-load.js.map +1 -0
- package/dist/index.js +16 -3
- package/dist/index.js.map +1 -1
- package/dist/migrate-connection.d.ts +29 -0
- package/dist/migrate-connection.js +569 -0
- package/dist/migrate-connection.js.map +1 -0
- package/dist/teams-api.js +6 -0
- package/dist/teams-api.js.map +1 -1
- package/dist/validate-findings.js +5 -1
- package/dist/validate-findings.js.map +1 -1
- package/loader/declaration-loader.hooks.mjs +187 -0
- package/loader/host-load-probe.mjs +20 -0
- package/loader/register-declaration-loader.mjs +3 -0
- package/package.json +5 -4
- package/templates/AGENTS.md.tmpl +17 -3
- package/templates/experience/package.json.tmpl +4 -4
- package/templates/package.json.tmpl +4 -4
- package/templates/skills/build-integration/references/oauth-setup.md +3 -3
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface FileEdit {
|
|
2
|
+
path: string;
|
|
3
|
+
source: string;
|
|
4
|
+
}
|
|
5
|
+
interface CredentialAtLevel {
|
|
6
|
+
kind: 'oauth' | 'activation';
|
|
7
|
+
id: string;
|
|
8
|
+
level: string;
|
|
9
|
+
}
|
|
10
|
+
export interface MigrateOptions {
|
|
11
|
+
credentials: readonly CredentialAtLevel[];
|
|
12
|
+
ungroupedSecretFields?: readonly {
|
|
13
|
+
name: string;
|
|
14
|
+
label?: string;
|
|
15
|
+
}[];
|
|
16
|
+
readImport?: (specifier: string) => FileEdit | null;
|
|
17
|
+
}
|
|
18
|
+
export type MigrateEdit = {
|
|
19
|
+
ok: true;
|
|
20
|
+
source: string;
|
|
21
|
+
changed: boolean;
|
|
22
|
+
notes: string[];
|
|
23
|
+
related: FileEdit[];
|
|
24
|
+
} | {
|
|
25
|
+
ok: false;
|
|
26
|
+
reason: string;
|
|
27
|
+
};
|
|
28
|
+
export declare function migrateConnectionSource(source: string, options: MigrateOptions): MigrateEdit;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
function skipString(source, index) {
|
|
2
|
+
const quote = source[index];
|
|
3
|
+
let i = index + 1;
|
|
4
|
+
while (i < source.length) {
|
|
5
|
+
const char = source[i];
|
|
6
|
+
if (char === '\\') {
|
|
7
|
+
i += 2;
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
if (quote === '`' && char === '$' && source[i + 1] === '{') {
|
|
11
|
+
i = matchClose(source, i + 1) + 1;
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (char === quote)
|
|
15
|
+
return i + 1;
|
|
16
|
+
i += 1;
|
|
17
|
+
}
|
|
18
|
+
return source.length;
|
|
19
|
+
}
|
|
20
|
+
function skipComment(source, index) {
|
|
21
|
+
if (source.startsWith('//', index)) {
|
|
22
|
+
const end = source.indexOf('\n', index);
|
|
23
|
+
return end === -1 ? source.length : end;
|
|
24
|
+
}
|
|
25
|
+
const end = source.indexOf('*/', index + 2);
|
|
26
|
+
return end === -1 ? source.length : end + 2;
|
|
27
|
+
}
|
|
28
|
+
function isCommentStart(source, index) {
|
|
29
|
+
return source.startsWith('//', index) || source.startsWith('/*', index);
|
|
30
|
+
}
|
|
31
|
+
const OPEN = new Set(['{', '[', '(']);
|
|
32
|
+
const CLOSE = new Set(['}', ']', ')']);
|
|
33
|
+
function matchClose(source, open) {
|
|
34
|
+
let depth = 0;
|
|
35
|
+
let i = open;
|
|
36
|
+
while (i < source.length) {
|
|
37
|
+
const char = source[i];
|
|
38
|
+
if (char === '"' || char === "'" || char === '`') {
|
|
39
|
+
i = skipString(source, i);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (isCommentStart(source, i)) {
|
|
43
|
+
i = skipComment(source, i);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (OPEN.has(char))
|
|
47
|
+
depth += 1;
|
|
48
|
+
if (CLOSE.has(char)) {
|
|
49
|
+
depth -= 1;
|
|
50
|
+
if (depth === 0)
|
|
51
|
+
return i;
|
|
52
|
+
}
|
|
53
|
+
i += 1;
|
|
54
|
+
}
|
|
55
|
+
return -1;
|
|
56
|
+
}
|
|
57
|
+
function propertiesOf(source, object) {
|
|
58
|
+
const properties = [];
|
|
59
|
+
let i = object.start + 1;
|
|
60
|
+
let entryStart = i;
|
|
61
|
+
const pushEntry = (end) => {
|
|
62
|
+
const text = source.slice(entryStart, end);
|
|
63
|
+
const match = /^(\s*(?:\/\/[^\n]*\n\s*|\/\*[\s\S]*?\*\/\s*)*)([A-Za-z_$][\w$]*|'[^']*'|"[^"]*"|\[[A-Za-z_$][\w$]*\])\s*:/.exec(text);
|
|
64
|
+
if (match) {
|
|
65
|
+
const keyStart = entryStart + match[1].length;
|
|
66
|
+
const raw = match[2];
|
|
67
|
+
properties.push({
|
|
68
|
+
key: /^['"]/.test(raw) ? raw.slice(1, -1) : raw,
|
|
69
|
+
keyStart,
|
|
70
|
+
valueStart: entryStart + match[0].length,
|
|
71
|
+
end,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else if (text.replace(/\/\/[^\n]*|\/\*[\s\S]*?\*\//g, '').trim() !== '') {
|
|
75
|
+
const lead = /^\s*/.exec(text)[0].length;
|
|
76
|
+
properties.push({
|
|
77
|
+
key: '',
|
|
78
|
+
keyStart: entryStart + lead,
|
|
79
|
+
valueStart: entryStart + lead,
|
|
80
|
+
end,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
while (i < object.end) {
|
|
85
|
+
const char = source[i];
|
|
86
|
+
if (char === '"' || char === "'" || char === '`') {
|
|
87
|
+
i = skipString(source, i);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (isCommentStart(source, i)) {
|
|
91
|
+
i = skipComment(source, i);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (OPEN.has(char)) {
|
|
95
|
+
i = matchClose(source, i) + 1;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (char === ',') {
|
|
99
|
+
pushEntry(i);
|
|
100
|
+
entryStart = i + 1;
|
|
101
|
+
}
|
|
102
|
+
i += 1;
|
|
103
|
+
}
|
|
104
|
+
pushEntry(object.end);
|
|
105
|
+
return properties;
|
|
106
|
+
}
|
|
107
|
+
function objectValue(source, property) {
|
|
108
|
+
let i = property.valueStart;
|
|
109
|
+
while (i < property.end && /\s/.test(source[i]))
|
|
110
|
+
i += 1;
|
|
111
|
+
if (source[i] !== '{')
|
|
112
|
+
return null;
|
|
113
|
+
return { start: i, end: matchClose(source, i) };
|
|
114
|
+
}
|
|
115
|
+
function trimmedValue(source, property) {
|
|
116
|
+
let start = property.valueStart;
|
|
117
|
+
let end = property.end;
|
|
118
|
+
while (start < end && /\s/.test(source[start]))
|
|
119
|
+
start += 1;
|
|
120
|
+
while (end > start && /\s/.test(source[end - 1]))
|
|
121
|
+
end -= 1;
|
|
122
|
+
return { start, end };
|
|
123
|
+
}
|
|
124
|
+
function indentAt(source, index) {
|
|
125
|
+
const lineStart = source.lastIndexOf('\n', index - 1) + 1;
|
|
126
|
+
return /^[ \t]*/.exec(source.slice(lineStart))[0];
|
|
127
|
+
}
|
|
128
|
+
function cutSpan(source, property) {
|
|
129
|
+
const lineStart = source.lastIndexOf('\n', property.keyStart - 1) + 1;
|
|
130
|
+
const onOwnLine = /^\s*$/.test(source.slice(lineStart, property.keyStart));
|
|
131
|
+
let end = property.end;
|
|
132
|
+
if (source[end] === ',')
|
|
133
|
+
end += 1;
|
|
134
|
+
if (onOwnLine) {
|
|
135
|
+
const newline = source.indexOf('\n', end);
|
|
136
|
+
if (newline !== -1 && /^[ \t]*$/.test(source.slice(end, newline))) {
|
|
137
|
+
return { start: lineStart, end: newline + 1 };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return { start: property.keyStart, end };
|
|
141
|
+
}
|
|
142
|
+
function definitionObject(source) {
|
|
143
|
+
const call = /\bdefineIntegration\s*(?:<[^(]*>)?\s*\(/g;
|
|
144
|
+
for (const match of source.matchAll(call)) {
|
|
145
|
+
let i = match.index + match[0].length;
|
|
146
|
+
while (i < source.length && /\s/.test(source[i]))
|
|
147
|
+
i += 1;
|
|
148
|
+
if (source[i] !== '{')
|
|
149
|
+
continue;
|
|
150
|
+
const end = matchClose(source, i);
|
|
151
|
+
if (end !== -1)
|
|
152
|
+
return { start: i, end };
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
function applyEdits(source, edits) {
|
|
157
|
+
let next = source;
|
|
158
|
+
for (const edit of [...edits].sort((a, b) => b.span.start - a.span.start || b.span.end - a.span.end)) {
|
|
159
|
+
next =
|
|
160
|
+
next.slice(0, edit.span.start) + edit.text + next.slice(edit.span.end);
|
|
161
|
+
}
|
|
162
|
+
return next;
|
|
163
|
+
}
|
|
164
|
+
const NO_DEFINITION = 'No `defineIntegration({ … })` call with an object literal in the entry file.';
|
|
165
|
+
function fail(reason) {
|
|
166
|
+
return { ok: false, reason };
|
|
167
|
+
}
|
|
168
|
+
function elementsOf(source, array) {
|
|
169
|
+
const spans = [];
|
|
170
|
+
let i = array.start + 1;
|
|
171
|
+
let start = i;
|
|
172
|
+
const push = (end) => {
|
|
173
|
+
let a = start;
|
|
174
|
+
let b = end;
|
|
175
|
+
while (a < b && /\s/.test(source[a]))
|
|
176
|
+
a += 1;
|
|
177
|
+
while (b > a && /\s/.test(source[b - 1]))
|
|
178
|
+
b -= 1;
|
|
179
|
+
if (b > a)
|
|
180
|
+
spans.push({ start: a, end: b });
|
|
181
|
+
};
|
|
182
|
+
while (i < array.end) {
|
|
183
|
+
const char = source[i];
|
|
184
|
+
if (char === '"' || char === "'" || char === '`') {
|
|
185
|
+
i = skipString(source, i);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (isCommentStart(source, i)) {
|
|
189
|
+
i = skipComment(source, i);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (OPEN.has(char)) {
|
|
193
|
+
i = matchClose(source, i) + 1;
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (char === ',') {
|
|
197
|
+
push(i);
|
|
198
|
+
start = i + 1;
|
|
199
|
+
}
|
|
200
|
+
i += 1;
|
|
201
|
+
}
|
|
202
|
+
push(array.end);
|
|
203
|
+
return spans;
|
|
204
|
+
}
|
|
205
|
+
function valueSpan(source, property) {
|
|
206
|
+
return trimmedValue(source, property);
|
|
207
|
+
}
|
|
208
|
+
function reindent(text, delta) {
|
|
209
|
+
if (delta === 0)
|
|
210
|
+
return text;
|
|
211
|
+
return text
|
|
212
|
+
.split('\n')
|
|
213
|
+
.map((line, index) => {
|
|
214
|
+
if (index === 0 || line.trim() === '')
|
|
215
|
+
return line;
|
|
216
|
+
if (delta > 0)
|
|
217
|
+
return ' '.repeat(delta) + line;
|
|
218
|
+
const lead = /^ */.exec(line)[0].length;
|
|
219
|
+
return line.slice(Math.min(lead, -delta));
|
|
220
|
+
})
|
|
221
|
+
.join('\n');
|
|
222
|
+
}
|
|
223
|
+
function quote(value) {
|
|
224
|
+
return `'${value.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`;
|
|
225
|
+
}
|
|
226
|
+
function levelOf(options, kind, id) {
|
|
227
|
+
var _a;
|
|
228
|
+
var _b;
|
|
229
|
+
return ((_b = (_a = options.credentials.find((credential) => credential.kind === kind && credential.id === id)) === null || _a === void 0 ? void 0 : _a.level) !== null && _b !== void 0 ? _b : null);
|
|
230
|
+
}
|
|
231
|
+
function convertOAuthObject(source, object, id, level) {
|
|
232
|
+
const inner = propertiesOf(source, object);
|
|
233
|
+
const edits = [];
|
|
234
|
+
const client = inner.find((property) => property.key === 'credentials');
|
|
235
|
+
if (client) {
|
|
236
|
+
const clientObject = objectValue(source, client);
|
|
237
|
+
const names = clientObject ? propertiesOf(source, clientObject) : [];
|
|
238
|
+
const idName = names.find((p) => p.key === 'clientIdSecretName');
|
|
239
|
+
const secretName = names.find((p) => p.key === 'clientSecretSecretName');
|
|
240
|
+
if (!clientObject || !idName || !secretName || names.length !== 2) {
|
|
241
|
+
return fail(`the ${id} OAuth credentials are not an object literal of clientIdSecretName and clientSecretSecretName. Move them by hand.`);
|
|
242
|
+
}
|
|
243
|
+
const idValue = source.slice(valueSpan(source, idName).start, valueSpan(source, idName).end);
|
|
244
|
+
const secretValue = source.slice(valueSpan(source, secretName).start, valueSpan(source, secretName).end);
|
|
245
|
+
edits.push({
|
|
246
|
+
span: { start: client.keyStart, end: client.end },
|
|
247
|
+
text: `client: {\n${indentAt(source, client.keyStart)} idSecretName: ${idValue},\n${indentAt(source, client.keyStart)} secretSecretName: ${secretValue},\n${indentAt(source, client.keyStart)}}`,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
const hasLevel = inner.some((property) => property.key === 'level');
|
|
251
|
+
const first = inner[0];
|
|
252
|
+
const indent = first
|
|
253
|
+
? indentAt(source, first.keyStart)
|
|
254
|
+
: `${indentAt(source, object.start)} `;
|
|
255
|
+
edits.push({
|
|
256
|
+
span: { start: object.start + 1, end: object.start + 1 },
|
|
257
|
+
text: `\n${indent}kind: 'oauth',\n${indent}id: ${quote(id)},${hasLevel ? '' : `\n${indent}level: ${quote(level)},`}`,
|
|
258
|
+
});
|
|
259
|
+
const edited = applyEdits(source.slice(0, object.end + 1), edits).slice(object.start);
|
|
260
|
+
return { ok: true, value: edited.replace(/\{\n\n/, '{\n') };
|
|
261
|
+
}
|
|
262
|
+
function oauthEntry(source, property, id, options, built) {
|
|
263
|
+
var _a;
|
|
264
|
+
const level = levelOf(options, 'oauth', id);
|
|
265
|
+
if (!level)
|
|
266
|
+
return fail(`no level is known for the ${id} OAuth credential.`);
|
|
267
|
+
const object = objectValue(source, property);
|
|
268
|
+
if (object) {
|
|
269
|
+
const converted = convertOAuthObject(source, object, id, level);
|
|
270
|
+
if (!converted.ok)
|
|
271
|
+
return converted;
|
|
272
|
+
built.entries.push({
|
|
273
|
+
text: converted.value,
|
|
274
|
+
indent: indentAt(source, property.keyStart),
|
|
275
|
+
});
|
|
276
|
+
return { ok: true, value: null };
|
|
277
|
+
}
|
|
278
|
+
const span = valueSpan(source, property);
|
|
279
|
+
const name = source.slice(span.start, span.end);
|
|
280
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(name)) {
|
|
281
|
+
return fail(`the ${id} OAuth credential is neither an object literal nor a constant. Move it into connection.credentials by hand.`);
|
|
282
|
+
}
|
|
283
|
+
const specifier = importSpecifierOf(source, name);
|
|
284
|
+
const file = specifier ? (_a = options.readImport) === null || _a === void 0 ? void 0 : _a.call(options, specifier) : null;
|
|
285
|
+
if (!file) {
|
|
286
|
+
return fail(`the ${id} OAuth credential ${name} is not imported from a file of this project. Move it into connection.credentials by hand.`);
|
|
287
|
+
}
|
|
288
|
+
const declared = new RegExp(`export\\s+const\\s+${name}\\s*(:\\s*PartnerOAuth(?:Connection)?Declaration\\b)?[^=]*=\\s*\\{`).exec(file.source);
|
|
289
|
+
if (!declared) {
|
|
290
|
+
return fail(`${name} in ${file.path} is not an exported object literal. Move it into connection.credentials by hand.`);
|
|
291
|
+
}
|
|
292
|
+
const open = declared.index + declared[0].length - 1;
|
|
293
|
+
const object2 = { start: open, end: matchClose(file.source, open) };
|
|
294
|
+
const converted = convertOAuthObject(file.source, object2, id, level);
|
|
295
|
+
if (!converted.ok)
|
|
296
|
+
return converted;
|
|
297
|
+
let next = file.source.slice(0, object2.start) +
|
|
298
|
+
converted.value +
|
|
299
|
+
file.source.slice(object2.end + 1);
|
|
300
|
+
if (declared[1]) {
|
|
301
|
+
next = next.replace(declared[0].slice(0, declared[0].length - 1), declared[0]
|
|
302
|
+
.slice(0, declared[0].length - 1)
|
|
303
|
+
.replace(/PartnerOAuth(?:Connection)?Declaration\b/, 'PartnerOAuthCredentialDeclaration'));
|
|
304
|
+
next = fixTypeImport(next);
|
|
305
|
+
}
|
|
306
|
+
built.related.push({ path: file.path, source: next });
|
|
307
|
+
built.entries.push({ text: name, indent: '' });
|
|
308
|
+
built.notes.push(`Made ${name} a connection credential.`);
|
|
309
|
+
return { ok: true, value: null };
|
|
310
|
+
}
|
|
311
|
+
function constantValue(source, name, options) {
|
|
312
|
+
var _a, _b;
|
|
313
|
+
var _c;
|
|
314
|
+
const pattern = new RegExp(`(?:const|let)\\s+${name}\\s*(?::[^=]+)?=\\s*(['"])([^'"]*)\\1`);
|
|
315
|
+
const local = pattern.exec(source);
|
|
316
|
+
if (local)
|
|
317
|
+
return local[2];
|
|
318
|
+
const specifier = importSpecifierOf(source, name);
|
|
319
|
+
const file = specifier ? (_a = options.readImport) === null || _a === void 0 ? void 0 : _a.call(options, specifier) : null;
|
|
320
|
+
return file ? ((_c = (_b = pattern.exec(file.source)) === null || _b === void 0 ? void 0 : _b[2]) !== null && _c !== void 0 ? _c : null) : null;
|
|
321
|
+
}
|
|
322
|
+
function importSpecifierOf(source, name) {
|
|
323
|
+
for (const match of source.matchAll(/import\s+(?:type\s+)?\{([^}]*)\}\s*from\s*['"]([^'"]+)['"]/g)) {
|
|
324
|
+
const names = match[1]
|
|
325
|
+
.split(',')
|
|
326
|
+
.map((part) => part.trim().replace(/^type\s+/, ''));
|
|
327
|
+
if (names.includes(name))
|
|
328
|
+
return match[2];
|
|
329
|
+
}
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
function fixTypeImport(source) {
|
|
333
|
+
const stillUsed = /PartnerOAuth(?:Connection)?Declaration\b/.test(source.replace(/import[\s\S]*?from\s*['"][^'"]+['"];?/g, ''));
|
|
334
|
+
return source.replace(/import\s+(type\s+)?\{([^}]*)\}\s*from\s*(['"][^'"]+['"])/g, (whole, typeWord, names, from) => {
|
|
335
|
+
if (!/PartnerOAuth(?:Connection)?Declaration\b/.test(names))
|
|
336
|
+
return whole;
|
|
337
|
+
const list = names
|
|
338
|
+
.split(',')
|
|
339
|
+
.map((part) => part.trim())
|
|
340
|
+
.filter(Boolean)
|
|
341
|
+
.filter((part) => stillUsed ||
|
|
342
|
+
!/^(type\s+)?PartnerOAuth(?:Connection)?Declaration$/.test(part));
|
|
343
|
+
if (!list.some((part) => /PartnerOAuthCredentialDeclaration$/.test(part))) {
|
|
344
|
+
list.push(typeWord
|
|
345
|
+
? 'PartnerOAuthCredentialDeclaration'
|
|
346
|
+
: 'type PartnerOAuthCredentialDeclaration');
|
|
347
|
+
}
|
|
348
|
+
return `import ${typeWord !== null && typeWord !== void 0 ? typeWord : ''}{ ${list.join(', ')} } from ${from}`;
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
function activationEntries(source, property, options, built) {
|
|
352
|
+
var _a, _b;
|
|
353
|
+
const object = objectValue(source, property);
|
|
354
|
+
if (!object) {
|
|
355
|
+
return fail('`activation` is not an object literal. Move it into connection by hand.');
|
|
356
|
+
}
|
|
357
|
+
const inner = propertiesOf(source, object);
|
|
358
|
+
const fields = inner.find((p) => p.key === 'fields');
|
|
359
|
+
const credentials = inner.find((p) => p.key === 'credentials');
|
|
360
|
+
if (inner.some((p) => p.key !== 'fields' && p.key !== 'credentials')) {
|
|
361
|
+
return fail('`activation` holds more than fields and credentials.');
|
|
362
|
+
}
|
|
363
|
+
if (fields) {
|
|
364
|
+
const span = valueSpan(source, fields);
|
|
365
|
+
built.fields = {
|
|
366
|
+
text: source.slice(span.start, span.end),
|
|
367
|
+
indent: indentAt(source, fields.keyStart),
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
if (credentials) {
|
|
371
|
+
const span = valueSpan(source, credentials);
|
|
372
|
+
if (source[span.start] !== '[') {
|
|
373
|
+
return fail('`activation.credentials` is not an array literal. Move it by hand.');
|
|
374
|
+
}
|
|
375
|
+
const array = { start: span.start, end: matchClose(source, span.start) };
|
|
376
|
+
for (const element of elementsOf(source, array)) {
|
|
377
|
+
if (source[element.start] !== '{') {
|
|
378
|
+
return fail('an activation credential is not an object literal. Move it by hand.');
|
|
379
|
+
}
|
|
380
|
+
const first = propertiesOf(source, {
|
|
381
|
+
start: element.start,
|
|
382
|
+
end: matchClose(source, element.start),
|
|
383
|
+
})[0];
|
|
384
|
+
const indent = first
|
|
385
|
+
? indentAt(source, first.keyStart)
|
|
386
|
+
: `${indentAt(source, element.start)} `;
|
|
387
|
+
const text = source.slice(element.start, element.end);
|
|
388
|
+
built.entries.push({
|
|
389
|
+
text: text.includes('\n')
|
|
390
|
+
? `{\n${indent}kind: 'activation',${text.slice(1).replace(/^\s*/, `\n${indent}`)}`
|
|
391
|
+
: `{ kind: 'activation', ${text.slice(1).trimStart()}`,
|
|
392
|
+
indent: indentAt(source, element.start),
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
const ungrouped = (_a = options.ungroupedSecretFields) !== null && _a !== void 0 ? _a : [];
|
|
397
|
+
if (ungrouped.length > 0) {
|
|
398
|
+
const level = (_b = levelOf(options, 'activation', 'activation')) !== null && _b !== void 0 ? _b : 'team';
|
|
399
|
+
const label = ungrouped.length === 1 && ungrouped[0].label
|
|
400
|
+
? ungrouped[0].label
|
|
401
|
+
: 'Connect form';
|
|
402
|
+
built.entries.push({
|
|
403
|
+
text: `{ kind: 'activation', id: 'activation', label: ${quote(label)}, level: ${quote(level)}, fields: [${ungrouped.map((field) => quote(field.name)).join(', ')}] }`,
|
|
404
|
+
indent: '',
|
|
405
|
+
});
|
|
406
|
+
built.notes.push(`Grouped the secret fields ${ungrouped.map((field) => field.name).join(', ')} into the activation credential "activation".`);
|
|
407
|
+
}
|
|
408
|
+
if (built.fields && built.entries.length === 0) {
|
|
409
|
+
built.notes.push('Moved activation.fields into connection.fields.');
|
|
410
|
+
}
|
|
411
|
+
return { ok: true, value: null };
|
|
412
|
+
}
|
|
413
|
+
export function migrateConnectionSource(source, options) {
|
|
414
|
+
const definition = definitionObject(source);
|
|
415
|
+
if (!definition)
|
|
416
|
+
return { ok: false, reason: NO_DEFINITION };
|
|
417
|
+
const top = propertiesOf(source, definition);
|
|
418
|
+
const notes = [];
|
|
419
|
+
const edits = [];
|
|
420
|
+
const built = {
|
|
421
|
+
entries: [],
|
|
422
|
+
fields: null,
|
|
423
|
+
cuts: [],
|
|
424
|
+
related: [],
|
|
425
|
+
notes,
|
|
426
|
+
};
|
|
427
|
+
const proposes = top.find((p) => p.key === 'proposes');
|
|
428
|
+
if (proposes) {
|
|
429
|
+
const object = objectValue(source, proposes);
|
|
430
|
+
if (!object) {
|
|
431
|
+
return {
|
|
432
|
+
ok: false,
|
|
433
|
+
reason: '`proposes` is not an object literal in the entry file. Remove its scope by hand.',
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
const inner = propertiesOf(source, object);
|
|
437
|
+
const scope = inner.find((p) => p.key === 'scope');
|
|
438
|
+
if (scope) {
|
|
439
|
+
notes.push('Removed proposes.scope.');
|
|
440
|
+
edits.push({
|
|
441
|
+
span: cutSpan(source, inner.length === 1 ? proposes : scope),
|
|
442
|
+
text: '',
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
const oauth = top.find((p) => p.key === 'oauth');
|
|
447
|
+
if (oauth) {
|
|
448
|
+
const result = oauthEntry(source, oauth, 'default', options, built);
|
|
449
|
+
if (!result.ok)
|
|
450
|
+
return result;
|
|
451
|
+
built.cuts.push(oauth);
|
|
452
|
+
}
|
|
453
|
+
const named = top.find((p) => p.key === 'oauthConnections');
|
|
454
|
+
if (named) {
|
|
455
|
+
const object = objectValue(source, named);
|
|
456
|
+
if (!object) {
|
|
457
|
+
return {
|
|
458
|
+
ok: false,
|
|
459
|
+
reason: '`oauthConnections` is not an object literal. Move it by hand.',
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
for (const property of propertiesOf(source, object)) {
|
|
463
|
+
const id = property.key.startsWith('[')
|
|
464
|
+
? constantValue(source, property.key.slice(1, -1), options)
|
|
465
|
+
: property.key;
|
|
466
|
+
if (!id) {
|
|
467
|
+
return {
|
|
468
|
+
ok: false,
|
|
469
|
+
reason: `an \`oauthConnections\` entry has a key ekanos migrate cannot read (${property.key || source.slice(property.keyStart, property.end).trim().slice(0, 40)}). Move it into connection.credentials by hand.`,
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
const result = oauthEntry(source, property, id, options, built);
|
|
473
|
+
if (!result.ok)
|
|
474
|
+
return result;
|
|
475
|
+
}
|
|
476
|
+
built.cuts.push(named);
|
|
477
|
+
}
|
|
478
|
+
const activation = top.find((p) => p.key === 'activation');
|
|
479
|
+
if (activation) {
|
|
480
|
+
const result = activationEntries(source, activation, options, built);
|
|
481
|
+
if (!result.ok)
|
|
482
|
+
return result;
|
|
483
|
+
built.cuts.push(activation);
|
|
484
|
+
}
|
|
485
|
+
for (const cut of built.cuts) {
|
|
486
|
+
edits.push({ span: cutSpan(source, cut), text: '' });
|
|
487
|
+
}
|
|
488
|
+
const connection = top.find((p) => p.key === 'connection');
|
|
489
|
+
const kept = [];
|
|
490
|
+
let hadLevels = false;
|
|
491
|
+
if (connection) {
|
|
492
|
+
const object = objectValue(source, connection);
|
|
493
|
+
if (!object) {
|
|
494
|
+
return {
|
|
495
|
+
ok: false,
|
|
496
|
+
reason: '`connection` is not an object literal in the entry file. Move its credentials in by hand.',
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
for (const property of propertiesOf(source, object)) {
|
|
500
|
+
if (property.key === '') {
|
|
501
|
+
return {
|
|
502
|
+
ok: false,
|
|
503
|
+
reason: '`connection` holds an entry ekanos migrate cannot read. Move its credentials in by hand.',
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
if (property.key === 'levels') {
|
|
507
|
+
hadLevels = true;
|
|
508
|
+
continue;
|
|
509
|
+
}
|
|
510
|
+
if (property.key === 'credentials' || property.key === 'fields') {
|
|
511
|
+
return { ok: true, source, changed: false, notes: [], related: [] };
|
|
512
|
+
}
|
|
513
|
+
kept.push(source.slice(property.keyStart, valueSpan(source, property).end));
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (hadLevels)
|
|
517
|
+
notes.push('Removed connection.levels.');
|
|
518
|
+
const anchor = connection !== null && connection !== void 0 ? connection : top.at(-1);
|
|
519
|
+
const base = anchor ? indentAt(source, anchor.keyStart) : ' ';
|
|
520
|
+
const pad = `${base} `;
|
|
521
|
+
const lines = [...kept.map((text) => `${pad}${text},`)];
|
|
522
|
+
if (built.fields) {
|
|
523
|
+
lines.push(`${pad}fields: ${reindent(built.fields.text, pad.length - built.fields.indent.length)},`);
|
|
524
|
+
}
|
|
525
|
+
if (built.entries.length > 0) {
|
|
526
|
+
const elementPad = `${pad} `;
|
|
527
|
+
lines.push(`${pad}credentials: [`);
|
|
528
|
+
for (const entry of built.entries) {
|
|
529
|
+
const delta = entry.indent ? elementPad.length - entry.indent.length : 0;
|
|
530
|
+
lines.push(`${elementPad}${reindent(entry.text, delta)},`);
|
|
531
|
+
}
|
|
532
|
+
lines.push(`${pad}],`);
|
|
533
|
+
notes.push(`Moved ${built.entries.length} ${built.entries.length === 1 ? 'credential' : 'credentials'} into connection.credentials.`);
|
|
534
|
+
}
|
|
535
|
+
const block = lines.length > 0 ? `connection: {\n${lines.join('\n')}\n${base}}` : null;
|
|
536
|
+
if (connection) {
|
|
537
|
+
if (block) {
|
|
538
|
+
edits.push({
|
|
539
|
+
span: { start: connection.keyStart, end: connection.end },
|
|
540
|
+
text: block,
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
else {
|
|
544
|
+
edits.push({ span: cutSpan(source, connection), text: '' });
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
else if (block) {
|
|
548
|
+
const closeLine = source.lastIndexOf('\n', definition.end - 1) + 1;
|
|
549
|
+
const before = source.slice(0, closeLine).replace(/\s*$/, '');
|
|
550
|
+
const comma = before.endsWith(',') || before.endsWith('{') ? '' : ',';
|
|
551
|
+
edits.push({
|
|
552
|
+
span: { start: before.length, end: before.length },
|
|
553
|
+
text: comma,
|
|
554
|
+
});
|
|
555
|
+
edits.push({
|
|
556
|
+
span: { start: closeLine, end: closeLine },
|
|
557
|
+
text: `${base}${block},\n`,
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
const next = applyEdits(source, edits);
|
|
561
|
+
return {
|
|
562
|
+
ok: true,
|
|
563
|
+
source: next,
|
|
564
|
+
changed: next !== source || built.related.length > 0,
|
|
565
|
+
notes,
|
|
566
|
+
related: built.related,
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
//# sourceMappingURL=migrate-connection.js.map
|