@ttoss/cloud-auth 0.3.1 → 0.5.0

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.
@@ -0,0 +1,237 @@
1
+ TN:
2
+ SF:src/config.ts
3
+ FNF:0
4
+ FNH:0
5
+ DA:1,1
6
+ LF:1
7
+ LH:1
8
+ BRF:0
9
+ BRH:0
10
+ end_of_record
11
+ TN:
12
+ SF:src/index.ts
13
+ FNF:0
14
+ FNH:0
15
+ DA:1,1
16
+ DA:2,1
17
+ LF:2
18
+ LH:2
19
+ BRDA:1,0,0,2
20
+ BRDA:1,1,0,1
21
+ BRDA:1,2,0,0
22
+ BRDA:1,3,0,1
23
+ BRDA:1,4,0,0
24
+ BRDA:1,5,0,0
25
+ BRDA:1,6,0,1
26
+ BRF:7
27
+ BRH:4
28
+ end_of_record
29
+ TN:
30
+ SF:src/template.ts
31
+ FN:16,createAuthTemplate
32
+ FNF:1
33
+ FNH:1
34
+ FNDA:12,createAuthTemplate
35
+ DA:1,1
36
+ DA:2,1
37
+ DA:3,1
38
+ DA:4,1
39
+ DA:5,1
40
+ DA:6,1
41
+ DA:7,1
42
+ DA:8,1
43
+ DA:9,1
44
+ DA:10,1
45
+ DA:11,1
46
+ DA:12,1
47
+ DA:13,1
48
+ DA:14,1
49
+ DA:15,1
50
+ DA:16,1
51
+ DA:17,12
52
+ DA:18,12
53
+ DA:19,12
54
+ DA:20,12
55
+ DA:21,12
56
+ DA:22,12
57
+ DA:23,12
58
+ DA:24,12
59
+ DA:25,12
60
+ DA:26,12
61
+ DA:27,12
62
+ DA:28,12
63
+ DA:29,12
64
+ DA:30,12
65
+ DA:31,12
66
+ DA:32,12
67
+ DA:33,12
68
+ DA:34,12
69
+ DA:35,12
70
+ DA:36,12
71
+ DA:37,12
72
+ DA:38,12
73
+ DA:39,12
74
+ DA:40,12
75
+ DA:41,12
76
+ DA:42,12
77
+ DA:43,12
78
+ DA:44,12
79
+ DA:45,12
80
+ DA:46,12
81
+ DA:47,12
82
+ DA:48,12
83
+ DA:49,12
84
+ DA:50,12
85
+ DA:51,9
86
+ DA:52,12
87
+ DA:53,12
88
+ DA:54,12
89
+ DA:55,12
90
+ DA:56,12
91
+ DA:57,12
92
+ DA:58,12
93
+ DA:59,12
94
+ DA:60,12
95
+ DA:61,12
96
+ DA:62,12
97
+ DA:63,12
98
+ DA:64,12
99
+ DA:65,12
100
+ DA:66,12
101
+ DA:67,12
102
+ DA:68,12
103
+ DA:69,12
104
+ DA:70,12
105
+ DA:71,12
106
+ DA:72,12
107
+ DA:73,12
108
+ DA:74,12
109
+ DA:75,12
110
+ DA:76,12
111
+ DA:77,12
112
+ DA:78,12
113
+ DA:79,12
114
+ DA:80,12
115
+ DA:81,12
116
+ DA:82,12
117
+ DA:83,12
118
+ DA:84,12
119
+ DA:85,12
120
+ DA:86,12
121
+ DA:87,12
122
+ DA:88,12
123
+ DA:89,12
124
+ DA:90,12
125
+ DA:91,12
126
+ DA:92,12
127
+ DA:93,12
128
+ DA:94,12
129
+ DA:95,12
130
+ DA:96,12
131
+ DA:97,12
132
+ DA:98,12
133
+ DA:99,12
134
+ DA:100,12
135
+ DA:101,12
136
+ DA:102,12
137
+ DA:103,12
138
+ DA:104,12
139
+ DA:105,12
140
+ DA:106,12
141
+ DA:107,12
142
+ DA:108,12
143
+ DA:109,12
144
+ DA:110,12
145
+ DA:111,12
146
+ DA:112,12
147
+ DA:113,12
148
+ DA:114,12
149
+ DA:115,12
150
+ DA:116,12
151
+ DA:117,12
152
+ DA:118,12
153
+ DA:119,12
154
+ DA:120,12
155
+ DA:121,12
156
+ DA:122,12
157
+ DA:123,12
158
+ DA:124,12
159
+ DA:125,12
160
+ DA:126,12
161
+ DA:127,12
162
+ DA:128,12
163
+ DA:129,12
164
+ DA:130,11
165
+ DA:131,11
166
+ DA:132,11
167
+ DA:133,11
168
+ DA:134,11
169
+ DA:135,11
170
+ DA:136,11
171
+ DA:137,11
172
+ DA:138,11
173
+ DA:139,11
174
+ DA:140,11
175
+ DA:141,11
176
+ DA:142,11
177
+ DA:143,11
178
+ DA:144,11
179
+ DA:145,11
180
+ DA:146,11
181
+ DA:147,11
182
+ DA:148,11
183
+ DA:149,11
184
+ DA:150,11
185
+ DA:151,1
186
+ DA:152,1
187
+ DA:153,1
188
+ DA:154,1
189
+ DA:155,1
190
+ DA:156,1
191
+ DA:157,1
192
+ DA:158,1
193
+ DA:159,1
194
+ DA:160,1
195
+ DA:161,1
196
+ DA:162,1
197
+ DA:163,1
198
+ DA:164,11
199
+ DA:165,11
200
+ DA:166,0
201
+ DA:167,0
202
+ DA:168,11
203
+ DA:169,11
204
+ DA:170,11
205
+ DA:171,11
206
+ DA:172,11
207
+ DA:173,11
208
+ DA:174,11
209
+ DA:175,11
210
+ DA:176,11
211
+ DA:177,11
212
+ DA:178,11
213
+ DA:179,11
214
+ DA:180,11
215
+ DA:181,11
216
+ DA:182,11
217
+ DA:183,11
218
+ DA:184,12
219
+ DA:185,12
220
+ DA:186,12
221
+ DA:187,1
222
+ DA:188,1
223
+ DA:189,1
224
+ DA:190,1
225
+ DA:191,1
226
+ LF:191
227
+ LH:189
228
+ BRDA:16,0,0,12
229
+ BRDA:50,1,0,10
230
+ BRDA:51,2,0,9
231
+ BRDA:52,3,0,3
232
+ BRDA:129,4,0,11
233
+ BRDA:150,5,0,1
234
+ BRDA:165,6,0,0
235
+ BRF:7
236
+ BRH:6
237
+ end_of_record
package/dist/esm/index.js CHANGED
@@ -7,13 +7,21 @@ var PASSWORD_MINIMUM_LENGTH = 8;
7
7
  var CognitoUserPoolLogicalId = "CognitoUserPool";
8
8
  var CognitoUserPoolClientLogicalId = "CognitoUserPoolClient";
9
9
  var CognitoIdentityPoolLogicalId = "CognitoIdentityPool";
10
- var createAuthTemplate = () => {
10
+ var createAuthTemplate = ({
11
+ autoVerifiedAttributes = ["email"],
12
+ identityPool = true,
13
+ roles,
14
+ schema,
15
+ usernameAttributes = ["email"]
16
+ } = {}) => {
17
+ const AutoVerifiedAttributes = Array.isArray(autoVerifiedAttributes) && autoVerifiedAttributes.length > 0 ? autoVerifiedAttributes : [];
11
18
  const template = {
19
+ AWSTemplateFormatVersion: "2010-09-09",
12
20
  Resources: {
13
21
  [CognitoUserPoolLogicalId]: {
14
22
  Type: "AWS::Cognito::UserPool",
15
23
  Properties: {
16
- AutoVerifiedAttributes: ["email"],
24
+ AutoVerifiedAttributes,
17
25
  Policies: {
18
26
  PasswordPolicy: {
19
27
  MinimumLength: PASSWORD_MINIMUM_LENGTH,
@@ -24,7 +32,8 @@ var createAuthTemplate = () => {
24
32
  TemporaryPasswordValidityDays: 30
25
33
  }
26
34
  },
27
- UsernameAttributes: ["email"],
35
+ Schema: schema,
36
+ UsernameAttributes: usernameAttributes,
28
37
  UsernameConfiguration: {
29
38
  CaseSensitive: false
30
39
  },
@@ -41,22 +50,6 @@ var createAuthTemplate = () => {
41
50
  Ref: "CognitoUserPool"
42
51
  }
43
52
  }
44
- },
45
- [CognitoIdentityPoolLogicalId]: {
46
- Type: "AWS::Cognito::IdentityPool",
47
- Properties: {
48
- AllowUnauthenticatedIdentities: true,
49
- CognitoIdentityProviders: [
50
- {
51
- ClientId: {
52
- Ref: CognitoUserPoolClientLogicalId
53
- },
54
- ProviderName: {
55
- "Fn::GetAtt": [CognitoUserPoolLogicalId, "ProviderName"]
56
- }
57
- }
58
- ]
59
- }
60
53
  }
61
54
  },
62
55
  Outputs: {
@@ -92,25 +85,60 @@ var createAuthTemplate = () => {
92
85
  "Fn::Join": [":", [{ Ref: "AWS::StackName" }, "AppClientId"]]
93
86
  }
94
87
  }
95
- },
96
- IdentityPoolId: {
97
- Description: "You use this value on Amplify Auth `identityPoolId`.",
98
- Value: {
99
- Ref: CognitoIdentityPoolLogicalId
100
- },
101
- Export: {
102
- Name: {
103
- "Fn::Join": [
104
- ":",
105
- [{ Ref: "AWS::StackName" }, "CognitoIdentityPoolId"]
106
- ]
107
- }
108
- }
109
88
  }
110
89
  }
111
90
  };
91
+ if (identityPool) {
92
+ template.Resources[CognitoIdentityPoolLogicalId] = {
93
+ Type: "AWS::Cognito::IdentityPool",
94
+ Properties: {
95
+ AllowUnauthenticatedIdentities: true,
96
+ CognitoIdentityProviders: [
97
+ {
98
+ ClientId: {
99
+ Ref: CognitoUserPoolClientLogicalId
100
+ },
101
+ ProviderName: {
102
+ "Fn::GetAtt": [CognitoUserPoolLogicalId, "ProviderName"]
103
+ }
104
+ }
105
+ ]
106
+ }
107
+ };
108
+ if (roles) {
109
+ template.Resources.CognitoIdentityPoolRoleAttachment = {
110
+ Type: "AWS::Cognito::IdentityPoolRoleAttachment",
111
+ Properties: {
112
+ IdentityPoolId: {
113
+ Ref: CognitoIdentityPoolLogicalId
114
+ },
115
+ Roles: roles
116
+ }
117
+ };
118
+ }
119
+ if (!template.Outputs) {
120
+ template.Outputs = {};
121
+ }
122
+ template.Outputs.IdentityPoolId = {
123
+ Description: "You use this value on Amplify Auth `identityPoolId`.",
124
+ Value: {
125
+ Ref: CognitoIdentityPoolLogicalId
126
+ },
127
+ Export: {
128
+ Name: {
129
+ "Fn::Join": [
130
+ ":",
131
+ [{ Ref: "AWS::StackName" }, "CognitoIdentityPoolId"]
132
+ ]
133
+ }
134
+ }
135
+ };
136
+ }
112
137
  return template;
113
138
  };
139
+ createAuthTemplate.CognitoUserPoolLogicalId = CognitoUserPoolLogicalId;
140
+ createAuthTemplate.CognitoUserPoolClientLogicalId = CognitoUserPoolClientLogicalId;
141
+ createAuthTemplate.CognitoIdentityPoolLogicalId = CognitoIdentityPoolLogicalId;
114
142
  export {
115
143
  PASSWORD_MINIMUM_LENGTH,
116
144
  createAuthTemplate
package/dist/index.d.ts CHANGED
@@ -1,111 +1,41 @@
1
+ import { CloudFormationTemplate } from '@ttoss/cloudformation';
2
+
1
3
  declare const PASSWORD_MINIMUM_LENGTH = 8;
2
4
 
3
- declare const createAuthTemplate: () => {
4
- Resources: {
5
- CognitoUserPool: {
6
- Type: string;
7
- Properties: {
8
- AutoVerifiedAttributes: string[];
9
- Policies: {
10
- PasswordPolicy: {
11
- MinimumLength: number;
12
- RequireLowercase: boolean;
13
- RequireNumbers: boolean;
14
- RequireSymbols: boolean;
15
- RequireUppercase: boolean;
16
- TemporaryPasswordValidityDays: number;
17
- };
18
- };
19
- UsernameAttributes: string[];
20
- UsernameConfiguration: {
21
- CaseSensitive: boolean;
22
- };
23
- UserPoolName: {
24
- Ref: string;
25
- };
26
- };
27
- };
28
- CognitoUserPoolClient: {
29
- Type: string;
30
- Properties: {
31
- SupportedIdentityProviders: string[];
32
- UserPoolId: {
33
- Ref: string;
34
- };
35
- };
36
- };
5
+ type Role = string | {
6
+ 'Fn::ImportValue': string;
7
+ };
8
+ declare const createAuthTemplate: {
9
+ ({ autoVerifiedAttributes, identityPool, roles, schema, usernameAttributes, }?: {
10
+ autoVerifiedAttributes?: false | ("email" | "phone_number")[] | null | undefined;
11
+ identityPool?: boolean | undefined;
12
+ roles?: {
13
+ authenticated?: Role | undefined;
14
+ unauthenticated?: Role | undefined;
15
+ } | undefined;
37
16
  /**
38
- * https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-identitypool.html
17
+ * https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cognito-userpool-schemaattribute.html
39
18
  */
40
- CognitoIdentityPool: {
41
- Type: string;
42
- Properties: {
43
- AllowUnauthenticatedIdentities: boolean;
44
- CognitoIdentityProviders: {
45
- ClientId: {
46
- Ref: string;
47
- };
48
- ProviderName: {
49
- 'Fn::GetAtt': string[];
50
- };
51
- }[];
52
- };
53
- };
54
- };
55
- Outputs: {
56
- Region: {
57
- Description: string;
58
- Value: {
59
- Ref: string;
60
- };
61
- Export: {
62
- Name: {
63
- 'Fn::Join': (string | (string | {
64
- Ref: string;
65
- })[])[];
66
- };
67
- };
68
- };
69
- UserPoolId: {
70
- Description: string;
71
- Value: {
72
- Ref: string;
73
- };
74
- Export: {
75
- Name: {
76
- 'Fn::Join': (string | (string | {
77
- Ref: string;
78
- })[])[];
79
- };
80
- };
81
- };
82
- AppClientId: {
83
- Description: string;
84
- Value: {
85
- Ref: string;
86
- };
87
- Export: {
88
- Name: {
89
- 'Fn::Join': (string | (string | {
90
- Ref: string;
91
- })[])[];
92
- };
93
- };
94
- };
95
- IdentityPoolId: {
96
- Description: string;
97
- Value: {
98
- Ref: string;
99
- };
100
- Export: {
101
- Name: {
102
- 'Fn::Join': (string | (string | {
103
- Ref: string;
104
- })[])[];
105
- };
106
- };
107
- };
108
- };
19
+ schema?: {
20
+ AttributeDataType?: "Boolean" | "DateTime" | "Number" | "String" | undefined;
21
+ DeveloperOnlyAttribute?: boolean | undefined;
22
+ Mutable?: boolean | undefined;
23
+ Name?: string | undefined;
24
+ NumberAttributeConstraints?: {
25
+ MaxValue?: string | undefined;
26
+ MinValue?: string | undefined;
27
+ } | undefined;
28
+ Required?: boolean | undefined;
29
+ StringAttributeConstraints?: {
30
+ MaxLength: string;
31
+ MinLength: string;
32
+ } | undefined;
33
+ }[] | undefined;
34
+ usernameAttributes?: ("email" | "phone_number")[] | null | undefined;
35
+ }): CloudFormationTemplate;
36
+ CognitoUserPoolLogicalId: string;
37
+ CognitoUserPoolClientLogicalId: string;
38
+ CognitoIdentityPoolLogicalId: string;
109
39
  };
110
40
 
111
41
  export { PASSWORD_MINIMUM_LENGTH, createAuthTemplate };
package/dist/index.js CHANGED
@@ -33,13 +33,21 @@ var PASSWORD_MINIMUM_LENGTH = 8;
33
33
  var CognitoUserPoolLogicalId = "CognitoUserPool";
34
34
  var CognitoUserPoolClientLogicalId = "CognitoUserPoolClient";
35
35
  var CognitoIdentityPoolLogicalId = "CognitoIdentityPool";
36
- var createAuthTemplate = () => {
36
+ var createAuthTemplate = ({
37
+ autoVerifiedAttributes = ["email"],
38
+ identityPool = true,
39
+ roles,
40
+ schema,
41
+ usernameAttributes = ["email"]
42
+ } = {}) => {
43
+ const AutoVerifiedAttributes = Array.isArray(autoVerifiedAttributes) && autoVerifiedAttributes.length > 0 ? autoVerifiedAttributes : [];
37
44
  const template = {
45
+ AWSTemplateFormatVersion: "2010-09-09",
38
46
  Resources: {
39
47
  [CognitoUserPoolLogicalId]: {
40
48
  Type: "AWS::Cognito::UserPool",
41
49
  Properties: {
42
- AutoVerifiedAttributes: ["email"],
50
+ AutoVerifiedAttributes,
43
51
  Policies: {
44
52
  PasswordPolicy: {
45
53
  MinimumLength: PASSWORD_MINIMUM_LENGTH,
@@ -50,7 +58,8 @@ var createAuthTemplate = () => {
50
58
  TemporaryPasswordValidityDays: 30
51
59
  }
52
60
  },
53
- UsernameAttributes: ["email"],
61
+ Schema: schema,
62
+ UsernameAttributes: usernameAttributes,
54
63
  UsernameConfiguration: {
55
64
  CaseSensitive: false
56
65
  },
@@ -67,22 +76,6 @@ var createAuthTemplate = () => {
67
76
  Ref: "CognitoUserPool"
68
77
  }
69
78
  }
70
- },
71
- [CognitoIdentityPoolLogicalId]: {
72
- Type: "AWS::Cognito::IdentityPool",
73
- Properties: {
74
- AllowUnauthenticatedIdentities: true,
75
- CognitoIdentityProviders: [
76
- {
77
- ClientId: {
78
- Ref: CognitoUserPoolClientLogicalId
79
- },
80
- ProviderName: {
81
- "Fn::GetAtt": [CognitoUserPoolLogicalId, "ProviderName"]
82
- }
83
- }
84
- ]
85
- }
86
79
  }
87
80
  },
88
81
  Outputs: {
@@ -118,25 +111,60 @@ var createAuthTemplate = () => {
118
111
  "Fn::Join": [":", [{ Ref: "AWS::StackName" }, "AppClientId"]]
119
112
  }
120
113
  }
121
- },
122
- IdentityPoolId: {
123
- Description: "You use this value on Amplify Auth `identityPoolId`.",
124
- Value: {
125
- Ref: CognitoIdentityPoolLogicalId
126
- },
127
- Export: {
128
- Name: {
129
- "Fn::Join": [
130
- ":",
131
- [{ Ref: "AWS::StackName" }, "CognitoIdentityPoolId"]
132
- ]
133
- }
134
- }
135
114
  }
136
115
  }
137
116
  };
117
+ if (identityPool) {
118
+ template.Resources[CognitoIdentityPoolLogicalId] = {
119
+ Type: "AWS::Cognito::IdentityPool",
120
+ Properties: {
121
+ AllowUnauthenticatedIdentities: true,
122
+ CognitoIdentityProviders: [
123
+ {
124
+ ClientId: {
125
+ Ref: CognitoUserPoolClientLogicalId
126
+ },
127
+ ProviderName: {
128
+ "Fn::GetAtt": [CognitoUserPoolLogicalId, "ProviderName"]
129
+ }
130
+ }
131
+ ]
132
+ }
133
+ };
134
+ if (roles) {
135
+ template.Resources.CognitoIdentityPoolRoleAttachment = {
136
+ Type: "AWS::Cognito::IdentityPoolRoleAttachment",
137
+ Properties: {
138
+ IdentityPoolId: {
139
+ Ref: CognitoIdentityPoolLogicalId
140
+ },
141
+ Roles: roles
142
+ }
143
+ };
144
+ }
145
+ if (!template.Outputs) {
146
+ template.Outputs = {};
147
+ }
148
+ template.Outputs.IdentityPoolId = {
149
+ Description: "You use this value on Amplify Auth `identityPoolId`.",
150
+ Value: {
151
+ Ref: CognitoIdentityPoolLogicalId
152
+ },
153
+ Export: {
154
+ Name: {
155
+ "Fn::Join": [
156
+ ":",
157
+ [{ Ref: "AWS::StackName" }, "CognitoIdentityPoolId"]
158
+ ]
159
+ }
160
+ }
161
+ };
162
+ }
138
163
  return template;
139
164
  };
165
+ createAuthTemplate.CognitoUserPoolLogicalId = CognitoUserPoolLogicalId;
166
+ createAuthTemplate.CognitoUserPoolClientLogicalId = CognitoUserPoolClientLogicalId;
167
+ createAuthTemplate.CognitoIdentityPoolLogicalId = CognitoIdentityPoolLogicalId;
140
168
  // Annotate the CommonJS export names for ESM import in node:
141
169
  0 && (module.exports = {
142
170
  PASSWORD_MINIMUM_LENGTH,
package/jest.config.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { jestConfig } from '@ttoss/config';
2
+
3
+ const config = jestConfig({});
4
+
5
+ export default config;
package/package.json CHANGED
@@ -1,20 +1,24 @@
1
1
  {
2
2
  "name": "@ttoss/cloud-auth",
3
- "version": "0.3.1",
3
+ "version": "0.5.0",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/esm/index.js",
6
6
  "scripts": {
7
- "build": "tsup"
7
+ "build": "tsup",
8
+ "test": "jest"
8
9
  },
9
10
  "typings": "./dist/index.d.ts",
11
+ "dependencies": {
12
+ "@ttoss/cloudformation": "^0.4.0"
13
+ },
10
14
  "devDependencies": {
11
- "@ttoss/config": "^1.26.0",
12
- "@types/jest": "^29.2.4",
15
+ "@ttoss/config": "^1.27.0",
16
+ "@types/jest": "^29.2.5",
13
17
  "jest": "^29.3.1",
14
18
  "typescript": "^4.9.4"
15
19
  },
16
20
  "publishConfig": {
17
21
  "access": "public"
18
22
  },
19
- "gitHead": "98cf227311c2f28ab73520c793bfe0bf0df27530"
23
+ "gitHead": "6c5898425e2847fed46511ae1e573ff8dc3eb1d4"
20
24
  }