@atlasauth/angular 0.2.1 → 0.4.0

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.
@@ -9,8 +9,13 @@ export interface AtlasOptions {
9
9
  /** The instance's publishable key (`pk_…`). Required. */
10
10
  publishableKey: string;
11
11
  /**
12
- * The instance's FAPI origin. Empty string (the default) means same-origin —
13
- * requests go to `/v1/...` on the app's own host.
12
+ * The instance's Frontend API: an absolute URL such as
13
+ * `"https://auth.example.com"`, or `"same-origin"` / a path such as `"/atlas"`
14
+ * behind a reverse proxy on the app's own origin (requests then go to
15
+ * `/v1/...` on the app's host). Required at runtime — `AtlasService` throws an
16
+ * `AtlasConfigError` (`FRONTEND_API_REQUIRED` / `FRONTEND_API_INVALID`) when
17
+ * it is missing or malformed. Optional in the type only so existing call sites
18
+ * keep compiling.
14
19
  */
15
20
  frontendApi?: string;
16
21
  /** Design tokens + per-element class overrides. See {@link Appearance}. */
@@ -1,6 +1,6 @@
1
1
  import { OnDestroy, Signal } from '@angular/core';
2
2
  import { Observable } from 'rxjs';
3
- import { FapiClient, type ProviderToken, type SignOutOptions } from '@atlasauth/js';
3
+ import { FapiClient, type ProviderToken, type SignOutOptions, type SignOutResult } from '@atlasauth/js';
4
4
  import { type ProtectCondition } from '@atlasauth/authz';
5
5
  import { type Appearance, type AppearanceRender, type InstanceDesign } from './appearance';
6
6
  import { type Catalog } from './i18n';
@@ -34,6 +34,14 @@ export declare class AtlasService implements OnDestroy {
34
34
  private readonly cache;
35
35
  private readonly fapiClient;
36
36
  private refreshTimer;
37
+ /**
38
+ * The sessions this browser signed out of (tombstones in localStorage, per
39
+ * Frontend API origin), the revoke and its background re-tries. Every reload /
40
+ * refresh asks it before adopting a session, so a sign-out the server never
41
+ * confirmed is not undone by the still-valid refresh cookie.
42
+ */
43
+ private readonly guard;
44
+ private stopWatchingSignOut;
37
45
  private readonly catalog;
38
46
  /**
39
47
  * A sign-in attempt handed back by an OAuth redirect that still needs a second
@@ -110,8 +118,19 @@ export declare class AtlasService implements OnDestroy {
110
118
  getProviderToken(provider: string): Promise<ProviderToken | null>;
111
119
  /** Imperative `has()` — the same evaluation `*atlasProtect` renders on. */
112
120
  has(condition: ProtectCondition): boolean;
113
- /** Revoke the current session server-side and drop all local auth state. */
114
- signOut(options?: SignOutOptions): Promise<void>;
121
+ /**
122
+ * Revoke the current session server-side and drop all local auth state.
123
+ *
124
+ * The session id is remembered before the revoke (a tombstone shared by every
125
+ * tab), so a reload, a token refresh, a sibling tab or a tab opened later never
126
+ * re-adopts it — even when the revoke failed (it is retried once, then again in
127
+ * the background) and the refresh cookie is still valid. Resolves
128
+ * `{ revoked, activeSessionId? }`; with `{ strict: true }` an unconfirmed revoke
129
+ * rejects with a `SignOutError` instead (after the local sign-out). A parked
130
+ * session the server promoted on revoke is adopted. Front-channel logout runs
131
+ * unless `{ frontchannel: false }`.
132
+ */
133
+ signOut(options?: SignOutOptions): Promise<SignOutResult>;
115
134
  /**
116
135
  * Switch the active organization (or `null` for the personal account). The
117
136
  * new token carries the new org claims, so the app's permission checks update
@@ -132,6 +151,7 @@ export declare class AtlasService implements OnDestroy {
132
151
  private call;
133
152
  private applyToken;
134
153
  private refresh;
154
+ private clearLocalState;
135
155
  /** §7.4: proactive, jittered refresh scheduled from the token's own expiry. */
136
156
  private scheduleRefresh;
137
157
  private clearRefreshTimer;
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from '@angular/core';
2
- import { type AttemptView, type FieldError } from '@atlasauth/js';
2
+ import { type AttemptView, type CaptchaController, type FieldError } from '@atlasauth/js';
3
3
  import { type ElementKey } from '../appearance';
4
4
  import * as i0 from "@angular/core";
5
5
  /**
@@ -30,8 +30,24 @@ export declare class AttemptFlowComponent {
30
30
  busy: boolean;
31
31
  errors: FieldError[];
32
32
  titleKey: string;
33
+ /**
34
+ * The sign-in captcha, drawn above the submit button on the identifier step
35
+ * (an always-on sign-in captcha) and on the challenge step the server demands
36
+ * with `needs_captcha`. Null when the flow draws none.
37
+ */
38
+ captcha: CaptchaController | null;
39
+ /**
40
+ * The first factors to offer on the `needs_first_factor` step — pass
41
+ * `AtlasFlowController.firstFactors()`, which drops email code / link while the
42
+ * app cannot deliver email. Null uses the server's list as-is.
43
+ */
44
+ firstFactors: string[] | null;
45
+ /** The first factor already sent (`AtlasFlowController.preparedFactor()`): its code is collected. */
46
+ preparedFactor: string | null;
33
47
  /** Emits the collected field values when the form is submitted. */
34
48
  submitFlow: EventEmitter<Record<string, string>>;
49
+ /** Emits when the user picks a first factor the server must send first (an emailed code). */
50
+ chooseFactor: EventEmitter<"email_code">;
35
51
  protected values: Record<string, string>;
36
52
  protected t(key: string, vars?: Record<string, string>): string;
37
53
  protected cls(key: ElementKey, base: string): string;
@@ -40,9 +56,13 @@ export declare class AttemptFlowComponent {
40
56
  protected formErrors(): FieldError[];
41
57
  protected fieldErrorsFor(name: string): FieldError[];
42
58
  private step;
59
+ protected showCaptcha(): boolean;
60
+ /** The first factors on offer at a `needs_first_factor` step (empty on any other). */
61
+ private offered;
62
+ protected showEmailCodeOption(): boolean;
43
63
  protected showSubmit(): boolean;
44
64
  protected fields(): StepField[];
45
65
  static ɵfac: i0.ɵɵFactoryDeclaration<AttemptFlowComponent, never>;
46
- static ɵcmp: i0.ɵɵComponentDeclaration<AttemptFlowComponent, "atlas-attempt-flow", never, { "attempt": { "alias": "attempt"; "required": false; }; "busy": { "alias": "busy"; "required": false; }; "errors": { "alias": "errors"; "required": false; }; "titleKey": { "alias": "titleKey"; "required": false; }; }, { "submitFlow": "submitFlow"; }, never, never, true, never>;
66
+ static ɵcmp: i0.ɵɵComponentDeclaration<AttemptFlowComponent, "atlas-attempt-flow", never, { "attempt": { "alias": "attempt"; "required": false; }; "busy": { "alias": "busy"; "required": false; }; "errors": { "alias": "errors"; "required": false; }; "titleKey": { "alias": "titleKey"; "required": false; }; "captcha": { "alias": "captcha"; "required": false; }; "firstFactors": { "alias": "firstFactors"; "required": false; }; "preparedFactor": { "alias": "preparedFactor"; "required": false; }; }, { "submitFlow": "submitFlow"; "chooseFactor": "chooseFactor"; }, never, never, true, never>;
47
67
  }
48
68
  export {};
@@ -1,5 +1,5 @@
1
1
  import { WritableSignal } from '@angular/core';
2
- import { FapiClient, type FlowState } from '@atlasauth/js';
2
+ import { FapiClient, type CaptchaController, type FlowState, type InstanceSettings } from '@atlasauth/js';
3
3
  /**
4
4
  * The server-driven sign-in / sign-up engine, shared by `<atlas-sign-in>` and
5
5
  * `<atlas-sign-up>` — the Angular counterpart of React's `useFlow` hook.
@@ -8,16 +8,71 @@ import { FapiClient, type FlowState } from '@atlasauth/js';
8
8
  * server via `advance`, and this controller only posts whatever the current step
9
9
  * needs and re-renders the returned status. State lives in a signal so templates
10
10
  * update whether the app runs zoned or zoneless.
11
+ *
12
+ * `<atlas-sign-up>` starts the attempt with {@link create}
13
+ * (`POST /v1/client/sign_ups`); the emailed-code step then runs through the same
14
+ * {@link submit}. Both flows draw the instance's captcha (from
15
+ * {@link loadSettings}) when it is required.
11
16
  */
12
17
  export declare class AtlasFlowController {
13
18
  private readonly client;
14
19
  private readonly reload;
20
+ /** Resolves the captcha messages' catalog keys. Defaults to en-US. */
21
+ private readonly t;
15
22
  readonly state: WritableSignal<FlowState>;
23
+ /**
24
+ * The instance's public sign-in / sign-up settings (captcha, sign-up fields,
25
+ * legal consent) from `GET /v1/appearance`; null until {@link loadSettings}
26
+ * resolves, or when the server could not be reached.
27
+ */
28
+ readonly settings: WritableSignal<InstanceSettings>;
29
+ /** The sign-in captcha (identifier step / `needs_captcha` challenge). */
30
+ readonly captcha: CaptchaController;
31
+ /** The sign-up captcha (the create-account step). */
32
+ readonly signUpCaptcha: CaptchaController;
33
+ /** Whether {@link captcha} currently draws a widget (for templates). */
34
+ readonly captchaDrawn: WritableSignal<boolean>;
35
+ /** Whether {@link signUpCaptcha} currently draws a widget (for templates). */
36
+ readonly signUpCaptchaDrawn: WritableSignal<boolean>;
37
+ /**
38
+ * The first factor the server was asked to send ({@link prepare}) on the
39
+ * current `needs_first_factor` step — the form then collects its code. Null
40
+ * otherwise.
41
+ */
42
+ readonly preparedFactor: WritableSignal<"email_code">;
16
43
  private pollTimer;
44
+ private identifier;
17
45
  constructor(client: FapiClient, reload: () => Promise<void>, pending: {
18
46
  id: string;
19
47
  status: string;
20
- } | null);
48
+ } | null,
49
+ /** Resolves the captcha messages' catalog keys. Defaults to en-US. */
50
+ t?: (key: string) => string);
51
+ /** Fetch the instance's public settings and draw whatever captcha they require. */
52
+ loadSettings(): Promise<void>;
53
+ /**
54
+ * The first factors to offer on a `needs_first_factor` step: the server's list
55
+ * without email code / link while the app cannot deliver email
56
+ * (`settings.emailDelivery.available === false`). Empty on any other step.
57
+ */
58
+ firstFactors(): string[];
59
+ /**
60
+ * True when email + password sign-up cannot complete because the app cannot
61
+ * send the verification email (`settings.emailDelivery.passwordSignUp === false`):
62
+ * `<atlas-sign-up>` shows the "can't send email" notice instead of the form.
63
+ */
64
+ signUpEmailUnavailable(): boolean;
65
+ /** False when a password reset email cannot be delivered — hide "Forgot password?". */
66
+ passwordResetAvailable(): boolean;
67
+ /**
68
+ * Ask the server to email a sign-in code for the current `needs_first_factor`
69
+ * step (`POST …/prepare_first_factor`); the form then collects the code, which
70
+ * {@link submit} posts as the `email_code` strategy.
71
+ */
72
+ prepare(strategy: 'email_code'): Promise<void>;
73
+ /** Keep both captchas in step with the settings and the flow's current step. */
74
+ private syncCaptcha;
75
+ private setState;
21
76
  /**
22
77
  * Advance the flow with the values the user typed. On completion, exchange the
23
78
  * one-time ticket for cookies over a same-origin request (FAPI is cross-origin
@@ -25,10 +80,18 @@ export declare class AtlasFlowController {
25
80
  * the app sees a signed-in user.
26
81
  */
27
82
  submit(values: Record<string, string>): Promise<void>;
83
+ /**
84
+ * Create an account (`POST /v1/client/sign_ups`) from a create-account form's
85
+ * values — email, password and any configured sign-up fields — carrying the
86
+ * sign-up captcha's token when the instance requires one. The emailed code is
87
+ * then posted with {@link submit}.
88
+ */
89
+ create(values: Record<string, string>, consent?: boolean): Promise<void>;
90
+ private finish;
28
91
  /** Start/stop the §5.3 magic-link poll to match the current state. */
29
92
  syncPolling(): void;
30
93
  private startPolling;
31
94
  private stopPolling;
32
- /** Release the poll timer — call from the component's `ngOnDestroy`. */
95
+ /** Release the poll timer and the captcha widgets — call from the component's `ngOnDestroy`. */
33
96
  destroy(): void;
34
97
  }
@@ -3,7 +3,9 @@ import { AtlasFlowController } from './flow-controller';
3
3
  import * as i0 from "@angular/core";
4
4
  /**
5
5
  * `<atlas-sign-in>` — the full, multi-step sign-in flow driven entirely by the
6
- * server-side attempt status. The Angular peer of React's `<SignIn/>`.
6
+ * server-side attempt status. The Angular peer of React's `<SignIn/>`. Draws the
7
+ * instance's sign-in captcha when it is required (always-on, or a
8
+ * `needs_captcha` challenge).
7
9
  *
8
10
  * ```html
9
11
  * <atlas-sign-in *atlasSignedOut afterUrl="/dashboard"></atlas-sign-in>
@@ -0,0 +1,47 @@
1
+ import { EventEmitter } from '@angular/core';
2
+ import type { CaptchaController, FieldError, InstanceSettings, PublicSignUpField } from '@atlasauth/js';
3
+ import { type ElementKey } from '../appearance';
4
+ import * as i0 from "@angular/core";
5
+ /** What the create-account form emits: the values typed plus the consent tick. */
6
+ export interface SignUpFormSubmit {
7
+ values: Record<string, string>;
8
+ consent: boolean;
9
+ }
10
+ /**
11
+ * The create-account step of `<atlas-sign-up>`: the instance's configured extra
12
+ * fields, email + password, the legal-consent row and — when the instance
13
+ * requires one on sign-up — the captcha widget. Values live on the component so
14
+ * a refused submit never clears them. When the app cannot send the verification
15
+ * email (`settings.emailDelivery.passwordSignUp === false`) it shows the
16
+ * `signUp.emailUnavailable` notice instead of the form.
17
+ */
18
+ export declare class SignUpFormComponent {
19
+ private readonly atlas;
20
+ settings: InstanceSettings | null;
21
+ busy: boolean;
22
+ errors: FieldError[];
23
+ captcha: CaptchaController | null;
24
+ /** Emits the typed values and the consent tick when the form is submitted. */
25
+ submitSignUp: EventEmitter<SignUpFormSubmit>;
26
+ protected values: Record<string, string>;
27
+ protected agreed: boolean;
28
+ protected t(key: string, vars?: Record<string, string>): string;
29
+ protected cls(key: ElementKey, base: string): string;
30
+ protected setValue(name: string, value: string): void;
31
+ /** Email + password sign-up cannot complete: the app cannot send the verification email. */
32
+ protected emailUnavailable(): boolean;
33
+ protected fields(): PublicSignUpField[];
34
+ protected label(f: PublicSignUpField): string;
35
+ protected inputType(f: PublicSignUpField): string;
36
+ /** Same encoding as React, the embed widget and the hosted page: one value,
37
+ * or a comma-joined list for multiselect. */
38
+ protected picked(key: string): string[];
39
+ protected toggle(f: PublicSignUpField, option: string, on: boolean): void;
40
+ protected showLegal(): boolean;
41
+ protected consentOk(): boolean;
42
+ protected formErrors(): FieldError[];
43
+ protected fieldErrorsFor(name: string): FieldError[];
44
+ protected onSubmit(event: Event): void;
45
+ static ɵfac: i0.ɵɵFactoryDeclaration<SignUpFormComponent, never>;
46
+ static ɵcmp: i0.ɵɵComponentDeclaration<SignUpFormComponent, "atlas-sign-up-form", never, { "settings": { "alias": "settings"; "required": false; }; "busy": { "alias": "busy"; "required": false; }; "errors": { "alias": "errors"; "required": false; }; "captcha": { "alias": "captcha"; "required": false; }; }, { "submitSignUp": "submitSignUp"; }, never, never, true, never>;
47
+ }
@@ -1,20 +1,24 @@
1
- import { OnDestroy } from '@angular/core';
1
+ import { OnDestroy, OnInit } from '@angular/core';
2
2
  import { AtlasFlowController } from './flow-controller';
3
3
  import * as i0 from "@angular/core";
4
4
  /**
5
- * `<atlas-sign-up>` — the full, server-driven sign-up flow. The Angular peer of
6
- * React's `<SignUp/>`. It shares the exact flow engine with `<atlas-sign-in>`;
7
- * only the title differs, because the sequence of steps is decided by the server.
5
+ * `<atlas-sign-up>` — creates an account. The Angular peer of React's
6
+ * `<SignUp/>`. The first step is the create-account form (the instance's
7
+ * configured fields, email, password, legal consent and — when required — the
8
+ * captcha), which POSTs `/v1/client/sign_ups`; from there it shares the flow
9
+ * engine with `<atlas-sign-in>` (the emailed-code step, then the ticket
10
+ * exchange), because the sequence of steps is decided by the server.
8
11
  *
9
12
  * ```html
10
13
  * <atlas-sign-up *atlasSignedOut></atlas-sign-up>
11
14
  * ```
12
15
  */
13
- export declare class SignUpComponent implements OnDestroy {
16
+ export declare class SignUpComponent implements OnInit, OnDestroy {
14
17
  private readonly atlas;
15
18
  /** Where to send the user once the flow completes. Reserved for host routing. */
16
19
  afterUrl?: string;
17
20
  protected readonly flow: AtlasFlowController;
21
+ ngOnInit(): void;
18
22
  ngOnDestroy(): void;
19
23
  static ɵfac: i0.ɵɵFactoryDeclaration<SignUpComponent, never>;
20
24
  static ɵcmp: i0.ɵɵComponentDeclaration<SignUpComponent, "atlas-sign-up", never, { "afterUrl": { "alias": "afterUrl"; "required": false; }; }, {}, never, never, true, never>;
@@ -0,0 +1,19 @@
1
+ import { OnDestroy, OnInit } from '@angular/core';
2
+ import type { CaptchaController } from '@atlasauth/js';
3
+ import * as i0 from "@angular/core";
4
+ /**
5
+ * `[atlasCaptchaSlot]="controller"` — the element a flow's captcha widget draws
6
+ * into (see `createCaptchaController` in `@atlasauth/js`). Attaches the
7
+ * controller to the host element while it is rendered and detaches it (removing
8
+ * the widget) when it goes away.
9
+ */
10
+ export declare class AtlasCaptchaSlotDirective implements OnInit, OnDestroy {
11
+ private readonly host;
12
+ private current;
13
+ private initialized;
14
+ set controller(next: CaptchaController | null);
15
+ ngOnInit(): void;
16
+ ngOnDestroy(): void;
17
+ static ɵfac: i0.ɵɵFactoryDeclaration<AtlasCaptchaSlotDirective, never>;
18
+ static ɵdir: i0.ɵɵDirectiveDeclaration<AtlasCaptchaSlotDirective, "[atlasCaptchaSlot]", never, { "controller": { "alias": "atlasCaptchaSlot"; "required": false; }; }, {}, never, never, true, never>;
19
+ }
@@ -18,6 +18,8 @@ export { OrganizationSwitcherComponent } from './lib/components/organization-swi
18
18
  export { UserProfileComponent } from './lib/components/user-profile.component';
19
19
  export { OrganizationProfileComponent } from './lib/components/organization-profile.component';
20
20
  export { AttemptFlowComponent } from './lib/components/attempt-flow.component';
21
+ export { SignUpFormComponent, type SignUpFormSubmit, } from './lib/components/sign-up-form.component';
22
+ export { AtlasCaptchaSlotDirective } from './lib/directives/captcha-slot.directive';
21
23
  export { AtlasFlowController } from './lib/components/flow-controller';
22
24
  export { ATLAS_UI } from './lib/atlas.ui';
23
25
  export { atlasGuard, atlasChildGuard, type AtlasGuardOptions, } from './lib/guards/atlas.guard';
@@ -26,3 +28,5 @@ export * from './lib/i18n';
26
28
  export * from './lib/protect';
27
29
  export * from './lib/types';
28
30
  export * from './lib/fapi';
31
+ export type { InstanceSettings, PublicSignUpField, CaptchaController, CaptchaFlowKey, CaptchaWidgetMode, FlowCaptcha, EmailDelivery, SignOutOptions, SignOutResult, } from '@atlasauth/js';
32
+ export { SignOutError } from '@atlasauth/js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlasauth/angular",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "Official Angular SDK for Atlas — the Angular peer of @atlasauth/react.",
5
5
  "license": "MIT",
6
6
  "module": "./dist/fesm2022/atlas-angular.mjs",
@@ -19,8 +19,8 @@
19
19
  "sideEffects": false,
20
20
  "dependencies": {
21
21
  "tslib": "^2.6.3",
22
- "@atlasauth/design": "0.1.0",
23
- "@atlasauth/js": "0.5.0",
22
+ "@atlasauth/design": "0.2.0",
23
+ "@atlasauth/js": "0.8.0",
24
24
  "@atlasauth/authz": "0.1.1"
25
25
  },
26
26
  "peerDependencies": {
@@ -50,7 +50,8 @@
50
50
  },
51
51
  "files": [
52
52
  "dist",
53
- "README.md"
53
+ "README.md",
54
+ "CHANGELOG.md"
54
55
  ],
55
56
  "repository": {
56
57
  "type": "git",
@@ -63,6 +64,7 @@
63
64
  },
64
65
  "scripts": {
65
66
  "build": "ng-packagr -p ng-package.json",
66
- "typecheck": "tsc -p tsconfig.json --noEmit"
67
+ "typecheck": "tsc -p tsconfig.json --noEmit",
68
+ "test": "vitest run"
67
69
  }
68
70
  }