@scalar/cli 2.8.0 → 2.11.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.
Files changed (111) hide show
  1. package/README.md +84 -1076
  2. package/chunks/action-25QMCP5G.js +122 -0
  3. package/chunks/{action-354TUG4H.js → action-2VF6LODL.js} +20 -16
  4. package/chunks/{action-XIUO64C7.js → action-5I4XDPPG.js} +20 -14
  5. package/chunks/action-6M5PTDF6.js +100 -0
  6. package/chunks/{action-NVI5DWFP.js → action-73ELLN3T.js} +8 -11
  7. package/chunks/{action-Y6NXJQ4H.js → action-7H3AWCHX.js} +21 -16
  8. package/chunks/{action-LLH4QPXM.js → action-BRSLSOE5.js} +19 -18
  9. package/chunks/{action-EOAVVL52.js → action-CQQCKSNS.js} +17 -22
  10. package/chunks/action-D5QWDNQ2.js +65 -0
  11. package/chunks/{action-Y7OUGD56.js → action-DQDHBOLJ.js} +34 -31
  12. package/chunks/{action-5SK5NE7E.js → action-EYPYQQVM.js} +18 -23
  13. package/chunks/{action-YRX6SN5F.js → action-FMA5ECUA.js} +12 -10
  14. package/chunks/{action-7PEQXDWT.js → action-GXDJLF2G.js} +134 -25
  15. package/chunks/action-HUICEXJZ.js +75 -0
  16. package/chunks/action-IH6G77C5.js +38 -0
  17. package/chunks/{action-H3RTILLM.js → action-IIQMZVRJ.js} +1 -1
  18. package/chunks/action-IQM54ITT.js +164 -0
  19. package/chunks/{action-UIKH4SZX.js → action-J5TO3UJW.js} +32 -26
  20. package/chunks/{action-H6OUJWWM.js → action-KC3ZCNDR.js} +17 -22
  21. package/chunks/{action-6BYGBXRC.js → action-L7TMS3Q3.js} +44 -37
  22. package/chunks/{action-GWXLHL2Z.js → action-LAAHRDSR.js} +5 -4
  23. package/chunks/{action-FCAYFPVR.js → action-LR75GHBA.js} +14 -11
  24. package/chunks/action-MJMLQFLT.js +1552 -0
  25. package/chunks/action-NHU4CUKT.js +130 -0
  26. package/chunks/action-NKTFNFU7.js +64 -0
  27. package/chunks/{action-F7A2K74G.js → action-NMW5WPD2.js} +12 -16
  28. package/chunks/{action-VOFDW3U2.js → action-OTPXODUE.js} +8 -7
  29. package/chunks/{action-43YBNBDR.js → action-RPCDNGCI.js} +54 -39
  30. package/chunks/{action-QQZLPI42.js → action-RQCXSJPZ.js} +55 -27
  31. package/chunks/action-SOYSVG67.js +147 -0
  32. package/chunks/action-Y7EBKCUU.js +16 -0
  33. package/chunks/{action-WFDNRA7D.js → action-YN4TE7TG.js} +24 -23
  34. package/chunks/{action-AQRPFQKI.js → action-ZGNVWTHZ.js} +14 -12
  35. package/chunks/action-ZKKRPLDK.js +64 -0
  36. package/chunks/{action-HT2DJ34Z.js → action-ZUZL7R3H.js} +20 -15
  37. package/chunks/{actions-OGIVBQC7.js → actions-S6K76HCW.js} +46 -19
  38. package/chunks/{agent-ASPV3R5U.js → agent-IRNEV4K5.js} +46 -9
  39. package/chunks/{asyncapi-QNFKXHEI.js → asyncapi-WQPIQMEZ.js} +15 -10
  40. package/chunks/{build.action-NM6CAE5F.js → build.action-CLBVKFWD.js} +28 -24
  41. package/chunks/chunk-25XERWCE.js +1058 -0
  42. package/chunks/chunk-3RIUDHLG.js +467 -0
  43. package/chunks/{chunk-MLSZVVTT.js → chunk-3TFOA64C.js} +19 -8
  44. package/chunks/{chunk-HGOD6THU.js → chunk-4JKXZ5CF.js} +12 -25
  45. package/chunks/{chunk-C2KAWRIX.js → chunk-5ENKYZA4.js} +1 -1
  46. package/chunks/{chunk-W24BETFG.js → chunk-5L7V7RCH.js} +10 -10
  47. package/chunks/chunk-6PSYZO3U.js +24 -0
  48. package/chunks/{chunk-IMG35UXX.js → chunk-ALYM4ZB2.js} +1 -1
  49. package/chunks/chunk-AVZFSWPD.js +37 -0
  50. package/chunks/{chunk-5UHLAJQD.js → chunk-BQYVSPAI.js} +36 -10
  51. package/chunks/{chunk-XXSQUBXS.js → chunk-CSSTCHHF.js} +6212 -4642
  52. package/chunks/chunk-DFOZG7ZV.js +15 -0
  53. package/chunks/{chunk-22HYZ7LE.js → chunk-DQD2753S.js} +3 -3
  54. package/chunks/{action-F2ZJNURT.js → chunk-EBNFCIKS.js} +7 -10
  55. package/chunks/{chunk-EXY3ZTV4.js → chunk-F3OPMYME.js} +143 -301
  56. package/chunks/{chunk-FDC2IESH.js → chunk-FG5AOTDN.js} +8519 -14702
  57. package/chunks/chunk-GKCVATQJ.js +92 -0
  58. package/chunks/{chunk-PH3WFNXJ.js → chunk-GMHIK5K2.js} +1 -1
  59. package/chunks/{chunk-GTV2BVXV.js → chunk-GYR5E6RB.js} +2 -2
  60. package/chunks/{chunk-OJ2EWIJH.js → chunk-HZN6IIPZ.js} +11 -6
  61. package/chunks/{chunk-IKT5F47M.js → chunk-I57ID5K7.js} +24 -11
  62. package/chunks/{chunk-BPGFSSUH.js → chunk-KOD2HX5I.js} +1 -1
  63. package/chunks/{chunk-L3UXDCBI.js → chunk-LOLVJNI5.js} +4 -4
  64. package/chunks/{chunk-KCCFN4F7.js → chunk-MN2AFJXM.js} +36 -29
  65. package/chunks/{chunk-UXJ753NV.js → chunk-N5CJ5MTY.js} +5 -13
  66. package/chunks/chunk-NAC63XJF.js +10 -0
  67. package/chunks/{chunk-2OCWX42S.js → chunk-NWJ37GI2.js} +166 -22
  68. package/chunks/{chunk-3ZJYGGAA.js → chunk-ORCUZITN.js} +1 -1
  69. package/chunks/chunk-QMLRYD76.js +24 -0
  70. package/chunks/{chunk-KKRGBXCE.js → chunk-SEURG74P.js} +303 -209
  71. package/chunks/{chunk-R5LK6VPY.js → chunk-SOV4POMS.js} +370 -264
  72. package/chunks/chunk-T34TL6KL.js +222 -0
  73. package/chunks/{chunk-5DEU2DVL.js → chunk-U6VE6JOS.js} +3 -15
  74. package/chunks/{chunk-YILQODZF.js → chunk-UFSFY7Z4.js} +23 -20
  75. package/chunks/{chunk-6YPQGVF4.js → chunk-ULRJZXMS.js} +1 -1
  76. package/chunks/chunk-US54KYOJ.js +131 -0
  77. package/chunks/chunk-V6LUKXBV.js +37 -0
  78. package/chunks/{chunk-5JLVQVKO.js → chunk-VRZSDUZK.js} +190 -152
  79. package/chunks/chunk-VUXPDHTQ.js +22 -0
  80. package/chunks/chunk-XP5UM7SF.js +21 -0
  81. package/chunks/chunk-Y6XGC4K5.js +311 -0
  82. package/chunks/{create.action-FUQ2BVJA.js → create.action-ITEOQ644.js} +34 -30
  83. package/chunks/{delete.action-47E66R3I.js → delete.action-77MFPLUN.js} +30 -26
  84. package/chunks/{delete.action-BTDFH7WY.js → delete.action-C6VX4S5Q.js} +30 -26
  85. package/chunks/{get.action-XC7KC2JO.js → get.action-3BP4FHZC.js} +20 -14
  86. package/chunks/get.action-LNBOWUVE.js +95 -0
  87. package/chunks/list.action-6CRFQPJT.js +156 -0
  88. package/chunks/list.action-KR5YIDR4.js +126 -0
  89. package/chunks/{publish.action-OS27XOX4.js → publish.action-YBORRPBM.js} +49 -42
  90. package/chunks/query-WKATAJJ6.js +129 -0
  91. package/chunks/scripts-6CI6U32J.js +102 -0
  92. package/chunks/{update.action-AEIBLCWD.js → update.action-O7TSXDGV.js} +34 -27
  93. package/chunks/{update.action-ZMS4CQ3T.js → update.action-QZI7M2MV.js} +34 -27
  94. package/index.js +579 -382
  95. package/package.json +15 -14
  96. package/skills/scalar-cli/SKILL.md +52 -46
  97. package/template.md +71 -136
  98. package/chunks/action-CA4QYPI6.js +0 -125
  99. package/chunks/action-JAHFRYWZ.js +0 -423
  100. package/chunks/action-KTYOCA2V.js +0 -229
  101. package/chunks/action-LEUD5P2U.js +0 -92
  102. package/chunks/action-LXGXKXZZ.js +0 -72
  103. package/chunks/action-W3C53GPH.js +0 -54
  104. package/chunks/action-YLF2G4G5.js +0 -37
  105. package/chunks/chunk-6XWCMJDB.js +0 -404
  106. package/chunks/chunk-K74E42RV.js +0 -7311
  107. package/chunks/chunk-QVQ4PNVL.js +0 -610
  108. package/chunks/chunk-XEDGMZJD.js +0 -366
  109. package/chunks/list.action-LXKEUYKO.js +0 -116
  110. package/chunks/list.action-OFGLMRE7.js +0 -95
  111. package/docs.html +0 -6245
@@ -0,0 +1,467 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ config
4
+ } from "./chunk-N5CJ5MTY.js";
5
+ import {
6
+ roleSchema
7
+ } from "./chunk-BQYVSPAI.js";
8
+ import {
9
+ output
10
+ } from "./chunk-T5HJUAWB.js";
11
+ import {
12
+ emailSchema,
13
+ external_exports,
14
+ zod_default
15
+ } from "./chunk-I57ID5K7.js";
16
+
17
+ // ../../packages/entities/dist/token/token.js
18
+ var accessTokenPayloadSchema = external_exports.object({
19
+ userIndex: external_exports.string(),
20
+ userUid: external_exports.string().brand(),
21
+ // Brand only — `.brand()` keeps the runtime `z.string()` validation (no
22
+ // `.min()`), so parsed tokens stay byte-identical while gaining the Team brand.
23
+ teamUid: external_exports.string().brand(),
24
+ email: emailSchema.nullable(),
25
+ role: roleSchema.optional(),
26
+ exp: external_exports.number().int()
27
+ }).meta({ id: "access-token-payload" });
28
+ var healthTokenPayloadSchema = external_exports.object({
29
+ svc: external_exports.string().optional(),
30
+ iat: external_exports.number().int().optional(),
31
+ exp: external_exports.number().int()
32
+ }).meta({ id: "health-token-payload" });
33
+ var edgeCacheSyncTokenPayloadSchema = external_exports.object({
34
+ svc: external_exports.literal("watcher-edge-cache-sync"),
35
+ iat: external_exports.number().int().optional(),
36
+ exp: external_exports.number().int()
37
+ }).meta({
38
+ id: "edge-cache-sync-token-payload"
39
+ });
40
+ var personalTokenPayloadSchema = external_exports.object({
41
+ uid: external_exports.string(),
42
+ teamUid: external_exports.string(),
43
+ userIndex: external_exports.string(),
44
+ iat: external_exports.number(),
45
+ exp: external_exports.number()
46
+ }).meta({ id: "personal-token-payload" });
47
+
48
+ // ../../packages/entities/dist/token/payload.js
49
+ var tokenResponseSchema = external_exports.object({
50
+ refreshToken: external_exports.string(),
51
+ accessToken: external_exports.string()
52
+ }).meta({ id: "token-response" });
53
+
54
+ // ../../node_modules/.pnpm/jose@5.9.6/node_modules/jose/dist/node/esm/runtime/base64url.js
55
+ import { Buffer as Buffer2 } from "node:buffer";
56
+
57
+ // ../../node_modules/.pnpm/jose@5.9.6/node_modules/jose/dist/node/esm/lib/buffer_utils.js
58
+ var encoder = new TextEncoder();
59
+ var decoder = new TextDecoder();
60
+ var MAX_INT32 = 2 ** 32;
61
+
62
+ // ../../node_modules/.pnpm/jose@5.9.6/node_modules/jose/dist/node/esm/runtime/base64url.js
63
+ function normalize(input) {
64
+ let encoded = input;
65
+ if (encoded instanceof Uint8Array) {
66
+ encoded = decoder.decode(encoded);
67
+ }
68
+ return encoded;
69
+ }
70
+ var decode = (input) => new Uint8Array(Buffer2.from(normalize(input), "base64url"));
71
+
72
+ // ../../node_modules/.pnpm/jose@5.9.6/node_modules/jose/dist/node/esm/util/errors.js
73
+ var JOSEError = class extends Error {
74
+ static code = "ERR_JOSE_GENERIC";
75
+ code = "ERR_JOSE_GENERIC";
76
+ constructor(message, options) {
77
+ super(message, options);
78
+ this.name = this.constructor.name;
79
+ Error.captureStackTrace?.(this, this.constructor);
80
+ }
81
+ };
82
+ var JWTInvalid = class extends JOSEError {
83
+ static code = "ERR_JWT_INVALID";
84
+ code = "ERR_JWT_INVALID";
85
+ };
86
+
87
+ // ../../node_modules/.pnpm/jose@5.9.6/node_modules/jose/dist/node/esm/lib/is_object.js
88
+ function isObjectLike(value) {
89
+ return typeof value === "object" && value !== null;
90
+ }
91
+ function isObject(input) {
92
+ if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
93
+ return false;
94
+ }
95
+ if (Object.getPrototypeOf(input) === null) {
96
+ return true;
97
+ }
98
+ let proto = input;
99
+ while (Object.getPrototypeOf(proto) !== null) {
100
+ proto = Object.getPrototypeOf(proto);
101
+ }
102
+ return Object.getPrototypeOf(input) === proto;
103
+ }
104
+
105
+ // ../../node_modules/.pnpm/jose@5.9.6/node_modules/jose/dist/node/esm/util/base64url.js
106
+ var decode2 = decode;
107
+
108
+ // ../../node_modules/.pnpm/jose@5.9.6/node_modules/jose/dist/node/esm/util/decode_protected_header.js
109
+ function decodeProtectedHeader(token) {
110
+ let protectedB64u;
111
+ if (typeof token === "string") {
112
+ const parts = token.split(".");
113
+ if (parts.length === 3 || parts.length === 5) {
114
+ ;
115
+ [protectedB64u] = parts;
116
+ }
117
+ } else if (typeof token === "object" && token) {
118
+ if ("protected" in token) {
119
+ protectedB64u = token.protected;
120
+ } else {
121
+ throw new TypeError("Token does not contain a Protected Header");
122
+ }
123
+ }
124
+ try {
125
+ if (typeof protectedB64u !== "string" || !protectedB64u) {
126
+ throw new Error();
127
+ }
128
+ const result = JSON.parse(decoder.decode(decode2(protectedB64u)));
129
+ if (!isObject(result)) {
130
+ throw new Error();
131
+ }
132
+ return result;
133
+ } catch {
134
+ throw new TypeError("Invalid Token or Protected Header formatting");
135
+ }
136
+ }
137
+
138
+ // ../../node_modules/.pnpm/jose@5.9.6/node_modules/jose/dist/node/esm/util/decode_jwt.js
139
+ function decodeJwt(jwt) {
140
+ if (typeof jwt !== "string")
141
+ throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
142
+ const { 1: payload, length } = jwt.split(".");
143
+ if (length === 5)
144
+ throw new JWTInvalid("Only JWTs using Compact JWS serialization can be decoded");
145
+ if (length !== 3)
146
+ throw new JWTInvalid("Invalid JWT");
147
+ if (!payload)
148
+ throw new JWTInvalid("JWTs must contain a payload");
149
+ let decoded;
150
+ try {
151
+ decoded = decode2(payload);
152
+ } catch {
153
+ throw new JWTInvalid("Failed to base64url decode the payload");
154
+ }
155
+ let result;
156
+ try {
157
+ result = JSON.parse(decoder.decode(decoded));
158
+ } catch {
159
+ throw new JWTInvalid("Failed to parse the decoded payload as JSON");
160
+ }
161
+ if (!isObject(result))
162
+ throw new JWTInvalid("Invalid JWT Claims Set");
163
+ return result;
164
+ }
165
+
166
+ // ../../packages/tokens/dist/error.js
167
+ function TokenError(msg, code) {
168
+ const err = new Error(msg);
169
+ err.code = code;
170
+ return err;
171
+ }
172
+
173
+ // ../../packages/tokens/dist/index.js
174
+ function validatePayload(data, schema) {
175
+ const result = schema.safeParse(data);
176
+ if (!result.success) {
177
+ console.error("Invalid token payload:");
178
+ console.error(result.error.issues);
179
+ throw TokenError("Invalid token payload", "invalid-payload");
180
+ }
181
+ return result.data;
182
+ }
183
+ function decode3(token, schema = external_exports.any()) {
184
+ return validatePayload(decodeJwt(token), schema);
185
+ }
186
+
187
+ // src/helpers/metadata.ts
188
+ import fs from "node:fs/promises";
189
+ import os from "node:os";
190
+ import path from "node:path";
191
+ var SCALAR_METADATA_FILE_NAME = ".scalar-config";
192
+ var METADATA_FILE_PATH = path.join(
193
+ os.homedir(),
194
+ SCALAR_METADATA_FILE_NAME
195
+ );
196
+ var authSchema = external_exports.union([
197
+ external_exports.object({
198
+ accessToken: external_exports.string(),
199
+ refreshToken: external_exports.string()
200
+ }),
201
+ external_exports.object({
202
+ accessToken: external_exports.string(),
203
+ personalToken: external_exports.string()
204
+ })
205
+ ]);
206
+ var metadataSchema = external_exports.object({
207
+ lastUpdateCheck: external_exports.number(),
208
+ lastKnownVersion: external_exports.string(),
209
+ auth: authSchema.nullable().default(null)
210
+ });
211
+ var metadataCache = null;
212
+ var getMetadataMtimeMs = async () => (await fs.stat(METADATA_FILE_PATH).catch(() => null))?.mtimeMs ?? null;
213
+ var writeQueue = Promise.resolve();
214
+ var setMetadata = async (metadata) => {
215
+ const write = writeQueue.then(async () => {
216
+ const currentMetadata = await getMetadata();
217
+ const updatedMetadata = { ...currentMetadata, ...metadata };
218
+ const tmpPath = `${METADATA_FILE_PATH}.${process.pid}.tmp`;
219
+ await fs.writeFile(tmpPath, JSON.stringify(updatedMetadata), {
220
+ mode: 384
221
+ });
222
+ await fs.chmod(tmpPath, 384);
223
+ await fs.rename(tmpPath, METADATA_FILE_PATH);
224
+ metadataCache = {
225
+ mtimeMs: await getMetadataMtimeMs(),
226
+ data: updatedMetadata
227
+ };
228
+ });
229
+ writeQueue = write.catch(() => {
230
+ });
231
+ return write;
232
+ };
233
+ var fileExists = async (path2) => !!await fs.stat(path2).catch(() => false);
234
+ var readMetadataFile = async () => {
235
+ const metadata = await fileExists(METADATA_FILE_PATH) ? await fs.readFile(METADATA_FILE_PATH, { encoding: "utf-8" }) : "{}";
236
+ try {
237
+ return metadataSchema.partial().parse(JSON.parse(metadata));
238
+ } catch {
239
+ return {};
240
+ }
241
+ };
242
+ var getMetadata = async () => {
243
+ const mtimeMs = await getMetadataMtimeMs();
244
+ if (metadataCache && metadataCache.mtimeMs === mtimeMs) {
245
+ return metadataCache.data;
246
+ }
247
+ const data = await readMetadataFile();
248
+ metadataCache = { mtimeMs, data };
249
+ return data;
250
+ };
251
+
252
+ // ../../packages/oauth/dist/scopes.js
253
+ var SCOPES = [
254
+ "consumer:docs",
255
+ "consumer:registry",
256
+ "consumer:mcp",
257
+ "consumer:sdk",
258
+ "platform:read",
259
+ "platform:write",
260
+ "platform:admin",
261
+ /** A first-party session: the dashboard's, the CLI's, a personal token's. Never granted to another client */
262
+ "platform:session"
263
+ ];
264
+ var PLATFORM_ROLES = ["owner", "admin", "editor", "viewer"];
265
+
266
+ // ../../packages/oauth/dist/claims.js
267
+ var ACCESS_TOKEN_TYP = "at+jwt";
268
+ var ACCESS_TOKEN_TTL_SECONDS = 15 * 60;
269
+ var PERSONAL_TOKEN_ACCESS_TTL_SECONDS = 12 * 60 * 60;
270
+ var address = external_exports.string().regex(/^[^@\s]+@[^@\s]+$/);
271
+ var commonClaims = {
272
+ /** The host the flow ran on: the shared auth host, or a customer's own domain */
273
+ iss: external_exports.url(),
274
+ aud: external_exports.union([external_exports.string().min(1), external_exports.array(external_exports.string().min(1)).min(1)]),
275
+ sub: external_exports.string().min(1),
276
+ exp: external_exports.number().int(),
277
+ iat: external_exports.number().int(),
278
+ client_id: external_exports.string().min(1),
279
+ /**
280
+ * Granted scopes. An array under `scp`, not a `scope` string: the apps
281
+ * behind the exchange bridge validate `scope` against core's old
282
+ * `read | write | admin` values and would reject the token.
283
+ */
284
+ scp: external_exports.array(external_exports.enum(SCOPES)),
285
+ /** The refresh family the token came from, or the credential for one that has none */
286
+ fid: external_exports.string().min(1)
287
+ };
288
+ var consumerClaimsSchema = external_exports.object({
289
+ ...commonClaims,
290
+ kind: external_exports.literal("consumer"),
291
+ email: address,
292
+ /** The namespace signed in to, without the `@` */
293
+ ns: external_exports.string().min(1),
294
+ teamUid: external_exports.string().min(1),
295
+ /**
296
+ * What the reader was admitted to: one docs project, registry record or
297
+ * MCP server environment, or the namespace's own pages. Several of these
298
+ * share a host and so an audience, and access is granted to each on its
299
+ * own, so a resource server checks this against what is being read.
300
+ */
301
+ res: external_exports.object({
302
+ kind: external_exports.enum(["project", "registry", "mcp", "namespace"]),
303
+ /** For `mcp`, the server uid; an installation uuid when `environment` is absent. */
304
+ uid: external_exports.string().min(1).optional(),
305
+ /** For `mcp`, the environment slug of the server named by `uid`. */
306
+ environment: external_exports.string().min(1).optional()
307
+ }),
308
+ /** How the person proved the address */
309
+ via: external_exports.enum(["email", "google", "microsoft", "sso", "scalar"]),
310
+ /** The SAML connection that vouched, when `via` is `sso` */
311
+ idp: external_exports.string().min(1).optional()
312
+ });
313
+ var platformClaimsSchema = external_exports.object({
314
+ ...commonClaims,
315
+ kind: external_exports.literal("platform"),
316
+ userIndex: external_exports.string(),
317
+ userUid: external_exports.string().min(1),
318
+ teamUid: external_exports.string().min(1),
319
+ email: address.nullable(),
320
+ /** The member's role, already lowered to what the scopes allow */
321
+ role: external_exports.enum(PLATFORM_ROLES).optional(),
322
+ /** The service a token was exchanged for, when one acts for the person (RFC 8693) */
323
+ act: external_exports.object({ sub: external_exports.string().min(1) }).optional()
324
+ });
325
+ var accessTokenClaimsSchema = external_exports.discriminatedUnion("kind", [
326
+ consumerClaimsSchema,
327
+ platformClaimsSchema
328
+ ]);
329
+
330
+ // ../../packages/oauth/dist/verify.js
331
+ var MAX_AGE_MS = 5 * 6e4;
332
+ function isAccessToken(token) {
333
+ try {
334
+ return decodeProtectedHeader(token).typ === ACCESS_TOKEN_TYP;
335
+ } catch {
336
+ return false;
337
+ }
338
+ }
339
+
340
+ // src/helpers/auth.ts
341
+ var claimsOf = (accessToken) => {
342
+ const { email, role, teamUid } = decode3(accessToken, accessTokenPayloadSchema);
343
+ return { email, role, teamUid };
344
+ };
345
+ var claimsIfReadable = (accessToken) => {
346
+ try {
347
+ return claimsOf(accessToken);
348
+ } catch {
349
+ return {};
350
+ }
351
+ };
352
+ var eventListeners = [];
353
+ var addEventListener = (callback) => {
354
+ eventListeners.push(callback);
355
+ };
356
+ var fireCallbacks = (auth) => eventListeners.forEach((callback) => callback(auth));
357
+ var setAuthData = async (authData) => {
358
+ await setMetadata({ auth: authData });
359
+ fireCallbacks({ ...authData, ...claimsIfReadable(authData.accessToken) });
360
+ };
361
+ var RENEWAL_MARGIN_MS = 6e4;
362
+ var SESSION_EXPIRED = "Your session has expired. Run `scalar auth login` to log in again.";
363
+ var SESSION_MOVED = "Your session moved to another team while this command ran. Run it again.";
364
+ var needsRenewal = (accessToken, marginMs = 0) => {
365
+ if (!isAccessToken(accessToken)) return true;
366
+ try {
367
+ const { exp } = decode3(accessToken, accessTokenPayloadSchema);
368
+ return exp * 1e3 - marginMs < Date.now();
369
+ } catch {
370
+ return true;
371
+ }
372
+ };
373
+ var renewAuth = async (auth) => "refreshToken" in auth ? refreshToken(auth.refreshToken) : generateAccessByPersonalToken({ personalToken: auth.personalToken });
374
+ var getAuthData = async (opts) => {
375
+ const { noExit } = opts ?? {};
376
+ const { auth } = await getMetadata();
377
+ if (!auth) {
378
+ if (noExit) throw new Error("Authentication required");
379
+ return output.error().title("Authentication required").message("Run `scalar auth login` before running this command.").exit("error");
380
+ }
381
+ if (!needsRenewal(auth.accessToken)) {
382
+ return { ...auth, ...claimsOf(auth.accessToken), addEventListener };
383
+ }
384
+ try {
385
+ const renewed = await renewAuth(auth);
386
+ return { ...renewed, ...claimsOf(renewed.accessToken), addEventListener };
387
+ } catch {
388
+ if (noExit) throw new Error(SESSION_EXPIRED);
389
+ return output.error().title("Session expired").message(SESSION_EXPIRED).exit("error");
390
+ }
391
+ };
392
+ var clearAuthData = async () => {
393
+ await setMetadata({ auth: null });
394
+ };
395
+ var CLI_CLIENT_ID = "scalar-cli";
396
+ var tokenResponseSchema2 = zod_default.object({
397
+ access_token: zod_default.string(),
398
+ refresh_token: zod_default.string().optional()
399
+ });
400
+ var requestTokens = async (form) => {
401
+ const result = await fetch(`${config.auth.origin}/_scalar/oauth/token`, {
402
+ method: "POST",
403
+ body: new URLSearchParams(form),
404
+ // Fail fast instead of hanging every authed command on a slow network
405
+ signal: AbortSignal.timeout(1e4)
406
+ });
407
+ const body = await result.json().catch(() => ({}));
408
+ if (!result.ok) {
409
+ throw new Error(body.error_description ?? "Could not get a token");
410
+ }
411
+ return tokenResponseSchema2.parse(body);
412
+ };
413
+ var refreshToken = async (token, teamUid) => {
414
+ const tokens = await requestTokens({
415
+ grant_type: "refresh_token",
416
+ refresh_token: token,
417
+ client_id: CLI_CLIENT_ID,
418
+ ...teamUid && { team: teamUid }
419
+ });
420
+ const auth = {
421
+ accessToken: tokens.access_token,
422
+ refreshToken: tokens.refresh_token ?? token
423
+ };
424
+ await setAuthData(auth);
425
+ return auth;
426
+ };
427
+ var generateAccessByPersonalToken = async ({
428
+ personalToken
429
+ }) => {
430
+ const tokens = await requestTokens({
431
+ grant_type: "client_credentials",
432
+ client_secret: personalToken
433
+ });
434
+ const auth = { accessToken: tokens.access_token, personalToken };
435
+ await setAuthData(auth);
436
+ return auth;
437
+ };
438
+ var logout = async () => {
439
+ const { auth } = await getMetadata();
440
+ if (auth && "refreshToken" in auth) {
441
+ await fetch(`${config.auth.origin}/_scalar/oauth/revoke`, {
442
+ method: "POST",
443
+ body: new URLSearchParams({ token: auth.refreshToken }),
444
+ signal: AbortSignal.timeout(1e4)
445
+ }).catch(() => void 0);
446
+ }
447
+ await clearAuthData();
448
+ };
449
+
450
+ export {
451
+ accessTokenPayloadSchema,
452
+ decode3 as decode,
453
+ setMetadata,
454
+ getMetadata,
455
+ setAuthData,
456
+ RENEWAL_MARGIN_MS,
457
+ SESSION_EXPIRED,
458
+ SESSION_MOVED,
459
+ needsRenewal,
460
+ renewAuth,
461
+ getAuthData,
462
+ CLI_CLIENT_ID,
463
+ requestTokens,
464
+ refreshToken,
465
+ generateAccessByPersonalToken,
466
+ logout
467
+ };
@@ -1,8 +1,9 @@
1
1
  import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
2
  import {
3
+ emailAllowanceSchema,
3
4
  teamImageSchema,
4
5
  teamNameSchema
5
- } from "./chunk-5UHLAJQD.js";
6
+ } from "./chunk-BQYVSPAI.js";
6
7
  import {
7
8
  brandedUid,
8
9
  emailSchema,
@@ -11,7 +12,7 @@ import {
11
12
  mintUid,
12
13
  timestampSchema,
13
14
  zod_default
14
- } from "./chunk-IKT5F47M.js";
15
+ } from "./chunk-I57ID5K7.js";
15
16
 
16
17
  // ../../packages/entities/dist/user/bitbucket.js
17
18
  var userBitbucketSchema = entitySchema.extend({
@@ -21,6 +22,12 @@ var userBitbucketSchema = entitySchema.extend({
21
22
  refreshExpiry: timestampSchema
22
23
  }).meta({ id: "user-bitbucket" });
23
24
 
25
+ // ../../packages/entities/dist/user/forgejo.js
26
+ var userForgejoSchema = entitySchema.extend({
27
+ /** Personal access token with repository read and write scope */
28
+ token: external_exports.string()
29
+ }).meta({ id: "user-forgejo" });
30
+
24
31
  // ../../packages/entities/dist/user/github.js
25
32
  var userGithubSchema = entitySchema.extend({
26
33
  token: zod_default.string(),
@@ -32,6 +39,7 @@ var userGithubSchema = entitySchema.extend({
32
39
  // ../../packages/entities/dist/user/password.js
33
40
  var userPasswordSchema = entitySchema.extend({
34
41
  passwordHash: external_exports.string().nullable().default(null),
42
+ passwordSetAt: external_exports.number().int().nullable().default(null),
35
43
  salt: external_exports.string().nullable().default(null),
36
44
  password: external_exports.string().nullable().default(null),
37
45
  passwordDeprecatedExp: external_exports.number().nullable().default(null)
@@ -70,19 +78,22 @@ var teamRefSchema = zod_default.object({
70
78
  var userSchema = entitySchema.extend({
71
79
  /** Own uid, branded so it cannot be confused with another entity's uid */
72
80
  uid: brandedUid().default(mintUid).meta({
73
- default: "nanoid()"
81
+ default: void 0
74
82
  }),
75
- theme: zod_default.string().optional(),
83
+ theme: zod_default.string().optional().meta({ examples: ["default"] }),
76
84
  /** Email or other unique token identifier for performant auth lookup */
77
85
  userIndex: zod_default.string().overwrite((s) => s.toLowerCase()),
78
86
  /** Federated auth provided must have a linked email */
79
87
  email: emailSchema,
80
88
  teams: teamRefSchema.array(),
81
- activeTeamId: zod_default.string().brand().nullable(),
82
- hasGithub: zod_default.boolean().optional().default(false),
89
+ activeTeamId: zod_default.string().brand().nullable().meta({ examples: ["GakgbKJ5m9gl0JDMbcJqL"] }),
90
+ hasGithub: zod_default.boolean().optional().default(false).meta({ examples: [true] }),
83
91
  hasBitbucket: zod_default.boolean().optional().default(false),
84
- /** Forgejo personal access token for git operations */
85
- forgejoToken: zod_default.string().optional()
92
+ /**
93
+ * Invite emails this user has sent from teams without a paid plan, in the
94
+ * current day and month.
95
+ */
96
+ emailAllowance: emailAllowanceSchema.optional()
86
97
  }).meta({ id: "user" });
87
98
 
88
99
  export {
@@ -1,7 +1,7 @@
1
1
  import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
2
  import {
3
- detectManagedDocType
4
- } from "./chunk-KCCFN4F7.js";
3
+ safeNormalize
4
+ } from "./chunk-QMLRYD76.js";
5
5
  import {
6
6
  isUrl
7
7
  } from "./chunk-4ORL4MST.js";
@@ -23,23 +23,13 @@ var printSpecificationBanner = (result) => {
23
23
  );
24
24
  output.info().title(
25
25
  `${as.white.bold(schema?.info?.title)} ${as.grey(`(OpenAPI v${version})`)}`
26
- ).title(as.grey(`${pathsCount} paths, ${operationsCount} operations`)).print();
26
+ ).title(
27
+ as.grey(
28
+ `${pathsCount} ${pathsCount === 1 ? "path" : "paths"}, ${operationsCount} ${operationsCount === 1 ? "operation" : "operations"}`
29
+ )
30
+ ).print();
27
31
  };
28
32
 
29
- // src/domains/document/helpers/safe-normalize.ts
30
- import { normalize } from "@scalar/json-magic/helpers/normalize";
31
- var safeNormalize = (value) => {
32
- try {
33
- return normalize(value);
34
- } catch {
35
- return void 0;
36
- }
37
- };
38
-
39
- // src/domains/document/helpers/document-type.ts
40
- var isAsyncApiDocument = (document) => detectManagedDocType(document) === "asyncapi";
41
- var isAsyncApiContent = (content) => content.includes("asyncapi") && isAsyncApiDocument(safeNormalize(content));
42
-
43
33
  // src/domains/document/helpers/is-document.ts
44
34
  var isDocument = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
45
35
 
@@ -51,12 +41,12 @@ var getFileOrUrl = async (input) => {
51
41
  if (isUrl(input)) {
52
42
  const response = await fetch(input);
53
43
  if (!response.ok) {
54
- return output.error().title("Failed to fetch from URL.").exit("error");
44
+ return output.error().title("Could not fetch the API description from the URL").exit("error");
55
45
  }
56
46
  return await response.text();
57
47
  }
58
48
  if (!fs.existsSync(input)) {
59
- return output.error().title("Could not read file.").exit("error");
49
+ return output.error().title("Could not read the API description file").exit("error");
60
50
  }
61
51
  return fs.readFileSync(input, "utf-8");
62
52
  };
@@ -64,14 +54,14 @@ var loadOpenApiDocument = async (content) => {
64
54
  try {
65
55
  const document = safeNormalize(content);
66
56
  if (!isDocument(document)) {
67
- throw new Error("Could not parse an OpenAPI document.");
57
+ throw new Error("Could not parse the OpenAPI description.");
68
58
  }
69
59
  if (isDocument(document.info) && typeof document.info.version !== "string") {
70
60
  document.info.version = "0.1.0";
71
61
  }
72
62
  const result = validate(document);
73
63
  if (!result.valid) {
74
- output.warn().title("File does not match the OpenAPI specification.").print();
64
+ output.warn().title("API description does not match the OpenAPI specification").print();
75
65
  result.errors.forEach((error) => {
76
66
  output.warn().title(
77
67
  error.path ? `${error.message} (${error.path})` : error.message
@@ -86,7 +76,7 @@ var loadOpenApiDocument = async (content) => {
86
76
  schema: result.schema
87
77
  };
88
78
  } catch (error) {
89
- output.error().title(error ? as2.red(error.toString()) : "Unknown error.").print();
79
+ output.error().title(error ? as2.red(error.toString()) : "An unexpected error occurred").print();
90
80
  const message = typeof error === "object" && error !== null && "message" in error ? String(error.message) : "Unknown error";
91
81
  return {
92
82
  valid: false,
@@ -105,9 +95,6 @@ var loadOpenApiDocument = async (content) => {
105
95
 
106
96
  export {
107
97
  printSpecificationBanner,
108
- safeNormalize,
109
- isAsyncApiDocument,
110
- isAsyncApiContent,
111
98
  isDocument,
112
99
  getFileOrUrl,
113
100
  loadOpenApiDocument
@@ -1,6 +1,6 @@
1
1
  import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
2
 
3
- // ../../node_modules/.pnpm/@scalar+helpers@0.15.0/node_modules/@scalar/helpers/dist/types/result.js
3
+ // ../../node_modules/.pnpm/@scalar+helpers@0.16.1/node_modules/@scalar/helpers/dist/types/result.js
4
4
  var ok = (data) => ({ ok: true, data });
5
5
  var err = (error, message) => ({
6
6
  ok: false,