@reproapp/node-sdk 0.0.34 → 0.0.35

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
@@ -3003,9 +3003,12 @@ function limitRawInlinePrivacyValue(target, value) {
3003
3003
  return limited.skipped ? limited : null;
3004
3004
  }
3005
3005
  function materializeInlinePrivacyValue(target, value, cfg, req, trace, masking, privacy, db) {
3006
- if (value === undefined || shouldCapturePrivacyRaw(cfg)) {
3006
+ if (value === undefined) {
3007
3007
  return { value };
3008
3008
  }
3009
+ if (shouldCapturePrivacyRaw(cfg)) {
3010
+ return { value: limitMaterializedTraceInlineValue(value) };
3011
+ }
3009
3012
  try {
3010
3013
  const valueAfterPrivacy = applyPrivacyThenMask(target, value, cfg, req, trace, masking, privacy, db);
3011
3014
  return { value: valueAfterPrivacy };
@@ -3022,9 +3025,12 @@ function materializeInlinePrivacyValue(target, value, cfg, req, trace, masking,
3022
3025
  }
3023
3026
  }
3024
3027
  async function materializeInlinePrivacyValueAsync(target, value, cfg, req, trace, masking, privacy, db) {
3025
- if (value === undefined || shouldCapturePrivacyRaw(cfg)) {
3028
+ if (value === undefined) {
3026
3029
  return { value };
3027
3030
  }
3031
+ if (shouldCapturePrivacyRaw(cfg)) {
3032
+ return { value: limitMaterializedTraceInlineValue(value) };
3033
+ }
3028
3034
  try {
3029
3035
  const valueAfterPrivacy = await applyPrivacyThenMaskAsync(target, value, cfg, req, trace, masking, privacy, db);
3030
3036
  return { value: valueAfterPrivacy };
@@ -5197,9 +5203,6 @@ function emitDbQuery(cfg, sid, aid, payload) {
5197
5203
  const spanContext = payload?.spanContext ?? captureSpanContextFromTracer();
5198
5204
  if (!shouldCaptureDbSpan(spanContext))
5199
5205
  return;
5200
- if (ctx.captureScope) {
5201
- ctx.captureScope.dbChangeCount += 1;
5202
- }
5203
5206
  const runCtx = {
5204
5207
  sid: ctx.sid,
5205
5208
  aid: ctx.aid,
@@ -5213,7 +5216,7 @@ function emitDbQuery(cfg, sid, aid, payload) {
5213
5216
  await als.run(runCtx, async () => {
5214
5217
  await emitDbQueryAsync(cfg, sid, aid, payload).catch(() => undefined);
5215
5218
  });
5216
- });
5219
+ }, { priority: 'high' });
5217
5220
  }
5218
5221
  async function emitDbQueryAsync(cfg, sid, aid, payload) {
5219
5222
  if (!sid)
@@ -5327,6 +5330,9 @@ async function emitDbQueryAsync(cfg, sid, aid, payload) {
5327
5330
  t: payload.t,
5328
5331
  }]
5329
5332
  });
5333
+ if (enqueued && ctx.captureScope) {
5334
+ ctx.captureScope.dbChangeCount += 1;
5335
+ }
5330
5336
  }
5331
5337
  function buildMinimalUpdate(before, after) {
5332
5338
  const set = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reproapp/node-sdk",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
4
4
  "description": "Repro Nest SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -3610,9 +3610,12 @@ function materializeInlinePrivacyValue(
3610
3610
  privacy: NormalizedRuntimePrivacyPolicy | null,
3611
3611
  db?: RuntimePrivacyDbContext | null,
3612
3612
  ): InlinePrivacyMaterializationResult {
3613
- if (value === undefined || shouldCapturePrivacyRaw(cfg)) {
3613
+ if (value === undefined) {
3614
3614
  return { value };
3615
3615
  }
3616
+ if (shouldCapturePrivacyRaw(cfg)) {
3617
+ return { value: limitMaterializedTraceInlineValue(value) };
3618
+ }
3616
3619
 
3617
3620
  try {
3618
3621
  const valueAfterPrivacy = applyPrivacyThenMask(target, value, cfg, req, trace, masking, privacy, db);
@@ -3639,9 +3642,12 @@ async function materializeInlinePrivacyValueAsync(
3639
3642
  privacy: NormalizedRuntimePrivacyPolicy | null,
3640
3643
  db?: RuntimePrivacyDbContext | null,
3641
3644
  ): Promise<InlinePrivacyMaterializationResult> {
3642
- if (value === undefined || shouldCapturePrivacyRaw(cfg)) {
3645
+ if (value === undefined) {
3643
3646
  return { value };
3644
3647
  }
3648
+ if (shouldCapturePrivacyRaw(cfg)) {
3649
+ return { value: limitMaterializedTraceInlineValue(value) };
3650
+ }
3645
3651
 
3646
3652
  try {
3647
3653
  const valueAfterPrivacy = await applyPrivacyThenMaskAsync(target, value, cfg, req, trace, masking, privacy, db);
@@ -6154,9 +6160,6 @@ function emitDbQuery(cfg: any, sid?: string, aid?: string, payload?: any) {
6154
6160
  const ctx = getCtx() as Ctx;
6155
6161
  const spanContext = payload?.spanContext ?? captureSpanContextFromTracer();
6156
6162
  if (!shouldCaptureDbSpan(spanContext)) return;
6157
- if (ctx.captureScope) {
6158
- ctx.captureScope.dbChangeCount += 1;
6159
- }
6160
6163
  const runCtx: Ctx = {
6161
6164
  sid: ctx.sid,
6162
6165
  aid: ctx.aid,
@@ -6170,7 +6173,7 @@ function emitDbQuery(cfg: any, sid?: string, aid?: string, payload?: any) {
6170
6173
  await als.run(runCtx, async () => {
6171
6174
  await emitDbQueryAsync(cfg, sid, aid, payload).catch(() => undefined);
6172
6175
  });
6173
- });
6176
+ }, { priority: 'high' });
6174
6177
  }
6175
6178
 
6176
6179
  async function emitDbQueryAsync(cfg: any, sid?: string, aid?: string, payload?: any) {
@@ -6283,6 +6286,9 @@ async function emitDbQueryAsync(cfg: any, sid?: string, aid?: string, payload?:
6283
6286
  t: payload.t,
6284
6287
  }]
6285
6288
  });
6289
+ if (enqueued && ctx.captureScope) {
6290
+ ctx.captureScope.dbChangeCount += 1;
6291
+ }
6286
6292
  }
6287
6293
 
6288
6294
  function buildMinimalUpdate(before: any, after: any) {
@@ -389,6 +389,68 @@ async function testNativeInsertOneIsCaptured() {
389
389
  });
390
390
  }
391
391
 
392
+ async function testCaptureRawNativeInsertOneUsesJsonSafeTransportValues() {
393
+ await withCapturedFetch(async (capturedBodies) => {
394
+ __reproTestHooks.resetSdkBackgroundQueuesForTest();
395
+ const sessionId = 'S_mongo_insert_raw_complex';
396
+ const actionId = 'A_mongo_insert_raw_complex';
397
+ const cfg = {
398
+ ...makeConfig(sessionId, actionId),
399
+ privacy: { environment: 'dev', captureRaw: true },
400
+ };
401
+
402
+ class FakeCollection {
403
+ constructor() {
404
+ this.collectionName = 'subjects';
405
+ this.dbName = 'clinical';
406
+ }
407
+
408
+ async insertOne(doc, options) {
409
+ assert.strictEqual(options.session.id, 'native-raw-complex-session-1');
410
+ doc._id = doc._id ?? 'subject-raw-complex-1';
411
+ return { acknowledged: true, insertedId: doc._id };
412
+ }
413
+ }
414
+
415
+ __reproTestHooks.patchMongoCollectionPrototypeForTest(FakeCollection.prototype, cfg);
416
+ const collection = new FakeCollection();
417
+ const doc = {
418
+ subjectNumber: '10013039',
419
+ status: 'screened',
420
+ counter: BigInt(42),
421
+ };
422
+ doc.self = doc;
423
+
424
+ await runCapturedRequest(cfg, sessionId, actionId, async () => {
425
+ await collection.insertOne(doc, {
426
+ session: {
427
+ id: 'native-raw-complex-session-1',
428
+ hasEnded: false,
429
+ inTransaction: () => true,
430
+ },
431
+ });
432
+ });
433
+
434
+ await waitFor(() => dbChanges(flattenEvents(capturedBodies)).length === 1);
435
+ await waitFor(() => requestCaptureManifests(flattenEvents(capturedBodies)).length === 1);
436
+ await drainSdk();
437
+
438
+ const [change] = dbChanges(flattenEvents(capturedBodies));
439
+ const [manifest] = requestCaptureManifests(flattenEvents(capturedBodies));
440
+ assert.strictEqual(change.type, 'mongo');
441
+ assert.strictEqual(change.collection, 'subjects');
442
+ assert.strictEqual(change.op, 'insertOne');
443
+ assert.strictEqual(change.query.driver, 'mongodb');
444
+ assert.strictEqual(change.query.doc.subjectNumber, '10013039');
445
+ assert.strictEqual(change.query.doc.counter, '42');
446
+ assert.deepStrictEqual(change.query.doc.self, { __reproCircularRef: '$.doc' });
447
+ assert.strictEqual(change.after.subjectNumber, '10013039');
448
+ assert.strictEqual(change.after.counter, '42');
449
+ assert.deepStrictEqual(change.after.self, { __reproCircularRef: '$' });
450
+ assert.strictEqual(manifest.expected.dbChange, 1);
451
+ });
452
+ }
453
+
392
454
  async function testNativeUpdateOneUpsertIsCaptured() {
393
455
  await withCapturedFetch(async (capturedBodies) => {
394
456
  __reproTestHooks.resetSdkBackgroundQueuesForTest();
@@ -535,6 +597,7 @@ async function testNativeOperationFailureIsCapturedAndRethrown() {
535
597
  await testReproMiddlewarePatchesPreloadedNativeMongoClientInsertOne();
536
598
  await testMongoClientDbCollectionChainIsPatchedWithoutCollectionExport();
537
599
  await testNativeInsertOneIsCaptured();
600
+ await testCaptureRawNativeInsertOneUsesJsonSafeTransportValues();
538
601
  await testNativeUpdateOneUpsertIsCaptured();
539
602
  await testNativeFindCursorToArrayIsCaptured();
540
603
  await testNativeOperationFailureIsCapturedAndRethrown();