@ttoss/cloud-auth 0.13.32 → 0.13.34
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/dist/{esm/index.js → index.cjs} +59 -94
- package/dist/index.d.cts +71 -0
- package/dist/index.d.mts +59 -50
- package/dist/{index.js → index.mjs} +56 -131
- package/package.json +8 -8
- package/dist/index.d.ts +0 -62
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value,
|
|
5
|
-
configurable: true
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, {
|
|
3
|
+
value: 'Module'
|
|
6
4
|
});
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
//#region src/config.ts
|
|
7
|
+
const PASSWORD_MINIMUM_LENGTH = 8;
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/template.ts
|
|
11
|
+
const CognitoUserPoolLogicalId = "CognitoUserPool";
|
|
12
|
+
const CognitoUserPoolClientLogicalId = "CognitoUserPoolClient";
|
|
13
|
+
const CognitoIdentityPoolLogicalId = "CognitoIdentityPool";
|
|
14
|
+
const IdentityPoolAuthenticatedIAMRoleLogicalId = "IdentityPoolAuthenticatedIAMRole";
|
|
15
|
+
const IdentityPoolUnauthenticatedIAMRoleLogicalId = "IdentityPoolUnauthenticatedIAMRole";
|
|
16
|
+
const DenyStatement = {
|
|
18
17
|
Effect: "Deny",
|
|
19
18
|
Action: ["*"],
|
|
20
19
|
Resource: ["*"]
|
|
21
20
|
};
|
|
22
|
-
|
|
21
|
+
const defaultPrincipalTags = {
|
|
23
22
|
appClientId: "aud",
|
|
24
23
|
userId: "sub"
|
|
25
24
|
};
|
|
26
|
-
|
|
25
|
+
const createAuthTemplate = ({
|
|
27
26
|
autoVerifiedAttributes = ["email"],
|
|
28
27
|
identityPool,
|
|
29
28
|
schema,
|
|
@@ -44,7 +43,7 @@ var createAuthTemplate = /* @__PURE__ */__name(({
|
|
|
44
43
|
AutoVerifiedAttributes,
|
|
45
44
|
Policies: {
|
|
46
45
|
PasswordPolicy: {
|
|
47
|
-
MinimumLength:
|
|
46
|
+
MinimumLength: 8,
|
|
48
47
|
RequireLowercase: false,
|
|
49
48
|
RequireNumbers: false,
|
|
50
49
|
RequireSymbols: false,
|
|
@@ -122,19 +121,15 @@ var createAuthTemplate = /* @__PURE__ */__name(({
|
|
|
122
121
|
if (schema) {
|
|
123
122
|
const Schema = schema.map(attribute => {
|
|
124
123
|
let NumberAttributeConstraints = void 0;
|
|
125
|
-
if (attribute.numberAttributeConstraints) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
};
|
|
130
|
-
}
|
|
124
|
+
if (attribute.numberAttributeConstraints) NumberAttributeConstraints = {
|
|
125
|
+
MaxValue: attribute.numberAttributeConstraints?.maxValue,
|
|
126
|
+
MinValue: attribute.numberAttributeConstraints?.minValue
|
|
127
|
+
};
|
|
131
128
|
let StringAttributeConstraints = void 0;
|
|
132
|
-
if (attribute.stringAttributeConstraints) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
};
|
|
137
|
-
}
|
|
129
|
+
if (attribute.stringAttributeConstraints) StringAttributeConstraints = {
|
|
130
|
+
MaxLength: attribute.stringAttributeConstraints?.maxLength,
|
|
131
|
+
MinLength: attribute.stringAttributeConstraints?.minLength
|
|
132
|
+
};
|
|
138
133
|
return {
|
|
139
134
|
AttributeDataType: attribute.attributeDataType,
|
|
140
135
|
DeveloperOnlyAttribute: attribute.developerOnlyAttribute,
|
|
@@ -168,12 +163,10 @@ var createAuthTemplate = /* @__PURE__ */__name(({
|
|
|
168
163
|
}]
|
|
169
164
|
}
|
|
170
165
|
};
|
|
171
|
-
if (identityPool.name) {
|
|
172
|
-
template.Resources[CognitoIdentityPoolLogicalId].Properties
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
};
|
|
176
|
-
}
|
|
166
|
+
if (identityPool.name) template.Resources[CognitoIdentityPoolLogicalId].Properties = {
|
|
167
|
+
...template.Resources[CognitoIdentityPoolLogicalId].Properties,
|
|
168
|
+
IdentityPoolName: identityPool.name
|
|
169
|
+
};
|
|
177
170
|
template.Resources.CognitoIdentityPoolRoleAttachment = {
|
|
178
171
|
/**
|
|
179
172
|
* https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-identitypoolroleattachment.html
|
|
@@ -224,11 +217,9 @@ var createAuthTemplate = /* @__PURE__ */__name(({
|
|
|
224
217
|
"Fn::GetAtt": [IdentityPoolAuthenticatedIAMRoleLogicalId, "Arn"]
|
|
225
218
|
}
|
|
226
219
|
});
|
|
227
|
-
} else {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
});
|
|
231
|
-
}
|
|
220
|
+
} else Object.assign(template.Resources.CognitoIdentityPoolRoleAttachment.Properties?.Roles, {
|
|
221
|
+
authenticated: identityPool.authenticatedRoleArn
|
|
222
|
+
});
|
|
232
223
|
if (!identityPool.unauthenticatedRoleArn) {
|
|
233
224
|
template.Resources[IdentityPoolUnauthenticatedIAMRoleLogicalId] = {
|
|
234
225
|
Type: "AWS::IAM::Role",
|
|
@@ -267,19 +258,16 @@ var createAuthTemplate = /* @__PURE__ */__name(({
|
|
|
267
258
|
"Fn::GetAtt": [IdentityPoolUnauthenticatedIAMRoleLogicalId, "Arn"]
|
|
268
259
|
}
|
|
269
260
|
});
|
|
270
|
-
} else {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
261
|
+
} else Object.assign(template.Resources.CognitoIdentityPoolRoleAttachment.Properties?.Roles, {
|
|
262
|
+
unauthenticated: identityPool.unauthenticatedRoleArn
|
|
263
|
+
});
|
|
264
|
+
/**
|
|
265
|
+
* https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-identitypoolprincipaltag.html
|
|
266
|
+
*/
|
|
275
267
|
if (identityPool.principalTags || identityPool.principalTags === void 0) {
|
|
276
268
|
const PrincipalTags = (() => {
|
|
277
|
-
if (typeof identityPool.principalTags === "boolean")
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
if (identityPool.principalTags === void 0) {
|
|
281
|
-
return defaultPrincipalTags;
|
|
282
|
-
}
|
|
269
|
+
if (typeof identityPool.principalTags === "boolean") return defaultPrincipalTags;
|
|
270
|
+
if (identityPool.principalTags === void 0) return defaultPrincipalTags;
|
|
283
271
|
return identityPool.principalTags;
|
|
284
272
|
})();
|
|
285
273
|
template.Resources.CognitoIdentityPoolPrincipalTag = {
|
|
@@ -315,48 +303,22 @@ var createAuthTemplate = /* @__PURE__ */__name(({
|
|
|
315
303
|
}
|
|
316
304
|
if (lambdaTriggers) {
|
|
317
305
|
const LambdaConfig = {};
|
|
318
|
-
if (lambdaTriggers.preSignUp)
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
if (lambdaTriggers.
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
if (lambdaTriggers.
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (lambdaTriggers.
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
if (
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
LambdaConfig.CreateAuthChallenge = lambdaTriggers.createAuthChallenge;
|
|
335
|
-
}
|
|
336
|
-
if (lambdaTriggers.verifyAuthChallengeResponse) {
|
|
337
|
-
LambdaConfig.VerifyAuthChallengeResponse = lambdaTriggers.verifyAuthChallengeResponse;
|
|
338
|
-
}
|
|
339
|
-
if (lambdaTriggers.preTokenGeneration) {
|
|
340
|
-
LambdaConfig.PreTokenGeneration = lambdaTriggers.preTokenGeneration;
|
|
341
|
-
}
|
|
342
|
-
if (lambdaTriggers.userMigration) {
|
|
343
|
-
LambdaConfig.UserMigration = lambdaTriggers.userMigration;
|
|
344
|
-
}
|
|
345
|
-
if (lambdaTriggers.customMessage) {
|
|
346
|
-
LambdaConfig.CustomMessage = lambdaTriggers.customMessage;
|
|
347
|
-
}
|
|
348
|
-
if (lambdaTriggers.customEmailSender) {
|
|
349
|
-
LambdaConfig.CustomEmailSender = lambdaTriggers.customEmailSender;
|
|
350
|
-
}
|
|
351
|
-
if (lambdaTriggers.customSMSSender) {
|
|
352
|
-
LambdaConfig.CustomSMSSender = lambdaTriggers.customSMSSender;
|
|
353
|
-
}
|
|
354
|
-
if (Object.keys(LambdaConfig).length > 0) {
|
|
355
|
-
template.Resources[CognitoUserPoolLogicalId].Properties = {
|
|
356
|
-
...template.Resources[CognitoUserPoolLogicalId].Properties,
|
|
357
|
-
LambdaConfig
|
|
358
|
-
};
|
|
359
|
-
}
|
|
306
|
+
if (lambdaTriggers.preSignUp) LambdaConfig.PreSignUp = lambdaTriggers.preSignUp;
|
|
307
|
+
if (lambdaTriggers.postConfirmation) LambdaConfig.PostConfirmation = lambdaTriggers.postConfirmation;
|
|
308
|
+
if (lambdaTriggers.preAuthentication) LambdaConfig.PreAuthentication = lambdaTriggers.preAuthentication;
|
|
309
|
+
if (lambdaTriggers.postAuthentication) LambdaConfig.PostAuthentication = lambdaTriggers.postAuthentication;
|
|
310
|
+
if (lambdaTriggers.defineAuthChallenge) LambdaConfig.DefineAuthChallenge = lambdaTriggers.defineAuthChallenge;
|
|
311
|
+
if (lambdaTriggers.createAuthChallenge) LambdaConfig.CreateAuthChallenge = lambdaTriggers.createAuthChallenge;
|
|
312
|
+
if (lambdaTriggers.verifyAuthChallengeResponse) LambdaConfig.VerifyAuthChallengeResponse = lambdaTriggers.verifyAuthChallengeResponse;
|
|
313
|
+
if (lambdaTriggers.preTokenGeneration) LambdaConfig.PreTokenGeneration = lambdaTriggers.preTokenGeneration;
|
|
314
|
+
if (lambdaTriggers.userMigration) LambdaConfig.UserMigration = lambdaTriggers.userMigration;
|
|
315
|
+
if (lambdaTriggers.customMessage) LambdaConfig.CustomMessage = lambdaTriggers.customMessage;
|
|
316
|
+
if (lambdaTriggers.customEmailSender) LambdaConfig.CustomEmailSender = lambdaTriggers.customEmailSender;
|
|
317
|
+
if (lambdaTriggers.customSMSSender) LambdaConfig.CustomSMSSender = lambdaTriggers.customSMSSender;
|
|
318
|
+
if (Object.keys(LambdaConfig).length > 0) template.Resources[CognitoUserPoolLogicalId].Properties = {
|
|
319
|
+
...template.Resources[CognitoUserPoolLogicalId].Properties,
|
|
320
|
+
LambdaConfig
|
|
321
|
+
};
|
|
360
322
|
for (const [key, lambdaTrigger] of Object.entries(LambdaConfig)) {
|
|
361
323
|
const permissionLogicalId = `${key}PermissionFor${CognitoUserPoolLogicalId}`.slice(0, 255);
|
|
362
324
|
template.Resources[permissionLogicalId] = {
|
|
@@ -373,10 +335,13 @@ var createAuthTemplate = /* @__PURE__ */__name(({
|
|
|
373
335
|
}
|
|
374
336
|
}
|
|
375
337
|
return template;
|
|
376
|
-
}
|
|
338
|
+
};
|
|
377
339
|
createAuthTemplate.CognitoUserPoolLogicalId = CognitoUserPoolLogicalId;
|
|
378
340
|
createAuthTemplate.CognitoUserPoolClientLogicalId = CognitoUserPoolClientLogicalId;
|
|
379
341
|
createAuthTemplate.CognitoIdentityPoolLogicalId = CognitoIdentityPoolLogicalId;
|
|
380
342
|
createAuthTemplate.IdentityPoolAuthenticatedIAMRoleLogicalId = IdentityPoolAuthenticatedIAMRoleLogicalId;
|
|
381
343
|
createAuthTemplate.IdentityPoolUnauthenticatedIAMRoleLogicalId = IdentityPoolUnauthenticatedIAMRoleLogicalId;
|
|
382
|
-
|
|
344
|
+
|
|
345
|
+
//#endregion
|
|
346
|
+
exports.PASSWORD_MINIMUM_LENGTH = PASSWORD_MINIMUM_LENGTH;
|
|
347
|
+
exports.createAuthTemplate = createAuthTemplate;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
|
|
2
|
+
import { CloudFormationGetAtt, CloudFormationTemplate, Policy } from "@ttoss/cloudformation";
|
|
3
|
+
|
|
4
|
+
//#region src/config.d.ts
|
|
5
|
+
declare const PASSWORD_MINIMUM_LENGTH = 8;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/template.d.ts
|
|
8
|
+
type SchemaAttribute = {
|
|
9
|
+
attributeDataType?: 'Boolean' | 'DateTime' | 'Number' | 'String';
|
|
10
|
+
developerOnlyAttribute?: boolean;
|
|
11
|
+
mutable?: boolean;
|
|
12
|
+
name?: string;
|
|
13
|
+
numberAttributeConstraints?: {
|
|
14
|
+
maxValue?: string;
|
|
15
|
+
minValue?: string;
|
|
16
|
+
};
|
|
17
|
+
required?: boolean;
|
|
18
|
+
stringAttributeConstraints?: {
|
|
19
|
+
maxLength: string;
|
|
20
|
+
minLength: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
type IdentityPoolConfig = {
|
|
24
|
+
enabled?: boolean;
|
|
25
|
+
name?: string;
|
|
26
|
+
allowUnauthenticatedIdentities?: boolean;
|
|
27
|
+
authenticatedRoleArn?: string;
|
|
28
|
+
authenticatedPolicies?: Policy[];
|
|
29
|
+
unauthenticatedRoleArn?: string;
|
|
30
|
+
unauthenticatedPolicies?: Policy[];
|
|
31
|
+
principalTags?: Record<string, string> | boolean;
|
|
32
|
+
};
|
|
33
|
+
type LambdaTriggers = {
|
|
34
|
+
preSignUp?: string | CloudFormationGetAtt;
|
|
35
|
+
postConfirmation?: string | CloudFormationGetAtt;
|
|
36
|
+
preAuthentication?: string | CloudFormationGetAtt;
|
|
37
|
+
postAuthentication?: string | CloudFormationGetAtt;
|
|
38
|
+
defineAuthChallenge?: string | CloudFormationGetAtt;
|
|
39
|
+
createAuthChallenge?: string | CloudFormationGetAtt;
|
|
40
|
+
verifyAuthChallengeResponse?: string | CloudFormationGetAtt;
|
|
41
|
+
preTokenGeneration?: string | CloudFormationGetAtt;
|
|
42
|
+
userMigration?: string | CloudFormationGetAtt;
|
|
43
|
+
customMessage?: string | CloudFormationGetAtt;
|
|
44
|
+
customEmailSender?: string | CloudFormationGetAtt;
|
|
45
|
+
customSMSSender?: string | CloudFormationGetAtt;
|
|
46
|
+
};
|
|
47
|
+
type CreateAuthTemplateParams = {
|
|
48
|
+
autoVerifiedAttributes?: Array<'email' | 'phone_number'> | null | false;
|
|
49
|
+
identityPool?: IdentityPoolConfig;
|
|
50
|
+
schema?: SchemaAttribute[];
|
|
51
|
+
usernameAttributes?: Array<'email' | 'phone_number'> | null;
|
|
52
|
+
lambdaTriggers?: LambdaTriggers;
|
|
53
|
+
deletionProtection?: 'ACTIVE' | 'INACTIVE';
|
|
54
|
+
};
|
|
55
|
+
declare const createAuthTemplate: {
|
|
56
|
+
({
|
|
57
|
+
autoVerifiedAttributes,
|
|
58
|
+
identityPool,
|
|
59
|
+
schema,
|
|
60
|
+
usernameAttributes,
|
|
61
|
+
lambdaTriggers,
|
|
62
|
+
deletionProtection
|
|
63
|
+
}?: CreateAuthTemplateParams): CloudFormationTemplate;
|
|
64
|
+
CognitoUserPoolLogicalId: string;
|
|
65
|
+
CognitoUserPoolClientLogicalId: string;
|
|
66
|
+
CognitoIdentityPoolLogicalId: string;
|
|
67
|
+
IdentityPoolAuthenticatedIAMRoleLogicalId: string;
|
|
68
|
+
IdentityPoolUnauthenticatedIAMRoleLogicalId: string;
|
|
69
|
+
};
|
|
70
|
+
//#endregion
|
|
71
|
+
export { type CloudFormationTemplate, PASSWORD_MINIMUM_LENGTH, createAuthTemplate };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,62 +1,71 @@
|
|
|
1
|
-
import { Policy, CloudFormationGetAtt, CloudFormationTemplate } from '@ttoss/cloudformation';
|
|
2
|
-
export { CloudFormationTemplate } from '@ttoss/cloudformation';
|
|
3
1
|
|
|
4
|
-
|
|
2
|
+
import { CloudFormationGetAtt, CloudFormationTemplate, Policy } from "@ttoss/cloudformation";
|
|
5
3
|
|
|
4
|
+
//#region src/config.d.ts
|
|
5
|
+
declare const PASSWORD_MINIMUM_LENGTH = 8;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/template.d.ts
|
|
6
8
|
type SchemaAttribute = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
attributeDataType?: 'Boolean' | 'DateTime' | 'Number' | 'String';
|
|
10
|
+
developerOnlyAttribute?: boolean;
|
|
11
|
+
mutable?: boolean;
|
|
12
|
+
name?: string;
|
|
13
|
+
numberAttributeConstraints?: {
|
|
14
|
+
maxValue?: string;
|
|
15
|
+
minValue?: string;
|
|
16
|
+
};
|
|
17
|
+
required?: boolean;
|
|
18
|
+
stringAttributeConstraints?: {
|
|
19
|
+
maxLength: string;
|
|
20
|
+
minLength: string;
|
|
21
|
+
};
|
|
20
22
|
};
|
|
21
23
|
type IdentityPoolConfig = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
enabled?: boolean;
|
|
25
|
+
name?: string;
|
|
26
|
+
allowUnauthenticatedIdentities?: boolean;
|
|
27
|
+
authenticatedRoleArn?: string;
|
|
28
|
+
authenticatedPolicies?: Policy[];
|
|
29
|
+
unauthenticatedRoleArn?: string;
|
|
30
|
+
unauthenticatedPolicies?: Policy[];
|
|
31
|
+
principalTags?: Record<string, string> | boolean;
|
|
30
32
|
};
|
|
31
33
|
type LambdaTriggers = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
preSignUp?: string | CloudFormationGetAtt;
|
|
35
|
+
postConfirmation?: string | CloudFormationGetAtt;
|
|
36
|
+
preAuthentication?: string | CloudFormationGetAtt;
|
|
37
|
+
postAuthentication?: string | CloudFormationGetAtt;
|
|
38
|
+
defineAuthChallenge?: string | CloudFormationGetAtt;
|
|
39
|
+
createAuthChallenge?: string | CloudFormationGetAtt;
|
|
40
|
+
verifyAuthChallengeResponse?: string | CloudFormationGetAtt;
|
|
41
|
+
preTokenGeneration?: string | CloudFormationGetAtt;
|
|
42
|
+
userMigration?: string | CloudFormationGetAtt;
|
|
43
|
+
customMessage?: string | CloudFormationGetAtt;
|
|
44
|
+
customEmailSender?: string | CloudFormationGetAtt;
|
|
45
|
+
customSMSSender?: string | CloudFormationGetAtt;
|
|
44
46
|
};
|
|
45
47
|
type CreateAuthTemplateParams = {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
autoVerifiedAttributes?: Array<'email' | 'phone_number'> | null | false;
|
|
49
|
+
identityPool?: IdentityPoolConfig;
|
|
50
|
+
schema?: SchemaAttribute[];
|
|
51
|
+
usernameAttributes?: Array<'email' | 'phone_number'> | null;
|
|
52
|
+
lambdaTriggers?: LambdaTriggers;
|
|
53
|
+
deletionProtection?: 'ACTIVE' | 'INACTIVE';
|
|
52
54
|
};
|
|
53
55
|
declare const createAuthTemplate: {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
({
|
|
57
|
+
autoVerifiedAttributes,
|
|
58
|
+
identityPool,
|
|
59
|
+
schema,
|
|
60
|
+
usernameAttributes,
|
|
61
|
+
lambdaTriggers,
|
|
62
|
+
deletionProtection
|
|
63
|
+
}?: CreateAuthTemplateParams): CloudFormationTemplate;
|
|
64
|
+
CognitoUserPoolLogicalId: string;
|
|
65
|
+
CognitoUserPoolClientLogicalId: string;
|
|
66
|
+
CognitoIdentityPoolLogicalId: string;
|
|
67
|
+
IdentityPoolAuthenticatedIAMRoleLogicalId: string;
|
|
68
|
+
IdentityPoolUnauthenticatedIAMRoleLogicalId: string;
|
|
60
69
|
};
|
|
61
|
-
|
|
62
|
-
export { PASSWORD_MINIMUM_LENGTH, createAuthTemplate };
|
|
70
|
+
//#endregion
|
|
71
|
+
export { type CloudFormationTemplate, PASSWORD_MINIMUM_LENGTH, createAuthTemplate };
|
|
@@ -1,60 +1,24 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
-
|
|
2
|
+
//#region src/config.ts
|
|
3
|
+
const PASSWORD_MINIMUM_LENGTH = 8;
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var __export = (target, all) => {
|
|
13
|
-
for (var name in all) __defProp(target, name, {
|
|
14
|
-
get: all[name],
|
|
15
|
-
enumerable: true
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
var __copyProps = (to, from, except, desc) => {
|
|
19
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
21
|
-
get: () => from[key],
|
|
22
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return to;
|
|
26
|
-
};
|
|
27
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
28
|
-
value: true
|
|
29
|
-
}), mod);
|
|
30
|
-
|
|
31
|
-
// src/index.ts
|
|
32
|
-
var index_exports = {};
|
|
33
|
-
__export(index_exports, {
|
|
34
|
-
PASSWORD_MINIMUM_LENGTH: () => PASSWORD_MINIMUM_LENGTH,
|
|
35
|
-
createAuthTemplate: () => createAuthTemplate
|
|
36
|
-
});
|
|
37
|
-
module.exports = __toCommonJS(index_exports);
|
|
38
|
-
|
|
39
|
-
// src/config.ts
|
|
40
|
-
var PASSWORD_MINIMUM_LENGTH = 8;
|
|
41
|
-
|
|
42
|
-
// src/template.ts
|
|
43
|
-
var CognitoUserPoolLogicalId = "CognitoUserPool";
|
|
44
|
-
var CognitoUserPoolClientLogicalId = "CognitoUserPoolClient";
|
|
45
|
-
var CognitoIdentityPoolLogicalId = "CognitoIdentityPool";
|
|
46
|
-
var IdentityPoolAuthenticatedIAMRoleLogicalId = "IdentityPoolAuthenticatedIAMRole";
|
|
47
|
-
var IdentityPoolUnauthenticatedIAMRoleLogicalId = "IdentityPoolUnauthenticatedIAMRole";
|
|
48
|
-
var DenyStatement = {
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/template.ts
|
|
7
|
+
const CognitoUserPoolLogicalId = "CognitoUserPool";
|
|
8
|
+
const CognitoUserPoolClientLogicalId = "CognitoUserPoolClient";
|
|
9
|
+
const CognitoIdentityPoolLogicalId = "CognitoIdentityPool";
|
|
10
|
+
const IdentityPoolAuthenticatedIAMRoleLogicalId = "IdentityPoolAuthenticatedIAMRole";
|
|
11
|
+
const IdentityPoolUnauthenticatedIAMRoleLogicalId = "IdentityPoolUnauthenticatedIAMRole";
|
|
12
|
+
const DenyStatement = {
|
|
49
13
|
Effect: "Deny",
|
|
50
14
|
Action: ["*"],
|
|
51
15
|
Resource: ["*"]
|
|
52
16
|
};
|
|
53
|
-
|
|
17
|
+
const defaultPrincipalTags = {
|
|
54
18
|
appClientId: "aud",
|
|
55
19
|
userId: "sub"
|
|
56
20
|
};
|
|
57
|
-
|
|
21
|
+
const createAuthTemplate = ({
|
|
58
22
|
autoVerifiedAttributes = ["email"],
|
|
59
23
|
identityPool,
|
|
60
24
|
schema,
|
|
@@ -75,7 +39,7 @@ var createAuthTemplate = /* @__PURE__ */__name(({
|
|
|
75
39
|
AutoVerifiedAttributes,
|
|
76
40
|
Policies: {
|
|
77
41
|
PasswordPolicy: {
|
|
78
|
-
MinimumLength:
|
|
42
|
+
MinimumLength: 8,
|
|
79
43
|
RequireLowercase: false,
|
|
80
44
|
RequireNumbers: false,
|
|
81
45
|
RequireSymbols: false,
|
|
@@ -153,19 +117,15 @@ var createAuthTemplate = /* @__PURE__ */__name(({
|
|
|
153
117
|
if (schema) {
|
|
154
118
|
const Schema = schema.map(attribute => {
|
|
155
119
|
let NumberAttributeConstraints = void 0;
|
|
156
|
-
if (attribute.numberAttributeConstraints) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
};
|
|
161
|
-
}
|
|
120
|
+
if (attribute.numberAttributeConstraints) NumberAttributeConstraints = {
|
|
121
|
+
MaxValue: attribute.numberAttributeConstraints?.maxValue,
|
|
122
|
+
MinValue: attribute.numberAttributeConstraints?.minValue
|
|
123
|
+
};
|
|
162
124
|
let StringAttributeConstraints = void 0;
|
|
163
|
-
if (attribute.stringAttributeConstraints) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
};
|
|
168
|
-
}
|
|
125
|
+
if (attribute.stringAttributeConstraints) StringAttributeConstraints = {
|
|
126
|
+
MaxLength: attribute.stringAttributeConstraints?.maxLength,
|
|
127
|
+
MinLength: attribute.stringAttributeConstraints?.minLength
|
|
128
|
+
};
|
|
169
129
|
return {
|
|
170
130
|
AttributeDataType: attribute.attributeDataType,
|
|
171
131
|
DeveloperOnlyAttribute: attribute.developerOnlyAttribute,
|
|
@@ -199,12 +159,10 @@ var createAuthTemplate = /* @__PURE__ */__name(({
|
|
|
199
159
|
}]
|
|
200
160
|
}
|
|
201
161
|
};
|
|
202
|
-
if (identityPool.name) {
|
|
203
|
-
template.Resources[CognitoIdentityPoolLogicalId].Properties
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
};
|
|
207
|
-
}
|
|
162
|
+
if (identityPool.name) template.Resources[CognitoIdentityPoolLogicalId].Properties = {
|
|
163
|
+
...template.Resources[CognitoIdentityPoolLogicalId].Properties,
|
|
164
|
+
IdentityPoolName: identityPool.name
|
|
165
|
+
};
|
|
208
166
|
template.Resources.CognitoIdentityPoolRoleAttachment = {
|
|
209
167
|
/**
|
|
210
168
|
* https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-identitypoolroleattachment.html
|
|
@@ -255,11 +213,9 @@ var createAuthTemplate = /* @__PURE__ */__name(({
|
|
|
255
213
|
"Fn::GetAtt": [IdentityPoolAuthenticatedIAMRoleLogicalId, "Arn"]
|
|
256
214
|
}
|
|
257
215
|
});
|
|
258
|
-
} else {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
});
|
|
262
|
-
}
|
|
216
|
+
} else Object.assign(template.Resources.CognitoIdentityPoolRoleAttachment.Properties?.Roles, {
|
|
217
|
+
authenticated: identityPool.authenticatedRoleArn
|
|
218
|
+
});
|
|
263
219
|
if (!identityPool.unauthenticatedRoleArn) {
|
|
264
220
|
template.Resources[IdentityPoolUnauthenticatedIAMRoleLogicalId] = {
|
|
265
221
|
Type: "AWS::IAM::Role",
|
|
@@ -298,19 +254,16 @@ var createAuthTemplate = /* @__PURE__ */__name(({
|
|
|
298
254
|
"Fn::GetAtt": [IdentityPoolUnauthenticatedIAMRoleLogicalId, "Arn"]
|
|
299
255
|
}
|
|
300
256
|
});
|
|
301
|
-
} else {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
257
|
+
} else Object.assign(template.Resources.CognitoIdentityPoolRoleAttachment.Properties?.Roles, {
|
|
258
|
+
unauthenticated: identityPool.unauthenticatedRoleArn
|
|
259
|
+
});
|
|
260
|
+
/**
|
|
261
|
+
* https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-identitypoolprincipaltag.html
|
|
262
|
+
*/
|
|
306
263
|
if (identityPool.principalTags || identityPool.principalTags === void 0) {
|
|
307
264
|
const PrincipalTags = (() => {
|
|
308
|
-
if (typeof identityPool.principalTags === "boolean")
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
if (identityPool.principalTags === void 0) {
|
|
312
|
-
return defaultPrincipalTags;
|
|
313
|
-
}
|
|
265
|
+
if (typeof identityPool.principalTags === "boolean") return defaultPrincipalTags;
|
|
266
|
+
if (identityPool.principalTags === void 0) return defaultPrincipalTags;
|
|
314
267
|
return identityPool.principalTags;
|
|
315
268
|
})();
|
|
316
269
|
template.Resources.CognitoIdentityPoolPrincipalTag = {
|
|
@@ -346,48 +299,22 @@ var createAuthTemplate = /* @__PURE__ */__name(({
|
|
|
346
299
|
}
|
|
347
300
|
if (lambdaTriggers) {
|
|
348
301
|
const LambdaConfig = {};
|
|
349
|
-
if (lambdaTriggers.preSignUp)
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
if (lambdaTriggers.
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
if (lambdaTriggers.
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
if (lambdaTriggers.
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
LambdaConfig.CreateAuthChallenge = lambdaTriggers.createAuthChallenge;
|
|
366
|
-
}
|
|
367
|
-
if (lambdaTriggers.verifyAuthChallengeResponse) {
|
|
368
|
-
LambdaConfig.VerifyAuthChallengeResponse = lambdaTriggers.verifyAuthChallengeResponse;
|
|
369
|
-
}
|
|
370
|
-
if (lambdaTriggers.preTokenGeneration) {
|
|
371
|
-
LambdaConfig.PreTokenGeneration = lambdaTriggers.preTokenGeneration;
|
|
372
|
-
}
|
|
373
|
-
if (lambdaTriggers.userMigration) {
|
|
374
|
-
LambdaConfig.UserMigration = lambdaTriggers.userMigration;
|
|
375
|
-
}
|
|
376
|
-
if (lambdaTriggers.customMessage) {
|
|
377
|
-
LambdaConfig.CustomMessage = lambdaTriggers.customMessage;
|
|
378
|
-
}
|
|
379
|
-
if (lambdaTriggers.customEmailSender) {
|
|
380
|
-
LambdaConfig.CustomEmailSender = lambdaTriggers.customEmailSender;
|
|
381
|
-
}
|
|
382
|
-
if (lambdaTriggers.customSMSSender) {
|
|
383
|
-
LambdaConfig.CustomSMSSender = lambdaTriggers.customSMSSender;
|
|
384
|
-
}
|
|
385
|
-
if (Object.keys(LambdaConfig).length > 0) {
|
|
386
|
-
template.Resources[CognitoUserPoolLogicalId].Properties = {
|
|
387
|
-
...template.Resources[CognitoUserPoolLogicalId].Properties,
|
|
388
|
-
LambdaConfig
|
|
389
|
-
};
|
|
390
|
-
}
|
|
302
|
+
if (lambdaTriggers.preSignUp) LambdaConfig.PreSignUp = lambdaTriggers.preSignUp;
|
|
303
|
+
if (lambdaTriggers.postConfirmation) LambdaConfig.PostConfirmation = lambdaTriggers.postConfirmation;
|
|
304
|
+
if (lambdaTriggers.preAuthentication) LambdaConfig.PreAuthentication = lambdaTriggers.preAuthentication;
|
|
305
|
+
if (lambdaTriggers.postAuthentication) LambdaConfig.PostAuthentication = lambdaTriggers.postAuthentication;
|
|
306
|
+
if (lambdaTriggers.defineAuthChallenge) LambdaConfig.DefineAuthChallenge = lambdaTriggers.defineAuthChallenge;
|
|
307
|
+
if (lambdaTriggers.createAuthChallenge) LambdaConfig.CreateAuthChallenge = lambdaTriggers.createAuthChallenge;
|
|
308
|
+
if (lambdaTriggers.verifyAuthChallengeResponse) LambdaConfig.VerifyAuthChallengeResponse = lambdaTriggers.verifyAuthChallengeResponse;
|
|
309
|
+
if (lambdaTriggers.preTokenGeneration) LambdaConfig.PreTokenGeneration = lambdaTriggers.preTokenGeneration;
|
|
310
|
+
if (lambdaTriggers.userMigration) LambdaConfig.UserMigration = lambdaTriggers.userMigration;
|
|
311
|
+
if (lambdaTriggers.customMessage) LambdaConfig.CustomMessage = lambdaTriggers.customMessage;
|
|
312
|
+
if (lambdaTriggers.customEmailSender) LambdaConfig.CustomEmailSender = lambdaTriggers.customEmailSender;
|
|
313
|
+
if (lambdaTriggers.customSMSSender) LambdaConfig.CustomSMSSender = lambdaTriggers.customSMSSender;
|
|
314
|
+
if (Object.keys(LambdaConfig).length > 0) template.Resources[CognitoUserPoolLogicalId].Properties = {
|
|
315
|
+
...template.Resources[CognitoUserPoolLogicalId].Properties,
|
|
316
|
+
LambdaConfig
|
|
317
|
+
};
|
|
391
318
|
for (const [key, lambdaTrigger] of Object.entries(LambdaConfig)) {
|
|
392
319
|
const permissionLogicalId = `${key}PermissionFor${CognitoUserPoolLogicalId}`.slice(0, 255);
|
|
393
320
|
template.Resources[permissionLogicalId] = {
|
|
@@ -404,14 +331,12 @@ var createAuthTemplate = /* @__PURE__ */__name(({
|
|
|
404
331
|
}
|
|
405
332
|
}
|
|
406
333
|
return template;
|
|
407
|
-
}
|
|
334
|
+
};
|
|
408
335
|
createAuthTemplate.CognitoUserPoolLogicalId = CognitoUserPoolLogicalId;
|
|
409
336
|
createAuthTemplate.CognitoUserPoolClientLogicalId = CognitoUserPoolClientLogicalId;
|
|
410
337
|
createAuthTemplate.CognitoIdentityPoolLogicalId = CognitoIdentityPoolLogicalId;
|
|
411
338
|
createAuthTemplate.IdentityPoolAuthenticatedIAMRoleLogicalId = IdentityPoolAuthenticatedIAMRoleLogicalId;
|
|
412
339
|
createAuthTemplate.IdentityPoolUnauthenticatedIAMRoleLogicalId = IdentityPoolUnauthenticatedIAMRoleLogicalId;
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
createAuthTemplate
|
|
417
|
-
});
|
|
340
|
+
|
|
341
|
+
//#endregion
|
|
342
|
+
export { PASSWORD_MINIMUM_LENGTH, createAuthTemplate };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/cloud-auth",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.34",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/ttoss/ttoss.git",
|
|
@@ -10,30 +10,30 @@
|
|
|
10
10
|
"sideEffects": false,
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"import": "./dist/
|
|
14
|
-
"require": "./dist/index.
|
|
15
|
-
"types": "./dist/index.d.
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"require": "./dist/index.cjs",
|
|
15
|
+
"types": "./dist/index.d.mts"
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@ttoss/cloudformation": "^0.13.
|
|
22
|
+
"@ttoss/cloudformation": "^0.13.6"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/jest": "^30.0.0",
|
|
26
26
|
"jest": "^30.3.0",
|
|
27
|
-
"
|
|
27
|
+
"tsdown": "^0.22.0",
|
|
28
28
|
"typescript": "~6.0.3",
|
|
29
|
-
"@ttoss/config": "^1.37.
|
|
29
|
+
"@ttoss/config": "^1.37.13"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public",
|
|
33
33
|
"provenance": true
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
|
-
"build": "
|
|
36
|
+
"build": "tsdown",
|
|
37
37
|
"test": "jest"
|
|
38
38
|
}
|
|
39
39
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Policy, CloudFormationGetAtt, CloudFormationTemplate } from '@ttoss/cloudformation';
|
|
2
|
-
export { CloudFormationTemplate } from '@ttoss/cloudformation';
|
|
3
|
-
|
|
4
|
-
declare const PASSWORD_MINIMUM_LENGTH = 8;
|
|
5
|
-
|
|
6
|
-
type SchemaAttribute = {
|
|
7
|
-
attributeDataType?: 'Boolean' | 'DateTime' | 'Number' | 'String';
|
|
8
|
-
developerOnlyAttribute?: boolean;
|
|
9
|
-
mutable?: boolean;
|
|
10
|
-
name?: string;
|
|
11
|
-
numberAttributeConstraints?: {
|
|
12
|
-
maxValue?: string;
|
|
13
|
-
minValue?: string;
|
|
14
|
-
};
|
|
15
|
-
required?: boolean;
|
|
16
|
-
stringAttributeConstraints?: {
|
|
17
|
-
maxLength: string;
|
|
18
|
-
minLength: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
type IdentityPoolConfig = {
|
|
22
|
-
enabled?: boolean;
|
|
23
|
-
name?: string;
|
|
24
|
-
allowUnauthenticatedIdentities?: boolean;
|
|
25
|
-
authenticatedRoleArn?: string;
|
|
26
|
-
authenticatedPolicies?: Policy[];
|
|
27
|
-
unauthenticatedRoleArn?: string;
|
|
28
|
-
unauthenticatedPolicies?: Policy[];
|
|
29
|
-
principalTags?: Record<string, string> | boolean;
|
|
30
|
-
};
|
|
31
|
-
type LambdaTriggers = {
|
|
32
|
-
preSignUp?: string | CloudFormationGetAtt;
|
|
33
|
-
postConfirmation?: string | CloudFormationGetAtt;
|
|
34
|
-
preAuthentication?: string | CloudFormationGetAtt;
|
|
35
|
-
postAuthentication?: string | CloudFormationGetAtt;
|
|
36
|
-
defineAuthChallenge?: string | CloudFormationGetAtt;
|
|
37
|
-
createAuthChallenge?: string | CloudFormationGetAtt;
|
|
38
|
-
verifyAuthChallengeResponse?: string | CloudFormationGetAtt;
|
|
39
|
-
preTokenGeneration?: string | CloudFormationGetAtt;
|
|
40
|
-
userMigration?: string | CloudFormationGetAtt;
|
|
41
|
-
customMessage?: string | CloudFormationGetAtt;
|
|
42
|
-
customEmailSender?: string | CloudFormationGetAtt;
|
|
43
|
-
customSMSSender?: string | CloudFormationGetAtt;
|
|
44
|
-
};
|
|
45
|
-
type CreateAuthTemplateParams = {
|
|
46
|
-
autoVerifiedAttributes?: Array<'email' | 'phone_number'> | null | false;
|
|
47
|
-
identityPool?: IdentityPoolConfig;
|
|
48
|
-
schema?: SchemaAttribute[];
|
|
49
|
-
usernameAttributes?: Array<'email' | 'phone_number'> | null;
|
|
50
|
-
lambdaTriggers?: LambdaTriggers;
|
|
51
|
-
deletionProtection?: 'ACTIVE' | 'INACTIVE';
|
|
52
|
-
};
|
|
53
|
-
declare const createAuthTemplate: {
|
|
54
|
-
({ autoVerifiedAttributes, identityPool, schema, usernameAttributes, lambdaTriggers, deletionProtection, }?: CreateAuthTemplateParams): CloudFormationTemplate;
|
|
55
|
-
CognitoUserPoolLogicalId: string;
|
|
56
|
-
CognitoUserPoolClientLogicalId: string;
|
|
57
|
-
CognitoIdentityPoolLogicalId: string;
|
|
58
|
-
IdentityPoolAuthenticatedIAMRoleLogicalId: string;
|
|
59
|
-
IdentityPoolUnauthenticatedIAMRoleLogicalId: string;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export { PASSWORD_MINIMUM_LENGTH, createAuthTemplate };
|