@quadient/skillshare 1.20.1 → 1.20.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 (2) hide show
  1. package/dist/teams-auth.js +39 -0
  2. package/package.json +1 -1
@@ -155,6 +155,9 @@ export async function captureTeamsLogin(options) {
155
155
  let lastAttemptFresh = false;
156
156
  let resetCache = false;
157
157
  let lastFailure = '';
158
+ let teamsOpenSince = null;
159
+ let stallRecovery = 'none';
160
+ const stallMs = options.stallMs ?? 60_000;
158
161
  // Exchange through the Teams tab so the browser's network, proxy and certificate settings apply, as they do for Teams itself.
159
162
  const exchangeSkype = (spacesToken) => browserSkypeExchange(page, spacesToken);
160
163
  while (true) {
@@ -206,6 +209,27 @@ export async function captureTeamsLogin(options) {
206
209
  }
207
210
  }
208
211
  }
212
+ // Time only while Teams itself is open; a Microsoft sign-in page means the user is still signing in.
213
+ teamsOpenSince = origins.has(new URL(page.url()).origin) ? teamsOpenSince ?? Date.now() : null;
214
+ if (!options.recover && teamsOpenSince !== null && Date.now() - teamsOpenSince > stallMs) {
215
+ if (stallRecovery === 'none') {
216
+ stallRecovery = 'reset';
217
+ options.onProgress?.('Teams has provided no API tokens for a minute. Clearing Teams web data in the Skillshare browser profile ' +
218
+ '(Microsoft sign-in cookies are kept) and reloading Teams.');
219
+ await abortable(clearTeamsWebData(page), signal);
220
+ await abortable(page.goto('https://teams.microsoft.com/v2/', { waitUntil: 'domcontentloaded', timeout: 60_000 }), signal);
221
+ teamsOpenSince = null;
222
+ lastRefresh = 0;
223
+ lastAttemptFresh = false;
224
+ continue;
225
+ }
226
+ if (stallRecovery === 'reset') {
227
+ stallRecovery = 'hinted';
228
+ options.onProgress?.('Teams still provides no API tokens. Press Ctrl+C, move the Skillshare browser profile aside and run skillshare teams login again; ' +
229
+ `you will sign in to Microsoft once more:\n mv ${JSON.stringify(options.profileDirectory)} ${JSON.stringify(options.profileDirectory + '.bak')}`);
230
+ lastProgress = Date.now();
231
+ }
232
+ }
209
233
  if (Date.now() - lastProgress > 30_000) {
210
234
  options.onProgress?.('Waiting for Teams sign-in and API tokens. Finish sign-in in the browser; open Teams search if needed.');
211
235
  lastProgress = Date.now();
@@ -340,6 +364,21 @@ export function describeFailure(error) {
340
364
  const cause = error.cause instanceof Error && error.cause.message && !error.message.includes(error.cause.message) ? ` (${error.cause.message})` : '';
341
365
  return `${error.message}${cause}`.slice(0, 400);
342
366
  }
367
+ /**
368
+ * Teams web can stall on stale cached app data ("Almost there…", "There was a problem reaching this app"). Clear what Teams
369
+ * stores per origin in this dedicated profile, but keep cookies so Microsoft SSO signs Teams in again without a prompt.
370
+ */
371
+ export async function clearTeamsWebData(page) {
372
+ const session = await page.context().newCDPSession(page);
373
+ try {
374
+ for (const origin of origins)
375
+ await session.send('Storage.clearDataForOrigin', { origin,
376
+ storageTypes: 'local_storage,indexeddb,service_workers,cache_storage,file_systems,websql,shader_cache' });
377
+ }
378
+ finally {
379
+ await session.detach().catch(() => { });
380
+ }
381
+ }
343
382
  async function resetTeamsGrant(page, objectId, clientId) {
344
383
  if (!origins.has(new URL(page.url()).origin))
345
384
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quadient/skillshare",
3
- "version": "1.20.1",
3
+ "version": "1.20.2",
4
4
  "description": "Skillshare CLI for installing and publishing Quadient skills",
5
5
  "type": "module",
6
6
  "bin": {