@adobe/react-native-aepmessaging 5.0.0 → 5.1.0-beta.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.
Files changed (61) hide show
  1. package/.babelrc +1 -1
  2. package/RCTAEPMessaging.podspec +25 -7
  3. package/README.md +109 -9
  4. package/android/build.gradle +87 -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 +267 -200
  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 +131 -0
  11. package/dist/Messaging.d.ts +62 -0
  12. package/dist/Messaging.js +112 -0
  13. package/dist/Messaging.js.map +1 -0
  14. package/{js → dist}/index.js +1 -1
  15. package/dist/index.js.map +1 -0
  16. package/dist/models/Message.d.ts +46 -0
  17. package/dist/models/Message.js +73 -0
  18. package/dist/models/Message.js.map +1 -0
  19. package/dist/models/MessagingDelegate.d.ts +30 -0
  20. package/{js → dist}/models/MessagingDelegate.js +1 -1
  21. package/dist/models/MessagingDelegate.js.map +1 -0
  22. package/{js → dist}/models/MessagingEdgeEventType.js +1 -1
  23. package/dist/models/MessagingEdgeEventType.js.map +1 -0
  24. package/dist/models/MessagingProposition.d.ts +8 -0
  25. package/dist/models/MessagingProposition.js +24 -0
  26. package/dist/models/MessagingProposition.js.map +1 -0
  27. package/dist/models/MessagingPropositionItem.d.ts +6 -0
  28. package/dist/models/MessagingPropositionItem.js +23 -0
  29. package/dist/models/MessagingPropositionItem.js.map +1 -0
  30. package/ios/src/RCTAEPMessaging-Bridging-Header.h +15 -0
  31. package/ios/src/RCTAEPMessaging.mm +50 -0
  32. package/ios/src/RCTAEPMessaging.swift +283 -0
  33. package/ios/src/RCTAEPMessagingConstants.swift +22 -0
  34. package/ios/src/RCTAEPMessagingDataBridge.swift +41 -0
  35. package/package.json +3 -3
  36. package/src/Messaging.ts +147 -0
  37. package/{ts → src}/index.ts +1 -1
  38. package/src/models/Message.ts +84 -0
  39. package/src/models/MessagingDelegate.ts +47 -0
  40. package/{ts → src}/models/MessagingEdgeEventType.ts +1 -1
  41. package/src/models/MessagingProposition.ts +32 -0
  42. package/src/models/MessagingPropositionItem.ts +23 -0
  43. package/tsconfig.json +2 -2
  44. package/ios/RCTAEPMessaging.xcodeproj/project.pbxproj +0 -304
  45. package/ios/src/RCTAEPMessaging.h +0 -20
  46. package/ios/src/RCTAEPMessaging.m +0 -196
  47. package/js/Messaging.d.ts +0 -32
  48. package/js/Messaging.js +0 -80
  49. package/js/Messaging.js.map +0 -1
  50. package/js/index.js.map +0 -1
  51. package/js/models/Message.d.ts +0 -43
  52. package/js/models/Message.js +0 -80
  53. package/js/models/Message.js.map +0 -1
  54. package/js/models/MessagingDelegate.d.ts +0 -25
  55. package/js/models/MessagingDelegate.js.map +0 -1
  56. package/js/models/MessagingEdgeEventType.js.map +0 -1
  57. package/ts/Messaging.ts +0 -99
  58. package/ts/models/Message.ts +0 -82
  59. package/ts/models/MessagingDelegate.ts +0 -41
  60. /package/{js → dist}/index.d.ts +0 -0
  61. /package/{js → dist}/models/MessagingEdgeEventType.d.ts +0 -0
@@ -0,0 +1,283 @@
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 handleJavascriptMessage(
148
+ _ id: String,
149
+ withName name: String,
150
+ withResolver resolve: @escaping RCTPromiseResolveBlock,
151
+ withRejecter reject: @escaping RCTPromiseRejectBlock
152
+ ) {
153
+ let msg = messageCache[id]
154
+ if msg != nil {
155
+ msg!.handleJavascriptMessage(name) { content in
156
+ resolve(content)
157
+ return
158
+ }
159
+ }
160
+ reject(Constants.CACHE_MISS, nil, nil)
161
+ }
162
+
163
+ @objc
164
+ func setAutoTrack(
165
+ _ id: String,
166
+ withSuppressAutoTrack suppressAutoTrack: Bool,
167
+ withResolver resolve: @escaping RCTPromiseResolveBlock,
168
+ withRejecter reject: @escaping RCTPromiseRejectBlock
169
+ ) {
170
+
171
+ let msg = messageCache[id]
172
+ if msg != nil {
173
+ msg!.autoTrack = suppressAutoTrack
174
+ resolve(nil)
175
+ return
176
+ }
177
+ reject(Constants.CACHE_MISS, nil, nil)
178
+ }
179
+
180
+ @objc
181
+ private func showMessage(
182
+ _ id: String,
183
+ withResolver resolve: @escaping RCTPromiseResolveBlock,
184
+ withRejecter reject: @escaping RCTPromiseRejectBlock
185
+ ) {
186
+ let msg = messageCache[id]
187
+ if msg != nil {
188
+ msg!.show()
189
+ resolve(nil)
190
+ return
191
+ }
192
+ reject(Constants.CACHE_MISS, nil, nil)
193
+
194
+ }
195
+
196
+ @objc
197
+ func trackMessage(
198
+ _ id: String,
199
+ withInteraction interaction: String,
200
+ withEventType eventType: Int,
201
+ withResolver resolve: @escaping RCTPromiseResolveBlock,
202
+ withRejecter reject: @escaping RCTPromiseRejectBlock
203
+ ) {
204
+
205
+ let msg = messageCache[id]
206
+ let eventType =
207
+ MessagingEdgeEventType.init(rawValue: eventType)
208
+ ?? MessagingEdgeEventType.inappDismiss
209
+ if msg != nil {
210
+ msg!.track(interaction, withEdgeEventType: eventType)
211
+ resolve(nil)
212
+ return
213
+ }
214
+ reject(Constants.CACHE_MISS, nil, nil)
215
+ }
216
+
217
+ // Messaging Delegate Methods
218
+ public func onDismiss(message: Showable) {
219
+ if let fullscreenMessage = message as? FullscreenMessage,
220
+ let parentMessage = fullscreenMessage.parent
221
+ {
222
+ emitNativeEvent(
223
+ name: Constants.ON_DISMISS_EVENT,
224
+ body: RCTAEPMessagingDataBridge.transformToMessage(
225
+ message: parentMessage
226
+ )
227
+ )
228
+ }
229
+ }
230
+
231
+ public func onShow(message: Showable) {
232
+ if let fullscreenMessage = message as? FullscreenMessage,
233
+ let message = fullscreenMessage.parent
234
+ {
235
+ emitNativeEvent(
236
+ name: Constants.ON_SHOW_EVENT,
237
+ body: RCTAEPMessagingDataBridge.transformToMessage(message: message)
238
+ )
239
+ }
240
+ }
241
+
242
+ public func shouldShowMessage(message: Showable) -> Bool {
243
+ if let fullscreenMessage = message as? FullscreenMessage,
244
+ let message = fullscreenMessage.parent
245
+ {
246
+ emitNativeEvent(
247
+ name: Constants.SHOULD_SHOW_MESSAGE_EVENT,
248
+ body: RCTAEPMessagingDataBridge.transformToMessage(message: message)
249
+ )
250
+ semaphore.wait()
251
+ if self.shouldSaveMessage {
252
+ self.messageCache[message.id] = message
253
+ }
254
+
255
+ if self.shouldShowMessage {
256
+ latestMessage = message
257
+ }
258
+
259
+ return self.shouldShowMessage
260
+ }
261
+ return false
262
+ }
263
+
264
+ public func urlLoaded(_ url: URL, byMessage message: Showable) {
265
+ if let fullscreenMessage = message as? FullscreenMessage,
266
+ let parentMessage = fullscreenMessage.parent
267
+ {
268
+ emitNativeEvent(
269
+ name: Constants.URL_LOADED_EVENT,
270
+ body: [
271
+ "url": url.absoluteString,
272
+ "message": RCTAEPMessagingDataBridge.transformToMessage(
273
+ message: parentMessage
274
+ ),
275
+ ]
276
+ )
277
+ }
278
+ }
279
+
280
+ private func emitNativeEvent(name: String, body: Any) {
281
+ RCTAEPMessaging.emitter.sendEvent(withName: name, body: body)
282
+ }
283
+ }
@@ -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,41 @@
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: [MessagingProposition]]) -> [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: MessagingProposition) -> [String: Any] {
32
+ return [
33
+ "scope": proposition.scope, "uniqueId": proposition.uniqueId,
34
+ "items": proposition.items.map({ item in
35
+ [
36
+ "content": item.content, "schema": item.schema, "uniqueId": item.uniqueId,
37
+ ]
38
+ }),
39
+ ]
40
+ }
41
+ }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@adobe/react-native-aepmessaging",
3
- "version": "5.0.0",
3
+ "version": "5.1.0-beta.1",
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"
@@ -38,5 +38,5 @@
38
38
  "installConfig": {
39
39
  "hoistingLimits": "dependencies"
40
40
  },
41
- "gitHead": "7c28b79c996a51d9d5048b0bfd60a5df4cbc8cc8"
41
+ "gitHead": "fdc4078e6278822c955f095dec2f133056c00713"
42
42
  }
@@ -0,0 +1,147 @@
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, NativeEventEmitter, NativeModule } from 'react-native';
14
+ import Message from './models/Message';
15
+ import { MessagingDelegate } from './models/MessagingDelegate';
16
+ import { MessagingProposition } from './models/MessagingProposition';
17
+
18
+ export interface NativeMessagingModule {
19
+ extensionVersion: () => Promise<string>;
20
+ getCachedMessages: () => Message[];
21
+ getLatestMessage: () => Message;
22
+ getPropositionsForSurfaces: (
23
+ surfaces: string[]
24
+ ) => Record<string, MessagingProposition[]>;
25
+ refreshInAppMessages: () => void;
26
+ setMessagingDelegate: (delegate?: MessagingDelegate) => void;
27
+ setMessageSettings: (
28
+ shouldShowMessage: boolean,
29
+ shouldSaveMessage: boolean
30
+ ) => void;
31
+ updatePropositionsForSurfaces: (surfaces: string[]) => void;
32
+ }
33
+
34
+ const RCTAEPMessaging: NativeModule & NativeMessagingModule =
35
+ NativeModules.AEPMessaging;
36
+
37
+ declare var messagingDelegate: MessagingDelegate;
38
+ var messagingDelegate: MessagingDelegate;
39
+
40
+ class Messaging {
41
+ /**
42
+ * Returns the version of the AEPMessaging extension
43
+ * @returns {string} Promise a promise that resolves with the extension version
44
+ */
45
+ static extensionVersion(): Promise<string> {
46
+ return Promise.resolve(RCTAEPMessaging.extensionVersion());
47
+ }
48
+
49
+ /**
50
+ * Initiates a network call to retrieve remote In-App Message definitions.
51
+ */
52
+ static refreshInAppMessages() {
53
+ RCTAEPMessaging.refreshInAppMessages();
54
+ }
55
+
56
+ /**
57
+ * Retrieves the list of messages which have been cached using the `shouldSaveMessage`
58
+ * method of the messaging delegate.
59
+ * Note: Messages should be cached before trying to use any of the methods on the message class
60
+ * @returns An array of messages that have been cached
61
+ */
62
+ static async getCachedMessages(): Promise<Message[]> {
63
+ const messages = await RCTAEPMessaging.getCachedMessages();
64
+ return messages.map(msg => new Message(msg));
65
+ }
66
+
67
+ /**
68
+ * Retrieves the last message that has been shown in the UI
69
+ * @returns The latest message to have been displayed
70
+ */
71
+ static async getLatestMessage(): Promise<Message> {
72
+ const message = await RCTAEPMessaging.getLatestMessage();
73
+ return message ? new Message(message) : undefined;
74
+ }
75
+
76
+ /**
77
+ * Retrieves the previously fetched (and cached) feeds content from the SDK for the provided surfaces.
78
+ * 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.
79
+ * @param surfaces A list of surfaces to fetch
80
+ * @returns A record of surface names with their corresponding propositions
81
+ */
82
+ static async getPropositionsForSurfaces(
83
+ surfaces: string[]
84
+ ): Promise<Record<string, MessagingProposition[]>> {
85
+ return await RCTAEPMessaging.getPropositionsForSurfaces(surfaces);
86
+ }
87
+
88
+ /**
89
+ * Function to set the UI Message delegate to listen the Message lifecycle events.
90
+ * @returns A function to unsubscribe from all event listeners
91
+ */
92
+ static setMessagingDelegate(delegate: MessagingDelegate): () => void {
93
+ messagingDelegate = delegate;
94
+
95
+ const eventEmitter = new NativeEventEmitter(RCTAEPMessaging);
96
+
97
+ eventEmitter.addListener('onShow', (message) =>
98
+ messagingDelegate?.onShow?.(message)
99
+ );
100
+
101
+ eventEmitter.addListener('onDismiss', (message) => {
102
+ messagingDelegate?.onDismiss?.(message);
103
+ });
104
+
105
+ eventEmitter.addListener('shouldShowMessage', (message) => {
106
+ const shouldShowMessage =
107
+ messagingDelegate?.shouldShowMessage?.(message) ?? true;
108
+ const shouldSaveMessage =
109
+ messagingDelegate?.shouldSaveMessage?.(message) ?? false;
110
+ RCTAEPMessaging.setMessageSettings(shouldShowMessage, shouldSaveMessage);
111
+ });
112
+
113
+ eventEmitter.addListener('urlLoaded', (event) =>
114
+ messagingDelegate?.urlLoaded?.(event.url, event.message)
115
+ );
116
+
117
+ RCTAEPMessaging.setMessagingDelegate();
118
+
119
+ return () => {
120
+ eventEmitter.removeAllListeners('onDismiss');
121
+ eventEmitter.removeAllListeners('onShow');
122
+ eventEmitter.removeAllListeners('shouldShowMessage');
123
+ eventEmitter.removeAllListeners('urlLoaded');
124
+ };
125
+ }
126
+
127
+ /**
128
+ * Sets global settings for messages being shown and cached
129
+ * Note: This method is also used by MessagingDelegate.shouldShowMessage,
130
+ * which allows finer-grained control over setting these settings
131
+ * @param shouldShowMessage Whether or not a message should be displayed
132
+ * @param shouldSaveMessage Whether or not a message should be cached
133
+ */
134
+ static setMessageSettings(shouldShowMessage: boolean, shouldSaveMessage: boolean) {
135
+ RCTAEPMessaging.setMessageSettings(shouldShowMessage, shouldSaveMessage);
136
+ }
137
+
138
+ /**
139
+ * Dispatches an event to fetch propositions for the provided surfaces from remote.
140
+ * @param surfaces A list of surface names to update
141
+ */
142
+ static updatePropositionsForSurfaces(surfaces: string[]) {
143
+ RCTAEPMessaging.updatePropositionsForSurfaces(surfaces);
144
+ }
145
+ }
146
+
147
+ 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
@@ -0,0 +1,84 @@
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
+ * Adds a handler for Javascript messages sent from the message's webview.
64
+ * The parameter passed to `handler` will contain the body of the message passed from the webview's Javascript.
65
+ * @param {string} name: the name of the message that should be handled by `handler`
66
+ * @return {Promise<any?>}: the Promise to be resolved with the body of the message passed by the Javascript message in the WebView
67
+ */
68
+ handleJavascriptMessage(name: string): Promise<any> {
69
+ return Promise.resolve(
70
+ RCTAEPMessaging.handleJavascriptMessage(this.id, name)
71
+ );
72
+ }
73
+
74
+ /**
75
+ * Clears the cached reference to the Message object.
76
+ * This function must be called if Message was saved by calling "MessagingDelegate.shouldSaveMessage" but no longer needed.
77
+ * Failure to call this function leads to memory leaks.
78
+ */
79
+ clear() {
80
+ RCTAEPMessaging.clear(this.id);
81
+ }
82
+ }
83
+
84
+ export default Message;
@@ -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 "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 Message from './Message';
14
+
15
+ export interface MessagingDelegate {
16
+ /**
17
+ * Invoked when the any message is displayed
18
+ * @param {Message} message: Message that is being displayed.
19
+ */
20
+ onShow?(message: Message): void;
21
+
22
+ /**
23
+ * Invoked when any message is dismissed
24
+ * @param {Message} message: Message that is being dismissed
25
+ */
26
+ onDismiss?(message: Message): void;
27
+
28
+ /**
29
+ * Used to determine whether a message should be cached, so it can be used later. Return true if the message should be cached.
30
+ * Note: Message must be cached in order to call any of the functions of the message object
31
+ */
32
+ shouldSaveMessage?(message: Message): boolean;
33
+
34
+ /**
35
+ * Used to find whether messages should be shown or not
36
+ * @param {Message} message: Message that is about to get displayed
37
+ * @returns {boolean}: true if the message should be shown else false
38
+ */
39
+ shouldShowMessage?(message: Message): boolean;
40
+
41
+ /**
42
+ * Called when message loads a URL
43
+ * @param {string} url: the URL being loaded by the message
44
+ * @param {Message} message: the Message loading a URL
45
+ */
46
+ urlLoaded?(url: string, message: Message): void;
47
+ }
@@ -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