@vercel/sandbox 1.1.4 → 1.1.5

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.
Files changed (70) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-test.log +14 -8
  3. package/.turbo/turbo-typecheck.log +1 -1
  4. package/CHANGELOG.md +6 -0
  5. package/__mocks__/picocolors.ts +13 -0
  6. package/dist/api-client/with-retry.js +1 -1
  7. package/dist/api-client/with-retry.js.map +1 -1
  8. package/dist/auth/api.d.ts +6 -0
  9. package/dist/auth/api.js +28 -0
  10. package/dist/auth/api.js.map +1 -0
  11. package/dist/auth/error.d.ts +11 -0
  12. package/dist/auth/error.js +12 -0
  13. package/dist/auth/error.js.map +1 -0
  14. package/dist/auth/file.d.ts +22 -0
  15. package/dist/auth/file.js +66 -0
  16. package/dist/auth/file.js.map +1 -0
  17. package/dist/auth/index.d.ts +6 -0
  18. package/dist/auth/index.js +27 -0
  19. package/dist/auth/index.js.map +1 -0
  20. package/dist/auth/linked-project.d.ts +10 -0
  21. package/dist/auth/linked-project.js +69 -0
  22. package/dist/auth/linked-project.js.map +1 -0
  23. package/dist/auth/oauth.d.ts +131 -0
  24. package/dist/auth/oauth.js +269 -0
  25. package/dist/auth/oauth.js.map +1 -0
  26. package/dist/auth/poll-for-token.d.ts +20 -0
  27. package/dist/auth/poll-for-token.js +66 -0
  28. package/dist/auth/poll-for-token.js.map +1 -0
  29. package/dist/auth/project.d.ts +40 -0
  30. package/dist/auth/project.js +80 -0
  31. package/dist/auth/project.js.map +1 -0
  32. package/dist/auth/zod.d.ts +5 -0
  33. package/dist/auth/zod.js +20 -0
  34. package/dist/auth/zod.js.map +1 -0
  35. package/dist/sandbox.js +1 -1
  36. package/dist/sandbox.js.map +1 -1
  37. package/dist/utils/dev-credentials.d.ts +37 -0
  38. package/dist/utils/dev-credentials.js +191 -0
  39. package/dist/utils/dev-credentials.js.map +1 -0
  40. package/dist/utils/get-credentials.d.ts +16 -0
  41. package/dist/utils/get-credentials.js +66 -7
  42. package/dist/utils/get-credentials.js.map +1 -1
  43. package/dist/utils/log.d.ts +2 -0
  44. package/dist/utils/log.js +24 -0
  45. package/dist/utils/log.js.map +1 -0
  46. package/dist/version.d.ts +1 -1
  47. package/dist/version.js +1 -1
  48. package/package.json +4 -1
  49. package/src/api-client/api-client.test.ts +128 -0
  50. package/src/api-client/with-retry.ts +1 -1
  51. package/src/auth/api.ts +31 -0
  52. package/src/auth/error.ts +8 -0
  53. package/src/auth/file.ts +69 -0
  54. package/src/auth/index.ts +9 -0
  55. package/src/auth/infer-scope.test.ts +178 -0
  56. package/src/auth/linked-project.test.ts +86 -0
  57. package/src/auth/linked-project.ts +40 -0
  58. package/src/auth/oauth.ts +333 -0
  59. package/src/auth/poll-for-token.ts +89 -0
  60. package/src/auth/project.ts +92 -0
  61. package/src/auth/zod.ts +16 -0
  62. package/src/sandbox.ts +1 -1
  63. package/src/utils/dev-credentials.test.ts +217 -0
  64. package/src/utils/dev-credentials.ts +189 -0
  65. package/src/utils/get-credentials.test.ts +20 -0
  66. package/src/utils/get-credentials.ts +72 -8
  67. package/src/utils/log.ts +20 -0
  68. package/src/version.ts +1 -1
  69. package/test-utils/mock-response.ts +12 -0
  70. package/vitest.config.ts +1 -0
@@ -1,4 +1,4 @@
1
1
 
2
- > @vercel/sandbox@1.1.4 build /home/runner/work/sandbox-sdk/sandbox-sdk/packages/vercel-sandbox
2
+ > @vercel/sandbox@1.1.5 build /home/runner/work/sandbox-sdk/sandbox-sdk/packages/vercel-sandbox
3
3
  > tsc
4
4
 
@@ -1,18 +1,24 @@
1
1
 
2
- > @vercel/sandbox@1.1.4 test /home/runner/work/sandbox-sdk/sandbox-sdk/packages/vercel-sandbox
2
+ > @vercel/sandbox@1.1.5 test /home/runner/work/sandbox-sdk/sandbox-sdk/packages/vercel-sandbox
3
3
  > vitest run
4
4
 
5
5
 
6
6
   RUN  v3.2.1 /home/runner/work/sandbox-sdk/sandbox-sdk/packages/vercel-sandbox
7
7
 
8
- ✓ src/utils/jwt-expiry.test.ts (10 tests) 21ms
8
+ ✓ src/utils/dev-credentials.test.ts (7 tests) 572ms
9
+ ✓ signInAndGetToken > times out after provided timeout  548ms
10
+ ✓ src/auth/infer-scope.test.ts (9 tests) 79ms
11
+ ✓ src/utils/jwt-expiry.test.ts (10 tests) 33ms
12
+ ✓ src/api-client/api-client.test.ts (5 tests) 100ms
9
13
  ↓ src/sandbox.test.ts (4 tests | 4 skipped)
10
- ✓ src/utils/normalizePath.test.ts (6 tests) 8ms
14
+ ✓ src/utils/normalizePath.test.ts (6 tests) 18ms
11
15
  ↓ src/command.test.ts (5 tests | 5 skipped)
12
- ✓ src/utils/types.test.js (1 test) 16ms
16
+ ✓ src/auth/linked-project.test.ts (6 tests) 47ms
17
+ ✓ src/utils/get-credentials.test.ts (2 tests) 31ms
18
+ ✓ src/utils/types.test.js (1 test) 6ms
13
19
 
14
-  Test Files  3 passed | 2 skipped (5)
15
-  Tests  17 passed | 9 skipped (26)
16
-  Start at  19:22:27
17
-  Duration  5.68s (transform 592ms, setup 184ms, collect 1.83s, tests 45ms, environment 12ms, prepare 1.26s)
20
+  Test Files  8 passed | 2 skipped (10)
21
+  Tests  46 passed | 9 skipped (55)
22
+  Start at  07:58:13
23
+  Duration  12.88s (transform 1.06s, setup 296ms, collect 3.68s, tests 886ms, environment 6ms, prepare 2.95s)
18
24
 
@@ -1,4 +1,4 @@
1
1
 
2
- > @vercel/sandbox@1.1.4 typecheck /home/runner/work/sandbox-sdk/sandbox-sdk/packages/vercel-sandbox
2
+ > @vercel/sandbox@1.1.5 typecheck /home/runner/work/sandbox-sdk/sandbox-sdk/packages/vercel-sandbox
3
3
  > tsc --noEmit
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @vercel/sandbox
2
2
 
3
+ ## 1.1.5
4
+
5
+ ### Patch Changes
6
+
7
+ - prompt to login on local machines to make it seamless to use ([#185](https://github.com/vercel/sandbox-sdk/pull/185))
8
+
3
9
  ## 1.1.4
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Mock implementation of picocolors for testing purposes
3
+ * Each color function wraps the input string with HTML-like tags
4
+ * e.g., red('text') => '<red>text</red>'
5
+ */
6
+ export default new Proxy(
7
+ {},
8
+ {
9
+ get(_, prop: string) {
10
+ return (str: string) => `<${prop}>${str}</${prop}>`;
11
+ },
12
+ },
13
+ );
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.withRetry = withRetry;
7
7
  const api_error_1 = require("./api-error");
8
- const promises_1 = require("timers/promises");
8
+ const promises_1 = require("node:timers/promises");
9
9
  const async_retry_1 = __importDefault(require("async-retry"));
10
10
  /**
11
11
  * Wraps a fetch function with retry logic. The retry logic will retry
@@ -1 +1 @@
1
- {"version":3,"file":"with-retry.js","sourceRoot":"","sources":["../../src/api-client/with-retry.ts"],"names":[],"mappings":";;;;;AAkBA,8BAwGC;AAzHD,2CAAuC;AACvC,8CAA6C;AAC7C,8DAAgC;AAOhC;;;;;;;GAOG;AACH,SAAgB,SAAS,CACvB,QAA4D;IAE5D,OAAO,KAAK,EACV,GAAiB,EACjB,OAA+C,EAAE,EACjD,EAAE;QACF;;;WAGG;QACH,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAC7B;YACE,UAAU,EAAE,EAAE;YACd,OAAO,EAAE,CAAC;YACV,MAAM,EAAE,CAAC;YACT,aAAa,EAAE,EAAE;SAClB,EACD,IAAI,CAAC,KAAK,CACX,CAAC;QAEF,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,SAAS,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;gBACtC,IAAI,CAAC,OAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;gBAC3B,IAAI,IAAI,CAAC,KAAK,IA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AAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf;;;uBAGG;oBACH,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;wBACxB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;oBACrB,CAAC;oBAED;;;uBAGG;oBACH,IAAI,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;wBACzB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC;oBAClE,CAAC;oBAED,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC,EAAE,SAAS,CAAC,CAAa,CAAC;QAC7B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf;;;;eAIG;YACH,IAAI,KAAK,YAAY,oBAAQ,EAAE,CAAC;gBAC9B,OAAO,KAAK,CAAC,QAAQ,CAAC;YACxB,CAAC;YAED,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,CACL,KAAK,KAAK,SAAS;QACnB,KAAK,KAAK,IAAI;QACb,KAAe,CAAC,IAAI,KAAK,YAAY,CACvC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"with-retry.js","sourceRoot":"","sources":["../../src/api-client/with-retry.ts"],"names":[],"mappings":";;;;;AAkBA,8BAwGC;AAzHD,2CAAuC;AACvC,mDAAkD;AAClD,8DAAgC;AAOhC;;;;;;;GAOG;AACH,SAAgB,SAAS,CACvB,QAA4D;IAE5D,OAAO,KAAK,EACV,GAAiB,EACjB,OAA+C,EAAE,EACjD,EAAE;QACF;;;WAGG;QACH,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAC7B;YACE,UAAU,EAAE,EAAE;YACd,OAAO,EAAE,CAAC;YACV,MAAM,EAAE,CAAC;YACT,aAAa,EAAE,EAAE;SAClB,EACD,IAAI,CAAC,KAAK,CACX,CAAC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BAED;;;uBAGG;oBACH,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;wBACpD,MAAM,IAAI,oBAAQ,CAAC,QAAQ,CAAC,CAAC;oBAC/B,CAAC;oBAED,OAAO,QAAQ,CAAC;gBAClB,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf;;;uBAGG;oBACH,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;wBACxB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;oBACrB,CAAC;oBAED;;;uBAGG;oBACH,IAAI,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;wBACzB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC;oBAClE,CAAC;oBAED,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC,EAAE,SAAS,CAAC,CAAa,CAAC;QAC7B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf;;;;eAIG;YACH,IAAI,KAAK,YAAY,oBAAQ,EAAE,CAAC;gBAC9B,OAAO,KAAK,CAAC,QAAQ,CAAC;YACxB,CAAC;YAED,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,CACL,KAAK,KAAK,SAAS;QACnB,KAAK,KAAK,IAAI;QACb,KAAe,CAAC,IAAI,KAAK,YAAY,CACvC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare function fetchApi(opts: {
2
+ token: string;
3
+ endpoint: string;
4
+ method?: string;
5
+ body?: string;
6
+ }): Promise<unknown>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchApi = fetchApi;
4
+ const error_1 = require("./error");
5
+ async function fetchApi(opts) {
6
+ const x = await fetch(`https://api.vercel.com${opts.endpoint}`, {
7
+ method: opts.method,
8
+ body: opts.body,
9
+ headers: {
10
+ Authorization: `Bearer ${opts.token}`,
11
+ "Content-Type": "application/json",
12
+ },
13
+ });
14
+ if (!x.ok) {
15
+ let message = await x.text();
16
+ try {
17
+ const { error } = JSON.parse(message);
18
+ message = `${error.code.toUpperCase()}: ${error.message}`;
19
+ }
20
+ catch { }
21
+ throw new error_1.NotOk({
22
+ responseText: message,
23
+ statusCode: x.status,
24
+ });
25
+ }
26
+ return (await x.json());
27
+ }
28
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/auth/api.ts"],"names":[],"mappings":";;AAEA,4BA4BC;AA9BD,mCAAgC;AAEzB,KAAK,UAAU,QAAQ,CAAC,IAK9B;IACC,MAAM,CAAC,GAAG,MAAM,KAAK,CAAC,yBAAyB,IAAI,CAAC,QAAQ,EAAE,EAAE;QAC9D,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,OAAO,EAAE;YACP,aAAa,EAAE,UAAU,IAAI,CAAC,KAAK,EAAE;YACrC,cAAc,EAAE,kBAAkB;SACnC;KACF,CAAC,CAAC;IACH,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QACV,IAAI,OAAO,GAAG,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;QAE7B,IAAI,CAAC;YACH,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACtC,OAAO,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;QAC5D,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;QAEV,MAAM,IAAI,aAAK,CAAC;YACd,YAAY,EAAE,OAAO;YACrB,UAAU,EAAE,CAAC,CAAC,MAAM;SACrB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAY,CAAC;AACrC,CAAC"}
@@ -0,0 +1,11 @@
1
+ export declare class NotOk extends Error {
2
+ name: string;
3
+ response: {
4
+ statusCode: number;
5
+ responseText: string;
6
+ };
7
+ constructor(response: {
8
+ statusCode: number;
9
+ responseText: string;
10
+ });
11
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotOk = void 0;
4
+ class NotOk extends Error {
5
+ constructor(response) {
6
+ super(`HTTP ${response.statusCode}: ${response.responseText}`);
7
+ this.name = "NotOk";
8
+ this.response = response;
9
+ }
10
+ }
11
+ exports.NotOk = NotOk;
12
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/auth/error.ts"],"names":[],"mappings":";;;AAAA,MAAa,KAAM,SAAQ,KAAK;IAG9B,YAAY,QAAsD;QAChE,KAAK,CAAC,QAAQ,QAAQ,CAAC,UAAU,KAAK,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC;QAHjE,SAAI,GAAG,OAAO,CAAC;QAIb,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAPD,sBAOC"}
@@ -0,0 +1,22 @@
1
+ import { z } from "zod";
2
+ declare const AuthFile: z.ZodObject<{
3
+ token: z.ZodOptional<z.ZodString>;
4
+ refreshToken: z.ZodOptional<z.ZodString>;
5
+ expiresAt: z.ZodOptional<z.ZodEffects<z.ZodNumber, Date, number>>;
6
+ }, "strip", z.ZodTypeAny, {
7
+ expiresAt?: Date | undefined;
8
+ token?: string | undefined;
9
+ refreshToken?: string | undefined;
10
+ }, {
11
+ expiresAt?: number | undefined;
12
+ token?: string | undefined;
13
+ refreshToken?: string | undefined;
14
+ }>;
15
+ type AuthFile = z.infer<typeof AuthFile>;
16
+ export declare const getAuth: () => {
17
+ expiresAt?: Date | undefined;
18
+ token?: string | undefined;
19
+ refreshToken?: string | undefined;
20
+ } | null;
21
+ export declare function updateAuthConfig(config: AuthFile): void;
22
+ export {};
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getAuth = void 0;
7
+ exports.updateAuthConfig = updateAuthConfig;
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const node_fs_1 = __importDefault(require("node:fs"));
10
+ const node_os_1 = require("node:os");
11
+ const xdg_app_paths_1 = __importDefault(require("xdg-app-paths"));
12
+ const zod_1 = require("zod");
13
+ const zod_2 = require("./zod");
14
+ const ZodDate = zod_1.z.number().transform((seconds) => new Date(seconds * 1000));
15
+ const AuthFile = zod_1.z.object({
16
+ token: zod_1.z.string().min(1).optional(),
17
+ refreshToken: zod_1.z.string().min(1).optional(),
18
+ expiresAt: ZodDate.optional(),
19
+ });
20
+ const StoredAuthFile = zod_2.json.pipe(AuthFile);
21
+ // Returns whether a directory exists
22
+ const isDirectory = (path) => {
23
+ try {
24
+ return node_fs_1.default.lstatSync(path).isDirectory();
25
+ }
26
+ catch (_) {
27
+ // We don't care which kind of error occured, it isn't a directory anyway.
28
+ return false;
29
+ }
30
+ };
31
+ // Returns in which directory the config should be present
32
+ const getGlobalPathConfig = () => {
33
+ const vercelDirectories = (0, xdg_app_paths_1.default)("com.vercel.cli").dataDirs();
34
+ const possibleConfigPaths = [
35
+ ...vercelDirectories, // latest vercel directory
36
+ node_path_1.default.join((0, node_os_1.homedir)(), ".now"), // legacy config in user's home directory
37
+ ...(0, xdg_app_paths_1.default)("now").dataDirs(), // legacy XDG directory
38
+ ];
39
+ // The customPath flag is the preferred location,
40
+ // followed by the vercel directory,
41
+ // followed by the now directory.
42
+ // If none of those exist, use the vercel directory.
43
+ return (possibleConfigPaths.find((configPath) => isDirectory(configPath)) ||
44
+ vercelDirectories[0]);
45
+ };
46
+ const getAuth = () => {
47
+ try {
48
+ const pathname = node_path_1.default.join(getGlobalPathConfig(), "auth.json");
49
+ return StoredAuthFile.parse(node_fs_1.default.readFileSync(pathname, "utf8"));
50
+ }
51
+ catch {
52
+ return null;
53
+ }
54
+ };
55
+ exports.getAuth = getAuth;
56
+ function updateAuthConfig(config) {
57
+ const pathname = node_path_1.default.join(getGlobalPathConfig(), "auth.json");
58
+ node_fs_1.default.mkdirSync(node_path_1.default.dirname(pathname), { recursive: true });
59
+ const content = {
60
+ token: config.token,
61
+ expiresAt: config.expiresAt && Math.round(config.expiresAt.getTime() / 1000),
62
+ refreshToken: config.refreshToken,
63
+ };
64
+ node_fs_1.default.writeFileSync(pathname, JSON.stringify(content) + "\n");
65
+ }
66
+ //# sourceMappingURL=file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/auth/file.ts"],"names":[],"mappings":";;;;;;AA0DA,4CAUC;AApED,0DAA6B;AAC7B,sDAAyB;AACzB,qCAAkC;AAClC,kEAAwC;AACxC,6BAAwB;AACxB,+BAA6B;AAE7B,MAAM,OAAO,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC;AAE5E,MAAM,QAAQ,GAAG,OAAC,CAAC,MAAM,CAAC;IACxB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACnC,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IAC1C,SAAS,EAAE,OAAO,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC;AAEH,MAAM,cAAc,GAAG,UAAI,CAAC,IAAI,CAAC,QAAQ,C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AAgB,gBAAgB,CAAC,MAAgB;IAC/C,MAAM,QAAQ,GAAG,mBAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,EAAE,WAAW,CAAC,CAAC;IAC/D,iBAAE,CAAC,SAAS,CAAC,mBAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG;QACd,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,SAAS,EACP,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;QACnE,YAAY,EAAE,MAAM,CAAC,YAAY;KACC,CAAC;IACrC,iBAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from "./file";
2
+ export type * from "./file";
3
+ export * from "./oauth";
4
+ export type * from "./oauth";
5
+ export { pollForToken } from "./poll-for-token";
6
+ export { inferScope, selectTeam } from "./project";
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ // This file can also be imported as `@vercel/sandbox/dist/auth`, which is completely fine.
3
+ // The only valid importer of this would be the CLI as we share the same codebase.
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.selectTeam = exports.inferScope = exports.pollForToken = void 0;
20
+ __exportStar(require("./file"), exports);
21
+ __exportStar(require("./oauth"), exports);
22
+ var poll_for_token_1 = require("./poll-for-token");
23
+ Object.defineProperty(exports, "pollForToken", { enumerable: true, get: function () { return poll_for_token_1.pollForToken; } });
24
+ var project_1 = require("./project");
25
+ Object.defineProperty(exports, "inferScope", { enumerable: true, get: function () { return project_1.inferScope; } });
26
+ Object.defineProperty(exports, "selectTeam", { enumerable: true, get: function () { return project_1.selectTeam; } });
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":";AAAA,2FAA2F;AAC3F,kFAAkF;;;;;;;;;;;;;;;;;AAElF,yCAAuB;AAEvB,0CAAwB;AAExB,mDAAgD;AAAvC,8GAAA,YAAY,OAAA;AACrB,qCAAmD;AAA1C,qGAAA,UAAU,OAAA;AAAE,qGAAA,UAAU,OAAA"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Reads the linked project configuration from `.vercel/project.json`.
3
+ *
4
+ * @param cwd - The directory to search for `.vercel/project.json`.
5
+ * @returns The linked project's `projectId` and `teamId`, or `null` if not found.
6
+ */
7
+ export declare function readLinkedProject(cwd: string): Promise<{
8
+ projectId: string;
9
+ teamId: string;
10
+ } | null>;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.readLinkedProject = readLinkedProject;
37
+ const zod_1 = require("zod");
38
+ const fs = __importStar(require("node:fs/promises"));
39
+ const path = __importStar(require("node:path"));
40
+ const zod_2 = require("./zod");
41
+ const LinkedProjectSchema = zod_2.json.pipe(zod_1.z.object({
42
+ projectId: zod_1.z.string(),
43
+ orgId: zod_1.z.string(),
44
+ }));
45
+ /**
46
+ * Reads the linked project configuration from `.vercel/project.json`.
47
+ *
48
+ * @param cwd - The directory to search for `.vercel/project.json`.
49
+ * @returns The linked project's `projectId` and `teamId`, or `null` if not found.
50
+ */
51
+ async function readLinkedProject(cwd) {
52
+ const projectJsonPath = path.join(cwd, ".vercel", "project.json");
53
+ let content;
54
+ try {
55
+ content = await fs.readFile(projectJsonPath, "utf-8");
56
+ }
57
+ catch {
58
+ return null;
59
+ }
60
+ const parsed = LinkedProjectSchema.safeParse(content);
61
+ if (!parsed.success) {
62
+ return null;
63
+ }
64
+ return {
65
+ projectId: parsed.data.projectId,
66
+ teamId: parsed.data.orgId,
67
+ };
68
+ }
69
+ //# sourceMappingURL=linked-project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linked-project.js","sourceRoot":"","sources":["../../src/auth/linked-project.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,8CAqBC;AAvCD,6BAAwB;AACxB,qDAAuC;AACvC,gDAAkC;AAClC,+BAA6B;AAE7B,MAAM,mBAAmB,GAAG,UAAI,CAAC,IAAI,CACnC,OAAC,CAAC,MAAM,CAAC;IACP,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE;IACrB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;CAClB,CAAC,CACH,CAAC;AAEF;;;;;GAKG;AACI,KAAK,UAAU,iBAAiB,CACrC,GAAW;IAEX,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC;IAElE,IAAI,OAAe,CAAC;IACpB,IAAI,CAAC;QACH,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,MAAM,GAAG,mBAAmB,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACtD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS;QAChC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK;KAC1B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,131 @@
1
+ import { z } from "zod";
2
+ declare const IntrospectionResponse: z.ZodUnion<[z.ZodObject<{
3
+ active: z.ZodLiteral<true>;
4
+ client_id: z.ZodString;
5
+ session_id: z.ZodString;
6
+ }, "strip", z.ZodTypeAny, {
7
+ active: true;
8
+ client_id: string;
9
+ session_id: string;
10
+ }, {
11
+ active: true;
12
+ client_id: string;
13
+ session_id: string;
14
+ }>, z.ZodObject<{
15
+ active: z.ZodLiteral<false>;
16
+ }, "strip", z.ZodTypeAny, {
17
+ active: false;
18
+ }, {
19
+ active: false;
20
+ }>]>;
21
+ export declare function OAuth(): Promise<{
22
+ /**
23
+ * Perform the Device Authorization Request
24
+ *
25
+ * @see https://datatracker.ietf.org/doc/html/rfc8628#section-3.1
26
+ * @see https://datatracker.ietf.org/doc/html/rfc8628#section-3.2
27
+ */
28
+ deviceAuthorizationRequest(): Promise<DeviceAuthorizationRequest>;
29
+ /**
30
+ * Perform the Device Access Token Request
31
+ *
32
+ * @see https://datatracker.ietf.org/doc/html/rfc8628#section-3.4
33
+ */
34
+ deviceAccessTokenRequest(device_code: string): Promise<[Error] | [null, Response]>;
35
+ /**
36
+ * Process the Token request Response
37
+ *
38
+ * @see https://datatracker.ietf.org/doc/html/rfc8628#section-3.5
39
+ */
40
+ processTokenResponse(response: Response): Promise<[OAuthError] | [null, TokenSet]>;
41
+ /**
42
+ * Perform a Token Revocation Request.
43
+ *
44
+ * @see https://datatracker.ietf.org/doc/html/rfc7009#section-2.1
45
+ * @see https://datatracker.ietf.org/doc/html/rfc7009#section-2.2
46
+ */
47
+ revokeToken(token: string): Promise<OAuthError | void>;
48
+ /**
49
+ * Perform Refresh Token Request.
50
+ *
51
+ * @see https://datatracker.ietf.org/doc/html/rfc6749#section-6
52
+ */
53
+ refreshToken(token: string): Promise<TokenSet>;
54
+ /**
55
+ * Perform Token Introspection Request.
56
+ *
57
+ * @see https://datatracker.ietf.org/doc/html/rfc7662#section-2.1
58
+ */
59
+ introspectToken(token: string): Promise<z.infer<typeof IntrospectionResponse>>;
60
+ }>;
61
+ export type OAuth = Awaited<ReturnType<typeof OAuth>>;
62
+ declare const TokenSet: z.ZodObject<{
63
+ /** The access token issued by the authorization server. */
64
+ access_token: z.ZodString;
65
+ /** The type of the token issued */
66
+ token_type: z.ZodLiteral<"Bearer">;
67
+ /** The lifetime in seconds of the access token. */
68
+ expires_in: z.ZodNumber;
69
+ /** The refresh token, which can be used to obtain new access tokens. */
70
+ refresh_token: z.ZodOptional<z.ZodString>;
71
+ /** The scope of the access token. */
72
+ scope: z.ZodOptional<z.ZodString>;
73
+ }, "strip", z.ZodTypeAny, {
74
+ expires_in: number;
75
+ access_token: string;
76
+ token_type: "Bearer";
77
+ refresh_token?: string | undefined;
78
+ scope?: string | undefined;
79
+ }, {
80
+ expires_in: number;
81
+ access_token: string;
82
+ token_type: "Bearer";
83
+ refresh_token?: string | undefined;
84
+ scope?: string | undefined;
85
+ }>;
86
+ type TokenSet = z.infer<typeof TokenSet>;
87
+ declare const OAuthErrorResponse: z.ZodObject<{
88
+ error: z.ZodEnum<["invalid_request", "invalid_client", "invalid_grant", "unauthorized_client", "unsupported_grant_type", "invalid_scope", "server_error", "authorization_pending", "slow_down", "access_denied", "expired_token", "unsupported_token_type"]>;
89
+ error_description: z.ZodOptional<z.ZodString>;
90
+ error_uri: z.ZodOptional<z.ZodString>;
91
+ }, "strip", z.ZodTypeAny, {
92
+ error: "invalid_request" | "invalid_client" | "invalid_grant" | "unauthorized_client" | "unsupported_grant_type" | "invalid_scope" | "server_error" | "authorization_pending" | "slow_down" | "access_denied" | "expired_token" | "unsupported_token_type";
93
+ error_description?: string | undefined;
94
+ error_uri?: string | undefined;
95
+ }, {
96
+ error: "invalid_request" | "invalid_client" | "invalid_grant" | "unauthorized_client" | "unsupported_grant_type" | "invalid_scope" | "server_error" | "authorization_pending" | "slow_down" | "access_denied" | "expired_token" | "unsupported_token_type";
97
+ error_description?: string | undefined;
98
+ error_uri?: string | undefined;
99
+ }>;
100
+ type OAuthErrorResponse = z.infer<typeof OAuthErrorResponse>;
101
+ declare class OAuthError extends Error {
102
+ name: string;
103
+ code: OAuthErrorResponse["error"];
104
+ cause: Error;
105
+ constructor(message: string, response: unknown);
106
+ }
107
+ export declare function isOAuthError(error: unknown): error is OAuthError;
108
+ export interface DeviceAuthorizationRequest {
109
+ /** The device verification code. */
110
+ device_code: string;
111
+ /** The end-user verification code. */
112
+ user_code: string;
113
+ /**
114
+ * The minimum amount of time in seconds that the client
115
+ * SHOULD wait between polling requests to the token endpoint.
116
+ */
117
+ interval: number;
118
+ /** The end-user verification URI on the authorization server. */
119
+ verification_uri: string;
120
+ /**
121
+ * The end-user verification URI on the authorization server,
122
+ * including the `user_code`, without redirection.
123
+ */
124
+ verification_uri_complete: string;
125
+ /**
126
+ * The absolute lifetime of the `device_code` and `user_code`.
127
+ * Calculated from `expires_in`.
128
+ */
129
+ expiresAt: number;
130
+ }
131
+ export {};