genesys-cloud-service-discovery-web 3.0.50 → 3.0.53
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/index.js +56 -93
- package/index.umd.js +999 -897
- package/package.json +11 -9
- package/validations.d.ts +1 -1
package/index.js
CHANGED
|
@@ -8,70 +8,34 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
8
8
|
|
|
9
9
|
var parseUrl__default = /*#__PURE__*/_interopDefaultLegacy(parseUrl);
|
|
10
10
|
|
|
11
|
-
/*! *****************************************************************************
|
|
12
|
-
Copyright (c) Microsoft Corporation.
|
|
13
|
-
|
|
14
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
15
|
-
purpose with or without fee is hereby granted.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
18
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
19
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
20
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
21
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
22
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
23
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
24
|
-
***************************************************************************** */
|
|
25
|
-
|
|
26
|
-
var __assign = function() {
|
|
27
|
-
__assign = Object.assign || function __assign(t) {
|
|
28
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
29
|
-
s = arguments[i];
|
|
30
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
31
|
-
}
|
|
32
|
-
return t;
|
|
33
|
-
};
|
|
34
|
-
return __assign.apply(this, arguments);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
function __spreadArrays() {
|
|
38
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
39
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
40
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
41
|
-
r[k] = a[j];
|
|
42
|
-
return r;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
11
|
function assert(value, msg) {
|
|
46
12
|
if (!value)
|
|
47
13
|
throw new Error(msg);
|
|
48
14
|
}
|
|
49
|
-
function assertValidStringArray(value, valueName) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var name_1 = value_1[_i];
|
|
54
|
-
assert(typeof name_1 === "string", "Each item in " + valueName + " must be a string");
|
|
15
|
+
function assertValidStringArray(value, valueName = 'value') {
|
|
16
|
+
assert(value instanceof Array, `${valueName} must be an array of strings`);
|
|
17
|
+
for (let name of value) {
|
|
18
|
+
assert(typeof name === "string", `Each item in ${valueName} must be a string`);
|
|
55
19
|
}
|
|
56
20
|
}
|
|
57
21
|
function parseValidUrl(value) {
|
|
58
22
|
assert(typeof value === "string", "url is not a string");
|
|
59
23
|
// Explicitly pass {} as 2nd param so that `url-parse` parses the url
|
|
60
24
|
// independently from the browser's current window location
|
|
61
|
-
|
|
62
|
-
assert(url.protocol && url.hostname,
|
|
25
|
+
const url = parseUrl__default['default'](value, {});
|
|
26
|
+
assert(url.protocol && url.hostname, `invalid url: '${value}', unable to parse hostname`);
|
|
63
27
|
return url;
|
|
64
28
|
}
|
|
65
29
|
function assertValidEnvFilters(value) {
|
|
66
30
|
assert(!!value && typeof value === "object", "Provided filters must be an object");
|
|
67
|
-
|
|
31
|
+
const filters = value;
|
|
68
32
|
if (filters.env !== undefined) {
|
|
69
33
|
assert(filters.env instanceof Array, 'filters.env must be an array');
|
|
70
|
-
assert(filters.env.every(
|
|
34
|
+
assert(filters.env.every(env => ENVS.indexOf(env) >= 0), `'${filters.env}' - filters.env must be an array containing only: ${ENVS.join(',')}`);
|
|
71
35
|
}
|
|
72
36
|
if (filters.status !== undefined) {
|
|
73
37
|
assert(filters.status instanceof Array, 'filters.status must be an array');
|
|
74
|
-
assert(filters.status.every(
|
|
38
|
+
assert(filters.status.every(status => STATUSES.indexOf(status) >= 0), `'${filters.status}' - filters.status must be an array containing only: ${STATUSES.join(',')}`);
|
|
75
39
|
}
|
|
76
40
|
}
|
|
77
41
|
|
|
@@ -166,6 +130,15 @@ var _environments = [
|
|
|
166
130
|
publicDomainAliases: [
|
|
167
131
|
]
|
|
168
132
|
},
|
|
133
|
+
{
|
|
134
|
+
name: "prod-sae1",
|
|
135
|
+
env: "prod",
|
|
136
|
+
region: "sa-east-1",
|
|
137
|
+
status: "beta",
|
|
138
|
+
publicDomainName: "sae1.pure.cloud",
|
|
139
|
+
publicDomainAliases: [
|
|
140
|
+
]
|
|
141
|
+
},
|
|
169
142
|
{
|
|
170
143
|
name: "prod-usw2",
|
|
171
144
|
env: "prod",
|
|
@@ -177,29 +150,28 @@ var _environments = [
|
|
|
177
150
|
}
|
|
178
151
|
];
|
|
179
152
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
153
|
+
const environments = _environments;
|
|
154
|
+
const ENVS = ["dev", "test", "prod", "fedramp"];
|
|
155
|
+
const STATUSES = ["alpha", "beta", "stable", "archived"];
|
|
156
|
+
const DEFAULT_LOCAL_HOSTNAMES = ["localhost", "127.0.0.1"];
|
|
157
|
+
const STABLE_PUBLIC_ENVS_FILTERS = { env: ["prod", "fedramp"], status: ["stable"] };
|
|
158
|
+
const NO_FILTERS = {};
|
|
159
|
+
const endsWith = (s1, s2) => {
|
|
187
160
|
return s1.slice(s1.length - s2.length) === s2;
|
|
188
161
|
};
|
|
189
|
-
|
|
190
|
-
return hostname === domain || endsWith(hostname,
|
|
191
|
-
};
|
|
162
|
+
const matchesHostname = (hostname) => (domain) => {
|
|
163
|
+
return hostname === domain || endsWith(hostname, `.${domain}`);
|
|
164
|
+
};
|
|
192
165
|
/**
|
|
193
166
|
* Retrieves the list of Genesys Cloud environment/region deployments.
|
|
194
167
|
* Defaults to only returning stable, publically available deployments (e.g. prod, fedramp)
|
|
195
168
|
*/
|
|
196
|
-
|
|
197
|
-
if (filters === void 0) { filters = STABLE_PUBLIC_ENVS_FILTERS; }
|
|
169
|
+
const getEnvironments = (filters = STABLE_PUBLIC_ENVS_FILTERS) => {
|
|
198
170
|
assertValidEnvFilters(filters);
|
|
199
|
-
|
|
171
|
+
const { env, status } = filters;
|
|
200
172
|
return environments
|
|
201
|
-
.filter(
|
|
202
|
-
.filter(
|
|
173
|
+
.filter(data => env === undefined || env.indexOf(data.env) >= 0)
|
|
174
|
+
.filter(data => status === undefined || status.indexOf(data.status) >= 0);
|
|
203
175
|
};
|
|
204
176
|
/**
|
|
205
177
|
* Whether or not the given url is a known Genesys Cloud deployment. If no filters
|
|
@@ -209,7 +181,7 @@ var getEnvironments = function (filters) {
|
|
|
209
181
|
* - throws an error if passed an invalid url
|
|
210
182
|
* - returns false for localhost
|
|
211
183
|
*/
|
|
212
|
-
|
|
184
|
+
const isKnown = (url, filters) => !!parse(url, filters);
|
|
213
185
|
/**
|
|
214
186
|
* Retrieve the Genesys Cloud `Environment` for a given url. If no filters
|
|
215
187
|
* are provided, the default behavior is to only check stable, publically available deployments
|
|
@@ -218,11 +190,10 @@ var isKnown = function (url, filters) { return !!parse(url, filters); };
|
|
|
218
190
|
* - throws an error if passed an invalid url
|
|
219
191
|
* - returns undefined if no match is found
|
|
220
192
|
*/
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return getEnvironments(filters).find(
|
|
224
|
-
|
|
225
|
-
var domains = __spreadArrays([publicDomainName], publicDomainAliases).filter(function (d) { return !!d; });
|
|
193
|
+
const parse = (url, filters) => {
|
|
194
|
+
const { hostname } = parseValidUrl(url);
|
|
195
|
+
return getEnvironments(filters).find(({ publicDomainName, publicDomainAliases }) => {
|
|
196
|
+
const domains = [publicDomainName, ...publicDomainAliases].filter(d => !!d);
|
|
226
197
|
return domains.some(matchesHostname(hostname));
|
|
227
198
|
});
|
|
228
199
|
};
|
|
@@ -232,17 +203,16 @@ var parse = function (url, filters) {
|
|
|
232
203
|
*
|
|
233
204
|
* By default, this method will attempt to search across all available environments (no filtering).
|
|
234
205
|
*/
|
|
235
|
-
|
|
236
|
-
if (url === void 0) { url = window.location.href; }
|
|
237
|
-
if (filters === void 0) { filters = NO_FILTERS; }
|
|
206
|
+
const parseDeployedRuntime = (url = window.location.href, filters = NO_FILTERS) => {
|
|
238
207
|
assertValidEnvFilters(filters);
|
|
239
|
-
|
|
240
|
-
|
|
208
|
+
const { hostname } = parseValidUrl(url);
|
|
209
|
+
const parsedEnv = parse(url, filters);
|
|
241
210
|
if (!parsedEnv)
|
|
242
211
|
return;
|
|
243
|
-
return
|
|
244
|
-
parsedEnv.publicDomainName
|
|
245
|
-
|
|
212
|
+
return Object.assign(Object.assign({}, parsedEnv), { local: false, currentDomainName: [
|
|
213
|
+
parsedEnv.publicDomainName,
|
|
214
|
+
...parsedEnv.publicDomainAliases
|
|
215
|
+
].filter(d => !!d).find(matchesHostname(hostname)) });
|
|
246
216
|
};
|
|
247
217
|
/**
|
|
248
218
|
* When the hostname matches a valid local hostname, either by matching our defaults or your custom list
|
|
@@ -255,22 +225,17 @@ var parseDeployedRuntime = function (url, filters) {
|
|
|
255
225
|
* Note: `currentDomainName` will be equal to `publicDomainName` when using this method.
|
|
256
226
|
* Example: https://localhost:3000/prod => us-east-1 prod environment & runtime details
|
|
257
227
|
*/
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if (!localEnv)
|
|
270
|
-
return;
|
|
271
|
-
return __assign(__assign({}, localEnv), { local: true, currentDomainName: localEnv.publicDomainName });
|
|
272
|
-
}
|
|
273
|
-
};
|
|
228
|
+
const parseRuntimeFromLocalPath = (localHostnames = DEFAULT_LOCAL_HOSTNAMES) => (url = window.location.href, filters = NO_FILTERS) => {
|
|
229
|
+
assertValidEnvFilters(filters);
|
|
230
|
+
assertValidStringArray(localHostnames, 'localHostnames');
|
|
231
|
+
const { hostname, pathname } = parseValidUrl(url);
|
|
232
|
+
if (localHostnames.indexOf(hostname) >= 0) {
|
|
233
|
+
const [, envName] = pathname.split("/");
|
|
234
|
+
const localEnv = getEnvironments(filters).find(e => e.name === envName);
|
|
235
|
+
if (!localEnv)
|
|
236
|
+
return;
|
|
237
|
+
return Object.assign(Object.assign({}, localEnv), { local: true, currentDomainName: localEnv.publicDomainName });
|
|
238
|
+
}
|
|
274
239
|
};
|
|
275
240
|
/**
|
|
276
241
|
* This is the default and recommended `RuntimeParser` implementation that is composed of the
|
|
@@ -278,9 +243,7 @@ var parseRuntimeFromLocalPath = function (localHostnames) {
|
|
|
278
243
|
* `parseDeployedRuntime` with your own `RuntimeParser` as an alternative to parseRuntimeFromLocalPath.
|
|
279
244
|
* You may also opt to use "parse" and `getEnvironments` together to create your own parsing strategy.
|
|
280
245
|
*/
|
|
281
|
-
|
|
282
|
-
if (url === void 0) { url = window.location.href; }
|
|
283
|
-
if (filters === void 0) { filters = NO_FILTERS; }
|
|
246
|
+
const parseRuntime = (url = window.location.href, filters = NO_FILTERS) => {
|
|
284
247
|
return parseRuntimeFromLocalPath()(url, filters) || parseDeployedRuntime(url, filters);
|
|
285
248
|
};
|
|
286
249
|
|