@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.
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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> {
|