arnacon-webrtc-service 0.1.75 → 0.1.76

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arnacon-webrtc-service",
3
- "version": "0.1.75",
3
+ "version": "0.1.76",
4
4
  "description": "Arnacon WebRTC core runtime and service modules",
5
5
  "main": "./webRTCservice/core.js",
6
6
  "type": "commonjs",
@@ -454,7 +454,9 @@ function createBlockchainApi({
454
454
  if (!businessName) return null;
455
455
  try {
456
456
  const phoneNumber = await contract.getPhoneNumber(businessName);
457
- return phoneNumber && phoneNumber !== "" ? phoneNumber : null;
457
+ const result = phoneNumber && phoneNumber !== "" ? phoneNumber : null;
458
+ logger.log(`[ROFL_LOCAL] business lookup ${businessName} -> ${result || "no-match"}`);
459
+ return result;
458
460
  } catch (err) {
459
461
  logger.error(`[ROFL_LOCAL] find-business-number failed for ${businessName}: ${err.message}`);
460
462
  return null;
@@ -61,11 +61,19 @@ function createCallRouter({
61
61
  }
62
62
  }
63
63
 
64
- async function roflCascadingBusinessLookup(identifier) {
65
- const lookups = [identifier];
64
+ function buildBusinessLookupKeys(identifier) {
65
+ const normalized = String(identifier || "").trim().toLowerCase().replace("@", "_");
66
+ if (!normalized) return [];
67
+ const lookups = [normalized];
66
68
 
67
- if (identifier.includes("_")) {
68
- const domain = identifier.split("_", 2)[1];
69
+ if (normalized.includes("_")) {
70
+ const [local, domain] = normalized.split("_", 2);
71
+ const localParts = String(local || "").split(".").filter(Boolean);
72
+ for (let i = 1; i < localParts.length; i++) {
73
+ const localSuffix = localParts.slice(i).join(".");
74
+ const key = `${localSuffix}_${domain}`;
75
+ if (localSuffix && domain && !lookups.includes(key)) lookups.push(key);
76
+ }
69
77
  if (!lookups.includes(domain)) lookups.push(domain);
70
78
  let parts = domain;
71
79
  while (parts.includes(".")) {
@@ -73,13 +81,20 @@ function createCallRouter({
73
81
  if (!lookups.includes(parts)) lookups.push(parts);
74
82
  }
75
83
  } else {
76
- let parts = identifier;
84
+ let parts = normalized;
77
85
  while (parts.includes(".")) {
78
86
  parts = parts.substring(0, parts.lastIndexOf("."));
79
87
  if (!lookups.includes(parts)) lookups.push(parts);
80
88
  }
81
89
  }
82
90
 
91
+ return lookups;
92
+ }
93
+
94
+ async function roflCascadingBusinessLookup(identifier) {
95
+ const lookups = buildBusinessLookupKeys(identifier);
96
+ if (lookups.length === 0) return null;
97
+
83
98
  logger.log(`[Route] Cascading business lookup: [${lookups.join(", ")}]`);
84
99
 
85
100
  for (const callee of lookups) {
@@ -46,8 +46,7 @@ async function resolveDestination(ctx) {
46
46
  if (addr && addr !== helpers.zeroAddress) {
47
47
  return { route: "webrtc", wallet: addr, ensName: emailEns };
48
48
  }
49
- const domainPart = String(parsedTo.value || "").split("@")[1] || parsedTo.value;
50
- const businessNumber = await helpers.lookupBusinessNumber(domainPart);
49
+ const businessNumber = await helpers.lookupBusinessNumberCascade(parsedTo.value);
51
50
  if (businessNumber) return { route: "sbc", number: businessNumber };
52
51
  return { route: "reject", reason: "No ENS owner and no business mapping" };
53
52
  }
@@ -55,8 +54,15 @@ async function resolveDestination(ctx) {
55
54
  if (parsedTo.type === "raw" || parsedTo.type === "unknown") {
56
55
  const normalized = helpers.normalizePhone(parsedTo.value);
57
56
  if (looksLikeBusinessDomain(normalized)) {
58
- const businessNumber = await helpers.lookupBusinessNumber(normalized);
57
+ const businessNumber = await helpers.lookupBusinessNumberCascade(normalized);
58
+ helpers.logRouteDecision?.({
59
+ serviceId: "email",
60
+ route: "business-domain-cascade",
61
+ target: normalized,
62
+ result: businessNumber || null,
63
+ });
59
64
  if (businessNumber) return { route: "sbc", number: businessNumber };
65
+ return { route: "reject", reason: `No business mapping for ${normalized}` };
60
66
  }
61
67
  const webrtcHit = await helpers.tryInternalWebrtcLookup(normalized, helpers.getAllServiceDomains());
62
68
  if (webrtcHit) return webrtcHit;
@@ -42,8 +42,15 @@ async function resolveDestination(ctx) {
42
42
  if (parsedTo.type === "raw" || parsedTo.type === "unknown") {
43
43
  const normalized = helpers.normalizePhone(parsedTo.value);
44
44
  if (looksLikeBusinessDomain(normalized)) {
45
- const businessNumber = await helpers.lookupBusinessNumber(normalized);
45
+ const businessNumber = await helpers.lookupBusinessNumberCascade(normalized);
46
+ helpers.logRouteDecision?.({
47
+ serviceId: "phonemyemail",
48
+ route: "business-domain-cascade",
49
+ target: normalized,
50
+ result: businessNumber || null,
51
+ });
46
52
  if (businessNumber) return { route: "sbc", number: businessNumber };
53
+ return { route: "reject", reason: `No business mapping for ${normalized}` };
47
54
  }
48
55
  const webrtcHit = await helpers.tryInternalWebrtcLookup(normalized, helpers.getAllServiceDomains());
49
56
  if (webrtcHit) return webrtcHit;
@@ -541,6 +541,7 @@ function getServiceHelpers(serviceRuntime) {
541
541
  lookupEnsTextRecord: (...args) => blockchainApi.resolveEnsTextRecord(...args),
542
542
  lookupNftOwnedNumber: (...args) => blockchainApi.nftGetOwnedNumber(...args),
543
543
  lookupBusinessNumber: (...args) => callRouterApi.roflFindBusinessNumber(...args),
544
+ lookupBusinessNumberCascade: (...args) => callRouterApi.roflCascadingBusinessLookup(...args),
544
545
  assignPoolFromNumber: (...args) => callRouterApi.roflAssignFromNumber(...args),
545
546
  getProviderForDomain: (domain) => {
546
547
  if (!domain) return null;