@cdot65/prisma-airs-sdk 0.6.6 → 0.6.7

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 CHANGED
@@ -430,7 +430,7 @@ var MAX_NUMBER_OF_BATCH_SCAN_OBJECTS = 5;
430
430
  var MAX_CONNECTION_POOL_SIZE = 100;
431
431
  var MAX_NUMBER_OF_RETRIES = 5;
432
432
  var HTTP_FORCE_RETRY_STATUS_CODES = [500, 502, 503, 504];
433
- var SDK_VERSION = "0.6.6";
433
+ var SDK_VERSION = "0.6.7";
434
434
  var USER_AGENT = `PAN-AIRS/${SDK_VERSION}-typescript-sdk`;
435
435
  var DEFAULT_MGMT_ENDPOINT = "https://api.sase.paloaltonetworks.com/aisec";
436
436
  var DEFAULT_TOKEN_ENDPOINT = "https://auth.apps.paloaltonetworks.com/oauth2/access_token";
@@ -3248,6 +3248,49 @@ var OAuthClient = class {
3248
3248
  }
3249
3249
  };
3250
3250
 
3251
+ // src/oauth-config.ts
3252
+ function resolveOAuthConfig(opts) {
3253
+ const { primaryEnvPrefix, fallbackEnvPrefix } = opts;
3254
+ const clientId = opts.clientId ?? process.env[`${primaryEnvPrefix}_CLIENT_ID`] ?? (fallbackEnvPrefix ? process.env[`${fallbackEnvPrefix}_CLIENT_ID`] : void 0);
3255
+ const clientSecret = opts.clientSecret ?? process.env[`${primaryEnvPrefix}_CLIENT_SECRET`] ?? (fallbackEnvPrefix ? process.env[`${fallbackEnvPrefix}_CLIENT_SECRET`] : void 0);
3256
+ const tsgId = opts.tsgId ?? process.env[`${primaryEnvPrefix}_TSG_ID`] ?? (fallbackEnvPrefix ? process.env[`${fallbackEnvPrefix}_TSG_ID`] : void 0);
3257
+ const tokenEndpoint = opts.tokenEndpoint ?? process.env[`${primaryEnvPrefix}_TOKEN_ENDPOINT`] ?? (fallbackEnvPrefix ? process.env[`${fallbackEnvPrefix}_TOKEN_ENDPOINT`] : void 0);
3258
+ const numRetries = Math.min(
3259
+ Math.max(opts.numRetries ?? MAX_NUMBER_OF_RETRIES, 0),
3260
+ MAX_NUMBER_OF_RETRIES
3261
+ );
3262
+ const envHint = fallbackEnvPrefix ? `${primaryEnvPrefix}_CLIENT_ID / ${fallbackEnvPrefix}_CLIENT_ID` : `${primaryEnvPrefix}_CLIENT_ID`;
3263
+ if (!clientId) {
3264
+ throw new AISecSDKException(
3265
+ `clientId is required (option or ${envHint} env var)`,
3266
+ "AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
3267
+ );
3268
+ }
3269
+ const secretHint = fallbackEnvPrefix ? `${primaryEnvPrefix}_CLIENT_SECRET / ${fallbackEnvPrefix}_CLIENT_SECRET` : `${primaryEnvPrefix}_CLIENT_SECRET`;
3270
+ if (!clientSecret) {
3271
+ throw new AISecSDKException(
3272
+ `clientSecret is required (option or ${secretHint} env var)`,
3273
+ "AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
3274
+ );
3275
+ }
3276
+ const tsgHint = fallbackEnvPrefix ? `${primaryEnvPrefix}_TSG_ID / ${fallbackEnvPrefix}_TSG_ID` : `${primaryEnvPrefix}_TSG_ID`;
3277
+ if (!tsgId) {
3278
+ throw new AISecSDKException(
3279
+ `tsgId is required (option or ${tsgHint} env var)`,
3280
+ "AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
3281
+ );
3282
+ }
3283
+ const oauthClient = new OAuthClient({
3284
+ clientId,
3285
+ clientSecret,
3286
+ tsgId,
3287
+ tokenEndpoint,
3288
+ tokenBufferMs: opts.tokenBufferMs,
3289
+ onTokenRefresh: opts.onTokenRefresh
3290
+ });
3291
+ return { baseUrl: opts.baseUrl, oauthClient, numRetries, tsgId };
3292
+ }
3293
+
3251
3294
  // src/management/management-http-client.ts
3252
3295
  async function managementHttpRequest(opts) {
3253
3296
  const { method, baseUrl, path, body, params, oauthClient, numRetries } = opts;
@@ -3853,80 +3896,57 @@ var ManagementClient = class {
3853
3896
  scanLogs;
3854
3897
  oauth;
3855
3898
  constructor(opts = {}) {
3856
- const clientId = opts.clientId ?? process.env[MGMT_CLIENT_ID];
3857
- const clientSecret = opts.clientSecret ?? process.env[MGMT_CLIENT_SECRET];
3858
- const tsgId = opts.tsgId ?? process.env[MGMT_TSG_ID];
3859
3899
  const apiEndpoint = opts.apiEndpoint ?? process.env[MGMT_ENDPOINT] ?? DEFAULT_MGMT_ENDPOINT;
3860
- const tokenEndpoint = opts.tokenEndpoint ?? process.env[MGMT_TOKEN_ENDPOINT];
3861
- const numRetries = Math.min(
3862
- Math.max(opts.numRetries ?? MAX_NUMBER_OF_RETRIES, 0),
3863
- MAX_NUMBER_OF_RETRIES
3864
- );
3865
- if (!clientId) {
3866
- throw new AISecSDKException(
3867
- "clientId is required (option or PANW_MGMT_CLIENT_ID env var)",
3868
- "AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
3869
- );
3870
- }
3871
- if (!clientSecret) {
3872
- throw new AISecSDKException(
3873
- "clientSecret is required (option or PANW_MGMT_CLIENT_SECRET env var)",
3874
- "AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
3875
- );
3876
- }
3877
- if (!tsgId) {
3878
- throw new AISecSDKException(
3879
- "tsgId is required (option or PANW_MGMT_TSG_ID env var)",
3880
- "AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
3881
- );
3882
- }
3883
- const oauthClient = new OAuthClient({
3884
- clientId,
3885
- clientSecret,
3886
- tsgId,
3887
- tokenEndpoint
3900
+ const { baseUrl, oauthClient, numRetries, tsgId } = resolveOAuthConfig({
3901
+ clientId: opts.clientId,
3902
+ clientSecret: opts.clientSecret,
3903
+ tsgId: opts.tsgId,
3904
+ baseUrl: apiEndpoint,
3905
+ numRetries: opts.numRetries,
3906
+ tokenEndpoint: opts.tokenEndpoint,
3907
+ primaryEnvPrefix: "PANW_MGMT"
3888
3908
  });
3889
3909
  this.profiles = new ProfilesClient({
3890
- baseUrl: apiEndpoint,
3910
+ baseUrl,
3891
3911
  oauthClient,
3892
3912
  tsgId,
3893
3913
  numRetries
3894
3914
  });
3895
3915
  this.topics = new TopicsClient({
3896
- baseUrl: apiEndpoint,
3916
+ baseUrl,
3897
3917
  oauthClient,
3898
3918
  tsgId,
3899
3919
  numRetries
3900
3920
  });
3901
3921
  this.apiKeys = new ApiKeysClient({
3902
- baseUrl: apiEndpoint,
3922
+ baseUrl,
3903
3923
  oauthClient,
3904
3924
  tsgId,
3905
3925
  numRetries
3906
3926
  });
3907
3927
  this.customerApps = new CustomerAppsClient({
3908
- baseUrl: apiEndpoint,
3928
+ baseUrl,
3909
3929
  oauthClient,
3910
3930
  tsgId,
3911
3931
  numRetries
3912
3932
  });
3913
3933
  this.dlpProfiles = new DlpProfilesClient({
3914
- baseUrl: apiEndpoint,
3934
+ baseUrl,
3915
3935
  oauthClient,
3916
3936
  numRetries
3917
3937
  });
3918
3938
  this.deploymentProfiles = new DeploymentProfilesClient({
3919
- baseUrl: apiEndpoint,
3939
+ baseUrl,
3920
3940
  oauthClient,
3921
3941
  numRetries
3922
3942
  });
3923
3943
  this.scanLogs = new ScanLogsClient({
3924
- baseUrl: apiEndpoint,
3944
+ baseUrl,
3925
3945
  oauthClient,
3926
3946
  numRetries
3927
3947
  });
3928
3948
  this.oauth = new OAuthManagementClient({
3929
- baseUrl: apiEndpoint,
3949
+ baseUrl,
3930
3950
  oauthClient,
3931
3951
  numRetries
3932
3952
  });
@@ -4542,55 +4562,34 @@ var ModelSecurityClient = class {
4542
4562
  oauthClient;
4543
4563
  numRetries;
4544
4564
  constructor(opts = {}) {
4545
- const clientId = opts.clientId ?? process.env[MODEL_SEC_CLIENT_ID] ?? process.env[MGMT_CLIENT_ID];
4546
- const clientSecret = opts.clientSecret ?? process.env[MODEL_SEC_CLIENT_SECRET] ?? process.env[MGMT_CLIENT_SECRET];
4547
- const tsgId = opts.tsgId ?? process.env[MODEL_SEC_TSG_ID] ?? process.env[MGMT_TSG_ID];
4548
4565
  const dataEndpoint = opts.dataEndpoint ?? process.env[MODEL_SEC_DATA_ENDPOINT] ?? DEFAULT_MODEL_SEC_DATA_ENDPOINT;
4549
4566
  const mgmtEndpoint = opts.mgmtEndpoint ?? process.env[MODEL_SEC_MGMT_ENDPOINT] ?? DEFAULT_MODEL_SEC_MGMT_ENDPOINT;
4550
- const tokenEndpoint = opts.tokenEndpoint ?? process.env[MODEL_SEC_TOKEN_ENDPOINT] ?? process.env[MGMT_TOKEN_ENDPOINT];
4551
- const numRetries = Math.min(
4552
- Math.max(opts.numRetries ?? MAX_NUMBER_OF_RETRIES, 0),
4553
- MAX_NUMBER_OF_RETRIES
4554
- );
4555
- if (!clientId) {
4556
- throw new AISecSDKException(
4557
- "clientId is required (option or PANW_MODEL_SEC_CLIENT_ID / PANW_MGMT_CLIENT_ID env var)",
4558
- "AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
4559
- );
4560
- }
4561
- if (!clientSecret) {
4562
- throw new AISecSDKException(
4563
- "clientSecret is required (option or PANW_MODEL_SEC_CLIENT_SECRET / PANW_MGMT_CLIENT_SECRET env var)",
4564
- "AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
4565
- );
4566
- }
4567
- if (!tsgId) {
4568
- throw new AISecSDKException(
4569
- "tsgId is required (option or PANW_MODEL_SEC_TSG_ID / PANW_MGMT_TSG_ID env var)",
4570
- "AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
4571
- );
4572
- }
4573
- this.oauthClient = new OAuthClient({
4574
- clientId,
4575
- clientSecret,
4576
- tsgId,
4577
- tokenEndpoint
4567
+ const { oauthClient, numRetries } = resolveOAuthConfig({
4568
+ clientId: opts.clientId,
4569
+ clientSecret: opts.clientSecret,
4570
+ tsgId: opts.tsgId,
4571
+ baseUrl: mgmtEndpoint,
4572
+ numRetries: opts.numRetries,
4573
+ tokenEndpoint: opts.tokenEndpoint,
4574
+ primaryEnvPrefix: "PANW_MODEL_SEC",
4575
+ fallbackEnvPrefix: "PANW_MGMT"
4578
4576
  });
4577
+ this.oauthClient = oauthClient;
4579
4578
  this.mgmtEndpoint = mgmtEndpoint;
4580
4579
  this.numRetries = numRetries;
4581
4580
  this.scans = new ModelSecurityScansClient({
4582
4581
  baseUrl: dataEndpoint,
4583
- oauthClient: this.oauthClient,
4582
+ oauthClient,
4584
4583
  numRetries
4585
4584
  });
4586
4585
  this.securityGroups = new ModelSecurityGroupsClient({
4587
4586
  baseUrl: mgmtEndpoint,
4588
- oauthClient: this.oauthClient,
4587
+ oauthClient,
4589
4588
  numRetries
4590
4589
  });
4591
4590
  this.securityRules = new ModelSecurityRulesClient({
4592
4591
  baseUrl: mgmtEndpoint,
4593
- oauthClient: this.oauthClient,
4592
+ oauthClient,
4594
4593
  numRetries
4595
4594
  });
4596
4595
  }
@@ -5742,61 +5741,45 @@ var RedTeamClient = class {
5742
5741
  oauthClient;
5743
5742
  numRetries;
5744
5743
  constructor(opts = {}) {
5745
- const clientId = opts.clientId ?? process.env[RED_TEAM_CLIENT_ID] ?? process.env[MGMT_CLIENT_ID];
5746
- const clientSecret = opts.clientSecret ?? process.env[RED_TEAM_CLIENT_SECRET] ?? process.env[MGMT_CLIENT_SECRET];
5747
- const tsgId = opts.tsgId ?? process.env[RED_TEAM_TSG_ID] ?? process.env[MGMT_TSG_ID];
5748
5744
  const dataEndpoint = opts.dataEndpoint ?? process.env[RED_TEAM_DATA_ENDPOINT] ?? DEFAULT_RED_TEAM_DATA_ENDPOINT;
5749
5745
  const mgmtEndpoint = opts.mgmtEndpoint ?? process.env[RED_TEAM_MGMT_ENDPOINT] ?? DEFAULT_RED_TEAM_MGMT_ENDPOINT;
5750
- const tokenEndpoint = opts.tokenEndpoint ?? process.env[RED_TEAM_TOKEN_ENDPOINT] ?? process.env[MGMT_TOKEN_ENDPOINT];
5751
- const numRetries = Math.min(
5752
- Math.max(opts.numRetries ?? MAX_NUMBER_OF_RETRIES, 0),
5753
- MAX_NUMBER_OF_RETRIES
5754
- );
5755
- if (!clientId) {
5756
- throw new AISecSDKException(
5757
- "clientId is required (option or PANW_RED_TEAM_CLIENT_ID / PANW_MGMT_CLIENT_ID env var)",
5758
- "AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
5759
- );
5760
- }
5761
- if (!clientSecret) {
5762
- throw new AISecSDKException(
5763
- "clientSecret is required (option or PANW_RED_TEAM_CLIENT_SECRET / PANW_MGMT_CLIENT_SECRET env var)",
5764
- "AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
5765
- );
5766
- }
5767
- if (!tsgId) {
5768
- throw new AISecSDKException(
5769
- "tsgId is required (option or PANW_RED_TEAM_TSG_ID / PANW_MGMT_TSG_ID env var)",
5770
- "AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
5771
- );
5772
- }
5773
- this.oauthClient = new OAuthClient({ clientId, clientSecret, tsgId, tokenEndpoint });
5746
+ const { oauthClient, numRetries } = resolveOAuthConfig({
5747
+ clientId: opts.clientId,
5748
+ clientSecret: opts.clientSecret,
5749
+ tsgId: opts.tsgId,
5750
+ baseUrl: dataEndpoint,
5751
+ numRetries: opts.numRetries,
5752
+ tokenEndpoint: opts.tokenEndpoint,
5753
+ primaryEnvPrefix: "PANW_RED_TEAM",
5754
+ fallbackEnvPrefix: "PANW_MGMT"
5755
+ });
5756
+ this.oauthClient = oauthClient;
5774
5757
  this.dataEndpoint = dataEndpoint;
5775
5758
  this.mgmtEndpoint = mgmtEndpoint;
5776
5759
  this.numRetries = numRetries;
5777
5760
  this.scans = new RedTeamScansClient({
5778
5761
  baseUrl: dataEndpoint,
5779
- oauthClient: this.oauthClient,
5762
+ oauthClient,
5780
5763
  numRetries
5781
5764
  });
5782
5765
  this.reports = new RedTeamReportsClient({
5783
5766
  baseUrl: dataEndpoint,
5784
- oauthClient: this.oauthClient,
5767
+ oauthClient,
5785
5768
  numRetries
5786
5769
  });
5787
5770
  this.customAttackReports = new RedTeamCustomAttackReportsClient({
5788
5771
  baseUrl: dataEndpoint,
5789
- oauthClient: this.oauthClient,
5772
+ oauthClient,
5790
5773
  numRetries
5791
5774
  });
5792
5775
  this.targets = new RedTeamTargetsClient({
5793
5776
  baseUrl: mgmtEndpoint,
5794
- oauthClient: this.oauthClient,
5777
+ oauthClient,
5795
5778
  numRetries
5796
5779
  });
5797
5780
  this.customAttacks = new RedTeamCustomAttacksClient({
5798
5781
  baseUrl: mgmtEndpoint,
5799
- oauthClient: this.oauthClient,
5782
+ oauthClient,
5800
5783
  numRetries
5801
5784
  });
5802
5785
  }