@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
@@ -1,610 +0,0 @@
1
- import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
- import {
3
- config
4
- } from "./chunk-UXJ753NV.js";
5
- import {
6
- TeamUserRole,
7
- roleSchema
8
- } from "./chunk-5UHLAJQD.js";
9
- import {
10
- isUrl
11
- } from "./chunk-4ORL4MST.js";
12
- import {
13
- output
14
- } from "./chunk-T5HJUAWB.js";
15
- import {
16
- emailSchema,
17
- entitySchema,
18
- external_exports,
19
- nanoidSchema,
20
- timestampSchema,
21
- zod_default
22
- } from "./chunk-IKT5F47M.js";
23
-
24
- // src/helpers/node-version.ts
25
- import semver from "semver";
26
- function checkNodeVersion() {
27
- const currentVersion = process.version;
28
- if (!semver.satisfies(currentVersion, ">=24")) {
29
- output.error().title("Node.js version incompatible").message(
30
- `Current Node.js version: ${currentVersion}
31
- Minimum required version: ${">=24"}
32
- Please upgrade your Node.js version and try again.
33
- Visit https://nodejs.org to download the latest version.`
34
- ).exit("error");
35
- }
36
- }
37
-
38
- // ../../packages/entities/dist/oauth/scopes.js
39
- var OAUTH_SCOPES = ["read", "write", "admin"];
40
- var oauthScopeSchema = external_exports.enum(OAUTH_SCOPES).meta({ id: "oauth-scope" });
41
- var roleRank = {
42
- [TeamUserRole.Viewer]: 0,
43
- [TeamUserRole.Editor]: 1,
44
- [TeamUserRole.Admin]: 2,
45
- [TeamUserRole.Owner]: 3
46
- };
47
- var oauthScopeRoleCeiling = {
48
- read: TeamUserRole.Viewer,
49
- write: TeamUserRole.Editor,
50
- admin: TeamUserRole.Admin
51
- };
52
-
53
- // ../../packages/entities/dist/oauth/client.js
54
- var oauthClientTypeSchema = external_exports.enum(["confidential", "public"]).meta({ id: "oauth-client-type" });
55
- var oauthClientSchema = external_exports.object({
56
- /** Doubles as the OAuth `client_id` */
57
- uid: nanoidSchema,
58
- teamUid: nanoidSchema,
59
- name: external_exports.string().trim().min(1).max(100),
60
- type: oauthClientTypeSchema,
61
- /**
62
- * sha256 hex digest of the client secret, confidential clients only. The
63
- * plaintext is shown once at creation and never stored.
64
- */
65
- secretHash: external_exports.string().optional(),
66
- redirectUris: external_exports.array(external_exports.string().max(2048)).min(1).max(10),
67
- /** Scopes the client may request; the strongest sets its ceiling */
68
- allowedScopes: external_exports.array(oauthScopeSchema).min(1),
69
- createdBy: nanoidSchema,
70
- createdAt: timestampSchema
71
- }).meta({ id: "oauth-client" });
72
- var oauthClientPublicSchema = oauthClientSchema.pick({ uid: true, name: true, type: true }).meta({ id: "oauth-client-public" });
73
-
74
- // ../../packages/entities/dist/oauth/api.js
75
- var oauthAuthorizeParamsSchema = external_exports.object({
76
- client_id: external_exports.string().max(256).optional(),
77
- redirect_uri: external_exports.string().max(2048).optional(),
78
- response_type: external_exports.string().max(32).optional(),
79
- scope: external_exports.string().max(256).optional(),
80
- state: external_exports.string().max(1024).optional(),
81
- code_challenge: external_exports.string().max(256).optional(),
82
- code_challenge_method: external_exports.string().max(32).optional()
83
- }).meta({ id: "oauth-authorize-params" });
84
- var oauthAuthorizeResultSchema = external_exports.discriminatedUnion("status", [
85
- external_exports.object({ status: external_exports.literal("ok"), uid: nanoidSchema }),
86
- external_exports.object({
87
- status: external_exports.literal("error"),
88
- error: external_exports.string(),
89
- errorDescription: external_exports.string(),
90
- redirectTo: external_exports.string().optional()
91
- })
92
- ]).meta({ id: "oauth-authorize-result" });
93
- var oauthAuthorizationRequestViewSchema = external_exports.object({
94
- uid: nanoidSchema,
95
- client: external_exports.object({
96
- uid: external_exports.string(),
97
- name: external_exports.string(),
98
- firstParty: external_exports.boolean(),
99
- /** Team that registered the app, absent for first-party clients */
100
- ownerTeamName: external_exports.string().optional()
101
- }),
102
- scope: oauthScopeSchema,
103
- /** Unix ms after which the request can no longer be decided */
104
- expiresAt: external_exports.number().int()
105
- }).meta({ id: "oauth-authorization-request-view" });
106
- var oauthDecisionSchema = external_exports.object({ accept: external_exports.boolean() }).meta({ id: "oauth-decision" });
107
- var oauthDecisionResultSchema = external_exports.object({ redirectTo: external_exports.string() }).meta({ id: "oauth-decision-result" });
108
- var oauthTokenRequestSchema = external_exports.object({
109
- grant_type: external_exports.string().max(64),
110
- client_id: external_exports.string().max(256).optional(),
111
- client_secret: external_exports.string().max(256).optional(),
112
- code: external_exports.string().max(256).optional(),
113
- redirect_uri: external_exports.string().max(2048).optional(),
114
- code_verifier: external_exports.string().max(256).optional(),
115
- refresh_token: external_exports.string().max(4096).optional(),
116
- scope: external_exports.string().max(256).optional()
117
- }).meta({ id: "oauth-token-request" });
118
- var oauthTokenResponseSchema = external_exports.object({
119
- access_token: external_exports.string(),
120
- token_type: external_exports.literal("Bearer"),
121
- /** Access token lifetime in seconds */
122
- expires_in: external_exports.number().int(),
123
- refresh_token: external_exports.string(),
124
- scope: oauthScopeSchema
125
- }).meta({ id: "oauth-token-response" });
126
- var oauthRevokeRequestSchema = external_exports.object({
127
- token: external_exports.string().max(4096),
128
- token_type_hint: external_exports.string().max(64).optional(),
129
- client_id: external_exports.string().max(256).optional(),
130
- client_secret: external_exports.string().max(256).optional()
131
- }).meta({ id: "oauth-revoke-request" });
132
- var oauthErrorResponseSchema = external_exports.object({
133
- error: external_exports.string(),
134
- error_description: external_exports.string().optional()
135
- }).meta({ id: "oauth-error-response" });
136
- var oauthClientCreateSchema = external_exports.object({
137
- name: external_exports.string().trim().min(1).max(100),
138
- type: oauthClientTypeSchema,
139
- redirectUris: external_exports.array(external_exports.string().trim().min(1).max(2048)).min(1).max(10),
140
- allowedScopes: external_exports.array(oauthScopeSchema).min(1)
141
- }).meta({ id: "oauth-client-create" });
142
- var oauthClientListItemSchema = oauthClientSchema.omit({ secretHash: true }).meta({ id: "oauth-client-list-item" });
143
- var oauthClientCreatedSchema = oauthClientListItemSchema.extend({ clientSecret: external_exports.string().optional() }).meta({ id: "oauth-client-created" });
144
-
145
- // ../../packages/entities/dist/oauth/authorization.js
146
- var codeChallengeSchema = external_exports.string().min(43).max(128);
147
- var oauthAuthorizationRequestSchema = external_exports.object({
148
- uid: nanoidSchema,
149
- clientId: external_exports.string(),
150
- redirectUri: external_exports.string(),
151
- scope: oauthScopeSchema,
152
- state: external_exports.string().max(1024).optional(),
153
- codeChallenge: codeChallengeSchema,
154
- /** Date because Mongo TTL indexes ignore numeric fields */
155
- expiresAt: external_exports.date()
156
- }).meta({ id: "oauth-authorization-request" });
157
- var oauthAuthorizationCodeSchema = external_exports.object({
158
- /** Row id only: mongobase keeps a unique `uid` index on every collection */
159
- uid: nanoidSchema,
160
- /** sha256 hex digest of the code; the plaintext only ever travels in the redirect */
161
- codeHash: external_exports.string(),
162
- clientId: external_exports.string(),
163
- userUid: nanoidSchema,
164
- teamUid: nanoidSchema,
165
- redirectUri: external_exports.string(),
166
- scope: oauthScopeSchema,
167
- codeChallenge: codeChallengeSchema,
168
- /**
169
- * Whether the code has been exchanged. The `false` guard on the exchange
170
- * write makes consumption a compare-and-set, so two racing exchanges of
171
- * one code cannot both succeed.
172
- */
173
- used: external_exports.boolean(),
174
- /** Unix ms of the exchange. A second exchange after this is a replay. */
175
- usedAt: external_exports.number().int().optional(),
176
- /** Refresh family issued from this code, revoked if the code is replayed */
177
- familyId: external_exports.string().optional(),
178
- /**
179
- * When the code stops being exchangeable. The row outlives this (see the
180
- * TTL index) so a late replay still revokes the family.
181
- */
182
- expiresAt: external_exports.date()
183
- }).meta({ id: "oauth-authorization-code" });
184
-
185
- // ../../packages/entities/dist/token/token.js
186
- var accessTokenPayloadSchema = external_exports.object({
187
- userIndex: external_exports.string(),
188
- userUid: external_exports.string().brand(),
189
- // Brand only — `.brand()` keeps the runtime `z.string()` validation (no
190
- // `.min()`), so parsed tokens stay byte-identical while gaining the Team brand.
191
- teamUid: external_exports.string().brand(),
192
- email: emailSchema.nullable(),
193
- role: roleSchema.optional(),
194
- clientId: external_exports.string().min(1).optional(),
195
- scope: oauthScopeSchema.optional(),
196
- exp: external_exports.number().int()
197
- }).meta({ id: "access-token-payload" });
198
- var healthTokenPayloadSchema = external_exports.object({
199
- svc: external_exports.string().optional(),
200
- iat: external_exports.number().int().optional(),
201
- exp: external_exports.number().int()
202
- }).meta({ id: "health-token-payload" });
203
- var edgeCacheSyncTokenPayloadSchema = external_exports.object({
204
- svc: external_exports.literal("watcher-edge-cache-sync"),
205
- iat: external_exports.number().int().optional(),
206
- exp: external_exports.number().int()
207
- }).meta({
208
- id: "edge-cache-sync-token-payload"
209
- });
210
- var refreshTokenPayloadSchema = external_exports.object({
211
- uid: external_exports.string(),
212
- teamUid: external_exports.string().nullable(),
213
- type: external_exports.string(),
214
- familyId: external_exports.string(),
215
- userIndex: external_exports.string(),
216
- clientId: external_exports.string().min(1).optional(),
217
- scope: oauthScopeSchema.optional(),
218
- exp: external_exports.number()
219
- }).meta({ id: "refresh-token-payload" });
220
- var personalTokenPayloadSchema = external_exports.object({
221
- uid: external_exports.string(),
222
- teamUid: external_exports.string(),
223
- userIndex: external_exports.string(),
224
- iat: external_exports.number(),
225
- exp: external_exports.number()
226
- }).meta({ id: "personal-token-payload" });
227
- var exchangeTokenSchema = external_exports.object({
228
- uid: external_exports.string(),
229
- accessToken: external_exports.string(),
230
- refreshToken: external_exports.string(),
231
- expiry: external_exports.number(),
232
- teamUid: external_exports.string()
233
- }).meta({ id: "exchange-token" });
234
- var socialOauthProviderSchema = external_exports.enum(["google", "microsoft"]).meta({ id: "social-oauth-provider" });
235
- var hostingExchangeTokenSchema = external_exports.object({
236
- email: emailSchema,
237
- aud: external_exports.url(),
238
- /** Identity provider uid, present when minted from a SAML assertion */
239
- idp: nanoidSchema.optional(),
240
- /**
241
- * The social provider that authenticated the email, present only for
242
- * OAuth logins. Absent means SAML, where the team's IdP is the authority.
243
- * OAuth proves email ownership only, so the consumer must re-check the
244
- * resource's email allowlists and that this provider is enabled before
245
- * creating a session.
246
- */
247
- provider: socialOauthProviderSchema.optional(),
248
- teamUid: nanoidSchema,
249
- exp: external_exports.number()
250
- }).meta({ id: "hosting-exchange-token" });
251
- var hostingLoginTokenSchema = entitySchema.extend({
252
- email: emailSchema,
253
- host: external_exports.string(),
254
- redirect: external_exports.string().optional(),
255
- loginPortalUid: external_exports.string().optional(),
256
- exp: timestampSchema
257
- }).meta({ id: "hosting-login-token" });
258
- var docsAgentTokenSchema = external_exports.object({
259
- uid: external_exports.string(),
260
- publishUid: external_exports.string(),
261
- projectUid: external_exports.string(),
262
- teamUid: external_exports.string(),
263
- mcpServerId: external_exports.string(),
264
- mcpInstallationId: external_exports.string(),
265
- iat: external_exports.number(),
266
- exp: external_exports.number()
267
- }).meta({ id: "docs-agent-token" });
268
-
269
- // ../../packages/entities/dist/token/payload.js
270
- var tokenResponseSchema = external_exports.object({
271
- refreshToken: external_exports.string(),
272
- accessToken: external_exports.string()
273
- }).meta({ id: "token-response" });
274
-
275
- // ../../packages/entities/dist/token/refresh.js
276
- var refreshTokenRecordSchema = external_exports.object({
277
- uid: external_exports.string(),
278
- /** Associate a refresh token with a team */
279
- teamUid: external_exports.string().nullable(),
280
- /** Token expiry in unix milliseconds */
281
- expiry: external_exports.number().int(),
282
- /** Tracks if a token has been used. No refresh token should be reused */
283
- used: external_exports.boolean(),
284
- /**
285
- * When the token was consumed by a rotation, in unix milliseconds.
286
- * Reuse within a short grace window after this moment is treated as a
287
- * benign client race (parallel tabs); reuse after it revokes the family.
288
- */
289
- usedAt: external_exports.number().int().optional(),
290
- /** family id is used to remove all tokens for a family in the event of a reuse */
291
- familyId: external_exports.string(),
292
- /** Unique lookup for the user */
293
- userIndex: external_exports.string(),
294
- /**
295
- * OAuth client the family was granted to. Absent on first-party sessions;
296
- * present, a rotation must come from the same client and re-signs the
297
- * same scope.
298
- */
299
- clientId: external_exports.string().optional(),
300
- scope: oauthScopeSchema.optional()
301
- }).meta({ id: "refresh-token-record" });
302
-
303
- // ../../node_modules/.pnpm/jose@5.9.6/node_modules/jose/dist/node/esm/runtime/base64url.js
304
- import { Buffer as Buffer2 } from "node:buffer";
305
-
306
- // ../../node_modules/.pnpm/jose@5.9.6/node_modules/jose/dist/node/esm/lib/buffer_utils.js
307
- var encoder = new TextEncoder();
308
- var decoder = new TextDecoder();
309
- var MAX_INT32 = 2 ** 32;
310
-
311
- // ../../node_modules/.pnpm/jose@5.9.6/node_modules/jose/dist/node/esm/runtime/base64url.js
312
- function normalize(input) {
313
- let encoded = input;
314
- if (encoded instanceof Uint8Array) {
315
- encoded = decoder.decode(encoded);
316
- }
317
- return encoded;
318
- }
319
- var decode = (input) => new Uint8Array(Buffer2.from(normalize(input), "base64url"));
320
-
321
- // ../../node_modules/.pnpm/jose@5.9.6/node_modules/jose/dist/node/esm/util/errors.js
322
- var JOSEError = class extends Error {
323
- static code = "ERR_JOSE_GENERIC";
324
- code = "ERR_JOSE_GENERIC";
325
- constructor(message, options) {
326
- super(message, options);
327
- this.name = this.constructor.name;
328
- Error.captureStackTrace?.(this, this.constructor);
329
- }
330
- };
331
- var JWTInvalid = class extends JOSEError {
332
- static code = "ERR_JWT_INVALID";
333
- code = "ERR_JWT_INVALID";
334
- };
335
-
336
- // ../../node_modules/.pnpm/jose@5.9.6/node_modules/jose/dist/node/esm/lib/is_object.js
337
- function isObjectLike(value) {
338
- return typeof value === "object" && value !== null;
339
- }
340
- function isObject(input) {
341
- if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
342
- return false;
343
- }
344
- if (Object.getPrototypeOf(input) === null) {
345
- return true;
346
- }
347
- let proto = input;
348
- while (Object.getPrototypeOf(proto) !== null) {
349
- proto = Object.getPrototypeOf(proto);
350
- }
351
- return Object.getPrototypeOf(input) === proto;
352
- }
353
-
354
- // ../../node_modules/.pnpm/jose@5.9.6/node_modules/jose/dist/node/esm/util/base64url.js
355
- var decode2 = decode;
356
-
357
- // ../../node_modules/.pnpm/jose@5.9.6/node_modules/jose/dist/node/esm/util/decode_jwt.js
358
- function decodeJwt(jwt) {
359
- if (typeof jwt !== "string")
360
- throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
361
- const { 1: payload, length } = jwt.split(".");
362
- if (length === 5)
363
- throw new JWTInvalid("Only JWTs using Compact JWS serialization can be decoded");
364
- if (length !== 3)
365
- throw new JWTInvalid("Invalid JWT");
366
- if (!payload)
367
- throw new JWTInvalid("JWTs must contain a payload");
368
- let decoded;
369
- try {
370
- decoded = decode2(payload);
371
- } catch {
372
- throw new JWTInvalid("Failed to base64url decode the payload");
373
- }
374
- let result;
375
- try {
376
- result = JSON.parse(decoder.decode(decoded));
377
- } catch {
378
- throw new JWTInvalid("Failed to parse the decoded payload as JSON");
379
- }
380
- if (!isObject(result))
381
- throw new JWTInvalid("Invalid JWT Claims Set");
382
- return result;
383
- }
384
-
385
- // ../../packages/tokens/dist/error.js
386
- function TokenError(msg, code) {
387
- const err = new Error(msg);
388
- err.code = code;
389
- return err;
390
- }
391
-
392
- // ../../packages/tokens/dist/index.js
393
- function validatePayload(data, schema) {
394
- const result = schema.safeParse(data);
395
- if (!result.success) {
396
- console.error("Invalid token payload:");
397
- console.error(result.error.issues);
398
- throw TokenError("Invalid token payload", "invalid-payload");
399
- }
400
- return result.data;
401
- }
402
- function decode3(token, schema = external_exports.any()) {
403
- return validatePayload(decodeJwt(token), schema);
404
- }
405
-
406
- // src/helpers/metadata.ts
407
- import fs from "node:fs/promises";
408
- import os from "node:os";
409
- import path from "node:path";
410
- var SCALAR_METADATA_FILE_NAME = ".scalar-config";
411
- var METADATA_FILE_PATH = path.join(
412
- os.homedir(),
413
- SCALAR_METADATA_FILE_NAME
414
- );
415
- var authSchema = external_exports.union([
416
- external_exports.object({
417
- accessToken: external_exports.string(),
418
- refreshToken: external_exports.string()
419
- }),
420
- external_exports.object({
421
- accessToken: external_exports.string(),
422
- personalToken: external_exports.string()
423
- })
424
- ]);
425
- var metadataSchema = external_exports.object({
426
- lastUpdateCheck: external_exports.number(),
427
- lastKnownVersion: external_exports.string(),
428
- auth: authSchema.nullable().default(null)
429
- });
430
- var metadataCache = null;
431
- var getMetadataMtimeMs = async () => (await fs.stat(METADATA_FILE_PATH).catch(() => null))?.mtimeMs ?? null;
432
- var writeQueue = Promise.resolve();
433
- var setMetadata = async (metadata) => {
434
- const write = writeQueue.then(async () => {
435
- const currentMetadata = await getMetadata();
436
- const updatedMetadata = { ...currentMetadata, ...metadata };
437
- const tmpPath = `${METADATA_FILE_PATH}.${process.pid}.tmp`;
438
- await fs.writeFile(tmpPath, JSON.stringify(updatedMetadata));
439
- await fs.rename(tmpPath, METADATA_FILE_PATH);
440
- metadataCache = {
441
- mtimeMs: await getMetadataMtimeMs(),
442
- data: updatedMetadata
443
- };
444
- });
445
- writeQueue = write.catch(() => {
446
- });
447
- return write;
448
- };
449
- var fileExists = async (path3) => !!await fs.stat(path3).catch(() => false);
450
- var readMetadataFile = async () => {
451
- const metadata = await fileExists(METADATA_FILE_PATH) ? await fs.readFile(METADATA_FILE_PATH, { encoding: "utf-8" }) : "{}";
452
- try {
453
- return metadataSchema.partial().parse(JSON.parse(metadata));
454
- } catch {
455
- return {};
456
- }
457
- };
458
- var getMetadata = async () => {
459
- const mtimeMs = await getMetadataMtimeMs();
460
- if (metadataCache && metadataCache.mtimeMs === mtimeMs) {
461
- return metadataCache.data;
462
- }
463
- const data = await readMetadataFile();
464
- metadataCache = { mtimeMs, data };
465
- return data;
466
- };
467
-
468
- // src/helpers/auth.ts
469
- var eventListeners = [];
470
- var addEventListener = (callback) => {
471
- eventListeners.push(callback);
472
- };
473
- var fireCallbacks = (auth) => eventListeners.forEach((callback) => callback(auth));
474
- var setAuthData = async (authData) => {
475
- await setMetadata({ auth: authData });
476
- fireCallbacks(authData);
477
- };
478
- var getAuthData = async (opts) => {
479
- const { noExit } = opts ?? {};
480
- const { auth } = await getMetadata();
481
- if (!auth) {
482
- if (noExit) throw new Error("Authorization required");
483
- return output.error().title("Authorization required").message("Please login before running this command.").exit("error");
484
- }
485
- const { email, role, teamUid, exp } = decode3(
486
- auth.accessToken,
487
- accessTokenPayloadSchema
488
- );
489
- const isExpired = exp * 1e3 < Date.now();
490
- if (!isExpired) {
491
- return { ...auth, email, role, teamUid, addEventListener };
492
- }
493
- try {
494
- if ("refreshToken" in auth) {
495
- const updatedAuth2 = await refreshToken(auth.refreshToken);
496
- return { ...updatedAuth2, email, role, teamUid, addEventListener };
497
- }
498
- const updatedAuth = await generateAccessByPersonalToken({
499
- personalToken: auth.personalToken
500
- });
501
- return { ...updatedAuth, email, role, teamUid, addEventListener };
502
- } catch {
503
- if (noExit) throw new Error("Session expired, please login again.");
504
- return output.error().title("Expired session").message("Session expired, please login again.").exit("error");
505
- }
506
- };
507
- var clearAuthData = async () => {
508
- await setMetadata({ auth: null });
509
- };
510
- var refreshTokenResponseSchema = zod_default.object({
511
- accessToken: zod_default.string(),
512
- refreshToken: zod_default.string()
513
- });
514
- var refreshToken = async (token, teamUid) => {
515
- const result = await fetch(`${config.services.api}/core/login/refresh`, {
516
- method: "POST",
517
- headers: {
518
- "Content-Type": "application/json"
519
- },
520
- credentials: "include",
521
- body: JSON.stringify({
522
- refreshToken: token,
523
- teamUid
524
- }),
525
- // Fail fast instead of hanging every authed command on a slow network
526
- signal: AbortSignal.timeout(1e4)
527
- });
528
- if (result.ok) {
529
- const { accessToken, refreshToken: refreshToken2 } = refreshTokenResponseSchema.parse(
530
- await result.json()
531
- );
532
- await setAuthData({ accessToken, refreshToken: refreshToken2 });
533
- return { accessToken, refreshToken: refreshToken2 };
534
- }
535
- throw Error("Could not refresh token");
536
- };
537
-
538
- // src/helpers/watch-file.ts
539
- import fs2 from "node:fs";
540
- import path2 from "node:path";
541
- import chokidar from "chokidar";
542
- var watchFile = async (file, callback, options) => {
543
- if (isUrl(file)) {
544
- setInterval(callback, 5e3);
545
- return;
546
- }
547
- const absoluteFilePath = path2.resolve(file);
548
- if (!fs2.existsSync(absoluteFilePath)) {
549
- throw new Error(`File ${absoluteFilePath} does not exist`);
550
- }
551
- output.info().title(`Watch ${file}`).print();
552
- const watcher = chokidar.watch(absoluteFilePath, { persistent: true });
553
- watcher.on("change", () => {
554
- callback();
555
- });
556
- if (options?.immediate) {
557
- callback();
558
- }
559
- return {
560
- unsubscribe: () => watcher.close()
561
- };
562
- };
563
-
564
- // src/domains/auth/login/helpers/personal-token-generate-access.ts
565
- var generateAccessByPersonalToken = async ({
566
- personalToken
567
- }) => {
568
- const result = await fetch(
569
- `${config.services.api}/core/login/personal-token/access`,
570
- {
571
- method: "POST",
572
- headers: {
573
- "Content-Type": "application/json"
574
- },
575
- body: JSON.stringify({
576
- personalToken
577
- })
578
- }
579
- );
580
- if (!result.ok) {
581
- const data = await result.json();
582
- throw new Error(
583
- data.message ?? "Could not generate an access token from the provided personal token"
584
- );
585
- }
586
- const { accessToken } = external_exports.object({ accessToken: external_exports.string() }).parse(await result.json());
587
- await setAuthData({ accessToken, personalToken });
588
- return { accessToken, personalToken };
589
- };
590
-
591
- export {
592
- checkNodeVersion,
593
- oauthAuthorizeResultSchema,
594
- oauthAuthorizationRequestViewSchema,
595
- oauthDecisionResultSchema,
596
- oauthTokenResponseSchema,
597
- oauthClientListItemSchema,
598
- oauthClientCreatedSchema,
599
- tokenResponseSchema,
600
- accessTokenPayloadSchema,
601
- decode3 as decode,
602
- generateAccessByPersonalToken,
603
- setMetadata,
604
- getMetadata,
605
- setAuthData,
606
- getAuthData,
607
- clearAuthData,
608
- refreshToken,
609
- watchFile
610
- };