@cdot65/prisma-airs-sdk 0.4.0 → 0.5.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.
- package/dist/index.cjs +50 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -3
- package/dist/index.d.ts +37 -3
- package/dist/index.js +49 -4
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/dist/index.cjs
CHANGED
|
@@ -188,6 +188,7 @@ __export(index_exports, {
|
|
|
188
188
|
ModelSecurityRuleResponseSchema: () => ModelSecurityRuleResponseSchema,
|
|
189
189
|
ModelSecurityRulesClient: () => ModelSecurityRulesClient,
|
|
190
190
|
ModelSecurityScansClient: () => ModelSecurityScansClient,
|
|
191
|
+
OAuthClient: () => OAuthClient,
|
|
191
192
|
PAYLOAD_HASH: () => PAYLOAD_HASH,
|
|
192
193
|
PolicySchema: () => PolicySchema,
|
|
193
194
|
PolicyType: () => PolicyType,
|
|
@@ -361,7 +362,7 @@ var MAX_NUMBER_OF_BATCH_SCAN_OBJECTS = 5;
|
|
|
361
362
|
var MAX_CONNECTION_POOL_SIZE = 100;
|
|
362
363
|
var MAX_NUMBER_OF_RETRIES = 5;
|
|
363
364
|
var HTTP_FORCE_RETRY_STATUS_CODES = [500, 502, 503, 504];
|
|
364
|
-
var SDK_VERSION = "0.
|
|
365
|
+
var SDK_VERSION = "0.5.0";
|
|
365
366
|
var USER_AGENT = `PAN-AIRS/${SDK_VERSION}-typescript-sdk`;
|
|
366
367
|
var DEFAULT_MGMT_ENDPOINT = "https://api.sase.paloaltonetworks.com/aisec";
|
|
367
368
|
var DEFAULT_TOKEN_ENDPOINT = "https://auth.apps.paloaltonetworks.com/oauth2/access_token";
|
|
@@ -2647,12 +2648,14 @@ var OAuthTokenResponseSchema = import_zod19.z.object({
|
|
|
2647
2648
|
});
|
|
2648
2649
|
|
|
2649
2650
|
// src/management/oauth-client.ts
|
|
2650
|
-
var
|
|
2651
|
+
var DEFAULT_TOKEN_BUFFER_MS = 3e4;
|
|
2651
2652
|
var OAuthClient = class {
|
|
2652
2653
|
tokenEndpoint;
|
|
2653
2654
|
clientId;
|
|
2654
2655
|
clientSecret;
|
|
2655
2656
|
tsgId;
|
|
2657
|
+
tokenBufferMs;
|
|
2658
|
+
onTokenRefresh;
|
|
2656
2659
|
accessToken = null;
|
|
2657
2660
|
expiresAt = 0;
|
|
2658
2661
|
pendingFetch = null;
|
|
@@ -2661,13 +2664,15 @@ var OAuthClient = class {
|
|
|
2661
2664
|
this.clientSecret = opts.clientSecret;
|
|
2662
2665
|
this.tsgId = opts.tsgId;
|
|
2663
2666
|
this.tokenEndpoint = opts.tokenEndpoint ?? DEFAULT_TOKEN_ENDPOINT;
|
|
2667
|
+
this.tokenBufferMs = opts.tokenBufferMs ?? DEFAULT_TOKEN_BUFFER_MS;
|
|
2668
|
+
this.onTokenRefresh = opts.onTokenRefresh;
|
|
2664
2669
|
}
|
|
2665
2670
|
/**
|
|
2666
2671
|
* Get a valid access token, refreshing if needed.
|
|
2667
2672
|
* @returns Bearer access token string.
|
|
2668
2673
|
*/
|
|
2669
2674
|
async getToken() {
|
|
2670
|
-
if (this.accessToken && Date.now() < this.expiresAt -
|
|
2675
|
+
if (this.accessToken && Date.now() < this.expiresAt - this.tokenBufferMs) {
|
|
2671
2676
|
return this.accessToken;
|
|
2672
2677
|
}
|
|
2673
2678
|
if (this.pendingFetch) {
|
|
@@ -2683,6 +2688,40 @@ var OAuthClient = class {
|
|
|
2683
2688
|
this.accessToken = null;
|
|
2684
2689
|
this.expiresAt = 0;
|
|
2685
2690
|
}
|
|
2691
|
+
/** Check if the current token has passed its expiry time. Returns true if no token exists. */
|
|
2692
|
+
isTokenExpired() {
|
|
2693
|
+
if (!this.accessToken) return true;
|
|
2694
|
+
return Date.now() >= this.expiresAt;
|
|
2695
|
+
}
|
|
2696
|
+
/**
|
|
2697
|
+
* Check if the token is within the pre-expiry buffer window.
|
|
2698
|
+
* Returns true if no token exists.
|
|
2699
|
+
* @param bufferMs - Custom buffer in ms. Defaults to the configured `tokenBufferMs`.
|
|
2700
|
+
*/
|
|
2701
|
+
isTokenExpiringSoon(bufferMs) {
|
|
2702
|
+
if (!this.accessToken) return true;
|
|
2703
|
+
const buffer = bufferMs ?? this.tokenBufferMs;
|
|
2704
|
+
return Date.now() >= this.expiresAt - buffer;
|
|
2705
|
+
}
|
|
2706
|
+
/**
|
|
2707
|
+
* Get a snapshot of the current token state without exposing the actual token value.
|
|
2708
|
+
* @returns Current {@link TokenInfo}.
|
|
2709
|
+
*/
|
|
2710
|
+
getTokenInfo() {
|
|
2711
|
+
const now = Date.now();
|
|
2712
|
+
const hasToken = this.accessToken !== null;
|
|
2713
|
+
const isExpired = !hasToken || now >= this.expiresAt;
|
|
2714
|
+
const isExpiringSoon = !hasToken || now >= this.expiresAt - this.tokenBufferMs;
|
|
2715
|
+
const expiresInMs = hasToken ? Math.max(0, this.expiresAt - now) : 0;
|
|
2716
|
+
return {
|
|
2717
|
+
hasToken,
|
|
2718
|
+
isValid: hasToken && !isExpiringSoon,
|
|
2719
|
+
isExpired,
|
|
2720
|
+
isExpiringSoon,
|
|
2721
|
+
expiresInMs,
|
|
2722
|
+
expiresAt: hasToken ? this.expiresAt : 0
|
|
2723
|
+
};
|
|
2724
|
+
}
|
|
2686
2725
|
async fetchToken() {
|
|
2687
2726
|
const credentials = btoa(`${this.clientId}:${this.clientSecret}`);
|
|
2688
2727
|
const body = new URLSearchParams({
|
|
@@ -2718,6 +2757,12 @@ var OAuthClient = class {
|
|
|
2718
2757
|
const data = OAuthTokenResponseSchema.parse(await response.json());
|
|
2719
2758
|
this.accessToken = data.access_token;
|
|
2720
2759
|
this.expiresAt = Date.now() + data.expires_in * 1e3;
|
|
2760
|
+
if (this.onTokenRefresh) {
|
|
2761
|
+
try {
|
|
2762
|
+
this.onTokenRefresh(this.getTokenInfo());
|
|
2763
|
+
} catch {
|
|
2764
|
+
}
|
|
2765
|
+
}
|
|
2721
2766
|
return this.accessToken;
|
|
2722
2767
|
}
|
|
2723
2768
|
};
|
|
@@ -2749,7 +2794,7 @@ async function managementHttpRequest(opts) {
|
|
|
2749
2794
|
return fetch(url.toString(), { method, headers, body: bodyStr });
|
|
2750
2795
|
},
|
|
2751
2796
|
onRetryableFailure: async (response2) => {
|
|
2752
|
-
if (response2.status === 401 && !hadTokenRefresh) {
|
|
2797
|
+
if ((response2.status === 401 || response2.status === 403) && !hadTokenRefresh) {
|
|
2753
2798
|
hadTokenRefresh = true;
|
|
2754
2799
|
oauthClient.clearToken();
|
|
2755
2800
|
return true;
|
|
@@ -4895,6 +4940,7 @@ var RedTeamClient = class {
|
|
|
4895
4940
|
ModelSecurityRuleResponseSchema,
|
|
4896
4941
|
ModelSecurityRulesClient,
|
|
4897
4942
|
ModelSecurityScansClient,
|
|
4943
|
+
OAuthClient,
|
|
4898
4944
|
PAYLOAD_HASH,
|
|
4899
4945
|
PolicySchema,
|
|
4900
4946
|
PolicyType,
|