@abraca/nuxt 2.84.0 → 2.86.0

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.
@@ -0,0 +1,84 @@
1
+ export async function waitForBackendReady(opts) {
2
+ const doFetch = opts.fetchImpl ?? globalThis.fetch;
3
+ const timeoutMs = opts.timeoutMs ?? 12e4;
4
+ const now = opts.now ?? (() => Date.now());
5
+ const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
6
+ const log = opts.onLog ?? ((level, message) => {
7
+ if (level === "warn") console.warn(message);
8
+ else console.log(message);
9
+ });
10
+ const started = now();
11
+ let attempt = 0;
12
+ let warned = false;
13
+ for (; ; ) {
14
+ attempt += 1;
15
+ try {
16
+ const res = await doFetch(`${opts.serverUrl}/health`);
17
+ if (res.ok) {
18
+ if (warned) {
19
+ log("info", `[abracadabra-service] backend ready after ${Math.round((now() - started) / 1e3)}s`);
20
+ }
21
+ return true;
22
+ }
23
+ } catch {
24
+ }
25
+ if (now() - started >= timeoutMs) {
26
+ log(
27
+ "warn",
28
+ `[abracadabra-service] ${opts.serverUrl}/health did not answer within ${Math.round(timeoutMs / 1e3)}s \u2014 attempting the handshake anyway.`
29
+ );
30
+ return false;
31
+ }
32
+ if (!warned) {
33
+ warned = true;
34
+ log(
35
+ "warn",
36
+ `[abracadabra-service] waiting for ${opts.serverUrl} to become ready \u2014 the backend is not answering /health yet.`
37
+ );
38
+ }
39
+ await sleep(Math.min(500 * 2 ** (attempt - 1), 5e3));
40
+ }
41
+ }
42
+ export function isRetryableAuthStatus(status) {
43
+ if (status === void 0) return true;
44
+ if (status === 410) return true;
45
+ return status >= 500 && status < 600;
46
+ }
47
+ export function authRetryDelayMs(attempt) {
48
+ return Math.min(250 * 2 ** (attempt - 1), 4e3);
49
+ }
50
+ export async function loginWithKeyRetrying(opts) {
51
+ const attempts = opts.attempts ?? 5;
52
+ const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
53
+ const log = opts.onLog ?? ((level, message) => {
54
+ if (level === "error") console.error(message);
55
+ else if (level === "warn") console.warn(message);
56
+ else console.log(message);
57
+ });
58
+ for (let attempt = 1; ; attempt++) {
59
+ try {
60
+ await opts.client.loginWithKey(opts.publicKey, opts.sign);
61
+ if (attempt > 1) {
62
+ log("info", `[abracadabra-service] handshake succeeded on attempt ${attempt}`);
63
+ }
64
+ return;
65
+ } catch (err) {
66
+ const status = err?.status;
67
+ const message = err instanceof Error ? err.message : String(err);
68
+ if (!isRetryableAuthStatus(status)) {
69
+ log("error", `[abracadabra-service] handshake refused (${message}) \u2014 not retrying. This is a credential problem, not a transient one: the runner's public key is not the key the backend registered for its service account. The backend only registers a key at ITS OWN boot, so after rotating one, recreate the backend container too.`);
70
+ throw err;
71
+ }
72
+ if (attempt >= attempts) {
73
+ log("error", `[abracadabra-service] handshake still failing after ${attempts} attempts: ${message}`);
74
+ throw err;
75
+ }
76
+ const delay = authRetryDelayMs(attempt);
77
+ log(
78
+ "warn",
79
+ `[abracadabra-service] handshake attempt ${attempt}/${attempts} failed (${message}) \u2014 retrying with a fresh challenge in ${delay}ms.` + (status === 410 ? " A 410 here means the backend process that answered /auth/verify never issued the challenge \u2014 expected while a deploy is still swapping backend containers." : "")
80
+ );
81
+ await sleep(delay);
82
+ }
83
+ }
84
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abraca/nuxt",
3
- "version": "2.84.0",
3
+ "version": "2.86.0",
4
4
  "description": "First-class Nuxt module for the Abracadabra CRDT collaboration platform",
5
5
  "repository": "abracadabra/abracadabra-nuxt",
6
6
  "license": "MIT",
@@ -173,9 +173,9 @@
173
173
  }
174
174
  },
175
175
  "devDependencies": {
176
- "@abraca/convert": "^2.83.0",
177
- "@abraca/dabra": "^2.83.0",
178
- "@abraca/plugin": "^2.83.0",
176
+ "@abraca/convert": "^2.85.0",
177
+ "@abraca/dabra": "^2.85.0",
178
+ "@abraca/plugin": "^2.85.0",
179
179
  "@codemirror/autocomplete": "^6.18.0",
180
180
  "@codemirror/commands": "^6.7.0",
181
181
  "@codemirror/lang-css": "^6.3.1",