cordova-plugin-insider 3.1.0 → 4.0.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.
- package/jest.setup.js +17 -0
- package/package.json +7 -3
- package/plugin.xml +5 -2
- package/src/android/CDVUtils.java +113 -4
- package/src/android/InsiderPlugin.java +418 -71
- package/src/android/build-extras.gradle +1 -1
- package/src/ios/CDVUtils.h +9 -2
- package/src/ios/CDVUtils.m +81 -0
- package/src/ios/InsiderPlugin.h +9 -0
- package/src/ios/InsiderPlugin.m +458 -69
- package/types/CloseButtonPosition.d.ts +5 -0
- package/types/Event.d.ts +1 -1
- package/types/InsiderAppCard.d.ts +202 -0
- package/types/InsiderAppCards.d.ts +291 -0
- package/types/InsiderAppCardsError.d.ts +75 -0
- package/types/InsiderPlugin.d.ts +52 -21
- package/types/Product.d.ts +3 -3
- package/types/User.d.ts +2 -2
- package/www/CallbackType.js +11 -0
- package/www/CloseButtonPosition.js +7 -0
- package/www/Constants.js +127 -0
- package/www/ContentOptimizerDataType.js +6 -0
- package/www/Event.js +224 -0
- package/www/Gender.js +7 -0
- package/www/Identifier.js +96 -0
- package/www/InsiderAppCard.js +455 -0
- package/www/InsiderAppCards.js +145 -0
- package/www/InsiderAppCardsError.js +99 -0
- package/www/InsiderPlugin.js +845 -0
- package/www/Product.js +559 -0
- package/www/User.js +511 -0
- package/www/Utils.js +112 -0
- package/.git-hooks/README.md +0 -36
- package/.git-hooks/commit-msg +0 -83
- package/babel.config.json +0 -9
package/jest.setup.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Mock window.cordova for tests
|
|
2
|
+
global.window = {
|
|
3
|
+
cordova: {
|
|
4
|
+
exec: jest.fn((success, error, className, method, args) => {
|
|
5
|
+
// Default mock implementation - can be overridden in tests
|
|
6
|
+
if (success) {
|
|
7
|
+
success('mock-success');
|
|
8
|
+
}
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Mock console.warn to avoid noise in test output
|
|
14
|
+
global.console = {
|
|
15
|
+
...console,
|
|
16
|
+
warn: jest.fn()
|
|
17
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cordova-plugin-insider",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "A plugin that you can use Insider SDK with Cordova and Ionic",
|
|
5
5
|
"cordova_name": "Insider Cordova Plugin",
|
|
6
6
|
"cordova": {
|
|
@@ -11,7 +11,10 @@
|
|
|
11
11
|
]
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"build": "babel js --out-dir www --copy-files"
|
|
14
|
+
"build": "babel js --out-dir www --copy-files --ignore '**/__tests__/**'",
|
|
15
|
+
"test": "jest",
|
|
16
|
+
"test:watch": "jest --watch",
|
|
17
|
+
"test:coverage": "jest --coverage"
|
|
15
18
|
},
|
|
16
19
|
"keywords": [
|
|
17
20
|
"cordova-plugin-insider",
|
|
@@ -25,7 +28,8 @@
|
|
|
25
28
|
"devDependencies": {
|
|
26
29
|
"@babel/cli": "^7.27.2",
|
|
27
30
|
"@babel/core": "^7.27.4",
|
|
28
|
-
"@babel/preset-env": "^7.27.2"
|
|
31
|
+
"@babel/preset-env": "^7.27.2",
|
|
32
|
+
"jest": "^29.7.0"
|
|
29
33
|
},
|
|
30
34
|
"dependencies": {
|
|
31
35
|
"babel": "^6.23.0"
|
package/plugin.xml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<?xml version='1.0' encoding='utf-8'?>
|
|
2
|
-
<plugin id="cordova-plugin-insider" version="
|
|
2
|
+
<plugin id="cordova-plugin-insider" version="4.0.1" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
|
|
3
3
|
<name>Insider</name>
|
|
4
4
|
<description>Insider Cordova Plugin</description>
|
|
5
5
|
<keywords>insider,cordova,cordova-ios,cordova-android</keywords>
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
<js-module name="User" src="www/User.js" />
|
|
20
20
|
<js-module name="Constants" src="www/Constants.js" />
|
|
21
21
|
<js-module name="Utils" src="www/Utils.js" />
|
|
22
|
+
<js-module name="InsiderAppCards" src="www/InsiderAppCards.js" />
|
|
23
|
+
<js-module name="InsiderAppCard" src="www/InsiderAppCard.js" />
|
|
24
|
+
<js-module name="InsiderAppCardsError" src="www/InsiderAppCardsError.js" />
|
|
22
25
|
|
|
23
26
|
<engines>
|
|
24
27
|
<engine name="cordova" version=">=7.0.0" />
|
|
@@ -71,7 +74,7 @@
|
|
|
71
74
|
<source url="https://cdn.cocoapods.org/" />
|
|
72
75
|
</config>
|
|
73
76
|
<pods use-frameworks="true">
|
|
74
|
-
<pod name="InsiderMobile" spec="
|
|
77
|
+
<pod name="InsiderMobile" spec="15.0.0" />
|
|
75
78
|
<pod name="InsiderGeofence" spec="1.2.4" />
|
|
76
79
|
<pod name="InsiderHybrid" spec="1.7.6" />
|
|
77
80
|
</pods>
|
|
@@ -6,6 +6,8 @@ import com.useinsider.insider.InsiderProduct;
|
|
|
6
6
|
import com.useinsider.insider.InsiderEvent;
|
|
7
7
|
import com.useinsider.insiderhybrid.InsiderHybridUtils;
|
|
8
8
|
|
|
9
|
+
import com.useinsider.insider.AppCardsException;
|
|
10
|
+
|
|
9
11
|
import org.json.JSONArray;
|
|
10
12
|
import org.json.JSONException;
|
|
11
13
|
import org.json.JSONObject;
|
|
@@ -16,12 +18,13 @@ import java.util.HashMap;
|
|
|
16
18
|
import java.util.Map;
|
|
17
19
|
|
|
18
20
|
public class CDVUtils {
|
|
21
|
+
private static final ObjectMapper objectMapper = new ObjectMapper();
|
|
22
|
+
|
|
19
23
|
public static Map<String, Object> convertJSONToMap(String jsonString) {
|
|
20
24
|
Map<String, Object> convertedData = null;
|
|
21
25
|
|
|
22
26
|
try {
|
|
23
|
-
convertedData =
|
|
24
|
-
|
|
27
|
+
convertedData = objectMapper.readValue(jsonString, HashMap.class);
|
|
25
28
|
} catch (Exception e) {
|
|
26
29
|
Insider.Instance.putException(e);
|
|
27
30
|
}
|
|
@@ -33,7 +36,7 @@ public class CDVUtils {
|
|
|
33
36
|
Map<String, String> convertedData = null;
|
|
34
37
|
|
|
35
38
|
try {
|
|
36
|
-
convertedData =
|
|
39
|
+
convertedData = objectMapper.readValue(jsonString, HashMap.class);
|
|
37
40
|
} catch (Exception e) {
|
|
38
41
|
Insider.Instance.putException(e);
|
|
39
42
|
}
|
|
@@ -46,7 +49,7 @@ public class CDVUtils {
|
|
|
46
49
|
ArrayList<String> listdata = new ArrayList<String>();
|
|
47
50
|
|
|
48
51
|
try {
|
|
49
|
-
listdata =
|
|
52
|
+
listdata = objectMapper.readValue(jsonString, ArrayList.class);
|
|
50
53
|
} catch (Exception e) {
|
|
51
54
|
Insider.Instance.putException(e);
|
|
52
55
|
}
|
|
@@ -320,6 +323,40 @@ public class CDVUtils {
|
|
|
320
323
|
&& requiredFields.containsKey(Constants.CURRENCY);
|
|
321
324
|
}
|
|
322
325
|
|
|
326
|
+
public static String mapAppCardsExceptionCode(AppCardsException exception) {
|
|
327
|
+
switch (exception.getCode()) {
|
|
328
|
+
case SDK_NOT_INITIALIZED: return "sdkNotInitialized";
|
|
329
|
+
case INVALID_PARAMETER: return "invalidParameter";
|
|
330
|
+
case NETWORK_ERROR: return "networkError";
|
|
331
|
+
case SERVER_ERROR: return "serverError";
|
|
332
|
+
case PARSE_ERROR: return "parseError";
|
|
333
|
+
default: return "unknown";
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
public static JSONObject appCardsErrorToJSON(Exception error) {
|
|
338
|
+
try {
|
|
339
|
+
JSONObject json = new JSONObject();
|
|
340
|
+
if (error instanceof AppCardsException) {
|
|
341
|
+
json.put("code", mapAppCardsExceptionCode((AppCardsException) error));
|
|
342
|
+
json.put("message", error.getMessage() != null ? error.getMessage() : "An unexpected error occurred.");
|
|
343
|
+
} else {
|
|
344
|
+
json.put("code", "unknown");
|
|
345
|
+
json.put("message", error.getMessage() != null ? error.getMessage() : "An unexpected error occurred.");
|
|
346
|
+
}
|
|
347
|
+
return json;
|
|
348
|
+
} catch (JSONException e) {
|
|
349
|
+
try {
|
|
350
|
+
JSONObject fallback = new JSONObject();
|
|
351
|
+
fallback.put("code", "unknown");
|
|
352
|
+
fallback.put("message", "An unexpected error occurred.");
|
|
353
|
+
return fallback;
|
|
354
|
+
} catch (JSONException ignored) {
|
|
355
|
+
return new JSONObject();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
323
360
|
private static void setProductCustomAttribute(InsiderProduct product, String key, Object value) {
|
|
324
361
|
try {
|
|
325
362
|
if (key == null || key.length() == 0 || value == null) return;
|
|
@@ -352,4 +389,76 @@ public class CDVUtils {
|
|
|
352
389
|
Insider.Instance.putException(e);
|
|
353
390
|
}
|
|
354
391
|
}
|
|
392
|
+
|
|
393
|
+
public static Map<String, Object> parseCustomParameters(JSONArray customParameters) {
|
|
394
|
+
Map<String, Object> mappedCustomParameters = new HashMap<>();
|
|
395
|
+
|
|
396
|
+
try {
|
|
397
|
+
if (customParameters == null) {
|
|
398
|
+
return mappedCustomParameters;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
for (int i = 0; i < customParameters.length(); i++) {
|
|
402
|
+
JSONObject parameter = customParameters.getJSONObject(i);
|
|
403
|
+
if (parameter == null) continue;
|
|
404
|
+
|
|
405
|
+
String type = parameter.optString("type", null);
|
|
406
|
+
String key = parameter.optString("key", null);
|
|
407
|
+
|
|
408
|
+
if (type == null || key == null) continue;
|
|
409
|
+
|
|
410
|
+
switch (type) {
|
|
411
|
+
case "string":
|
|
412
|
+
if (parameter.has("value") && !parameter.isNull("value")) {
|
|
413
|
+
mappedCustomParameters.put(key, parameter.getString("value"));
|
|
414
|
+
}
|
|
415
|
+
break;
|
|
416
|
+
case "integer":
|
|
417
|
+
if (parameter.has("value") && !parameter.isNull("value")) {
|
|
418
|
+
mappedCustomParameters.put(key, parameter.getInt("value"));
|
|
419
|
+
}
|
|
420
|
+
break;
|
|
421
|
+
case "double":
|
|
422
|
+
if (parameter.has("value") && !parameter.isNull("value")) {
|
|
423
|
+
mappedCustomParameters.put(key, parameter.getDouble("value"));
|
|
424
|
+
}
|
|
425
|
+
break;
|
|
426
|
+
case "boolean":
|
|
427
|
+
if (parameter.has("value") && !parameter.isNull("value")) {
|
|
428
|
+
mappedCustomParameters.put(key, parameter.getBoolean("value"));
|
|
429
|
+
}
|
|
430
|
+
break;
|
|
431
|
+
case "date":
|
|
432
|
+
if (parameter.has("value") && !parameter.isNull("value")) {
|
|
433
|
+
long epochMillis = parameter.getLong("value");
|
|
434
|
+
Date dateValue = new Date(epochMillis);
|
|
435
|
+
mappedCustomParameters.put(key, dateValue);
|
|
436
|
+
}
|
|
437
|
+
break;
|
|
438
|
+
case "numeric_array":
|
|
439
|
+
if (parameter.has("value") && !parameter.isNull("value")) {
|
|
440
|
+
JSONArray arrayValue = parameter.getJSONArray("value");
|
|
441
|
+
Number[] numberArray = convertJSONArrayToNumericArray(arrayValue);
|
|
442
|
+
if (numberArray != null) {
|
|
443
|
+
mappedCustomParameters.put(key, numberArray);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
break;
|
|
447
|
+
case "string_array":
|
|
448
|
+
if (parameter.has("value") && !parameter.isNull("value")) {
|
|
449
|
+
JSONArray arrayValue = parameter.getJSONArray("value");
|
|
450
|
+
String[] stringArray = convertJSONArrayToStringArray(arrayValue);
|
|
451
|
+
if (stringArray != null) {
|
|
452
|
+
mappedCustomParameters.put(key, stringArray);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
} catch (Exception e) {
|
|
459
|
+
Insider.Instance.putException(e);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
return mappedCustomParameters;
|
|
463
|
+
}
|
|
355
464
|
}
|