@stll/anonymize-wasm 2.5.0 → 2.6.1

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/wasm.mjs CHANGED
@@ -1,6 +1,73 @@
1
1
  import { DEFAULT_ENTITY_LABELS, DETECTION_SOURCES, DETECTOR_PRIORITY, ENTITY_CAPABILITIES, ENTITY_LABELS, ENTITY_SELECTIONS, OPERATOR_TYPES } from "./constants.mjs";
2
2
  import { CAPABILITY_MANIFEST, CAPABILITY_MANIFEST_SCHEMA_VERSION, CAPABILITY_PARITY_PROFILES, CAPABILITY_RUNTIMES, CAPABILITY_SURFACES } from "./capabilities.mjs";
3
3
  //#region src/native.ts
4
+ /** Exhaustive runtime-member contract shared by loaders and parity gates. */
5
+ const NATIVE_BINDING_PARITY_MEMBERS = {
6
+ root: [
7
+ "convertExternalDetectionBatch",
8
+ "externalDetectionLimitsJson",
9
+ "extractDocxTextJson",
10
+ "inspectPdfJson",
11
+ "rewritePdfRasterFromDetectionsJson",
12
+ "rewriteDocxTextNative",
13
+ "planDocxRestorationJson",
14
+ "normalizeForSearch",
15
+ "nativePackageVersion",
16
+ "prepareStaticSearchPackageBytes",
17
+ "prepareStaticSearchCompressedPackageBytes",
18
+ "assembleStaticSearchConfigJson",
19
+ "assembleStaticSearchPackageBytes",
20
+ "assembleStaticSearchCompressedPackageBytes"
21
+ ],
22
+ factories: [
23
+ "fromConfigJsonBytes",
24
+ "fromPreparedPackageBytes",
25
+ "fromPreparedPackageBytesWithoutCache",
26
+ "fromTrustedPreparedPackageBytes",
27
+ "fromTrustedPreparedPackageBytesWithoutCache"
28
+ ],
29
+ prepared: [
30
+ "prepareDiagnosticsJson",
31
+ "warmLazyRegex",
32
+ "warmLazyRegexDiagnosticsJson",
33
+ "createRedactionSession",
34
+ "createRedactionSessionWithLifecycle",
35
+ "restoreRedactionSession",
36
+ "restoreEncryptedRedactionSession",
37
+ "redactStaticEntities",
38
+ "redactStaticEntitiesJson",
39
+ "redactStaticEntitiesWithCallerDetectionsJson",
40
+ "redactStaticEntitiesWithCallerDetectionsDiagnosticsJson",
41
+ "redactStaticEntitiesResultStreamJson",
42
+ "redactStaticEntitiesDiagnosticsJson",
43
+ "redactStaticEntitiesDiagnosticsStreamJson",
44
+ "redactStaticEntitiesSummaryDiagnosticsJson"
45
+ ],
46
+ session: [
47
+ "sessionId",
48
+ "mappingCount",
49
+ "restoreText",
50
+ "restoreTextAt",
51
+ "toPlaintextJson",
52
+ "toPlaintextJsonAt",
53
+ "toEncryptedArchive",
54
+ "toEncryptedArchiveAt",
55
+ "inspectJson",
56
+ "deleteJson",
57
+ "redactStaticEntitiesJson",
58
+ "redactStaticEntitiesJsonAt",
59
+ "planStaticEntitiesWithCallerDetections"
60
+ ],
61
+ plan: ["resultJson", "commit"]
62
+ };
63
+ const isBindingPropertyBag = (value) => typeof value === "object" && value !== null || typeof value === "function";
64
+ /** Validate the complete runtime-neutral root and factory binding shape. */
65
+ const isNativeAnonymizeBinding = (candidate) => {
66
+ if (!isBindingPropertyBag(candidate)) return false;
67
+ if (!NATIVE_BINDING_PARITY_MEMBERS.root.every((name) => typeof candidate[name] === "function")) return false;
68
+ const preparedSearch = candidate["NativePreparedSearch"];
69
+ return isBindingPropertyBag(preparedSearch) && NATIVE_BINDING_PARITY_MEMBERS.factories.every((name) => typeof preparedSearch[name] === "function");
70
+ };
4
71
  const CALLER_DETECTION_CONTRACT_VERSION = 2;
5
72
  const EXTERNAL_DETECTION_BATCH_VERSION = 1;
6
73
  const EXTERNAL_DETECTION_BATCH_MAX_BYTES = 16 * 1024 * 1024;
@@ -15,9 +82,7 @@ const EXTERNAL_DETECTION_OFFSET_UNITS = {
15
82
  utf8Byte: "utf8-byte"
16
83
  };
17
84
  const convert_external_detection_batch$1 = ({ binding, document, batch }) => {
18
- const convert = binding.convertExternalDetectionBatch;
19
- if (convert === void 0) throw new Error("Native anonymize binding does not support external detection batches");
20
- return convert(document, typeof batch === "string" ? batch : JSON.stringify(batch));
85
+ return binding.convertExternalDetectionBatch(document, typeof batch === "string" ? batch : JSON.stringify(batch));
21
86
  };
22
87
  const callerDetectionRequestJson = (detections) => JSON.stringify({
23
88
  version: 2,
@@ -48,14 +113,8 @@ var PreparedNativeRedactionSession = class {
48
113
  return this.mappingCount();
49
114
  }
50
115
  restoreText(fullText, observedAtEpochSeconds) {
51
- if (observedAtEpochSeconds === void 0) {
52
- const restore = this.#session.restoreText;
53
- if (!restore) throw new Error("Native anonymize binding does not support session restoration");
54
- return restore.call(this.#session, fullText);
55
- }
56
- const restore = this.#session.restoreTextAt;
57
- if (!restore) throw new Error("Native anonymize binding does not support session restoration lifecycle controls");
58
- return restore.call(this.#session, fullText, observedAtEpochSeconds);
116
+ if (observedAtEpochSeconds === void 0) return this.#session.restoreText(fullText);
117
+ return this.#session.restoreTextAt(fullText, observedAtEpochSeconds);
59
118
  }
60
119
  restore_text(fullText, observedAtEpochSeconds) {
61
120
  return this.restoreText(fullText, observedAtEpochSeconds);
@@ -67,33 +126,25 @@ var PreparedNativeRedactionSession = class {
67
126
  return this.toPlaintextJson();
68
127
  }
69
128
  toPlaintextJsonAt(observedAtEpochSeconds) {
70
- const serialize = this.#session.toPlaintextJsonAt;
71
- if (!serialize) throw new Error("Native anonymize binding does not support session lifecycle controls");
72
- return serialize.call(this.#session, observedAtEpochSeconds);
129
+ return this.#session.toPlaintextJsonAt(observedAtEpochSeconds);
73
130
  }
74
131
  to_plaintext_json_at(observedAtEpochSeconds) {
75
132
  return this.toPlaintextJsonAt(observedAtEpochSeconds);
76
133
  }
77
134
  toEncryptedArchive(key) {
78
- const serialize = this.#session.toEncryptedArchive;
79
- if (!serialize) throw new Error("Native anonymize binding does not support encrypted session archives");
80
- return serialize.call(this.#session, key);
135
+ return this.#session.toEncryptedArchive(key);
81
136
  }
82
137
  to_encrypted_archive(key) {
83
138
  return this.toEncryptedArchive(key);
84
139
  }
85
140
  toEncryptedArchiveAt(key, observedAtEpochSeconds) {
86
- const serialize = this.#session.toEncryptedArchiveAt;
87
- if (!serialize) throw new Error("Native anonymize binding does not support encrypted session archives");
88
- return serialize.call(this.#session, key, observedAtEpochSeconds);
141
+ return this.#session.toEncryptedArchiveAt(key, observedAtEpochSeconds);
89
142
  }
90
143
  to_encrypted_archive_at(key, observedAtEpochSeconds) {
91
144
  return this.toEncryptedArchiveAt(key, observedAtEpochSeconds);
92
145
  }
93
146
  inspect(observedAtEpochSeconds) {
94
- const inspect = this.#session.inspectJson;
95
- if (!inspect) throw new Error("Native anonymize binding does not support session lifecycle controls");
96
- const metadata = JSON.parse(inspect.call(this.#session, observedAtEpochSeconds));
147
+ const metadata = JSON.parse(this.#session.inspectJson(observedAtEpochSeconds));
97
148
  return {
98
149
  sessionId: metadata.session_id,
99
150
  createdAtEpochSeconds: metadata.created_at_epoch_seconds,
@@ -103,9 +154,7 @@ var PreparedNativeRedactionSession = class {
103
154
  };
104
155
  }
105
156
  delete() {
106
- const deleteSession = this.#session.deleteJson;
107
- if (!deleteSession) throw new Error("Native anonymize binding does not support session lifecycle controls");
108
- const summary = JSON.parse(deleteSession.call(this.#session));
157
+ const summary = JSON.parse(this.#session.deleteJson());
109
158
  return {
110
159
  sessionId: summary.session_id,
111
160
  deletedMappingCount: summary.deleted_mapping_count
@@ -141,18 +190,14 @@ var PreparedNativeRedactionSession = class {
141
190
  return this.redactStaticEntitiesAt(options);
142
191
  }
143
192
  redactTextJsonAt({ fullText, observedAtEpochSeconds, operators }) {
144
- const redact = this.#session.redactStaticEntitiesJsonAt;
145
- if (!redact) throw new Error("Native anonymize binding does not support session lifecycle controls");
146
- return redact.call(this.#session, fullText, observedAtEpochSeconds, toBindingOperatorConfig(operators));
193
+ return this.#session.redactStaticEntitiesJsonAt(fullText, observedAtEpochSeconds, toBindingOperatorConfig(operators));
147
194
  }
148
195
  redact_text_json_at(options) {
149
196
  return this.redactTextJsonAt(options);
150
197
  }
151
198
  planTextBatchWithCallerDetections({ inputs, operators, observedAtEpochSeconds }) {
152
- const plan = this.#session.planStaticEntitiesWithCallerDetections;
153
- if (!plan) throw new Error("Native anonymize binding does not support transactional caller-detection session plans");
154
199
  const bindingOperators = toBindingOperatorConfig(operators);
155
- return new PreparedNativeSessionRedactionPlan(plan.call(this.#session, {
200
+ return new PreparedNativeSessionRedactionPlan(this.#session.planStaticEntitiesWithCallerDetections({
156
201
  inputs: inputs.map(({ detections, fullText }) => ({
157
202
  fullText,
158
203
  requestJson: callerDetectionRequestJson(detections)
@@ -184,56 +229,43 @@ var PreparedNativeAnonymizer = class {
184
229
  this.#prepared = prepared;
185
230
  }
186
231
  prepareDiagnosticsJson() {
187
- return this.#prepared.prepareDiagnosticsJson?.() ?? null;
232
+ return this.#prepared.prepareDiagnosticsJson();
188
233
  }
189
234
  prepare_diagnostics_json() {
190
235
  return this.prepareDiagnosticsJson();
191
236
  }
192
237
  warmLazyRegex() {
193
- if (this.#prepared.warmLazyRegex) {
194
- this.#prepared.warmLazyRegex();
195
- return;
196
- }
197
- this.#prepared.warm_lazy_regex?.();
238
+ this.#prepared.warmLazyRegex();
198
239
  }
199
240
  warm_lazy_regex() {
200
241
  this.warmLazyRegex();
201
242
  }
202
243
  warmLazyRegexDiagnosticsJson() {
203
- if (this.#prepared.warmLazyRegexDiagnosticsJson) return this.#prepared.warmLazyRegexDiagnosticsJson();
204
- return this.#prepared.warm_lazy_regex_diagnostics_json?.() ?? null;
244
+ return this.#prepared.warmLazyRegexDiagnosticsJson();
205
245
  }
206
246
  warm_lazy_regex_diagnostics_json() {
207
247
  return this.warmLazyRegexDiagnosticsJson();
208
248
  }
209
249
  createRedactionSession(sessionId) {
210
- const create = this.#prepared.createRedactionSession;
211
- if (!create) throw new Error("Native anonymize binding does not support redaction sessions");
212
- return new PreparedNativeRedactionSession(create.call(this.#prepared, sessionId));
250
+ return new PreparedNativeRedactionSession(this.#prepared.createRedactionSession(sessionId));
213
251
  }
214
252
  create_redaction_session(sessionId) {
215
253
  return this.createRedactionSession(sessionId);
216
254
  }
217
255
  createRedactionSessionWithLifecycle({ sessionId, createdAtEpochSeconds, expiresAtEpochSeconds }) {
218
- const create = this.#prepared.createRedactionSessionWithLifecycle;
219
- if (!create) throw new Error("Native anonymize binding does not support session lifecycle controls");
220
- return new PreparedNativeRedactionSession(create.call(this.#prepared, sessionId, createdAtEpochSeconds, expiresAtEpochSeconds));
256
+ return new PreparedNativeRedactionSession(this.#prepared.createRedactionSessionWithLifecycle(sessionId, createdAtEpochSeconds, expiresAtEpochSeconds));
221
257
  }
222
258
  create_redaction_session_with_lifecycle(options) {
223
259
  return this.createRedactionSessionWithLifecycle(options);
224
260
  }
225
261
  restoreRedactionSession(plaintextJson) {
226
- const restore = this.#prepared.restoreRedactionSession;
227
- if (!restore) throw new Error("Native anonymize binding does not support redaction sessions");
228
- return new PreparedNativeRedactionSession(restore.call(this.#prepared, plaintextJson));
262
+ return new PreparedNativeRedactionSession(this.#prepared.restoreRedactionSession(plaintextJson));
229
263
  }
230
264
  restore_redaction_session(plaintextJson) {
231
265
  return this.restoreRedactionSession(plaintextJson);
232
266
  }
233
267
  restoreEncryptedRedactionSession({ archive, key, expectedSessionId, observedAtEpochSeconds }) {
234
- const restore = this.#prepared.restoreEncryptedRedactionSession;
235
- if (!restore) throw new Error("Native anonymize binding does not support encrypted session archives");
236
- return new PreparedNativeRedactionSession(restore.call(this.#prepared, {
268
+ return new PreparedNativeRedactionSession(this.#prepared.restoreEncryptedRedactionSession({
237
269
  archive,
238
270
  key,
239
271
  expectedSessionId,
@@ -251,11 +283,9 @@ var PreparedNativeAnonymizer = class {
251
283
  }
252
284
  redact_text_json(fullText, operators) {
253
285
  const bindingOperators = toBindingOperatorConfig(operators);
254
- if (this.#prepared.redactStaticEntitiesJson) return this.#prepared.redactStaticEntitiesJson(fullText, bindingOperators);
255
- return JSON.stringify(toBindingStaticRedactionResult(toNativeStaticRedactionResult(this.#prepared.redactStaticEntities(fullText, bindingOperators))));
286
+ return this.#prepared.redactStaticEntitiesJson(fullText, bindingOperators);
256
287
  }
257
288
  redactStaticEntitiesWithCallerDetections(fullText, options) {
258
- if (!this.#prepared.redactStaticEntitiesWithCallerDetectionsJson) throw new Error("Native anonymize binding does not support caller detections");
259
289
  const requestJson = callerDetectionRequestJson(options.detections);
260
290
  const operators = toBindingOperatorConfig(options.operators);
261
291
  const result = JSON.parse(this.#prepared.redactStaticEntitiesWithCallerDetectionsJson(fullText, {
@@ -268,11 +298,9 @@ var PreparedNativeAnonymizer = class {
268
298
  return this.redactStaticEntitiesWithCallerDetections(fullText, options);
269
299
  }
270
300
  redactStaticEntitiesWithCallerDetectionsDiagnosticsJson(fullText, options) {
271
- const redact = this.#prepared.redactStaticEntitiesWithCallerDetectionsDiagnosticsJson;
272
- if (!redact) return null;
273
301
  const requestJson = callerDetectionRequestJson(options.detections);
274
302
  const operators = toBindingOperatorConfig(options.operators);
275
- return redact.call(this.#prepared, fullText, {
303
+ return this.#prepared.redactStaticEntitiesWithCallerDetectionsDiagnosticsJson(fullText, {
276
304
  requestJson,
277
305
  ...operators ? { operators } : {}
278
306
  });
@@ -284,28 +312,24 @@ var PreparedNativeAnonymizer = class {
284
312
  return this.redact_text_json(fullText, operators);
285
313
  }
286
314
  redactTextStreamJson(fullText, onEvent, operators) {
287
- if (!this.#prepared.redactStaticEntitiesResultStreamJson) return null;
288
315
  return this.#prepared.redactStaticEntitiesResultStreamJson(fullText, toBindingOperatorConfig(operators), onEvent);
289
316
  }
290
317
  redact_text_stream_json(fullText, onEvent, operators) {
291
318
  return this.redactTextStreamJson(fullText, onEvent, operators);
292
319
  }
293
320
  redactStaticEntitiesDiagnosticsJson(fullText, operators) {
294
- if (!this.#prepared.redactStaticEntitiesDiagnosticsJson) return null;
295
321
  return this.#prepared.redactStaticEntitiesDiagnosticsJson(fullText, toBindingOperatorConfig(operators));
296
322
  }
297
323
  diagnostics_json(fullText, operators) {
298
324
  return this.redactStaticEntitiesDiagnosticsJson(fullText, operators);
299
325
  }
300
326
  diagnosticsStreamJson(fullText, onBatch, operators) {
301
- if (!this.#prepared.redactStaticEntitiesDiagnosticsStreamJson) return null;
302
327
  return this.#prepared.redactStaticEntitiesDiagnosticsStreamJson(fullText, toBindingOperatorConfig(operators), onBatch);
303
328
  }
304
329
  diagnostics_stream_json(fullText, onBatch, operators) {
305
330
  return this.diagnosticsStreamJson(fullText, onBatch, operators);
306
331
  }
307
332
  redactStaticEntitiesSummaryDiagnosticsJson(fullText, operators) {
308
- if (!this.#prepared.redactStaticEntitiesSummaryDiagnosticsJson) return null;
309
333
  return this.#prepared.redactStaticEntitiesSummaryDiagnosticsJson(fullText, toBindingOperatorConfig(operators));
310
334
  }
311
335
  summary_diagnostics_json(fullText, operators) {
@@ -468,21 +492,6 @@ const fromCanonicalStaticRedactionResult = (result) => ({
468
492
  entityCount: result.redaction.entity_count
469
493
  }
470
494
  });
471
- const toBindingStaticRedactionResult = (result) => ({
472
- resolved_entities: result.resolvedEntities.map(toBindingPipelineEntity),
473
- redaction: {
474
- redacted_text: result.redaction.redactedText,
475
- redaction_map: [...result.redaction.redactionMap.entries()].map(([placeholder, original]) => ({
476
- placeholder,
477
- original
478
- })),
479
- operator_map: [...result.redaction.operatorMap.entries()].map(([placeholder, operator]) => ({
480
- placeholder,
481
- operator
482
- })),
483
- entity_count: result.redaction.entityCount
484
- }
485
- });
486
495
  const toNativePipelineEntity = (entity) => ({
487
496
  start: entity.start,
488
497
  end: entity.end,
@@ -494,12 +503,6 @@ const toNativePipelineEntity = (entity) => ({
494
503
  ...entity.providerId ? { providerId: entity.providerId } : {},
495
504
  ...entity.detectionId ? { detectionId: entity.detectionId } : {}
496
505
  });
497
- const toBindingPipelineEntity = ({ sourceDetail, providerId, detectionId, ...entity }) => ({
498
- ...entity,
499
- source_detail: sourceDetail ?? null,
500
- provider_id: providerId ?? null,
501
- detection_id: detectionId ?? null
502
- });
503
506
  const toNativeRedactionResult = (result) => ({
504
507
  redactedText: result.redactedText,
505
508
  redactionMap: toRedactionMap(result.redactionMap),
@@ -517,6 +520,150 @@ const toOperatorMap = (entries) => {
517
520
  return map;
518
521
  };
519
522
  //#endregion
523
+ //#region src/wasm-binding.ts
524
+ const RAW_WASM_MODULE_FUNCTION_MEMBERS = [
525
+ "default",
526
+ "normalizeForSearch",
527
+ "nativePackageVersion",
528
+ "externalDetectionLimitsJson",
529
+ "convertExternalDetectionBatchJson",
530
+ "extractDocxTextJson",
531
+ "rewriteDocxTextNative",
532
+ "planDocxRestorationJson",
533
+ "inspectPdfJson",
534
+ "rewritePdfRasterFromDetectionsJson",
535
+ "prepareStaticSearchPackageBytes",
536
+ "prepareStaticSearchCompressedPackageBytes",
537
+ "assembleStaticSearchConfigJson",
538
+ "assembleStaticSearchPackageBytes",
539
+ "assembleStaticSearchCompressedPackageBytes"
540
+ ];
541
+ const RAW_WASM_PREPARED_SEARCH_FACTORY_MEMBERS = [
542
+ "fromConfigJsonBytes",
543
+ "fromPreparedPackageBytes",
544
+ "fromTrustedPreparedPackageBytes"
545
+ ];
546
+ const isPropertyBag = (value) => typeof value === "object" && value !== null || typeof value === "function";
547
+ /** Validate every raw export consumed by the runtime adapter. */
548
+ const isRawWasmModule = (value) => {
549
+ if (!isPropertyBag(value) || !RAW_WASM_MODULE_FUNCTION_MEMBERS.every((name) => typeof value[name] === "function")) return false;
550
+ const preparedSearch = value["WasmPreparedSearch"];
551
+ return isPropertyBag(preparedSearch) && typeof preparedSearch === "function" && isPropertyBag(preparedSearch["prototype"]) && RAW_WASM_PREPARED_SEARCH_FACTORY_MEMBERS.every((name) => typeof preparedSearch[name] === "function");
552
+ };
553
+ const createWasmBinding = (raw) => ({
554
+ convertExternalDetectionBatch: (document, batchJson) => {
555
+ return JSON.parse(raw.convertExternalDetectionBatchJson(document, batchJson)).map(({ start, end, label, score, provider_id, detection_id }) => ({
556
+ start,
557
+ end,
558
+ label,
559
+ score,
560
+ providerId: provider_id,
561
+ detectionId: detection_id
562
+ }));
563
+ },
564
+ externalDetectionLimitsJson: raw.externalDetectionLimitsJson,
565
+ extractDocxTextJson: raw.extractDocxTextJson,
566
+ inspectPdfJson: raw.inspectPdfJson,
567
+ rewritePdfRasterFromDetectionsJson: (document, requestJson, pagePixels) => {
568
+ assertPdfPixelPages(pagePixels);
569
+ const result = raw.rewritePdfRasterFromDetectionsJson(document, requestJson, [...pagePixels]);
570
+ return {
571
+ document: result.document,
572
+ certificateJson: result.certificateJson
573
+ };
574
+ },
575
+ rewriteDocxTextNative: (document, rewritesJson) => {
576
+ const result = raw.rewriteDocxTextNative(document, rewritesJson);
577
+ return {
578
+ document: result.document,
579
+ rewrittenBlockCount: result.rewrittenBlockCount,
580
+ appliedReplacementCount: result.appliedReplacementCount
581
+ };
582
+ },
583
+ planDocxRestorationJson: raw.planDocxRestorationJson,
584
+ normalizeForSearch: raw.normalizeForSearch,
585
+ nativePackageVersion: raw.nativePackageVersion,
586
+ NativePreparedSearch: {
587
+ fromConfigJsonBytes: (bytes) => wrapPrepared(raw.WasmPreparedSearch.fromConfigJsonBytes(bytes)),
588
+ fromPreparedPackageBytes: (bytes) => wrapPrepared(raw.WasmPreparedSearch.fromPreparedPackageBytes(bytes)),
589
+ fromPreparedPackageBytesWithoutCache: (bytes) => wrapPrepared(raw.WasmPreparedSearch.fromPreparedPackageBytes(bytes)),
590
+ fromTrustedPreparedPackageBytes: (bytes) => wrapPrepared(raw.WasmPreparedSearch.fromTrustedPreparedPackageBytes(bytes)),
591
+ fromTrustedPreparedPackageBytesWithoutCache: (bytes) => wrapPrepared(raw.WasmPreparedSearch.fromTrustedPreparedPackageBytes(bytes))
592
+ },
593
+ prepareStaticSearchPackageBytes: raw.prepareStaticSearchPackageBytes,
594
+ prepareStaticSearchCompressedPackageBytes: raw.prepareStaticSearchCompressedPackageBytes,
595
+ assembleStaticSearchConfigJson: raw.assembleStaticSearchConfigJson,
596
+ assembleStaticSearchPackageBytes: raw.assembleStaticSearchPackageBytes,
597
+ assembleStaticSearchCompressedPackageBytes: raw.assembleStaticSearchCompressedPackageBytes
598
+ });
599
+ const wrapPrepared = (raw) => ({
600
+ prepareDiagnosticsJson: raw.prepareDiagnosticsJson.bind(raw),
601
+ warmLazyRegex: raw.warmLazyRegex.bind(raw),
602
+ warmLazyRegexDiagnosticsJson: raw.warmLazyRegexDiagnosticsJson.bind(raw),
603
+ createRedactionSession: (sessionId) => wrapSession(raw.createRedactionSession(sessionId)),
604
+ createRedactionSessionWithLifecycle: (sessionId, createdAtEpochSeconds, expiresAtEpochSeconds) => wrapSession(raw.createRedactionSessionWithLifecycle(sessionId, createdAtEpochSeconds, expiresAtEpochSeconds)),
605
+ restoreRedactionSession: (plaintextJson) => wrapSession(raw.restoreRedactionSession(plaintextJson)),
606
+ restoreEncryptedRedactionSession: ({ archive, key, expectedSessionId, observedAtEpochSeconds }) => wrapSession(raw.restoreEncryptedRedactionSession(archive, key, expectedSessionId, observedAtEpochSeconds)),
607
+ redactStaticEntities: (fullText, operators) => canonicalResult(JSON.parse(raw.redactStaticEntitiesJson(fullText, json(operators)))),
608
+ redactStaticEntitiesJson: (fullText, operators) => raw.redactStaticEntitiesJson(fullText, json(operators)),
609
+ redactStaticEntitiesWithCallerDetectionsJson: (fullText, { requestJson, operators }) => raw.redactStaticEntitiesWithCallerDetectionsJson(fullText, requestJson, json(operators)),
610
+ redactStaticEntitiesWithCallerDetectionsDiagnosticsJson: (fullText, { requestJson, operators }) => raw.redactStaticEntitiesWithCallerDetectionsDiagnosticsJson(fullText, requestJson, json(operators)),
611
+ redactStaticEntitiesResultStreamJson: (fullText, operators, onEvent) => {
612
+ return raw.redactStaticEntitiesResultStreamJson(fullText, json(operators), onEvent);
613
+ },
614
+ redactStaticEntitiesDiagnosticsJson: (fullText, operators) => raw.redactStaticEntitiesDiagnosticsJson(fullText, json(operators)),
615
+ redactStaticEntitiesDiagnosticsStreamJson: (fullText, operators, onBatch) => raw.redactStaticEntitiesDiagnosticsStreamJson(fullText, json(operators), onBatch),
616
+ redactStaticEntitiesSummaryDiagnosticsJson: (fullText, operators) => raw.redactStaticEntitiesSummaryDiagnosticsJson(fullText, json(operators))
617
+ });
618
+ const wrapSession = (raw) => ({
619
+ sessionId: raw.sessionId.bind(raw),
620
+ mappingCount: raw.mappingCount.bind(raw),
621
+ restoreText: raw.restoreText.bind(raw),
622
+ restoreTextAt: raw.restoreTextAt.bind(raw),
623
+ toPlaintextJson: raw.toPlaintextJson.bind(raw),
624
+ toPlaintextJsonAt: raw.toPlaintextJsonAt.bind(raw),
625
+ toEncryptedArchive: raw.toEncryptedArchive.bind(raw),
626
+ toEncryptedArchiveAt: raw.toEncryptedArchiveAt.bind(raw),
627
+ inspectJson: raw.inspectJson.bind(raw),
628
+ deleteJson: raw.deleteJson.bind(raw),
629
+ redactStaticEntitiesJson: (fullText, operators) => raw.redactStaticEntitiesJson(fullText, json(operators)),
630
+ redactStaticEntitiesJsonAt: (fullText, observedAtEpochSeconds, operators) => raw.redactStaticEntitiesJsonAt(fullText, observedAtEpochSeconds, json(operators)),
631
+ planStaticEntitiesWithCallerDetections: ({ inputs, operators, observedAtEpochSeconds }) => raw.planStaticEntitiesWithCallerDetections(JSON.stringify(inputs.map(({ fullText, requestJson }) => ({
632
+ full_text: fullText,
633
+ request_json: requestJson
634
+ }))), json(operators), observedAtEpochSeconds)
635
+ });
636
+ const json = (value) => value === void 0 ? void 0 : JSON.stringify(value);
637
+ const canonicalResult = (result) => ({
638
+ resolvedEntities: result.resolved_entities.map(({ source_detail, provider_id, detection_id, ...entity }) => ({
639
+ ...entity,
640
+ ...source_detail === void 0 ? {} : { sourceDetail: source_detail },
641
+ ...provider_id === void 0 ? {} : { providerId: provider_id },
642
+ ...detection_id === void 0 ? {} : { detectionId: detection_id }
643
+ })),
644
+ redaction: {
645
+ redactedText: result.redaction.redacted_text,
646
+ redactionMap: result.redaction.redaction_map,
647
+ operatorMap: result.redaction.operator_map.map(({ placeholder, operator }) => ({
648
+ placeholder,
649
+ operator: parseOperatorType(operator)
650
+ })),
651
+ entityCount: result.redaction.entity_count
652
+ }
653
+ });
654
+ const parseOperatorType = (operator) => {
655
+ switch (operator) {
656
+ case "keep":
657
+ case "mask":
658
+ case "redact":
659
+ case "replace": return operator;
660
+ default: throw new TypeError(`Unknown redaction operator: ${operator}`);
661
+ }
662
+ };
663
+ const assertPdfPixelPages = (pagePixels) => {
664
+ for (const [index, page] of pagePixels.entries()) if (!(page instanceof Uint8Array)) throw new TypeError(`PDF pagePixels[${index}] must be a Uint8Array`);
665
+ };
666
+ //#endregion
520
667
  //#region src/context.ts
521
668
  /** Create a fresh, empty pipeline context. */
522
669
  const createPipelineContext = () => ({
@@ -888,8 +1035,8 @@ const nativePackageCacheKey = ({ binding, config, gazetteerEntries, compressed }
888
1035
  ].join(":");
889
1036
  //#endregion
890
1037
  //#region src/wasm.ts
891
- const NODE_GLUE_MODULE = "index.wasi.cjs";
892
- const BROWSER_GLUE_MODULE = "index.wasi-browser.js";
1038
+ const GLUE_MODULE = "index.js";
1039
+ const WASM_MODULE = "index_bg.wasm";
893
1040
  const NODE_FS_MODULE = "node:fs/promises";
894
1041
  const NATIVE_ASSET_DIR = "native";
895
1042
  const DEFAULT_PACKAGE_FILE = "native-pipeline.stlanonpkg";
@@ -905,12 +1052,14 @@ const getBinding = () => {
905
1052
  return bindingPromise;
906
1053
  };
907
1054
  const loadWasmBinding = async () => {
908
- const glueModule = isNodeRuntime() ? NODE_GLUE_MODULE : BROWSER_GLUE_MODULE;
909
1055
  const loaded = await import(
910
1056
  /* @vite-ignore */
911
- assetUrl(glueModule).href
1057
+ assetUrl(GLUE_MODULE).href
912
1058
  );
913
- return toNativeAnonymizeBinding(loaded);
1059
+ if (!isRawWasmModule(loaded)) throw new Error("wasm module does not expose the expected binding surface");
1060
+ const moduleInput = isNodeRuntime() ? await readFileUrlBytes(assetUrl(WASM_MODULE).href) : assetUrl(WASM_MODULE);
1061
+ await loaded.default({ module_or_path: moduleInput });
1062
+ return createWasmBinding(loaded);
914
1063
  };
915
1064
  const isNodeRuntime = () => {
916
1065
  const globals = globalThis;
@@ -1078,11 +1227,7 @@ const summary_diagnostics_json = async (config, fullText, operators, options) =>
1078
1227
  });
1079
1228
  /** Inspect PDF bytes and optional renderer observations through the same
1080
1229
  * fail-closed core used by Node and Python. This does not redact the PDF. */
1081
- const inspect_pdf_json = async (document, observationsJson, options) => {
1082
- const inspect = (await resolveBinding(options)).inspectPdfJson;
1083
- if (inspect === void 0) throw new Error("wasm binding is stale: inspectPdfJson is missing");
1084
- return inspect(document, observationsJson);
1085
- };
1230
+ const inspect_pdf_json = async (document, observationsJson, options) => (await resolveBinding(options)).inspectPdfJson(document, observationsJson);
1086
1231
  const toNativeAnonymizeBinding = (loaded) => {
1087
1232
  const candidate = pickBindingCandidate(loaded);
1088
1233
  if (!isNativeAnonymizeBinding(candidate)) throw new Error("wasm binding module does not expose the native anonymize surface");
@@ -1092,18 +1237,6 @@ const pickBindingCandidate = (loaded) => {
1092
1237
  if (isRecord(loaded) && isNativeAnonymizeBinding(loaded["default"])) return loaded["default"];
1093
1238
  return loaded;
1094
1239
  };
1095
- const isNativeAnonymizeBinding = (value) => {
1096
- if (!isRecord(value)) return false;
1097
- if (typeof value["nativePackageVersion"] !== "function") return false;
1098
- if (typeof value["normalizeForSearch"] !== "function") return false;
1099
- if (typeof value["prepareStaticSearchPackageBytes"] !== "function") return false;
1100
- if (typeof value["inspectPdfJson"] !== "function") return false;
1101
- if (typeof value["prepareStaticSearchCompressedPackageBytes"] !== "function") return false;
1102
- const preparedSearch = value["NativePreparedSearch"];
1103
- if (!isRecord(preparedSearch)) return false;
1104
- if (typeof preparedSearch["fromConfigJsonBytes"] !== "function") return false;
1105
- return typeof preparedSearch["fromPreparedPackageBytes"] === "function";
1106
- };
1107
1240
  const isRecord = (value) => typeof value === "object" && value !== null || typeof value === "function";
1108
1241
  const normalizeLanguage = (language) => {
1109
1242
  const normalized = language.trim().toLowerCase();
@@ -1111,6 +1244,6 @@ const normalizeLanguage = (language) => {
1111
1244
  return normalized;
1112
1245
  };
1113
1246
  //#endregion
1114
- export { CALLER_DETECTION_CONTRACT_VERSION, CAPABILITY_MANIFEST, CAPABILITY_MANIFEST_SCHEMA_VERSION, CAPABILITY_PARITY_PROFILES, CAPABILITY_RUNTIMES, CAPABILITY_SURFACES, DEFAULT_ENTITY_LABELS, DETECTION_SOURCES, DETECTOR_PRIORITY, ENTITY_CAPABILITIES, ENTITY_LABELS, ENTITY_SELECTIONS, EXTERNAL_DETECTION_BATCH_MAX_BYTES, EXTERNAL_DETECTION_BATCH_VERSION, EXTERNAL_DETECTION_DOCUMENT_MAX_BYTES, EXTERNAL_DETECTION_MAX_DETECTIONS, EXTERNAL_DETECTION_MAX_LABEL_MAPPINGS, EXTERNAL_DETECTION_MAX_METADATA_BYTES, EXTERNAL_DETECTION_OFFSET_UNITS, EXTERNAL_DETECTION_PROVIDER_ID_MAX_BYTES, OPERATOR_TYPES, PreparedAnonymizer, PreparedNativeAnonymizer, PreparedNativePipeline, PreparedNativeRedactionSession, PreparedNativeSessionRedactionPlan, PreparedSearch, assertNativeBindingVersion, assertNativePipelineSupported, convert_external_detection_batch, createNativeAnonymizerFromConfig, createNativeAnonymizerFromPackage, createNativePipelineFromConfig, createNativePipelineFromPackage, createPipelineContext, deanonymise, defaultPackageUrl, diagnostics_json, diagnostics_stream_json, encodeNativeSearchConfig, encodeNativeSearchConfigInput, exportRedactionKey, getBinding, getDefaultPipeline, getNativeBindingVersion, getNativePipelineCompatibility, inspect_pdf_json, loadDefaultPipeline, loadPipeline, load_prepared_package, native_package_version, normalize_for_search, prepareNativePipelineConfig, prepareNativePipelinePackage, prepareNativeSearchPackage, prepare_search_package, redactDefaultText, redactDefaultTextJson, redact_text, redact_text_json, redact_text_stream_json, summary_diagnostics_json };
1247
+ export { CALLER_DETECTION_CONTRACT_VERSION, CAPABILITY_MANIFEST, CAPABILITY_MANIFEST_SCHEMA_VERSION, CAPABILITY_PARITY_PROFILES, CAPABILITY_RUNTIMES, CAPABILITY_SURFACES, DEFAULT_ENTITY_LABELS, DETECTION_SOURCES, DETECTOR_PRIORITY, ENTITY_CAPABILITIES, ENTITY_LABELS, ENTITY_SELECTIONS, EXTERNAL_DETECTION_BATCH_MAX_BYTES, EXTERNAL_DETECTION_BATCH_VERSION, EXTERNAL_DETECTION_DOCUMENT_MAX_BYTES, EXTERNAL_DETECTION_MAX_DETECTIONS, EXTERNAL_DETECTION_MAX_LABEL_MAPPINGS, EXTERNAL_DETECTION_MAX_METADATA_BYTES, EXTERNAL_DETECTION_OFFSET_UNITS, EXTERNAL_DETECTION_PROVIDER_ID_MAX_BYTES, NATIVE_BINDING_PARITY_MEMBERS, OPERATOR_TYPES, PreparedAnonymizer, PreparedNativeAnonymizer, PreparedNativePipeline, PreparedNativeRedactionSession, PreparedNativeSessionRedactionPlan, PreparedSearch, assertNativeBindingVersion, assertNativePipelineSupported, convert_external_detection_batch, createNativeAnonymizerFromConfig, createNativeAnonymizerFromPackage, createNativePipelineFromConfig, createNativePipelineFromPackage, createPipelineContext, deanonymise, defaultPackageUrl, diagnostics_json, diagnostics_stream_json, encodeNativeSearchConfig, encodeNativeSearchConfigInput, exportRedactionKey, getBinding, getDefaultPipeline, getNativeBindingVersion, getNativePipelineCompatibility, inspect_pdf_json, isNativeAnonymizeBinding, loadDefaultPipeline, loadPipeline, load_prepared_package, native_package_version, normalize_for_search, prepareNativePipelineConfig, prepareNativePipelinePackage, prepareNativeSearchPackage, prepare_search_package, redactDefaultText, redactDefaultTextJson, redact_text, redact_text_json, redact_text_stream_json, summary_diagnostics_json };
1115
1248
 
1116
1249
  //# sourceMappingURL=wasm.mjs.map