@lafken/auth 0.10.1
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.
- package/LICENCE +21 -0
- package/README.md +493 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +18 -0
- package/lib/main/attribute/attribute.d.ts +86 -0
- package/lib/main/attribute/attribute.js +109 -0
- package/lib/main/attribute/attribute.types.d.ts +90 -0
- package/lib/main/attribute/attribute.types.js +13 -0
- package/lib/main/attribute/index.d.ts +2 -0
- package/lib/main/attribute/index.js +18 -0
- package/lib/main/event/event.d.ts +19 -0
- package/lib/main/event/event.js +26 -0
- package/lib/main/extension/extension.d.ts +60 -0
- package/lib/main/extension/extension.js +74 -0
- package/lib/main/extension/extension.types.d.ts +37 -0
- package/lib/main/extension/extension.types.js +2 -0
- package/lib/main/extension/index.d.ts +1 -0
- package/lib/main/extension/index.js +2 -0
- package/lib/main/index.d.ts +1 -0
- package/lib/main/index.js +17 -0
- package/lib/resolver/auth/auth.d.ts +11 -0
- package/lib/resolver/auth/auth.js +50 -0
- package/lib/resolver/auth/auth.utils.d.ts +2 -0
- package/lib/resolver/auth/auth.utils.js +23 -0
- package/lib/resolver/auth/user-pool/extension/extension.d.ts +8 -0
- package/lib/resolver/auth/user-pool/extension/extension.js +51 -0
- package/lib/resolver/auth/user-pool/extension/extension.types.d.ts +6 -0
- package/lib/resolver/auth/user-pool/extension/extension.types.js +2 -0
- package/lib/resolver/auth/user-pool/external/external.d.ts +14 -0
- package/lib/resolver/auth/user-pool/external/external.js +14 -0
- package/lib/resolver/auth/user-pool/identity-provider/identity-provider.d.ts +13 -0
- package/lib/resolver/auth/user-pool/identity-provider/identity-provider.js +120 -0
- package/lib/resolver/auth/user-pool/identity-provider/identity-provider.types.d.ts +6 -0
- package/lib/resolver/auth/user-pool/identity-provider/identity-provider.types.js +2 -0
- package/lib/resolver/auth/user-pool/internal/internal.d.ts +30 -0
- package/lib/resolver/auth/user-pool/internal/internal.js +332 -0
- package/lib/resolver/auth/user-pool/user-pool.types.d.ts +263 -0
- package/lib/resolver/auth/user-pool/user-pool.types.js +2 -0
- package/lib/resolver/auth/user-pool-client/external/external.d.ts +7 -0
- package/lib/resolver/auth/user-pool-client/external/external.js +16 -0
- package/lib/resolver/auth/user-pool-client/internal/internal.d.ts +14 -0
- package/lib/resolver/auth/user-pool-client/internal/internal.js +115 -0
- package/lib/resolver/auth/user-pool-client/user-pool-client.types.d.ts +169 -0
- package/lib/resolver/auth/user-pool-client/user-pool-client.types.js +2 -0
- package/lib/resolver/index.d.ts +1 -0
- package/lib/resolver/index.js +17 -0
- package/lib/resolver/resolver.d.ts +12 -0
- package/lib/resolver/resolver.js +25 -0
- package/lib/resolver/resolver.types.d.ts +62 -0
- package/lib/resolver/resolver.types.js +2 -0
- package/package.json +87 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Standard = exports.Custom = exports.Attributes = exports.authPayloadKey = exports.authFieldKey = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const common_1 = require("@lafken/common");
|
|
6
|
+
const extension_1 = require("../extension/extension");
|
|
7
|
+
exports.authFieldKey = (0, common_1.createFieldName)(extension_1.RESOURCE_TYPE, common_1.FieldProperties.field);
|
|
8
|
+
exports.authPayloadKey = (0, common_1.createFieldName)(extension_1.RESOURCE_TYPE, common_1.FieldProperties.payload);
|
|
9
|
+
/**
|
|
10
|
+
* Class decorator that declares a class as a Cognito User Pool
|
|
11
|
+
* attributes definition.
|
|
12
|
+
*
|
|
13
|
+
* The decorated class groups standard and custom attributes that will
|
|
14
|
+
* be configured on the Cognito User Pool. Use `@Standard` and `@Custom`
|
|
15
|
+
* on its properties to describe each attribute.
|
|
16
|
+
*
|
|
17
|
+
* @param props - Optional payload configuration (e.g. a custom `name`).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* @Attributes()
|
|
22
|
+
* export class UserAttributes {
|
|
23
|
+
* @Standard({ required: true })
|
|
24
|
+
* email: string;
|
|
25
|
+
*
|
|
26
|
+
* @Custom({ minLen: 2, maxLen: 50 })
|
|
27
|
+
* displayName: string;
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
exports.Attributes = (0, common_1.createPayloadDecorator)({
|
|
32
|
+
prefix: extension_1.RESOURCE_TYPE,
|
|
33
|
+
createUniqueId: false,
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Property decorator that registers a custom attribute on the Cognito
|
|
37
|
+
* User Pool.
|
|
38
|
+
*
|
|
39
|
+
* Custom attributes are user-defined fields that extend the default
|
|
40
|
+
* Cognito schema. The decorator options are resolved based on the
|
|
41
|
+
* property type: string fields accept `minLen` / `maxLen`, number fields
|
|
42
|
+
* accept `min` / `max`, and all types support `mutable`.
|
|
43
|
+
*
|
|
44
|
+
* @typeParam T - The class type that owns the decorated property.
|
|
45
|
+
* @typeParam A - The property key being decorated.
|
|
46
|
+
* @param props - Optional type-specific constraints for the attribute.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* @Attributes()
|
|
51
|
+
* export class UserAttributes {
|
|
52
|
+
* @Custom({ minLen: 2, maxLen: 100 })
|
|
53
|
+
* displayName: string;
|
|
54
|
+
*
|
|
55
|
+
* @Custom({ min: 0, max: 200 })
|
|
56
|
+
* score: number;
|
|
57
|
+
*
|
|
58
|
+
* @Custom({ mutable: false })
|
|
59
|
+
* isVerified: boolean;
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
const Custom = (props = {}) => (target, propertyName) => (0, common_1.createFieldDecorator)({
|
|
64
|
+
prefix: extension_1.RESOURCE_TYPE,
|
|
65
|
+
getMetadata: (props) => ({
|
|
66
|
+
...props,
|
|
67
|
+
attributeType: 'custom',
|
|
68
|
+
mutable: props?.mutable ?? true,
|
|
69
|
+
}),
|
|
70
|
+
})(props)(target, propertyName);
|
|
71
|
+
exports.Custom = Custom;
|
|
72
|
+
/**
|
|
73
|
+
* Property decorator that marks a field as a standard Cognito User Pool
|
|
74
|
+
* attribute.
|
|
75
|
+
*
|
|
76
|
+
* Standard attributes are predefined by Cognito and follow the OpenID
|
|
77
|
+
* Connect specification. The property name must match one of the
|
|
78
|
+
* supported attribute keys:
|
|
79
|
+
*
|
|
80
|
+
* `name`, `familyName`, `givenName`, `middleName`, `nickname`,
|
|
81
|
+
* `preferredUsername`, `profile`, `picture`, `website`, `gender`,
|
|
82
|
+
* `birthdate`, `zoneInfo`, `locale`, `updated_at`, `address`,
|
|
83
|
+
* `email`, `phoneNumber`, `sub`.
|
|
84
|
+
*
|
|
85
|
+
* @param props - Optional settings for the attribute.
|
|
86
|
+
* @param props.required - Whether the attribute is required during sign-up. Defaults to `true`.
|
|
87
|
+
* @param props.mutable - Whether the attribute value can be changed after creation. Defaults to `true`.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* @Attributes()
|
|
92
|
+
* export class UserAttributes {
|
|
93
|
+
* @Standard({ required: true })
|
|
94
|
+
* email: string;
|
|
95
|
+
*
|
|
96
|
+
* @Standard({ required: false, mutable: true })
|
|
97
|
+
* nickname: string;
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
const Standard = (props = {}) => (target, propertyKey) => (0, common_1.createFieldDecorator)({
|
|
102
|
+
prefix: extension_1.RESOURCE_TYPE,
|
|
103
|
+
getMetadata: (props) => ({
|
|
104
|
+
attributeType: 'standard',
|
|
105
|
+
mutable: props?.mutable ?? true,
|
|
106
|
+
required: props?.required ?? true,
|
|
107
|
+
}),
|
|
108
|
+
})(props)(target, propertyKey);
|
|
109
|
+
exports.Standard = Standard;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { FieldMetadata, FieldProps } from '@lafken/common';
|
|
2
|
+
/**
|
|
3
|
+
* Metadata keys used internally to store Cognito attribute
|
|
4
|
+
* information via `Reflect.defineMetadata`.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum CognitoPropertyReflectKeys {
|
|
7
|
+
custom = "cognito:custom-attribute",
|
|
8
|
+
standard = "cognito:standard-attribute",
|
|
9
|
+
PAYLOAD = "cognito:payload"
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Base options shared by all custom Cognito attributes.
|
|
13
|
+
*/
|
|
14
|
+
interface CommonCustomAttribute extends Omit<FieldProps, 'type'> {
|
|
15
|
+
/**
|
|
16
|
+
* Whether the attribute value can be changed after the user is created.
|
|
17
|
+
* Defaults to `true`.
|
|
18
|
+
*/
|
|
19
|
+
mutable?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The data type of the attribute. Accepted values are `String`,
|
|
22
|
+
* `Number`, or `Boolean`.
|
|
23
|
+
*/
|
|
24
|
+
type?: String | Number | Boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Options for a standard Cognito attribute.
|
|
28
|
+
*/
|
|
29
|
+
export interface CommonStandardAttribute extends Omit<CommonCustomAttribute, 'name'> {
|
|
30
|
+
/**
|
|
31
|
+
* Whether the attribute is required during user sign-up.
|
|
32
|
+
* Defaults to `true`.
|
|
33
|
+
*/
|
|
34
|
+
required?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Resolved metadata stored for a standard attribute after the
|
|
38
|
+
* `@Standard` decorator is processed.
|
|
39
|
+
*/
|
|
40
|
+
export type StandardAttributeMetadata = Required<CommonStandardAttribute> & FieldMetadata & {
|
|
41
|
+
attributeType: 'standard';
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Options for a custom attribute whose property type is `number`.
|
|
45
|
+
*/
|
|
46
|
+
export interface NumberCustomAttribute extends CommonCustomAttribute {
|
|
47
|
+
/** Minimum allowed value. */
|
|
48
|
+
min?: number;
|
|
49
|
+
/** Maximum allowed value. */
|
|
50
|
+
max?: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Options for a custom attribute whose property type is `string`.
|
|
54
|
+
*/
|
|
55
|
+
export interface StringCustomAttribute extends CommonCustomAttribute {
|
|
56
|
+
/** Minimum string length. */
|
|
57
|
+
minLen?: number;
|
|
58
|
+
/** Maximum string length. */
|
|
59
|
+
maxLen?: number;
|
|
60
|
+
}
|
|
61
|
+
export interface AuthAttributes {
|
|
62
|
+
name?: string;
|
|
63
|
+
familyName?: string;
|
|
64
|
+
givenName?: string;
|
|
65
|
+
middleName?: string;
|
|
66
|
+
nickname?: string;
|
|
67
|
+
preferredUsername?: string;
|
|
68
|
+
profile?: string;
|
|
69
|
+
picture?: string;
|
|
70
|
+
website?: string;
|
|
71
|
+
gender?: string;
|
|
72
|
+
birthdate?: Date;
|
|
73
|
+
zoneInfo?: string;
|
|
74
|
+
locale?: string;
|
|
75
|
+
updated_at?: string;
|
|
76
|
+
address?: string;
|
|
77
|
+
email?: string;
|
|
78
|
+
phoneNumber?: string;
|
|
79
|
+
sub?: string;
|
|
80
|
+
}
|
|
81
|
+
export type CustomAttributeProps<T> = T extends number ? NumberCustomAttribute : T extends string ? StringCustomAttribute : CommonCustomAttribute;
|
|
82
|
+
export type CustomAttributesMetadata = FieldMetadata & {
|
|
83
|
+
attributeType: 'custom';
|
|
84
|
+
mutable: boolean;
|
|
85
|
+
min?: number;
|
|
86
|
+
max?: number;
|
|
87
|
+
minLen?: number;
|
|
88
|
+
maxLen?: number;
|
|
89
|
+
};
|
|
90
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CognitoPropertyReflectKeys = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Metadata keys used internally to store Cognito attribute
|
|
6
|
+
* information via `Reflect.defineMetadata`.
|
|
7
|
+
*/
|
|
8
|
+
var CognitoPropertyReflectKeys;
|
|
9
|
+
(function (CognitoPropertyReflectKeys) {
|
|
10
|
+
CognitoPropertyReflectKeys["custom"] = "cognito:custom-attribute";
|
|
11
|
+
CognitoPropertyReflectKeys["standard"] = "cognito:standard-attribute";
|
|
12
|
+
CognitoPropertyReflectKeys["PAYLOAD"] = "cognito:payload";
|
|
13
|
+
})(CognitoPropertyReflectKeys || (exports.CognitoPropertyReflectKeys = CognitoPropertyReflectKeys = {}));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./attribute"), exports);
|
|
18
|
+
__exportStar(require("./attribute.types"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parameter decorator that binds the incoming Cognito trigger event
|
|
3
|
+
* to a handler method argument.
|
|
4
|
+
*
|
|
5
|
+
* Use it on a `@Trigger` handler parameter so the framework
|
|
6
|
+
* automatically injects the raw Cognito event object at runtime.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* @AuthExtension()
|
|
11
|
+
* export class AuthTriggers {
|
|
12
|
+
* @Trigger({ type: 'preSignUp' })
|
|
13
|
+
* onPreSignUp(@Event() event: PreSignUpTriggerEvent) {
|
|
14
|
+
* // event contains the Cognito trigger payload
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const Event: () => (target: any, methodName: string, _number: number) => void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Event = void 0;
|
|
4
|
+
const common_1 = require("@lafken/common");
|
|
5
|
+
const extension_1 = require("../extension/extension");
|
|
6
|
+
/**
|
|
7
|
+
* Parameter decorator that binds the incoming Cognito trigger event
|
|
8
|
+
* to a handler method argument.
|
|
9
|
+
*
|
|
10
|
+
* Use it on a `@Trigger` handler parameter so the framework
|
|
11
|
+
* automatically injects the raw Cognito event object at runtime.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* @AuthExtension()
|
|
16
|
+
* export class AuthTriggers {
|
|
17
|
+
* @Trigger({ type: 'preSignUp' })
|
|
18
|
+
* onPreSignUp(@Event() event: PreSignUpTriggerEvent) {
|
|
19
|
+
* // event contains the Cognito trigger payload
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
const Event = () => (0, common_1.createEventDecorator)({ prefix: extension_1.RESOURCE_TYPE })(class {
|
|
25
|
+
});
|
|
26
|
+
exports.Event = Event;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ExtensionsProps, TriggerProps } from './extension.types';
|
|
2
|
+
export declare const RESOURCE_TYPE: "AUTHENTICATION";
|
|
3
|
+
/**
|
|
4
|
+
* Class decorator that registers a class as a Cognito authentication
|
|
5
|
+
* extension resource.
|
|
6
|
+
*
|
|
7
|
+
* The decorated class groups one or more `@Trigger` handlers that
|
|
8
|
+
* respond to Cognito User Pool lifecycle events (e.g. pre sign-up,
|
|
9
|
+
* post confirmation, custom message, etc.).
|
|
10
|
+
*
|
|
11
|
+
* @param props - Optional configuration.
|
|
12
|
+
* @param props.name - A custom name for the resource.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* @AuthExtension()
|
|
17
|
+
* export class AuthTriggers {
|
|
18
|
+
* @Trigger({ type: 'preSignUp' })
|
|
19
|
+
* onPreSignUp(@Event() event) { }
|
|
20
|
+
*
|
|
21
|
+
* @Trigger({ type: 'postConfirmation' })
|
|
22
|
+
* onPostConfirmation(@Event() event) { }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const AuthExtension: (props?: ExtensionsProps) => (constructor: Function) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Method decorator that registers a handler for a specific Cognito
|
|
29
|
+
* User Pool trigger.
|
|
30
|
+
*
|
|
31
|
+
* Each decorated method becomes a Lambda function that Cognito invokes
|
|
32
|
+
* during the corresponding lifecycle event. Supported trigger types:
|
|
33
|
+
*
|
|
34
|
+
* `preSignUp`, `preAuthentication`, `preTokenGeneration`,
|
|
35
|
+
* `preTokenGenerationConfig`, `userMigration`, `postAuthentication`,
|
|
36
|
+
* `postConfirmation`, `createAuthChallenge`, `defineAuthChallenge`,
|
|
37
|
+
* `customMessage`, `customEmailSender`, `customSmsSender`,
|
|
38
|
+
* `verifyAuthChallengeResponse`.
|
|
39
|
+
*
|
|
40
|
+
* @param props - Trigger configuration.
|
|
41
|
+
* @param props.type - The Cognito trigger type to handle.
|
|
42
|
+
* @param props.lambda - Optional Lambda settings (memory, timeout, etc.).
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* @AuthExtension()
|
|
47
|
+
* export class AuthTriggers {
|
|
48
|
+
* @Trigger({ type: 'preSignUp' })
|
|
49
|
+
* validateSignUp(@Event() event) {
|
|
50
|
+
* // validate and return event
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* @Trigger({ type: 'customMessage', lambda: { memory: 512 } })
|
|
54
|
+
* customEmail(@Event() event) {
|
|
55
|
+
* // customize the email message
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare const Trigger: (props: TriggerProps) => (target: any, methodName: string, descriptor: PropertyDescriptor) => any;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Trigger = exports.AuthExtension = exports.RESOURCE_TYPE = void 0;
|
|
4
|
+
const common_1 = require("@lafken/common");
|
|
5
|
+
exports.RESOURCE_TYPE = 'AUTHENTICATION';
|
|
6
|
+
/**
|
|
7
|
+
* Class decorator that registers a class as a Cognito authentication
|
|
8
|
+
* extension resource.
|
|
9
|
+
*
|
|
10
|
+
* The decorated class groups one or more `@Trigger` handlers that
|
|
11
|
+
* respond to Cognito User Pool lifecycle events (e.g. pre sign-up,
|
|
12
|
+
* post confirmation, custom message, etc.).
|
|
13
|
+
*
|
|
14
|
+
* @param props - Optional configuration.
|
|
15
|
+
* @param props.name - A custom name for the resource.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* @AuthExtension()
|
|
20
|
+
* export class AuthTriggers {
|
|
21
|
+
* @Trigger({ type: 'preSignUp' })
|
|
22
|
+
* onPreSignUp(@Event() event) { }
|
|
23
|
+
*
|
|
24
|
+
* @Trigger({ type: 'postConfirmation' })
|
|
25
|
+
* onPostConfirmation(@Event() event) { }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
const AuthExtension = (props) => (0, common_1.createResourceDecorator)({
|
|
30
|
+
callerFileIndex: 5,
|
|
31
|
+
type: exports.RESOURCE_TYPE,
|
|
32
|
+
getMetadata: (props) => props,
|
|
33
|
+
})(props);
|
|
34
|
+
exports.AuthExtension = AuthExtension;
|
|
35
|
+
/**
|
|
36
|
+
* Method decorator that registers a handler for a specific Cognito
|
|
37
|
+
* User Pool trigger.
|
|
38
|
+
*
|
|
39
|
+
* Each decorated method becomes a Lambda function that Cognito invokes
|
|
40
|
+
* during the corresponding lifecycle event. Supported trigger types:
|
|
41
|
+
*
|
|
42
|
+
* `preSignUp`, `preAuthentication`, `preTokenGeneration`,
|
|
43
|
+
* `preTokenGenerationConfig`, `userMigration`, `postAuthentication`,
|
|
44
|
+
* `postConfirmation`, `createAuthChallenge`, `defineAuthChallenge`,
|
|
45
|
+
* `customMessage`, `customEmailSender`, `customSmsSender`,
|
|
46
|
+
* `verifyAuthChallengeResponse`.
|
|
47
|
+
*
|
|
48
|
+
* @param props - Trigger configuration.
|
|
49
|
+
* @param props.type - The Cognito trigger type to handle.
|
|
50
|
+
* @param props.lambda - Optional Lambda settings (memory, timeout, etc.).
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* @AuthExtension()
|
|
55
|
+
* export class AuthTriggers {
|
|
56
|
+
* @Trigger({ type: 'preSignUp' })
|
|
57
|
+
* validateSignUp(@Event() event) {
|
|
58
|
+
* // validate and return event
|
|
59
|
+
* }
|
|
60
|
+
*
|
|
61
|
+
* @Trigger({ type: 'customMessage', lambda: { memory: 512 } })
|
|
62
|
+
* customEmail(@Event() event) {
|
|
63
|
+
* // customize the email message
|
|
64
|
+
* }
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
const Trigger = (props) => (0, common_1.createLambdaDecorator)({
|
|
69
|
+
getLambdaMetadata: (props, name) => ({
|
|
70
|
+
name,
|
|
71
|
+
...props,
|
|
72
|
+
}),
|
|
73
|
+
})(props);
|
|
74
|
+
exports.Trigger = Trigger;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { LambdaMetadata, LambdaProps, ResourceMetadata } from '@lafken/common';
|
|
2
|
+
/**
|
|
3
|
+
* Supported Cognito User Pool trigger types.
|
|
4
|
+
*
|
|
5
|
+
* Each value corresponds to a lifecycle event that Cognito can invoke
|
|
6
|
+
* a Lambda function for during user authentication and management flows.
|
|
7
|
+
*/
|
|
8
|
+
export type TriggerType = 'preAuthentication' | 'preSignUp' | 'preTokenGeneration' | 'preTokenGenerationConfig' | 'userMigration' | 'postAuthentication' | 'postConfirmation' | 'createAuthChallenge' | 'defineAuthChallenge' | 'customMessage' | 'customEmailSender' | 'customSmsSender' | 'verifyAuthChallengeResponse';
|
|
9
|
+
/**
|
|
10
|
+
* Configuration options for the `@AuthExtension` class decorator.
|
|
11
|
+
*/
|
|
12
|
+
export interface ExtensionsProps {
|
|
13
|
+
/**
|
|
14
|
+
* A custom name for the authentication extension resource.
|
|
15
|
+
* If omitted, the class name is used by default.
|
|
16
|
+
*/
|
|
17
|
+
name?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ExtensionsMetadata extends ResourceMetadata {
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Configuration options for the `@Trigger` method decorator.
|
|
23
|
+
*/
|
|
24
|
+
export interface TriggerProps {
|
|
25
|
+
/**
|
|
26
|
+
* Optional Lambda function settings applied to the trigger handler
|
|
27
|
+
* (e.g. memory, timeout, runtime, environment variables).
|
|
28
|
+
*/
|
|
29
|
+
lambda?: LambdaProps;
|
|
30
|
+
/**
|
|
31
|
+
* The Cognito User Pool trigger type this handler responds to.
|
|
32
|
+
*/
|
|
33
|
+
type: TriggerType;
|
|
34
|
+
}
|
|
35
|
+
export interface TriggerMetadata extends LambdaMetadata {
|
|
36
|
+
type: TriggerType;
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './attribute';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./attribute"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Construct } from 'constructs';
|
|
2
|
+
import type { AuthOptions } from '../resolver.types';
|
|
3
|
+
export declare class Auth extends Construct {
|
|
4
|
+
private id;
|
|
5
|
+
private props;
|
|
6
|
+
private userPool;
|
|
7
|
+
private userPoolClient;
|
|
8
|
+
constructor(scope: Construct, id: string, props: AuthOptions<any>);
|
|
9
|
+
create(): Promise<void>;
|
|
10
|
+
callExtends(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Auth = void 0;
|
|
4
|
+
const constructs_1 = require("constructs");
|
|
5
|
+
const external_1 = require("./user-pool/external/external");
|
|
6
|
+
const internal_1 = require("./user-pool/internal/internal");
|
|
7
|
+
const external_2 = require("./user-pool-client/external/external");
|
|
8
|
+
const internal_2 = require("./user-pool-client/internal/internal");
|
|
9
|
+
class Auth extends constructs_1.Construct {
|
|
10
|
+
id;
|
|
11
|
+
props;
|
|
12
|
+
userPool;
|
|
13
|
+
userPoolClient;
|
|
14
|
+
constructor(scope, id, props) {
|
|
15
|
+
super(scope, `${id}-auth`);
|
|
16
|
+
this.id = id;
|
|
17
|
+
this.props = props;
|
|
18
|
+
}
|
|
19
|
+
async create() {
|
|
20
|
+
if (this.props.userPool?.isExternal) {
|
|
21
|
+
this.userPool = new external_1.ExternalUserPool(this, this.id, this.props.userPool);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
this.userPool = new internal_1.InternalUserPool(this, this.id, this.props.userPool || {});
|
|
25
|
+
}
|
|
26
|
+
if (this.props.userClient?.isExternal) {
|
|
27
|
+
this.userPoolClient = new external_2.ExternalUserPoolClient(this, this.id, {
|
|
28
|
+
userPoolId: this.userPool.id,
|
|
29
|
+
...this.props.userClient,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
this.userPoolClient = new internal_2.InternalUserPoolClient(this, this.id, {
|
|
34
|
+
userPoolId: this.userPool.id,
|
|
35
|
+
...this.props.userClient,
|
|
36
|
+
attributeByName: this.userPool instanceof internal_1.InternalUserPool ? this.userPool.attributeByName : {},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async callExtends() {
|
|
41
|
+
if (this.props.extend) {
|
|
42
|
+
await this.props.extend({
|
|
43
|
+
scope: this,
|
|
44
|
+
userPool: this.userPool,
|
|
45
|
+
userPoolClient: this.userPoolClient.cognitoUserPoolClient,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.Auth = Auth;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapUserAttributes = void 0;
|
|
4
|
+
exports.mapUserAttributes = {
|
|
5
|
+
name: 'name',
|
|
6
|
+
familyName: 'family_name',
|
|
7
|
+
givenName: 'given_name',
|
|
8
|
+
middleName: 'middle_name',
|
|
9
|
+
nickname: 'nickname',
|
|
10
|
+
preferredUsername: 'preferred_username',
|
|
11
|
+
profile: 'profile',
|
|
12
|
+
picture: 'picture',
|
|
13
|
+
website: 'website',
|
|
14
|
+
gender: 'gender',
|
|
15
|
+
birthdate: 'birthdate',
|
|
16
|
+
zoneInfo: 'zoneinfo',
|
|
17
|
+
locale: 'locale',
|
|
18
|
+
updated_at: 'updated_at',
|
|
19
|
+
address: 'address',
|
|
20
|
+
email: 'email',
|
|
21
|
+
phoneNumber: 'phone_number',
|
|
22
|
+
sub: 'sub',
|
|
23
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CognitoUserPoolLambdaConfig } from '@cdktn/provider-aws/lib/cognito-user-pool';
|
|
2
|
+
import { Construct } from 'constructs';
|
|
3
|
+
import type { ExtensionProps } from './extension.types';
|
|
4
|
+
export declare class Extension extends Construct {
|
|
5
|
+
props: ExtensionProps;
|
|
6
|
+
constructor(scope: Construct, id: string, props: ExtensionProps);
|
|
7
|
+
createTriggers(userPoolArn: string): CognitoUserPoolLambdaConfig;
|
|
8
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Extension = void 0;
|
|
4
|
+
const resolver_1 = require("@lafken/resolver");
|
|
5
|
+
const constructs_1 = require("constructs");
|
|
6
|
+
class Extension extends constructs_1.Construct {
|
|
7
|
+
props;
|
|
8
|
+
constructor(scope, id, props) {
|
|
9
|
+
super(scope, id);
|
|
10
|
+
this.props = props;
|
|
11
|
+
}
|
|
12
|
+
createTriggers(userPoolArn) {
|
|
13
|
+
const triggers = {};
|
|
14
|
+
const { handlers, resourceMetadata } = this.props;
|
|
15
|
+
for (const handler of handlers) {
|
|
16
|
+
const lambdaHandler = new resolver_1.LambdaHandler(this, `${handler.name}-${resourceMetadata.name}`, {
|
|
17
|
+
...handler,
|
|
18
|
+
originalName: resourceMetadata.originalName,
|
|
19
|
+
filename: resourceMetadata.filename,
|
|
20
|
+
foldername: resourceMetadata.foldername,
|
|
21
|
+
principal: 'cognito-idp.amazonaws.com',
|
|
22
|
+
suffix: 'auth',
|
|
23
|
+
sourceArn: userPoolArn,
|
|
24
|
+
});
|
|
25
|
+
switch (handler.type) {
|
|
26
|
+
case 'customEmailSender':
|
|
27
|
+
triggers.customEmailSender = {
|
|
28
|
+
lambdaArn: lambdaHandler.arn,
|
|
29
|
+
lambdaVersion: 'V1_0',
|
|
30
|
+
};
|
|
31
|
+
break;
|
|
32
|
+
case 'customSmsSender':
|
|
33
|
+
triggers.customSmsSender = {
|
|
34
|
+
lambdaArn: lambdaHandler.arn,
|
|
35
|
+
lambdaVersion: 'V1_0',
|
|
36
|
+
};
|
|
37
|
+
break;
|
|
38
|
+
case 'preTokenGenerationConfig':
|
|
39
|
+
triggers.preTokenGenerationConfig = {
|
|
40
|
+
lambdaArn: lambdaHandler.arn,
|
|
41
|
+
lambdaVersion: 'V1_0',
|
|
42
|
+
};
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
triggers[handler.type] = lambdaHandler.arn;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return triggers;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.Extension = Extension;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DataAwsCognitoUserPool } from '@cdktn/provider-aws/lib/data-aws-cognito-user-pool';
|
|
2
|
+
import type { Construct } from 'constructs';
|
|
3
|
+
import type { ExternalUserPoolProps } from '../user-pool.types';
|
|
4
|
+
declare const ExternalUserPool_base: (new (...args: any[]) => {
|
|
5
|
+
isGlobal(module: import("@lafken/common").ModuleGlobalReferenceNames | (string & {}), id: string): void;
|
|
6
|
+
isDependent(resolveDependency: () => void): void;
|
|
7
|
+
readonly node: import("constructs").Node;
|
|
8
|
+
with(...mixins: import("constructs").IMixin[]): import("constructs").IConstruct;
|
|
9
|
+
toString(): string;
|
|
10
|
+
}) & typeof DataAwsCognitoUserPool;
|
|
11
|
+
export declare class ExternalUserPool extends ExternalUserPool_base {
|
|
12
|
+
constructor(scope: Construct, id: string, props: ExternalUserPoolProps);
|
|
13
|
+
}
|
|
14
|
+
export {};
|