@cdot65/prisma-airs-sdk 0.1.2 → 0.2.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/README.md +33 -1
- package/dist/index.cjs +553 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9030 -2
- package/dist/index.d.ts +9030 -2
- package/dist/index.js +527 -0
- package/dist/index.js.map +1 -1
- package/package.json +10 -3
package/dist/index.js
CHANGED
|
@@ -25,10 +25,22 @@ var MAX_NUMBER_OF_RETRIES = 5;
|
|
|
25
25
|
var HTTP_FORCE_RETRY_STATUS_CODES = [500, 502, 503, 504];
|
|
26
26
|
var SDK_VERSION = "0.1.2";
|
|
27
27
|
var USER_AGENT = `PAN-AIRS/${SDK_VERSION}-typescript-sdk`;
|
|
28
|
+
var DEFAULT_MGMT_ENDPOINT = "https://api.sase.paloaltonetworks.com/aisec";
|
|
29
|
+
var DEFAULT_TOKEN_ENDPOINT = "https://auth.apps.paloaltonetworks.com/oauth2/access_token";
|
|
30
|
+
var MGMT_CLIENT_ID = "PANW_MGMT_CLIENT_ID";
|
|
31
|
+
var MGMT_CLIENT_SECRET = "PANW_MGMT_CLIENT_SECRET";
|
|
32
|
+
var MGMT_TSG_ID = "PANW_MGMT_TSG_ID";
|
|
33
|
+
var MGMT_ENDPOINT = "PANW_MGMT_ENDPOINT";
|
|
34
|
+
var MGMT_TOKEN_ENDPOINT = "PANW_MGMT_TOKEN_ENDPOINT";
|
|
28
35
|
var SYNC_SCAN_PATH = "/v1/scan/sync/request";
|
|
29
36
|
var ASYNC_SCAN_PATH = "/v1/scan/async/request";
|
|
30
37
|
var SCAN_RESULTS_PATH = "/v1/scan/results";
|
|
31
38
|
var SCAN_REPORTS_PATH = "/v1/scan/reports";
|
|
39
|
+
var MGMT_PROFILE_PATH = "/v1/mgmt/profile";
|
|
40
|
+
var MGMT_PROFILES_TSG_PATH = "/v1/mgmt/profiles/tsg";
|
|
41
|
+
var MGMT_TOPIC_PATH = "/v1/mgmt/topic";
|
|
42
|
+
var MGMT_TOPICS_TSG_PATH = "/v1/mgmt/topics/tsg";
|
|
43
|
+
var MGMT_TOPIC_FORCE_PATH = "/v1/mgmt/topic/force";
|
|
32
44
|
|
|
33
45
|
// src/errors.ts
|
|
34
46
|
var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
|
|
@@ -37,6 +49,7 @@ var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
|
|
|
37
49
|
ErrorType2["USER_REQUEST_PAYLOAD_ERROR"] = "AISEC_USER_REQUEST_PAYLOAD_ERROR";
|
|
38
50
|
ErrorType2["MISSING_VARIABLE"] = "AISEC_MISSING_VARIABLE";
|
|
39
51
|
ErrorType2["AISEC_SDK_ERROR"] = "AISEC_SDK_ERROR";
|
|
52
|
+
ErrorType2["OAUTH_ERROR"] = "AISEC_OAUTH_ERROR";
|
|
40
53
|
return ErrorType2;
|
|
41
54
|
})(ErrorType || {});
|
|
42
55
|
var AISecSDKException = class _AISecSDKException extends Error {
|
|
@@ -657,6 +670,494 @@ var ErrorResponseSchema = z14.object({
|
|
|
657
670
|
unit: z14.string().optional()
|
|
658
671
|
}).optional()
|
|
659
672
|
});
|
|
673
|
+
|
|
674
|
+
// src/models/mgmt-security-profile.ts
|
|
675
|
+
import { z as z15 } from "zod";
|
|
676
|
+
var DlpDataProfileSchema = z15.object({
|
|
677
|
+
profile_name: z15.string(),
|
|
678
|
+
active: z15.boolean().optional()
|
|
679
|
+
}).passthrough();
|
|
680
|
+
var DlpSchema = z15.object({
|
|
681
|
+
dlp_status: z15.string().optional(),
|
|
682
|
+
data_profiles: z15.array(DlpDataProfileSchema).optional()
|
|
683
|
+
}).passthrough();
|
|
684
|
+
var DataLeakDetectionSchema = z15.object({
|
|
685
|
+
"data-leak-detection-status": z15.string().optional(),
|
|
686
|
+
dlp: DlpSchema.optional()
|
|
687
|
+
}).passthrough();
|
|
688
|
+
var AppProtectionSchema = z15.object({
|
|
689
|
+
"prompt-injection": z15.string().optional(),
|
|
690
|
+
"jailbreak-detection": z15.string().optional()
|
|
691
|
+
}).passthrough();
|
|
692
|
+
var ModelProtectionSchema = z15.object({
|
|
693
|
+
"model-denial-of-service": z15.string().optional()
|
|
694
|
+
}).passthrough();
|
|
695
|
+
var AgentProtectionSchema = z15.object({
|
|
696
|
+
"malicious-agent-activity": z15.string().optional()
|
|
697
|
+
}).passthrough();
|
|
698
|
+
var LatencySchema = z15.object({
|
|
699
|
+
status: z15.string().optional(),
|
|
700
|
+
max_latency_ms: z15.number().optional()
|
|
701
|
+
}).passthrough();
|
|
702
|
+
var ModelConfigurationSchema = z15.object({
|
|
703
|
+
latency: LatencySchema.optional()
|
|
704
|
+
}).passthrough();
|
|
705
|
+
var PolicySchema = z15.object({
|
|
706
|
+
"data-leak-detection": DataLeakDetectionSchema.optional(),
|
|
707
|
+
"app-protection": AppProtectionSchema.optional(),
|
|
708
|
+
"model-protection": ModelProtectionSchema.optional(),
|
|
709
|
+
"agent-protection": AgentProtectionSchema.optional(),
|
|
710
|
+
"model-configuration": ModelConfigurationSchema.optional()
|
|
711
|
+
}).passthrough();
|
|
712
|
+
var SecurityProfileSchema = z15.object({
|
|
713
|
+
profile_id: z15.string().optional(),
|
|
714
|
+
profile_name: z15.string(),
|
|
715
|
+
revision: z15.number().optional(),
|
|
716
|
+
active: z15.boolean().optional(),
|
|
717
|
+
policy: PolicySchema.optional(),
|
|
718
|
+
created_by: z15.string().optional(),
|
|
719
|
+
updated_by: z15.string().optional(),
|
|
720
|
+
last_modified_ts: z15.string().optional()
|
|
721
|
+
}).passthrough();
|
|
722
|
+
var CreateSecurityProfileRequestSchema = z15.object({
|
|
723
|
+
profile_id: z15.string().optional(),
|
|
724
|
+
profile_name: z15.string(),
|
|
725
|
+
revision: z15.number().optional(),
|
|
726
|
+
active: z15.boolean().optional(),
|
|
727
|
+
policy: PolicySchema.optional(),
|
|
728
|
+
created_by: z15.string().optional(),
|
|
729
|
+
updated_by: z15.string().optional(),
|
|
730
|
+
last_modified_ts: z15.string().optional()
|
|
731
|
+
}).passthrough();
|
|
732
|
+
var SecurityProfileListResponseSchema = z15.object({
|
|
733
|
+
ai_profiles: z15.array(SecurityProfileSchema),
|
|
734
|
+
next_offset: z15.number().optional()
|
|
735
|
+
}).passthrough();
|
|
736
|
+
var DeleteProfileResponseSchema = z15.object({
|
|
737
|
+
message: z15.string()
|
|
738
|
+
}).passthrough();
|
|
739
|
+
var DeleteProfileConflictSchema = z15.object({
|
|
740
|
+
message: z15.string(),
|
|
741
|
+
payload: z15.array(
|
|
742
|
+
z15.object({
|
|
743
|
+
policy_id: z15.string(),
|
|
744
|
+
policy_name: z15.string(),
|
|
745
|
+
priority: z15.number()
|
|
746
|
+
}).passthrough()
|
|
747
|
+
)
|
|
748
|
+
}).passthrough();
|
|
749
|
+
|
|
750
|
+
// src/models/mgmt-custom-topic.ts
|
|
751
|
+
import { z as z16 } from "zod";
|
|
752
|
+
var CustomTopicSchema = z16.object({
|
|
753
|
+
topic_id: z16.string().optional(),
|
|
754
|
+
topic_name: z16.string(),
|
|
755
|
+
revision: z16.number().optional(),
|
|
756
|
+
active: z16.boolean().optional(),
|
|
757
|
+
description: z16.string().optional(),
|
|
758
|
+
examples: z16.array(z16.string()).optional(),
|
|
759
|
+
created_by: z16.string().optional(),
|
|
760
|
+
updated_by: z16.string().optional(),
|
|
761
|
+
last_modified_ts: z16.string().optional(),
|
|
762
|
+
created_ts: z16.string().optional()
|
|
763
|
+
}).passthrough();
|
|
764
|
+
var CreateCustomTopicRequestSchema = z16.object({
|
|
765
|
+
topic_id: z16.string().optional(),
|
|
766
|
+
topic_name: z16.string(),
|
|
767
|
+
revision: z16.number().optional(),
|
|
768
|
+
active: z16.boolean().optional(),
|
|
769
|
+
description: z16.string().optional(),
|
|
770
|
+
examples: z16.array(z16.string()).optional(),
|
|
771
|
+
created_by: z16.string().optional(),
|
|
772
|
+
updated_by: z16.string().optional(),
|
|
773
|
+
last_modified_ts: z16.string().optional(),
|
|
774
|
+
created_ts: z16.string().optional()
|
|
775
|
+
}).passthrough();
|
|
776
|
+
var CustomTopicListResponseSchema = z16.object({
|
|
777
|
+
custom_topics: z16.array(CustomTopicSchema),
|
|
778
|
+
next_offset: z16.number().optional()
|
|
779
|
+
}).passthrough();
|
|
780
|
+
var DeleteTopicResponseSchema = z16.object({
|
|
781
|
+
message: z16.string()
|
|
782
|
+
}).passthrough();
|
|
783
|
+
var DeleteTopicConflictSchema = z16.object({
|
|
784
|
+
message: z16.string(),
|
|
785
|
+
payload: z16.array(
|
|
786
|
+
z16.object({
|
|
787
|
+
profile_id: z16.string(),
|
|
788
|
+
profile_name: z16.string(),
|
|
789
|
+
revision: z16.number()
|
|
790
|
+
}).passthrough()
|
|
791
|
+
)
|
|
792
|
+
}).passthrough();
|
|
793
|
+
|
|
794
|
+
// src/models/oauth-token.ts
|
|
795
|
+
import { z as z17 } from "zod";
|
|
796
|
+
var OAuthTokenResponseSchema = z17.object({
|
|
797
|
+
access_token: z17.string(),
|
|
798
|
+
token_type: z17.string().optional(),
|
|
799
|
+
expires_in: z17.number(),
|
|
800
|
+
scope: z17.string().optional()
|
|
801
|
+
});
|
|
802
|
+
|
|
803
|
+
// src/management/oauth-client.ts
|
|
804
|
+
var TOKEN_BUFFER_MS = 3e4;
|
|
805
|
+
var OAuthClient = class {
|
|
806
|
+
tokenEndpoint;
|
|
807
|
+
clientId;
|
|
808
|
+
clientSecret;
|
|
809
|
+
tsgId;
|
|
810
|
+
accessToken = null;
|
|
811
|
+
expiresAt = 0;
|
|
812
|
+
pendingFetch = null;
|
|
813
|
+
constructor(opts) {
|
|
814
|
+
this.clientId = opts.clientId;
|
|
815
|
+
this.clientSecret = opts.clientSecret;
|
|
816
|
+
this.tsgId = opts.tsgId;
|
|
817
|
+
this.tokenEndpoint = opts.tokenEndpoint ?? DEFAULT_TOKEN_ENDPOINT;
|
|
818
|
+
}
|
|
819
|
+
async getToken() {
|
|
820
|
+
if (this.accessToken && Date.now() < this.expiresAt - TOKEN_BUFFER_MS) {
|
|
821
|
+
return this.accessToken;
|
|
822
|
+
}
|
|
823
|
+
if (this.pendingFetch) {
|
|
824
|
+
return this.pendingFetch;
|
|
825
|
+
}
|
|
826
|
+
this.pendingFetch = this.fetchToken().finally(() => {
|
|
827
|
+
this.pendingFetch = null;
|
|
828
|
+
});
|
|
829
|
+
return this.pendingFetch;
|
|
830
|
+
}
|
|
831
|
+
clearToken() {
|
|
832
|
+
this.accessToken = null;
|
|
833
|
+
this.expiresAt = 0;
|
|
834
|
+
}
|
|
835
|
+
async fetchToken() {
|
|
836
|
+
const credentials = btoa(`${this.clientId}:${this.clientSecret}`);
|
|
837
|
+
const body = new URLSearchParams({
|
|
838
|
+
grant_type: "client_credentials",
|
|
839
|
+
scope: `tsg_id:${this.tsgId}`
|
|
840
|
+
});
|
|
841
|
+
let response;
|
|
842
|
+
try {
|
|
843
|
+
response = await fetch(this.tokenEndpoint, {
|
|
844
|
+
method: "POST",
|
|
845
|
+
headers: {
|
|
846
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
847
|
+
Authorization: `Basic ${credentials}`
|
|
848
|
+
},
|
|
849
|
+
body: body.toString()
|
|
850
|
+
});
|
|
851
|
+
} catch (err) {
|
|
852
|
+
throw new AISecSDKException(
|
|
853
|
+
`Token request failed: ${err.message}`,
|
|
854
|
+
"AISEC_OAUTH_ERROR" /* OAUTH_ERROR */
|
|
855
|
+
);
|
|
856
|
+
}
|
|
857
|
+
if (!response.ok) {
|
|
858
|
+
let errorMsg;
|
|
859
|
+
try {
|
|
860
|
+
const errorBody = await response.json();
|
|
861
|
+
errorMsg = errorBody.error_description ?? errorBody.error ?? `Token request failed with status ${response.status}`;
|
|
862
|
+
} catch {
|
|
863
|
+
errorMsg = `Token request failed with status ${response.status}`;
|
|
864
|
+
}
|
|
865
|
+
throw new AISecSDKException(errorMsg, "AISEC_OAUTH_ERROR" /* OAUTH_ERROR */);
|
|
866
|
+
}
|
|
867
|
+
const data = OAuthTokenResponseSchema.parse(await response.json());
|
|
868
|
+
this.accessToken = data.access_token;
|
|
869
|
+
this.expiresAt = Date.now() + data.expires_in * 1e3;
|
|
870
|
+
return this.accessToken;
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
// src/management/management-http-client.ts
|
|
875
|
+
function sleep2(ms) {
|
|
876
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
877
|
+
}
|
|
878
|
+
function extractError(body, status) {
|
|
879
|
+
try {
|
|
880
|
+
const parsed = JSON.parse(body);
|
|
881
|
+
return parsed.error_message ?? parsed.message ?? `API error ${status}: ${body}`;
|
|
882
|
+
} catch {
|
|
883
|
+
return body ? `API error ${status}: ${body}` : `API error ${status}`;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
async function managementHttpRequest(opts) {
|
|
887
|
+
const { method, baseUrl, path, body, params, oauthClient, numRetries } = opts;
|
|
888
|
+
let hadTokenRefresh = false;
|
|
889
|
+
for (let attempt = 0; attempt <= numRetries; attempt++) {
|
|
890
|
+
const token = await oauthClient.getToken();
|
|
891
|
+
const stripped = baseUrl.replace(/\/+$/, "");
|
|
892
|
+
const url = new URL(`${stripped}${path}`);
|
|
893
|
+
if (params) {
|
|
894
|
+
for (const [key, value] of Object.entries(params)) {
|
|
895
|
+
url.searchParams.set(key, value);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
const headers = {
|
|
899
|
+
Authorization: `Bearer ${token}`,
|
|
900
|
+
"User-Agent": USER_AGENT
|
|
901
|
+
};
|
|
902
|
+
let bodyStr;
|
|
903
|
+
if (body !== void 0) {
|
|
904
|
+
headers["Content-Type"] = "application/json";
|
|
905
|
+
bodyStr = JSON.stringify(body);
|
|
906
|
+
}
|
|
907
|
+
let response;
|
|
908
|
+
try {
|
|
909
|
+
response = await fetch(url.toString(), {
|
|
910
|
+
method,
|
|
911
|
+
headers,
|
|
912
|
+
body: bodyStr
|
|
913
|
+
});
|
|
914
|
+
} catch (err) {
|
|
915
|
+
if (attempt < numRetries) {
|
|
916
|
+
await sleep2(Math.pow(2, attempt) * 1e3);
|
|
917
|
+
continue;
|
|
918
|
+
}
|
|
919
|
+
throw new AISecSDKException(
|
|
920
|
+
err.message ?? "Network error",
|
|
921
|
+
"AISEC_CLIENT_SIDE_ERROR" /* CLIENT_SIDE_ERROR */
|
|
922
|
+
);
|
|
923
|
+
}
|
|
924
|
+
if (response.ok) {
|
|
925
|
+
const text = await response.text();
|
|
926
|
+
const data = text ? JSON.parse(text) : {};
|
|
927
|
+
return { status: response.status, data };
|
|
928
|
+
}
|
|
929
|
+
if (response.status === 401 && !hadTokenRefresh) {
|
|
930
|
+
hadTokenRefresh = true;
|
|
931
|
+
oauthClient.clearToken();
|
|
932
|
+
attempt--;
|
|
933
|
+
continue;
|
|
934
|
+
}
|
|
935
|
+
if (HTTP_FORCE_RETRY_STATUS_CODES.includes(response.status) && attempt < numRetries) {
|
|
936
|
+
await sleep2(Math.pow(2, attempt) * 1e3);
|
|
937
|
+
continue;
|
|
938
|
+
}
|
|
939
|
+
const errorText = await response.text();
|
|
940
|
+
const errorMessage = extractError(errorText, response.status);
|
|
941
|
+
const errorType = response.status >= 500 ? "AISEC_SERVER_SIDE_ERROR" /* SERVER_SIDE_ERROR */ : "AISEC_CLIENT_SIDE_ERROR" /* CLIENT_SIDE_ERROR */;
|
|
942
|
+
throw new AISecSDKException(errorMessage, errorType);
|
|
943
|
+
}
|
|
944
|
+
throw new AISecSDKException("Max retries exceeded", "AISEC_CLIENT_SIDE_ERROR" /* CLIENT_SIDE_ERROR */);
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
// src/management/profiles.ts
|
|
948
|
+
var ProfilesClient = class {
|
|
949
|
+
baseUrl;
|
|
950
|
+
oauthClient;
|
|
951
|
+
tsgId;
|
|
952
|
+
numRetries;
|
|
953
|
+
constructor(opts) {
|
|
954
|
+
this.baseUrl = opts.baseUrl;
|
|
955
|
+
this.oauthClient = opts.oauthClient;
|
|
956
|
+
this.tsgId = opts.tsgId;
|
|
957
|
+
this.numRetries = opts.numRetries;
|
|
958
|
+
}
|
|
959
|
+
async create(request) {
|
|
960
|
+
const res = await managementHttpRequest({
|
|
961
|
+
method: "POST",
|
|
962
|
+
baseUrl: this.baseUrl,
|
|
963
|
+
path: MGMT_PROFILE_PATH,
|
|
964
|
+
body: request,
|
|
965
|
+
oauthClient: this.oauthClient,
|
|
966
|
+
numRetries: this.numRetries
|
|
967
|
+
});
|
|
968
|
+
return res.data;
|
|
969
|
+
}
|
|
970
|
+
async list(opts) {
|
|
971
|
+
const params = {
|
|
972
|
+
offset: String(opts?.offset ?? 0),
|
|
973
|
+
limit: String(opts?.limit ?? 100)
|
|
974
|
+
};
|
|
975
|
+
const res = await managementHttpRequest({
|
|
976
|
+
method: "GET",
|
|
977
|
+
baseUrl: this.baseUrl,
|
|
978
|
+
path: `${MGMT_PROFILES_TSG_PATH}/${this.tsgId}`,
|
|
979
|
+
params,
|
|
980
|
+
oauthClient: this.oauthClient,
|
|
981
|
+
numRetries: this.numRetries
|
|
982
|
+
});
|
|
983
|
+
return res.data;
|
|
984
|
+
}
|
|
985
|
+
async update(profileId, request) {
|
|
986
|
+
if (!isValidUuid(profileId)) {
|
|
987
|
+
throw new AISecSDKException(
|
|
988
|
+
`Invalid profile_id: ${profileId}`,
|
|
989
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
const res = await managementHttpRequest({
|
|
993
|
+
method: "PUT",
|
|
994
|
+
baseUrl: this.baseUrl,
|
|
995
|
+
path: `${MGMT_PROFILE_PATH}/uuid/${profileId}`,
|
|
996
|
+
body: request,
|
|
997
|
+
oauthClient: this.oauthClient,
|
|
998
|
+
numRetries: this.numRetries
|
|
999
|
+
});
|
|
1000
|
+
return res.data;
|
|
1001
|
+
}
|
|
1002
|
+
async delete(profileId) {
|
|
1003
|
+
if (!isValidUuid(profileId)) {
|
|
1004
|
+
throw new AISecSDKException(
|
|
1005
|
+
`Invalid profile_id: ${profileId}`,
|
|
1006
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
1007
|
+
);
|
|
1008
|
+
}
|
|
1009
|
+
const res = await managementHttpRequest({
|
|
1010
|
+
method: "DELETE",
|
|
1011
|
+
baseUrl: this.baseUrl,
|
|
1012
|
+
path: `${MGMT_PROFILE_PATH}/${profileId}`,
|
|
1013
|
+
oauthClient: this.oauthClient,
|
|
1014
|
+
numRetries: this.numRetries
|
|
1015
|
+
});
|
|
1016
|
+
return res.data;
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
|
|
1020
|
+
// src/management/topics.ts
|
|
1021
|
+
var TopicsClient = class {
|
|
1022
|
+
baseUrl;
|
|
1023
|
+
oauthClient;
|
|
1024
|
+
tsgId;
|
|
1025
|
+
numRetries;
|
|
1026
|
+
constructor(opts) {
|
|
1027
|
+
this.baseUrl = opts.baseUrl;
|
|
1028
|
+
this.oauthClient = opts.oauthClient;
|
|
1029
|
+
this.tsgId = opts.tsgId;
|
|
1030
|
+
this.numRetries = opts.numRetries;
|
|
1031
|
+
}
|
|
1032
|
+
async create(request) {
|
|
1033
|
+
const res = await managementHttpRequest({
|
|
1034
|
+
method: "POST",
|
|
1035
|
+
baseUrl: this.baseUrl,
|
|
1036
|
+
path: MGMT_TOPIC_PATH,
|
|
1037
|
+
body: request,
|
|
1038
|
+
oauthClient: this.oauthClient,
|
|
1039
|
+
numRetries: this.numRetries
|
|
1040
|
+
});
|
|
1041
|
+
return res.data;
|
|
1042
|
+
}
|
|
1043
|
+
async list(opts) {
|
|
1044
|
+
const params = {
|
|
1045
|
+
offset: String(opts?.offset ?? 0),
|
|
1046
|
+
limit: String(opts?.limit ?? 100)
|
|
1047
|
+
};
|
|
1048
|
+
const res = await managementHttpRequest({
|
|
1049
|
+
method: "GET",
|
|
1050
|
+
baseUrl: this.baseUrl,
|
|
1051
|
+
path: `${MGMT_TOPICS_TSG_PATH}/${this.tsgId}`,
|
|
1052
|
+
params,
|
|
1053
|
+
oauthClient: this.oauthClient,
|
|
1054
|
+
numRetries: this.numRetries
|
|
1055
|
+
});
|
|
1056
|
+
return res.data;
|
|
1057
|
+
}
|
|
1058
|
+
async update(topicId, request) {
|
|
1059
|
+
if (!isValidUuid(topicId)) {
|
|
1060
|
+
throw new AISecSDKException(
|
|
1061
|
+
`Invalid topic_id: ${topicId}`,
|
|
1062
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
1063
|
+
);
|
|
1064
|
+
}
|
|
1065
|
+
const res = await managementHttpRequest({
|
|
1066
|
+
method: "PUT",
|
|
1067
|
+
baseUrl: this.baseUrl,
|
|
1068
|
+
path: `${MGMT_TOPIC_PATH}/uuid/${topicId}`,
|
|
1069
|
+
body: request,
|
|
1070
|
+
oauthClient: this.oauthClient,
|
|
1071
|
+
numRetries: this.numRetries
|
|
1072
|
+
});
|
|
1073
|
+
return res.data;
|
|
1074
|
+
}
|
|
1075
|
+
async delete(topicId) {
|
|
1076
|
+
if (!isValidUuid(topicId)) {
|
|
1077
|
+
throw new AISecSDKException(
|
|
1078
|
+
`Invalid topic_id: ${topicId}`,
|
|
1079
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
1080
|
+
);
|
|
1081
|
+
}
|
|
1082
|
+
const res = await managementHttpRequest({
|
|
1083
|
+
method: "DELETE",
|
|
1084
|
+
baseUrl: this.baseUrl,
|
|
1085
|
+
path: `${MGMT_TOPIC_PATH}/${topicId}`,
|
|
1086
|
+
oauthClient: this.oauthClient,
|
|
1087
|
+
numRetries: this.numRetries
|
|
1088
|
+
});
|
|
1089
|
+
return res.data;
|
|
1090
|
+
}
|
|
1091
|
+
async forceDelete(topicId) {
|
|
1092
|
+
if (!isValidUuid(topicId)) {
|
|
1093
|
+
throw new AISecSDKException(
|
|
1094
|
+
`Invalid topic_id: ${topicId}`,
|
|
1095
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
1096
|
+
);
|
|
1097
|
+
}
|
|
1098
|
+
const res = await managementHttpRequest({
|
|
1099
|
+
method: "DELETE",
|
|
1100
|
+
baseUrl: this.baseUrl,
|
|
1101
|
+
path: `${MGMT_TOPIC_FORCE_PATH}/${topicId}`,
|
|
1102
|
+
oauthClient: this.oauthClient,
|
|
1103
|
+
numRetries: this.numRetries
|
|
1104
|
+
});
|
|
1105
|
+
return res.data;
|
|
1106
|
+
}
|
|
1107
|
+
};
|
|
1108
|
+
|
|
1109
|
+
// src/management/client.ts
|
|
1110
|
+
var ManagementClient = class {
|
|
1111
|
+
profiles;
|
|
1112
|
+
topics;
|
|
1113
|
+
constructor(opts = {}) {
|
|
1114
|
+
const clientId = opts.clientId ?? process.env[MGMT_CLIENT_ID];
|
|
1115
|
+
const clientSecret = opts.clientSecret ?? process.env[MGMT_CLIENT_SECRET];
|
|
1116
|
+
const tsgId = opts.tsgId ?? process.env[MGMT_TSG_ID];
|
|
1117
|
+
const apiEndpoint = opts.apiEndpoint ?? process.env[MGMT_ENDPOINT] ?? DEFAULT_MGMT_ENDPOINT;
|
|
1118
|
+
const tokenEndpoint = opts.tokenEndpoint ?? process.env[MGMT_TOKEN_ENDPOINT];
|
|
1119
|
+
const numRetries = Math.min(
|
|
1120
|
+
Math.max(opts.numRetries ?? MAX_NUMBER_OF_RETRIES, 0),
|
|
1121
|
+
MAX_NUMBER_OF_RETRIES
|
|
1122
|
+
);
|
|
1123
|
+
if (!clientId) {
|
|
1124
|
+
throw new AISecSDKException(
|
|
1125
|
+
"clientId is required (option or PANW_MGMT_CLIENT_ID env var)",
|
|
1126
|
+
"AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
|
|
1127
|
+
);
|
|
1128
|
+
}
|
|
1129
|
+
if (!clientSecret) {
|
|
1130
|
+
throw new AISecSDKException(
|
|
1131
|
+
"clientSecret is required (option or PANW_MGMT_CLIENT_SECRET env var)",
|
|
1132
|
+
"AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
|
|
1133
|
+
);
|
|
1134
|
+
}
|
|
1135
|
+
if (!tsgId) {
|
|
1136
|
+
throw new AISecSDKException(
|
|
1137
|
+
"tsgId is required (option or PANW_MGMT_TSG_ID env var)",
|
|
1138
|
+
"AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
|
|
1139
|
+
);
|
|
1140
|
+
}
|
|
1141
|
+
const oauthClient = new OAuthClient({
|
|
1142
|
+
clientId,
|
|
1143
|
+
clientSecret,
|
|
1144
|
+
tsgId,
|
|
1145
|
+
tokenEndpoint
|
|
1146
|
+
});
|
|
1147
|
+
this.profiles = new ProfilesClient({
|
|
1148
|
+
baseUrl: apiEndpoint,
|
|
1149
|
+
oauthClient,
|
|
1150
|
+
tsgId,
|
|
1151
|
+
numRetries
|
|
1152
|
+
});
|
|
1153
|
+
this.topics = new TopicsClient({
|
|
1154
|
+
baseUrl: apiEndpoint,
|
|
1155
|
+
oauthClient,
|
|
1156
|
+
tsgId,
|
|
1157
|
+
numRetries
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
};
|
|
660
1161
|
export {
|
|
661
1162
|
AISecSDKException,
|
|
662
1163
|
AI_SEC_API_ENDPOINT,
|
|
@@ -669,9 +1170,19 @@ export {
|
|
|
669
1170
|
AsyncScanResponseSchema,
|
|
670
1171
|
BEARER,
|
|
671
1172
|
Content,
|
|
1173
|
+
CreateCustomTopicRequestSchema,
|
|
1174
|
+
CreateSecurityProfileRequestSchema,
|
|
1175
|
+
CustomTopicListResponseSchema,
|
|
1176
|
+
CustomTopicSchema,
|
|
672
1177
|
DEFAULT_ENDPOINT,
|
|
1178
|
+
DEFAULT_MGMT_ENDPOINT,
|
|
1179
|
+
DEFAULT_TOKEN_ENDPOINT,
|
|
673
1180
|
DSDetailResultSchema,
|
|
674
1181
|
DSResultMetadataSchema,
|
|
1182
|
+
DeleteProfileConflictSchema,
|
|
1183
|
+
DeleteProfileResponseSchema,
|
|
1184
|
+
DeleteTopicConflictSchema,
|
|
1185
|
+
DeleteTopicResponseSchema,
|
|
675
1186
|
DetectionServiceResultSchema,
|
|
676
1187
|
DlpReportSchema,
|
|
677
1188
|
ErrorResponseSchema,
|
|
@@ -695,9 +1206,22 @@ export {
|
|
|
695
1206
|
MAX_SESSION_ID_STR_LENGTH,
|
|
696
1207
|
MAX_TOKEN_LENGTH,
|
|
697
1208
|
MAX_TRANSACTION_ID_STR_LENGTH,
|
|
1209
|
+
MGMT_CLIENT_ID,
|
|
1210
|
+
MGMT_CLIENT_SECRET,
|
|
1211
|
+
MGMT_ENDPOINT,
|
|
1212
|
+
MGMT_PROFILES_TSG_PATH,
|
|
1213
|
+
MGMT_PROFILE_PATH,
|
|
1214
|
+
MGMT_TOKEN_ENDPOINT,
|
|
1215
|
+
MGMT_TOPICS_TSG_PATH,
|
|
1216
|
+
MGMT_TOPIC_FORCE_PATH,
|
|
1217
|
+
MGMT_TOPIC_PATH,
|
|
1218
|
+
MGMT_TSG_ID,
|
|
1219
|
+
ManagementClient,
|
|
698
1220
|
MaskedDataSchema,
|
|
699
1221
|
MetadataSchema,
|
|
700
1222
|
PAYLOAD_HASH,
|
|
1223
|
+
PolicySchema,
|
|
1224
|
+
ProfilesClient,
|
|
701
1225
|
PromptDetectedSchema,
|
|
702
1226
|
PromptDetectionDetailsSchema,
|
|
703
1227
|
ResponseDetectedSchema,
|
|
@@ -712,10 +1236,13 @@ export {
|
|
|
712
1236
|
ScanResponseSchema,
|
|
713
1237
|
ScanSummarySchema,
|
|
714
1238
|
Scanner,
|
|
1239
|
+
SecurityProfileListResponseSchema,
|
|
1240
|
+
SecurityProfileSchema,
|
|
715
1241
|
ThreatScanReportSchema,
|
|
716
1242
|
ToolDetectedSchema,
|
|
717
1243
|
ToolEventMetadataSchema,
|
|
718
1244
|
ToolEventSchema,
|
|
1245
|
+
TopicsClient,
|
|
719
1246
|
USER_AGENT,
|
|
720
1247
|
UrlfEntrySchema,
|
|
721
1248
|
globalConfiguration,
|