@forge/notification 0.2.2 → 0.3.0-next.0-experimental-5b18257
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/CHANGELOG.md +12 -0
- package/out/index.d.ts +1 -1
- package/out/index.d.ts.map +1 -1
- package/out/types.d.ts +55 -9
- package/out/types.d.ts.map +1 -1
- package/out/util.d.ts.map +1 -1
- package/out/util.js +14 -6
- package/out/validators.d.ts.map +1 -1
- package/out/validators.js +56 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @forge/notification
|
|
2
2
|
|
|
3
|
+
## 0.3.0-next.0-experimental-5b18257
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ff1594c: Modified NotificationPayload type to support custom templates. Added more types to types.ts. Since users can now specify template id, removed hardcoded template id used inside util.ts to instead use the template id supplied by user. Also had to remove validation check for htmlBody since not all templates use this field anymore. Modified existing unit tests to include 'id' field in NotificationPayload and added some unit tests for each of the new templates.
|
|
8
|
+
|
|
9
|
+
## 0.3.0-next.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- ff1594c: Modified NotificationPayload type to support custom templates. Added more types to types.ts. Since users can now specify template id, removed hardcoded template id used inside util.ts to instead use the template id supplied by user. Also had to remove validation check for htmlBody since not all templates use this field anymore. Modified existing unit tests to include 'id' field in NotificationPayload and added some unit tests for each of the new templates.
|
|
14
|
+
|
|
3
15
|
## 0.2.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/out/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { NotificationApi } from './notification-api';
|
|
2
2
|
export { NotificationApi as default } from './notification-api';
|
|
3
|
-
export { NotificationPayload, DeliveryChannel, RecipientType,
|
|
3
|
+
export { NotificationPayload, DeliveryChannel, RecipientType, NotificationResponse, EmailRecipient } from './types';
|
|
4
4
|
export { NotificationError, InvalidPayloadError, RateLimitError, InternalServerError } from './errors';
|
|
5
5
|
export { validateAPIResponse } from './validators';
|
|
6
6
|
export type { APIResponse, FetchMethod } from '@forge/api';
|
package/out/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,EAAE,eAAe,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGhE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,EAAE,eAAe,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGhE,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,aAAa,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAGpH,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAGvG,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGnD,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
package/out/types.d.ts
CHANGED
|
@@ -14,10 +14,9 @@ export declare enum RecipientType {
|
|
|
14
14
|
}
|
|
15
15
|
export declare type NotificationPayload = {
|
|
16
16
|
deliveryChannel?: DeliveryChannel;
|
|
17
|
-
context: MessageTemplateContext;
|
|
18
17
|
recipientsUserIds?: string[];
|
|
19
18
|
recipientEmails?: EmailRecipient[];
|
|
20
|
-
};
|
|
19
|
+
} & MessageTemplateData;
|
|
21
20
|
export declare type EmailRecipient = {
|
|
22
21
|
emailAddress: string;
|
|
23
22
|
locale?: string;
|
|
@@ -30,17 +29,14 @@ export declare type RecipientsToProcess = {
|
|
|
30
29
|
emailAddresses: EmailRecipient[];
|
|
31
30
|
};
|
|
32
31
|
};
|
|
33
|
-
export declare type MessageTemplateData =
|
|
32
|
+
export declare type MessageTemplateData = Basic | Action | Confirmation | Custom;
|
|
33
|
+
export declare type InternalMessageTemplateData = {
|
|
34
34
|
id: string;
|
|
35
|
-
context:
|
|
36
|
-
};
|
|
37
|
-
export declare type MessageTemplateContext = {
|
|
38
|
-
subject: string;
|
|
39
|
-
htmlBody: string;
|
|
35
|
+
context: BasicContext | ActionContext | ConfirmationContext | CustomContext;
|
|
40
36
|
};
|
|
41
37
|
export declare type NotificationPORequest = {
|
|
42
38
|
triggerId: string;
|
|
43
|
-
messageTemplateData:
|
|
39
|
+
messageTemplateData: InternalMessageTemplateData;
|
|
44
40
|
recipientsToProcess: RecipientsToProcess;
|
|
45
41
|
client: string;
|
|
46
42
|
eventTime?: string;
|
|
@@ -52,5 +48,55 @@ export interface NotificationResponse {
|
|
|
52
48
|
triggerId?: string;
|
|
53
49
|
errors?: string[];
|
|
54
50
|
}
|
|
51
|
+
declare type Basic = {
|
|
52
|
+
id: 'basic';
|
|
53
|
+
context: BasicContext;
|
|
54
|
+
};
|
|
55
|
+
declare type Action = {
|
|
56
|
+
id: 'action';
|
|
57
|
+
context: ActionContext;
|
|
58
|
+
};
|
|
59
|
+
declare type Confirmation = {
|
|
60
|
+
id: 'confirmation';
|
|
61
|
+
context: ConfirmationContext;
|
|
62
|
+
};
|
|
63
|
+
declare type Custom = {
|
|
64
|
+
id: 'custom';
|
|
65
|
+
context: CustomContext;
|
|
66
|
+
};
|
|
67
|
+
declare type BasicContext = {
|
|
68
|
+
subject: string;
|
|
69
|
+
headline: string;
|
|
70
|
+
copy: string;
|
|
71
|
+
supportUrl: string;
|
|
72
|
+
footerLinkItems: LinkItem[];
|
|
73
|
+
disclaimer: string;
|
|
74
|
+
};
|
|
75
|
+
declare type ActionContext = {
|
|
76
|
+
subject: string;
|
|
77
|
+
headline: string;
|
|
78
|
+
copy: string;
|
|
79
|
+
ctaLinkItem: LinkItem;
|
|
80
|
+
supportUrl: string;
|
|
81
|
+
footerLinkItems: LinkItem[];
|
|
82
|
+
disclaimer: string;
|
|
83
|
+
};
|
|
84
|
+
declare type ConfirmationContext = {
|
|
85
|
+
subject: string;
|
|
86
|
+
headline: string;
|
|
87
|
+
copy: string;
|
|
88
|
+
ctaLinkItem: LinkItem;
|
|
89
|
+
supportUrl: string;
|
|
90
|
+
footerLinkItems: LinkItem[];
|
|
91
|
+
disclaimer: string;
|
|
92
|
+
};
|
|
93
|
+
declare type CustomContext = {
|
|
94
|
+
subject: string;
|
|
95
|
+
htmlBody: string;
|
|
96
|
+
};
|
|
97
|
+
declare type LinkItem = {
|
|
98
|
+
text: string;
|
|
99
|
+
link: string;
|
|
100
|
+
};
|
|
55
101
|
export {};
|
|
56
102
|
//# sourceMappingURL=types.d.ts.map
|
package/out/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,UAAU,GAAG;IACX,QAAQ,EAAE,MAAM,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,MAAM,CAAC;CACvB;AAED,oBAAY,eAAe,GAAG,GAAG,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD,oBAAY,eAAe;IACzB,KAAK,UAAU;CAChB;AAED,oBAAY,aAAa;IACvB,aAAa,iBAAiB;IAC9B,UAAU,cAAc;CACzB;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,UAAU,GAAG;IACX,QAAQ,EAAE,MAAM,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,MAAM,CAAC;CACvB;AAED,oBAAY,eAAe,GAAG,GAAG,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAA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;CAClB,CAAC;AAEF,aAAK,QAAQ,GAAG;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
|
package/out/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,qBAAqB,EAAuB,MAAM,SAAS,CAAC;AAI3G,eAAO,MAAM,mBAAmB,WAAY,MAAM,KAAG,eAGnD,CAAC;AAEH,eAAO,MAAM,2BAA2B,UAAW,mBAAmB,aAAa,MAAM,KAAG,qBA4B3F,CAAC"}
|
package/out/util.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createNotificationPORequest = exports.userIdToIdentityAri = void 0;
|
|
4
4
|
const CLIENT_FORGE_NOTIFICATION_SDK = 'forge-notification-sdk';
|
|
5
|
-
const ECOSYSTEM_FORGE_NOTIFICATION_TEMPLATE = 'ecosystem-forge-notifications-spike';
|
|
6
5
|
const userIdToIdentityAri = (userId) => ({
|
|
7
6
|
userId,
|
|
8
7
|
toString: () => `ari:cloud:identity::user/${userId}`
|
|
@@ -21,16 +20,25 @@ const createNotificationPORequest = (input, triggerId) => {
|
|
|
21
20
|
emailAddresses: input.recipientEmails
|
|
22
21
|
};
|
|
23
22
|
}
|
|
24
|
-
const messageTemplateData = {
|
|
25
|
-
id: ECOSYSTEM_FORGE_NOTIFICATION_TEMPLATE,
|
|
26
|
-
context: input.context
|
|
27
|
-
};
|
|
28
23
|
return {
|
|
29
24
|
triggerId,
|
|
30
|
-
messageTemplateData,
|
|
25
|
+
messageTemplateData: { id: mapping(input.id), context: input.context },
|
|
31
26
|
recipientsToProcess: recipientsToProcess,
|
|
32
27
|
eventTime: new Date().toISOString(),
|
|
33
28
|
client: CLIENT_FORGE_NOTIFICATION_SDK
|
|
34
29
|
};
|
|
35
30
|
};
|
|
36
31
|
exports.createNotificationPORequest = createNotificationPORequest;
|
|
32
|
+
const mapping = (id) => {
|
|
33
|
+
switch (id) {
|
|
34
|
+
case 'basic':
|
|
35
|
+
return 'forge-basic-notification';
|
|
36
|
+
case 'action':
|
|
37
|
+
return 'forge-action-notification';
|
|
38
|
+
case 'confirmation':
|
|
39
|
+
return 'forge-confirmation-notification';
|
|
40
|
+
case 'custom':
|
|
41
|
+
default:
|
|
42
|
+
return 'ecosystem-forge-notifications-spike';
|
|
43
|
+
}
|
|
44
|
+
};
|
package/out/validators.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,eAAO,MAAM,2BAA2B,YAAa,mBAAmB,
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,eAAO,MAAM,2BAA2B,YAAa,mBAAmB,YA8GvE,CAAC;AAEF,eAAO,MAAM,mBAAmB,aAAoB,WAAW,kBAe9D,CAAC"}
|
package/out/validators.js
CHANGED
|
@@ -37,11 +37,63 @@ const validateNotificationPayload = (payload) => {
|
|
|
37
37
|
if (!hasValidUserIds && !hasValidEmails) {
|
|
38
38
|
throw new errors_1.InvalidPayloadError('Either recipientsUserIds or recipientEmails must be provided');
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
const validIds = ['custom', 'confirmation', 'action', 'basic'];
|
|
41
|
+
if (!payload.id || typeof payload.id !== 'string' || !validIds.includes(payload.id)) {
|
|
42
|
+
throw new errors_1.InvalidPayloadError('Missing or invalid id');
|
|
42
43
|
}
|
|
43
|
-
if (!payload.context
|
|
44
|
-
throw new errors_1.InvalidPayloadError('Missing or invalid
|
|
44
|
+
if (!payload.context || typeof payload.context !== 'object') {
|
|
45
|
+
throw new errors_1.InvalidPayloadError('Missing or invalid context');
|
|
46
|
+
}
|
|
47
|
+
switch (payload.id) {
|
|
48
|
+
case 'custom':
|
|
49
|
+
if (!payload.context.subject || typeof payload.context.subject !== 'string') {
|
|
50
|
+
throw new errors_1.InvalidPayloadError('Missing or invalid subject');
|
|
51
|
+
}
|
|
52
|
+
if (!payload.context.htmlBody || typeof payload.context.htmlBody !== 'string') {
|
|
53
|
+
throw new errors_1.InvalidPayloadError('Missing or invalid htmlBody');
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
case 'confirmation':
|
|
57
|
+
case 'action':
|
|
58
|
+
case 'basic':
|
|
59
|
+
if (!payload.context.subject || typeof payload.context.subject !== 'string') {
|
|
60
|
+
throw new errors_1.InvalidPayloadError('Missing or invalid subject');
|
|
61
|
+
}
|
|
62
|
+
if (!payload.context.headline || typeof payload.context.headline !== 'string') {
|
|
63
|
+
throw new errors_1.InvalidPayloadError('Missing or invalid headline');
|
|
64
|
+
}
|
|
65
|
+
if (!payload.context.copy || typeof payload.context.copy !== 'string') {
|
|
66
|
+
throw new errors_1.InvalidPayloadError('Missing or invalid copy');
|
|
67
|
+
}
|
|
68
|
+
if (!payload.context.supportUrl || typeof payload.context.supportUrl !== 'string') {
|
|
69
|
+
throw new errors_1.InvalidPayloadError('Missing or invalid supportUrl');
|
|
70
|
+
}
|
|
71
|
+
if (!payload.context.footerLinkItems || !Array.isArray(payload.context.footerLinkItems)) {
|
|
72
|
+
throw new errors_1.InvalidPayloadError('Missing or invalid footerLinkItems');
|
|
73
|
+
}
|
|
74
|
+
for (const footerLinkItem of payload.context.footerLinkItems) {
|
|
75
|
+
if (!footerLinkItem.text || typeof footerLinkItem.text !== 'string') {
|
|
76
|
+
throw new errors_1.InvalidPayloadError('Missing or invalid footerLinkItem text');
|
|
77
|
+
}
|
|
78
|
+
if (!footerLinkItem.link || typeof footerLinkItem.link !== 'string') {
|
|
79
|
+
throw new errors_1.InvalidPayloadError('Missing or invalid footerLinkItem link');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (!payload.context.disclaimer || typeof payload.context.disclaimer !== 'string') {
|
|
83
|
+
throw new errors_1.InvalidPayloadError('Missing or invalid disclaimer');
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
if (payload.id === 'action' || payload.id === 'confirmation') {
|
|
88
|
+
if (!payload.context.ctaLinkItem || typeof payload.context.ctaLinkItem !== 'object') {
|
|
89
|
+
throw new errors_1.InvalidPayloadError('Missing or invalid ctaLinkItem');
|
|
90
|
+
}
|
|
91
|
+
if (!payload.context.ctaLinkItem.text || typeof payload.context.ctaLinkItem.text !== 'string') {
|
|
92
|
+
throw new errors_1.InvalidPayloadError('Missing or invalid ctaLinkItem text');
|
|
93
|
+
}
|
|
94
|
+
if (!payload.context.ctaLinkItem.link || typeof payload.context.ctaLinkItem.link !== 'string') {
|
|
95
|
+
throw new errors_1.InvalidPayloadError('Missing or invalid ctaLinkItem link');
|
|
96
|
+
}
|
|
45
97
|
}
|
|
46
98
|
return true;
|
|
47
99
|
};
|