@saasquatch/component-environment 1.0.2-4 → 1.0.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 ReferralSaaSquatch.com, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,46 +1,46 @@
1
- Provides the environment for running SaaSquatch web components.
2
-
3
- SaaSquatch web components can run in a number of different environments, including:
4
-
5
- - in a widget via `squatch-js`
6
- - in a microsite (portal)
7
- - in a mobile SDK (i.e. `squatch-android`)
8
- - in the admin portal
9
-
10
- In each environment, a different set of context information about the tenant, user and program are provided, and the goal of this package is to normalize the differences in environments to provide a common API.
11
-
12
- The environment is provided in a set of contexts through `dom-context`, which provides vanilla global context providers. They can be accessed through a raw `ContextListener` or via `useDomContext` in `dom-context-hooks`.
13
-
14
- ## General environment
15
-
16
- ### `getEnvironment()`
17
-
18
- Get the environment type. The current possible values are: `SquatchJS2`, `SquatchAndroid`, `SquatchPortal`, `SquatchAdmin` or `None`.
19
-
20
- ### `isDemo()`
21
-
22
- Returns whether components should run in demo/preview mode.
23
-
24
- ### `getTenantAlias()`
25
-
26
- Get the current tenant alias.
27
-
28
- ### `getAppDomain()`
29
-
30
- Get the SaaSquatch app domain.
31
-
32
- ### `getEngagementMedium()`
33
-
34
- Get the current engagement medium. This is particularly important in widgets rendered by `squatch-js` for informing metadata about share link clicks.
35
-
36
- ## User identity
37
-
38
- The user identity context name is exported in a constant `USER_CONTEXT_NAME`. The current value can be retrieved with `getUserIdentity()` and set with `setUserIdentity(identity)`.
39
-
40
- ## Locale
41
-
42
- The locale context name is exported in a constnat `LOCALE_CONTEXT_NAME`. The current value can be retrieved with `getLocale()` and set with `setLocal(locale)`.
43
-
44
- ## Program ID
45
-
46
- The program ID context name is exported in a constant `PROGRAM_CONTEXT_NAME`. The current value can be retrieved with `getProgramId()` and set with `setProgramId(programId)`.
1
+ Provides the environment for running SaaSquatch web components.
2
+
3
+ SaaSquatch web components can run in a number of different environments, including:
4
+
5
+ - in a widget via `squatch-js`
6
+ - in a microsite (portal)
7
+ - in a mobile SDK (i.e. `squatch-android`)
8
+ - in the admin portal
9
+
10
+ In each environment, a different set of context information about the tenant, user and program are provided, and the goal of this package is to normalize the differences in environments to provide a common API.
11
+
12
+ The environment is provided in a set of contexts through `dom-context`, which provides vanilla global context providers. They can be accessed through a raw `ContextListener` or via `useDomContext` in `dom-context-hooks`.
13
+
14
+ ## General environment
15
+
16
+ ### `getEnvironment()`
17
+
18
+ Get the environment type. The current possible values are: `SquatchJS2`, `SquatchAndroid`, `SquatchPortal`, `SquatchAdmin` or `None`.
19
+
20
+ ### `isDemo()`
21
+
22
+ Returns whether components should run in demo/preview mode.
23
+
24
+ ### `getTenantAlias()`
25
+
26
+ Get the current tenant alias.
27
+
28
+ ### `getAppDomain()`
29
+
30
+ Get the SaaSquatch app domain.
31
+
32
+ ### `getEngagementMedium()`
33
+
34
+ Get the current engagement medium. This is particularly important in widgets rendered by `squatch-js` for informing metadata about share link clicks.
35
+
36
+ ## User identity
37
+
38
+ The user identity context name is exported in a constant `USER_CONTEXT_NAME`. The current value can be retrieved with `getUserIdentity()` and set with `setUserIdentity(identity)`.
39
+
40
+ ## Locale
41
+
42
+ The locale context name is exported in a constnat `LOCALE_CONTEXT_NAME`. The current value can be retrieved with `getLocale()` and set with `setLocal(locale)`.
43
+
44
+ ## Program ID
45
+
46
+ The program ID context name is exported in a constant `PROGRAM_CONTEXT_NAME`. The current value can be retrieved with `getProgramId()` and set with `setProgramId(programId)`.
package/dist/index.d.ts CHANGED
@@ -137,9 +137,6 @@ declare type EnvironmentSDK = {
137
137
  type: "SquatchAndroid";
138
138
  android: SquatchAndroid;
139
139
  widgetIdent: WidgetIdent;
140
- } | {
141
- type: "SquatchIOS";
142
- widgetIdent: WidgetIdent;
143
140
  } | {
144
141
  type: "SquatchPortal";
145
142
  env: PortalEnv;
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, _c;
82
+ var _a, _b;
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 (((_a = window.frameElement) == null ? void 0 : _a["squatchJsApi"]) && ((_b = window["widgetIdent"]) == null ? void 0 : _b.env) !== "demo") {
102
+ if (window["widgetIdent"] && ((_a = window["widgetIdent"]) == null ? void 0 : _a.env) !== "demo") {
103
103
  return {
104
104
  type: "SquatchJS2",
105
- api: (_c = window.frameElement) == null ? void 0 : _c["squatchJsApi"],
105
+ api: (_b = window.frameElement) == null ? void 0 : _b["squatchJsApi"],
106
106
  widgetIdent: window["widgetIdent"]
107
107
  };
108
108
  }
@@ -116,13 +116,11 @@ function isDemo() {
116
116
  }
117
117
  var FAKE_TENANT = "demo";
118
118
  function getTenantAlias() {
119
- var _a;
120
119
  const sdk = getEnvironmentSDK();
121
120
  switch (sdk.type) {
122
121
  case "SquatchAndroid":
123
- case "SquatchIOS":
124
122
  case "SquatchJS2":
125
- return (_a = sdk.widgetIdent) == null ? void 0 : _a.tenantAlias;
123
+ return sdk.widgetIdent.tenantAlias;
126
124
  case "SquatchAdmin":
127
125
  case "None":
128
126
  return FAKE_TENANT;
@@ -132,28 +130,25 @@ function getTenantAlias() {
132
130
  }
133
131
  var DEFAULT_DOMAIN = "https://app.referralsaasquatch.com";
134
132
  function getAppDomain() {
135
- var _a, _b;
133
+ var _a;
136
134
  const sdk = getEnvironmentSDK();
137
135
  switch (sdk.type) {
138
136
  case "SquatchAndroid":
139
- case "SquatchIOS":
140
137
  case "SquatchJS2":
141
- return ((_a = sdk.widgetIdent) == null ? void 0 : _a.appDomain) || DEFAULT_DOMAIN;
138
+ return sdk.widgetIdent.appDomain;
142
139
  case "SquatchPortal":
143
- return ((_b = sdk.env) == null ? void 0 : _b.appDomain) || DEFAULT_DOMAIN;
140
+ return ((_a = sdk.env) == null ? void 0 : _a.appDomain) || DEFAULT_DOMAIN;
144
141
  case "SquatchAdmin":
145
142
  case "None":
146
143
  return DEFAULT_DOMAIN;
147
144
  }
148
145
  }
149
146
  function getEngagementMedium() {
150
- var _a;
151
147
  const sdk = getEnvironmentSDK();
152
148
  switch (sdk.type) {
153
149
  case "SquatchJS2":
154
- return ((_a = sdk.widgetIdent) == null ? void 0 : _a.engagementMedium) || DEFAULT_MEDIUM;
150
+ return sdk.widgetIdent.engagementMedium || DEFAULT_MEDIUM;
155
151
  case "SquatchAndroid":
156
- case "SquatchIOS":
157
152
  case "SquatchPortal":
158
153
  case "SquatchAdmin":
159
154
  case "None":
@@ -516,11 +511,9 @@ function userIdentityFromJwt(jwt) {
516
511
  userId = decoded.user.id;
517
512
  }
518
513
  if (!userId || !accountId) {
519
- debug6("No user information");
520
514
  return void 0;
521
515
  }
522
516
  if (exp && Date.now() >= exp * 1e3) {
523
- debug6("JWT has expired");
524
517
  return void 0;
525
518
  }
526
519
  return {
@@ -529,21 +522,14 @@ function userIdentityFromJwt(jwt) {
529
522
  jwt
530
523
  };
531
524
  } catch (e) {
532
- debug6("Invalid JWT");
533
525
  return void 0;
534
526
  }
535
527
  }
536
528
  function _getInitialValue() {
537
529
  const sdk = getEnvironmentSDK();
538
530
  switch (sdk.type) {
539
- case "SquatchIOS":
540
531
  case "SquatchAndroid":
541
532
  case "SquatchJS2":
542
- if (!sdk.widgetIdent)
543
- return void 0;
544
- const { userId, accountId, token } = sdk.widgetIdent;
545
- if (!userId || !accountId || !token)
546
- return void 0;
547
533
  return {
548
534
  id: sdk.widgetIdent.userId,
549
535
  accountId: sdk.widgetIdent.accountId,
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, _c;
33
+ var _a, _b;
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 (((_a = window.frameElement) == null ? void 0 : _a["squatchJsApi"]) && ((_b = window["widgetIdent"]) == null ? void 0 : _b.env) !== "demo") {
53
+ if (window["widgetIdent"] && ((_a = window["widgetIdent"]) == null ? void 0 : _a.env) !== "demo") {
54
54
  return {
55
55
  type: "SquatchJS2",
56
- api: (_c = window.frameElement) == null ? void 0 : _c["squatchJsApi"],
56
+ api: (_b = window.frameElement) == null ? void 0 : _b["squatchJsApi"],
57
57
  widgetIdent: window["widgetIdent"]
58
58
  };
59
59
  }
@@ -67,13 +67,11 @@ function isDemo() {
67
67
  }
68
68
  var FAKE_TENANT = "demo";
69
69
  function getTenantAlias() {
70
- var _a;
71
70
  const sdk = getEnvironmentSDK();
72
71
  switch (sdk.type) {
73
72
  case "SquatchAndroid":
74
- case "SquatchIOS":
75
73
  case "SquatchJS2":
76
- return (_a = sdk.widgetIdent) == null ? void 0 : _a.tenantAlias;
74
+ return sdk.widgetIdent.tenantAlias;
77
75
  case "SquatchAdmin":
78
76
  case "None":
79
77
  return FAKE_TENANT;
@@ -83,28 +81,25 @@ function getTenantAlias() {
83
81
  }
84
82
  var DEFAULT_DOMAIN = "https://app.referralsaasquatch.com";
85
83
  function getAppDomain() {
86
- var _a, _b;
84
+ var _a;
87
85
  const sdk = getEnvironmentSDK();
88
86
  switch (sdk.type) {
89
87
  case "SquatchAndroid":
90
- case "SquatchIOS":
91
88
  case "SquatchJS2":
92
- return ((_a = sdk.widgetIdent) == null ? void 0 : _a.appDomain) || DEFAULT_DOMAIN;
89
+ return sdk.widgetIdent.appDomain;
93
90
  case "SquatchPortal":
94
- return ((_b = sdk.env) == null ? void 0 : _b.appDomain) || DEFAULT_DOMAIN;
91
+ return ((_a = sdk.env) == null ? void 0 : _a.appDomain) || DEFAULT_DOMAIN;
95
92
  case "SquatchAdmin":
96
93
  case "None":
97
94
  return DEFAULT_DOMAIN;
98
95
  }
99
96
  }
100
97
  function getEngagementMedium() {
101
- var _a;
102
98
  const sdk = getEnvironmentSDK();
103
99
  switch (sdk.type) {
104
100
  case "SquatchJS2":
105
- return ((_a = sdk.widgetIdent) == null ? void 0 : _a.engagementMedium) || DEFAULT_MEDIUM;
101
+ return sdk.widgetIdent.engagementMedium || DEFAULT_MEDIUM;
106
102
  case "SquatchAndroid":
107
- case "SquatchIOS":
108
103
  case "SquatchPortal":
109
104
  case "SquatchAdmin":
110
105
  case "None":
@@ -467,11 +462,9 @@ function userIdentityFromJwt(jwt) {
467
462
  userId = decoded.user.id;
468
463
  }
469
464
  if (!userId || !accountId) {
470
- debug6("No user information");
471
465
  return void 0;
472
466
  }
473
467
  if (exp && Date.now() >= exp * 1e3) {
474
- debug6("JWT has expired");
475
468
  return void 0;
476
469
  }
477
470
  return {
@@ -480,21 +473,14 @@ function userIdentityFromJwt(jwt) {
480
473
  jwt
481
474
  };
482
475
  } catch (e) {
483
- debug6("Invalid JWT");
484
476
  return void 0;
485
477
  }
486
478
  }
487
479
  function _getInitialValue() {
488
480
  const sdk = getEnvironmentSDK();
489
481
  switch (sdk.type) {
490
- case "SquatchIOS":
491
482
  case "SquatchAndroid":
492
483
  case "SquatchJS2":
493
- if (!sdk.widgetIdent)
494
- return void 0;
495
- const { userId, accountId, token } = sdk.widgetIdent;
496
- if (!userId || !accountId || !token)
497
- return void 0;
498
484
  return {
499
485
  id: sdk.widgetIdent.userId,
500
486
  accountId: sdk.widgetIdent.accountId,
package/package.json CHANGED
@@ -1,38 +1,38 @@
1
- {
2
- "name": "@saasquatch/component-environment",
3
- "version": "1.0.2-4",
4
- "description": "Environment and contexts for SaaSquatch components",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "files": [
8
- "dist/"
9
- ],
10
- "scripts": {
11
- "build": "tsup src/index.ts --format esm,cjs --dts",
12
- "test": "jest"
13
- },
14
- "engines": {
15
- "node": ">=16.15"
16
- },
17
- "repository": {
18
- "type": "git",
19
- "url": "https://github.com/saasquatch/program-tools",
20
- "directory": "packages/component-environment"
21
- },
22
- "author": "Johan Venter <johan@saasquatch.com>",
23
- "license": "ISC",
24
- "devDependencies": {
25
- "@types/jest": "^28.1.4",
26
- "jest": "^28.1.2",
27
- "jest-environment-jsdom": "^28.1.2",
28
- "ts-jest": "^28.0.5",
29
- "ts-node": "^10.8.2",
30
- "tsup": "^6.1.2",
31
- "typescript": "^4.7.3"
32
- },
33
- "dependencies": {
34
- "@wry/equality": "^0.5.2",
35
- "dom-context": "^1.2.0",
36
- "jwt-decode": "^3.1.2"
37
- }
38
- }
1
+ {
2
+ "name": "@saasquatch/component-environment",
3
+ "version": "1.0.2",
4
+ "description": "Environment and contexts for SaaSquatch components",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "files": [
8
+ "dist/"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsup src/index.ts --format esm,cjs --dts",
12
+ "test": "jest"
13
+ },
14
+ "engines": {
15
+ "node": ">=16.15"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/saasquatch/program-tools",
20
+ "directory": "packages/component-environment"
21
+ },
22
+ "author": "ReferralSaaSquatch.com, Inc.",
23
+ "license": "MIT",
24
+ "devDependencies": {
25
+ "@types/jest": "^28.1.4",
26
+ "jest": "^28.1.2",
27
+ "jest-environment-jsdom": "^28.1.2",
28
+ "ts-jest": "^28.0.5",
29
+ "ts-node": "^10.8.2",
30
+ "tsup": "^6.1.2",
31
+ "typescript": "^4.7.3"
32
+ },
33
+ "dependencies": {
34
+ "@wry/equality": "^0.5.2",
35
+ "dom-context": "^1.2.0",
36
+ "jwt-decode": "^3.1.2"
37
+ }
38
+ }