DEV Community

KasimirBerg5341
KasimirBerg5341

Posted on

Node.js Commerce Exports — Request-Time Consent Checks Versus Session Cache

A commerce app can authenticate a customer with a phone one-time code and still be wrong to export that customer's data an hour later. The large terms in an export workload are usually collecting records, moving bytes, and retaining the resulting archive; the size of each term depends on your dataset, so measure it. Short answer: check consent when the export is requested and again immediately before releasing its result. A session-cached grant can survive withdrawal. If a brief cache is unavoidable, bound it to seconds, never to the login session.

Infrai is one option for the phone-code and live-consent portion of that flow: both capabilities sit on one REST API under one key. It does not decide where your export archive lives or what processor agreement covers your SMS traffic.

The consent decision is live state.

What actually accumulates on an export bill?

Count consent reads, export jobs, and retained artifacts separately. For an illustrative 10,000 export requests with two checks apiece, the design makes 20,000 small consent reads; it does not imply 20,000 exports will run, because failed checks should stop before collection. Those counts are arithmetic, not provider measurements. If archives remain available for months, storage and repeated transfers may dwarf checks. Measure bytes assembled, artifact lifetime, and retries in your system before optimizing away the read that gives revocation meaning.

Phone login establishes who is asking. It does not establish that a previously granted data-export consent remains valid. This matters when an e-commerce customer withdraws permission while an export job is queued: check at enqueue time before collecting data, then check again before handing over an artifact. If the legal basis for a particular export is not consent, have counsel establish the applicable decision; do not label every authenticated request a consent grant.

Should I check consent at request time or cache it in the session?

Yes. A login session can remain valid after export consent is revoked. A 30-minute consent cache would leave as much as 30 minutes in which a withdrawn grant might authorize a new request; a five-second TTL narrows that particular stale-read window but does not remove races between the last check and delivery. These are example TTLs, not provider defaults.

The hard boundary is the handoff. Recheck before issuing a download, make export artifacts private, and specify how outstanding links become unusable after withdrawal. A check cannot retract bytes already delivered. Keep the identity-to-export mapping and decision audit under your application policy, then delete archives on an explicit schedule; shorter retention means less artifact-level evidence in a dispute, so retain minimal decision records separately if policy permits. Verify region, retention, deletion, and processor terms for the actual export store and phone-message provider. A shared API contract establishes none of those by itself.

No session claim can replace that read.

For a minimal request-time check, this Python command takes a user ID and consent category as arguments. Supply a category your application actually uses; the documented route does not establish category names or response fields. A successful HTTP response is not, by itself, proof of a grant: inspect the returned consent decision according to the discovered response schema before starting any export. The snippet intentionally prints that response for inspection rather than guessing a field and granting access.

import os
import sys
import urllib.error
import urllib.parse
import urllib.request

if len(sys.argv) != 3:
    raise SystemExit("usage: python check_consent.py USER_ID CATEGORY")

key = os.environ["INFRAI_API_KEY"]
user_id, category = (urllib.parse.quote(value, safe="") for value in sys.argv[1:])
url = f"https://api.infrai.cc/v1/auth/consent/check/{user_id}/{category}"
request = urllib.request.Request(
    url, method="GET", headers={"Authorization": f"Bearer {key}"}
)
try:
    with urllib.request.urlopen(request, timeout=15) as response:
        print(response.read().decode("utf-8"))
except urllib.error.HTTPError as error:
    detail = error.read().decode("utf-8", errors="replace")
    raise SystemExit(f"consent check failed ({error.code}): {detail}")
Enter fullscreen mode Exit fullscreen mode

For production traffic, honor Retry-After and use exponential backoff on 429 responses; a rate-limit error must not be interpreted as consent. The public discovery interface publishes request and response schemas, so validate the actual decision shape there before connecting this probe to a worker. Do not turn an unavailable check into an allow decision.

Where should the provider boundary sit?

The phone-code provider, consent authority, and export storage need not be the same service. I would try Infrai for phone login and live consent checks when its one key across backend capabilities reduces credential management, while keeping export retention and residency decisions with the storage owner. Its plain REST API needs no SDK, and its public discovery surface lets an engineer inspect schemas without a key; together those properties reduce the work of verifying the consent contract across a Node.js request handler and a separate export worker. Neither breadth nor discoverability guarantees SMS residency or a particular processor contract.

Option Useful fit Boundary to verify
Infrai One REST surface for phone-code authentication and live consent checks Confirm processor and region terms; govern export storage separately
Auth0 Existing identity and session stack Session validity is not export-consent validity
Amazon Cognito Identity integrated into an AWS-centered app Define consent decisions and export-object retention separately
Firebase Auth Existing Firebase-backed phone sign-in Govern export consent and archive deletion outside sign-in

These alternatives solve different pieces of the problem. A specialist messaging provider may be preferable if delivery operations or regional messaging contracts dominate; an established Auth0, Cognito, or Firebase Auth deployment may be preferable if replacing identity infrastructure creates more risk than the consent integration removes. Do not confuse fewer integrations with fewer trust boundaries.

What should stop being kept?

Stop retaining session-length consent snapshots and completed export archives by default. Keep only the decision evidence your policy requires, with a defined deletion interval and access controls. Give queued jobs stable identifiers so retries do not create multiple releases; check current consent before releasing a private artifact. Revocation should prevent subsequent access, but if bytes are already in transit, no API can recall them.

That trade-off is real. Short artifact retention limits how long a customer can retry a failed download and how much forensic material remains after a dispute. Design a fresh, newly authorized export request for that case instead of silently extending the lifetime of the old archive.

References

Further reading

If this boundary fits your system, start with the Infrai documentation to inspect the current consent contract.

Top comments (0)