@forge/notification 0.1.1-next.0 → 0.2.0-next.1
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 +6 -0
- package/out/fetch.d.ts +0 -2
- package/out/fetch.d.ts.map +1 -1
- package/out/fetch.js +1 -12
- package/out/index.d.ts +1 -1
- package/out/index.d.ts.map +1 -1
- package/out/notification-api.d.ts +1 -2
- package/out/notification-api.d.ts.map +1 -1
- package/out/notification-api.js +1 -18
- package/out/types.d.ts +0 -12
- package/out/types.d.ts.map +1 -1
- package/out/validators.d.ts +2 -3
- package/out/validators.d.ts.map +1 -1
- package/out/validators.js +3 -35
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/out/fetch.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { APIResponse, FetchMethod } from '@forge/api';
|
|
2
2
|
export declare const POST_OFFICE_FORGE_NOTIFICATION_PATH = "/post-office/api/v1/forge/notification/{contextAri}/{environmentId}/{appId}/{cloudId}";
|
|
3
|
-
export declare const POST_OFFICE_FORGE_STATUS_PATH = "/post-office/api/v1/forge/notification/status/{contextAri}/{environmentId}/{appId}/{cloudId}";
|
|
4
3
|
export declare const post: (endpoint: string, body: unknown, apiClient: FetchMethod) => Promise<APIResponse>;
|
|
5
|
-
export declare const get: (endpoint: string, apiClient: FetchMethod) => Promise<APIResponse>;
|
|
6
4
|
//# sourceMappingURL=fetch.d.ts.map
|
package/out/fetch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtD,eAAO,MAAM,mCAAmC,0FACyC,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtD,eAAO,MAAM,mCAAmC,0FACyC,CAAC;AAE1F,eAAO,MAAM,IAAI,aAAoB,MAAM,QAAQ,OAAO,aAAa,WAAW,KAAG,QAAQ,WAAW,CAUvG,CAAC"}
|
package/out/fetch.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.post = exports.POST_OFFICE_FORGE_NOTIFICATION_PATH = void 0;
|
|
4
4
|
exports.POST_OFFICE_FORGE_NOTIFICATION_PATH = '/post-office/api/v1/forge/notification/{contextAri}/{environmentId}/{appId}/{cloudId}';
|
|
5
|
-
exports.POST_OFFICE_FORGE_STATUS_PATH = '/post-office/api/v1/forge/notification/status/{contextAri}/{environmentId}/{appId}/{cloudId}';
|
|
6
5
|
const post = async (endpoint, body, apiClient) => {
|
|
7
6
|
const request = {
|
|
8
7
|
method: 'POST',
|
|
@@ -14,13 +13,3 @@ const post = async (endpoint, body, apiClient) => {
|
|
|
14
13
|
return await apiClient(endpoint, request);
|
|
15
14
|
};
|
|
16
15
|
exports.post = post;
|
|
17
|
-
const get = async (endpoint, apiClient) => {
|
|
18
|
-
const request = {
|
|
19
|
-
method: 'GET',
|
|
20
|
-
headers: {
|
|
21
|
-
'content-type': 'application/json'
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
return await apiClient(endpoint, request);
|
|
25
|
-
};
|
|
26
|
-
exports.get = get;
|
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, MessageTemplateContext, 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,EACL,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,
|
|
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,EACL,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACpB,cAAc,EACf,MAAM,SAAS,CAAC;AAGjB,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"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { FetchMethod } from '@forge/api';
|
|
2
|
-
import {
|
|
2
|
+
import { NotificationPayload, NotificationResponse } from './types';
|
|
3
3
|
export declare class NotificationApi {
|
|
4
4
|
private readonly apiClient;
|
|
5
5
|
constructor(apiClient?: FetchMethod);
|
|
6
6
|
sendNotification(payload: NotificationPayload): Promise<NotificationResponse>;
|
|
7
|
-
getNotificationStatus(triggerId: string, recipient: string, recipientType: RecipientType, deliveryChannel: DeliveryChannel): Promise<NotificationStatusResponse>;
|
|
8
7
|
}
|
|
9
8
|
//# sourceMappingURL=notification-api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-api.d.ts","sourceRoot":"","sources":["../src/notification-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,WAAW,EAAE,MAAM,YAAY,CAAC;AAGlE,OAAO,
|
|
1
|
+
{"version":3,"file":"notification-api.d.ts","sourceRoot":"","sources":["../src/notification-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,WAAW,EAAE,MAAM,YAAY,CAAC;AAGlE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAIpE,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,GAAE,WAAqC;IAEvE,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;CAcpF"}
|
package/out/notification-api.js
CHANGED
|
@@ -4,7 +4,6 @@ exports.NotificationApi = void 0;
|
|
|
4
4
|
const api_1 = require("@forge/api");
|
|
5
5
|
const uuid_1 = require("uuid");
|
|
6
6
|
const fetch_1 = require("./fetch");
|
|
7
|
-
const types_1 = require("./types");
|
|
8
7
|
const validators_1 = require("./validators");
|
|
9
8
|
const util_1 = require("./util");
|
|
10
9
|
class NotificationApi {
|
|
@@ -17,27 +16,11 @@ class NotificationApi {
|
|
|
17
16
|
const triggerId = (0, uuid_1.v4)();
|
|
18
17
|
const notificationPORequest = (0, util_1.createNotificationPORequest)(payload, triggerId);
|
|
19
18
|
const response = await (0, fetch_1.post)(fetch_1.POST_OFFICE_FORGE_NOTIFICATION_PATH, notificationPORequest, this.apiClient);
|
|
20
|
-
await (0, validators_1.validateAPIResponse)(response
|
|
19
|
+
await (0, validators_1.validateAPIResponse)(response);
|
|
21
20
|
return {
|
|
22
21
|
...(await response.json()),
|
|
23
22
|
triggerId
|
|
24
23
|
};
|
|
25
24
|
}
|
|
26
|
-
async getNotificationStatus(triggerId, recipient, recipientType, deliveryChannel) {
|
|
27
|
-
(0, validators_1.validateNotificationStatusParams)(triggerId, recipient, recipientType, deliveryChannel);
|
|
28
|
-
const endpoint = `${fetch_1.POST_OFFICE_FORGE_STATUS_PATH}?triggerId=${encodeURIComponent(triggerId)}&recipient=${encodeURIComponent(recipientType === types_1.RecipientType.ACCOUNT_ID ? (0, util_1.userIdToIdentityAri)(recipient).toString() : recipient)}&recipientType=${encodeURIComponent(recipientType)}&deliveryChannel=${encodeURIComponent(deliveryChannel)}`;
|
|
29
|
-
const response = await (0, fetch_1.get)(endpoint, this.apiClient);
|
|
30
|
-
await (0, validators_1.validateAPIResponse)(response, 'status');
|
|
31
|
-
const responseData = await response.json();
|
|
32
|
-
const allStatuses = Array.isArray(responseData.allStatuses) ? responseData.allStatuses : [];
|
|
33
|
-
return {
|
|
34
|
-
triggerId: responseData.triggerId,
|
|
35
|
-
recipient: responseData.recipient,
|
|
36
|
-
deliveryChannel: responseData.deliveryChannel,
|
|
37
|
-
latestStatus: allStatuses.length > 0 ? allStatuses[0].status : responseData.deliveryStatus,
|
|
38
|
-
allStatuses,
|
|
39
|
-
errors: responseData.errors
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
25
|
}
|
|
43
26
|
exports.NotificationApi = NotificationApi;
|
package/out/types.d.ts
CHANGED
|
@@ -52,17 +52,5 @@ export interface NotificationResponse {
|
|
|
52
52
|
triggerId?: string;
|
|
53
53
|
errors?: string[];
|
|
54
54
|
}
|
|
55
|
-
export interface StatusDetails {
|
|
56
|
-
status: string;
|
|
57
|
-
timestamp: number;
|
|
58
|
-
}
|
|
59
|
-
export interface NotificationStatusResponse {
|
|
60
|
-
triggerId: string;
|
|
61
|
-
recipient: string;
|
|
62
|
-
deliveryChannel: string;
|
|
63
|
-
latestStatus: string;
|
|
64
|
-
allStatuses: StatusDetails[];
|
|
65
|
-
errors?: string[];
|
|
66
|
-
}
|
|
67
55
|
export {};
|
|
68
56
|
//# 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;AACD,oBAAY,mBAAmB,GAAG;IAChC,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,OAAO,EAAE,sBAAsB,CAAC;IAChC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,eAAe,CAAC,EAAE,cAAc,EAAE,CAAC;CACpC,CAAC;AAEF,oBAAY,cAAc,GAAG;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,oBAAY,mBAAmB,GAAG;IAChC,KAAK,CAAC,EAAE;QACN,OAAO,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC;IACF,MAAM,CAAC,EAAE;QACP,cAAc,EAAE,cAAc,EAAE,CAAC;KAClC,CAAC;CACH,CAAC;AAEF,oBAAY,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,sBAAsB,CAAC;CACjC,CAAC;AAEF,oBAAY,sBAAsB,GAAG;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,oBAAY,qBAAqB,GAAG;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,mBAAmB,EAA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AE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,sBAAsB,CAAC;CACjC,CAAC;AAEF,oBAAY,sBAAsB,GAAG;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,oBAAY,qBAAqB,GAAG;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,eAAe,EAAE,CAAC;CAC5B,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB"}
|
package/out/validators.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NotificationPayload } from './types';
|
|
2
2
|
import { APIResponse } from '@forge/api';
|
|
3
3
|
export declare const validateNotificationPayload: (payload: NotificationPayload) => boolean;
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const validateAPIResponse: (response: APIResponse, method: 'notification' | 'status') => Promise<void>;
|
|
4
|
+
export declare const validateAPIResponse: (response: APIResponse) => Promise<void>;
|
|
6
5
|
//# sourceMappingURL=validators.d.ts.map
|
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,
|
|
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,YAqDvE,CAAC;AAEF,eAAO,MAAM,mBAAmB,aAAoB,WAAW,kBAe9D,CAAC"}
|
package/out/validators.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateAPIResponse = exports.
|
|
3
|
+
exports.validateAPIResponse = exports.validateNotificationPayload = void 0;
|
|
4
4
|
const errors_1 = require("./errors");
|
|
5
|
-
const types_1 = require("./types");
|
|
6
5
|
const validateNotificationPayload = (payload) => {
|
|
7
6
|
if (!payload || typeof payload !== 'object') {
|
|
8
7
|
throw new errors_1.InvalidPayloadError('Payload must be an object');
|
|
@@ -47,38 +46,7 @@ const validateNotificationPayload = (payload) => {
|
|
|
47
46
|
return true;
|
|
48
47
|
};
|
|
49
48
|
exports.validateNotificationPayload = validateNotificationPayload;
|
|
50
|
-
const
|
|
51
|
-
if (triggerId !== undefined) {
|
|
52
|
-
if (typeof triggerId !== 'string' || triggerId.trim() === '') {
|
|
53
|
-
throw new errors_1.InvalidPayloadError('Invalid triggerId: must be a non-empty string when provided');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (recipient !== undefined) {
|
|
57
|
-
if (typeof recipient !== 'string' || recipient.trim() === '') {
|
|
58
|
-
throw new errors_1.InvalidPayloadError('Invalid recipient: must be a non-empty string when provided');
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (recipientType !== undefined) {
|
|
62
|
-
if (typeof recipientType !== 'string' || recipientType.trim() === '') {
|
|
63
|
-
throw new errors_1.InvalidPayloadError('Invalid recipientType: must be a non-empty string when provided');
|
|
64
|
-
}
|
|
65
|
-
const allowedRecipientTypes = Object.values(types_1.RecipientType);
|
|
66
|
-
if (!allowedRecipientTypes.includes(recipientType)) {
|
|
67
|
-
throw new errors_1.InvalidPayloadError(`Invalid recipientType: must be one of ${allowedRecipientTypes.join(', ')}`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (deliveryChannel !== undefined) {
|
|
71
|
-
if (typeof deliveryChannel !== 'string' || deliveryChannel.trim() === '') {
|
|
72
|
-
throw new errors_1.InvalidPayloadError('Invalid deliveryChannel: must be a non-empty string when provided');
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const allowedChannels = Object.values(types_1.DeliveryChannel);
|
|
76
|
-
if (!allowedChannels.includes(deliveryChannel)) {
|
|
77
|
-
throw new errors_1.InvalidPayloadError(`Invalid deliveryChannel: must be one of ${allowedChannels.join(', ')}`);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
exports.validateNotificationStatusParams = validateNotificationStatusParams;
|
|
81
|
-
const validateAPIResponse = async (response, method) => {
|
|
49
|
+
const validateAPIResponse = async (response) => {
|
|
82
50
|
if (!response || typeof response !== 'object') {
|
|
83
51
|
throw new errors_1.InternalServerError('Unexpected response object');
|
|
84
52
|
}
|
|
@@ -86,7 +54,7 @@ const validateAPIResponse = async (response, method) => {
|
|
|
86
54
|
throw new errors_1.RateLimitError(`Rate limit exceeded ${response.statusText}`);
|
|
87
55
|
}
|
|
88
56
|
if (!response.ok) {
|
|
89
|
-
throw new errors_1.InternalServerError(`Failed to
|
|
57
|
+
throw new errors_1.InternalServerError(`Failed to send notification: ${response.statusText}`, response.status, await response.text());
|
|
90
58
|
}
|
|
91
59
|
};
|
|
92
60
|
exports.validateAPIResponse = validateAPIResponse;
|