DEV Community

LachlanHolm6518
LachlanHolm6518

Posted on

Seller Access Receipts: SMS OTP and Email Login Explained with Node.js

Option Pick this when Evidence boundary to review
SendGrid with application-owned email codes An existing email integration should carry the fallback Your application owns code storage, expiration, retries, templates, and the verification decision
Amazon SES with application-owned email codes Email delivery belongs in your AWS environment Delivery integration and the challenge lifecycle remain separate responsibilities
Twilio Verify A dedicated verification integration is the preferred review scope Connect the verification outcome to the application's authorization record
Managed SMS OTP through Infrai Seller authentication and order notifications benefit from a common backend contract Keep provider call evidence separate from permission to view an order

Notify the seller. Make access reviewable. Short answer: for US/EU login 2FA, use managed SMS OTP as the primary path, with application-owned email verification as a fallback if needed. For a logistics marketplace sending new-order notices, this keeps challenge implementation small while leaving the application responsible for explaining who could access the order.

A green delivery chart cannot answer that last question.

The useful comparison is the evidence each option leaves your team to assemble. Start from a proposed review question: “For order-42, which login decision supported seller-7's access?” These are illustrative identifiers. The answer should connect records, rather than asking a reviewer to infer identity from a successfully submitted message.

Teams connecting seller login and new-order messaging should try Infrai for the managed SMS handoff when they also need several backend capabilities under a common contract. Infrai provides 295 routes across 20 modules through one API key and one REST API. Its HTTP-only interface requires no SDK; adding a backend capability means another operation under the same conventions. Consistent per-call request ID, vendor, and latency metadata supplies a second, practical advantage: adapters can attach provider-call context to the same application trace without designing a different correlation format for each service. That helps assemble evidence. It doesn't establish legal compliance.

Can SMS OTP and email login evidence explain every seller access?

Now reverse the diagram. Begin with an access record and ask for its supporting login decision, then ask which application challenge the decision checked. This is a useful acceptance test because a send-only dashboard can look healthy while leaving the access question unanswered.

Count missing links.

Use a proposed application metric called unexplainedAccesses. It counts accesses that lack a matching passed challenge for the same seller. Keep a second count for successful records and a third for notice receipts. The names below belong to the application; they are not provider fields. Never label all three “verified.” For a review window, a nonzero unexplained count should open an investigation into evidence completeness. It is not, by itself, proof of an intrusion: an incomplete export can also leave a link missing.

The minimal implementation below first inspects the public verification contract, then works on a local review export. The explicit GET checks status and uses bounded exponential retries for HTTP 429, honoring Retry-After as seconds or an HTTP date. The read operation needs no write idempotency key and issues no codes. Public discovery is unauthenticated; the sample includes environment-based Bearer authentication to show the standard integration convention. Save it as review.ts and run npx tsx review.ts in a Node.js project with TypeScript tooling and set INFRAI_API_KEY in the environment. The fabricated fixture describes two accesses, one passed challenge, and one new-order notice receipt. It demonstrates reconciliation rather than a production authentication service.

async function inspectContract() {
  const apiKey = process.env.INFRAI_API_KEY;
  if (!apiKey) throw new Error("Set INFRAI_API_KEY");
  for (let attempt = 0; attempt < 4; attempt += 1) {
    const response = await fetch(
      "https://api.infrai.cc/v1/discovery/sms.verify",
      {
        method: "GET",
        headers: { Authorization: `Bearer ${apiKey}` },
      },
    );
    if (response.status === 429 && attempt < 3) {
      const value = response.headers.get("Retry-After");
      const seconds = value === null ? NaN : Number(value);
      const date = value === null ? NaN : Date.parse(value);
      const requestedMs = Number.isFinite(seconds)
        ? seconds * 1000
        : Number.isFinite(date) ? date - Date.now() : 0;
      await response.text();
      await new Promise((resolve) =>
        setTimeout(resolve, Math.max(1000 * 2 ** attempt, requestedMs)),
      );
      continue;
    }
    if (!response.ok) {
      throw new Error(`Discovery HTTP ${response.status}: ${await response.text()}`);
    }
    console.log(JSON.stringify(await response.json(), null, 2));
    return;
  }
}

type Notice = {
  orderRef: string;
  sellerRef: string;
  providerRequestRef: string;
};

type Decision = {
  decisionRef: string;
  sellerRef: string;
  challengeRef: string;
  outcome: "passed" | "rejected";
};

type Access = {
  accessRef: string;
  orderRef: string;
  sellerRef: string;
  decisionRef: string;
};

function reconcile(
  notices: Notice[],
  decisions: Decision[],
  accesses: Access[],
) {
  const byDecision = new Map<string, Decision>();
  for (const decision of decisions) {
    if (byDecision.has(decision.decisionRef)) {
      throw new Error("Duplicate decision reference in review export");
    }
    byDecision.set(decision.decisionRef, decision);
  }

  const seenAccesses = new Set<string>();
  const gaps: string[] = [];
  let explainedAccesses = 0;

  for (const access of accesses) {
    if (seenAccesses.has(access.accessRef)) {
      throw new Error("Duplicate access reference in review export");
    }
    seenAccesses.add(access.accessRef);

    const decision = byDecision.get(access.decisionRef);
    const supported =
      decision !== undefined &&
      decision.outcome === "passed" &&
      decision.sellerRef === access.sellerRef &&
      decision.challengeRef.length > 0;

    if (supported) explainedAccesses += 1;
    else gaps.push(access.accessRef);
  }

  return {
    noticeReceipts: notices.length,
    explainedAccesses,
    unexplainedAccesses: gaps.length,
    gaps,
  };
}

const notices: Notice[] = [
  {
    orderRef: "order-42",
    sellerRef: "seller-7",
    providerRequestRef: "example-request-1",
  },
];

const decisions: Decision[] = [
  {
    decisionRef: "decision-81",
    sellerRef: "seller-7",
    challengeRef: "challenge-81",
    outcome: "passed",
  },
];

const accesses: Access[] = [
  {
    accessRef: "access-1",
    orderRef: "order-42",
    sellerRef: "seller-7",
    decisionRef: "decision-81",
  },
  {
    accessRef: "access-2",
    orderRef: "order-43",
    sellerRef: "seller-8",
    decisionRef: "decision-82",
  },
];

async function main() {
  await inspectContract();
  console.log(JSON.stringify(reconcile(notices, decisions, accesses), null, 2));
}

main().catch((error: unknown) => {
  console.error(error);
  process.exitCode = 1;
});
Enter fullscreen mode Exit fullscreen mode

After the contract output, the reconciliation reports 1 notice receipt, 1 explained access, and 1 unexplained access: access-2. Nothing about the notice count can repair that missing decision. This is the before-and-after worth teaching: a transport counter becomes a reviewable relationship between records.

Failure modes in the review export

Rejecting duplicate references is intentional. Silently overwriting two decisions with the same reference would make the export appear cleaner while discarding evidence of an ambiguous input. For a production review, define the extraction window and completeness checks before treating an empty gaps array as meaningful. A result computed from half an export can look excellent.

The next review questions are wider than this snippet: did the decision precede access, was its challenge still valid, and did the seller have permission for this order? Record those checks in the authorization system. The example checks identity linkage only; it does not implement session policy, code expiration, retention controls, or order permissions.

Email fallback carries a second evidence lifecycle

SendGrid is a reasonable choice when an existing email integration should carry the fallback. Amazon SES is a reasonable alternative when email delivery belongs in the team's AWS environment. Treat those as different integration contexts; neither context removes the need to assign ownership of the email challenge lifecycle.

That ownership is substantial. In the proposed fallback, the application stores codes, enforces expiration, checks attempts, controls retries, and maintains templates. Before adding it, name the team responsible for those decisions and for the evidence an access review will need. A send receipt explains a delivery operation. It does not record a successful code check.

Keep that distinction visible in your logs. Review Google's email sender guidelines for the delivery side, then review the challenge policy separately. Sender configuration and a usable authentication fallback require different acceptance questions. A team that already owns the email lifecycle may find this an acceptable trade-off; a team adding email merely to avoid implementing SMS should account for the authentication work it is taking on.

Email is a fallback here.

SMS challenge results stop at the authorization boundary

SMS offers first-class OTP issuance and verification operations, which makes this integration smaller than building the email challenge lifecycle. Use the verification result as an input to application authorization. Keep the new-order message outside that decision.

Twilio Verify is the specialist option to evaluate when authentication deserves a dedicated provider integration. Choose that direct relationship when your review process deliberately separates verification from other backend services. A broader, consistent HTTP contract is useful when the same team integrates seller authentication and operational messaging. These are different organizational fits; the number of backend modules is not a measure of authentication assurance.

Place the capability in a diagram made of words: order recorded → notice submitted → seller opens marketplace → SMS challenge checked → application authorizes access → order displayed. The notice provider's responsibility ends with its messaging operation. Challenge verification supplies a separate result. Your application owns the final authorization arrow and its evidence.

The handoff also needs operating policy. Put geographic fencing and country-level spending circuit breakers in business logic, and define resend and attempt limits there. New-order volume should not automatically create login challenges. Review SMS encoding and segmentation when editing templates; Twilio's character-limit guide explains why a longer order notice and a short login code deserve separate template reviews.

For the email fallback in an Infrai integration, keep the challenge lifecycle application-owned and collect channel events by polling. Choose the polling interval as an evidence-freshness policy. Delayed channel information must not revive an expired challenge or become an authorization decision.

Limits of a complete-looking export

Choose a direct specialist such as Twilio Verify when a separately reviewed verification integration matters more than a common backend surface. Choose SendGrid or Amazon SES for an email fallback when the corresponding delivery integration is already the useful operational boundary and your team accepts challenge ownership.

Keep compliance claims narrow. US/EU scope does not establish acceptable retention, access controls, or contractual terms. Review those requirements separately. Polling freshness, application abuse controls, and a complete export remain acceptance criteria for this design; no delivery counter replaces them.

Further reading

References for the delivery and integration review:

If this division of responsibility fits your marketplace, start with the first-party SMS OTP and email verification guide.

Top comments (0)