@sparkvault/sdk-js 8.9.1 → 8.10.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.ts +186 -2
- package/dist/notify/index.d.ts +77 -0
- package/dist/notify/types.d.ts +105 -0
- package/dist/sparkvault.cjs.js +201 -0
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +201 -1
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1808,6 +1808,188 @@ declare class EntropyModule {
|
|
|
1808
1808
|
private validateByteCount;
|
|
1809
1809
|
}
|
|
1810
1810
|
|
|
1811
|
+
/**
|
|
1812
|
+
* Notify Module Types
|
|
1813
|
+
*
|
|
1814
|
+
* The signed-in user's first-party inbox. Unlike Entropy/Sparks, notification
|
|
1815
|
+
* ROWS are NOT remapped to camelCase: a row is an opaque, metadata-only pointer
|
|
1816
|
+
* whose fields mirror the wire and whose content is never carried here (it lives
|
|
1817
|
+
* behind the SparkLink `sparklink_code`). Keeping the wire shape verbatim is the
|
|
1818
|
+
* single source of truth shared with `@sparkvault/sdk-mobile` and the first-party
|
|
1819
|
+
* console, so do not "camelCase" these rows. Only the input option `createdAt`
|
|
1820
|
+
* is camelCase for call ergonomics (mapped to `created_at` on the wire).
|
|
1821
|
+
*/
|
|
1822
|
+
/** Inbox views the feed can be filtered to. `all` excludes archived rows. */
|
|
1823
|
+
type NotificationInboxState = 'all' | 'unseen' | 'unread' | 'archived';
|
|
1824
|
+
/** Terminal display states the recipient can apply to one of their rows. */
|
|
1825
|
+
type NotificationMarkState = 'seen' | 'read' | 'archived';
|
|
1826
|
+
/**
|
|
1827
|
+
* A metadata-only inbox row. Rows are LOCKED pointers: the content lives behind
|
|
1828
|
+
* the SparkLink (`sparklink_code`) and is never carried here — open the SparkLink
|
|
1829
|
+
* to unseal it. Timestamps are epoch SECONDS.
|
|
1830
|
+
*/
|
|
1831
|
+
interface NotificationRow {
|
|
1832
|
+
notification_id: string;
|
|
1833
|
+
send_id: string;
|
|
1834
|
+
created_at: number;
|
|
1835
|
+
title: string;
|
|
1836
|
+
category: string;
|
|
1837
|
+
type: string;
|
|
1838
|
+
seen_at: number | null;
|
|
1839
|
+
read_at: number | null;
|
|
1840
|
+
archived_at: number | null;
|
|
1841
|
+
sparklink_code: string;
|
|
1842
|
+
locked: true;
|
|
1843
|
+
thread_id?: string;
|
|
1844
|
+
}
|
|
1845
|
+
interface ListNotificationsOptions {
|
|
1846
|
+
state?: NotificationInboxState;
|
|
1847
|
+
/** Page size, 1-100 (server default 50). */
|
|
1848
|
+
limit?: number;
|
|
1849
|
+
/** Opaque cursor from a prior response. */
|
|
1850
|
+
cursor?: string;
|
|
1851
|
+
}
|
|
1852
|
+
interface ListNotificationsResponse {
|
|
1853
|
+
notifications: NotificationRow[];
|
|
1854
|
+
/**
|
|
1855
|
+
* Next-page cursor, or null on the last page. A page can be SHORT of `limit`
|
|
1856
|
+
* yet still carry a non-null cursor (the state/sender filter is applied after
|
|
1857
|
+
* the key query) — follow the cursor; never treat a short page as the end.
|
|
1858
|
+
*/
|
|
1859
|
+
cursor: string | null;
|
|
1860
|
+
}
|
|
1861
|
+
interface UnreadCountResponse {
|
|
1862
|
+
unread_count: number;
|
|
1863
|
+
/** True when the true count is at/beyond the badge ceiling (render "N+"). */
|
|
1864
|
+
capped: boolean;
|
|
1865
|
+
}
|
|
1866
|
+
interface MarkNotificationStateOptions {
|
|
1867
|
+
/** The row's `created_at` (epoch seconds), round-tripped from the list row. Required. */
|
|
1868
|
+
createdAt: number;
|
|
1869
|
+
state: NotificationMarkState;
|
|
1870
|
+
}
|
|
1871
|
+
interface MarkNotificationStateResponse {
|
|
1872
|
+
notification_id: string;
|
|
1873
|
+
state: NotificationMarkState;
|
|
1874
|
+
updated_at: number;
|
|
1875
|
+
}
|
|
1876
|
+
/** The platform VAPID public key needed for pushManager.subscribe(). */
|
|
1877
|
+
interface WebPushKeyResponse {
|
|
1878
|
+
/** False until the VAPID keypair is provisioned server-side — hide the UI. */
|
|
1879
|
+
configured: boolean;
|
|
1880
|
+
/** base64url VAPID application server key, or null when not configured. */
|
|
1881
|
+
vapid_public_key: string | null;
|
|
1882
|
+
/** The VAPID `sub` contact (mailto:/https), or null when not configured. */
|
|
1883
|
+
subject: string | null;
|
|
1884
|
+
}
|
|
1885
|
+
/** RFC 8030 subscription shape sent to the server (a PushSubscription's JSON). */
|
|
1886
|
+
interface WebPushSubscriptionInput {
|
|
1887
|
+
endpoint: string;
|
|
1888
|
+
keys: {
|
|
1889
|
+
p256dh: string;
|
|
1890
|
+
auth: string;
|
|
1891
|
+
};
|
|
1892
|
+
}
|
|
1893
|
+
interface RegisterWebPushResponse {
|
|
1894
|
+
success: boolean;
|
|
1895
|
+
created: boolean;
|
|
1896
|
+
refreshed: boolean;
|
|
1897
|
+
}
|
|
1898
|
+
interface UnsubscribeWebPushResponse {
|
|
1899
|
+
success: boolean;
|
|
1900
|
+
deleted: boolean;
|
|
1901
|
+
}
|
|
1902
|
+
/** Terminal outcomes of the end-to-end subscribeWebPush ceremony. */
|
|
1903
|
+
type SubscribeWebPushStatus = 'subscribed' | 'already_subscribed' | 'not_supported' | 'not_configured' | 'permission_denied';
|
|
1904
|
+
interface SubscribeWebPushOptions {
|
|
1905
|
+
/**
|
|
1906
|
+
* The caller's service-worker registration (the app owns the worker file and
|
|
1907
|
+
* its lifecycle). Web Push requires a service worker to receive push events.
|
|
1908
|
+
*/
|
|
1909
|
+
serviceWorkerRegistration: ServiceWorkerRegistration;
|
|
1910
|
+
}
|
|
1911
|
+
interface SubscribeWebPushResult {
|
|
1912
|
+
status: SubscribeWebPushStatus;
|
|
1913
|
+
/** The live PushSubscription on 'subscribed'/'already_subscribed'. */
|
|
1914
|
+
subscription?: PushSubscription;
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
/**
|
|
1918
|
+
* Notify Module
|
|
1919
|
+
*
|
|
1920
|
+
* The signed-in user's first-party Notify surface: their own metadata-only
|
|
1921
|
+
* inbox. The recipient is ALWAYS derived from the session on the server — no
|
|
1922
|
+
* method takes a `recipient_id`, and any account/recipient a caller might try
|
|
1923
|
+
* to supply is ignored. This mirrors `@sparkvault/sdk-mobile`'s notify client;
|
|
1924
|
+
* device push registration is intentionally omitted (Expo-only on mobile).
|
|
1925
|
+
*/
|
|
1926
|
+
|
|
1927
|
+
declare class NotifyModule {
|
|
1928
|
+
private readonly http;
|
|
1929
|
+
constructor(http: HttpClient);
|
|
1930
|
+
/**
|
|
1931
|
+
* The caller's own inbox feed (newest first). Follow `cursor` to page — a
|
|
1932
|
+
* page can come back short of `limit` yet still carry a non-null cursor.
|
|
1933
|
+
*
|
|
1934
|
+
* @example
|
|
1935
|
+
* const { notifications, cursor } = await sv.notify.getInbox({ state: 'unread' });
|
|
1936
|
+
*/
|
|
1937
|
+
getInbox(options?: ListNotificationsOptions): Promise<ListNotificationsResponse>;
|
|
1938
|
+
/**
|
|
1939
|
+
* Bounded unseen badge count for the caller's own inbox. `capped` true means
|
|
1940
|
+
* the true count is at/beyond the ceiling — render "N+".
|
|
1941
|
+
*
|
|
1942
|
+
* @example
|
|
1943
|
+
* const { unread_count, capped } = await sv.notify.getUnreadCount();
|
|
1944
|
+
*/
|
|
1945
|
+
getUnreadCount(): Promise<UnreadCountResponse>;
|
|
1946
|
+
/**
|
|
1947
|
+
* Apply a terminal display state to one of the caller's own rows (idempotent).
|
|
1948
|
+
* `createdAt` MUST be the row's own `created_at` (round-tripped from the list
|
|
1949
|
+
* row) — the id alone cannot address the row.
|
|
1950
|
+
*
|
|
1951
|
+
* @example
|
|
1952
|
+
* await sv.notify.markState('ntf_abc', { createdAt: row.created_at, state: 'read' });
|
|
1953
|
+
*/
|
|
1954
|
+
markState(notificationId: string, options: MarkNotificationStateOptions): Promise<MarkNotificationStateResponse>;
|
|
1955
|
+
/**
|
|
1956
|
+
* Whether this environment can do Web Push (service worker + Push API +
|
|
1957
|
+
* Notifications). Feature-detect before showing an enable-notifications UI.
|
|
1958
|
+
*/
|
|
1959
|
+
isWebPushSupported(): boolean;
|
|
1960
|
+
/**
|
|
1961
|
+
* The platform VAPID public key for `pushManager.subscribe()`. `configured`
|
|
1962
|
+
* is false until the server-side VAPID keypair is provisioned — hide the
|
|
1963
|
+
* enable-notifications affordance while false.
|
|
1964
|
+
*/
|
|
1965
|
+
getWebPushKey(): Promise<WebPushKeyResponse>;
|
|
1966
|
+
/**
|
|
1967
|
+
* Register (or refresh) a browser push subscription for the signed-in user.
|
|
1968
|
+
* Accepts a live PushSubscription or its JSON shape.
|
|
1969
|
+
*/
|
|
1970
|
+
registerWebPushSubscription(subscription: PushSubscription | WebPushSubscriptionInput): Promise<RegisterWebPushResponse>;
|
|
1971
|
+
/** Remove a browser push subscription for the signed-in user, by endpoint. */
|
|
1972
|
+
unsubscribeWebPushEndpoint(endpoint: string): Promise<UnsubscribeWebPushResponse>;
|
|
1973
|
+
/**
|
|
1974
|
+
* End-to-end enable ceremony: feature-detect, fetch the VAPID key, ensure
|
|
1975
|
+
* Notification permission, subscribe via the caller's service worker, and
|
|
1976
|
+
* register the subscription with the server. Returns a typed status instead
|
|
1977
|
+
* of throwing on the expected declines (unsupported / not configured /
|
|
1978
|
+
* permission denied) so a host can branch on the outcome. Call it from a user
|
|
1979
|
+
* gesture (permission prompts require one).
|
|
1980
|
+
*
|
|
1981
|
+
* @example
|
|
1982
|
+
* const reg = await navigator.serviceWorker.register('/sw.js');
|
|
1983
|
+
* const { status } = await sv.notify.subscribeWebPush({ serviceWorkerRegistration: reg });
|
|
1984
|
+
*/
|
|
1985
|
+
subscribeWebPush(options: SubscribeWebPushOptions): Promise<SubscribeWebPushResult>;
|
|
1986
|
+
/**
|
|
1987
|
+
* Disable Web Push on this device: unsubscribe the browser subscription and
|
|
1988
|
+
* remove it server-side. Safe to call when not subscribed (returns false).
|
|
1989
|
+
*/
|
|
1990
|
+
unsubscribeWebPush(options: SubscribeWebPushOptions): Promise<boolean>;
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1811
1993
|
/**
|
|
1812
1994
|
* SparkVault Debug Logger
|
|
1813
1995
|
*
|
|
@@ -1893,6 +2075,8 @@ declare class SparkVault {
|
|
|
1893
2075
|
readonly sparks: SparksModule;
|
|
1894
2076
|
/** Hardware-backed random generation. */
|
|
1895
2077
|
readonly entropy: EntropyModule;
|
|
2078
|
+
/** The signed-in user's first-party notification inbox. */
|
|
2079
|
+
readonly notify: NotifyModule;
|
|
1896
2080
|
/** API availability checks. */
|
|
1897
2081
|
readonly health: HealthModule;
|
|
1898
2082
|
private readonly config;
|
|
@@ -1928,5 +2112,5 @@ declare global {
|
|
|
1928
2112
|
}
|
|
1929
2113
|
}
|
|
1930
2114
|
|
|
1931
|
-
export { AuthenticationError, AuthorizationError, EntropyModule, FoldersModule, IdentityModule, IngotsModule, NetworkError, PlanRequiredError, PopupBlockedError, ProductsModule, QuotaExceededError, SparkVault, SparkVaultError, SparksModule, TimeoutError, UserCancelledError, ValidationError, VaultsModule, SparkVault as default, logger, setDebugMode };
|
|
1932
|
-
export type { AccessLogRetention, AccessLogsOptions, ApiResponse, AuthMethod, BandwidthPool, CreateFolderOptions, CreateSparkOptions, CreateUploadOptions, CreateVaultOptions, CreatedIngot, CreatedSpark, EntropyFormat, EntropyResult, Folder, FolderBreadcrumbItem, GenerateEntropyOptions, HealthCheckOptions, HealthCheckResult, AttachOptions as IdentityAttachOptions, Ingot, IngotAccessLog, IngotAccessLogPage, IngotDownloadLink, IngotInvite, IngotPage, IngotSharingConfig, IngotUpload, ListContentsOptions, ListIngotsOptions, ListSparksOptions, PoolState, PoolsMeta, QuotaResource, ReplaceIngotOptions, ResponseMeta, SearchIngotsOptions, ShareSparkOptions, Spark, SparkPage, SparkShare, SparkSummary, SparkVaultConfig, SparkVisibility, StoragePool, Theme, TokenClaims, UnsealedVault, UpdateFolderOptions, UpdateIngotSharingOptions, UpdateVaultUploadOptions, UpdatedVault, UploadAttachOptions, UploadBranding, UploadIngotOptions, UploadOptions, UploadProgress, UploadResult, Vault, VaultDetail, VaultSharingConfig, VaultSharingOptions, VaultSummary, VaultUploadConfig, VaultUploadSettings, VerifyOptions, VerifyResult };
|
|
2115
|
+
export { AuthenticationError, AuthorizationError, EntropyModule, FoldersModule, IdentityModule, IngotsModule, NetworkError, NotifyModule, PlanRequiredError, PopupBlockedError, ProductsModule, QuotaExceededError, SparkVault, SparkVaultError, SparksModule, TimeoutError, UserCancelledError, ValidationError, VaultsModule, SparkVault as default, logger, setDebugMode };
|
|
2116
|
+
export type { AccessLogRetention, AccessLogsOptions, ApiResponse, AuthMethod, BandwidthPool, CreateFolderOptions, CreateSparkOptions, CreateUploadOptions, CreateVaultOptions, CreatedIngot, CreatedSpark, EntropyFormat, EntropyResult, Folder, FolderBreadcrumbItem, GenerateEntropyOptions, HealthCheckOptions, HealthCheckResult, AttachOptions as IdentityAttachOptions, Ingot, IngotAccessLog, IngotAccessLogPage, IngotDownloadLink, IngotInvite, IngotPage, IngotSharingConfig, IngotUpload, ListContentsOptions, ListIngotsOptions, ListNotificationsOptions, ListNotificationsResponse, ListSparksOptions, MarkNotificationStateOptions, MarkNotificationStateResponse, NotificationInboxState, NotificationMarkState, NotificationRow, PoolState, PoolsMeta, QuotaResource, RegisterWebPushResponse, ReplaceIngotOptions, ResponseMeta, SearchIngotsOptions, ShareSparkOptions, Spark, SparkPage, SparkShare, SparkSummary, SparkVaultConfig, SparkVisibility, StoragePool, SubscribeWebPushOptions, SubscribeWebPushResult, SubscribeWebPushStatus, Theme, TokenClaims, UnreadCountResponse, UnsealedVault, UnsubscribeWebPushResponse, UpdateFolderOptions, UpdateIngotSharingOptions, UpdateVaultUploadOptions, UpdatedVault, UploadAttachOptions, UploadBranding, UploadIngotOptions, UploadOptions, UploadProgress, UploadResult, Vault, VaultDetail, VaultSharingConfig, VaultSharingOptions, VaultSummary, VaultUploadConfig, VaultUploadSettings, VerifyOptions, VerifyResult, WebPushKeyResponse, WebPushSubscriptionInput };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notify Module
|
|
3
|
+
*
|
|
4
|
+
* The signed-in user's first-party Notify surface: their own metadata-only
|
|
5
|
+
* inbox. The recipient is ALWAYS derived from the session on the server — no
|
|
6
|
+
* method takes a `recipient_id`, and any account/recipient a caller might try
|
|
7
|
+
* to supply is ignored. This mirrors `@sparkvault/sdk-mobile`'s notify client;
|
|
8
|
+
* device push registration is intentionally omitted (Expo-only on mobile).
|
|
9
|
+
*/
|
|
10
|
+
import { HttpClient } from '../http';
|
|
11
|
+
import type { ListNotificationsOptions, ListNotificationsResponse, UnreadCountResponse, MarkNotificationStateOptions, MarkNotificationStateResponse, WebPushKeyResponse, WebPushSubscriptionInput, RegisterWebPushResponse, UnsubscribeWebPushResponse, SubscribeWebPushOptions, SubscribeWebPushResult } from './types';
|
|
12
|
+
export declare class NotifyModule {
|
|
13
|
+
private readonly http;
|
|
14
|
+
constructor(http: HttpClient);
|
|
15
|
+
/**
|
|
16
|
+
* The caller's own inbox feed (newest first). Follow `cursor` to page — a
|
|
17
|
+
* page can come back short of `limit` yet still carry a non-null cursor.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const { notifications, cursor } = await sv.notify.getInbox({ state: 'unread' });
|
|
21
|
+
*/
|
|
22
|
+
getInbox(options?: ListNotificationsOptions): Promise<ListNotificationsResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Bounded unseen badge count for the caller's own inbox. `capped` true means
|
|
25
|
+
* the true count is at/beyond the ceiling — render "N+".
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* const { unread_count, capped } = await sv.notify.getUnreadCount();
|
|
29
|
+
*/
|
|
30
|
+
getUnreadCount(): Promise<UnreadCountResponse>;
|
|
31
|
+
/**
|
|
32
|
+
* Apply a terminal display state to one of the caller's own rows (idempotent).
|
|
33
|
+
* `createdAt` MUST be the row's own `created_at` (round-tripped from the list
|
|
34
|
+
* row) — the id alone cannot address the row.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* await sv.notify.markState('ntf_abc', { createdAt: row.created_at, state: 'read' });
|
|
38
|
+
*/
|
|
39
|
+
markState(notificationId: string, options: MarkNotificationStateOptions): Promise<MarkNotificationStateResponse>;
|
|
40
|
+
/**
|
|
41
|
+
* Whether this environment can do Web Push (service worker + Push API +
|
|
42
|
+
* Notifications). Feature-detect before showing an enable-notifications UI.
|
|
43
|
+
*/
|
|
44
|
+
isWebPushSupported(): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The platform VAPID public key for `pushManager.subscribe()`. `configured`
|
|
47
|
+
* is false until the server-side VAPID keypair is provisioned — hide the
|
|
48
|
+
* enable-notifications affordance while false.
|
|
49
|
+
*/
|
|
50
|
+
getWebPushKey(): Promise<WebPushKeyResponse>;
|
|
51
|
+
/**
|
|
52
|
+
* Register (or refresh) a browser push subscription for the signed-in user.
|
|
53
|
+
* Accepts a live PushSubscription or its JSON shape.
|
|
54
|
+
*/
|
|
55
|
+
registerWebPushSubscription(subscription: PushSubscription | WebPushSubscriptionInput): Promise<RegisterWebPushResponse>;
|
|
56
|
+
/** Remove a browser push subscription for the signed-in user, by endpoint. */
|
|
57
|
+
unsubscribeWebPushEndpoint(endpoint: string): Promise<UnsubscribeWebPushResponse>;
|
|
58
|
+
/**
|
|
59
|
+
* End-to-end enable ceremony: feature-detect, fetch the VAPID key, ensure
|
|
60
|
+
* Notification permission, subscribe via the caller's service worker, and
|
|
61
|
+
* register the subscription with the server. Returns a typed status instead
|
|
62
|
+
* of throwing on the expected declines (unsupported / not configured /
|
|
63
|
+
* permission denied) so a host can branch on the outcome. Call it from a user
|
|
64
|
+
* gesture (permission prompts require one).
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* const reg = await navigator.serviceWorker.register('/sw.js');
|
|
68
|
+
* const { status } = await sv.notify.subscribeWebPush({ serviceWorkerRegistration: reg });
|
|
69
|
+
*/
|
|
70
|
+
subscribeWebPush(options: SubscribeWebPushOptions): Promise<SubscribeWebPushResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Disable Web Push on this device: unsubscribe the browser subscription and
|
|
73
|
+
* remove it server-side. Safe to call when not subscribed (returns false).
|
|
74
|
+
*/
|
|
75
|
+
unsubscribeWebPush(options: SubscribeWebPushOptions): Promise<boolean>;
|
|
76
|
+
}
|
|
77
|
+
export type { NotificationInboxState, NotificationMarkState, NotificationRow, ListNotificationsOptions, ListNotificationsResponse, UnreadCountResponse, MarkNotificationStateOptions, MarkNotificationStateResponse, WebPushKeyResponse, WebPushSubscriptionInput, RegisterWebPushResponse, UnsubscribeWebPushResponse, SubscribeWebPushStatus, SubscribeWebPushOptions, SubscribeWebPushResult, } from './types';
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notify Module Types
|
|
3
|
+
*
|
|
4
|
+
* The signed-in user's first-party inbox. Unlike Entropy/Sparks, notification
|
|
5
|
+
* ROWS are NOT remapped to camelCase: a row is an opaque, metadata-only pointer
|
|
6
|
+
* whose fields mirror the wire and whose content is never carried here (it lives
|
|
7
|
+
* behind the SparkLink `sparklink_code`). Keeping the wire shape verbatim is the
|
|
8
|
+
* single source of truth shared with `@sparkvault/sdk-mobile` and the first-party
|
|
9
|
+
* console, so do not "camelCase" these rows. Only the input option `createdAt`
|
|
10
|
+
* is camelCase for call ergonomics (mapped to `created_at` on the wire).
|
|
11
|
+
*/
|
|
12
|
+
/** Inbox views the feed can be filtered to. `all` excludes archived rows. */
|
|
13
|
+
export type NotificationInboxState = 'all' | 'unseen' | 'unread' | 'archived';
|
|
14
|
+
/** Terminal display states the recipient can apply to one of their rows. */
|
|
15
|
+
export type NotificationMarkState = 'seen' | 'read' | 'archived';
|
|
16
|
+
/**
|
|
17
|
+
* A metadata-only inbox row. Rows are LOCKED pointers: the content lives behind
|
|
18
|
+
* the SparkLink (`sparklink_code`) and is never carried here — open the SparkLink
|
|
19
|
+
* to unseal it. Timestamps are epoch SECONDS.
|
|
20
|
+
*/
|
|
21
|
+
export interface NotificationRow {
|
|
22
|
+
notification_id: string;
|
|
23
|
+
send_id: string;
|
|
24
|
+
created_at: number;
|
|
25
|
+
title: string;
|
|
26
|
+
category: string;
|
|
27
|
+
type: string;
|
|
28
|
+
seen_at: number | null;
|
|
29
|
+
read_at: number | null;
|
|
30
|
+
archived_at: number | null;
|
|
31
|
+
sparklink_code: string;
|
|
32
|
+
locked: true;
|
|
33
|
+
thread_id?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface ListNotificationsOptions {
|
|
36
|
+
state?: NotificationInboxState;
|
|
37
|
+
/** Page size, 1-100 (server default 50). */
|
|
38
|
+
limit?: number;
|
|
39
|
+
/** Opaque cursor from a prior response. */
|
|
40
|
+
cursor?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface ListNotificationsResponse {
|
|
43
|
+
notifications: NotificationRow[];
|
|
44
|
+
/**
|
|
45
|
+
* Next-page cursor, or null on the last page. A page can be SHORT of `limit`
|
|
46
|
+
* yet still carry a non-null cursor (the state/sender filter is applied after
|
|
47
|
+
* the key query) — follow the cursor; never treat a short page as the end.
|
|
48
|
+
*/
|
|
49
|
+
cursor: string | null;
|
|
50
|
+
}
|
|
51
|
+
export interface UnreadCountResponse {
|
|
52
|
+
unread_count: number;
|
|
53
|
+
/** True when the true count is at/beyond the badge ceiling (render "N+"). */
|
|
54
|
+
capped: boolean;
|
|
55
|
+
}
|
|
56
|
+
export interface MarkNotificationStateOptions {
|
|
57
|
+
/** The row's `created_at` (epoch seconds), round-tripped from the list row. Required. */
|
|
58
|
+
createdAt: number;
|
|
59
|
+
state: NotificationMarkState;
|
|
60
|
+
}
|
|
61
|
+
export interface MarkNotificationStateResponse {
|
|
62
|
+
notification_id: string;
|
|
63
|
+
state: NotificationMarkState;
|
|
64
|
+
updated_at: number;
|
|
65
|
+
}
|
|
66
|
+
/** The platform VAPID public key needed for pushManager.subscribe(). */
|
|
67
|
+
export interface WebPushKeyResponse {
|
|
68
|
+
/** False until the VAPID keypair is provisioned server-side — hide the UI. */
|
|
69
|
+
configured: boolean;
|
|
70
|
+
/** base64url VAPID application server key, or null when not configured. */
|
|
71
|
+
vapid_public_key: string | null;
|
|
72
|
+
/** The VAPID `sub` contact (mailto:/https), or null when not configured. */
|
|
73
|
+
subject: string | null;
|
|
74
|
+
}
|
|
75
|
+
/** RFC 8030 subscription shape sent to the server (a PushSubscription's JSON). */
|
|
76
|
+
export interface WebPushSubscriptionInput {
|
|
77
|
+
endpoint: string;
|
|
78
|
+
keys: {
|
|
79
|
+
p256dh: string;
|
|
80
|
+
auth: string;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export interface RegisterWebPushResponse {
|
|
84
|
+
success: boolean;
|
|
85
|
+
created: boolean;
|
|
86
|
+
refreshed: boolean;
|
|
87
|
+
}
|
|
88
|
+
export interface UnsubscribeWebPushResponse {
|
|
89
|
+
success: boolean;
|
|
90
|
+
deleted: boolean;
|
|
91
|
+
}
|
|
92
|
+
/** Terminal outcomes of the end-to-end subscribeWebPush ceremony. */
|
|
93
|
+
export type SubscribeWebPushStatus = 'subscribed' | 'already_subscribed' | 'not_supported' | 'not_configured' | 'permission_denied';
|
|
94
|
+
export interface SubscribeWebPushOptions {
|
|
95
|
+
/**
|
|
96
|
+
* The caller's service-worker registration (the app owns the worker file and
|
|
97
|
+
* its lifecycle). Web Push requires a service worker to receive push events.
|
|
98
|
+
*/
|
|
99
|
+
serviceWorkerRegistration: ServiceWorkerRegistration;
|
|
100
|
+
}
|
|
101
|
+
export interface SubscribeWebPushResult {
|
|
102
|
+
status: SubscribeWebPushStatus;
|
|
103
|
+
/** The live PushSubscription on 'subscribed'/'already_subscribed'. */
|
|
104
|
+
subscription?: PushSubscription;
|
|
105
|
+
}
|
package/dist/sparkvault.cjs.js
CHANGED
|
@@ -13524,6 +13524,205 @@ class EntropyModule {
|
|
|
13524
13524
|
}
|
|
13525
13525
|
}
|
|
13526
13526
|
|
|
13527
|
+
/**
|
|
13528
|
+
* Notify Module
|
|
13529
|
+
*
|
|
13530
|
+
* The signed-in user's first-party Notify surface: their own metadata-only
|
|
13531
|
+
* inbox. The recipient is ALWAYS derived from the session on the server — no
|
|
13532
|
+
* method takes a `recipient_id`, and any account/recipient a caller might try
|
|
13533
|
+
* to supply is ignored. This mirrors `@sparkvault/sdk-mobile`'s notify client;
|
|
13534
|
+
* device push registration is intentionally omitted (Expo-only on mobile).
|
|
13535
|
+
*/
|
|
13536
|
+
const MARK_STATES = ['seen', 'read', 'archived'];
|
|
13537
|
+
/**
|
|
13538
|
+
* Decode a base64url VAPID key into the Uint8Array `pushManager.subscribe`
|
|
13539
|
+
* requires for `applicationServerKey`. Standalone (no atob dependency on a
|
|
13540
|
+
* data: URL) so it works in every browser context.
|
|
13541
|
+
*/
|
|
13542
|
+
function urlBase64ToUint8Array(base64url) {
|
|
13543
|
+
const padding = '='.repeat((4 - (base64url.length % 4)) % 4);
|
|
13544
|
+
const base64 = (base64url + padding).replace(/-/g, '+').replace(/_/g, '/');
|
|
13545
|
+
const raw = atob(base64);
|
|
13546
|
+
const output = new Uint8Array(new ArrayBuffer(raw.length));
|
|
13547
|
+
for (let i = 0; i < raw.length; i += 1) {
|
|
13548
|
+
output[i] = raw.charCodeAt(i);
|
|
13549
|
+
}
|
|
13550
|
+
return output;
|
|
13551
|
+
}
|
|
13552
|
+
/** Normalize a PushSubscription (or its JSON) to the server's wire shape. */
|
|
13553
|
+
function toSubscriptionInput(subscription) {
|
|
13554
|
+
const json = typeof subscription.toJSON === 'function'
|
|
13555
|
+
? subscription.toJSON()
|
|
13556
|
+
: subscription;
|
|
13557
|
+
const endpoint = json.endpoint;
|
|
13558
|
+
const p256dh = json.keys?.p256dh;
|
|
13559
|
+
const auth = json.keys?.auth;
|
|
13560
|
+
if (!endpoint || !p256dh || !auth) {
|
|
13561
|
+
throw new ValidationError('A web push subscription requires endpoint and keys.p256dh/auth');
|
|
13562
|
+
}
|
|
13563
|
+
return { endpoint, keys: { p256dh, auth } };
|
|
13564
|
+
}
|
|
13565
|
+
class NotifyModule {
|
|
13566
|
+
constructor(http) {
|
|
13567
|
+
this.http = http;
|
|
13568
|
+
}
|
|
13569
|
+
/**
|
|
13570
|
+
* The caller's own inbox feed (newest first). Follow `cursor` to page — a
|
|
13571
|
+
* page can come back short of `limit` yet still carry a non-null cursor.
|
|
13572
|
+
*
|
|
13573
|
+
* @example
|
|
13574
|
+
* const { notifications, cursor } = await sv.notify.getInbox({ state: 'unread' });
|
|
13575
|
+
*/
|
|
13576
|
+
async getInbox(options = {}) {
|
|
13577
|
+
const params = new URLSearchParams();
|
|
13578
|
+
if (options.state)
|
|
13579
|
+
params.set('state', options.state);
|
|
13580
|
+
if (options.limit)
|
|
13581
|
+
params.set('limit', String(options.limit));
|
|
13582
|
+
if (options.cursor)
|
|
13583
|
+
params.set('cursor', options.cursor);
|
|
13584
|
+
const query = params.toString();
|
|
13585
|
+
const response = await this.http.get(query ? `/v1/me/notifications?${query}` : '/v1/me/notifications');
|
|
13586
|
+
return response.data;
|
|
13587
|
+
}
|
|
13588
|
+
/**
|
|
13589
|
+
* Bounded unseen badge count for the caller's own inbox. `capped` true means
|
|
13590
|
+
* the true count is at/beyond the ceiling — render "N+".
|
|
13591
|
+
*
|
|
13592
|
+
* @example
|
|
13593
|
+
* const { unread_count, capped } = await sv.notify.getUnreadCount();
|
|
13594
|
+
*/
|
|
13595
|
+
async getUnreadCount() {
|
|
13596
|
+
const response = await this.http.get('/v1/me/notifications/unread-count');
|
|
13597
|
+
return response.data;
|
|
13598
|
+
}
|
|
13599
|
+
/**
|
|
13600
|
+
* Apply a terminal display state to one of the caller's own rows (idempotent).
|
|
13601
|
+
* `createdAt` MUST be the row's own `created_at` (round-tripped from the list
|
|
13602
|
+
* row) — the id alone cannot address the row.
|
|
13603
|
+
*
|
|
13604
|
+
* @example
|
|
13605
|
+
* await sv.notify.markState('ntf_abc', { createdAt: row.created_at, state: 'read' });
|
|
13606
|
+
*/
|
|
13607
|
+
async markState(notificationId, options) {
|
|
13608
|
+
if (!notificationId || typeof notificationId !== 'string') {
|
|
13609
|
+
throw new ValidationError('notificationId is required', { field: 'notificationId' });
|
|
13610
|
+
}
|
|
13611
|
+
if (!Number.isFinite(options?.createdAt)) {
|
|
13612
|
+
throw new ValidationError('createdAt (the row\'s created_at) is required', {
|
|
13613
|
+
field: 'createdAt',
|
|
13614
|
+
received: options?.createdAt,
|
|
13615
|
+
});
|
|
13616
|
+
}
|
|
13617
|
+
if (!MARK_STATES.includes(options.state)) {
|
|
13618
|
+
throw new ValidationError(`state must be one of ${MARK_STATES.join(', ')}`, {
|
|
13619
|
+
field: 'state',
|
|
13620
|
+
received: options.state,
|
|
13621
|
+
});
|
|
13622
|
+
}
|
|
13623
|
+
const response = await this.http.post(`/v1/me/notifications/${encodeURIComponent(notificationId)}/state`, { created_at: options.createdAt, state: options.state });
|
|
13624
|
+
return response.data;
|
|
13625
|
+
}
|
|
13626
|
+
// ── Browser Web Push ──────────────────────────────────────────────────────
|
|
13627
|
+
/**
|
|
13628
|
+
* Whether this environment can do Web Push (service worker + Push API +
|
|
13629
|
+
* Notifications). Feature-detect before showing an enable-notifications UI.
|
|
13630
|
+
*/
|
|
13631
|
+
isWebPushSupported() {
|
|
13632
|
+
return (typeof window !== 'undefined' &&
|
|
13633
|
+
'serviceWorker' in navigator &&
|
|
13634
|
+
'PushManager' in window &&
|
|
13635
|
+
'Notification' in window);
|
|
13636
|
+
}
|
|
13637
|
+
/**
|
|
13638
|
+
* The platform VAPID public key for `pushManager.subscribe()`. `configured`
|
|
13639
|
+
* is false until the server-side VAPID keypair is provisioned — hide the
|
|
13640
|
+
* enable-notifications affordance while false.
|
|
13641
|
+
*/
|
|
13642
|
+
async getWebPushKey() {
|
|
13643
|
+
const response = await this.http.get('/v1/me/notifications/web-push/key');
|
|
13644
|
+
return response.data;
|
|
13645
|
+
}
|
|
13646
|
+
/**
|
|
13647
|
+
* Register (or refresh) a browser push subscription for the signed-in user.
|
|
13648
|
+
* Accepts a live PushSubscription or its JSON shape.
|
|
13649
|
+
*/
|
|
13650
|
+
async registerWebPushSubscription(subscription) {
|
|
13651
|
+
const input = toSubscriptionInput(subscription);
|
|
13652
|
+
const response = await this.http.post('/v1/me/notifications/web-push', input);
|
|
13653
|
+
return response.data;
|
|
13654
|
+
}
|
|
13655
|
+
/** Remove a browser push subscription for the signed-in user, by endpoint. */
|
|
13656
|
+
async unsubscribeWebPushEndpoint(endpoint) {
|
|
13657
|
+
if (!endpoint || typeof endpoint !== 'string') {
|
|
13658
|
+
throw new ValidationError('endpoint is required');
|
|
13659
|
+
}
|
|
13660
|
+
const response = await this.http.post('/v1/me/notifications/web-push/unsubscribe', { endpoint });
|
|
13661
|
+
return response.data;
|
|
13662
|
+
}
|
|
13663
|
+
/**
|
|
13664
|
+
* End-to-end enable ceremony: feature-detect, fetch the VAPID key, ensure
|
|
13665
|
+
* Notification permission, subscribe via the caller's service worker, and
|
|
13666
|
+
* register the subscription with the server. Returns a typed status instead
|
|
13667
|
+
* of throwing on the expected declines (unsupported / not configured /
|
|
13668
|
+
* permission denied) so a host can branch on the outcome. Call it from a user
|
|
13669
|
+
* gesture (permission prompts require one).
|
|
13670
|
+
*
|
|
13671
|
+
* @example
|
|
13672
|
+
* const reg = await navigator.serviceWorker.register('/sw.js');
|
|
13673
|
+
* const { status } = await sv.notify.subscribeWebPush({ serviceWorkerRegistration: reg });
|
|
13674
|
+
*/
|
|
13675
|
+
async subscribeWebPush(options) {
|
|
13676
|
+
if (!this.isWebPushSupported()) {
|
|
13677
|
+
return { status: 'not_supported' };
|
|
13678
|
+
}
|
|
13679
|
+
const registration = options?.serviceWorkerRegistration;
|
|
13680
|
+
if (!registration || typeof registration.pushManager?.subscribe !== 'function') {
|
|
13681
|
+
throw new ValidationError('serviceWorkerRegistration with a pushManager is required');
|
|
13682
|
+
}
|
|
13683
|
+
const key = await this.getWebPushKey();
|
|
13684
|
+
if (!key.configured || !key.vapid_public_key) {
|
|
13685
|
+
return { status: 'not_configured' };
|
|
13686
|
+
}
|
|
13687
|
+
if (Notification.permission === 'denied') {
|
|
13688
|
+
return { status: 'permission_denied' };
|
|
13689
|
+
}
|
|
13690
|
+
if (Notification.permission === 'default') {
|
|
13691
|
+
const permission = await Notification.requestPermission();
|
|
13692
|
+
if (permission !== 'granted') {
|
|
13693
|
+
return { status: 'permission_denied' };
|
|
13694
|
+
}
|
|
13695
|
+
}
|
|
13696
|
+
// Reuse an existing subscription if present; browsers return the same one,
|
|
13697
|
+
// but registering again refreshes the server TTL.
|
|
13698
|
+
const existing = await registration.pushManager.getSubscription();
|
|
13699
|
+
const subscription = existing ??
|
|
13700
|
+
(await registration.pushManager.subscribe({
|
|
13701
|
+
userVisibleOnly: true,
|
|
13702
|
+
applicationServerKey: urlBase64ToUint8Array(key.vapid_public_key),
|
|
13703
|
+
}));
|
|
13704
|
+
await this.registerWebPushSubscription(subscription);
|
|
13705
|
+
return { status: existing ? 'already_subscribed' : 'subscribed', subscription };
|
|
13706
|
+
}
|
|
13707
|
+
/**
|
|
13708
|
+
* Disable Web Push on this device: unsubscribe the browser subscription and
|
|
13709
|
+
* remove it server-side. Safe to call when not subscribed (returns false).
|
|
13710
|
+
*/
|
|
13711
|
+
async unsubscribeWebPush(options) {
|
|
13712
|
+
const registration = options?.serviceWorkerRegistration;
|
|
13713
|
+
if (!registration || typeof registration.pushManager?.getSubscription !== 'function') {
|
|
13714
|
+
return false;
|
|
13715
|
+
}
|
|
13716
|
+
const subscription = await registration.pushManager.getSubscription();
|
|
13717
|
+
if (!subscription) {
|
|
13718
|
+
return false;
|
|
13719
|
+
}
|
|
13720
|
+
// Remove server-side first (still authenticated), then drop it locally.
|
|
13721
|
+
await this.unsubscribeWebPushEndpoint(subscription.endpoint).catch(() => undefined);
|
|
13722
|
+
return subscription.unsubscribe();
|
|
13723
|
+
}
|
|
13724
|
+
}
|
|
13725
|
+
|
|
13527
13726
|
/**
|
|
13528
13727
|
* SparkVault Debug Logger
|
|
13529
13728
|
*
|
|
@@ -13712,6 +13911,7 @@ class SparkVault {
|
|
|
13712
13911
|
this.folders = new FoldersModule(http);
|
|
13713
13912
|
this.sparks = new SparksModule(http);
|
|
13714
13913
|
this.entropy = new EntropyModule(http);
|
|
13914
|
+
this.notify = new NotifyModule(http);
|
|
13715
13915
|
this.health = new HealthModule(this.config);
|
|
13716
13916
|
}
|
|
13717
13917
|
/**
|
|
@@ -13758,6 +13958,7 @@ exports.FoldersModule = FoldersModule;
|
|
|
13758
13958
|
exports.IdentityModule = IdentityModule;
|
|
13759
13959
|
exports.IngotsModule = IngotsModule;
|
|
13760
13960
|
exports.NetworkError = NetworkError;
|
|
13961
|
+
exports.NotifyModule = NotifyModule;
|
|
13761
13962
|
exports.PlanRequiredError = PlanRequiredError;
|
|
13762
13963
|
exports.PopupBlockedError = PopupBlockedError;
|
|
13763
13964
|
exports.ProductsModule = ProductsModule;
|