@puckeditor/cloud-client 0.7.0 → 0.7.1-canary.7dd7318f

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.
@@ -4,9 +4,9 @@ import {
4
4
  init_react_import
5
5
  } from "./chunk-O6DC5HI2.mjs";
6
6
 
7
- // ../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/token-error.js
7
+ // ../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/token-error.js
8
8
  var require_token_error = __commonJS({
9
- "../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/token-error.js"(exports, module) {
9
+ "../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/token-error.js"(exports, module) {
10
10
  "use strict";
11
11
  init_react_import();
12
12
  var __defProp = Object.defineProperty;
@@ -47,9 +47,9 @@ var require_token_error = __commonJS({
47
47
  }
48
48
  });
49
49
 
50
- // ../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/token-io.js
50
+ // ../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/token-io.js
51
51
  var require_token_io = __commonJS({
52
- "../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/token-io.js"(exports, module) {
52
+ "../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/token-io.js"(exports, module) {
53
53
  "use strict";
54
54
  init_react_import();
55
55
  var __create = Object.create;
@@ -127,9 +127,9 @@ var require_token_io = __commonJS({
127
127
  }
128
128
  });
129
129
 
130
- // ../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/auth-config.js
130
+ // ../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/auth-config.js
131
131
  var require_auth_config = __commonJS({
132
- "../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/auth-config.js"(exports, module) {
132
+ "../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/auth-config.js"(exports, module) {
133
133
  "use strict";
134
134
  init_react_import();
135
135
  var __create = Object.create;
@@ -201,20 +201,21 @@ var require_auth_config = __commonJS({
201
201
  }
202
202
  fs.writeFileSync(authPath, JSON.stringify(config, null, 2), { mode: 384 });
203
203
  }
204
- function isValidAccessToken(authConfig) {
204
+ function isValidAccessToken(authConfig, expirationBufferMs = 0) {
205
205
  if (!authConfig.token)
206
206
  return false;
207
207
  if (typeof authConfig.expiresAt !== "number")
208
208
  return true;
209
209
  const nowInSeconds = Math.floor(Date.now() / 1e3);
210
- return authConfig.expiresAt >= nowInSeconds;
210
+ const bufferInSeconds = expirationBufferMs / 1e3;
211
+ return authConfig.expiresAt >= nowInSeconds + bufferInSeconds;
211
212
  }
212
213
  }
213
214
  });
214
215
 
215
- // ../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/oauth.js
216
+ // ../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/oauth.js
216
217
  var require_oauth = __commonJS({
217
- "../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/oauth.js"(exports, module) {
218
+ "../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/oauth.js"(exports, module) {
218
219
  "use strict";
219
220
  init_react_import();
220
221
  var __defProp = Object.defineProperty;
@@ -302,9 +303,54 @@ var require_oauth = __commonJS({
302
303
  }
303
304
  });
304
305
 
305
- // ../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/token-util.js
306
+ // ../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/auth-errors.js
307
+ var require_auth_errors = __commonJS({
308
+ "../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/auth-errors.js"(exports, module) {
309
+ "use strict";
310
+ init_react_import();
311
+ var __defProp = Object.defineProperty;
312
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
313
+ var __getOwnPropNames = Object.getOwnPropertyNames;
314
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
315
+ var __export = (target, all) => {
316
+ for (var name in all)
317
+ __defProp(target, name, { get: all[name], enumerable: true });
318
+ };
319
+ var __copyProps = (to, from, except, desc) => {
320
+ if (from && typeof from === "object" || typeof from === "function") {
321
+ for (let key of __getOwnPropNames(from))
322
+ if (!__hasOwnProp.call(to, key) && key !== except)
323
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
324
+ }
325
+ return to;
326
+ };
327
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
328
+ var auth_errors_exports = {};
329
+ __export(auth_errors_exports, {
330
+ AccessTokenMissingError: () => AccessTokenMissingError,
331
+ RefreshAccessTokenFailedError: () => RefreshAccessTokenFailedError
332
+ });
333
+ module.exports = __toCommonJS(auth_errors_exports);
334
+ var AccessTokenMissingError = class extends Error {
335
+ constructor() {
336
+ super(
337
+ "No authentication found. Please log in with the Vercel CLI (vercel login)."
338
+ );
339
+ this.name = "AccessTokenMissingError";
340
+ }
341
+ };
342
+ var RefreshAccessTokenFailedError = class extends Error {
343
+ constructor(cause) {
344
+ super("Failed to refresh authentication token.", { cause });
345
+ this.name = "RefreshAccessTokenFailedError";
346
+ }
347
+ };
348
+ }
349
+ });
350
+
351
+ // ../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/token-util.js
306
352
  var require_token_util = __commonJS({
307
- "../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/token-util.js"(exports, module) {
353
+ "../../node_modules/.pnpm/@vercel+oidc@3.2.0/node_modules/@vercel/oidc/dist/token-util.js"(exports, module) {
308
354
  init_react_import();
309
355
  var __create = Object.create;
310
356
  var __defProp = Object.defineProperty;
@@ -338,9 +384,9 @@ var require_token_util = __commonJS({
338
384
  assertVercelOidcTokenResponse: () => assertVercelOidcTokenResponse,
339
385
  findProjectInfo: () => findProjectInfo,
340
386
  getTokenPayload: () => getTokenPayload,
341
- getVercelCliToken: () => getVercelCliToken,
342
387
  getVercelDataDir: () => getVercelDataDir,
343
388
  getVercelOidcToken: () => getVercelOidcToken,
389
+ getVercelToken: () => getVercelToken,
344
390
  isExpired: () => isExpired,
345
391
  loadToken: () => loadToken,
346
392
  saveToken: () => saveToken
@@ -352,6 +398,7 @@ var require_token_util = __commonJS({
352
398
  var import_token_io = require_token_io();
353
399
  var import_auth_config = require_auth_config();
354
400
  var import_oauth = require_oauth();
401
+ var import_auth_errors = require_auth_errors();
355
402
  function getVercelDataDir() {
356
403
  const vercelFolder = "com.vercel.cli";
357
404
  const dataDir = (0, import_token_io.getUserDataDir)();
@@ -360,17 +407,17 @@ var require_token_util = __commonJS({
360
407
  }
361
408
  return path.join(dataDir, vercelFolder);
362
409
  }
363
- async function getVercelCliToken() {
410
+ async function getVercelToken(options) {
364
411
  const authConfig = (0, import_auth_config.readAuthConfig)();
365
- if (!authConfig) {
366
- return null;
412
+ if (!authConfig?.token) {
413
+ throw new import_auth_errors.AccessTokenMissingError();
367
414
  }
368
- if ((0, import_auth_config.isValidAccessToken)(authConfig)) {
369
- return authConfig.token || null;
415
+ if ((0, import_auth_config.isValidAccessToken)(authConfig, options?.expirationBufferMs)) {
416
+ return authConfig.token;
370
417
  }
371
418
  if (!authConfig.refreshToken) {
372
419
  (0, import_auth_config.writeAuthConfig)({});
373
- return null;
420
+ throw new import_auth_errors.RefreshAccessTokenFailedError("No refresh token available");
374
421
  }
375
422
  try {
376
423
  const tokenResponse = await (0, import_oauth.refreshTokenRequest)({
@@ -379,7 +426,7 @@ var require_token_util = __commonJS({
379
426
  const [tokensError, tokens] = await (0, import_oauth.processTokenResponse)(tokenResponse);
380
427
  if (tokensError || !tokens) {
381
428
  (0, import_auth_config.writeAuthConfig)({});
382
- return null;
429
+ throw new import_auth_errors.RefreshAccessTokenFailedError(tokensError);
383
430
  }
384
431
  const updatedConfig = {
385
432
  token: tokens.access_token,
@@ -389,10 +436,13 @@ var require_token_util = __commonJS({
389
436
  updatedConfig.refreshToken = tokens.refresh_token;
390
437
  }
391
438
  (0, import_auth_config.writeAuthConfig)(updatedConfig);
392
- return updatedConfig.token ?? null;
439
+ return updatedConfig.token;
393
440
  } catch (error) {
394
441
  (0, import_auth_config.writeAuthConfig)({});
395
- return null;
442
+ if (error instanceof import_auth_errors.AccessTokenMissingError || error instanceof import_auth_errors.RefreshAccessTokenFailedError) {
443
+ throw error;
444
+ }
445
+ throw new import_auth_errors.RefreshAccessTokenFailedError(error);
396
446
  }
397
447
  }
398
448
  async function getVercelOidcToken(authToken, projectId, teamId) {
@@ -488,8 +538,8 @@ var require_token_util = __commonJS({
488
538
  );
489
539
  return JSON.parse(Buffer.from(padded, "base64").toString("utf8"));
490
540
  }
491
- function isExpired(token) {
492
- return token.exp * 1e3 < Date.now();
541
+ function isExpired(token, bufferMs = 0) {
542
+ return token.exp * 1e3 < Date.now() + bufferMs;
493
543
  }
494
544
  }
495
545
  });