@webex/webex-core 3.11.0-webex-services-ready.1 → 3.12.0-llmrefactor.1

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 (49) hide show
  1. package/README.md +5 -2
  2. package/dist/config.js +15 -0
  3. package/dist/config.js.map +1 -1
  4. package/dist/credentials-config.js +12 -0
  5. package/dist/credentials-config.js.map +1 -1
  6. package/dist/interceptors/redirect.js +1 -1
  7. package/dist/interceptors/redirect.js.map +1 -1
  8. package/dist/lib/batcher.js +23 -7
  9. package/dist/lib/batcher.js.map +1 -1
  10. package/dist/lib/credentials/credentials.js +48 -4
  11. package/dist/lib/credentials/credentials.js.map +1 -1
  12. package/dist/lib/credentials/token.js +1 -1
  13. package/dist/lib/domains.js +90 -0
  14. package/dist/lib/domains.js.map +1 -0
  15. package/dist/lib/services/service-catalog.js +6 -10
  16. package/dist/lib/services/service-catalog.js.map +1 -1
  17. package/dist/lib/services/services.js +208 -51
  18. package/dist/lib/services/services.js.map +1 -1
  19. package/dist/lib/services-v2/service-catalog.js +6 -12
  20. package/dist/lib/services-v2/service-catalog.js.map +1 -1
  21. package/dist/lib/services-v2/services-v2.js +207 -46
  22. package/dist/lib/services-v2/services-v2.js.map +1 -1
  23. package/dist/plugins/logger.js +1 -1
  24. package/dist/webex-core.js +2 -2
  25. package/dist/webex-core.js.map +1 -1
  26. package/package.json +13 -13
  27. package/src/config.js +17 -0
  28. package/src/credentials-config.js +13 -0
  29. package/src/interceptors/redirect.js +4 -1
  30. package/src/lib/batcher.js +25 -10
  31. package/src/lib/credentials/credentials.js +50 -3
  32. package/src/lib/domains.ts +94 -0
  33. package/src/lib/services/service-catalog.js +6 -10
  34. package/src/lib/services/services.js +174 -37
  35. package/src/lib/services-v2/service-catalog.ts +6 -11
  36. package/src/lib/services-v2/services-v2.ts +173 -33
  37. package/test/fixtures/activation-email.ts +22 -0
  38. package/test/integration/spec/services/service-catalog.js +7 -6
  39. package/test/integration/spec/services/services.js +49 -24
  40. package/test/integration/spec/services-v2/services-v2.js +49 -24
  41. package/test/unit/spec/credentials/credentials.js +133 -2
  42. package/test/unit/spec/interceptors/auth.js +56 -0
  43. package/test/unit/spec/lib/batcher.js +56 -0
  44. package/test/unit/spec/services/service-catalog.js +93 -11
  45. package/test/unit/spec/services/services.js +458 -322
  46. package/test/unit/spec/services-v2/service-catalog.ts +93 -11
  47. package/test/unit/spec/services-v2/services-v2.ts +403 -214
  48. package/test/unit/spec/webex-core.js +0 -2
  49. package/test/unit/spec/webex-internal-core.js +0 -2
@@ -101,7 +101,24 @@ describe('webex-core', () => {
101
101
  const domains = [];
102
102
 
103
103
  beforeEach(() => {
104
- domains.push('example-a', 'example-b', 'example-c');
104
+ // Shaped like a real catalog rather than a tidy list: the commercial
105
+ // domains the sdk ships with, a multi-part suffix, sites added at
106
+ // runtime from meeting preferences, an entry that overlaps another,
107
+ // and an unset entry, which callers can add and which must match
108
+ // nothing.
109
+ domains.push(
110
+ 'wbx2.com',
111
+ 'ciscospark.com',
112
+ 'webex.com',
113
+ 'webexapis.com',
114
+ 'broadcloud.com.au',
115
+ 'webexgov.us',
116
+ 'example-a.com',
117
+ 'example-b.com',
118
+ 'example-c.com',
119
+ 'go.example-a.com',
120
+ ''
121
+ );
105
122
 
106
123
  catalog.setAllowedDomains(domains);
107
124
  });
@@ -110,10 +127,60 @@ describe('webex-core', () => {
110
127
  domains.length = 0;
111
128
  });
112
129
 
113
- it('finds an allowed domain that matches a specific url', () => {
114
- const domain = catalog.findAllowedDomain('http://example-a.com/resource/id');
115
-
116
- assert.include(domains, domain);
130
+ [
131
+ // real service hosts resolve to the entry that covers them
132
+ ['https://u2c-a.wbx2.com/u2c/api/v1/limited/catalog', 'wbx2.com'],
133
+ ['https://conv-a.wbx2.com/conversation/api/v1/conversations', 'wbx2.com'],
134
+ ['https://foobar.ciscospark.com/resource/id', 'ciscospark.com'],
135
+ ['https://idbroker.webex.com/idb/token', 'webex.com'],
136
+ ['https://webexapis.com/v1/people/me', 'webexapis.com'],
137
+ // an entry is not required to be a bare registrable domain
138
+ ['https://foo.broadcloud.com.au/resource/id', 'broadcloud.com.au'],
139
+ ['https://a.b.webexgov.us/resource/id', 'webexgov.us'],
140
+ // the domain itself and its subdomains match
141
+ ['https://example-a.com/resource/id', 'example-a.com'],
142
+ ['https://sub.example-b.com/resource/id', 'example-b.com'],
143
+ ['https://deep.sub.example-c.com/resource/id', 'example-c.com'],
144
+ // overlapping entries resolve to the first covering entry in the list
145
+ ['https://go.example-a.com/resource/id', 'example-a.com'],
146
+ // an explicit port must not defeat the match
147
+ ['https://example-a.com:8443/resource/id', 'example-a.com'],
148
+ ['https://u2c-a.wbx2.com:8000/resource/id', 'wbx2.com'],
149
+ // hostname comparison is case insensitive
150
+ ['https://U2C-A.WBX2.COM/resource/id', 'wbx2.com'],
151
+ // a trailing dot is the same name
152
+ ['https://u2c-a.wbx2.com./resource/id', 'wbx2.com'],
153
+ // a sibling registrable domain must not match
154
+ ['https://notwebex.com/resource/id', undefined],
155
+ ['https://mywebexgov.us/resource/id', undefined],
156
+ ['https://webex.company/resource/id', undefined],
157
+ ['https://webex.com-unrelated.example/resource/id', undefined],
158
+ ['https://example-a.community/resource/id', undefined],
159
+ // a partial label must not match, even against a multi-part entry
160
+ ['https://broadcloud.com/resource/id', undefined],
161
+ // the domain matches only as a suffix, on a label boundary
162
+ ['https://webex.com.unrelated.example/resource/id', undefined],
163
+ ['https://unrelated.example/webex.com/resource/id', undefined],
164
+ ['https://unrelated.example/?next=https://webex.com', undefined],
165
+ // userinfo is not the host
166
+ ['https://webex.com@unrelated.example/resource/id', undefined],
167
+ // an encoded or unusual separator is not a label boundary, and the url
168
+ // parsers used by the transports do not agree on where these end the
169
+ // host, so they must not resolve to an allowed domain
170
+ ['https://webex.com%2eunrelated.example/resource/id', undefined],
171
+ ['https://webex.com%2Eunrelated.example/resource/id', undefined],
172
+ ['https://unrelated.example%2ewebex.com/resource/id', undefined],
173
+ ['https://unrelated.example%2Ewebex.com/resource/id', undefined],
174
+ ['https://unrelated.example;.webex.com/resource/id', undefined],
175
+ // an empty allowed domain entry matches nothing
176
+ ['https://unrelated.example/resource/id', undefined],
177
+ // unparseable urls
178
+ ['', undefined],
179
+ ['not a url', undefined],
180
+ ].forEach(([url, expected]) => {
181
+ it(`returns ${expected} for ${url || '<empty>'}`, () => {
182
+ assert.equal(catalog.findAllowedDomain(url), expected);
183
+ });
117
184
  });
118
185
  });
119
186
 
@@ -121,7 +188,7 @@ describe('webex-core', () => {
121
188
  const domains = [];
122
189
 
123
190
  beforeEach(() => {
124
- domains.push('example-a', 'example-b', 'example-c');
191
+ domains.push('example-a.com', 'example-b.com', 'example-c.com');
125
192
 
126
193
  catalog.setAllowedDomains(domains);
127
194
  });
@@ -141,7 +208,7 @@ describe('webex-core', () => {
141
208
  const domains = [];
142
209
 
143
210
  beforeEach(() => {
144
- domains.push('example-a', 'example-b', 'example-c');
211
+ domains.push('example-a.com', 'example-b.com', 'example-c.com');
145
212
 
146
213
  catalog.setAllowedDomains(domains);
147
214
  });
@@ -151,19 +218,31 @@ describe('webex-core', () => {
151
218
  });
152
219
 
153
220
  it('sets the allowed domain entries to new values', () => {
154
- const newValues = ['example-d', 'example-e', 'example-f'];
221
+ const newValues = ['example-d.com', 'example-e.com', 'example-f.com'];
155
222
 
156
223
  catalog.setAllowedDomains(newValues);
157
224
 
158
225
  assert.notDeepInclude(domains, newValues);
159
226
  });
227
+
228
+ it('canonicalizes entries and discards those that are not usable', () => {
229
+ catalog.setAllowedDomains([
230
+ 'Example-D.COM',
231
+ 'example-d.com',
232
+ 'example-e.com.',
233
+ '',
234
+ undefined,
235
+ ]);
236
+
237
+ assert.deepEqual(catalog.getAllowedDomains(), ['example-d.com', 'example-e.com']);
238
+ });
160
239
  });
161
240
 
162
241
  describe('#addAllowedDomains()', () => {
163
242
  const domains = [];
164
243
 
165
244
  beforeEach(() => {
166
- domains.push('example-a', 'example-b', 'example-c');
245
+ domains.push('example-a.com', 'example-b.com', 'example-c.com');
167
246
 
168
247
  catalog.setAllowedDomains(domains);
169
248
  });
@@ -173,13 +252,16 @@ describe('webex-core', () => {
173
252
  });
174
253
 
175
254
  it('merge the allowed domain entries with new values', () => {
176
- const newValues = ['example-c', 'example-e', 'example-f'];
255
+ const newValues = ['example-c.com', 'example-e.com', 'example-f.com'];
177
256
 
178
257
  catalog.addAllowedDomains(newValues);
179
258
 
180
259
  const list = catalog.getAllowedDomains();
181
260
 
182
- assert.match(['example-a', 'example-b', 'example-c', 'example-e', 'example-f'], list);
261
+ assert.match(
262
+ ['example-a.com', 'example-b.com', 'example-c.com', 'example-e.com', 'example-f.com'],
263
+ list
264
+ );
183
265
  });
184
266
  });
185
267