@webex/webex-core 3.12.0 → 3.13.0-next.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.
Files changed (75) hide show
  1. package/.repo-context.json +653 -0
  2. package/.sdd/manifest.json +605 -0
  3. package/AGENTS.md +209 -0
  4. package/README.md +5 -2
  5. package/dist/config.js +45 -0
  6. package/dist/config.js.map +1 -1
  7. package/dist/credentials-config.js +12 -0
  8. package/dist/credentials-config.js.map +1 -1
  9. package/dist/index.js +14 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/interceptors/catalog-url.js +87 -0
  12. package/dist/interceptors/catalog-url.js.map +1 -0
  13. package/dist/interceptors/payload-transformer.js +25 -4
  14. package/dist/interceptors/payload-transformer.js.map +1 -1
  15. package/dist/lib/batcher.js +23 -7
  16. package/dist/lib/batcher.js.map +1 -1
  17. package/dist/lib/credentials/credentials.js +103 -4
  18. package/dist/lib/credentials/credentials.js.map +1 -1
  19. package/dist/lib/credentials/token.js +1 -1
  20. package/dist/lib/domains.js +90 -0
  21. package/dist/lib/domains.js.map +1 -0
  22. package/dist/lib/services/service-catalog.js +108 -18
  23. package/dist/lib/services/service-catalog.js.map +1 -1
  24. package/dist/lib/services/services.js +242 -38
  25. package/dist/lib/services/services.js.map +1 -1
  26. package/dist/lib/services-v2/service-catalog.js +14 -13
  27. package/dist/lib/services-v2/service-catalog.js.map +1 -1
  28. package/dist/lib/services-v2/services-v2.js +255 -42
  29. package/dist/lib/services-v2/services-v2.js.map +1 -1
  30. package/dist/lib/static-asset-loader.js +153 -0
  31. package/dist/lib/static-asset-loader.js.map +1 -0
  32. package/dist/plugins/logger.js +1 -1
  33. package/dist/webex-core.js +11 -3
  34. package/dist/webex-core.js.map +1 -1
  35. package/docs/adr/index.md +32 -0
  36. package/docs/architecture.md +298 -0
  37. package/docs/getting-started.md +96 -0
  38. package/docs/index.md +55 -0
  39. package/docs/specs/README.md +76 -0
  40. package/package.json +13 -13
  41. package/schemas/repo-context.schema.json +796 -0
  42. package/src/config.js +49 -0
  43. package/src/credentials-config.js +13 -0
  44. package/src/docs/README.md +732 -0
  45. package/src/index.js +2 -0
  46. package/src/interceptors/catalog-url.js +66 -0
  47. package/src/interceptors/docs/README.md +658 -0
  48. package/src/interceptors/payload-transformer.js +23 -1
  49. package/src/lib/batcher.js +25 -10
  50. package/src/lib/credentials/credentials.js +93 -3
  51. package/src/lib/credentials/docs/README.md +846 -0
  52. package/src/lib/domains.ts +94 -0
  53. package/src/lib/services/docs/README.md +737 -0
  54. package/src/lib/services/service-catalog.js +112 -16
  55. package/src/lib/services/services.js +220 -22
  56. package/src/lib/services-v2/docs/README.md +751 -0
  57. package/src/lib/services-v2/service-catalog.ts +16 -12
  58. package/src/lib/services-v2/services-v2.ts +234 -24
  59. package/src/lib/static-asset-loader.ts +128 -0
  60. package/src/lib/storage/docs/README.md +646 -0
  61. package/src/webex-core.js +8 -0
  62. package/test/fixtures/activation-email.ts +22 -0
  63. package/test/integration/spec/services/services.js +183 -112
  64. package/test/integration/spec/services-v2/services-v2.js +169 -98
  65. package/test/unit/spec/credentials/credentials.js +247 -3
  66. package/test/unit/spec/interceptors/auth.js +56 -0
  67. package/test/unit/spec/interceptors/catalog-url.js +224 -0
  68. package/test/unit/spec/interceptors/payload-transformer.js +119 -1
  69. package/test/unit/spec/lib/batcher.js +56 -0
  70. package/test/unit/spec/services/service-catalog.js +368 -11
  71. package/test/unit/spec/services/services.js +466 -2
  72. package/test/unit/spec/services-v2/service-catalog.ts +134 -11
  73. package/test/unit/spec/services-v2/services-v2.ts +588 -0
  74. package/test/unit/spec/static-asset-loader.ts +224 -0
  75. package/test/unit/spec/webex-core.js +77 -1
@@ -0,0 +1,94 @@
1
+ import Url from 'url';
2
+
3
+ import {uniq} from 'lodash';
4
+
5
+ // Canonicalise a hostname for comparison: lowercase, drop the brackets around
6
+ // an IPv6 literal, and drop leading/trailing dots. DNS treats `Example.com`,
7
+ // `example.com.` and `example.com` as the same name.
8
+ //
9
+ // Node's `url.domainToASCII` looks like the standard way to do this, but the
10
+ // `url` polyfill this package bundles for the browser does not implement it,
11
+ // so it cannot be used here. It also leaves trailing dots in place.
12
+ const normalizeHostname = (value: string): string =>
13
+ typeof value === 'string'
14
+ ? value
15
+ .toLowerCase()
16
+ .replace(/^\[|\]$/g, '')
17
+ .replace(/^\.+/, '')
18
+ .replace(/\.+$/, '')
19
+ : '';
20
+
21
+ /**
22
+ * Canonicalise a list of configured allowed domains, discarding any entry that
23
+ * is not a usable hostname. Callers normalise on the way in so the stored list
24
+ * is already canonical, rather than re-deriving it on every request.
25
+ *
26
+ * @param {Array<string>} allowedDomains - The configured allowed domains.
27
+ * @returns {Array<string>} - Normalized, de-duplicated, non-empty entries.
28
+ */
29
+ export const normalizeAllowedDomains = (allowedDomains: Array<string>): Array<string> =>
30
+ uniq(
31
+ (Array.isArray(allowedDomains) ? allowedDomains : []).map(normalizeHostname).filter(Boolean)
32
+ );
33
+
34
+ /**
35
+ * Determine if a hostname is covered by an allowed domain, matching only on DNS
36
+ * label boundaries, so that a hostname is allowed only when it is the domain
37
+ * itself or a subdomain of it. Matching on a substring instead would treat
38
+ * unrelated hostnames that merely contain the domain as allowed.
39
+ *
40
+ * @param {string} hostname - Hostname to test. Must not include a port.
41
+ * @param {string} allowedDomain - The configured allowed domain.
42
+ * @returns {boolean} - True when the hostname is the domain or a subdomain of it.
43
+ */
44
+ const hostnameMatchesDomain = (hostname: string, allowedDomain: string): boolean => {
45
+ // The stored list is normalized on write, but `allowedDomains` is a public
46
+ // property, so normalize again here rather than trust it.
47
+ const host = normalizeHostname(hostname);
48
+ const domain = normalizeHostname(allowedDomain);
49
+
50
+ return !!host && !!domain && (host === domain || host.endsWith(`.${domain}`));
51
+ };
52
+
53
+ /**
54
+ * Find the allowed domain covering a url, or `undefined` if there is none.
55
+ *
56
+ * Parsing lives here rather than in the callers, and deliberately uses both url
57
+ * parsers, because this check gates an `Authorization` header. The two
58
+ * transports behind `@webex/http-core` do not use the same url parser: the
59
+ * browser transport parses per WHATWG, the node transport uses Node's legacy
60
+ * `Url.parse`, and for some inputs the two resolve different hosts.
61
+ *
62
+ * Rather than picking one, require both to agree and fail closed when they do
63
+ * not, so this check can never authorize a host that differs from the one a
64
+ * transport would actually connect to. Do not narrow this to a single parser.
65
+ *
66
+ * @param {string} url - The url to match the allowed domains against.
67
+ * @param {Array<string>} allowedDomains - The configured allowed domains.
68
+ * @returns {string} - The matching allowed domain, or undefined if there is none.
69
+ */
70
+ export const matchAllowedDomain = (
71
+ url: string,
72
+ allowedDomains: Array<string>
73
+ ): string | undefined => {
74
+ let hostname: string;
75
+ let legacyHostname: string;
76
+
77
+ try {
78
+ ({hostname} = new URL(url));
79
+ ({hostname: legacyHostname} = Url.parse(url));
80
+ } catch {
81
+ // Not a parsable absolute url, so it cannot belong to an allowed domain.
82
+ return undefined;
83
+ }
84
+
85
+ if (normalizeHostname(hostname) !== normalizeHostname(legacyHostname)) {
86
+ return undefined;
87
+ }
88
+
89
+ return (allowedDomains || []).find((allowedDomain) =>
90
+ hostnameMatchesDomain(hostname, allowedDomain)
91
+ );
92
+ };
93
+
94
+ export default matchAllowedDomain;