@cdot65/prisma-airs-sdk 0.17.0 → 0.18.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.js CHANGED
@@ -1361,6 +1361,60 @@ var Content = class _Content {
1361
1361
  }
1362
1362
  };
1363
1363
 
1364
+ // src/listing.ts
1365
+ async function* paginate(fetchPage, initialCursor) {
1366
+ let cursor = initialCursor;
1367
+ const seen = /* @__PURE__ */ new Set();
1368
+ while (true) {
1369
+ if (seen.has(cursor)) throw new Error("Pagination returned a repeated cursor");
1370
+ seen.add(cursor);
1371
+ const page = await fetchPage(cursor);
1372
+ yield* page.items;
1373
+ if (page.next === void 0) return;
1374
+ cursor = page.next;
1375
+ }
1376
+ }
1377
+ async function collectAll(iterable, opts = {}) {
1378
+ const max = opts.max ?? 1e4;
1379
+ if (!Number.isSafeInteger(max) || max < 0)
1380
+ throw new RangeError("max must be a non-negative integer");
1381
+ const items = [];
1382
+ for await (const item of iterable) {
1383
+ if (max > 0 && items.length >= max) break;
1384
+ items.push(item);
1385
+ }
1386
+ return items;
1387
+ }
1388
+ function collectSkipPages(fetchPage, opts = {}) {
1389
+ const limit = opts.limit ?? 50;
1390
+ return collectAll(
1391
+ paginate(async (skip) => {
1392
+ const page = await fetchPage(skip, limit);
1393
+ const next = skip + page.items.length;
1394
+ const hasMore = page.items.length > 0 && (page.total == null ? page.items.length === limit : next < page.total);
1395
+ return { items: page.items, next: hasMore ? next : void 0 };
1396
+ }, 0),
1397
+ { max: opts.max }
1398
+ );
1399
+ }
1400
+ function collectSpringPages(fetchPage, opts = {}) {
1401
+ const size = opts.size ?? 50;
1402
+ return collectAll(
1403
+ paginate(async (page) => {
1404
+ const result = await fetchPage(page, size);
1405
+ return { items: result.items, next: result.last ? void 0 : page + 1 };
1406
+ }, 0),
1407
+ { max: opts.max }
1408
+ );
1409
+ }
1410
+ function serializeListing(opts) {
1411
+ const params = {};
1412
+ if (opts?.skip !== void 0) params.skip = String(opts.skip);
1413
+ if (opts?.limit !== void 0) params.limit = String(opts.limit);
1414
+ if (opts?.search !== void 0) params.search = opts.search;
1415
+ return params;
1416
+ }
1417
+
1364
1418
  // src/models/enums.ts
1365
1419
  var Verdict = {
1366
1420
  BENIGN: "benign",
@@ -4922,6 +4976,7 @@ var ProfilesClient = class {
4922
4976
  offset: String(opts?.offset ?? 0),
4923
4977
  limit: String(opts?.limit ?? 100)
4924
4978
  };
4979
+ if (opts?.latest !== void 0) params.latest = String(opts.latest);
4925
4980
  return request({
4926
4981
  method: "GET",
4927
4982
  baseUrl: this.baseUrl,
@@ -4932,6 +4987,23 @@ var ProfilesClient = class {
4932
4987
  numRetries: this.numRetries
4933
4988
  });
4934
4989
  }
4990
+ /**
4991
+ * List security profiles across every response page.
4992
+ * @example
4993
+ * ```ts
4994
+ * const profiles = await mgmt.profiles.listAll({ latest: true });
4995
+ * ```
4996
+ */
4997
+ async listAll(opts = {}) {
4998
+ const limit = opts.limit ?? 100;
4999
+ return collectAll(
5000
+ paginate(async (offset) => {
5001
+ const page = await this.list({ offset, limit, latest: opts.latest });
5002
+ return { items: page.ai_profiles, next: page.next_offset || void 0 };
5003
+ }, 0),
5004
+ { max: opts.max }
5005
+ );
5006
+ }
4935
5007
  /**
4936
5008
  * Get a security profile by UUID.
4937
5009
  * Fetches all profiles and filters — no dedicated API endpoint exists.
@@ -4949,7 +5021,7 @@ var ProfilesClient = class {
4949
5021
  * ```
4950
5022
  */
4951
5023
  async get(profileId) {
4952
- const { ai_profiles } = await this.list();
5024
+ const ai_profiles = await this.listAll();
4953
5025
  const profile = ai_profiles.find((p) => p.profile_id === profileId);
4954
5026
  if (!profile) {
4955
5027
  throw new AISecSDKException(
@@ -4975,7 +5047,7 @@ var ProfilesClient = class {
4975
5047
  * ```
4976
5048
  */
4977
5049
  async getByName(profileName) {
4978
- const { ai_profiles } = await this.list();
5050
+ const ai_profiles = await this.listAll();
4979
5051
  const matches = ai_profiles.filter((p) => p.profile_name === profileName);
4980
5052
  if (matches.length === 0) {
4981
5053
  throw new AISecSDKException(
@@ -5130,6 +5202,22 @@ var TopicsClient = class {
5130
5202
  * ```
5131
5203
  */
5132
5204
  async list(opts) {
5205
+ if (opts?.latestOnly) {
5206
+ const all = await this.listAll({ limit: 200 });
5207
+ const latest = /* @__PURE__ */ new Map();
5208
+ for (const topic of all) {
5209
+ const current = latest.get(topic.topic_name);
5210
+ if (!current || topic.revision > current.revision) latest.set(topic.topic_name, topic);
5211
+ }
5212
+ const custom_topics = [...latest.values()];
5213
+ const offset = opts.offset ?? 0;
5214
+ const limit = opts.limit ?? 100;
5215
+ const nextOffset = offset + limit;
5216
+ return {
5217
+ custom_topics: custom_topics.slice(offset, nextOffset),
5218
+ next_offset: nextOffset < custom_topics.length ? nextOffset : void 0
5219
+ };
5220
+ }
5133
5221
  const params = {
5134
5222
  offset: String(opts?.offset ?? 0),
5135
5223
  limit: String(opts?.limit ?? 100)
@@ -5144,6 +5232,55 @@ var TopicsClient = class {
5144
5232
  numRetries: this.numRetries
5145
5233
  });
5146
5234
  }
5235
+ /**
5236
+ * List custom topics across every response page.
5237
+ * @example
5238
+ * ```ts
5239
+ * const topics = await mgmt.topics.listAll({ limit: 200 });
5240
+ * ```
5241
+ */
5242
+ async listAll(opts = {}) {
5243
+ const limit = opts.limit ?? 100;
5244
+ return collectAll(
5245
+ paginate(async (offset) => {
5246
+ const page = await this.list({ offset, limit });
5247
+ return { items: page.custom_topics, next: page.next_offset || void 0 };
5248
+ }, 0),
5249
+ { max: opts.max }
5250
+ );
5251
+ }
5252
+ /**
5253
+ * Get an exact custom-topic revision by UUID.
5254
+ * @example
5255
+ * ```ts
5256
+ * const topic = await mgmt.topics.get('550e8400-e29b-41d4-a716-446655440000');
5257
+ * ```
5258
+ */
5259
+ async get(topicId) {
5260
+ const topic = (await this.listAll()).find((item) => item.topic_id === topicId);
5261
+ if (!topic)
5262
+ throw new AISecSDKException(
5263
+ `Topic not found: ${topicId}`,
5264
+ "AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
5265
+ );
5266
+ return topic;
5267
+ }
5268
+ /**
5269
+ * Get the highest revision of a custom topic by name.
5270
+ * @example
5271
+ * ```ts
5272
+ * const topic = await mgmt.topics.getByName('credit-cards');
5273
+ * ```
5274
+ */
5275
+ async getByName(topicName) {
5276
+ const matches = (await this.listAll()).filter((item) => item.topic_name === topicName);
5277
+ if (matches.length === 0)
5278
+ throw new AISecSDKException(
5279
+ `Topic not found: ${topicName}`,
5280
+ "AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
5281
+ );
5282
+ return matches.reduce((best, topic) => topic.revision > best.revision ? topic : best);
5283
+ }
5147
5284
  /**
5148
5285
  * Update an existing custom topic.
5149
5286
  * @param topicId - UUID of the topic to update.
@@ -5307,6 +5444,17 @@ var ApiKeysClient = class {
5307
5444
  numRetries: this.numRetries
5308
5445
  });
5309
5446
  }
5447
+ /** List all API keys. @example `const keys = await mgmt.apiKeys.listAll();` */
5448
+ async listAll(opts = {}) {
5449
+ const limit = opts.limit ?? 100;
5450
+ return collectAll(
5451
+ paginate(async (offset) => {
5452
+ const page = await this.list({ offset, limit });
5453
+ return { items: page.api_keys ?? [], next: page.next_offset || void 0 };
5454
+ }, 0),
5455
+ { max: opts.max }
5456
+ );
5457
+ }
5310
5458
  /**
5311
5459
  * Delete an API key by name.
5312
5460
  * @param apiKeyName - Name of the API key to delete.
@@ -5431,6 +5579,17 @@ var CustomerAppsClient = class {
5431
5579
  numRetries: this.numRetries
5432
5580
  });
5433
5581
  }
5582
+ /** List all customer applications. @example `const apps = await mgmt.customerApps.listAll();` */
5583
+ async listAll(opts = {}) {
5584
+ const limit = opts.limit ?? 100;
5585
+ return collectAll(
5586
+ paginate(async (offset) => {
5587
+ const page = await this.list({ offset, limit });
5588
+ return { items: page.customer_apps ?? [], next: page.next_offset || void 0 };
5589
+ }, 0),
5590
+ { max: opts.max }
5591
+ );
5592
+ }
5434
5593
  /**
5435
5594
  * Update a customer app.
5436
5595
  * @param customerAppId - UUID of the customer app to update.
@@ -5878,6 +6037,17 @@ var DataFilteringProfilesClient = class {
5878
6037
  numRetries: this.numRetries
5879
6038
  });
5880
6039
  }
6040
+ /** List all filtering profiles. @example `const profiles = await mgmt.dlp.dataFilteringProfiles.listAll();` */
6041
+ async listAll(params = {}) {
6042
+ return collectSpringPages(
6043
+ async (page, size) => {
6044
+ const result = await this.list({ ...params, page, size });
6045
+ const last = result.last ?? (result.totalPages !== void 0 ? page + 1 >= result.totalPages : result.content.length < size);
6046
+ return { items: result.content, last };
6047
+ },
6048
+ { size: params.size, max: params.max }
6049
+ );
6050
+ }
5881
6051
  /**
5882
6052
  * Get a single data filtering profile by resource ID.
5883
6053
  * @example
@@ -5971,6 +6141,17 @@ var DataPatternsClient = class {
5971
6141
  numRetries: this.numRetries
5972
6142
  });
5973
6143
  }
6144
+ /** List all data patterns. @example `const patterns = await mgmt.dlp.dataPatterns.listAll();` */
6145
+ async listAll(params = {}) {
6146
+ return collectSpringPages(
6147
+ async (page, size) => {
6148
+ const result = await this.list({ ...params, page, size });
6149
+ const last = result.last ?? (result.totalPages !== void 0 ? page + 1 >= result.totalPages : result.content.length < size);
6150
+ return { items: result.content, last };
6151
+ },
6152
+ { size: params.size, max: params.max }
6153
+ );
6154
+ }
5974
6155
  /**
5975
6156
  * Create a new custom data pattern.
5976
6157
  * @example
@@ -6144,6 +6325,17 @@ var DataProfilesClient = class {
6144
6325
  numRetries: this.numRetries
6145
6326
  });
6146
6327
  }
6328
+ /** List all data profiles. @example `const profiles = await mgmt.dlp.dataProfiles.listAll();` */
6329
+ async listAll(params = {}) {
6330
+ return collectSpringPages(
6331
+ async (page, size) => {
6332
+ const result = await this.list({ ...params, page, size });
6333
+ const last = result.last ?? (result.totalPages !== void 0 ? page + 1 >= result.totalPages : result.content.length < size);
6334
+ return { items: result.content, last };
6335
+ },
6336
+ { size: params.size, max: params.max }
6337
+ );
6338
+ }
6147
6339
  /**
6148
6340
  * Create a new data profile.
6149
6341
  * @example
@@ -6324,6 +6516,17 @@ var DictionariesClient = class {
6324
6516
  numRetries: this.numRetries
6325
6517
  });
6326
6518
  }
6519
+ /** List all dictionaries. @example `const dictionaries = await mgmt.dlp.dictionaries.listAll();` */
6520
+ async listAll(params = {}) {
6521
+ return collectSpringPages(
6522
+ async (page, size) => {
6523
+ const result = await this.list({ ...params, page, size });
6524
+ const last = result.last ?? (result.totalPages !== void 0 ? page + 1 >= result.totalPages : result.content.length < size);
6525
+ return { items: result.content, last };
6526
+ },
6527
+ { size: params.size, max: params.max }
6528
+ );
6529
+ }
6327
6530
  /**
6328
6531
  * Create a dictionary by uploading a keyword file. Sends a multipart body — the SDK does
6329
6532
  * not set Content-Type so the runtime can write the correct boundary.
@@ -6556,15 +6759,6 @@ var ManagementClient = class {
6556
6759
  }
6557
6760
  };
6558
6761
 
6559
- // src/listing.ts
6560
- function serializeListing(opts) {
6561
- const params = {};
6562
- if (opts?.skip !== void 0) params.skip = String(opts.skip);
6563
- if (opts?.limit !== void 0) params.limit = String(opts.limit);
6564
- if (opts?.search !== void 0) params.search = opts.search;
6565
- return params;
6566
- }
6567
-
6568
6762
  // src/model-security/scans-client.ts
6569
6763
  function buildScanListParams(opts) {
6570
6764
  const params = serializeListing(opts);
@@ -6660,6 +6854,13 @@ var ModelSecurityScansClient = class {
6660
6854
  numRetries: this.numRetries
6661
6855
  });
6662
6856
  }
6857
+ /** List every model-security scan page. @example `const scans = await ms.scans.listAll();` */
6858
+ async listAll(opts = {}) {
6859
+ return collectSkipPages(async (skip, limit) => {
6860
+ const page = await this.list({ ...opts, skip, limit });
6861
+ return { items: page.scans, total: page.pagination.total_items };
6862
+ }, opts);
6863
+ }
6663
6864
  /**
6664
6865
  * Get a single scan by UUID.
6665
6866
  * @param uuid - Scan UUID.
@@ -7038,6 +7239,13 @@ var ModelSecurityGroupsClient = class {
7038
7239
  numRetries: this.numRetries
7039
7240
  });
7040
7241
  }
7242
+ /** List every security-group page. @example `const groups = await ms.securityGroups.listAll();` */
7243
+ async listAll(opts = {}) {
7244
+ return collectSkipPages(async (skip, limit) => {
7245
+ const page = await this.list({ ...opts, skip, limit });
7246
+ return { items: page.security_groups, total: page.pagination.total_items };
7247
+ }, opts);
7248
+ }
7041
7249
  /**
7042
7250
  * Get a single security group by UUID.
7043
7251
  * @param uuid - Security group UUID.
@@ -7253,6 +7461,13 @@ var ModelSecurityRulesClient = class {
7253
7461
  numRetries: this.numRetries
7254
7462
  });
7255
7463
  }
7464
+ /** List every security-rule page. @example `const rules = await ms.securityRules.listAll();` */
7465
+ async listAll(opts = {}) {
7466
+ return collectSkipPages(async (skip, limit) => {
7467
+ const page = await this.list({ ...opts, skip, limit });
7468
+ return { items: page.rules, total: page.pagination.total_items };
7469
+ }, opts);
7470
+ }
7256
7471
  /**
7257
7472
  * Get a single security rule by UUID.
7258
7473
  * @param uuid - Security rule UUID.
@@ -7332,6 +7547,13 @@ var ModelSecurityModelsClient = class {
7332
7547
  numRetries: this.numRetries
7333
7548
  });
7334
7549
  }
7550
+ /** List every model page. @example `const models = await ms.models.listAllModels();` */
7551
+ async listAllModels(opts = {}) {
7552
+ return collectSkipPages(async (skip, limit) => {
7553
+ const page = await this.listModels({ ...opts, skip, limit });
7554
+ return { items: page.models, total: page.pagination.total_items };
7555
+ }, opts);
7556
+ }
7335
7557
  /**
7336
7558
  * Get a single model by UUID.
7337
7559
  * @param uuid - Model UUID.
@@ -7388,6 +7610,13 @@ var ModelSecurityModelsClient = class {
7388
7610
  numRetries: this.numRetries
7389
7611
  });
7390
7612
  }
7613
+ /** List every version of a model. @example `const versions = await ms.models.listAllModelVersions(modelUuid);` */
7614
+ async listAllModelVersions(modelUuid, opts = {}) {
7615
+ return collectSkipPages(async (skip, limit) => {
7616
+ const page = await this.listModelVersions(modelUuid, { ...opts, skip, limit });
7617
+ return { items: page.model_versions, total: page.pagination.total_items };
7618
+ }, opts);
7619
+ }
7391
7620
  /**
7392
7621
  * Get a single model version by UUID.
7393
7622
  * @param uuid - Model version UUID.
@@ -7442,6 +7671,13 @@ var ModelSecurityModelsClient = class {
7442
7671
  numRetries: this.numRetries
7443
7672
  });
7444
7673
  }
7674
+ /** List every file in a model version. @example `const files = await ms.models.listAllModelVersionFiles(versionUuid);` */
7675
+ async listAllModelVersionFiles(modelVersionUuid, opts = {}) {
7676
+ return collectSkipPages(async (skip, limit) => {
7677
+ const page = await this.listModelVersionFiles(modelVersionUuid, { ...opts, skip, limit });
7678
+ return { items: page.files, total: page.pagination.total_items };
7679
+ }, opts);
7680
+ }
7445
7681
  };
7446
7682
 
7447
7683
  // src/model-security/client.ts
@@ -7582,6 +7818,13 @@ var RedTeamScansClient = class {
7582
7818
  numRetries: this.numRetries
7583
7819
  });
7584
7820
  }
7821
+ /** List every scan page. @example `const scans = await rt.scans.listAll({ status: 'COMPLETED' });` */
7822
+ async listAll(opts = {}) {
7823
+ return collectSkipPages(async (skip, limit) => {
7824
+ const page = await this.list({ ...opts, skip, limit });
7825
+ return { items: page.data, total: page.pagination.total_items };
7826
+ }, opts);
7827
+ }
7585
7828
  /**
7586
7829
  * Get a single scan job by ID.
7587
7830
  * @param jobId - The job UUID.
@@ -8359,6 +8602,29 @@ var RedTeamTargetsClient = class {
8359
8602
  numRetries: this.numRetries
8360
8603
  });
8361
8604
  }
8605
+ /**
8606
+ * List targets across every page while preserving the supplied filters.
8607
+ * @example
8608
+ * ```ts
8609
+ * const targets = await rt.targets.listAll({ limit: 100, status: 'READY' });
8610
+ * ```
8611
+ */
8612
+ async listAll(opts = {}) {
8613
+ const limit = opts.limit ?? 50;
8614
+ return collectAll(
8615
+ paginate(async (skip) => {
8616
+ const page = await this.list({ ...opts, skip, limit });
8617
+ const items = page.data ?? [];
8618
+ const next = skip + items.length;
8619
+ const total = page.pagination.total_items;
8620
+ return {
8621
+ items,
8622
+ next: items.length > 0 && (total == null ? items.length === limit : next < total) ? next : void 0
8623
+ };
8624
+ }, 0),
8625
+ { max: opts.max }
8626
+ );
8627
+ }
8362
8628
  /**
8363
8629
  * Get a target by UUID.
8364
8630
  * @param uuid - The target UUID.
@@ -8675,6 +8941,13 @@ var RedTeamCustomAttacksClient = class {
8675
8941
  numRetries: this.numRetries
8676
8942
  });
8677
8943
  }
8944
+ /** List every custom prompt-set page. @example `const sets = await rt.customAttacks.listAllPromptSets();` */
8945
+ async listAllPromptSets(opts = {}) {
8946
+ return collectSkipPages(async (skip, limit) => {
8947
+ const page = await this.listPromptSets({ ...opts, skip, limit });
8948
+ return { items: page.data ?? [], total: page.pagination.total_items };
8949
+ }, opts);
8950
+ }
8678
8951
  /**
8679
8952
  * Get a prompt set by UUID.
8680
8953
  * @param uuid - The prompt set UUID.
@@ -8987,6 +9260,13 @@ var RedTeamCustomAttacksClient = class {
8987
9260
  numRetries: this.numRetries
8988
9261
  });
8989
9262
  }
9263
+ /** List every prompt page for a set. @example `const prompts = await rt.customAttacks.listAllPrompts(promptSetUuid);` */
9264
+ async listAllPrompts(promptSetUuid, opts = {}) {
9265
+ return collectSkipPages(async (skip, limit) => {
9266
+ const page = await this.listPrompts(promptSetUuid, { ...opts, skip, limit });
9267
+ return { items: page.data ?? [], total: page.pagination.total_items };
9268
+ }, opts);
9269
+ }
8990
9270
  /**
8991
9271
  * Get a prompt by UUID.
8992
9272
  * @param promptSetUuid - The prompt set UUID.
@@ -9733,6 +10013,13 @@ var RedTeamAdaptersClient = class {
9733
10013
  numRetries: this.numRetries
9734
10014
  });
9735
10015
  }
10016
+ /** List every adapter page. @example `const adapters = await rt.adapters.listAll();` */
10017
+ async listAll(opts = {}) {
10018
+ return collectSkipPages(async (skip, limit) => {
10019
+ const page = await this.list({ ...opts, skip, limit });
10020
+ return { items: page.data ?? [], total: page.pagination.total_items };
10021
+ }, opts);
10022
+ }
9736
10023
  /**
9737
10024
  * Get a single adapter by UUID.
9738
10025
  * @param uuid - Adapter UUID.
@@ -12769,9 +13056,14 @@ export {
12769
13056
  WebSocketConnectionParamsSchema,
12770
13057
  WeightedRegexSchema,
12771
13058
  aiGwOrganisationsAuthSettingsPath,
13059
+ collectAll,
13060
+ collectSkipPages,
13061
+ collectSpringPages,
12772
13062
  globalConfiguration,
12773
13063
  init,
12774
13064
  jsonNullable,
12775
- pageSchema
13065
+ pageSchema,
13066
+ paginate,
13067
+ serializeListing
12776
13068
  };
12777
13069
  //# sourceMappingURL=index.js.map