s3db.js 19.4.11 → 19.4.12
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/plugins/api/concerns/cookie-chunking.js +22 -1
- package/dist/plugins/api/index.js +3 -1
- package/dist/plugins/index.js +1 -1
- package/dist/s3db-lite.cjs +2 -2
- package/dist/s3db-lite.es.js +2 -2
- package/dist/s3db.cjs +172 -45
- package/dist/s3db.d.ts +2 -1
- package/dist/s3db.es.js +150 -24
- package/dist/types/plugins/api/concerns/cookie-chunking.d.ts +1 -0
- package/dist/types/plugins/api/index.d.ts +1 -1
- package/dist/types/plugins/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/plugins/api/concerns/cookie-chunking.ts +48 -8
- package/src/plugins/api/index.ts +3 -0
- package/src/plugins/index.ts +2 -1
|
@@ -1,6 +1,22 @@
|
|
|
1
|
-
import { generateCookie, getCookie, setCookie } from 'hono/cookie';
|
|
2
1
|
import { createLogger } from '../../../concerns/logger.js';
|
|
3
2
|
const logger = createLogger({ name: 'CookieChunking', level: 'info' });
|
|
3
|
+
let honoCookieModule = null;
|
|
4
|
+
async function getHonoCookie() {
|
|
5
|
+
if (!honoCookieModule) {
|
|
6
|
+
honoCookieModule = await import('hono/cookie');
|
|
7
|
+
}
|
|
8
|
+
return honoCookieModule;
|
|
9
|
+
}
|
|
10
|
+
function getHonoCookieSync() {
|
|
11
|
+
if (!honoCookieModule) {
|
|
12
|
+
throw new Error('[Cookie Chunking] Hono cookie module not initialized. ' +
|
|
13
|
+
'Call initCookieChunking() before using cookie functions.');
|
|
14
|
+
}
|
|
15
|
+
return honoCookieModule;
|
|
16
|
+
}
|
|
17
|
+
export async function initCookieChunking() {
|
|
18
|
+
await getHonoCookie();
|
|
19
|
+
}
|
|
4
20
|
const MAX_COOKIE_SIZE = 4000;
|
|
5
21
|
const MAX_CHUNKS = 10;
|
|
6
22
|
const CHUNK_SUFFIX_PATTERN = /^\d+$/;
|
|
@@ -19,6 +35,7 @@ function getEncodedLength(value) {
|
|
|
19
35
|
}
|
|
20
36
|
function getCookieJar(context) {
|
|
21
37
|
try {
|
|
38
|
+
const { getCookie } = getHonoCookieSync();
|
|
22
39
|
const cookies = getCookie(context);
|
|
23
40
|
if (cookies && typeof cookies === 'object' && !Array.isArray(cookies)) {
|
|
24
41
|
return cookies;
|
|
@@ -50,6 +67,7 @@ function getChunkEntriesFromJar(cookieJar, baseName) {
|
|
|
50
67
|
.sort((a, b) => a.index - b.index);
|
|
51
68
|
}
|
|
52
69
|
function calculateChunkSize(name, options) {
|
|
70
|
+
const { generateCookie } = getHonoCookieSync();
|
|
53
71
|
const sampleCookie = generateCookie(`${name}.0`, '', options);
|
|
54
72
|
const overhead = Buffer.byteLength(sampleCookie);
|
|
55
73
|
const chunkSize = MAX_COOKIE_SIZE - overhead;
|
|
@@ -106,6 +124,7 @@ export function setChunkedCookie(context, name, value, options = {}, chunkingOpt
|
|
|
106
124
|
deleteChunkedCookie(context, name, options);
|
|
107
125
|
return;
|
|
108
126
|
}
|
|
127
|
+
const { setCookie } = getHonoCookieSync();
|
|
109
128
|
const chunkSize = calculateChunkSize(name, options);
|
|
110
129
|
const encodedLength = getEncodedLength(value);
|
|
111
130
|
const requestCookies = getCookieJar(context);
|
|
@@ -184,6 +203,7 @@ export function getChunkedCookie(context, name, cookieJarOverride = null) {
|
|
|
184
203
|
return chunks.join('');
|
|
185
204
|
}
|
|
186
205
|
export function deleteChunkedCookie(context, name, options = {}, cookieJar = null) {
|
|
206
|
+
const { setCookie } = getHonoCookieSync();
|
|
187
207
|
const jar = cookieJar || getCookieJar(context);
|
|
188
208
|
const namesToDelete = new Set();
|
|
189
209
|
if (Object.prototype.hasOwnProperty.call(jar, name)) {
|
|
@@ -206,6 +226,7 @@ export function deleteChunkedCookie(context, name, options = {}, cookieJar = nul
|
|
|
206
226
|
});
|
|
207
227
|
}
|
|
208
228
|
export function isChunkedCookie(context, name) {
|
|
229
|
+
const { getCookie } = getHonoCookieSync();
|
|
209
230
|
return !!getCookie(context, `${name}.__chunks`);
|
|
210
231
|
}
|
|
211
232
|
//# sourceMappingURL=cookie-chunking.js.map
|
|
@@ -48,6 +48,7 @@ import { createIdentityContextMiddleware } from './middleware/identity.js';
|
|
|
48
48
|
import { createLoggingMiddleware } from './middleware/logging.js';
|
|
49
49
|
import { createRateLimitMiddleware } from './middleware/rate-limit.js';
|
|
50
50
|
import { createSecurityMiddleware } from './middleware/security.js';
|
|
51
|
+
import { initCookieChunking } from './concerns/cookie-chunking.js';
|
|
51
52
|
const BASE_USER_ATTRIBUTES = {
|
|
52
53
|
id: 'string|optional',
|
|
53
54
|
username: 'string|required|minlength:3',
|
|
@@ -256,6 +257,7 @@ export class ApiPlugin extends Plugin {
|
|
|
256
257
|
throwOnError: true,
|
|
257
258
|
checkVersions: true
|
|
258
259
|
});
|
|
260
|
+
await initCookieChunking();
|
|
259
261
|
}
|
|
260
262
|
async onInstall() {
|
|
261
263
|
if (this.config.logLevel) {
|
|
@@ -498,5 +500,5 @@ export { RouteContext, withContext } from './concerns/route-context.js';
|
|
|
498
500
|
export { errorResponse, successResponse } from './utils/route-helper.js';
|
|
499
501
|
export { createContextInjectionMiddleware } from './middlewares/context-injection.js';
|
|
500
502
|
export { HttpBadRequestError, HttpValidationError, HttpUnauthorizedError, HttpForbiddenError, HttpNotFoundError, HttpMethodNotAllowedError, HttpConflictError, HttpUnprocessableEntityError, HttpTooManyRequestsError, HttpInternalServerError, HttpNotImplementedError, HttpServiceUnavailableError, HTTP_ERRORS, createHttpError } from './errors.js';
|
|
501
|
-
export { getChunkedCookie, setChunkedCookie, deleteChunkedCookie, isChunkedCookie, CookieChunkOverflowError } from './concerns/cookie-chunking.js';
|
|
503
|
+
export { getChunkedCookie, setChunkedCookie, deleteChunkedCookie, isChunkedCookie, initCookieChunking, CookieChunkOverflowError } from './concerns/cookie-chunking.js';
|
|
502
504
|
//# sourceMappingURL=index.js.map
|
package/dist/plugins/index.js
CHANGED
|
@@ -85,7 +85,7 @@ export { GeoPlugin } from './geo.plugin.js';
|
|
|
85
85
|
export { ReplicatorPlugin } from './replicator.plugin.js';
|
|
86
86
|
export { QueueConsumerPlugin } from './queue-consumer.plugin.js';
|
|
87
87
|
export { WebSocketPlugin, WebSocketServer } from './websocket/index.js';
|
|
88
|
-
export { OIDCClient, setupTemplateEngine, ejsEngine, pugEngine, jsxEngine, OpenGraphHelper, RouteContext, withContext, errorResponse, successResponse, createContextInjectionMiddleware, getChunkedCookie, setChunkedCookie, deleteChunkedCookie, isChunkedCookie } from './api/index.js';
|
|
88
|
+
export { OIDCClient, setupTemplateEngine, ejsEngine, pugEngine, jsxEngine, OpenGraphHelper, RouteContext, withContext, errorResponse, successResponse, createContextInjectionMiddleware, getChunkedCookie, setChunkedCookie, deleteChunkedCookie, isChunkedCookie, initCookieChunking } from './api/index.js';
|
|
89
89
|
export { HttpBadRequestError, HttpValidationError, HttpUnauthorizedError, HttpForbiddenError, HttpNotFoundError, HttpMethodNotAllowedError, HttpConflictError, HttpUnprocessableEntityError, HttpTooManyRequestsError, HttpInternalServerError, HttpNotImplementedError, HttpServiceUnavailableError, HTTP_ERRORS, createHttpError } from './api/errors.js';
|
|
90
90
|
export { NotificationStateMachine, AttemptStateMachine, createNotificationStateMachine, createAttemptStateMachine } from './api/concerns/state-machine.js';
|
|
91
91
|
//# sourceMappingURL=index.js.map
|
package/dist/s3db-lite.cjs
CHANGED
|
@@ -70660,8 +70660,8 @@ class Database extends SafeEventEmitter {
|
|
|
70660
70660
|
})();
|
|
70661
70661
|
this.version = '1';
|
|
70662
70662
|
this.s3dbVersion = (() => {
|
|
70663
|
-
const [ok, , version] = tryFnSync(() => (typeof globalThis['19.4.
|
|
70664
|
-
? globalThis['19.4.
|
|
70663
|
+
const [ok, , version] = tryFnSync(() => (typeof globalThis['19.4.12'] !== 'undefined' && globalThis['19.4.12'] !== '19.4.12'
|
|
70664
|
+
? globalThis['19.4.12']
|
|
70665
70665
|
: 'latest'));
|
|
70666
70666
|
return ok ? version : 'latest';
|
|
70667
70667
|
})();
|
package/dist/s3db-lite.es.js
CHANGED
|
@@ -70637,8 +70637,8 @@ class Database extends SafeEventEmitter {
|
|
|
70637
70637
|
})();
|
|
70638
70638
|
this.version = '1';
|
|
70639
70639
|
this.s3dbVersion = (() => {
|
|
70640
|
-
const [ok, , version] = tryFnSync(() => (typeof globalThis['19.4.
|
|
70641
|
-
? globalThis['19.4.
|
|
70640
|
+
const [ok, , version] = tryFnSync(() => (typeof globalThis['19.4.12'] !== 'undefined' && globalThis['19.4.12'] !== '19.4.12'
|
|
70641
|
+
? globalThis['19.4.12']
|
|
70642
70642
|
: 'latest'));
|
|
70643
70643
|
return ok ? version : 'latest';
|
|
70644
70644
|
})();
|