@sagepilot-ai/react-native-sdk 0.3.6 → 0.4.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/README.md +45 -0
- package/dist/index.d.mts +208 -1
- package/dist/index.d.ts +208 -1
- package/dist/index.js +672 -105
- package/dist/index.mjs +616 -51
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,6 +16,8 @@ For full integration docs, see [React Native SDK docs](https://docs.sagepilot.ai
|
|
|
16
16
|
|
|
17
17
|
## Install
|
|
18
18
|
|
|
19
|
+
The base SDK, camera add-on and push add-on share release **0.4.1**. Install matching versions of the add-ons your app uses; chat-only apps do not need either add-on.
|
|
20
|
+
|
|
19
21
|
```bash
|
|
20
22
|
npm install @sagepilot-ai/react-native-sdk@latest react-native-webview
|
|
21
23
|
```
|
|
@@ -211,6 +213,7 @@ More details: [Native file picker](https://docs.sagepilot.ai/sdks/react-native/n
|
|
|
211
213
|
|---|---|
|
|
212
214
|
| `SagepilotChat.configure(config)` | `Promise<SagepilotMobileConfigureResult>` |
|
|
213
215
|
| `SagepilotChat.identify(identity)` | `Promise<SagepilotIdentifyResult>` |
|
|
216
|
+
| `SagepilotChat.authorizePush(proof)` | `Promise<void>` |
|
|
214
217
|
| `SagepilotChat.logout()` | `Promise<SagepilotLogoutResponse>` |
|
|
215
218
|
| `SagepilotChat.getSession()` | `Promise<SagepilotSessionState>` |
|
|
216
219
|
| `SagepilotChat.getUnreadCount()` | `Promise<number>` |
|
|
@@ -237,3 +240,45 @@ Full API reference: [SDK API reference](https://docs.sagepilot.ai/sdks/react-nat
|
|
|
237
240
|
## License
|
|
238
241
|
|
|
239
242
|
MIT
|
|
243
|
+
|
|
244
|
+
## Brand push notifications (0.4.0)
|
|
245
|
+
|
|
246
|
+
For apps using chat and push, use **one customer session** with the optional `@sagepilot-ai/react-native-push-addon`. The add-on owns native display, images, analytics buffering/retry/upload. The base SDK owns identity, installation/preferences and authenticated transport.
|
|
247
|
+
|
|
248
|
+
**Using Firebase/provider display still enables Sagepilot push analytics.** Connect Firebase methods with `createFirebasePushAdapter`, wrap it with `createSagepilotNativePushAdapter` as below, and complete the add-on's callback/native forwarding setup. The add-on uploads available receipt and open events for Sagepilot-sent notifications to journey/campaign reports. Token registration alone does not report engagement; destination success requires `push.track('destination_opened', ...)` after the screen loads.
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
import { SagepilotChat, createFirebasePushAdapter } from '@sagepilot-ai/react-native-sdk';
|
|
252
|
+
import { createSagepilotNativePushAdapter } from '@sagepilot-ai/react-native-push-addon';
|
|
253
|
+
|
|
254
|
+
await SagepilotChat.configure({ ...existingChatConfig,
|
|
255
|
+
push: {
|
|
256
|
+
channelId: brandPushChannelId,
|
|
257
|
+
storage: AsyncStorage,
|
|
258
|
+
adapter: createSagepilotNativePushAdapter(
|
|
259
|
+
createFirebasePushAdapter(firebaseMethods, permissionMethods),
|
|
260
|
+
{ displayMode: 'provider', onError: reportError },
|
|
261
|
+
),
|
|
262
|
+
onOpen: routeApprovedDestination,
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
await SagepilotChat.identify(existingCustomerIdentity);
|
|
266
|
+
await SagepilotChat.authorizePush(identityTokenFromYourAuthenticatedBackend);
|
|
267
|
+
// Explicit opt-in action:
|
|
268
|
+
await SagepilotChat.push.requestPermission();
|
|
269
|
+
await SagepilotChat.push.setPreferences({ enabled: true, app: { marketing_enabled: true } });
|
|
270
|
+
// After the intended screen actually mounts:
|
|
271
|
+
await SagepilotChat.push.track('destination_opened', notificationMessage);
|
|
272
|
+
// Revoke the installation before discarding credentials:
|
|
273
|
+
await SagepilotChat.logout();
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
The host backend authenticates its user and signs an HS256 proof with the brand channel's server-only `config.identity_verification.secret`. Required claims: `aud: "sagepilot-brand-push"`, `channel_id`, `client_customer_id` (or existing internal `customer_id`), `iat`, `exp`; maximum 300 seconds. A signed proof is always required for shared and standalone SDK push. There is no verification-off mode. Never accept an arbitrary customer UUID from a client or embed the signing secret in an app.
|
|
277
|
+
|
|
278
|
+
`authorizePush(proof)` and standalone `brand.identify(proof)` require a nonempty proof string. Missing proofs and plain identity objects fail locally without sending a request, changing the stored session or revoking its installation. Your app can fetch the proof automatically from its authenticated backend after sign-in.
|
|
279
|
+
|
|
280
|
+
`authorizePush` upgrades the existing encrypted session with a verified brand grant. Workspace/customer must match; chat session/channel/conversation stay intact. The SDK stores and uses one token for both. Identify clears previous brand permission; authorize again afterwards. A same-customer hosted-chat token refresh preserves the grant's original expiry. Fresh proof is needed after 24 hours for registration/preferences; revocation and signed historical event uploads remain possible after proof freshness expires.
|
|
281
|
+
|
|
282
|
+
Push-only integrations may still use `new SagepilotBrandPush({ key: 'workspace_id:brand_push_channel_id', tokenStorage, push, onError })`, followed by `start()` and `identify(proof)`. This standalone session cannot access chat. Do not create both clients for a chat-plus-push integration. Legacy base push adapters/outboxes continue to work; new add-on observations are owned/uploaded by the add-on.
|
|
283
|
+
|
|
284
|
+
[Native add-on setup and limits](../react-native-push-addon/README.md) covers Expo/native forwarding, iOS image extension/signing, provider versus SDK display, callback availability, persistence and host-confirmed destinations. Sender capability selection is Step 3. Android/iOS package builds and focused compatibility checks pass; live delivery still requires brand configuration and real-device validation. Neither package has been published by this change.
|
package/dist/index.d.mts
CHANGED
|
@@ -270,6 +270,8 @@ type SagepilotBiometricsAdapter = {
|
|
|
270
270
|
authenticate: (prompt: string) => Promise<boolean>;
|
|
271
271
|
};
|
|
272
272
|
type SagepilotMobileConfig = {
|
|
273
|
+
/** Optional native push integration; requires durable storage and a verified identified session. */
|
|
274
|
+
push?: SagepilotPushConfig;
|
|
273
275
|
/**
|
|
274
276
|
* Public Sagepilot routing key in the format "workspace_id:channel_id".
|
|
275
277
|
* This is not an API secret and is safe to ship in a mobile app.
|
|
@@ -487,11 +489,180 @@ type SagepilotChatProviderProps = {
|
|
|
487
489
|
loadingLabel?: string;
|
|
488
490
|
};
|
|
489
491
|
|
|
492
|
+
type SagepilotPushPermission = "authorized" | "provisional" | "denied" | "not_determined";
|
|
493
|
+
type SagepilotPushMessage = {
|
|
494
|
+
data?: Record<string, string | undefined>;
|
|
495
|
+
notification?: {
|
|
496
|
+
title?: string;
|
|
497
|
+
body?: string;
|
|
498
|
+
imageUrl?: string;
|
|
499
|
+
};
|
|
500
|
+
};
|
|
501
|
+
type SagepilotPushEventType = "received" | "presentation_requested" | "opened" | "presentation_failed" | "destination_opened" | "destination_failed" | "action" | "dismissed" | "conversion";
|
|
502
|
+
type SagepilotPushPreferenceOverride = {
|
|
503
|
+
enabled?: boolean;
|
|
504
|
+
marketing_enabled?: boolean;
|
|
505
|
+
support_enabled?: boolean;
|
|
506
|
+
};
|
|
507
|
+
type SagepilotPushPreferences = SagepilotPushPreferenceOverride & {
|
|
508
|
+
web?: SagepilotPushPreferenceOverride;
|
|
509
|
+
app?: SagepilotPushPreferenceOverride;
|
|
510
|
+
};
|
|
511
|
+
/** Advertised support only; provider display remains the default until native handling is installed. */
|
|
512
|
+
type SagepilotPushCapabilities = {
|
|
513
|
+
version: 1;
|
|
514
|
+
display_modes: Array<"provider" | "sdk">;
|
|
515
|
+
media: Array<"image">;
|
|
516
|
+
addon_version?: string;
|
|
517
|
+
preferred_display_mode?: "provider" | "sdk";
|
|
518
|
+
};
|
|
519
|
+
type SagepilotPushObservation = {
|
|
520
|
+
event_id: string;
|
|
521
|
+
occurred_at: string;
|
|
522
|
+
sdk_version: string;
|
|
523
|
+
event_type: SagepilotPushEventType;
|
|
524
|
+
message: SagepilotPushMessage;
|
|
525
|
+
metadata?: Record<string, unknown>;
|
|
526
|
+
};
|
|
527
|
+
type SagepilotPushOwner = {
|
|
528
|
+
customerId: string;
|
|
529
|
+
endpointId: string;
|
|
530
|
+
};
|
|
531
|
+
type SagepilotPushRegistration = {
|
|
532
|
+
token: string;
|
|
533
|
+
provider: "fcm" | "apns";
|
|
534
|
+
permission: SagepilotPushPermission;
|
|
535
|
+
app_id?: string;
|
|
536
|
+
capabilities?: SagepilotPushCapabilities;
|
|
537
|
+
};
|
|
538
|
+
type SagepilotPushAdapter = {
|
|
539
|
+
capabilities?: SagepilotPushCapabilities;
|
|
540
|
+
/** Add-ons own native buffering and uploading through this scoped authenticated transport. */
|
|
541
|
+
start?: (context: {
|
|
542
|
+
workspaceId: string;
|
|
543
|
+
channelId: string;
|
|
544
|
+
sdkVersion: string;
|
|
545
|
+
owner: SagepilotPushOwner | null;
|
|
546
|
+
customerId: () => string | null;
|
|
547
|
+
upload: (event: SagepilotPushEvent) => Promise<unknown>;
|
|
548
|
+
onOpen: (message: SagepilotPushMessage) => void;
|
|
549
|
+
}) => Promise<() => void>;
|
|
550
|
+
setOwner?: (owner: SagepilotPushOwner | null) => Promise<void>;
|
|
551
|
+
track?: (type: SagepilotPushEventType, message: SagepilotPushMessage, metadata?: Record<string, unknown>, actionId?: string) => Promise<boolean>;
|
|
552
|
+
flush?: () => Promise<void>;
|
|
553
|
+
provider: "fcm" | "apns";
|
|
554
|
+
getPermission: () => Promise<SagepilotPushPermission>;
|
|
555
|
+
requestPermission: () => Promise<SagepilotPushPermission>;
|
|
556
|
+
getToken: () => Promise<string>;
|
|
557
|
+
onTokenRefresh: (callback: (token: string) => void) => () => void;
|
|
558
|
+
onMessage: (callback: (message: SagepilotPushMessage) => void) => () => void;
|
|
559
|
+
onOpened: (callback: (message: SagepilotPushMessage) => void) => () => void;
|
|
560
|
+
getInitialNotification: () => Promise<SagepilotPushMessage | null>;
|
|
561
|
+
};
|
|
562
|
+
type SagepilotPushConfig = {
|
|
563
|
+
/** Brand channel permission is granted independently of the chat channel. */
|
|
564
|
+
channelId?: string;
|
|
565
|
+
/** Durable storage is required; use the existing AsyncStorage or secure-storage adapter. */
|
|
566
|
+
storage: SagepilotCacheStorage;
|
|
567
|
+
/** Reuse the host installation ID, or let the SDK create and persist one. */
|
|
568
|
+
installationId?: string;
|
|
569
|
+
appId?: string;
|
|
570
|
+
appVersion?: string;
|
|
571
|
+
adapter?: SagepilotPushAdapter;
|
|
572
|
+
/** Optional foreground presentation. Background alerts are displayed by the OS. */
|
|
573
|
+
presentForeground?: (message: SagepilotPushMessage) => Promise<void>;
|
|
574
|
+
/** Host routing callback. Deep links must be checked against the app's allowlist. */
|
|
575
|
+
onOpen?: (message: SagepilotPushMessage) => void;
|
|
576
|
+
};
|
|
577
|
+
type SagepilotPushEvent = {
|
|
578
|
+
event_id: string;
|
|
579
|
+
occurred_at: string;
|
|
580
|
+
sdk_version?: string;
|
|
581
|
+
event_type: SagepilotPushEventType;
|
|
582
|
+
message_id: string;
|
|
583
|
+
endpoint_id: string;
|
|
584
|
+
event_token: string;
|
|
585
|
+
action_id?: string;
|
|
586
|
+
metadata: Record<string, unknown>;
|
|
587
|
+
};
|
|
588
|
+
type PushContext = {
|
|
589
|
+
workspaceId: string;
|
|
590
|
+
channelId: string;
|
|
591
|
+
platform: "ios" | "android";
|
|
592
|
+
brand?: boolean;
|
|
593
|
+
customerId: () => string | null;
|
|
594
|
+
request: <T>(path: string, method: string, body?: unknown) => Promise<T>;
|
|
595
|
+
onError: (error: unknown) => void;
|
|
596
|
+
};
|
|
597
|
+
/** Handles installation lifecycle and SDK engagement without loading a native push dependency. */
|
|
598
|
+
declare class SagepilotPush {
|
|
599
|
+
private readonly config;
|
|
600
|
+
private readonly context;
|
|
601
|
+
private readonly cache;
|
|
602
|
+
private pending;
|
|
603
|
+
private paused;
|
|
604
|
+
private stopped;
|
|
605
|
+
private started;
|
|
606
|
+
private flushPromise;
|
|
607
|
+
private retryTimer;
|
|
608
|
+
private retryAttempt;
|
|
609
|
+
private subscriptions;
|
|
610
|
+
/** Reuses a channel-specific durable cache and the SDK's authenticated request gateway. */
|
|
611
|
+
constructor(config: SagepilotPushConfig, context: PushContext);
|
|
612
|
+
/** Serializes state changes so registration, revocation and outbox writes cannot overwrite one another. */
|
|
613
|
+
private mutate;
|
|
614
|
+
/** Starts optional native listeners without prompting for notification permission. */
|
|
615
|
+
start(): Promise<void>;
|
|
616
|
+
/** Requests native permission only following an explicit host action, then resynchronizes the token. */
|
|
617
|
+
requestPermission(): Promise<SagepilotPushPermission>;
|
|
618
|
+
/** Refreshes an existing authorized installation after identity, token or permission changes. */
|
|
619
|
+
sync(token?: string): Promise<void>;
|
|
620
|
+
/** Registers a native token only for the current identified customer; the server verifies identity. */
|
|
621
|
+
register(input: SagepilotPushRegistration): Promise<{
|
|
622
|
+
endpoint_id: string;
|
|
623
|
+
}>;
|
|
624
|
+
/** Revokes this installation before credentials are discarded; failures retain the binding for retry. */
|
|
625
|
+
unregister(): Promise<void>;
|
|
626
|
+
/** Pauses refresh callbacks and revokes the installation before logout or identity replacement. */
|
|
627
|
+
pauseAndRevoke(): Promise<void>;
|
|
628
|
+
/** Allows token refresh again after the identity transition has finished. */
|
|
629
|
+
resume(): void;
|
|
630
|
+
/** Reads notification preferences for the current verified customer. */
|
|
631
|
+
getPreferences(): Promise<SagepilotPushPreferences>;
|
|
632
|
+
/** Saves customer consent independently of the device's notification permission. */
|
|
633
|
+
setPreferences(preferences: SagepilotPushPreferences): Promise<SagepilotPushPreferences>;
|
|
634
|
+
/** Persists actual callback receipt and presents only foreground messages when the host opted in. */
|
|
635
|
+
handleReceived(message: SagepilotPushMessage, foreground?: boolean): Promise<boolean>;
|
|
636
|
+
/** Persists a real tap before invoking host navigation, including cold-start taps. */
|
|
637
|
+
handleOpened(message: SagepilotPushMessage): Promise<boolean>;
|
|
638
|
+
/** Records SDK engagement; reuse actionId for duplicate callbacks and distinct IDs for separate conversions. */
|
|
639
|
+
track(type: SagepilotPushEventType, message: SagepilotPushMessage, metadata?: Record<string, unknown>, actionId?: string): Promise<boolean>;
|
|
640
|
+
/** Uploads preserved event metadata with the current request version and bounded exponential retries. */
|
|
641
|
+
flush(): Promise<void>;
|
|
642
|
+
/** Removes listeners and timers without revoking an installation merely because its UI was destroyed. */
|
|
643
|
+
stop(): void;
|
|
644
|
+
}
|
|
645
|
+
/** Adapts injected Firebase methods; native Firebase remains an optional host-owned dependency. */
|
|
646
|
+
declare function createFirebasePushAdapter(firebase: {
|
|
647
|
+
getToken: SagepilotPushAdapter["getToken"];
|
|
648
|
+
onTokenRefresh: SagepilotPushAdapter["onTokenRefresh"];
|
|
649
|
+
onMessage: SagepilotPushAdapter["onMessage"];
|
|
650
|
+
onNotificationOpenedApp: SagepilotPushAdapter["onOpened"];
|
|
651
|
+
getInitialNotification: SagepilotPushAdapter["getInitialNotification"];
|
|
652
|
+
}, permissions: {
|
|
653
|
+
getPermission: SagepilotPushAdapter["getPermission"];
|
|
654
|
+
requestPermission: SagepilotPushAdapter["requestPermission"];
|
|
655
|
+
}): SagepilotPushAdapter;
|
|
656
|
+
|
|
490
657
|
type Callback<T> = (value: T) => void;
|
|
491
658
|
declare const SagepilotChat: {
|
|
659
|
+
/** Provides push registration, preferences and SDK engagement callbacks. */
|
|
660
|
+
readonly push: SagepilotPush;
|
|
492
661
|
configure: (config: SagepilotMobileConfig) => Promise<SagepilotMobileConfigureResult>;
|
|
493
662
|
getSession: () => Promise<SagepilotSessionState>;
|
|
494
663
|
identify: (identity: SagepilotIdentity) => Promise<SagepilotIdentifyResult>;
|
|
664
|
+
/** Authorizes the configured brand on the same customer session used by chat. */
|
|
665
|
+
authorizePush: (identityToken: string) => Promise<void>;
|
|
495
666
|
logout: () => Promise<SagepilotLogoutResponse>;
|
|
496
667
|
getIdentityState: () => {
|
|
497
668
|
identified: boolean;
|
|
@@ -557,4 +728,40 @@ declare function SagepilotChatProvider({ children, closeLabel, loadingLabel }: S
|
|
|
557
728
|
|
|
558
729
|
declare function useSagepilotChat(): SagepilotChatHookState;
|
|
559
730
|
|
|
560
|
-
|
|
731
|
+
type SagepilotBrandPushConfig = {
|
|
732
|
+
key: string;
|
|
733
|
+
host?: string;
|
|
734
|
+
fetch?: typeof fetch;
|
|
735
|
+
tokenStorage: SagepilotTokenStorage;
|
|
736
|
+
push: SagepilotPushConfig;
|
|
737
|
+
onError: (error: unknown) => void;
|
|
738
|
+
};
|
|
739
|
+
/** Owns a brand push session independently of chat, reusing the shared installation lifecycle. */
|
|
740
|
+
declare class SagepilotBrandPush {
|
|
741
|
+
private readonly config;
|
|
742
|
+
readonly push: SagepilotPush;
|
|
743
|
+
private readonly scope;
|
|
744
|
+
private readonly tokens;
|
|
745
|
+
private readonly http;
|
|
746
|
+
private readonly host;
|
|
747
|
+
private session;
|
|
748
|
+
private pending;
|
|
749
|
+
private started;
|
|
750
|
+
private appStateSubscription;
|
|
751
|
+
/** Keeps brand credentials separate from chat and other workspace/channel sessions. */
|
|
752
|
+
constructor(config: SagepilotBrandPushConfig);
|
|
753
|
+
/** Serializes identity transitions so an old installation is revoked with its original credentials. */
|
|
754
|
+
private transition;
|
|
755
|
+
/** Sends through the shared version-stamped transport using the current brand credential. */
|
|
756
|
+
private request;
|
|
757
|
+
/** Restores durable credentials before registering listeners; never prompts for permission. */
|
|
758
|
+
start(): Promise<void>;
|
|
759
|
+
/** Exchanges a host-server proof, then revokes old ownership before adopting the new session. */
|
|
760
|
+
identify(identityToken: string): Promise<void>;
|
|
761
|
+
/** Retains credentials on failed revocation so logout can be retried safely. */
|
|
762
|
+
logout(): Promise<void>;
|
|
763
|
+
/** Stops listeners; call logout first when the customer is signing out. */
|
|
764
|
+
destroy(): Promise<void>;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
export { SAGEPILOT_DEFAULT_IMAGE_MAX_DIMENSION, SAGEPILOT_DEFAULT_IMAGE_MAX_FILE_SIZE_BYTES, SAGEPILOT_DEFAULT_IMAGE_QUALITY, type SagepilotBiometricsAdapter, type SagepilotBlobUtilLike, type SagepilotBootstrapChannelResponse, SagepilotBrandPush, type SagepilotBrandPushConfig, type SagepilotCacheStorage, SagepilotChat, SagepilotChatError, type SagepilotChatErrorCode, type SagepilotChatHookState, SagepilotChatProvider, type SagepilotChatProviderProps, type SagepilotConversationCreatedEvent, type SagepilotCreateFilePickerOptions, type SagepilotCreateFileStoreOptions, type SagepilotDeviceInfo, type SagepilotDeviceInfoAdapter, type SagepilotDocumentsPickerModule, type SagepilotFilePickerAdapter, SagepilotFilePickerError, type SagepilotFilePickerErrorCode, type SagepilotFilePickerRequest, type SagepilotFilePickerSource, type SagepilotFileReaderModule, type SagepilotIdentifyResult, type SagepilotIdentity, type SagepilotIdentityState, type SagepilotImagePickerModule, type SagepilotImagePickerResult, type SagepilotLifecycleState, type SagepilotLogoutResponse, type SagepilotMessageComposerOptions, type SagepilotMobileBehaviorConfig, type SagepilotMobileColorScheme, type SagepilotMobileConfig, type SagepilotMobileConfigureResult, type SagepilotMobileLauncherConfig, type SagepilotMobilePresentationConfig, type SagepilotMobilePresentationStyle, type SagepilotMobileResolvedLauncherConfig, type SagepilotMobileState, type SagepilotMobileSubscription, type SagepilotMobileThemeConfig, type SagepilotMobileThemeState, type SagepilotPersistedFileStore, type SagepilotPickedFile, SagepilotPush, type SagepilotPushAdapter, type SagepilotPushCapabilities, type SagepilotPushConfig, type SagepilotPushEvent, type SagepilotPushEventType, type SagepilotPushMessage, type SagepilotPushObservation, type SagepilotPushOwner, type SagepilotPushPermission, type SagepilotPushPreferenceOverride, type SagepilotPushPreferences, type SagepilotPushRegistration, type SagepilotSessionState, type SagepilotTokenStorage, type SagepilotUnreadState, createAsyncStorageCacheStorage, createFirebasePushAdapter, createKeychainTokenStorage, createSagepilotFilePicker, createSagepilotFileStore, ensureSagepilotAndroidCameraPermission, promptOpenSagepilotCameraSettings, useSagepilotChat };
|
package/dist/index.d.ts
CHANGED
|
@@ -270,6 +270,8 @@ type SagepilotBiometricsAdapter = {
|
|
|
270
270
|
authenticate: (prompt: string) => Promise<boolean>;
|
|
271
271
|
};
|
|
272
272
|
type SagepilotMobileConfig = {
|
|
273
|
+
/** Optional native push integration; requires durable storage and a verified identified session. */
|
|
274
|
+
push?: SagepilotPushConfig;
|
|
273
275
|
/**
|
|
274
276
|
* Public Sagepilot routing key in the format "workspace_id:channel_id".
|
|
275
277
|
* This is not an API secret and is safe to ship in a mobile app.
|
|
@@ -487,11 +489,180 @@ type SagepilotChatProviderProps = {
|
|
|
487
489
|
loadingLabel?: string;
|
|
488
490
|
};
|
|
489
491
|
|
|
492
|
+
type SagepilotPushPermission = "authorized" | "provisional" | "denied" | "not_determined";
|
|
493
|
+
type SagepilotPushMessage = {
|
|
494
|
+
data?: Record<string, string | undefined>;
|
|
495
|
+
notification?: {
|
|
496
|
+
title?: string;
|
|
497
|
+
body?: string;
|
|
498
|
+
imageUrl?: string;
|
|
499
|
+
};
|
|
500
|
+
};
|
|
501
|
+
type SagepilotPushEventType = "received" | "presentation_requested" | "opened" | "presentation_failed" | "destination_opened" | "destination_failed" | "action" | "dismissed" | "conversion";
|
|
502
|
+
type SagepilotPushPreferenceOverride = {
|
|
503
|
+
enabled?: boolean;
|
|
504
|
+
marketing_enabled?: boolean;
|
|
505
|
+
support_enabled?: boolean;
|
|
506
|
+
};
|
|
507
|
+
type SagepilotPushPreferences = SagepilotPushPreferenceOverride & {
|
|
508
|
+
web?: SagepilotPushPreferenceOverride;
|
|
509
|
+
app?: SagepilotPushPreferenceOverride;
|
|
510
|
+
};
|
|
511
|
+
/** Advertised support only; provider display remains the default until native handling is installed. */
|
|
512
|
+
type SagepilotPushCapabilities = {
|
|
513
|
+
version: 1;
|
|
514
|
+
display_modes: Array<"provider" | "sdk">;
|
|
515
|
+
media: Array<"image">;
|
|
516
|
+
addon_version?: string;
|
|
517
|
+
preferred_display_mode?: "provider" | "sdk";
|
|
518
|
+
};
|
|
519
|
+
type SagepilotPushObservation = {
|
|
520
|
+
event_id: string;
|
|
521
|
+
occurred_at: string;
|
|
522
|
+
sdk_version: string;
|
|
523
|
+
event_type: SagepilotPushEventType;
|
|
524
|
+
message: SagepilotPushMessage;
|
|
525
|
+
metadata?: Record<string, unknown>;
|
|
526
|
+
};
|
|
527
|
+
type SagepilotPushOwner = {
|
|
528
|
+
customerId: string;
|
|
529
|
+
endpointId: string;
|
|
530
|
+
};
|
|
531
|
+
type SagepilotPushRegistration = {
|
|
532
|
+
token: string;
|
|
533
|
+
provider: "fcm" | "apns";
|
|
534
|
+
permission: SagepilotPushPermission;
|
|
535
|
+
app_id?: string;
|
|
536
|
+
capabilities?: SagepilotPushCapabilities;
|
|
537
|
+
};
|
|
538
|
+
type SagepilotPushAdapter = {
|
|
539
|
+
capabilities?: SagepilotPushCapabilities;
|
|
540
|
+
/** Add-ons own native buffering and uploading through this scoped authenticated transport. */
|
|
541
|
+
start?: (context: {
|
|
542
|
+
workspaceId: string;
|
|
543
|
+
channelId: string;
|
|
544
|
+
sdkVersion: string;
|
|
545
|
+
owner: SagepilotPushOwner | null;
|
|
546
|
+
customerId: () => string | null;
|
|
547
|
+
upload: (event: SagepilotPushEvent) => Promise<unknown>;
|
|
548
|
+
onOpen: (message: SagepilotPushMessage) => void;
|
|
549
|
+
}) => Promise<() => void>;
|
|
550
|
+
setOwner?: (owner: SagepilotPushOwner | null) => Promise<void>;
|
|
551
|
+
track?: (type: SagepilotPushEventType, message: SagepilotPushMessage, metadata?: Record<string, unknown>, actionId?: string) => Promise<boolean>;
|
|
552
|
+
flush?: () => Promise<void>;
|
|
553
|
+
provider: "fcm" | "apns";
|
|
554
|
+
getPermission: () => Promise<SagepilotPushPermission>;
|
|
555
|
+
requestPermission: () => Promise<SagepilotPushPermission>;
|
|
556
|
+
getToken: () => Promise<string>;
|
|
557
|
+
onTokenRefresh: (callback: (token: string) => void) => () => void;
|
|
558
|
+
onMessage: (callback: (message: SagepilotPushMessage) => void) => () => void;
|
|
559
|
+
onOpened: (callback: (message: SagepilotPushMessage) => void) => () => void;
|
|
560
|
+
getInitialNotification: () => Promise<SagepilotPushMessage | null>;
|
|
561
|
+
};
|
|
562
|
+
type SagepilotPushConfig = {
|
|
563
|
+
/** Brand channel permission is granted independently of the chat channel. */
|
|
564
|
+
channelId?: string;
|
|
565
|
+
/** Durable storage is required; use the existing AsyncStorage or secure-storage adapter. */
|
|
566
|
+
storage: SagepilotCacheStorage;
|
|
567
|
+
/** Reuse the host installation ID, or let the SDK create and persist one. */
|
|
568
|
+
installationId?: string;
|
|
569
|
+
appId?: string;
|
|
570
|
+
appVersion?: string;
|
|
571
|
+
adapter?: SagepilotPushAdapter;
|
|
572
|
+
/** Optional foreground presentation. Background alerts are displayed by the OS. */
|
|
573
|
+
presentForeground?: (message: SagepilotPushMessage) => Promise<void>;
|
|
574
|
+
/** Host routing callback. Deep links must be checked against the app's allowlist. */
|
|
575
|
+
onOpen?: (message: SagepilotPushMessage) => void;
|
|
576
|
+
};
|
|
577
|
+
type SagepilotPushEvent = {
|
|
578
|
+
event_id: string;
|
|
579
|
+
occurred_at: string;
|
|
580
|
+
sdk_version?: string;
|
|
581
|
+
event_type: SagepilotPushEventType;
|
|
582
|
+
message_id: string;
|
|
583
|
+
endpoint_id: string;
|
|
584
|
+
event_token: string;
|
|
585
|
+
action_id?: string;
|
|
586
|
+
metadata: Record<string, unknown>;
|
|
587
|
+
};
|
|
588
|
+
type PushContext = {
|
|
589
|
+
workspaceId: string;
|
|
590
|
+
channelId: string;
|
|
591
|
+
platform: "ios" | "android";
|
|
592
|
+
brand?: boolean;
|
|
593
|
+
customerId: () => string | null;
|
|
594
|
+
request: <T>(path: string, method: string, body?: unknown) => Promise<T>;
|
|
595
|
+
onError: (error: unknown) => void;
|
|
596
|
+
};
|
|
597
|
+
/** Handles installation lifecycle and SDK engagement without loading a native push dependency. */
|
|
598
|
+
declare class SagepilotPush {
|
|
599
|
+
private readonly config;
|
|
600
|
+
private readonly context;
|
|
601
|
+
private readonly cache;
|
|
602
|
+
private pending;
|
|
603
|
+
private paused;
|
|
604
|
+
private stopped;
|
|
605
|
+
private started;
|
|
606
|
+
private flushPromise;
|
|
607
|
+
private retryTimer;
|
|
608
|
+
private retryAttempt;
|
|
609
|
+
private subscriptions;
|
|
610
|
+
/** Reuses a channel-specific durable cache and the SDK's authenticated request gateway. */
|
|
611
|
+
constructor(config: SagepilotPushConfig, context: PushContext);
|
|
612
|
+
/** Serializes state changes so registration, revocation and outbox writes cannot overwrite one another. */
|
|
613
|
+
private mutate;
|
|
614
|
+
/** Starts optional native listeners without prompting for notification permission. */
|
|
615
|
+
start(): Promise<void>;
|
|
616
|
+
/** Requests native permission only following an explicit host action, then resynchronizes the token. */
|
|
617
|
+
requestPermission(): Promise<SagepilotPushPermission>;
|
|
618
|
+
/** Refreshes an existing authorized installation after identity, token or permission changes. */
|
|
619
|
+
sync(token?: string): Promise<void>;
|
|
620
|
+
/** Registers a native token only for the current identified customer; the server verifies identity. */
|
|
621
|
+
register(input: SagepilotPushRegistration): Promise<{
|
|
622
|
+
endpoint_id: string;
|
|
623
|
+
}>;
|
|
624
|
+
/** Revokes this installation before credentials are discarded; failures retain the binding for retry. */
|
|
625
|
+
unregister(): Promise<void>;
|
|
626
|
+
/** Pauses refresh callbacks and revokes the installation before logout or identity replacement. */
|
|
627
|
+
pauseAndRevoke(): Promise<void>;
|
|
628
|
+
/** Allows token refresh again after the identity transition has finished. */
|
|
629
|
+
resume(): void;
|
|
630
|
+
/** Reads notification preferences for the current verified customer. */
|
|
631
|
+
getPreferences(): Promise<SagepilotPushPreferences>;
|
|
632
|
+
/** Saves customer consent independently of the device's notification permission. */
|
|
633
|
+
setPreferences(preferences: SagepilotPushPreferences): Promise<SagepilotPushPreferences>;
|
|
634
|
+
/** Persists actual callback receipt and presents only foreground messages when the host opted in. */
|
|
635
|
+
handleReceived(message: SagepilotPushMessage, foreground?: boolean): Promise<boolean>;
|
|
636
|
+
/** Persists a real tap before invoking host navigation, including cold-start taps. */
|
|
637
|
+
handleOpened(message: SagepilotPushMessage): Promise<boolean>;
|
|
638
|
+
/** Records SDK engagement; reuse actionId for duplicate callbacks and distinct IDs for separate conversions. */
|
|
639
|
+
track(type: SagepilotPushEventType, message: SagepilotPushMessage, metadata?: Record<string, unknown>, actionId?: string): Promise<boolean>;
|
|
640
|
+
/** Uploads preserved event metadata with the current request version and bounded exponential retries. */
|
|
641
|
+
flush(): Promise<void>;
|
|
642
|
+
/** Removes listeners and timers without revoking an installation merely because its UI was destroyed. */
|
|
643
|
+
stop(): void;
|
|
644
|
+
}
|
|
645
|
+
/** Adapts injected Firebase methods; native Firebase remains an optional host-owned dependency. */
|
|
646
|
+
declare function createFirebasePushAdapter(firebase: {
|
|
647
|
+
getToken: SagepilotPushAdapter["getToken"];
|
|
648
|
+
onTokenRefresh: SagepilotPushAdapter["onTokenRefresh"];
|
|
649
|
+
onMessage: SagepilotPushAdapter["onMessage"];
|
|
650
|
+
onNotificationOpenedApp: SagepilotPushAdapter["onOpened"];
|
|
651
|
+
getInitialNotification: SagepilotPushAdapter["getInitialNotification"];
|
|
652
|
+
}, permissions: {
|
|
653
|
+
getPermission: SagepilotPushAdapter["getPermission"];
|
|
654
|
+
requestPermission: SagepilotPushAdapter["requestPermission"];
|
|
655
|
+
}): SagepilotPushAdapter;
|
|
656
|
+
|
|
490
657
|
type Callback<T> = (value: T) => void;
|
|
491
658
|
declare const SagepilotChat: {
|
|
659
|
+
/** Provides push registration, preferences and SDK engagement callbacks. */
|
|
660
|
+
readonly push: SagepilotPush;
|
|
492
661
|
configure: (config: SagepilotMobileConfig) => Promise<SagepilotMobileConfigureResult>;
|
|
493
662
|
getSession: () => Promise<SagepilotSessionState>;
|
|
494
663
|
identify: (identity: SagepilotIdentity) => Promise<SagepilotIdentifyResult>;
|
|
664
|
+
/** Authorizes the configured brand on the same customer session used by chat. */
|
|
665
|
+
authorizePush: (identityToken: string) => Promise<void>;
|
|
495
666
|
logout: () => Promise<SagepilotLogoutResponse>;
|
|
496
667
|
getIdentityState: () => {
|
|
497
668
|
identified: boolean;
|
|
@@ -557,4 +728,40 @@ declare function SagepilotChatProvider({ children, closeLabel, loadingLabel }: S
|
|
|
557
728
|
|
|
558
729
|
declare function useSagepilotChat(): SagepilotChatHookState;
|
|
559
730
|
|
|
560
|
-
|
|
731
|
+
type SagepilotBrandPushConfig = {
|
|
732
|
+
key: string;
|
|
733
|
+
host?: string;
|
|
734
|
+
fetch?: typeof fetch;
|
|
735
|
+
tokenStorage: SagepilotTokenStorage;
|
|
736
|
+
push: SagepilotPushConfig;
|
|
737
|
+
onError: (error: unknown) => void;
|
|
738
|
+
};
|
|
739
|
+
/** Owns a brand push session independently of chat, reusing the shared installation lifecycle. */
|
|
740
|
+
declare class SagepilotBrandPush {
|
|
741
|
+
private readonly config;
|
|
742
|
+
readonly push: SagepilotPush;
|
|
743
|
+
private readonly scope;
|
|
744
|
+
private readonly tokens;
|
|
745
|
+
private readonly http;
|
|
746
|
+
private readonly host;
|
|
747
|
+
private session;
|
|
748
|
+
private pending;
|
|
749
|
+
private started;
|
|
750
|
+
private appStateSubscription;
|
|
751
|
+
/** Keeps brand credentials separate from chat and other workspace/channel sessions. */
|
|
752
|
+
constructor(config: SagepilotBrandPushConfig);
|
|
753
|
+
/** Serializes identity transitions so an old installation is revoked with its original credentials. */
|
|
754
|
+
private transition;
|
|
755
|
+
/** Sends through the shared version-stamped transport using the current brand credential. */
|
|
756
|
+
private request;
|
|
757
|
+
/** Restores durable credentials before registering listeners; never prompts for permission. */
|
|
758
|
+
start(): Promise<void>;
|
|
759
|
+
/** Exchanges a host-server proof, then revokes old ownership before adopting the new session. */
|
|
760
|
+
identify(identityToken: string): Promise<void>;
|
|
761
|
+
/** Retains credentials on failed revocation so logout can be retried safely. */
|
|
762
|
+
logout(): Promise<void>;
|
|
763
|
+
/** Stops listeners; call logout first when the customer is signing out. */
|
|
764
|
+
destroy(): Promise<void>;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
export { SAGEPILOT_DEFAULT_IMAGE_MAX_DIMENSION, SAGEPILOT_DEFAULT_IMAGE_MAX_FILE_SIZE_BYTES, SAGEPILOT_DEFAULT_IMAGE_QUALITY, type SagepilotBiometricsAdapter, type SagepilotBlobUtilLike, type SagepilotBootstrapChannelResponse, SagepilotBrandPush, type SagepilotBrandPushConfig, type SagepilotCacheStorage, SagepilotChat, SagepilotChatError, type SagepilotChatErrorCode, type SagepilotChatHookState, SagepilotChatProvider, type SagepilotChatProviderProps, type SagepilotConversationCreatedEvent, type SagepilotCreateFilePickerOptions, type SagepilotCreateFileStoreOptions, type SagepilotDeviceInfo, type SagepilotDeviceInfoAdapter, type SagepilotDocumentsPickerModule, type SagepilotFilePickerAdapter, SagepilotFilePickerError, type SagepilotFilePickerErrorCode, type SagepilotFilePickerRequest, type SagepilotFilePickerSource, type SagepilotFileReaderModule, type SagepilotIdentifyResult, type SagepilotIdentity, type SagepilotIdentityState, type SagepilotImagePickerModule, type SagepilotImagePickerResult, type SagepilotLifecycleState, type SagepilotLogoutResponse, type SagepilotMessageComposerOptions, type SagepilotMobileBehaviorConfig, type SagepilotMobileColorScheme, type SagepilotMobileConfig, type SagepilotMobileConfigureResult, type SagepilotMobileLauncherConfig, type SagepilotMobilePresentationConfig, type SagepilotMobilePresentationStyle, type SagepilotMobileResolvedLauncherConfig, type SagepilotMobileState, type SagepilotMobileSubscription, type SagepilotMobileThemeConfig, type SagepilotMobileThemeState, type SagepilotPersistedFileStore, type SagepilotPickedFile, SagepilotPush, type SagepilotPushAdapter, type SagepilotPushCapabilities, type SagepilotPushConfig, type SagepilotPushEvent, type SagepilotPushEventType, type SagepilotPushMessage, type SagepilotPushObservation, type SagepilotPushOwner, type SagepilotPushPermission, type SagepilotPushPreferenceOverride, type SagepilotPushPreferences, type SagepilotPushRegistration, type SagepilotSessionState, type SagepilotTokenStorage, type SagepilotUnreadState, createAsyncStorageCacheStorage, createFirebasePushAdapter, createKeychainTokenStorage, createSagepilotFilePicker, createSagepilotFileStore, ensureSagepilotAndroidCameraPermission, promptOpenSagepilotCameraSettings, useSagepilotChat };
|