genesys-cloud-service-discovery-web 3.0.57 → 3.0.60

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.
Files changed (3) hide show
  1. package/index.js +95 -47
  2. package/index.umd.js +1047 -999
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -8,34 +8,72 @@ 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 __spreadArray(to, from, pack) {
38
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
39
+ if (ar || !(i in from)) {
40
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
41
+ ar[i] = from[i];
42
+ }
43
+ }
44
+ return to.concat(ar || Array.prototype.slice.call(from));
45
+ }
46
+
11
47
  function assert(value, msg) {
12
48
  if (!value)
13
49
  throw new Error(msg);
14
50
  }
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`);
51
+ function assertValidStringArray(value, valueName) {
52
+ if (valueName === void 0) { valueName = 'value'; }
53
+ assert(value instanceof Array, "".concat(valueName, " must be an array of strings"));
54
+ for (var _i = 0, value_1 = value; _i < value_1.length; _i++) {
55
+ var name_1 = value_1[_i];
56
+ assert(typeof name_1 === "string", "Each item in ".concat(valueName, " must be a string"));
19
57
  }
20
58
  }
21
59
  function parseValidUrl(value) {
22
60
  assert(typeof value === "string", "url is not a string");
23
61
  // Explicitly pass {} as 2nd param so that `url-parse` parses the url
24
62
  // independently from the browser's current window location
25
- const url = parseUrl__default['default'](value, {});
26
- assert(url.protocol && url.hostname, `invalid url: '${value}', unable to parse hostname`);
63
+ var url = parseUrl__default['default'](value, {});
64
+ assert(url.protocol && url.hostname, "invalid url: '".concat(value, "', unable to parse hostname"));
27
65
  return url;
28
66
  }
29
67
  function assertValidEnvFilters(value) {
30
68
  assert(!!value && typeof value === "object", "Provided filters must be an object");
31
- const filters = value;
69
+ var filters = value;
32
70
  if (filters.env !== undefined) {
33
71
  assert(filters.env instanceof Array, 'filters.env must be an array');
34
- assert(filters.env.every(env => ENVS.indexOf(env) >= 0), `'${filters.env}' - filters.env must be an array containing only: ${ENVS.join(',')}`);
72
+ assert(filters.env.every(function (env) { return ENVS.indexOf(env) >= 0; }), "'".concat(filters.env, "' - filters.env must be an array containing only: ").concat(ENVS.join(',')));
35
73
  }
36
74
  if (filters.status !== undefined) {
37
75
  assert(filters.status instanceof Array, 'filters.status must be an array');
38
- assert(filters.status.every(status => STATUSES.indexOf(status) >= 0), `'${filters.status}' - filters.status must be an array containing only: ${STATUSES.join(',')}`);
76
+ assert(filters.status.every(function (status) { return STATUSES.indexOf(status) >= 0; }), "'".concat(filters.status, "' - filters.status must be an array containing only: ").concat(STATUSES.join(',')));
39
77
  }
40
78
  }
41
79
 
@@ -150,28 +188,29 @@ var _environments = [
150
188
  }
151
189
  ];
152
190
 
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) => {
191
+ var environments = _environments;
192
+ var ENVS = ["dev", "test", "prod", "fedramp"];
193
+ var STATUSES = ["alpha", "beta", "stable", "archived"];
194
+ var DEFAULT_LOCAL_HOSTNAMES = ["localhost", "127.0.0.1"];
195
+ var STABLE_PUBLIC_ENVS_FILTERS = { env: ["prod", "fedramp"], status: ["stable"] };
196
+ var NO_FILTERS = {};
197
+ var endsWith = function (s1, s2) {
160
198
  return s1.slice(s1.length - s2.length) === s2;
161
199
  };
162
- const matchesHostname = (hostname) => (domain) => {
163
- return hostname === domain || endsWith(hostname, `.${domain}`);
164
- };
200
+ var matchesHostname = function (hostname) { return function (domain) {
201
+ return hostname === domain || endsWith(hostname, ".".concat(domain));
202
+ }; };
165
203
  /**
166
204
  * Retrieves the list of Genesys Cloud environment/region deployments.
167
205
  * Defaults to only returning stable, publically available deployments (e.g. prod, fedramp)
168
206
  */
169
- const getEnvironments = (filters = STABLE_PUBLIC_ENVS_FILTERS) => {
207
+ var getEnvironments = function (filters) {
208
+ if (filters === void 0) { filters = STABLE_PUBLIC_ENVS_FILTERS; }
170
209
  assertValidEnvFilters(filters);
171
- const { env, status } = filters;
210
+ var env = filters.env, status = filters.status;
172
211
  return environments
173
- .filter(data => env === undefined || env.indexOf(data.env) >= 0)
174
- .filter(data => status === undefined || status.indexOf(data.status) >= 0);
212
+ .filter(function (data) { return env === undefined || env.indexOf(data.env) >= 0; })
213
+ .filter(function (data) { return status === undefined || status.indexOf(data.status) >= 0; });
175
214
  };
176
215
  /**
177
216
  * Whether or not the given url is a known Genesys Cloud deployment. If no filters
@@ -181,7 +220,7 @@ const getEnvironments = (filters = STABLE_PUBLIC_ENVS_FILTERS) => {
181
220
  * - throws an error if passed an invalid url
182
221
  * - returns false for localhost
183
222
  */
184
- const isKnown = (url, filters) => !!parse(url, filters);
223
+ var isKnown = function (url, filters) { return !!parse(url, filters); };
185
224
  /**
186
225
  * Retrieve the Genesys Cloud `Environment` for a given url. If no filters
187
226
  * are provided, the default behavior is to only check stable, publically available deployments
@@ -190,10 +229,11 @@ const isKnown = (url, filters) => !!parse(url, filters);
190
229
  * - throws an error if passed an invalid url
191
230
  * - returns undefined if no match is found
192
231
  */
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);
232
+ var parse = function (url, filters) {
233
+ var hostname = parseValidUrl(url).hostname;
234
+ return getEnvironments(filters).find(function (_a) {
235
+ var publicDomainName = _a.publicDomainName, publicDomainAliases = _a.publicDomainAliases;
236
+ var domains = __spreadArray([publicDomainName], publicDomainAliases, true).filter(function (d) { return !!d; });
197
237
  return domains.some(matchesHostname(hostname));
198
238
  });
199
239
  };
@@ -203,16 +243,17 @@ const parse = (url, filters) => {
203
243
  *
204
244
  * By default, this method will attempt to search across all available environments (no filtering).
205
245
  */
206
- const parseDeployedRuntime = (url = window.location.href, filters = NO_FILTERS) => {
246
+ var parseDeployedRuntime = function (url, filters) {
247
+ if (url === void 0) { url = window.location.href; }
248
+ if (filters === void 0) { filters = NO_FILTERS; }
207
249
  assertValidEnvFilters(filters);
208
- const { hostname } = parseValidUrl(url);
209
- const parsedEnv = parse(url, filters);
250
+ var hostname = parseValidUrl(url).hostname;
251
+ var parsedEnv = parse(url, filters);
210
252
  if (!parsedEnv)
211
253
  return;
212
- return Object.assign(Object.assign({}, parsedEnv), { local: false, currentDomainName: [
213
- parsedEnv.publicDomainName,
214
- ...parsedEnv.publicDomainAliases
215
- ].filter(d => !!d).find(matchesHostname(hostname)) });
254
+ return __assign(__assign({}, parsedEnv), { local: false, currentDomainName: __spreadArray([
255
+ parsedEnv.publicDomainName
256
+ ], parsedEnv.publicDomainAliases, true).filter(function (d) { return !!d; }).find(matchesHostname(hostname)) });
216
257
  };
217
258
  /**
218
259
  * When the hostname matches a valid local hostname, either by matching our defaults or your custom list
@@ -225,17 +266,22 @@ const parseDeployedRuntime = (url = window.location.href, filters = NO_FILTERS)
225
266
  * Note: `currentDomainName` will be equal to `publicDomainName` when using this method.
226
267
  * Example: https://localhost:3000/prod => us-east-1 prod environment & runtime details
227
268
  */
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
- }
269
+ var parseRuntimeFromLocalPath = function (localHostnames) {
270
+ if (localHostnames === void 0) { localHostnames = DEFAULT_LOCAL_HOSTNAMES; }
271
+ return function (url, filters) {
272
+ if (url === void 0) { url = window.location.href; }
273
+ if (filters === void 0) { filters = NO_FILTERS; }
274
+ assertValidEnvFilters(filters);
275
+ assertValidStringArray(localHostnames, 'localHostnames');
276
+ var _a = parseValidUrl(url), hostname = _a.hostname, pathname = _a.pathname;
277
+ if (localHostnames.indexOf(hostname) >= 0) {
278
+ var _b = pathname.split("/"), envName_1 = _b[1];
279
+ var localEnv = getEnvironments(filters).find(function (e) { return e.name === envName_1; });
280
+ if (!localEnv)
281
+ return;
282
+ return __assign(__assign({}, localEnv), { local: true, currentDomainName: localEnv.publicDomainName });
283
+ }
284
+ };
239
285
  };
240
286
  /**
241
287
  * This is the default and recommended `RuntimeParser` implementation that is composed of the
@@ -243,7 +289,9 @@ const parseRuntimeFromLocalPath = (localHostnames = DEFAULT_LOCAL_HOSTNAMES) =>
243
289
  * `parseDeployedRuntime` with your own `RuntimeParser` as an alternative to parseRuntimeFromLocalPath.
244
290
  * You may also opt to use "parse" and `getEnvironments` together to create your own parsing strategy.
245
291
  */
246
- const parseRuntime = (url = window.location.href, filters = NO_FILTERS) => {
292
+ var parseRuntime = function (url, filters) {
293
+ if (url === void 0) { url = window.location.href; }
294
+ if (filters === void 0) { filters = NO_FILTERS; }
247
295
  return parseRuntimeFromLocalPath()(url, filters) || parseDeployedRuntime(url, filters);
248
296
  };
249
297