@adtrackify/at-service-common 1.2.24 → 1.2.26

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.
Files changed (75) hide show
  1. package/dist/__tests__/helpers/subscription-helper.spec.d.ts +1 -1
  2. package/dist/__tests__/helpers/subscription-helper.spec.js +27 -27
  3. package/dist/clients/generic/cognito-client.d.ts +19 -19
  4. package/dist/clients/generic/cognito-client.js +139 -139
  5. package/dist/clients/generic/dynamodb-client.d.ts +15 -15
  6. package/dist/clients/generic/dynamodb-client.js +122 -122
  7. package/dist/clients/generic/eventbridge-client.d.ts +14 -14
  8. package/dist/clients/generic/eventbridge-client.js +45 -45
  9. package/dist/clients/generic/http-client.d.ts +30 -30
  10. package/dist/clients/generic/http-client.js +28 -28
  11. package/dist/clients/generic/index.d.ts +6 -6
  12. package/dist/clients/generic/index.js +6 -6
  13. package/dist/clients/generic/s3-client.d.ts +9 -9
  14. package/dist/clients/generic/s3-client.js +29 -29
  15. package/dist/clients/generic/s3-client.js.map +1 -1
  16. package/dist/clients/generic/sqs-client.d.ts +14 -14
  17. package/dist/clients/generic/sqs-client.js +34 -34
  18. package/dist/clients/index.d.ts +3 -3
  19. package/dist/clients/index.js +3 -3
  20. package/dist/clients/internal-api/accounts-client.d.ts +82 -82
  21. package/dist/clients/internal-api/accounts-client.js +78 -78
  22. package/dist/clients/internal-api/destinations-client.d.ts +54 -54
  23. package/dist/clients/internal-api/destinations-client.js +36 -36
  24. package/dist/clients/internal-api/index.d.ts +4 -4
  25. package/dist/clients/internal-api/index.js +4 -4
  26. package/dist/clients/internal-api/shopify-app-install-client.d.ts +57 -57
  27. package/dist/clients/internal-api/shopify-app-install-client.js +42 -42
  28. package/dist/clients/internal-api/users-auth-client.d.ts +61 -61
  29. package/dist/clients/internal-api/users-auth-client.js +73 -73
  30. package/dist/clients/third-party/index.d.ts +1 -1
  31. package/dist/clients/third-party/index.js +1 -1
  32. package/dist/clients/third-party/shopify-client.d.ts +90 -90
  33. package/dist/clients/third-party/shopify-client.js +121 -121
  34. package/dist/helpers/index.d.ts +5 -5
  35. package/dist/helpers/index.js +5 -5
  36. package/dist/helpers/input-validation-helper.d.ts +2 -2
  37. package/dist/helpers/input-validation-helper.js +18 -18
  38. package/dist/helpers/logging-helper.d.ts +15 -15
  39. package/dist/helpers/logging-helper.js +53 -45
  40. package/dist/helpers/logging-helper.js.map +1 -1
  41. package/dist/helpers/response-helper.d.ts +36 -36
  42. package/dist/helpers/response-helper.js +35 -35
  43. package/dist/helpers/shopify-helper.d.ts +9 -9
  44. package/dist/helpers/shopify-helper.js +23 -23
  45. package/dist/helpers/subscription-helper.d.ts +8 -8
  46. package/dist/helpers/subscription-helper.js +181 -181
  47. package/dist/index.d.ts +5 -5
  48. package/dist/index.esm.js +10 -5
  49. package/dist/index.esm.js.map +2 -2
  50. package/dist/index.js +5 -5
  51. package/dist/libs/crypto.d.ts +1 -1
  52. package/dist/libs/crypto.js +5 -5
  53. package/dist/libs/dates.d.ts +3 -3
  54. package/dist/libs/dates.js +10 -10
  55. package/dist/libs/http-error.d.ts +21 -21
  56. package/dist/libs/http-error.js +55 -55
  57. package/dist/libs/http-status-codes.d.ts +58 -58
  58. package/dist/libs/http-status-codes.js +59 -59
  59. package/dist/libs/index.d.ts +6 -6
  60. package/dist/libs/index.js +6 -6
  61. package/dist/libs/url.d.ts +1 -1
  62. package/dist/libs/url.js +9 -9
  63. package/dist/services/eventbridge-integration-service.d.ts +9 -9
  64. package/dist/services/eventbridge-integration-service.js +24 -24
  65. package/dist/services/index.d.ts +1 -1
  66. package/dist/services/index.js +1 -1
  67. package/dist/types/api-response.d.ts +6 -6
  68. package/dist/types/api-response.js +1 -1
  69. package/dist/types/index.d.ts +1 -1
  70. package/dist/types/index.js +1 -1
  71. package/dist/types/internal-events/event-detail-types.d.ts +20 -20
  72. package/dist/types/internal-events/event-detail-types.js +24 -24
  73. package/dist/types/internal-events/index.d.ts +1 -1
  74. package/dist/types/internal-events/index.js +1 -1
  75. package/package.json +1 -1
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,28 +1,28 @@
1
- jest.mock('lambda-log');
2
- import * as Logger from 'lambda-log';
3
- import { getPlanDetails } from '../../helpers/subscription-helper.js';
4
- describe('postmark service email test', () => {
5
- jest.spyOn(Logger, 'warn').mockImplementation(() => {
6
- return new Logger.LogMessage({ level: 'null', msg: 'null' }, {});
7
- });
8
- jest.spyOn(Logger, 'info').mockImplementation(() => {
9
- return new Logger.LogMessage({ level: 'null', msg: 'null' }, {});
10
- });
11
- jest.spyOn(Logger, 'debug').mockImplementation(() => {
12
- return new Logger.LogMessage({ level: 'null', msg: 'null' }, {});
13
- });
14
- jest.spyOn(Logger, 'error').mockImplementation(() => {
15
- return new Logger.LogMessage({ level: 'null', msg: 'null' }, {});
16
- });
17
- beforeEach(async () => {
18
- });
19
- afterEach(() => {
20
- jest.resetAllMocks();
21
- });
22
- it('should call send email message', async () => {
23
- const plan = getPlanDetails(2, 'dev');
24
- console.log(plan);
25
- expect(plan).not.toEqual(null);
26
- });
27
- });
1
+ jest.mock('lambda-log');
2
+ import * as Logger from 'lambda-log';
3
+ import { getPlanDetails } from '../../helpers/subscription-helper.js';
4
+ describe('postmark service email test', () => {
5
+ jest.spyOn(Logger, 'warn').mockImplementation(() => {
6
+ return new Logger.LogMessage({ level: 'null', msg: 'null' }, {});
7
+ });
8
+ jest.spyOn(Logger, 'info').mockImplementation(() => {
9
+ return new Logger.LogMessage({ level: 'null', msg: 'null' }, {});
10
+ });
11
+ jest.spyOn(Logger, 'debug').mockImplementation(() => {
12
+ return new Logger.LogMessage({ level: 'null', msg: 'null' }, {});
13
+ });
14
+ jest.spyOn(Logger, 'error').mockImplementation(() => {
15
+ return new Logger.LogMessage({ level: 'null', msg: 'null' }, {});
16
+ });
17
+ beforeEach(async () => {
18
+ });
19
+ afterEach(() => {
20
+ jest.resetAllMocks();
21
+ });
22
+ it('should call send email message', async () => {
23
+ const plan = getPlanDetails(2, 'dev');
24
+ console.log(plan);
25
+ expect(plan).not.toEqual(null);
26
+ });
27
+ });
28
28
  //# sourceMappingURL=subscription-helper.spec.js.map
@@ -1,19 +1,19 @@
1
- export declare function dictToAwsAttributes(input: any): {
2
- Name: string;
3
- Value: any;
4
- }[];
5
- export declare class CognitoClient {
6
- cognitoClient: any;
7
- USER_POOL_ID: string;
8
- USER_POOL_NO_SECRET_CLIENT_ID: string;
9
- constructor(userPoolId: string, userPoolNoSecretClientId: string);
10
- signupUser: (data: any) => Promise<any>;
11
- forgotPassword: (email: string) => Promise<any>;
12
- adminEmailVerify: (email: string) => Promise<void>;
13
- forceValidateEmail: (email: string) => Promise<void>;
14
- adminConfirmUser: (data: any) => Promise<any>;
15
- confirmUser: (data: any) => Promise<any>;
16
- resendCode: (email: string) => Promise<void>;
17
- adminDeleteUser: (userId: string) => Promise<boolean>;
18
- getUserByEmail: (email: string) => Promise<any>;
19
- }
1
+ export declare function dictToAwsAttributes(input: any): {
2
+ Name: string;
3
+ Value: any;
4
+ }[];
5
+ export declare class CognitoClient {
6
+ cognitoClient: any;
7
+ USER_POOL_ID: string;
8
+ USER_POOL_NO_SECRET_CLIENT_ID: string;
9
+ constructor(userPoolId: string, userPoolNoSecretClientId: string);
10
+ signupUser: (data: any) => Promise<any>;
11
+ forgotPassword: (email: string) => Promise<any>;
12
+ adminEmailVerify: (email: string) => Promise<void>;
13
+ forceValidateEmail: (email: string) => Promise<void>;
14
+ adminConfirmUser: (data: any) => Promise<any>;
15
+ confirmUser: (data: any) => Promise<any>;
16
+ resendCode: (email: string) => Promise<void>;
17
+ adminDeleteUser: (userId: string) => Promise<boolean>;
18
+ getUserByEmail: (email: string) => Promise<any>;
19
+ }
@@ -1,140 +1,140 @@
1
- import { CognitoIdentityProvider } from '@aws-sdk/client-cognito-identity-provider';
2
- import { Logger } from '../../index.js';
3
- export function dictToAwsAttributes(input) {
4
- delete input.email;
5
- delete input.password;
6
- const output = [];
7
- for (const att in input) {
8
- if (Object.prototype.hasOwnProperty.call(input, att)) {
9
- output.push({ Name: att, Value: input[att] });
10
- }
11
- }
12
- return output;
13
- }
14
- const buildAttributes = (data) => {
15
- const attributes = {
16
- name: data.givenName,
17
- family_name: data.familyName,
18
- };
19
- return dictToAwsAttributes(attributes);
20
- };
21
- export class CognitoClient {
22
- cognitoClient;
23
- USER_POOL_ID;
24
- USER_POOL_NO_SECRET_CLIENT_ID;
25
- constructor(userPoolId, userPoolNoSecretClientId) {
26
- this.cognitoClient = new CognitoIdentityProvider({});
27
- this.USER_POOL_ID = userPoolId;
28
- this.USER_POOL_NO_SECRET_CLIENT_ID = userPoolNoSecretClientId;
29
- }
30
- signupUser = async (data) => {
31
- const params = {
32
- ClientId: this.USER_POOL_NO_SECRET_CLIENT_ID,
33
- Password: data.password,
34
- Username: data.email,
35
- UserAttributes: buildAttributes(data),
36
- };
37
- const cognitoResponse = await this.cognitoClient.signUp(params);
38
- Logger.debug('Successfully Registered User', { cognitoResponse });
39
- return cognitoResponse;
40
- };
41
- forgotPassword = async (email) => {
42
- await this.adminEmailVerify(email);
43
- const params = {
44
- ClientId: this.USER_POOL_NO_SECRET_CLIENT_ID,
45
- Username: email,
46
- };
47
- const cognitoResponse = await this.cognitoClient.forgotPassword(params);
48
- Logger.debug('Sent Forgot Password', { cognitoResponse });
49
- return cognitoResponse;
50
- };
51
- adminEmailVerify = async (email) => {
52
- try {
53
- const user = await this.getUserByEmail(email);
54
- if (user && user?.UserStatus === 'CONFIRMED' && user?.email_verified !== 'true') {
55
- await this.forceValidateEmail(email);
56
- }
57
- }
58
- catch (error) {
59
- Logger.error('Failed admin email verify', { error });
60
- }
61
- };
62
- forceValidateEmail = async (email) => {
63
- try {
64
- const params = {
65
- UserPoolId: this.USER_POOL_ID,
66
- Username: email,
67
- UserAttributes: [
68
- {
69
- Name: 'email_verified',
70
- Value: 'true',
71
- },
72
- ],
73
- };
74
- await this.cognitoClient.adminUpdateUserAttributes(params);
75
- }
76
- catch (error) {
77
- Logger.error('Failed force validate email', { email, error });
78
- }
79
- };
80
- adminConfirmUser = async (data) => {
81
- const params = {
82
- UserPoolId: this.USER_POOL_ID,
83
- Username: data.email,
84
- };
85
- const cognitoResponse = await this.cognitoClient.adminConfirmSignUp(params);
86
- await this.forceValidateEmail(data.email);
87
- Logger.debug('Admin Successfully Confirmed User', { cognitoResponse });
88
- return cognitoResponse;
89
- };
90
- confirmUser = async (data) => {
91
- const params = {
92
- ClientId: this.USER_POOL_NO_SECRET_CLIENT_ID,
93
- ConfirmationCode: data.confirmationCode,
94
- Username: data.email,
95
- };
96
- const cognitoResponse = await this.cognitoClient.confirmSignUp(params);
97
- Logger.debug('Successfully Confirmed User', { cognitoResponse });
98
- return cognitoResponse;
99
- };
100
- resendCode = async (email) => {
101
- const params = {
102
- ClientId: this.USER_POOL_NO_SECRET_CLIENT_ID,
103
- Username: email,
104
- };
105
- await this.cognitoClient.resendConfirmationCode(params);
106
- Logger.debug('Successfully Resend Confirmation Code', { email });
107
- return;
108
- };
109
- adminDeleteUser = async (userId) => {
110
- const params = {
111
- UserPoolId: this.USER_POOL_ID,
112
- Username: userId,
113
- };
114
- await this.cognitoClient.adminDeleteUser(params);
115
- return true;
116
- };
117
- getUserByEmail = async (email) => {
118
- const params = {
119
- UserPoolId: this.USER_POOL_ID,
120
- Filter: `email=\"${email}\"`,
121
- Limit: 1,
122
- };
123
- const cognitoResponse = await this.cognitoClient.listUsers(params);
124
- Logger.debug('Get Users by Email', { cognitoResponse });
125
- if (cognitoResponse?.Users && cognitoResponse?.Users.length > 0) {
126
- const attributes = cognitoResponse.Users[0].Attributes;
127
- const user = {
128
- ...cognitoResponse.Users[0],
129
- Attributes: undefined,
130
- id: cognitoResponse.Users[0].sub,
131
- };
132
- attributes.forEach((attr) => {
133
- user[attr.Name] = attr?.Value;
134
- });
135
- return user;
136
- }
137
- return null;
138
- };
139
- }
1
+ import { CognitoIdentityProvider } from '@aws-sdk/client-cognito-identity-provider';
2
+ import { Logger } from '../../index.js';
3
+ export function dictToAwsAttributes(input) {
4
+ delete input.email;
5
+ delete input.password;
6
+ const output = [];
7
+ for (const att in input) {
8
+ if (Object.prototype.hasOwnProperty.call(input, att)) {
9
+ output.push({ Name: att, Value: input[att] });
10
+ }
11
+ }
12
+ return output;
13
+ }
14
+ const buildAttributes = (data) => {
15
+ const attributes = {
16
+ name: data.givenName,
17
+ family_name: data.familyName,
18
+ };
19
+ return dictToAwsAttributes(attributes);
20
+ };
21
+ export class CognitoClient {
22
+ cognitoClient;
23
+ USER_POOL_ID;
24
+ USER_POOL_NO_SECRET_CLIENT_ID;
25
+ constructor(userPoolId, userPoolNoSecretClientId) {
26
+ this.cognitoClient = new CognitoIdentityProvider({});
27
+ this.USER_POOL_ID = userPoolId;
28
+ this.USER_POOL_NO_SECRET_CLIENT_ID = userPoolNoSecretClientId;
29
+ }
30
+ signupUser = async (data) => {
31
+ const params = {
32
+ ClientId: this.USER_POOL_NO_SECRET_CLIENT_ID,
33
+ Password: data.password,
34
+ Username: data.email,
35
+ UserAttributes: buildAttributes(data),
36
+ };
37
+ const cognitoResponse = await this.cognitoClient.signUp(params);
38
+ Logger.debug('Successfully Registered User', { cognitoResponse });
39
+ return cognitoResponse;
40
+ };
41
+ forgotPassword = async (email) => {
42
+ await this.adminEmailVerify(email);
43
+ const params = {
44
+ ClientId: this.USER_POOL_NO_SECRET_CLIENT_ID,
45
+ Username: email,
46
+ };
47
+ const cognitoResponse = await this.cognitoClient.forgotPassword(params);
48
+ Logger.debug('Sent Forgot Password', { cognitoResponse });
49
+ return cognitoResponse;
50
+ };
51
+ adminEmailVerify = async (email) => {
52
+ try {
53
+ const user = await this.getUserByEmail(email);
54
+ if (user && user?.UserStatus === 'CONFIRMED' && user?.email_verified !== 'true') {
55
+ await this.forceValidateEmail(email);
56
+ }
57
+ }
58
+ catch (error) {
59
+ Logger.error('Failed admin email verify', { error });
60
+ }
61
+ };
62
+ forceValidateEmail = async (email) => {
63
+ try {
64
+ const params = {
65
+ UserPoolId: this.USER_POOL_ID,
66
+ Username: email,
67
+ UserAttributes: [
68
+ {
69
+ Name: 'email_verified',
70
+ Value: 'true',
71
+ },
72
+ ],
73
+ };
74
+ await this.cognitoClient.adminUpdateUserAttributes(params);
75
+ }
76
+ catch (error) {
77
+ Logger.error('Failed force validate email', { email, error });
78
+ }
79
+ };
80
+ adminConfirmUser = async (data) => {
81
+ const params = {
82
+ UserPoolId: this.USER_POOL_ID,
83
+ Username: data.email,
84
+ };
85
+ const cognitoResponse = await this.cognitoClient.adminConfirmSignUp(params);
86
+ await this.forceValidateEmail(data.email);
87
+ Logger.debug('Admin Successfully Confirmed User', { cognitoResponse });
88
+ return cognitoResponse;
89
+ };
90
+ confirmUser = async (data) => {
91
+ const params = {
92
+ ClientId: this.USER_POOL_NO_SECRET_CLIENT_ID,
93
+ ConfirmationCode: data.confirmationCode,
94
+ Username: data.email,
95
+ };
96
+ const cognitoResponse = await this.cognitoClient.confirmSignUp(params);
97
+ Logger.debug('Successfully Confirmed User', { cognitoResponse });
98
+ return cognitoResponse;
99
+ };
100
+ resendCode = async (email) => {
101
+ const params = {
102
+ ClientId: this.USER_POOL_NO_SECRET_CLIENT_ID,
103
+ Username: email,
104
+ };
105
+ await this.cognitoClient.resendConfirmationCode(params);
106
+ Logger.debug('Successfully Resend Confirmation Code', { email });
107
+ return;
108
+ };
109
+ adminDeleteUser = async (userId) => {
110
+ const params = {
111
+ UserPoolId: this.USER_POOL_ID,
112
+ Username: userId,
113
+ };
114
+ await this.cognitoClient.adminDeleteUser(params);
115
+ return true;
116
+ };
117
+ getUserByEmail = async (email) => {
118
+ const params = {
119
+ UserPoolId: this.USER_POOL_ID,
120
+ Filter: `email=\"${email}\"`,
121
+ Limit: 1,
122
+ };
123
+ const cognitoResponse = await this.cognitoClient.listUsers(params);
124
+ Logger.debug('Get Users by Email', { cognitoResponse });
125
+ if (cognitoResponse?.Users && cognitoResponse?.Users.length > 0) {
126
+ const attributes = cognitoResponse.Users[0].Attributes;
127
+ const user = {
128
+ ...cognitoResponse.Users[0],
129
+ Attributes: undefined,
130
+ id: cognitoResponse.Users[0].sub,
131
+ };
132
+ attributes.forEach((attr) => {
133
+ user[attr.Name] = attr?.Value;
134
+ });
135
+ return user;
136
+ }
137
+ return null;
138
+ };
139
+ }
140
140
  //# sourceMappingURL=cognito-client.js.map
@@ -1,15 +1,15 @@
1
- export declare class DynamoDbClient {
2
- static safeGet: (tableName: string, keyName: string, keyValue: any) => Promise<Record<string, any> | null>;
3
- static safePut: (tableName: string, data: any) => Promise<import("@aws-sdk/lib-dynamodb").PutCommandOutput | null>;
4
- static safeDelete: (tableName: string, keyName: string, keyValue: any) => Promise<import("@aws-sdk/lib-dynamodb").DeleteCommandOutput | null>;
5
- static safeQueryByGSI: (tableName: string, gsiName: string, keyName: string, keyValue: any) => Promise<any[] | null>;
6
- static safeBatchGet: (tableName: string, keys: any) => Promise<Record<string, any>[]>;
7
- static queryAll: (params: any) => Promise<any[] | null>;
8
- static batchGet: (params: any) => Promise<import("@aws-sdk/lib-dynamodb").BatchGetCommandOutput>;
9
- static get: (params: any) => Promise<import("@aws-sdk/lib-dynamodb").GetCommandOutput>;
10
- static put: (params: any) => Promise<import("@aws-sdk/lib-dynamodb").PutCommandOutput>;
11
- static query: (params: any) => Promise<import("@aws-sdk/lib-dynamodb").QueryCommandOutput>;
12
- static scan: (params: any) => Promise<import("@aws-sdk/lib-dynamodb").ScanCommandOutput>;
13
- static update: (params: any) => Promise<import("@aws-sdk/lib-dynamodb").UpdateCommandOutput>;
14
- static delete: (params: any) => Promise<import("@aws-sdk/lib-dynamodb").DeleteCommandOutput>;
15
- }
1
+ export declare class DynamoDbClient {
2
+ static safeGet: (tableName: string, keyName: string, keyValue: any) => Promise<Record<string, any> | null>;
3
+ static safePut: (tableName: string, data: any) => Promise<import("@aws-sdk/lib-dynamodb").PutCommandOutput | null>;
4
+ static safeDelete: (tableName: string, keyName: string, keyValue: any) => Promise<import("@aws-sdk/lib-dynamodb").DeleteCommandOutput | null>;
5
+ static safeQueryByGSI: (tableName: string, gsiName: string, keyName: string, keyValue: any) => Promise<any[] | null>;
6
+ static safeBatchGet: (tableName: string, keys: any) => Promise<Record<string, any>[]>;
7
+ static queryAll: (params: any) => Promise<any[] | null>;
8
+ static batchGet: (params: any) => Promise<import("@aws-sdk/lib-dynamodb").BatchGetCommandOutput>;
9
+ static get: (params: any) => Promise<import("@aws-sdk/lib-dynamodb").GetCommandOutput>;
10
+ static put: (params: any) => Promise<import("@aws-sdk/lib-dynamodb").PutCommandOutput>;
11
+ static query: (params: any) => Promise<import("@aws-sdk/lib-dynamodb").QueryCommandOutput>;
12
+ static scan: (params: any) => Promise<import("@aws-sdk/lib-dynamodb").ScanCommandOutput>;
13
+ static update: (params: any) => Promise<import("@aws-sdk/lib-dynamodb").UpdateCommandOutput>;
14
+ static delete: (params: any) => Promise<import("@aws-sdk/lib-dynamodb").DeleteCommandOutput>;
15
+ }
@@ -1,123 +1,123 @@
1
- import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
2
- import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
3
- import { Logger } from '../../index.js';
4
- const marshallOptions = {
5
- convertEmptyValues: false,
6
- removeUndefinedValues: false,
7
- convertClassInstanceToMap: true
8
- };
9
- const unmarshallOptions = {
10
- wrapNumbers: false,
11
- };
12
- const translateConfig = { marshallOptions, unmarshallOptions };
13
- const ddbClient = new DynamoDBClient({});
14
- const client = DynamoDBDocument.from(ddbClient, translateConfig);
15
- export class DynamoDbClient {
16
- static safeGet = async (tableName, keyName, keyValue) => {
17
- try {
18
- const params = {
19
- TableName: tableName,
20
- Key: {
21
- [keyName]: keyValue
22
- }
23
- };
24
- const res = await client.get(params);
25
- return res?.Item ?? null;
26
- }
27
- catch (e) {
28
- Logger.error(e, { message: 'Dynamo Client Get Failed' });
29
- return null;
30
- }
31
- };
32
- static safePut = async (tableName, data) => {
33
- try {
34
- const params = {
35
- TableName: tableName,
36
- Item: data
37
- };
38
- const res = await client.put(params);
39
- return res;
40
- }
41
- catch (e) {
42
- Logger.error(e, { message: 'Dynamo failed simplePut' });
43
- return null;
44
- }
45
- };
46
- static safeDelete = async (tableName, keyName, keyValue) => {
47
- try {
48
- const params = {
49
- TableName: tableName,
50
- Key: {
51
- [keyName]: keyValue
52
- }
53
- };
54
- const res = await client.delete(params);
55
- return res;
56
- }
57
- catch (e) {
58
- Logger.error(e, { message: 'Dynamo failed safeDelete' });
59
- return null;
60
- }
61
- };
62
- static safeQueryByGSI = async (tableName, gsiName, keyName, keyValue) => {
63
- const query = {
64
- TableName: tableName,
65
- IndexName: gsiName,
66
- KeyConditionExpression: `${keyName} = :value`,
67
- ExpressionAttributeValues: {
68
- ':value': keyValue
69
- }
70
- };
71
- const results = await DynamoDbClient.queryAll(query);
72
- return results;
73
- };
74
- static safeBatchGet = async (tableName, keys) => {
75
- try {
76
- const params = {
77
- RequestItems: {}
78
- };
79
- params.RequestItems[tableName] = {
80
- Keys: keys
81
- };
82
- const res = await client.batchGet(params);
83
- Logger.debug('batchget res', { batchGetRes: res });
84
- if (res?.Responses?.[tableName]) {
85
- return res?.Responses?.[tableName];
86
- }
87
- return [];
88
- }
89
- catch (e) {
90
- Logger.error(e, { message: 'Dynamo failed safeBatchGet' });
91
- return [];
92
- }
93
- };
94
- static queryAll = async (params) => {
95
- try {
96
- Logger.debug('Invoke Query All', { params });
97
- let currentResult, exclusiveStartKey;
98
- let accumulatedResults = [];
99
- do {
100
- params.ExclusiveStartKey = exclusiveStartKey;
101
- params.Limit = 200;
102
- currentResult = await client.query(params);
103
- if (currentResult.Items) {
104
- exclusiveStartKey = currentResult.LastEvaluatedKey;
105
- accumulatedResults = [...accumulatedResults, ...currentResult.Items];
106
- }
107
- } while (currentResult.Items && currentResult.Items.length > 0 && currentResult.LastEvaluatedKey);
108
- return accumulatedResults;
109
- }
110
- catch (e) {
111
- Logger.error(e, { message: 'Dynamo failed queryAll' });
112
- return null;
113
- }
114
- };
115
- static batchGet = (params) => client.batchGet(params);
116
- static get = (params) => client.get(params);
117
- static put = (params) => client.put(params);
118
- static query = (params) => client.query(params);
119
- static scan = (params) => client.scan(params);
120
- static update = (params) => client.update(params);
121
- static delete = (params) => client.delete(params);
122
- }
1
+ import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
2
+ import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
3
+ import { Logger } from '../../index.js';
4
+ const marshallOptions = {
5
+ convertEmptyValues: false,
6
+ removeUndefinedValues: false,
7
+ convertClassInstanceToMap: true
8
+ };
9
+ const unmarshallOptions = {
10
+ wrapNumbers: false,
11
+ };
12
+ const translateConfig = { marshallOptions, unmarshallOptions };
13
+ const ddbClient = new DynamoDBClient({});
14
+ const client = DynamoDBDocument.from(ddbClient, translateConfig);
15
+ export class DynamoDbClient {
16
+ static safeGet = async (tableName, keyName, keyValue) => {
17
+ try {
18
+ const params = {
19
+ TableName: tableName,
20
+ Key: {
21
+ [keyName]: keyValue
22
+ }
23
+ };
24
+ const res = await client.get(params);
25
+ return res?.Item ?? null;
26
+ }
27
+ catch (e) {
28
+ Logger.error(e, { message: 'Dynamo Client Get Failed' });
29
+ return null;
30
+ }
31
+ };
32
+ static safePut = async (tableName, data) => {
33
+ try {
34
+ const params = {
35
+ TableName: tableName,
36
+ Item: data
37
+ };
38
+ const res = await client.put(params);
39
+ return res;
40
+ }
41
+ catch (e) {
42
+ Logger.error(e, { message: 'Dynamo failed simplePut' });
43
+ return null;
44
+ }
45
+ };
46
+ static safeDelete = async (tableName, keyName, keyValue) => {
47
+ try {
48
+ const params = {
49
+ TableName: tableName,
50
+ Key: {
51
+ [keyName]: keyValue
52
+ }
53
+ };
54
+ const res = await client.delete(params);
55
+ return res;
56
+ }
57
+ catch (e) {
58
+ Logger.error(e, { message: 'Dynamo failed safeDelete' });
59
+ return null;
60
+ }
61
+ };
62
+ static safeQueryByGSI = async (tableName, gsiName, keyName, keyValue) => {
63
+ const query = {
64
+ TableName: tableName,
65
+ IndexName: gsiName,
66
+ KeyConditionExpression: `${keyName} = :value`,
67
+ ExpressionAttributeValues: {
68
+ ':value': keyValue
69
+ }
70
+ };
71
+ const results = await DynamoDbClient.queryAll(query);
72
+ return results;
73
+ };
74
+ static safeBatchGet = async (tableName, keys) => {
75
+ try {
76
+ const params = {
77
+ RequestItems: {}
78
+ };
79
+ params.RequestItems[tableName] = {
80
+ Keys: keys
81
+ };
82
+ const res = await client.batchGet(params);
83
+ Logger.debug('batchget res', { batchGetRes: res });
84
+ if (res?.Responses?.[tableName]) {
85
+ return res?.Responses?.[tableName];
86
+ }
87
+ return [];
88
+ }
89
+ catch (e) {
90
+ Logger.error(e, { message: 'Dynamo failed safeBatchGet' });
91
+ return [];
92
+ }
93
+ };
94
+ static queryAll = async (params) => {
95
+ try {
96
+ Logger.debug('Invoke Query All', { params });
97
+ let currentResult, exclusiveStartKey;
98
+ let accumulatedResults = [];
99
+ do {
100
+ params.ExclusiveStartKey = exclusiveStartKey;
101
+ params.Limit = 200;
102
+ currentResult = await client.query(params);
103
+ if (currentResult.Items) {
104
+ exclusiveStartKey = currentResult.LastEvaluatedKey;
105
+ accumulatedResults = [...accumulatedResults, ...currentResult.Items];
106
+ }
107
+ } while (currentResult.Items && currentResult.Items.length > 0 && currentResult.LastEvaluatedKey);
108
+ return accumulatedResults;
109
+ }
110
+ catch (e) {
111
+ Logger.error(e, { message: 'Dynamo failed queryAll' });
112
+ return null;
113
+ }
114
+ };
115
+ static batchGet = (params) => client.batchGet(params);
116
+ static get = (params) => client.get(params);
117
+ static put = (params) => client.put(params);
118
+ static query = (params) => client.query(params);
119
+ static scan = (params) => client.scan(params);
120
+ static update = (params) => client.update(params);
121
+ static delete = (params) => client.delete(params);
122
+ }
123
123
  //# sourceMappingURL=dynamodb-client.js.map