idea-aws 4.4.3 → 4.4.4

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 (100) hide show
  1. package/package.json +1 -1
  2. package/.prettierrc +0 -9
  3. package/.vscode/settings.json +0 -26
  4. package/HOW-TO-RELEASE.md +0 -8
  5. package/build.sh +0 -21
  6. package/dist/src/attachments.d.ts +0 -27
  7. package/dist/src/attachments.js +0 -39
  8. package/dist/src/cognito.d.ts +0 -177
  9. package/dist/src/cognito.js +0 -412
  10. package/dist/src/comprehend.d.ts +0 -34
  11. package/dist/src/comprehend.js +0 -58
  12. package/dist/src/dynamoDB.d.ts +0 -108
  13. package/dist/src/dynamoDB.js +0 -296
  14. package/dist/src/genericController.d.ts +0 -60
  15. package/dist/src/genericController.js +0 -89
  16. package/dist/src/lambdaLogger.d.ts +0 -13
  17. package/dist/src/lambdaLogger.js +0 -43
  18. package/dist/src/metrics.d.ts +0 -31
  19. package/dist/src/metrics.js +0 -45
  20. package/dist/src/resourceController.d.ts +0 -232
  21. package/dist/src/resourceController.js +0 -561
  22. package/dist/src/s3.d.ts +0 -225
  23. package/dist/src/s3.js +0 -180
  24. package/dist/src/secretsManager.d.ts +0 -15
  25. package/dist/src/secretsManager.js +0 -48
  26. package/dist/src/ses.d.ts +0 -161
  27. package/dist/src/ses.js +0 -196
  28. package/dist/src/sns.d.ts +0 -60
  29. package/dist/src/sns.js +0 -94
  30. package/dist/src/ssm.d.ts +0 -22
  31. package/dist/src/ssm.js +0 -54
  32. package/dist/src/streamController.d.ts +0 -11
  33. package/dist/src/streamController.js +0 -20
  34. package/dist/src/translate.d.ts +0 -61
  35. package/dist/src/translate.js +0 -155
  36. package/docs/.nojekyll +0 -1
  37. package/docs/assets/custom.css +0 -4
  38. package/docs/assets/highlight.css +0 -50
  39. package/docs/assets/main.js +0 -58
  40. package/docs/assets/search.js +0 -1
  41. package/docs/assets/style.css +0 -1367
  42. package/docs/classes/Attachments.html +0 -201
  43. package/docs/classes/Cognito.html +0 -713
  44. package/docs/classes/Comprehend.html +0 -176
  45. package/docs/classes/DynamoDB.html +0 -584
  46. package/docs/classes/GenericController.html +0 -262
  47. package/docs/classes/HandledError.html +0 -219
  48. package/docs/classes/LambdaLogger.html +0 -220
  49. package/docs/classes/ResourceController.html +0 -957
  50. package/docs/classes/S3.html +0 -391
  51. package/docs/classes/SES.html +0 -335
  52. package/docs/classes/SNS.html +0 -185
  53. package/docs/classes/SecretsManager.html +0 -159
  54. package/docs/classes/StreamController.html +0 -284
  55. package/docs/classes/SystemsManager.html +0 -184
  56. package/docs/classes/Translate.html +0 -239
  57. package/docs/classes/UnhandledError.html +0 -252
  58. package/docs/functions/cleanFilename.html +0 -93
  59. package/docs/index.html +0 -95
  60. package/docs/interfaces/BasicEmailData.html +0 -145
  61. package/docs/interfaces/CognitoGroup.html +0 -122
  62. package/docs/interfaces/CognitoUserGeneric.html +0 -125
  63. package/docs/interfaces/CopyObjectOptions.html +0 -132
  64. package/docs/interfaces/CreateDownloadURLFromDataOptions.html +0 -163
  65. package/docs/interfaces/CreateUserOptions.html +0 -122
  66. package/docs/interfaces/DeleteObjectOptions.html +0 -122
  67. package/docs/interfaces/DetectSentimentParameters.html +0 -121
  68. package/docs/interfaces/EmailAttachment.html +0 -176
  69. package/docs/interfaces/EmailData.html +0 -188
  70. package/docs/interfaces/GetObjectOptions.html +0 -133
  71. package/docs/interfaces/HeadObjectOptions.html +0 -132
  72. package/docs/interfaces/InternalAPIRequestParams.html +0 -207
  73. package/docs/interfaces/ListObjectsOptions.html +0 -122
  74. package/docs/interfaces/PutObjectOptions.html +0 -173
  75. package/docs/interfaces/ResourceControllerOptions.html +0 -142
  76. package/docs/interfaces/SESParams.html +0 -152
  77. package/docs/interfaces/SNSCreateEndpointParams.html +0 -132
  78. package/docs/interfaces/SNSPublishParams.html +0 -142
  79. package/docs/interfaces/SignedURLOptions.html +0 -123
  80. package/docs/interfaces/TemplatedEmailData.html +0 -186
  81. package/docs/interfaces/TranslateParameters.html +0 -140
  82. package/docs/modules.html +0 -130
  83. package/docs/variables/LOG_LEVELS_PRIORITY.html +0 -81
  84. package/docs.style.css +0 -4
  85. package/src/attachments.ts +0 -41
  86. package/src/cognito.ts +0 -511
  87. package/src/comprehend.ts +0 -52
  88. package/src/dynamoDB.ts +0 -311
  89. package/src/genericController.ts +0 -103
  90. package/src/lambdaLogger.ts +0 -39
  91. package/src/metrics.ts +0 -45
  92. package/src/resourceController.ts +0 -645
  93. package/src/s3.ts +0 -334
  94. package/src/secretsManager.ts +0 -24
  95. package/src/ses.ts +0 -313
  96. package/src/sns.ts +0 -118
  97. package/src/ssm.ts +0 -33
  98. package/src/streamController.ts +0 -25
  99. package/src/translate.ts +0 -174
  100. package/tsconfig.json +0 -10
package/src/sns.ts DELETED
@@ -1,118 +0,0 @@
1
- import * as AWSSNS from '@aws-sdk/client-sns';
2
- import { PushNotificationsPlatforms } from 'idea-toolbox';
3
-
4
- import { LambdaLogger } from './lambdaLogger';
5
-
6
- /**
7
- * A wrapper for AWS Simple Notification Service.
8
- */
9
- export class SNS {
10
- protected client: AWSSNS.SNSClient;
11
- protected logger = new LambdaLogger();
12
-
13
- constructor(options: { region?: string } = {}) {
14
- this.client = new AWSSNS.SNSClient({ region: options.region });
15
- }
16
-
17
- /**
18
- * Create a new endpoint in the SNS platform specified.
19
- * @return platform endpoint ARN
20
- */
21
- async createPlatormEndpoint(
22
- platform: PushNotificationsPlatforms,
23
- token: string,
24
- options: SNSCreateEndpointParams
25
- ): Promise<string> {
26
- let platformARN: string;
27
- switch (platform) {
28
- case PushNotificationsPlatforms.APNS:
29
- platformARN = options.appleArn;
30
- break;
31
- case PushNotificationsPlatforms.APNS_SANDBOX:
32
- platformARN = options.appleDevArn;
33
- break;
34
- case PushNotificationsPlatforms.FCM:
35
- platformARN = options.androidArn;
36
- break;
37
- default:
38
- throw new Error('Unsupported platform');
39
- }
40
-
41
- this.logger.trace('SNS add platform endpoint');
42
- const command = new AWSSNS.CreatePlatformEndpointCommand({ PlatformApplicationArn: platformARN, Token: token });
43
- const { EndpointArn } = await this.client.send(command);
44
- return EndpointArn;
45
- }
46
-
47
- /**
48
- * Publish a message to a SNS endpoint.
49
- */
50
- async publish(options: SNSPublishParams): Promise<AWSSNS.PublishCommandOutput> {
51
- let structuredMessage;
52
- if (options.json) structuredMessage = { default: JSON.stringify(options.json) };
53
- else
54
- switch (options.platform) {
55
- case PushNotificationsPlatforms.APNS:
56
- structuredMessage = { APNS: JSON.stringify({ aps: { alert: options.message } }) };
57
- break;
58
- case PushNotificationsPlatforms.APNS_SANDBOX:
59
- structuredMessage = { APNS_SANDBOX: JSON.stringify({ aps: { alert: options.message } }) };
60
- break;
61
- case PushNotificationsPlatforms.FCM:
62
- structuredMessage = {
63
- GCM: JSON.stringify({ notification: { body: options.message, title: options.message } })
64
- };
65
- break;
66
- default:
67
- throw new Error('Unsupported platform');
68
- }
69
-
70
- this.logger.trace('SNS publish in topic');
71
- const command = new AWSSNS.PublishCommand({
72
- MessageStructure: 'json',
73
- Message: JSON.stringify(structuredMessage),
74
- TargetArn: options.endpoint
75
- });
76
- return await this.client.send(command);
77
- }
78
- }
79
-
80
- /**
81
- * Options for creating a SNS endpoint.
82
- */
83
- export interface SNSCreateEndpointParams {
84
- /**
85
- * ARN to production of Apple's (iOS, MacOS) notification services.
86
- */
87
- appleArn?: string;
88
- /**
89
- * ARN to development of Apple's (iOS, MacOS) notification services.
90
- */
91
- appleDevArn?: string;
92
- /**
93
- * ARN to Android's notification services.
94
- */
95
- androidArn?: string;
96
- }
97
-
98
- /**
99
- * Options to publish a message on a SNS endpoint.
100
- */
101
- export interface SNSPublishParams {
102
- /**
103
- * The endpoint of the notification.
104
- */
105
- endpoint: string;
106
- /**
107
- * The message to send.
108
- */
109
- message?: string;
110
- /**
111
- * The platform receiver; used to structure the message.
112
- */
113
- platform?: PushNotificationsPlatforms;
114
- /**
115
- * If set, message and platform will be ignored and the content of this attribute will be preferred.
116
- */
117
- json?: any;
118
- }
package/src/ssm.ts DELETED
@@ -1,33 +0,0 @@
1
- import * as AWSSystemsManager from '@aws-sdk/client-ssm';
2
-
3
- /**
4
- * A wrapper for AWS Systems Manager (SSM).
5
- */
6
- export class SystemsManager {
7
- protected ssm: AWSSystemsManager.SSMClient;
8
- protected cache = new Map<string, string>();
9
-
10
- constructor() {
11
- this.ssm = new AWSSystemsManager.SSMClient();
12
- }
13
-
14
- /**
15
- * Get a parameter by its name (path).
16
- */
17
- async getParameterByName(
18
- name: string,
19
- options: { noCache?: boolean; withDecryption?: boolean } = {}
20
- ): Promise<string> {
21
- if (!options.noCache && this.cache.has(name)) return this.cache.get(name);
22
- const command = new AWSSystemsManager.GetParameterCommand({ Name: name, WithDecryption: options.withDecryption });
23
- const { Parameter } = await this.ssm.send(command);
24
- this.cache.set(name, Parameter.Value);
25
- return Parameter.Value;
26
- }
27
- /**
28
- * Get a parameter (with decryption) by its name (path).
29
- */
30
- async getSecretByName(name: string, options: { noCache?: boolean } = {}): Promise<string> {
31
- return this.getParameterByName(name, { ...options, withDecryption: true });
32
- }
33
- }
@@ -1,25 +0,0 @@
1
- import { DynamoDBRecord } from 'aws-lambda';
2
-
3
- import { GenericController } from './genericController';
4
-
5
- /**
6
- * An abstract class to inherit to manage AWS DDB streams in an AWS Lambda function.
7
- */
8
- export abstract class StreamController extends GenericController {
9
- records: any[];
10
-
11
- constructor(event: any, callback: any) {
12
- super(event, callback);
13
- this.records = event.Records ?? [];
14
- }
15
-
16
- protected abstract handleRecord(record: DynamoDBRecord): Promise<void>;
17
-
18
- async handleRequest(): Promise<void> {
19
- this.logger.info('START', { streamOfRecords: this.records.length ?? 0 });
20
-
21
- await Promise.all(this.records.map(record => this.handleRecord(record)))
22
- .then((): void => this.done())
23
- .catch((err: Error): void => this.done(this.handleControllerError(err, 'STREAM-ERROR', 'Operation failed')));
24
- }
25
- }
package/src/translate.ts DELETED
@@ -1,174 +0,0 @@
1
- import * as AWSTranslate from '@aws-sdk/client-translate';
2
- import {
3
- Languages,
4
- PDFEntity,
5
- PDFTemplateComplexField,
6
- PDFTemplateSection,
7
- PDFTemplateSectionTypes,
8
- PDFTemplateSimpleField
9
- } from 'idea-toolbox';
10
-
11
- /**
12
- * A wrapper for Amazon Translate.
13
- */
14
- export class Translate {
15
- protected translate: AWSTranslate.TranslateClient;
16
-
17
- /**
18
- * Default input language code.
19
- */
20
- sourceLanguageCode = 'en';
21
- /**
22
- * Default output language code.
23
- */
24
- targetLanguageCode = 'en';
25
- /**
26
- * Default terminology list.
27
- */
28
- terminologyNames: string[] = [];
29
-
30
- /**
31
- * Initialize a new Translate helper object.
32
- */
33
- constructor(options: { region?: string } = {}) {
34
- this.translate = new AWSTranslate.TranslateClient({ region: options.region });
35
- }
36
-
37
- /**
38
- * Translates input text from the source language to the target language.
39
- * @param params the parameters for translateText
40
- */
41
- async text(params: TranslateParameters): Promise<string> {
42
- if (params.sourceLanguageCode) this.sourceLanguageCode = params.sourceLanguageCode;
43
- if (params.targetLanguageCode) this.targetLanguageCode = params.targetLanguageCode;
44
- if (params.terminologyNames) this.terminologyNames = params.terminologyNames;
45
-
46
- if (!this.sourceLanguageCode || !this.targetLanguageCode || !params.text) throw new Error('Bad parameters');
47
-
48
- const command = new AWSTranslate.TranslateTextCommand({
49
- Text: params.text,
50
- SourceLanguageCode: this.sourceLanguageCode,
51
- TargetLanguageCode: this.targetLanguageCode,
52
- TerminologyNames: this.terminologyNames
53
- });
54
- const { TranslatedText } = await this.translate.send(command);
55
-
56
- return TranslatedText;
57
- }
58
-
59
- /**
60
- * Get the contents of a PDF template (against a PDFEntity) translated in the desired language,
61
- * if the latter isn't between the ones already available.
62
- * @return an object that maps original texts with their translations (or nothing).
63
- */
64
- async pdfTemplate(
65
- entity: PDFEntity,
66
- template: PDFTemplateSection[],
67
- language: string,
68
- languages: Languages
69
- ): Promise<Record<string, string>> {
70
- // if the language is included in the ones supported by the team, skip
71
- if (languages.available.some(l => l === language)) return null;
72
-
73
- // analyse the template to extract terms to translate based on the entity (using a sourceLanguage as reference)
74
- const termsToTranslate = Array.from(
75
- await this.analysePDFTemplateForTermsToTranslate(template, entity, languages.default)
76
- );
77
-
78
- const translations: { [original: string]: string } = {};
79
- for (let i = 0; i < termsToTranslate.length; i++) {
80
- const original = termsToTranslate[i];
81
- const translated = await this.text({
82
- sourceLanguageCode: languages.default,
83
- targetLanguageCode: language,
84
- text: original
85
- });
86
- translations[original] = translated
87
- // fix markdown issue (the translations add a space before and after asterisks)
88
- .replace(/\*\* /gm, '**')
89
- .replace(/ \*\*/gm, '**');
90
- }
91
- return translations;
92
- }
93
- /**
94
- * Analyse a PDFTemplate to extract terms to translate based on a PDFEntity (using a sourceLanguage as reference).
95
- */
96
- protected async analysePDFTemplateForTermsToTranslate(
97
- template: PDFTemplateSection[],
98
- entity: PDFEntity,
99
- sourceLanguage: string
100
- ): Promise<Set<string>> {
101
- const toTranslate = new Set<string>();
102
- // gather the terms to translate from contents available on this level
103
- template
104
- .filter(s => s.isEither(PDFTemplateSectionTypes.ROW, PDFTemplateSectionTypes.HEADER))
105
- .forEach(s => {
106
- switch (s.type) {
107
- case PDFTemplateSectionTypes.ROW:
108
- s.columns
109
- .filter((_, index): boolean => s.doesColumnContainAField(index))
110
- .forEach(field => {
111
- field = field as PDFTemplateSimpleField | PDFTemplateComplexField;
112
- if (field.isComplex()) {
113
- const complex = field as PDFTemplateComplexField;
114
- toTranslate.add(complex.content[sourceLanguage]);
115
- } else {
116
- const simple = field as PDFTemplateSimpleField;
117
- toTranslate.add(simple.label[sourceLanguage]);
118
- // try to consider only notes (long fields)
119
- if (typeof entity[simple.code] === 'string' && entity[simple.code].length > 50)
120
- toTranslate.add(entity[simple.code]);
121
- }
122
- });
123
- break;
124
- case PDFTemplateSectionTypes.HEADER:
125
- toTranslate.add(s.title[sourceLanguage]);
126
- break;
127
- }
128
- });
129
- // gather inner sections in a flat structure for further elaboraton
130
- const innerSections = new Array<{ data: any; template: PDFTemplateSection[] }>();
131
- template
132
- .filter(s => s.isEither(PDFTemplateSectionTypes.INNER_SECTION, PDFTemplateSectionTypes.REPEATED_INNER_SECTION))
133
- .forEach(s => {
134
- switch (s.type) {
135
- case PDFTemplateSectionTypes.INNER_SECTION:
136
- innerSections.push({ data: entity[s.context], template: s.innerTemplate });
137
- break;
138
- case PDFTemplateSectionTypes.REPEATED_INNER_SECTION:
139
- entity[s.context].forEach((element: PDFEntity): number =>
140
- innerSections.push({ data: element, template: s.innerTemplate })
141
- );
142
- break;
143
- }
144
- });
145
- // run (inception) the inner sections to gather terms to translate from inner levels
146
- for (let i = 0; i < innerSections.length; i++) {
147
- const s = innerSections[i];
148
- const res = await this.analysePDFTemplateForTermsToTranslate(s.template, s.data, sourceLanguage);
149
- res.forEach(x => toTranslate.add(x));
150
- }
151
- return toTranslate;
152
- }
153
- }
154
-
155
- export interface TranslateParameters {
156
- /**
157
- * The text to translate. Required.
158
- * The text string can be a maximum of 5,000 bytes long; depending on the char set, it may be fewer than 5,000 chars.
159
- */
160
- text: string;
161
- /**
162
- * The input language.
163
- */
164
- sourceLanguageCode?: string;
165
- /**
166
- * The output language.
167
- */
168
- targetLanguageCode?: string;
169
- /**
170
- * The name of the terminology list file to be used in the TranslateText request.
171
- * Terminology lists can contain a maximum of 256 terms.
172
- */
173
- terminologyNames?: string[];
174
- }
package/tsconfig.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "./node_modules/@tsconfig/node18/tsconfig.json",
3
- "compilerOptions": {
4
- "useDefineForClassFields": false,
5
- "declaration": true,
6
- "strictPropertyInitialization": false,
7
- "strictNullChecks": false,
8
- "outDir": "dist"
9
- }
10
- }