@dubsdotapp/expo 0.2.65 → 0.2.67
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/app.plugin.js +53 -38
- package/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +12 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +0 -3
- package/src/hooks/usePushNotifications.ts +18 -17
package/app.plugin.js
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {
|
|
2
|
+
withDangerousMod,
|
|
3
|
+
withProjectBuildGradle,
|
|
4
|
+
withAppBuildGradle,
|
|
5
|
+
} = require('@expo/config-plugins');
|
|
2
6
|
const fs = require('fs');
|
|
3
7
|
const path = require('path');
|
|
4
8
|
|
|
9
|
+
const GMS_CLASSPATH =
|
|
10
|
+
"classpath('com.google.gms:google-services:4.4.2')";
|
|
11
|
+
const GMS_PLUGIN = 'apply plugin: "com.google.gms.google-services"';
|
|
12
|
+
|
|
5
13
|
/**
|
|
6
14
|
* @dubsdotapp/expo Expo config plugin.
|
|
7
15
|
*
|
|
8
|
-
* Generates
|
|
9
|
-
*
|
|
10
|
-
* to initialise automatically at runtime — no manual Firebase setup required.
|
|
16
|
+
* 1. Generates google-services.json (Dubs Firebase project + app's package name)
|
|
17
|
+
* 2. Adds the Google Services Gradle classpath + plugin so Firebase initialises
|
|
11
18
|
*
|
|
12
19
|
* Usage in app.json:
|
|
13
20
|
* ["@dubsdotapp/expo"]
|
|
14
21
|
*/
|
|
15
22
|
function withDubsNotifications(config) {
|
|
16
|
-
|
|
23
|
+
// Step 1 — write google-services.json
|
|
24
|
+
config = withDangerousMod(config, [
|
|
17
25
|
'android',
|
|
18
26
|
async (cfg) => {
|
|
19
27
|
const packageName = cfg.android?.package;
|
|
@@ -23,6 +31,15 @@ function withDubsNotifications(config) {
|
|
|
23
31
|
);
|
|
24
32
|
}
|
|
25
33
|
|
|
34
|
+
const projectRoot = cfg.modRequest.projectRoot;
|
|
35
|
+
const filePath = path.join(projectRoot, 'android', 'app', 'google-services.json');
|
|
36
|
+
|
|
37
|
+
// Skip if developer already has their own Firebase config
|
|
38
|
+
const rootGoogleServices = path.join(projectRoot, 'google-services.json');
|
|
39
|
+
if (fs.existsSync(filePath) || fs.existsSync(rootGoogleServices)) {
|
|
40
|
+
return cfg;
|
|
41
|
+
}
|
|
42
|
+
|
|
26
43
|
const googleServices = {
|
|
27
44
|
project_info: {
|
|
28
45
|
project_number: '161838368570',
|
|
@@ -33,52 +50,50 @@ function withDubsNotifications(config) {
|
|
|
33
50
|
{
|
|
34
51
|
client_info: {
|
|
35
52
|
mobilesdk_app_id: '1:161838368570:android:5d77e05a49f7efc64b7203',
|
|
36
|
-
android_client_info: {
|
|
37
|
-
package_name: packageName,
|
|
38
|
-
},
|
|
53
|
+
android_client_info: { package_name: packageName },
|
|
39
54
|
},
|
|
40
55
|
oauth_client: [],
|
|
41
|
-
api_key: [
|
|
42
|
-
|
|
43
|
-
current_key: 'AIzaSyCtJKF-o1cZ3Y89oM5FlXIGsjFchETzzkM',
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
services: {
|
|
47
|
-
appinvite_service: {
|
|
48
|
-
other_platform_oauth_client: [],
|
|
49
|
-
},
|
|
50
|
-
},
|
|
56
|
+
api_key: [{ current_key: 'AIzaSyCtJKF-o1cZ3Y89oM5FlXIGsjFchETzzkM' }],
|
|
57
|
+
services: { appinvite_service: { other_platform_oauth_client: [] } },
|
|
51
58
|
},
|
|
52
59
|
],
|
|
53
60
|
configuration_version: '1',
|
|
54
61
|
};
|
|
55
62
|
|
|
56
|
-
const projectRoot = cfg.modRequest.projectRoot;
|
|
57
|
-
const filePath = path.join(
|
|
58
|
-
projectRoot,
|
|
59
|
-
'android',
|
|
60
|
-
'app',
|
|
61
|
-
'google-services.json',
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
// If the developer already has their own google-services.json, leave it alone.
|
|
65
|
-
// Their existing Firebase project will handle FCM just fine.
|
|
66
|
-
if (fs.existsSync(filePath)) {
|
|
67
|
-
return cfg;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Also check the project root (some devs place it there for app.json googleServicesFile)
|
|
71
|
-
const rootGoogleServices = path.join(projectRoot, 'google-services.json');
|
|
72
|
-
if (fs.existsSync(rootGoogleServices)) {
|
|
73
|
-
return cfg;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
63
|
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
77
64
|
fs.writeFileSync(filePath, JSON.stringify(googleServices, null, 2));
|
|
78
65
|
|
|
79
66
|
return cfg;
|
|
80
67
|
},
|
|
81
68
|
]);
|
|
69
|
+
|
|
70
|
+
// Step 2 — add Google Services classpath to project-level build.gradle
|
|
71
|
+
config = withProjectBuildGradle(config, (cfg) => {
|
|
72
|
+
if (cfg.modResults.contents.includes('com.google.gms:google-services')) {
|
|
73
|
+
return cfg;
|
|
74
|
+
}
|
|
75
|
+
// Insert after the last existing classpath line
|
|
76
|
+
cfg.modResults.contents = cfg.modResults.contents.replace(
|
|
77
|
+
/(classpath\(['"]org\.jetbrains\.kotlin:kotlin-gradle-plugin[^)]*\))/,
|
|
78
|
+
`$1\n ${GMS_CLASSPATH}`,
|
|
79
|
+
);
|
|
80
|
+
return cfg;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Step 3 — apply plugin in app-level build.gradle
|
|
84
|
+
config = withAppBuildGradle(config, (cfg) => {
|
|
85
|
+
if (cfg.modResults.contents.includes('com.google.gms.google-services')) {
|
|
86
|
+
return cfg;
|
|
87
|
+
}
|
|
88
|
+
// Add at the top, after the existing apply plugin lines
|
|
89
|
+
cfg.modResults.contents = cfg.modResults.contents.replace(
|
|
90
|
+
/(apply plugin: "com\.facebook\.react")/,
|
|
91
|
+
`$1\n${GMS_PLUGIN}`,
|
|
92
|
+
);
|
|
93
|
+
return cfg;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
return config;
|
|
82
97
|
}
|
|
83
98
|
|
|
84
99
|
module.exports = withDubsNotifications;
|
package/dist/index.d.mts
CHANGED
|
@@ -902,7 +902,11 @@ interface PushNotificationStatus {
|
|
|
902
902
|
enabled: boolean;
|
|
903
903
|
/** Whether notification permission has been granted */
|
|
904
904
|
hasPermission: boolean;
|
|
905
|
-
/** The
|
|
905
|
+
/** The push token (native FCM/APNs), if registered */
|
|
906
|
+
pushToken: string | null;
|
|
907
|
+
/**
|
|
908
|
+
* @deprecated Use pushToken instead. Kept for backwards compatibility.
|
|
909
|
+
*/
|
|
906
910
|
expoPushToken: string | null;
|
|
907
911
|
/** Whether a registration operation is in progress */
|
|
908
912
|
loading: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -902,7 +902,11 @@ interface PushNotificationStatus {
|
|
|
902
902
|
enabled: boolean;
|
|
903
903
|
/** Whether notification permission has been granted */
|
|
904
904
|
hasPermission: boolean;
|
|
905
|
-
/** The
|
|
905
|
+
/** The push token (native FCM/APNs), if registered */
|
|
906
|
+
pushToken: string | null;
|
|
907
|
+
/**
|
|
908
|
+
* @deprecated Use pushToken instead. Kept for backwards compatibility.
|
|
909
|
+
*/
|
|
906
910
|
expoPushToken: string | null;
|
|
907
911
|
/** Whether a registration operation is in progress */
|
|
908
912
|
loading: boolean;
|
package/dist/index.js
CHANGED
|
@@ -95,7 +95,6 @@ if (typeof self === "undefined" && typeof globalThis !== "undefined") {
|
|
|
95
95
|
|
|
96
96
|
// src/constants.ts
|
|
97
97
|
var DEFAULT_BASE_URL = "https://dubs-server-prod-9c91d3f01199.herokuapp.com/api/developer/v1";
|
|
98
|
-
var DUBS_EXPO_PROJECT_ID = "aaca4fc9-64be-46b2-9be2-4175cb0f59a2";
|
|
99
98
|
var DEFAULT_RPC_URL = "https://api.mainnet-beta.solana.com";
|
|
100
99
|
var NETWORK_CONFIG = {
|
|
101
100
|
"mainnet-beta": {
|
|
@@ -2371,7 +2370,7 @@ function usePushNotifications() {
|
|
|
2371
2370
|
const { client, appName, pushEnabled } = useDubs();
|
|
2372
2371
|
const channelId = (0, import_react16.useMemo)(() => appName.toLowerCase().replace(/[^a-z0-9-]/g, ""), [appName]);
|
|
2373
2372
|
const [hasPermission, setHasPermission] = (0, import_react16.useState)(false);
|
|
2374
|
-
const [
|
|
2373
|
+
const [pushToken, setPushToken] = (0, import_react16.useState)(null);
|
|
2375
2374
|
const [loading, setLoading] = (0, import_react16.useState)(false);
|
|
2376
2375
|
const [error, setError] = (0, import_react16.useState)(null);
|
|
2377
2376
|
const registering = (0, import_react16.useRef)(false);
|
|
@@ -2432,11 +2431,9 @@ function usePushNotifications() {
|
|
|
2432
2431
|
return false;
|
|
2433
2432
|
}
|
|
2434
2433
|
setHasPermission(true);
|
|
2435
|
-
const tokenResult = await Notifications.
|
|
2436
|
-
projectId: DUBS_EXPO_PROJECT_ID
|
|
2437
|
-
});
|
|
2434
|
+
const tokenResult = await Notifications.getDevicePushTokenAsync();
|
|
2438
2435
|
const token = tokenResult.data;
|
|
2439
|
-
|
|
2436
|
+
setPushToken(token);
|
|
2440
2437
|
await registerTokenWithServer(token);
|
|
2441
2438
|
setupAndroidChannels(Notifications);
|
|
2442
2439
|
setLoading(false);
|
|
@@ -2452,14 +2449,14 @@ function usePushNotifications() {
|
|
|
2452
2449
|
}
|
|
2453
2450
|
}, [getNotificationsModule, registerTokenWithServer, setupAndroidChannels]);
|
|
2454
2451
|
const unregister = (0, import_react16.useCallback)(async () => {
|
|
2455
|
-
if (!
|
|
2452
|
+
if (!pushToken) return;
|
|
2456
2453
|
try {
|
|
2457
|
-
await client.unregisterPushToken(
|
|
2458
|
-
|
|
2454
|
+
await client.unregisterPushToken(pushToken);
|
|
2455
|
+
setPushToken(null);
|
|
2459
2456
|
} catch (err) {
|
|
2460
2457
|
console.error("[usePushNotifications] Unregister error:", err);
|
|
2461
2458
|
}
|
|
2462
|
-
}, [client,
|
|
2459
|
+
}, [client, pushToken]);
|
|
2463
2460
|
const restoreIfGranted = (0, import_react16.useCallback)(async () => {
|
|
2464
2461
|
if (!pushEnabled) return;
|
|
2465
2462
|
try {
|
|
@@ -2467,12 +2464,10 @@ function usePushNotifications() {
|
|
|
2467
2464
|
if (!Notifications) return;
|
|
2468
2465
|
const { status } = await Notifications.getPermissionsAsync();
|
|
2469
2466
|
if (status !== "granted") return;
|
|
2470
|
-
const tokenResult = await Notifications.
|
|
2471
|
-
projectId: DUBS_EXPO_PROJECT_ID
|
|
2472
|
-
});
|
|
2467
|
+
const tokenResult = await Notifications.getDevicePushTokenAsync();
|
|
2473
2468
|
const token = tokenResult.data;
|
|
2474
2469
|
await registerTokenWithServer(token);
|
|
2475
|
-
|
|
2470
|
+
setPushToken(token);
|
|
2476
2471
|
setHasPermission(true);
|
|
2477
2472
|
setupAndroidChannels(Notifications);
|
|
2478
2473
|
} catch (err) {
|
|
@@ -2489,7 +2484,9 @@ function usePushNotifications() {
|
|
|
2489
2484
|
return {
|
|
2490
2485
|
enabled: pushEnabled,
|
|
2491
2486
|
hasPermission,
|
|
2492
|
-
|
|
2487
|
+
pushToken,
|
|
2488
|
+
expoPushToken: pushToken,
|
|
2489
|
+
// backwards compat
|
|
2493
2490
|
loading,
|
|
2494
2491
|
error,
|
|
2495
2492
|
register,
|