@cdot65/prisma-airs-sdk 0.1.0 → 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 CHANGED
@@ -129,7 +129,39 @@ try {
129
129
  }
130
130
  ```
131
131
 
132
- Error types: `SERVER_SIDE_ERROR`, `CLIENT_SIDE_ERROR`, `USER_REQUEST_PAYLOAD_ERROR`, `MISSING_VARIABLE`, `AISEC_SDK_ERROR`.
132
+ Error types: `SERVER_SIDE_ERROR`, `CLIENT_SIDE_ERROR`, `USER_REQUEST_PAYLOAD_ERROR`, `MISSING_VARIABLE`, `AISEC_SDK_ERROR`, `OAUTH_ERROR`.
133
+
134
+ ## Management API
135
+
136
+ Separate client for CRUD operations on Security Profiles and Custom Topics via OAuth2 client credentials. See [docs/management-api.md](docs/management-api.md) for full details.
137
+
138
+ ```bash
139
+ # Required env vars (or pass as constructor options)
140
+ export PANW_MGMT_CLIENT_ID=your-client-id
141
+ export PANW_MGMT_CLIENT_SECRET=your-client-secret
142
+ export PANW_MGMT_TSG_ID=1234567890
143
+ # Optional: override for EU/UK/FedRAMP
144
+ # export PANW_MGMT_ENDPOINT=https://api.eu.sase.paloaltonetworks.com/aisec
145
+ ```
146
+
147
+ ```ts
148
+ import { ManagementClient } from '@cdot65/prisma-airs-sdk';
149
+
150
+ const client = new ManagementClient();
151
+
152
+ // Security Profiles
153
+ const profiles = await client.profiles.list();
154
+ const created = await client.profiles.create({ profile_name: 'my-profile', active: true, policy: { ... } });
155
+ await client.profiles.update(created.profile_id, { ... });
156
+ await client.profiles.delete(created.profile_id);
157
+
158
+ // Custom Topics
159
+ const topics = await client.topics.list();
160
+ const topic = await client.topics.create({ topic_name: 'pii-detector', examples: ['SSN: 123-45-6789'] });
161
+ await client.topics.update(topic.topic_id, { ... });
162
+ await client.topics.delete(topic.topic_id);
163
+ await client.topics.forceDelete(topic.topic_id); // even if referenced by a profile
164
+ ```
133
165
 
134
166
  ## Migration from v0.1
135
167
 
package/dist/index.cjs CHANGED
@@ -31,9 +31,19 @@ __export(index_exports, {
31
31
  AsyncScanResponseSchema: () => AsyncScanResponseSchema,
32
32
  BEARER: () => BEARER,
33
33
  Content: () => Content,
34
+ CreateCustomTopicRequestSchema: () => CreateCustomTopicRequestSchema,
35
+ CreateSecurityProfileRequestSchema: () => CreateSecurityProfileRequestSchema,
36
+ CustomTopicListResponseSchema: () => CustomTopicListResponseSchema,
37
+ CustomTopicSchema: () => CustomTopicSchema,
34
38
  DEFAULT_ENDPOINT: () => DEFAULT_ENDPOINT,
39
+ DEFAULT_MGMT_ENDPOINT: () => DEFAULT_MGMT_ENDPOINT,
40
+ DEFAULT_TOKEN_ENDPOINT: () => DEFAULT_TOKEN_ENDPOINT,
35
41
  DSDetailResultSchema: () => DSDetailResultSchema,
36
42
  DSResultMetadataSchema: () => DSResultMetadataSchema,
43
+ DeleteProfileConflictSchema: () => DeleteProfileConflictSchema,
44
+ DeleteProfileResponseSchema: () => DeleteProfileResponseSchema,
45
+ DeleteTopicConflictSchema: () => DeleteTopicConflictSchema,
46
+ DeleteTopicResponseSchema: () => DeleteTopicResponseSchema,
37
47
  DetectionServiceResultSchema: () => DetectionServiceResultSchema,
38
48
  DlpReportSchema: () => DlpReportSchema,
39
49
  ErrorResponseSchema: () => ErrorResponseSchema,
@@ -57,9 +67,22 @@ __export(index_exports, {
57
67
  MAX_SESSION_ID_STR_LENGTH: () => MAX_SESSION_ID_STR_LENGTH,
58
68
  MAX_TOKEN_LENGTH: () => MAX_TOKEN_LENGTH,
59
69
  MAX_TRANSACTION_ID_STR_LENGTH: () => MAX_TRANSACTION_ID_STR_LENGTH,
70
+ MGMT_CLIENT_ID: () => MGMT_CLIENT_ID,
71
+ MGMT_CLIENT_SECRET: () => MGMT_CLIENT_SECRET,
72
+ MGMT_ENDPOINT: () => MGMT_ENDPOINT,
73
+ MGMT_PROFILES_TSG_PATH: () => MGMT_PROFILES_TSG_PATH,
74
+ MGMT_PROFILE_PATH: () => MGMT_PROFILE_PATH,
75
+ MGMT_TOKEN_ENDPOINT: () => MGMT_TOKEN_ENDPOINT,
76
+ MGMT_TOPICS_TSG_PATH: () => MGMT_TOPICS_TSG_PATH,
77
+ MGMT_TOPIC_FORCE_PATH: () => MGMT_TOPIC_FORCE_PATH,
78
+ MGMT_TOPIC_PATH: () => MGMT_TOPIC_PATH,
79
+ MGMT_TSG_ID: () => MGMT_TSG_ID,
80
+ ManagementClient: () => ManagementClient,
60
81
  MaskedDataSchema: () => MaskedDataSchema,
61
82
  MetadataSchema: () => MetadataSchema,
62
83
  PAYLOAD_HASH: () => PAYLOAD_HASH,
84
+ PolicySchema: () => PolicySchema,
85
+ ProfilesClient: () => ProfilesClient,
63
86
  PromptDetectedSchema: () => PromptDetectedSchema,
64
87
  PromptDetectionDetailsSchema: () => PromptDetectionDetailsSchema,
65
88
  ResponseDetectedSchema: () => ResponseDetectedSchema,
@@ -74,10 +97,13 @@ __export(index_exports, {
74
97
  ScanResponseSchema: () => ScanResponseSchema,
75
98
  ScanSummarySchema: () => ScanSummarySchema,
76
99
  Scanner: () => Scanner,
100
+ SecurityProfileListResponseSchema: () => SecurityProfileListResponseSchema,
101
+ SecurityProfileSchema: () => SecurityProfileSchema,
77
102
  ThreatScanReportSchema: () => ThreatScanReportSchema,
78
103
  ToolDetectedSchema: () => ToolDetectedSchema,
79
104
  ToolEventMetadataSchema: () => ToolEventMetadataSchema,
80
105
  ToolEventSchema: () => ToolEventSchema,
106
+ TopicsClient: () => TopicsClient,
81
107
  USER_AGENT: () => USER_AGENT,
82
108
  UrlfEntrySchema: () => UrlfEntrySchema,
83
109
  globalConfiguration: () => globalConfiguration,
@@ -110,12 +136,24 @@ var MAX_NUMBER_OF_BATCH_SCAN_OBJECTS = 5;
110
136
  var MAX_CONNECTION_POOL_SIZE = 100;
111
137
  var MAX_NUMBER_OF_RETRIES = 5;
112
138
  var HTTP_FORCE_RETRY_STATUS_CODES = [500, 502, 503, 504];
113
- var SDK_VERSION = "0.1.0";
139
+ var SDK_VERSION = "0.1.2";
114
140
  var USER_AGENT = `PAN-AIRS/${SDK_VERSION}-typescript-sdk`;
141
+ var DEFAULT_MGMT_ENDPOINT = "https://api.sase.paloaltonetworks.com/aisec";
142
+ var DEFAULT_TOKEN_ENDPOINT = "https://auth.apps.paloaltonetworks.com/oauth2/access_token";
143
+ var MGMT_CLIENT_ID = "PANW_MGMT_CLIENT_ID";
144
+ var MGMT_CLIENT_SECRET = "PANW_MGMT_CLIENT_SECRET";
145
+ var MGMT_TSG_ID = "PANW_MGMT_TSG_ID";
146
+ var MGMT_ENDPOINT = "PANW_MGMT_ENDPOINT";
147
+ var MGMT_TOKEN_ENDPOINT = "PANW_MGMT_TOKEN_ENDPOINT";
115
148
  var SYNC_SCAN_PATH = "/v1/scan/sync/request";
116
149
  var ASYNC_SCAN_PATH = "/v1/scan/async/request";
117
150
  var SCAN_RESULTS_PATH = "/v1/scan/results";
118
151
  var SCAN_REPORTS_PATH = "/v1/scan/reports";
152
+ var MGMT_PROFILE_PATH = "/v1/mgmt/profile";
153
+ var MGMT_PROFILES_TSG_PATH = "/v1/mgmt/profiles/tsg";
154
+ var MGMT_TOPIC_PATH = "/v1/mgmt/topic";
155
+ var MGMT_TOPICS_TSG_PATH = "/v1/mgmt/topics/tsg";
156
+ var MGMT_TOPIC_FORCE_PATH = "/v1/mgmt/topic/force";
119
157
 
120
158
  // src/errors.ts
121
159
  var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
@@ -124,6 +162,7 @@ var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
124
162
  ErrorType2["USER_REQUEST_PAYLOAD_ERROR"] = "AISEC_USER_REQUEST_PAYLOAD_ERROR";
125
163
  ErrorType2["MISSING_VARIABLE"] = "AISEC_MISSING_VARIABLE";
126
164
  ErrorType2["AISEC_SDK_ERROR"] = "AISEC_SDK_ERROR";
165
+ ErrorType2["OAUTH_ERROR"] = "AISEC_OAUTH_ERROR";
127
166
  return ErrorType2;
128
167
  })(ErrorType || {});
129
168
  var AISecSDKException = class _AISecSDKException extends Error {
@@ -744,6 +783,494 @@ var ErrorResponseSchema = import_zod14.z.object({
744
783
  unit: import_zod14.z.string().optional()
745
784
  }).optional()
746
785
  });
786
+
787
+ // src/models/mgmt-security-profile.ts
788
+ var import_zod15 = require("zod");
789
+ var DlpDataProfileSchema = import_zod15.z.object({
790
+ profile_name: import_zod15.z.string(),
791
+ active: import_zod15.z.boolean().optional()
792
+ }).passthrough();
793
+ var DlpSchema = import_zod15.z.object({
794
+ dlp_status: import_zod15.z.string().optional(),
795
+ data_profiles: import_zod15.z.array(DlpDataProfileSchema).optional()
796
+ }).passthrough();
797
+ var DataLeakDetectionSchema = import_zod15.z.object({
798
+ "data-leak-detection-status": import_zod15.z.string().optional(),
799
+ dlp: DlpSchema.optional()
800
+ }).passthrough();
801
+ var AppProtectionSchema = import_zod15.z.object({
802
+ "prompt-injection": import_zod15.z.string().optional(),
803
+ "jailbreak-detection": import_zod15.z.string().optional()
804
+ }).passthrough();
805
+ var ModelProtectionSchema = import_zod15.z.object({
806
+ "model-denial-of-service": import_zod15.z.string().optional()
807
+ }).passthrough();
808
+ var AgentProtectionSchema = import_zod15.z.object({
809
+ "malicious-agent-activity": import_zod15.z.string().optional()
810
+ }).passthrough();
811
+ var LatencySchema = import_zod15.z.object({
812
+ status: import_zod15.z.string().optional(),
813
+ max_latency_ms: import_zod15.z.number().optional()
814
+ }).passthrough();
815
+ var ModelConfigurationSchema = import_zod15.z.object({
816
+ latency: LatencySchema.optional()
817
+ }).passthrough();
818
+ var PolicySchema = import_zod15.z.object({
819
+ "data-leak-detection": DataLeakDetectionSchema.optional(),
820
+ "app-protection": AppProtectionSchema.optional(),
821
+ "model-protection": ModelProtectionSchema.optional(),
822
+ "agent-protection": AgentProtectionSchema.optional(),
823
+ "model-configuration": ModelConfigurationSchema.optional()
824
+ }).passthrough();
825
+ var SecurityProfileSchema = import_zod15.z.object({
826
+ profile_id: import_zod15.z.string().optional(),
827
+ profile_name: import_zod15.z.string(),
828
+ revision: import_zod15.z.number().optional(),
829
+ active: import_zod15.z.boolean().optional(),
830
+ policy: PolicySchema.optional(),
831
+ created_by: import_zod15.z.string().optional(),
832
+ updated_by: import_zod15.z.string().optional(),
833
+ last_modified_ts: import_zod15.z.string().optional()
834
+ }).passthrough();
835
+ var CreateSecurityProfileRequestSchema = import_zod15.z.object({
836
+ profile_id: import_zod15.z.string().optional(),
837
+ profile_name: import_zod15.z.string(),
838
+ revision: import_zod15.z.number().optional(),
839
+ active: import_zod15.z.boolean().optional(),
840
+ policy: PolicySchema.optional(),
841
+ created_by: import_zod15.z.string().optional(),
842
+ updated_by: import_zod15.z.string().optional(),
843
+ last_modified_ts: import_zod15.z.string().optional()
844
+ }).passthrough();
845
+ var SecurityProfileListResponseSchema = import_zod15.z.object({
846
+ ai_profiles: import_zod15.z.array(SecurityProfileSchema),
847
+ next_offset: import_zod15.z.number().optional()
848
+ }).passthrough();
849
+ var DeleteProfileResponseSchema = import_zod15.z.object({
850
+ message: import_zod15.z.string()
851
+ }).passthrough();
852
+ var DeleteProfileConflictSchema = import_zod15.z.object({
853
+ message: import_zod15.z.string(),
854
+ payload: import_zod15.z.array(
855
+ import_zod15.z.object({
856
+ policy_id: import_zod15.z.string(),
857
+ policy_name: import_zod15.z.string(),
858
+ priority: import_zod15.z.number()
859
+ }).passthrough()
860
+ )
861
+ }).passthrough();
862
+
863
+ // src/models/mgmt-custom-topic.ts
864
+ var import_zod16 = require("zod");
865
+ var CustomTopicSchema = import_zod16.z.object({
866
+ topic_id: import_zod16.z.string().optional(),
867
+ topic_name: import_zod16.z.string(),
868
+ revision: import_zod16.z.number().optional(),
869
+ active: import_zod16.z.boolean().optional(),
870
+ description: import_zod16.z.string().optional(),
871
+ examples: import_zod16.z.array(import_zod16.z.string()).optional(),
872
+ created_by: import_zod16.z.string().optional(),
873
+ updated_by: import_zod16.z.string().optional(),
874
+ last_modified_ts: import_zod16.z.string().optional(),
875
+ created_ts: import_zod16.z.string().optional()
876
+ }).passthrough();
877
+ var CreateCustomTopicRequestSchema = import_zod16.z.object({
878
+ topic_id: import_zod16.z.string().optional(),
879
+ topic_name: import_zod16.z.string(),
880
+ revision: import_zod16.z.number().optional(),
881
+ active: import_zod16.z.boolean().optional(),
882
+ description: import_zod16.z.string().optional(),
883
+ examples: import_zod16.z.array(import_zod16.z.string()).optional(),
884
+ created_by: import_zod16.z.string().optional(),
885
+ updated_by: import_zod16.z.string().optional(),
886
+ last_modified_ts: import_zod16.z.string().optional(),
887
+ created_ts: import_zod16.z.string().optional()
888
+ }).passthrough();
889
+ var CustomTopicListResponseSchema = import_zod16.z.object({
890
+ custom_topics: import_zod16.z.array(CustomTopicSchema),
891
+ next_offset: import_zod16.z.number().optional()
892
+ }).passthrough();
893
+ var DeleteTopicResponseSchema = import_zod16.z.object({
894
+ message: import_zod16.z.string()
895
+ }).passthrough();
896
+ var DeleteTopicConflictSchema = import_zod16.z.object({
897
+ message: import_zod16.z.string(),
898
+ payload: import_zod16.z.array(
899
+ import_zod16.z.object({
900
+ profile_id: import_zod16.z.string(),
901
+ profile_name: import_zod16.z.string(),
902
+ revision: import_zod16.z.number()
903
+ }).passthrough()
904
+ )
905
+ }).passthrough();
906
+
907
+ // src/models/oauth-token.ts
908
+ var import_zod17 = require("zod");
909
+ var OAuthTokenResponseSchema = import_zod17.z.object({
910
+ access_token: import_zod17.z.string(),
911
+ token_type: import_zod17.z.string().optional(),
912
+ expires_in: import_zod17.z.number(),
913
+ scope: import_zod17.z.string().optional()
914
+ });
915
+
916
+ // src/management/oauth-client.ts
917
+ var TOKEN_BUFFER_MS = 3e4;
918
+ var OAuthClient = class {
919
+ tokenEndpoint;
920
+ clientId;
921
+ clientSecret;
922
+ tsgId;
923
+ accessToken = null;
924
+ expiresAt = 0;
925
+ pendingFetch = null;
926
+ constructor(opts) {
927
+ this.clientId = opts.clientId;
928
+ this.clientSecret = opts.clientSecret;
929
+ this.tsgId = opts.tsgId;
930
+ this.tokenEndpoint = opts.tokenEndpoint ?? DEFAULT_TOKEN_ENDPOINT;
931
+ }
932
+ async getToken() {
933
+ if (this.accessToken && Date.now() < this.expiresAt - TOKEN_BUFFER_MS) {
934
+ return this.accessToken;
935
+ }
936
+ if (this.pendingFetch) {
937
+ return this.pendingFetch;
938
+ }
939
+ this.pendingFetch = this.fetchToken().finally(() => {
940
+ this.pendingFetch = null;
941
+ });
942
+ return this.pendingFetch;
943
+ }
944
+ clearToken() {
945
+ this.accessToken = null;
946
+ this.expiresAt = 0;
947
+ }
948
+ async fetchToken() {
949
+ const credentials = btoa(`${this.clientId}:${this.clientSecret}`);
950
+ const body = new URLSearchParams({
951
+ grant_type: "client_credentials",
952
+ scope: `tsg_id:${this.tsgId}`
953
+ });
954
+ let response;
955
+ try {
956
+ response = await fetch(this.tokenEndpoint, {
957
+ method: "POST",
958
+ headers: {
959
+ "Content-Type": "application/x-www-form-urlencoded",
960
+ Authorization: `Basic ${credentials}`
961
+ },
962
+ body: body.toString()
963
+ });
964
+ } catch (err) {
965
+ throw new AISecSDKException(
966
+ `Token request failed: ${err.message}`,
967
+ "AISEC_OAUTH_ERROR" /* OAUTH_ERROR */
968
+ );
969
+ }
970
+ if (!response.ok) {
971
+ let errorMsg;
972
+ try {
973
+ const errorBody = await response.json();
974
+ errorMsg = errorBody.error_description ?? errorBody.error ?? `Token request failed with status ${response.status}`;
975
+ } catch {
976
+ errorMsg = `Token request failed with status ${response.status}`;
977
+ }
978
+ throw new AISecSDKException(errorMsg, "AISEC_OAUTH_ERROR" /* OAUTH_ERROR */);
979
+ }
980
+ const data = OAuthTokenResponseSchema.parse(await response.json());
981
+ this.accessToken = data.access_token;
982
+ this.expiresAt = Date.now() + data.expires_in * 1e3;
983
+ return this.accessToken;
984
+ }
985
+ };
986
+
987
+ // src/management/management-http-client.ts
988
+ function sleep2(ms) {
989
+ return new Promise((resolve) => setTimeout(resolve, ms));
990
+ }
991
+ function extractError(body, status) {
992
+ try {
993
+ const parsed = JSON.parse(body);
994
+ return parsed.error_message ?? parsed.message ?? `API error ${status}: ${body}`;
995
+ } catch {
996
+ return body ? `API error ${status}: ${body}` : `API error ${status}`;
997
+ }
998
+ }
999
+ async function managementHttpRequest(opts) {
1000
+ const { method, baseUrl, path, body, params, oauthClient, numRetries } = opts;
1001
+ let hadTokenRefresh = false;
1002
+ for (let attempt = 0; attempt <= numRetries; attempt++) {
1003
+ const token = await oauthClient.getToken();
1004
+ const stripped = baseUrl.replace(/\/+$/, "");
1005
+ const url = new URL(`${stripped}${path}`);
1006
+ if (params) {
1007
+ for (const [key, value] of Object.entries(params)) {
1008
+ url.searchParams.set(key, value);
1009
+ }
1010
+ }
1011
+ const headers = {
1012
+ Authorization: `Bearer ${token}`,
1013
+ "User-Agent": USER_AGENT
1014
+ };
1015
+ let bodyStr;
1016
+ if (body !== void 0) {
1017
+ headers["Content-Type"] = "application/json";
1018
+ bodyStr = JSON.stringify(body);
1019
+ }
1020
+ let response;
1021
+ try {
1022
+ response = await fetch(url.toString(), {
1023
+ method,
1024
+ headers,
1025
+ body: bodyStr
1026
+ });
1027
+ } catch (err) {
1028
+ if (attempt < numRetries) {
1029
+ await sleep2(Math.pow(2, attempt) * 1e3);
1030
+ continue;
1031
+ }
1032
+ throw new AISecSDKException(
1033
+ err.message ?? "Network error",
1034
+ "AISEC_CLIENT_SIDE_ERROR" /* CLIENT_SIDE_ERROR */
1035
+ );
1036
+ }
1037
+ if (response.ok) {
1038
+ const text = await response.text();
1039
+ const data = text ? JSON.parse(text) : {};
1040
+ return { status: response.status, data };
1041
+ }
1042
+ if (response.status === 401 && !hadTokenRefresh) {
1043
+ hadTokenRefresh = true;
1044
+ oauthClient.clearToken();
1045
+ attempt--;
1046
+ continue;
1047
+ }
1048
+ if (HTTP_FORCE_RETRY_STATUS_CODES.includes(response.status) && attempt < numRetries) {
1049
+ await sleep2(Math.pow(2, attempt) * 1e3);
1050
+ continue;
1051
+ }
1052
+ const errorText = await response.text();
1053
+ const errorMessage = extractError(errorText, response.status);
1054
+ const errorType = response.status >= 500 ? "AISEC_SERVER_SIDE_ERROR" /* SERVER_SIDE_ERROR */ : "AISEC_CLIENT_SIDE_ERROR" /* CLIENT_SIDE_ERROR */;
1055
+ throw new AISecSDKException(errorMessage, errorType);
1056
+ }
1057
+ throw new AISecSDKException("Max retries exceeded", "AISEC_CLIENT_SIDE_ERROR" /* CLIENT_SIDE_ERROR */);
1058
+ }
1059
+
1060
+ // src/management/profiles.ts
1061
+ var ProfilesClient = class {
1062
+ baseUrl;
1063
+ oauthClient;
1064
+ tsgId;
1065
+ numRetries;
1066
+ constructor(opts) {
1067
+ this.baseUrl = opts.baseUrl;
1068
+ this.oauthClient = opts.oauthClient;
1069
+ this.tsgId = opts.tsgId;
1070
+ this.numRetries = opts.numRetries;
1071
+ }
1072
+ async create(request) {
1073
+ const res = await managementHttpRequest({
1074
+ method: "POST",
1075
+ baseUrl: this.baseUrl,
1076
+ path: MGMT_PROFILE_PATH,
1077
+ body: request,
1078
+ oauthClient: this.oauthClient,
1079
+ numRetries: this.numRetries
1080
+ });
1081
+ return res.data;
1082
+ }
1083
+ async list(opts) {
1084
+ const params = {
1085
+ offset: String(opts?.offset ?? 0),
1086
+ limit: String(opts?.limit ?? 100)
1087
+ };
1088
+ const res = await managementHttpRequest({
1089
+ method: "GET",
1090
+ baseUrl: this.baseUrl,
1091
+ path: `${MGMT_PROFILES_TSG_PATH}/${this.tsgId}`,
1092
+ params,
1093
+ oauthClient: this.oauthClient,
1094
+ numRetries: this.numRetries
1095
+ });
1096
+ return res.data;
1097
+ }
1098
+ async update(profileId, request) {
1099
+ if (!isValidUuid(profileId)) {
1100
+ throw new AISecSDKException(
1101
+ `Invalid profile_id: ${profileId}`,
1102
+ "AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
1103
+ );
1104
+ }
1105
+ const res = await managementHttpRequest({
1106
+ method: "PUT",
1107
+ baseUrl: this.baseUrl,
1108
+ path: `${MGMT_PROFILE_PATH}/uuid/${profileId}`,
1109
+ body: request,
1110
+ oauthClient: this.oauthClient,
1111
+ numRetries: this.numRetries
1112
+ });
1113
+ return res.data;
1114
+ }
1115
+ async delete(profileId) {
1116
+ if (!isValidUuid(profileId)) {
1117
+ throw new AISecSDKException(
1118
+ `Invalid profile_id: ${profileId}`,
1119
+ "AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
1120
+ );
1121
+ }
1122
+ const res = await managementHttpRequest({
1123
+ method: "DELETE",
1124
+ baseUrl: this.baseUrl,
1125
+ path: `${MGMT_PROFILE_PATH}/${profileId}`,
1126
+ oauthClient: this.oauthClient,
1127
+ numRetries: this.numRetries
1128
+ });
1129
+ return res.data;
1130
+ }
1131
+ };
1132
+
1133
+ // src/management/topics.ts
1134
+ var TopicsClient = class {
1135
+ baseUrl;
1136
+ oauthClient;
1137
+ tsgId;
1138
+ numRetries;
1139
+ constructor(opts) {
1140
+ this.baseUrl = opts.baseUrl;
1141
+ this.oauthClient = opts.oauthClient;
1142
+ this.tsgId = opts.tsgId;
1143
+ this.numRetries = opts.numRetries;
1144
+ }
1145
+ async create(request) {
1146
+ const res = await managementHttpRequest({
1147
+ method: "POST",
1148
+ baseUrl: this.baseUrl,
1149
+ path: MGMT_TOPIC_PATH,
1150
+ body: request,
1151
+ oauthClient: this.oauthClient,
1152
+ numRetries: this.numRetries
1153
+ });
1154
+ return res.data;
1155
+ }
1156
+ async list(opts) {
1157
+ const params = {
1158
+ offset: String(opts?.offset ?? 0),
1159
+ limit: String(opts?.limit ?? 100)
1160
+ };
1161
+ const res = await managementHttpRequest({
1162
+ method: "GET",
1163
+ baseUrl: this.baseUrl,
1164
+ path: `${MGMT_TOPICS_TSG_PATH}/${this.tsgId}`,
1165
+ params,
1166
+ oauthClient: this.oauthClient,
1167
+ numRetries: this.numRetries
1168
+ });
1169
+ return res.data;
1170
+ }
1171
+ async update(topicId, request) {
1172
+ if (!isValidUuid(topicId)) {
1173
+ throw new AISecSDKException(
1174
+ `Invalid topic_id: ${topicId}`,
1175
+ "AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
1176
+ );
1177
+ }
1178
+ const res = await managementHttpRequest({
1179
+ method: "PUT",
1180
+ baseUrl: this.baseUrl,
1181
+ path: `${MGMT_TOPIC_PATH}/uuid/${topicId}`,
1182
+ body: request,
1183
+ oauthClient: this.oauthClient,
1184
+ numRetries: this.numRetries
1185
+ });
1186
+ return res.data;
1187
+ }
1188
+ async delete(topicId) {
1189
+ if (!isValidUuid(topicId)) {
1190
+ throw new AISecSDKException(
1191
+ `Invalid topic_id: ${topicId}`,
1192
+ "AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
1193
+ );
1194
+ }
1195
+ const res = await managementHttpRequest({
1196
+ method: "DELETE",
1197
+ baseUrl: this.baseUrl,
1198
+ path: `${MGMT_TOPIC_PATH}/${topicId}`,
1199
+ oauthClient: this.oauthClient,
1200
+ numRetries: this.numRetries
1201
+ });
1202
+ return res.data;
1203
+ }
1204
+ async forceDelete(topicId) {
1205
+ if (!isValidUuid(topicId)) {
1206
+ throw new AISecSDKException(
1207
+ `Invalid topic_id: ${topicId}`,
1208
+ "AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
1209
+ );
1210
+ }
1211
+ const res = await managementHttpRequest({
1212
+ method: "DELETE",
1213
+ baseUrl: this.baseUrl,
1214
+ path: `${MGMT_TOPIC_FORCE_PATH}/${topicId}`,
1215
+ oauthClient: this.oauthClient,
1216
+ numRetries: this.numRetries
1217
+ });
1218
+ return res.data;
1219
+ }
1220
+ };
1221
+
1222
+ // src/management/client.ts
1223
+ var ManagementClient = class {
1224
+ profiles;
1225
+ topics;
1226
+ constructor(opts = {}) {
1227
+ const clientId = opts.clientId ?? process.env[MGMT_CLIENT_ID];
1228
+ const clientSecret = opts.clientSecret ?? process.env[MGMT_CLIENT_SECRET];
1229
+ const tsgId = opts.tsgId ?? process.env[MGMT_TSG_ID];
1230
+ const apiEndpoint = opts.apiEndpoint ?? process.env[MGMT_ENDPOINT] ?? DEFAULT_MGMT_ENDPOINT;
1231
+ const tokenEndpoint = opts.tokenEndpoint ?? process.env[MGMT_TOKEN_ENDPOINT];
1232
+ const numRetries = Math.min(
1233
+ Math.max(opts.numRetries ?? MAX_NUMBER_OF_RETRIES, 0),
1234
+ MAX_NUMBER_OF_RETRIES
1235
+ );
1236
+ if (!clientId) {
1237
+ throw new AISecSDKException(
1238
+ "clientId is required (option or PANW_MGMT_CLIENT_ID env var)",
1239
+ "AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
1240
+ );
1241
+ }
1242
+ if (!clientSecret) {
1243
+ throw new AISecSDKException(
1244
+ "clientSecret is required (option or PANW_MGMT_CLIENT_SECRET env var)",
1245
+ "AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
1246
+ );
1247
+ }
1248
+ if (!tsgId) {
1249
+ throw new AISecSDKException(
1250
+ "tsgId is required (option or PANW_MGMT_TSG_ID env var)",
1251
+ "AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
1252
+ );
1253
+ }
1254
+ const oauthClient = new OAuthClient({
1255
+ clientId,
1256
+ clientSecret,
1257
+ tsgId,
1258
+ tokenEndpoint
1259
+ });
1260
+ this.profiles = new ProfilesClient({
1261
+ baseUrl: apiEndpoint,
1262
+ oauthClient,
1263
+ tsgId,
1264
+ numRetries
1265
+ });
1266
+ this.topics = new TopicsClient({
1267
+ baseUrl: apiEndpoint,
1268
+ oauthClient,
1269
+ tsgId,
1270
+ numRetries
1271
+ });
1272
+ }
1273
+ };
747
1274
  // Annotate the CommonJS export names for ESM import in node:
748
1275
  0 && (module.exports = {
749
1276
  AISecSDKException,
@@ -757,9 +1284,19 @@ var ErrorResponseSchema = import_zod14.z.object({
757
1284
  AsyncScanResponseSchema,
758
1285
  BEARER,
759
1286
  Content,
1287
+ CreateCustomTopicRequestSchema,
1288
+ CreateSecurityProfileRequestSchema,
1289
+ CustomTopicListResponseSchema,
1290
+ CustomTopicSchema,
760
1291
  DEFAULT_ENDPOINT,
1292
+ DEFAULT_MGMT_ENDPOINT,
1293
+ DEFAULT_TOKEN_ENDPOINT,
761
1294
  DSDetailResultSchema,
762
1295
  DSResultMetadataSchema,
1296
+ DeleteProfileConflictSchema,
1297
+ DeleteProfileResponseSchema,
1298
+ DeleteTopicConflictSchema,
1299
+ DeleteTopicResponseSchema,
763
1300
  DetectionServiceResultSchema,
764
1301
  DlpReportSchema,
765
1302
  ErrorResponseSchema,
@@ -783,9 +1320,22 @@ var ErrorResponseSchema = import_zod14.z.object({
783
1320
  MAX_SESSION_ID_STR_LENGTH,
784
1321
  MAX_TOKEN_LENGTH,
785
1322
  MAX_TRANSACTION_ID_STR_LENGTH,
1323
+ MGMT_CLIENT_ID,
1324
+ MGMT_CLIENT_SECRET,
1325
+ MGMT_ENDPOINT,
1326
+ MGMT_PROFILES_TSG_PATH,
1327
+ MGMT_PROFILE_PATH,
1328
+ MGMT_TOKEN_ENDPOINT,
1329
+ MGMT_TOPICS_TSG_PATH,
1330
+ MGMT_TOPIC_FORCE_PATH,
1331
+ MGMT_TOPIC_PATH,
1332
+ MGMT_TSG_ID,
1333
+ ManagementClient,
786
1334
  MaskedDataSchema,
787
1335
  MetadataSchema,
788
1336
  PAYLOAD_HASH,
1337
+ PolicySchema,
1338
+ ProfilesClient,
789
1339
  PromptDetectedSchema,
790
1340
  PromptDetectionDetailsSchema,
791
1341
  ResponseDetectedSchema,
@@ -800,10 +1350,13 @@ var ErrorResponseSchema = import_zod14.z.object({
800
1350
  ScanResponseSchema,
801
1351
  ScanSummarySchema,
802
1352
  Scanner,
1353
+ SecurityProfileListResponseSchema,
1354
+ SecurityProfileSchema,
803
1355
  ThreatScanReportSchema,
804
1356
  ToolDetectedSchema,
805
1357
  ToolEventMetadataSchema,
806
1358
  ToolEventSchema,
1359
+ TopicsClient,
807
1360
  USER_AGENT,
808
1361
  UrlfEntrySchema,
809
1362
  globalConfiguration,