@forgerock/login-widget 1.0.0-beta.5 → 1.0.0-beta.7

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.
@@ -1,13 +1,3 @@
1
- interface StringDict<T> {
2
- [name: string]: T;
3
- }
4
- interface Tokens {
5
- accessToken: string;
6
- idToken?: string;
7
- refreshToken?: string;
8
- tokenExpiry?: number;
9
- }
10
-
11
1
  declare enum ActionTypes {
12
2
  Authenticate = "AUTHENTICATE",
13
3
  Authorize = "AUTHORIZE",
@@ -21,6 +11,16 @@ declare enum ActionTypes {
21
11
  UserInfo = "USER_INFO"
22
12
  }
23
13
 
14
+ interface StringDict<T> {
15
+ [name: string]: T;
16
+ }
17
+ interface Tokens {
18
+ accessToken: string;
19
+ idToken?: string;
20
+ refreshToken?: string;
21
+ tokenExpiry?: number;
22
+ }
23
+
24
24
  /**
25
25
  * Types of callbacks directly supported by the SDK.
26
26
  */
@@ -225,19 +225,44 @@ interface TokenStoreObject {
225
225
  }
226
226
 
227
227
  /**
228
- * Tokens returned after successful authentication.
228
+ * An event-handling function.
229
229
  */
230
- interface OAuth2Tokens {
231
- accessToken: string;
232
- idToken?: string;
233
- refreshToken?: string;
234
- tokenExpiry?: number;
230
+ declare type Listener = (e: FREvent) => void;
231
+ interface FREvent {
232
+ type: string;
235
233
  }
236
234
 
237
- interface GetTokensOptions extends ConfigOptions {
238
- forceRenew?: boolean;
239
- login?: 'embedded' | 'redirect' | undefined;
240
- query?: StringDict<string>;
235
+ /**
236
+ * Event dispatcher for subscribing and publishing categorized events.
237
+ */
238
+ declare class Dispatcher {
239
+ private callbacks;
240
+ /**
241
+ * Subscribes to an event type.
242
+ *
243
+ * @param type The event type
244
+ * @param listener The function to subscribe to events of this type
245
+ */
246
+ addEventListener(type: string, listener: Listener): void;
247
+ /**
248
+ * Unsubscribes from an event type.
249
+ *
250
+ * @param type The event type
251
+ * @param listener The function to unsubscribe from events of this type
252
+ */
253
+ removeEventListener(type: string, listener: Listener): void;
254
+ /**
255
+ * Unsubscribes all listener functions to a single event type or all event types.
256
+ *
257
+ * @param type The event type, or all event types if not specified
258
+ */
259
+ clearEventListeners(type?: string): void;
260
+ /**
261
+ * Publishes an event.
262
+ *
263
+ * @param event The event object to publish
264
+ */
265
+ dispatchEvent<T extends FREvent>(event: T): void;
241
266
  }
242
267
 
243
268
  /**
@@ -336,70 +361,38 @@ interface HttpClientRequestOptions {
336
361
  */
337
362
  declare type RequiresNewTokenFn = (res: Response) => boolean;
338
363
 
339
- interface MessageCreator {
340
- [key: string]: (propertyName: string, params?: {
341
- [key: string]: unknown;
342
- }) => string;
343
- }
344
- interface ProcessedPropertyError {
345
- detail: FailedPolicyRequirement;
346
- messages: string[];
347
- }
348
-
349
- declare class FRLoginFailure implements AuthResponse {
350
- payload: Step;
351
- /**
352
- * The type of step.
353
- */
354
- readonly type = StepType.LoginFailure;
355
- /**
356
- * @param payload The raw payload returned by OpenAM
357
- */
358
- constructor(payload: Step);
359
- /**
360
- * Gets the error code.
361
- */
362
- getCode(): number;
363
- /**
364
- * Gets the failure details.
365
- */
366
- getDetail(): FailureDetail | undefined;
367
- /**
368
- * Gets the failure message.
369
- */
370
- getMessage(): string | undefined;
371
- /**
372
- * Gets processed failure message.
373
- */
374
- getProcessedMessage(messageCreator?: MessageCreator): ProcessedPropertyError[];
375
- /**
376
- * Gets the failure reason.
377
- */
378
- getReason(): string | undefined;
379
- }
380
-
381
- declare class FRLoginSuccess implements AuthResponse {
382
- payload: Step;
383
- /**
384
- * The type of step.
385
- */
386
- readonly type = StepType.LoginSuccess;
387
- /**
388
- * @param payload The raw payload returned by OpenAM
389
- */
390
- constructor(payload: Step);
391
- /**
392
- * Gets the step's realm.
393
- */
394
- getRealm(): string | undefined;
395
- /**
396
- * Gets the step's session token.
397
- */
398
- getSessionToken(): string | undefined;
364
+ /**
365
+ * HTTP client that includes bearer token injection and refresh.
366
+ * This module also supports authorization for policy protected endpoints.
367
+ *
368
+ * Example:
369
+ *
370
+ * ```js
371
+ * return forgerock.HttpClient.request({
372
+ * url: `https://example.com/protected/resource`,
373
+ * init: {
374
+ * method: 'GET',
375
+ * credentials: 'include',
376
+ * },
377
+ * authorization: {
378
+ * handleStep: async (step) => {
379
+ * step.getCallbackOfType('PasswordCallback').setPassword(pw);
380
+ * return Promise.resolve(step);
381
+ * },
382
+ * },
383
+ * });
384
+ * ```
385
+ */
386
+ declare abstract class HttpClient extends Dispatcher {
399
387
  /**
400
- * Gets the step's success URL.
388
+ * Makes a request using the specified options.
389
+ *
390
+ * @param options The options to use when making the request
401
391
  */
402
- getSuccessUrl(): string | undefined;
392
+ static request(options: HttpClientRequestOptions): Promise<Response>;
393
+ private static setAuthHeaders;
394
+ private static stepIterator;
395
+ private static _request;
403
396
  }
404
397
 
405
398
  declare function noop(): void;
@@ -559,8 +552,151 @@ declare class SvelteComponentTyped<Props extends Record<string, any> = any, Even
559
552
  constructor(options: ComponentConstructorOptions<Props>);
560
553
  }
561
554
 
555
+ /** Callback to inform of a value updates. */
556
+ declare type Subscriber<T> = (value: T) => void;
557
+ /** Unsubscribes from value updates. */
558
+ declare type Unsubscriber = () => void;
559
+ /** Callback to update a value. */
560
+ declare type Updater<T> = (value: T) => T;
561
+ /** Cleanup logic callback. */
562
+ declare type Invalidator<T> = (value?: T) => void;
563
+ /** Readable interface for subscribing. */
564
+ interface Readable<T> {
565
+ /**
566
+ * Subscribe on value changes.
567
+ * @param run subscription callback
568
+ * @param invalidate cleanup callback
569
+ */
570
+ subscribe(this: void, run: Subscriber<T>, invalidate?: Invalidator<T>): Unsubscriber;
571
+ }
572
+ /** Writable interface for both updating and subscribing. */
573
+ interface Writable<T> extends Readable<T> {
574
+ /**
575
+ * Set value and inform subscribers.
576
+ * @param value to set
577
+ */
578
+ set(this: void, value: T): void;
579
+ /**
580
+ * Update value using callback and inform subscribers.
581
+ * @param updater callback
582
+ */
583
+ update(this: void, updater: Updater<T>): void;
584
+ }
585
+
586
+ interface MessageCreator {
587
+ [key: string]: (propertyName: string, params?: {
588
+ [key: string]: unknown;
589
+ }) => string;
590
+ }
591
+ interface ProcessedPropertyError {
592
+ detail: FailedPolicyRequirement;
593
+ messages: string[];
594
+ }
595
+
596
+ declare class FRLoginFailure implements AuthResponse {
597
+ payload: Step;
598
+ /**
599
+ * The type of step.
600
+ */
601
+ readonly type = StepType.LoginFailure;
602
+ /**
603
+ * @param payload The raw payload returned by OpenAM
604
+ */
605
+ constructor(payload: Step);
606
+ /**
607
+ * Gets the error code.
608
+ */
609
+ getCode(): number;
610
+ /**
611
+ * Gets the failure details.
612
+ */
613
+ getDetail(): FailureDetail | undefined;
614
+ /**
615
+ * Gets the failure message.
616
+ */
617
+ getMessage(): string | undefined;
618
+ /**
619
+ * Gets processed failure message.
620
+ */
621
+ getProcessedMessage(messageCreator?: MessageCreator): ProcessedPropertyError[];
622
+ /**
623
+ * Gets the failure reason.
624
+ */
625
+ getReason(): string | undefined;
626
+ }
627
+
628
+ declare class FRLoginSuccess implements AuthResponse {
629
+ payload: Step;
630
+ /**
631
+ * The type of step.
632
+ */
633
+ readonly type = StepType.LoginSuccess;
634
+ /**
635
+ * @param payload The raw payload returned by OpenAM
636
+ */
637
+ constructor(payload: Step);
638
+ /**
639
+ * Gets the step's realm.
640
+ */
641
+ getRealm(): string | undefined;
642
+ /**
643
+ * Gets the step's session token.
644
+ */
645
+ getSessionToken(): string | undefined;
646
+ /**
647
+ * Gets the step's success URL.
648
+ */
649
+ getSuccessUrl(): string | undefined;
650
+ }
651
+
652
+ /**
653
+ * Tokens returned after successful authentication.
654
+ */
655
+ interface OAuth2Tokens {
656
+ accessToken: string;
657
+ idToken?: string;
658
+ refreshToken?: string;
659
+ tokenExpiry?: number;
660
+ }
661
+
662
+ interface GetTokensOptions extends ConfigOptions {
663
+ forceRenew?: boolean;
664
+ login?: 'embedded' | 'redirect' | undefined;
665
+ query?: StringDict<string>;
666
+ }
667
+
562
668
  type Maybe<T> = T | null | undefined;
563
669
 
670
+ interface UserStore extends Pick<Writable<UserStoreValue>, 'subscribe'> {
671
+ get: (getOptions?: ConfigOptions) => void;
672
+ reset: () => void;
673
+ }
674
+ interface UserStoreValue {
675
+ completed: boolean;
676
+ error: Maybe<{
677
+ code?: Maybe<number>;
678
+ message: Maybe<string>;
679
+ }>;
680
+ loading: boolean;
681
+ successful: boolean;
682
+ response: unknown;
683
+ }
684
+
685
+ interface OAuthStore extends Pick<Writable<OAuthTokenStoreValue>, 'subscribe'> {
686
+ get: (getOptions?: GetTokensOptions) => void;
687
+ reset: () => void;
688
+ }
689
+ interface OAuthTokenStoreValue {
690
+ completed: boolean;
691
+ error: Maybe<{
692
+ code?: Maybe<number>;
693
+ message: Maybe<string>;
694
+ }>;
695
+ loading: boolean;
696
+ successful: boolean;
697
+ response: Maybe<OAuth2Tokens> | void;
698
+ }
699
+
564
700
  interface CallbackMetadata {
565
701
  derived: {
566
702
  canForceUserInputOptionality: boolean;
@@ -572,6 +708,14 @@ interface CallbackMetadata {
572
708
  idx: number;
573
709
  platform?: Record<string, unknown>;
574
710
  }
711
+ interface JourneyStore extends Pick<Writable<JourneyStoreValue>, 'subscribe'> {
712
+ next: (prevStep?: StepTypes, nextOptions?: StepOptions) => void;
713
+ pop: () => void;
714
+ push: (changeOptions: StepOptions) => void;
715
+ reset: () => void;
716
+ resume: (url: string, resumeOptions?: StepOptions) => void;
717
+ start: (startOptions?: StepOptions) => void;
718
+ }
575
719
  interface JourneyStoreValue {
576
720
  completed: boolean;
577
721
  error: Maybe<{
@@ -600,42 +744,6 @@ interface StepMetadata {
600
744
  }
601
745
  type StepTypes = FRStep | FRLoginSuccess | FRLoginFailure | null;
602
746
 
603
- interface OAuthTokenStoreValue {
604
- completed: boolean;
605
- error: Maybe<{
606
- code?: Maybe<number>;
607
- message: Maybe<string>;
608
- }>;
609
- loading: boolean;
610
- successful: boolean;
611
- response: Maybe<OAuth2Tokens> | void;
612
- }
613
-
614
- interface UserStoreValue {
615
- completed: boolean;
616
- error: Maybe<{
617
- code?: Maybe<number>;
618
- message: Maybe<string>;
619
- }>;
620
- loading: boolean;
621
- successful: boolean;
622
- response: unknown;
623
- }
624
-
625
- interface JourneyOptions {
626
- config?: StepOptions;
627
- journey?: string;
628
- oauth?: boolean;
629
- resumeUrl?: string;
630
- user?: boolean;
631
- }
632
- interface Response$1 {
633
- journey?: JourneyStoreValue;
634
- oauth?: OAuthTokenStoreValue;
635
- user?: UserStoreValue;
636
- }
637
-
638
-
639
747
  declare type Primitive = string | number | bigint | boolean | null | undefined;
640
748
 
641
749
  declare namespace util {
@@ -1473,14 +1581,6 @@ declare enum ZodFirstPartyTypeKind {
1473
1581
  ZodBranded = "ZodBranded"
1474
1582
  }
1475
1583
 
1476
- declare const partialLinksSchema: ZodObject<{
1477
- termsAndConditions: ZodOptional<ZodString>;
1478
- }, "strict", ZodTypeAny, {
1479
- termsAndConditions?: string | undefined;
1480
- }, {
1481
- termsAndConditions?: string | undefined;
1482
- }>;
1483
-
1484
1584
  declare const partialConfigSchema: ZodObject<{
1485
1585
  callbackFactory: ZodOptional<ZodOptional<ZodFunction<ZodTuple<[ZodObject<{
1486
1586
  _id: ZodOptional<ZodNumber>;
@@ -1797,6 +1897,14 @@ declare const journeyConfigSchema: ZodObject<{
1797
1897
  };
1798
1898
  }>;
1799
1899
 
1900
+ declare const partialLinksSchema: ZodObject<{
1901
+ termsAndConditions: ZodOptional<ZodString>;
1902
+ }, "strict", ZodTypeAny, {
1903
+ termsAndConditions?: string | undefined;
1904
+ }, {
1905
+ termsAndConditions?: string | undefined;
1906
+ }>;
1907
+
1800
1908
  declare const partialStringsSchema: ZodObject<{
1801
1909
  alreadyHaveAnAccount: ZodOptional<ZodString>;
1802
1910
  backToDefault: ZodOptional<ZodString>;
@@ -2071,89 +2179,134 @@ declare const partialStyleSchema: ZodObject<{
2071
2179
  } | undefined;
2072
2180
  }>;
2073
2181
 
2074
- declare const configuration: {
2075
- set(options: {
2076
- type?: string | undefined;
2077
- callbackFactory?: ((args_0: {
2078
- input?: {
2079
- value?: unknown;
2080
- name: string;
2081
- }[] | undefined;
2082
- _id?: number | undefined;
2083
- type: CallbackType;
2084
- output: {
2085
- value?: unknown;
2086
- name: string;
2087
- }[];
2088
- }, ...args_1: unknown[]) => FRCallback) | undefined;
2089
- clientId?: string | undefined;
2090
- middleware?: ((...args: unknown[]) => unknown)[] | undefined;
2091
- realmPath?: string | undefined;
2092
- redirectUri?: string | undefined;
2093
- scope?: string | undefined;
2094
- serverConfig?: {
2095
- paths?: {
2096
- authenticate: string;
2097
- authorize: string;
2098
- accessToken: string;
2099
- endSession: string;
2100
- userInfo: string;
2101
- revoke: string;
2102
- sessions: string;
2103
- } | undefined;
2104
- timeout: number;
2105
- baseUrl: string;
2106
- } | undefined;
2107
- support?: "modern" | "legacy" | undefined;
2108
- tokenStore?: "localStorage" | "indexedDB" | "sessionStorage" | {
2109
- set: (args_0: string, ...args_1: unknown[]) => Promise<void>;
2110
- remove: (args_0: string, ...args_1: unknown[]) => Promise<void>;
2111
- get: (args_0: string, ...args_1: unknown[]) => Promise<{
2112
- idToken?: string | undefined;
2113
- refreshToken?: string | undefined;
2114
- tokenExpiry?: number | undefined;
2115
- accessToken: string;
2116
- }>;
2117
- } | undefined;
2118
- tree?: string | undefined;
2119
- oauthThreshold?: number | undefined;
2120
- }): void;
2182
+ interface JourneyOptions {
2183
+ oauth?: boolean;
2184
+ user?: boolean;
2185
+ }
2186
+ interface JourneyOptionsStart {
2187
+ config?: StepOptions;
2188
+ journey?: string;
2189
+ resumeUrl?: string;
2190
+ }
2191
+ interface WidgetConfigOptions {
2192
+ config?: TypeOf<typeof partialConfigSchema>;
2193
+ content?: TypeOf<typeof partialStringsSchema>;
2194
+ journeys?: TypeOf<typeof journeyConfigSchema>;
2195
+ links?: TypeOf<typeof partialLinksSchema>;
2196
+ style?: TypeOf<typeof partialStyleSchema>;
2197
+ }
2198
+
2199
+
2200
+ interface ComponentStoreValue {
2201
+ error: {
2202
+ code: string;
2203
+ message: string;
2204
+ } | null;
2205
+ modal: {
2206
+ component: SvelteComponentDev$1;
2207
+ element: HTMLDialogElement;
2208
+ } | null;
2209
+ mounted: boolean;
2210
+ open: boolean | null;
2211
+ reason: 'auto' | 'external' | 'user' | null;
2212
+ type: 'inline' | 'modal' | null;
2213
+ }
2214
+
2215
+ declare const api: {
2216
+ component: {
2217
+ close: (args?: {
2218
+ reason: "auto" | "external" | "user";
2219
+ } | undefined) => void;
2220
+ mount: (component: SvelteComponentDev$1, element: HTMLDialogElement) => void;
2221
+ open: () => void;
2222
+ subscribe: (this: void, run: Subscriber<ComponentStoreValue>, invalidate?: ((value?: ComponentStoreValue | undefined) => void) | undefined) => Unsubscriber;
2223
+ };
2224
+ configuration: (options?: WidgetConfigOptions | undefined) => {
2225
+ set(setOptions?: WidgetConfigOptions | undefined): void;
2226
+ };
2227
+ getStores: () => {
2228
+ journeyStore: JourneyStore;
2229
+ oauthStore: OAuthStore;
2230
+ userStore: UserStore;
2231
+ };
2232
+ journey: (options?: JourneyOptions | undefined) => {
2233
+ start: (startOptions?: JourneyOptionsStart | undefined) => Promise<unknown>;
2234
+ subscribe: (this: void, run: Subscriber<{
2235
+ journey: JourneyStoreValue;
2236
+ oauth: OAuthTokenStoreValue;
2237
+ user: UserStoreValue;
2238
+ }>, invalidate?: ((value?: {
2239
+ journey: JourneyStoreValue;
2240
+ oauth: OAuthTokenStoreValue;
2241
+ user: UserStoreValue;
2242
+ } | undefined) => void) | undefined) => Unsubscriber;
2243
+ };
2244
+ request: typeof HttpClient.request;
2245
+ user: {
2246
+ info(): {
2247
+ get: (options?: ConfigOptions | undefined) => Promise<unknown>;
2248
+ subscribe: (this: void, run: Subscriber<UserStoreValue>, invalidate?: ((value?: UserStoreValue | undefined) => void) | undefined) => Unsubscriber;
2249
+ };
2250
+ logout(): Promise<void>;
2251
+ tokens(): {
2252
+ get: (options?: ConfigOptions | undefined) => Promise<unknown>;
2253
+ subscribe: (this: void, run: Subscriber<OAuthTokenStoreValue>, invalidate?: ((value?: OAuthTokenStoreValue | undefined) => void) | undefined) => Unsubscriber;
2254
+ };
2255
+ };
2256
+ };
2257
+ declare const configuration: (options?: WidgetConfigOptions | undefined) => {
2258
+ set(setOptions?: WidgetConfigOptions | undefined): void;
2121
2259
  };
2122
- declare const form: {
2123
- onMount(fn: (form: HTMLFormElement) => void): void;
2260
+ declare const journey: (options?: JourneyOptions | undefined) => {
2261
+ start: (startOptions?: JourneyOptionsStart | undefined) => Promise<unknown>;
2262
+ subscribe: (this: void, run: Subscriber<{
2263
+ journey: JourneyStoreValue;
2264
+ oauth: OAuthTokenStoreValue;
2265
+ user: UserStoreValue;
2266
+ }>, invalidate?: ((value?: {
2267
+ journey: JourneyStoreValue;
2268
+ oauth: OAuthTokenStoreValue;
2269
+ user: UserStoreValue;
2270
+ } | undefined) => void) | undefined) => Unsubscriber;
2124
2271
  };
2125
- declare const journey: {
2126
- start(options?: JourneyOptions | undefined): void;
2127
- onFailure(fn: (response: Response$1) => void): void;
2128
- onSuccess(fn: (response: Response$1) => void): void;
2272
+ declare const component: () => {
2273
+ close: (args?: {
2274
+ reason: "auto" | "external" | "user";
2275
+ } | undefined) => void;
2276
+ mount: (component: SvelteComponentDev$1, element: HTMLDialogElement) => void;
2277
+ open: () => void;
2278
+ subscribe: (this: void, run: Subscriber<ComponentStoreValue>, invalidate?: ((value?: ComponentStoreValue | undefined) => void) | undefined) => Unsubscriber;
2129
2279
  };
2130
- declare const request: (options: HttpClientRequestOptions) => Promise<Response>;
2280
+ declare const request: typeof HttpClient.request;
2131
2281
  declare const user: {
2132
- authorized(remote?: boolean): Promise<unknown>;
2133
- info(remote?: boolean): Promise<unknown>;
2134
- logout: () => Promise<void>;
2135
- tokens(options?: GetTokensOptions | undefined): Promise<void | OAuth2Tokens>;
2282
+ info(): {
2283
+ get: (options?: ConfigOptions | undefined) => Promise<unknown>;
2284
+ subscribe: (this: void, run: Subscriber<UserStoreValue>, invalidate?: ((value?: UserStoreValue | undefined) => void) | undefined) => Unsubscriber;
2285
+ };
2286
+ logout(): Promise<void>;
2287
+ tokens(): {
2288
+ get: (options?: ConfigOptions | undefined) => Promise<unknown>;
2289
+ subscribe: (this: void, run: Subscriber<OAuthTokenStoreValue>, invalidate?: ((value?: OAuthTokenStoreValue | undefined) => void) | undefined) => Unsubscriber;
2290
+ };
2136
2291
  };
2292
+ type ConfigurationApi = ReturnType<typeof api.configuration>;
2293
+ type JourneyApi = ReturnType<typeof api.journey>;
2294
+ type UserInfoApi = ReturnType<typeof api.user.info>;
2295
+ type UserTokensApi = ReturnType<typeof api.user.tokens>;
2137
2296
 
2138
2297
  declare const __propDef: {
2139
2298
  props: {
2140
- config?: TypeOf<typeof partialConfigSchema> | undefined;
2141
- content?: TypeOf<typeof partialStringsSchema> | undefined;
2142
- journeys?: TypeOf<typeof journeyConfigSchema> | undefined;
2143
- links?: TypeOf<typeof partialLinksSchema> | undefined;
2144
- style?: TypeOf<typeof partialStyleSchema> | undefined;
2299
+ type?: "inline" | "modal" | undefined;
2145
2300
  };
2146
2301
  events: {
2147
- 'form-mount': CustomEvent<any>;
2148
- } & {
2149
2302
  [evt: string]: CustomEvent<any>;
2150
2303
  };
2151
2304
  slots: {};
2152
2305
  };
2153
- type InlineProps = typeof __propDef.props;
2154
- type InlineEvents = typeof __propDef.events;
2155
- type InlineSlots = typeof __propDef.slots;
2156
- declare class Inline extends SvelteComponentTyped<InlineProps, InlineEvents, InlineSlots> {
2306
+ type IndexProps = typeof __propDef.props;
2307
+ type IndexEvents = typeof __propDef.events;
2308
+ type IndexSlots = typeof __propDef.slots;
2309
+ declare class Index extends SvelteComponentTyped<IndexProps, IndexEvents, IndexSlots> {
2157
2310
  }
2158
2311
 
2159
- export { InlineEvents, InlineProps, InlineSlots, configuration, Inline as default, form, journey, request, user };
2312
+ export { ConfigurationApi, IndexEvents, IndexProps, IndexSlots, JourneyApi, UserInfoApi, UserTokensApi, component, configuration, Index as default, journey, request, user };