@adobe/react-native-aepmessaging 5.0.0 → 6.0.0

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.
Files changed (61) hide show
  1. package/.babelrc +1 -1
  2. package/RCTAEPMessaging.podspec +26 -8
  3. package/README.md +93 -10
  4. package/android/build.gradle +84 -22
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +0 -2
  7. package/android/src/main/AndroidManifestNew.xml +2 -0
  8. package/android/src/main/java/com/adobe/marketing/mobile/reactnative/messaging/RCTAEPMessagingModule.java +215 -202
  9. package/android/src/main/java/com/adobe/marketing/mobile/reactnative/messaging/RCTAEPMessagingPackage.java +27 -25
  10. package/android/src/main/java/com/adobe/marketing/mobile/reactnative/messaging/RCTAEPMessagingUtil.java +134 -0
  11. package/dist/Messaging.d.ts +62 -0
  12. package/dist/Messaging.js +118 -0
  13. package/dist/Messaging.js.map +1 -0
  14. package/{js → dist}/index.d.ts +3 -1
  15. package/{js → dist}/index.js +4 -2
  16. package/dist/index.js.map +1 -0
  17. package/dist/models/Message.d.ts +39 -0
  18. package/dist/models/Message.js +64 -0
  19. package/dist/models/Message.js.map +1 -0
  20. package/dist/models/MessagingDelegate.d.ts +35 -0
  21. package/{js → dist}/models/MessagingDelegate.js +1 -1
  22. package/dist/models/MessagingDelegate.js.map +1 -0
  23. package/{js → dist}/models/MessagingEdgeEventType.d.ts +4 -4
  24. package/{js → dist}/models/MessagingEdgeEventType.js +5 -5
  25. package/dist/models/MessagingEdgeEventType.js.map +1 -0
  26. package/dist/models/MessagingProposition.d.ts +8 -0
  27. package/dist/models/MessagingProposition.js +24 -0
  28. package/dist/models/MessagingProposition.js.map +1 -0
  29. package/dist/models/MessagingPropositionItem.d.ts +8 -0
  30. package/dist/models/MessagingPropositionItem.js +14 -0
  31. package/dist/models/MessagingPropositionItem.js.map +1 -0
  32. package/ios/src/RCTAEPMessaging-Bridging-Header.h +15 -0
  33. package/ios/src/RCTAEPMessaging.mm +50 -0
  34. package/ios/src/RCTAEPMessaging.swift +266 -0
  35. package/ios/src/RCTAEPMessagingConstants.swift +22 -0
  36. package/ios/src/RCTAEPMessagingDataBridge.swift +47 -0
  37. package/package.json +6 -6
  38. package/src/Messaging.ts +164 -0
  39. package/{ts → src}/index.ts +11 -2
  40. package/src/models/Message.ts +72 -0
  41. package/src/models/MessagingDelegate.ts +53 -0
  42. package/{ts → src}/models/MessagingEdgeEventType.ts +5 -5
  43. package/src/models/MessagingProposition.ts +32 -0
  44. package/src/models/MessagingPropositionItem.ts +20 -0
  45. package/tsconfig.json +2 -2
  46. package/ios/RCTAEPMessaging.xcodeproj/project.pbxproj +0 -304
  47. package/ios/src/RCTAEPMessaging.h +0 -20
  48. package/ios/src/RCTAEPMessaging.m +0 -196
  49. package/js/Messaging.d.ts +0 -32
  50. package/js/Messaging.js +0 -80
  51. package/js/Messaging.js.map +0 -1
  52. package/js/index.js.map +0 -1
  53. package/js/models/Message.d.ts +0 -43
  54. package/js/models/Message.js +0 -80
  55. package/js/models/Message.js.map +0 -1
  56. package/js/models/MessagingDelegate.d.ts +0 -25
  57. package/js/models/MessagingDelegate.js.map +0 -1
  58. package/js/models/MessagingEdgeEventType.js.map +0 -1
  59. package/ts/Messaging.ts +0 -99
  60. package/ts/models/Message.ts +0 -82
  61. package/ts/models/MessagingDelegate.ts +0 -41
@@ -0,0 +1,50 @@
1
+ /*
2
+ Copyright 2023 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the
4
+ "License"); you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
7
+ or agreed to in writing, software distributed under the License is
8
+ distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF
9
+ ANY KIND, either express or implied. See the License for the specific
10
+ language governing permissions and limitations under the License.
11
+ */
12
+
13
+ #import <React/RCTBridgeModule.h>
14
+ #import <React/RCTEventEmitter.h>
15
+
16
+ @interface RCT_EXTERN_MODULE (RCTAEPMessaging, RCTEventEmitter)
17
+
18
+ RCT_EXTERN_METHOD(supportedEvents)
19
+
20
+ RCT_EXTERN_METHOD(extensionVersion
21
+ : (RCTPromiseResolveBlock)resolve rejecter
22
+ : (RCTPromiseRejectBlock)reject);
23
+
24
+ RCT_EXTERN_METHOD(getCachedMessages
25
+ : (RCTPromiseResolveBlock)resolve withRejecter
26
+ : (RCTPromiseRejectBlock)reject)
27
+
28
+ RCT_EXTERN_METHOD(getLatestMessage
29
+ : (RCTPromiseResolveBlock)resolve withRejecter
30
+ : (RCTPromiseRejectBlock)reject)
31
+
32
+ RCT_EXTERN_METHOD(getPropositionsForSurfaces
33
+ : (NSArray<NSString *> *)surfaces withResolver
34
+ : (RCTPromiseResolveBlock)resolve withRejecter
35
+ : (RCTPromiseRejectBlock)reject);
36
+
37
+ RCT_EXTERN_METHOD(refreshInAppMessages);
38
+
39
+ RCT_EXTERN_METHOD(setMessagingDelegate);
40
+
41
+ RCT_EXTERN_METHOD(setMessageSettings
42
+ : (BOOL) shouldShowMessage withShouldSaveMessage
43
+ : (BOOL)shouldSaveMessage);
44
+
45
+ RCT_EXTERN_METHOD(updatePropositionsForSurfaces
46
+ : (NSArray<NSString *> *)surfaces withResolver
47
+ : (RCTPromiseResolveBlock)resolve withRejecter
48
+ : (RCTPromiseRejectBlock)reject);
49
+
50
+ @end
@@ -0,0 +1,266 @@
1
+ /*
2
+ Copyright 2023 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the
4
+ "License"); you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
7
+ or agreed to in writing, software distributed under the License is
8
+ distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF
9
+ ANY KIND, either express or implied. See the License for the specific
10
+ language governing permissions and limitations under the License.
11
+ */
12
+
13
+ import AEPCore
14
+ import AEPMessaging
15
+ import AEPServices
16
+ import Foundation
17
+ import UIKit
18
+ import UserNotifications
19
+ import WebKit
20
+
21
+ @objc(RCTAEPMessaging)
22
+ public class RCTAEPMessaging: RCTEventEmitter, MessagingDelegate {
23
+ private var messageCache = [String: Message]()
24
+ private var latestMessage: Message? = nil
25
+ private let semaphore = DispatchSemaphore(value: 0)
26
+ private var shouldSaveMessage = false
27
+ private var shouldShowMessage = true
28
+ public static var emitter: RCTEventEmitter!
29
+
30
+ override init() {
31
+ super.init()
32
+ RCTAEPMessaging.emitter = self
33
+ }
34
+
35
+ @objc override public static func requiresMainQueueSetup() -> Bool {
36
+ return false
37
+ }
38
+
39
+ @objc open override func supportedEvents() -> [String] {
40
+ return Constants.SUPPORTED_EVENTS
41
+ }
42
+
43
+ @objc
44
+ func extensionVersion(_ resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock)
45
+ {
46
+ resolve(Messaging.extensionVersion)
47
+ }
48
+
49
+ @objc
50
+ private func getCachedMessages(
51
+ _ resolve: RCTPromiseResolveBlock,
52
+ withRejecter reject: RCTPromiseRejectBlock
53
+ ) {
54
+ let cachedMessages = messageCache.values.map {
55
+ RCTAEPMessagingDataBridge.transformToMessage(message: $0)
56
+ }
57
+ resolve(cachedMessages)
58
+ }
59
+
60
+ @objc
61
+ func getLatestMessage(
62
+ _ resolve: RCTPromiseResolveBlock,
63
+ withRejecter reject: RCTPromiseRejectBlock
64
+ ) {
65
+ resolve(self.latestMessage != nil ? RCTAEPMessagingDataBridge.transformToMessage(message: self.latestMessage!) : nil)
66
+ }
67
+
68
+ @objc
69
+ func getPropositionsForSurfaces(
70
+ _ surfaces: [String],
71
+ withResolver resolve: @escaping RCTPromiseResolveBlock,
72
+ withRejecter reject: @escaping RCTPromiseRejectBlock
73
+ ) {
74
+ let surfacePaths = surfaces.map { Surface(path: $0) }
75
+ Messaging.getPropositionsForSurfaces(surfacePaths) { propositionsDict, error in
76
+ guard error == nil else {
77
+ reject("Unable to Retrieve Propositions", nil, nil)
78
+ return
79
+ }
80
+ resolve(RCTAEPMessagingDataBridge.transformPropositionDict(dict: propositionsDict!))
81
+ }
82
+ }
83
+
84
+ @objc
85
+ func refreshInAppMessages() {
86
+ Messaging.refreshInAppMessages()
87
+ }
88
+
89
+ @objc
90
+ func setMessageSettings(
91
+ _ shouldShowMessage: Bool,
92
+ withShouldSaveMessage shouldSaveMessage: Bool
93
+ ) {
94
+ self.shouldShowMessage = shouldShowMessage
95
+ self.shouldSaveMessage = shouldSaveMessage
96
+ semaphore.signal()
97
+ }
98
+
99
+ @objc
100
+ func setMessagingDelegate() {
101
+ MobileCore.messagingDelegate = self
102
+ }
103
+
104
+ @objc
105
+ func updatePropositionsForSurfaces(
106
+ _ surfaces: [String],
107
+ withResolver resolve: @escaping RCTPromiseResolveBlock,
108
+ withRejecter reject: @escaping RCTPromiseRejectBlock
109
+ ) {
110
+ let mapped = surfaces.map { Surface(path: $0) }
111
+ Messaging.updatePropositionsForSurfaces(mapped)
112
+ resolve(nil)
113
+ }
114
+
115
+ /// Message Class Methods
116
+ @objc
117
+ func clearMessage(
118
+ _ id: String,
119
+ withResolver resolve: @escaping RCTPromiseResolveBlock,
120
+ withRejecter reject: @escaping RCTPromiseRejectBlock
121
+ ) {
122
+ let msg = messageCache[id]
123
+ if msg != nil {
124
+ messageCache.removeValue(forKey: msg!.id)
125
+ resolve(nil)
126
+ }
127
+ reject(Constants.CACHE_MISS, nil, nil)
128
+ }
129
+
130
+ @objc
131
+ func dismissMessage(
132
+ _ id: String,
133
+ withSuppressAutoTrack suppressAutoTrack: Bool,
134
+ withResolver resolve: @escaping RCTPromiseResolveBlock,
135
+ withRejecter reject: @escaping RCTPromiseRejectBlock
136
+ ) {
137
+ let msg = messageCache[id]
138
+ if msg != nil {
139
+ msg!.dismiss(suppressAutoTrack: suppressAutoTrack)
140
+ resolve(nil)
141
+ return
142
+ }
143
+ reject(Constants.CACHE_MISS, nil, nil)
144
+ }
145
+
146
+ @objc
147
+ func setAutoTrack(
148
+ _ id: String,
149
+ withSuppressAutoTrack suppressAutoTrack: Bool,
150
+ withResolver resolve: @escaping RCTPromiseResolveBlock,
151
+ withRejecter reject: @escaping RCTPromiseRejectBlock
152
+ ) {
153
+
154
+ let msg = messageCache[id]
155
+ if msg != nil {
156
+ msg!.autoTrack = suppressAutoTrack
157
+ resolve(nil)
158
+ return
159
+ }
160
+ reject(Constants.CACHE_MISS, nil, nil)
161
+ }
162
+
163
+ @objc
164
+ private func showMessage(
165
+ _ id: String,
166
+ withResolver resolve: @escaping RCTPromiseResolveBlock,
167
+ withRejecter reject: @escaping RCTPromiseRejectBlock
168
+ ) {
169
+ let msg = messageCache[id]
170
+ if msg != nil {
171
+ msg!.show()
172
+ resolve(nil)
173
+ return
174
+ }
175
+ reject(Constants.CACHE_MISS, nil, nil)
176
+
177
+ }
178
+
179
+ @objc
180
+ func trackMessage(
181
+ _ id: String,
182
+ withInteraction interaction: String,
183
+ withEventType eventType: Int,
184
+ withResolver resolve: @escaping RCTPromiseResolveBlock,
185
+ withRejecter reject: @escaping RCTPromiseRejectBlock
186
+ ) {
187
+
188
+ let msg = messageCache[id]
189
+ let eventType =
190
+ MessagingEdgeEventType.init(rawValue: eventType)
191
+ ?? MessagingEdgeEventType.dismiss
192
+ if msg != nil {
193
+ msg!.track(interaction, withEdgeEventType: eventType)
194
+ resolve(nil)
195
+ return
196
+ }
197
+ reject(Constants.CACHE_MISS, nil, nil)
198
+ }
199
+
200
+ // Messaging Delegate Methods
201
+ public func onDismiss(message: Showable) {
202
+ if let fullscreenMessage = message as? FullscreenMessage,
203
+ let parentMessage = fullscreenMessage.parent
204
+ {
205
+ emitNativeEvent(
206
+ name: Constants.ON_DISMISS_EVENT,
207
+ body: RCTAEPMessagingDataBridge.transformToMessage(
208
+ message: parentMessage
209
+ )
210
+ )
211
+ }
212
+ }
213
+
214
+ public func onShow(message: Showable) {
215
+ if let fullscreenMessage = message as? FullscreenMessage,
216
+ let message = fullscreenMessage.parent
217
+ {
218
+ emitNativeEvent(
219
+ name: Constants.ON_SHOW_EVENT,
220
+ body: RCTAEPMessagingDataBridge.transformToMessage(message: message)
221
+ )
222
+ }
223
+ }
224
+
225
+ public func shouldShowMessage(message: Showable) -> Bool {
226
+ if let fullscreenMessage = message as? FullscreenMessage,
227
+ let message = fullscreenMessage.parent
228
+ {
229
+ emitNativeEvent(
230
+ name: Constants.SHOULD_SHOW_MESSAGE_EVENT,
231
+ body: RCTAEPMessagingDataBridge.transformToMessage(message: message)
232
+ )
233
+ semaphore.wait()
234
+ if self.shouldSaveMessage {
235
+ self.messageCache[message.id] = message
236
+ }
237
+
238
+ if self.shouldShowMessage {
239
+ latestMessage = message
240
+ }
241
+
242
+ return self.shouldShowMessage
243
+ }
244
+ return false
245
+ }
246
+
247
+ public func urlLoaded(_ url: URL, byMessage message: Showable) {
248
+ if let fullscreenMessage = message as? FullscreenMessage,
249
+ let parentMessage = fullscreenMessage.parent
250
+ {
251
+ emitNativeEvent(
252
+ name: Constants.URL_LOADED_EVENT,
253
+ body: [
254
+ "url": url.absoluteString,
255
+ "message": RCTAEPMessagingDataBridge.transformToMessage(
256
+ message: parentMessage
257
+ ),
258
+ ]
259
+ )
260
+ }
261
+ }
262
+
263
+ private func emitNativeEvent(name: String, body: Any) {
264
+ RCTAEPMessaging.emitter.sendEvent(withName: name, body: body)
265
+ }
266
+ }
@@ -0,0 +1,22 @@
1
+ /*
2
+ Copyright 2023 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the
4
+ "License"); you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
7
+ or agreed to in writing, software distributed under the License is
8
+ distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF
9
+ ANY KIND, either express or implied. See the License for the specific
10
+ language governing permissions and limitations under the License.
11
+ */
12
+
13
+ class Constants {
14
+ static let CACHE_MISS = "No message found in cache. Please ensure you have cached the message"
15
+ static let ON_DISMISS_EVENT = "onDismiss"
16
+ static let ON_SHOW_EVENT = "onShow"
17
+ static let SHOULD_SHOW_MESSAGE_EVENT = "shouldShowMessage"
18
+ static let URL_LOADED_EVENT = "urlLoaded"
19
+ static let SUPPORTED_EVENTS = [
20
+ ON_DISMISS_EVENT, ON_SHOW_EVENT, SHOULD_SHOW_MESSAGE_EVENT, URL_LOADED_EVENT,
21
+ ]
22
+ }
@@ -0,0 +1,47 @@
1
+ /*
2
+ Copyright 2023 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the
4
+ "License"); you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
7
+ or agreed to in writing, software distributed under the License is
8
+ distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF
9
+ ANY KIND, either express or implied. See the License for the specific
10
+ language governing permissions and limitations under the License.
11
+ */
12
+
13
+ import AEPMessaging
14
+
15
+ public class RCTAEPMessagingDataBridge: NSObject {
16
+ static func transformToMessage(message: Message) -> [String: Any] {
17
+ return [
18
+ "id": message.id, "autoTrack": message.autoTrack,
19
+ ]
20
+ }
21
+
22
+ static func transformPropositionDict(dict: [Surface: [Proposition]]) -> [String: [Any]]
23
+ {
24
+ let bundleID = "mobileapp://" + Bundle.main.bundleIdentifier! + "/"
25
+ return dict.reduce(into: [:]) { result, element in
26
+ result[element.key.uri.replacingOccurrences(of: bundleID, with: "")] = element.value
27
+ .map({ self.transformToProposition(proposition: $0) })
28
+ }
29
+ }
30
+
31
+ static func transformToProposition(proposition: Proposition) -> [String: Any?] {
32
+ return [
33
+ "scope": proposition.scope,
34
+ "uniqueId": proposition.uniqueId,
35
+ "items": proposition.items.map({ item in
36
+ [
37
+ "htmlContent": item.htmlContent,
38
+ "jsonContentArray": item.jsonContentArray,
39
+ "jsonContent": item.jsonContentDictionary,
40
+ "itemData": item.itemData as Any?,
41
+ "schema": item.schema,
42
+ "itemId": item.itemId
43
+ ]
44
+ }),
45
+ ]
46
+ }
47
+ }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@adobe/react-native-aepmessaging",
3
- "version": "5.0.0",
3
+ "version": "6.0.0",
4
4
  "description": "Adobe Experience Platform support for React Native apps.",
5
5
  "homepage": "https://developer.adobe.com/client-sdks/documentation/",
6
6
  "license": "Apache-2.0",
7
- "main": "./ts/index.ts",
7
+ "main": "./src/index.ts",
8
8
  "scripts": {
9
9
  "cleanup": "rm -rf node_modules",
10
10
  "tsc": "tsc"
@@ -27,9 +27,9 @@
27
27
  "name": "Adobe Experience Platform SDK Team"
28
28
  },
29
29
  "peerDependencies": {
30
- "@adobe/react-native-aepcore": "^5.0.0",
31
- "@adobe/react-native-aepedge": "^5.0.0",
32
- "@adobe/react-native-aepedgeidentity": "^5.0.0",
30
+ "@adobe/react-native-aepcore": "^6.0.0",
31
+ "@adobe/react-native-aepedge": "^6.0.0",
32
+ "@adobe/react-native-aepedgeidentity": "^6.0.0",
33
33
  "react-native": ">=0.60.0"
34
34
  },
35
35
  "publishConfig": {
@@ -38,5 +38,5 @@
38
38
  "installConfig": {
39
39
  "hoistingLimits": "dependencies"
40
40
  },
41
- "gitHead": "7c28b79c996a51d9d5048b0bfd60a5df4cbc8cc8"
41
+ "gitHead": "7df5d257041d7bc1072177e21ff4286cf04773f6"
42
42
  }
@@ -0,0 +1,164 @@
1
+ /*
2
+ Copyright 2023 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import {
14
+ NativeModules,
15
+ NativeEventEmitter,
16
+ NativeModule,
17
+ Platform
18
+ } from 'react-native';
19
+ import Message from './models/Message';
20
+ import { MessagingDelegate } from './models/MessagingDelegate';
21
+ import { MessagingProposition } from './models/MessagingProposition';
22
+
23
+ export interface NativeMessagingModule {
24
+ extensionVersion: () => Promise<string>;
25
+ getCachedMessages: () => Message[];
26
+ getLatestMessage: () => Message;
27
+ getPropositionsForSurfaces: (
28
+ surfaces: string[]
29
+ ) => Record<string, MessagingProposition[]>;
30
+ refreshInAppMessages: () => void;
31
+ setMessagingDelegate: (delegate?: MessagingDelegate) => void;
32
+ setMessageSettings: (
33
+ shouldShowMessage: boolean,
34
+ shouldSaveMessage: boolean
35
+ ) => void;
36
+ updatePropositionsForSurfaces: (surfaces: string[]) => void;
37
+ }
38
+
39
+ const RCTAEPMessaging: NativeModule & NativeMessagingModule =
40
+ NativeModules.AEPMessaging;
41
+
42
+ declare var messagingDelegate: MessagingDelegate;
43
+ var messagingDelegate: MessagingDelegate;
44
+
45
+ class Messaging {
46
+ /**
47
+ * Returns the version of the AEPMessaging extension
48
+ * @returns {string} Promise a promise that resolves with the extension version
49
+ */
50
+ static extensionVersion(): Promise<string> {
51
+ return Promise.resolve(RCTAEPMessaging.extensionVersion());
52
+ }
53
+
54
+ /**
55
+ * Initiates a network call to retrieve remote In-App Message definitions.
56
+ */
57
+ static refreshInAppMessages() {
58
+ RCTAEPMessaging.refreshInAppMessages();
59
+ }
60
+
61
+ /**
62
+ * Retrieves the list of messages which have been cached using the `shouldSaveMessage`
63
+ * method of the messaging delegate.
64
+ * Note: Messages should be cached before trying to use any of the methods on the message class
65
+ * @returns An array of messages that have been cached
66
+ */
67
+ static async getCachedMessages(): Promise<Message[]> {
68
+ const messages = await RCTAEPMessaging.getCachedMessages();
69
+ return messages.map((msg) => new Message(msg));
70
+ }
71
+
72
+ /**
73
+ * Retrieves the last message that has been shown in the UI
74
+ * @returns The latest message to have been displayed
75
+ */
76
+ static async getLatestMessage(): Promise<Message> {
77
+ const message = await RCTAEPMessaging.getLatestMessage();
78
+ return message ? new Message(message) : undefined;
79
+ }
80
+
81
+ /**
82
+ * Retrieves the previously fetched (and cached) feeds content from the SDK for the provided surfaces.
83
+ * If the feeds content for one or more surfaces isn't previously cached in the SDK, it will not be retrieved from Adobe Journey Optimizer via the Experience Edge network.
84
+ * @param surfaces A list of surfaces to fetch
85
+ * @returns A record of surface names with their corresponding propositions
86
+ */
87
+ static async getPropositionsForSurfaces(
88
+ surfaces: string[]
89
+ ): Promise<Record<string, MessagingProposition[]>> {
90
+ return await RCTAEPMessaging.getPropositionsForSurfaces(surfaces);
91
+ }
92
+
93
+ /**
94
+ * Function to set the UI Message delegate to listen the Message lifecycle events.
95
+ * @returns A function to unsubscribe from all event listeners
96
+ */
97
+ static setMessagingDelegate(delegate: MessagingDelegate): () => void {
98
+ messagingDelegate = delegate;
99
+
100
+ const eventEmitter = new NativeEventEmitter(RCTAEPMessaging);
101
+
102
+ eventEmitter.addListener('onShow', (message) =>
103
+ messagingDelegate?.onShow?.(message)
104
+ );
105
+
106
+ eventEmitter.addListener('onDismiss', (message) => {
107
+ messagingDelegate?.onDismiss?.(message);
108
+ });
109
+
110
+ eventEmitter.addListener('shouldShowMessage', (message) => {
111
+ const shouldShowMessage =
112
+ messagingDelegate?.shouldShowMessage?.(message) ?? true;
113
+ const shouldSaveMessage =
114
+ messagingDelegate?.shouldSaveMessage?.(message) ?? false;
115
+ RCTAEPMessaging.setMessageSettings(shouldShowMessage, shouldSaveMessage);
116
+ });
117
+
118
+ if (Platform.OS === 'ios') {
119
+ eventEmitter.addListener('urlLoaded', (event) =>
120
+ messagingDelegate?.urlLoaded?.(event.url, event.message)
121
+ );
122
+ }
123
+
124
+ if (Platform.OS === 'android') {
125
+ eventEmitter.addListener('onContentLoaded', (event) =>
126
+ messagingDelegate?.onContentLoaded?.(event.message)
127
+ );
128
+ }
129
+
130
+ RCTAEPMessaging.setMessagingDelegate();
131
+
132
+ return () => {
133
+ eventEmitter.removeAllListeners('onDismiss');
134
+ eventEmitter.removeAllListeners('onShow');
135
+ eventEmitter.removeAllListeners('shouldShowMessage');
136
+ eventEmitter.removeAllListeners('urlLoaded');
137
+ eventEmitter.removeAllListeners('onContentLoaded');
138
+ };
139
+ }
140
+
141
+ /**
142
+ * Sets global settings for messages being shown and cached
143
+ * Note: This method is also used by MessagingDelegate.shouldShowMessage,
144
+ * which allows finer-grained control over setting these settings
145
+ * @param shouldShowMessage Whether or not a message should be displayed
146
+ * @param shouldSaveMessage Whether or not a message should be cached
147
+ */
148
+ static setMessageSettings(
149
+ shouldShowMessage: boolean,
150
+ shouldSaveMessage: boolean
151
+ ) {
152
+ RCTAEPMessaging.setMessageSettings(shouldShowMessage, shouldSaveMessage);
153
+ }
154
+
155
+ /**
156
+ * Dispatches an event to fetch propositions for the provided surfaces from remote.
157
+ * @param surfaces A list of surface names to update
158
+ */
159
+ static updatePropositionsForSurfaces(surfaces: string[]) {
160
+ RCTAEPMessaging.updatePropositionsForSurfaces(surfaces);
161
+ }
162
+ }
163
+
164
+ export default Messaging;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2022 Adobe. All rights reserved.
2
+ Copyright 2023 Adobe. All rights reserved.
3
3
  This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License. You may obtain a copy
5
5
  of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -14,5 +14,14 @@ import Messaging from './Messaging';
14
14
  import Message from './models/Message';
15
15
  import { MessagingDelegate } from './models/MessagingDelegate';
16
16
  import MessagingEdgeEventType from './models/MessagingEdgeEventType';
17
+ import { MessagingProposition } from './models/MessagingProposition';
18
+ import { MessagingPropositionItem } from './models/MessagingPropositionItem';
17
19
 
18
- export { Messaging, Message, MessagingDelegate, MessagingEdgeEventType };
20
+ export {
21
+ Messaging,
22
+ Message,
23
+ MessagingDelegate,
24
+ MessagingEdgeEventType,
25
+ MessagingProposition,
26
+ MessagingPropositionItem
27
+ };
@@ -0,0 +1,72 @@
1
+ /*
2
+ Copyright 2023 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import { NativeModules } from 'react-native';
14
+ const RCTAEPMessaging = NativeModules.AEPMessaging;
15
+
16
+ class Message {
17
+ id: string;
18
+ autoTrack: boolean;
19
+
20
+ constructor({id, autoTrack = false}: {id: string; autoTrack: boolean}) {
21
+ this.id = id;
22
+ this.autoTrack = autoTrack;
23
+ }
24
+
25
+ /**
26
+ * Update the value of property "autoTrack"
27
+ * This function works only for the Message objects that were saved by calling "Messaging.saveMessage"
28
+ * @param {boolean} autoTrack: New value of property autoTrack.
29
+ */
30
+ setAutoTrack(autoTrack: boolean) {
31
+ this.autoTrack = autoTrack;
32
+ RCTAEPMessaging.setAutoTrack(this.id, autoTrack);
33
+ }
34
+
35
+ /**
36
+ * Signals to the UIServices that the message should be shown.
37
+ * If autoTrack is true, calling this method will result in an "inapp.display" Edge Event being dispatched.
38
+ */
39
+ show() {
40
+ RCTAEPMessaging.show(this.id);
41
+ }
42
+
43
+ /**
44
+ * Signals to the UIServices that the message should be dismissed.
45
+ * If `autoTrack` is true, calling this method will result in an "inapp.dismiss" Edge Event being dispatched.
46
+ * @param {boolean?} suppressAutoTrack: if set to true, the inapp.dismiss Edge Event will not be sent regardless
47
+ * of the autoTrack setting.
48
+ */
49
+ dismiss(suppressAutoTrack?: boolean) {
50
+ RCTAEPMessaging.dismiss(this.id, suppressAutoTrack ? true : false);
51
+ }
52
+
53
+ /**
54
+ * Generates an Edge Event for the provided interaction and eventType.
55
+ * @param {string?} interaction: a custom String value to be recorded in the interaction
56
+ * @param {MessagingEdgeEventType} eventType: the MessagingEdgeEventType to be used for the ensuing Edge Event
57
+ */
58
+ track(interaction: string, eventType: number) {
59
+ RCTAEPMessaging.track(this.id, interaction, eventType);
60
+ }
61
+
62
+ /**
63
+ * Clears the cached reference to the Message object.
64
+ * This function must be called if Message was saved by calling "MessagingDelegate.shouldSaveMessage" but no longer needed.
65
+ * Failure to call this function leads to memory leaks.
66
+ */
67
+ clear() {
68
+ RCTAEPMessaging.clear(this.id);
69
+ }
70
+ }
71
+
72
+ export default Message;