@saasquatch/component-environment 1.0.1 → 1.0.2-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/index.d.ts +3 -0
- package/dist/index.js +29 -3
- package/dist/index.mjs +29 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -79,7 +79,7 @@ function getEnvironment() {
|
|
|
79
79
|
return getEnvironmentSDK().type;
|
|
80
80
|
}
|
|
81
81
|
function getEnvironmentSDK() {
|
|
82
|
-
var _a, _b;
|
|
82
|
+
var _a, _b, _c;
|
|
83
83
|
if (window["SquatchAndroid"]) {
|
|
84
84
|
return {
|
|
85
85
|
type: "SquatchAndroid",
|
|
@@ -99,10 +99,10 @@ function getEnvironmentSDK() {
|
|
|
99
99
|
adminSDK: window["SquatchAdmin"]
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
|
-
if (window["
|
|
102
|
+
if (((_a = window.frameElement) == null ? void 0 : _a["squatchJsApi"]) && ((_b = window["widgetIdent"]) == null ? void 0 : _b.env) !== "demo") {
|
|
103
103
|
return {
|
|
104
104
|
type: "SquatchJS2",
|
|
105
|
-
api: (
|
|
105
|
+
api: (_c = window.frameElement) == null ? void 0 : _c["squatchJsApi"],
|
|
106
106
|
widgetIdent: window["widgetIdent"]
|
|
107
107
|
};
|
|
108
108
|
}
|
|
@@ -119,6 +119,7 @@ function getTenantAlias() {
|
|
|
119
119
|
const sdk = getEnvironmentSDK();
|
|
120
120
|
switch (sdk.type) {
|
|
121
121
|
case "SquatchAndroid":
|
|
122
|
+
case "SquatchIOS":
|
|
122
123
|
case "SquatchJS2":
|
|
123
124
|
return sdk.widgetIdent.tenantAlias;
|
|
124
125
|
case "SquatchAdmin":
|
|
@@ -134,6 +135,7 @@ function getAppDomain() {
|
|
|
134
135
|
const sdk = getEnvironmentSDK();
|
|
135
136
|
switch (sdk.type) {
|
|
136
137
|
case "SquatchAndroid":
|
|
138
|
+
case "SquatchIOS":
|
|
137
139
|
case "SquatchJS2":
|
|
138
140
|
return sdk.widgetIdent.appDomain;
|
|
139
141
|
case "SquatchPortal":
|
|
@@ -149,6 +151,7 @@ function getEngagementMedium() {
|
|
|
149
151
|
case "SquatchJS2":
|
|
150
152
|
return sdk.widgetIdent.engagementMedium || DEFAULT_MEDIUM;
|
|
151
153
|
case "SquatchAndroid":
|
|
154
|
+
case "SquatchIOS":
|
|
152
155
|
case "SquatchPortal":
|
|
153
156
|
case "SquatchAdmin":
|
|
154
157
|
case "None":
|
|
@@ -528,8 +531,23 @@ function userIdentityFromJwt(jwt) {
|
|
|
528
531
|
function _getInitialValue() {
|
|
529
532
|
const sdk = getEnvironmentSDK();
|
|
530
533
|
switch (sdk.type) {
|
|
534
|
+
case "SquatchIOS":
|
|
531
535
|
case "SquatchAndroid":
|
|
532
536
|
case "SquatchJS2":
|
|
537
|
+
if (!sdk.widgetIdent)
|
|
538
|
+
return void 0;
|
|
539
|
+
const { programId, tenantAlias, userId, accountId, token } = sdk.widgetIdent;
|
|
540
|
+
const storedSquatchUser = localStorage.getItem(`${USER_CONTEXT_NAME}:${tenantAlias}:${programId || "global"}`);
|
|
541
|
+
if (storedSquatchUser) {
|
|
542
|
+
try {
|
|
543
|
+
const potentialUserIdent = JSON.parse(storedSquatchUser);
|
|
544
|
+
return userIdentityFromJwt(potentialUserIdent.jwt);
|
|
545
|
+
} catch (e) {
|
|
546
|
+
return void 0;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
if (!userId || !accountId || !token)
|
|
550
|
+
return void 0;
|
|
533
551
|
return {
|
|
534
552
|
id: sdk.widgetIdent.userId,
|
|
535
553
|
accountId: sdk.widgetIdent.accountId,
|
|
@@ -560,10 +578,18 @@ function _getInitialValue() {
|
|
|
560
578
|
}
|
|
561
579
|
function setUserIdentity(identity) {
|
|
562
580
|
const globalProvider = lazilyStartUserContext();
|
|
581
|
+
const sdk = getEnvironmentSDK();
|
|
582
|
+
const widgetIdent = sdk.type === "SquatchJS2" ? sdk.widgetIdent : void 0;
|
|
583
|
+
console.log({ sdk, widgetIdent });
|
|
563
584
|
if (!(0, import_equality.equal)(globalProvider.context, identity)) {
|
|
564
585
|
debug6(`Setting user context value [${JSON.stringify(identity)}]`);
|
|
565
586
|
globalProvider.context = identity;
|
|
566
587
|
}
|
|
588
|
+
if (identity && widgetIdent) {
|
|
589
|
+
localStorage.setItem(`${USER_CONTEXT_NAME}:${widgetIdent.tenantAlias}:${widgetIdent.programId || "global"}`, JSON.stringify(identity));
|
|
590
|
+
} else if (!identity && widgetIdent) {
|
|
591
|
+
localStorage.removeItem(`${USER_CONTEXT_NAME}:${widgetIdent.tenantAlias}:${widgetIdent.programId || "global"}`);
|
|
592
|
+
}
|
|
567
593
|
if (identity && getEnvironmentSDK().type === "SquatchPortal") {
|
|
568
594
|
localStorage.setItem(USER_CONTEXT_NAME, JSON.stringify(identity));
|
|
569
595
|
} else if (!identity) {
|
package/dist/index.mjs
CHANGED
|
@@ -30,7 +30,7 @@ function getEnvironment() {
|
|
|
30
30
|
return getEnvironmentSDK().type;
|
|
31
31
|
}
|
|
32
32
|
function getEnvironmentSDK() {
|
|
33
|
-
var _a, _b;
|
|
33
|
+
var _a, _b, _c;
|
|
34
34
|
if (window["SquatchAndroid"]) {
|
|
35
35
|
return {
|
|
36
36
|
type: "SquatchAndroid",
|
|
@@ -50,10 +50,10 @@ function getEnvironmentSDK() {
|
|
|
50
50
|
adminSDK: window["SquatchAdmin"]
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
if (window["
|
|
53
|
+
if (((_a = window.frameElement) == null ? void 0 : _a["squatchJsApi"]) && ((_b = window["widgetIdent"]) == null ? void 0 : _b.env) !== "demo") {
|
|
54
54
|
return {
|
|
55
55
|
type: "SquatchJS2",
|
|
56
|
-
api: (
|
|
56
|
+
api: (_c = window.frameElement) == null ? void 0 : _c["squatchJsApi"],
|
|
57
57
|
widgetIdent: window["widgetIdent"]
|
|
58
58
|
};
|
|
59
59
|
}
|
|
@@ -70,6 +70,7 @@ function getTenantAlias() {
|
|
|
70
70
|
const sdk = getEnvironmentSDK();
|
|
71
71
|
switch (sdk.type) {
|
|
72
72
|
case "SquatchAndroid":
|
|
73
|
+
case "SquatchIOS":
|
|
73
74
|
case "SquatchJS2":
|
|
74
75
|
return sdk.widgetIdent.tenantAlias;
|
|
75
76
|
case "SquatchAdmin":
|
|
@@ -85,6 +86,7 @@ function getAppDomain() {
|
|
|
85
86
|
const sdk = getEnvironmentSDK();
|
|
86
87
|
switch (sdk.type) {
|
|
87
88
|
case "SquatchAndroid":
|
|
89
|
+
case "SquatchIOS":
|
|
88
90
|
case "SquatchJS2":
|
|
89
91
|
return sdk.widgetIdent.appDomain;
|
|
90
92
|
case "SquatchPortal":
|
|
@@ -100,6 +102,7 @@ function getEngagementMedium() {
|
|
|
100
102
|
case "SquatchJS2":
|
|
101
103
|
return sdk.widgetIdent.engagementMedium || DEFAULT_MEDIUM;
|
|
102
104
|
case "SquatchAndroid":
|
|
105
|
+
case "SquatchIOS":
|
|
103
106
|
case "SquatchPortal":
|
|
104
107
|
case "SquatchAdmin":
|
|
105
108
|
case "None":
|
|
@@ -479,8 +482,23 @@ function userIdentityFromJwt(jwt) {
|
|
|
479
482
|
function _getInitialValue() {
|
|
480
483
|
const sdk = getEnvironmentSDK();
|
|
481
484
|
switch (sdk.type) {
|
|
485
|
+
case "SquatchIOS":
|
|
482
486
|
case "SquatchAndroid":
|
|
483
487
|
case "SquatchJS2":
|
|
488
|
+
if (!sdk.widgetIdent)
|
|
489
|
+
return void 0;
|
|
490
|
+
const { programId, tenantAlias, userId, accountId, token } = sdk.widgetIdent;
|
|
491
|
+
const storedSquatchUser = localStorage.getItem(`${USER_CONTEXT_NAME}:${tenantAlias}:${programId || "global"}`);
|
|
492
|
+
if (storedSquatchUser) {
|
|
493
|
+
try {
|
|
494
|
+
const potentialUserIdent = JSON.parse(storedSquatchUser);
|
|
495
|
+
return userIdentityFromJwt(potentialUserIdent.jwt);
|
|
496
|
+
} catch (e) {
|
|
497
|
+
return void 0;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
if (!userId || !accountId || !token)
|
|
501
|
+
return void 0;
|
|
484
502
|
return {
|
|
485
503
|
id: sdk.widgetIdent.userId,
|
|
486
504
|
accountId: sdk.widgetIdent.accountId,
|
|
@@ -511,10 +529,18 @@ function _getInitialValue() {
|
|
|
511
529
|
}
|
|
512
530
|
function setUserIdentity(identity) {
|
|
513
531
|
const globalProvider = lazilyStartUserContext();
|
|
532
|
+
const sdk = getEnvironmentSDK();
|
|
533
|
+
const widgetIdent = sdk.type === "SquatchJS2" ? sdk.widgetIdent : void 0;
|
|
534
|
+
console.log({ sdk, widgetIdent });
|
|
514
535
|
if (!equal(globalProvider.context, identity)) {
|
|
515
536
|
debug6(`Setting user context value [${JSON.stringify(identity)}]`);
|
|
516
537
|
globalProvider.context = identity;
|
|
517
538
|
}
|
|
539
|
+
if (identity && widgetIdent) {
|
|
540
|
+
localStorage.setItem(`${USER_CONTEXT_NAME}:${widgetIdent.tenantAlias}:${widgetIdent.programId || "global"}`, JSON.stringify(identity));
|
|
541
|
+
} else if (!identity && widgetIdent) {
|
|
542
|
+
localStorage.removeItem(`${USER_CONTEXT_NAME}:${widgetIdent.tenantAlias}:${widgetIdent.programId || "global"}`);
|
|
543
|
+
}
|
|
518
544
|
if (identity && getEnvironmentSDK().type === "SquatchPortal") {
|
|
519
545
|
localStorage.setItem(USER_CONTEXT_NAME, JSON.stringify(identity));
|
|
520
546
|
} else if (!identity) {
|