paisa-mcp 0.0.14 → 0.0.16

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
@@ -45676,47 +45676,54 @@ async function backfillPersons(client, crypto3, opts = {}) {
45676
45676
  groups.set(norm, g2);
45677
45677
  }
45678
45678
  const plan = [];
45679
- const links = [];
45680
- let created = 0;
45679
+ const newGroups = [];
45681
45680
  let reused = 0;
45682
45681
  for (const [norm, g2] of groups) {
45683
45682
  const upiHandles = [...g2.upiHandles];
45684
- let personId = personIdByNorm.get(norm);
45685
- const action = personId ? "reuse" : "create";
45683
+ const isReuse = personIdByNorm.has(norm);
45686
45684
  plan.push({
45687
45685
  name: g2.displayName,
45688
45686
  normalized: norm,
45689
45687
  txnCount: g2.txnIds.length,
45690
45688
  upiHandles,
45691
- action
45692
- });
45693
- if (!opts.dryRun) {
45694
- if (!personId) {
45695
- const fields = {
45696
- name: g2.displayName,
45697
- upiHandles,
45698
- phoneNumbers: [],
45699
- relationship: null,
45700
- notes: null
45701
- };
45702
- const body = crypto3 ? await encryptPersonCipher(fields, crypto3.key) : { name: fields.name, upiHandles, phoneNumbers: [], relationship: null, notes: null };
45703
- const res = await client.post("/api/persons", body);
45704
- personId = res.data.id;
45705
- personIdByNorm.set(norm, personId);
45706
- created++;
45707
- } else {
45708
- reused++;
45709
- }
45689
+ action: isReuse ? "reuse" : "create"
45690
+ });
45691
+ if (isReuse)
45692
+ reused++;
45693
+ else
45694
+ newGroups.push({ norm, displayName: g2.displayName, upiHandles });
45695
+ }
45696
+ if (!opts.dryRun && newGroups.length > 0) {
45697
+ const bodies = await Promise.all(newGroups.map(async ({ displayName, upiHandles }) => {
45698
+ const fields = {
45699
+ name: displayName,
45700
+ upiHandles,
45701
+ phoneNumbers: [],
45702
+ relationship: null,
45703
+ notes: null
45704
+ };
45705
+ return crypto3 ? await encryptPersonCipher(fields, crypto3.key) : { name: displayName, upiHandles, phoneNumbers: [], relationship: null, notes: null };
45706
+ }));
45707
+ const res = await client.post("/api/persons/bulk", {
45708
+ persons: bodies
45709
+ });
45710
+ res.data.forEach((p2, i2) => {
45711
+ personIdByNorm.set(newGroups[i2].norm, p2.id);
45712
+ });
45713
+ }
45714
+ const created = newGroups.length;
45715
+ const links = [];
45716
+ if (!opts.dryRun) {
45717
+ for (const [norm, g2] of groups) {
45718
+ const personId = personIdByNorm.get(norm);
45719
+ if (!personId)
45720
+ continue;
45710
45721
  for (const txnId of g2.txnIds)
45711
45722
  links.push({ transactionId: txnId, personId });
45712
- } else if (personId) {
45713
- reused++;
45714
- } else {
45715
- created++;
45716
45723
  }
45717
45724
  }
45718
45725
  if (!opts.dryRun && links.length > 0) {
45719
- const CHUNK = 500;
45726
+ const CHUNK = 25;
45720
45727
  for (let i2 = 0;i2 < links.length; i2 += CHUNK) {
45721
45728
  await client.post("/api/transactions/bulk-link-entity", { links: links.slice(i2, i2 + CHUNK) });
45722
45729
  }
@@ -46207,5 +46214,5 @@ main().catch((err) => {
46207
46214
  process.exit(1);
46208
46215
  });
46209
46216
 
46210
- //# debugId=52C61062ED34DC2364756E2164756E21
46217
+ //# debugId=F486FC7CCC9FDB0C64756E2164756E21
46211
46218
  //# sourceMappingURL=index.js.map