@randstad-uca/aws-sns-publisher 1.2.3 → 1.2.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.
- package/build/constants.d.ts +1 -0
- package/build/constants.js +1 -0
- package/build/generate-schema-doc.js +5 -0
- package/build/schemas/certifications.schema.js +4 -3
- package/build/schemas/custom-events.schema.d.ts +2 -0
- package/build/schemas/custom-events.schema.js +18 -0
- package/build/schemas/cv.schema.js +0 -1
- package/build/schemas/education.schema.js +0 -2
- package/build/schemas/index.d.ts +1 -0
- package/build/schemas/index.js +1 -0
- package/build/schemas/language.schema.js +3 -3
- package/build/schemas/personal-data.schema.js +0 -1
- package/build/schemas/work-experience.schema.js +0 -2
- package/build/types/certifications.type.d.ts +0 -1
- package/build/types/custom-events.type.d.ts +12 -0
- package/build/types/custom-events.type.js +6 -0
- package/build/types/cv.type.d.ts +0 -1
- package/build/types/education.type.d.ts +0 -3
- package/build/types/index.d.ts +1 -0
- package/build/types/index.js +1 -0
- package/build/types/language.type.d.ts +0 -3
- package/build/types/personal-data.type.d.ts +0 -1
- package/build/types/user-identity.type.d.ts +0 -1
- package/build/types/work-experience.type.d.ts +0 -3
- package/build/validator.js +4 -0
- package/package.json +50 -50
- package/readme.md +156 -156
- package/schema-doc.md +0 -12
package/build/constants.d.ts
CHANGED
package/build/constants.js
CHANGED
|
@@ -21,6 +21,7 @@ const push_schema_1 = require("./schemas/push.schema");
|
|
|
21
21
|
const cv_schema_1 = require("./schemas/cv.schema");
|
|
22
22
|
const user_identity_schema_1 = require("./schemas/user-identity.schema");
|
|
23
23
|
const one_signal_schema_1 = require("./schemas/one-signal.schema");
|
|
24
|
+
const custom_events_schema_1 = require("./schemas/custom-events.schema");
|
|
24
25
|
const schemas = {
|
|
25
26
|
[constants_1.validEventTypes.sms]: { schema: sms_schema_1.SMSSchema, label: 'SMS' },
|
|
26
27
|
[constants_1.validEventTypes.updatePersonalData]: {
|
|
@@ -119,6 +120,10 @@ const schemas = {
|
|
|
119
120
|
schema: one_signal_schema_1.DeleteOneSignalUserSchema,
|
|
120
121
|
label: 'Delete OneSignal User',
|
|
121
122
|
},
|
|
123
|
+
[constants_1.validEventTypes.customEvents]: {
|
|
124
|
+
schema: custom_events_schema_1.CustomEventsSchema,
|
|
125
|
+
label: 'Custom Events',
|
|
126
|
+
},
|
|
122
127
|
};
|
|
123
128
|
function getFieldsFromJoi(schema) {
|
|
124
129
|
const description = schema.describe();
|
|
@@ -5,10 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.UpdateCertificationsSchema = void 0;
|
|
7
7
|
const joi_1 = __importDefault(require("joi"));
|
|
8
|
+
const userId = joi_1.default.string().uuid().required();
|
|
9
|
+
const certificaciones = joi_1.default.string().valid('si', 'no').required();
|
|
8
10
|
exports.UpdateCertificationsSchema = joi_1.default.object({
|
|
9
|
-
userId
|
|
10
|
-
certificaciones
|
|
11
|
-
fechaActualizacionPerfil: joi_1.default.date().timestamp('javascript').required(),
|
|
11
|
+
userId,
|
|
12
|
+
certificaciones,
|
|
12
13
|
})
|
|
13
14
|
.unknown(false)
|
|
14
15
|
.meta({ className: 'UpdateCertificationsType' });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CustomEventsSchema = void 0;
|
|
7
|
+
const joi_1 = __importDefault(require("joi"));
|
|
8
|
+
const CustomEventItemSchema = joi_1.default.object({
|
|
9
|
+
name: joi_1.default.string().required(),
|
|
10
|
+
external_id: joi_1.default.string().uuid().required(),
|
|
11
|
+
properties: joi_1.default.object().pattern(joi_1.default.string(), joi_1.default.string()).optional(),
|
|
12
|
+
idempotency_key: joi_1.default.string().uuid().optional(),
|
|
13
|
+
}).unknown(false);
|
|
14
|
+
exports.CustomEventsSchema = joi_1.default.array()
|
|
15
|
+
.items(CustomEventItemSchema)
|
|
16
|
+
.min(1)
|
|
17
|
+
.required()
|
|
18
|
+
.meta({ className: 'CustomEventsType' });
|
|
@@ -8,7 +8,6 @@ const joi_1 = __importDefault(require("joi"));
|
|
|
8
8
|
exports.SetCvSchema = joi_1.default.object({
|
|
9
9
|
userId: joi_1.default.string().uuid().required(),
|
|
10
10
|
cvAdjunto: joi_1.default.string().valid('si', 'no').required(),
|
|
11
|
-
fechaActualizacionPerfil: joi_1.default.date().timestamp('javascript').required(),
|
|
12
11
|
})
|
|
13
12
|
.unknown(false)
|
|
14
13
|
.meta({ className: 'SetCvType' });
|
|
@@ -14,14 +14,12 @@ const estado = joi_1.default.string()
|
|
|
14
14
|
.valid('completo', 'incompleto', 'en curso')
|
|
15
15
|
.required();
|
|
16
16
|
const nivelMaximo = joi_1.default.number().integer().min(1).required();
|
|
17
|
-
const fechaActualizacionPerfil = joi_1.default.date().timestamp('javascript').required();
|
|
18
17
|
const baseFields = {
|
|
19
18
|
userId,
|
|
20
19
|
nivel,
|
|
21
20
|
area,
|
|
22
21
|
estado,
|
|
23
22
|
nivelMaximo,
|
|
24
|
-
fechaActualizacionPerfil,
|
|
25
23
|
};
|
|
26
24
|
exports.AddEducationSchema = joi_1.default.object(baseFields)
|
|
27
25
|
.unknown(false)
|
package/build/schemas/index.d.ts
CHANGED
package/build/schemas/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./alert.schema"), exports);
|
|
18
18
|
__exportStar(require("./certifications.schema"), exports);
|
|
19
|
+
__exportStar(require("./custom-events.schema"), exports);
|
|
19
20
|
__exportStar(require("./update-documents-status.schema"), exports);
|
|
20
21
|
__exportStar(require("./education.schema"), exports);
|
|
21
22
|
__exportStar(require("./email.schema"), exports);
|
|
@@ -5,18 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DeleteLanguageSchema = exports.UpdateLanguageSchema = exports.AddLanguageSchema = void 0;
|
|
7
7
|
const joi_1 = __importDefault(require("joi"));
|
|
8
|
+
const idioma = joi_1.default.string().min(1).max(50).required();
|
|
8
9
|
const baseFields = {
|
|
9
10
|
userId: joi_1.default.string().uuid().required(),
|
|
10
11
|
nivelMaximo: joi_1.default.number().integer().min(1).required(),
|
|
11
|
-
idioma
|
|
12
|
-
fechaActualizacionPerfil: joi_1.default.date().timestamp('javascript').required(),
|
|
12
|
+
idioma,
|
|
13
13
|
};
|
|
14
14
|
exports.AddLanguageSchema = joi_1.default.object(baseFields)
|
|
15
15
|
.unknown(false)
|
|
16
16
|
.meta({ className: 'AddLanguageType' });
|
|
17
17
|
exports.UpdateLanguageSchema = joi_1.default.object({
|
|
18
18
|
...baseFields,
|
|
19
|
-
prevIdioma:
|
|
19
|
+
prevIdioma: idioma,
|
|
20
20
|
})
|
|
21
21
|
.unknown(false)
|
|
22
22
|
.meta({ className: 'UpdateLanguageType' });
|
|
@@ -22,7 +22,6 @@ const baseFields = {
|
|
|
22
22
|
.message('phone number must be in E.164 format (e.g., +5491234567890)')
|
|
23
23
|
.optional(),
|
|
24
24
|
subscriptions: one_signal_schema_1.SubscriptionSchema.optional(),
|
|
25
|
-
fechaActualizacionPerfil: joi_1.default.date().timestamp('javascript').required(),
|
|
26
25
|
};
|
|
27
26
|
exports.UpdatePersonalDataSchema = joi_1.default.object(baseFields)
|
|
28
27
|
.unknown(false)
|
|
@@ -10,14 +10,12 @@ const puesto = joi_1.default.string().min(1).max(45).required();
|
|
|
10
10
|
const area = joi_1.default.string().min(1).max(45).required();
|
|
11
11
|
const rubro = joi_1.default.string().min(1).max(45).required();
|
|
12
12
|
const nivelMaximo = joi_1.default.number().integer().min(1).required();
|
|
13
|
-
const fechaActualizacionPerfil = joi_1.default.date().timestamp('javascript').required();
|
|
14
13
|
const baseFields = {
|
|
15
14
|
userId,
|
|
16
15
|
puesto,
|
|
17
16
|
area,
|
|
18
17
|
rubro,
|
|
19
18
|
nivelMaximo,
|
|
20
|
-
fechaActualizacionPerfil,
|
|
21
19
|
};
|
|
22
20
|
exports.AddWorkExperienceSchema = joi_1.default.object(baseFields)
|
|
23
21
|
.unknown(false)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by joi-to-typescript
|
|
3
|
+
* Do not modify this file manually
|
|
4
|
+
*/
|
|
5
|
+
export interface CustomEventItem {
|
|
6
|
+
name: string;
|
|
7
|
+
external_id: string;
|
|
8
|
+
properties: {
|
|
9
|
+
[key: string]: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export type CustomEventsType = CustomEventItem[];
|
package/build/types/cv.type.d.ts
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
export interface AddEducationType {
|
|
6
6
|
area?: string;
|
|
7
7
|
estado: 'completo' | 'incompleto' | 'en curso';
|
|
8
|
-
fechaActualizacionPerfil: Date;
|
|
9
8
|
nivel: 'primario' | 'secundario' | 'terciario' | 'universitario' | 'posgrado' | 'master' | 'doctorado';
|
|
10
9
|
nivelMaximo: number;
|
|
11
10
|
userId: string;
|
|
@@ -13,7 +12,6 @@ export interface AddEducationType {
|
|
|
13
12
|
export interface DeleteEducationType {
|
|
14
13
|
area?: string;
|
|
15
14
|
estado: 'completo' | 'incompleto' | 'en curso';
|
|
16
|
-
fechaActualizacionPerfil: Date;
|
|
17
15
|
nivel: 'primario' | 'secundario' | 'terciario' | 'universitario' | 'posgrado' | 'master' | 'doctorado';
|
|
18
16
|
nivelMaximo: number;
|
|
19
17
|
userId: string;
|
|
@@ -21,7 +19,6 @@ export interface DeleteEducationType {
|
|
|
21
19
|
export interface UpdateEducationType {
|
|
22
20
|
area?: string;
|
|
23
21
|
estado: 'completo' | 'incompleto' | 'en curso';
|
|
24
|
-
fechaActualizacionPerfil: Date;
|
|
25
22
|
nivel: 'primario' | 'secundario' | 'terciario' | 'universitario' | 'posgrado' | 'master' | 'doctorado';
|
|
26
23
|
nivelMaximo: number;
|
|
27
24
|
prevArea?: string;
|
package/build/types/index.d.ts
CHANGED
package/build/types/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
__exportStar(require("./alert.type"), exports);
|
|
22
22
|
__exportStar(require("./certifications.type"), exports);
|
|
23
|
+
__exportStar(require("./custom-events.type"), exports);
|
|
23
24
|
__exportStar(require("./cv.type"), exports);
|
|
24
25
|
__exportStar(require("./education.type"), exports);
|
|
25
26
|
__exportStar(require("./email.type"), exports);
|
|
@@ -3,19 +3,16 @@
|
|
|
3
3
|
* Do not modify this file manually
|
|
4
4
|
*/
|
|
5
5
|
export interface AddLanguageType {
|
|
6
|
-
fechaActualizacionPerfil: Date;
|
|
7
6
|
idioma: string;
|
|
8
7
|
nivelMaximo: number;
|
|
9
8
|
userId: string;
|
|
10
9
|
}
|
|
11
10
|
export interface DeleteLanguageType {
|
|
12
|
-
fechaActualizacionPerfil: Date;
|
|
13
11
|
idioma: string;
|
|
14
12
|
nivelMaximo: number;
|
|
15
13
|
userId: string;
|
|
16
14
|
}
|
|
17
15
|
export interface UpdateLanguageType {
|
|
18
|
-
fechaActualizacionPerfil: Date;
|
|
19
16
|
idioma: string;
|
|
20
17
|
nivelMaximo: number;
|
|
21
18
|
prevIdioma: string;
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export interface AddWorkExperienceType {
|
|
6
6
|
area: string;
|
|
7
|
-
fechaActualizacionPerfil: Date;
|
|
8
7
|
nivelMaximo: number;
|
|
9
8
|
puesto: string;
|
|
10
9
|
rubro: string;
|
|
@@ -12,7 +11,6 @@ export interface AddWorkExperienceType {
|
|
|
12
11
|
}
|
|
13
12
|
export interface DeleteWorkExperienceType {
|
|
14
13
|
area: string;
|
|
15
|
-
fechaActualizacionPerfil: Date;
|
|
16
14
|
nivelMaximo: number;
|
|
17
15
|
puesto: string;
|
|
18
16
|
rubro: string;
|
|
@@ -20,7 +18,6 @@ export interface DeleteWorkExperienceType {
|
|
|
20
18
|
}
|
|
21
19
|
export interface UpdateWorkExperienceType {
|
|
22
20
|
area: string;
|
|
23
|
-
fechaActualizacionPerfil: Date;
|
|
24
21
|
nivelMaximo: number;
|
|
25
22
|
prevArea: string;
|
|
26
23
|
prevPuesto: string;
|
package/build/validator.js
CHANGED
|
@@ -17,6 +17,7 @@ const cv_schema_1 = require("./schemas/cv.schema");
|
|
|
17
17
|
const update_documents_status_schema_1 = require("./schemas/update-documents-status.schema");
|
|
18
18
|
const user_identity_schema_1 = require("./schemas/user-identity.schema");
|
|
19
19
|
const one_signal_schema_1 = require("./schemas/one-signal.schema");
|
|
20
|
+
const custom_events_schema_1 = require("./schemas/custom-events.schema");
|
|
20
21
|
const validateSchema = (eventType, data) => {
|
|
21
22
|
let schema;
|
|
22
23
|
switch (eventType) {
|
|
@@ -94,6 +95,9 @@ const validateSchema = (eventType, data) => {
|
|
|
94
95
|
case constants_1.validEventTypes.deleteOneSignalUser:
|
|
95
96
|
schema = one_signal_schema_1.DeleteOneSignalUserSchema;
|
|
96
97
|
break;
|
|
98
|
+
case constants_1.validEventTypes.customEvents:
|
|
99
|
+
schema = custom_events_schema_1.CustomEventsSchema;
|
|
100
|
+
break;
|
|
97
101
|
default:
|
|
98
102
|
console.error(`Unknown event type: ${eventType}`);
|
|
99
103
|
return false;
|
package/package.json
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@randstad-uca/aws-sns-publisher",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"description": "AWS SNS Publisher",
|
|
5
|
-
"main": "./build/index.js",
|
|
6
|
-
"types": "./build/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"build/**/*",
|
|
9
|
-
"schema-doc.md"
|
|
10
|
-
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
"clean": "rimraf build",
|
|
13
|
-
"build": "npm run clean && npx tsc",
|
|
14
|
-
"test": "echo \"No tests implemented yet\" && exit 0",
|
|
15
|
-
"prepublishOnly": "npm run test && npm run generate-types && npm run generate-doc && npm run build",
|
|
16
|
-
"pub": "npm publish",
|
|
17
|
-
"generate-doc": "ts-node ./src/generate-schema-doc.ts",
|
|
18
|
-
"generate-types": "ts-node ./src/generate-types.ts"
|
|
19
|
-
},
|
|
20
|
-
"keywords": [
|
|
21
|
-
"aws",
|
|
22
|
-
"sns",
|
|
23
|
-
"publisher"
|
|
24
|
-
],
|
|
25
|
-
"author": "Facundo Brusa",
|
|
26
|
-
"repository": {
|
|
27
|
-
"type": "git",
|
|
28
|
-
"url": "git+https://github.com/randstad-argentina/aws-sns-publisher.git"
|
|
29
|
-
},
|
|
30
|
-
"bugs": {
|
|
31
|
-
"url": "https://github.com/randstad-argentina/aws-sns-publisher/issues"
|
|
32
|
-
},
|
|
33
|
-
"homepage": "https://github.com/randstad-argentina/aws-sns-publisher#readme",
|
|
34
|
-
"license": "ISC",
|
|
35
|
-
"publishConfig": {
|
|
36
|
-
"access": "public"
|
|
37
|
-
},
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"@types/node": "^22.15.17",
|
|
40
|
-
"joi-to-typescript": "^4.15.0",
|
|
41
|
-
"rimraf": "^6.0.1",
|
|
42
|
-
"ts-node": "^10.9.2",
|
|
43
|
-
"typescript": "^5.7.3"
|
|
44
|
-
},
|
|
45
|
-
"dependencies": {
|
|
46
|
-
"@aws-sdk/client-sns": "^3.741.0",
|
|
47
|
-
"joi": "^17.13.3",
|
|
48
|
-
"uuid": "^11.0.5"
|
|
49
|
-
}
|
|
50
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@randstad-uca/aws-sns-publisher",
|
|
3
|
+
"version": "1.2.4",
|
|
4
|
+
"description": "AWS SNS Publisher",
|
|
5
|
+
"main": "./build/index.js",
|
|
6
|
+
"types": "./build/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"build/**/*",
|
|
9
|
+
"schema-doc.md"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"clean": "rimraf build",
|
|
13
|
+
"build": "npm run clean && npx tsc",
|
|
14
|
+
"test": "echo \"No tests implemented yet\" && exit 0",
|
|
15
|
+
"prepublishOnly": "npm run test && npm run generate-types && npm run generate-doc && npm run build",
|
|
16
|
+
"pub": "npm publish",
|
|
17
|
+
"generate-doc": "ts-node ./src/generate-schema-doc.ts",
|
|
18
|
+
"generate-types": "ts-node ./src/generate-types.ts"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"aws",
|
|
22
|
+
"sns",
|
|
23
|
+
"publisher"
|
|
24
|
+
],
|
|
25
|
+
"author": "Facundo Brusa",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/randstad-argentina/aws-sns-publisher.git"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/randstad-argentina/aws-sns-publisher/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/randstad-argentina/aws-sns-publisher#readme",
|
|
34
|
+
"license": "ISC",
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^22.15.17",
|
|
40
|
+
"joi-to-typescript": "^4.15.0",
|
|
41
|
+
"rimraf": "^6.0.1",
|
|
42
|
+
"ts-node": "^10.9.2",
|
|
43
|
+
"typescript": "^5.7.3"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@aws-sdk/client-sns": "^3.741.0",
|
|
47
|
+
"joi": "^17.13.3",
|
|
48
|
+
"uuid": "^11.0.5"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/readme.md
CHANGED
|
@@ -1,156 +1,156 @@
|
|
|
1
|
-
# @randstad-uca/aws-sns-publisher
|
|
2
|
-
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Es una librería ligera desarrollada en Node.js para publicar mensajes a Amazon SNS de forma simple, validada y con logging configurable. Ideal para sistemas desacoplados y orientados a eventos en entornos AWS.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## 📦 Instalación
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm install @randstad-uca/aws-sns-publisher
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## 🚀 Uso Básico
|
|
18
|
-
|
|
19
|
-
```js
|
|
20
|
-
import { SimpleSNSPublisher } from '@randstad-uca/aws-sns-publisher';
|
|
21
|
-
|
|
22
|
-
const SNSClient = new SimpleSNSPublisher({
|
|
23
|
-
awsConfig: { region: 'us-east-1' }, // required obj
|
|
24
|
-
logEnabled: true, // optional (default value: true)
|
|
25
|
-
logLevel: 'info', // optional (default value: info)
|
|
26
|
-
throwError: true, // optional (default value: true)
|
|
27
|
-
logHandler: {
|
|
28
|
-
// You can implement your own logging handler here (optional)
|
|
29
|
-
info: (args) =>
|
|
30
|
-
// success case
|
|
31
|
-
console.log('Custom success logging handler logic', args),
|
|
32
|
-
error: (args) =>
|
|
33
|
-
// error case
|
|
34
|
-
console.error('Custom error logging handler logic', args),
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const payload = {
|
|
39
|
-
eventType: 'sms',
|
|
40
|
-
payload: {
|
|
41
|
-
phone: '+543564123123',
|
|
42
|
-
message: 'Hello there!',
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
SNSClient.publish({
|
|
47
|
-
message: JSON.stringify(payload),
|
|
48
|
-
topicARN: 'your-sns-topic-ARN',
|
|
49
|
-
apiName: 'api-name', // If the topic type is FIFO you must define a valid apiName
|
|
50
|
-
})
|
|
51
|
-
.then((result) => console.log('Success:', result))
|
|
52
|
-
.catch((err) => console.error('Error:', err));
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
---
|
|
56
|
-
|
|
57
|
-
## 📘 API
|
|
58
|
-
|
|
59
|
-
#### Clase: `SimpleSNSPublisher`
|
|
60
|
-
|
|
61
|
-
##### Constructor
|
|
62
|
-
```js
|
|
63
|
-
new SimpleSNSPublisher(options: IPublisherOptions)
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
`IPublisherOptions:`
|
|
67
|
-
|
|
68
|
-
- `awsConfig: SNSClientConfig` – **Requerido**. Como minimo se debe especificar la región de AWS para instanciar el cliente SNS.
|
|
69
|
-
|
|
70
|
-
- `logEnabled?: boolean` – Habilita logs. Default: `true`.
|
|
71
|
-
|
|
72
|
-
- `logLevel?: 'info' | 'silent'` – Nivel de log. Default: `'info'`.
|
|
73
|
-
|
|
74
|
-
- `throwError?: boolean` – Si lanzar errores o no. Default: `true`.
|
|
75
|
-
|
|
76
|
-
- `logHandler?: { info: Function; error: Function }` – Handler personalizado para logs.
|
|
77
|
-
|
|
78
|
-
---
|
|
79
|
-
|
|
80
|
-
## ✨ Metodos
|
|
81
|
-
|
|
82
|
-
#### Método: `publish(options: IPublishOptions): Promise<PublishResponse>`
|
|
83
|
-
|
|
84
|
-
Publica un mensaje en un topic SNS. Antes de enviar el mensaje, se valida su estructura usando la libreria `Joi`.
|
|
85
|
-
|
|
86
|
-
`IPublishOptions`:
|
|
87
|
-
|
|
88
|
-
- `message: string` – Debe ser un string que contenga un objeto, y este **debe** tener las siguientes propiedades:
|
|
89
|
-
|
|
90
|
-
- `eventType: string` – Tipo del evento (ej: `"sms"`, `"add-personal-data"` o cualquiera que se encuentre dentro del objeto ***validEventTypes*** ubicado en el archivo `constants.ts`).
|
|
91
|
-
|
|
92
|
-
- `payload: object` – Objeto con los datos del evento.
|
|
93
|
-
|
|
94
|
-
- `topicARN: string` – ARN del SNS Topic.
|
|
95
|
-
|
|
96
|
-
- `apiName?: string` – Nombre de la API emisora, las unicas validas son las que se encuentran dentro del objeto ***validApiNames*** ubicado en el archivo `constants.ts`.
|
|
97
|
-
<span style="color: red;">Esta se utiliza como bandera para la creación del MessageDeduplicationId y MessageGroupId necesarios en topics FIFO.</span>
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
- `extraOptions?: object` – Parámetros adicionales para `PublishCommand`.
|
|
101
|
-
|
|
102
|
-
**Validaciones automáticas:**
|
|
103
|
-
|
|
104
|
-
- `eventType` es obligatorio y debe estar en la lista de eventos válidos.
|
|
105
|
-
|
|
106
|
-
- Se valida el `payload` según el tipo de evento con esquemas Joi definidos internamente.
|
|
107
|
-
|
|
108
|
-
- Si se configura `throwError: true`, lanza error. Si no, devuelve `Promise.reject()` con el error.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
#### Método: `validateSchema(eventType: string, payload: object): boolean`
|
|
112
|
-
|
|
113
|
-
Valida el `payload` contra el esquema correspondiente según eventType.
|
|
114
|
-
|
|
115
|
-
---
|
|
116
|
-
|
|
117
|
-
### 📎 Ejemplo de payload válido
|
|
118
|
-
|
|
119
|
-
```json
|
|
120
|
-
{
|
|
121
|
-
"eventType": "email",
|
|
122
|
-
"payload": {
|
|
123
|
-
"to": "user@example.com",
|
|
124
|
-
"subject": "Hello!",
|
|
125
|
-
"body": "This is an example email."
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
---
|
|
131
|
-
|
|
132
|
-
## 📄 Schema Documentation
|
|
133
|
-
|
|
134
|
-
See [schema-doc.md](./schema-doc.md) for a full list of event types and their schema fields
|
|
135
|
-
|
|
136
|
-
---
|
|
137
|
-
|
|
138
|
-
🧩 Características
|
|
139
|
-
|
|
140
|
-
- ✅ Compatible con múltiples regiones AWS.
|
|
141
|
-
|
|
142
|
-
- ✅ Validación automática con Joi.
|
|
143
|
-
|
|
144
|
-
- ✅ Logging personalizable (info y error).
|
|
145
|
-
|
|
146
|
-
- ✅ Ideal para arquitectura orientada a eventos.
|
|
147
|
-
|
|
148
|
-
---
|
|
149
|
-
|
|
150
|
-
📌 Consideraciones
|
|
151
|
-
|
|
152
|
-
- Se espera que los topics estén previamente creados en SNS.
|
|
153
|
-
|
|
154
|
-
- Esta librería no crea los topics automáticamente.
|
|
155
|
-
|
|
156
|
-
- <span style="color:red">En caso de usar topics FIFO, es importante pasar un `apiName` **valido** para deduplicación.</span>
|
|
1
|
+
# @randstad-uca/aws-sns-publisher
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Es una librería ligera desarrollada en Node.js para publicar mensajes a Amazon SNS de forma simple, validada y con logging configurable. Ideal para sistemas desacoplados y orientados a eventos en entornos AWS.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 📦 Instalación
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @randstad-uca/aws-sns-publisher
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 🚀 Uso Básico
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import { SimpleSNSPublisher } from '@randstad-uca/aws-sns-publisher';
|
|
21
|
+
|
|
22
|
+
const SNSClient = new SimpleSNSPublisher({
|
|
23
|
+
awsConfig: { region: 'us-east-1' }, // required obj
|
|
24
|
+
logEnabled: true, // optional (default value: true)
|
|
25
|
+
logLevel: 'info', // optional (default value: info)
|
|
26
|
+
throwError: true, // optional (default value: true)
|
|
27
|
+
logHandler: {
|
|
28
|
+
// You can implement your own logging handler here (optional)
|
|
29
|
+
info: (args) =>
|
|
30
|
+
// success case
|
|
31
|
+
console.log('Custom success logging handler logic', args),
|
|
32
|
+
error: (args) =>
|
|
33
|
+
// error case
|
|
34
|
+
console.error('Custom error logging handler logic', args),
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const payload = {
|
|
39
|
+
eventType: 'sms',
|
|
40
|
+
payload: {
|
|
41
|
+
phone: '+543564123123',
|
|
42
|
+
message: 'Hello there!',
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
SNSClient.publish({
|
|
47
|
+
message: JSON.stringify(payload),
|
|
48
|
+
topicARN: 'your-sns-topic-ARN',
|
|
49
|
+
apiName: 'api-name', // If the topic type is FIFO you must define a valid apiName
|
|
50
|
+
})
|
|
51
|
+
.then((result) => console.log('Success:', result))
|
|
52
|
+
.catch((err) => console.error('Error:', err));
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 📘 API
|
|
58
|
+
|
|
59
|
+
#### Clase: `SimpleSNSPublisher`
|
|
60
|
+
|
|
61
|
+
##### Constructor
|
|
62
|
+
```js
|
|
63
|
+
new SimpleSNSPublisher(options: IPublisherOptions)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`IPublisherOptions:`
|
|
67
|
+
|
|
68
|
+
- `awsConfig: SNSClientConfig` – **Requerido**. Como minimo se debe especificar la región de AWS para instanciar el cliente SNS.
|
|
69
|
+
|
|
70
|
+
- `logEnabled?: boolean` – Habilita logs. Default: `true`.
|
|
71
|
+
|
|
72
|
+
- `logLevel?: 'info' | 'silent'` – Nivel de log. Default: `'info'`.
|
|
73
|
+
|
|
74
|
+
- `throwError?: boolean` – Si lanzar errores o no. Default: `true`.
|
|
75
|
+
|
|
76
|
+
- `logHandler?: { info: Function; error: Function }` – Handler personalizado para logs.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## ✨ Metodos
|
|
81
|
+
|
|
82
|
+
#### Método: `publish(options: IPublishOptions): Promise<PublishResponse>`
|
|
83
|
+
|
|
84
|
+
Publica un mensaje en un topic SNS. Antes de enviar el mensaje, se valida su estructura usando la libreria `Joi`.
|
|
85
|
+
|
|
86
|
+
`IPublishOptions`:
|
|
87
|
+
|
|
88
|
+
- `message: string` – Debe ser un string que contenga un objeto, y este **debe** tener las siguientes propiedades:
|
|
89
|
+
|
|
90
|
+
- `eventType: string` – Tipo del evento (ej: `"sms"`, `"add-personal-data"` o cualquiera que se encuentre dentro del objeto ***validEventTypes*** ubicado en el archivo `constants.ts`).
|
|
91
|
+
|
|
92
|
+
- `payload: object` – Objeto con los datos del evento.
|
|
93
|
+
|
|
94
|
+
- `topicARN: string` – ARN del SNS Topic.
|
|
95
|
+
|
|
96
|
+
- `apiName?: string` – Nombre de la API emisora, las unicas validas son las que se encuentran dentro del objeto ***validApiNames*** ubicado en el archivo `constants.ts`.
|
|
97
|
+
<span style="color: red;">Esta se utiliza como bandera para la creación del MessageDeduplicationId y MessageGroupId necesarios en topics FIFO.</span>
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
- `extraOptions?: object` – Parámetros adicionales para `PublishCommand`.
|
|
101
|
+
|
|
102
|
+
**Validaciones automáticas:**
|
|
103
|
+
|
|
104
|
+
- `eventType` es obligatorio y debe estar en la lista de eventos válidos.
|
|
105
|
+
|
|
106
|
+
- Se valida el `payload` según el tipo de evento con esquemas Joi definidos internamente.
|
|
107
|
+
|
|
108
|
+
- Si se configura `throwError: true`, lanza error. Si no, devuelve `Promise.reject()` con el error.
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
#### Método: `validateSchema(eventType: string, payload: object): boolean`
|
|
112
|
+
|
|
113
|
+
Valida el `payload` contra el esquema correspondiente según eventType.
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
### 📎 Ejemplo de payload válido
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"eventType": "email",
|
|
122
|
+
"payload": {
|
|
123
|
+
"to": "user@example.com",
|
|
124
|
+
"subject": "Hello!",
|
|
125
|
+
"body": "This is an example email."
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## 📄 Schema Documentation
|
|
133
|
+
|
|
134
|
+
See [schema-doc.md](./schema-doc.md) for a full list of event types and their schema fields
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
🧩 Características
|
|
139
|
+
|
|
140
|
+
- ✅ Compatible con múltiples regiones AWS.
|
|
141
|
+
|
|
142
|
+
- ✅ Validación automática con Joi.
|
|
143
|
+
|
|
144
|
+
- ✅ Logging personalizable (info y error).
|
|
145
|
+
|
|
146
|
+
- ✅ Ideal para arquitectura orientada a eventos.
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
📌 Consideraciones
|
|
151
|
+
|
|
152
|
+
- Se espera que los topics estén previamente creados en SNS.
|
|
153
|
+
|
|
154
|
+
- Esta librería no crea los topics automáticamente.
|
|
155
|
+
|
|
156
|
+
- <span style="color:red">En caso de usar topics FIFO, es importante pasar un `apiName` **valido** para deduplicación.</span>
|
package/schema-doc.md
CHANGED
|
@@ -18,7 +18,6 @@ This file describes the required and optional fields for each `eventType`.
|
|
|
18
18
|
|
|
19
19
|
**Required fields:**
|
|
20
20
|
- `userId` (string)
|
|
21
|
-
- `fechaActualizacionPerfil` (date)
|
|
22
21
|
|
|
23
22
|
**Optional fields:**
|
|
24
23
|
- `email` (string)
|
|
@@ -49,7 +48,6 @@ This file describes the required and optional fields for each `eventType`.
|
|
|
49
48
|
- `nivel` (string) (valid: 'primario', 'secundario', 'terciario', 'universitario', 'posgrado', 'master', 'doctorado')
|
|
50
49
|
- `estado` (string) (valid: 'completo', 'incompleto', 'en curso')
|
|
51
50
|
- `nivelMaximo` (number)
|
|
52
|
-
- `fechaActualizacionPerfil` (date)
|
|
53
51
|
|
|
54
52
|
**Optional fields:**
|
|
55
53
|
- `area` (string)
|
|
@@ -63,7 +61,6 @@ This file describes the required and optional fields for each `eventType`.
|
|
|
63
61
|
- `nivel` (string) (valid: 'primario', 'secundario', 'terciario', 'universitario', 'posgrado', 'master', 'doctorado')
|
|
64
62
|
- `estado` (string) (valid: 'completo', 'incompleto', 'en curso')
|
|
65
63
|
- `nivelMaximo` (number)
|
|
66
|
-
- `fechaActualizacionPerfil` (date)
|
|
67
64
|
- `prevNivel` (string) (valid: 'primario', 'secundario', 'terciario', 'universitario', 'posgrado', 'master', 'doctorado')
|
|
68
65
|
- `prevEstado` (string) (valid: 'completo', 'incompleto', 'en curso')
|
|
69
66
|
|
|
@@ -80,7 +77,6 @@ This file describes the required and optional fields for each `eventType`.
|
|
|
80
77
|
- `nivel` (string) (valid: 'primario', 'secundario', 'terciario', 'universitario', 'posgrado', 'master', 'doctorado')
|
|
81
78
|
- `estado` (string) (valid: 'completo', 'incompleto', 'en curso')
|
|
82
79
|
- `nivelMaximo` (number)
|
|
83
|
-
- `fechaActualizacionPerfil` (date)
|
|
84
80
|
|
|
85
81
|
**Optional fields:**
|
|
86
82
|
- `area` (string)
|
|
@@ -95,7 +91,6 @@ This file describes the required and optional fields for each `eventType`.
|
|
|
95
91
|
- `area` (string)
|
|
96
92
|
- `rubro` (string)
|
|
97
93
|
- `nivelMaximo` (number)
|
|
98
|
-
- `fechaActualizacionPerfil` (date)
|
|
99
94
|
|
|
100
95
|
**Optional fields:**
|
|
101
96
|
- *(none)*
|
|
@@ -110,7 +105,6 @@ This file describes the required and optional fields for each `eventType`.
|
|
|
110
105
|
- `area` (string)
|
|
111
106
|
- `rubro` (string)
|
|
112
107
|
- `nivelMaximo` (number)
|
|
113
|
-
- `fechaActualizacionPerfil` (date)
|
|
114
108
|
- `prevPuesto` (string)
|
|
115
109
|
- `prevArea` (string)
|
|
116
110
|
- `prevRubro` (string)
|
|
@@ -128,7 +122,6 @@ This file describes the required and optional fields for each `eventType`.
|
|
|
128
122
|
- `area` (string)
|
|
129
123
|
- `rubro` (string)
|
|
130
124
|
- `nivelMaximo` (number)
|
|
131
|
-
- `fechaActualizacionPerfil` (date)
|
|
132
125
|
|
|
133
126
|
**Optional fields:**
|
|
134
127
|
- *(none)*
|
|
@@ -194,7 +187,6 @@ This file describes the required and optional fields for each `eventType`.
|
|
|
194
187
|
- `userId` (string)
|
|
195
188
|
- `nivelMaximo` (number)
|
|
196
189
|
- `idioma` (string)
|
|
197
|
-
- `fechaActualizacionPerfil` (date)
|
|
198
190
|
|
|
199
191
|
**Optional fields:**
|
|
200
192
|
- *(none)*
|
|
@@ -207,7 +199,6 @@ This file describes the required and optional fields for each `eventType`.
|
|
|
207
199
|
- `userId` (string)
|
|
208
200
|
- `nivelMaximo` (number)
|
|
209
201
|
- `idioma` (string)
|
|
210
|
-
- `fechaActualizacionPerfil` (date)
|
|
211
202
|
- `prevIdioma` (string)
|
|
212
203
|
|
|
213
204
|
**Optional fields:**
|
|
@@ -221,7 +212,6 @@ This file describes the required and optional fields for each `eventType`.
|
|
|
221
212
|
- `userId` (string)
|
|
222
213
|
- `nivelMaximo` (number)
|
|
223
214
|
- `idioma` (string)
|
|
224
|
-
- `fechaActualizacionPerfil` (date)
|
|
225
215
|
|
|
226
216
|
**Optional fields:**
|
|
227
217
|
- *(none)*
|
|
@@ -233,7 +223,6 @@ This file describes the required and optional fields for each `eventType`.
|
|
|
233
223
|
**Required fields:**
|
|
234
224
|
- `userId` (string)
|
|
235
225
|
- `cvAdjunto` (string) (valid: 'si', 'no')
|
|
236
|
-
- `fechaActualizacionPerfil` (date)
|
|
237
226
|
|
|
238
227
|
**Optional fields:**
|
|
239
228
|
- *(none)*
|
|
@@ -331,7 +320,6 @@ This file describes the required and optional fields for each `eventType`.
|
|
|
331
320
|
|
|
332
321
|
**Required fields:**
|
|
333
322
|
- `userId` (string)
|
|
334
|
-
- `fechaActualizacionPerfil` (date)
|
|
335
323
|
- `alerta` (string) (valid: 'si', 'no', '')
|
|
336
324
|
- `cvAdjunto` (string) (valid: 'si', 'no')
|
|
337
325
|
- `certificaciones` (string) (valid: 'si', 'no')
|