cordova-plugin-reteno 2.0.4 → 2.2.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.
@@ -135,7 +135,7 @@ var urlutil = require('cordova/urlutil');
135
135
  */
136
136
 
137
137
  const RetenoPluginFunctions = {
138
- /*
138
+ /*
139
139
  options: {
140
140
  accessKey?: string,
141
141
  pauseInAppMessages?: boolean,
@@ -143,7 +143,7 @@ const RetenoPluginFunctions = {
143
143
  inAppMessagesPauseBehaviour?: 'SKIP_IN_APPS' | 'POSTPONE_IN_APPS',
144
144
  isAutomaticScreenReportingEnabled?: boolean,
145
145
  isDebugMode?: boolean,
146
- sessionDurationSeconds?: number, // Android 2.9.4+, iOS 2.7.0+
146
+ sessionDurationSeconds?: number, // Android 2.9.6+, iOS 2.7.2+
147
147
  lifecycleTrackingOptions?: {
148
148
  appLifecycleEnabled?: boolean,
149
149
  foregroundLifecycleEnabled?: boolean,
@@ -154,206 +154,207 @@ const RetenoPluginFunctions = {
154
154
  }
155
155
  }
156
156
  */
157
- init: function (arg0, success, error) {
158
- // Back-compat: init(success, error)
159
- if (typeof arg0 === 'function') {
160
- error = success;
161
- success = arg0;
162
- arg0 = {};
163
- }
164
-
165
- const options = arg0 || {};
166
- const p = __ensureInit(options);
167
- if (__isFn(success) || __isFn(error)) {
168
- p.then(function (res) {
169
- if (__isFn(success)) success(res);
170
- return res;
171
- }).catch(function (err) {
172
- if (__isFn(error)) error(err);
173
- throw err;
174
- });
175
- }
176
- return p;
177
- },
157
+ init: function (arg0, success, error) {
158
+ // Back-compat: init(success, error)
159
+ if (typeof arg0 === 'function') {
160
+ error = success;
161
+ success = arg0;
162
+ arg0 = {};
163
+ }
164
+
165
+ const options = arg0 || {};
166
+ const p = __ensureInit(options);
167
+ if (__isFn(success) || __isFn(error)) {
168
+ p.then(function (res) {
169
+ if (__isFn(success)) success(res);
170
+ return res;
171
+ }).catch(function (err) {
172
+ if (__isFn(error)) error(err);
173
+ throw err;
174
+ });
175
+ }
176
+ return p;
177
+ },
178
178
 
179
- /* arg0:
179
+ /* arg0:
180
180
  eventName: string,
181
181
  date: string,
182
182
  // date parameter should be in ISO8601 format
183
183
  parameters: CustomEventParameter[],
184
184
  forcePush?: boolean
185
185
  */
186
- logEvent: function (arg0, success, error) {
187
- return __callWithAutoInit('logEvent', [arg0], success, error);
188
- },
186
+ logEvent: function (arg0, success, error) {
187
+ return __callWithAutoInit('logEvent', [arg0], success, error);
188
+ },
189
189
 
190
- /*
190
+ /*
191
191
  payload: LogEcommerceEventPayload
192
192
  See https://docs.reteno.com/reference/android-ecommerce-activity-tracking
193
193
  */
194
- logEcommerceEvent: function (arg0, success, error) {
195
- // Accept either `payload` or legacy `[payload]`.
196
- const payload = Array.isArray(arg0) ? arg0[0] : arg0;
197
- if (!payload || typeof payload !== 'object') {
198
- return Promise.reject(new Error('Missing argument: payload'));
199
- }
200
- if (!payload.eventType || typeof payload.eventType !== 'string' || payload.eventType.trim().length === 0) {
201
- return Promise.reject(new Error('Missing argument: eventType'));
202
- }
203
- return __callWithAutoInit('logEcommerceEvent', [payload], success, error);
204
- },
205
-
206
- /*
194
+ logEcommerceEvent: function (arg0, success, error) {
195
+ // Accept either `payload` or legacy `[payload]`.
196
+ const payload = Array.isArray(arg0) ? arg0[0] : arg0;
197
+ if (!payload || typeof payload !== 'object') {
198
+ return Promise.reject(new Error('Missing argument: payload'));
199
+ }
200
+ if (
201
+ !payload.eventType ||
202
+ typeof payload.eventType !== 'string' ||
203
+ payload.eventType.trim().length === 0
204
+ ) {
205
+ return Promise.reject(new Error('Missing argument: eventType'));
206
+ }
207
+ return __callWithAutoInit('logEcommerceEvent', [payload], success, error);
208
+ },
209
+
210
+ /*
207
211
  payload: SetUserAttributesPayload
208
212
  */
209
- setUserAttributes: function (arg0, success, error) {
210
- // Accept either `payload` or legacy `[payload]`.
211
- const payload = Array.isArray(arg0) ? arg0[0] : arg0;
212
- if (
213
- !payload ||
214
- !payload.externalUserId ||
215
- (payload.externalUserId && payload.externalUserId.length === 0)
216
- ) {
217
- return Promise.reject(new Error('Missing argument: "externalUserId"'));
218
- }
219
- return __callWithAutoInit('setUserAttributes', [payload], success, error);
220
- },
221
-
222
- /*
213
+ setUserAttributes: function (arg0, success, error) {
214
+ // Accept either `payload` or legacy `[payload]`.
215
+ const payload = Array.isArray(arg0) ? arg0[0] : arg0;
216
+ if (
217
+ !payload ||
218
+ !payload.externalUserId ||
219
+ (payload.externalUserId && payload.externalUserId.length === 0)
220
+ ) {
221
+ return Promise.reject(new Error('Missing argument: "externalUserId"'));
222
+ }
223
+ return __callWithAutoInit('setUserAttributes', [payload], success, error);
224
+ },
225
+
226
+ /*
223
227
  payload: UserAttributesAnonymous
224
228
  */
225
- setAnonymousUserAttributes: function (arg0, success, error) {
226
- // Accept either `payload` or legacy `[payload]`.
227
- const payload = Array.isArray(arg0) ? arg0[0] : arg0;
228
- if (!payload || typeof payload !== 'object') {
229
- return Promise.reject(new Error('Missing argument: payload'));
230
- }
231
-
232
- // Reteno docs: anonymous user attributes cannot include phone/email.
233
- if (payload.phone || payload.email) {
234
- return Promise.reject(
235
- new Error(
236
- 'Anonymous user attributes cannot include phone/email. Use setUserAttributes(externalUserId, user) instead.'
237
- )
238
- );
239
- }
240
- if (
241
- payload.userAttributes &&
242
- (payload.userAttributes.phone || payload.userAttributes.email)
243
- ) {
244
- return Promise.reject(
245
- new Error(
246
- 'Anonymous user attributes cannot include phone/email. Use setUserAttributes(externalUserId, user) instead.'
247
- )
248
- );
249
- }
250
- return __callWithAutoInit('setAnonymousUserAttributes', [payload], success, error);
251
- },
252
-
253
- /*
229
+ setAnonymousUserAttributes: function (arg0, success, error) {
230
+ // Accept either `payload` or legacy `[payload]`.
231
+ const payload = Array.isArray(arg0) ? arg0[0] : arg0;
232
+ if (!payload || typeof payload !== 'object') {
233
+ return Promise.reject(new Error('Missing argument: payload'));
234
+ }
235
+
236
+ // Reteno docs: anonymous user attributes cannot include phone/email.
237
+ if (payload.phone || payload.email) {
238
+ return Promise.reject(
239
+ new Error(
240
+ 'Anonymous user attributes cannot include phone/email. Use setUserAttributes(externalUserId, user) instead.'
241
+ )
242
+ );
243
+ }
244
+ if (payload.userAttributes && (payload.userAttributes.phone || payload.userAttributes.email)) {
245
+ return Promise.reject(
246
+ new Error(
247
+ 'Anonymous user attributes cannot include phone/email. Use setUserAttributes(externalUserId, user) instead.'
248
+ )
249
+ );
250
+ }
251
+ return __callWithAutoInit('setAnonymousUserAttributes', [payload], success, error);
252
+ },
253
+
254
+ /*
254
255
  payload: SetMultiAccountUserAttributesPayload
255
256
  */
256
- setMultiAccountUserAttributes: function (arg0, success, error) {
257
- // Accept either `payload` or legacy `[payload]`.
258
- const payload = Array.isArray(arg0) ? arg0[0] : arg0;
259
- if (
260
- !payload ||
261
- !payload.externalUserId ||
262
- (payload.externalUserId && payload.externalUserId.length === 0)
263
- ) {
264
- return Promise.reject(new Error('Missing argument: "externalUserId"'));
265
- }
266
- if (!payload.user || typeof payload.user !== 'object') {
267
- return Promise.reject(new Error('Missing argument: "user"'));
268
- }
269
- return __callWithAutoInit('setMultiAccountUserAttributes', [payload], success, error);
270
- },
271
-
272
- getInitialNotification: function (arg0, success, error) {
273
- // Allowed before init (used on cold start).
274
- return __callWithExec('getInitialNotification', [arg0], success, error);
275
- },
276
-
277
- setOnRetenoPushReceivedListener: function (arg0, arg1) {
278
- // Back-compat:
279
- // - setOnRetenoPushReceivedListener(listener)
280
- // - setOnRetenoPushReceivedListener(reteno, listener) (legacy)
281
- const listener = typeof arg0 === 'function' ? arg0 : arg1;
282
- if (typeof listener !== 'function') return;
283
- document.addEventListener('reteno-push-received', listener);
284
- },
285
-
286
- setOnRetenoNotificationClickedListener: function (arg0, arg1) {
287
- // Back-compat:
288
- // - setOnRetenoNotificationClickedListener(listener)
289
- // - setOnRetenoNotificationClickedListener(reteno, listener) (legacy)
290
- const listener = typeof arg0 === 'function' ? arg0 : arg1;
291
- if (typeof listener !== 'function') return;
292
- document.addEventListener('reteno-notification-clicked', listener);
293
- },
294
-
295
- removeOnRetenoPushReceivedListener: function (listener) {
296
- if (typeof listener !== 'function') return;
297
- document.removeEventListener('reteno-push-received', listener);
298
- },
299
-
300
- removeOnRetenoNotificationClickedListener: function (listener) {
301
- if (typeof listener !== 'function') return;
302
- document.removeEventListener('reteno-notification-clicked', listener);
303
- },
304
-
305
- setOnInAppMessageCustomDataReceivedListener: function (arg0, arg1) {
306
- // Back-compat:
307
- // - setOnInAppMessageCustomDataReceivedListener(listener)
308
- // - setOnInAppMessageCustomDataReceivedListener(reteno, listener) (legacy)
309
- const listener = typeof arg0 === 'function' ? arg0 : arg1;
310
- if (typeof listener !== 'function') return;
311
- document.addEventListener('reteno-in-app-custom-data', listener);
312
- },
313
-
314
- removeOnInAppMessageCustomDataReceivedListener: function (arg0, arg1) {
315
- const listener = typeof arg0 === 'function' ? arg0 : arg1;
316
- if (typeof listener !== 'function') return;
317
- document.removeEventListener('reteno-in-app-custom-data', listener);
318
- },
319
-
320
- // Push notification dismissed (swiped away)
321
- setOnRetenoPushDismissedListener: function (arg0, arg1) {
322
- const listener = typeof arg0 === 'function' ? arg0 : arg1;
323
- if (typeof listener !== 'function') return;
324
- document.addEventListener('reteno-push-dismissed', listener);
325
- },
326
-
327
- removeOnRetenoPushDismissedListener: function (listener) {
328
- if (typeof listener !== 'function') return;
329
- document.removeEventListener('reteno-push-dismissed', listener);
330
- },
331
-
332
- // Custom push notification received
333
- setOnRetenoCustomPushReceivedListener: function (arg0, arg1) {
334
- const listener = typeof arg0 === 'function' ? arg0 : arg1;
335
- if (typeof listener !== 'function') return;
336
- document.addEventListener('reteno-custom-push-received', listener);
337
- },
338
-
339
- removeOnRetenoCustomPushReceivedListener: function (listener) {
340
- if (typeof listener !== 'function') return;
341
- document.removeEventListener('reteno-custom-push-received', listener);
342
- },
343
-
344
- // Push notification action button clicked (iOS & Android)
345
- setOnRetenoPushButtonClickedListener: function (arg0, arg1) {
346
- const listener = typeof arg0 === 'function' ? arg0 : arg1;
347
- if (typeof listener !== 'function') return;
348
- document.addEventListener('reteno-push-button-clicked', listener);
349
- },
350
-
351
- removeOnRetenoPushButtonClickedListener: function (listener) {
352
- if (typeof listener !== 'function') return;
353
- document.removeEventListener('reteno-push-button-clicked', listener);
354
- },
355
-
356
- /*
257
+ setMultiAccountUserAttributes: function (arg0, success, error) {
258
+ // Accept either `payload` or legacy `[payload]`.
259
+ const payload = Array.isArray(arg0) ? arg0[0] : arg0;
260
+ if (
261
+ !payload ||
262
+ !payload.externalUserId ||
263
+ (payload.externalUserId && payload.externalUserId.length === 0)
264
+ ) {
265
+ return Promise.reject(new Error('Missing argument: "externalUserId"'));
266
+ }
267
+ if (!payload.user || typeof payload.user !== 'object') {
268
+ return Promise.reject(new Error('Missing argument: "user"'));
269
+ }
270
+ return __callWithAutoInit('setMultiAccountUserAttributes', [payload], success, error);
271
+ },
272
+
273
+ getInitialNotification: function (arg0, success, error) {
274
+ // Allowed before init (used on cold start).
275
+ return __callWithExec('getInitialNotification', [arg0], success, error);
276
+ },
277
+
278
+ setOnRetenoPushReceivedListener: function (arg0, arg1) {
279
+ // Back-compat:
280
+ // - setOnRetenoPushReceivedListener(listener)
281
+ // - setOnRetenoPushReceivedListener(reteno, listener) (legacy)
282
+ const listener = typeof arg0 === 'function' ? arg0 : arg1;
283
+ if (typeof listener !== 'function') return;
284
+ document.addEventListener('reteno-push-received', listener);
285
+ },
286
+
287
+ setOnRetenoNotificationClickedListener: function (arg0, arg1) {
288
+ // Back-compat:
289
+ // - setOnRetenoNotificationClickedListener(listener)
290
+ // - setOnRetenoNotificationClickedListener(reteno, listener) (legacy)
291
+ const listener = typeof arg0 === 'function' ? arg0 : arg1;
292
+ if (typeof listener !== 'function') return;
293
+ document.addEventListener('reteno-notification-clicked', listener);
294
+ },
295
+
296
+ removeOnRetenoPushReceivedListener: function (listener) {
297
+ if (typeof listener !== 'function') return;
298
+ document.removeEventListener('reteno-push-received', listener);
299
+ },
300
+
301
+ removeOnRetenoNotificationClickedListener: function (listener) {
302
+ if (typeof listener !== 'function') return;
303
+ document.removeEventListener('reteno-notification-clicked', listener);
304
+ },
305
+
306
+ setOnInAppMessageCustomDataReceivedListener: function (arg0, arg1) {
307
+ // Back-compat:
308
+ // - setOnInAppMessageCustomDataReceivedListener(listener)
309
+ // - setOnInAppMessageCustomDataReceivedListener(reteno, listener) (legacy)
310
+ const listener = typeof arg0 === 'function' ? arg0 : arg1;
311
+ if (typeof listener !== 'function') return;
312
+ document.addEventListener('reteno-in-app-custom-data', listener);
313
+ },
314
+
315
+ removeOnInAppMessageCustomDataReceivedListener: function (arg0, arg1) {
316
+ const listener = typeof arg0 === 'function' ? arg0 : arg1;
317
+ if (typeof listener !== 'function') return;
318
+ document.removeEventListener('reteno-in-app-custom-data', listener);
319
+ },
320
+
321
+ // Push notification dismissed (swiped away)
322
+ setOnRetenoPushDismissedListener: function (arg0, arg1) {
323
+ const listener = typeof arg0 === 'function' ? arg0 : arg1;
324
+ if (typeof listener !== 'function') return;
325
+ document.addEventListener('reteno-push-dismissed', listener);
326
+ },
327
+
328
+ removeOnRetenoPushDismissedListener: function (listener) {
329
+ if (typeof listener !== 'function') return;
330
+ document.removeEventListener('reteno-push-dismissed', listener);
331
+ },
332
+
333
+ // Custom push notification received
334
+ setOnRetenoCustomPushReceivedListener: function (arg0, arg1) {
335
+ const listener = typeof arg0 === 'function' ? arg0 : arg1;
336
+ if (typeof listener !== 'function') return;
337
+ document.addEventListener('reteno-custom-push-received', listener);
338
+ },
339
+
340
+ removeOnRetenoCustomPushReceivedListener: function (listener) {
341
+ if (typeof listener !== 'function') return;
342
+ document.removeEventListener('reteno-custom-push-received', listener);
343
+ },
344
+
345
+ // Push notification action button clicked (iOS & Android)
346
+ setOnRetenoPushButtonClickedListener: function (arg0, arg1) {
347
+ const listener = typeof arg0 === 'function' ? arg0 : arg1;
348
+ if (typeof listener !== 'function') return;
349
+ document.addEventListener('reteno-push-button-clicked', listener);
350
+ },
351
+
352
+ removeOnRetenoPushButtonClickedListener: function (listener) {
353
+ if (typeof listener !== 'function') return;
354
+ document.removeEventListener('reteno-push-button-clicked', listener);
355
+ },
356
+
357
+ /*
357
358
  payload: boolean | { enabled?: boolean, emitEvent?: boolean }
358
359
  iOS: the native handler is installed when both `enabled` (default: true)
359
360
  and `emitEvent` are true. So both { enabled: true, emitEvent: true }
@@ -364,159 +365,205 @@ const RetenoPluginFunctions = {
364
365
  Android: no-op — action button clicks are automatically detected
365
366
  from the notification-clicked bundle.
366
367
  */
367
- setNotificationActionHandler: function (arg0, success, error) {
368
- return __callWithExec('setNotificationActionHandler', [arg0], success, error);
369
- },
370
-
371
- setOnInAppLifecycleCallback: function (arg0, arg1) {
372
- const listener = typeof arg0 === 'function' ? arg0 : arg1;
373
- if (arg0 === null || listener === null) {
374
- return __callWithAutoInit('setInAppLifecycleCallback', [null]);
375
- }
376
- if (typeof listener !== 'function') {
377
- return Promise.reject(new Error('setOnInAppLifecycleCallback: expected a function or null'));
378
- }
379
- document.addEventListener('reteno-in-app-lifecycle', listener);
380
- return __callWithAutoInit('setInAppLifecycleCallback', []);
381
- },
382
-
383
- /*
368
+ setNotificationActionHandler: function (arg0, success, error) {
369
+ return __callWithExec('setNotificationActionHandler', [arg0], success, error);
370
+ },
371
+
372
+ setOnInAppLifecycleCallback: function (arg0, arg1) {
373
+ const listener = typeof arg0 === 'function' ? arg0 : arg1;
374
+ if (arg0 === null || listener === null) {
375
+ return __callWithAutoInit('setInAppLifecycleCallback', [null]);
376
+ }
377
+ if (typeof listener !== 'function') {
378
+ return Promise.reject(new Error('setOnInAppLifecycleCallback: expected a function or null'));
379
+ }
380
+ document.addEventListener('reteno-in-app-lifecycle', listener);
381
+ return __callWithAutoInit('setInAppLifecycleCallback', []);
382
+ },
383
+
384
+ /*
384
385
  deviceToken: string
385
386
  */
386
- setDeviceToken: function (arg0, success, error) {
387
- return __callWithAutoInit('setDeviceToken', [arg0], success, error);
388
- },
387
+ setDeviceToken: function (arg0, success, error) {
388
+ return __callWithAutoInit('setDeviceToken', [arg0], success, error);
389
+ },
389
390
 
390
- /*
391
+ /*
391
392
  options: LifecycleTrackingOptions
392
393
  */
393
- setLifecycleTrackingOptions: function (arg0, success, error) {
394
- // Accept either `options` or legacy `[options]`.
395
- const options = Array.isArray(arg0) ? arg0[0] : arg0;
396
- if (!options) {
397
- return Promise.reject(new Error('Missing argument: options'));
394
+ setLifecycleTrackingOptions: function (arg0, success, error) {
395
+ // Accept either `options` or legacy `[options]`.
396
+ const options = Array.isArray(arg0) ? arg0[0] : arg0;
397
+ if (!options) {
398
+ return Promise.reject(new Error('Missing argument: options'));
399
+ }
400
+
401
+ if (__isIosPlatform()) {
402
+ let p;
403
+ if (__retenoState.initialized || __retenoState.initPromise) {
404
+ p = Promise.reject(
405
+ new Error(
406
+ 'iOS supports lifecycleTrackingOptions only during init(...) before SDK initialization.'
407
+ )
408
+ );
409
+ } else {
410
+ __retenoState.pendingInitOptions = Object.assign({}, __retenoState.pendingInitOptions, {
411
+ lifecycleTrackingOptions: options,
412
+ });
413
+ p = Promise.resolve(1);
398
414
  }
399
415
 
400
- if (__isIosPlatform()) {
401
- let p;
402
- if (__retenoState.initialized || __retenoState.initPromise) {
403
- p = Promise.reject(
404
- new Error('iOS supports lifecycleTrackingOptions only during init(...) before SDK initialization.')
405
- );
406
- } else {
407
- __retenoState.pendingInitOptions = Object.assign({}, __retenoState.pendingInitOptions, {
408
- lifecycleTrackingOptions: options,
409
- });
410
- p = Promise.resolve(1);
411
- }
412
-
413
- if (__isFn(success) || __isFn(error)) {
414
- p.then(function (res) {
415
- if (__isFn(success)) success(res);
416
- return res;
417
- }).catch(function (err) {
418
- if (__isFn(error)) error(err);
419
- throw err;
420
- });
421
- }
422
- return p;
416
+ if (__isFn(success) || __isFn(error)) {
417
+ p.then(function (res) {
418
+ if (__isFn(success)) success(res);
419
+ return res;
420
+ }).catch(function (err) {
421
+ if (__isFn(error)) error(err);
422
+ throw err;
423
+ });
423
424
  }
425
+ return p;
426
+ }
424
427
 
425
- return __callWithAutoInit('setLifecycleTrackingOptions', [options], success, error);
426
- },
428
+ return __callWithAutoInit('setLifecycleTrackingOptions', [options], success, error);
429
+ },
427
430
 
428
- /*
431
+ /*
429
432
  screenName: string
430
433
  */
431
- logScreenView: function (arg0, success, error) {
432
- if (!arg0) {
433
- return Promise.reject(new Error('Missing argument: screenName'));
434
- }
435
- return __callWithAutoInit('logScreenView', [arg0], success, error);
436
- },
437
-
438
- forcePushData: function (success, error) {
439
- if (__isIosPlatform()) {
440
- return __callWithAutoInit(
441
- 'logEvent',
442
- [
443
- {
444
- eventName: '__cordova_force_push_data__',
445
- parameters: [],
446
- forcePush: true,
447
- },
448
- ],
449
- success,
450
- error
451
- );
452
- }
453
- return __callWithAutoInit('forcePushData', [], success, error);
454
- },
455
-
456
- /*
434
+ logScreenView: function (arg0, success, error) {
435
+ if (!arg0) {
436
+ return Promise.reject(new Error('Missing argument: screenName'));
437
+ }
438
+ return __callWithAutoInit('logScreenView', [arg0], success, error);
439
+ },
440
+
441
+ forcePushData: function (success, error) {
442
+ if (__isIosPlatform()) {
443
+ return __callWithAutoInit(
444
+ 'logEvent',
445
+ [
446
+ {
447
+ eventName: '__cordova_force_push_data__',
448
+ parameters: [],
449
+ forcePush: true,
450
+ },
451
+ ],
452
+ success,
453
+ error
454
+ );
455
+ }
456
+ return __callWithAutoInit('forcePushData', [], success, error);
457
+ },
458
+
459
+ /*
457
460
  isPaused: boolean
458
461
  */
459
- pauseInAppMessages: function (arg0, success, error) {
460
- const isPaused = !!arg0;
461
- return __callWithAutoInit('pauseInAppMessages', [isPaused], success, error);
462
- },
462
+ pauseInAppMessages: function (arg0, success, error) {
463
+ const isPaused = !!arg0;
464
+ return __callWithAutoInit('pauseInAppMessages', [isPaused], success, error);
465
+ },
463
466
 
464
- /*
467
+ /*
465
468
  behaviour: 'SKIP_IN_APPS' | 'POSTPONE_IN_APPS'
466
469
  */
467
- setInAppMessagesPauseBehaviour: function (arg0, success, error) {
468
- if (!arg0 || typeof arg0 !== 'string') {
469
- return Promise.reject(new Error("Missing argument: behaviour ('SKIP_IN_APPS' or 'POSTPONE_IN_APPS')"));
470
- }
471
- return __callWithAutoInit('setInAppMessagesPauseBehaviour', [arg0], success, error);
472
- },
473
-
474
- requestNotificationPermission: function (success, error) {
475
- return __callWithAutoInit('requestNotificationPermission', [], success, error);
476
- },
477
-
478
- /*
470
+ setInAppMessagesPauseBehaviour: function (arg0, success, error) {
471
+ if (!arg0 || typeof arg0 !== 'string') {
472
+ return Promise.reject(
473
+ new Error("Missing argument: behaviour ('SKIP_IN_APPS' or 'POSTPONE_IN_APPS')")
474
+ );
475
+ }
476
+ return __callWithAutoInit('setInAppMessagesPauseBehaviour', [arg0], success, error);
477
+ },
478
+
479
+ requestNotificationPermission: function (success, error) {
480
+ return __callWithAutoInit('requestNotificationPermission', [], success, error);
481
+ },
482
+
483
+ /*
479
484
  options: string[] | { options?: string[], presentationOptions?: string[], emitEvent?: boolean }
480
485
  Passing null removes the handler.
481
486
  Supported options: "badge", "sound", "alert", "banner", "list"
482
487
  If emitEvent is true, the plugin will emit "reteno-push-received".
483
488
  */
484
- setWillPresentNotificationOptions: function (arg0, success, error) {
485
- return __callWithExec('setWillPresentNotificationOptions', [arg0], success, error);
486
- },
489
+ setWillPresentNotificationOptions: function (arg0, success, error) {
490
+ return __callWithExec('setWillPresentNotificationOptions', [arg0], success, error);
491
+ },
487
492
 
488
- /*
493
+ /*
489
494
  payload: boolean | { enabled?: boolean, emitEvent?: boolean }
490
495
  If emitEvent is true, the plugin will emit "reteno-notification-clicked".
491
496
  Passing false or null removes the handler.
492
497
  */
493
- setDidReceiveNotificationResponseHandler: function (arg0, success, error) {
494
- return __callWithExec('setDidReceiveNotificationResponseHandler', [arg0], success, error);
495
- },
498
+ setDidReceiveNotificationResponseHandler: function (arg0, success, error) {
499
+ return __callWithExec('setDidReceiveNotificationResponseHandler', [arg0], success, error);
500
+ },
496
501
 
497
- /*
502
+ /*
498
503
  config: NotificationChannelConfig
499
504
  {
500
505
  name: string,
501
506
  description: string
502
507
  }
503
508
  */
504
- updateDefaultNotificationChannel: function (arg0, success, error) {
505
- // Accept either `config` or legacy `[config]`.
506
- const config = Array.isArray(arg0) ? arg0[0] : arg0;
507
- if (!config || typeof config !== 'object') {
508
- return Promise.reject(new Error('Missing argument: config'));
509
- }
510
- if (!config.name || typeof config.name !== 'string' || config.name.trim().length === 0) {
511
- return Promise.reject(new Error('Missing argument: name'));
512
- }
513
- if (!config.description || typeof config.description !== 'string' || config.description.trim().length === 0) {
514
- return Promise.reject(new Error('Missing argument: description'));
515
- }
516
- return __callWithAutoInit('updateDefaultNotificationChannel', [config], success, error);
517
- },
518
-
519
- /*
509
+ updateDefaultNotificationChannel: function (arg0, success, error) {
510
+ // Accept either `config` or legacy `[config]`.
511
+ const config = Array.isArray(arg0) ? arg0[0] : arg0;
512
+ if (!config || typeof config !== 'object') {
513
+ return Promise.reject(new Error('Missing argument: config'));
514
+ }
515
+ if (!config.name || typeof config.name !== 'string' || config.name.trim().length === 0) {
516
+ return Promise.reject(new Error('Missing argument: name'));
517
+ }
518
+ if (
519
+ !config.description ||
520
+ typeof config.description !== 'string' ||
521
+ config.description.trim().length === 0
522
+ ) {
523
+ return Promise.reject(new Error('Missing argument: description'));
524
+ }
525
+ return __callWithAutoInit('updateDefaultNotificationChannel', [config], success, error);
526
+ },
527
+
528
+ /*
529
+ config: NotificationGroupingRule | null
530
+ { payloadKey: string } groups by a value from the push payload.
531
+ { groupId: string } assigns every Reteno notification to a constant group.
532
+ Set showSummary: true to let the plugin maintain a group-summary notification.
533
+ Passing null disables grouping.
534
+ Android only.
535
+ */
536
+ setNotificationGroupingRule: function (arg0, success, error) {
537
+ // Accept either `config` or legacy `[config]`.
538
+ const config = Array.isArray(arg0) ? arg0[0] : arg0;
539
+ if (config === null) {
540
+ return __callWithExec('setNotificationGroupingRule', [null], success, error);
541
+ }
542
+ if (!config || typeof config !== 'object') {
543
+ return Promise.reject(
544
+ new Error('Invalid argument: expected null or an object with payloadKey or groupId')
545
+ );
546
+ }
547
+
548
+ const payloadKey = typeof config.payloadKey === 'string' ? config.payloadKey.trim() : '';
549
+ const groupId = typeof config.groupId === 'string' ? config.groupId.trim() : '';
550
+ if (config.showSummary !== undefined && typeof config.showSummary !== 'boolean') {
551
+ return Promise.reject(new Error('Invalid argument: showSummary must be a boolean'));
552
+ }
553
+ if (!!payloadKey === !!groupId) {
554
+ return Promise.reject(
555
+ new Error('Invalid argument: provide exactly one of payloadKey or groupId')
556
+ );
557
+ }
558
+
559
+ const normalizedConfig = payloadKey ? { payloadKey } : { groupId };
560
+ if (config.showSummary === true) {
561
+ normalizedConfig.showSummary = true;
562
+ }
563
+ return __callWithExec('setNotificationGroupingRule', [normalizedConfig], success, error);
564
+ },
565
+
566
+ /*
520
567
  payload: GetAppInboxMessagesPayload
521
568
  {
522
569
  page: number,
@@ -524,94 +571,94 @@ const RetenoPluginFunctions = {
524
571
  status?: 'OPENED' | 'UNOPENED'
525
572
  }
526
573
  */
527
- getAppInboxMessages: function (arg0, success, error) {
528
- // Accept either `payload` or legacy `[payload]`.
529
- const payload = Array.isArray(arg0) ? arg0[0] : arg0;
530
- if (!payload || typeof payload !== 'object') {
531
- return Promise.reject(new Error('Missing argument: payload'));
532
- }
533
- if (payload.page == null) {
534
- return Promise.reject(new Error('Missing argument: page'));
535
- }
536
- if (payload.pageSize == null) {
537
- return Promise.reject(new Error('Missing argument: pageSize'));
538
- }
539
- return __callWithAutoInit('getAppInboxMessages', [payload], success, error);
540
- },
541
-
542
- getAppInboxMessagesCount: function (success, error) {
543
- return __callWithAutoInit('getAppInboxMessagesCount', [], success, error);
544
- },
545
-
546
- subscribeOnMessagesCountChanged: function (arg0, arg1) {
547
- const success = typeof arg0 === 'function' ? arg0 : arg1;
548
- const error = typeof arg0 === 'function' ? arg1 : undefined;
549
- return __ensureInit().then(function () {
550
- exec(success, error, PLUGIN_NAME, 'subscribeOnMessagesCountChanged', []);
551
- return 1;
552
- });
553
- },
574
+ getAppInboxMessages: function (arg0, success, error) {
575
+ // Accept either `payload` or legacy `[payload]`.
576
+ const payload = Array.isArray(arg0) ? arg0[0] : arg0;
577
+ if (!payload || typeof payload !== 'object') {
578
+ return Promise.reject(new Error('Missing argument: payload'));
579
+ }
580
+ if (payload.page == null) {
581
+ return Promise.reject(new Error('Missing argument: page'));
582
+ }
583
+ if (payload.pageSize == null) {
584
+ return Promise.reject(new Error('Missing argument: pageSize'));
585
+ }
586
+ return __callWithAutoInit('getAppInboxMessages', [payload], success, error);
587
+ },
588
+
589
+ getAppInboxMessagesCount: function (success, error) {
590
+ return __callWithAutoInit('getAppInboxMessagesCount', [], success, error);
591
+ },
592
+
593
+ subscribeOnMessagesCountChanged: function (arg0, arg1) {
594
+ const success = typeof arg0 === 'function' ? arg0 : arg1;
595
+ const error = typeof arg0 === 'function' ? arg1 : undefined;
596
+ return __ensureInit().then(function () {
597
+ exec(success, error, PLUGIN_NAME, 'subscribeOnMessagesCountChanged', []);
598
+ return 1;
599
+ });
600
+ },
554
601
 
555
- unsubscribeMessagesCountChanged: function (success, error) {
556
- return __callWithAutoInit('unsubscribeMessagesCountChanged', [], success, error);
557
- },
602
+ unsubscribeMessagesCountChanged: function (success, error) {
603
+ return __callWithAutoInit('unsubscribeMessagesCountChanged', [], success, error);
604
+ },
558
605
 
559
- /*
606
+ /*
560
607
  messageId: string
561
608
  */
562
- markAsOpened: function (arg0, success, error) {
563
- // Accept either `messageId` or legacy `[messageId]`.
564
- const messageId = Array.isArray(arg0) ? arg0[0] : arg0;
565
- if (!messageId || typeof messageId !== 'string' || messageId.trim().length === 0) {
566
- return Promise.reject(new Error('Missing argument: messageId'));
567
- }
568
- return __callWithAutoInit('markAsOpened', [messageId], success, error);
569
- },
570
-
571
- markAllMessagesAsOpened: function (success, error) {
572
- return __callWithAutoInit('markAllMessagesAsOpened', [], success, error);
573
- },
574
-
575
- /*
609
+ markAsOpened: function (arg0, success, error) {
610
+ // Accept either `messageId` or legacy `[messageId]`.
611
+ const messageId = Array.isArray(arg0) ? arg0[0] : arg0;
612
+ if (!messageId || typeof messageId !== 'string' || messageId.trim().length === 0) {
613
+ return Promise.reject(new Error('Missing argument: messageId'));
614
+ }
615
+ return __callWithAutoInit('markAsOpened', [messageId], success, error);
616
+ },
617
+
618
+ markAllMessagesAsOpened: function (success, error) {
619
+ return __callWithAutoInit('markAllMessagesAsOpened', [], success, error);
620
+ },
621
+
622
+ /*
576
623
  payload: GetRecommendationsPayload
577
624
  */
578
- getRecommendations: function (arg0, success, error) {
579
- // Accept either `payload` or legacy `[payload]`.
580
- const payload = Array.isArray(arg0) ? arg0[0] : arg0;
581
- if (!payload || typeof payload !== 'object') {
582
- return Promise.reject(new Error('Missing argument: payload'));
583
- }
584
- if (
585
- !payload.recomVariantId ||
586
- typeof payload.recomVariantId !== 'string' ||
587
- payload.recomVariantId.trim().length === 0
588
- ) {
589
- return Promise.reject(new Error('Missing argument: recomVariantId'));
590
- }
591
- return __callWithAutoInit('getRecommendations', [payload], success, error);
592
- },
593
-
594
- /*
625
+ getRecommendations: function (arg0, success, error) {
626
+ // Accept either `payload` or legacy `[payload]`.
627
+ const payload = Array.isArray(arg0) ? arg0[0] : arg0;
628
+ if (!payload || typeof payload !== 'object') {
629
+ return Promise.reject(new Error('Missing argument: payload'));
630
+ }
631
+ if (
632
+ !payload.recomVariantId ||
633
+ typeof payload.recomVariantId !== 'string' ||
634
+ payload.recomVariantId.trim().length === 0
635
+ ) {
636
+ return Promise.reject(new Error('Missing argument: recomVariantId'));
637
+ }
638
+ return __callWithAutoInit('getRecommendations', [payload], success, error);
639
+ },
640
+
641
+ /*
595
642
  payload: LogRecommendationsPayload
596
643
  */
597
- logRecommendations: function (arg0, success, error) {
598
- // Accept either `payload` or legacy `[payload]`.
599
- const payload = Array.isArray(arg0) ? arg0[0] : arg0;
600
- if (!payload || typeof payload !== 'object') {
601
- return Promise.reject(new Error('Missing argument: payload'));
602
- }
603
- if (
604
- !payload.recomVariantId ||
605
- typeof payload.recomVariantId !== 'string' ||
606
- payload.recomVariantId.trim().length === 0
607
- ) {
608
- return Promise.reject(new Error('Missing argument: recomVariantId'));
609
- }
610
- if (!Array.isArray(payload.recomEvents) || payload.recomEvents.length === 0) {
611
- return Promise.reject(new Error('Missing argument: recomEvents'));
612
- }
613
- return __callWithAutoInit('logRecommendations', [payload], success, error);
614
- },
615
- };
644
+ logRecommendations: function (arg0, success, error) {
645
+ // Accept either `payload` or legacy `[payload]`.
646
+ const payload = Array.isArray(arg0) ? arg0[0] : arg0;
647
+ if (!payload || typeof payload !== 'object') {
648
+ return Promise.reject(new Error('Missing argument: payload'));
649
+ }
650
+ if (
651
+ !payload.recomVariantId ||
652
+ typeof payload.recomVariantId !== 'string' ||
653
+ payload.recomVariantId.trim().length === 0
654
+ ) {
655
+ return Promise.reject(new Error('Missing argument: recomVariantId'));
656
+ }
657
+ if (!Array.isArray(payload.recomEvents) || payload.recomEvents.length === 0) {
658
+ return Promise.reject(new Error('Missing argument: recomEvents'));
659
+ }
660
+ return __callWithAutoInit('logRecommendations', [payload], success, error);
661
+ },
662
+ };
616
663
 
617
664
  module.exports = RetenoPluginFunctions;