gt-react 3.1.39 → 3.1.41
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/cjs/client/ClientProvider.d.ts +19 -0
- package/dist/cjs/client/ClientProvider.d.ts.map +1 -0
- package/dist/cjs/client/ClientProvider.js +29 -0
- package/dist/cjs/client/ClientProvider.js.map +1 -0
- package/dist/cjs/client/client-only/GTClientProvider.d.ts +13 -0
- package/dist/cjs/client/client-only/GTClientProvider.d.ts.map +1 -0
- package/dist/cjs/client/client-only/GTClientProvider.js +95 -0
- package/dist/cjs/client/client-only/GTClientProvider.js.map +1 -0
- package/dist/cjs/client/client-only/helpers/renderDictionary.d.ts +2 -0
- package/dist/cjs/client/client-only/helpers/renderDictionary.d.ts.map +1 -0
- package/dist/cjs/client/client-only/helpers/renderDictionary.js +150 -0
- package/dist/cjs/client/client-only/helpers/renderDictionary.js.map +1 -0
- package/dist/cjs/client/hooks/useBrowserLocale.d.ts +7 -0
- package/dist/cjs/client/hooks/useBrowserLocale.d.ts.map +1 -0
- package/dist/cjs/client/hooks/useBrowserLocale.js +41 -0
- package/dist/cjs/client/hooks/useBrowserLocale.js.map +1 -0
- package/dist/cjs/client/hooks/useDefaultLocale.d.ts +5 -0
- package/dist/cjs/client/hooks/useDefaultLocale.d.ts.map +1 -0
- package/dist/cjs/client/hooks/useDefaultLocale.js +13 -0
- package/dist/cjs/client/hooks/useDefaultLocale.js.map +1 -0
- package/dist/cjs/client/hooks/useGT.d.ts +10 -0
- package/dist/cjs/client/hooks/useGT.d.ts.map +1 -0
- package/dist/cjs/client/hooks/useGT.js +54 -0
- package/dist/cjs/client/hooks/useGT.js.map +1 -0
- package/dist/cjs/client/hooks/useLocale.d.ts +5 -0
- package/dist/cjs/client/hooks/useLocale.d.ts.map +1 -0
- package/dist/cjs/client/hooks/useLocale.js +13 -0
- package/dist/cjs/client/hooks/useLocale.js.map +1 -0
- package/dist/cjs/client/plural/ClientPlural.d.ts +28 -0
- package/dist/cjs/client/plural/ClientPlural.d.ts.map +1 -0
- package/dist/cjs/client/plural/ClientPlural.js +78 -0
- package/dist/cjs/client/plural/ClientPlural.js.map +1 -0
- package/dist/cjs/client/value/ClientValue.d.ts +16 -0
- package/dist/cjs/client/value/ClientValue.d.ts.map +1 -0
- package/dist/cjs/client/value/ClientValue.js +43 -0
- package/dist/cjs/client/value/ClientValue.js.map +1 -0
- package/dist/cjs/client/value/RenderClientVariable.d.ts +6 -0
- package/dist/cjs/client/value/RenderClientVariable.d.ts.map +1 -0
- package/dist/cjs/client/value/RenderClientVariable.js +106 -0
- package/dist/cjs/client/value/RenderClientVariable.js.map +1 -0
- package/dist/cjs/client/variables/ClientCurrency.d.ts +13 -0
- package/dist/cjs/client/variables/ClientCurrency.d.ts.map +1 -0
- package/dist/cjs/client/variables/ClientCurrency.js +31 -0
- package/dist/cjs/client/variables/ClientCurrency.js.map +1 -0
- package/dist/cjs/client/variables/ClientDateTime.d.ts +12 -0
- package/dist/cjs/client/variables/ClientDateTime.d.ts.map +1 -0
- package/dist/cjs/client/variables/ClientDateTime.js +45 -0
- package/dist/cjs/client/variables/ClientDateTime.js.map +1 -0
- package/dist/cjs/client/variables/ClientNum.d.ts +12 -0
- package/dist/cjs/client/variables/ClientNum.d.ts.map +1 -0
- package/dist/cjs/client/variables/ClientNum.js +29 -0
- package/dist/cjs/client/variables/ClientNum.js.map +1 -0
- package/dist/cjs/client/variables/ClientVar.d.ts +21 -0
- package/dist/cjs/client/variables/ClientVar.d.ts.map +1 -0
- package/dist/cjs/client/variables/ClientVar.js +26 -0
- package/dist/cjs/client/variables/ClientVar.js.map +1 -0
- package/dist/cjs/client.d.ts +12 -0
- package/dist/cjs/client.d.ts.map +1 -0
- package/dist/cjs/client.js +27 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/config/I18NConfiguration.d.ts +135 -0
- package/dist/cjs/config/I18NConfiguration.d.ts.map +1 -0
- package/dist/cjs/config/I18NConfiguration.js +343 -0
- package/dist/cjs/config/I18NConfiguration.js.map +1 -0
- package/dist/cjs/config/LocalDictionaryManager.d.ts +31 -0
- package/dist/cjs/config/LocalDictionaryManager.d.ts.map +1 -0
- package/dist/cjs/config/LocalDictionaryManager.js +95 -0
- package/dist/cjs/config/LocalDictionaryManager.js.map +1 -0
- package/dist/cjs/config/RemoteDictionaryManager.d.ts +59 -0
- package/dist/cjs/config/RemoteDictionaryManager.d.ts.map +1 -0
- package/dist/cjs/config/RemoteDictionaryManager.js +120 -0
- package/dist/cjs/config/RemoteDictionaryManager.js.map +1 -0
- package/dist/cjs/config/determineLocale.d.ts +2 -0
- package/dist/cjs/config/determineLocale.d.ts.map +1 -0
- package/dist/cjs/config/determineLocale.js +32 -0
- package/dist/cjs/config/determineLocale.js.map +1 -0
- package/dist/cjs/config/local/getDefaultFromEnv.d.ts +12 -0
- package/dist/cjs/config/local/getDefaultFromEnv.d.ts.map +1 -0
- package/dist/cjs/config/local/getDefaultFromEnv.js +21 -0
- package/dist/cjs/config/local/getDefaultFromEnv.js.map +1 -0
- package/dist/cjs/dictionary/createDictFunction.d.ts +3 -0
- package/dist/cjs/dictionary/createDictFunction.d.ts.map +1 -0
- package/dist/cjs/dictionary/createDictFunction.js +14 -0
- package/dist/cjs/dictionary/createDictFunction.js.map +1 -0
- package/dist/cjs/dictionary/createExecuteTFunction.d.ts +12 -0
- package/dist/cjs/dictionary/createExecuteTFunction.d.ts.map +1 -0
- package/dist/cjs/dictionary/createExecuteTFunction.js +94 -0
- package/dist/cjs/dictionary/createExecuteTFunction.js.map +1 -0
- package/dist/cjs/dictionary/createGetGTFunction.d.ts +3 -0
- package/dist/cjs/dictionary/createGetGTFunction.d.ts.map +1 -0
- package/dist/cjs/dictionary/createGetGTFunction.js +10 -0
- package/dist/cjs/dictionary/createGetGTFunction.js.map +1 -0
- package/dist/cjs/dictionary/getDictionaryEntry.d.ts +2 -0
- package/dist/cjs/dictionary/getDictionaryEntry.d.ts.map +1 -0
- package/dist/cjs/dictionary/getDictionaryEntry.js +14 -0
- package/dist/cjs/dictionary/getDictionaryEntry.js.map +1 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +15 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/intl/createIntlFunction.d.ts +6 -0
- package/dist/cjs/intl/createIntlFunction.d.ts.map +1 -0
- package/dist/cjs/intl/createIntlFunction.js +48 -0
- package/dist/cjs/intl/createIntlFunction.js.map +1 -0
- package/dist/cjs/middleware/cookieSettings.d.ts +2 -0
- package/dist/cjs/middleware/cookieSettings.d.ts.map +1 -0
- package/dist/cjs/middleware/cookieSettings.js +5 -0
- package/dist/cjs/middleware/cookieSettings.js.map +1 -0
- package/dist/cjs/middleware/createNextMiddleware.d.ts +10 -0
- package/dist/cjs/middleware/createNextMiddleware.d.ts.map +1 -0
- package/dist/cjs/middleware/createNextMiddleware.js +151 -0
- package/dist/cjs/middleware/createNextMiddleware.js.map +1 -0
- package/dist/cjs/middleware.d.ts +3 -0
- package/dist/cjs/middleware.d.ts.map +1 -0
- package/dist/cjs/middleware.js +9 -0
- package/dist/cjs/middleware.js.map +1 -0
- package/dist/cjs/next/imports/imports.d.ts +6 -0
- package/dist/cjs/next/imports/imports.d.ts.map +1 -0
- package/dist/cjs/next/imports/imports.js +84 -0
- package/dist/cjs/next/imports/imports.js.map +1 -0
- package/dist/cjs/next/requestFunctions.d.ts +21 -0
- package/dist/cjs/next/requestFunctions.d.ts.map +1 -0
- package/dist/cjs/next/requestFunctions.js +58 -0
- package/dist/cjs/next/requestFunctions.js.map +1 -0
- package/dist/cjs/next.d.ts +38 -0
- package/dist/cjs/next.d.ts.map +1 -0
- package/dist/cjs/next.js +58 -0
- package/dist/cjs/next.js.map +1 -0
- package/dist/cjs/primitives/calculateID.d.ts +2 -0
- package/dist/cjs/primitives/calculateID.d.ts.map +1 -0
- package/dist/cjs/primitives/calculateID.js +49 -0
- package/dist/cjs/primitives/calculateID.js.map +1 -0
- package/dist/cjs/primitives/createValues.d.ts +6 -0
- package/dist/cjs/primitives/createValues.d.ts.map +1 -0
- package/dist/cjs/primitives/createValues.js +16 -0
- package/dist/cjs/primitives/createValues.js.map +1 -0
- package/dist/cjs/primitives/defaultVariableNames.d.ts +3 -0
- package/dist/cjs/primitives/defaultVariableNames.d.ts.map +1 -0
- package/dist/cjs/primitives/defaultVariableNames.js +10 -0
- package/dist/cjs/primitives/defaultVariableNames.js.map +1 -0
- package/dist/cjs/primitives/flattenDictionary.d.ts +9 -0
- package/dist/cjs/primitives/flattenDictionary.d.ts.map +1 -0
- package/dist/cjs/primitives/flattenDictionary.js +29 -0
- package/dist/cjs/primitives/flattenDictionary.js.map +1 -0
- package/dist/cjs/primitives/getDictionaryReference.d.ts +8 -0
- package/dist/cjs/primitives/getDictionaryReference.d.ts.map +1 -0
- package/dist/cjs/primitives/getDictionaryReference.js +13 -0
- package/dist/cjs/primitives/getDictionaryReference.js.map +1 -0
- package/dist/cjs/primitives/getEntryMetadata.d.ts +5 -0
- package/dist/cjs/primitives/getEntryMetadata.d.ts.map +1 -0
- package/dist/cjs/primitives/getEntryMetadata.js +17 -0
- package/dist/cjs/primitives/getEntryMetadata.js.map +1 -0
- package/dist/cjs/primitives/getEntryTranslationType.d.ts +2 -0
- package/dist/cjs/primitives/getEntryTranslationType.d.ts.map +1 -0
- package/dist/cjs/primitives/getEntryTranslationType.js +31 -0
- package/dist/cjs/primitives/getEntryTranslationType.js.map +1 -0
- package/dist/cjs/primitives/getPluralBranch.d.ts +14 -0
- package/dist/cjs/primitives/getPluralBranch.d.ts.map +1 -0
- package/dist/cjs/primitives/getPluralBranch.js +88 -0
- package/dist/cjs/primitives/getPluralBranch.js.map +1 -0
- package/dist/cjs/primitives/getRenderAttributes.d.ts +5 -0
- package/dist/cjs/primitives/getRenderAttributes.d.ts.map +1 -0
- package/dist/cjs/primitives/getRenderAttributes.js +24 -0
- package/dist/cjs/primitives/getRenderAttributes.js.map +1 -0
- package/dist/cjs/primitives/getValueBranch.d.ts +9 -0
- package/dist/cjs/primitives/getValueBranch.d.ts.map +1 -0
- package/dist/cjs/primitives/getValueBranch.js +67 -0
- package/dist/cjs/primitives/getValueBranch.js.map +1 -0
- package/dist/cjs/primitives/hasTransformation.d.ts +3 -0
- package/dist/cjs/primitives/hasTransformation.d.ts.map +1 -0
- package/dist/cjs/primitives/hasTransformation.js +16 -0
- package/dist/cjs/primitives/hasTransformation.js.map +1 -0
- package/dist/cjs/primitives/isValidReactNode.d.ts +15 -0
- package/dist/cjs/primitives/isValidReactNode.d.ts.map +1 -0
- package/dist/cjs/primitives/isValidReactNode.js +27 -0
- package/dist/cjs/primitives/isValidReactNode.js.map +1 -0
- package/dist/cjs/server/T.d.ts +15 -0
- package/dist/cjs/server/T.d.ts.map +1 -0
- package/dist/cjs/server/T.js +98 -0
- package/dist/cjs/server/T.js.map +1 -0
- package/dist/cjs/server/createTComponent.d.ts +12 -0
- package/dist/cjs/server/createTComponent.d.ts.map +1 -0
- package/dist/cjs/server/createTComponent.js +31 -0
- package/dist/cjs/server/createTComponent.js.map +1 -0
- package/dist/cjs/server/helpers/Resolver.d.ts +5 -0
- package/dist/cjs/server/helpers/Resolver.d.ts.map +1 -0
- package/dist/cjs/server/helpers/Resolver.js +25 -0
- package/dist/cjs/server/helpers/Resolver.js.map +1 -0
- package/dist/cjs/server/helpers/addGTIdentifier.d.ts +11 -0
- package/dist/cjs/server/helpers/addGTIdentifier.d.ts.map +1 -0
- package/dist/cjs/server/helpers/addGTIdentifier.js +148 -0
- package/dist/cjs/server/helpers/addGTIdentifier.js.map +1 -0
- package/dist/cjs/server/helpers/writeChildrenAsObjects.d.ts +11 -0
- package/dist/cjs/server/helpers/writeChildrenAsObjects.d.ts.map +1 -0
- package/dist/cjs/server/helpers/writeChildrenAsObjects.js +116 -0
- package/dist/cjs/server/helpers/writeChildrenAsObjects.js.map +1 -0
- package/dist/cjs/server/plural/InnerPlural.d.ts +24 -0
- package/dist/cjs/server/plural/InnerPlural.d.ts.map +1 -0
- package/dist/cjs/server/plural/InnerPlural.js +35 -0
- package/dist/cjs/server/plural/InnerPlural.js.map +1 -0
- package/dist/cjs/server/plural/createPluralComponent.d.ts +12 -0
- package/dist/cjs/server/plural/createPluralComponent.d.ts.map +1 -0
- package/dist/cjs/server/plural/createPluralComponent.js +30 -0
- package/dist/cjs/server/plural/createPluralComponent.js.map +1 -0
- package/dist/cjs/server/provider/GTProvider.d.ts +13 -0
- package/dist/cjs/server/provider/GTProvider.d.ts.map +1 -0
- package/dist/cjs/server/provider/GTProvider.js +61 -0
- package/dist/cjs/server/provider/GTProvider.js.map +1 -0
- package/dist/cjs/server/provider/createGTProviderComponent.d.ts +10 -0
- package/dist/cjs/server/provider/createGTProviderComponent.d.ts.map +1 -0
- package/dist/cjs/server/provider/createGTProviderComponent.js +30 -0
- package/dist/cjs/server/provider/createGTProviderComponent.js.map +1 -0
- package/dist/cjs/server/renderChildren.d.ts +24 -0
- package/dist/cjs/server/renderChildren.d.ts.map +1 -0
- package/dist/cjs/server/renderChildren.js +177 -0
- package/dist/cjs/server/renderChildren.js.map +1 -0
- package/dist/cjs/server/value/InnerValue.d.ts +12 -0
- package/dist/cjs/server/value/InnerValue.d.ts.map +1 -0
- package/dist/cjs/server/value/InnerValue.js +30 -0
- package/dist/cjs/server/value/InnerValue.js.map +1 -0
- package/dist/cjs/server/value/createValueComponent.d.ts +13 -0
- package/dist/cjs/server/value/createValueComponent.d.ts.map +1 -0
- package/dist/cjs/server/value/createValueComponent.js +29 -0
- package/dist/cjs/server/value/createValueComponent.js.map +1 -0
- package/dist/cjs/server/value/renderVariable.d.ts +9 -0
- package/dist/cjs/server/value/renderVariable.d.ts.map +1 -0
- package/dist/cjs/server/value/renderVariable.js +66 -0
- package/dist/cjs/server/value/renderVariable.js.map +1 -0
- package/dist/cjs/server/variables/Currency/Currency.d.ts +15 -0
- package/dist/cjs/server/variables/Currency/Currency.d.ts.map +1 -0
- package/dist/cjs/server/variables/Currency/Currency.js +29 -0
- package/dist/cjs/server/variables/Currency/Currency.js.map +1 -0
- package/dist/cjs/server/variables/Currency/createCurrencyComponent.d.ts +8 -0
- package/dist/cjs/server/variables/Currency/createCurrencyComponent.d.ts.map +1 -0
- package/dist/cjs/server/variables/Currency/createCurrencyComponent.js +29 -0
- package/dist/cjs/server/variables/Currency/createCurrencyComponent.js.map +1 -0
- package/dist/cjs/server/variables/DateTime/DateTime.d.ts +13 -0
- package/dist/cjs/server/variables/DateTime/DateTime.d.ts.map +1 -0
- package/dist/cjs/server/variables/DateTime/DateTime.js +45 -0
- package/dist/cjs/server/variables/DateTime/DateTime.js.map +1 -0
- package/dist/cjs/server/variables/DateTime/createDateTimeComponent.d.ts +8 -0
- package/dist/cjs/server/variables/DateTime/createDateTimeComponent.d.ts.map +1 -0
- package/dist/cjs/server/variables/DateTime/createDateTimeComponent.js +29 -0
- package/dist/cjs/server/variables/DateTime/createDateTimeComponent.js.map +1 -0
- package/dist/cjs/server/variables/Num/Num.d.ts +14 -0
- package/dist/cjs/server/variables/Num/Num.d.ts.map +1 -0
- package/dist/cjs/server/variables/Num/Num.js +27 -0
- package/dist/cjs/server/variables/Num/Num.js.map +1 -0
- package/dist/cjs/server/variables/Num/createNumComponent.d.ts +8 -0
- package/dist/cjs/server/variables/Num/createNumComponent.d.ts.map +1 -0
- package/dist/cjs/server/variables/Num/createNumComponent.js +30 -0
- package/dist/cjs/server/variables/Num/createNumComponent.js.map +1 -0
- package/dist/cjs/server/variables/Var/Var.d.ts +12 -0
- package/dist/cjs/server/variables/Var/Var.d.ts.map +1 -0
- package/dist/cjs/server/variables/Var/Var.js +24 -0
- package/dist/cjs/server/variables/Var/Var.js.map +1 -0
- package/dist/cjs/server/variables/Var/createVarComponent.d.ts +7 -0
- package/dist/cjs/server/variables/Var/createVarComponent.d.ts.map +1 -0
- package/dist/cjs/server/variables/Var/createVarComponent.js +29 -0
- package/dist/cjs/server/variables/Var/createVarComponent.js.map +1 -0
- package/dist/cjs/server.d.ts +45 -0
- package/dist/cjs/server.d.ts.map +1 -0
- package/dist/cjs/server.js +149 -0
- package/dist/cjs/server.js.map +1 -0
- package/dist/cjs/types/CreateGTProps.d.ts +23 -0
- package/dist/cjs/types/CreateGTProps.d.ts.map +1 -0
- package/dist/cjs/types/CreateGTProps.js +3 -0
- package/dist/cjs/types/CreateGTProps.js.map +1 -0
- package/dist/cjs/types/GeneralTranslationInterface.d.ts +118 -0
- package/dist/cjs/types/GeneralTranslationInterface.d.ts.map +1 -0
- package/dist/cjs/types/GeneralTranslationInterface.js +3 -0
- package/dist/cjs/types/GeneralTranslationInterface.js.map +1 -0
- package/dist/cjs/types/Variables.d.ts +83 -0
- package/dist/cjs/types/Variables.d.ts.map +1 -0
- package/dist/cjs/types/Variables.js +3 -0
- package/dist/cjs/types/Variables.js.map +1 -0
- package/dist/cjs/types/defaultGTProps.d.ts +20 -0
- package/dist/cjs/types/defaultGTProps.d.ts.map +1 -0
- package/dist/cjs/types/defaultGTProps.js +31 -0
- package/dist/cjs/types/defaultGTProps.js.map +1 -0
- package/dist/mjs/client/client-only/helpers/renderDictionary.d.ts.map +1 -1
- package/dist/mjs/client/client-only/helpers/renderDictionary.js +59 -3
- package/dist/mjs/client/client-only/helpers/renderDictionary.js.map +1 -1
- package/dist/mjs/client/hooks/useGT.d.ts.map +1 -1
- package/dist/mjs/client/hooks/useGT.js +4 -11
- package/dist/mjs/client/hooks/useGT.js.map +1 -1
- package/dist/mjs/server/renderChildren.d.ts +1 -1
- package/dist/mjs/server/renderChildren.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = createNextMiddleware;
|
|
4
|
+
const generaltranslation_1 = require("generaltranslation");
|
|
5
|
+
const imports_1 = require("../next/imports/imports");
|
|
6
|
+
const cookieSettings_1 = require("./cookieSettings");
|
|
7
|
+
/**
|
|
8
|
+
* Extracts the locale from the given pathname.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} pathname - The pathname to extract from.
|
|
11
|
+
* @returns {string} The extracted locale.
|
|
12
|
+
*/
|
|
13
|
+
function extractLocale(pathname) {
|
|
14
|
+
const matches = pathname.match(/^\/([^\/]+)(?:\/|$)/);
|
|
15
|
+
return matches ? matches[1] : null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Copy cookies from the Set-Cookie header of the response to the Cookie header of the request,
|
|
19
|
+
* so that it will appear to SSR/RSC as if the user already has the new cookies.
|
|
20
|
+
* via
|
|
21
|
+
*/
|
|
22
|
+
function applyNewCookies(req, res) {
|
|
23
|
+
const NextResponse = (0, imports_1.getNextResponse)();
|
|
24
|
+
if (!NextResponse)
|
|
25
|
+
return;
|
|
26
|
+
const ResponseCookies = (0, imports_1.getNextResponseCookies)();
|
|
27
|
+
if (!ResponseCookies)
|
|
28
|
+
return;
|
|
29
|
+
const RequestCookies = (0, imports_1.getNextRequestCookies)();
|
|
30
|
+
if (!RequestCookies)
|
|
31
|
+
return;
|
|
32
|
+
// 1. Parse Set-Cookie header from the response
|
|
33
|
+
const setCookies = new ResponseCookies(res.headers);
|
|
34
|
+
// 2. Construct updated Cookie header for the request
|
|
35
|
+
const newReqHeaders = new Headers(req.headers);
|
|
36
|
+
const newReqCookies = new RequestCookies(newReqHeaders);
|
|
37
|
+
setCookies.getAll().forEach((cookie) => newReqCookies.set(cookie));
|
|
38
|
+
// 3. Set up the “request header overrides” (see https://github.com/vercel/next.js/pull/41380)
|
|
39
|
+
// on a dummy response
|
|
40
|
+
// NextResponse.next will set x-middleware-override-headers / x-middleware-request-* headers
|
|
41
|
+
const dummyRes = NextResponse.next({ request: { headers: newReqHeaders } });
|
|
42
|
+
// 4. Copy the “request header overrides” headers from our dummy response to the real response
|
|
43
|
+
dummyRes.headers.forEach((value, key) => {
|
|
44
|
+
if (key === 'x-middleware-override-headers' || key.startsWith('x-middleware-request-')) {
|
|
45
|
+
res.headers.set(key, value);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Middleware to set a cookie based on the locale.
|
|
51
|
+
* @param {NextRequest} req - The incoming request object.
|
|
52
|
+
*/
|
|
53
|
+
function createNextMiddleware({ defaultLocale = 'en', approvedLocales, localeRouting = true } = { defaultLocale: 'en', localeRouting: true }) {
|
|
54
|
+
return (req) => {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
const NextResponse = (0, imports_1.getNextResponse)();
|
|
57
|
+
if (!NextResponse)
|
|
58
|
+
return;
|
|
59
|
+
const headers = (0, imports_1.getNextHeaders)();
|
|
60
|
+
if (!headers)
|
|
61
|
+
return;
|
|
62
|
+
const headerList = headers();
|
|
63
|
+
const res = NextResponse.next();
|
|
64
|
+
let userLocale = defaultLocale;
|
|
65
|
+
if (localeRouting) {
|
|
66
|
+
// Check if there is any supported locale in the pathname
|
|
67
|
+
const { pathname } = req.nextUrl;
|
|
68
|
+
const locale = extractLocale(pathname);
|
|
69
|
+
let pathnameHasLocale = false;
|
|
70
|
+
if (locale) {
|
|
71
|
+
if (approvedLocales) {
|
|
72
|
+
for (const approvedLocale of approvedLocales) {
|
|
73
|
+
if ((0, generaltranslation_1.isSameLanguage)(approvedLocale, locale)) {
|
|
74
|
+
userLocale = approvedLocale;
|
|
75
|
+
pathnameHasLocale = true;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
if ((0, generaltranslation_1.isValidLanguageCode)(locale)) {
|
|
82
|
+
userLocale = locale;
|
|
83
|
+
pathnameHasLocale = true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (pathnameHasLocale) {
|
|
88
|
+
res.cookies.set(cookieSettings_1.localeCookieName, userLocale);
|
|
89
|
+
applyNewCookies(req, res);
|
|
90
|
+
return res;
|
|
91
|
+
}
|
|
92
|
+
// If there's no locale, try to get one from the referer
|
|
93
|
+
const referer = headerList.get('referer');
|
|
94
|
+
if (referer && typeof referer === 'string') {
|
|
95
|
+
const refererLocale = extractLocale((_a = (new URL(referer))) === null || _a === void 0 ? void 0 : _a.pathname);
|
|
96
|
+
if (refererLocale) {
|
|
97
|
+
let refererLocaleIsValid = false;
|
|
98
|
+
if (approvedLocales) {
|
|
99
|
+
for (const approvedLocale of approvedLocales) {
|
|
100
|
+
if ((0, generaltranslation_1.isSameLanguage)(approvedLocale, refererLocale)) {
|
|
101
|
+
userLocale = approvedLocale;
|
|
102
|
+
refererLocaleIsValid = true;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
if ((0, generaltranslation_1.isValidLanguageCode)(refererLocale)) {
|
|
109
|
+
userLocale = refererLocale;
|
|
110
|
+
refererLocaleIsValid = true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (refererLocaleIsValid) {
|
|
114
|
+
req.nextUrl.pathname = `/${userLocale}/${pathname}`;
|
|
115
|
+
applyNewCookies(req, res);
|
|
116
|
+
return NextResponse.redirect(req.nextUrl);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const acceptedLocales = (_b = headerList.get('accept-language')) === null || _b === void 0 ? void 0 : _b.split(',').map(item => { var _a; return (_a = item.split(';')) === null || _a === void 0 ? void 0 : _a[0].trim(); });
|
|
122
|
+
if (acceptedLocales && acceptedLocales.length > 0) {
|
|
123
|
+
if (approvedLocales) {
|
|
124
|
+
for (const locale of acceptedLocales) {
|
|
125
|
+
for (const approvedLocale of approvedLocales) {
|
|
126
|
+
if ((0, generaltranslation_1.isSameLanguage)(locale, approvedLocale)) {
|
|
127
|
+
userLocale = approvedLocale;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
userLocale = acceptedLocales[0];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
res.cookies.set(cookieSettings_1.localeCookieName, userLocale);
|
|
138
|
+
if (localeRouting) {
|
|
139
|
+
const { pathname } = req.nextUrl;
|
|
140
|
+
// Redirect if there is no locale
|
|
141
|
+
req.nextUrl.pathname = `/${userLocale}${pathname}`;
|
|
142
|
+
// e.g. incoming request is /products
|
|
143
|
+
// The new URL is now /en-US/products
|
|
144
|
+
applyNewCookies(req, res);
|
|
145
|
+
return NextResponse.redirect(req.nextUrl);
|
|
146
|
+
}
|
|
147
|
+
applyNewCookies(req, res);
|
|
148
|
+
return res;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=createNextMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createNextMiddleware.js","sourceRoot":"","sources":["../../../src/middleware/createNextMiddleware.ts"],"names":[],"mappings":";;AAwDA,uCAyHC;AAjLD,2DAAyE;AACzE,qDAAyH;AACzH,qDAAoD;AAEpD;;;;;GAKG;AACH,SAAS,aAAa,CAAC,QAAgB;IACnC,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACtD,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACvC,CAAC;AAED;;;;GAIG;AACH,SAAS,eAAe,CAAC,GAAQ,EAAE,GAAQ;IAEvC,MAAM,YAAY,GAAG,IAAA,yBAAe,GAAE,CAAC;IACvC,IAAI,CAAC,YAAY;QAAE,OAAO;IAE1B,MAAM,eAAe,GAAG,IAAA,gCAAsB,GAAE,CAAC;IACjD,IAAI,CAAC,eAAe;QAAE,OAAO;IAE7B,MAAM,cAAc,GAAG,IAAA,+BAAqB,GAAE,CAAC;IAC/C,IAAI,CAAC,cAAc;QAAE,OAAO;IAE5B,+CAA+C;IAC/C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AM,EAAE,cAAc,CAAC,EAAE,CAAC;4BACzC,UAAU,GAAG,cAAc,CAAC;4BAC5B,MAAM;wBACV,CAAC;oBACL,CAAC;gBACL,CAAC;YACL,CAAC;iBACI,CAAC;gBACF,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,CAAA;YACnC,CAAC;QACL,CAAC;QAED,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,iCAAgB,EAAE,UAAU,CAAC,CAAA;QAE7C,IAAI,aAAa,EAAE,CAAC;YAEhB,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,OAAO,CAAA;YAEhC,iCAAiC;YACjC,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,IAAI,UAAU,GAAG,QAAQ,EAAE,CAAA;YAElD,qCAAqC;YACrC,qCAAqC;YACrC,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YAC1B,OAAO,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAE7C,CAAC;QAED,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC1B,OAAO,GAAG,CAAC;IAEf,CAAC,CAAA;AAEL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,MAAM,mCAAmC,CAAC;AACrE,OAAO,EACH,oBAAoB,EACvB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createNextMiddleware = void 0;
|
|
7
|
+
const createNextMiddleware_1 = __importDefault(require("./middleware/createNextMiddleware"));
|
|
8
|
+
exports.createNextMiddleware = createNextMiddleware_1.default;
|
|
9
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":";;;;;;AAAA,6FAAqE;AAEjE,+BAFG,8BAAoB,CAEH"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function getNextHeaders(): (() => Headers) | null;
|
|
2
|
+
export declare function getNextCookies(): (() => any) | null;
|
|
3
|
+
export declare function getNextResponse(): any;
|
|
4
|
+
export declare function getNextRequestCookies(): any;
|
|
5
|
+
export declare function getNextResponseCookies(): any;
|
|
6
|
+
//# sourceMappingURL=imports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../../../../src/next/imports/imports.ts"],"names":[],"mappings":"AAkBA,wBAAgB,cAAc,WAjBV,OAAO,SAoB1B;AAED,wBAAgB,cAAc,WAvBV,GAAG,SA0BtB;AAoBD,wBAAgB,eAAe,QAG9B;AAsBD,wBAAgB,qBAAqB,QAGpC;AAED,wBAAgB,sBAAsB,QAGrC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNextHeaders = getNextHeaders;
|
|
4
|
+
exports.getNextCookies = getNextCookies;
|
|
5
|
+
exports.getNextResponse = getNextResponse;
|
|
6
|
+
exports.getNextRequestCookies = getNextRequestCookies;
|
|
7
|
+
exports.getNextResponseCookies = getNextResponseCookies;
|
|
8
|
+
let cookies = null;
|
|
9
|
+
let headers = null;
|
|
10
|
+
/**
|
|
11
|
+
* Load the 'next/headers' module
|
|
12
|
+
*/
|
|
13
|
+
function loadNextHeaders() {
|
|
14
|
+
try {
|
|
15
|
+
if (!headers || !cookies) {
|
|
16
|
+
const nextHeaders = require('next/headers');
|
|
17
|
+
headers = nextHeaders.headers;
|
|
18
|
+
cookies = nextHeaders.cookies;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.warn('next/headers is not available. Running in non-Next.js environment.');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function getNextHeaders() {
|
|
26
|
+
if (!headers)
|
|
27
|
+
loadNextHeaders();
|
|
28
|
+
return headers;
|
|
29
|
+
}
|
|
30
|
+
function getNextCookies() {
|
|
31
|
+
if (!cookies)
|
|
32
|
+
loadNextHeaders();
|
|
33
|
+
return cookies;
|
|
34
|
+
}
|
|
35
|
+
//
|
|
36
|
+
let NextResponse = null;
|
|
37
|
+
/**
|
|
38
|
+
* Load the 'next/server' module
|
|
39
|
+
*/
|
|
40
|
+
function loadNextServer() {
|
|
41
|
+
try {
|
|
42
|
+
if (!NextResponse) {
|
|
43
|
+
const server = require('next/server');
|
|
44
|
+
NextResponse = server.NextResponse;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.warn('next/server is not available. Running in non-Next.js environment.');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function getNextResponse() {
|
|
52
|
+
if (!NextResponse)
|
|
53
|
+
loadNextServer();
|
|
54
|
+
return NextResponse;
|
|
55
|
+
}
|
|
56
|
+
//
|
|
57
|
+
let ResponseCookies = null;
|
|
58
|
+
let RequestCookies = null;
|
|
59
|
+
/**
|
|
60
|
+
* Load the 'next/dist/server/web/spec-extension/cookies' module
|
|
61
|
+
*/
|
|
62
|
+
function loadNextSpecExtensionCookies() {
|
|
63
|
+
try {
|
|
64
|
+
if (!ResponseCookies) {
|
|
65
|
+
const cookies = require('next/dist/server/web/spec-extension/cookies');
|
|
66
|
+
ResponseCookies = cookies.ResponseCookies;
|
|
67
|
+
RequestCookies = cookies.RequestCookies;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
console.warn('next/server is not available. Running in non-Next.js environment.');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function getNextRequestCookies() {
|
|
75
|
+
if (!RequestCookies)
|
|
76
|
+
loadNextSpecExtensionCookies();
|
|
77
|
+
return RequestCookies;
|
|
78
|
+
}
|
|
79
|
+
function getNextResponseCookies() {
|
|
80
|
+
if (!ResponseCookies)
|
|
81
|
+
loadNextSpecExtensionCookies();
|
|
82
|
+
return ResponseCookies;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=imports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imports.js","sourceRoot":"","sources":["../../../../src/next/imports/imports.ts"],"names":[],"mappings":";;AAkBA,wCAGC;AAED,wCAGC;AAoBD,0CAGC;AAsBD,sDAGC;AAED,wDAGC;AA/ED,IAAI,OAAO,GAAuB,IAAI,CAAC;AACvC,IAAI,OAAO,GAA2B,IAAI,CAAC;AAE3C;;GAEG;AACH,SAAS,eAAe;IACpB,IAAI,CAAC;QACD,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;YACvB,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;YAC5C,OAAO,GAAG,WAAW,CAAC,OAA0B,CAAC;YACjD,OAAO,GAAG,WAAW,CAAC,OAAsB,CAAC;QACjD,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,oEAAoE,CAAC,CAAC;IACvF,CAAC;AACL,CAAC;AAED,SAAgB,cAAc;IAC1B,IAAI,CAAC,OAAO;QAAE,eAAe,EAAE,CAAC;IAChC,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,SAAgB,cAAc;IAC1B,IAAI,CAAC,OAAO;QAAE,eAAe,EAAE,CAAC;IAChC,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,EAAE;AAEF,IAAI,YAAY,GAAQ,IAAI,CAAC;AAE7B;;GAEG;AACH,SAAS,cAAc;IACnB,IAAI,CAAC;QACD,IAAI,CAAC,YAAY,EAAE,CAAC;YAChB,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;YACtC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACvC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,mEAAmE,CAAC,CAAC;IACtF,CAAC;AACL,CAAC;AAED,SAAgB,eAAe;IAC3B,IAAI,CAAC,YAAY;QAAE,cAAc,EAAE,CAAC;IACpC,OAAO,YAAY,CAAC;AACxB,CAAC;AAED,EAAE;AAEF,IAAI,eAAe,GAAe,IAAI,CAAC;AACvC,IAAI,cAAc,GAAe,IAAI,CAAC;AAEtC;;GAEG;AACH,SAAS,4BAA4B;IACjC,IAAI,CAAC;QACD,IAAI,CAAC,eAAe,EAAE,CAAC;YACnB,MAAM,OAAO,GAAG,OAAO,CAAC,6CAA6C,CAAC,CAAC;YACvE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;YAC1C,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;QAC3C,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,mEAAmE,CAAC,CAAC;IACtF,CAAC;AACL,CAAC;AAED,SAAgB,qBAAqB;IACjC,IAAI,CAAC,cAAc;QAAE,4BAA4B,EAAE,CAAC;IACpD,OAAO,cAAc,CAAC;AAC1B,CAAC;AAED,SAAgB,sBAAsB;IAClC,IAAI,CAAC,eAAe;QAAE,4BAA4B,EAAE,CAAC;IACrD,OAAO,eAAe,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves the 'accept-language' header from the headers list.
|
|
3
|
+
* If the 'next/headers' module is not available, it attempts to load it. If the
|
|
4
|
+
* headers function is available, it returns the primary language from the 'accept-language'
|
|
5
|
+
* header. If the headers function or 'accept-language' header is not available, returns null.
|
|
6
|
+
*
|
|
7
|
+
* @returns {string | null} A promise that resolves to the primary language from the
|
|
8
|
+
* 'accept-language' header, or null if not available.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getNextLocale(defaultLocale?: string, approvedLocales?: string[] | undefined): string;
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves the 'host' header from the headers list.
|
|
13
|
+
* If the 'next/headers' module is not available, it attempts to load it. If the
|
|
14
|
+
* headers function is available, it returns the value of the 'host' header.
|
|
15
|
+
* If the headers function or 'host' header is not available, returns null.
|
|
16
|
+
*
|
|
17
|
+
* @returns {string | null} A promise that resolves to the value of the 'host' header,
|
|
18
|
+
* or null if not available.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getNextDomain(): string | null;
|
|
21
|
+
//# sourceMappingURL=requestFunctions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestFunctions.d.ts","sourceRoot":"","sources":["../../../src/next/requestFunctions.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,aAAa,GAAE,MAAW,EAAE,eAAe,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,CAiBxG;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,IAAI,MAAM,GAAG,IAAI,CAK7C"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getNextLocale = getNextLocale;
|
|
7
|
+
exports.getNextDomain = getNextDomain;
|
|
8
|
+
const determineLocale_1 = __importDefault(require("../config/determineLocale"));
|
|
9
|
+
const cookieSettings_1 = require("../middleware/cookieSettings");
|
|
10
|
+
const imports_1 = require("./imports/imports");
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves the 'accept-language' header from the headers list.
|
|
13
|
+
* If the 'next/headers' module is not available, it attempts to load it. If the
|
|
14
|
+
* headers function is available, it returns the primary language from the 'accept-language'
|
|
15
|
+
* header. If the headers function or 'accept-language' header is not available, returns null.
|
|
16
|
+
*
|
|
17
|
+
* @returns {string | null} A promise that resolves to the primary language from the
|
|
18
|
+
* 'accept-language' header, or null if not available.
|
|
19
|
+
*/
|
|
20
|
+
function getNextLocale(defaultLocale = '', approvedLocales) {
|
|
21
|
+
var _a;
|
|
22
|
+
try {
|
|
23
|
+
const cookies = (0, imports_1.getNextCookies)();
|
|
24
|
+
if (cookies) {
|
|
25
|
+
const cookieStore = cookies();
|
|
26
|
+
const localeCookie = cookieStore.get(cookieSettings_1.localeCookieName);
|
|
27
|
+
if (localeCookie === null || localeCookie === void 0 ? void 0 : localeCookie.value)
|
|
28
|
+
return localeCookie.value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.warn(error);
|
|
33
|
+
}
|
|
34
|
+
const headers = (0, imports_1.getNextHeaders)();
|
|
35
|
+
if (!headers)
|
|
36
|
+
return defaultLocale;
|
|
37
|
+
const headerList = headers();
|
|
38
|
+
const acceptedLocales = (_a = headerList.get('accept-language')) === null || _a === void 0 ? void 0 : _a.split(',').map(item => { var _a; return (_a = item.split(';')) === null || _a === void 0 ? void 0 : _a[0].trim(); });
|
|
39
|
+
const locale = acceptedLocales ? (0, determineLocale_1.default)(approvedLocales, acceptedLocales, defaultLocale) : defaultLocale;
|
|
40
|
+
return locale;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves the 'host' header from the headers list.
|
|
44
|
+
* If the 'next/headers' module is not available, it attempts to load it. If the
|
|
45
|
+
* headers function is available, it returns the value of the 'host' header.
|
|
46
|
+
* If the headers function or 'host' header is not available, returns null.
|
|
47
|
+
*
|
|
48
|
+
* @returns {string | null} A promise that resolves to the value of the 'host' header,
|
|
49
|
+
* or null if not available.
|
|
50
|
+
*/
|
|
51
|
+
function getNextDomain() {
|
|
52
|
+
const headers = (0, imports_1.getNextHeaders)();
|
|
53
|
+
if (!headers)
|
|
54
|
+
return null;
|
|
55
|
+
const headerList = headers();
|
|
56
|
+
return headerList.get('host') || null;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=requestFunctions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestFunctions.js","sourceRoot":"","sources":["../../../src/next/requestFunctions.ts"],"names":[],"mappings":";;;;;AAaA,sCAiBC;AAWD,sCAKC;AA9CD,gFAAwD;AACxD,iEAAgE;AAChE,+CAAmE;AAEnE;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAAC,gBAAwB,EAAE,EAAE,eAAsC;;IAC5F,IAAI,CAAC;QACD,MAAM,OAAO,GAAG,IAAA,wBAAc,GAAE,CAAC;QACjC,IAAI,OAAO,EAAE,CAAC;YACV,MAAM,WAAW,GAAG,OAAO,EAAE,CAAC;YAC9B,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,iCAAgB,CAAC,CAAC;YACvD,IAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,KAAK;gBAAE,OAAO,YAAY,CAAC,KAAK,CAAC;QACvD,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IACD,MAAM,OAAO,GAAG,IAAA,wBAAc,GAAE,CAAC;IACjC,IAAI,CAAC,OAAO;QAAE,OAAO,aAAa,CAAC;IACnC,MAAM,UAAU,GAAG,OAAO,EAAE,CAAC;IAC7B,MAAM,eAAe,GAAG,MAAA,UAAU,CAAC,GAAG,CAAC,iBAAiB,CAAC,0CAAE,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,WAAC,OAAA,MAAA,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,0CAAG,CAAC,EAAE,IAAI,EAAE,CAAA,EAAA,CAAC,CAAC;IAC/G,MAAM,MAAM,GAAG,eAAe,CAAC,CAAC,CAAC,IAAA,yBAAe,EAAC,eAAe,EAAE,eAAe,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;IAClH,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,aAAa;IACzB,MAAM,OAAO,GAAG,IAAA,wBAAc,GAAE,CAAC;IACjC,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAC1B,MAAM,UAAU,GAAG,OAAO,EAAE,CAAC;IAC7B,OAAO,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import CreateGTProps from './types/CreateGTProps';
|
|
2
|
+
import GeneralTranslation from "./types/GeneralTranslationInterface";
|
|
3
|
+
import Variables from "./types/Variables";
|
|
4
|
+
/**
|
|
5
|
+
* Initializes the `gt-react` i18n library with Next.js specific configurations.
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} params - Configuration options.
|
|
8
|
+
* @param {string} [params.apiKey] - API key for cloud integration. Default is fetched from environment variable `GT_API_KEY`.
|
|
9
|
+
* @param {string} [params.projectID] - Project ID for cloud integration. Default is fetched from environment variable `GT_PROJECT_ID`.
|
|
10
|
+
* @param {string} [params.cacheURL] - URL for caching. Default is "https://cache.gtx.dev".
|
|
11
|
+
* @param {string} [params.baseURL] - Base URL for API requests. Default is "https://prod.gtx.dev".
|
|
12
|
+
* @param {string[]} [params.approvedLocales] - List of approved locales. Default is an empty array.
|
|
13
|
+
* @param {string} [params.defaultLocale] - Default locale for the translation. Default is the first locale in `approvedLocales` or 'en'.
|
|
14
|
+
* @param {Function} [params.getLocale] - Function to get the current locale. Sets using Next.js request headers if not provided.
|
|
15
|
+
* @param {string} [params.renderMethod] - How translations are rendered for the first time. options are "skeleton", "replace", "hang", "subtle".
|
|
16
|
+
* @param {string} [params.dictionaryName] - Name of the dictionary to use. Default is "default".
|
|
17
|
+
* @param {Object} [params.dictionary] - Dictionary object containing translations.
|
|
18
|
+
* @param {number} [params.maxConcurrentRequests] - Maximum number of concurrent requests. Default is 2.
|
|
19
|
+
* @param {number} [params.batchInterval] - Interval for batching requests in milliseconds. Default is 1000.
|
|
20
|
+
* @param {Object} [...metadata] - Any additional metadata. Used for experimental variables.
|
|
21
|
+
* @returns {GeneralTranslation} An object containing internationalization and translation functions.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createGT({ approvedLocales, defaultLocale, getLocale, getMetadata, ...metadata }?: CreateGTProps): GeneralTranslation;
|
|
24
|
+
/**
|
|
25
|
+
* Creates variable components only, for use in GT dictionaries.
|
|
26
|
+
*
|
|
27
|
+
* @param {Object} params - Configuration options.
|
|
28
|
+
* @param {string[]} [params.approvedLocales] - List of approved locales.
|
|
29
|
+
* @param {string} params.defaultLocale - Default locale for the translation.
|
|
30
|
+
* @param {() => string} params.getLocale - Function to get the current locale.
|
|
31
|
+
* @returns {Object} An object containing variable components.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createVariables({ approvedLocales, defaultLocale, getLocale }: {
|
|
34
|
+
approvedLocales?: string[];
|
|
35
|
+
defaultLocale?: string;
|
|
36
|
+
getLocale?: () => string;
|
|
37
|
+
}): Variables;
|
|
38
|
+
//# sourceMappingURL=next.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../../src/next.ts"],"names":[],"mappings":"AAEA,OAAO,aAAa,MAAM,uBAAuB,CAAC;AAClD,OAAO,kBAAkB,MAAM,qCAAqC,CAAC;AACrE,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAE1C;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CAAC,EACrB,eAAe,EACf,aAA4C,EAC5C,SAAS,EAAE,WAAW,EACtB,GAAG,QAAQ,EACd,GAAE,aAEF,GAAG,kBAAkB,CAIrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,EAC5B,eAAe,EACf,aAAa,EACb,SAAS,EACZ,EAAE;IACC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,MAAM,CAAC;CAC5B,GAAG,SAAS,CAGZ"}
|
package/dist/cjs/next.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.createGT = createGT;
|
|
15
|
+
exports.createVariables = createVariables;
|
|
16
|
+
const server_1 = require("./server");
|
|
17
|
+
const requestFunctions_1 = require("./next/requestFunctions");
|
|
18
|
+
/**
|
|
19
|
+
* Initializes the `gt-react` i18n library with Next.js specific configurations.
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} params - Configuration options.
|
|
22
|
+
* @param {string} [params.apiKey] - API key for cloud integration. Default is fetched from environment variable `GT_API_KEY`.
|
|
23
|
+
* @param {string} [params.projectID] - Project ID for cloud integration. Default is fetched from environment variable `GT_PROJECT_ID`.
|
|
24
|
+
* @param {string} [params.cacheURL] - URL for caching. Default is "https://cache.gtx.dev".
|
|
25
|
+
* @param {string} [params.baseURL] - Base URL for API requests. Default is "https://prod.gtx.dev".
|
|
26
|
+
* @param {string[]} [params.approvedLocales] - List of approved locales. Default is an empty array.
|
|
27
|
+
* @param {string} [params.defaultLocale] - Default locale for the translation. Default is the first locale in `approvedLocales` or 'en'.
|
|
28
|
+
* @param {Function} [params.getLocale] - Function to get the current locale. Sets using Next.js request headers if not provided.
|
|
29
|
+
* @param {string} [params.renderMethod] - How translations are rendered for the first time. options are "skeleton", "replace", "hang", "subtle".
|
|
30
|
+
* @param {string} [params.dictionaryName] - Name of the dictionary to use. Default is "default".
|
|
31
|
+
* @param {Object} [params.dictionary] - Dictionary object containing translations.
|
|
32
|
+
* @param {number} [params.maxConcurrentRequests] - Maximum number of concurrent requests. Default is 2.
|
|
33
|
+
* @param {number} [params.batchInterval] - Interval for batching requests in milliseconds. Default is 1000.
|
|
34
|
+
* @param {Object} [...metadata] - Any additional metadata. Used for experimental variables.
|
|
35
|
+
* @returns {GeneralTranslation} An object containing internationalization and translation functions.
|
|
36
|
+
*/
|
|
37
|
+
function createGT(_a = {
|
|
38
|
+
defaultLocale: 'en'
|
|
39
|
+
}) {
|
|
40
|
+
var { approvedLocales, defaultLocale = (approvedLocales === null || approvedLocales === void 0 ? void 0 : approvedLocales[0]) || 'en', getLocale, getMetadata } = _a, metadata = __rest(_a, ["approvedLocales", "defaultLocale", "getLocale", "getMetadata"]);
|
|
41
|
+
const finalGetLocale = getLocale || (() => { return (0, requestFunctions_1.getNextLocale)(defaultLocale, approvedLocales); });
|
|
42
|
+
const finalGetMetadata = getMetadata || (() => { return { domain: (0, requestFunctions_1.getNextDomain)() }; });
|
|
43
|
+
return (0, server_1.createGT)(Object.assign({ defaultLocale, getLocale: finalGetLocale, getMetadata: finalGetMetadata }, metadata));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates variable components only, for use in GT dictionaries.
|
|
47
|
+
*
|
|
48
|
+
* @param {Object} params - Configuration options.
|
|
49
|
+
* @param {string[]} [params.approvedLocales] - List of approved locales.
|
|
50
|
+
* @param {string} params.defaultLocale - Default locale for the translation.
|
|
51
|
+
* @param {() => string} params.getLocale - Function to get the current locale.
|
|
52
|
+
* @returns {Object} An object containing variable components.
|
|
53
|
+
*/
|
|
54
|
+
function createVariables({ approvedLocales, defaultLocale, getLocale }) {
|
|
55
|
+
const finalGetLocale = getLocale || (() => { return (0, requestFunctions_1.getNextLocale)(defaultLocale, approvedLocales); });
|
|
56
|
+
return (0, server_1.createVariables)({ approvedLocales, defaultLocale, getLocale: finalGetLocale });
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=next.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.js","sourceRoot":"","sources":["../../src/next.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAyBA,4BAWC;AAWD,0CAWC;AA1DD,qCAA4F;AAC5F,8DAAuE;AAKvE;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,QAAQ,CAAC,KAKN;IACf,aAAa,EAAE,IAAI;CACtB;QAPwB,EACrB,eAAe,EACf,aAAa,GAAG,CAAA,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAG,CAAC,CAAC,KAAI,IAAI,EAC5C,SAAS,EAAE,WAAW,OAIzB,EAHM,QAAQ,cAJU,gEAKxB,CADc;IAIX,MAAM,cAAc,GAAG,SAAS,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,IAAA,gCAAa,EAAC,aAAa,EAAE,eAAe,CAAC,CAAA,CAAC,CAAC,CAAC,CAAC;IACrG,MAAM,gBAAgB,GAAG,WAAW,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,IAAA,gCAAa,GAAE,EAAE,CAAA,CAAC,CAAC,CAAC,CAAC;IACvF,OAAO,IAAA,iBAAY,kBAAG,aAAa,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,gBAAgB,IAAK,QAAQ,EAAG,CAAC;AAClH,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAAC,EAC5B,eAAe,EACf,aAAa,EACb,SAAS,EAKZ;IACG,MAAM,cAAc,GAAG,SAAS,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,IAAA,gCAAa,EAAC,aAAa,EAAE,eAAe,CAAC,CAAA,CAAC,CAAC,CAAC,CAAC;IACrG,OAAO,IAAA,wBAAmB,EAAC,EAAE,eAAe,EAAE,aAAa,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC,CAAC;AAC9F,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculateID.d.ts","sourceRoot":"","sources":["../../../src/primitives/calculateID.ts"],"names":[],"mappings":"AASA,wBAA8B,WAAW,CAAC,iBAAiB,EAAE,GAAG,mBAM/D"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.default = calculateID;
|
|
16
|
+
const xxhash_wasm_1 = __importDefault(require("xxhash-wasm"));
|
|
17
|
+
let hashFunctionPromise = (0, xxhash_wasm_1.default)().then(hasher => hasher.h64ToString);
|
|
18
|
+
let hashFunction = null;
|
|
19
|
+
hashFunctionPromise.then(fn => {
|
|
20
|
+
hashFunction = fn;
|
|
21
|
+
});
|
|
22
|
+
function calculateID(childrenAsObjects) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
if (!hashFunction) {
|
|
25
|
+
hashFunction = yield hashFunctionPromise;
|
|
26
|
+
}
|
|
27
|
+
const unhashedKey = JSON.stringify(sanitizeChildrenAsObjects(childrenAsObjects));
|
|
28
|
+
return hashFunction(unhashedKey);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function sanitizeChildrenAsObjects(childrenAsObjects) {
|
|
32
|
+
const sanitizeChild = (child) => {
|
|
33
|
+
var _a;
|
|
34
|
+
if (typeof child === 'object' && child.type) {
|
|
35
|
+
if ((_a = child === null || child === void 0 ? void 0 : child.props) === null || _a === void 0 ? void 0 : _a.children) {
|
|
36
|
+
return Object.assign(Object.assign({}, child), { props: Object.assign(Object.assign({}, child.props), { children: sanitizeChildren(child.props.children) }), type: '' });
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return Object.assign(Object.assign({}, child), { type: '' });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return child;
|
|
43
|
+
};
|
|
44
|
+
const sanitizeChildren = (children) => {
|
|
45
|
+
return (Array.isArray(children)) ? children.map(sanitizeChild) : sanitizeChild(children);
|
|
46
|
+
};
|
|
47
|
+
return sanitizeChildren(childrenAsObjects);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=calculateID.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculateID.js","sourceRoot":"","sources":["../../../src/primitives/calculateID.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AASA,8BAMC;AAfD,8DAAiC;AAEjC,IAAI,mBAAmB,GAAG,IAAA,qBAAM,GAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AACtE,IAAI,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}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createValues.d.ts","sourceRoot":"","sources":["../../../src/primitives/createValues.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;;;cAW5E"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = createValues;
|
|
4
|
+
function createValues(n, values) {
|
|
5
|
+
if (typeof n !== 'number') {
|
|
6
|
+
if (!values || typeof values !== 'object') {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
return Object.assign({}, values);
|
|
10
|
+
}
|
|
11
|
+
if (values && typeof values === 'object') {
|
|
12
|
+
return Object.assign(Object.assign({}, values), { n });
|
|
13
|
+
}
|
|
14
|
+
return { n };
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=createValues.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createValues.js","sourceRoot":"","sources":["../../../src/primitives/createValues.ts"],"names":[],"mappings":";;AAAA,+BAWC;AAXD,SAAwB,YAAY,CAAC,CAAU,EAAE,MAA4B;IACzE,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QACxB,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YACxC,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,yBAAY,MAAM,EAAG;IACzB,CAAC;IACD,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QACvC,uCAAY,MAAM,KAAE,CAAC,IAAG;IAC5B,CAAC;IACD,OAAO,EAAE,CAAC,EAAE,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultVariableNames.d.ts","sourceRoot":"","sources":["../../../src/primitives/defaultVariableNames.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAKhD,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const defaultVariableNames = {
|
|
4
|
+
"variable": "value",
|
|
5
|
+
"number": "n",
|
|
6
|
+
"date": "date",
|
|
7
|
+
"currency": "cost"
|
|
8
|
+
};
|
|
9
|
+
exports.default = defaultVariableNames;
|
|
10
|
+
//# sourceMappingURL=defaultVariableNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultVariableNames.js","sourceRoot":"","sources":["../../../src/primitives/defaultVariableNames.ts"],"names":[],"mappings":";;AAAA,MAAM,oBAAoB,GAA2B;IACjD,UAAU,EAAE,OAAO;IACnB,QAAQ,EAAE,GAAG;IACb,MAAM,EAAE,MAAM;IACd,UAAU,EAAE,MAAM;CACrB,CAAC;AAEF,kBAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Flattens a nested dictionary by concatenating nested keys.
|
|
4
|
+
* @param {Record<string, any>} obj - The dictionary to flatten.
|
|
5
|
+
* @param {string} [prefix=''] - The prefix for nested keys.
|
|
6
|
+
* @returns {Record<string, React.ReactNode>} The flattened dictionary object.
|
|
7
|
+
*/
|
|
8
|
+
export default function flattenDictionary(obj: Record<string, any>, prefix?: string): Record<string, React.ReactNode>;
|
|
9
|
+
//# sourceMappingURL=flattenDictionary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flattenDictionary.d.ts","sourceRoot":"","sources":["../../../src/primitives/flattenDictionary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAE,MAAW,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAgBxH"}
|