@carlonicora/nextjs-jsonapi 3.28.1 → 4.0.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-ATZVHS6X.js → BlockNoteEditor-BXMTGKDV.js} +21 -20
- package/dist/BlockNoteEditor-BXMTGKDV.js.map +1 -0
- package/dist/{BlockNoteEditor-CWW2D3SG.mjs → BlockNoteEditor-FGVQP35E.mjs} +9 -8
- package/dist/{BlockNoteEditor-CWW2D3SG.mjs.map → BlockNoteEditor-FGVQP35E.mjs.map} +1 -1
- package/dist/{BlockNoteViewer-KRTAFTUX.mjs → BlockNoteViewer-DQYT6IJW.mjs} +3 -3
- package/dist/{BlockNoteViewer-7BFNTN4E.js → BlockNoteViewer-YH7G66PS.js} +4 -4
- package/dist/{BlockNoteViewer-7BFNTN4E.js.map → BlockNoteViewer-YH7G66PS.js.map} +1 -1
- package/dist/{HandbookSectionInterface-DgYH--Ik.d.mts → HandbookSectionInterface-BYsmnPEz.d.mts} +1 -1
- package/dist/{HandbookSectionInterface-Ck1wZJ81.d.ts → HandbookSectionInterface-OePKPbqN.d.ts} +1 -1
- package/dist/{JsonApiRequest-UHOWNI3O.mjs → JsonApiRequest-MEP6AXDT.mjs} +2 -2
- package/dist/JsonApiRequest-OB6WL4LA.js +26 -0
- package/dist/{JsonApiRequest-TE5WD3WS.js.map → JsonApiRequest-OB6WL4LA.js.map} +1 -1
- package/dist/ServerSession-DFNNNkg7.d.ts +29 -0
- package/dist/ServerSession-DK1z0_Ql.d.mts +29 -0
- package/dist/{analytics.modules-CfczU12P.d.ts → analytics.modules-Bsacu6ik.d.ts} +1 -1
- package/dist/{analytics.modules-pzGwMASI.d.mts → analytics.modules-txdCLNG-.d.mts} +1 -1
- package/dist/billing/index.js +404 -402
- package/dist/billing/index.js.map +1 -1
- package/dist/billing/index.mjs +10 -8
- package/dist/billing/index.mjs.map +1 -1
- package/dist/{chunk-7B4E42R5.mjs → chunk-3CZ2GK5R.mjs} +33 -9
- package/dist/chunk-3CZ2GK5R.mjs.map +1 -0
- package/dist/{chunk-4Z45NYPR.js → chunk-5W5MN7JP.js} +14 -83
- package/dist/chunk-5W5MN7JP.js.map +1 -0
- package/dist/{chunk-CAKOFJZD.js → chunk-6OFANJTE.js} +195 -142
- package/dist/chunk-6OFANJTE.js.map +1 -0
- package/dist/{chunk-5TRFNKJS.js → chunk-6TUB7Y6T.js} +23 -25
- package/dist/chunk-6TUB7Y6T.js.map +1 -0
- package/dist/{chunk-37DMFVLN.mjs → chunk-7SCREMTX.mjs} +4 -3
- package/dist/{chunk-37DMFVLN.mjs.map → chunk-7SCREMTX.mjs.map} +1 -1
- package/dist/{chunk-Q6J2ICKO.mjs → chunk-ADZSH3MG.mjs} +3 -72
- package/dist/chunk-ADZSH3MG.mjs.map +1 -0
- package/dist/{chunk-E3I4MT53.mjs → chunk-AQZ3T4BR.mjs} +71 -18
- package/dist/chunk-AQZ3T4BR.mjs.map +1 -0
- package/dist/{chunk-SJLXPHK5.mjs → chunk-E2LENTUH.mjs} +22 -24
- package/dist/chunk-E2LENTUH.mjs.map +1 -0
- package/dist/chunk-EBEXWN3I.mjs +17 -0
- package/dist/chunk-EBEXWN3I.mjs.map +1 -0
- package/dist/chunk-G4JR3SFV.js +28 -0
- package/dist/chunk-G4JR3SFV.js.map +1 -0
- package/dist/chunk-IK65TDQH.js +15 -0
- package/dist/chunk-IK65TDQH.js.map +1 -0
- package/dist/{chunk-GHFMKH3M.js → chunk-JEQ34Z5E.js} +62 -38
- package/dist/chunk-JEQ34Z5E.js.map +1 -0
- package/dist/{chunk-YDPDJIJF.js → chunk-NFCXUAE6.js} +1330 -1184
- package/dist/chunk-NFCXUAE6.js.map +1 -0
- package/dist/chunk-OEOK6A3P.js +17 -0
- package/dist/chunk-OEOK6A3P.js.map +1 -0
- package/dist/chunk-PW42LRSL.mjs +28 -0
- package/dist/chunk-PW42LRSL.mjs.map +1 -0
- package/dist/{chunk-U65JPKO3.mjs → chunk-R6ZYB4VN.mjs} +2 -2
- package/dist/chunk-T7SAW3UW.mjs +15 -0
- package/dist/chunk-T7SAW3UW.mjs.map +1 -0
- package/dist/{chunk-GKDHYB2R.js → chunk-TWBZ2GSX.js} +3 -3
- package/dist/{chunk-GKDHYB2R.js.map → chunk-TWBZ2GSX.js.map} +1 -1
- package/dist/{chunk-26MQIJNB.js → chunk-WGVNJXZO.js} +4 -3
- package/dist/chunk-WGVNJXZO.js.map +1 -0
- package/dist/{chunk-2IMQ5IKA.mjs → chunk-WJC4SYRL.mjs} +2133 -1987
- package/dist/chunk-WJC4SYRL.mjs.map +1 -0
- package/dist/client/index.d.mts +3 -3
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +6 -5
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +13 -12
- package/dist/components/index.d.mts +16 -6
- package/dist/components/index.d.ts +16 -6
- package/dist/components/index.js +8 -5
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +9 -6
- package/dist/{config-3N1LSrcC.d.ts → config-B6UB7j69.d.ts} +1 -1
- package/dist/{config-BmufyEj6.d.mts → config-CEAq4Ozy.d.mts} +10 -1
- package/dist/{config-AVtuvfM1.d.ts → config-DydDHCfb.d.ts} +10 -1
- package/dist/{config-BSKTYDoh.d.mts → config-n-ZpPmOL.d.mts} +1 -1
- package/dist/contexts/index.d.mts +28 -4
- package/dist/contexts/index.d.ts +28 -4
- package/dist/contexts/index.js +10 -5
- package/dist/contexts/index.js.map +1 -1
- package/dist/contexts/index.mjs +9 -4
- package/dist/core/index.d.mts +6 -6
- package/dist/core/index.d.ts +6 -6
- package/dist/core/index.js +5 -5
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +4 -4
- package/dist/features/analytics/index.d.mts +2 -2
- package/dist/features/analytics/index.d.ts +2 -2
- package/dist/features/analytics/index.js +124 -123
- package/dist/features/analytics/index.js.map +1 -1
- package/dist/features/analytics/index.mjs +6 -5
- package/dist/features/analytics/index.mjs.map +1 -1
- package/dist/features/analytics/server.d.mts +10 -2
- package/dist/features/analytics/server.d.ts +10 -2
- package/dist/features/analytics/server.js +8 -6
- package/dist/features/analytics/server.js.map +1 -1
- package/dist/features/analytics/server.mjs +6 -4
- package/dist/features/analytics/server.mjs.map +1 -1
- package/dist/features/help/index.d.mts +2 -2
- package/dist/features/help/index.d.ts +2 -2
- package/dist/features/help/index.js +39 -38
- package/dist/features/help/index.js.map +1 -1
- package/dist/features/help/index.mjs +5 -4
- package/dist/features/help/index.mjs.map +1 -1
- package/dist/features/tokenusage/index.d.mts +2 -2
- package/dist/features/tokenusage/index.d.ts +2 -2
- package/dist/features/tokenusage/index.js +127 -126
- package/dist/features/tokenusage/index.js.map +1 -1
- package/dist/features/tokenusage/index.mjs +6 -5
- package/dist/features/tokenusage/index.mjs.map +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -9
- package/dist/next-config/index.d.mts +43 -0
- package/dist/next-config/index.d.ts +43 -0
- package/dist/next-config/index.js +230 -0
- package/dist/next-config/index.js.map +1 -0
- package/dist/next-config/index.mjs +230 -0
- package/dist/next-config/index.mjs.map +1 -0
- package/dist/{request-FXF63NSQ.mjs → request-3IUMNVOS.mjs} +2 -2
- package/dist/request-LZBAOT3Y.js +8 -0
- package/dist/request-LZBAOT3Y.js.map +1 -0
- package/dist/server/cachedGet.d.mts +28 -0
- package/dist/server/cachedGet.d.ts +28 -0
- package/dist/server/cachedGet.js +60 -0
- package/dist/server/cachedGet.js.map +1 -0
- package/dist/server/cachedGet.mjs +60 -0
- package/dist/server/cachedGet.mjs.map +1 -0
- package/dist/server/cachedGet.stub.d.mts +7 -0
- package/dist/server/cachedGet.stub.d.ts +7 -0
- package/dist/server/cachedGet.stub.js +17 -0
- package/dist/server/cachedGet.stub.js.map +1 -0
- package/dist/server/cachedGet.stub.mjs +17 -0
- package/dist/server/cachedGet.stub.mjs.map +1 -0
- package/dist/server/index.d.mts +27 -25
- package/dist/server/index.d.ts +27 -25
- package/dist/server/index.js +13 -6
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +15 -8
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/index.mjs.map +1 -1
- package/dist/{types-D0uLYV2P.d.mts → types-Bq_UA8Lg.d.mts} +1 -1
- package/dist/{types-Cn153-mH.d.ts → types-bsm8Fp55.d.ts} +1 -1
- package/dist/{usePageUrlGenerator-B-3FRKBD.d.ts → usePageUrlGenerator-J_ECv-oQ.d.ts} +1 -1
- package/dist/{usePageUrlGenerator-CCJ_cdQy.d.mts → usePageUrlGenerator-uKBjAKqC.d.mts} +1 -1
- package/package.json +12 -1
- package/src/components/forms/__tests__/EditorSheet.test.tsx +25 -1
- package/src/components/forms/__tests__/useEditorDialog.test.ts +164 -1
- package/src/components/forms/useEditorDialog.ts +69 -2
- package/src/contexts/SessionContext.tsx +20 -0
- package/src/contexts/SocketContext.tsx +30 -3
- package/src/contexts/ViewportContext.tsx +17 -2
- package/src/contexts/__tests__/SessionContext.test.tsx +58 -0
- package/src/contexts/__tests__/SocketContext.session.test.tsx +77 -0
- package/src/contexts/index.ts +1 -0
- package/src/core/abstracts/AbstractService.ts +4 -6
- package/src/core/abstracts/__tests__/AbstractService.locale.test.ts +64 -0
- package/src/features/analytics/components/server/AnalyticsAdminPage.tsx +5 -1
- package/src/features/analytics/components/server/AnalyticsJourneyPage.tsx +5 -1
- package/src/features/company/hooks/useSubscriptionStatus.ts +6 -1
- package/src/features/notification/contexts/NotificationContext.tsx +5 -2
- package/src/features/notification/contexts/__tests__/NotificationContext.spec.tsx +22 -0
- package/src/features/user/contexts/CurrentUserContext.tsx +7 -5
- package/src/features/user/contexts/__tests__/CurrentUserContext.spec.tsx +63 -3
- package/src/hooks/__tests__/useSocket.render.test.ts +22 -0
- package/src/hooks/useSocket.ts +0 -1
- package/src/i18n/__tests__/config.test.ts +27 -0
- package/src/i18n/config.ts +17 -0
- package/src/i18n/index.ts +2 -0
- package/src/next-config/__tests__/createNextConfig.test.ts +268 -0
- package/src/next-config/csp.ts +128 -0
- package/src/next-config/headers.ts +61 -0
- package/src/next-config/index.ts +114 -0
- package/src/server/JsonApiServer.ts +3 -1
- package/src/server/ServerSession.ts +29 -1
- package/src/server/__tests__/JsonApiServer.test.ts +41 -0
- package/src/server/__tests__/ServerSession.read.test.ts +67 -0
- package/src/server/__tests__/cache.test.ts +48 -0
- package/src/server/__tests__/cachedGet.test.ts +125 -0
- package/src/server/__tests__/request.test.ts +96 -1
- package/src/server/cache.ts +21 -4
- package/src/server/cacheDigest.ts +10 -0
- package/src/server/cacheProfiles.ts +15 -0
- package/src/server/cachedGet.stub.ts +15 -0
- package/src/server/cachedGet.ts +80 -0
- package/src/server/request.ts +33 -32
- package/src/shadcnui/ui/__tests__/sidebar.menu-skeleton.test.tsx +50 -0
- package/src/shadcnui/ui/__tests__/sidebar.session.test.tsx +133 -0
- package/src/shadcnui/ui/sidebar.tsx +121 -18
- package/src/testing/matchers/jsonApiMatchers.ts +1 -0
- package/src/unified/JsonApiRequest.ts +4 -1
- package/src/unified/__tests__/JsonApiGet.cache.test.ts +51 -0
- package/src/utils/__tests__/map-thenable.test.ts +29 -0
- package/src/utils/__tests__/use-mobile.test.tsx +102 -1
- package/src/utils/map-thenable.ts +15 -0
- package/src/utils/use-mobile.tsx +13 -4
- package/dist/BlockNoteEditor-ATZVHS6X.js.map +0 -1
- package/dist/JsonApiRequest-TE5WD3WS.js +0 -26
- package/dist/chunk-26MQIJNB.js.map +0 -1
- package/dist/chunk-2IMQ5IKA.mjs.map +0 -1
- package/dist/chunk-4Z45NYPR.js.map +0 -1
- package/dist/chunk-5TRFNKJS.js.map +0 -1
- package/dist/chunk-7B4E42R5.mjs.map +0 -1
- package/dist/chunk-CAKOFJZD.js.map +0 -1
- package/dist/chunk-E3I4MT53.mjs.map +0 -1
- package/dist/chunk-GHFMKH3M.js.map +0 -1
- package/dist/chunk-Q6J2ICKO.mjs.map +0 -1
- package/dist/chunk-SJLXPHK5.mjs.map +0 -1
- package/dist/chunk-YDPDJIJF.js.map +0 -1
- package/dist/request-ZTX6I63X.js +0 -8
- package/dist/request-ZTX6I63X.js.map +0 -1
- /package/dist/{BlockNoteViewer-KRTAFTUX.mjs.map → BlockNoteViewer-DQYT6IJW.mjs.map} +0 -0
- /package/dist/{JsonApiRequest-UHOWNI3O.mjs.map → JsonApiRequest-MEP6AXDT.mjs.map} +0 -0
- /package/dist/{chunk-U65JPKO3.mjs.map → chunk-R6ZYB4VN.mjs.map} +0 -0
- /package/dist/{request-FXF63NSQ.mjs.map → request-3IUMNVOS.mjs.map} +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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
|
+
|
|
3
|
+
var _chunk7QVYU63Ejs = require('./chunk-7QVYU63E.js');
|
|
4
|
+
|
|
5
|
+
// src/server/cacheDigest.ts
|
|
6
|
+
function statusFromDigest(error) {
|
|
7
|
+
const digest = _optionalChain([error, 'optionalAccess', _ => _.digest]);
|
|
8
|
+
if (typeof digest !== "string") return void 0;
|
|
9
|
+
const match = /^HTTP_(\d+)$/.exec(digest);
|
|
10
|
+
return match ? Number(match[1]) : void 0;
|
|
11
|
+
}
|
|
12
|
+
_chunk7QVYU63Ejs.__name.call(void 0, statusFromDigest, "statusFromDigest");
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
exports.statusFromDigest = statusFromDigest;
|
|
17
|
+
//# sourceMappingURL=chunk-OEOK6A3P.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/chunk-OEOK6A3P.js","../src/server/cacheDigest.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;ACAO,SAAS,gBAAA,CAAiB,KAAA,EAAoC;AACnE,EAAA,MAAM,OAAA,kBAAU,KAAA,2BAAmD,QAAA;AACnE,EAAA,GAAA,CAAI,OAAO,OAAA,IAAW,QAAA,EAAU,OAAO,KAAA,CAAA;AACvC,EAAA,MAAM,MAAA,EAAQ,cAAA,CAAe,IAAA,CAAK,MAAM,CAAA;AACxC,EAAA,OAAO,MAAA,EAAQ,MAAA,CAAO,KAAA,CAAM,CAAC,CAAC,EAAA,EAAI,KAAA,CAAA;AACpC;AALgB,qCAAA,gBAAA,EAAA,kBAAA,CAAA;ADQhB;AACA;AACE;AACF,4CAAC","file":"/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/chunk-OEOK6A3P.js","sourcesContent":[null,"// Shared by `cachedGet.ts` and its client stub, so `serverRequest` reads the status\n// back the same way whichever one the bundler resolved.\n\n/** Reads the HTTP status from an `HTTP_<status>` digest, or `undefined` when there is none. */\nexport function statusFromDigest(error: unknown): number | undefined {\n const digest = (error as { digest?: unknown } | null | undefined)?.digest;\n if (typeof digest !== \"string\") return undefined;\n const match = /^HTTP_(\\d+)$/.exec(digest);\n return match ? Number(match[1]) : undefined;\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-PAWJFY3S.mjs";
|
|
4
|
+
|
|
5
|
+
// src/roles/config.ts
|
|
6
|
+
var _roleId = null;
|
|
7
|
+
function configureRoles(roleId) {
|
|
8
|
+
_roleId = roleId;
|
|
9
|
+
}
|
|
10
|
+
__name(configureRoles, "configureRoles");
|
|
11
|
+
function getRoleId() {
|
|
12
|
+
if (!_roleId) {
|
|
13
|
+
throw new Error("Roles not configured. Call configureRoles() at app startup.");
|
|
14
|
+
}
|
|
15
|
+
return _roleId;
|
|
16
|
+
}
|
|
17
|
+
__name(getRoleId, "getRoleId");
|
|
18
|
+
function isRolesConfigured() {
|
|
19
|
+
return _roleId !== null;
|
|
20
|
+
}
|
|
21
|
+
__name(isRolesConfigured, "isRolesConfigured");
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
configureRoles,
|
|
25
|
+
getRoleId,
|
|
26
|
+
isRolesConfigured
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=chunk-PW42LRSL.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/roles/config.ts"],"sourcesContent":["/**\n * Role ID configuration interface\n * Apps provide their role IDs via configureRoles()\n */\nexport interface RoleIdConfig {\n Administrator: string;\n CompanyAdministrator: string;\n [key: string]: string; // Allow additional roles\n}\n\n// Private storage for the injected role IDs\nlet _roleId: RoleIdConfig | null = null;\n\n/**\n * Configure role IDs for the library\n * Call this at app startup to provide role ID constants\n *\n * @example\n * ```typescript\n * import { configureRoles } from \"@carlonicora/nextjs-jsonapi\";\n * import { RoleId } from \"@phlow/shared\";\n *\n * configureRoles(RoleId);\n * ```\n */\nexport function configureRoles(roleId: RoleIdConfig): void {\n _roleId = roleId;\n}\n\n/**\n * Get configured role IDs\n * @throws Error if roles not configured\n */\nexport function getRoleId(): RoleIdConfig {\n if (!_roleId) {\n throw new Error(\"Roles not configured. Call configureRoles() at app startup.\");\n }\n return _roleId;\n}\n\n/**\n * Check if roles have been configured\n */\nexport function isRolesConfigured(): boolean {\n return _roleId !== null;\n}\n"],"mappings":";;;;;AAWA,IAAI,UAA+B;AAc5B,SAAS,eAAe,QAA4B;AACzD,YAAU;AACZ;AAFgB;AAQT,SAAS,YAA0B;AACxC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,6DAA6D;AAAA,EAC/E;AACA,SAAO;AACT;AALgB;AAUT,SAAS,oBAA6B;AAC3C,SAAO,YAAY;AACrB;AAFgB;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getTokenUsageCurrency
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-AQZ3T4BR.mjs";
|
|
4
4
|
import {
|
|
5
5
|
__name
|
|
6
6
|
} from "./chunk-PAWJFY3S.mjs";
|
|
@@ -107,4 +107,4 @@ export {
|
|
|
107
107
|
SEQUENTIAL_RAMP,
|
|
108
108
|
seriesColor
|
|
109
109
|
};
|
|
110
|
-
//# sourceMappingURL=chunk-
|
|
110
|
+
//# sourceMappingURL=chunk-R6ZYB4VN.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/cacheProfiles.ts"],"sourcesContent":["// Plain constants, no `next/cache` import: `cachedGet.ts` reads them, and this file\n// keeps `revalidateTag`/`updateTag` (in `cache.ts`) out of every graph that loads it.\n\nexport type CacheProfile = \"seconds\" | \"minutes\" | \"hours\" | \"days\" | \"weeks\" | \"max\" | \"default\";\n\n/** The built-in `cacheLife` profile names. A module `cache` value outside this list is treated as a tag. */\nexport const CACHE_PROFILES: readonly CacheProfile[] = [\n \"seconds\",\n \"minutes\",\n \"hours\",\n \"days\",\n \"weeks\",\n \"max\",\n \"default\",\n];\n"],"mappings":";AAMO,IAAM,iBAA0C;AAAA,EACrD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
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
|
-
var
|
|
3
|
+
var _chunk6OFANJTEjs = require('./chunk-6OFANJTE.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunk7QVYU63Ejs = require('./chunk-7QVYU63E.js');
|
|
@@ -43,7 +43,7 @@ function createUsageFormatters(locale, currency) {
|
|
|
43
43
|
_chunk7QVYU63Ejs.__name.call(void 0, createUsageFormatters, "createUsageFormatters");
|
|
44
44
|
function useUsageFormatters() {
|
|
45
45
|
const locale = _nextintl.useLocale.call(void 0, );
|
|
46
|
-
const currency =
|
|
46
|
+
const currency = _chunk6OFANJTEjs.getTokenUsageCurrency.call(void 0, );
|
|
47
47
|
return _react.useMemo.call(void 0, () => createUsageFormatters(locale, currency), [locale, currency]);
|
|
48
48
|
}
|
|
49
49
|
_chunk7QVYU63Ejs.__name.call(void 0, useUsageFormatters, "useUsageFormatters");
|
|
@@ -107,4 +107,4 @@ _chunk7QVYU63Ejs.__name.call(void 0, seriesColor, "seriesColor");
|
|
|
107
107
|
|
|
108
108
|
|
|
109
109
|
exports.createUsageFormatters = createUsageFormatters; exports.useUsageFormatters = useUsageFormatters; exports.metricValue = metricValue; exports.cacheHitPercentage = cacheHitPercentage; exports.percentageDelta = percentageDelta; exports.CATEGORICAL_CEILING = CATEGORICAL_CEILING; exports.OTHER_COLOR = OTHER_COLOR; exports.SEQUENTIAL_RAMP = SEQUENTIAL_RAMP; exports.seriesColor = seriesColor;
|
|
110
|
-
//# sourceMappingURL=chunk-
|
|
110
|
+
//# sourceMappingURL=chunk-TWBZ2GSX.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/chunk-GKDHYB2R.js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S,MAAM,CAAA;AAEzC,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IAEA,WAAA,CAAY,KAAA,EAAO,MAAA,EAAQ;AACzB,MAAA,GAAA,CAAI,OAAA,IAAW,MAAA,EAAQ,OAAO,CAAA,EAAA;AAIJ,MAAA;AACH,MAAA;AACzB,IAAA;AAE0B,IAAA;AACI,MAAA;AAC9B,IAAA;AAE6B,IAAA;AACF,MAAA;AAC3B,IAAA;AAEe,IAAA;AACe,MAAA;AAC9B,IAAA;AAE6B,IAAA;AACd,MAAA;AACU,MAAA;AACzB,IAAA;AAEc,IAAA;AACgB,MAAA;AAC9B,IAAA;AACF,EAAA;AACF;AAnDgB;AA0DsC;AAC3B,EAAA;AACR,EAAA;AACI,EAAA;AACvB;AAJgB;ADlDqB;AACA;AEzBuC;AACxC,EAAA;AACD,EAAA;AACP,EAAA;AAC5B;AAJgB;AAUmC;AAC3B,EAAA;AACO,EAAA;AAC/B;AAHgB;AAYiC;AACzB,EAAA;AACQ,EAAA;AAChC;AAHgB;AFoBqB;AACA;AGwDQ;AAC3C,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACF;AAG4C;AAC1C,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACF;AAcmC;AAOR;AAcuB;AAUA;AAE3B;AAYsC;AACjC,EAAA;AACO,EAAA;AACnC;AAHgB;AHzGqB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/chunk-GKDHYB2R.js","sourcesContent":[null,"\"use client\";\n\nimport { useLocale } from \"next-intl\";\nimport { useMemo } from \"react\";\nimport type { Metric } from \"../data/tokenusage-admin.types\";\nimport { getTokenUsageCurrency } from \"./config\";\n\nexport type UsageFormatters = {\n /** Locale-aware fixed-decimal number, e.g. 9.46 → \"9,46\" in it-IT. */\n decimal(value: number, decimals: number): string;\n /** Currency for cost, 2 decimals for credits, whole numbers for tokens. */\n metricValue(value: number, metric: Metric): string;\n /** Currency with an explicit decimal count — the per-call tile needs 4. */\n currency(value: number, decimals: number): string;\n /** Percentage with one decimal by default, e.g. 60 → \"60,0 %\" in it-IT. */\n percent(value: number, decimals?: number): string;\n /** Compact notation for axis ticks, e.g. 1500000 → \"1,5 Mln\" in it-IT. */\n compact(value: number): string;\n /** A \"YYYY-MM-DD\" bucket key rendered as an axis or tooltip label, in UTC. */\n bucketDate(iso: string, granularity: \"day\" | \"week\" | \"month\"): string;\n /** Locale collation for client-side table sorting. */\n compare(a: string, b: string): number;\n};\n\n/**\n * Builds every formatter the token-usage surfaces need, for one locale and one\n * currency.\n *\n * A pure factory on purpose: it takes no React context, so the arithmetic and\n * the formatting are unit-testable without rendering, and a server component or\n * a test can construct a set for an arbitrary locale.\n *\n * The currency symbol is placed with a space rather than through\n * `style: \"currency\"`, which is what the previous hard-coded implementation\n * rendered (\"€ 9,46\"). Keeping that shape means a consuming app on EUR sees\n * byte-identical output after this refactor.\n *\n * `bucketDate` formats in UTC, always. The wire value is a `type: \"date\"` — a\n * calendar day — parsed to UTC midnight; reading it back with local getters\n * would shift the label a day early west of UTC.\n */\nexport function createUsageFormatters(locale: string, currency: string): UsageFormatters {\n const symbol =\n new Intl.NumberFormat(locale, { style: \"currency\", currency, currencyDisplay: \"narrowSymbol\" })\n .formatToParts(0)\n .find((part) => part.type === \"currency\")?.value ?? currency;\n\n const decimal = (value: number, decimals: number): string =>\n value.toLocaleString(locale, { minimumFractionDigits: decimals, maximumFractionDigits: decimals });\n\n const dayFormat = new Intl.DateTimeFormat(locale, { day: \"numeric\", month: \"short\", timeZone: \"UTC\" });\n const monthFormat = new Intl.DateTimeFormat(locale, { month: \"short\", year: \"numeric\", timeZone: \"UTC\" });\n // Axis ticks step by 1, 2, 2.5 or 5 times a power of ten, so a tick never needs\n // more than three significant digits. A fixed one-decimal cap rounded a 0.05\n // step into repeated labels (0.1, 0.1, 0.2, 0.2); significant digits keep every\n // tick distinct at any scale (0.05, 0.15, 1.25K).\n const compactFormat = new Intl.NumberFormat(locale, { notation: \"compact\", maximumSignificantDigits: 3 });\n const collator = new Intl.Collator(locale);\n\n return {\n decimal,\n\n metricValue(value, metric) {\n if (metric === \"cost\") return `${symbol} ${decimal(value, 2)}`;\n // Credits are stored to 4 decimals (round4(cost / creditCost)), but that\n // precision is noise to a reader comparing rows: one decimal is enough to\n // separate two values and keeps the columns narrow enough to scan.\n if (metric === \"credits\") return decimal(value, 1);\n return decimal(value, 0);\n },\n\n currency(value, decimals) {\n return `${symbol} ${decimal(value, decimals)}`;\n },\n\n percent(value, decimals = 1) {\n return `${decimal(value, decimals)} %`;\n },\n\n compact(value) {\n return compactFormat.format(value);\n },\n\n bucketDate(iso, granularity) {\n const date = new Date(`${iso}T00:00:00.000Z`);\n return granularity === \"month\" ? monthFormat.format(date) : dayFormat.format(date);\n },\n\n compare(a, b) {\n return collator.compare(a, b);\n },\n };\n}\n\n/**\n * The formatter set for the current request's locale and the app's configured\n * currency. Memoised on both, so the Intl objects are built once per locale\n * rather than on every render.\n */\nexport function useUsageFormatters(): UsageFormatters {\n const locale = useLocale();\n const currency = getTokenUsageCurrency();\n return useMemo(() => createUsageFormatters(locale, currency), [locale, currency]);\n}\n","import type { Metric } from \"../data/tokenusage-admin.types\";\n\n/**\n * Locale-free arithmetic for the token-usage surfaces.\n *\n * Everything that turns a number into a STRING lives in `./formatters` instead,\n * because it depends on the request's locale and the app's configured currency.\n * This file stays pure arithmetic so it needs neither.\n */\n\n/**\n * The metric field set every admin token-usage resource carries. Declared\n * structurally so it accepts the summary, timeline and breakdown interfaces\n * alike — all three expose exactly these getters.\n */\nexport type TokenUsageMetrics = {\n cost: number;\n credits: number;\n tokensIn: number;\n tokensOut: number;\n cached: number;\n calls: number;\n};\n\n/** Reads the single number a row contributes for the currently selected metric. */\nexport function metricValue(row: TokenUsageMetrics, metric: Metric): number {\n if (metric === \"cost\") return row.cost;\n if (metric === \"credits\") return row.credits;\n return row.tokensIn + row.tokensOut;\n}\n\n/**\n * Share of cached input tokens. Returns 0 rather than NaN when the window holds\n * no input tokens at all, so the tile renders \"0,0 %\" instead of \"NaN %\".\n */\nexport function cacheHitPercentage(cached: number, tokensIn: number): number {\n if (!tokensIn) return 0;\n return (cached / tokensIn) * 100;\n}\n\n/**\n * Percentage change of `current` against `previous`, rounded to a whole number.\n *\n * Returns `undefined` when the previous window is zero — there is no meaningful\n * percentage change from nothing, and rendering Infinity would be worse than\n * rendering nothing. Callers show an em dash in that slot.\n */\nexport function percentageDelta(current: number, previous: number): number | undefined {\n if (!previous) return undefined;\n return Math.round(((current - previous) / previous) * 100);\n}\n","/**\n * Chart palette for the administrative token-usage dashboard.\n *\n * Every value here is a documented step of the dataviz skill's reference ramps —\n * nothing was eyeballed, nothing was hand-mixed. The palette was run through the\n * skill's validator against THIS application's real chart surfaces in both modes.\n * The verbatim output is below.\n *\n * The surface is `--card`, NOT `--background`. Every chart that uses this palette\n * is painted inside a `<Card>`, so the card is the surface the marks actually sit\n * on — and in dark mode it is the *lighter* of the two (`oklch(0.205 0 0)` vs the\n * background's `oklch(0.145 0 0)`), which is the harder case for contrast. Taken\n * from `apps/web/src/app/globals.css` (narr8 declares two `:root`/`.dark` pairs;\n * the LATER pair wins, and it is the one read here) — light `oklch(1 0 0)`, dark\n * `oklch(0.205 0 0)`. a360ai declares the same two values.\n *\n * oklch→hex conversion: the algebraic inverse of the Björn Ottosson OKLab\n * matrices — the same matrices the validator applies in the forward direction —\n * giving light `#ffffff` and dark `#171717`. Cross-checked by feeding it the\n * previously recorded background value, which it reproduces exactly:\n * `oklch(0.145 0 0)` → `#0a0a0a`. ✓\n *\n * Light and dark are two SELECTED sets of steps, chosen for their own surface —\n * never one set with its lightness flipped at runtime. Consumers pick a set from\n * the resolved theme (`seriesColor(i, mode)` / `sequentialColor(i, mode)`).\n *\n * ---------------------------------------------------------------------------\n * VALIDATOR OUTPUT — dataviz `scripts/validate_palette.js`, run 2026-08-15\n * ---------------------------------------------------------------------------\n *\n * $ node scripts/validate_palette.js \"#2a78d6,#eb6834,#1baf7a,#eda100,#e87ba4,#008300,#4a3aa7\" --mode light --surface \"#ffffff\"\n *\n * Palette (light, surface #ffffff, categorical): 7 slots\n * [PASS] Lightness band all 7 inside L 0.43–0.77\n * [PASS] Chroma floor all 7 >= 0.1\n * [PASS] CVD separation worst adjacent #eda100↔#1baf7a ΔE 9.1 (protan) · tritan 5.8\n * [PASS] Normal-vision floor worst adjacent #e87ba4↔#eda100 ΔE 19.6 (normal)\n * [WARN] Contrast vs surface below 3:1 — relief required (visible labels or table view): [[\"#1baf7a\",2.82],[\"#eda100\",2.17],[\"#e87ba4\",2.69]]\n *\n * → ALL CHECKS PASS (CVD in the 6–8 floor band is legal ONLY with secondary encoding: direct labels, gaps, or texture)\n * scope: categorical palettes only. For a lone status/text color check WCAG text contrast; for a sequential ramp, lightness monotonicity.\n *\n * $ node scripts/validate_palette.js \"#3987e5,#d95926,#199e70,#c98500,#d55181,#008300,#9085e9\" --mode dark --surface \"#171717\"\n *\n * Palette (dark, surface #171717, categorical): 7 slots\n * [PASS] Lightness band all 7 inside L 0.48–0.67\n * [PASS] Chroma floor all 7 >= 0.1\n * [PASS] CVD separation worst adjacent #c98500↔#199e70 ΔE 8.4 (protan) · tritan 8.7\n * [PASS] Normal-vision floor worst adjacent #d55181↔#c98500 ΔE 19.3 (normal)\n * [PASS] Contrast vs surface all 7 >= 3:1\n *\n * → ALL CHECKS PASS (CVD in the 6–8 floor band is legal ONLY with secondary encoding: direct labels, gaps, or texture)\n * scope: categorical palettes only. For a lone status/text color check WCAG text contrast; for a sequential ramp, lightness monotonicity.\n *\n * $ node scripts/validate_palette.js \"#104281,#1c5cab,#2a78d6,#5598e7,#86b6ef\" --mode light --surface \"#ffffff\" --ordinal\n *\n * Palette (light, surface #ffffff, ordinal ramp): 5 slots\n * [PASS] Lightness monotone steps read light→dark\n * [PASS] Adjacent ΔL all gaps >= 0.06\n * [PASS] Light-end contrast #86b6ef at 2.11:1 vs surface\n * [PASS] Single hue hue spread 3°\n *\n * → ALL CHECKS PASS (ordinal: one hue, monotone L, visible step gaps, light end clears surface)\n *\n * $ node scripts/validate_palette.js \"#9ec5f4,#6da7ec,#3987e5,#256abf,#184f95\" --mode dark --surface \"#171717\" --ordinal\n *\n * Palette (dark, surface #171717, ordinal ramp): 5 slots\n * [PASS] Lightness monotone steps read light→dark\n * [PASS] Adjacent ΔL all gaps >= 0.06\n * [PASS] Light-end contrast #184f95 at 2.21:1 vs surface\n * [PASS] Single hue hue spread 3°\n *\n * → ALL CHECKS PASS (ordinal: one hue, monotone L, visible step gaps, light end clears surface)\n *\n * OTHER_COLOR is achromatic, so the categorical checks (which gate hue identity)\n * do not apply to it; it was gated on contrast alone with the validator's own\n * `contrast()` export: 3.59:1 on `#ffffff`, 4.99:1 on `#171717` — both clear 3:1.\n *\n * ---------------------------------------------------------------------------\n * WHAT THE RESULTS OBLIGE US TO DO\n * ---------------------------------------------------------------------------\n *\n * - NO COLOUR VALUE CHANGED in the move from `--background` to `--card`. Every\n * gate that passed on the background still passes on the card, so re-stepping\n * a hue would have been churn, not a fix. Only the recorded surface, the\n * recorded numbers and this prose changed.\n * - The dark set still clears 3:1 on the LIGHTER card surface: the worst slot is\n * green `#008300` at 3.63:1, and the ordinal ramp's surface-nearest step lands\n * at 2.21:1 (down from 2.44:1 on the background) — still above the 2:1 gate.\n * That headroom is thin, so a future card-surface lightening MUST re-run these\n * four commands rather than assume the set still holds.\n * - The light-mode contrast WARN is NOT dismissable. Three slots (aqua, yellow,\n * magenta) sit below 3:1 on white, so every surface that paints with this\n * palette MUST ship the relief channel: a visible legend, direct labels and a\n * tooltip carrying the value in text. The timeline chart and the breakdown\n * table both do. The light card is `#ffffff`, identical to the light\n * background, so this WARN is unchanged rather than newly incurred.\n * - CVD separation is measured on ADJACENT pairs, which is the correct pairlist\n * for stacked bars, grouped bars and lines — the only forms this palette paints.\n * A scatter / bubble / small-multiples chart would need `--pairs all`, which\n * caps the usable slot count at three; do not reuse this array there without\n * re-running the validator with that flag.\n */\n\n/** Which surface the colours are being painted on. */\nexport type ChartMode = \"light\" | \"dark\";\n\n/**\n * The chart surfaces the palette was validated against (globals.css `--card`).\n *\n * `--card`, never `--background`: the charts are painted inside a `<Card>`.\n */\nexport const CHART_SURFACE: Readonly<Record<ChartMode, string>> = {\n light: \"#ffffff\",\n dark: \"#171717\",\n};\n\n/**\n * Categorical slots, in FIXED order. Slot n is series n — the order is the\n * CVD-safety mechanism, not decoration, so it is never re-ordered and never\n * cycled. The two-series default (customer / platform) takes slots 0 and 1.\n *\n * Hues, in order: blue, orange, aqua, yellow, magenta, green, violet.\n */\nconst CATEGORICAL_LIGHT: readonly string[] = [\n \"#2a78d6\",\n \"#eb6834\",\n \"#1baf7a\",\n \"#eda100\",\n \"#e87ba4\",\n \"#008300\",\n \"#4a3aa7\",\n];\n\n/** The same seven hues, re-stepped for the dark surface. Not a lightness flip. */\nconst CATEGORICAL_DARK: readonly string[] = [\n \"#3987e5\",\n \"#d95926\",\n \"#199e70\",\n \"#c98500\",\n \"#d55181\",\n \"#008300\",\n \"#9085e9\",\n];\n\n/**\n * The default (light-surface) categorical set.\n *\n * Prefer `seriesColor(index, mode)` — this array exists for consumers that only\n * need the documented default order.\n */\nexport const CATEGORICAL: readonly string[] = CATEGORICAL_LIGHT;\n\n/**\n * How many series may carry their own identity hue. An 8th series is NEVER a\n * generated hue: it folds into `other`.\n */\nexport const CATEGORICAL_CEILING = CATEGORICAL_LIGHT.length;\n\n/**\n * The \"other\" rollup colour: deliberately achromatic so it reads as \"not an\n * identity\" beside the seven hues. Same step in both modes — it clears 3:1 on\n * both card surfaces (3.59:1 on `#ffffff`, 4.99:1 on `#171717`).\n */\nexport const OTHER_COLOR = \"#898781\";\n\n/**\n * Sequential (single-hue, blue) ramp for MAGNITUDE, indexed by rank position:\n * index 0 is rank 1 — the largest value — so the strongest step leads.\n *\n * On the light surface \"strongest\" is the darkest step; on the dark surface it\n * is the lightest. The anchor flips with the surface, which is why there are two\n * selected sets rather than one array reversed at runtime.\n *\n * Five steps, not eight: with the adjacent-ΔL ≥ 0.06 gate and the ≥ 2:1\n * surface-contrast gate on the step nearest the surface, the blue ramp fits\n * exactly five distinguishable steps. Consumers clamp past the end.\n */\nconst SEQUENTIAL_RAMP_LIGHT: readonly string[] = [\"#104281\", \"#1c5cab\", \"#2a78d6\", \"#5598e7\", \"#86b6ef\"];\n\nconst SEQUENTIAL_RAMP_DARK: readonly string[] = [\"#9ec5f4\", \"#6da7ec\", \"#3987e5\", \"#256abf\", \"#184f95\"];\n\n/**\n * The default (light-surface) sequential ramp.\n *\n * Prefer `sequentialColor(index, mode)` — this array exists for consumers that\n * only need the documented default.\n */\nexport const SEQUENTIAL_RAMP: readonly string[] = SEQUENTIAL_RAMP_LIGHT;\n\nconst categoricalSet = (mode: ChartMode): readonly string[] => (mode === \"dark\" ? CATEGORICAL_DARK : CATEGORICAL_LIGHT);\n\nconst sequentialSet = (mode: ChartMode): readonly string[] =>\n mode === \"dark\" ? SEQUENTIAL_RAMP_DARK : SEQUENTIAL_RAMP_LIGHT;\n\n/**\n * The identity colour for series `index`.\n *\n * Never generates a hue and never cycles: anything at or past the ceiling gets\n * `OTHER_COLOR`, because a series past the ceiling should already have been\n * folded into the \"other\" bucket by the caller.\n */\nexport function seriesColor(index: number, mode: ChartMode = \"light\"): string {\n if (index < 0 || index >= CATEGORICAL_CEILING) return OTHER_COLOR;\n return categoricalSet(mode)[index];\n}\n\n/**\n * Both mode steps for series `index`, shaped for a shadcn `ChartConfig` entry's\n * `theme` field.\n */\nexport function seriesTheme(index: number): { light: string; dark: string } {\n return { light: seriesColor(index, \"light\"), dark: seriesColor(index, \"dark\") };\n}\n\n/**\n * The magnitude colour for rank position `index`, clamped to the last step so a\n * long list keeps its weakest step rather than falling off the ramp.\n */\nexport function sequentialColor(index: number, mode: ChartMode = \"light\"): string {\n const ramp = sequentialSet(mode);\n const clamped = Math.min(Math.max(index, 0), ramp.length - 1);\n return ramp[clamped];\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/chunk-TWBZ2GSX.js","../src/features/tokenusage/lib/formatters.ts","../src/features/tokenusage/lib/metrics.ts","../src/features/tokenusage/lib/palette.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACLA,qCAA0B;AAC1B,8BAAwB;AAsCjB,SAAS,qBAAA,CAAsB,MAAA,EAAgB,QAAA,EAAmC;AACvF,EAAA,MAAM,OAAA,mCACJ,IAAI,IAAA,CAAK,YAAA,CAAa,MAAA,EAAQ,EAAE,KAAA,EAAO,UAAA,EAAY,QAAA,EAAU,eAAA,EAAiB,eAAe,CAAC,CAAA,mBAC3F,aAAA,mBAAc,CAAC,CAAA,qBACf,IAAA,mBAAK,CAAC,IAAA,EAAA,GAAS,IAAA,CAAK,KAAA,IAAS,UAAU,CAAA,6BAAG,OAAA,UAAS,UAAA;AAExD,EAAA,MAAM,QAAA,kBAAU,qCAAA,CAAC,KAAA,EAAe,QAAA,EAAA,GAC9B,KAAA,CAAM,cAAA,CAAe,MAAA,EAAQ,EAAE,qBAAA,EAAuB,QAAA,EAAU,qBAAA,EAAuB,SAAS,CAAC,CAAA,EADnF,SAAA,CAAA;AAGhB,EAAA,MAAM,UAAA,EAAY,IAAI,IAAA,CAAK,cAAA,CAAe,MAAA,EAAQ,EAAE,GAAA,EAAK,SAAA,EAAW,KAAA,EAAO,OAAA,EAAS,QAAA,EAAU,MAAM,CAAC,CAAA;AACrG,EAAA,MAAM,YAAA,EAAc,IAAI,IAAA,CAAK,cAAA,CAAe,MAAA,EAAQ,EAAE,KAAA,EAAO,OAAA,EAAS,IAAA,EAAM,SAAA,EAAW,QAAA,EAAU,MAAM,CAAC,CAAA;AAKxG,EAAA,MAAM,cA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\nimport { useLocale } from \"next-intl\";\nimport { useMemo } from \"react\";\nimport type { Metric } from \"../data/tokenusage-admin.types\";\nimport { getTokenUsageCurrency } from \"./config\";\n\nexport type UsageFormatters = {\n /** Locale-aware fixed-decimal number, e.g. 9.46 → \"9,46\" in it-IT. */\n decimal(value: number, decimals: number): string;\n /** Currency for cost, 2 decimals for credits, whole numbers for tokens. */\n metricValue(value: number, metric: Metric): string;\n /** Currency with an explicit decimal count — the per-call tile needs 4. */\n currency(value: number, decimals: number): string;\n /** Percentage with one decimal by default, e.g. 60 → \"60,0 %\" in it-IT. */\n percent(value: number, decimals?: number): string;\n /** Compact notation for axis ticks, e.g. 1500000 → \"1,5 Mln\" in it-IT. */\n compact(value: number): string;\n /** A \"YYYY-MM-DD\" bucket key rendered as an axis or tooltip label, in UTC. */\n bucketDate(iso: string, granularity: \"day\" | \"week\" | \"month\"): string;\n /** Locale collation for client-side table sorting. */\n compare(a: string, b: string): number;\n};\n\n/**\n * Builds every formatter the token-usage surfaces need, for one locale and one\n * currency.\n *\n * A pure factory on purpose: it takes no React context, so the arithmetic and\n * the formatting are unit-testable without rendering, and a server component or\n * a test can construct a set for an arbitrary locale.\n *\n * The currency symbol is placed with a space rather than through\n * `style: \"currency\"`, which is what the previous hard-coded implementation\n * rendered (\"€ 9,46\"). Keeping that shape means a consuming app on EUR sees\n * byte-identical output after this refactor.\n *\n * `bucketDate` formats in UTC, always. The wire value is a `type: \"date\"` — a\n * calendar day — parsed to UTC midnight; reading it back with local getters\n * would shift the label a day early west of UTC.\n */\nexport function createUsageFormatters(locale: string, currency: string): UsageFormatters {\n const symbol =\n new Intl.NumberFormat(locale, { style: \"currency\", currency, currencyDisplay: \"narrowSymbol\" })\n .formatToParts(0)\n .find((part) => part.type === \"currency\")?.value ?? currency;\n\n const decimal = (value: number, decimals: number): string =>\n value.toLocaleString(locale, { minimumFractionDigits: decimals, maximumFractionDigits: decimals });\n\n const dayFormat = new Intl.DateTimeFormat(locale, { day: \"numeric\", month: \"short\", timeZone: \"UTC\" });\n const monthFormat = new Intl.DateTimeFormat(locale, { month: \"short\", year: \"numeric\", timeZone: \"UTC\" });\n // Axis ticks step by 1, 2, 2.5 or 5 times a power of ten, so a tick never needs\n // more than three significant digits. A fixed one-decimal cap rounded a 0.05\n // step into repeated labels (0.1, 0.1, 0.2, 0.2); significant digits keep every\n // tick distinct at any scale (0.05, 0.15, 1.25K).\n const compactFormat = new Intl.NumberFormat(locale, { notation: \"compact\", maximumSignificantDigits: 3 });\n const collator = new Intl.Collator(locale);\n\n return {\n decimal,\n\n metricValue(value, metric) {\n if (metric === \"cost\") return `${symbol} ${decimal(value, 2)}`;\n // Credits are stored to 4 decimals (round4(cost / creditCost)), but that\n // precision is noise to a reader comparing rows: one decimal is enough to\n // separate two values and keeps the columns narrow enough to scan.\n if (metric === \"credits\") return decimal(value, 1);\n return decimal(value, 0);\n },\n\n currency(value, decimals) {\n return `${symbol} ${decimal(value, decimals)}`;\n },\n\n percent(value, decimals = 1) {\n return `${decimal(value, decimals)} %`;\n },\n\n compact(value) {\n return compactFormat.format(value);\n },\n\n bucketDate(iso, granularity) {\n const date = new Date(`${iso}T00:00:00.000Z`);\n return granularity === \"month\" ? monthFormat.format(date) : dayFormat.format(date);\n },\n\n compare(a, b) {\n return collator.compare(a, b);\n },\n };\n}\n\n/**\n * The formatter set for the current request's locale and the app's configured\n * currency. Memoised on both, so the Intl objects are built once per locale\n * rather than on every render.\n */\nexport function useUsageFormatters(): UsageFormatters {\n const locale = useLocale();\n const currency = getTokenUsageCurrency();\n return useMemo(() => createUsageFormatters(locale, currency), [locale, currency]);\n}\n","import type { Metric } from \"../data/tokenusage-admin.types\";\n\n/**\n * Locale-free arithmetic for the token-usage surfaces.\n *\n * Everything that turns a number into a STRING lives in `./formatters` instead,\n * because it depends on the request's locale and the app's configured currency.\n * This file stays pure arithmetic so it needs neither.\n */\n\n/**\n * The metric field set every admin token-usage resource carries. Declared\n * structurally so it accepts the summary, timeline and breakdown interfaces\n * alike — all three expose exactly these getters.\n */\nexport type TokenUsageMetrics = {\n cost: number;\n credits: number;\n tokensIn: number;\n tokensOut: number;\n cached: number;\n calls: number;\n};\n\n/** Reads the single number a row contributes for the currently selected metric. */\nexport function metricValue(row: TokenUsageMetrics, metric: Metric): number {\n if (metric === \"cost\") return row.cost;\n if (metric === \"credits\") return row.credits;\n return row.tokensIn + row.tokensOut;\n}\n\n/**\n * Share of cached input tokens. Returns 0 rather than NaN when the window holds\n * no input tokens at all, so the tile renders \"0,0 %\" instead of \"NaN %\".\n */\nexport function cacheHitPercentage(cached: number, tokensIn: number): number {\n if (!tokensIn) return 0;\n return (cached / tokensIn) * 100;\n}\n\n/**\n * Percentage change of `current` against `previous`, rounded to a whole number.\n *\n * Returns `undefined` when the previous window is zero — there is no meaningful\n * percentage change from nothing, and rendering Infinity would be worse than\n * rendering nothing. Callers show an em dash in that slot.\n */\nexport function percentageDelta(current: number, previous: number): number | undefined {\n if (!previous) return undefined;\n return Math.round(((current - previous) / previous) * 100);\n}\n","/**\n * Chart palette for the administrative token-usage dashboard.\n *\n * Every value here is a documented step of the dataviz skill's reference ramps —\n * nothing was eyeballed, nothing was hand-mixed. The palette was run through the\n * skill's validator against THIS application's real chart surfaces in both modes.\n * The verbatim output is below.\n *\n * The surface is `--card`, NOT `--background`. Every chart that uses this palette\n * is painted inside a `<Card>`, so the card is the surface the marks actually sit\n * on — and in dark mode it is the *lighter* of the two (`oklch(0.205 0 0)` vs the\n * background's `oklch(0.145 0 0)`), which is the harder case for contrast. Taken\n * from `apps/web/src/app/globals.css` (narr8 declares two `:root`/`.dark` pairs;\n * the LATER pair wins, and it is the one read here) — light `oklch(1 0 0)`, dark\n * `oklch(0.205 0 0)`. a360ai declares the same two values.\n *\n * oklch→hex conversion: the algebraic inverse of the Björn Ottosson OKLab\n * matrices — the same matrices the validator applies in the forward direction —\n * giving light `#ffffff` and dark `#171717`. Cross-checked by feeding it the\n * previously recorded background value, which it reproduces exactly:\n * `oklch(0.145 0 0)` → `#0a0a0a`. ✓\n *\n * Light and dark are two SELECTED sets of steps, chosen for their own surface —\n * never one set with its lightness flipped at runtime. Consumers pick a set from\n * the resolved theme (`seriesColor(i, mode)` / `sequentialColor(i, mode)`).\n *\n * ---------------------------------------------------------------------------\n * VALIDATOR OUTPUT — dataviz `scripts/validate_palette.js`, run 2026-08-15\n * ---------------------------------------------------------------------------\n *\n * $ node scripts/validate_palette.js \"#2a78d6,#eb6834,#1baf7a,#eda100,#e87ba4,#008300,#4a3aa7\" --mode light --surface \"#ffffff\"\n *\n * Palette (light, surface #ffffff, categorical): 7 slots\n * [PASS] Lightness band all 7 inside L 0.43–0.77\n * [PASS] Chroma floor all 7 >= 0.1\n * [PASS] CVD separation worst adjacent #eda100↔#1baf7a ΔE 9.1 (protan) · tritan 5.8\n * [PASS] Normal-vision floor worst adjacent #e87ba4↔#eda100 ΔE 19.6 (normal)\n * [WARN] Contrast vs surface below 3:1 — relief required (visible labels or table view): [[\"#1baf7a\",2.82],[\"#eda100\",2.17],[\"#e87ba4\",2.69]]\n *\n * → ALL CHECKS PASS (CVD in the 6–8 floor band is legal ONLY with secondary encoding: direct labels, gaps, or texture)\n * scope: categorical palettes only. For a lone status/text color check WCAG text contrast; for a sequential ramp, lightness monotonicity.\n *\n * $ node scripts/validate_palette.js \"#3987e5,#d95926,#199e70,#c98500,#d55181,#008300,#9085e9\" --mode dark --surface \"#171717\"\n *\n * Palette (dark, surface #171717, categorical): 7 slots\n * [PASS] Lightness band all 7 inside L 0.48–0.67\n * [PASS] Chroma floor all 7 >= 0.1\n * [PASS] CVD separation worst adjacent #c98500↔#199e70 ΔE 8.4 (protan) · tritan 8.7\n * [PASS] Normal-vision floor worst adjacent #d55181↔#c98500 ΔE 19.3 (normal)\n * [PASS] Contrast vs surface all 7 >= 3:1\n *\n * → ALL CHECKS PASS (CVD in the 6–8 floor band is legal ONLY with secondary encoding: direct labels, gaps, or texture)\n * scope: categorical palettes only. For a lone status/text color check WCAG text contrast; for a sequential ramp, lightness monotonicity.\n *\n * $ node scripts/validate_palette.js \"#104281,#1c5cab,#2a78d6,#5598e7,#86b6ef\" --mode light --surface \"#ffffff\" --ordinal\n *\n * Palette (light, surface #ffffff, ordinal ramp): 5 slots\n * [PASS] Lightness monotone steps read light→dark\n * [PASS] Adjacent ΔL all gaps >= 0.06\n * [PASS] Light-end contrast #86b6ef at 2.11:1 vs surface\n * [PASS] Single hue hue spread 3°\n *\n * → ALL CHECKS PASS (ordinal: one hue, monotone L, visible step gaps, light end clears surface)\n *\n * $ node scripts/validate_palette.js \"#9ec5f4,#6da7ec,#3987e5,#256abf,#184f95\" --mode dark --surface \"#171717\" --ordinal\n *\n * Palette (dark, surface #171717, ordinal ramp): 5 slots\n * [PASS] Lightness monotone steps read light→dark\n * [PASS] Adjacent ΔL all gaps >= 0.06\n * [PASS] Light-end contrast #184f95 at 2.21:1 vs surface\n * [PASS] Single hue hue spread 3°\n *\n * → ALL CHECKS PASS (ordinal: one hue, monotone L, visible step gaps, light end clears surface)\n *\n * OTHER_COLOR is achromatic, so the categorical checks (which gate hue identity)\n * do not apply to it; it was gated on contrast alone with the validator's own\n * `contrast()` export: 3.59:1 on `#ffffff`, 4.99:1 on `#171717` — both clear 3:1.\n *\n * ---------------------------------------------------------------------------\n * WHAT THE RESULTS OBLIGE US TO DO\n * ---------------------------------------------------------------------------\n *\n * - NO COLOUR VALUE CHANGED in the move from `--background` to `--card`. Every\n * gate that passed on the background still passes on the card, so re-stepping\n * a hue would have been churn, not a fix. Only the recorded surface, the\n * recorded numbers and this prose changed.\n * - The dark set still clears 3:1 on the LIGHTER card surface: the worst slot is\n * green `#008300` at 3.63:1, and the ordinal ramp's surface-nearest step lands\n * at 2.21:1 (down from 2.44:1 on the background) — still above the 2:1 gate.\n * That headroom is thin, so a future card-surface lightening MUST re-run these\n * four commands rather than assume the set still holds.\n * - The light-mode contrast WARN is NOT dismissable. Three slots (aqua, yellow,\n * magenta) sit below 3:1 on white, so every surface that paints with this\n * palette MUST ship the relief channel: a visible legend, direct labels and a\n * tooltip carrying the value in text. The timeline chart and the breakdown\n * table both do. The light card is `#ffffff`, identical to the light\n * background, so this WARN is unchanged rather than newly incurred.\n * - CVD separation is measured on ADJACENT pairs, which is the correct pairlist\n * for stacked bars, grouped bars and lines — the only forms this palette paints.\n * A scatter / bubble / small-multiples chart would need `--pairs all`, which\n * caps the usable slot count at three; do not reuse this array there without\n * re-running the validator with that flag.\n */\n\n/** Which surface the colours are being painted on. */\nexport type ChartMode = \"light\" | \"dark\";\n\n/**\n * The chart surfaces the palette was validated against (globals.css `--card`).\n *\n * `--card`, never `--background`: the charts are painted inside a `<Card>`.\n */\nexport const CHART_SURFACE: Readonly<Record<ChartMode, string>> = {\n light: \"#ffffff\",\n dark: \"#171717\",\n};\n\n/**\n * Categorical slots, in FIXED order. Slot n is series n — the order is the\n * CVD-safety mechanism, not decoration, so it is never re-ordered and never\n * cycled. The two-series default (customer / platform) takes slots 0 and 1.\n *\n * Hues, in order: blue, orange, aqua, yellow, magenta, green, violet.\n */\nconst CATEGORICAL_LIGHT: readonly string[] = [\n \"#2a78d6\",\n \"#eb6834\",\n \"#1baf7a\",\n \"#eda100\",\n \"#e87ba4\",\n \"#008300\",\n \"#4a3aa7\",\n];\n\n/** The same seven hues, re-stepped for the dark surface. Not a lightness flip. */\nconst CATEGORICAL_DARK: readonly string[] = [\n \"#3987e5\",\n \"#d95926\",\n \"#199e70\",\n \"#c98500\",\n \"#d55181\",\n \"#008300\",\n \"#9085e9\",\n];\n\n/**\n * The default (light-surface) categorical set.\n *\n * Prefer `seriesColor(index, mode)` — this array exists for consumers that only\n * need the documented default order.\n */\nexport const CATEGORICAL: readonly string[] = CATEGORICAL_LIGHT;\n\n/**\n * How many series may carry their own identity hue. An 8th series is NEVER a\n * generated hue: it folds into `other`.\n */\nexport const CATEGORICAL_CEILING = CATEGORICAL_LIGHT.length;\n\n/**\n * The \"other\" rollup colour: deliberately achromatic so it reads as \"not an\n * identity\" beside the seven hues. Same step in both modes — it clears 3:1 on\n * both card surfaces (3.59:1 on `#ffffff`, 4.99:1 on `#171717`).\n */\nexport const OTHER_COLOR = \"#898781\";\n\n/**\n * Sequential (single-hue, blue) ramp for MAGNITUDE, indexed by rank position:\n * index 0 is rank 1 — the largest value — so the strongest step leads.\n *\n * On the light surface \"strongest\" is the darkest step; on the dark surface it\n * is the lightest. The anchor flips with the surface, which is why there are two\n * selected sets rather than one array reversed at runtime.\n *\n * Five steps, not eight: with the adjacent-ΔL ≥ 0.06 gate and the ≥ 2:1\n * surface-contrast gate on the step nearest the surface, the blue ramp fits\n * exactly five distinguishable steps. Consumers clamp past the end.\n */\nconst SEQUENTIAL_RAMP_LIGHT: readonly string[] = [\"#104281\", \"#1c5cab\", \"#2a78d6\", \"#5598e7\", \"#86b6ef\"];\n\nconst SEQUENTIAL_RAMP_DARK: readonly string[] = [\"#9ec5f4\", \"#6da7ec\", \"#3987e5\", \"#256abf\", \"#184f95\"];\n\n/**\n * The default (light-surface) sequential ramp.\n *\n * Prefer `sequentialColor(index, mode)` — this array exists for consumers that\n * only need the documented default.\n */\nexport const SEQUENTIAL_RAMP: readonly string[] = SEQUENTIAL_RAMP_LIGHT;\n\nconst categoricalSet = (mode: ChartMode): readonly string[] => (mode === \"dark\" ? CATEGORICAL_DARK : CATEGORICAL_LIGHT);\n\nconst sequentialSet = (mode: ChartMode): readonly string[] =>\n mode === \"dark\" ? SEQUENTIAL_RAMP_DARK : SEQUENTIAL_RAMP_LIGHT;\n\n/**\n * The identity colour for series `index`.\n *\n * Never generates a hue and never cycles: anything at or past the ceiling gets\n * `OTHER_COLOR`, because a series past the ceiling should already have been\n * folded into the \"other\" bucket by the caller.\n */\nexport function seriesColor(index: number, mode: ChartMode = \"light\"): string {\n if (index < 0 || index >= CATEGORICAL_CEILING) return OTHER_COLOR;\n return categoricalSet(mode)[index];\n}\n\n/**\n * Both mode steps for series `index`, shaped for a shadcn `ChartConfig` entry's\n * `theme` field.\n */\nexport function seriesTheme(index: number): { light: string; dark: string } {\n return { light: seriesColor(index, \"light\"), dark: seriesColor(index, \"dark\") };\n}\n\n/**\n * The magnitude colour for rank position `index`, clamped to the last step so a\n * long list keeps its weakest step rather than falling off the ramp.\n */\nexport function sequentialColor(index: number, mode: ChartMode = \"light\"): string {\n const ramp = sequentialSet(mode);\n const clamped = Math.min(Math.max(index, 0), ramp.length - 1);\n return ramp[clamped];\n}\n"]}
|
|
@@ -307,7 +307,7 @@ async function makeRequest(params) {
|
|
|
307
307
|
});
|
|
308
308
|
} else {
|
|
309
309
|
if (!_serverRequest) {
|
|
310
|
-
const serverModule = await Promise.resolve().then(() => _interopRequireWildcard(require("./request-
|
|
310
|
+
const serverModule = await Promise.resolve().then(() => _interopRequireWildcard(require("./request-LZBAOT3Y.js")));
|
|
311
311
|
_serverRequest = serverModule.serverRequest;
|
|
312
312
|
}
|
|
313
313
|
return _serverRequest({
|
|
@@ -366,7 +366,8 @@ function buildUrl(endpoint, baseUrl) {
|
|
|
366
366
|
_chunk7QVYU63Ejs.__name.call(void 0, buildUrl, "buildUrl");
|
|
367
367
|
async function JsonApiGet(params) {
|
|
368
368
|
runBootstrapper();
|
|
369
|
-
const
|
|
369
|
+
const isServerCached = typeof window === "undefined" && !!params.classKey.cache;
|
|
370
|
+
const token = isServerCached ? void 0 : await _asyncNullishCoalesce(params.token, async () => ( await getToken()));
|
|
370
371
|
const apiResponse = await makeRequest({
|
|
371
372
|
method: "GET",
|
|
372
373
|
url: buildUrl(params.endpoint, params.baseUrl),
|
|
@@ -515,4 +516,4 @@ _chunk7QVYU63Ejs.__name.call(void 0, JsonApiDelete, "JsonApiDelete");
|
|
|
515
516
|
|
|
516
517
|
|
|
517
518
|
exports.ENV = ENV; exports.DataClassRegistry = DataClassRegistry; exports.JsonApiDataFactory = JsonApiDataFactory; exports.setBootstrapper = setBootstrapper; exports.getBootstrapper = getBootstrapper; exports.tryBootstrap = tryBootstrap; exports.hasBootstrapper = hasBootstrapper; exports.resetBootstrapStore = resetBootstrapStore; exports.translateData = translateData; exports.translateResponse = translateResponse; exports.configureJsonApi = configureJsonApi; exports.getApiUrl = getApiUrl; exports.getAppUrl = getAppUrl; exports.getTrackablePages = getTrackablePages; exports.buildUrl = buildUrl; exports.JsonApiGet = JsonApiGet; exports.JsonApiPost = JsonApiPost; exports.JsonApiPut = JsonApiPut; exports.JsonApiPatch = JsonApiPatch; exports.JsonApiDelete = JsonApiDelete;
|
|
518
|
-
//# sourceMappingURL=chunk-
|
|
519
|
+
//# sourceMappingURL=chunk-WGVNJXZO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/chunk-WGVNJXZO.js","../src/core/env.ts","../src/core/registry/DataClassRegistry.ts","../src/core/factories/JsonApiDataFactory.ts","../src/core/registry/bootstrapStore.ts","../src/core/utils/translateResponse.ts","../src/unified/JsonApiRequest.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACA;AC4BO,IAAM,IAAA,EAAM;AAAA;AAAA,EAEjB,IAAI,OAAA,CAAA,EAAkB;AACpB,IAAA,wBAAO,OAAA,CAAQ,GAAA,CAAI,mBAAA,UAAuB,IAAA;AAAA,EAC5C,CAAA;AAAA;AAAA,EAEA,IAAI,OAAA,CAAA,EAAkB;AACpB,IAAA,wBAAO,OAAA,CAAQ,GAAA,CAAI,mBAAA,UAAuB,IAAA;AAAA,EAC5C,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,iBAAA,CAAA,EAA4B;AAC9B,IAAA,wBAAO,OAAA,CAAQ,GAAA,CAAI,mBAAA,UAAuB,IAAA;AAAA,EAC5C,CAAA;AAAA;AAAA,EAEA,IAAI,gBAAA,CAAA,EAA2B;AAC7B,IAAA,wBAAO,OAAA,CAAQ,GAAA,CAAI,4BAAA,UAAgC,IAAA;AAAA,EACrD,CAAA;AAAA;AAAA,EAEA,IAAI,mBAAA,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AAA;AAGxD,EAAA;AAAsC,IAAA;AAC5B,IAAA;AACqC,IAAA;AAC7C,IAAA;AACA,IAAA;AACc,IAAA;AACI,IAAA;AACD,IAAA;AACiB,EAAA;AAGpC,EAAA;AAAyB,IAAA;AACiB,IAAA;AACxC,IAAA;AACkB,IAAA;AACD,EAAA;AAErB;AAtCsB;AAwCtB;AAYE,EAAA;AACA,EAAA;AAEA,EAAA;AACA,EAAA;AACE,IAAA;AAAQ,EAAA;AAER,IAAA;AAAsD,EAAA;AAGxD,EAAA;AAAsC,IAAA;AAC5B,IAAA;AACqC,IAAA;AAC7C,IAAA;AACA,IAAA;AACc,IAAA;AACI,IAAA;AACD,IAAA;AACiB,EAAA;AAGpC,EAAA;AAAyB,IAAA;AACiB,IAAA;AACxC,IAAA;AACkB,IAAA;AACD,EAAA;AAErB;AAvCsB;AAyCtB;AASE,EAAA;AACA,EAAA;AAEA,EAAA;AAAsC,IAAA;AAC5B,IAAA;AACqC,IAAA;AAC7C,IAAA;AACkB,IAAA;AACD,IAAA;AACiB,EAAA;AAGpC,EAAA;AAAyB,IAAA;AACiB,IAAA;AACxC,IAAA;AACkB,IAAA;AACD,EAAA;AAErB;AA3BsB;ANqJtB;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-WGVNJXZO.js","sourcesContent":[null,"/**\n * The single place in this package that reads `process.env`.\n *\n * Everything else imports {@link ENV}. Centralising the reads keeps every\n * default in one place — the same contract `base.config.ts` provides on the\n * NestJS side — instead of scattering `process.env.X || \"…\"` across hooks,\n * clients and components where the fallbacks silently drift apart.\n *\n * WHY THE READS MUST STAY LITERAL: Next.js inlines `NEXT_PUBLIC_*` by textual\n * substitution at build time, replacing the exact expression\n * `process.env.NEXT_PUBLIC_FOO` with a string literal. A computed lookup\n * (`process.env[key]`) is NOT substituted and reads as `undefined` in the\n * browser bundle. Every entry below therefore spells its variable out in full,\n * and new entries must do the same.\n *\n * WHY GETTERS AND NOT PLAIN PROPERTIES: every call site this replaced read\n * `process.env` at CALL time, not at import time. A plain property would freeze\n * the value when the module is first imported, which breaks any consumer that\n * assigns the variable after boot — the package's own tests do exactly that.\n * Getters keep the read lazy while leaving the expression literal, so the build\n * time substitution still applies.\n *\n * Because that substitution happens before the code runs, no reference to\n * `process` survives into the client bundle — so this module is safe to import\n * from client components, server components, route handlers and middleware\n * alike. It deliberately carries no `\"use client\"` directive for that reason.\n *\n * Values are normalised (empty string rather than `undefined`, booleans rather\n * than string comparisons) so callers never repeat the parsing. Callers that\n * must distinguish \"unset\" from \"set to empty\" — the URL getters, which throw a\n * configuration error — check for an empty string.\n */\nexport const ENV = {\n /** Public API base URL (NEXT_PUBLIC_API_URL). Empty when unset. */\n get API_URL(): string {\n return process.env.NEXT_PUBLIC_API_URL ?? \"\";\n },\n /** Public app base URL (NEXT_PUBLIC_ADDRESS). Empty when unset. */\n get APP_URL(): string {\n return process.env.NEXT_PUBLIC_ADDRESS ?? \"\";\n },\n /**\n * Alternative app base URL (NEXT_PUBLIC_APP_URL), used only by\n * `client/config.ts`'s `getAppUrl()` before it falls back to\n * `window.location.origin`. Empty when unset.\n */\n get APP_URL_ALTERNATE(): string {\n return process.env.NEXT_PUBLIC_APP_URL ?? \"\";\n },\n /** Web-push VAPID public key (NEXT_PUBLIC_VAPID_PUBLIC_KEY). Empty when unset. */\n get VAPID_PUBLIC_KEY(): string {\n return process.env.NEXT_PUBLIC_VAPID_PUBLIC_KEY ?? \"\";\n },\n /** Google Maps JS key (NEXT_PUBLIC_GOOGLE_MAPS_API_KEY). Empty disables autocomplete. */\n get GOOGLE_MAPS_API_KEY(): string {\n return process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY ?? \"\";\n },\n /**\n * NEXT_PUBLIC_PRIVATE_INSTALLATION === \"true\", case-insensitively\n * (default false). A private installation is a single-tenant deployment.\n */\n get PRIVATE_INSTALLATION(): boolean {\n return process.env.NEXT_PUBLIC_PRIVATE_INSTALLATION?.toLowerCase() === \"true\";\n },\n /** NODE_ENV === \"production\" — set by the Next build, not by `.env`. */\n get IS_PRODUCTION(): boolean {\n return process.env.NODE_ENV === \"production\";\n },\n /** NODE_ENV === \"development\" — gates verbose client-side diagnostics. */\n get IS_DEVELOPMENT(): boolean {\n return process.env.NODE_ENV === \"development\";\n },\n};\n","import { ApiDataInterface } from \"../interfaces/ApiDataInterface\";\nimport { ApiRequestDataTypeInterface } from \"../interfaces/ApiRequestDataTypeInterface\";\n\nexport class DataClassRegistry {\n // Use Map with string key (module.name) for reliable lookup\n // String keys are stable across HMR and module re-evaluations\n // Note: WeakMap with object identity was tried but fails during Next.js navigation\n // because module re-evaluation creates new object instances with different identity\n private static _map = new Map<string, { new (): ApiDataInterface }>();\n\n public static registerObjectClass(\n key: ApiRequestDataTypeInterface,\n classConstructor: { new (): ApiDataInterface },\n ): void {\n // Last registration wins. An earlier version skipped re-registration, which\n // silently pinned the registry to the FIRST constructor seen by the process.\n // In dev that made a long-lived `next dev` server keep rehydrating with the\n // pre-edit class after any model change, so SSR produced a different tree\n // from the freshly bundled client and React threw a hydration mismatch.\n // Production is unaffected either way: bootstrap runs once per process.\n this._map.set(key.name, classConstructor);\n }\n\n public static get(classKey: ApiRequestDataTypeInterface): {\n new (): ApiDataInterface;\n } {\n const response = this._map.get(classKey.name);\n if (!response) {\n throw new Error(\n `Class not registered for key: ${typeof classKey === \"string\" ? classKey : classKey.name}. Ensure bootstrap() was called.`,\n );\n }\n\n return response;\n }\n\n /**\n * Get class constructor by JSON:API type name.\n * Used for polymorphic rehydration where the type is determined at runtime.\n */\n public static getByJsonApiType(typeName: string): { new (): ApiDataInterface } | undefined {\n return this._map.get(typeName);\n }\n\n /**\n * Bootstrap the registry with all modules.\n * This is a convenience method for apps to register all their modules at once.\n *\n * @param modules - An object with module definitions (like the app's Modules class)\n */\n public static bootstrap(modules: Record<string, ApiRequestDataTypeInterface>): void {\n Object.values(modules).forEach((module) => {\n if (module && module.model) {\n this.registerObjectClass(module, module.model);\n }\n });\n }\n\n /**\n * Clear all registered classes. Useful for testing.\n */\n public static clear(): void {\n this._map.clear();\n }\n}\n\n// Export alias for backward compatibility\nexport { DataClassRegistry as DataClass };\n","import { ApiDataInterface } from \"../interfaces/ApiDataInterface\";\nimport { ApiRequestDataTypeInterface } from \"../interfaces/ApiRequestDataTypeInterface\";\nimport { DataClassRegistry } from \"../registry/DataClassRegistry\";\n\nexport class JsonApiDataFactory {\n public static create(classKey: ApiRequestDataTypeInterface, data: any): any {\n const factoryClass = DataClassRegistry.get(classKey);\n\n const instance = new factoryClass() as ApiDataInterface;\n const result = instance.createJsonApi(data);\n return result;\n }\n}\n","/**\n * Centralized bootstrap store accessible from ModuleRegistry.\n * This file has NO external dependencies to avoid circular imports.\n *\n * The bootstrap store allows ModuleRegistry to call the app's bootstrapper\n * when modules are accessed before bootstrap() was called, providing\n * self-healing behavior for module evaluation order issues.\n *\n * IMPORTANT: We use globalThis to persist state across HMR/Turbopack\n * module re-evaluations in development mode. Without this, the bootstrapper\n * reference would be lost when modules are hot-reloaded, causing\n * \"Module not registered\" errors during navigation.\n */\n\ntype BootstrapperFn = () => void;\n\n// Symbol key to avoid conflicts with other globals\nconst BOOTSTRAP_KEY = Symbol.for(\"nextjs-jsonapi:bootstrapper\");\nconst BOOTSTRAP_ATTEMPTED_KEY = Symbol.for(\"nextjs-jsonapi:bootstrapAttempted\");\n\n// Use globalThis to persist across HMR reloads\nconst globalStore = globalThis as unknown as {\n [BOOTSTRAP_KEY]?: BootstrapperFn | null;\n [BOOTSTRAP_ATTEMPTED_KEY]?: boolean;\n};\n\n// Initialize from global if not set\nif (globalStore[BOOTSTRAP_KEY] === undefined) {\n globalStore[BOOTSTRAP_KEY] = null;\n}\nif (globalStore[BOOTSTRAP_ATTEMPTED_KEY] === undefined) {\n globalStore[BOOTSTRAP_ATTEMPTED_KEY] = false;\n}\n\n// Getters/setters that use the global store\nfunction getBootstrapperInternal(): BootstrapperFn | null {\n return globalStore[BOOTSTRAP_KEY] ?? null;\n}\n\nfunction setBootstrapperInternal(fn: BootstrapperFn | null): void {\n globalStore[BOOTSTRAP_KEY] = fn;\n}\n\nfunction getBootstrapAttempted(): boolean {\n return globalStore[BOOTSTRAP_ATTEMPTED_KEY] ?? false;\n}\n\nfunction setBootstrapAttempted(value: boolean): void {\n globalStore[BOOTSTRAP_ATTEMPTED_KEY] = value;\n}\n\n/**\n * Register the bootstrapper function.\n * Called by configureJsonApi() from client/config, client/JsonApiClient, or unified/JsonApiRequest.\n */\nexport function setBootstrapper(fn: BootstrapperFn): void {\n setBootstrapperInternal(fn);\n}\n\n/**\n * Get the registered bootstrapper function.\n * Returns null if no bootstrapper has been registered.\n */\nexport function getBootstrapper(): BootstrapperFn | null {\n return getBootstrapperInternal();\n}\n\n/**\n * Attempt to run the bootstrapper if one is registered.\n * Returns true if bootstrapper was executed, false if not available.\n * Safe to call multiple times - bootstrapper is expected to be idempotent.\n */\nexport function tryBootstrap(): boolean {\n const bootstrapper = getBootstrapperInternal();\n const attempted = getBootstrapAttempted();\n\n if (attempted && !bootstrapper) {\n // Already tried and no bootstrapper available\n return false;\n }\n setBootstrapAttempted(true);\n\n if (bootstrapper) {\n bootstrapper();\n return true;\n }\n return false;\n}\n\n/**\n * Check if a bootstrapper has been registered.\n */\nexport function hasBootstrapper(): boolean {\n return getBootstrapperInternal() !== null;\n}\n\n/**\n * Reset the bootstrap store. Useful for testing.\n */\nexport function resetBootstrapStore(): void {\n setBootstrapperInternal(null);\n setBootstrapAttempted(false);\n}\n","import { ApiData } from \"../interfaces/ApiData\";\nimport { ApiDataInterface } from \"../interfaces/ApiDataInterface\";\nimport { ApiRequestDataTypeInterface } from \"../interfaces/ApiRequestDataTypeInterface\";\nimport { ApiResponseInterface } from \"../interfaces/ApiResponseInterface\";\nimport { DataClassRegistry } from \"../registry/DataClassRegistry\";\n\n/**\n * Translates raw JSON:API data into typed objects.\n * Does not require API response metadata.\n */\nexport function translateData<T extends ApiDataInterface>(params: {\n classKey: ApiRequestDataTypeInterface;\n data: any;\n}): T | T[] {\n const factoryClass = DataClassRegistry.get(params.classKey);\n\n if (!factoryClass) {\n throw new Error(\n `Class not registered for key: ${typeof params.classKey === \"string\" ? params.classKey : params.classKey.name}`,\n );\n }\n\n const included: any = params.data.included ?? [];\n\n if (Array.isArray(params.data.data)) {\n const responseData: T[] = [];\n\n for (const data of params.data.data) {\n const object = new factoryClass();\n object.rehydrate({ jsonApi: data, included: included, allData: params.data.data });\n responseData.push(object as T);\n }\n\n return responseData as T[];\n } else {\n const responseData = new factoryClass();\n responseData.rehydrate({\n jsonApi: params.data.data,\n included: included,\n });\n\n return responseData as T;\n }\n}\n\n/**\n * Translates a full API response into a typed ApiResponseInterface.\n * Includes pagination support.\n */\nexport async function translateResponse<T extends ApiDataInterface>(params: {\n classKey: ApiRequestDataTypeInterface;\n apiResponse: ApiData;\n companyId?: string;\n language: string;\n paginationHandler?: (endpoint: string) => Promise<ApiResponseInterface>;\n}): Promise<ApiResponseInterface> {\n const response: ApiResponseInterface = {\n ok: true,\n response: 0,\n data: [],\n error: \"\",\n };\n\n const factoryClass = DataClassRegistry.get(params.classKey);\n\n if (!factoryClass) {\n throw new Error(\n `Class not registered for key: ${typeof params.classKey === \"string\" ? params.classKey : params.classKey.name}`,\n );\n }\n\n response.ok = params.apiResponse.ok;\n response.response = params.apiResponse.status;\n\n if (!params.apiResponse.ok) {\n // `statusText` is empty over HTTP/2 (the reason phrase was removed from the protocol), so the\n // body is the only reliable source of error text. APIs in this stack use either key.\n response.error =\n params.apiResponse?.data?.message ?? params.apiResponse?.data?.error ?? params.apiResponse.statusText;\n response.raw = params.apiResponse.data;\n return response;\n }\n\n if (params.apiResponse.status === 204) return response;\n\n // A success with no body (e.g. a 200 from a handler that sends nothing —\n // @HttpCode is inert when a controller injects @Res, so \"204\" endpoints can\n // arrive as empty 200s) translates to an empty success, not a crash on\n // `.included` below.\n if (params.apiResponse.data === undefined || params.apiResponse.data === null) return response;\n\n response.raw = params.apiResponse.data;\n\n // Extract meta from JSON:API response\n if (params.apiResponse.data?.meta) {\n response.meta = params.apiResponse.data.meta;\n }\n\n try {\n // Check if response is JSON:API formatted (has a 'data' property)\n // If not, return the raw response data directly (e.g., { url: \"...\" } or { clientSecret: \"...\" })\n if (\n params.apiResponse.data &&\n typeof params.apiResponse.data === \"object\" &&\n !Array.isArray(params.apiResponse.data) &&\n params.apiResponse.data.data === undefined\n ) {\n response.data = params.apiResponse.data;\n return response;\n }\n\n const included: any = params.apiResponse.data.included ?? [];\n\n if (params.apiResponse.data.links) {\n response.self = params.apiResponse.data.links.self;\n\n if (params.apiResponse.data.links.next && params.paginationHandler) {\n response.next = params.apiResponse.data.links.next;\n response.nextPage = async () => params.paginationHandler!(params.apiResponse.data.links.next);\n }\n\n if (params.apiResponse.data.links.prev && params.paginationHandler) {\n response.prev = params.apiResponse.data.links.prev;\n response.prevPage = async () => params.paginationHandler!(params.apiResponse.data.links.prev);\n }\n }\n\n if (Array.isArray(params.apiResponse.data.data)) {\n const responseData: T[] = [];\n\n for (const data of params.apiResponse.data.data) {\n const object = new factoryClass();\n object.rehydrate({ jsonApi: data, included: included, allData: params.apiResponse.data.data });\n responseData.push(object as T);\n }\n\n response.data = responseData;\n } else {\n const responseData = new factoryClass();\n responseData.rehydrate({\n jsonApi: params.apiResponse.data.data,\n included: included,\n });\n\n response.data = responseData;\n }\n } catch (e) {\n console.error(e);\n }\n\n return response;\n}\n","import { ENV } from \"../core/env\";\nimport { JsonApiDataFactory } from \"../core/factories/JsonApiDataFactory\";\nimport { ApiData } from \"../core/interfaces/ApiData\";\nimport { ApiRequestDataTypeInterface } from \"../core/interfaces/ApiRequestDataTypeInterface\";\nimport { ApiResponseInterface } from \"../core/interfaces/ApiResponseInterface\";\nimport { setBootstrapper } from \"../core/registry/bootstrapStore\";\nimport { translateResponse } from \"../core/utils/translateResponse\";\nimport { ModuleWithPermissions } from \"../permissions/types\";\n\n// Type definitions for dynamically imported functions (avoiding typeof import to prevent bundling)\ntype DirectFetchFn = (params: {\n method: string;\n url: string;\n token?: string;\n body?: any;\n files?: { [key: string]: File | Blob } | File | Blob;\n companyId?: string;\n language: string;\n additionalHeaders?: Record<string, string>;\n}) => Promise<ApiData>;\n\ntype ServerRequestFn = (params: {\n method: string;\n url: string;\n token?: string;\n cache?: string;\n body?: any;\n files?: { [key: string]: File | Blob } | File | Blob;\n companyId?: string;\n language: string;\n additionalHeaders?: Record<string, string>;\n}) => Promise<ApiData>;\n\ntype GetTokenFn = () => Promise<string | undefined>;\n\n// These will be dynamically imported based on environment\nlet _directFetch: DirectFetchFn;\nlet _serverRequest: ServerRequestFn;\nlet _getClientToken: GetTokenFn;\nlet _getServerToken: GetTokenFn;\n\n// Config storage for non-React contexts\nlet _staticConfig: {\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 client for non-React contexts (e.g., server components).\n * For React contexts, use JsonApiProvider instead.\n */\nexport function configureJsonApi(config: {\n apiUrl: string;\n appUrl?: string;\n trackablePages?: ModuleWithPermissions[];\n bootstrapper?: () => void;\n additionalHeaders?: Record<string, string>;\n}): void {\n _staticConfig = config;\n // Register and call bootstrapper to register all modules\n if (config.bootstrapper) {\n setBootstrapper(config.bootstrapper);\n config.bootstrapper();\n }\n}\n\nasync function getToken(): Promise<string | undefined> {\n if (typeof window === \"undefined\") {\n // Server-side\n if (!_getServerToken) {\n const serverModule = await import(\"../server/token\");\n _getServerToken = serverModule.getServerToken;\n }\n return _getServerToken();\n } else {\n // Client-side\n if (!_getClientToken) {\n const clientModule = await import(\"../client/token\");\n _getClientToken = clientModule.getClientToken;\n }\n return _getClientToken();\n }\n}\n\nasync function makeRequest(params: {\n method: string;\n url: string;\n token?: string;\n cache?: string;\n body?: any;\n files?: { [key: string]: File | Blob } | File | Blob;\n companyId?: string;\n language: string;\n additionalHeaders?: Record<string, string>;\n}): Promise<ApiData> {\n if (typeof window !== \"undefined\") {\n // Client-side: use direct fetch\n if (!_directFetch) {\n const clientModule = await import(\"../client/request\");\n _directFetch = clientModule.directFetch;\n }\n return _directFetch({\n method: params.method,\n url: params.url,\n token: params.token,\n body: params.body,\n files: params.files,\n companyId: params.companyId,\n language: params.language,\n additionalHeaders: params.additionalHeaders,\n });\n } else {\n // Server-side: use server request with caching\n if (!_serverRequest) {\n const serverModule = await import(\"../server/request\");\n _serverRequest = serverModule.serverRequest;\n }\n return _serverRequest({\n method: params.method,\n url: params.url,\n token: params.token,\n cache: params.cache,\n body: params.body,\n files: params.files,\n companyId: params.companyId,\n language: params.language,\n additionalHeaders: params.additionalHeaders,\n });\n }\n}\n\nexport function getApiUrl(): string {\n if (_staticConfig?.apiUrl) {\n return _staticConfig.apiUrl;\n }\n // Fallback to environment variable\n const envUrl = ENV.API_URL;\n if (!envUrl) {\n throw new Error(\"API URL not configured. Use configureJsonApi() or set NEXT_PUBLIC_API_URL environment variable.\");\n }\n return envUrl;\n}\n\nexport function getAppUrl(): string {\n if (_staticConfig?.appUrl) {\n return _staticConfig.appUrl;\n }\n // Fallback to environment variable\n const envUrl = ENV.APP_URL;\n if (!envUrl) {\n throw new Error(\n \"App URL not configured. Use configureJsonApi({ appUrl }) or set NEXT_PUBLIC_ADDRESS environment variable.\",\n );\n }\n return envUrl.trim().replace(/\\/+$/, \"\");\n}\n\nexport function getTrackablePages(): ModuleWithPermissions[] {\n return _staticConfig?.trackablePages ?? [];\n}\n\nfunction runBootstrapper(): void {\n if (_staticConfig?.bootstrapper) {\n _staticConfig.bootstrapper();\n }\n}\n\n/**\n * Resolve the final request URL for an endpoint.\n *\n * - `endpoint` starting with \"http\" is always passed through unchanged (existing behaviour).\n * - Otherwise, an explicit `baseUrl` (per-call override) takes precedence over the global\n * `getApiUrl()` resolution. Omitting `baseUrl` preserves today's behaviour exactly.\n */\nexport function buildUrl(endpoint: string, baseUrl?: string): string {\n if (endpoint.startsWith(\"http\")) return endpoint;\n const apiUrl = baseUrl ?? getApiUrl();\n return `${apiUrl}${endpoint}`;\n}\n\nexport async function JsonApiGet(params: {\n classKey: ApiRequestDataTypeInterface;\n endpoint: string;\n companyId?: string;\n language: string;\n token?: string;\n baseUrl?: string;\n}): Promise<ApiResponseInterface> {\n runBootstrapper();\n // A cached server GET never sends the token, so it must not read the cookie either:\n // the read would make a public page dynamic.\n const isServerCached = typeof window === \"undefined\" && !!params.classKey.cache;\n const token = isServerCached ? undefined : (params.token ?? (await getToken()));\n\n const apiResponse = await makeRequest({\n method: \"GET\",\n url: buildUrl(params.endpoint, params.baseUrl),\n token,\n cache: params.classKey.cache,\n companyId: params.companyId,\n language: params.language,\n additionalHeaders: _staticConfig?.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 JsonApiGet({\n classKey: params.classKey,\n endpoint,\n companyId: params.companyId,\n language: params.language,\n token: params.token,\n baseUrl: params.baseUrl,\n }),\n });\n}\n\nexport async function JsonApiPost(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 token?: string;\n baseUrl?: string;\n}): Promise<ApiResponseInterface> {\n runBootstrapper();\n const token = params.token ?? (await getToken());\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 makeRequest({\n method: \"POST\",\n url: buildUrl(params.endpoint, params.baseUrl),\n token,\n body,\n files: params.files,\n companyId: params.companyId,\n language: params.language,\n additionalHeaders: _staticConfig?.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 JsonApiPut(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 token?: string;\n baseUrl?: string;\n}): Promise<ApiResponseInterface> {\n runBootstrapper();\n const token = params.token ?? (await getToken());\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 makeRequest({\n method: \"PUT\",\n url: buildUrl(params.endpoint, params.baseUrl),\n token,\n body,\n files: params.files,\n companyId: params.companyId,\n language: params.language,\n additionalHeaders: _staticConfig?.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 JsonApiPatch(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 token?: string;\n baseUrl?: string;\n}): Promise<ApiResponseInterface> {\n runBootstrapper();\n const token = params.token ?? (await getToken());\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 makeRequest({\n method: \"PATCH\",\n url: buildUrl(params.endpoint, params.baseUrl),\n token,\n body,\n files: params.files,\n companyId: params.companyId,\n language: params.language,\n additionalHeaders: _staticConfig?.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 JsonApiDelete(params: {\n classKey: ApiRequestDataTypeInterface;\n endpoint: string;\n companyId?: string;\n language: string;\n responseType?: ApiRequestDataTypeInterface;\n token?: string;\n baseUrl?: string;\n}): Promise<ApiResponseInterface> {\n runBootstrapper();\n const token = params.token ?? (await getToken());\n\n const apiResponse = await makeRequest({\n method: \"DELETE\",\n url: buildUrl(params.endpoint, params.baseUrl),\n token,\n companyId: params.companyId,\n language: params.language,\n additionalHeaders: _staticConfig?.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"]}
|