@nopaque/sdk 0.1.1 → 0.4.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.mjs CHANGED
@@ -91,7 +91,7 @@ function resolveConfig(opts) {
91
91
  }
92
92
 
93
93
  // src/version.ts
94
- var VERSION = true ? "0.1.1" : "0.0.0-dev";
94
+ var VERSION = true ? "0.4.0" : "0.0.0-dev";
95
95
 
96
96
  // src/userAgent.ts
97
97
  function composeUserAgent() {
@@ -449,7 +449,13 @@ var AudioResource = class extends Resource {
449
449
  const resolvedName = input.name ?? inferredName ?? "upload.bin";
450
450
  const resolvedType = input.contentType ?? sniffContentType(resolvedName);
451
451
  const presign = await this.createUploadUrl(
452
- { fileName: resolvedName, contentType: resolvedType },
452
+ {
453
+ filename: resolvedName,
454
+ contentType: resolvedType,
455
+ category: input.category,
456
+ ...input.associatedId && { associatedId: input.associatedId },
457
+ sizeBytes: bytes.byteLength
458
+ },
453
459
  requestOptions
454
460
  );
455
461
  await s3Put(presign.uploadUrl, bytes, {
@@ -574,6 +580,62 @@ var BatchesResource = class extends Resource {
574
580
  }
575
581
  };
576
582
 
583
+ // src/resources/compliance.ts
584
+ function encodePhone(phoneNumber) {
585
+ return encodeURIComponent(phoneNumber);
586
+ }
587
+ var ComplianceResource = class extends Resource {
588
+ async getCatalogue(params = {}, requestOptions) {
589
+ return await this.transport.request("GET", "/testing/compliance-catalogue", { params, requestOptions });
590
+ }
591
+ // Atomic batch dispatch. Server enforces compliancePickerLimits[tier] on
592
+ // testIds.length and returns 402 with code='BATCH_SIZE_EXCEEDS_TIER' on
593
+ // overflow. Surfaces as a typed NopaqueAPIError with code preserved.
594
+ async run(body, requestOptions) {
595
+ return await this.transport.request("POST", "/testing/compliance-runs", { body, requestOptions });
596
+ }
597
+ listReports(params = {}, requestOptions) {
598
+ return new Paginator({
599
+ fetchPage: async (p) => await this.transport.request("GET", "/testing/compliance-reports", { params: p, requestOptions }),
600
+ params: { ...params }
601
+ });
602
+ }
603
+ async listReportsPage(params = {}, requestOptions) {
604
+ const raw = await this.transport.request("GET", "/testing/compliance-reports", { params, requestOptions });
605
+ return new Page(raw.items, raw.nextToken);
606
+ }
607
+ async getReport(phoneNumber, requestOptions) {
608
+ return await this.transport.request(
609
+ "GET",
610
+ `/testing/compliance-reports/${encodePhone(phoneNumber)}`,
611
+ { requestOptions }
612
+ );
613
+ }
614
+ // Returns the presigned S3 URL the platform uploaded the PDF to. The 1 hour
615
+ // expiry is baked into the URL itself; the response body is `{ url }` only.
616
+ async generatePdfUrl(phoneNumber, body = {}, requestOptions) {
617
+ return await this.transport.request(
618
+ "POST",
619
+ `/testing/compliance-reports/${encodePhone(phoneNumber)}/pdf`,
620
+ { body, requestOptions }
621
+ );
622
+ }
623
+ // Convenience: get the URL, then fetch the bytes. For applications that
624
+ // already have an HTTP client, prefer generatePdfUrl() and fetch the URL
625
+ // with that client instead.
626
+ async downloadReportPdf(phoneNumber, body = {}, requestOptions) {
627
+ const { url } = await this.generatePdfUrl(phoneNumber, body, requestOptions);
628
+ const response = await this.transport.config.fetch(url);
629
+ if (!response.ok) {
630
+ throw new Error(`Failed to download PDF: ${response.status} ${response.statusText}`);
631
+ }
632
+ return new Uint8Array(await response.arrayBuffer());
633
+ }
634
+ async rerun(runId, requestOptions) {
635
+ return await this.transport.request("POST", `/testing/compliance-runs/${runId}/rerun`, { requestOptions });
636
+ }
637
+ };
638
+
577
639
  // src/resources/datasets.ts
578
640
  var DatasetsResource = class extends Resource {
579
641
  async create(body, requestOptions) {
@@ -606,6 +668,207 @@ var DatasetsResource = class extends Resource {
606
668
  }
607
669
  };
608
670
 
671
+ // src/resources/digitalCompliance.ts
672
+ var DigitalComplianceResource = class extends Resource {
673
+ /**
674
+ * List digital compliance audits, one entry per target.
675
+ *
676
+ * @beta Access is limited to beta workspaces during the beta period.
677
+ */
678
+ async listAudits(requestOptions) {
679
+ const raw = await this.transport.request(
680
+ "GET",
681
+ "/digital-testing/compliance-audits",
682
+ { requestOptions }
683
+ );
684
+ return raw.audits ?? [];
685
+ }
686
+ /**
687
+ * Compliance report for one digital target.
688
+ *
689
+ * `targetRef` goes in the QUERY STRING, not the path: a targetRef contains
690
+ * slashes (`acme/billing-bot`) and a single path segment cannot hold one. The
691
+ * API made the same choice for the same reason.
692
+ *
693
+ * Pass `{ sector }` to restrict the catalogue to tests applicable to that sector.
694
+ *
695
+ * @beta Access is limited to beta workspaces during the beta period.
696
+ */
697
+ async getReport(targetRef, params = {}, requestOptions) {
698
+ return await this.transport.request("GET", "/digital-testing/compliance-audits/report", {
699
+ params: { targetRef, ...params },
700
+ requestOptions
701
+ });
702
+ }
703
+ };
704
+
705
+ // src/resources/digitalTestConfigs.ts
706
+ var DigitalTestConfigsResource = class extends Resource {
707
+ /** @beta Access is limited to beta workspaces during the beta period. */
708
+ list(params = {}, requestOptions) {
709
+ return new Paginator({
710
+ fetchPage: async (p) => {
711
+ const { nextToken, cursor, ...rest } = p;
712
+ const raw = await this.transport.request(
713
+ "GET",
714
+ "/digital-testing/configs",
715
+ {
716
+ // `nextToken` first: the Paginator advances by writing it, and a
717
+ // caller-supplied `cursor` would otherwise pin every page to page one.
718
+ params: { ...rest, cursor: nextToken ?? cursor },
719
+ requestOptions
720
+ }
721
+ );
722
+ return {
723
+ items: raw.configs ?? raw.items ?? [],
724
+ nextToken: raw.nextCursor ?? raw.nextToken ?? null
725
+ };
726
+ },
727
+ params: { ...params }
728
+ });
729
+ }
730
+ /** @beta Access is limited to beta workspaces during the beta period. */
731
+ async listPage(params = {}, requestOptions) {
732
+ const { nextToken, cursor, ...rest } = params;
733
+ const raw = await this.transport.request("GET", "/digital-testing/configs", {
734
+ params: { ...rest, cursor: nextToken ?? cursor },
735
+ requestOptions
736
+ });
737
+ return new Page(raw.configs ?? raw.items ?? [], raw.nextCursor ?? raw.nextToken ?? null);
738
+ }
739
+ /**
740
+ * Save a digital test config. Per-kind rules are enforced at SAVE time, so a
741
+ * config that could never run is rejected with 400 rather than stored.
742
+ *
743
+ * @beta Access is limited to beta workspaces during the beta period.
744
+ */
745
+ async create(body, requestOptions) {
746
+ return await this.transport.request("POST", "/digital-testing/configs", {
747
+ body,
748
+ requestOptions
749
+ });
750
+ }
751
+ /** @beta Access is limited to beta workspaces during the beta period. */
752
+ async get(configId, requestOptions) {
753
+ return await this.transport.request("GET", `/digital-testing/configs/${configId}`, {
754
+ requestOptions
755
+ });
756
+ }
757
+ /** @beta Access is limited to beta workspaces during the beta period. */
758
+ async update(configId, body, requestOptions) {
759
+ return await this.transport.request("PATCH", `/digital-testing/configs/${configId}`, {
760
+ body,
761
+ requestOptions
762
+ });
763
+ }
764
+ /** @beta Access is limited to beta workspaces during the beta period. */
765
+ async delete(configId, requestOptions) {
766
+ await this.transport.request("DELETE", `/digital-testing/configs/${configId}`, {
767
+ requestOptions
768
+ });
769
+ }
770
+ /**
771
+ * Launch a run from a saved config. `target` and `targetRef` must be
772
+ * overridden together — a half-override is a 400.
773
+ *
774
+ * @beta Access is limited to beta workspaces during the beta period.
775
+ */
776
+ async launch(configId, body = {}, requestOptions) {
777
+ const raw = await this.transport.request("POST", `/digital-testing/configs/${configId}/runs`, { body, requestOptions });
778
+ return raw.run ?? raw;
779
+ }
780
+ };
781
+
782
+ // src/resources/digitalTesting.ts
783
+ var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]);
784
+ var DigitalTestingResource = class extends Resource {
785
+ /**
786
+ * Queue a digital test run.
787
+ *
788
+ * @beta Access is limited to beta workspaces during the beta period.
789
+ */
790
+ async create(body, requestOptions) {
791
+ const raw = await this.transport.request("POST", "/digital-testing/runs", { body, requestOptions });
792
+ return raw.run ?? raw;
793
+ }
794
+ /**
795
+ * Paginated list of digital test runs, newest first.
796
+ *
797
+ * @beta Access is limited to beta workspaces during the beta period.
798
+ */
799
+ list(params = {}, requestOptions) {
800
+ return new Paginator({
801
+ fetchPage: async (p) => {
802
+ const { nextToken, cursor, ...rest } = p;
803
+ const raw = await this.transport.request("GET", "/digital-testing/runs", {
804
+ // `nextToken` first: the Paginator advances by writing it, and a
805
+ // caller-supplied `cursor` would otherwise pin every page to page one.
806
+ params: { ...rest, cursor: nextToken ?? cursor },
807
+ requestOptions
808
+ });
809
+ return {
810
+ items: raw.runs ?? raw.items ?? [],
811
+ nextToken: raw.nextCursor ?? raw.nextToken ?? null
812
+ };
813
+ },
814
+ params: { ...params }
815
+ });
816
+ }
817
+ /**
818
+ * One page of digital test runs.
819
+ *
820
+ * @beta Access is limited to beta workspaces during the beta period.
821
+ */
822
+ async listPage(params = {}, requestOptions) {
823
+ const { nextToken, cursor, ...rest } = params;
824
+ const raw = await this.transport.request("GET", "/digital-testing/runs", {
825
+ params: { ...rest, cursor: nextToken ?? cursor },
826
+ requestOptions
827
+ });
828
+ return new Page(raw.runs ?? raw.items ?? [], raw.nextCursor ?? raw.nextToken ?? null);
829
+ }
830
+ /**
831
+ * Get one digital test run.
832
+ *
833
+ * @beta Access is limited to beta workspaces during the beta period.
834
+ */
835
+ async get(runId, requestOptions) {
836
+ return await this.transport.request("GET", `/digital-testing/runs/${runId}`, {
837
+ requestOptions
838
+ });
839
+ }
840
+ /**
841
+ * Cancel a digital test run.
842
+ *
843
+ * @beta Access is limited to beta workspaces during the beta period.
844
+ */
845
+ async cancel(runId, requestOptions) {
846
+ return await this.transport.request("POST", `/digital-testing/runs/${runId}/cancel`, {
847
+ requestOptions
848
+ });
849
+ }
850
+ /**
851
+ * Poll until the run reaches a terminal state.
852
+ *
853
+ * Resolves on `completed`, `failed` and `cancelled` alike and returns the run.
854
+ * A bot that behaved badly is `completed` with `outcome: 'fail'`, which is a
855
+ * RESULT, not an error — this never throws on it. `failed` means the test could
856
+ * not be delivered.
857
+ *
858
+ * @beta Access is limited to beta workspaces during the beta period.
859
+ */
860
+ async waitForRun(runId, opts = {}) {
861
+ return await waitFor({
862
+ fetch: () => this.get(runId, opts.requestOptions),
863
+ isTerminal: (r) => TERMINAL.has(r.status),
864
+ timeout: opts.timeout,
865
+ initialInterval: opts.pollInterval,
866
+ intervalCap: opts.intervalCap,
867
+ onUpdate: opts.onUpdate
868
+ });
869
+ }
870
+ };
871
+
609
872
  // src/resources/enrichment.ts
610
873
  var EnrichmentResource = class extends Resource {
611
874
  async get(jobId, runId, type, requestOptions) {
@@ -720,17 +983,24 @@ var TERMINAL_STATUSES2 = /* @__PURE__ */ new Set(["completed", "failed", "limite
720
983
  var MappingResource = class extends Resource {
721
984
  list(params = {}, requestOptions) {
722
985
  return new Paginator({
723
- fetchPage: async (p) => await this.transport.request("GET", "/mapping", { params: p, requestOptions }),
986
+ fetchPage: async (p) => {
987
+ const { nextToken, cursor, ...rest } = p;
988
+ const raw = await this.transport.request("GET", "/mapping", {
989
+ params: { ...rest, cursor: cursor ?? nextToken },
990
+ requestOptions
991
+ });
992
+ return { items: raw.items ?? [], nextToken: raw.nextCursor ?? raw.nextToken ?? null };
993
+ },
724
994
  params: { ...params }
725
995
  });
726
996
  }
727
997
  async listPage(params = {}, requestOptions) {
728
- const raw = await this.transport.request(
729
- "GET",
730
- "/mapping",
731
- { params, requestOptions }
732
- );
733
- return new Page(raw.items, raw.nextToken);
998
+ const { nextToken, cursor, ...rest } = params;
999
+ const raw = await this.transport.request("GET", "/mapping", {
1000
+ params: { ...rest, cursor: cursor ?? nextToken },
1001
+ requestOptions
1002
+ });
1003
+ return new Page(raw.items ?? [], raw.nextCursor ?? raw.nextToken ?? null);
734
1004
  }
735
1005
  async get(jobId, requestOptions) {
736
1006
  return await this.transport.request("GET", `/mapping/${jobId}`, { requestOptions });
@@ -756,6 +1026,16 @@ var MappingResource = class extends Resource {
756
1026
  requestOptions
757
1027
  });
758
1028
  }
1029
+ // Trigger on-demand security-probe analysis on a completed mapping run.
1030
+ // Returns the queue summary { message, probeCount }; poll the run / steps
1031
+ // afterwards to see classified results land.
1032
+ async probe(jobId, runId, requestOptions) {
1033
+ return await this.transport.request(
1034
+ "POST",
1035
+ `/mapping/${jobId}/runs/${runId}/probe`,
1036
+ { requestOptions }
1037
+ );
1038
+ }
759
1039
  steps(jobId, params = {}, requestOptions) {
760
1040
  return new Paginator({
761
1041
  fetchPage: async (p) => await this.transport.request("GET", `/mapping/${jobId}/steps`, {
@@ -812,13 +1092,6 @@ var MappingResource = class extends Resource {
812
1092
  { requestOptions }
813
1093
  );
814
1094
  }
815
- async probe(jobId, runId, body = {}, requestOptions) {
816
- return await this.transport.request(
817
- "POST",
818
- `/mapping/${jobId}/runs/${runId}/probe`,
819
- { body, requestOptions }
820
- );
821
- }
822
1095
  async waitForComplete(jobId, opts = {}) {
823
1096
  return await waitFor({
824
1097
  fetch: () => this.get(jobId, opts.requestOptions),
@@ -831,6 +1104,83 @@ var MappingResource = class extends Resource {
831
1104
  }
832
1105
  };
833
1106
 
1107
+ // src/resources/missionTestConfigs.ts
1108
+ var MissionTestConfigsResource = class extends Resource {
1109
+ list(params = {}, requestOptions) {
1110
+ return new Paginator({
1111
+ fetchPage: async (p) => {
1112
+ const { nextToken, cursor, ...rest } = p;
1113
+ const raw = await this.transport.request("GET", "/testing/mission-test-configs", {
1114
+ params: { ...rest, cursor: cursor ?? nextToken },
1115
+ requestOptions
1116
+ });
1117
+ return { items: raw.items ?? [], nextToken: raw.nextCursor ?? raw.nextToken ?? null };
1118
+ },
1119
+ params: { ...params }
1120
+ });
1121
+ }
1122
+ async listPage(params = {}, requestOptions) {
1123
+ const { nextToken, cursor, ...rest } = params;
1124
+ const raw = await this.transport.request("GET", "/testing/mission-test-configs", {
1125
+ params: { ...rest, cursor: cursor ?? nextToken },
1126
+ requestOptions
1127
+ });
1128
+ return new Page(raw.items ?? [], raw.nextCursor ?? raw.nextToken ?? null);
1129
+ }
1130
+ async create(body, requestOptions) {
1131
+ return await this.transport.request("POST", "/testing/mission-test-configs", { body, requestOptions });
1132
+ }
1133
+ async get(id, requestOptions) {
1134
+ return await this.transport.request("GET", `/testing/mission-test-configs/${id}`, { requestOptions });
1135
+ }
1136
+ async update(id, body, requestOptions) {
1137
+ return await this.transport.request("PATCH", `/testing/mission-test-configs/${id}`, {
1138
+ body,
1139
+ requestOptions
1140
+ });
1141
+ }
1142
+ async delete(id, requestOptions) {
1143
+ await this.transport.request("DELETE", `/testing/mission-test-configs/${id}`, { requestOptions });
1144
+ }
1145
+ // Launch a mission test run from a saved config. The returned run is freeform-shaped.
1146
+ async run(id, requestOptions) {
1147
+ return await this.transport.request("POST", `/testing/mission-test-configs/${id}/runs`, { requestOptions });
1148
+ }
1149
+ };
1150
+
1151
+ // src/resources/missionTests.ts
1152
+ var MissionTestsResource = class extends Resource {
1153
+ list(params = {}, requestOptions) {
1154
+ return new Paginator({
1155
+ fetchPage: async (p) => await this.transport.request("GET", "/testing/mission-tests", { params: p, requestOptions }),
1156
+ params: { ...params }
1157
+ });
1158
+ }
1159
+ async listPage(params = {}, requestOptions) {
1160
+ const raw = await this.transport.request(
1161
+ "GET",
1162
+ "/testing/mission-tests",
1163
+ { params, requestOptions }
1164
+ );
1165
+ return new Page(raw.items, raw.nextToken);
1166
+ }
1167
+ async create(body, requestOptions) {
1168
+ return await this.transport.request("POST", "/testing/mission-tests", { body, requestOptions });
1169
+ }
1170
+ // Returns 503 with code='CATALOG_NOT_READY' until the mission-tester service
1171
+ // publishes its SSM payload. Callers can catch and retry, or fall back to a
1172
+ // known-good default sector/mission/acceptance.
1173
+ async getDefaults(requestOptions) {
1174
+ return await this.transport.request("GET", "/testing/mission-tests/defaults", { requestOptions });
1175
+ }
1176
+ async get(id, requestOptions) {
1177
+ return await this.transport.request("GET", `/testing/mission-tests/${id}`, { requestOptions });
1178
+ }
1179
+ async cancel(id, requestOptions) {
1180
+ return await this.transport.request("POST", `/testing/mission-tests/${id}/cancel`, { requestOptions });
1181
+ }
1182
+ };
1183
+
834
1184
  // src/resources/profiles.ts
835
1185
  var ProfilesResource = class extends Resource {
836
1186
  async create(body, requestOptions) {
@@ -1061,15 +1411,33 @@ var TestingRunsResource = class extends Resource {
1061
1411
  list(params = {}, requestOptions) {
1062
1412
  return new Paginator({
1063
1413
  fetchPage: async (p) => {
1064
- const raw = await this.transport.request("GET", "/testing/runs", { params: p, requestOptions });
1065
- return { items: raw.runs ?? raw.items ?? [], nextToken: null };
1414
+ const { nextToken, cursor, ...rest } = p;
1415
+ const raw = await this.transport.request("GET", "/testing/runs", {
1416
+ params: { ...rest, cursor: cursor ?? nextToken },
1417
+ requestOptions
1418
+ });
1419
+ return {
1420
+ items: raw.runs ?? raw.items ?? [],
1421
+ nextToken: raw.nextCursor ?? raw.nextToken ?? null
1422
+ };
1066
1423
  },
1067
1424
  params: { ...params }
1068
1425
  });
1069
1426
  }
1070
1427
  async listPage(params = {}, requestOptions) {
1071
- const raw = await this.transport.request("GET", "/testing/runs", { params, requestOptions });
1072
- return new Page(raw.runs ?? raw.items ?? [], raw.nextToken ?? null);
1428
+ const { nextToken, cursor, ...rest } = params;
1429
+ const raw = await this.transport.request("GET", "/testing/runs", {
1430
+ params: { ...rest, cursor: cursor ?? nextToken },
1431
+ requestOptions
1432
+ });
1433
+ return new Page(raw.runs ?? raw.items ?? [], raw.nextCursor ?? raw.nextToken ?? null);
1434
+ }
1435
+ /** GET /testing/runs/aggregate — grouped counts over test runs. */
1436
+ async aggregate(params, requestOptions) {
1437
+ return await this.transport.request("GET", "/testing/runs/aggregate", {
1438
+ params,
1439
+ requestOptions
1440
+ });
1073
1441
  }
1074
1442
  async get(runId, requestOptions) {
1075
1443
  return await this.transport.request("GET", `/testing/runs/${runId}`, { requestOptions });
@@ -1095,6 +1463,24 @@ var TestingResource = class extends Resource {
1095
1463
  this.jobs = new TestingJobsResource(transport);
1096
1464
  this.runs = new TestingRunsResource(transport);
1097
1465
  }
1466
+ /** Paginated, filtered list of test runs (alias for `testing.runs.list()`). */
1467
+ listRuns(params = {}, requestOptions) {
1468
+ return this.runs.list(params, requestOptions);
1469
+ }
1470
+ /** GET /testing/voices — operator-enabled voices a mission test may use. */
1471
+ async listVoices(requestOptions) {
1472
+ return await this.transport.request("GET", "/testing/voices", { requestOptions });
1473
+ }
1474
+ /** GET /testing/runs/aggregate — grouped counts over test runs. */
1475
+ async aggregateRuns(params, requestOptions) {
1476
+ return await this.runs.aggregate(params, requestOptions);
1477
+ }
1478
+ /** GET /testing/mission-test-runs/{id} — mission-strict run detail (no steps). */
1479
+ async getMissionTestRun(id, requestOptions) {
1480
+ return await this.transport.request("GET", `/testing/mission-test-runs/${id}`, {
1481
+ requestOptions
1482
+ });
1483
+ }
1098
1484
  };
1099
1485
 
1100
1486
  // src/client.ts
@@ -1109,6 +1495,12 @@ var Nopaque = class {
1109
1495
  loadTesting;
1110
1496
  scheduler;
1111
1497
  enrichment;
1498
+ missionTests;
1499
+ missionTestConfigs;
1500
+ compliance;
1501
+ digitalTesting;
1502
+ digitalTestConfigs;
1503
+ digitalCompliance;
1112
1504
  transport;
1113
1505
  constructor(options = {}) {
1114
1506
  const config = resolveConfig(options);
@@ -1123,6 +1515,12 @@ var Nopaque = class {
1123
1515
  this.loadTesting = new LoadTestingResource(this.transport);
1124
1516
  this.scheduler = new SchedulerResource(this.transport);
1125
1517
  this.enrichment = new EnrichmentResource(this.transport);
1518
+ this.missionTests = new MissionTestsResource(this.transport);
1519
+ this.missionTestConfigs = new MissionTestConfigsResource(this.transport);
1520
+ this.compliance = new ComplianceResource(this.transport);
1521
+ this.digitalTesting = new DigitalTestingResource(this.transport);
1522
+ this.digitalTestConfigs = new DigitalTestConfigsResource(this.transport);
1523
+ this.digitalCompliance = new DigitalComplianceResource(this.transport);
1126
1524
  }
1127
1525
  close() {
1128
1526
  }