@revenexx/cover 0.2.8 → 0.2.9

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": "@revenexx/cover",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "Cover — revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -91,42 +91,49 @@ export class ApiAuthService implements IAuthService {
91
91
  return null;
92
92
  }
93
93
 
94
- try {
95
- // session_id makes the customers app validate the session is still
96
- // alive — a logged-out/revoked session answers 401 here. Raw call:
97
- // the AuthMeRequest contract does not declare session_id yet, so
98
- // the generated customersAuthMe() would drop the session check.
99
- const { user, contact } = await useRevenexxSdk().call<{
100
- user: { $id: string; name?: string; email: string };
101
- contact: ApiContact | null;
102
- }>("POST", "/v1/customers/auth/me", { body: { user_id: parsed.userId, session_id: parsed.id } });
94
+ // Validate the session against the customers app, retrying transient
95
+ // failures. A 401 is the only proof the session is gone (revoked/expired)
96
+ // → clear the cookie + log out. Anything else (5xx "capability dispatch
97
+ // failed", network blip, cold-start dispatch) is transient infra trouble:
98
+ // returning null on the FIRST blip bounced a still-valid session to login
99
+ // mid-flight (worst on a cold storefront's first SSR me()). So retry a
100
+ // couple times before giving up; the cookie is never dropped on transient
101
+ // errors, and the request only degrades to guest if every attempt blips.
102
+ const MAX_ATTEMPTS = 3;
103
+ let lastErr: unknown;
104
+ for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
105
+ try {
106
+ // session_id makes the customers app validate the session is still
107
+ // alive — a logged-out/revoked session answers 401 here. Raw call:
108
+ // the AuthMeRequest contract does not declare session_id yet, so
109
+ // the generated customersAuthMe() would drop the session check.
110
+ const { user, contact } = await useRevenexxSdk().call<{
111
+ user: { $id: string; name?: string; email: string };
112
+ contact: ApiContact | null;
113
+ }>("POST", "/v1/customers/auth/me", { body: { user_id: parsed.userId, session_id: parsed.id } });
103
114
 
104
- return {
105
- $id: user.$id,
106
- name: contactName(contact, user.name ?? user.email),
107
- email: user.email,
108
- role: toAuthRole(contact?.role),
109
- ...(contact?.id ? { contactId: contact.id } : {}),
110
- ...(contact?.organization_id ? { organizationId: contact.organization_id } : {}),
111
- };
112
- }
113
- catch (err) {
114
- // Only a genuine auth failure (401 = revoked/expired session) proves
115
- // the session is gone — clear the cookie so the user logs out cleanly.
116
- // Any other error (5xx like the gateway's "capability dispatch failed",
117
- // or a network blip) is transient infrastructure trouble, NOT proof the
118
- // session is invalid. Deleting the cookie here turned a flaky gateway
119
- // into a SILENT LOGOUT + empty order history (the account history is
120
- // filtered strictly by contact_id and falls back to me()). So keep the
121
- // cookie and return null: callers still degrade to the guest path for
122
- // this one request, and the session self-heals on the next.
123
- if (isApiUserError(err) && err.code === 401) {
124
- deleteCookie(event, SESSION_COOKIE_NAME, sessionCookieOptions());
125
- return null;
115
+ return {
116
+ $id: user.$id,
117
+ name: contactName(contact, user.name ?? user.email),
118
+ email: user.email,
119
+ role: toAuthRole(contact?.role),
120
+ ...(contact?.id ? { contactId: contact.id } : {}),
121
+ ...(contact?.organization_id ? { organizationId: contact.organization_id } : {}),
122
+ };
123
+ }
124
+ catch (err) {
125
+ lastErr = err;
126
+ if (isApiUserError(err) && err.code === 401) {
127
+ deleteCookie(event, SESSION_COOKIE_NAME, sessionCookieOptions());
128
+ return null;
129
+ }
130
+ if (attempt < MAX_ATTEMPTS) {
131
+ await new Promise(resolve => setTimeout(resolve, 300 * attempt));
132
+ }
126
133
  }
127
- getLogService().error("API request failed: auth/me", apiErrorContext(err));
128
- return null;
129
134
  }
135
+ getLogService().error("API request failed: auth/me", apiErrorContext(lastErr));
136
+ return null;
130
137
  }
131
138
 
132
139
  async logout(event: H3Event): Promise<void> {