@amrshbib/react-native-pushbib 0.1.0 → 0.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@amrshbib/react-native-pushbib",
3
- "version": "0.1.0",
4
- "description": "Self-hosted push notification SDK for React Native. Pushbib-style API (login, tags, click events) with zero Firebase setup in the app — no google-services.json, no GoogleService-Info.plist.",
3
+ "version": "0.2.0",
4
+ "description": "Self-hosted push notification SDK for React Native. Pushbib-style API (login, tags, click events) with zero Firebase setup in the app \u2014 no google-services.json, no GoogleService-Info.plist.",
5
5
  "main": "src/index.js",
6
6
  "types": "index.d.ts",
7
7
  "react-native": "src/index.js",
package/src/index.js CHANGED
@@ -41,11 +41,35 @@ function tagItems(value) {
41
41
  return [String(value)];
42
42
  }
43
43
 
44
+ // Android carries a notification's data as strings and nothing else, so a nested value —
45
+ // queries: { featureId } — arrives as the JSON text of itself, while iOS carries the real thing.
46
+ // Reading it back here is what lets an app written once see the same shape on both.
47
+ function reviveData(value) {
48
+ if (Array.isArray(value)) return value.map(reviveData);
49
+ if (value && typeof value === 'object') {
50
+ const out = {};
51
+ for (const key of Object.keys(value)) out[key] = reviveData(value[key]);
52
+ return out;
53
+ }
54
+ if (typeof value !== 'string') return value;
55
+
56
+ const text = value.trim();
57
+ const shaped = (text.startsWith('{') && text.endsWith('}'))
58
+ || (text.startsWith('[') && text.endsWith(']'));
59
+ if (!shaped) return value;
60
+ try {
61
+ return reviveData(JSON.parse(text));
62
+ } catch (err) {
63
+ // It only looked like JSON. What the sender wrote is what the app gets.
64
+ return value;
65
+ }
66
+ }
67
+
44
68
  // Notification events carry OneSignal's shape as well as Pushbib's own fields: callers can read
45
69
  // additionalData / launchURL and call getNotification() and display(), so one handler fits both SDKs.
46
70
  function buildNotification(raw, display) {
47
71
  const payload = raw || {};
48
- const data = payload.data || {};
72
+ const data = reviveData(payload.data || {});
49
73
  return {
50
74
  ...payload,
51
75
  notificationId: payload.notificationId ?? null,
package/src/version.js CHANGED
@@ -1,2 +1,2 @@
1
- export const SDK_VERSION = '0.1.0';
1
+ export const SDK_VERSION = '0.2.0';
2
2
  export const SDK_NAME = `pushbib-rn/${SDK_VERSION}`;