@aws-amplify/rtn-push-notification 1.2.23 → 1.2.24
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/dist/cjs/apis/registerHeadlessTask.js +1 -1
- package/dist/cjs/apis/registerHeadlessTask.js.map +1 -1
- package/dist/esm/apis/registerHeadlessTask.mjs +1 -1
- package/dist/esm/apis/registerHeadlessTask.mjs.map +1 -1
- package/dist/esm/nativeModule.mjs.map +1 -1
- package/dist/esm/types/native.d.ts +15 -15
- package/package.json +4 -3
- package/src/apis/addMessageEventListener.ts +1 -0
- package/src/apis/addTokenEventListener.ts +1 -0
- package/src/apis/registerHeadlessTask.ts +3 -1
- package/src/index.ts +1 -0
- package/src/nativeModule.ts +2 -1
- package/src/types/native.ts +17 -16
- package/src/utils/normalizeNativeMessage.ts +6 -0
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.registerHeadlessTask = void 0;
|
|
7
7
|
const react_native_1 = require("react-native");
|
|
8
|
-
const getConstants_1 = require("./getConstants");
|
|
9
8
|
const utils_1 = require("../utils");
|
|
9
|
+
const getConstants_1 = require("./getConstants");
|
|
10
10
|
const registerHeadlessTask = (task) => {
|
|
11
11
|
const { NativeHeadlessTaskKey } = (0, getConstants_1.getConstants)();
|
|
12
12
|
if (NativeHeadlessTaskKey) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerHeadlessTask.js","sources":["../../../src/apis/registerHeadlessTask.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.registerHeadlessTask = void 0;\nconst react_native_1 = require(\"react-native\");\nconst
|
|
1
|
+
{"version":3,"file":"registerHeadlessTask.js","sources":["../../../src/apis/registerHeadlessTask.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.registerHeadlessTask = void 0;\nconst react_native_1 = require(\"react-native\");\nconst utils_1 = require(\"../utils\");\nconst getConstants_1 = require(\"./getConstants\");\nconst registerHeadlessTask = (task) => {\n const { NativeHeadlessTaskKey } = (0, getConstants_1.getConstants)();\n if (NativeHeadlessTaskKey) {\n react_native_1.AppRegistry.registerHeadlessTask(NativeHeadlessTaskKey, () => async (nativeMessage) => {\n await task((0, utils_1.normalizeNativeMessage)(nativeMessage));\n });\n }\n};\nexports.registerHeadlessTask = registerHeadlessTask;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,oBAAoB,GAAG,KAAK,CAAC,CAAC;AACtC,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACpC,MAAM,cAAc,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AACjD,MAAM,oBAAoB,GAAG,CAAC,IAAI,KAAK;AACvC,IAAI,MAAM,EAAE,qBAAqB,EAAE,GAAG,IAAI,cAAc,CAAC,YAAY,GAAG,CAAC;AACzE,IAAI,IAAI,qBAAqB,EAAE;AAC/B,QAAQ,cAAc,CAAC,WAAW,CAAC,oBAAoB,CAAC,qBAAqB,EAAE,MAAM,OAAO,aAAa,KAAK;AAC9G,YAAY,MAAM,IAAI,CAAC,IAAI,OAAO,CAAC,sBAAsB,EAAE,aAAa,CAAC,CAAC,CAAC;AAC3E,SAAS,CAAC,CAAC;AACX,KAAK;AACL,CAAC,CAAC;AACF,OAAO,CAAC,oBAAoB,GAAG,oBAAoB;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AppRegistry } from 'react-native';
|
|
2
|
-
import { getConstants } from './getConstants.mjs';
|
|
3
2
|
import { normalizeNativeMessage } from '../utils/normalizeNativeMessage.mjs';
|
|
3
|
+
import { getConstants } from './getConstants.mjs';
|
|
4
4
|
|
|
5
5
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
6
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerHeadlessTask.mjs","sources":["../../../src/apis/registerHeadlessTask.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AppRegistry } from 'react-native';\nimport {
|
|
1
|
+
{"version":3,"file":"registerHeadlessTask.mjs","sources":["../../../src/apis/registerHeadlessTask.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AppRegistry } from 'react-native';\nimport { normalizeNativeMessage } from '../utils';\nimport { getConstants } from './getConstants';\nexport const registerHeadlessTask = (task) => {\n const { NativeHeadlessTaskKey } = getConstants();\n if (NativeHeadlessTaskKey) {\n AppRegistry.registerHeadlessTask(NativeHeadlessTaskKey, () => async (nativeMessage) => {\n await task(normalizeNativeMessage(nativeMessage));\n });\n }\n};\n"],"names":[],"mappings":";;;;AAAA;AACA;AAIY,MAAC,oBAAoB,GAAG,CAAC,IAAI,KAAK;AAC9C,IAAI,MAAM,EAAE,qBAAqB,EAAE,GAAG,YAAY,EAAE,CAAC;AACrD,IAAI,IAAI,qBAAqB,EAAE;AAC/B,QAAQ,WAAW,CAAC,oBAAoB,CAAC,qBAAqB,EAAE,MAAM,OAAO,aAAa,KAAK;AAC/F,YAAY,MAAM,IAAI,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAC,CAAC;AAC9D,SAAS,CAAC,CAAC;AACX,KAAK;AACL;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeModule.mjs","sources":["../../src/nativeModule.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport {
|
|
1
|
+
{"version":3,"file":"nativeModule.mjs","sources":["../../src/nativeModule.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { NativeEventEmitter, NativeModules } from 'react-native';\nimport { LINKING_ERROR } from './constants';\nexport const nativeModule = NativeModules.AmplifyRTNPushNotification\n ? NativeModules.AmplifyRTNPushNotification\n : new Proxy({}, {\n get() {\n throw new Error(LINKING_ERROR);\n },\n });\nexport const nativeEventEmitter = new NativeEventEmitter(nativeModule);\n"],"names":[],"mappings":";;;AAAA;AACA;AAGY,MAAC,YAAY,GAAG,aAAa,CAAC,0BAA0B;AACpE,MAAM,aAAa,CAAC,0BAA0B;AAC9C,MAAM,IAAI,KAAK,CAAC,EAAE,EAAE;AACpB,QAAQ,GAAG,GAAG;AACd,YAAY,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;AAC3C,SAAS;AACT,KAAK,EAAE;AACK,MAAC,kBAAkB,GAAG,IAAI,kBAAkB,CAAC,YAAY;;;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NativeModule } from 'react-native';
|
|
2
2
|
import { PushNotificationMessage, PushNotificationPermissions } from './module';
|
|
3
3
|
export interface PushNotificationNativeModule extends NativeModule {
|
|
4
|
-
completeNotification
|
|
5
|
-
getConstants
|
|
4
|
+
completeNotification?(completionHandlerId: string): void;
|
|
5
|
+
getConstants(): {
|
|
6
6
|
NativeEvent: {
|
|
7
7
|
BACKGROUND_MESSAGE_RECEIVED?: string;
|
|
8
8
|
FOREGROUND_MESSAGE_RECEIVED: string;
|
|
@@ -12,16 +12,16 @@ export interface PushNotificationNativeModule extends NativeModule {
|
|
|
12
12
|
};
|
|
13
13
|
NativeHeadlessTaskKey?: string;
|
|
14
14
|
};
|
|
15
|
-
getLaunchNotification
|
|
16
|
-
getBadgeCount
|
|
17
|
-
setBadgeCount
|
|
18
|
-
getPermissionStatus
|
|
19
|
-
requestPermissions
|
|
15
|
+
getLaunchNotification(): Promise<NativeMessage | null>;
|
|
16
|
+
getBadgeCount?(): Promise<number>;
|
|
17
|
+
setBadgeCount?(count: number): void;
|
|
18
|
+
getPermissionStatus(): Promise<NativePermissionStatus>;
|
|
19
|
+
requestPermissions(permissions: PushNotificationPermissions): Promise<boolean>;
|
|
20
20
|
}
|
|
21
|
-
export
|
|
21
|
+
export interface NativeAction {
|
|
22
22
|
deeplink?: string;
|
|
23
23
|
url?: string;
|
|
24
|
-
}
|
|
24
|
+
}
|
|
25
25
|
export type NativeMessage = (ApnsMessage | FcmMessage) & {
|
|
26
26
|
token?: never;
|
|
27
27
|
};
|
|
@@ -34,7 +34,7 @@ export interface NormalizedValues {
|
|
|
34
34
|
options?: Pick<PushNotificationMessage, 'apnsOptions' | 'fcmOptions'>;
|
|
35
35
|
data?: Record<string, unknown>;
|
|
36
36
|
}
|
|
37
|
-
export
|
|
37
|
+
export interface ApnsMessage {
|
|
38
38
|
aps: {
|
|
39
39
|
alert?: {
|
|
40
40
|
body?: string;
|
|
@@ -48,9 +48,9 @@ export type ApnsMessage = {
|
|
|
48
48
|
};
|
|
49
49
|
rawData?: never;
|
|
50
50
|
completionHandlerId?: string;
|
|
51
|
-
}
|
|
51
|
+
}
|
|
52
52
|
export type IosPermissionStatus = 'NotDetermined' | 'Authorized' | 'Denied';
|
|
53
|
-
export
|
|
53
|
+
export interface FcmMessage {
|
|
54
54
|
action?: NativeAction;
|
|
55
55
|
aps?: never;
|
|
56
56
|
body?: string;
|
|
@@ -62,8 +62,8 @@ export type FcmMessage = {
|
|
|
62
62
|
senderId?: string;
|
|
63
63
|
sendTime?: number;
|
|
64
64
|
completionHandlerId?: never;
|
|
65
|
-
}
|
|
65
|
+
}
|
|
66
66
|
export type AndroidPermissionStatus = 'ShouldRequest' | 'ShouldExplainThenRequest' | 'Granted' | 'Denied';
|
|
67
|
-
export
|
|
67
|
+
export interface TokenPayload {
|
|
68
68
|
token: string;
|
|
69
|
-
}
|
|
69
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/rtn-push-notification",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.24",
|
|
4
4
|
"description": "React Native module for aws-amplify push notifications",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"build": "npm run clean && npm run build:esm-cjs",
|
|
20
20
|
"clean": "rimraf lib-esm lib dist",
|
|
21
21
|
"format": "echo \"Not implemented\"",
|
|
22
|
-
"lint": "
|
|
22
|
+
"lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
|
|
23
|
+
"lint:fix": "eslint '**/*.{ts,tsx}' --fix",
|
|
23
24
|
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 99"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
@@ -44,5 +45,5 @@
|
|
|
44
45
|
"dist/esm",
|
|
45
46
|
"src"
|
|
46
47
|
],
|
|
47
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "6c46368559f4c3229024d10c18aabb34c58efe68"
|
|
48
49
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { EmitterSubscription } from 'react-native';
|
|
5
|
+
|
|
5
6
|
import { nativeEventEmitter } from '../nativeModule';
|
|
6
7
|
import { NativeMessage, PushNotificationMessage } from '../types';
|
|
7
8
|
import { normalizeNativeMessage } from '../utils';
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { AppRegistry } from 'react-native';
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
import { NativeMessage, PushNotificationMessage } from '../types';
|
|
7
7
|
import { normalizeNativeMessage } from '../utils';
|
|
8
8
|
|
|
9
|
+
import { getConstants } from './getConstants';
|
|
10
|
+
|
|
9
11
|
export const registerHeadlessTask = (
|
|
10
12
|
task: (message: PushNotificationMessage | null) => Promise<void>,
|
|
11
13
|
): void => {
|
package/src/index.ts
CHANGED
package/src/nativeModule.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { NativeEventEmitter, NativeModules } from 'react-native';
|
|
5
|
+
|
|
5
6
|
import { LINKING_ERROR } from './constants';
|
|
6
7
|
import { PushNotificationNativeModule } from './types';
|
|
7
8
|
|
package/src/types/native.ts
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { NativeModule } from 'react-native';
|
|
5
|
+
|
|
5
6
|
import { PushNotificationMessage, PushNotificationPermissions } from './module';
|
|
6
7
|
|
|
7
8
|
export interface PushNotificationNativeModule extends NativeModule {
|
|
8
|
-
completeNotification
|
|
9
|
-
getConstants
|
|
9
|
+
completeNotification?(completionHandlerId: string): void;
|
|
10
|
+
getConstants(): {
|
|
10
11
|
NativeEvent: {
|
|
11
12
|
BACKGROUND_MESSAGE_RECEIVED?: string;
|
|
12
13
|
FOREGROUND_MESSAGE_RECEIVED: string;
|
|
@@ -16,19 +17,19 @@ export interface PushNotificationNativeModule extends NativeModule {
|
|
|
16
17
|
};
|
|
17
18
|
NativeHeadlessTaskKey?: string;
|
|
18
19
|
};
|
|
19
|
-
getLaunchNotification
|
|
20
|
-
getBadgeCount
|
|
21
|
-
setBadgeCount
|
|
22
|
-
getPermissionStatus
|
|
23
|
-
requestPermissions
|
|
20
|
+
getLaunchNotification(): Promise<NativeMessage | null>;
|
|
21
|
+
getBadgeCount?(): Promise<number>;
|
|
22
|
+
setBadgeCount?(count: number): void;
|
|
23
|
+
getPermissionStatus(): Promise<NativePermissionStatus>;
|
|
24
|
+
requestPermissions(
|
|
24
25
|
permissions: PushNotificationPermissions,
|
|
25
|
-
)
|
|
26
|
+
): Promise<boolean>;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
export
|
|
29
|
+
export interface NativeAction {
|
|
29
30
|
deeplink?: string;
|
|
30
31
|
url?: string;
|
|
31
|
-
}
|
|
32
|
+
}
|
|
32
33
|
|
|
33
34
|
export type NativeMessage = (ApnsMessage | FcmMessage) & {
|
|
34
35
|
token?: never;
|
|
@@ -48,7 +49,7 @@ export interface NormalizedValues {
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
// iOS
|
|
51
|
-
export
|
|
52
|
+
export interface ApnsMessage {
|
|
52
53
|
aps: {
|
|
53
54
|
alert?: {
|
|
54
55
|
body?: string;
|
|
@@ -62,12 +63,12 @@ export type ApnsMessage = {
|
|
|
62
63
|
};
|
|
63
64
|
rawData?: never;
|
|
64
65
|
completionHandlerId?: string;
|
|
65
|
-
}
|
|
66
|
+
}
|
|
66
67
|
|
|
67
68
|
export type IosPermissionStatus = 'NotDetermined' | 'Authorized' | 'Denied';
|
|
68
69
|
|
|
69
70
|
// Android
|
|
70
|
-
export
|
|
71
|
+
export interface FcmMessage {
|
|
71
72
|
action?: NativeAction;
|
|
72
73
|
aps?: never;
|
|
73
74
|
body?: string;
|
|
@@ -79,7 +80,7 @@ export type FcmMessage = {
|
|
|
79
80
|
senderId?: string;
|
|
80
81
|
sendTime?: number;
|
|
81
82
|
completionHandlerId?: never;
|
|
82
|
-
}
|
|
83
|
+
}
|
|
83
84
|
|
|
84
85
|
export type AndroidPermissionStatus =
|
|
85
86
|
| 'ShouldRequest'
|
|
@@ -87,6 +88,6 @@ export type AndroidPermissionStatus =
|
|
|
87
88
|
| 'Granted'
|
|
88
89
|
| 'Denied';
|
|
89
90
|
|
|
90
|
-
export
|
|
91
|
+
export interface TokenPayload {
|
|
91
92
|
token: string;
|
|
92
|
-
}
|
|
93
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import isEmpty from 'lodash/isEmpty.js';
|
|
5
|
+
|
|
5
6
|
import {
|
|
6
7
|
ApnsMessage,
|
|
7
8
|
FcmMessage,
|
|
@@ -26,6 +27,7 @@ export const normalizeNativeMessage = (
|
|
|
26
27
|
return null;
|
|
27
28
|
}
|
|
28
29
|
const { body, imageUrl, title, action, options, data } = normalized;
|
|
30
|
+
|
|
29
31
|
return {
|
|
30
32
|
body,
|
|
31
33
|
data,
|
|
@@ -42,6 +44,7 @@ const normalizeApnsMessage = (apnsMessage: ApnsMessage): NormalizedValues => {
|
|
|
42
44
|
const action = getApnsAction(data?.pinpoint) ?? {};
|
|
43
45
|
const imageUrl = data?.['media-url'];
|
|
44
46
|
const options = getApnsOptions(apnsMessage);
|
|
47
|
+
|
|
45
48
|
return { body, imageUrl, title, action, options, data };
|
|
46
49
|
};
|
|
47
50
|
|
|
@@ -49,6 +52,7 @@ const normalizeFcmMessage = (fcmMessage: FcmMessage): NormalizedValues => {
|
|
|
49
52
|
const { body, imageUrl, rawData: data, title } = fcmMessage;
|
|
50
53
|
const action = getFcmAction(fcmMessage.action) ?? {};
|
|
51
54
|
const options = getFcmOptions(fcmMessage);
|
|
55
|
+
|
|
52
56
|
return { body, imageUrl, title, action, options, data };
|
|
53
57
|
};
|
|
54
58
|
|
|
@@ -76,6 +80,7 @@ const getApnsOptions = ({
|
|
|
76
80
|
}: ApnsMessage): Pick<PushNotificationMessage, 'apnsOptions'> => {
|
|
77
81
|
const { subtitle } = aps.alert ?? {};
|
|
78
82
|
const apnsOptions = { ...(subtitle && { subtitle }) };
|
|
83
|
+
|
|
79
84
|
return { ...(!isEmpty(apnsOptions) && { apnsOptions }) };
|
|
80
85
|
};
|
|
81
86
|
|
|
@@ -91,6 +96,7 @@ const getFcmOptions = ({
|
|
|
91
96
|
senderId,
|
|
92
97
|
sendTime: new Date(sendTime),
|
|
93
98
|
};
|
|
99
|
+
|
|
94
100
|
return { ...(!isEmpty(fcmOptions) && { fcmOptions }) };
|
|
95
101
|
};
|
|
96
102
|
|