diff --git a/ember-simple-auth-token/package.json b/ember-simple-auth-token/package.json index 95ac25d..f715139 100644 --- a/ember-simple-auth-token/package.json +++ b/ember-simple-auth-token/package.json @@ -10,11 +10,7 @@ "build": "rollup --config", "deploy": "ember build -prod && ember github-pages:commit --message \"Deploy gh-pages from commit $(git rev-parse HEAD)\" && git push origin gh-pages:gh-pages", "lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"", - "lint:css": "stylelint \"**/*.css\"", - "lint:css:fix": "concurrently \"npm:lint:css -- --fix\"", "lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"", - "lint:hbs": "ember-template-lint .", - "lint:hbs:fix": "ember-template-lint . --fix", "lint:js": "eslint . --cache", "lint:js:fix": "eslint . --fix", "prepack": "rollup --config", @@ -31,10 +27,10 @@ "license": "MIT", "dependencies": { "@babel/core": "^7.23.9", - "@embroider/addon-shim": "^1.8.6" + "@embroider/addon-shim": "^1.8.6", + "ember-lifeline": "^7.0.0" }, "devDependencies": { - "ember-simple-auth": "~6.0.0", "@babel/core": "^7.23.2", "@babel/plugin-proposal-decorators": "^7.23.9", "@babel/plugin-transform-class-properties": "^7.22.5", @@ -44,6 +40,7 @@ "@rollup/plugin-babel": "^6.0.4", "babel-plugin-ember-template-compilation": "^2.2.1", "concurrently": "^8.2.2", + "ember-simple-auth": "~6.0.0", "ember-source": "~5.6.0", "rollup": "^4.9.6", "rollup-plugin-copy": "^3.5.0", @@ -59,8 +56,8 @@ "authorization" ], "peerDependencies": { - "ember-source": ">= 4.8.0", - "ember-simple-auth": ">= 6.0.0" + "ember-simple-auth": ">= 6.0.0", + "ember-source": ">= 4.8.0" }, "engines": { "node": ">= 18" diff --git a/ember-simple-auth-token/src/authenticators/jwt.js b/ember-simple-auth-token/src/authenticators/jwt.js index 1ebf2ad..a88348c 100644 --- a/ember-simple-auth-token/src/authenticators/jwt.js +++ b/ember-simple-auth-token/src/authenticators/jwt.js @@ -2,7 +2,7 @@ import { get } from '@ember/object'; import { getOwner } from '@ember/application'; import { Promise, resolve } from 'rsvp'; import { isEmpty } from '@ember/utils'; -import { cancel, later } from '@ember/runloop'; +import { runTask, cancelTask } from 'ember-lifeline'; import TokenAuthenticator from './token'; const decode = (str) => { @@ -168,13 +168,11 @@ export default class JwtAuthenticator extends TokenAuthenticator { if (!isEmpty(refreshToken) && !isEmpty(expiresAt)) { if (wait > 0) { - cancel(this._refreshTokenTimeout); + cancelTask(this, this._refreshTokenTimeout); delete this._refreshTokenTimeout; - this._refreshTokenTimeout = later( + this._refreshTokenTimeout = runTask( this, - this.refreshAccessToken, - refreshToken, - 0, + () => this.refreshAccessToken(refreshToken, 0), wait, ); } else if (expiresAt > now) { @@ -270,9 +268,9 @@ export default class JwtAuthenticator extends TokenAuthenticator { @return {Promise} Resolving promise */ invalidate() { - cancel(this._refreshTokenTimeout); + cancelTask(this, this._refreshTokenTimeout); delete this._refreshTokenTimeout; - cancel(this._tokenExpirationTimeout); + cancelTask(this, this._tokenExpirationTimeout); delete this._tokenExpirationTimeout; return resolve(); } @@ -343,13 +341,11 @@ export default class JwtAuthenticator extends TokenAuthenticator { this.trigger('sessionDataInvalidated'); }); } else if (attempts++ < this.refreshAccessTokenRetryAttempts) { - cancel(this._refreshTokenTimeout); + cancelTask(this, this._refreshTokenTimeout); delete this._refreshTokenTimeout; - this._refreshTokenTimeout = later( + this._refreshTokenTimeout = runTask( this, - this.refreshAccessToken, - refreshToken, - attempts, + () => this.refreshAccessToken(refreshToken, attempts), this.refreshAccessTokenRetryTimeout, ); } else if (this.tokenRefreshFailInvalidateSession) { @@ -370,11 +366,11 @@ export default class JwtAuthenticator extends TokenAuthenticator { const wait = Math.max((expiresAt - now) * 1000, 0); if (!isEmpty(expiresAt)) { - cancel(this._tokenExpirationTimeout); + cancelTask(this, this._tokenExpirationTimeout); delete this._tokenExpirationTimeout; - this._tokenExpirationTimeout = later( + this._tokenExpirationTimeout = runTask( this, - this.handleAccessTokenExpiration, + () => this.handleAccessTokenExpiration(), wait, ); } diff --git a/ember-simple-auth-token/src/authenticators/token.js b/ember-simple-auth-token/src/authenticators/token.js index 3cdca58..59316f3 100644 --- a/ember-simple-auth-token/src/authenticators/token.js +++ b/ember-simple-auth-token/src/authenticators/token.js @@ -55,10 +55,14 @@ export default class TokenAuthenticator extends Base { @return {Promise} Promise that resolves when an auth token is successfully acquired from the server and rejects otherwise */ async authenticate(credentials, headers) { - const response = await this.makeRequest(this.serverTokenEndpoint, credentials, { - ...this.headers, - ...headers, - }); + const response = await this.makeRequest( + this.serverTokenEndpoint, + credentials, + { + ...this.headers, + ...headers, + }, + ); return response.json; } diff --git a/ember-simple-auth-token/src/initializers/simple-auth-token.js b/ember-simple-auth-token/src/initializers/simple-auth-token.js index a523b11..16ab9a0 100644 --- a/ember-simple-auth-token/src/initializers/simple-auth-token.js +++ b/ember-simple-auth-token/src/initializers/simple-auth-token.js @@ -11,5 +11,5 @@ export default { initialize(container) { container.register('authenticator:token', TokenAuthenticator); container.register('authenticator:jwt', JWTAuthenticator); - } + }, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 16bd98a..adcd70f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,6 +20,9 @@ importers: '@embroider/addon-shim': specifier: ^1.8.6 version: 1.8.7 + ember-lifeline: + specifier: ^7.0.0 + version: 7.0.0 devDependencies: '@babel/plugin-proposal-decorators': specifier: ^7.23.9 @@ -47,10 +50,10 @@ importers: version: 8.2.2 ember-simple-auth: specifier: ~6.0.0 - version: 6.0.0 + version: 6.0.0(@ember/test-helpers@3.2.1) ember-source: specifier: ~5.6.0 - version: 5.6.0(@babel/core@7.23.9)(rsvp@4.8.5)(webpack@5.90.1) + version: 5.6.0(@babel/core@7.23.9)(@glimmer/component@1.1.2)(rsvp@4.8.5)(webpack@5.90.1) rollup: specifier: ^4.9.6 version: 4.9.6 @@ -171,12 +174,15 @@ importers: ember-resolver: specifier: ^11.0.1 version: 11.0.1(ember-source@5.6.0) + ember-simple-auth: + specifier: ~6.0.0 + version: 6.0.0(@ember/test-helpers@3.2.1) ember-sinon-qunit: specifier: ^7.4.0 version: 7.4.0(ember-source@5.6.0)(qunit@2.20.0)(sinon@17.0.1) ember-source: specifier: ~5.6.0 - version: 5.6.0(@babel/core@7.23.9)(rsvp@4.8.5)(webpack@5.90.1) + version: 5.6.0(@babel/core@7.23.9)(@glimmer/component@1.1.2)(rsvp@4.8.5)(webpack@5.90.1) ember-source-channel-url: specifier: ^3.0.0 version: 3.0.0 @@ -2096,7 +2102,7 @@ packages: ember-auto-import: 2.7.2(webpack@5.90.1) ember-cli-babel: 7.26.11 ember-cli-htmlbars: 6.3.0 - ember-source: 5.6.0(@babel/core@7.23.9)(rsvp@4.8.5)(webpack@5.90.1) + ember-source: 5.6.0(@babel/core@7.23.9)(@glimmer/component@1.1.2)(rsvp@4.8.5)(webpack@5.90.1) transitivePeerDependencies: - '@glint/template' - supports-color @@ -5889,7 +5895,7 @@ packages: ember-cache-primitive-polyfill: 1.0.1(@babel/core@7.23.9) ember-cli-babel: 7.26.11 ember-cli-babel-plugin-helpers: 1.1.1 - ember-source: 5.6.0(@babel/core@7.23.9)(rsvp@4.8.5)(webpack@5.90.1) + ember-source: 5.6.0(@babel/core@7.23.9)(@glimmer/component@1.1.2)(rsvp@4.8.5)(webpack@5.90.1) transitivePeerDependencies: - '@babel/core' - '@glint/template' @@ -5903,7 +5909,7 @@ packages: ember-source: ^3.28.0 || >= 4.0.0 dependencies: ember-cli-babel: 7.26.11 - ember-source: 5.6.0(@babel/core@7.23.9)(rsvp@4.8.5)(webpack@5.90.1) + ember-source: 5.6.0(@babel/core@7.23.9)(@glimmer/component@1.1.2)(rsvp@4.8.5)(webpack@5.90.1) git-repo-info: 2.1.1 transitivePeerDependencies: - supports-color @@ -6026,7 +6032,7 @@ packages: body-parser: 1.20.2 ember-auto-import: 2.7.2(webpack@5.90.1) ember-cli-babel: 7.26.11 - ember-source: 5.6.0(@babel/core@7.23.9)(rsvp@4.8.5)(webpack@5.90.1) + ember-source: 5.6.0(@babel/core@7.23.9)(@glimmer/component@1.1.2)(rsvp@4.8.5)(webpack@5.90.1) fastboot: 4.1.2 json-fn: 1.1.1 minimist: 1.2.8 @@ -6505,6 +6511,20 @@ packages: - supports-color dev: true + /ember-lifeline@7.0.0: + resolution: {integrity: sha512-2l51NzgH5vjN972zgbs+32rnXnnEFKB7qsSpJF+lBI4V5TG6DMy4SfowC72ZEuAtS58OVfwITbOO+RnM21EdpA==} + engines: {node: 16.* || >= 18} + peerDependencies: + '@ember/test-helpers': '>= 1.0.0' + peerDependenciesMeta: + '@ember/test-helpers': + optional: true + dependencies: + '@embroider/addon-shim': 1.8.7 + transitivePeerDependencies: + - supports-color + dev: false + /ember-load-initializers@2.1.2(@babel/core@7.23.9): resolution: {integrity: sha512-CYR+U/wRxLbrfYN3dh+0Tb6mFaxJKfdyz+wNql6cqTrA0BBi9k6J3AaKXj273TqvEpyyXegQFFkZEiuZdYtgJw==} engines: {node: 6.* || 8.* || >= 10.*} @@ -6524,7 +6544,7 @@ packages: dependencies: '@embroider/addon-shim': 1.8.7 '@simple-dom/document': 1.4.0 - ember-source: 5.6.0(@babel/core@7.23.9)(rsvp@4.8.5)(webpack@5.90.1) + ember-source: 5.6.0(@babel/core@7.23.9)(@glimmer/component@1.1.2)(rsvp@4.8.5)(webpack@5.90.1) transitivePeerDependencies: - supports-color dev: true @@ -6540,7 +6560,7 @@ packages: '@embroider/addon-shim': 1.8.7 '@embroider/macros': 1.13.3 ember-cli-test-loader: 3.1.0 - ember-source: 5.6.0(@babel/core@7.23.9)(rsvp@4.8.5)(webpack@5.90.1) + ember-source: 5.6.0(@babel/core@7.23.9)(@glimmer/component@1.1.2)(rsvp@4.8.5)(webpack@5.90.1) qunit: 2.20.0 transitivePeerDependencies: - '@glint/template' @@ -6557,7 +6577,7 @@ packages: optional: true dependencies: ember-cli-babel: 7.26.11 - ember-source: 5.6.0(@babel/core@7.23.9)(rsvp@4.8.5)(webpack@5.90.1) + ember-source: 5.6.0(@babel/core@7.23.9)(@glimmer/component@1.1.2)(rsvp@4.8.5)(webpack@5.90.1) transitivePeerDependencies: - supports-color dev: true @@ -6576,7 +6596,7 @@ packages: - supports-color dev: true - /ember-simple-auth@6.0.0: + /ember-simple-auth@6.0.0(@ember/test-helpers@3.2.1): resolution: {integrity: sha512-9SzSFApxZ74CD4UxIeTV+poIPeXcRLXWM60cMvC1SwTYjoc/p9DeQF0pVm6m1XV6uA3kPUzEsEn4/GeHc2YX1w==} peerDependencies: '@ember/test-helpers': '>= 3 || > 2.7' @@ -6584,6 +6604,7 @@ packages: '@ember/test-helpers': optional: true dependencies: + '@ember/test-helpers': 3.2.1(ember-source@5.6.0)(webpack@5.90.1) '@ember/test-waiters': 3.1.0 '@embroider/addon-shim': 1.8.7 '@embroider/macros': 1.13.3 @@ -6604,7 +6625,7 @@ packages: dependencies: '@embroider/addon-shim': 1.8.7 '@types/sinon': 10.0.20 - ember-source: 5.6.0(@babel/core@7.23.9)(rsvp@4.8.5)(webpack@5.90.1) + ember-source: 5.6.0(@babel/core@7.23.9)(@glimmer/component@1.1.2)(rsvp@4.8.5)(webpack@5.90.1) qunit: 2.20.0 sinon: 17.0.1 transitivePeerDependencies: @@ -6621,9 +6642,11 @@ packages: - encoding dev: true - /ember-source@5.6.0(@babel/core@7.23.9)(rsvp@4.8.5)(webpack@5.90.1): + /ember-source@5.6.0(@babel/core@7.23.9)(@glimmer/component@1.1.2)(rsvp@4.8.5)(webpack@5.90.1): resolution: {integrity: sha512-dtxi3cVPT4/+NyhA+a+4UL/i+ut4Fuu3uJAgkVqrN1XlK4TXpyVp9I6VbH7DjD5+LJdF1+UqIn8GJ50dIdoH2Q==} engines: {node: '>= 16.*'} + peerDependencies: + '@glimmer/component': ^1.1.2 dependencies: '@babel/helper-module-imports': 7.22.15 '@ember/edition-utils': 1.2.0 diff --git a/test-app/.eslintrc.js b/test-app/.eslintrc.js index 3d2a6b6..0bc81fd 100644 --- a/test-app/.eslintrc.js +++ b/test-app/.eslintrc.js @@ -35,6 +35,8 @@ module.exports = { './testem.js', './blueprints/*/index.js', './config/**/*.js', + 'playwright.config.js', + 'e2e/**/*.js', './tests/dummy/config/**/*.js', ], parserOptions: { diff --git a/test-app/app/routes/application.js b/test-app/app/routes/application.js index 6ca556f..116ec2e 100644 --- a/test-app/app/routes/application.js +++ b/test-app/app/routes/application.js @@ -1,4 +1,3 @@ -import { action } from '@ember/object'; import Route from '@ember/routing/route'; import { inject } from '@ember/service'; diff --git a/test-app/config/fastboot.js b/test-app/config/fastboot.js index 6ccb657..903113a 100644 --- a/test-app/config/fastboot.js +++ b/test-app/config/fastboot.js @@ -1,19 +1,30 @@ -module.exports = function() { +module.exports = function () { return { buildSandboxGlobals(defaultGlobals) { return Object.assign({}, defaultGlobals, { - TextEncoder: typeof TextEncoder !== 'undefined' ? TextEncoder : require('util').TextEncoder, + TextEncoder: + typeof TextEncoder !== 'undefined' + ? TextEncoder + : require('util').TextEncoder, AbortController, - navigator: { - - }, - Response: typeof Response !== 'undefined' ? Response : require('node-fetch').Response, + navigator: {}, + Response: + typeof Response !== 'undefined' + ? Response + : // eslint-disable-next-line n/no-missing-require + require('node-fetch').Response, ReadableStream: - typeof ReadableStream !== 'undefined' ? ReadableStream : require('node:stream/web').ReadableStream, + typeof ReadableStream !== 'undefined' + ? ReadableStream + : require('node:stream/web').ReadableStream, WritableStream: - typeof WritableStream !== 'undefined' ? WritableStream : require('node:stream/web').WritableStream, + typeof WritableStream !== 'undefined' + ? WritableStream + : require('node:stream/web').WritableStream, TransformStream: - typeof TransformStream !== 'undefined' ? TransformStream : require('node:stream/web').TransformStream, + typeof TransformStream !== 'undefined' + ? TransformStream + : require('node:stream/web').TransformStream, Headers: typeof Headers !== 'undefined' ? Headers : undefined, }); }, diff --git a/test-app/config/targets.js b/test-app/config/targets.js index 498e438..e5e92fa 100644 --- a/test-app/config/targets.js +++ b/test-app/config/targets.js @@ -8,5 +8,5 @@ const browsers = [ module.exports = { browsers, - node: 'current' + node: 'current', }; diff --git a/test-app/e2e/example.spec.js b/test-app/e2e/example.spec.js index 59b6a93..c8d5aca 100644 --- a/test-app/e2e/example.spec.js +++ b/test-app/e2e/example.spec.js @@ -6,5 +6,5 @@ test('Renders page in fastboot mode', async ({ page }) => { // Expect a title "to contain" a substring. await expect(page).toHaveTitle(/Dummy/); - await expect(page.locator("h2")).toHaveText("Welcome to Ember"); + await expect(page.locator('h2')).toHaveText('Welcome to Ember'); }); diff --git a/test-app/package.json b/test-app/package.json index 6fa5b99..845bee2 100644 --- a/test-app/package.json +++ b/test-app/package.json @@ -66,6 +66,7 @@ "ember-page-title": "^8.2.0", "ember-qunit": "^8.0.2", "ember-resolver": "^11.0.1", + "ember-simple-auth": "~6.0.0", "ember-sinon-qunit": "^7.4.0", "ember-source": "~5.6.0", "ember-source-channel-url": "^3.0.0", diff --git a/test-app/playwright.config.js b/test-app/playwright.config.js index 33434fa..d117d7b 100644 --- a/test-app/playwright.config.js +++ b/test-app/playwright.config.js @@ -36,7 +36,7 @@ module.exports = defineConfig({ { name: 'chromium', use: { ...devices['Desktop Chrome'] }, - } + }, /* Test against mobile viewports. */ // { @@ -66,4 +66,3 @@ module.exports = defineConfig({ reuseExistingServer: !process.env.CI, }, }); -