triangle-utils 1.4.26 → 1.4.28

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,10 +1,10 @@
1
1
  export declare class UtilsCognito {
2
2
  private readonly cognito;
3
3
  constructor(region: string);
4
- get_username(token: string): Promise<string | undefined>;
5
4
  admin_get_user(user_pool_id: string, username: string): Promise<import("@aws-sdk/client-cognito-identity-provider").AdminGetUserCommandOutput | undefined>;
6
5
  admin_create_user(user_pool_id: string, username: string, user_id: string): Promise<Error | import("@aws-sdk/client-cognito-identity-provider").AdminCreateUserCommandOutput>;
7
6
  admin_reset_password(user_pool_id: string, username: string): Promise<Error | import("@aws-sdk/client-cognito-identity-provider").AdminCreateUserCommandOutput>;
7
+ get_email(token: string): Promise<string | undefined>;
8
8
  get_user_id(token: string): Promise<string | undefined>;
9
9
  get_new_token(client_id: string, client_secret: string, refresh_token: string): Promise<string | undefined>;
10
10
  sign_out(token: string): Promise<void>;
@@ -4,18 +4,6 @@ export class UtilsCognito {
4
4
  constructor(region) {
5
5
  this.cognito = new CognitoIdentityProvider({ region: region });
6
6
  }
7
- async get_username(token) {
8
- try {
9
- const user_info = await this.cognito.getUser({
10
- AccessToken: token
11
- });
12
- const username = user_info.Username;
13
- return username;
14
- }
15
- catch (error) {
16
- return undefined;
17
- }
18
- }
19
7
  async admin_get_user(user_pool_id, username) {
20
8
  try {
21
9
  return await this.cognito.adminGetUser({
@@ -64,6 +52,26 @@ export class UtilsCognito {
64
52
  return new Error();
65
53
  }
66
54
  }
55
+ async get_email(token) {
56
+ try {
57
+ const user_info = await this.cognito.getUser({
58
+ AccessToken: token
59
+ });
60
+ const user_attributes = user_info.UserAttributes;
61
+ if (user_attributes === undefined) {
62
+ return undefined;
63
+ }
64
+ const user_attribute = user_attributes.filter(attribute => attribute.Name === "email")[0];
65
+ if (user_attribute === undefined) {
66
+ return undefined;
67
+ }
68
+ const email = user_attribute.Value;
69
+ return email;
70
+ }
71
+ catch (error) {
72
+ return undefined;
73
+ }
74
+ }
67
75
  async get_user_id(token) {
68
76
  try {
69
77
  const user_info = await this.cognito.getUser({
@@ -10,7 +10,7 @@ export declare class UtilsDynamoDB {
10
10
  concurrency?: number;
11
11
  }): Promise<Record<string, any>[]>;
12
12
  get(table: string, key: Record<string, any>, consistent?: boolean): Promise<Record<string, any> | undefined>;
13
- get_max(table: string, primary_key: Record<string, any>): Promise<Record<string, any> | undefined>;
13
+ get_max(table_index_name: string, primary_key: Record<string, any>): Promise<Record<string, any> | undefined>;
14
14
  query(table_index_name: string, primary_key: Record<string, any>, options?: {
15
15
  reverse?: boolean;
16
16
  compile?: boolean;
@@ -155,7 +155,9 @@ export class UtilsDynamoDB {
155
155
  }
156
156
  return converted_output;
157
157
  }
158
- async get_max(table, primary_key) {
158
+ async get_max(table_index_name, primary_key) {
159
+ const table_name = table_index_name.split(":")[0];
160
+ const index_name = table_index_name.split(":")[1];
159
161
  if (Object.keys(primary_key).length !== 1) {
160
162
  return undefined;
161
163
  }
@@ -165,7 +167,8 @@ export class UtilsDynamoDB {
165
167
  return undefined;
166
168
  }
167
169
  const request = {
168
- TableName: table,
170
+ TableName: table_name,
171
+ IndexName: index_name,
169
172
  ExpressionAttributeNames: {
170
173
  "#a": key
171
174
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.26",
3
+ "version": "1.4.28",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -8,18 +8,6 @@ export class UtilsCognito {
8
8
  this.cognito = new CognitoIdentityProvider({ region : region })
9
9
  }
10
10
 
11
- async get_username(token : string) {
12
- try {
13
- const user_info = await this.cognito.getUser({
14
- AccessToken : token
15
- })
16
- const username = user_info.Username
17
- return username
18
- } catch (error) {
19
- return undefined
20
- }
21
- }
22
-
23
11
  async admin_get_user(user_pool_id : string, username : string) {
24
12
  try {
25
13
  return await this.cognito.adminGetUser({
@@ -68,6 +56,26 @@ export class UtilsCognito {
68
56
  }
69
57
  }
70
58
 
59
+ async get_email(token : string) {
60
+ try {
61
+ const user_info = await this.cognito.getUser({
62
+ AccessToken : token
63
+ })
64
+ const user_attributes = user_info.UserAttributes
65
+ if (user_attributes === undefined) {
66
+ return undefined
67
+ }
68
+ const user_attribute = user_attributes.filter(attribute => attribute.Name === "email")[0]
69
+ if (user_attribute === undefined) {
70
+ return undefined
71
+ }
72
+ const email = user_attribute.Value
73
+ return email
74
+ } catch (error) {
75
+ return undefined
76
+ }
77
+ }
78
+
71
79
  async get_user_id(token : string) : Promise<string | undefined> {
72
80
  try {
73
81
  const user_info = await this.cognito.getUser({
@@ -182,9 +182,11 @@ export class UtilsDynamoDB {
182
182
  }
183
183
 
184
184
  async get_max(
185
- table : string,
185
+ table_index_name : string,
186
186
  primary_key : Record<string, any>
187
187
  ) : Promise<Record<string, any> | undefined> {
188
+ const table_name : string = table_index_name.split(":")[0]
189
+ const index_name : string | undefined = table_index_name.split(":")[1]
188
190
  if (Object.keys(primary_key).length !== 1) {
189
191
  return undefined
190
192
  }
@@ -194,7 +196,8 @@ export class UtilsDynamoDB {
194
196
  return undefined
195
197
  }
196
198
  const request : QueryCommandInput = {
197
- TableName : table,
199
+ TableName : table_name,
200
+ IndexName : index_name,
198
201
  ExpressionAttributeNames: {
199
202
  "#a": key
200
203
  },