@scarn/sdk 0.8.20 → 0.8.21
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/auth/api-token-cache.d.ts +24 -0
- package/dist/auth/api-token-source.d.ts +39 -0
- package/dist/auth/authenticated-fetch.d.ts +10 -0
- package/dist/auth/index.d.ts +3 -0
- package/dist/auth/index.js +20 -0
- package/dist/automations/index.js +4 -4
- package/dist/{chunk-pqtd0hr7.js → chunk-08gcnrzh.js} +2 -2
- package/dist/{chunk-g4j5cfpc.js → chunk-0he2dx5n.js} +5 -5
- package/dist/{chunk-z4smq8qd.js → chunk-59arcerk.js} +1 -1
- package/dist/{chunk-46wmsgv7.js → chunk-5say64w8.js} +1 -1
- package/dist/{chunk-habmdf89.js → chunk-6p340dd4.js} +1 -1
- package/dist/{chunk-19brnwkp.js → chunk-8hsk6f6b.js} +1 -1
- package/dist/{chunk-098740f7.js → chunk-8kzaxz52.js} +1 -1
- package/dist/{chunk-n3ywwx7n.js → chunk-8tmsvkmj.js} +5 -5
- package/dist/{chunk-e0pt5x0e.js → chunk-aph2js2v.js} +5 -5
- package/dist/chunk-azss2d1n.js +1036 -0
- package/dist/{chunk-t1dq2c2s.js → chunk-gasw078g.js} +5 -5
- package/dist/{chunk-0c60x3v8.js → chunk-h1v6w1fh.js} +5 -5
- package/dist/{chunk-tr3v83cn.js → chunk-k57h6qke.js} +8 -5
- package/dist/{chunk-aemxz9r7.js → chunk-mrzn5tq4.js} +1 -1
- package/dist/{chunk-qgkx89eg.js → chunk-nkm31g10.js} +3 -3
- package/dist/{chunk-yq0sf8sb.js → chunk-p74r4y6j.js} +13 -13
- package/dist/{chunk-a56zc4s5.js → chunk-pwyj6qf3.js} +2 -2
- package/dist/{chunk-b9ja6ss5.js → chunk-qt81x1pm.js} +1 -1
- package/dist/{chunk-mzj1j0p5.js → chunk-r3sbp2wn.js} +3 -3
- package/dist/{chunk-rphfy0fj.js → chunk-vsp708vw.js} +1 -1
- package/dist/{chunk-yf15kdte.js → chunk-xhpp6qz8.js} +96 -96
- package/dist/{chunk-y34zsgsw.js → chunk-y7ac1t9c.js} +1 -1
- package/dist/{chunk-rq5k7m33.js → chunk-y81cr6tp.js} +28 -14
- package/dist/{chunk-91f5gm5z.js → chunk-zxzvketc.js} +5 -5
- package/dist/client.d.ts +5 -1
- package/dist/client.js +2 -2
- package/dist/connectors/index.js +4 -4
- package/dist/contracts/artifacts.js +2 -2
- package/dist/contracts/automation-document/index.js +3 -3
- package/dist/contracts/pipeline-document/index.js +2 -2
- package/dist/contracts/step-artifact-submissions.js +2 -2
- package/dist/contracts/work-item-changes.js +1 -1
- package/dist/create-api-client.d.ts +11 -0
- package/dist/defaults/index.js +32 -871
- package/dist/defaults/load-push-defaults.d.ts +11 -4
- package/dist/defaults/project-ref.d.ts +2 -4
- package/dist/definitions/automations/automations-client.d.ts +2 -1
- package/dist/definitions/automations/index.js +3 -3
- package/dist/definitions/environments/environments-client.d.ts +2 -1
- package/dist/definitions/environments/index.js +10 -10
- package/dist/definitions/pipelines/index.js +3 -3
- package/dist/definitions/pipelines/pipeline-definitions-client.d.ts +2 -1
- package/dist/definitions/steps/index.js +13 -13
- package/dist/definitions/steps/step-definitions-client.d.ts +2 -1
- package/dist/definitions/validation/index.js +10 -10
- package/dist/devcontainer-config-path.js +2 -2
- package/dist/env-vars.js +2 -2
- package/dist/environment.js +7 -7
- package/dist/health-checks.js +2 -2
- package/dist/index.js +20 -20
- package/dist/managed-runtimes.js +2 -2
- package/dist/opencode-mcp.js +3 -3
- package/dist/pipelines/index.js +3 -3
- package/dist/push/index.js +42 -41
- package/dist/push/push-from-directory.d.ts +6 -1
- package/dist/repo-config.js +2 -2
- package/dist/resolve-environment.js +8 -8
- package/dist/task-plane-client.d.ts +6 -0
- package/package.json +6 -2
|
@@ -0,0 +1,1036 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/auth/api-token-cache.ts
|
|
3
|
+
import { existsSync as existsSync2, lstatSync, readFileSync } from "fs";
|
|
4
|
+
import { join } from "path";
|
|
5
|
+
|
|
6
|
+
// ../../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
7
|
+
function createScanner(text, ignoreTrivia = false) {
|
|
8
|
+
const len = text.length;
|
|
9
|
+
let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
10
|
+
function scanHexDigits(count, exact) {
|
|
11
|
+
let digits = 0;
|
|
12
|
+
let value2 = 0;
|
|
13
|
+
while (digits < count || !exact) {
|
|
14
|
+
let ch = text.charCodeAt(pos);
|
|
15
|
+
if (ch >= 48 && ch <= 57) {
|
|
16
|
+
value2 = value2 * 16 + ch - 48;
|
|
17
|
+
} else if (ch >= 65 && ch <= 70) {
|
|
18
|
+
value2 = value2 * 16 + ch - 65 + 10;
|
|
19
|
+
} else if (ch >= 97 && ch <= 102) {
|
|
20
|
+
value2 = value2 * 16 + ch - 97 + 10;
|
|
21
|
+
} else {
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
pos++;
|
|
25
|
+
digits++;
|
|
26
|
+
}
|
|
27
|
+
if (digits < count) {
|
|
28
|
+
value2 = -1;
|
|
29
|
+
}
|
|
30
|
+
return value2;
|
|
31
|
+
}
|
|
32
|
+
function setPosition(newPosition) {
|
|
33
|
+
pos = newPosition;
|
|
34
|
+
value = "";
|
|
35
|
+
tokenOffset = 0;
|
|
36
|
+
token = 16;
|
|
37
|
+
scanError = 0;
|
|
38
|
+
}
|
|
39
|
+
function scanNumber() {
|
|
40
|
+
let start = pos;
|
|
41
|
+
if (text.charCodeAt(pos) === 48) {
|
|
42
|
+
pos++;
|
|
43
|
+
} else {
|
|
44
|
+
pos++;
|
|
45
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
46
|
+
pos++;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (pos < text.length && text.charCodeAt(pos) === 46) {
|
|
50
|
+
pos++;
|
|
51
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
52
|
+
pos++;
|
|
53
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
54
|
+
pos++;
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
scanError = 3;
|
|
58
|
+
return text.substring(start, pos);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
let end = pos;
|
|
62
|
+
if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
|
|
63
|
+
pos++;
|
|
64
|
+
if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
|
|
65
|
+
pos++;
|
|
66
|
+
}
|
|
67
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
68
|
+
pos++;
|
|
69
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
70
|
+
pos++;
|
|
71
|
+
}
|
|
72
|
+
end = pos;
|
|
73
|
+
} else {
|
|
74
|
+
scanError = 3;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return text.substring(start, end);
|
|
78
|
+
}
|
|
79
|
+
function scanString() {
|
|
80
|
+
let result = "", start = pos;
|
|
81
|
+
while (true) {
|
|
82
|
+
if (pos >= len) {
|
|
83
|
+
result += text.substring(start, pos);
|
|
84
|
+
scanError = 2;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
const ch = text.charCodeAt(pos);
|
|
88
|
+
if (ch === 34) {
|
|
89
|
+
result += text.substring(start, pos);
|
|
90
|
+
pos++;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
if (ch === 92) {
|
|
94
|
+
result += text.substring(start, pos);
|
|
95
|
+
pos++;
|
|
96
|
+
if (pos >= len) {
|
|
97
|
+
scanError = 2;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
const ch2 = text.charCodeAt(pos++);
|
|
101
|
+
switch (ch2) {
|
|
102
|
+
case 34:
|
|
103
|
+
result += '"';
|
|
104
|
+
break;
|
|
105
|
+
case 92:
|
|
106
|
+
result += "\\";
|
|
107
|
+
break;
|
|
108
|
+
case 47:
|
|
109
|
+
result += "/";
|
|
110
|
+
break;
|
|
111
|
+
case 98:
|
|
112
|
+
result += "\b";
|
|
113
|
+
break;
|
|
114
|
+
case 102:
|
|
115
|
+
result += "\f";
|
|
116
|
+
break;
|
|
117
|
+
case 110:
|
|
118
|
+
result += `
|
|
119
|
+
`;
|
|
120
|
+
break;
|
|
121
|
+
case 114:
|
|
122
|
+
result += "\r";
|
|
123
|
+
break;
|
|
124
|
+
case 116:
|
|
125
|
+
result += "\t";
|
|
126
|
+
break;
|
|
127
|
+
case 117:
|
|
128
|
+
const ch3 = scanHexDigits(4, true);
|
|
129
|
+
if (ch3 >= 0) {
|
|
130
|
+
result += String.fromCharCode(ch3);
|
|
131
|
+
} else {
|
|
132
|
+
scanError = 4;
|
|
133
|
+
}
|
|
134
|
+
break;
|
|
135
|
+
default:
|
|
136
|
+
scanError = 5;
|
|
137
|
+
}
|
|
138
|
+
start = pos;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (ch >= 0 && ch <= 31) {
|
|
142
|
+
if (isLineBreak(ch)) {
|
|
143
|
+
result += text.substring(start, pos);
|
|
144
|
+
scanError = 2;
|
|
145
|
+
break;
|
|
146
|
+
} else {
|
|
147
|
+
scanError = 6;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
pos++;
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
function scanNext() {
|
|
155
|
+
value = "";
|
|
156
|
+
scanError = 0;
|
|
157
|
+
tokenOffset = pos;
|
|
158
|
+
lineStartOffset = lineNumber;
|
|
159
|
+
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
160
|
+
if (pos >= len) {
|
|
161
|
+
tokenOffset = len;
|
|
162
|
+
return token = 17;
|
|
163
|
+
}
|
|
164
|
+
let code = text.charCodeAt(pos);
|
|
165
|
+
if (isWhiteSpace(code)) {
|
|
166
|
+
do {
|
|
167
|
+
pos++;
|
|
168
|
+
value += String.fromCharCode(code);
|
|
169
|
+
code = text.charCodeAt(pos);
|
|
170
|
+
} while (isWhiteSpace(code));
|
|
171
|
+
return token = 15;
|
|
172
|
+
}
|
|
173
|
+
if (isLineBreak(code)) {
|
|
174
|
+
pos++;
|
|
175
|
+
value += String.fromCharCode(code);
|
|
176
|
+
if (code === 13 && text.charCodeAt(pos) === 10) {
|
|
177
|
+
pos++;
|
|
178
|
+
value += `
|
|
179
|
+
`;
|
|
180
|
+
}
|
|
181
|
+
lineNumber++;
|
|
182
|
+
tokenLineStartOffset = pos;
|
|
183
|
+
return token = 14;
|
|
184
|
+
}
|
|
185
|
+
switch (code) {
|
|
186
|
+
case 123:
|
|
187
|
+
pos++;
|
|
188
|
+
return token = 1;
|
|
189
|
+
case 125:
|
|
190
|
+
pos++;
|
|
191
|
+
return token = 2;
|
|
192
|
+
case 91:
|
|
193
|
+
pos++;
|
|
194
|
+
return token = 3;
|
|
195
|
+
case 93:
|
|
196
|
+
pos++;
|
|
197
|
+
return token = 4;
|
|
198
|
+
case 58:
|
|
199
|
+
pos++;
|
|
200
|
+
return token = 6;
|
|
201
|
+
case 44:
|
|
202
|
+
pos++;
|
|
203
|
+
return token = 5;
|
|
204
|
+
case 34:
|
|
205
|
+
pos++;
|
|
206
|
+
value = scanString();
|
|
207
|
+
return token = 10;
|
|
208
|
+
case 47:
|
|
209
|
+
const start = pos - 1;
|
|
210
|
+
if (text.charCodeAt(pos + 1) === 47) {
|
|
211
|
+
pos += 2;
|
|
212
|
+
while (pos < len) {
|
|
213
|
+
if (isLineBreak(text.charCodeAt(pos))) {
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
pos++;
|
|
217
|
+
}
|
|
218
|
+
value = text.substring(start, pos);
|
|
219
|
+
return token = 12;
|
|
220
|
+
}
|
|
221
|
+
if (text.charCodeAt(pos + 1) === 42) {
|
|
222
|
+
pos += 2;
|
|
223
|
+
const safeLength = len - 1;
|
|
224
|
+
let commentClosed = false;
|
|
225
|
+
while (pos < safeLength) {
|
|
226
|
+
const ch = text.charCodeAt(pos);
|
|
227
|
+
if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
|
|
228
|
+
pos += 2;
|
|
229
|
+
commentClosed = true;
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
pos++;
|
|
233
|
+
if (isLineBreak(ch)) {
|
|
234
|
+
if (ch === 13 && text.charCodeAt(pos) === 10) {
|
|
235
|
+
pos++;
|
|
236
|
+
}
|
|
237
|
+
lineNumber++;
|
|
238
|
+
tokenLineStartOffset = pos;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (!commentClosed) {
|
|
242
|
+
pos++;
|
|
243
|
+
scanError = 1;
|
|
244
|
+
}
|
|
245
|
+
value = text.substring(start, pos);
|
|
246
|
+
return token = 13;
|
|
247
|
+
}
|
|
248
|
+
value += String.fromCharCode(code);
|
|
249
|
+
pos++;
|
|
250
|
+
return token = 16;
|
|
251
|
+
case 45:
|
|
252
|
+
value += String.fromCharCode(code);
|
|
253
|
+
pos++;
|
|
254
|
+
if (pos === len || !isDigit(text.charCodeAt(pos))) {
|
|
255
|
+
return token = 16;
|
|
256
|
+
}
|
|
257
|
+
case 48:
|
|
258
|
+
case 49:
|
|
259
|
+
case 50:
|
|
260
|
+
case 51:
|
|
261
|
+
case 52:
|
|
262
|
+
case 53:
|
|
263
|
+
case 54:
|
|
264
|
+
case 55:
|
|
265
|
+
case 56:
|
|
266
|
+
case 57:
|
|
267
|
+
value += scanNumber();
|
|
268
|
+
return token = 11;
|
|
269
|
+
default:
|
|
270
|
+
while (pos < len && isUnknownContentCharacter(code)) {
|
|
271
|
+
pos++;
|
|
272
|
+
code = text.charCodeAt(pos);
|
|
273
|
+
}
|
|
274
|
+
if (tokenOffset !== pos) {
|
|
275
|
+
value = text.substring(tokenOffset, pos);
|
|
276
|
+
switch (value) {
|
|
277
|
+
case "true":
|
|
278
|
+
return token = 8;
|
|
279
|
+
case "false":
|
|
280
|
+
return token = 9;
|
|
281
|
+
case "null":
|
|
282
|
+
return token = 7;
|
|
283
|
+
}
|
|
284
|
+
return token = 16;
|
|
285
|
+
}
|
|
286
|
+
value += String.fromCharCode(code);
|
|
287
|
+
pos++;
|
|
288
|
+
return token = 16;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function isUnknownContentCharacter(code) {
|
|
292
|
+
if (isWhiteSpace(code) || isLineBreak(code)) {
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
switch (code) {
|
|
296
|
+
case 125:
|
|
297
|
+
case 93:
|
|
298
|
+
case 123:
|
|
299
|
+
case 91:
|
|
300
|
+
case 34:
|
|
301
|
+
case 58:
|
|
302
|
+
case 44:
|
|
303
|
+
case 47:
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
function scanNextNonTrivia() {
|
|
309
|
+
let result;
|
|
310
|
+
do {
|
|
311
|
+
result = scanNext();
|
|
312
|
+
} while (result >= 12 && result <= 15);
|
|
313
|
+
return result;
|
|
314
|
+
}
|
|
315
|
+
return {
|
|
316
|
+
setPosition,
|
|
317
|
+
getPosition: () => pos,
|
|
318
|
+
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
319
|
+
getToken: () => token,
|
|
320
|
+
getTokenValue: () => value,
|
|
321
|
+
getTokenOffset: () => tokenOffset,
|
|
322
|
+
getTokenLength: () => pos - tokenOffset,
|
|
323
|
+
getTokenStartLine: () => lineStartOffset,
|
|
324
|
+
getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
|
|
325
|
+
getTokenError: () => scanError
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function isWhiteSpace(ch) {
|
|
329
|
+
return ch === 32 || ch === 9;
|
|
330
|
+
}
|
|
331
|
+
function isLineBreak(ch) {
|
|
332
|
+
return ch === 10 || ch === 13;
|
|
333
|
+
}
|
|
334
|
+
function isDigit(ch) {
|
|
335
|
+
return ch >= 48 && ch <= 57;
|
|
336
|
+
}
|
|
337
|
+
var CharacterCodes;
|
|
338
|
+
(function(CharacterCodes2) {
|
|
339
|
+
CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
|
|
340
|
+
CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
|
|
341
|
+
CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
|
|
342
|
+
CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
|
|
343
|
+
CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
|
|
344
|
+
CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
|
|
345
|
+
CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
|
|
346
|
+
CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
|
|
347
|
+
CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
|
|
348
|
+
CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
|
|
349
|
+
CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
|
|
350
|
+
CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
|
|
351
|
+
CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
|
|
352
|
+
CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
|
|
353
|
+
CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
|
|
354
|
+
CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
|
|
355
|
+
CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
|
|
356
|
+
CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
|
|
357
|
+
CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
|
|
358
|
+
CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
|
|
359
|
+
CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
|
|
360
|
+
CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
|
|
361
|
+
CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
|
|
362
|
+
CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
|
|
363
|
+
CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
|
|
364
|
+
CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
|
|
365
|
+
CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
|
|
366
|
+
CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
|
|
367
|
+
CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
|
|
368
|
+
CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
|
|
369
|
+
CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
|
|
370
|
+
CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
|
|
371
|
+
CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
|
|
372
|
+
CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
|
|
373
|
+
CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
|
|
374
|
+
CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
|
|
375
|
+
CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
|
|
376
|
+
CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
|
|
377
|
+
CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
|
|
378
|
+
CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
|
|
379
|
+
CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
|
|
380
|
+
CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
|
|
381
|
+
CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
|
|
382
|
+
CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
|
|
383
|
+
CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
|
|
384
|
+
CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
|
|
385
|
+
CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
|
|
386
|
+
CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
|
|
387
|
+
CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
|
|
388
|
+
CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
|
|
389
|
+
CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
|
|
390
|
+
CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
|
|
391
|
+
CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
|
|
392
|
+
CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
|
|
393
|
+
CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
|
|
394
|
+
CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
|
|
395
|
+
CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
|
|
396
|
+
CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
|
|
397
|
+
CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
|
|
398
|
+
CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
|
|
399
|
+
CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
|
|
400
|
+
CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
|
|
401
|
+
CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
|
|
402
|
+
CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
|
|
403
|
+
CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
|
|
404
|
+
CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
|
|
405
|
+
CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
|
|
406
|
+
CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
|
|
407
|
+
CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
|
|
408
|
+
CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
|
|
409
|
+
CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
|
|
410
|
+
CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
|
|
411
|
+
CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
|
|
412
|
+
CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
|
|
413
|
+
CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
|
|
414
|
+
CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
|
|
415
|
+
CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
|
|
416
|
+
CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
|
|
417
|
+
CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
|
|
418
|
+
CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
|
|
419
|
+
})(CharacterCodes || (CharacterCodes = {}));
|
|
420
|
+
|
|
421
|
+
// ../../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/string-intern.js
|
|
422
|
+
var cachedSpaces = new Array(20).fill(0).map((_, index) => {
|
|
423
|
+
return " ".repeat(index);
|
|
424
|
+
});
|
|
425
|
+
var maxCachedValues = 200;
|
|
426
|
+
var cachedBreakLinesWithSpaces = {
|
|
427
|
+
" ": {
|
|
428
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
429
|
+
return `
|
|
430
|
+
` + " ".repeat(index);
|
|
431
|
+
}),
|
|
432
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
433
|
+
return "\r" + " ".repeat(index);
|
|
434
|
+
}),
|
|
435
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
436
|
+
return `\r
|
|
437
|
+
` + " ".repeat(index);
|
|
438
|
+
})
|
|
439
|
+
},
|
|
440
|
+
"\t": {
|
|
441
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
442
|
+
return `
|
|
443
|
+
` + "\t".repeat(index);
|
|
444
|
+
}),
|
|
445
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
446
|
+
return "\r" + "\t".repeat(index);
|
|
447
|
+
}),
|
|
448
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
449
|
+
return `\r
|
|
450
|
+
` + "\t".repeat(index);
|
|
451
|
+
})
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
// ../../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/parser.js
|
|
456
|
+
var ParseOptions;
|
|
457
|
+
(function(ParseOptions2) {
|
|
458
|
+
ParseOptions2.DEFAULT = {
|
|
459
|
+
allowTrailingComma: false
|
|
460
|
+
};
|
|
461
|
+
})(ParseOptions || (ParseOptions = {}));
|
|
462
|
+
function parse(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
463
|
+
let currentProperty = null;
|
|
464
|
+
let currentParent = [];
|
|
465
|
+
const previousParents = [];
|
|
466
|
+
function onValue(value) {
|
|
467
|
+
if (Array.isArray(currentParent)) {
|
|
468
|
+
currentParent.push(value);
|
|
469
|
+
} else if (currentProperty !== null) {
|
|
470
|
+
currentParent[currentProperty] = value;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
const visitor = {
|
|
474
|
+
onObjectBegin: () => {
|
|
475
|
+
const object = {};
|
|
476
|
+
onValue(object);
|
|
477
|
+
previousParents.push(currentParent);
|
|
478
|
+
currentParent = object;
|
|
479
|
+
currentProperty = null;
|
|
480
|
+
},
|
|
481
|
+
onObjectProperty: (name) => {
|
|
482
|
+
currentProperty = name;
|
|
483
|
+
},
|
|
484
|
+
onObjectEnd: () => {
|
|
485
|
+
currentParent = previousParents.pop();
|
|
486
|
+
},
|
|
487
|
+
onArrayBegin: () => {
|
|
488
|
+
const array = [];
|
|
489
|
+
onValue(array);
|
|
490
|
+
previousParents.push(currentParent);
|
|
491
|
+
currentParent = array;
|
|
492
|
+
currentProperty = null;
|
|
493
|
+
},
|
|
494
|
+
onArrayEnd: () => {
|
|
495
|
+
currentParent = previousParents.pop();
|
|
496
|
+
},
|
|
497
|
+
onLiteralValue: onValue,
|
|
498
|
+
onError: (error, offset, length) => {
|
|
499
|
+
errors.push({ error, offset, length });
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
visit(text, visitor, options);
|
|
503
|
+
return currentParent[0];
|
|
504
|
+
}
|
|
505
|
+
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
506
|
+
const _scanner = createScanner(text, false);
|
|
507
|
+
const _jsonPath = [];
|
|
508
|
+
let suppressedCallbacks = 0;
|
|
509
|
+
function toNoArgVisit(visitFunction) {
|
|
510
|
+
return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
511
|
+
}
|
|
512
|
+
function toOneArgVisit(visitFunction) {
|
|
513
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
514
|
+
}
|
|
515
|
+
function toOneArgVisitWithPath(visitFunction) {
|
|
516
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
517
|
+
}
|
|
518
|
+
function toBeginVisit(visitFunction) {
|
|
519
|
+
return visitFunction ? () => {
|
|
520
|
+
if (suppressedCallbacks > 0) {
|
|
521
|
+
suppressedCallbacks++;
|
|
522
|
+
} else {
|
|
523
|
+
let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
|
|
524
|
+
if (cbReturn === false) {
|
|
525
|
+
suppressedCallbacks = 1;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
} : () => true;
|
|
529
|
+
}
|
|
530
|
+
function toEndVisit(visitFunction) {
|
|
531
|
+
return visitFunction ? () => {
|
|
532
|
+
if (suppressedCallbacks > 0) {
|
|
533
|
+
suppressedCallbacks--;
|
|
534
|
+
}
|
|
535
|
+
if (suppressedCallbacks === 0) {
|
|
536
|
+
visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
|
|
537
|
+
}
|
|
538
|
+
} : () => true;
|
|
539
|
+
}
|
|
540
|
+
const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
|
|
541
|
+
const disallowComments = options && options.disallowComments;
|
|
542
|
+
const allowTrailingComma = options && options.allowTrailingComma;
|
|
543
|
+
function scanNext() {
|
|
544
|
+
while (true) {
|
|
545
|
+
const token = _scanner.scan();
|
|
546
|
+
switch (_scanner.getTokenError()) {
|
|
547
|
+
case 4:
|
|
548
|
+
handleError(14);
|
|
549
|
+
break;
|
|
550
|
+
case 5:
|
|
551
|
+
handleError(15);
|
|
552
|
+
break;
|
|
553
|
+
case 3:
|
|
554
|
+
handleError(13);
|
|
555
|
+
break;
|
|
556
|
+
case 1:
|
|
557
|
+
if (!disallowComments) {
|
|
558
|
+
handleError(11);
|
|
559
|
+
}
|
|
560
|
+
break;
|
|
561
|
+
case 2:
|
|
562
|
+
handleError(12);
|
|
563
|
+
break;
|
|
564
|
+
case 6:
|
|
565
|
+
handleError(16);
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
568
|
+
switch (token) {
|
|
569
|
+
case 12:
|
|
570
|
+
case 13:
|
|
571
|
+
if (disallowComments) {
|
|
572
|
+
handleError(10);
|
|
573
|
+
} else {
|
|
574
|
+
onComment();
|
|
575
|
+
}
|
|
576
|
+
break;
|
|
577
|
+
case 16:
|
|
578
|
+
handleError(1);
|
|
579
|
+
break;
|
|
580
|
+
case 15:
|
|
581
|
+
case 14:
|
|
582
|
+
break;
|
|
583
|
+
default:
|
|
584
|
+
return token;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
function handleError(error, skipUntilAfter = [], skipUntil = []) {
|
|
589
|
+
onError(error);
|
|
590
|
+
if (skipUntilAfter.length + skipUntil.length > 0) {
|
|
591
|
+
let token = _scanner.getToken();
|
|
592
|
+
while (token !== 17) {
|
|
593
|
+
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
594
|
+
scanNext();
|
|
595
|
+
break;
|
|
596
|
+
} else if (skipUntil.indexOf(token) !== -1) {
|
|
597
|
+
break;
|
|
598
|
+
}
|
|
599
|
+
token = scanNext();
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
function parseString(isValue) {
|
|
604
|
+
const value = _scanner.getTokenValue();
|
|
605
|
+
if (isValue) {
|
|
606
|
+
onLiteralValue(value);
|
|
607
|
+
} else {
|
|
608
|
+
onObjectProperty(value);
|
|
609
|
+
_jsonPath.push(value);
|
|
610
|
+
}
|
|
611
|
+
scanNext();
|
|
612
|
+
return true;
|
|
613
|
+
}
|
|
614
|
+
function parseLiteral() {
|
|
615
|
+
switch (_scanner.getToken()) {
|
|
616
|
+
case 11:
|
|
617
|
+
const tokenValue = _scanner.getTokenValue();
|
|
618
|
+
let value = Number(tokenValue);
|
|
619
|
+
if (isNaN(value)) {
|
|
620
|
+
handleError(2);
|
|
621
|
+
value = 0;
|
|
622
|
+
}
|
|
623
|
+
onLiteralValue(value);
|
|
624
|
+
break;
|
|
625
|
+
case 7:
|
|
626
|
+
onLiteralValue(null);
|
|
627
|
+
break;
|
|
628
|
+
case 8:
|
|
629
|
+
onLiteralValue(true);
|
|
630
|
+
break;
|
|
631
|
+
case 9:
|
|
632
|
+
onLiteralValue(false);
|
|
633
|
+
break;
|
|
634
|
+
default:
|
|
635
|
+
return false;
|
|
636
|
+
}
|
|
637
|
+
scanNext();
|
|
638
|
+
return true;
|
|
639
|
+
}
|
|
640
|
+
function parseProperty() {
|
|
641
|
+
if (_scanner.getToken() !== 10) {
|
|
642
|
+
handleError(3, [], [2, 5]);
|
|
643
|
+
return false;
|
|
644
|
+
}
|
|
645
|
+
parseString(false);
|
|
646
|
+
if (_scanner.getToken() === 6) {
|
|
647
|
+
onSeparator(":");
|
|
648
|
+
scanNext();
|
|
649
|
+
if (!parseValue()) {
|
|
650
|
+
handleError(4, [], [2, 5]);
|
|
651
|
+
}
|
|
652
|
+
} else {
|
|
653
|
+
handleError(5, [], [2, 5]);
|
|
654
|
+
}
|
|
655
|
+
_jsonPath.pop();
|
|
656
|
+
return true;
|
|
657
|
+
}
|
|
658
|
+
function parseObject() {
|
|
659
|
+
onObjectBegin();
|
|
660
|
+
scanNext();
|
|
661
|
+
let needsComma = false;
|
|
662
|
+
while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
|
|
663
|
+
if (_scanner.getToken() === 5) {
|
|
664
|
+
if (!needsComma) {
|
|
665
|
+
handleError(4, [], []);
|
|
666
|
+
}
|
|
667
|
+
onSeparator(",");
|
|
668
|
+
scanNext();
|
|
669
|
+
if (_scanner.getToken() === 2 && allowTrailingComma) {
|
|
670
|
+
break;
|
|
671
|
+
}
|
|
672
|
+
} else if (needsComma) {
|
|
673
|
+
handleError(6, [], []);
|
|
674
|
+
}
|
|
675
|
+
if (!parseProperty()) {
|
|
676
|
+
handleError(4, [], [2, 5]);
|
|
677
|
+
}
|
|
678
|
+
needsComma = true;
|
|
679
|
+
}
|
|
680
|
+
onObjectEnd();
|
|
681
|
+
if (_scanner.getToken() !== 2) {
|
|
682
|
+
handleError(7, [2], []);
|
|
683
|
+
} else {
|
|
684
|
+
scanNext();
|
|
685
|
+
}
|
|
686
|
+
return true;
|
|
687
|
+
}
|
|
688
|
+
function parseArray() {
|
|
689
|
+
onArrayBegin();
|
|
690
|
+
scanNext();
|
|
691
|
+
let isFirstElement = true;
|
|
692
|
+
let needsComma = false;
|
|
693
|
+
while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
|
|
694
|
+
if (_scanner.getToken() === 5) {
|
|
695
|
+
if (!needsComma) {
|
|
696
|
+
handleError(4, [], []);
|
|
697
|
+
}
|
|
698
|
+
onSeparator(",");
|
|
699
|
+
scanNext();
|
|
700
|
+
if (_scanner.getToken() === 4 && allowTrailingComma) {
|
|
701
|
+
break;
|
|
702
|
+
}
|
|
703
|
+
} else if (needsComma) {
|
|
704
|
+
handleError(6, [], []);
|
|
705
|
+
}
|
|
706
|
+
if (isFirstElement) {
|
|
707
|
+
_jsonPath.push(0);
|
|
708
|
+
isFirstElement = false;
|
|
709
|
+
} else {
|
|
710
|
+
_jsonPath[_jsonPath.length - 1]++;
|
|
711
|
+
}
|
|
712
|
+
if (!parseValue()) {
|
|
713
|
+
handleError(4, [], [4, 5]);
|
|
714
|
+
}
|
|
715
|
+
needsComma = true;
|
|
716
|
+
}
|
|
717
|
+
onArrayEnd();
|
|
718
|
+
if (!isFirstElement) {
|
|
719
|
+
_jsonPath.pop();
|
|
720
|
+
}
|
|
721
|
+
if (_scanner.getToken() !== 4) {
|
|
722
|
+
handleError(8, [4], []);
|
|
723
|
+
} else {
|
|
724
|
+
scanNext();
|
|
725
|
+
}
|
|
726
|
+
return true;
|
|
727
|
+
}
|
|
728
|
+
function parseValue() {
|
|
729
|
+
switch (_scanner.getToken()) {
|
|
730
|
+
case 3:
|
|
731
|
+
return parseArray();
|
|
732
|
+
case 1:
|
|
733
|
+
return parseObject();
|
|
734
|
+
case 10:
|
|
735
|
+
return parseString(true);
|
|
736
|
+
default:
|
|
737
|
+
return parseLiteral();
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
scanNext();
|
|
741
|
+
if (_scanner.getToken() === 17) {
|
|
742
|
+
if (options.allowEmptyContent) {
|
|
743
|
+
return true;
|
|
744
|
+
}
|
|
745
|
+
handleError(4, [], []);
|
|
746
|
+
return false;
|
|
747
|
+
}
|
|
748
|
+
if (!parseValue()) {
|
|
749
|
+
handleError(4, [], []);
|
|
750
|
+
return false;
|
|
751
|
+
}
|
|
752
|
+
if (_scanner.getToken() !== 17) {
|
|
753
|
+
handleError(9, [], []);
|
|
754
|
+
}
|
|
755
|
+
return true;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// ../../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/main.js
|
|
759
|
+
var ScanError;
|
|
760
|
+
(function(ScanError2) {
|
|
761
|
+
ScanError2[ScanError2["None"] = 0] = "None";
|
|
762
|
+
ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
|
763
|
+
ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
|
764
|
+
ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
|
765
|
+
ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
|
|
766
|
+
ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
|
767
|
+
ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
|
|
768
|
+
})(ScanError || (ScanError = {}));
|
|
769
|
+
var SyntaxKind;
|
|
770
|
+
(function(SyntaxKind2) {
|
|
771
|
+
SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
|
|
772
|
+
SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
|
|
773
|
+
SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
|
|
774
|
+
SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
|
|
775
|
+
SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
|
|
776
|
+
SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
|
|
777
|
+
SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
|
|
778
|
+
SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
|
|
779
|
+
SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
|
|
780
|
+
SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
|
|
781
|
+
SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
|
|
782
|
+
SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
|
783
|
+
SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
|
784
|
+
SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
|
785
|
+
SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
|
|
786
|
+
SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
|
|
787
|
+
SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
|
|
788
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
789
|
+
var parse2 = parse;
|
|
790
|
+
var ParseErrorCode;
|
|
791
|
+
(function(ParseErrorCode2) {
|
|
792
|
+
ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
793
|
+
ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
|
794
|
+
ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
|
795
|
+
ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
|
|
796
|
+
ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
|
|
797
|
+
ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
|
|
798
|
+
ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
|
799
|
+
ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
|
800
|
+
ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
|
801
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
|
802
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
|
803
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
|
804
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
|
805
|
+
ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
|
|
806
|
+
ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
807
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
808
|
+
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
809
|
+
|
|
810
|
+
// src/defaults/atomic-json-file.ts
|
|
811
|
+
import {
|
|
812
|
+
chmodSync,
|
|
813
|
+
existsSync,
|
|
814
|
+
mkdirSync,
|
|
815
|
+
renameSync,
|
|
816
|
+
writeFileSync
|
|
817
|
+
} from "fs";
|
|
818
|
+
import { dirname } from "path";
|
|
819
|
+
var ensureFilePermissions = (filePath) => {
|
|
820
|
+
try {
|
|
821
|
+
chmodSync(filePath, 384);
|
|
822
|
+
} catch {}
|
|
823
|
+
};
|
|
824
|
+
function writeJsonFileAtomically(filePath, data) {
|
|
825
|
+
const parentDirectory = dirname(filePath);
|
|
826
|
+
if (!existsSync(parentDirectory)) {
|
|
827
|
+
mkdirSync(parentDirectory, { recursive: true });
|
|
828
|
+
}
|
|
829
|
+
const temporaryPath = `${filePath}.${String(process.pid)}.${String(Date.now())}.tmp`;
|
|
830
|
+
writeFileSync(temporaryPath, `${JSON.stringify(data, null, 2)}
|
|
831
|
+
`, {
|
|
832
|
+
encoding: "utf8",
|
|
833
|
+
mode: 384
|
|
834
|
+
});
|
|
835
|
+
ensureFilePermissions(temporaryPath);
|
|
836
|
+
renameSync(temporaryPath, filePath);
|
|
837
|
+
ensureFilePermissions(filePath);
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
// src/defaults/home-dir.ts
|
|
841
|
+
import { homedir } from "os";
|
|
842
|
+
var homeDirOverrideForTests;
|
|
843
|
+
function setHomeDirForTests(dir) {
|
|
844
|
+
homeDirOverrideForTests = dir;
|
|
845
|
+
}
|
|
846
|
+
function resolveHomeDir() {
|
|
847
|
+
return homeDirOverrideForTests ?? homedir();
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
// src/auth/api-token-cache.ts
|
|
851
|
+
var apiTokenCacheFilePath = () => join(resolveHomeDir(), ".scarn", "api-tokens.jsonc");
|
|
852
|
+
var getApiTokenCacheFilePath = () => apiTokenCacheFilePath();
|
|
853
|
+
function isApiTokenCacheEntry(value) {
|
|
854
|
+
if (typeof value !== "object" || value === null)
|
|
855
|
+
return false;
|
|
856
|
+
const obj = value;
|
|
857
|
+
return typeof obj["sessionHash"] === "string" && typeof obj["token"] === "string" && typeof obj["expiresAt"] === "number";
|
|
858
|
+
}
|
|
859
|
+
var readCacheFile = () => {
|
|
860
|
+
const tokens = {};
|
|
861
|
+
try {
|
|
862
|
+
const filePath = apiTokenCacheFilePath();
|
|
863
|
+
if (!existsSync2(filePath) || !lstatSync(filePath).isFile()) {
|
|
864
|
+
return { tokens };
|
|
865
|
+
}
|
|
866
|
+
const errors = [];
|
|
867
|
+
const parsed = parse2(readFileSync(filePath, "utf8"), errors, {
|
|
868
|
+
allowTrailingComma: true
|
|
869
|
+
});
|
|
870
|
+
if (errors.length > 0 || typeof parsed !== "object" || parsed === null) {
|
|
871
|
+
return { tokens };
|
|
872
|
+
}
|
|
873
|
+
const rawTokens = parsed["tokens"];
|
|
874
|
+
if (typeof rawTokens !== "object" || rawTokens === null)
|
|
875
|
+
return { tokens };
|
|
876
|
+
for (const [baseUrl, entry] of Object.entries(rawTokens)) {
|
|
877
|
+
if (isApiTokenCacheEntry(entry))
|
|
878
|
+
tokens[baseUrl] = entry;
|
|
879
|
+
}
|
|
880
|
+
} catch {
|
|
881
|
+
return { tokens: {} };
|
|
882
|
+
}
|
|
883
|
+
return { tokens };
|
|
884
|
+
};
|
|
885
|
+
var loadApiTokenCacheEntry = (baseUrl) => readCacheFile().tokens[baseUrl] ?? null;
|
|
886
|
+
var saveApiTokenCacheEntry = (baseUrl, entry) => {
|
|
887
|
+
const file = readCacheFile();
|
|
888
|
+
file.tokens[baseUrl] = entry;
|
|
889
|
+
writeJsonFileAtomically(apiTokenCacheFilePath(), file);
|
|
890
|
+
};
|
|
891
|
+
var deleteApiTokenCacheEntry = (baseUrl, options) => {
|
|
892
|
+
const file = readCacheFile();
|
|
893
|
+
const entry = file.tokens[baseUrl];
|
|
894
|
+
if (!entry)
|
|
895
|
+
return;
|
|
896
|
+
if (options?.onlyToken !== undefined && entry.token !== options.onlyToken) {
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
writeJsonFileAtomically(apiTokenCacheFilePath(), {
|
|
900
|
+
tokens: Object.fromEntries(Object.entries(file.tokens).filter(([key]) => key !== baseUrl))
|
|
901
|
+
});
|
|
902
|
+
};
|
|
903
|
+
// src/auth/api-token-source.ts
|
|
904
|
+
import { createHash } from "crypto";
|
|
905
|
+
class ApiTokenAuthError extends Error {
|
|
906
|
+
baseUrl;
|
|
907
|
+
status;
|
|
908
|
+
constructor(message, baseUrl, status) {
|
|
909
|
+
super(message);
|
|
910
|
+
this.name = "ApiTokenAuthError";
|
|
911
|
+
this.baseUrl = baseUrl;
|
|
912
|
+
this.status = status;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
var MIN_REMAINING_MS = 60000;
|
|
916
|
+
var BEARER_PREFIX = "Bearer ";
|
|
917
|
+
var hashSessionToken = (sessionToken) => createHash("sha256").update(sessionToken).digest("hex");
|
|
918
|
+
var decodeJwtExpiry = (token) => {
|
|
919
|
+
const payload = token.split(".")[1];
|
|
920
|
+
if (!payload)
|
|
921
|
+
throw new Error("API token is not a JWT");
|
|
922
|
+
const claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
923
|
+
const exp = typeof claims === "object" && claims !== null ? claims["exp"] : undefined;
|
|
924
|
+
if (typeof exp !== "number")
|
|
925
|
+
throw new Error("API token has no exp claim");
|
|
926
|
+
return exp * 1000;
|
|
927
|
+
};
|
|
928
|
+
var readTokenFromResponse = async (response) => {
|
|
929
|
+
const body = await response.json();
|
|
930
|
+
const token = typeof body === "object" && body !== null ? body["token"] : undefined;
|
|
931
|
+
if (typeof token !== "string" || token.length === 0) {
|
|
932
|
+
throw new Error("API token response has no token");
|
|
933
|
+
}
|
|
934
|
+
return token;
|
|
935
|
+
};
|
|
936
|
+
function createApiTokenSource(options) {
|
|
937
|
+
const baseUrl = options.baseUrl;
|
|
938
|
+
const tokenUrl = `${baseUrl.replace(/\/+$/, "")}/api/auth/token`;
|
|
939
|
+
const fetchImpl = options.fetch ?? ((...args) => fetch(...args));
|
|
940
|
+
let sessionFallback = false;
|
|
941
|
+
let cached = null;
|
|
942
|
+
let inFlight = null;
|
|
943
|
+
const isUsable = (entry, sessionHash) => entry !== null && entry.sessionHash === sessionHash && entry.expiresAt - Date.now() > MIN_REMAINING_MS;
|
|
944
|
+
const jwtCredential = (token) => ({
|
|
945
|
+
authorization: `${BEARER_PREFIX}${token}`,
|
|
946
|
+
kind: "jwt"
|
|
947
|
+
});
|
|
948
|
+
const sessionCredential = (sessionToken) => ({
|
|
949
|
+
authorization: `${BEARER_PREFIX}${sessionToken}`,
|
|
950
|
+
kind: "session"
|
|
951
|
+
});
|
|
952
|
+
const mint = async (sessionToken, sessionHash) => {
|
|
953
|
+
const response = await fetchImpl(tokenUrl, {
|
|
954
|
+
method: "GET",
|
|
955
|
+
headers: { Authorization: `${BEARER_PREFIX}${sessionToken}` }
|
|
956
|
+
});
|
|
957
|
+
if (response.status === 404) {
|
|
958
|
+
sessionFallback = true;
|
|
959
|
+
return sessionCredential(sessionToken);
|
|
960
|
+
}
|
|
961
|
+
if (response.status === 401) {
|
|
962
|
+
throw new ApiTokenAuthError("The server rejected the session token while issuing an API token", baseUrl, 401);
|
|
963
|
+
}
|
|
964
|
+
if (!response.ok) {
|
|
965
|
+
throw new Error(`Failed to issue an API token: HTTP ${String(response.status)}`);
|
|
966
|
+
}
|
|
967
|
+
const token = await readTokenFromResponse(response);
|
|
968
|
+
const entry = {
|
|
969
|
+
sessionHash,
|
|
970
|
+
token,
|
|
971
|
+
expiresAt: decodeJwtExpiry(token)
|
|
972
|
+
};
|
|
973
|
+
cached = entry;
|
|
974
|
+
try {
|
|
975
|
+
saveApiTokenCacheEntry(baseUrl, entry);
|
|
976
|
+
} catch {}
|
|
977
|
+
return jwtCredential(token);
|
|
978
|
+
};
|
|
979
|
+
const getCredential = async () => {
|
|
980
|
+
const sessionToken = await options.getSessionToken();
|
|
981
|
+
if (!sessionToken) {
|
|
982
|
+
throw new ApiTokenAuthError("No session token: log in first", baseUrl);
|
|
983
|
+
}
|
|
984
|
+
if (sessionFallback)
|
|
985
|
+
return sessionCredential(sessionToken);
|
|
986
|
+
const sessionHash = hashSessionToken(sessionToken);
|
|
987
|
+
if (isUsable(cached, sessionHash))
|
|
988
|
+
return jwtCredential(cached.token);
|
|
989
|
+
const fromDisk = loadApiTokenCacheEntry(baseUrl);
|
|
990
|
+
if (isUsable(fromDisk, sessionHash)) {
|
|
991
|
+
cached = fromDisk;
|
|
992
|
+
return jwtCredential(fromDisk.token);
|
|
993
|
+
}
|
|
994
|
+
if (inFlight?.sessionHash === sessionHash)
|
|
995
|
+
return inFlight.promise;
|
|
996
|
+
const promise = mint(sessionToken, sessionHash).finally(() => {
|
|
997
|
+
if (inFlight?.promise === promise)
|
|
998
|
+
inFlight = null;
|
|
999
|
+
});
|
|
1000
|
+
inFlight = { sessionHash, promise };
|
|
1001
|
+
return promise;
|
|
1002
|
+
};
|
|
1003
|
+
const invalidate = (failedAuthorization) => {
|
|
1004
|
+
const failedToken = failedAuthorization === undefined ? cached?.token : failedAuthorization.startsWith(BEARER_PREFIX) ? failedAuthorization.slice(BEARER_PREFIX.length) : failedAuthorization;
|
|
1005
|
+
if (failedToken === undefined)
|
|
1006
|
+
return;
|
|
1007
|
+
if (cached?.token === failedToken)
|
|
1008
|
+
cached = null;
|
|
1009
|
+
try {
|
|
1010
|
+
deleteApiTokenCacheEntry(baseUrl, { onlyToken: failedToken });
|
|
1011
|
+
} catch {}
|
|
1012
|
+
};
|
|
1013
|
+
return {
|
|
1014
|
+
getAuthorization: async () => (await getCredential()).authorization,
|
|
1015
|
+
getCredential,
|
|
1016
|
+
invalidate
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
// src/auth/authenticated-fetch.ts
|
|
1020
|
+
function createAuthenticatedFetch(source, options) {
|
|
1021
|
+
const fetchImpl = options?.fetch ?? ((...args) => fetch(...args));
|
|
1022
|
+
return async (input, init) => {
|
|
1023
|
+
const request = new Request(input, init);
|
|
1024
|
+
const retryRequest = request.clone();
|
|
1025
|
+
const credential = await source.getCredential();
|
|
1026
|
+
request.headers.set("Authorization", credential.authorization);
|
|
1027
|
+
const response = await fetchImpl(request);
|
|
1028
|
+
if (response.status !== 401 || credential.kind !== "jwt")
|
|
1029
|
+
return response;
|
|
1030
|
+
source.invalidate(credential.authorization);
|
|
1031
|
+
const retryCredential = await source.getCredential();
|
|
1032
|
+
retryRequest.headers.set("Authorization", retryCredential.authorization);
|
|
1033
|
+
return fetchImpl(retryRequest);
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
export { parse2 as parse, writeJsonFileAtomically, setHomeDirForTests, resolveHomeDir, getApiTokenCacheFilePath, loadApiTokenCacheEntry, saveApiTokenCacheEntry, deleteApiTokenCacheEntry, ApiTokenAuthError, createApiTokenSource, createAuthenticatedFetch };
|