@carlonicora/nextjs-jsonapi 6.13.1 → 6.14.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.
- package/dist/{BlockNoteEditor-UBVEUFNR.js → BlockNoteEditor-CUNH4LSQ.js} +25 -25
- package/dist/{BlockNoteEditor-UBVEUFNR.js.map → BlockNoteEditor-CUNH4LSQ.js.map} +1 -1
- package/dist/{BlockNoteEditor-VXMDSQAA.mjs → BlockNoteEditor-QIVV2OB4.mjs} +10 -10
- package/dist/{BlockNoteViewer-2XYASA5Y.js → BlockNoteViewer-APBOPT4B.js} +8 -8
- package/dist/{BlockNoteViewer-2XYASA5Y.js.map → BlockNoteViewer-APBOPT4B.js.map} +1 -1
- package/dist/{BlockNoteViewer-NBW2H6LC.mjs → BlockNoteViewer-HIUAJQRI.mjs} +7 -7
- package/dist/JsonApiRequest-G4J2WTSU.js +26 -0
- package/dist/{JsonApiRequest-WISJZSDE.js.map → JsonApiRequest-G4J2WTSU.js.map} +1 -1
- package/dist/{JsonApiRequest-F6TMJ42G.mjs → JsonApiRequest-IKKHWCPB.mjs} +2 -2
- package/dist/billing/index.js +497 -497
- package/dist/billing/index.mjs +9 -9
- package/dist/{chunk-7DBJTNSU.mjs → chunk-4RPGFQBA.mjs} +2 -2
- package/dist/{chunk-BZ5J2FIV.js → chunk-4XLDBOSE.js} +11 -11
- package/dist/{chunk-BZ5J2FIV.js.map → chunk-4XLDBOSE.js.map} +1 -1
- package/dist/{chunk-27LQDGNP.mjs → chunk-4ZJIUTIV.mjs} +6 -1
- package/dist/chunk-4ZJIUTIV.mjs.map +1 -0
- package/dist/{chunk-PXDUJ47N.js → chunk-6RCZ64BQ.js} +18 -18
- package/dist/{chunk-PXDUJ47N.js.map → chunk-6RCZ64BQ.js.map} +1 -1
- package/dist/{chunk-7JZHPMGW.mjs → chunk-A3RB47X4.mjs} +44 -20
- package/dist/chunk-A3RB47X4.mjs.map +1 -0
- package/dist/{chunk-DOCIFE6A.mjs → chunk-AUD6ZLBB.mjs} +3 -3
- package/dist/{chunk-GB6DBFYY.js → chunk-DGN3PR2F.js} +3 -3
- package/dist/{chunk-GB6DBFYY.js.map → chunk-DGN3PR2F.js.map} +1 -1
- package/dist/{chunk-7ZHTPFFT.js → chunk-DJXSCARG.js} +15 -15
- package/dist/{chunk-7ZHTPFFT.js.map → chunk-DJXSCARG.js.map} +1 -1
- package/dist/{chunk-QKNGZDSQ.js → chunk-GM4VZTWL.js} +2 -2
- package/dist/{chunk-QKNGZDSQ.js.map → chunk-GM4VZTWL.js.map} +1 -1
- package/dist/{chunk-PYRZCKC2.js → chunk-GSRTVIIK.js} +923 -923
- package/dist/{chunk-PYRZCKC2.js.map → chunk-GSRTVIIK.js.map} +1 -1
- package/dist/{chunk-47BBY5KA.mjs → chunk-HAW5PNJG.mjs} +4 -4
- package/dist/{chunk-YRKIFYOE.mjs → chunk-KTGKW72G.mjs} +27 -8
- package/dist/chunk-KTGKW72G.mjs.map +1 -0
- package/dist/{chunk-PV4Z5W6V.js → chunk-KV4N7DEG.js} +19 -19
- package/dist/{chunk-PV4Z5W6V.js.map → chunk-KV4N7DEG.js.map} +1 -1
- package/dist/{chunk-ZLTOUZN2.mjs → chunk-M3N7LPHX.mjs} +4 -4
- package/dist/{chunk-DGWOVYEC.mjs → chunk-MQ7TXALH.mjs} +2 -2
- package/dist/{chunk-W62MHDWM.js → chunk-N5ZE2Z6I.js} +58 -34
- package/dist/chunk-N5ZE2Z6I.js.map +1 -0
- package/dist/{chunk-2SV4SS6N.js → chunk-OQQ7CZWT.js} +12 -12
- package/dist/{chunk-2SV4SS6N.js.map → chunk-OQQ7CZWT.js.map} +1 -1
- package/dist/{chunk-JJMMT24D.mjs → chunk-OUEYZOLB.mjs} +2 -2
- package/dist/{chunk-XXP3TQHF.mjs → chunk-OY65RYD3.mjs} +2 -2
- package/dist/{chunk-MOGEGWXW.js → chunk-PMESKNKL.js} +868 -868
- package/dist/{chunk-MOGEGWXW.js.map → chunk-PMESKNKL.js.map} +1 -1
- package/dist/{chunk-B6JGKDP2.js → chunk-QGVVF77L.js} +48 -29
- package/dist/chunk-QGVVF77L.js.map +1 -0
- package/dist/{chunk-BH6JWIKI.mjs → chunk-QIEF7HIL.mjs} +2 -2
- package/dist/{chunk-P445QGOC.mjs → chunk-RFKSJIQB.mjs} +7 -7
- package/dist/{chunk-6JUCIWDC.mjs → chunk-UOTHRJD2.mjs} +2 -2
- package/dist/{chunk-KMW7UNL2.js → chunk-WCEYT3GG.js} +8 -8
- package/dist/{chunk-KMW7UNL2.js.map → chunk-WCEYT3GG.js.map} +1 -1
- package/dist/{chunk-MHB36MYE.js → chunk-WUNSG3IN.js} +7 -2
- package/dist/chunk-WUNSG3IN.js.map +1 -0
- package/dist/{chunk-N4RZZKL5.mjs → chunk-YKNULEHB.mjs} +12 -12
- package/dist/{chunk-Z4POQWFG.js → chunk-ZYSNJKOP.js} +4 -4
- package/dist/{chunk-Z4POQWFG.js.map → chunk-ZYSNJKOP.js.map} +1 -1
- package/dist/client/index.js +10 -10
- package/dist/client/index.mjs +9 -9
- package/dist/components/index.js +10 -10
- package/dist/components/index.mjs +9 -9
- package/dist/contexts/index.js +10 -10
- package/dist/contexts/index.mjs +9 -9
- package/dist/core/index.js +7 -7
- package/dist/core/index.mjs +6 -6
- package/dist/email-automations/index.js +99 -99
- package/dist/email-automations/index.mjs +9 -9
- package/dist/features/analytics/index.js +126 -126
- package/dist/features/analytics/index.mjs +9 -9
- package/dist/features/analytics/server.js +10 -10
- package/dist/features/analytics/server.mjs +8 -8
- package/dist/features/blog/index.js +156 -156
- package/dist/features/blog/index.mjs +9 -9
- package/dist/features/blog/server.js +28 -28
- package/dist/features/blog/server.mjs +7 -7
- package/dist/features/help/index.js +43 -43
- package/dist/features/help/index.mjs +9 -9
- package/dist/features/tokenusage/index.js +132 -132
- package/dist/features/tokenusage/index.mjs +9 -9
- package/dist/index.js +8 -8
- package/dist/index.mjs +7 -7
- package/dist/{lifecycle-LKGPRBS7.mjs → lifecycle-KI3PCJSE.mjs} +3 -3
- package/dist/lifecycle-TO65I7TO.js +23 -0
- package/dist/{lifecycle-4GUOTB46.js.map → lifecycle-TO65I7TO.js.map} +1 -1
- package/dist/local-transport-4YDJ6FQG.js +15 -0
- package/dist/{local-transport-7H3SPZSA.js.map → local-transport-4YDJ6FQG.js.map} +1 -1
- package/dist/local-transport-C7YTA4I7.mjs +15 -0
- package/dist/offline/index.d.mts +160 -4
- package/dist/offline/index.d.ts +160 -4
- package/dist/offline/index.js +210 -163
- package/dist/offline/index.js.map +1 -1
- package/dist/offline/index.mjs +76 -29
- package/dist/offline/index.mjs.map +1 -1
- package/dist/request-66FGJIHB.mjs +10 -0
- package/dist/request-6W6UGKJV.js +10 -0
- package/dist/{request-KTBV6HHH.js.map → request-6W6UGKJV.js.map} +1 -1
- package/dist/server/index.js +9 -9
- package/dist/server/index.mjs +8 -8
- package/dist/write-through-BAPS24GL.js +15 -0
- package/dist/{write-through-FDQ7N4YI.js.map → write-through-BAPS24GL.js.map} +1 -1
- package/dist/write-through-IWQKXYHE.mjs +15 -0
- package/package.json +1 -1
- package/src/offline/__tests__/generic-answers.spec.ts +146 -3
- package/src/offline/__tests__/local-transport.spec.ts +15 -1
- package/src/offline/__tests__/offline-fixtures.ts +29 -2
- package/src/offline/__tests__/write-through.spec.ts +27 -1
- package/src/offline/config.ts +9 -0
- package/src/offline/generic-answers.ts +44 -17
- package/src/offline/index.ts +2 -0
- package/src/offline/local-transport.ts +5 -3
- package/src/offline/sync/__tests__/runtime.spec.ts +30 -1
- package/src/offline/sync/__tests__/sync-fixtures.ts +22 -0
- package/src/offline/sync/__tests__/sync-root.spec.ts +184 -1
- package/src/offline/sync/known-roots.ts +29 -7
- package/src/offline/sync/runtime.ts +3 -2
- package/src/offline/sync/sync-root.ts +70 -19
- package/src/offline/types.ts +39 -1
- package/src/offline/write-through.ts +6 -3
- package/dist/JsonApiRequest-WISJZSDE.js +0 -26
- package/dist/chunk-27LQDGNP.mjs.map +0 -1
- package/dist/chunk-7JZHPMGW.mjs.map +0 -1
- package/dist/chunk-B6JGKDP2.js.map +0 -1
- package/dist/chunk-MHB36MYE.js.map +0 -1
- package/dist/chunk-W62MHDWM.js.map +0 -1
- package/dist/chunk-YRKIFYOE.mjs.map +0 -1
- package/dist/lifecycle-4GUOTB46.js +0 -23
- package/dist/local-transport-7H3SPZSA.js +0 -15
- package/dist/local-transport-QYFKA6AN.mjs +0 -15
- package/dist/request-KTBV6HHH.js +0 -10
- package/dist/request-SQOUNWZ4.mjs +0 -10
- package/dist/write-through-FDQ7N4YI.js +0 -15
- package/dist/write-through-R25VQMH6.mjs +0 -15
- /package/dist/{BlockNoteEditor-VXMDSQAA.mjs.map → BlockNoteEditor-QIVV2OB4.mjs.map} +0 -0
- /package/dist/{BlockNoteViewer-NBW2H6LC.mjs.map → BlockNoteViewer-HIUAJQRI.mjs.map} +0 -0
- /package/dist/{JsonApiRequest-F6TMJ42G.mjs.map → JsonApiRequest-IKKHWCPB.mjs.map} +0 -0
- /package/dist/{chunk-7DBJTNSU.mjs.map → chunk-4RPGFQBA.mjs.map} +0 -0
- /package/dist/{chunk-DOCIFE6A.mjs.map → chunk-AUD6ZLBB.mjs.map} +0 -0
- /package/dist/{chunk-47BBY5KA.mjs.map → chunk-HAW5PNJG.mjs.map} +0 -0
- /package/dist/{chunk-ZLTOUZN2.mjs.map → chunk-M3N7LPHX.mjs.map} +0 -0
- /package/dist/{chunk-DGWOVYEC.mjs.map → chunk-MQ7TXALH.mjs.map} +0 -0
- /package/dist/{chunk-JJMMT24D.mjs.map → chunk-OUEYZOLB.mjs.map} +0 -0
- /package/dist/{chunk-XXP3TQHF.mjs.map → chunk-OY65RYD3.mjs.map} +0 -0
- /package/dist/{chunk-BH6JWIKI.mjs.map → chunk-QIEF7HIL.mjs.map} +0 -0
- /package/dist/{chunk-P445QGOC.mjs.map → chunk-RFKSJIQB.mjs.map} +0 -0
- /package/dist/{chunk-6JUCIWDC.mjs.map → chunk-UOTHRJD2.mjs.map} +0 -0
- /package/dist/{chunk-N4RZZKL5.mjs.map → chunk-YKNULEHB.mjs.map} +0 -0
- /package/dist/{lifecycle-LKGPRBS7.mjs.map → lifecycle-KI3PCJSE.mjs.map} +0 -0
- /package/dist/{local-transport-QYFKA6AN.mjs.map → local-transport-C7YTA4I7.mjs.map} +0 -0
- /package/dist/{request-SQOUNWZ4.mjs.map → request-66FGJIHB.mjs.map} +0 -0
- /package/dist/{write-through-R25VQMH6.mjs.map → write-through-IWQKXYHE.mjs.map} +0 -0
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkKV4N7DEGjs = require('./chunk-KV4N7DEG.js');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var _chunkMHB36MYEjs = require('./chunk-MHB36MYE.js');
|
|
12
11
|
|
|
12
|
+
var _chunkWUNSG3INjs = require('./chunk-WUNSG3IN.js');
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
var _chunkGM4VZTWLjs = require('./chunk-GM4VZTWL.js');
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
var _chunk7QVYU63Ejs = require('./chunk-7QVYU63E.js');
|
|
@@ -38,7 +39,7 @@ async function singleAnswer(store, record, status = 200) {
|
|
|
38
39
|
}
|
|
39
40
|
_chunk7QVYU63Ejs.__name.call(void 0, singleAnswer, "singleAnswer");
|
|
40
41
|
function isRootWriteLocked(rootId) {
|
|
41
|
-
return !!rootId &&
|
|
42
|
+
return !!rootId && _chunkWUNSG3INjs.getOfflineState.call(void 0, ).lockedRootIds.includes(rootId);
|
|
42
43
|
}
|
|
43
44
|
_chunk7QVYU63Ejs.__name.call(void 0, isRootWriteLocked, "isRootWriteLocked");
|
|
44
45
|
function identifiersOf(relationship) {
|
|
@@ -90,8 +91,8 @@ async function includedFor(store, records) {
|
|
|
90
91
|
_chunk7QVYU63Ejs.__name.call(void 0, includedFor, "includedFor");
|
|
91
92
|
function signedInUserResource(target) {
|
|
92
93
|
try {
|
|
93
|
-
if (target.id !==
|
|
94
|
-
const stored = JSON.parse(_nullishCoalesce(window.localStorage.getItem(
|
|
94
|
+
if (target.id !== _chunkWUNSG3INjs.getOfflineConfig.call(void 0, ).getUserId()) return void 0;
|
|
95
|
+
const stored = JSON.parse(_nullishCoalesce(window.localStorage.getItem(_chunkKV4N7DEGjs.CURRENT_USER_STORAGE_KEY), () => ( "null")));
|
|
95
96
|
const user = _optionalChain([stored, 'optionalAccess', _7 => _7.jsonApi]);
|
|
96
97
|
if (_optionalChain([user, 'optionalAccess', _8 => _8.type]) !== target.type || _optionalChain([user, 'optionalAccess', _9 => _9.id]) !== target.id) return void 0;
|
|
97
98
|
return { type: user.type, id: user.id, attributes: _nullishCoalesce(user.attributes, () => ( {})), meta: user.meta };
|
|
@@ -277,8 +278,8 @@ async function getOne(ctx, type) {
|
|
|
277
278
|
return singleAnswer(ctx.store, record);
|
|
278
279
|
}
|
|
279
280
|
_chunk7QVYU63Ejs.__name.call(void 0, getOne, "getOne");
|
|
280
|
-
async function rootList(ctx,
|
|
281
|
-
const rootType =
|
|
281
|
+
async function rootList(ctx, kind, typeConfig) {
|
|
282
|
+
const rootType = kind.module.name;
|
|
282
283
|
const rootId = ctx.params.rootId;
|
|
283
284
|
if (!await ctx.store.getRecord(rootType, rootId)) return notOnDeviceAnswer(rootType, rootId);
|
|
284
285
|
const records = await ctx.store.listRecords({ type: typeConfig.module.name, rootId });
|
|
@@ -320,10 +321,10 @@ async function relatedList(ctx, config, typeConfig) {
|
|
|
320
321
|
}
|
|
321
322
|
_chunk7QVYU63Ejs.__name.call(void 0, relatedList, "relatedList");
|
|
322
323
|
async function rootIdForResource(store, config, resource) {
|
|
323
|
-
const
|
|
324
|
-
if (_optionalChain([resource, 'optionalAccess', _30 => _30.type])
|
|
324
|
+
const rootTypes = new Set(_chunkWUNSG3INjs.rootKinds.call(void 0, config).map((kind) => kind.module.name));
|
|
325
|
+
if (rootTypes.has(_optionalChain([resource, 'optionalAccess', _30 => _30.type])) && resource.id) return resource.id;
|
|
325
326
|
const identifiers = Object.values(_nullishCoalesce(_optionalChain([resource, 'optionalAccess', _31 => _31.relationships]), () => ( {}))).flatMap(identifiersOf);
|
|
326
|
-
const root = identifiers.find((identifier) => identifier.type
|
|
327
|
+
const root = identifiers.find((identifier) => rootTypes.has(identifier.type));
|
|
327
328
|
if (root) return root.id;
|
|
328
329
|
for (const identifier of identifiers) {
|
|
329
330
|
const stored = await store.getRecord(identifier.type, identifier.id);
|
|
@@ -405,6 +406,16 @@ async function create(ctx, config, type) {
|
|
|
405
406
|
body: ctx.request.body,
|
|
406
407
|
base: null
|
|
407
408
|
});
|
|
409
|
+
if (_optionalChain([typeConfig, 'optionalAccess', _41 => _41.afterLocalWrite])) {
|
|
410
|
+
await typeConfig.afterLocalWrite({
|
|
411
|
+
store,
|
|
412
|
+
module: typeConfig.module,
|
|
413
|
+
id,
|
|
414
|
+
method: "POST",
|
|
415
|
+
resource,
|
|
416
|
+
previous: null
|
|
417
|
+
});
|
|
418
|
+
}
|
|
408
419
|
});
|
|
409
420
|
return singleAnswer(ctx.store, record, 201);
|
|
410
421
|
}
|
|
@@ -414,20 +425,16 @@ async function update(ctx, config, type) {
|
|
|
414
425
|
const existing = await ctx.store.getRecord(type, id);
|
|
415
426
|
if (!existing) return notOnDeviceAnswer(type, id);
|
|
416
427
|
if (isRootWriteLocked(existing.rootId)) return needsConnectionAnswer("The root record is locked");
|
|
417
|
-
const data = _nullishCoalesce(_optionalChain([ctx, 'access',
|
|
428
|
+
const data = _nullishCoalesce(_optionalChain([ctx, 'access', _42 => _42.request, 'access', _43 => _43.body, 'optionalAccess', _44 => _44.data]), () => ( {}));
|
|
418
429
|
const before = _nullishCoalesce(existing.resource, () => ( { type, id }));
|
|
419
430
|
const resource = mergeResource(before, { type, id }, data);
|
|
420
431
|
const base = existing.localOnly ? null : _nullishCoalesce(existing.base, () => ( before));
|
|
432
|
+
const typeConfig = typeConfigOf(config, type);
|
|
433
|
+
const method = ctx.request.method === "PATCH" ? "PATCH" : "PUT";
|
|
421
434
|
const record = { ...existing, resource, base, localOnly: existing.localOnly };
|
|
422
435
|
await ctx.store.transaction(async (store) => {
|
|
423
436
|
await store.putRecord(record);
|
|
424
|
-
await linkRelationships(
|
|
425
|
-
store,
|
|
426
|
-
typeConfigOf(config, type),
|
|
427
|
-
{ type, id },
|
|
428
|
-
_nullishCoalesce(before.relationships, () => ( {})),
|
|
429
|
-
_nullishCoalesce(data.relationships, () => ( {}))
|
|
430
|
-
);
|
|
437
|
+
await linkRelationships(store, typeConfig, { type, id }, _nullishCoalesce(before.relationships, () => ( {})), _nullishCoalesce(data.relationships, () => ( {})));
|
|
431
438
|
await store.enqueue({
|
|
432
439
|
rootId: existing.rootId,
|
|
433
440
|
method: ctx.request.method,
|
|
@@ -437,11 +444,14 @@ async function update(ctx, config, type) {
|
|
|
437
444
|
recordId: id,
|
|
438
445
|
base
|
|
439
446
|
});
|
|
447
|
+
if (_optionalChain([typeConfig, 'optionalAccess', _45 => _45.afterLocalWrite])) {
|
|
448
|
+
await typeConfig.afterLocalWrite({ store, module: typeConfig.module, id, method, resource, previous: before });
|
|
449
|
+
}
|
|
440
450
|
});
|
|
441
451
|
return singleAnswer(ctx.store, record);
|
|
442
452
|
}
|
|
443
453
|
_chunk7QVYU63Ejs.__name.call(void 0, update, "update");
|
|
444
|
-
async function remove(ctx, type) {
|
|
454
|
+
async function remove(ctx, config, type) {
|
|
445
455
|
const id = ctx.params.id;
|
|
446
456
|
const existing = await ctx.store.getRecord(type, id);
|
|
447
457
|
if (!existing) return notOnDeviceAnswer(type, id);
|
|
@@ -459,6 +469,17 @@ async function remove(ctx, type) {
|
|
|
459
469
|
recordId: id,
|
|
460
470
|
base
|
|
461
471
|
});
|
|
472
|
+
const typeConfig = typeConfigOf(config, type);
|
|
473
|
+
if (_optionalChain([typeConfig, 'optionalAccess', _46 => _46.afterLocalWrite])) {
|
|
474
|
+
await typeConfig.afterLocalWrite({
|
|
475
|
+
store,
|
|
476
|
+
module: typeConfig.module,
|
|
477
|
+
id,
|
|
478
|
+
method: "DELETE",
|
|
479
|
+
resource: null,
|
|
480
|
+
previous: existing.resource
|
|
481
|
+
});
|
|
482
|
+
}
|
|
462
483
|
});
|
|
463
484
|
return { status: 204, body: void 0 };
|
|
464
485
|
}
|
|
@@ -478,7 +499,9 @@ function buildGenericRoutes(config) {
|
|
|
478
499
|
for (const typeConfig of config.types) {
|
|
479
500
|
const type = typeConfig.module.name;
|
|
480
501
|
route("GET", [typeConfig.module, ":id"], (ctx) => getOne(ctx, type));
|
|
481
|
-
|
|
502
|
+
for (const kind of _chunkWUNSG3INjs.rootKinds.call(void 0, config)) {
|
|
503
|
+
route("GET", [kind.module, ":rootId", typeConfig.module], (ctx) => rootList(ctx, kind, typeConfig));
|
|
504
|
+
}
|
|
482
505
|
route(
|
|
483
506
|
"POST",
|
|
484
507
|
[typeConfig.module],
|
|
@@ -497,7 +520,7 @@ function buildGenericRoutes(config) {
|
|
|
497
520
|
route(
|
|
498
521
|
"DELETE",
|
|
499
522
|
[typeConfig.module, ":id"],
|
|
500
|
-
readOnlyGuard(typeConfig, (ctx) => remove(ctx, type))
|
|
523
|
+
readOnlyGuard(typeConfig, (ctx) => remove(ctx, config, type))
|
|
501
524
|
);
|
|
502
525
|
}
|
|
503
526
|
for (const typeConfig of config.types) {
|
|
@@ -548,7 +571,7 @@ _chunk7QVYU63Ejs.__name.call(void 0, matchRoute, "matchRoute");
|
|
|
548
571
|
var METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
549
572
|
function apiBases() {
|
|
550
573
|
const bases = [];
|
|
551
|
-
for (const read of [
|
|
574
|
+
for (const read of [_chunkGM4VZTWLjs.getApiUrl, _chunkKV4N7DEGjs.getClientApiUrl]) {
|
|
552
575
|
try {
|
|
553
576
|
const base = read();
|
|
554
577
|
if (base) bases.push(base);
|
|
@@ -592,20 +615,20 @@ function toApiData(answer) {
|
|
|
592
615
|
}
|
|
593
616
|
_chunk7QVYU63Ejs.__name.call(void 0, toApiData, "toApiData");
|
|
594
617
|
async function rootIdForCustomWrite(store, pattern, params, rootSegmentParam) {
|
|
595
|
-
const config =
|
|
618
|
+
const config = _chunkWUNSG3INjs.getOfflineConfig.call(void 0, );
|
|
596
619
|
if (rootSegmentParam && params[rootSegmentParam]) return params[rootSegmentParam];
|
|
597
620
|
for (const value of Object.values(params)) {
|
|
598
621
|
for (const typeConfig of config.types) {
|
|
599
622
|
const stored = await store.getRecord(typeConfig.module.name, value);
|
|
600
|
-
if (_optionalChain([stored, 'optionalAccess',
|
|
623
|
+
if (_optionalChain([stored, 'optionalAccess', _47 => _47.rootId])) return stored.rootId;
|
|
601
624
|
}
|
|
602
625
|
}
|
|
603
|
-
return rootIdForResource(store, config, _optionalChain([pattern, 'access',
|
|
626
|
+
return rootIdForResource(store, config, _optionalChain([pattern, 'access', _48 => _48.body, 'optionalAccess', _49 => _49.data]));
|
|
604
627
|
}
|
|
605
628
|
_chunk7QVYU63Ejs.__name.call(void 0, rootIdForCustomWrite, "rootIdForCustomWrite");
|
|
606
629
|
async function refreshPendingCount(store) {
|
|
607
630
|
const entries = await store.queue();
|
|
608
|
-
|
|
631
|
+
_chunkWUNSG3INjs.setOfflineState.call(void 0, { pending: entries.filter((entry) => entry.status !== "conflict").length });
|
|
609
632
|
}
|
|
610
633
|
_chunk7QVYU63Ejs.__name.call(void 0, refreshPendingCount, "refreshPendingCount");
|
|
611
634
|
async function localTransport(request) {
|
|
@@ -613,7 +636,7 @@ async function localTransport(request) {
|
|
|
613
636
|
const method = request.method.toUpperCase();
|
|
614
637
|
if (!METHODS.includes(method)) return toApiData(needsConnectionAnswer());
|
|
615
638
|
if (request.files) return toApiData(needsConnectionAnswer("Uploading files needs a connection"));
|
|
616
|
-
const config =
|
|
639
|
+
const config = _chunkWUNSG3INjs.getOfflineConfig.call(void 0, );
|
|
617
640
|
const { path, query } = splitApiUrl(request.url);
|
|
618
641
|
const offlineRequest = { method, path, query, body: request.body, url: request.url };
|
|
619
642
|
const custom = matchRoute(config.routes, method, path);
|
|
@@ -621,16 +644,17 @@ async function localTransport(request) {
|
|
|
621
644
|
if (!match) return toApiData(needsConnectionAnswer(`${method} ${path} has no offline answer`));
|
|
622
645
|
let store;
|
|
623
646
|
try {
|
|
624
|
-
store = await
|
|
647
|
+
store = await _chunkWUNSG3INjs.getOfflineStore.call(void 0, );
|
|
625
648
|
} catch (error) {
|
|
626
|
-
if (error instanceof
|
|
649
|
+
if (error instanceof _chunkWUNSG3INjs.NeedsConnectionError) return toApiData(needsConnectionAnswer(error.message));
|
|
627
650
|
console.warn("[offline] the device copy could not be opened", error);
|
|
628
651
|
return toApiData(needsConnectionAnswer("The device copy is not available in this tab"));
|
|
629
652
|
}
|
|
630
653
|
const ctx = { request: offlineRequest, params: match.params, store };
|
|
654
|
+
const rootTypes = new Set(_chunkWUNSG3INjs.rootKinds.call(void 0, config).map((kind) => kind.module.name));
|
|
631
655
|
const customRootId = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, async (route) => {
|
|
632
656
|
const rootIndex = route.pattern.findIndex(
|
|
633
|
-
(segment) => typeof segment !== "string" && segment.name
|
|
657
|
+
(segment) => typeof segment !== "string" && rootTypes.has(segment.name)
|
|
634
658
|
);
|
|
635
659
|
const next = rootIndex >= 0 ? route.pattern[rootIndex + 1] : void 0;
|
|
636
660
|
const rootParam = typeof next === "string" && next.startsWith(":") ? next.slice(1) : void 0;
|
|
@@ -666,12 +690,12 @@ async function localTransport(request) {
|
|
|
666
690
|
await refreshPendingCount(store);
|
|
667
691
|
return toApiData(answer);
|
|
668
692
|
} catch (error) {
|
|
669
|
-
if (error instanceof
|
|
693
|
+
if (error instanceof _chunkWUNSG3INjs.NeedsConnectionError) return toApiData(needsConnectionAnswer(error.message));
|
|
670
694
|
console.error("[offline] local answer failed", error);
|
|
671
695
|
return toApiData({
|
|
672
696
|
status: 500,
|
|
673
697
|
body: {
|
|
674
|
-
errors: [{ status: "500", title: "Offline answer failed", detail: String(_nullishCoalesce(_optionalChain([error, 'optionalAccess',
|
|
698
|
+
errors: [{ status: "500", title: "Offline answer failed", detail: String(_nullishCoalesce(_optionalChain([error, 'optionalAccess', _50 => _50.message]), () => ( error))) }]
|
|
675
699
|
}
|
|
676
700
|
});
|
|
677
701
|
}
|
|
@@ -701,4 +725,4 @@ _chunk7QVYU63Ejs.__name.call(void 0, localTransport, "localTransport");
|
|
|
701
725
|
|
|
702
726
|
|
|
703
727
|
exports.errorAnswer = errorAnswer; exports.needsConnectionAnswer = needsConnectionAnswer; exports.notFoundAnswer = notFoundAnswer; exports.singleAnswer = singleAnswer; exports.includedFor = includedFor; exports.SERVER_DEFAULT_ORDER_BY = SERVER_DEFAULT_ORDER_BY; exports.searchRecords = searchRecords; exports.orderRecords = orderRecords; exports.listAnswer = listAnswer; exports.orderedListAnswer = orderedListAnswer; exports.resourceListAnswer = resourceListAnswer; exports.linkKindFor = linkKindFor; exports.linkKindsOf = linkKindsOf; exports.linksOfKind = linksOfKind; exports.rootIdForResource = rootIdForResource; exports.resourceFromDocument = resourceFromDocument; exports.mergeResource = mergeResource; exports.matchPattern = matchPattern; exports.matchRoute = matchRoute; exports.splitApiUrl = splitApiUrl; exports.localTransport = localTransport;
|
|
704
|
-
//# sourceMappingURL=chunk-
|
|
728
|
+
//# sourceMappingURL=chunk-N5ZE2Z6I.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/chunk-N5ZE2Z6I.js","../src/offline/generic-answers.ts","../src/offline/router.ts","../src/offline/local-transport.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,sDAA4B;AAC5B;AACE;AACA;AACA;AACA;AACA;AACA;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACLA,IAAM,kBAAA,EAAoB,EAAA;AAOnB,SAAS,WAAA,CAAY,MAAA,EAAgB,KAAA,EAAe,MAAA,EAAgB,IAAA,EAA8B;AACvG,EAAA,OAAO;AAAA,IACL,MAAA;AAAA,IACA,IAAA,EAAM,EAAE,MAAA,EAAQ,CAAC,EAAE,MAAA,EAAQ,MAAA,CAAO,MAAM,CAAA,EAAG,GAAI,KAAA,EAAO,EAAE,KAAK,EAAA,EAAI,CAAC,CAAA,EAAI,KAAA,EAAO,OAAO,CAAC,EAAE;AAAA,EACzF,CAAA;AACF;AALgB,qCAAA,WAAA,EAAA,aAAA,CAAA;AAOT,SAAS,qBAAA,CAAsB,OAAA,EAAiB,oBAAA,EAAqC;AAC1F,EAAA,OAAO,WAAA,CAAY,GAAA,EAAK,oBAAA,EAAsB,MAAA,EAAQ,kBAAkB,CAAA;AAC1E;AAFgB,qCAAA,qBAAA,EAAA,uBAAA,CAAA;AAIT,SAAS,cAAA,CAAe,MAAA,EAA+B;AAC5D,EAAA,OAAO,WAAA,CAAY,GAAA,EAAK,WAAA,EAAa,MAAM,CAAA;AAC7C;AAFgB,qCAAA,cAAA,EAAA,gBAAA,CAAA;AAKhB,MAAA,SAAsB,YAAA,CACpB,KAAA,EACA,MAAA,EACA,OAAA,EAAiB,GAAA,EACO;AACxB,EA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;AACT,EAAA;AAC6B,IAAA;AAC7B,IAAA;AACG,IAAA;AACP,MAAA;AACF,MAAA;AAC6B,QAAA;AACnC,MAAA;AACD,IAAA;AACH,EAAA;AACF;AAlFsB;AHmlB4B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/chunk-N5ZE2Z6I.js","sourcesContent":[null,"import { CURRENT_USER_STORAGE_KEY } from \"../features/user/data/user.storage\";\nimport { getOfflineConfig, rootKinds } from \"./config\";\nimport { getOfflineState } from \"./state\";\nimport type { DeviceStore, StoredLink, StoredRecord } from \"./store/DeviceStore\";\nimport type {\n LocalAnswerContext,\n OfflineAnswer,\n OfflineConfig,\n OfflineMethod,\n OfflineRootKind,\n OfflineRoute,\n OfflineTypeConfig,\n} from \"./types\";\n\nconst DEFAULT_PAGE_SIZE = 25;\n\n// ---------------------------------------------------------------------------------------------\n// Answers shared by every route\n// ---------------------------------------------------------------------------------------------\n\n/** A JSON:API errors document with one error, answered with `status`. */\nexport function errorAnswer(status: number, title: string, detail: string, code?: string): OfflineAnswer {\n return {\n status,\n body: { errors: [{ status: String(status), ...(code ? { code } : {}), title, detail }] },\n };\n}\n\nexport function needsConnectionAnswer(detail: string = \"Needs a connection\"): OfflineAnswer {\n return errorAnswer(503, \"Needs a connection\", detail, \"needs-connection\");\n}\n\nexport function notFoundAnswer(detail: string): OfflineAnswer {\n return errorAnswer(404, \"Not found\", detail);\n}\n\n/** A single document of one stored record, with `included` (`includedFor`). */\nexport async function singleAnswer(\n store: DeviceStore,\n record: StoredRecord,\n status: number = 200,\n): Promise<OfflineAnswer> {\n return { status, body: { data: record.resource, included: await includedFor(store, [record]) } };\n}\n\nexport function isRootWriteLocked(rootId: string | undefined): boolean {\n return !!rootId && getOfflineState().lockedRootIds.includes(rootId);\n}\n\n// ---------------------------------------------------------------------------------------------\n// Resource helpers\n// ---------------------------------------------------------------------------------------------\n\ntype ResourceIdentifier = { type: string; id: string };\n\nfunction identifiersOf(relationship: any): ResourceIdentifier[] {\n const data = relationship?.data;\n if (!data) return [];\n return (Array.isArray(data) ? data : [data]).filter((item: any) => item && item.type && item.id);\n}\n\nfunction linkedIds(links: StoredLink[], id: string): ResourceIdentifier[] {\n return links.map((link) =>\n link.fromId === id ? { type: link.toType, id: link.toId } : { type: link.fromType, id: link.fromId },\n );\n}\n\n/** Every stored resource linked to one of `ids`, in either direction, without duplicates or the records themselves. */\n/** The `{ type, id }` every relationship of a JSON:API resource points to. */\nfunction relationshipTargets(resource: any): { type: string; id: string }[] {\n const targets: { type: string; id: string }[] = [];\n for (const relationship of Object.values<any>(resource?.relationships ?? {})) {\n const data = relationship?.data;\n for (const ref of Array.isArray(data) ? data : data ? [data] : []) {\n if (ref?.type && ref?.id) targets.push({ type: ref.type, id: ref.id });\n }\n }\n return targets;\n}\n\n/**\n * The `included` of a local answer: the stored records linked to `records` (the synced links),\n * then the stored records their relationships point to, and one level further the stored records\n * the relationships of those included records point to (an NPC's root record, then the root record's\n * owner), so a model reads the same nested relationships it reads from the server.\n *\n * Stored resources point at each other (a root record at its owner, the owner at the root record's\n * company, the company back at the owner); `RehydrationFactory` skips a resource met again inside\n * its own chain, so those circles never recurse.\n */\nexport async function includedFor(store: DeviceStore, records: StoredRecord[]): Promise<any[]> {\n // 0: the answer's own records; 1: what they link to; 2: what those link to.\n const level = new Map<string, number>(records.map((record) => [`${record.type}:${record.id}`, 0]));\n const included: { resource: any; level: number }[] = [];\n\n const add = async (target: { type: string; id: string }, atLevel: number): Promise<void> => {\n const key = `${target.type}:${target.id}`;\n if (level.has(key)) return;\n level.set(key, atLevel);\n const stored = await store.getRecord(target.type, target.id);\n const resource = stored?.resource ?? signedInUserResource(target);\n if (resource) included.push({ resource, level: atLevel });\n };\n\n for (const record of records) {\n const links = [...(await store.linksFrom(record.id)), ...(await store.linksTo(record.id))];\n for (const target of linkedIds(links, record.id)) await add(target, 1);\n }\n for (const record of records) {\n for (const target of relationshipTargets(record.resource)) await add(target, 1);\n }\n for (const entry of included.filter((candidate) => candidate.level === 1)) {\n for (const target of relationshipTargets(entry.resource)) await add(target, 2);\n }\n return included.map((entry) => entry.resource);\n}\n\n/**\n * The signed-in user as a resource, when `target` is that user. Users are not kept on the device,\n * but a relationship to the signed-in user (every downloaded root record's owner) must still resolve:\n * the app tells a GM from a player by comparing the root record's owner with the signed-in user. The\n * resource comes from the copy CurrentUserProvider keeps in localStorage, without relationships.\n */\nfunction signedInUserResource(target: { type: string; id: string }): any | undefined {\n try {\n if (target.id !== getOfflineConfig().getUserId()) return undefined;\n const stored = JSON.parse(window.localStorage.getItem(CURRENT_USER_STORAGE_KEY) ?? \"null\");\n const user = stored?.jsonApi;\n if (user?.type !== target.type || user?.id !== target.id) return undefined;\n return { type: user.type, id: user.id, attributes: user.attributes ?? {}, meta: user.meta };\n } catch {\n return undefined;\n }\n}\n\nfunction attributeOf(record: StoredRecord, name: string): unknown {\n const value = record.resource?.attributes?.[name];\n if (value !== undefined && value !== null) return value;\n // The server value the sync keeps beside the resource.\n if (name === \"updatedAt\") return record.updatedAt ?? null;\n return value;\n}\n\n/** The server's default list order (`defineEntity` sets `defaultOrderBy: \"updatedAt DESC\"`). */\nexport const SERVER_DEFAULT_ORDER_BY = \"updatedAt DESC\";\n\n/** The only `orderBy` the server accepts (`buildLegacyOrderByClause`): one property, optional ASC/DESC. */\nconst ORDER_BY = /^([A-Za-z_][A-Za-z0-9_]*)(?:\\s+(ASC|DESC))?$/i;\n\nconst ISO_DATE = /^\\d{4}-\\d{2}-\\d{2}(T|$)/;\n\nfunction comparable(value: unknown): unknown {\n if (value instanceof Date) return value.getTime();\n if (typeof value === \"string\" && ISO_DATE.test(value)) {\n const time = Date.parse(value);\n if (!Number.isNaN(time)) return time;\n }\n return value;\n}\n\n/** Cypher ORDER BY on one property, ascending: null sorts after every value. */\nfunction compareAscending(left: unknown, right: unknown): number {\n const a = comparable(left);\n const b = comparable(right);\n const aNull = a === undefined || a === null;\n const bNull = b === undefined || b === null;\n if (aNull || bNull) return aNull === bNull ? 0 : aNull ? 1 : -1;\n if (typeof a === \"number\" && typeof b === \"number\") return a - b;\n if (typeof a === \"boolean\" && typeof b === \"boolean\") return Number(a) - Number(b);\n const x = String(a);\n const y = String(b);\n return x < y ? -1 : x > y ? 1 : 0;\n}\n\nexport type ListOptions = {\n /** The string attributes the server's fulltext index covers (default: every string attribute). */\n searchFields?: string[];\n /** The order with no `orderBy` (default `updatedAt DESC`, the server's). */\n defaultOrderBy?: string;\n};\n\n/**\n * `search` as the server runs it: the term is split into letter/digit tokens and a record\n * matches when every token appears, case-insensitive, inside one of its indexed string\n * attributes (the fulltext query `*token* AND ...`).\n */\nexport function searchRecords(\n records: StoredRecord[],\n query: URLSearchParams,\n options: ListOptions = {},\n): StoredRecord[] {\n const term = query.get(\"search\");\n if (term === null || term === undefined || term.trim() === \"\") return records;\n const tokens = term\n .toLowerCase()\n .split(/[^\\p{L}\\p{N}]+/u)\n .filter(Boolean);\n if (tokens.length === 0) return records;\n\n return records.filter((record) => {\n const attributes = record.resource?.attributes ?? {};\n const fields = options.searchFields ?? Object.keys(attributes);\n const texts = fields\n .map((field) => attributes[field])\n .filter((value): value is string => typeof value === \"string\")\n .map((value) => value.toLowerCase());\n return tokens.every((token) => texts.some((text) => text.includes(token)));\n });\n}\n\n/**\n * Orders records as the server's `ORDER BY` does for `orderBy` (`field` or `field ASC|DESC`),\n * or for the default order when there is none. `null` when the server would refuse the\n * `orderBy` (400).\n */\nexport function orderRecords(\n records: StoredRecord[],\n query: URLSearchParams,\n options: ListOptions = {},\n): StoredRecord[] | null {\n const requested = query.get(\"orderBy\")?.trim();\n const value = requested || options.defaultOrderBy?.trim() || SERVER_DEFAULT_ORDER_BY;\n const match = ORDER_BY.exec(value);\n if (!match) return null;\n const field = match[1];\n const desc = match[2]?.toUpperCase() === \"DESC\";\n return [...records].sort((left, right) => {\n const order = compareAscending(attributeOf(left, field), attributeOf(right, field));\n return desc ? -order : order;\n });\n}\n\nfunction linkUrl(base: string, query: URLSearchParams, changes: Record<string, string | undefined>): string {\n const params = new URLSearchParams(query);\n for (const [key, value] of Object.entries(changes)) {\n if (value === undefined) params.delete(key);\n else params.set(key, value);\n }\n const search = params.toString().replace(/%5B/g, \"[\").replace(/%5D/g, \"]\").replace(/%2C/g, \",\");\n return search ? `${base}?${search}` : base;\n}\n\n/**\n * One list answer for a set of stored records, as the server answers a list: `search`, then\n * `orderBy` (or the default order), then paged the way `JsonApiPaginator` pages (`fetchAll`,\n * `page[size]`, `page[offset]`), with `included`. App answers pass the records they selected.\n */\nexport async function listAnswer(\n ctx: LocalAnswerContext,\n records: StoredRecord[],\n options: ListOptions = {},\n): Promise<OfflineAnswer> {\n const { request, store } = ctx;\n const base = request.url ? request.url.split(\"?\")[0] : request.path;\n const sorted = orderRecords(searchRecords(records, request.query, options), request.query, options);\n if (!sorted) {\n return errorAnswer(400, \"Bad Request\", \"Invalid orderBy\");\n }\n\n if (request.query.get(\"fetchAll\") === \"true\") {\n return {\n status: 200,\n body: {\n data: sorted.map((record) => record.resource),\n included: await includedFor(store, sorted),\n links: { self: linkUrl(base, request.query, {}) },\n meta: { total: sorted.length },\n },\n };\n }\n\n const size = Number(request.query.get(\"page[size]\")) || DEFAULT_PAGE_SIZE;\n const offset = Number(request.query.get(\"page[offset]\")) || 0;\n const page = sorted.slice(offset, offset + size);\n\n const links: Record<string, string> = {\n self: linkUrl(base, request.query, { \"page[size]\": String(size), \"page[offset]\": undefined }),\n };\n if (offset + size < sorted.length) {\n links.next = linkUrl(base, request.query, { \"page[size]\": String(size), \"page[offset]\": String(offset + size) });\n }\n if (offset > 0) {\n links.prev = linkUrl(base, request.query, {\n \"page[size]\": String(size),\n \"page[offset]\": String(Math.max(0, offset - size)),\n });\n // The server names it `previous`; the client reads `prev`.\n links.previous = links.prev;\n }\n\n return {\n status: 200,\n body: {\n data: page.map((record) => record.resource),\n included: await includedFor(store, page),\n links,\n meta: { total: sorted.length },\n },\n };\n}\n\n/**\n * A list document of stored records in the order the caller settled, every record in one page,\n * with `included`: for an app's custom list query that has its own `ORDER BY` and no paging.\n */\nexport async function orderedListAnswer(store: DeviceStore, records: StoredRecord[]): Promise<OfflineAnswer> {\n return {\n status: 200,\n body: {\n data: records.map((record) => record.resource),\n included: await includedFor(store, records),\n meta: { total: records.length },\n },\n };\n}\n\n/**\n * A list document of resources the device computed rather than stored (a query-result\n * projection such as a search hit, built by its model), answered as they are, nothing included.\n */\nexport function resourceListAnswer(resources: any[]): OfflineAnswer {\n return { status: 200, body: { data: resources, included: [] } };\n}\n\nfunction listOptionsOf(typeConfig: OfflineTypeConfig): ListOptions {\n return { searchFields: typeConfig.searchFields, defaultOrderBy: typeConfig.defaultOrderBy };\n}\n\n// ---------------------------------------------------------------------------------------------\n// Link kinds\n// ---------------------------------------------------------------------------------------------\n\n/**\n * The kind a link written on the device carries for relationship `name`: the Neo4j type the\n * type config maps it to (the kind synced links carry), otherwise the name itself.\n */\nexport function linkKindFor(typeConfig: OfflineTypeConfig | undefined, name: string): string {\n return typeConfig?.relationshipKinds?.[name] ?? name;\n}\n\n/**\n * Every kind a link of relationship `name` may carry on the device: the name (written on the\n * device before a mapping existed) and the mapped Neo4j type (synced). `undefined` when the\n * Neo4j type is not known: then a link of any kind may be the one.\n */\nexport function linkKindsOf(typeConfig: OfflineTypeConfig | undefined, name: string): string[] | undefined {\n const mapped = typeConfig?.relationshipKinds?.[name];\n return mapped ? [name, mapped] : undefined;\n}\n\n/**\n * The stored links of `id` whose kind is one of `kinds` (Neo4j types and/or relationship\n * names). `out`: links from `id`; `in`: links to `id`; `both`: either.\n */\nexport async function linksOfKind(\n store: DeviceStore,\n id: string,\n kinds: string[],\n direction: \"out\" | \"in\" | \"both\" = \"both\",\n): Promise<StoredLink[]> {\n const result: StoredLink[] = [];\n const seen = new Set<string>();\n for (const kind of new Set(kinds)) {\n const links = [\n ...(direction !== \"in\" ? await store.linksFrom(id, kind) : []),\n ...(direction !== \"out\" ? await store.linksTo(id, kind) : []),\n ];\n for (const link of links) {\n const key = `${link.fromId}|${link.toId}|${link.kind}`;\n if (seen.has(key)) continue;\n seen.add(key);\n result.push(link);\n }\n }\n return result;\n}\n\nfunction typeConfigOf(config: OfflineConfig, type: string): OfflineTypeConfig | undefined {\n return config.types.find((typeConfig) => typeConfig.module.name === type);\n}\n\n/** The relationship names of `resource` that point to a record of `type`. */\nfunction relationshipNamesToward(resource: any, type: string): string[] {\n return Object.entries<any>(resource?.relationships ?? {})\n .filter(([, relationship]) => identifiersOf(relationship).some((identifier) => identifier.type === type))\n .map(([name]) => name);\n}\n\n// ---------------------------------------------------------------------------------------------\n// Reads\n// ---------------------------------------------------------------------------------------------\n\n/** A record that is not on the device: only the server can answer for it. */\nfunction notOnDeviceAnswer(type: string, id: string): OfflineAnswer {\n return needsConnectionAnswer(`${type} ${id} is not on this device`);\n}\n\nasync function getOne(ctx: LocalAnswerContext, type: string): Promise<OfflineAnswer> {\n const record = await ctx.store.getRecord(type, ctx.params.id);\n if (!record) return notOnDeviceAnswer(type, ctx.params.id);\n return singleAnswer(ctx.store, record);\n}\n\nasync function rootList(\n ctx: LocalAnswerContext,\n kind: OfflineRootKind,\n typeConfig: OfflineTypeConfig,\n): Promise<OfflineAnswer> {\n const rootType = kind.module.name;\n const rootId = ctx.params.rootId;\n if (!(await ctx.store.getRecord(rootType, rootId))) return notOnDeviceAnswer(rootType, rootId);\n const records = await ctx.store.listRecords({ type: typeConfig.module.name, rootId });\n return listAnswer(ctx, records, listOptionsOf(typeConfig));\n}\n\n/**\n * `GET <parent>/:parentId/<type>`: the stored records of `type` linked to the parent by the\n * relationship between the two types. That relationship is the one whose name, on either\n * record, points to the other type; its links are matched by name and by mapped Neo4j type.\n * When its Neo4j type is not known, links of any kind count.\n */\nasync function relatedList(\n ctx: LocalAnswerContext,\n config: OfflineConfig,\n typeConfig: OfflineTypeConfig,\n): Promise<OfflineAnswer> {\n const type = typeConfig.module.name;\n const { parentType, parentId } = ctx.params;\n const parent = await ctx.store.getRecord(parentType, parentId);\n if (!parent) return notOnDeviceAnswer(parentType, parentId);\n\n const links = [...(await ctx.store.linksFrom(parentId)), ...(await ctx.store.linksTo(parentId))].filter((link) =>\n link.fromId === parentId ? link.toType === type : link.fromType === type,\n );\n const candidates = await ctx.store.listRecords({\n type,\n ids: [...new Set(links.map((link) => (link.fromId === parentId ? link.toId : link.fromId)))],\n });\n\n const kinds = new Set<string>();\n let anyKind = false;\n const collect = (owner: OfflineTypeConfig | undefined, names: string[]) => {\n for (const name of names) {\n const known = linkKindsOf(owner, name);\n if (known) known.forEach((kind) => kinds.add(kind));\n else anyKind = true;\n }\n };\n collect(typeConfig, [\n ...new Set(candidates.flatMap((record) => relationshipNamesToward(record.resource, parentType))),\n ]);\n collect(typeConfigOf(config, parentType), relationshipNamesToward(parent.resource, type));\n\n const accepted = anyKind || kinds.size === 0 ? links : links.filter((link) => kinds.has(link.kind));\n const ids = new Set(accepted.map((link) => (link.fromId === parentId ? link.toId : link.fromId)));\n return listAnswer(\n ctx,\n candidates.filter((record) => ids.has(record.id)),\n listOptionsOf(typeConfig),\n );\n}\n\n// ---------------------------------------------------------------------------------------------\n// Writes\n// ---------------------------------------------------------------------------------------------\n\n/**\n * The root record a record belongs to: itself (the type of any root kind), a relationship to a\n * root of any kind, or a related stored record.\n */\nexport async function rootIdForResource(\n store: DeviceStore,\n config: OfflineConfig,\n resource: any,\n): Promise<string | undefined> {\n const rootTypes = new Set(rootKinds(config).map((kind) => kind.module.name));\n if (rootTypes.has(resource?.type) && resource.id) return resource.id;\n\n const identifiers = Object.values(resource?.relationships ?? {}).flatMap(identifiersOf);\n const root = identifiers.find((identifier) => rootTypes.has(identifier.type));\n if (root) return root.id;\n\n for (const identifier of identifiers) {\n const stored = await store.getRecord(identifier.type, identifier.id);\n if (stored?.rootId) return stored.rootId;\n }\n return undefined;\n}\n\nasync function linkRelationships(\n store: DeviceStore,\n typeConfig: OfflineTypeConfig | undefined,\n record: { type: string; id: string },\n before: Record<string, any>,\n after: Record<string, any>,\n): Promise<void> {\n for (const [name, relationship] of Object.entries(after)) {\n const previous = new Map(identifiersOf(before[name]).map((identifier) => [identifier.id, identifier]));\n const next = new Map(identifiersOf(relationship).map((identifier) => [identifier.id, identifier]));\n const kinds = linkKindsOf(typeConfig, name);\n\n for (const [id] of previous) {\n if (next.has(id)) continue;\n // Only the links of this relationship (by name or Neo4j type); any kind when it is not known.\n const links = kinds\n ? await linksOfKind(store, record.id, kinds, \"both\")\n : [...(await store.linksFrom(record.id)), ...(await store.linksTo(record.id))];\n for (const link of links) {\n if (link.fromId === id || link.toId === id) {\n await store.deleteLink({ fromId: link.fromId, toId: link.toId, kind: link.kind });\n }\n }\n }\n for (const [id, identifier] of next) {\n if (previous.has(id)) continue;\n await store.putLink({\n fromType: record.type,\n fromId: record.id,\n toType: identifier.type,\n toId: id,\n kind: linkKindFor(typeConfig, name),\n props: {},\n });\n }\n }\n}\n\n/** The `data` of a JSON:API document a model built (`createJsonApi()` or a dedicated method). */\nexport type ResourceDocumentData = {\n attributes?: Record<string, unknown>;\n relationships?: Record<string, unknown>;\n meta?: Record<string, unknown>;\n};\n\n/**\n * The resource a create document stands for, under `identity`: the document's attributes,\n * relationships and meta, as the device stores a record it creates.\n */\nexport function resourceFromDocument(document: any, identity: { type: string; id: string }): any {\n const data: ResourceDocumentData = document?.data ?? {};\n const resource: any = { type: identity.type, id: identity.id };\n if (data.attributes) resource.attributes = { ...data.attributes };\n if (data.relationships) resource.relationships = { ...data.relationships };\n if (data.meta) resource.meta = { ...data.meta };\n return resource;\n}\n\n/**\n * A stored resource with a document's `data` written over it: attributes and relationships merged\n * by name, and meta merged when the document carries one, as the device applies an edit.\n */\nexport function mergeResource(before: any, identity: { type: string; id: string }, data: ResourceDocumentData): any {\n const previous = before ?? identity;\n const resource: any = {\n ...previous,\n type: identity.type,\n id: identity.id,\n attributes: { ...(previous.attributes ?? {}), ...(data?.attributes ?? {}) },\n relationships: { ...(previous.relationships ?? {}), ...(data?.relationships ?? {}) },\n };\n if (data?.meta) resource.meta = { ...(previous.meta ?? {}), ...data.meta };\n return resource;\n}\n\nfunction newId(): string {\n if (typeof crypto !== \"undefined\" && typeof crypto.randomUUID === \"function\") return crypto.randomUUID();\n return `local-${Date.now()}-${Math.random().toString(16).slice(2)}`;\n}\n\nasync function create(ctx: LocalAnswerContext, config: OfflineConfig, type: string): Promise<OfflineAnswer> {\n const typeConfig = typeConfigOf(config, type);\n const id: string = ctx.request.body?.data?.id ?? newId();\n const resource = resourceFromDocument(ctx.request.body, { type, id });\n const rootId = await rootIdForResource(ctx.store, config, resource);\n if (!rootId) return needsConnectionAnswer(`A new ${type} that belongs to no root record needs a connection`);\n if (isRootWriteLocked(rootId)) return needsConnectionAnswer(\"The root record is locked\");\n\n const record: StoredRecord = { type, id, rootId, resource, updatedAt: null, base: null, localOnly: true };\n await ctx.store.transaction(async (store) => {\n await store.putRecord(record);\n await linkRelationships(store, typeConfig, { type, id }, {}, resource.relationships ?? {});\n await store.enqueue({\n rootId,\n method: ctx.request.method,\n path: queuePath(ctx),\n body: ctx.request.body,\n base: null,\n });\n // The type's hook, inside the write's transaction: a throw rolls the write and the enqueue back.\n if (typeConfig?.afterLocalWrite) {\n await typeConfig.afterLocalWrite({\n store,\n module: typeConfig.module,\n id,\n method: \"POST\",\n resource,\n previous: null,\n });\n }\n });\n\n return singleAnswer(ctx.store, record, 201);\n}\n\nasync function update(ctx: LocalAnswerContext, config: OfflineConfig, type: string): Promise<OfflineAnswer> {\n const id = ctx.params.id;\n const existing = await ctx.store.getRecord(type, id);\n if (!existing) return notOnDeviceAnswer(type, id);\n if (isRootWriteLocked(existing.rootId)) return needsConnectionAnswer(\"The root record is locked\");\n\n const data = ctx.request.body?.data ?? {};\n const before = existing.resource ?? { type, id };\n const resource = mergeResource(before, { type, id }, data);\n // A record created on this device has no server version to merge against.\n const base = existing.localOnly ? null : (existing.base ?? before);\n\n const typeConfig = typeConfigOf(config, type);\n const method = ctx.request.method === \"PATCH\" ? \"PATCH\" : \"PUT\";\n const record: StoredRecord = { ...existing, resource, base, localOnly: existing.localOnly };\n await ctx.store.transaction(async (store) => {\n await store.putRecord(record);\n await linkRelationships(store, typeConfig, { type, id }, before.relationships ?? {}, data.relationships ?? {});\n await store.enqueue({\n rootId: existing.rootId,\n method: ctx.request.method,\n path: queuePath(ctx),\n body: ctx.request.body,\n recordType: type,\n recordId: id,\n base,\n });\n if (typeConfig?.afterLocalWrite) {\n await typeConfig.afterLocalWrite({ store, module: typeConfig.module, id, method, resource, previous: before });\n }\n });\n\n return singleAnswer(ctx.store, record);\n}\n\nasync function remove(ctx: LocalAnswerContext, config: OfflineConfig, type: string): Promise<OfflineAnswer> {\n const id = ctx.params.id;\n const existing = await ctx.store.getRecord(type, id);\n if (!existing) return notOnDeviceAnswer(type, id);\n if (isRootWriteLocked(existing.rootId)) return needsConnectionAnswer(\"The root record is locked\");\n\n const base = existing.localOnly ? null : (existing.base ?? existing.resource);\n\n await ctx.store.transaction(async (store) => {\n const links = [...(await store.linksFrom(id)), ...(await store.linksTo(id))];\n for (const link of links) await store.deleteLink({ fromId: link.fromId, toId: link.toId, kind: link.kind });\n await store.deleteRecord(type, id);\n await store.enqueue({\n rootId: existing.rootId,\n method: \"DELETE\",\n path: queuePath(ctx),\n recordType: type,\n recordId: id,\n base,\n });\n const typeConfig = typeConfigOf(config, type);\n if (typeConfig?.afterLocalWrite) {\n await typeConfig.afterLocalWrite({\n store,\n module: typeConfig.module,\n id,\n method: \"DELETE\",\n resource: null,\n previous: existing.resource,\n });\n }\n });\n\n return { status: 204, body: undefined };\n}\n\n/** The request path as `EndpointCreator` built it, query string included. */\nexport function queuePath(ctx: Pick<LocalAnswerContext, \"request\">): string {\n const query = ctx.request.query.toString();\n return query ? `${ctx.request.path}?${query}` : ctx.request.path;\n}\n\n// ---------------------------------------------------------------------------------------------\n// The generic route list\n// ---------------------------------------------------------------------------------------------\n\nfunction readOnlyGuard(typeConfig: OfflineTypeConfig, answer: (ctx: LocalAnswerContext) => Promise<OfflineAnswer>) {\n return async (ctx: LocalAnswerContext): Promise<OfflineAnswer> =>\n typeConfig.readOnly ? needsConnectionAnswer(`${typeConfig.module.name} is read-only offline`) : answer(ctx);\n}\n\n/**\n * One set of routes per configured type, in matching order: the root record list before the\n * related list (both are `x/:id/<type>`), the related list last. These generic routes are not\n * queued by the layer: each write answer queues itself, with its base.\n */\nexport function buildGenericRoutes(config: OfflineConfig): OfflineRoute[] {\n const routes: OfflineRoute[] = [];\n const route = (method: OfflineMethod, pattern: OfflineRoute[\"pattern\"], answer: OfflineRoute[\"answer\"]) =>\n routes.push({ method, pattern, answer, queue: false });\n\n for (const typeConfig of config.types) {\n const type = typeConfig.module.name;\n route(\"GET\", [typeConfig.module, \":id\"], (ctx) => getOne(ctx, type));\n for (const kind of rootKinds(config)) {\n route(\"GET\", [kind.module, \":rootId\", typeConfig.module], (ctx) => rootList(ctx, kind, typeConfig));\n }\n route(\n \"POST\",\n [typeConfig.module],\n readOnlyGuard(typeConfig, (ctx) => create(ctx, config, type)),\n );\n route(\n \"PUT\",\n [typeConfig.module, \":id\"],\n readOnlyGuard(typeConfig, (ctx) => update(ctx, config, type)),\n );\n route(\n \"PATCH\",\n [typeConfig.module, \":id\"],\n readOnlyGuard(typeConfig, (ctx) => update(ctx, config, type)),\n );\n route(\n \"DELETE\",\n [typeConfig.module, \":id\"],\n readOnlyGuard(typeConfig, (ctx) => remove(ctx, config, type)),\n );\n }\n for (const typeConfig of config.types) {\n route(\"GET\", [\":parentType\", \":parentId\", typeConfig.module], (ctx) => relatedList(ctx, config, typeConfig));\n }\n\n return routes;\n}\n","import type { OfflineMethod, OfflineRoute, PatternSegment } from \"./types\";\n\nexport type RouteMatch = { route: OfflineRoute; params: Record<string, string> };\n\nfunction splitPath(path: string): string[] {\n const withoutQuery = path.split(\"?\")[0].split(\"#\")[0];\n return withoutQuery.split(\"/\").filter((segment) => segment.length > 0);\n}\n\n/** A Module segment may itself hold slashes (\"roots/played\"), so each one is expanded. */\nfunction expandPattern(pattern: PatternSegment[]): string[] {\n return pattern.flatMap((segment) => splitPath(typeof segment === \"string\" ? segment : segment.name));\n}\n\nexport function matchPattern(pattern: PatternSegment[], path: string): Record<string, string> | null {\n const expected = expandPattern(pattern);\n const actual = splitPath(path);\n if (expected.length !== actual.length) return null;\n\n const params: Record<string, string> = {};\n for (let index = 0; index < expected.length; index++) {\n const segment = expected[index];\n const value = decodeURIComponent(actual[index]);\n if (segment.startsWith(\":\")) {\n params[segment.slice(1)] = value;\n } else if (segment !== value) {\n return null;\n }\n }\n return params;\n}\n\n/** The first route, in the order given, whose method and pattern match. The query string is ignored. */\nexport function matchRoute(routes: OfflineRoute[], method: OfflineMethod, path: string): RouteMatch | null {\n for (const route of routes) {\n if (route.method !== method) continue;\n const params = matchPattern(route.pattern, path);\n if (params) return { route, params };\n }\n return null;\n}\n","import { getClientApiUrl } from \"../client/JsonApiClient\";\nimport type { ApiData } from \"../core/interfaces/ApiData\";\nimport { getApiUrl } from \"../unified/JsonApiRequest\";\nimport { getOfflineConfig, getOfflineStore, rootKinds } from \"./config\";\nimport {\n buildGenericRoutes,\n rootIdForResource,\n isRootWriteLocked,\n needsConnectionAnswer,\n queuePath,\n} from \"./generic-answers\";\nimport { matchRoute } from \"./router\";\nimport { setOfflineState } from \"./state\";\nimport type { DeviceStore } from \"./store/DeviceStore\";\nimport {\n NeedsConnectionError,\n type OfflineAnswer,\n type OfflineMethod,\n type OfflineRequest,\n type OfflineRoute,\n} from \"./types\";\n\nexport type LocalTransportRequest = {\n method: string;\n url: string;\n body?: any;\n files?: unknown;\n};\n\nconst METHODS: OfflineMethod[] = [\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"];\n\nfunction apiBases(): string[] {\n const bases: string[] = [];\n for (const read of [getApiUrl, getClientApiUrl]) {\n try {\n const base = read();\n if (base) bases.push(base);\n } catch {\n // not configured on this side\n }\n }\n return bases;\n}\n\n/** The path relative to the API base, as `EndpointCreator` built it, and its query. */\nexport function splitApiUrl(url: string): { path: string; query: URLSearchParams } {\n let relative: string | undefined;\n for (const base of apiBases()) {\n if (url.startsWith(base)) {\n relative = url.slice(base.length);\n break;\n }\n }\n if (relative === undefined) {\n try {\n const parsed = new URL(url);\n relative = `${parsed.pathname}${parsed.search}`;\n } catch {\n relative = url;\n }\n }\n\n const [pathPart, ...queryParts] = relative.split(\"?\");\n return {\n path: pathPart.replace(/^\\/+/, \"\").replace(/\\/+$/, \"\"),\n query: new URLSearchParams(queryParts.join(\"?\")),\n };\n}\n\nfunction toApiData(answer: OfflineAnswer): ApiData {\n const ok = answer.status >= 200 && answer.status < 300;\n return {\n ok,\n status: answer.status,\n statusText: ok ? \"OK\" : answer.status === 503 ? \"Service Unavailable\" : \"Error\",\n data: answer.body,\n };\n}\n\n/** The root record a custom write belongs to: a `<root>/:param` capture, a stored record named by a param, or the body. */\nasync function rootIdForCustomWrite(\n store: DeviceStore,\n pattern: OfflineRequest,\n params: Record<string, string>,\n rootSegmentParam: string | undefined,\n): Promise<string | undefined> {\n const config = getOfflineConfig();\n if (rootSegmentParam && params[rootSegmentParam]) return params[rootSegmentParam];\n\n for (const value of Object.values(params)) {\n for (const typeConfig of config.types) {\n const stored = await store.getRecord(typeConfig.module.name, value);\n if (stored?.rootId) return stored.rootId;\n }\n }\n return rootIdForResource(store, config, pattern.body?.data);\n}\n\nasync function refreshPendingCount(store: DeviceStore): Promise<void> {\n const entries = await store.queue();\n setOfflineState({ pending: entries.filter((entry) => entry.status !== \"conflict\").length });\n}\n\n/**\n * Answers a request from the device copy: the app's custom routes first, then the generic ones.\n * The result has the `ApiData` shape `directFetch` returns, so `translateResponse` and\n * `rehydrate()` run unchanged.\n */\nexport async function localTransport(request: LocalTransportRequest): Promise<ApiData> {\n try {\n const method = request.method.toUpperCase() as OfflineMethod;\n if (!METHODS.includes(method)) return toApiData(needsConnectionAnswer());\n if (request.files) return toApiData(needsConnectionAnswer(\"Uploading files needs a connection\"));\n\n const config = getOfflineConfig();\n const { path, query } = splitApiUrl(request.url);\n const offlineRequest: OfflineRequest = { method, path, query, body: request.body, url: request.url };\n\n const custom = matchRoute(config.routes, method, path);\n const match = custom ?? matchRoute(buildGenericRoutes(config), method, path);\n if (!match) return toApiData(needsConnectionAnswer(`${method} ${path} has no offline answer`));\n\n let store: DeviceStore;\n try {\n store = await getOfflineStore();\n } catch (error) {\n // The device copy cannot be opened here (another tab holds the file, storage refused,\n // no signed-in user): only the server can answer.\n if (error instanceof NeedsConnectionError) return toApiData(needsConnectionAnswer(error.message));\n console.warn(\"[offline] the device copy could not be opened\", error);\n return toApiData(needsConnectionAnswer(\"The device copy is not available in this tab\"));\n }\n const ctx = { request: offlineRequest, params: match.params, store };\n\n // The root record of a custom write (a `<root>/:param` capture of any root kind's module, a\n // stored record, or the body).\n const rootTypes = new Set(rootKinds(config).map((kind) => kind.module.name));\n const customRootId = async (route: OfflineRoute): Promise<string | undefined> => {\n const rootIndex = route.pattern.findIndex(\n (segment) => typeof segment !== \"string\" && rootTypes.has(segment.name),\n );\n const next = rootIndex >= 0 ? route.pattern[rootIndex + 1] : undefined;\n const rootParam = typeof next === \"string\" && next.startsWith(\":\") ? next.slice(1) : undefined;\n return rootIdForCustomWrite(store, offlineRequest, match.params, rootParam);\n };\n\n if (!custom || !custom.route.queue) {\n // A custom write that is not queued is refused on a locked root record too (GETs stay allowed).\n if (custom && method !== \"GET\") {\n const rootId = await customRootId(custom.route);\n if (rootId && isRootWriteLocked(rootId)) {\n return toApiData(needsConnectionAnswer(\"The root record is locked\"));\n }\n }\n const answer = await match.route.answer(ctx);\n if (method !== \"GET\") await refreshPendingCount(store);\n return toApiData(answer);\n }\n\n // A custom write the server must run too: refused on a locked root record, otherwise the answer\n // updates the device copy and the original request is queued in the same transaction.\n const rootId = await customRootId(custom.route);\n if (!rootId) return toApiData(needsConnectionAnswer(`${method} ${path} belongs to no root record on this device`));\n if (isRootWriteLocked(rootId)) return toApiData(needsConnectionAnswer(\"The root record is locked\"));\n\n const answer = await store.transaction(async (transactionStore) => {\n const result = await custom.route.answer({ ...ctx, store: transactionStore });\n if (result.status >= 200 && result.status < 300) {\n await transactionStore.enqueue({\n rootId,\n method,\n path: queuePath(ctx),\n body: request.body,\n base: null,\n });\n }\n return result;\n });\n await refreshPendingCount(store);\n return toApiData(answer);\n } catch (error) {\n if (error instanceof NeedsConnectionError) return toApiData(needsConnectionAnswer(error.message));\n console.error(\"[offline] local answer failed\", error);\n return toApiData({\n status: 500,\n body: {\n errors: [{ status: \"500\", title: \"Offline answer failed\", detail: String((error as Error)?.message ?? error) }],\n },\n });\n }\n}\n"]}
|
|
@@ -8,7 +8,7 @@ var _chunkYUO55Q5Ajs = require('./chunk-YUO55Q5A.js');
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkGM4VZTWLjs = require('./chunk-GM4VZTWL.js');
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
var _chunk7QVYU63Ejs = require('./chunk-7QVYU63E.js');
|
|
@@ -26,7 +26,7 @@ function getServerApiUrl() {
|
|
|
26
26
|
if (_optionalChain([_serverConfig, 'optionalAccess', _ => _.apiUrl])) {
|
|
27
27
|
return _serverConfig.apiUrl;
|
|
28
28
|
}
|
|
29
|
-
const envUrl =
|
|
29
|
+
const envUrl = _chunkGM4VZTWLjs.ENV.API_URL;
|
|
30
30
|
if (!envUrl) {
|
|
31
31
|
throw new Error(
|
|
32
32
|
"API URL not configured. Use configureServerJsonApi() or set NEXT_PUBLIC_API_URL environment variable."
|
|
@@ -39,7 +39,7 @@ function getServerAppUrl() {
|
|
|
39
39
|
if (_optionalChain([_serverConfig, 'optionalAccess', _2 => _2.appUrl])) {
|
|
40
40
|
return _serverConfig.appUrl;
|
|
41
41
|
}
|
|
42
|
-
const envUrl =
|
|
42
|
+
const envUrl = _chunkGM4VZTWLjs.ENV.APP_URL;
|
|
43
43
|
if (!envUrl) {
|
|
44
44
|
throw new Error(
|
|
45
45
|
"App URL not configured. Use configureServerJsonApi({ appUrl }) or set NEXT_PUBLIC_ADDRESS environment variable."
|
|
@@ -75,7 +75,7 @@ async function ServerJsonApiGet(params) {
|
|
|
75
75
|
language: params.language,
|
|
76
76
|
additionalHeaders: _optionalChain([_serverConfig, 'optionalAccess', _5 => _5.additionalHeaders])
|
|
77
77
|
});
|
|
78
|
-
return
|
|
78
|
+
return _chunkGM4VZTWLjs.translateResponse.call(void 0, {
|
|
79
79
|
classKey: params.classKey,
|
|
80
80
|
apiResponse,
|
|
81
81
|
companyId: params.companyId,
|
|
@@ -96,7 +96,7 @@ async function ServerJsonApiPost(params) {
|
|
|
96
96
|
if (!body) {
|
|
97
97
|
body = {};
|
|
98
98
|
} else if (params.overridesJsonApiCreation !== true) {
|
|
99
|
-
body =
|
|
99
|
+
body = _chunkGM4VZTWLjs.JsonApiDataFactory.create(params.classKey, body);
|
|
100
100
|
}
|
|
101
101
|
const apiResponse = await _chunk6TUB7Y6Tjs.serverRequest.call(void 0, {
|
|
102
102
|
method: "POST",
|
|
@@ -108,7 +108,7 @@ async function ServerJsonApiPost(params) {
|
|
|
108
108
|
language: params.language,
|
|
109
109
|
additionalHeaders: _optionalChain([_serverConfig, 'optionalAccess', _6 => _6.additionalHeaders])
|
|
110
110
|
});
|
|
111
|
-
return
|
|
111
|
+
return _chunkGM4VZTWLjs.translateResponse.call(void 0, {
|
|
112
112
|
classKey: _nullishCoalesce(params.responseType, () => ( params.classKey)),
|
|
113
113
|
apiResponse,
|
|
114
114
|
companyId: params.companyId,
|
|
@@ -123,7 +123,7 @@ async function ServerJsonApiPut(params) {
|
|
|
123
123
|
if (!body) {
|
|
124
124
|
body = {};
|
|
125
125
|
} else {
|
|
126
|
-
body =
|
|
126
|
+
body = _chunkGM4VZTWLjs.JsonApiDataFactory.create(params.classKey, body);
|
|
127
127
|
}
|
|
128
128
|
const apiResponse = await _chunk6TUB7Y6Tjs.serverRequest.call(void 0, {
|
|
129
129
|
method: "PUT",
|
|
@@ -135,7 +135,7 @@ async function ServerJsonApiPut(params) {
|
|
|
135
135
|
language: params.language,
|
|
136
136
|
additionalHeaders: _optionalChain([_serverConfig, 'optionalAccess', _7 => _7.additionalHeaders])
|
|
137
137
|
});
|
|
138
|
-
return
|
|
138
|
+
return _chunkGM4VZTWLjs.translateResponse.call(void 0, {
|
|
139
139
|
classKey: _nullishCoalesce(params.responseType, () => ( params.classKey)),
|
|
140
140
|
apiResponse,
|
|
141
141
|
companyId: params.companyId,
|
|
@@ -150,7 +150,7 @@ async function ServerJsonApiPatch(params) {
|
|
|
150
150
|
if (!body) {
|
|
151
151
|
body = {};
|
|
152
152
|
} else if (params.overridesJsonApiCreation !== true) {
|
|
153
|
-
body =
|
|
153
|
+
body = _chunkGM4VZTWLjs.JsonApiDataFactory.create(params.classKey, body);
|
|
154
154
|
}
|
|
155
155
|
const apiResponse = await _chunk6TUB7Y6Tjs.serverRequest.call(void 0, {
|
|
156
156
|
method: "PATCH",
|
|
@@ -162,7 +162,7 @@ async function ServerJsonApiPatch(params) {
|
|
|
162
162
|
language: params.language,
|
|
163
163
|
additionalHeaders: _optionalChain([_serverConfig, 'optionalAccess', _8 => _8.additionalHeaders])
|
|
164
164
|
});
|
|
165
|
-
return
|
|
165
|
+
return _chunkGM4VZTWLjs.translateResponse.call(void 0, {
|
|
166
166
|
classKey: _nullishCoalesce(params.responseType, () => ( params.classKey)),
|
|
167
167
|
apiResponse,
|
|
168
168
|
companyId: params.companyId,
|
|
@@ -181,7 +181,7 @@ async function ServerJsonApiDelete(params) {
|
|
|
181
181
|
language: params.language,
|
|
182
182
|
additionalHeaders: _optionalChain([_serverConfig, 'optionalAccess', _9 => _9.additionalHeaders])
|
|
183
183
|
});
|
|
184
|
-
return
|
|
184
|
+
return _chunkGM4VZTWLjs.translateResponse.call(void 0, {
|
|
185
185
|
classKey: _nullishCoalesce(params.responseType, () => ( params.classKey)),
|
|
186
186
|
apiResponse,
|
|
187
187
|
companyId: params.companyId,
|
|
@@ -201,4 +201,4 @@ _chunk7QVYU63Ejs.__name.call(void 0, ServerJsonApiDelete, "ServerJsonApiDelete")
|
|
|
201
201
|
|
|
202
202
|
|
|
203
203
|
exports.configureServerJsonApi = configureServerJsonApi; exports.getServerApiUrl = getServerApiUrl; exports.getServerAppUrl = getServerAppUrl; exports.getServerTrackablePages = getServerTrackablePages; exports.ServerJsonApiGet = ServerJsonApiGet; exports.ServerJsonApiPost = ServerJsonApiPost; exports.ServerJsonApiPut = ServerJsonApiPut; exports.ServerJsonApiPatch = ServerJsonApiPatch; exports.ServerJsonApiDelete = ServerJsonApiDelete;
|
|
204
|
-
//# sourceMappingURL=chunk-
|
|
204
|
+
//# sourceMappingURL=chunk-OQQ7CZWT.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/chunk-2SV4SS6N.js","../src/server/JsonApiServer.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACA;AACA;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACHA,IAAI,cAAA,EAMO,IAAA;AAMJ,SAAS,sBAAA,CAAuB,MAAA,EAM9B;AACP,EAAA,cAAA,EAAgB,MAAA;AAChB,EAAA,GAAA,CAAI,MAAA,CAAO,YAAA,EAAc;AACvB,IAAA,MAAA,CAAO,YAAA,CAAa,CAAA;AAAA,EACtB;AACF;AAXgB,qCAAA,sBAAA,EAAA,wBAAA,CAAA;AAaT,SAAS,eAAA,CAAA,EAA0B;AACxC,EAAA,GAAA,iBAAI,aAAA,2BAAe,QAAA,EAAQ;AACzB,IAAA,OAAO,aAAA,CAAc,MAAA;AAAA,EACvB;AACA,EAAA,MAAM,OAAA,EAAS,oBAAA,CAAI,OAAA;AACnB,EAA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,IAAA;AACkB,IAAA;AACD,IAAA;AAClB,EAAA;AACH;AAzBsB;ADvC6B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/chunk-2SV4SS6N.js","sourcesContent":[null,"// Server-only utilities (NOT server actions - these cannot be called from client components)\n\nimport { ENV } from \"../core/env\";\nimport { JsonApiDataFactory } from \"../core/factories/JsonApiDataFactory\";\nimport { ApiRequestDataTypeInterface } from \"../core/interfaces/ApiRequestDataTypeInterface\";\nimport { ApiResponseInterface } from \"../core/interfaces/ApiResponseInterface\";\nimport { translateResponse } from \"../core/utils/translateResponse\";\nimport { ModuleWithPermissions } from \"../permissions/types\";\nimport { serverRequest } from \"./request\";\nimport { getServerToken } from \"./token\";\n\n// Config storage for server contexts\nlet _serverConfig: {\n apiUrl: string;\n appUrl?: string;\n trackablePages?: ModuleWithPermissions[];\n bootstrapper?: () => void;\n additionalHeaders?: Record<string, string>;\n} | null = null;\n\n/**\n * Configure the JSON:API server client.\n * Call this in your Bootstrapper or server initialization.\n */\nexport function configureServerJsonApi(config: {\n apiUrl: string;\n appUrl?: string;\n trackablePages?: ModuleWithPermissions[];\n bootstrapper?: () => void;\n additionalHeaders?: Record<string, string>;\n}): void {\n _serverConfig = config;\n if (config.bootstrapper) {\n config.bootstrapper();\n }\n}\n\nexport function getServerApiUrl(): string {\n if (_serverConfig?.apiUrl) {\n return _serverConfig.apiUrl;\n }\n const envUrl = ENV.API_URL;\n if (!envUrl) {\n throw new Error(\n \"API URL not configured. Use configureServerJsonApi() or set NEXT_PUBLIC_API_URL environment variable.\",\n );\n }\n return envUrl;\n}\n\nexport function getServerAppUrl(): string {\n if (_serverConfig?.appUrl) {\n return _serverConfig.appUrl;\n }\n const envUrl = ENV.APP_URL;\n if (!envUrl) {\n throw new Error(\n \"App URL not configured. Use configureServerJsonApi({ appUrl }) or set NEXT_PUBLIC_ADDRESS environment variable.\",\n );\n }\n return envUrl.trim().replace(/\\/+$/, \"\");\n}\n\nexport function getServerTrackablePages(): ModuleWithPermissions[] {\n return _serverConfig?.trackablePages ?? [];\n}\n\nfunction runServerBootstrapper(): void {\n if (_serverConfig?.bootstrapper) {\n _serverConfig.bootstrapper();\n }\n}\n\nfunction buildServerUrl(endpoint: string): string {\n const apiUrl = getServerApiUrl();\n return endpoint.startsWith(\"http\") ? endpoint : `${apiUrl}${endpoint}`;\n}\n\nexport async function ServerJsonApiGet(params: {\n classKey: ApiRequestDataTypeInterface;\n endpoint: string;\n companyId?: string;\n language: string;\n}): Promise<ApiResponseInterface> {\n runServerBootstrapper();\n // A cached GET never sends the token, so it must not read the cookie either:\n // the read would make a public page dynamic.\n const token = params.classKey.cache ? undefined : await getServerToken();\n\n const apiResponse = await serverRequest({\n method: \"GET\",\n url: buildServerUrl(params.endpoint),\n token,\n cache: params.classKey.cache,\n companyId: params.companyId,\n language: params.language,\n additionalHeaders: _serverConfig?.additionalHeaders,\n });\n\n return translateResponse({\n classKey: params.classKey,\n apiResponse,\n companyId: params.companyId,\n language: params.language,\n paginationHandler: async (endpoint: string) =>\n ServerJsonApiGet({\n classKey: params.classKey,\n endpoint,\n companyId: params.companyId,\n language: params.language,\n }),\n });\n}\n\nexport async function ServerJsonApiPost(params: {\n classKey: ApiRequestDataTypeInterface;\n endpoint: string;\n companyId?: string;\n body?: any;\n overridesJsonApiCreation?: boolean;\n files?: { [key: string]: File | Blob } | File | Blob;\n language: string;\n responseType?: ApiRequestDataTypeInterface;\n}): Promise<ApiResponseInterface> {\n runServerBootstrapper();\n const token = await getServerToken();\n\n let body = params.body;\n if (!body) {\n body = {};\n } else if (params.overridesJsonApiCreation !== true) {\n body = JsonApiDataFactory.create(params.classKey, body);\n }\n\n const apiResponse = await serverRequest({\n method: \"POST\",\n url: buildServerUrl(params.endpoint),\n token,\n body,\n files: params.files,\n companyId: params.companyId,\n language: params.language,\n additionalHeaders: _serverConfig?.additionalHeaders,\n });\n\n return translateResponse({\n classKey: params.responseType ?? params.classKey,\n apiResponse,\n companyId: params.companyId,\n language: params.language,\n });\n}\n\nexport async function ServerJsonApiPut(params: {\n classKey: ApiRequestDataTypeInterface;\n endpoint: string;\n companyId?: string;\n body?: any;\n files?: { [key: string]: File | Blob } | File | Blob;\n language: string;\n responseType?: ApiRequestDataTypeInterface;\n}): Promise<ApiResponseInterface> {\n runServerBootstrapper();\n const token = await getServerToken();\n\n let body = params.body;\n if (!body) {\n body = {};\n } else {\n body = JsonApiDataFactory.create(params.classKey, body);\n }\n\n const apiResponse = await serverRequest({\n method: \"PUT\",\n url: buildServerUrl(params.endpoint),\n token,\n body,\n files: params.files,\n companyId: params.companyId,\n language: params.language,\n additionalHeaders: _serverConfig?.additionalHeaders,\n });\n\n return translateResponse({\n classKey: params.responseType ?? params.classKey,\n apiResponse,\n companyId: params.companyId,\n language: params.language,\n });\n}\n\nexport async function ServerJsonApiPatch(params: {\n classKey: ApiRequestDataTypeInterface;\n endpoint: string;\n companyId?: string;\n body?: any;\n files?: { [key: string]: File | Blob } | File | Blob;\n overridesJsonApiCreation?: boolean;\n responseType?: ApiRequestDataTypeInterface;\n language: string;\n}): Promise<ApiResponseInterface> {\n runServerBootstrapper();\n const token = await getServerToken();\n\n let body = params.body;\n if (!body) {\n body = {};\n } else if (params.overridesJsonApiCreation !== true) {\n body = JsonApiDataFactory.create(params.classKey, body);\n }\n\n const apiResponse = await serverRequest({\n method: \"PATCH\",\n url: buildServerUrl(params.endpoint),\n token,\n body,\n files: params.files,\n companyId: params.companyId,\n language: params.language,\n additionalHeaders: _serverConfig?.additionalHeaders,\n });\n\n return translateResponse({\n classKey: params.responseType ?? params.classKey,\n apiResponse,\n companyId: params.companyId,\n language: params.language,\n });\n}\n\nexport async function ServerJsonApiDelete(params: {\n classKey: ApiRequestDataTypeInterface;\n endpoint: string;\n companyId?: string;\n language: string;\n responseType?: ApiRequestDataTypeInterface;\n}): Promise<ApiResponseInterface> {\n runServerBootstrapper();\n const token = await getServerToken();\n\n const apiResponse = await serverRequest({\n method: \"DELETE\",\n url: buildServerUrl(params.endpoint),\n token,\n companyId: params.companyId,\n language: params.language,\n additionalHeaders: _serverConfig?.additionalHeaders,\n });\n\n return translateResponse({\n classKey: params.responseType ?? params.classKey,\n apiResponse,\n companyId: params.companyId,\n language: params.language,\n });\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/chunk-OQQ7CZWT.js","../src/server/JsonApiServer.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACA;AACA;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACHA,IAAI,cAAA,EAMO,IAAA;AAMJ,SAAS,sBAAA,CAAuB,MAAA,EAM9B;AACP,EAAA,cAAA,EAAgB,MAAA;AAChB,EAAA,GAAA,CAAI,MAAA,CAAO,YAAA,EAAc;AACvB,IAAA,MAAA,CAAO,YAAA,CAAa,CAAA;AAAA,EACtB;AACF;AAXgB,qCAAA,sBAAA,EAAA,wBAAA,CAAA;AAaT,SAAS,eAAA,CAAA,EAA0B;AACxC,EAAA,GAAA,iBAAI,aAAA,2BAAe,QAAA,EAAQ;AACzB,IAAA,OAAO,aAAA,CAAc,MAAA;AAAA,EACvB;AACA,EAAA,MAAM,OAAA,EAAS,oBAAA,CAAI,OAAA;AACnB,EAAA,GAAA,CAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,IACF,CAAA;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAXgB,qCAAA,eAAA,EAAA,iBAAA,CAAA;AAaT,SAAS,eAAA,CAAA,EAA0B;AACxC,EAAA,GAAA,iBAAI,aAAA,6BAAe,QAAA,EAAQ;AACzB,IAAA,OAAO,aAAA,CAAc,MAAA;AAAA,EACvB;AACA,EAAA,MAAM,OAAA,EAAS,oBAAA,CAAI,O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,IAAA;AACD,IAAA;AACiB,IAAA;AACnC,EAAA;AAEwB,EAAA;AACiB,IAAA;AACxC,IAAA;AACkB,IAAA;AACD,IAAA;AAClB,EAAA;AACH;AArCsB;AA+CY;AACV,EAAA;AACa,EAAA;AAEjB,EAAA;AACP,EAAA;AACD,IAAA;AACH,EAAA;AACmC,IAAA;AAC1C,EAAA;AAEwC,EAAA;AAC9B,IAAA;AAC2B,IAAA;AACnC,IAAA;AACA,IAAA;AACc,IAAA;AACI,IAAA;AACD,IAAA;AACiB,IAAA;AACnC,EAAA;AAEwB,EAAA;AACiB,IAAA;AACxC,IAAA;AACkB,IAAA;AACD,IAAA;AAClB,EAAA;AACH;AApCsB;AA+CY;AACV,EAAA;AACa,EAAA;AAEjB,EAAA;AACP,EAAA;AACD,IAAA;AACqC,EAAA;AACL,IAAA;AAC1C,EAAA;AAEwC,EAAA;AAC9B,IAAA;AAC2B,IAAA;AACnC,IAAA;AACA,IAAA;AACc,IAAA;AACI,IAAA;AACD,IAAA;AACiB,IAAA;AACnC,EAAA;AAEwB,EAAA;AACiB,IAAA;AACxC,IAAA;AACkB,IAAA;AACD,IAAA;AAClB,EAAA;AACH;AArCsB;AA6CY;AACV,EAAA;AACa,EAAA;AAEK,EAAA;AAC9B,IAAA;AAC2B,IAAA;AACnC,IAAA;AACkB,IAAA;AACD,IAAA;AACiB,IAAA;AACnC,EAAA;AAEwB,EAAA;AACiB,IAAA;AACxC,IAAA;AACkB,IAAA;AACD,IAAA;AAClB,EAAA;AACH;AAzBsB;ADvC6B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/chunk-OQQ7CZWT.js","sourcesContent":[null,"// Server-only utilities (NOT server actions - these cannot be called from client components)\n\nimport { ENV } from \"../core/env\";\nimport { JsonApiDataFactory } from \"../core/factories/JsonApiDataFactory\";\nimport { ApiRequestDataTypeInterface } from \"../core/interfaces/ApiRequestDataTypeInterface\";\nimport { ApiResponseInterface } from \"../core/interfaces/ApiResponseInterface\";\nimport { translateResponse } from \"../core/utils/translateResponse\";\nimport { ModuleWithPermissions } from \"../permissions/types\";\nimport { serverRequest } from \"./request\";\nimport { getServerToken } from \"./token\";\n\n// Config storage for server contexts\nlet _serverConfig: {\n apiUrl: string;\n appUrl?: string;\n trackablePages?: ModuleWithPermissions[];\n bootstrapper?: () => void;\n additionalHeaders?: Record<string, string>;\n} | null = null;\n\n/**\n * Configure the JSON:API server client.\n * Call this in your Bootstrapper or server initialization.\n */\nexport function configureServerJsonApi(config: {\n apiUrl: string;\n appUrl?: string;\n trackablePages?: ModuleWithPermissions[];\n bootstrapper?: () => void;\n additionalHeaders?: Record<string, string>;\n}): void {\n _serverConfig = config;\n if (config.bootstrapper) {\n config.bootstrapper();\n }\n}\n\nexport function getServerApiUrl(): string {\n if (_serverConfig?.apiUrl) {\n return _serverConfig.apiUrl;\n }\n const envUrl = ENV.API_URL;\n if (!envUrl) {\n throw new Error(\n \"API URL not configured. Use configureServerJsonApi() or set NEXT_PUBLIC_API_URL environment variable.\",\n );\n }\n return envUrl;\n}\n\nexport function getServerAppUrl(): string {\n if (_serverConfig?.appUrl) {\n return _serverConfig.appUrl;\n }\n const envUrl = ENV.APP_URL;\n if (!envUrl) {\n throw new Error(\n \"App URL not configured. Use configureServerJsonApi({ appUrl }) or set NEXT_PUBLIC_ADDRESS environment variable.\",\n );\n }\n return envUrl.trim().replace(/\\/+$/, \"\");\n}\n\nexport function getServerTrackablePages(): ModuleWithPermissions[] {\n return _serverConfig?.trackablePages ?? [];\n}\n\nfunction runServerBootstrapper(): void {\n if (_serverConfig?.bootstrapper) {\n _serverConfig.bootstrapper();\n }\n}\n\nfunction buildServerUrl(endpoint: string): string {\n const apiUrl = getServerApiUrl();\n return endpoint.startsWith(\"http\") ? endpoint : `${apiUrl}${endpoint}`;\n}\n\nexport async function ServerJsonApiGet(params: {\n classKey: ApiRequestDataTypeInterface;\n endpoint: string;\n companyId?: string;\n language: string;\n}): Promise<ApiResponseInterface> {\n runServerBootstrapper();\n // A cached GET never sends the token, so it must not read the cookie either:\n // the read would make a public page dynamic.\n const token = params.classKey.cache ? undefined : await getServerToken();\n\n const apiResponse = await serverRequest({\n method: \"GET\",\n url: buildServerUrl(params.endpoint),\n token,\n cache: params.classKey.cache,\n companyId: params.companyId,\n language: params.language,\n additionalHeaders: _serverConfig?.additionalHeaders,\n });\n\n return translateResponse({\n classKey: params.classKey,\n apiResponse,\n companyId: params.companyId,\n language: params.language,\n paginationHandler: async (endpoint: string) =>\n ServerJsonApiGet({\n classKey: params.classKey,\n endpoint,\n companyId: params.companyId,\n language: params.language,\n }),\n });\n}\n\nexport async function ServerJsonApiPost(params: {\n classKey: ApiRequestDataTypeInterface;\n endpoint: string;\n companyId?: string;\n body?: any;\n overridesJsonApiCreation?: boolean;\n files?: { [key: string]: File | Blob } | File | Blob;\n language: string;\n responseType?: ApiRequestDataTypeInterface;\n}): Promise<ApiResponseInterface> {\n runServerBootstrapper();\n const token = await getServerToken();\n\n let body = params.body;\n if (!body) {\n body = {};\n } else if (params.overridesJsonApiCreation !== true) {\n body = JsonApiDataFactory.create(params.classKey, body);\n }\n\n const apiResponse = await serverRequest({\n method: \"POST\",\n url: buildServerUrl(params.endpoint),\n token,\n body,\n files: params.files,\n companyId: params.companyId,\n language: params.language,\n additionalHeaders: _serverConfig?.additionalHeaders,\n });\n\n return translateResponse({\n classKey: params.responseType ?? params.classKey,\n apiResponse,\n companyId: params.companyId,\n language: params.language,\n });\n}\n\nexport async function ServerJsonApiPut(params: {\n classKey: ApiRequestDataTypeInterface;\n endpoint: string;\n companyId?: string;\n body?: any;\n files?: { [key: string]: File | Blob } | File | Blob;\n language: string;\n responseType?: ApiRequestDataTypeInterface;\n}): Promise<ApiResponseInterface> {\n runServerBootstrapper();\n const token = await getServerToken();\n\n let body = params.body;\n if (!body) {\n body = {};\n } else {\n body = JsonApiDataFactory.create(params.classKey, body);\n }\n\n const apiResponse = await serverRequest({\n method: \"PUT\",\n url: buildServerUrl(params.endpoint),\n token,\n body,\n files: params.files,\n companyId: params.companyId,\n language: params.language,\n additionalHeaders: _serverConfig?.additionalHeaders,\n });\n\n return translateResponse({\n classKey: params.responseType ?? params.classKey,\n apiResponse,\n companyId: params.companyId,\n language: params.language,\n });\n}\n\nexport async function ServerJsonApiPatch(params: {\n classKey: ApiRequestDataTypeInterface;\n endpoint: string;\n companyId?: string;\n body?: any;\n files?: { [key: string]: File | Blob } | File | Blob;\n overridesJsonApiCreation?: boolean;\n responseType?: ApiRequestDataTypeInterface;\n language: string;\n}): Promise<ApiResponseInterface> {\n runServerBootstrapper();\n const token = await getServerToken();\n\n let body = params.body;\n if (!body) {\n body = {};\n } else if (params.overridesJsonApiCreation !== true) {\n body = JsonApiDataFactory.create(params.classKey, body);\n }\n\n const apiResponse = await serverRequest({\n method: \"PATCH\",\n url: buildServerUrl(params.endpoint),\n token,\n body,\n files: params.files,\n companyId: params.companyId,\n language: params.language,\n additionalHeaders: _serverConfig?.additionalHeaders,\n });\n\n return translateResponse({\n classKey: params.responseType ?? params.classKey,\n apiResponse,\n companyId: params.companyId,\n language: params.language,\n });\n}\n\nexport async function ServerJsonApiDelete(params: {\n classKey: ApiRequestDataTypeInterface;\n endpoint: string;\n companyId?: string;\n language: string;\n responseType?: ApiRequestDataTypeInterface;\n}): Promise<ApiResponseInterface> {\n runServerBootstrapper();\n const token = await getServerToken();\n\n const apiResponse = await serverRequest({\n method: \"DELETE\",\n url: buildServerUrl(params.endpoint),\n token,\n companyId: params.companyId,\n language: params.language,\n additionalHeaders: _serverConfig?.additionalHeaders,\n });\n\n return translateResponse({\n classKey: params.responseType ?? params.classKey,\n apiResponse,\n companyId: params.companyId,\n language: params.language,\n });\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
VIEWPORT_COOKIE_NAME,
|
|
6
6
|
checkPermissionsFromServer
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-RFKSJIQB.mjs";
|
|
8
8
|
import {
|
|
9
9
|
__name
|
|
10
10
|
} from "./chunk-PAWJFY3S.mjs";
|
|
@@ -138,4 +138,4 @@ export {
|
|
|
138
138
|
ServerSession,
|
|
139
139
|
buildOfflineManifest
|
|
140
140
|
};
|
|
141
|
-
//# sourceMappingURL=chunk-
|
|
141
|
+
//# sourceMappingURL=chunk-OUEYZOLB.mjs.map
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
SERVER_SNAPSHOT,
|
|
3
3
|
getOfflineState,
|
|
4
4
|
subscribeOfflineState
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-4ZJIUTIV.mjs";
|
|
6
6
|
import {
|
|
7
7
|
__name
|
|
8
8
|
} from "./chunk-PAWJFY3S.mjs";
|
|
@@ -22,4 +22,4 @@ export {
|
|
|
22
22
|
useOfflineState,
|
|
23
23
|
useNeedsConnection
|
|
24
24
|
};
|
|
25
|
-
//# sourceMappingURL=chunk-
|
|
25
|
+
//# sourceMappingURL=chunk-OY65RYD3.mjs.map
|