shield-llm 0.1.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.
@@ -0,0 +1,574 @@
1
+ import { createRequire as __cjs_createRequire } from "module"; import { fileURLToPath as __cjs_fileURLToPath } from "url"; import { dirname as __cjs_dirname } from "path"; const __filename = __cjs_fileURLToPath(import.meta.url); const __dirname = __cjs_dirname(__filename); const require = __cjs_createRequire(import.meta.url);
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
10
+ }) : x)(function(x) {
11
+ if (typeof require !== "undefined") return require.apply(this, arguments);
12
+ throw Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __commonJS = (cb, mod) => function __require2() {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ mod
32
+ ));
33
+
34
+ // ../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/token-error.js
35
+ var require_token_error = __commonJS({
36
+ "../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/token-error.js"(exports, module) {
37
+ "use strict";
38
+ var __defProp2 = Object.defineProperty;
39
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
40
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
41
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
42
+ var __export = (target, all) => {
43
+ for (var name in all)
44
+ __defProp2(target, name, { get: all[name], enumerable: true });
45
+ };
46
+ var __copyProps2 = (to, from, except, desc) => {
47
+ if (from && typeof from === "object" || typeof from === "function") {
48
+ for (let key of __getOwnPropNames2(from))
49
+ if (!__hasOwnProp2.call(to, key) && key !== except)
50
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
51
+ }
52
+ return to;
53
+ };
54
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
55
+ var token_error_exports = {};
56
+ __export(token_error_exports, {
57
+ VercelOidcTokenError: () => VercelOidcTokenError
58
+ });
59
+ module.exports = __toCommonJS(token_error_exports);
60
+ var VercelOidcTokenError = class extends Error {
61
+ constructor(message, cause) {
62
+ super(message);
63
+ this.name = "VercelOidcTokenError";
64
+ this.cause = cause;
65
+ }
66
+ toString() {
67
+ if (this.cause) {
68
+ return `${this.name}: ${this.message}: ${this.cause}`;
69
+ }
70
+ return `${this.name}: ${this.message}`;
71
+ }
72
+ };
73
+ }
74
+ });
75
+
76
+ // ../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/token-io.js
77
+ var require_token_io = __commonJS({
78
+ "../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/token-io.js"(exports, module) {
79
+ "use strict";
80
+ var __create2 = Object.create;
81
+ var __defProp2 = Object.defineProperty;
82
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
83
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
84
+ var __getProtoOf2 = Object.getPrototypeOf;
85
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
86
+ var __export = (target, all) => {
87
+ for (var name in all)
88
+ __defProp2(target, name, { get: all[name], enumerable: true });
89
+ };
90
+ var __copyProps2 = (to, from, except, desc) => {
91
+ if (from && typeof from === "object" || typeof from === "function") {
92
+ for (let key of __getOwnPropNames2(from))
93
+ if (!__hasOwnProp2.call(to, key) && key !== except)
94
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
95
+ }
96
+ return to;
97
+ };
98
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
99
+ // If the importer is in node compatibility mode or this is not an ESM
100
+ // file that has been converted to a CommonJS file using a Babel-
101
+ // compatible transform (i.e. "__esModule" has not been set), then set
102
+ // "default" to the CommonJS "module.exports" for node compatibility.
103
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
104
+ mod
105
+ ));
106
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
107
+ var token_io_exports = {};
108
+ __export(token_io_exports, {
109
+ findRootDir: () => findRootDir,
110
+ getUserDataDir: () => getUserDataDir
111
+ });
112
+ module.exports = __toCommonJS(token_io_exports);
113
+ var import_path = __toESM2(__require("path"));
114
+ var import_fs = __toESM2(__require("fs"));
115
+ var import_os = __toESM2(__require("os"));
116
+ var import_token_error = require_token_error();
117
+ function findRootDir() {
118
+ try {
119
+ let dir = process.cwd();
120
+ while (dir !== import_path.default.dirname(dir)) {
121
+ const pkgPath = import_path.default.join(dir, ".vercel");
122
+ if (import_fs.default.existsSync(pkgPath)) {
123
+ return dir;
124
+ }
125
+ dir = import_path.default.dirname(dir);
126
+ }
127
+ } catch (e) {
128
+ throw new import_token_error.VercelOidcTokenError(
129
+ "Token refresh only supported in node server environments"
130
+ );
131
+ }
132
+ return null;
133
+ }
134
+ function getUserDataDir() {
135
+ if (process.env.XDG_DATA_HOME) {
136
+ return process.env.XDG_DATA_HOME;
137
+ }
138
+ switch (import_os.default.platform()) {
139
+ case "darwin":
140
+ return import_path.default.join(import_os.default.homedir(), "Library/Application Support");
141
+ case "linux":
142
+ return import_path.default.join(import_os.default.homedir(), ".local/share");
143
+ case "win32":
144
+ if (process.env.LOCALAPPDATA) {
145
+ return process.env.LOCALAPPDATA;
146
+ }
147
+ return null;
148
+ default:
149
+ return null;
150
+ }
151
+ }
152
+ }
153
+ });
154
+
155
+ // ../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/auth-config.js
156
+ var require_auth_config = __commonJS({
157
+ "../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/auth-config.js"(exports, module) {
158
+ "use strict";
159
+ var __create2 = Object.create;
160
+ var __defProp2 = Object.defineProperty;
161
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
162
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
163
+ var __getProtoOf2 = Object.getPrototypeOf;
164
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
165
+ var __export = (target, all) => {
166
+ for (var name in all)
167
+ __defProp2(target, name, { get: all[name], enumerable: true });
168
+ };
169
+ var __copyProps2 = (to, from, except, desc) => {
170
+ if (from && typeof from === "object" || typeof from === "function") {
171
+ for (let key of __getOwnPropNames2(from))
172
+ if (!__hasOwnProp2.call(to, key) && key !== except)
173
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
174
+ }
175
+ return to;
176
+ };
177
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
178
+ // If the importer is in node compatibility mode or this is not an ESM
179
+ // file that has been converted to a CommonJS file using a Babel-
180
+ // compatible transform (i.e. "__esModule" has not been set), then set
181
+ // "default" to the CommonJS "module.exports" for node compatibility.
182
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
183
+ mod
184
+ ));
185
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
186
+ var auth_config_exports = {};
187
+ __export(auth_config_exports, {
188
+ isValidAccessToken: () => isValidAccessToken,
189
+ readAuthConfig: () => readAuthConfig,
190
+ writeAuthConfig: () => writeAuthConfig
191
+ });
192
+ module.exports = __toCommonJS(auth_config_exports);
193
+ var fs = __toESM2(__require("fs"));
194
+ var path = __toESM2(__require("path"));
195
+ var import_token_util = require_token_util();
196
+ function getAuthConfigPath() {
197
+ const dataDir = (0, import_token_util.getVercelDataDir)();
198
+ if (!dataDir) {
199
+ throw new Error(
200
+ `Unable to find Vercel CLI data directory. Your platform: ${process.platform}. Supported: darwin, linux, win32.`
201
+ );
202
+ }
203
+ return path.join(dataDir, "auth.json");
204
+ }
205
+ function readAuthConfig() {
206
+ try {
207
+ const authPath = getAuthConfigPath();
208
+ if (!fs.existsSync(authPath)) {
209
+ return null;
210
+ }
211
+ const content = fs.readFileSync(authPath, "utf8");
212
+ if (!content) {
213
+ return null;
214
+ }
215
+ return JSON.parse(content);
216
+ } catch (error) {
217
+ return null;
218
+ }
219
+ }
220
+ function writeAuthConfig(config) {
221
+ const authPath = getAuthConfigPath();
222
+ const authDir = path.dirname(authPath);
223
+ if (!fs.existsSync(authDir)) {
224
+ fs.mkdirSync(authDir, { mode: 504, recursive: true });
225
+ }
226
+ fs.writeFileSync(authPath, JSON.stringify(config, null, 2), { mode: 384 });
227
+ }
228
+ function isValidAccessToken(authConfig, expirationBufferMs = 0) {
229
+ if (!authConfig.token)
230
+ return false;
231
+ if (typeof authConfig.expiresAt !== "number")
232
+ return true;
233
+ const nowInSeconds = Math.floor(Date.now() / 1e3);
234
+ const bufferInSeconds = expirationBufferMs / 1e3;
235
+ return authConfig.expiresAt >= nowInSeconds + bufferInSeconds;
236
+ }
237
+ }
238
+ });
239
+
240
+ // ../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/oauth.js
241
+ var require_oauth = __commonJS({
242
+ "../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/oauth.js"(exports, module) {
243
+ "use strict";
244
+ var __defProp2 = Object.defineProperty;
245
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
246
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
247
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
248
+ var __export = (target, all) => {
249
+ for (var name in all)
250
+ __defProp2(target, name, { get: all[name], enumerable: true });
251
+ };
252
+ var __copyProps2 = (to, from, except, desc) => {
253
+ if (from && typeof from === "object" || typeof from === "function") {
254
+ for (let key of __getOwnPropNames2(from))
255
+ if (!__hasOwnProp2.call(to, key) && key !== except)
256
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
257
+ }
258
+ return to;
259
+ };
260
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
261
+ var oauth_exports = {};
262
+ __export(oauth_exports, {
263
+ processTokenResponse: () => processTokenResponse,
264
+ refreshTokenRequest: () => refreshTokenRequest
265
+ });
266
+ module.exports = __toCommonJS(oauth_exports);
267
+ var import_os = __require("os");
268
+ var VERCEL_ISSUER = "https://vercel.com";
269
+ var VERCEL_CLI_CLIENT_ID = "cl_HYyOPBNtFMfHhaUn9L4QPfTZz6TP47bp";
270
+ var userAgent = `@vercel/oidc node-${process.version} ${(0, import_os.platform)()} (${(0, import_os.arch)()}) ${(0, import_os.hostname)()}`;
271
+ var _tokenEndpoint = null;
272
+ async function getTokenEndpoint() {
273
+ if (_tokenEndpoint) {
274
+ return _tokenEndpoint;
275
+ }
276
+ const discoveryUrl = `${VERCEL_ISSUER}/.well-known/openid-configuration`;
277
+ const response = await fetch(discoveryUrl, {
278
+ headers: { "user-agent": userAgent }
279
+ });
280
+ if (!response.ok) {
281
+ throw new Error("Failed to discover OAuth endpoints");
282
+ }
283
+ const metadata = await response.json();
284
+ if (!metadata || typeof metadata.token_endpoint !== "string") {
285
+ throw new Error("Invalid OAuth discovery response");
286
+ }
287
+ const endpoint = metadata.token_endpoint;
288
+ _tokenEndpoint = endpoint;
289
+ return endpoint;
290
+ }
291
+ async function refreshTokenRequest(options) {
292
+ const tokenEndpoint = await getTokenEndpoint();
293
+ return await fetch(tokenEndpoint, {
294
+ method: "POST",
295
+ headers: {
296
+ "Content-Type": "application/x-www-form-urlencoded",
297
+ "user-agent": userAgent
298
+ },
299
+ body: new URLSearchParams({
300
+ client_id: VERCEL_CLI_CLIENT_ID,
301
+ grant_type: "refresh_token",
302
+ ...options
303
+ })
304
+ });
305
+ }
306
+ async function processTokenResponse(response) {
307
+ const json = await response.json();
308
+ if (!response.ok) {
309
+ const errorMsg = typeof json === "object" && json && "error" in json ? String(json.error) : "Token refresh failed";
310
+ return [new Error(errorMsg)];
311
+ }
312
+ if (typeof json !== "object" || json === null) {
313
+ return [new Error("Invalid token response")];
314
+ }
315
+ if (typeof json.access_token !== "string") {
316
+ return [new Error("Missing access_token in response")];
317
+ }
318
+ if (json.token_type !== "Bearer") {
319
+ return [new Error("Invalid token_type in response")];
320
+ }
321
+ if (typeof json.expires_in !== "number") {
322
+ return [new Error("Missing expires_in in response")];
323
+ }
324
+ return [null, json];
325
+ }
326
+ }
327
+ });
328
+
329
+ // ../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/auth-errors.js
330
+ var require_auth_errors = __commonJS({
331
+ "../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/auth-errors.js"(exports, module) {
332
+ "use strict";
333
+ var __defProp2 = Object.defineProperty;
334
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
335
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
336
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
337
+ var __export = (target, all) => {
338
+ for (var name in all)
339
+ __defProp2(target, name, { get: all[name], enumerable: true });
340
+ };
341
+ var __copyProps2 = (to, from, except, desc) => {
342
+ if (from && typeof from === "object" || typeof from === "function") {
343
+ for (let key of __getOwnPropNames2(from))
344
+ if (!__hasOwnProp2.call(to, key) && key !== except)
345
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
346
+ }
347
+ return to;
348
+ };
349
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
350
+ var auth_errors_exports = {};
351
+ __export(auth_errors_exports, {
352
+ AccessTokenMissingError: () => AccessTokenMissingError,
353
+ RefreshAccessTokenFailedError: () => RefreshAccessTokenFailedError
354
+ });
355
+ module.exports = __toCommonJS(auth_errors_exports);
356
+ var AccessTokenMissingError = class extends Error {
357
+ constructor() {
358
+ super(
359
+ "No authentication found. Please log in with the Vercel CLI (vercel login)."
360
+ );
361
+ this.name = "AccessTokenMissingError";
362
+ }
363
+ };
364
+ var RefreshAccessTokenFailedError = class extends Error {
365
+ constructor(cause) {
366
+ super("Failed to refresh authentication token.", { cause });
367
+ this.name = "RefreshAccessTokenFailedError";
368
+ }
369
+ };
370
+ }
371
+ });
372
+
373
+ // ../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/token-util.js
374
+ var require_token_util = __commonJS({
375
+ "../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/token-util.js"(exports, module) {
376
+ var __create2 = Object.create;
377
+ var __defProp2 = Object.defineProperty;
378
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
379
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
380
+ var __getProtoOf2 = Object.getPrototypeOf;
381
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
382
+ var __export = (target, all) => {
383
+ for (var name in all)
384
+ __defProp2(target, name, { get: all[name], enumerable: true });
385
+ };
386
+ var __copyProps2 = (to, from, except, desc) => {
387
+ if (from && typeof from === "object" || typeof from === "function") {
388
+ for (let key of __getOwnPropNames2(from))
389
+ if (!__hasOwnProp2.call(to, key) && key !== except)
390
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
391
+ }
392
+ return to;
393
+ };
394
+ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
395
+ // If the importer is in node compatibility mode or this is not an ESM
396
+ // file that has been converted to a CommonJS file using a Babel-
397
+ // compatible transform (i.e. "__esModule" has not been set), then set
398
+ // "default" to the CommonJS "module.exports" for node compatibility.
399
+ isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
400
+ mod
401
+ ));
402
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
403
+ var token_util_exports = {};
404
+ __export(token_util_exports, {
405
+ assertVercelOidcTokenResponse: () => assertVercelOidcTokenResponse,
406
+ findProjectInfo: () => findProjectInfo,
407
+ getTokenPayload: () => getTokenPayload,
408
+ getVercelDataDir: () => getVercelDataDir,
409
+ getVercelOidcToken: () => getVercelOidcToken,
410
+ getVercelToken: () => getVercelToken,
411
+ isExpired: () => isExpired,
412
+ loadToken: () => loadToken,
413
+ saveToken: () => saveToken
414
+ });
415
+ module.exports = __toCommonJS(token_util_exports);
416
+ var path = __toESM2(__require("path"));
417
+ var fs = __toESM2(__require("fs"));
418
+ var import_token_error = require_token_error();
419
+ var import_token_io = require_token_io();
420
+ var import_auth_config = require_auth_config();
421
+ var import_oauth = require_oauth();
422
+ var import_auth_errors = require_auth_errors();
423
+ function getVercelDataDir() {
424
+ const vercelFolder = "com.vercel.cli";
425
+ const dataDir = (0, import_token_io.getUserDataDir)();
426
+ if (!dataDir) {
427
+ return null;
428
+ }
429
+ return path.join(dataDir, vercelFolder);
430
+ }
431
+ async function getVercelToken(options) {
432
+ const authConfig = (0, import_auth_config.readAuthConfig)();
433
+ if (!authConfig?.token) {
434
+ throw new import_auth_errors.AccessTokenMissingError();
435
+ }
436
+ if ((0, import_auth_config.isValidAccessToken)(authConfig, options?.expirationBufferMs)) {
437
+ return authConfig.token;
438
+ }
439
+ if (!authConfig.refreshToken) {
440
+ (0, import_auth_config.writeAuthConfig)({});
441
+ throw new import_auth_errors.RefreshAccessTokenFailedError("No refresh token available");
442
+ }
443
+ try {
444
+ const tokenResponse = await (0, import_oauth.refreshTokenRequest)({
445
+ refresh_token: authConfig.refreshToken
446
+ });
447
+ const [tokensError, tokens] = await (0, import_oauth.processTokenResponse)(tokenResponse);
448
+ if (tokensError || !tokens) {
449
+ (0, import_auth_config.writeAuthConfig)({});
450
+ throw new import_auth_errors.RefreshAccessTokenFailedError(tokensError);
451
+ }
452
+ const updatedConfig = {
453
+ token: tokens.access_token,
454
+ expiresAt: Math.floor(Date.now() / 1e3) + tokens.expires_in
455
+ };
456
+ if (tokens.refresh_token) {
457
+ updatedConfig.refreshToken = tokens.refresh_token;
458
+ }
459
+ (0, import_auth_config.writeAuthConfig)(updatedConfig);
460
+ return updatedConfig.token;
461
+ } catch (error) {
462
+ (0, import_auth_config.writeAuthConfig)({});
463
+ if (error instanceof import_auth_errors.AccessTokenMissingError || error instanceof import_auth_errors.RefreshAccessTokenFailedError) {
464
+ throw error;
465
+ }
466
+ throw new import_auth_errors.RefreshAccessTokenFailedError(error);
467
+ }
468
+ }
469
+ async function getVercelOidcToken(authToken, projectId, teamId) {
470
+ const url = `https://api.vercel.com/v1/projects/${projectId}/token?source=vercel-oidc-refresh${teamId ? `&teamId=${teamId}` : ""}`;
471
+ const res = await fetch(url, {
472
+ method: "POST",
473
+ headers: {
474
+ Authorization: `Bearer ${authToken}`
475
+ }
476
+ });
477
+ if (!res.ok) {
478
+ throw new import_token_error.VercelOidcTokenError(
479
+ `Failed to refresh OIDC token: ${res.statusText}`
480
+ );
481
+ }
482
+ const tokenRes = await res.json();
483
+ assertVercelOidcTokenResponse(tokenRes);
484
+ return tokenRes;
485
+ }
486
+ function assertVercelOidcTokenResponse(res) {
487
+ if (!res || typeof res !== "object") {
488
+ throw new TypeError(
489
+ "Vercel OIDC token is malformed. Expected an object. Please run `vc env pull` and try again"
490
+ );
491
+ }
492
+ if (!("token" in res) || typeof res.token !== "string") {
493
+ throw new TypeError(
494
+ "Vercel OIDC token is malformed. Expected a string-valued token property. Please run `vc env pull` and try again"
495
+ );
496
+ }
497
+ }
498
+ function findProjectInfo() {
499
+ const dir = (0, import_token_io.findRootDir)();
500
+ if (!dir) {
501
+ throw new import_token_error.VercelOidcTokenError(
502
+ "Unable to find project root directory. Have you linked your project with `vc link?`"
503
+ );
504
+ }
505
+ const prjPath = path.join(dir, ".vercel", "project.json");
506
+ if (!fs.existsSync(prjPath)) {
507
+ throw new import_token_error.VercelOidcTokenError(
508
+ "project.json not found, have you linked your project with `vc link?`"
509
+ );
510
+ }
511
+ const prj = JSON.parse(fs.readFileSync(prjPath, "utf8"));
512
+ if (typeof prj.projectId !== "string" && typeof prj.orgId !== "string") {
513
+ throw new TypeError(
514
+ "Expected a string-valued projectId property. Try running `vc link` to re-link your project."
515
+ );
516
+ }
517
+ return { projectId: prj.projectId, teamId: prj.orgId };
518
+ }
519
+ function saveToken(token, projectId) {
520
+ const dir = (0, import_token_io.getUserDataDir)();
521
+ if (!dir) {
522
+ throw new import_token_error.VercelOidcTokenError(
523
+ "Unable to find user data directory. Please reach out to Vercel support."
524
+ );
525
+ }
526
+ const tokenPath = path.join(dir, "com.vercel.token", `${projectId}.json`);
527
+ const tokenJson = JSON.stringify(token);
528
+ fs.mkdirSync(path.dirname(tokenPath), { mode: 504, recursive: true });
529
+ fs.writeFileSync(tokenPath, tokenJson);
530
+ fs.chmodSync(tokenPath, 432);
531
+ return;
532
+ }
533
+ function loadToken(projectId) {
534
+ const dir = (0, import_token_io.getUserDataDir)();
535
+ if (!dir) {
536
+ throw new import_token_error.VercelOidcTokenError(
537
+ "Unable to find user data directory. Please reach out to Vercel support."
538
+ );
539
+ }
540
+ const tokenPath = path.join(dir, "com.vercel.token", `${projectId}.json`);
541
+ if (!fs.existsSync(tokenPath)) {
542
+ return null;
543
+ }
544
+ const token = JSON.parse(fs.readFileSync(tokenPath, "utf8"));
545
+ assertVercelOidcTokenResponse(token);
546
+ return token;
547
+ }
548
+ function getTokenPayload(token) {
549
+ const tokenParts = token.split(".");
550
+ if (tokenParts.length !== 3) {
551
+ throw new import_token_error.VercelOidcTokenError(
552
+ "Invalid token. Please run `vc env pull` and try again"
553
+ );
554
+ }
555
+ const base64 = tokenParts[1].replace(/-/g, "+").replace(/_/g, "/");
556
+ const padded = base64.padEnd(
557
+ base64.length + (4 - base64.length % 4) % 4,
558
+ "="
559
+ );
560
+ return JSON.parse(Buffer.from(padded, "base64").toString("utf8"));
561
+ }
562
+ function isExpired(token, bufferMs = 0) {
563
+ return token.exp * 1e3 < Date.now() + bufferMs;
564
+ }
565
+ }
566
+ });
567
+
568
+ export {
569
+ __commonJS,
570
+ __toESM,
571
+ require_token_error,
572
+ require_auth_errors,
573
+ require_token_util
574
+ };