@reactionary/core 0.12.5 → 0.12.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.
|
@@ -8,18 +8,33 @@ class IdentityCapability extends BaseCapability {
|
|
|
8
8
|
this.context.session.identityContext.lastUpdated = /* @__PURE__ */ new Date();
|
|
9
9
|
this.context.session.identityContext.identity = identity;
|
|
10
10
|
}
|
|
11
|
-
setPendingExternalLogin(provider, state) {
|
|
12
|
-
this.context.session.identityContext.pendingExternalLogin = {
|
|
11
|
+
setPendingExternalLogin(provider, state, data) {
|
|
12
|
+
this.context.session.identityContext.pendingExternalLogin = {
|
|
13
|
+
provider,
|
|
14
|
+
state,
|
|
15
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
16
|
+
...data ? { data } : {}
|
|
17
|
+
};
|
|
13
18
|
}
|
|
14
|
-
/**
|
|
15
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Returns the pending login, and clears it, when provider and state match a login started in this session within
|
|
21
|
+
* the last 10 minutes. Returns undefined otherwise. A pending login can only be taken once.
|
|
22
|
+
*/
|
|
23
|
+
takePendingExternalLogin(provider, state) {
|
|
16
24
|
const pending = this.context.session.identityContext.pendingExternalLogin;
|
|
17
25
|
delete this.context.session.identityContext.pendingExternalLogin;
|
|
18
26
|
if (!pending || !state) {
|
|
19
|
-
return
|
|
27
|
+
return void 0;
|
|
20
28
|
}
|
|
21
29
|
const fresh = Date.now() - new Date(pending.createdAt).getTime() <= PENDING_EXTERNAL_LOGIN_TTL_MS;
|
|
22
|
-
|
|
30
|
+
if (!fresh || pending.provider !== provider || pending.state !== state) {
|
|
31
|
+
return void 0;
|
|
32
|
+
}
|
|
33
|
+
return { data: pending.data ?? {} };
|
|
34
|
+
}
|
|
35
|
+
/** Returns true, and clears the pending login, when provider and state match a login started in this session within the last 10 minutes. */
|
|
36
|
+
consumePendingExternalLogin(provider, state) {
|
|
37
|
+
return this.takePendingExternalLogin(provider, state) !== void 0;
|
|
23
38
|
}
|
|
24
39
|
}
|
|
25
40
|
export {
|
package/package.json
CHANGED
|
@@ -15,7 +15,8 @@ const IdentityContextSchema = z.looseObject({
|
|
|
15
15
|
pendingExternalLogin: z.looseObject({
|
|
16
16
|
provider: z.string(),
|
|
17
17
|
state: z.string(),
|
|
18
|
-
createdAt: z.coerce.date()
|
|
18
|
+
createdAt: z.coerce.date(),
|
|
19
|
+
data: z.record(z.string(), z.string()).optional().meta({ description: "Provider specific values that must survive the redirect, such as a PKCE code verifier and nonce." })
|
|
19
20
|
}).optional().meta({ description: "An external login that has been started but not completed. Binds the callback to the browser that started it." })
|
|
20
21
|
});
|
|
21
22
|
const SessionSchema = z.looseObject({
|
|
@@ -18,7 +18,14 @@ export declare abstract class IdentityCapability<TIdentity extends Identity = Id
|
|
|
18
18
|
abstract completeExternalLogin(payload: IdentityMutationCompleteExternalLogin): Promise<Result<TIdentity, IdentityConflictError>>;
|
|
19
19
|
protected getResourceName(): string;
|
|
20
20
|
protected updateIdentityContext(identity: TIdentity): void;
|
|
21
|
-
protected setPendingExternalLogin(provider: string, state: string): void;
|
|
21
|
+
protected setPendingExternalLogin(provider: string, state: string, data?: Record<string, string>): void;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the pending login, and clears it, when provider and state match a login started in this session within
|
|
24
|
+
* the last 10 minutes. Returns undefined otherwise. A pending login can only be taken once.
|
|
25
|
+
*/
|
|
26
|
+
protected takePendingExternalLogin(provider: string, state: string | undefined): {
|
|
27
|
+
data: Record<string, string>;
|
|
28
|
+
} | undefined;
|
|
22
29
|
/** Returns true, and clears the pending login, when provider and state match a login started in this session within the last 10 minutes. */
|
|
23
30
|
protected consumePendingExternalLogin(provider: string, state: string | undefined): boolean;
|
|
24
31
|
}
|
|
@@ -207,6 +207,7 @@ export declare const IdentityContextSchema: z.ZodObject<{
|
|
|
207
207
|
provider: z.ZodString;
|
|
208
208
|
state: z.ZodString;
|
|
209
209
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
210
|
+
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
210
211
|
}, z.core.$loose>>;
|
|
211
212
|
}, z.core.$loose>;
|
|
212
213
|
export declare const SessionSchema: z.ZodObject<{
|
|
@@ -230,6 +231,7 @@ export declare const SessionSchema: z.ZodObject<{
|
|
|
230
231
|
provider: z.ZodString;
|
|
231
232
|
state: z.ZodString;
|
|
232
233
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
234
|
+
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
233
235
|
}, z.core.$loose>>;
|
|
234
236
|
}, z.core.$loose>;
|
|
235
237
|
marketingContext: z.ZodDefault<z.ZodObject<{
|
|
@@ -272,6 +274,7 @@ export declare const RequestContextSchema: z.ZodObject<{
|
|
|
272
274
|
provider: z.ZodString;
|
|
273
275
|
state: z.ZodString;
|
|
274
276
|
createdAt: z.ZodCoercedDate<unknown>;
|
|
277
|
+
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
275
278
|
}, z.core.$loose>>;
|
|
276
279
|
}, z.core.$loose>;
|
|
277
280
|
marketingContext: z.ZodDefault<z.ZodObject<{
|