@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.
@@ -1,29 +1,28 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- var __defProp = Object.defineProperty;
3
- var __name = (target, value) => __defProp(target, "name", {
4
- value,
5
- configurable: true
2
+ Object.defineProperty(exports, Symbol.toStringTag, {
3
+ value: 'Module'
6
4
  });
7
5
 
8
- // src/config.ts
9
- var PASSWORD_MINIMUM_LENGTH = 8;
6
+ //#region src/config.ts
7
+ const PASSWORD_MINIMUM_LENGTH = 8;
10
8
 
11
- // src/template.ts
12
- var CognitoUserPoolLogicalId = "CognitoUserPool";
13
- var CognitoUserPoolClientLogicalId = "CognitoUserPoolClient";
14
- var CognitoIdentityPoolLogicalId = "CognitoIdentityPool";
15
- var IdentityPoolAuthenticatedIAMRoleLogicalId = "IdentityPoolAuthenticatedIAMRole";
16
- var IdentityPoolUnauthenticatedIAMRoleLogicalId = "IdentityPoolUnauthenticatedIAMRole";
17
- var DenyStatement = {
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
- var defaultPrincipalTags = {
21
+ const defaultPrincipalTags = {
23
22
  appClientId: "aud",
24
23
  userId: "sub"
25
24
  };
26
- var createAuthTemplate = /* @__PURE__ */__name(({
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: PASSWORD_MINIMUM_LENGTH,
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
- NumberAttributeConstraints = {
127
- MaxValue: attribute.numberAttributeConstraints?.maxValue,
128
- MinValue: attribute.numberAttributeConstraints?.minValue
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
- StringAttributeConstraints = {
134
- MaxLength: attribute.stringAttributeConstraints?.maxLength,
135
- MinLength: attribute.stringAttributeConstraints?.minLength
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
- ...template.Resources[CognitoIdentityPoolLogicalId].Properties,
174
- IdentityPoolName: identityPool.name
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
- Object.assign(template.Resources.CognitoIdentityPoolRoleAttachment.Properties?.Roles, {
229
- authenticated: identityPool.authenticatedRoleArn
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
- Object.assign(template.Resources.CognitoIdentityPoolRoleAttachment.Properties?.Roles, {
272
- unauthenticated: identityPool.unauthenticatedRoleArn
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
- return defaultPrincipalTags;
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
- LambdaConfig.PreSignUp = lambdaTriggers.preSignUp;
320
- }
321
- if (lambdaTriggers.postConfirmation) {
322
- LambdaConfig.PostConfirmation = lambdaTriggers.postConfirmation;
323
- }
324
- if (lambdaTriggers.preAuthentication) {
325
- LambdaConfig.PreAuthentication = lambdaTriggers.preAuthentication;
326
- }
327
- if (lambdaTriggers.postAuthentication) {
328
- LambdaConfig.PostAuthentication = lambdaTriggers.postAuthentication;
329
- }
330
- if (lambdaTriggers.defineAuthChallenge) {
331
- LambdaConfig.DefineAuthChallenge = lambdaTriggers.defineAuthChallenge;
332
- }
333
- if (lambdaTriggers.createAuthChallenge) {
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
- }, "createAuthTemplate");
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
- export { PASSWORD_MINIMUM_LENGTH, createAuthTemplate };
344
+
345
+ //#endregion
346
+ exports.PASSWORD_MINIMUM_LENGTH = PASSWORD_MINIMUM_LENGTH;
347
+ exports.createAuthTemplate = createAuthTemplate;
@@ -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
- declare const PASSWORD_MINIMUM_LENGTH = 8;
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
- 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
- };
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
- 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;
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
- 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;
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
- 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';
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
- ({ autoVerifiedAttributes, identityPool, schema, usernameAttributes, lambdaTriggers, deletionProtection, }?: CreateAuthTemplateParams): CloudFormationTemplate;
55
- CognitoUserPoolLogicalId: string;
56
- CognitoUserPoolClientLogicalId: string;
57
- CognitoIdentityPoolLogicalId: string;
58
- IdentityPoolAuthenticatedIAMRoleLogicalId: string;
59
- IdentityPoolUnauthenticatedIAMRoleLogicalId: string;
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
- "use strict";
2
+ //#region src/config.ts
3
+ const PASSWORD_MINIMUM_LENGTH = 8;
3
4
 
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __name = (target, value) => __defProp(target, "name", {
9
- value,
10
- configurable: true
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
- var defaultPrincipalTags = {
17
+ const defaultPrincipalTags = {
54
18
  appClientId: "aud",
55
19
  userId: "sub"
56
20
  };
57
- var createAuthTemplate = /* @__PURE__ */__name(({
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: PASSWORD_MINIMUM_LENGTH,
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
- NumberAttributeConstraints = {
158
- MaxValue: attribute.numberAttributeConstraints?.maxValue,
159
- MinValue: attribute.numberAttributeConstraints?.minValue
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
- StringAttributeConstraints = {
165
- MaxLength: attribute.stringAttributeConstraints?.maxLength,
166
- MinLength: attribute.stringAttributeConstraints?.minLength
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
- ...template.Resources[CognitoIdentityPoolLogicalId].Properties,
205
- IdentityPoolName: identityPool.name
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
- Object.assign(template.Resources.CognitoIdentityPoolRoleAttachment.Properties?.Roles, {
260
- authenticated: identityPool.authenticatedRoleArn
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
- Object.assign(template.Resources.CognitoIdentityPoolRoleAttachment.Properties?.Roles, {
303
- unauthenticated: identityPool.unauthenticatedRoleArn
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
- return defaultPrincipalTags;
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
- LambdaConfig.PreSignUp = lambdaTriggers.preSignUp;
351
- }
352
- if (lambdaTriggers.postConfirmation) {
353
- LambdaConfig.PostConfirmation = lambdaTriggers.postConfirmation;
354
- }
355
- if (lambdaTriggers.preAuthentication) {
356
- LambdaConfig.PreAuthentication = lambdaTriggers.preAuthentication;
357
- }
358
- if (lambdaTriggers.postAuthentication) {
359
- LambdaConfig.PostAuthentication = lambdaTriggers.postAuthentication;
360
- }
361
- if (lambdaTriggers.defineAuthChallenge) {
362
- LambdaConfig.DefineAuthChallenge = lambdaTriggers.defineAuthChallenge;
363
- }
364
- if (lambdaTriggers.createAuthChallenge) {
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
- }, "createAuthTemplate");
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
- // Annotate the CommonJS export names for ESM import in node:
414
- 0 && (module.exports = {
415
- PASSWORD_MINIMUM_LENGTH,
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.32",
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/esm/index.js",
14
- "require": "./dist/index.js",
15
- "types": "./dist/index.d.ts"
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.4"
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
- "tsup": "^8.5.1",
27
+ "tsdown": "^0.22.0",
28
28
  "typescript": "~6.0.3",
29
- "@ttoss/config": "^1.37.12"
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": "tsup",
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 };