@open-wa/session-sync 5.6.0 → 5.6.2
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/dist/index.cjs +8 -56
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -165,7 +165,7 @@ const keyPart = (value) => {
|
|
|
165
165
|
if (!value || value === "." || value === ".." || /[\x00-\x1f\x7f\\]/.test(value)) throw new SessionStoreError("SESSION_S3_KEY_INVALID", 400);
|
|
166
166
|
return encodeURIComponent(value).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
167
167
|
};
|
|
168
|
-
/** PicoS3
|
|
168
|
+
/** Shared PicoS3 session storage with unconditional, last-write-wins replacement. */
|
|
169
169
|
async function acquireSessionFile(config, filename) {
|
|
170
170
|
try {
|
|
171
171
|
return await acquire(config, filename);
|
|
@@ -189,7 +189,7 @@ async function acquire(config, filename) {
|
|
|
189
189
|
"x-amz-expected-bucket-owner",
|
|
190
190
|
"x-amz-request-payer"
|
|
191
191
|
].includes(key)));
|
|
192
|
-
const request = async (name, method, body
|
|
192
|
+
const request = async (name, method, body) => {
|
|
193
193
|
const object = {
|
|
194
194
|
...options,
|
|
195
195
|
filename: name,
|
|
@@ -217,59 +217,24 @@ async function acquire(config, filename) {
|
|
|
217
217
|
...data ? {
|
|
218
218
|
"Content-Type": body.startsWith("{") ? "application/json" : "text/plain",
|
|
219
219
|
"Content-Length": String(data.length)
|
|
220
|
-
} : {}
|
|
221
|
-
...etag === null ? { "If-None-Match": "*" } : etag ? { "If-Match": etag } : {}
|
|
220
|
+
} : {}
|
|
222
221
|
}
|
|
223
222
|
});
|
|
224
223
|
if (method === "GET" && response.status === 404) return null;
|
|
225
224
|
if (response.status === 409 || response.status === 412) throw new SessionStoreError("SESSION_S3_CONFLICT", 409);
|
|
226
225
|
if (response.status !== 200) throw new SessionStoreError("SESSION_S3_REQUEST_FAILED");
|
|
227
|
-
|
|
228
|
-
if (typeof version !== "string" || !/^"[^"\r\n]+"$/.test(version)) throw new SessionStoreError("SESSION_S3_ETAG_REQUIRED");
|
|
229
|
-
return {
|
|
230
|
-
etag: version,
|
|
231
|
-
body: method === "GET" ? Buffer.from(response.data).toString("utf8") : body
|
|
232
|
-
};
|
|
226
|
+
return method === "GET" ? Buffer.from(response.data).toString("utf8") : body;
|
|
233
227
|
} catch (error) {
|
|
234
228
|
throw error instanceof SessionStoreError ? error : new SessionStoreError("SESSION_S3_REQUEST_FAILED");
|
|
235
229
|
}
|
|
236
230
|
};
|
|
237
|
-
const lockName = `${encodedFilename}.lock`;
|
|
238
|
-
const owner = (0, node_crypto.randomUUID)();
|
|
239
|
-
const previous = await request(lockName, "GET");
|
|
240
|
-
if (previous) {
|
|
241
|
-
let value;
|
|
242
|
-
try {
|
|
243
|
-
value = JSON.parse(previous.body);
|
|
244
|
-
} catch {
|
|
245
|
-
throw new SessionStoreError("SESSION_S3_LOCK_INVALID");
|
|
246
|
-
}
|
|
247
|
-
if (!value || value.owner !== null || typeof value.nonce !== "string") throw new SessionStoreError("SESSION_S3_LOCKED", 409);
|
|
248
|
-
}
|
|
249
|
-
const lock = await request(lockName, "PUT", JSON.stringify({
|
|
250
|
-
owner,
|
|
251
|
-
nonce: (0, node_crypto.randomUUID)()
|
|
252
|
-
}), previous?.etag ?? null);
|
|
253
|
-
if (!lock) throw new SessionStoreError("SESSION_S3_LOCK_FAILED");
|
|
254
231
|
let closed = false;
|
|
255
232
|
let busy = false;
|
|
256
233
|
let uncertain = false;
|
|
257
|
-
let
|
|
258
|
-
let current;
|
|
259
|
-
try {
|
|
260
|
-
current = await request(encodedFilename, "GET");
|
|
261
|
-
} catch (error) {
|
|
262
|
-
try {
|
|
263
|
-
await request(lockName, "PUT", JSON.stringify({
|
|
264
|
-
owner: null,
|
|
265
|
-
nonce: (0, node_crypto.randomUUID)()
|
|
266
|
-
}), lock.etag);
|
|
267
|
-
} catch {}
|
|
268
|
-
throw error;
|
|
269
|
-
}
|
|
234
|
+
let current = await request(encodedFilename, "GET");
|
|
270
235
|
const snapshot = () => ({
|
|
271
236
|
exists: current !== null,
|
|
272
|
-
payload: current === null || current
|
|
237
|
+
payload: current === null || current === "LOGGED OUT" || current.startsWith(logoutPrefix) ? null : current
|
|
273
238
|
});
|
|
274
239
|
const available = () => {
|
|
275
240
|
if (closed || uncertain) throw new SessionStoreError("SESSION_S3_CLOSED");
|
|
@@ -280,7 +245,7 @@ async function acquire(config, filename) {
|
|
|
280
245
|
if (typeof body !== "string" || Buffer.byteLength(body) > limit) throw new SessionStoreError("SESSION_S3_PAYLOAD_INVALID", 400);
|
|
281
246
|
busy = true;
|
|
282
247
|
try {
|
|
283
|
-
current = await request(encodedFilename, "PUT", body
|
|
248
|
+
current = await request(encodedFilename, "PUT", body);
|
|
284
249
|
} catch (error) {
|
|
285
250
|
uncertain = true;
|
|
286
251
|
throw error;
|
|
@@ -295,21 +260,8 @@ async function acquire(config, filename) {
|
|
|
295
260
|
},
|
|
296
261
|
write: replace,
|
|
297
262
|
remove: () => replace(`${logoutPrefix}${(0, node_crypto.randomUUID)()}`),
|
|
298
|
-
release: () => {
|
|
299
|
-
if (releaseResult) return releaseResult;
|
|
300
|
-
try {
|
|
301
|
-
available();
|
|
302
|
-
} catch (error) {
|
|
303
|
-
return Promise.reject(error);
|
|
304
|
-
}
|
|
263
|
+
release: async () => {
|
|
305
264
|
closed = true;
|
|
306
|
-
releaseResult = request(lockName, "PUT", JSON.stringify({
|
|
307
|
-
owner: null,
|
|
308
|
-
nonce: (0, node_crypto.randomUUID)()
|
|
309
|
-
}), lock.etag).then(() => void 0, () => {
|
|
310
|
-
throw new SessionStoreError("SESSION_S3_RELEASE_FAILED");
|
|
311
|
-
});
|
|
312
|
-
return releaseResult;
|
|
313
265
|
}
|
|
314
266
|
};
|
|
315
267
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-wa/session-sync",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.2",
|
|
4
4
|
"main": "dist/index.cjs",
|
|
5
5
|
"types": "dist/index.d.cts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@open-wa/schema": "5.6.
|
|
7
|
+
"@open-wa/schema": "5.6.2",
|
|
8
8
|
"chokidar": "^5.0.0",
|
|
9
9
|
"pico-s3": "^2.11.0",
|
|
10
10
|
"simple-zstd": "^2.1.0",
|