@saasquatch/component-environment 1.0.0 → 1.0.1-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/index.d.ts CHANGED
@@ -253,6 +253,7 @@ declare function setUserIdentity(identity?: UserIdentity): void;
253
253
  */
254
254
  declare function getUserIdentity(): UserIdentity | undefined;
255
255
 
256
+ declare function validateLocale(locale?: string): string | undefined;
256
257
  /**
257
258
  * Lazily start the locale context provider. If it already exists, the existing provider is
258
259
  * returned. This function is safe to call multiple times.
@@ -289,4 +290,4 @@ declare function setProgramId(programId: string | undefined): void;
289
290
  */
290
291
  declare function getProgramId(): string | undefined;
291
292
 
292
- export { BrowserHistory, DEFAULT_MEDIUM, DecodedSquatchJWT, DecodedWidgetAPIJWT, EngagementMedium, Environment, EnvironmentSDK, HistoryEntry, LOCALE_CONTEXT_NAME, LazyHistory, LocaleContextName, MemoryHistory, PROGRAM_CONTEXT_NAME, PortalEnv, ProgramContextName, SquatchAdmin, SquatchAndroid, SquatchJS2, USER_CONTEXT_NAME, UserContextName, UserId, UserIdentity, WidgetIdent, getAppDomain, getEngagementMedium, getEnvironment, getEnvironmentSDK, getLocale, getProgramId, getTenantAlias, getUserIdentity, _default as history, isDemo, lazilyStartLocaleContext, lazilyStartProgramContext, lazilyStartUserContext, setLocale, setProgramId, setUserIdentity, userIdentityFromJwt };
293
+ export { BrowserHistory, DEFAULT_MEDIUM, DecodedSquatchJWT, DecodedWidgetAPIJWT, EngagementMedium, Environment, EnvironmentSDK, HistoryEntry, LOCALE_CONTEXT_NAME, LazyHistory, LocaleContextName, MemoryHistory, PROGRAM_CONTEXT_NAME, PortalEnv, ProgramContextName, SquatchAdmin, SquatchAndroid, SquatchJS2, USER_CONTEXT_NAME, UserContextName, UserId, UserIdentity, WidgetIdent, getAppDomain, getEngagementMedium, getEnvironment, getEnvironmentSDK, getLocale, getProgramId, getTenantAlias, getUserIdentity, _default as history, isDemo, lazilyStartLocaleContext, lazilyStartProgramContext, lazilyStartUserContext, setLocale, setProgramId, setUserIdentity, userIdentityFromJwt, validateLocale };
package/dist/index.js CHANGED
@@ -63,7 +63,8 @@ __export(src_exports, {
63
63
  setLocale: () => setLocale,
64
64
  setProgramId: () => setProgramId,
65
65
  setUserIdentity: () => setUserIdentity,
66
- userIdentityFromJwt: () => userIdentityFromJwt
66
+ userIdentityFromJwt: () => userIdentityFromJwt,
67
+ validateLocale: () => validateLocale
67
68
  });
68
69
  module.exports = __toCommonJS(src_exports);
69
70
 
@@ -359,14 +360,20 @@ var import_dom_context2 = require("dom-context");
359
360
  // src/contexts/LocaleContext.ts
360
361
  var import_dom_context = require("dom-context");
361
362
  var debug3 = (...args) => debug(LOCALE_CONTEXT_NAME, ...args);
363
+ function validateLocale(locale) {
364
+ if (locale && /[a-z]{2}_[A-Z]{2}/.test(locale)) {
365
+ return locale;
366
+ }
367
+ }
362
368
  function lazilyStartLocaleContext() {
363
369
  var _a;
364
370
  let globalProvider = window.squatchLocale;
365
371
  if (!globalProvider) {
366
372
  debug3("Creating locale context provider");
373
+ const locale = ((_a = window.widgetIdent) == null ? void 0 : _a.locale) ?? validateLocale(navigator.language.replace("-", "_"));
367
374
  globalProvider = new import_dom_context.ContextProvider({
368
375
  element: document.documentElement,
369
- initialState: ((_a = window.widgetIdent) == null ? void 0 : _a.locale) || navigator.language.replace("-", "_"),
376
+ initialState: locale,
370
377
  contextName: LOCALE_CONTEXT_NAME
371
378
  }).start();
372
379
  window.squatchLocale = globalProvider;
@@ -621,5 +628,6 @@ function getProgramId() {
621
628
  setLocale,
622
629
  setProgramId,
623
630
  setUserIdentity,
624
- userIdentityFromJwt
631
+ userIdentityFromJwt,
632
+ validateLocale
625
633
  });
package/dist/index.mjs CHANGED
@@ -311,14 +311,20 @@ import { ContextListener } from "dom-context";
311
311
  // src/contexts/LocaleContext.ts
312
312
  import { ContextProvider } from "dom-context";
313
313
  var debug3 = (...args) => debug(LOCALE_CONTEXT_NAME, ...args);
314
+ function validateLocale(locale) {
315
+ if (locale && /[a-z]{2}_[A-Z]{2}/.test(locale)) {
316
+ return locale;
317
+ }
318
+ }
314
319
  function lazilyStartLocaleContext() {
315
320
  var _a;
316
321
  let globalProvider = window.squatchLocale;
317
322
  if (!globalProvider) {
318
323
  debug3("Creating locale context provider");
324
+ const locale = ((_a = window.widgetIdent) == null ? void 0 : _a.locale) ?? validateLocale(navigator.language.replace("-", "_"));
319
325
  globalProvider = new ContextProvider({
320
326
  element: document.documentElement,
321
- initialState: ((_a = window.widgetIdent) == null ? void 0 : _a.locale) || navigator.language.replace("-", "_"),
327
+ initialState: locale,
322
328
  contextName: LOCALE_CONTEXT_NAME
323
329
  }).start();
324
330
  window.squatchLocale = globalProvider;
@@ -572,5 +578,6 @@ export {
572
578
  setLocale,
573
579
  setProgramId,
574
580
  setUserIdentity,
575
- userIdentityFromJwt
581
+ userIdentityFromJwt,
582
+ validateLocale
576
583
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saasquatch/component-environment",
3
- "version": "1.0.0",
3
+ "version": "1.0.1-0",
4
4
  "description": "Environment and contexts for SaaSquatch components",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",