@vercel/sandbox 2.0.0-beta.11 → 2.0.0-beta.13

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 (196) hide show
  1. package/README.md +8 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  3. package/dist/api-client/api-client.cjs +456 -0
  4. package/dist/api-client/api-client.cjs.map +1 -0
  5. package/dist/api-client/api-client.d.cts +790 -0
  6. package/dist/api-client/api-client.d.ts +784 -777
  7. package/dist/api-client/api-client.js +445 -471
  8. package/dist/api-client/api-client.js.map +1 -1
  9. package/dist/api-client/api-error.cjs +32 -0
  10. package/dist/api-client/api-error.cjs.map +1 -0
  11. package/dist/api-client/api-error.d.cts +29 -0
  12. package/dist/api-client/api-error.d.ts +21 -18
  13. package/dist/api-client/api-error.js +28 -33
  14. package/dist/api-client/api-error.js.map +1 -1
  15. package/dist/api-client/base-client.cjs +125 -0
  16. package/dist/api-client/base-client.cjs.map +1 -0
  17. package/dist/api-client/base-client.d.cts +38 -0
  18. package/dist/api-client/base-client.d.ts +31 -36
  19. package/dist/api-client/base-client.js +110 -130
  20. package/dist/api-client/base-client.js.map +1 -1
  21. package/dist/api-client/file-writer.cjs +62 -0
  22. package/dist/api-client/file-writer.cjs.map +1 -0
  23. package/dist/api-client/file-writer.d.cts +66 -0
  24. package/dist/api-client/file-writer.d.ts +56 -52
  25. package/dist/api-client/file-writer.js +57 -61
  26. package/dist/api-client/file-writer.js.map +1 -1
  27. package/dist/api-client/index.cjs +2 -0
  28. package/dist/api-client/index.d.ts +2 -2
  29. package/dist/api-client/index.js +4 -21
  30. package/dist/api-client/validators.cjs +182 -0
  31. package/dist/api-client/validators.cjs.map +1 -0
  32. package/dist/api-client/validators.d.cts +1469 -0
  33. package/dist/api-client/validators.d.ts +1282 -3699
  34. package/dist/api-client/validators.js +155 -170
  35. package/dist/api-client/validators.js.map +1 -1
  36. package/dist/api-client/with-retry.cjs +89 -0
  37. package/dist/api-client/with-retry.cjs.map +1 -0
  38. package/dist/api-client/with-retry.d.cts +10 -0
  39. package/dist/api-client/with-retry.d.ts +9 -13
  40. package/dist/api-client/with-retry.js +81 -102
  41. package/dist/api-client/with-retry.js.map +1 -1
  42. package/dist/auth/api.cjs +29 -0
  43. package/dist/auth/api.cjs.map +1 -0
  44. package/dist/auth/api.js +26 -25
  45. package/dist/auth/api.js.map +1 -1
  46. package/dist/auth/error.cjs +13 -0
  47. package/dist/auth/error.cjs.map +1 -0
  48. package/dist/auth/error.js +11 -11
  49. package/dist/auth/error.js.map +1 -1
  50. package/dist/auth/file.cjs +64 -0
  51. package/dist/auth/file.cjs.map +1 -0
  52. package/dist/auth/file.d.cts +26 -0
  53. package/dist/auth/file.d.ts +19 -15
  54. package/dist/auth/file.js +49 -64
  55. package/dist/auth/file.js.map +1 -1
  56. package/dist/auth/index.cjs +12 -0
  57. package/dist/auth/index.d.cts +5 -0
  58. package/dist/auth/index.d.ts +5 -6
  59. package/dist/auth/index.js +6 -27
  60. package/dist/auth/linked-project.cjs +38 -0
  61. package/dist/auth/linked-project.cjs.map +1 -0
  62. package/dist/auth/linked-project.js +30 -64
  63. package/dist/auth/linked-project.js.map +1 -1
  64. package/dist/auth/oauth.cjs +205 -0
  65. package/dist/auth/oauth.cjs.map +1 -0
  66. package/dist/auth/oauth.d.cts +135 -0
  67. package/dist/auth/oauth.d.ts +113 -109
  68. package/dist/auth/oauth.js +185 -252
  69. package/dist/auth/oauth.js.map +1 -1
  70. package/dist/auth/poll-for-token.cjs +82 -0
  71. package/dist/auth/poll-for-token.cjs.map +1 -0
  72. package/dist/auth/poll-for-token.d.cts +28 -0
  73. package/dist/auth/poll-for-token.d.ts +23 -15
  74. package/dist/auth/poll-for-token.js +79 -64
  75. package/dist/auth/poll-for-token.js.map +1 -1
  76. package/dist/auth/project.cjs +80 -0
  77. package/dist/auth/project.cjs.map +1 -0
  78. package/dist/auth/project.d.cts +44 -0
  79. package/dist/auth/project.d.ts +12 -8
  80. package/dist/auth/project.js +70 -72
  81. package/dist/auth/project.js.map +1 -1
  82. package/dist/auth/zod.cjs +22 -0
  83. package/dist/auth/zod.cjs.map +1 -0
  84. package/dist/auth/zod.js +18 -17
  85. package/dist/auth/zod.js.map +1 -1
  86. package/dist/command.cjs +328 -0
  87. package/dist/command.cjs.map +1 -0
  88. package/dist/command.d.cts +289 -0
  89. package/dist/command.d.ts +265 -171
  90. package/dist/command.js +323 -226
  91. package/dist/command.js.map +1 -1
  92. package/dist/constants.d.cts +5 -0
  93. package/dist/constants.d.ts +5 -1
  94. package/dist/index.cjs +13 -0
  95. package/dist/index.d.cts +7 -0
  96. package/dist/index.d.ts +7 -6
  97. package/dist/index.js +7 -17
  98. package/dist/network-policy.d.cts +100 -0
  99. package/dist/network-policy.d.ts +32 -28
  100. package/dist/sandbox.cjs +694 -0
  101. package/dist/sandbox.cjs.map +1 -0
  102. package/dist/sandbox.d.cts +796 -0
  103. package/dist/sandbox.d.ts +783 -711
  104. package/dist/sandbox.js +684 -615
  105. package/dist/sandbox.js.map +1 -1
  106. package/dist/session.cjs +520 -0
  107. package/dist/session.cjs.map +1 -0
  108. package/dist/session.d.cts +406 -0
  109. package/dist/session.d.ts +398 -367
  110. package/dist/session.js +517 -505
  111. package/dist/session.js.map +1 -1
  112. package/dist/snapshot.cjs +116 -0
  113. package/dist/snapshot.cjs.map +1 -0
  114. package/dist/snapshot.d.cts +107 -0
  115. package/dist/snapshot.d.ts +98 -91
  116. package/dist/snapshot.js +114 -115
  117. package/dist/snapshot.js.map +1 -1
  118. package/dist/utils/array.cjs +17 -0
  119. package/dist/utils/array.cjs.map +1 -0
  120. package/dist/utils/array.js +12 -15
  121. package/dist/utils/array.js.map +1 -1
  122. package/dist/utils/consume-readable.cjs +18 -0
  123. package/dist/utils/consume-readable.cjs.map +1 -0
  124. package/dist/utils/consume-readable.js +13 -12
  125. package/dist/utils/consume-readable.js.map +1 -1
  126. package/dist/utils/decode-base64-url.cjs +15 -0
  127. package/dist/utils/decode-base64-url.cjs.map +1 -0
  128. package/dist/utils/decode-base64-url.js +10 -9
  129. package/dist/utils/decode-base64-url.js.map +1 -1
  130. package/dist/utils/dev-credentials.cjs +142 -0
  131. package/dist/utils/dev-credentials.cjs.map +1 -0
  132. package/dist/utils/dev-credentials.js +126 -184
  133. package/dist/utils/dev-credentials.js.map +1 -1
  134. package/dist/utils/get-credentials.cjs +123 -0
  135. package/dist/utils/get-credentials.cjs.map +1 -0
  136. package/dist/utils/get-credentials.d.cts +21 -0
  137. package/dist/utils/get-credentials.d.ts +19 -61
  138. package/dist/utils/get-credentials.js +106 -140
  139. package/dist/utils/get-credentials.js.map +1 -1
  140. package/dist/utils/log.cjs +25 -0
  141. package/dist/utils/log.cjs.map +1 -0
  142. package/dist/utils/log.js +15 -17
  143. package/dist/utils/log.js.map +1 -1
  144. package/dist/utils/network-policy.cjs +65 -0
  145. package/dist/utils/network-policy.cjs.map +1 -0
  146. package/dist/utils/network-policy.js +58 -77
  147. package/dist/utils/network-policy.js.map +1 -1
  148. package/dist/utils/normalizePath.cjs +27 -0
  149. package/dist/utils/normalizePath.cjs.map +1 -0
  150. package/dist/utils/normalizePath.js +21 -28
  151. package/dist/utils/normalizePath.js.map +1 -1
  152. package/dist/utils/resolveSignal.cjs +20 -0
  153. package/dist/utils/resolveSignal.cjs.map +1 -0
  154. package/dist/utils/resolveSignal.d.cts +15 -0
  155. package/dist/utils/resolveSignal.d.ts +12 -10
  156. package/dist/utils/resolveSignal.js +14 -17
  157. package/dist/utils/resolveSignal.js.map +1 -1
  158. package/dist/utils/sandbox-snapshot.cjs +14 -0
  159. package/dist/utils/sandbox-snapshot.cjs.map +1 -0
  160. package/dist/utils/sandbox-snapshot.d.cts +10 -0
  161. package/dist/utils/sandbox-snapshot.d.ts +11 -0
  162. package/dist/utils/sandbox-snapshot.js +14 -0
  163. package/dist/utils/sandbox-snapshot.js.map +1 -0
  164. package/dist/utils/types.cjs +13 -0
  165. package/dist/utils/types.cjs.map +1 -0
  166. package/dist/utils/types.d.cts +11 -0
  167. package/dist/utils/types.d.ts +5 -7
  168. package/dist/utils/types.js +8 -8
  169. package/dist/utils/types.js.map +1 -1
  170. package/dist/version.cjs +7 -0
  171. package/dist/version.cjs.map +1 -0
  172. package/dist/version.js +5 -5
  173. package/dist/version.js.map +1 -1
  174. package/package.json +23 -3
  175. package/dist/api-client/index.js.map +0 -1
  176. package/dist/auth/api.d.ts +0 -6
  177. package/dist/auth/error.d.ts +0 -11
  178. package/dist/auth/index.js.map +0 -1
  179. package/dist/auth/linked-project.d.ts +0 -10
  180. package/dist/auth/zod.d.ts +0 -5
  181. package/dist/constants.js +0 -3
  182. package/dist/constants.js.map +0 -1
  183. package/dist/index.js.map +0 -1
  184. package/dist/network-policy.js +0 -3
  185. package/dist/network-policy.js.map +0 -1
  186. package/dist/utils/array.d.ts +0 -9
  187. package/dist/utils/consume-readable.d.ts +0 -5
  188. package/dist/utils/convert-sandbox.d.ts +0 -6
  189. package/dist/utils/convert-sandbox.js +0 -14
  190. package/dist/utils/convert-sandbox.js.map +0 -1
  191. package/dist/utils/decode-base64-url.d.ts +0 -7
  192. package/dist/utils/dev-credentials.d.ts +0 -37
  193. package/dist/utils/log.d.ts +0 -2
  194. package/dist/utils/network-policy.d.ts +0 -7
  195. package/dist/utils/normalizePath.d.ts +0 -17
  196. package/dist/version.d.ts +0 -1
package/dist/auth/file.js CHANGED
@@ -1,74 +1,59 @@
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(),
1
+ import { json } from "./zod.js";
2
+ import { z } from "zod";
3
+ import path from "node:path";
4
+ import fs from "node:fs";
5
+ import { homedir } from "node:os";
6
+ import XDGAppPaths from "xdg-app-paths";
7
+
8
+ //#region src/auth/file.ts
9
+ const ZodDate = z.number().transform((seconds) => /* @__PURE__ */ new Date(seconds * 1e3));
10
+ const AuthFile = z.object({
11
+ token: z.string().min(1).optional(),
12
+ refreshToken: z.string().min(1).optional(),
13
+ expiresAt: ZodDate.optional()
19
14
  });
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
- }
15
+ const StoredAuthFile = json.pipe(AuthFile);
16
+ const isDirectory = (path$1) => {
17
+ try {
18
+ return fs.lstatSync(path$1).isDirectory();
19
+ } catch (_) {
20
+ return false;
21
+ }
30
22
  };
31
23
  /**
32
- * Returns in which directory the config should be present.
33
- *
34
- * @internal The `VERCEL_AUTH_CONFIG_DIR` env var is for testing purposes only
35
- * and is not part of the public API.
36
- */
24
+ * Returns in which directory the config should be present.
25
+ *
26
+ * @internal The `VERCEL_AUTH_CONFIG_DIR` env var is for testing purposes only
27
+ * and is not part of the public API.
28
+ */
37
29
  const getGlobalPathConfig = () => {
38
- if (process.env.VERCEL_AUTH_CONFIG_DIR) {
39
- return process.env.VERCEL_AUTH_CONFIG_DIR;
40
- }
41
- const vercelDirectories = (0, xdg_app_paths_1.default)("com.vercel.cli").dataDirs();
42
- const possibleConfigPaths = [
43
- ...vercelDirectories, // latest vercel directory
44
- node_path_1.default.join((0, node_os_1.homedir)(), ".now"), // legacy config in user's home directory
45
- ...(0, xdg_app_paths_1.default)("now").dataDirs(), // legacy XDG directory
46
- ];
47
- // The customPath flag is the preferred location,
48
- // followed by the vercel directory,
49
- // followed by the now directory.
50
- // If none of those exist, use the vercel directory.
51
- return (possibleConfigPaths.find((configPath) => isDirectory(configPath)) ||
52
- vercelDirectories[0]);
30
+ if (process.env.VERCEL_AUTH_CONFIG_DIR) return process.env.VERCEL_AUTH_CONFIG_DIR;
31
+ const vercelDirectories = XDGAppPaths("com.vercel.cli").dataDirs();
32
+ return [
33
+ ...vercelDirectories,
34
+ path.join(homedir(), ".now"),
35
+ ...XDGAppPaths("now").dataDirs()
36
+ ].find((configPath) => isDirectory(configPath)) || vercelDirectories[0];
53
37
  };
54
38
  const getAuth = () => {
55
- try {
56
- const pathname = node_path_1.default.join(getGlobalPathConfig(), "auth.json");
57
- return StoredAuthFile.parse(node_fs_1.default.readFileSync(pathname, "utf8"));
58
- }
59
- catch {
60
- return null;
61
- }
39
+ try {
40
+ const pathname = path.join(getGlobalPathConfig(), "auth.json");
41
+ return StoredAuthFile.parse(fs.readFileSync(pathname, "utf8"));
42
+ } catch {
43
+ return null;
44
+ }
62
45
  };
63
- exports.getAuth = getAuth;
64
46
  function updateAuthConfig(config) {
65
- const pathname = node_path_1.default.join(getGlobalPathConfig(), "auth.json");
66
- node_fs_1.default.mkdirSync(node_path_1.default.dirname(pathname), { recursive: true });
67
- const content = {
68
- token: config.token,
69
- expiresAt: config.expiresAt && Math.round(config.expiresAt.getTime() / 1000),
70
- refreshToken: config.refreshToken,
71
- };
72
- node_fs_1.default.writeFileSync(pathname, JSON.stringify(content) + "\n");
47
+ const pathname = path.join(getGlobalPathConfig(), "auth.json");
48
+ fs.mkdirSync(path.dirname(pathname), { recursive: true });
49
+ const content = {
50
+ token: config.token,
51
+ expiresAt: config.expiresAt && Math.round(config.expiresAt.getTime() / 1e3),
52
+ refreshToken: config.refreshToken
53
+ };
54
+ fs.writeFileSync(pathname, JSON.stringify(content) + "\n");
73
55
  }
56
+
57
+ //#endregion
58
+ export { getAuth, updateAuthConfig };
74
59
  //# sourceMappingURL=file.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/auth/file.ts"],"names":[],"mappings":";;;;;;AAmEA,4CAUC;AA7ED,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,CAAC,CAAC;AAI3C,qCAAqC;AACrC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAW,EAAE;IAC5C,IAAI,CAAC;QACH,OAAO,iBAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IAC1C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,0EAA0E;QAC1E,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,mBAAmB,GAAG,GAAW,EAAE;IACvC,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAE,CAAC;QACvC,OAAO,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC;IAC5C,CAAC;IAED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AI,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"}
1
+ {"version":3,"file":"file.js","names":["path"],"sources":["../../src/auth/file.ts"],"sourcesContent":["import path from \"node:path\";\nimport fs from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport XDGAppPaths from \"xdg-app-paths\";\nimport { z } from \"zod\";\nimport { json } from \"./zod.js\";\n\nconst ZodDate = z.number().transform((seconds) => new Date(seconds * 1000));\n\nconst AuthFile = z.object({\n token: z.string().min(1).optional(),\n refreshToken: z.string().min(1).optional(),\n expiresAt: ZodDate.optional(),\n});\n\nconst StoredAuthFile = json.pipe(AuthFile);\n\ntype AuthFile = z.infer<typeof AuthFile>;\n\n// Returns whether a directory exists\nconst isDirectory = (path: string): boolean => {\n try {\n return fs.lstatSync(path).isDirectory();\n } catch (_) {\n // We don't care which kind of error occured, it isn't a directory anyway.\n return false;\n }\n};\n\n/**\n * Returns in which directory the config should be present.\n *\n * @internal The `VERCEL_AUTH_CONFIG_DIR` env var is for testing purposes only\n * and is not part of the public API.\n */\nconst getGlobalPathConfig = (): string => {\n if (process.env.VERCEL_AUTH_CONFIG_DIR) {\n return process.env.VERCEL_AUTH_CONFIG_DIR;\n }\n\n const vercelDirectories = XDGAppPaths(\"com.vercel.cli\").dataDirs();\n\n const possibleConfigPaths = [\n ...vercelDirectories, // latest vercel directory\n path.join(homedir(), \".now\"), // legacy config in user's home directory\n ...XDGAppPaths(\"now\").dataDirs(), // legacy XDG directory\n ];\n\n // The customPath flag is the preferred location,\n // followed by the vercel directory,\n // followed by the now directory.\n // If none of those exist, use the vercel directory.\n return (\n possibleConfigPaths.find((configPath) => isDirectory(configPath)) ||\n vercelDirectories[0]\n );\n};\n\nexport const getAuth = () => {\n try {\n const pathname = path.join(getGlobalPathConfig(), \"auth.json\");\n return StoredAuthFile.parse(fs.readFileSync(pathname, \"utf8\"));\n } catch {\n return null;\n }\n};\n\nexport function updateAuthConfig(config: AuthFile): void {\n const pathname = path.join(getGlobalPathConfig(), \"auth.json\");\n fs.mkdirSync(path.dirname(pathname), { recursive: true });\n const content = {\n token: config.token,\n expiresAt:\n config.expiresAt && Math.round(config.expiresAt.getTime() / 1000),\n refreshToken: config.refreshToken,\n } satisfies z.input<typeof AuthFile>;\n fs.writeFileSync(pathname, JSON.stringify(content) + \"\\n\");\n}\n"],"mappings":";;;;;;;;AAOA,MAAM,UAAU,EAAE,QAAQ,CAAC,WAAW,4BAAY,IAAI,KAAK,UAAU,IAAK,CAAC;AAE3E,MAAM,WAAW,EAAE,OAAO;CACxB,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,UAAU;CACnC,cAAc,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,UAAU;CAC1C,WAAW,QAAQ,UAAU;CAC9B,CAAC;AAEF,MAAM,iBAAiB,KAAK,KAAK,SAAS;AAK1C,MAAM,eAAe,WAA0B;AAC7C,KAAI;AACF,SAAO,GAAG,UAAUA,OAAK,CAAC,aAAa;UAChC,GAAG;AAEV,SAAO;;;;;;;;;AAUX,MAAM,4BAAoC;AACxC,KAAI,QAAQ,IAAI,uBACd,QAAO,QAAQ,IAAI;CAGrB,MAAM,oBAAoB,YAAY,iBAAiB,CAAC,UAAU;AAYlE,QAV4B;EAC1B,GAAG;EACH,KAAK,KAAK,SAAS,EAAE,OAAO;EAC5B,GAAG,YAAY,MAAM,CAAC,UAAU;EACjC,CAOqB,MAAM,eAAe,YAAY,WAAW,CAAC,IACjE,kBAAkB;;AAItB,MAAa,gBAAgB;AAC3B,KAAI;EACF,MAAM,WAAW,KAAK,KAAK,qBAAqB,EAAE,YAAY;AAC9D,SAAO,eAAe,MAAM,GAAG,aAAa,UAAU,OAAO,CAAC;SACxD;AACN,SAAO;;;AAIX,SAAgB,iBAAiB,QAAwB;CACvD,MAAM,WAAW,KAAK,KAAK,qBAAqB,EAAE,YAAY;AAC9D,IAAG,UAAU,KAAK,QAAQ,SAAS,EAAE,EAAE,WAAW,MAAM,CAAC;CACzD,MAAM,UAAU;EACd,OAAO,OAAO;EACd,WACE,OAAO,aAAa,KAAK,MAAM,OAAO,UAAU,SAAS,GAAG,IAAK;EACnE,cAAc,OAAO;EACtB;AACD,IAAG,cAAc,UAAU,KAAK,UAAU,QAAQ,GAAG,KAAK"}
@@ -0,0 +1,12 @@
1
+ const require_file = require('./file.cjs');
2
+ const require_oauth = require('./oauth.cjs');
3
+ const require_poll_for_token = require('./poll-for-token.cjs');
4
+ const require_project = require('./project.cjs');
5
+
6
+ exports.OAuth = require_oauth.OAuth;
7
+ exports.getAuth = require_file.getAuth;
8
+ exports.inferScope = require_project.inferScope;
9
+ exports.isOAuthError = require_oauth.isOAuthError;
10
+ exports.pollForToken = require_poll_for_token.pollForToken;
11
+ exports.selectTeam = require_project.selectTeam;
12
+ exports.updateAuthConfig = require_file.updateAuthConfig;
@@ -0,0 +1,5 @@
1
+ import { getAuth, updateAuthConfig } from "./file.cjs";
2
+ import { DeviceAuthorizationRequest, OAuth, isOAuthError } from "./oauth.cjs";
3
+ import { pollForToken } from "./poll-for-token.cjs";
4
+ import { inferScope, selectTeam } from "./project.cjs";
5
+ export { DeviceAuthorizationRequest, OAuth, getAuth, inferScope, isOAuthError, pollForToken, selectTeam, updateAuthConfig };
@@ -1,6 +1,5 @@
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";
1
+ import { getAuth, updateAuthConfig } from "./file.js";
2
+ import { DeviceAuthorizationRequest, OAuth, isOAuthError } from "./oauth.js";
3
+ import { pollForToken } from "./poll-for-token.js";
4
+ import { inferScope, selectTeam } from "./project.js";
5
+ export { DeviceAuthorizationRequest, OAuth, getAuth, inferScope, isOAuthError, pollForToken, selectTeam, updateAuthConfig };
@@ -1,27 +1,6 @@
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
1
+ import { getAuth, updateAuthConfig } from "./file.js";
2
+ import { OAuth, isOAuthError } from "./oauth.js";
3
+ import { pollForToken } from "./poll-for-token.js";
4
+ import { inferScope, selectTeam } from "./project.js";
5
+
6
+ export { OAuth, getAuth, inferScope, isOAuthError, pollForToken, selectTeam, updateAuthConfig };
@@ -0,0 +1,38 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_zod = require('./zod.cjs');
3
+ let zod = require("zod");
4
+ let node_path = require("node:path");
5
+ node_path = require_rolldown_runtime.__toESM(node_path);
6
+ let node_fs_promises = require("node:fs/promises");
7
+ node_fs_promises = require_rolldown_runtime.__toESM(node_fs_promises);
8
+
9
+ //#region src/auth/linked-project.ts
10
+ const LinkedProjectSchema = require_zod.json.pipe(zod.z.object({
11
+ projectId: zod.z.string(),
12
+ orgId: zod.z.string()
13
+ }));
14
+ /**
15
+ * Reads the linked project configuration from `.vercel/project.json`.
16
+ *
17
+ * @param cwd - The directory to search for `.vercel/project.json`.
18
+ * @returns The linked project's `projectId` and `teamId`, or `null` if not found.
19
+ */
20
+ async function readLinkedProject(cwd) {
21
+ const projectJsonPath = node_path.join(cwd, ".vercel", "project.json");
22
+ let content;
23
+ try {
24
+ content = await node_fs_promises.readFile(projectJsonPath, "utf-8");
25
+ } catch {
26
+ return null;
27
+ }
28
+ const parsed = LinkedProjectSchema.safeParse(content);
29
+ if (!parsed.success) return null;
30
+ return {
31
+ projectId: parsed.data.projectId,
32
+ teamId: parsed.data.orgId
33
+ };
34
+ }
35
+
36
+ //#endregion
37
+ exports.readLinkedProject = readLinkedProject;
38
+ //# sourceMappingURL=linked-project.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linked-project.cjs","names":["json","z","path","content: string","fs"],"sources":["../../src/auth/linked-project.ts"],"sourcesContent":["import { z } from \"zod\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport { json } from \"./zod.js\";\n\nconst LinkedProjectSchema = json.pipe(\n z.object({\n projectId: z.string(),\n orgId: z.string(),\n }),\n);\n\n/**\n * Reads the linked project configuration from `.vercel/project.json`.\n *\n * @param cwd - The directory to search for `.vercel/project.json`.\n * @returns The linked project's `projectId` and `teamId`, or `null` if not found.\n */\nexport async function readLinkedProject(\n cwd: string,\n): Promise<{ projectId: string; teamId: string } | null> {\n const projectJsonPath = path.join(cwd, \".vercel\", \"project.json\");\n\n let content: string;\n try {\n content = await fs.readFile(projectJsonPath, \"utf-8\");\n } catch {\n return null;\n }\n\n const parsed = LinkedProjectSchema.safeParse(content);\n if (!parsed.success) {\n return null;\n }\n\n return {\n projectId: parsed.data.projectId,\n teamId: parsed.data.orgId,\n };\n}\n"],"mappings":";;;;;;;;;AAKA,MAAM,sBAAsBA,iBAAK,KAC/BC,MAAE,OAAO;CACP,WAAWA,MAAE,QAAQ;CACrB,OAAOA,MAAE,QAAQ;CAClB,CAAC,CACH;;;;;;;AAQD,eAAsB,kBACpB,KACuD;CACvD,MAAM,kBAAkBC,UAAK,KAAK,KAAK,WAAW,eAAe;CAEjE,IAAIC;AACJ,KAAI;AACF,YAAU,MAAMC,iBAAG,SAAS,iBAAiB,QAAQ;SAC/C;AACN,SAAO;;CAGT,MAAM,SAAS,oBAAoB,UAAU,QAAQ;AACrD,KAAI,CAAC,OAAO,QACV,QAAO;AAGT,QAAO;EACL,WAAW,OAAO,KAAK;EACvB,QAAQ,OAAO,KAAK;EACrB"}
@@ -1,69 +1,35 @@
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(),
1
+ import { json } from "./zod.js";
2
+ import { z } from "zod";
3
+ import * as path$1 from "node:path";
4
+ import * as fs from "node:fs/promises";
5
+
6
+ //#region src/auth/linked-project.ts
7
+ const LinkedProjectSchema = json.pipe(z.object({
8
+ projectId: z.string(),
9
+ orgId: z.string()
44
10
  }));
45
11
  /**
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
- */
12
+ * Reads the linked project configuration from `.vercel/project.json`.
13
+ *
14
+ * @param cwd - The directory to search for `.vercel/project.json`.
15
+ * @returns The linked project's `projectId` and `teamId`, or `null` if not found.
16
+ */
51
17
  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
- };
18
+ const projectJsonPath = path$1.join(cwd, ".vercel", "project.json");
19
+ let content;
20
+ try {
21
+ content = await fs.readFile(projectJsonPath, "utf-8");
22
+ } catch {
23
+ return null;
24
+ }
25
+ const parsed = LinkedProjectSchema.safeParse(content);
26
+ if (!parsed.success) return null;
27
+ return {
28
+ projectId: parsed.data.projectId,
29
+ teamId: parsed.data.orgId
30
+ };
68
31
  }
32
+
33
+ //#endregion
34
+ export { readLinkedProject };
69
35
  //# sourceMappingURL=linked-project.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"linked-project.js","names":["path","content: string"],"sources":["../../src/auth/linked-project.ts"],"sourcesContent":["import { z } from \"zod\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport { json } from \"./zod.js\";\n\nconst LinkedProjectSchema = json.pipe(\n z.object({\n projectId: z.string(),\n orgId: z.string(),\n }),\n);\n\n/**\n * Reads the linked project configuration from `.vercel/project.json`.\n *\n * @param cwd - The directory to search for `.vercel/project.json`.\n * @returns The linked project's `projectId` and `teamId`, or `null` if not found.\n */\nexport async function readLinkedProject(\n cwd: string,\n): Promise<{ projectId: string; teamId: string } | null> {\n const projectJsonPath = path.join(cwd, \".vercel\", \"project.json\");\n\n let content: string;\n try {\n content = await fs.readFile(projectJsonPath, \"utf-8\");\n } catch {\n return null;\n }\n\n const parsed = LinkedProjectSchema.safeParse(content);\n if (!parsed.success) {\n return null;\n }\n\n return {\n projectId: parsed.data.projectId,\n teamId: parsed.data.orgId,\n };\n}\n"],"mappings":";;;;;;AAKA,MAAM,sBAAsB,KAAK,KAC/B,EAAE,OAAO;CACP,WAAW,EAAE,QAAQ;CACrB,OAAO,EAAE,QAAQ;CAClB,CAAC,CACH;;;;;;;AAQD,eAAsB,kBACpB,KACuD;CACvD,MAAM,kBAAkBA,OAAK,KAAK,KAAK,WAAW,eAAe;CAEjE,IAAIC;AACJ,KAAI;AACF,YAAU,MAAM,GAAG,SAAS,iBAAiB,QAAQ;SAC/C;AACN,SAAO;;CAGT,MAAM,SAAS,oBAAoB,UAAU,QAAQ;AACrD,KAAI,CAAC,OAAO,QACV,QAAO;AAGT,QAAO;EACL,WAAW,OAAO,KAAK;EACvB,QAAQ,OAAO,KAAK;EACrB"}
@@ -0,0 +1,205 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_version = require('../version.cjs');
3
+ let zod = require("zod");
4
+ let os = require("os");
5
+ os = require_rolldown_runtime.__toESM(os);
6
+
7
+ //#region src/auth/oauth.ts
8
+ const USER_AGENT = `${os.default.hostname()} @ vercel/sandbox/${require_version.VERSION} node-${process.version} ${os.default.platform()} (${os.default.arch()})`;
9
+ const ISSUER = new URL("https://vercel.com");
10
+ const CLIENT_ID = "cl_HYyOPBNtFMfHhaUn9L4QPfTZz6TP47bp";
11
+ const AuthorizationServerMetadata = zod.z.object({
12
+ issuer: zod.z.string().url(),
13
+ device_authorization_endpoint: zod.z.string().url(),
14
+ token_endpoint: zod.z.string().url(),
15
+ revocation_endpoint: zod.z.string().url(),
16
+ jwks_uri: zod.z.string().url(),
17
+ introspection_endpoint: zod.z.string().url()
18
+ });
19
+ let _as;
20
+ const DeviceAuthorization = zod.z.object({
21
+ device_code: zod.z.string(),
22
+ user_code: zod.z.string(),
23
+ verification_uri: zod.z.string().url(),
24
+ verification_uri_complete: zod.z.string().url(),
25
+ expires_in: zod.z.number(),
26
+ interval: zod.z.number()
27
+ });
28
+ const IntrospectionResponse = zod.z.object({
29
+ active: zod.z.literal(true),
30
+ client_id: zod.z.string(),
31
+ session_id: zod.z.string()
32
+ }).or(zod.z.object({ active: zod.z.literal(false) }));
33
+ /**
34
+ * Returns the Authorization Server Metadata
35
+ *
36
+ * @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationRequest
37
+ * @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationResponse
38
+ */
39
+ async function authorizationServerMetadata() {
40
+ if (_as) return _as;
41
+ const response = await fetch(new URL(".well-known/openid-configuration", ISSUER), { headers: {
42
+ "Content-Type": "application/json",
43
+ "user-agent": USER_AGENT
44
+ } });
45
+ _as = AuthorizationServerMetadata.parse(await response.json());
46
+ return _as;
47
+ }
48
+ async function OAuth() {
49
+ const as = await authorizationServerMetadata();
50
+ return {
51
+ async deviceAuthorizationRequest() {
52
+ const json = await (await fetch(as.device_authorization_endpoint, {
53
+ method: "POST",
54
+ headers: {
55
+ "Content-Type": "application/x-www-form-urlencoded",
56
+ "user-agent": USER_AGENT
57
+ },
58
+ body: new URLSearchParams({
59
+ client_id: CLIENT_ID,
60
+ scope: "openid offline_access"
61
+ })
62
+ })).json();
63
+ const parsed = DeviceAuthorization.safeParse(json);
64
+ if (!parsed.success) throw new OAuthError(`Failed to parse device authorization response: ${parsed.error.message}`, json);
65
+ return {
66
+ device_code: parsed.data.device_code,
67
+ user_code: parsed.data.user_code,
68
+ verification_uri: parsed.data.verification_uri,
69
+ verification_uri_complete: parsed.data.verification_uri_complete,
70
+ expiresAt: Date.now() + parsed.data.expires_in * 1e3,
71
+ interval: parsed.data.interval
72
+ };
73
+ },
74
+ async deviceAccessTokenRequest(device_code) {
75
+ try {
76
+ return [null, await fetch(as.token_endpoint, {
77
+ method: "POST",
78
+ headers: {
79
+ "Content-Type": "application/x-www-form-urlencoded",
80
+ "user-agent": USER_AGENT
81
+ },
82
+ body: new URLSearchParams({
83
+ client_id: CLIENT_ID,
84
+ grant_type: "urn:ietf:params:oauth:grant-type:device_code",
85
+ device_code
86
+ }),
87
+ signal: AbortSignal.timeout(10 * 1e3)
88
+ })];
89
+ } catch (error) {
90
+ if (error instanceof Error) return [error];
91
+ return [new Error("An unknown error occurred. See the logs for details.", { cause: error })];
92
+ }
93
+ },
94
+ async processTokenResponse(response) {
95
+ const json = await response.json();
96
+ const processed = TokenSet.safeParse(json);
97
+ if (!processed.success) return [new OAuthError(`Failed to parse token response: ${processed.error.message}`, json)];
98
+ return [null, processed.data];
99
+ },
100
+ async revokeToken(token) {
101
+ const response = await fetch(as.revocation_endpoint, {
102
+ method: "POST",
103
+ headers: {
104
+ "Content-Type": "application/x-www-form-urlencoded",
105
+ "user-agent": USER_AGENT
106
+ },
107
+ body: new URLSearchParams({
108
+ token,
109
+ client_id: CLIENT_ID
110
+ })
111
+ });
112
+ if (response.ok) return;
113
+ return new OAuthError("Revocation request failed", await response.json());
114
+ },
115
+ async refreshToken(token) {
116
+ const response = await fetch(as.token_endpoint, {
117
+ method: "POST",
118
+ headers: {
119
+ "Content-Type": "application/x-www-form-urlencoded",
120
+ "user-agent": USER_AGENT
121
+ },
122
+ body: new URLSearchParams({
123
+ client_id: CLIENT_ID,
124
+ grant_type: "refresh_token",
125
+ refresh_token: token
126
+ })
127
+ });
128
+ const [tokensError, tokenSet] = await this.processTokenResponse(response);
129
+ if (tokensError) throw tokensError;
130
+ return tokenSet;
131
+ },
132
+ async introspectToken(token) {
133
+ const json = await (await fetch(as.introspection_endpoint, {
134
+ method: "POST",
135
+ headers: {
136
+ "Content-Type": "application/x-www-form-urlencoded",
137
+ "user-agent": USER_AGENT
138
+ },
139
+ body: new URLSearchParams({ token })
140
+ })).json();
141
+ const processed = IntrospectionResponse.safeParse(json);
142
+ if (!processed.success) throw new OAuthError(`Failed to parse introspection response: ${processed.error.message}`, json);
143
+ return processed.data;
144
+ }
145
+ };
146
+ }
147
+ const TokenSet = zod.z.object({
148
+ access_token: zod.z.string(),
149
+ token_type: zod.z.literal("Bearer"),
150
+ expires_in: zod.z.number(),
151
+ refresh_token: zod.z.string().optional(),
152
+ scope: zod.z.string().optional()
153
+ });
154
+ const OAuthErrorResponse = zod.z.object({
155
+ error: zod.z.enum([
156
+ "invalid_request",
157
+ "invalid_client",
158
+ "invalid_grant",
159
+ "unauthorized_client",
160
+ "unsupported_grant_type",
161
+ "invalid_scope",
162
+ "server_error",
163
+ "authorization_pending",
164
+ "slow_down",
165
+ "access_denied",
166
+ "expired_token",
167
+ "unsupported_token_type"
168
+ ]),
169
+ error_description: zod.z.string().optional(),
170
+ error_uri: zod.z.string().optional()
171
+ });
172
+ function processOAuthErrorResponse(json) {
173
+ try {
174
+ return OAuthErrorResponse.parse(json);
175
+ } catch (error) {
176
+ if (error instanceof zod.z.ZodError) return /* @__PURE__ */ new TypeError(`Invalid OAuth error response: ${error.message}`);
177
+ return /* @__PURE__ */ new TypeError("Failed to parse OAuth error response");
178
+ }
179
+ }
180
+ var OAuthError = class extends Error {
181
+ constructor(message, response) {
182
+ super(message);
183
+ this.name = "OAuthError";
184
+ const error = processOAuthErrorResponse(response);
185
+ if (error instanceof TypeError) {
186
+ const message$1 = `Unexpected server response: ${JSON.stringify(response)}`;
187
+ this.cause = new Error(message$1, { cause: error });
188
+ this.code = "server_error";
189
+ return;
190
+ }
191
+ let cause = error.error;
192
+ if (error.error_description) cause += `: ${error.error_description}`;
193
+ if (error.error_uri) cause += ` (${error.error_uri})`;
194
+ this.cause = new Error(cause);
195
+ this.code = error.error;
196
+ }
197
+ };
198
+ function isOAuthError(error) {
199
+ return error instanceof OAuthError;
200
+ }
201
+
202
+ //#endregion
203
+ exports.OAuth = OAuth;
204
+ exports.isOAuthError = isOAuthError;
205
+ //# sourceMappingURL=oauth.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.cjs","names":["VERSION","z","_as: AuthorizationServerMetadata","message"],"sources":["../../src/auth/oauth.ts"],"sourcesContent":["import os from \"os\";\nimport { z } from \"zod\";\nimport { VERSION } from \"../version.js\";\n\nconst USER_AGENT = `${os.hostname()} @ vercel/sandbox/${VERSION} node-${\n process.version\n} ${os.platform()} (${os.arch()})`;\n\nconst ISSUER = new URL(\"https://vercel.com\");\nconst CLIENT_ID = \"cl_HYyOPBNtFMfHhaUn9L4QPfTZz6TP47bp\";\n\nconst AuthorizationServerMetadata = z.object({\n issuer: z.string().url(),\n device_authorization_endpoint: z.string().url(),\n token_endpoint: z.string().url(),\n revocation_endpoint: z.string().url(),\n jwks_uri: z.string().url(),\n introspection_endpoint: z.string().url(),\n});\ntype AuthorizationServerMetadata = z.infer<typeof AuthorizationServerMetadata>;\nlet _as: AuthorizationServerMetadata;\n\nconst DeviceAuthorization = z.object({\n device_code: z.string(),\n user_code: z.string(),\n verification_uri: z.string().url(),\n verification_uri_complete: z.string().url(),\n expires_in: z.number(),\n interval: z.number(),\n});\n\nconst IntrospectionResponse = z\n .object({\n active: z.literal(true),\n client_id: z.string(),\n session_id: z.string(),\n })\n .or(z.object({ active: z.literal(false) }));\n\n/**\n * Returns the Authorization Server Metadata\n *\n * @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationRequest\n * @see https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationResponse\n */\nasync function authorizationServerMetadata(): Promise<AuthorizationServerMetadata> {\n if (_as) return _as;\n\n const response = await fetch(\n new URL(\".well-known/openid-configuration\", ISSUER),\n {\n headers: { \"Content-Type\": \"application/json\", \"user-agent\": USER_AGENT },\n },\n );\n\n _as = AuthorizationServerMetadata.parse(await response.json());\n return _as;\n}\n\nexport async function OAuth() {\n const as = await authorizationServerMetadata();\n return {\n /**\n * Perform the Device Authorization Request\n *\n * @see https://datatracker.ietf.org/doc/html/rfc8628#section-3.1\n * @see https://datatracker.ietf.org/doc/html/rfc8628#section-3.2\n */\n async deviceAuthorizationRequest(): Promise<DeviceAuthorizationRequest> {\n const response = await fetch(as.device_authorization_endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n \"user-agent\": USER_AGENT,\n },\n body: new URLSearchParams({\n client_id: CLIENT_ID,\n scope: \"openid offline_access\",\n }),\n });\n\n const json = await response.json();\n const parsed = DeviceAuthorization.safeParse(json);\n\n if (!parsed.success) {\n throw new OAuthError(\n `Failed to parse device authorization response: ${parsed.error.message}`,\n json,\n );\n }\n\n return {\n device_code: parsed.data.device_code,\n user_code: parsed.data.user_code,\n verification_uri: parsed.data.verification_uri,\n verification_uri_complete: parsed.data.verification_uri_complete,\n expiresAt: Date.now() + parsed.data.expires_in * 1000,\n interval: parsed.data.interval,\n };\n },\n /**\n * Perform the Device Access Token Request\n *\n * @see https://datatracker.ietf.org/doc/html/rfc8628#section-3.4\n */\n async deviceAccessTokenRequest(\n device_code: string,\n ): Promise<[Error] | [null, Response]> {\n try {\n return [\n null,\n await fetch(as.token_endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n \"user-agent\": USER_AGENT,\n },\n body: new URLSearchParams({\n client_id: CLIENT_ID,\n grant_type: \"urn:ietf:params:oauth:grant-type:device_code\",\n device_code,\n }),\n signal: AbortSignal.timeout(10 * 1000),\n }),\n ];\n } catch (error) {\n if (error instanceof Error) return [error];\n return [\n new Error(\"An unknown error occurred. See the logs for details.\", {\n cause: error,\n }),\n ];\n }\n },\n /**\n * Process the Token request Response\n *\n * @see https://datatracker.ietf.org/doc/html/rfc8628#section-3.5\n */\n async processTokenResponse(\n response: Response,\n ): Promise<[OAuthError] | [null, TokenSet]> {\n const json = await response.json();\n const processed = TokenSet.safeParse(json);\n\n if (!processed.success) {\n return [\n new OAuthError(\n `Failed to parse token response: ${processed.error.message}`,\n json,\n ),\n ];\n }\n\n return [null, processed.data];\n },\n /**\n * Perform a Token Revocation Request.\n *\n * @see https://datatracker.ietf.org/doc/html/rfc7009#section-2.1\n * @see https://datatracker.ietf.org/doc/html/rfc7009#section-2.2\n */\n async revokeToken(token: string): Promise<OAuthError | void> {\n const response = await fetch(as.revocation_endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n \"user-agent\": USER_AGENT,\n },\n body: new URLSearchParams({ token, client_id: CLIENT_ID }),\n });\n\n if (response.ok) return;\n const json = await response.json();\n\n return new OAuthError(\"Revocation request failed\", json);\n },\n /**\n * Perform Refresh Token Request.\n *\n * @see https://datatracker.ietf.org/doc/html/rfc6749#section-6\n */\n async refreshToken(token: string): Promise<TokenSet> {\n const response = await fetch(as.token_endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n \"user-agent\": USER_AGENT,\n },\n body: new URLSearchParams({\n client_id: CLIENT_ID,\n grant_type: \"refresh_token\",\n refresh_token: token,\n }),\n });\n\n const [tokensError, tokenSet] = await this.processTokenResponse(response);\n if (tokensError) throw tokensError;\n return tokenSet;\n },\n /**\n * Perform Token Introspection Request.\n *\n * @see https://datatracker.ietf.org/doc/html/rfc7662#section-2.1\n */\n async introspectToken(\n token: string,\n ): Promise<z.infer<typeof IntrospectionResponse>> {\n const response = await fetch(as.introspection_endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n \"user-agent\": USER_AGENT,\n },\n body: new URLSearchParams({ token }),\n });\n\n const json = await response.json();\n const processed = IntrospectionResponse.safeParse(json);\n if (!processed.success) {\n throw new OAuthError(\n `Failed to parse introspection response: ${processed.error.message}`,\n json,\n );\n }\n\n return processed.data;\n },\n };\n}\n\nexport type OAuth = Awaited<ReturnType<typeof OAuth>>;\n\nconst TokenSet = z.object({\n /** The access token issued by the authorization server. */\n access_token: z.string(),\n /** The type of the token issued */\n token_type: z.literal(\"Bearer\"),\n /** The lifetime in seconds of the access token. */\n expires_in: z.number(),\n /** The refresh token, which can be used to obtain new access tokens. */\n refresh_token: z.string().optional(),\n /** The scope of the access token. */\n scope: z.string().optional(),\n});\n\ntype TokenSet = z.infer<typeof TokenSet>;\n\nconst OAuthErrorResponse = z.object({\n error: z.enum([\n \"invalid_request\",\n \"invalid_client\",\n \"invalid_grant\",\n \"unauthorized_client\",\n \"unsupported_grant_type\",\n \"invalid_scope\",\n \"server_error\",\n // Device Authorization Response Errors\n \"authorization_pending\",\n \"slow_down\",\n \"access_denied\",\n \"expired_token\",\n // Revocation Response Errors\n \"unsupported_token_type\",\n ]),\n error_description: z.string().optional(),\n error_uri: z.string().optional(),\n});\n\ntype OAuthErrorResponse = z.infer<typeof OAuthErrorResponse>;\n\nfunction processOAuthErrorResponse(\n json: unknown,\n): OAuthErrorResponse | TypeError {\n try {\n return OAuthErrorResponse.parse(json);\n } catch (error) {\n if (error instanceof z.ZodError) {\n return new TypeError(`Invalid OAuth error response: ${error.message}`);\n }\n return new TypeError(\"Failed to parse OAuth error response\");\n }\n}\n\nclass OAuthError extends Error {\n name = \"OAuthError\";\n code: OAuthErrorResponse[\"error\"];\n cause: Error;\n constructor(message: string, response: unknown) {\n super(message);\n const error = processOAuthErrorResponse(response);\n if (error instanceof TypeError) {\n const message = `Unexpected server response: ${JSON.stringify(response)}`;\n this.cause = new Error(message, { cause: error });\n this.code = \"server_error\";\n return;\n }\n let cause = error.error;\n if (error.error_description) cause += `: ${error.error_description}`;\n if (error.error_uri) cause += ` (${error.error_uri})`;\n\n this.cause = new Error(cause);\n this.code = error.error;\n }\n}\n\nexport function isOAuthError(error: unknown): error is OAuthError {\n return error instanceof OAuthError;\n}\n\nexport interface DeviceAuthorizationRequest {\n /** The device verification code. */\n device_code: string;\n /** The end-user verification code. */\n user_code: string;\n /**\n * The minimum amount of time in seconds that the client\n * SHOULD wait between polling requests to the token endpoint.\n */\n interval: number;\n /** The end-user verification URI on the authorization server. */\n verification_uri: string;\n /**\n * The end-user verification URI on the authorization server,\n * including the `user_code`, without redirection.\n */\n verification_uri_complete: string;\n /**\n * The absolute lifetime of the `device_code` and `user_code`.\n * Calculated from `expires_in`.\n */\n expiresAt: number;\n}\n"],"mappings":";;;;;;;AAIA,MAAM,aAAa,GAAG,WAAG,UAAU,CAAC,oBAAoBA,wBAAQ,QAC9D,QAAQ,QACT,GAAG,WAAG,UAAU,CAAC,IAAI,WAAG,MAAM,CAAC;AAEhC,MAAM,SAAS,IAAI,IAAI,qBAAqB;AAC5C,MAAM,YAAY;AAElB,MAAM,8BAA8BC,MAAE,OAAO;CAC3C,QAAQA,MAAE,QAAQ,CAAC,KAAK;CACxB,+BAA+BA,MAAE,QAAQ,CAAC,KAAK;CAC/C,gBAAgBA,MAAE,QAAQ,CAAC,KAAK;CAChC,qBAAqBA,MAAE,QAAQ,CAAC,KAAK;CACrC,UAAUA,MAAE,QAAQ,CAAC,KAAK;CAC1B,wBAAwBA,MAAE,QAAQ,CAAC,KAAK;CACzC,CAAC;AAEF,IAAIC;AAEJ,MAAM,sBAAsBD,MAAE,OAAO;CACnC,aAAaA,MAAE,QAAQ;CACvB,WAAWA,MAAE,QAAQ;CACrB,kBAAkBA,MAAE,QAAQ,CAAC,KAAK;CAClC,2BAA2BA,MAAE,QAAQ,CAAC,KAAK;CAC3C,YAAYA,MAA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