@metamask-previews/notification-services-controller 24.3.0-preview-6fc64deac → 24.3.0-preview-c4108f3eb
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 +16 -0
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.cjs +32 -16
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.mjs +32 -16
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.cjs +2 -2
- package/dist/NotificationServicesController/services/api-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.mjs +2 -2
- package/dist/NotificationServicesController/services/api-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/notification-api.cjs +1 -0
- package/dist/NotificationServicesController/types/notification-api/notification-api.cjs.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts +7 -14
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts +7 -14
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/notification-api.mjs +1 -1
- package/dist/NotificationServicesController/types/notification-api/notification-api.mjs.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/schema.cjs.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/schema.d.cts +366 -2
- package/dist/NotificationServicesController/types/notification-api/schema.d.cts.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/schema.d.mts +366 -2
- package/dist/NotificationServicesController/types/notification-api/schema.d.mts.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/schema.mjs.map +1 -1
- package/dist/shared/index.cjs +1 -0
- package/dist/shared/index.cjs.map +1 -1
- package/dist/shared/index.d.cts +1 -0
- package/dist/shared/index.d.cts.map +1 -1
- package/dist/shared/index.d.mts +1 -0
- package/dist/shared/index.d.mts.map +1 -1
- package/dist/shared/index.mjs +1 -0
- package/dist/shared/index.mjs.map +1 -1
- package/dist/shared/notification-api-type-guards.cjs +24 -0
- package/dist/shared/notification-api-type-guards.cjs.map +1 -0
- package/dist/shared/notification-api-type-guards.d.cts +16 -0
- package/dist/shared/notification-api-type-guards.d.cts.map +1 -0
- package/dist/shared/notification-api-type-guards.d.mts +16 -0
- package/dist/shared/notification-api-type-guards.d.mts.map +1 -0
- package/dist/shared/notification-api-type-guards.mjs +19 -0
- package/dist/shared/notification-api-type-guards.mjs.map +1 -0
- package/dist/shared/to-raw-notification.cjs +8 -13
- package/dist/shared/to-raw-notification.cjs.map +1 -1
- package/dist/shared/to-raw-notification.d.cts.map +1 -1
- package/dist/shared/to-raw-notification.d.mts.map +1 -1
- package/dist/shared/to-raw-notification.mjs +8 -13
- package/dist/shared/to-raw-notification.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { UnprocessedRawNotification, OnChainNotification, PlatformNotification } from "../NotificationServicesController/types/notification-api/index.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* Narrows a v4 API notification to an on-chain notification.
|
|
4
|
+
*
|
|
5
|
+
* @param notification - Unprocessed v4 API notification.
|
|
6
|
+
* @returns Whether the notification is an on-chain notification.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isOnChainNotification(notification: UnprocessedRawNotification): notification is OnChainNotification;
|
|
9
|
+
/**
|
|
10
|
+
* Narrows a v4 API notification to a platform notification.
|
|
11
|
+
*
|
|
12
|
+
* @param notification - Unprocessed v4 API notification.
|
|
13
|
+
* @returns Whether the notification is a platform notification.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isPlatformNotification(notification: UnprocessedRawNotification): notification is PlatformNotification;
|
|
16
|
+
//# sourceMappingURL=notification-api-type-guards.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-api-type-guards.d.cts","sourceRoot":"","sources":["../../src/shared/notification-api-type-guards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,mBAAmB,EACnB,oBAAoB,EACrB,2EAAiE;AAElE;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,0BAA0B,GACvC,YAAY,IAAI,mBAAmB,CAErC;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,0BAA0B,GACvC,YAAY,IAAI,oBAAoB,CAEtC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { UnprocessedRawNotification, OnChainNotification, PlatformNotification } from "../NotificationServicesController/types/notification-api/index.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Narrows a v4 API notification to an on-chain notification.
|
|
4
|
+
*
|
|
5
|
+
* @param notification - Unprocessed v4 API notification.
|
|
6
|
+
* @returns Whether the notification is an on-chain notification.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isOnChainNotification(notification: UnprocessedRawNotification): notification is OnChainNotification;
|
|
9
|
+
/**
|
|
10
|
+
* Narrows a v4 API notification to a platform notification.
|
|
11
|
+
*
|
|
12
|
+
* @param notification - Unprocessed v4 API notification.
|
|
13
|
+
* @returns Whether the notification is a platform notification.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isPlatformNotification(notification: UnprocessedRawNotification): notification is PlatformNotification;
|
|
16
|
+
//# sourceMappingURL=notification-api-type-guards.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-api-type-guards.d.mts","sourceRoot":"","sources":["../../src/shared/notification-api-type-guards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,mBAAmB,EACnB,oBAAoB,EACrB,2EAAiE;AAElE;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,0BAA0B,GACvC,YAAY,IAAI,mBAAmB,CAErC;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,0BAA0B,GACvC,YAAY,IAAI,oBAAoB,CAEtC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrows a v4 API notification to an on-chain notification.
|
|
3
|
+
*
|
|
4
|
+
* @param notification - Unprocessed v4 API notification.
|
|
5
|
+
* @returns Whether the notification is an on-chain notification.
|
|
6
|
+
*/
|
|
7
|
+
export function isOnChainNotification(notification) {
|
|
8
|
+
return notification.notification_type === 'wallet_activity';
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Narrows a v4 API notification to a platform notification.
|
|
12
|
+
*
|
|
13
|
+
* @param notification - Unprocessed v4 API notification.
|
|
14
|
+
* @returns Whether the notification is a platform notification.
|
|
15
|
+
*/
|
|
16
|
+
export function isPlatformNotification(notification) {
|
|
17
|
+
return !isOnChainNotification(notification);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=notification-api-type-guards.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification-api-type-guards.mjs","sourceRoot":"","sources":["../../src/shared/notification-api-type-guards.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CACnC,YAAwC;IAExC,OAAO,YAAY,CAAC,iBAAiB,KAAK,iBAAiB,CAAC;AAC9D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,YAAwC;IAExC,OAAO,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["import type {\n UnprocessedRawNotification,\n OnChainNotification,\n PlatformNotification,\n} from '../NotificationServicesController/types/notification-api';\n\n/**\n * Narrows a v4 API notification to an on-chain notification.\n *\n * @param notification - Unprocessed v4 API notification.\n * @returns Whether the notification is an on-chain notification.\n */\nexport function isOnChainNotification(\n notification: UnprocessedRawNotification,\n): notification is OnChainNotification {\n return notification.notification_type === 'wallet_activity';\n}\n\n/**\n * Narrows a v4 API notification to a platform notification.\n *\n * @param notification - Unprocessed v4 API notification.\n * @returns Whether the notification is a platform notification.\n */\nexport function isPlatformNotification(\n notification: UnprocessedRawNotification,\n): notification is PlatformNotification {\n return !isOnChainNotification(notification);\n}\n"]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toRawAPINotification = void 0;
|
|
4
|
+
const notification_schema_1 = require("../NotificationServicesController/constants/notification-schema.cjs");
|
|
5
|
+
const notification_api_type_guards_1 = require("./notification-api-type-guards.cjs");
|
|
4
6
|
/**
|
|
5
7
|
* A true "raw notification" does not have some fields that exist on this type. E.g. the `type` field.
|
|
6
8
|
* This is retro-actively added when we fetch notifications to be able to easily type-discriminate notifications.
|
|
@@ -10,12 +12,8 @@ exports.toRawAPINotification = void 0;
|
|
|
10
12
|
* @returns a complete raw onchain notification
|
|
11
13
|
*/
|
|
12
14
|
function toRawAPINotification(data) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
throw new Error(`toRawAPINotification - No processor found for notification kind ${type}`);
|
|
16
|
-
};
|
|
17
|
-
if (data.notification_type === 'on-chain') {
|
|
18
|
-
if (!data?.payload?.data?.kind) {
|
|
15
|
+
if ((0, notification_api_type_guards_1.isOnChainNotification)(data)) {
|
|
16
|
+
if (!data.payload.data?.kind) {
|
|
19
17
|
throw new Error('toRawAPINotification - No kind found for on-chain notification');
|
|
20
18
|
}
|
|
21
19
|
return {
|
|
@@ -23,13 +21,10 @@ function toRawAPINotification(data) {
|
|
|
23
21
|
type: data.payload.data.kind,
|
|
24
22
|
};
|
|
25
23
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
return exhaustedAllCases(data);
|
|
24
|
+
return {
|
|
25
|
+
...data,
|
|
26
|
+
type: notification_schema_1.TRIGGER_TYPES.PLATFORM,
|
|
27
|
+
};
|
|
33
28
|
}
|
|
34
29
|
exports.toRawAPINotification = toRawAPINotification;
|
|
35
30
|
//# sourceMappingURL=to-raw-notification.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-raw-notification.cjs","sourceRoot":"","sources":["../../src/shared/to-raw-notification.ts"],"names":[],"mappings":";;;AAOA;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAClC,IAAgC;IAEhC,
|
|
1
|
+
{"version":3,"file":"to-raw-notification.cjs","sourceRoot":"","sources":["../../src/shared/to-raw-notification.ts"],"names":[],"mappings":";;;AAOA,6GAAgG;AAChG,qFAAuE;AAEvE;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAClC,IAAgC;IAEhC,IAAI,IAAA,oDAAqB,EAAC,IAAI,CAAC,EAAE,CAAC;QAChC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;QACJ,CAAC;QACD,OAAO;YACL,GAAG,IAAI;YACP,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI;SACH,CAAC;IAC9B,CAAC;IAED,OAAO;QACL,GAAG,IAAI;QACP,IAAI,EAAE,mCAAa,CAAC,QAAQ;KACF,CAAC;AAC/B,CAAC;AAnBD,oDAmBC","sourcesContent":["import type {\n UnprocessedRawNotification,\n NormalisedAPINotification,\n OnChainRawNotification,\n PlatformRawNotification,\n} from 'src/NotificationServicesController/types/notification-api';\n\nimport { TRIGGER_TYPES } from '../NotificationServicesController/constants/notification-schema';\nimport { isOnChainNotification } from './notification-api-type-guards';\n\n/**\n * A true \"raw notification\" does not have some fields that exist on this type. E.g. the `type` field.\n * This is retro-actively added when we fetch notifications to be able to easily type-discriminate notifications.\n * We use this to ensure that the correct missing fields are added to the raw shapes\n *\n * @param data - raw onchain notification\n * @returns a complete raw onchain notification\n */\nexport function toRawAPINotification(\n data: UnprocessedRawNotification,\n): NormalisedAPINotification {\n if (isOnChainNotification(data)) {\n if (!data.payload.data?.kind) {\n throw new Error(\n 'toRawAPINotification - No kind found for on-chain notification',\n );\n }\n return {\n ...data,\n type: data.payload.data.kind,\n } as OnChainRawNotification;\n }\n\n return {\n ...data,\n type: TRIGGER_TYPES.PLATFORM,\n } as PlatformRawNotification;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-raw-notification.d.cts","sourceRoot":"","sources":["../../src/shared/to-raw-notification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,yBAAyB,EAG1B,kEAAkE;
|
|
1
|
+
{"version":3,"file":"to-raw-notification.d.cts","sourceRoot":"","sources":["../../src/shared/to-raw-notification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,yBAAyB,EAG1B,kEAAkE;AAKnE;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,0BAA0B,GAC/B,yBAAyB,CAiB3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-raw-notification.d.mts","sourceRoot":"","sources":["../../src/shared/to-raw-notification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,yBAAyB,EAG1B,kEAAkE;
|
|
1
|
+
{"version":3,"file":"to-raw-notification.d.mts","sourceRoot":"","sources":["../../src/shared/to-raw-notification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,yBAAyB,EAG1B,kEAAkE;AAKnE;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,0BAA0B,GAC/B,yBAAyB,CAiB3B"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { TRIGGER_TYPES } from "../NotificationServicesController/constants/notification-schema.mjs";
|
|
2
|
+
import { isOnChainNotification } from "./notification-api-type-guards.mjs";
|
|
1
3
|
/**
|
|
2
4
|
* A true "raw notification" does not have some fields that exist on this type. E.g. the `type` field.
|
|
3
5
|
* This is retro-actively added when we fetch notifications to be able to easily type-discriminate notifications.
|
|
@@ -7,12 +9,8 @@
|
|
|
7
9
|
* @returns a complete raw onchain notification
|
|
8
10
|
*/
|
|
9
11
|
export function toRawAPINotification(data) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
throw new Error(`toRawAPINotification - No processor found for notification kind ${type}`);
|
|
13
|
-
};
|
|
14
|
-
if (data.notification_type === 'on-chain') {
|
|
15
|
-
if (!data?.payload?.data?.kind) {
|
|
12
|
+
if (isOnChainNotification(data)) {
|
|
13
|
+
if (!data.payload.data?.kind) {
|
|
16
14
|
throw new Error('toRawAPINotification - No kind found for on-chain notification');
|
|
17
15
|
}
|
|
18
16
|
return {
|
|
@@ -20,12 +18,9 @@ export function toRawAPINotification(data) {
|
|
|
20
18
|
type: data.payload.data.kind,
|
|
21
19
|
};
|
|
22
20
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
return exhaustedAllCases(data);
|
|
21
|
+
return {
|
|
22
|
+
...data,
|
|
23
|
+
type: TRIGGER_TYPES.PLATFORM,
|
|
24
|
+
};
|
|
30
25
|
}
|
|
31
26
|
//# sourceMappingURL=to-raw-notification.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-raw-notification.mjs","sourceRoot":"","sources":["../../src/shared/to-raw-notification.ts"],"names":[],"mappings":"AAOA
|
|
1
|
+
{"version":3,"file":"to-raw-notification.mjs","sourceRoot":"","sources":["../../src/shared/to-raw-notification.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,4EAAwE;AAChG,OAAO,EAAE,qBAAqB,EAAE,2CAAuC;AAEvE;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAClC,IAAgC;IAEhC,IAAI,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;QACJ,CAAC;QACD,OAAO;YACL,GAAG,IAAI;YACP,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI;SACH,CAAC;IAC9B,CAAC;IAED,OAAO;QACL,GAAG,IAAI;QACP,IAAI,EAAE,aAAa,CAAC,QAAQ;KACF,CAAC;AAC/B,CAAC","sourcesContent":["import type {\n UnprocessedRawNotification,\n NormalisedAPINotification,\n OnChainRawNotification,\n PlatformRawNotification,\n} from 'src/NotificationServicesController/types/notification-api';\n\nimport { TRIGGER_TYPES } from '../NotificationServicesController/constants/notification-schema';\nimport { isOnChainNotification } from './notification-api-type-guards';\n\n/**\n * A true \"raw notification\" does not have some fields that exist on this type. E.g. the `type` field.\n * This is retro-actively added when we fetch notifications to be able to easily type-discriminate notifications.\n * We use this to ensure that the correct missing fields are added to the raw shapes\n *\n * @param data - raw onchain notification\n * @returns a complete raw onchain notification\n */\nexport function toRawAPINotification(\n data: UnprocessedRawNotification,\n): NormalisedAPINotification {\n if (isOnChainNotification(data)) {\n if (!data.payload.data?.kind) {\n throw new Error(\n 'toRawAPINotification - No kind found for on-chain notification',\n );\n }\n return {\n ...data,\n type: data.payload.data.kind,\n } as OnChainRawNotification;\n }\n\n return {\n ...data,\n type: TRIGGER_TYPES.PLATFORM,\n } as PlatformRawNotification;\n}\n"]}
|
package/package.json
CHANGED