@spacelr/sdk 0.5.1 → 0.6.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/dist/index.d.mts +25 -4
- package/dist/index.d.ts +25 -4
- package/dist/index.js +33 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1285,9 +1285,15 @@ declare class DatabaseModule {
|
|
|
1285
1285
|
collection<T = Record<string, unknown>>(name: string): CollectionRef<T>;
|
|
1286
1286
|
}
|
|
1287
1287
|
|
|
1288
|
+
/**
|
|
1289
|
+
* Push subscription platform. `web` = VAPID WebPush; `android`/`ios` = native
|
|
1290
|
+
* device tokens; `web-fcm` = a web Firebase Cloud Messaging registration token.
|
|
1291
|
+
* Defined locally so `@spacelr/sdk` stays a standalone, dependency-free package.
|
|
1292
|
+
*/
|
|
1293
|
+
type PushPlatform = 'web' | 'android' | 'ios' | 'web-fcm';
|
|
1288
1294
|
interface PushSubscriptionInfo {
|
|
1289
1295
|
id: string;
|
|
1290
|
-
platform:
|
|
1296
|
+
platform: PushPlatform;
|
|
1291
1297
|
endpoint?: string;
|
|
1292
1298
|
deviceToken?: string;
|
|
1293
1299
|
deviceId?: string;
|
|
@@ -1318,9 +1324,9 @@ declare class NotificationsModule {
|
|
|
1318
1324
|
private detectDeviceName;
|
|
1319
1325
|
/** Get the VAPID public key for Web Push setup */
|
|
1320
1326
|
getVapidPublicKey(): Promise<VapidKeyResponse>;
|
|
1321
|
-
/** Register a push subscription (web, android, or
|
|
1327
|
+
/** Register a push subscription (web, android, ios, or web-fcm) */
|
|
1322
1328
|
subscribe(subscription: {
|
|
1323
|
-
platform:
|
|
1329
|
+
platform: PushPlatform;
|
|
1324
1330
|
endpoint?: string;
|
|
1325
1331
|
keys?: {
|
|
1326
1332
|
p256dh: string;
|
|
@@ -1329,7 +1335,16 @@ declare class NotificationsModule {
|
|
|
1329
1335
|
deviceToken?: string;
|
|
1330
1336
|
}, deviceName?: string): Promise<PushSubscriptionInfo>;
|
|
1331
1337
|
/** Unregister a push subscription */
|
|
1332
|
-
unsubscribe(platform:
|
|
1338
|
+
unsubscribe(platform: PushPlatform, identifier: string): Promise<{
|
|
1339
|
+
deleted: boolean;
|
|
1340
|
+
}>;
|
|
1341
|
+
/**
|
|
1342
|
+
* Unregister a push subscription by its `id` (as returned by
|
|
1343
|
+
* {@link getSubscriptions}). Robust regardless of platform — use this to
|
|
1344
|
+
* remove a listed device (e.g. web-fcm rows whose raw token is not returned
|
|
1345
|
+
* by the listing and so cannot be passed to {@link unsubscribe}).
|
|
1346
|
+
*/
|
|
1347
|
+
unsubscribeById(subscriptionId: string): Promise<{
|
|
1333
1348
|
deleted: boolean;
|
|
1334
1349
|
}>;
|
|
1335
1350
|
/** Get all subscriptions for the current user */
|
|
@@ -1344,6 +1359,12 @@ declare class NotificationsModule {
|
|
|
1344
1359
|
* Helper: Register a mobile device push token (FCM or APNs).
|
|
1345
1360
|
*/
|
|
1346
1361
|
registerDevicePush(deviceToken: string, platform: 'android' | 'ios', deviceName?: string): Promise<PushSubscriptionInfo>;
|
|
1362
|
+
/**
|
|
1363
|
+
* Registers a web Firebase Cloud Messaging registration token (obtained via
|
|
1364
|
+
* the Firebase JS SDK `getToken()`), so `notifications.send` delivers to this
|
|
1365
|
+
* browser through the project's FCM provider instead of VAPID WebPush.
|
|
1366
|
+
*/
|
|
1367
|
+
registerWebFcm(fcmToken: string, deviceName?: string): Promise<PushSubscriptionInfo>;
|
|
1347
1368
|
private urlBase64ToUint8Array;
|
|
1348
1369
|
}
|
|
1349
1370
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1285,9 +1285,15 @@ declare class DatabaseModule {
|
|
|
1285
1285
|
collection<T = Record<string, unknown>>(name: string): CollectionRef<T>;
|
|
1286
1286
|
}
|
|
1287
1287
|
|
|
1288
|
+
/**
|
|
1289
|
+
* Push subscription platform. `web` = VAPID WebPush; `android`/`ios` = native
|
|
1290
|
+
* device tokens; `web-fcm` = a web Firebase Cloud Messaging registration token.
|
|
1291
|
+
* Defined locally so `@spacelr/sdk` stays a standalone, dependency-free package.
|
|
1292
|
+
*/
|
|
1293
|
+
type PushPlatform = 'web' | 'android' | 'ios' | 'web-fcm';
|
|
1288
1294
|
interface PushSubscriptionInfo {
|
|
1289
1295
|
id: string;
|
|
1290
|
-
platform:
|
|
1296
|
+
platform: PushPlatform;
|
|
1291
1297
|
endpoint?: string;
|
|
1292
1298
|
deviceToken?: string;
|
|
1293
1299
|
deviceId?: string;
|
|
@@ -1318,9 +1324,9 @@ declare class NotificationsModule {
|
|
|
1318
1324
|
private detectDeviceName;
|
|
1319
1325
|
/** Get the VAPID public key for Web Push setup */
|
|
1320
1326
|
getVapidPublicKey(): Promise<VapidKeyResponse>;
|
|
1321
|
-
/** Register a push subscription (web, android, or
|
|
1327
|
+
/** Register a push subscription (web, android, ios, or web-fcm) */
|
|
1322
1328
|
subscribe(subscription: {
|
|
1323
|
-
platform:
|
|
1329
|
+
platform: PushPlatform;
|
|
1324
1330
|
endpoint?: string;
|
|
1325
1331
|
keys?: {
|
|
1326
1332
|
p256dh: string;
|
|
@@ -1329,7 +1335,16 @@ declare class NotificationsModule {
|
|
|
1329
1335
|
deviceToken?: string;
|
|
1330
1336
|
}, deviceName?: string): Promise<PushSubscriptionInfo>;
|
|
1331
1337
|
/** Unregister a push subscription */
|
|
1332
|
-
unsubscribe(platform:
|
|
1338
|
+
unsubscribe(platform: PushPlatform, identifier: string): Promise<{
|
|
1339
|
+
deleted: boolean;
|
|
1340
|
+
}>;
|
|
1341
|
+
/**
|
|
1342
|
+
* Unregister a push subscription by its `id` (as returned by
|
|
1343
|
+
* {@link getSubscriptions}). Robust regardless of platform — use this to
|
|
1344
|
+
* remove a listed device (e.g. web-fcm rows whose raw token is not returned
|
|
1345
|
+
* by the listing and so cannot be passed to {@link unsubscribe}).
|
|
1346
|
+
*/
|
|
1347
|
+
unsubscribeById(subscriptionId: string): Promise<{
|
|
1333
1348
|
deleted: boolean;
|
|
1334
1349
|
}>;
|
|
1335
1350
|
/** Get all subscriptions for the current user */
|
|
@@ -1344,6 +1359,12 @@ declare class NotificationsModule {
|
|
|
1344
1359
|
* Helper: Register a mobile device push token (FCM or APNs).
|
|
1345
1360
|
*/
|
|
1346
1361
|
registerDevicePush(deviceToken: string, platform: 'android' | 'ios', deviceName?: string): Promise<PushSubscriptionInfo>;
|
|
1362
|
+
/**
|
|
1363
|
+
* Registers a web Firebase Cloud Messaging registration token (obtained via
|
|
1364
|
+
* the Firebase JS SDK `getToken()`), so `notifications.send` delivers to this
|
|
1365
|
+
* browser through the project's FCM provider instead of VAPID WebPush.
|
|
1366
|
+
*/
|
|
1367
|
+
registerWebFcm(fcmToken: string, deviceName?: string): Promise<PushSubscriptionInfo>;
|
|
1347
1368
|
private urlBase64ToUint8Array;
|
|
1348
1369
|
}
|
|
1349
1370
|
|
package/dist/index.js
CHANGED
|
@@ -2747,7 +2747,7 @@ var NotificationsModule = class {
|
|
|
2747
2747
|
authenticated: true
|
|
2748
2748
|
});
|
|
2749
2749
|
}
|
|
2750
|
-
/** Register a push subscription (web, android, or
|
|
2750
|
+
/** Register a push subscription (web, android, ios, or web-fcm) */
|
|
2751
2751
|
async subscribe(subscription, deviceName) {
|
|
2752
2752
|
return this.http.request({
|
|
2753
2753
|
method: "POST",
|
|
@@ -2775,6 +2775,19 @@ var NotificationsModule = class {
|
|
|
2775
2775
|
authenticated: true
|
|
2776
2776
|
});
|
|
2777
2777
|
}
|
|
2778
|
+
/**
|
|
2779
|
+
* Unregister a push subscription by its `id` (as returned by
|
|
2780
|
+
* {@link getSubscriptions}). Robust regardless of platform — use this to
|
|
2781
|
+
* remove a listed device (e.g. web-fcm rows whose raw token is not returned
|
|
2782
|
+
* by the listing and so cannot be passed to {@link unsubscribe}).
|
|
2783
|
+
*/
|
|
2784
|
+
async unsubscribeById(subscriptionId) {
|
|
2785
|
+
return this.http.request({
|
|
2786
|
+
method: "DELETE",
|
|
2787
|
+
path: `/notifications/subscriptions/${encodeURIComponent(subscriptionId)}`,
|
|
2788
|
+
authenticated: true
|
|
2789
|
+
});
|
|
2790
|
+
}
|
|
2778
2791
|
/** Get all subscriptions for the current user */
|
|
2779
2792
|
async getSubscriptions() {
|
|
2780
2793
|
return this.http.request({
|
|
@@ -2833,6 +2846,25 @@ var NotificationsModule = class {
|
|
|
2833
2846
|
deviceName
|
|
2834
2847
|
);
|
|
2835
2848
|
}
|
|
2849
|
+
/**
|
|
2850
|
+
* Registers a web Firebase Cloud Messaging registration token (obtained via
|
|
2851
|
+
* the Firebase JS SDK `getToken()`), so `notifications.send` delivers to this
|
|
2852
|
+
* browser through the project's FCM provider instead of VAPID WebPush.
|
|
2853
|
+
*/
|
|
2854
|
+
async registerWebFcm(fcmToken, deviceName) {
|
|
2855
|
+
if (/^https?:\/\//i.test(fcmToken)) {
|
|
2856
|
+
console.warn(
|
|
2857
|
+
"[spacelr] registerWebFcm received what looks like a Web Push endpoint URL, not a Firebase FCM registration token. A web-fcm token must come from getToken(getMessaging(app), { vapidKey, serviceWorkerRegistration }). For plain (non-FCM) Web Push, use registerBrowserPush instead."
|
|
2858
|
+
);
|
|
2859
|
+
}
|
|
2860
|
+
return this.subscribe(
|
|
2861
|
+
{
|
|
2862
|
+
platform: "web-fcm",
|
|
2863
|
+
deviceToken: fcmToken
|
|
2864
|
+
},
|
|
2865
|
+
deviceName
|
|
2866
|
+
);
|
|
2867
|
+
}
|
|
2836
2868
|
urlBase64ToUint8Array(base64String) {
|
|
2837
2869
|
const padding = "=".repeat((4 - base64String.length % 4) % 4);
|
|
2838
2870
|
const base64 = (base64String + padding).replace(/-/g, "+").replace(/_/g, "/");
|