@sasjs/utils 3.5.9 → 3.6.1

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.
package/auth/auth.js CHANGED
@@ -1,10 +1,26 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
4
20
  };
5
21
  Object.defineProperty(exports, "__esModule", { value: true });
6
22
  exports.decodeToken = exports.hasTokenExpired = exports.isRefreshTokenExpiring = exports.isAccessTokenExpiring = void 0;
7
- const jwt_decode_1 = __importDefault(require("jwt-decode"));
23
+ const jwt_decode_1 = __importStar(require("jwt-decode"));
8
24
  /**
9
25
  * Checks if the Access Token is expired or is expiring in 1 hour. A default Access Token
10
26
  * lasts 12 hours. If the Access Token expires, the Refresh Token is used to fetch a new
@@ -50,7 +66,29 @@ function hasTokenExpired(token) {
50
66
  }
51
67
  exports.hasTokenExpired = hasTokenExpired;
52
68
  function isTokenExpiring(token, timeToLiveSeconds) {
53
- const payload = (0, jwt_decode_1.default)(token);
69
+ var _a, _b;
70
+ let payload;
71
+ try {
72
+ payload = (0, jwt_decode_1.default)(token);
73
+ }
74
+ catch (err) {
75
+ // Only tolerate undecodable (opaque / non-JWT) tokens - anything else
76
+ // is a genuine bug and should surface.
77
+ if (!(err instanceof jwt_decode_1.InvalidTokenError))
78
+ throw err;
79
+ // Opaque tokens cannot be expiry-checked client-side.
80
+ // Assume the token is usable and let the server reject it if expired.
81
+ // Route through process.logger so the message respects the configured
82
+ // log level and doesn't pollute stdout in CI/test runs. Falls back to a
83
+ // no-op when no logger has been installed (e.g. library-only usage).
84
+ (_b = (_a = process.logger) === null || _a === void 0 ? void 0 : _a.debug) === null || _b === void 0 ? void 0 : _b.call(_a, 'isTokenExpiring: token is not a decodable JWT, treating it as not expiring.');
85
+ return false;
86
+ }
87
+ // A JWT without an `exp` claim cannot be expiry-checked either.
88
+ // Note: `== null` (not `!`) - exp of 0 is a real (long-expired) claim,
89
+ // not a missing one.
90
+ if (payload.exp == null)
91
+ return false;
54
92
  const timeToLive = payload.exp - new Date().valueOf() / 1000;
55
93
  return timeToLive <= timeToLiveSeconds;
56
94
  }
package/auth/auth.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/auth/auth.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAkC;AAGlC;;;;;;;;GAQG;AACH,SAAgB,qBAAqB,CACnC,KAAc,EACd,iBAAiB,GAAG,IAAI;IAExB,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,eAAe,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAA;AAClD,CAAC;AARD,sDAQC;AAED;;;;;;;;GAQG;AACH,SAAgB,sBAAsB,CACpC,KAAc,EACd,iBAAiB,GAAG,EAAE;IAEtB,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,eAAe,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAA;AAClD,CAAC;AARD,wDAQC;AAED;;;;GAIG;AACH,SAAg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"version": "3.5.9"
85
+ "version": "3.6.1"
86
86
  }
package/types/config.d.ts CHANGED
@@ -58,8 +58,16 @@ export interface StreamConfig {
58
58
  export interface AuthConfig {
59
59
  access_token: string;
60
60
  refresh_token: string;
61
- client: string;
62
- secret: string;
61
+ /**
62
+ * OAuth client ID. Optional: tokens minted without a registered client
63
+ * (e.g. via the password grant against the built-in public `sas.cli`
64
+ * client) have none. When absent, refresh falls back to `sas.cli`.
65
+ */
66
+ client?: string;
67
+ /**
68
+ * OAuth client secret. Optional for the same reason as `client`.
69
+ */
70
+ secret?: string;
63
71
  }
64
72
  export interface AuthConfigSas9 {
65
73
  userName: string;