@saasquatch/component-environment 1.0.0-0 → 1.0.0-1
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/contexts/LocaleContext.js +15 -9
- package/dist/contexts/ProgramContext.js +15 -9
- package/dist/contexts/UserIdentityContext.js +32 -22
- package/dist/debug.js +5 -1
- package/dist/environment.js +18 -9
- package/dist/fetchLocale.js +10 -6
- package/dist/index.js +21 -5
- package/dist/listeners.js +22 -15
- package/dist/types.js +7 -4
- package/package.json +1 -2
- package/tsconfig.json +1 -1
|
@@ -1,41 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLocale = exports.setLocale = exports.lazilyStartLocaleContext = void 0;
|
|
4
|
+
const dom_context_1 = require("dom-context");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const debug_1 = require("../debug");
|
|
7
|
+
const debug = (...args) => (0, debug_1.debug)(types_1.LOCALE_CONTEXT_NAME, ...args);
|
|
5
8
|
/**
|
|
6
9
|
* Lazily start the locale context provider. If it already exists, the existing provider is
|
|
7
10
|
* returned. This function is safe to call multiple times.
|
|
8
11
|
*
|
|
9
12
|
* @returns The global locale context provider
|
|
10
13
|
*/
|
|
11
|
-
|
|
14
|
+
function lazilyStartLocaleContext() {
|
|
12
15
|
let globalProvider = window.squatchLocale;
|
|
13
16
|
if (!globalProvider) {
|
|
14
17
|
debug("Creating locale context provider");
|
|
15
|
-
globalProvider = new ContextProvider({
|
|
18
|
+
globalProvider = new dom_context_1.ContextProvider({
|
|
16
19
|
element: document.documentElement,
|
|
17
20
|
initialState: window.widgetIdent?.locale || navigator.language.replace("-", "_"),
|
|
18
|
-
contextName: LOCALE_CONTEXT_NAME,
|
|
21
|
+
contextName: types_1.LOCALE_CONTEXT_NAME,
|
|
19
22
|
}).start();
|
|
20
23
|
window.squatchLocale = globalProvider;
|
|
21
24
|
}
|
|
22
25
|
return globalProvider;
|
|
23
26
|
}
|
|
27
|
+
exports.lazilyStartLocaleContext = lazilyStartLocaleContext;
|
|
24
28
|
/**
|
|
25
29
|
* Overide the globally defined Locale context
|
|
26
30
|
*
|
|
27
31
|
* @param locale the new locale used by the user
|
|
28
32
|
*/
|
|
29
|
-
|
|
33
|
+
function setLocale(locale) {
|
|
30
34
|
const globalProvider = lazilyStartLocaleContext();
|
|
31
35
|
if (globalProvider.context !== locale) {
|
|
32
36
|
debug(`Setting locale context value [${locale}]`);
|
|
33
37
|
globalProvider.context = locale;
|
|
34
38
|
}
|
|
35
39
|
}
|
|
40
|
+
exports.setLocale = setLocale;
|
|
36
41
|
/**
|
|
37
42
|
* Get the current value of the locale context
|
|
38
43
|
*/
|
|
39
|
-
|
|
44
|
+
function getLocale() {
|
|
40
45
|
return window.squatchLocale?.context;
|
|
41
46
|
}
|
|
47
|
+
exports.getLocale = getLocale;
|
|
@@ -1,42 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProgramId = exports.setProgramId = exports.lazilyStartProgramContext = void 0;
|
|
4
|
+
const dom_context_1 = require("dom-context");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const debug_1 = require("../debug");
|
|
7
|
+
const debug = (...args) => (0, debug_1.debug)(types_1.PROGRAM_CONTEXT_NAME, ...args);
|
|
5
8
|
/**
|
|
6
9
|
* Lazily start the program context provider. If it already exists, the existing provider is
|
|
7
10
|
* returned. This function is safe to call multiple times.
|
|
8
11
|
*
|
|
9
12
|
* @returns The global program context provider
|
|
10
13
|
*/
|
|
11
|
-
|
|
14
|
+
function lazilyStartProgramContext() {
|
|
12
15
|
let globalProvider = window.squatchProgramId;
|
|
13
16
|
if (!globalProvider) {
|
|
14
17
|
debug("Creating program context provider");
|
|
15
18
|
// Lazily creates a global provider
|
|
16
|
-
globalProvider = new ContextProvider({
|
|
19
|
+
globalProvider = new dom_context_1.ContextProvider({
|
|
17
20
|
element: document.documentElement,
|
|
18
21
|
initialState: window.widgetIdent?.programId || undefined,
|
|
19
|
-
contextName: PROGRAM_CONTEXT_NAME,
|
|
22
|
+
contextName: types_1.PROGRAM_CONTEXT_NAME,
|
|
20
23
|
}).start();
|
|
21
24
|
window.squatchProgramId = globalProvider;
|
|
22
25
|
}
|
|
23
26
|
return globalProvider;
|
|
24
27
|
}
|
|
28
|
+
exports.lazilyStartProgramContext = lazilyStartProgramContext;
|
|
25
29
|
/**
|
|
26
30
|
* Overide the globally defined Program ID context
|
|
27
31
|
*
|
|
28
32
|
* @param programId the new programID used by the user, or undefined if logged out
|
|
29
33
|
*/
|
|
30
|
-
|
|
34
|
+
function setProgramId(programId) {
|
|
31
35
|
const globalProvider = lazilyStartProgramContext();
|
|
32
36
|
if (globalProvider.context !== programId) {
|
|
33
37
|
debug(`Setting program context value [${programId}]`);
|
|
34
38
|
globalProvider.context = programId;
|
|
35
39
|
}
|
|
36
40
|
}
|
|
41
|
+
exports.setProgramId = setProgramId;
|
|
37
42
|
/**
|
|
38
43
|
* Get the current value of the program context
|
|
39
44
|
*/
|
|
40
|
-
|
|
45
|
+
function getProgramId() {
|
|
41
46
|
return window.squatchLocale?.context;
|
|
42
47
|
}
|
|
48
|
+
exports.getProgramId = getProgramId;
|
|
@@ -1,32 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
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.getUserIdentity = exports.setUserIdentity = exports.userIdentityFromJwt = exports.lazilyStartUserContext = void 0;
|
|
7
|
+
const jwt_decode_1 = __importDefault(require("jwt-decode"));
|
|
8
|
+
const dom_context_1 = require("dom-context");
|
|
9
|
+
const equality_1 = require("@wry/equality");
|
|
10
|
+
const environment_1 = require("../environment");
|
|
11
|
+
const types_1 = require("../types");
|
|
12
|
+
const listeners_1 = require("../listeners");
|
|
13
|
+
const debug_1 = require("../debug");
|
|
14
|
+
const debug = (...args) => (0, debug_1.debug)(types_1.USER_CONTEXT_NAME, ...args);
|
|
9
15
|
/**
|
|
10
16
|
* Lazily start the user context provider. If it already exists, the existing provider is
|
|
11
17
|
* returned. This function is safe to call multiple times.
|
|
12
18
|
*
|
|
13
19
|
* @returns The global user context provider
|
|
14
20
|
*/
|
|
15
|
-
|
|
21
|
+
function lazilyStartUserContext() {
|
|
16
22
|
let globalProvider = window.squatchUserIdentity;
|
|
17
23
|
if (!globalProvider) {
|
|
18
24
|
debug("Creating user context provider");
|
|
19
25
|
// Lazily creates a global provider
|
|
20
|
-
globalProvider = new ContextProvider({
|
|
26
|
+
globalProvider = new dom_context_1.ContextProvider({
|
|
21
27
|
element: document.documentElement,
|
|
22
28
|
initialState: _getInitialValue(),
|
|
23
|
-
contextName: USER_CONTEXT_NAME,
|
|
29
|
+
contextName: types_1.USER_CONTEXT_NAME,
|
|
24
30
|
}).start();
|
|
25
31
|
window.squatchUserIdentity = globalProvider;
|
|
26
|
-
startUserContextListenerForLocale();
|
|
32
|
+
(0, listeners_1.startUserContextListenerForLocale)();
|
|
27
33
|
}
|
|
28
34
|
return globalProvider;
|
|
29
35
|
}
|
|
36
|
+
exports.lazilyStartUserContext = lazilyStartUserContext;
|
|
30
37
|
function isDecodedSquatchJWT(decoded) {
|
|
31
38
|
return decoded.user && decoded.user.id && decoded.user.accountId;
|
|
32
39
|
}
|
|
@@ -39,11 +46,11 @@ function isDecodedWidgetAPIJWT(decoded) {
|
|
|
39
46
|
* @param jwt The JWT to extract a user identity from
|
|
40
47
|
* @returns The user identity or undefined if the JWT is not valid
|
|
41
48
|
*/
|
|
42
|
-
|
|
49
|
+
function userIdentityFromJwt(jwt) {
|
|
43
50
|
if (!jwt)
|
|
44
51
|
return undefined;
|
|
45
52
|
try {
|
|
46
|
-
const decoded =
|
|
53
|
+
const decoded = (0, jwt_decode_1.default)(jwt);
|
|
47
54
|
const exp = decoded.exp;
|
|
48
55
|
let userId = undefined;
|
|
49
56
|
let accountId = undefined;
|
|
@@ -78,8 +85,9 @@ export function userIdentityFromJwt(jwt) {
|
|
|
78
85
|
return undefined;
|
|
79
86
|
}
|
|
80
87
|
}
|
|
88
|
+
exports.userIdentityFromJwt = userIdentityFromJwt;
|
|
81
89
|
function _getInitialValue() {
|
|
82
|
-
const sdk = getEnvironmentSDK();
|
|
90
|
+
const sdk = (0, environment_1.getEnvironmentSDK)();
|
|
83
91
|
switch (sdk.type) {
|
|
84
92
|
case "SquatchAndroid":
|
|
85
93
|
case "SquatchJS2":
|
|
@@ -95,7 +103,7 @@ function _getInitialValue() {
|
|
|
95
103
|
return userIdentityFromJwt(searchParams.get("jwt"));
|
|
96
104
|
}
|
|
97
105
|
// Look for user identity in local storage
|
|
98
|
-
const stored = localStorage.getItem(USER_CONTEXT_NAME);
|
|
106
|
+
const stored = localStorage.getItem(types_1.USER_CONTEXT_NAME);
|
|
99
107
|
if (!stored)
|
|
100
108
|
return undefined;
|
|
101
109
|
try {
|
|
@@ -124,23 +132,25 @@ function _getInitialValue() {
|
|
|
124
132
|
*
|
|
125
133
|
* @param identity the new identity of the user, or undefined if logged out
|
|
126
134
|
*/
|
|
127
|
-
|
|
135
|
+
function setUserIdentity(identity) {
|
|
128
136
|
const globalProvider = lazilyStartUserContext();
|
|
129
|
-
if (!equal(globalProvider.context, identity)) {
|
|
137
|
+
if (!(0, equality_1.equal)(globalProvider.context, identity)) {
|
|
130
138
|
debug(`Setting user context value [${JSON.stringify(identity)}]`);
|
|
131
139
|
globalProvider.context = identity;
|
|
132
140
|
}
|
|
133
141
|
// Portals store identity in local storage
|
|
134
|
-
if (identity && getEnvironmentSDK().type === "SquatchPortal") {
|
|
135
|
-
localStorage.setItem(USER_CONTEXT_NAME, JSON.stringify(identity));
|
|
142
|
+
if (identity && (0, environment_1.getEnvironmentSDK)().type === "SquatchPortal") {
|
|
143
|
+
localStorage.setItem(types_1.USER_CONTEXT_NAME, JSON.stringify(identity));
|
|
136
144
|
}
|
|
137
145
|
else if (!identity) {
|
|
138
|
-
localStorage.removeItem(USER_CONTEXT_NAME);
|
|
146
|
+
localStorage.removeItem(types_1.USER_CONTEXT_NAME);
|
|
139
147
|
}
|
|
140
148
|
}
|
|
149
|
+
exports.setUserIdentity = setUserIdentity;
|
|
141
150
|
/**
|
|
142
151
|
* Get the current value of the user context
|
|
143
152
|
*/
|
|
144
|
-
|
|
153
|
+
function getUserIdentity() {
|
|
145
154
|
return window.squatchUserIdentity?.context;
|
|
146
155
|
}
|
|
156
|
+
exports.getUserIdentity = getUserIdentity;
|
package/dist/debug.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.debug = void 0;
|
|
1
4
|
const debugEnabled = localStorage.getItem("debug");
|
|
2
|
-
|
|
5
|
+
function debug(ns, ...args) {
|
|
3
6
|
if (debugEnabled) {
|
|
4
7
|
console.debug(`sq:environment:${ns}`, ...args);
|
|
5
8
|
}
|
|
6
9
|
}
|
|
10
|
+
exports.debug = debug;
|
package/dist/environment.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEngagementMedium = exports.getAppDomain = exports.getTenantAlias = exports.isDemo = exports.getEnvironmentSDK = exports.getEnvironment = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
2
5
|
/**
|
|
3
6
|
* Get the type of environment that this widget is being rendered in
|
|
4
7
|
*
|
|
5
8
|
* Should never return null.
|
|
6
9
|
*/
|
|
7
|
-
|
|
10
|
+
function getEnvironment() {
|
|
8
11
|
return getEnvironmentSDK().type;
|
|
9
12
|
}
|
|
13
|
+
exports.getEnvironment = getEnvironment;
|
|
10
14
|
/**
|
|
11
15
|
* Get the SDK for interacting with the host environment
|
|
12
16
|
*/
|
|
13
|
-
|
|
17
|
+
function getEnvironmentSDK() {
|
|
14
18
|
//@ts-ignore
|
|
15
19
|
if (window["SquatchAndroid"]) {
|
|
16
20
|
return {
|
|
@@ -51,13 +55,15 @@ export function getEnvironmentSDK() {
|
|
|
51
55
|
type: "None",
|
|
52
56
|
};
|
|
53
57
|
}
|
|
54
|
-
|
|
58
|
+
exports.getEnvironmentSDK = getEnvironmentSDK;
|
|
59
|
+
function isDemo() {
|
|
55
60
|
const sdk = getEnvironmentSDK();
|
|
56
61
|
return sdk.type === "None" || sdk.type === "SquatchAdmin";
|
|
57
62
|
}
|
|
63
|
+
exports.isDemo = isDemo;
|
|
58
64
|
// Fake tenant alias in demo mode
|
|
59
65
|
const FAKE_TENANT = "demo";
|
|
60
|
-
|
|
66
|
+
function getTenantAlias() {
|
|
61
67
|
const sdk = getEnvironmentSDK();
|
|
62
68
|
switch (sdk.type) {
|
|
63
69
|
case "SquatchAndroid":
|
|
@@ -70,8 +76,9 @@ export function getTenantAlias() {
|
|
|
70
76
|
return sdk.env.tenantAlias;
|
|
71
77
|
}
|
|
72
78
|
}
|
|
79
|
+
exports.getTenantAlias = getTenantAlias;
|
|
73
80
|
const DEFAULT_DOMAIN = "https://app.referralsaasquatch.com";
|
|
74
|
-
|
|
81
|
+
function getAppDomain() {
|
|
75
82
|
const sdk = getEnvironmentSDK();
|
|
76
83
|
switch (sdk.type) {
|
|
77
84
|
case "SquatchAndroid":
|
|
@@ -84,15 +91,17 @@ export function getAppDomain() {
|
|
|
84
91
|
return DEFAULT_DOMAIN;
|
|
85
92
|
}
|
|
86
93
|
}
|
|
87
|
-
|
|
94
|
+
exports.getAppDomain = getAppDomain;
|
|
95
|
+
function getEngagementMedium() {
|
|
88
96
|
const sdk = getEnvironmentSDK();
|
|
89
97
|
switch (sdk.type) {
|
|
90
98
|
case "SquatchJS2":
|
|
91
|
-
return sdk.widgetIdent.engagementMedium || DEFAULT_MEDIUM;
|
|
99
|
+
return sdk.widgetIdent.engagementMedium || types_1.DEFAULT_MEDIUM;
|
|
92
100
|
case "SquatchAndroid":
|
|
93
101
|
case "SquatchPortal":
|
|
94
102
|
case "SquatchAdmin":
|
|
95
103
|
case "None":
|
|
96
|
-
return DEFAULT_MEDIUM;
|
|
104
|
+
return types_1.DEFAULT_MEDIUM;
|
|
97
105
|
}
|
|
98
106
|
}
|
|
107
|
+
exports.getEngagementMedium = getEngagementMedium;
|
package/dist/fetchLocale.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchLocale = void 0;
|
|
4
|
+
const environment_1 = require("./environment");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
const debug_1 = require("./debug");
|
|
7
|
+
const debug = (...args) => (0, debug_1.debug)(types_1.LOCALE_CONTEXT_NAME, ...args);
|
|
5
8
|
const GET_LOCALE = `
|
|
6
9
|
query {
|
|
7
10
|
viewer {
|
|
@@ -11,10 +14,10 @@ const GET_LOCALE = `
|
|
|
11
14
|
}
|
|
12
15
|
}
|
|
13
16
|
`;
|
|
14
|
-
|
|
17
|
+
async function fetchLocale() {
|
|
15
18
|
debug("Fetching locale from GraphQL for current user");
|
|
16
19
|
try {
|
|
17
|
-
const result = await fetch(`${getAppDomain()}/api/v1/${getTenantAlias()}/graphql`, {
|
|
20
|
+
const result = await fetch(`${(0, environment_1.getAppDomain)()}/api/v1/${(0, environment_1.getTenantAlias)()}/graphql`, {
|
|
18
21
|
method: "POST",
|
|
19
22
|
headers: { "Content-Type": "application/json" },
|
|
20
23
|
body: JSON.stringify({
|
|
@@ -35,3 +38,4 @@ export async function fetchLocale() {
|
|
|
35
38
|
return undefined;
|
|
36
39
|
}
|
|
37
40
|
}
|
|
41
|
+
exports.fetchLocale = fetchLocale;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./environment"), exports);
|
|
19
|
+
__exportStar(require("./contexts/UserIdentityContext"), exports);
|
|
20
|
+
__exportStar(require("./contexts/LocaleContext"), exports);
|
|
21
|
+
__exportStar(require("./contexts/ProgramContext"), exports);
|
package/dist/listeners.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
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.startUserContextListenerForLocale = void 0;
|
|
7
|
+
const equality_1 = __importDefault(require("@wry/equality"));
|
|
8
|
+
const dom_context_1 = require("dom-context");
|
|
9
|
+
const types_1 = require("./types");
|
|
10
|
+
const LocaleContext_1 = require("./contexts/LocaleContext");
|
|
11
|
+
const UserIdentityContext_1 = require("./contexts/UserIdentityContext");
|
|
12
|
+
const fetchLocale_1 = require("./fetchLocale");
|
|
13
|
+
const debug_1 = require("./debug");
|
|
14
|
+
const debug = (...args) => (0, debug_1.debug)(types_1.LOCALE_CONTEXT_NAME, ...args);
|
|
9
15
|
const userContextListenerDiv = (() => {
|
|
10
16
|
const id = "__environment_context_listener";
|
|
11
17
|
let div = document.getElementById(id);
|
|
@@ -17,16 +23,16 @@ const userContextListenerDiv = (() => {
|
|
|
17
23
|
return div;
|
|
18
24
|
})();
|
|
19
25
|
// Listens to user changes and refetches the locale from GraphQL
|
|
20
|
-
const userContextListenerForLocale = new ContextListener({
|
|
21
|
-
contextName: USER_CONTEXT_NAME,
|
|
26
|
+
const userContextListenerForLocale = new dom_context_1.ContextListener({
|
|
27
|
+
contextName: types_1.USER_CONTEXT_NAME,
|
|
22
28
|
element: userContextListenerDiv,
|
|
23
29
|
onChange: async (next) => {
|
|
24
30
|
if (next) {
|
|
25
|
-
const userProvider = lazilyStartUserContext();
|
|
26
|
-
if (!
|
|
31
|
+
const userProvider = (0, UserIdentityContext_1.lazilyStartUserContext)();
|
|
32
|
+
if (!(0, equality_1.default)(userProvider.context, next)) {
|
|
27
33
|
debug("User context changed, refetching locale");
|
|
28
|
-
const locale = await fetchLocale();
|
|
29
|
-
const localeProvider = lazilyStartLocaleContext();
|
|
34
|
+
const locale = await (0, fetchLocale_1.fetchLocale)();
|
|
35
|
+
const localeProvider = (0, LocaleContext_1.lazilyStartLocaleContext)();
|
|
30
36
|
if (localeProvider.context !== locale) {
|
|
31
37
|
debug(`New value fetched from GraphQL [${locale}]`);
|
|
32
38
|
localeProvider.context =
|
|
@@ -38,7 +44,8 @@ const userContextListenerForLocale = new ContextListener({
|
|
|
38
44
|
}
|
|
39
45
|
},
|
|
40
46
|
});
|
|
41
|
-
|
|
47
|
+
function startUserContextListenerForLocale() {
|
|
42
48
|
debug("Starting user context listener for locale updates");
|
|
43
49
|
userContextListenerForLocale.start();
|
|
44
50
|
}
|
|
51
|
+
exports.startUserContextListenerForLocale = startUserContextListenerForLocale;
|
package/dist/types.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_MEDIUM = exports.PROGRAM_CONTEXT_NAME = exports.LOCALE_CONTEXT_NAME = exports.USER_CONTEXT_NAME = void 0;
|
|
4
|
+
exports.USER_CONTEXT_NAME = "sq:user-identity";
|
|
5
|
+
exports.LOCALE_CONTEXT_NAME = "sq:locale";
|
|
6
|
+
exports.PROGRAM_CONTEXT_NAME = "sq:program-id";
|
|
7
|
+
exports.DEFAULT_MEDIUM = "EMBED";
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saasquatch/component-environment",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-1",
|
|
4
4
|
"description": "Environment and contexts for SaaSquatch components",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"type": "module",
|
|
7
6
|
"scripts": {
|
|
8
7
|
"build": "tsc",
|
|
9
8
|
"test": "echo \"Error: no test specified\" && exit 1"
|