diff --git a/packages/ember-simple-auth/index.d.ts b/packages/ember-simple-auth/index.d.ts new file mode 100644 index 000000000..23b79745c --- /dev/null +++ b/packages/ember-simple-auth/index.d.ts @@ -0,0 +1,140 @@ +interface Callback { + (): void; +} +type Data = Record; +interface SessionData { + authenticated: T; +} + +declare module 'ember-simple-auth/services/session' { + import Evented from '@ember/object/evented'; + import Service from '@ember/service'; + import type BaseSessionStore from 'ember-simple-auth/session-stores/base'; + import type Transition from '@ember/routing/-private/transition'; + + export default class SessionService extends Service.extend(Evented) { + isAuthenticated: boolean; + data: SessionData; + store: BaseSessionStore; + attemptedTransition: Transition | null; + + authenticate(authenticator: string, ...args: unknown[]): Promise; + invalidate(...args: unknown[]): Promise; + requireAuthentication(transition: Transition, routeOrCallback: string | Callback): boolean; + prohibitAuthentication(routeOrCallback: string | Callback): boolean; + handleAuthentication(routeAfterAuthentication: string): void; + handleInvalidation(routeAfterInvalidation: string): void; + setup(): Promise; + } +} + +declare module 'ember-simple-auth/authenticators/base' { + import EmberObject from '@ember/object'; + import Evented from '@ember/object/evented'; + + export default class extends EmberObject.extend(Evented) { + restore(data: Data): Promise; + authenticate(...args: unknown[]): Promise; + invalidate(data: Data, ...args: unknown[]): Promise; + } +} + +declare module 'ember-simple-auth/session-stores/base' { + import EmberObject from '@ember/object'; + import Evented from '@ember/object/evented'; + + export default class extends EmberObject.extend(Evented) { + persist(data: SessionData): Promise; + restore(): Promise>; + clear(): Promise; + } +} + +declare module 'ember-simple-auth/session-stores/local-storage' { + import BaseSessionStore from 'ember-simple-auth/session-stores/base'; + + export default class extends BaseSessionStore { + key: string; + } +} + +declare module 'ember-simple-auth/session-stores/cookie' { + import BaseSessionStore from 'ember-simple-auth/session-stores/base'; + + export default class extends BaseSessionStore { + cookieDomain: string; + cookieExpirationTime: null | number; + cookieName: string; + cookiePath: string; + sameSite: null | 'Strict' | 'Lax'; + } +} + +declare module 'ember-simple-auth/session-stores/adaptive' { + import CookieSessionStore from 'ember-simple-auth/session-stores/base'; + + export default class extends CookieSessionStore { + localStorageKey: string; + } +} + +declare module 'ember-simple-auth/session-stores/ephemeral' { + import BaseSessionStore from 'ember-simple-auth/session-stores/base'; + + export default class extends BaseSessionStore { } +} + +declare module 'ember-simple-auth/session-stores/session-storage' { + import BaseSessionStore from 'ember-simple-auth/session-stores/base'; + + export default class extends BaseSessionStore { + key: string; + } +} + +declare module 'ember-simple-auth/authenticators/test' { + import BaseAuthenticator from 'ember-simple-auth/authenticators/base'; + + export default class extends BaseAuthenticator { } +} + +declare module 'ember-simple-auth/authenticators/devise' { + import BaseAuthenticator from 'ember-simple-auth/authenticators/base'; + + export default class extends BaseAuthenticator { + serverTokenEndpoint: string; + resourceName: string; + tokenAttributeName: string; + identificationAttributeName: string; + } +} + +declare module 'ember-simple-auth/authenticators/oauth2-implicit-grant' { + import BaseAuthenticator from 'ember-simple-auth/authenticators/base'; + + export default class extends BaseAuthenticator { } +} + +declare module 'ember-simple-auth/authenticators/oauth2-password-grant' { + import BaseAuthenticator from 'ember-simple-auth/authenticators/base'; + + export default class extends BaseAuthenticator { + clientId: string | null; + serverTokenEndpoint: string; + serverTokenRevocationEndpoint: string | null; + refreshAccessTokens: boolean; + } +} + +declare module 'ember-simple-auth/authenticators/torii' { + import BaseAuthenticator from 'ember-simple-auth/authenticators/base'; + + export default class extends BaseAuthenticator { } +} + +declare module 'ember-simple-auth/test-support' { + import SimpleAuthSessionService from 'ember-simple-auth/services/session'; + export function currentSession(): SimpleAuthSessionService; + export function authenticateSession(sessionData: Data): Promise; + export function invalidateSession(): Promise; +} diff --git a/packages/ember-simple-auth/package.json b/packages/ember-simple-auth/package.json index b83ac9beb..e0ba8350f 100644 --- a/packages/ember-simple-auth/package.json +++ b/packages/ember-simple-auth/package.json @@ -12,6 +12,7 @@ "doc": "doc", "test": "tests" }, + "types": "./index.d.ts", "scripts": { "build": "ember build", "lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"", @@ -36,6 +37,7 @@ "@embroider/test-setup": "^2.0.0", "@glimmer/component": "^1.0.0", "@glimmer/tracking": "^1.0.0", + "@types/ember": "4.0.3", "babel-eslint": "^10.1.0", "broccoli-asset-rev": "^3.0.0", "ember-auto-import": "^2.4.2",