genesys-spark 4.0.0-beta.37
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/README.md +34 -0
- package/dist/hosts.d.ts +8 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +94 -0
- package/package.json +23 -0
- package/rollup.config.js +21 -0
- package/src/hosts.ts +46 -0
- package/src/index.ts +65 -0
- package/tsconfig.json +9 -0
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# genesys-spark
|
|
2
|
+
|
|
3
|
+
This package is the default way to use Spark. It provides access to Spark's lazy-loading custom elements via a single shared CDN, as well as utilities for non-rendering UI tasks.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Use your package manager of choice to install the package in your project.
|
|
8
|
+
|
|
9
|
+
`npm install genesys-spark`
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
When initializing your app/page, call `registerSparkCompnents`, which will inject
|
|
14
|
+
the script and style tags into your page that define the main Spark custom elements:
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
import { registerSparkComponents } from 'genesys-spark';
|
|
18
|
+
|
|
19
|
+
// It's not _required_ to await component loading, but it can help prevent a flash
|
|
20
|
+
// of unstyled content
|
|
21
|
+
await registerSparkComponents();
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Loading Mechanism
|
|
25
|
+
|
|
26
|
+
By adding a script tag to the document, we ensure that the components are always
|
|
27
|
+
loaded from the same location. This keeps the bundle size of the consuming application
|
|
28
|
+
smaller, and ensures that multiple apps on the same domain will share the browser's
|
|
29
|
+
cache of the component definitions. Overall, this leads to a better end-user experience.
|
|
30
|
+
|
|
31
|
+
Additionally, Stencil builds the components so that their full implementations do
|
|
32
|
+
not need to be loaded up-front. Instead, components are fetched as they are used
|
|
33
|
+
in the page. Those lazy-loaded implementations also benefit from sharing the
|
|
34
|
+
browser cache in the same way as the initial script.
|
package/dist/hosts.d.ts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Default domain to load assets from
|
|
2
|
+
var DEFAULT_DOMAIN = 'mypurecloud.com';
|
|
3
|
+
// List of Genesys UI domains
|
|
4
|
+
var DOMAIN_LIST = [
|
|
5
|
+
'apne2.pure.cloud',
|
|
6
|
+
'aps1.pure.cloud',
|
|
7
|
+
'cac1.pure.cloud',
|
|
8
|
+
'euw2.pure.cloud',
|
|
9
|
+
'inindca.com',
|
|
10
|
+
'inintca.com',
|
|
11
|
+
'mypurecloud.com.au',
|
|
12
|
+
'mypurecloud.com',
|
|
13
|
+
'mypurecloud.de',
|
|
14
|
+
'mypurecloud.ie',
|
|
15
|
+
'mypurecloud.jp',
|
|
16
|
+
'sae1.pure.cloud',
|
|
17
|
+
'use2.maximus-pure.cloud',
|
|
18
|
+
// 'use2.us-gov-pure.cloud', Assets are not currently deployed to FedRAMP and should fallback to the default domain
|
|
19
|
+
'usw2.pure.cloud'
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* Returns the origin that web component assets should be loaded from.
|
|
23
|
+
* Will use the domain of the current window if it matches a Genesys domain.
|
|
24
|
+
*/
|
|
25
|
+
function getAssetsOrigin() {
|
|
26
|
+
var pageHost = window.location.hostname;
|
|
27
|
+
var matchedDomain = DOMAIN_LIST.find(function (regionDomain) {
|
|
28
|
+
return pageHost.endsWith(regionDomain);
|
|
29
|
+
});
|
|
30
|
+
return "https://app.".concat(matchedDomain || DEFAULT_DOMAIN);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var ASSET_PREFIX = "/spark-components/build-assets/4.0.0-beta.37-42/genesys-webcomponents/";
|
|
34
|
+
var SCRIPT_PATH = "genesys-webcomponents.esm.js";
|
|
35
|
+
var STYLE_PATH = "genesys-webcomponents.css";
|
|
36
|
+
var SCRIPT_SRC = "".concat(getAssetsOrigin()).concat(ASSET_PREFIX).concat(SCRIPT_PATH);
|
|
37
|
+
var STYLE_HREF = "".concat(getAssetsOrigin()).concat(ASSET_PREFIX).concat(STYLE_PATH);
|
|
38
|
+
/**
|
|
39
|
+
* Loads the spark webcomponents from a shared CDN
|
|
40
|
+
* @returns a promise that succeeds if the component script and styles
|
|
41
|
+
* load successfully.
|
|
42
|
+
*/
|
|
43
|
+
function registerSparkComponents() {
|
|
44
|
+
return Promise.all([
|
|
45
|
+
checkAndLoadScript(SCRIPT_SRC),
|
|
46
|
+
checkAndLoadStyle(STYLE_HREF)
|
|
47
|
+
]).then();
|
|
48
|
+
}
|
|
49
|
+
function checkAndLoadScript(scriptSrc) {
|
|
50
|
+
var existingTag = document.querySelector("script[src=\"".concat(scriptSrc, "\"]"));
|
|
51
|
+
if (existingTag) {
|
|
52
|
+
return Promise.resolve();
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
var scriptTag_1 = document.createElement('script');
|
|
56
|
+
scriptTag_1.setAttribute("type", "module");
|
|
57
|
+
scriptTag_1.setAttribute("src", scriptSrc);
|
|
58
|
+
var result = new Promise(function (resolve, reject) {
|
|
59
|
+
scriptTag_1.addEventListener('load', function () {
|
|
60
|
+
resolve();
|
|
61
|
+
});
|
|
62
|
+
scriptTag_1.addEventListener('error', function () {
|
|
63
|
+
reject("Spark script failed to load: ".concat(scriptSrc));
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
document.head.appendChild(scriptTag_1);
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function checkAndLoadStyle(styleHref) {
|
|
71
|
+
var existingTag = document.querySelector("link[href=\"".concat(styleHref, "\"]"));
|
|
72
|
+
if (existingTag) {
|
|
73
|
+
return Promise.resolve();
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
var styleTag_1 = document.createElement('link');
|
|
77
|
+
styleTag_1.setAttribute("href", styleHref);
|
|
78
|
+
styleTag_1.setAttribute("rel", "stylesheet");
|
|
79
|
+
var result = new Promise(function (resolve, reject) {
|
|
80
|
+
styleTag_1.addEventListener('load', function () {
|
|
81
|
+
resolve();
|
|
82
|
+
});
|
|
83
|
+
styleTag_1.addEventListener('error', function () {
|
|
84
|
+
reject("Spark styles failed to load: ".concat(styleHref));
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
document.head.appendChild(styleTag_1);
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// TODO: Build out utility functions where components aren't the right solution
|
|
92
|
+
// export function formatDate(...)
|
|
93
|
+
|
|
94
|
+
export { registerSparkComponents };
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "genesys-spark",
|
|
3
|
+
"version": "4.0.0-beta.37",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"author": "",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "rollup -c",
|
|
11
|
+
"dev": "rollup -c --watch",
|
|
12
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
13
|
+
"version-sync": "npm version --no-git-tag-version --allow-same-version"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@rollup/plugin-replace": "^5.0.2",
|
|
17
|
+
"@rollup/plugin-typescript": "^11.1.3",
|
|
18
|
+
"rollup": "^3.29.3"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@tsconfig/strictest": "^2.0.2"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import replace from '@rollup/plugin-replace';
|
|
2
|
+
import typescript from '@rollup/plugin-typescript';
|
|
3
|
+
|
|
4
|
+
const IS_DEV_MODE = (process.env.ROLLUP_WATCH === "true");
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
input: 'src/index.ts',
|
|
8
|
+
output: {
|
|
9
|
+
dir: 'dist'
|
|
10
|
+
},
|
|
11
|
+
plugins: [
|
|
12
|
+
replace({
|
|
13
|
+
values: {
|
|
14
|
+
'IS_DEV_MODE': IS_DEV_MODE,
|
|
15
|
+
'__ASSET_PREFIX__': IS_DEV_MODE ? '/dist/genesys-webcomponents/' : process.env.COMPONENT_ASSETS_PATH
|
|
16
|
+
},
|
|
17
|
+
preventAssignment: true
|
|
18
|
+
}),
|
|
19
|
+
typescript()
|
|
20
|
+
]
|
|
21
|
+
};
|
package/src/hosts.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
// IS_DEV_MODE is rewritten by @rollup/plugin-replace. This definition lets
|
|
3
|
+
// our typescript file typecheck.
|
|
4
|
+
var IS_DEV_MODE: boolean
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// Default domain to load assets from
|
|
8
|
+
const DEFAULT_DOMAIN = 'mypurecloud.com';
|
|
9
|
+
|
|
10
|
+
// List of Genesys UI domains
|
|
11
|
+
const DOMAIN_LIST = [
|
|
12
|
+
'apne2.pure.cloud',
|
|
13
|
+
'aps1.pure.cloud',
|
|
14
|
+
'cac1.pure.cloud',
|
|
15
|
+
'euw2.pure.cloud',
|
|
16
|
+
'inindca.com',
|
|
17
|
+
'inintca.com',
|
|
18
|
+
'mypurecloud.com.au',
|
|
19
|
+
'mypurecloud.com',
|
|
20
|
+
'mypurecloud.de',
|
|
21
|
+
'mypurecloud.ie',
|
|
22
|
+
'mypurecloud.jp',
|
|
23
|
+
'sae1.pure.cloud',
|
|
24
|
+
'use2.maximus-pure.cloud',
|
|
25
|
+
// 'use2.us-gov-pure.cloud', Assets are not currently deployed to FedRAMP and should fallback to the default domain
|
|
26
|
+
'usw2.pure.cloud'
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns the origin that web component assets should be loaded from.
|
|
31
|
+
* Will use the domain of the current window if it matches a Genesys domain.
|
|
32
|
+
*/
|
|
33
|
+
export function getAssetsOrigin(): string {
|
|
34
|
+
if (IS_DEV_MODE == true) {
|
|
35
|
+
// This conditional is optimized out in production due to @rollup/plugin-replace
|
|
36
|
+
// and rollup's dead code elimination
|
|
37
|
+
return "http://localhost:3333";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const pageHost = window.location.hostname;
|
|
41
|
+
const matchedDomain = DOMAIN_LIST.find(regionDomain =>
|
|
42
|
+
pageHost.endsWith(regionDomain)
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return `https://app.${matchedDomain || DEFAULT_DOMAIN}`;
|
|
46
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { getAssetsOrigin } from "./hosts";
|
|
2
|
+
|
|
3
|
+
const ASSET_PREFIX = "__ASSET_PREFIX__";
|
|
4
|
+
const SCRIPT_PATH = "genesys-webcomponents.esm.js";
|
|
5
|
+
const STYLE_PATH = "genesys-webcomponents.css";
|
|
6
|
+
|
|
7
|
+
const SCRIPT_SRC = `${getAssetsOrigin()}${ASSET_PREFIX}${SCRIPT_PATH}`;
|
|
8
|
+
const STYLE_HREF = `${getAssetsOrigin()}${ASSET_PREFIX}${STYLE_PATH}`;
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Loads the spark webcomponents from a shared CDN
|
|
13
|
+
* @returns a promise that succeeds if the component script and styles
|
|
14
|
+
* load successfully.
|
|
15
|
+
*/
|
|
16
|
+
export function registerSparkComponents() : Promise<void> {
|
|
17
|
+
return Promise.all([
|
|
18
|
+
checkAndLoadScript(SCRIPT_SRC),
|
|
19
|
+
checkAndLoadStyle(STYLE_HREF)
|
|
20
|
+
]).then()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function checkAndLoadScript(scriptSrc: string): Promise<void> {
|
|
24
|
+
const existingTag = document.querySelector(`script[src="${scriptSrc}"]`);
|
|
25
|
+
if (existingTag) {
|
|
26
|
+
return Promise.resolve();
|
|
27
|
+
} else {
|
|
28
|
+
const scriptTag = document.createElement('script');
|
|
29
|
+
scriptTag.setAttribute("type", "module");
|
|
30
|
+
scriptTag.setAttribute("src", scriptSrc);
|
|
31
|
+
const result = new Promise<void>((resolve, reject) => {
|
|
32
|
+
scriptTag.addEventListener('load', () => {
|
|
33
|
+
resolve();
|
|
34
|
+
})
|
|
35
|
+
scriptTag.addEventListener('error', () => {
|
|
36
|
+
reject(`Spark script failed to load: ${scriptSrc}`);
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
document.head.appendChild(scriptTag);
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function checkAndLoadStyle(styleHref: string): Promise<void> {
|
|
45
|
+
const existingTag = document.querySelector(`link[href="${styleHref}"]`);
|
|
46
|
+
if (existingTag) {
|
|
47
|
+
return Promise.resolve();
|
|
48
|
+
} else {
|
|
49
|
+
const styleTag = document.createElement('link');
|
|
50
|
+
styleTag.setAttribute("href", styleHref);
|
|
51
|
+
styleTag.setAttribute("rel", "stylesheet");
|
|
52
|
+
const result = new Promise<void>((resolve, reject) => {
|
|
53
|
+
styleTag.addEventListener('load', () => {
|
|
54
|
+
resolve();
|
|
55
|
+
})
|
|
56
|
+
styleTag.addEventListener('error', () => {
|
|
57
|
+
reject(`Spark styles failed to load: ${styleHref}`);
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
document.head.appendChild(styleTag);
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// TODO: Build out utility functions where components aren't the right solution
|
|
65
|
+
// export function formatDate(...)
|