@scalemule/sdk 0.0.21 → 0.0.23
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 +178 -15
- package/dist/index.d.ts +178 -15
- package/dist/index.js +308 -2
- package/dist/index.mjs +306 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2534,14 +2534,24 @@ declare class FlagsService extends ServiceModule {
|
|
|
2534
2534
|
* Email, SMS, push notifications with template support.
|
|
2535
2535
|
*
|
|
2536
2536
|
* Routes:
|
|
2537
|
-
* POST /email/send
|
|
2538
|
-
* POST /email/templates/{name}/send
|
|
2539
|
-
* POST /sms/send
|
|
2540
|
-
* POST /sms/templates/{name}/send
|
|
2541
|
-
* POST /push/send
|
|
2542
|
-
* POST /push/register
|
|
2543
|
-
* DELETE /push/tokens/{token}
|
|
2544
|
-
*
|
|
2537
|
+
* POST /email/send → send email
|
|
2538
|
+
* POST /email/templates/{name}/send → send templated email
|
|
2539
|
+
* POST /sms/send → send SMS
|
|
2540
|
+
* POST /sms/templates/{name}/send → send templated SMS
|
|
2541
|
+
* POST /push/send → send push notification
|
|
2542
|
+
* POST /push/register → register push token
|
|
2543
|
+
* DELETE /push/tokens/{token} → unregister push token (legacy)
|
|
2544
|
+
* DELETE /push/tokens/by-id/{id} → unregister push token by ID
|
|
2545
|
+
* PUT /push/tokens/by-id/{id}/user → associate token with authenticated user
|
|
2546
|
+
* DELETE /push/tokens/by-id/{id}/user → disassociate user (logout)
|
|
2547
|
+
* GET /push/settings/me → get push settings for current app
|
|
2548
|
+
* GET /push/topics → list notification topics
|
|
2549
|
+
* POST /push/topics/{id}/subscribe → subscribe to topic
|
|
2550
|
+
* DELETE /push/topics/{id}/subscribe → unsubscribe from topic
|
|
2551
|
+
* GET /push/subscriptions → list subscriptions
|
|
2552
|
+
* GET /push/preferences → get push preferences
|
|
2553
|
+
* PUT /push/preferences → update push preferences
|
|
2554
|
+
* GET /messages/{id} → get message status
|
|
2545
2555
|
*/
|
|
2546
2556
|
|
|
2547
2557
|
interface MessageStatus {
|
|
@@ -2559,10 +2569,68 @@ interface MessageStatus {
|
|
|
2559
2569
|
error_message?: string;
|
|
2560
2570
|
}
|
|
2561
2571
|
interface PushToken {
|
|
2562
|
-
|
|
2563
|
-
platform:
|
|
2572
|
+
id: string;
|
|
2573
|
+
platform: 'ios' | 'android' | 'web';
|
|
2574
|
+
user_id?: string;
|
|
2575
|
+
is_active: boolean;
|
|
2564
2576
|
created_at: string;
|
|
2565
2577
|
}
|
|
2578
|
+
interface PushTokenAssociationResult {
|
|
2579
|
+
id: string;
|
|
2580
|
+
user_id: string;
|
|
2581
|
+
subscriptions_copied: number;
|
|
2582
|
+
}
|
|
2583
|
+
interface PushSettings {
|
|
2584
|
+
push_enabled: boolean;
|
|
2585
|
+
webpush_enabled: boolean;
|
|
2586
|
+
vapid_public_key: string | null;
|
|
2587
|
+
fcm_enabled: boolean;
|
|
2588
|
+
apns_enabled: boolean;
|
|
2589
|
+
silent_push_enabled: boolean;
|
|
2590
|
+
rich_media_enabled: boolean;
|
|
2591
|
+
broadcast_enabled: boolean;
|
|
2592
|
+
max_per_user_per_hour: number;
|
|
2593
|
+
max_per_user_per_day: number;
|
|
2594
|
+
}
|
|
2595
|
+
interface PushTopic {
|
|
2596
|
+
id: string;
|
|
2597
|
+
name: string;
|
|
2598
|
+
display_name: string;
|
|
2599
|
+
description: string | null;
|
|
2600
|
+
is_default: boolean;
|
|
2601
|
+
is_visible: boolean;
|
|
2602
|
+
subscriber_count?: number;
|
|
2603
|
+
}
|
|
2604
|
+
interface PushSubscriptionInfo {
|
|
2605
|
+
id: string;
|
|
2606
|
+
topic_id: string;
|
|
2607
|
+
topic_name?: string;
|
|
2608
|
+
}
|
|
2609
|
+
interface PushPreferences {
|
|
2610
|
+
marketing_enabled: boolean;
|
|
2611
|
+
transactional_enabled: boolean;
|
|
2612
|
+
alert_enabled: boolean;
|
|
2613
|
+
quiet_hours_enabled: boolean;
|
|
2614
|
+
quiet_hours_start: string | null;
|
|
2615
|
+
quiet_hours_end: string | null;
|
|
2616
|
+
quiet_hours_tz: string | null;
|
|
2617
|
+
}
|
|
2618
|
+
interface WebPushSubscriptionData {
|
|
2619
|
+
endpoint: string;
|
|
2620
|
+
keys: {
|
|
2621
|
+
p256dh: string;
|
|
2622
|
+
auth: string;
|
|
2623
|
+
};
|
|
2624
|
+
}
|
|
2625
|
+
interface RegisterPushTokenData {
|
|
2626
|
+
token: string;
|
|
2627
|
+
platform: 'ios' | 'android' | 'web';
|
|
2628
|
+
device_id?: string;
|
|
2629
|
+
subscription?: WebPushSubscriptionData;
|
|
2630
|
+
app_version?: string;
|
|
2631
|
+
os_version?: string;
|
|
2632
|
+
device_model?: string;
|
|
2633
|
+
}
|
|
2566
2634
|
declare class CommunicationService extends ServiceModule {
|
|
2567
2635
|
protected basePath: string;
|
|
2568
2636
|
sendEmail(data: {
|
|
@@ -2590,13 +2658,23 @@ declare class CommunicationService extends ServiceModule {
|
|
|
2590
2658
|
body: string;
|
|
2591
2659
|
data?: Record<string, unknown>;
|
|
2592
2660
|
}, options?: RequestOptions): Promise<ApiResponse<MessageStatus>>;
|
|
2593
|
-
registerPushToken(data:
|
|
2594
|
-
|
|
2595
|
-
platform: string;
|
|
2596
|
-
}, options?: RequestOptions): Promise<ApiResponse<PushToken>>;
|
|
2661
|
+
registerPushToken(data: RegisterPushTokenData, options?: RequestOptions): Promise<ApiResponse<PushToken>>;
|
|
2662
|
+
/** @deprecated Use unregisterPushTokenById() for web push tokens */
|
|
2597
2663
|
unregisterPushToken(token: string, options?: RequestOptions): Promise<ApiResponse<{
|
|
2598
2664
|
unregistered: boolean;
|
|
2599
2665
|
}>>;
|
|
2666
|
+
unregisterPushTokenById(id: string, options?: RequestOptions): Promise<ApiResponse<void>>;
|
|
2667
|
+
associatePushTokenUserById(id: string, options?: RequestOptions): Promise<ApiResponse<PushTokenAssociationResult>>;
|
|
2668
|
+
disassociatePushTokenUser(id: string, options?: RequestOptions): Promise<ApiResponse<void>>;
|
|
2669
|
+
getMyPushSettings(options?: RequestOptions): Promise<ApiResponse<PushSettings>>;
|
|
2670
|
+
listTopics(options?: RequestOptions): Promise<ApiResponse<PushTopic[]>>;
|
|
2671
|
+
subscribeTopic(topicId: string, data?: {
|
|
2672
|
+
push_token_id?: string;
|
|
2673
|
+
}, options?: RequestOptions): Promise<ApiResponse<void>>;
|
|
2674
|
+
unsubscribeTopic(topicId: string, options?: RequestOptions): Promise<ApiResponse<void>>;
|
|
2675
|
+
listSubscriptions(options?: RequestOptions): Promise<ApiResponse<PushSubscriptionInfo[]>>;
|
|
2676
|
+
getPushPreferences(options?: RequestOptions): Promise<ApiResponse<PushPreferences>>;
|
|
2677
|
+
updatePushPreferences(data: Partial<PushPreferences>, options?: RequestOptions): Promise<ApiResponse<PushPreferences>>;
|
|
2600
2678
|
getMessageStatus(id: string, options?: RequestOptions): Promise<ApiResponse<MessageStatus>>;
|
|
2601
2679
|
/** @deprecated Use sendSms() instead */
|
|
2602
2680
|
sendSMS(data: {
|
|
@@ -2612,6 +2690,91 @@ declare class CommunicationService extends ServiceModule {
|
|
|
2612
2690
|
}): Promise<ApiResponse<MessageStatus>>;
|
|
2613
2691
|
}
|
|
2614
2692
|
|
|
2693
|
+
/**
|
|
2694
|
+
* WebPushManager — Browser push notification subscription manager
|
|
2695
|
+
*
|
|
2696
|
+
* Handles service worker registration, Notification permission prompts,
|
|
2697
|
+
* PushManager.subscribe(), and backend token registration.
|
|
2698
|
+
*
|
|
2699
|
+
* All HTTP calls go through an injectable PushApiFetcher — this lets
|
|
2700
|
+
* the NextJS hook inject a fetcher that routes through /api/push/* proxy,
|
|
2701
|
+
* while the React hook injects one that calls the gateway directly.
|
|
2702
|
+
*/
|
|
2703
|
+
|
|
2704
|
+
interface PushApiFetcher {
|
|
2705
|
+
getSettings(): Promise<PushSettings>;
|
|
2706
|
+
registerToken(data: RegisterPushTokenData): Promise<{
|
|
2707
|
+
id: string;
|
|
2708
|
+
}>;
|
|
2709
|
+
unregisterToken(tokenId: string): Promise<void>;
|
|
2710
|
+
associateUser(tokenId: string): Promise<void>;
|
|
2711
|
+
disassociateUser(tokenId: string): Promise<void>;
|
|
2712
|
+
}
|
|
2713
|
+
interface WebPushManagerOptions {
|
|
2714
|
+
/** Service worker URL (default: '/sw.js') */
|
|
2715
|
+
serviceWorkerUrl?: string;
|
|
2716
|
+
/** Required: HTTP transport abstraction */
|
|
2717
|
+
fetcher: PushApiFetcher;
|
|
2718
|
+
}
|
|
2719
|
+
declare class WebPushManager {
|
|
2720
|
+
private fetcher;
|
|
2721
|
+
private swUrl;
|
|
2722
|
+
private state;
|
|
2723
|
+
private registration;
|
|
2724
|
+
constructor(options: WebPushManagerOptions);
|
|
2725
|
+
/** Whether the browser supports Web Push */
|
|
2726
|
+
isSupported(): boolean;
|
|
2727
|
+
/** Current notification permission state */
|
|
2728
|
+
getPermissionState(): NotificationPermission | 'unsupported';
|
|
2729
|
+
/** Request notification permission from the user */
|
|
2730
|
+
requestPermission(): Promise<NotificationPermission>;
|
|
2731
|
+
/**
|
|
2732
|
+
* Full subscribe flow:
|
|
2733
|
+
* 1. Check browser support
|
|
2734
|
+
* 2. Request notification permission
|
|
2735
|
+
* 3. Register service worker
|
|
2736
|
+
* 4. Fetch VAPID public key from backend
|
|
2737
|
+
* 5. PushManager.subscribe() with VAPID key
|
|
2738
|
+
* 6. Register token with backend
|
|
2739
|
+
*
|
|
2740
|
+
* @param deviceId Optional device identifier for anonymous users.
|
|
2741
|
+
* If not provided, generates a random UUID stored in localStorage.
|
|
2742
|
+
*/
|
|
2743
|
+
subscribe(deviceId?: string): Promise<{
|
|
2744
|
+
tokenId: string;
|
|
2745
|
+
endpoint: string;
|
|
2746
|
+
} | null>;
|
|
2747
|
+
/** Unsubscribe from browser push and deregister token */
|
|
2748
|
+
unsubscribe(): Promise<void>;
|
|
2749
|
+
/** Link push token to the currently authenticated user (call after login) */
|
|
2750
|
+
associateUser(): Promise<void>;
|
|
2751
|
+
/** Clear user association from push token (call before logout) */
|
|
2752
|
+
disassociateUser(): Promise<void>;
|
|
2753
|
+
/** Check if currently subscribed to push notifications */
|
|
2754
|
+
isSubscribed(): Promise<boolean>;
|
|
2755
|
+
/** Get the active PushSubscription from the service worker */
|
|
2756
|
+
getSubscription(): Promise<PushSubscription | null>;
|
|
2757
|
+
/** Get the stored token ID (for external use) */
|
|
2758
|
+
getTokenId(): string | null;
|
|
2759
|
+
private persistState;
|
|
2760
|
+
private clearState;
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2763
|
+
/**
|
|
2764
|
+
* Web Push Service Worker Template
|
|
2765
|
+
*
|
|
2766
|
+
* Exports a JavaScript string that can be served as a service worker.
|
|
2767
|
+
* Customers can either:
|
|
2768
|
+
* 1. Use this string with a Next.js API route to serve dynamically
|
|
2769
|
+
* 2. Copy the content into their own public/sw.js
|
|
2770
|
+
*
|
|
2771
|
+
* The service worker handles:
|
|
2772
|
+
* - push events: parse JSON, show notification
|
|
2773
|
+
* - notificationclick: open/focus app window
|
|
2774
|
+
* - message posting to client pages for foreground handling
|
|
2775
|
+
*/
|
|
2776
|
+
declare const WEB_PUSH_SERVICE_WORKER = "\n// ScaleMule Push Notification Service Worker\n\nself.addEventListener('push', function(event) {\n if (!event.data) return;\n\n var data;\n try {\n data = event.data.json();\n } catch (e) {\n data = { title: 'New Notification', body: event.data.text() };\n }\n\n var title = data.title || 'Notification';\n var options = {\n body: data.body || '',\n icon: data.icon || undefined,\n image: data.image || undefined,\n badge: data.badge || undefined,\n data: data.data || data,\n tag: data.tag || undefined,\n actions: data.actions || undefined,\n requireInteraction: data.requireInteraction || false,\n };\n\n // Show the notification\n event.waitUntil(\n self.registration.showNotification(title, options)\n .then(function() {\n // Post message to all client pages for foreground handling\n return self.clients.matchAll({ type: 'window', includeUncontrolled: true });\n })\n .then(function(clients) {\n clients.forEach(function(client) {\n client.postMessage({\n type: 'push-received',\n payload: data,\n });\n });\n })\n );\n});\n\nself.addEventListener('notificationclick', function(event) {\n event.notification.close();\n\n var url = '/';\n if (event.notification.data && event.notification.data.url) {\n url = event.notification.data.url;\n }\n\n // Handle action button clicks\n if (event.action && event.notification.data && event.notification.data.actions) {\n var action = event.notification.data.actions.find(function(a) {\n return a.action === event.action;\n });\n if (action && action.url) {\n url = action.url;\n }\n }\n\n event.waitUntil(\n self.clients.matchAll({ type: 'window', includeUncontrolled: true })\n .then(function(clientList) {\n // Try to focus an existing window\n for (var i = 0; i < clientList.length; i++) {\n var client = clientList[i];\n if (client.url.indexOf(self.registration.scope) !== -1 && 'focus' in client) {\n client.focus();\n client.navigate(url);\n return;\n }\n }\n // Open a new window if none exists\n if (self.clients.openWindow) {\n return self.clients.openWindow(url);\n }\n })\n );\n});\n";
|
|
2777
|
+
|
|
2615
2778
|
/**
|
|
2616
2779
|
* Scheduler Service Module
|
|
2617
2780
|
*
|
|
@@ -5278,4 +5441,4 @@ declare class ScaleMule {
|
|
|
5278
5441
|
getClient(): ScaleMuleClient;
|
|
5279
5442
|
}
|
|
5280
5443
|
|
|
5281
|
-
export { type AccountBalance, AccountsService, type ActiveUsers, type ActivityItem, AgentAuthService, AgentModelsService, type AgentProfile, AgentProjectsService, type AgentResponse, type AgentSecurityPolicy, AgentSessionsService, type AgentSigningKey, type AgentToken, type AgentToolEntitlement, AgentToolsService, type Workspace as AgentWorkspace, AgentsService, type AggregateOptions, type AggregateResult, type AnalyticsEvent, AnalyticsService, type ApiError, type ApiKey, type ApiResponse, type Appeal, type Application, type Attachment, type Attendee, type AuditLog, type AuthRegisterAgentRequest, type AuthRegisterAgentResponse, AuthService, type AuthSession, type AuthUser, type BackupCodes, BillingService, type CacheEntry, CacheService, type CalendarEvent, type CatalogEntry, CatalogService, type ChatMessage, type ChatReaction, ChatService, type ClaimResult, type Client, type ClientContext, type Collection, type Comment, CommunicationService, type CompletedPart, ComplianceService, type CompressionConfig, type ConnectedAccount, type ConnectedAccountSubscription, type ConnectedSetupIntentResponse, type ConnectedSubscriptionListParams, type ConnectionStatus, type ContentFlag, type Conversation, type CostReportDay, type CreateFlagRequest, type CreateRuleRequest, type CreateSegmentRequest, type CreateSessionResponse, type CreateVariantRequest, type Credential, type CredentialScope, type Customer, type DataAccessPolicy, type DataExport, DataService, type DataSource, type DeadLetterJob, type DeviceInfo, type Document, type ErrorCode, ErrorCodes, type EventAggregation, EventsService, type FileInfo, type FlagAuditEntry, type FlagCheck, type FlagCondition, FlagContentService, type FlagDefinition, type FlagDetail, type FlagEnvironment, type FlagEvaluation, type FlagSegment, type FlagVariant, FlagsService, type FollowStatus, type FunctionExecution, type FunctionMetrics, FunctionsService, type Funnel, type FunnelConversion, type GdprRequest, type GrantInfo, type GraphEdge, type GraphNode, GraphService, IdentityService, type IdentityType, type IncomingRequestLike, type Invoice, type JobExecution, type JobStats, type Leaderboard, type LeaderboardEntry, LeaderboardService, type Like, type Listing, ListingsService, type LogEntry, type LogInput, type LogQueryParams, type LogQueryResponse, type LogRecord, LoggerService, type LoginActivitySummary, type LoginDeviceInfo, type LoginHistoryEntry, type LoginRiskInfo, type MessageCallback, type MessageStatus, type MetricDataPoint, type MfaStatus, type Model, type ModelEntitlement, type ModelPricing, type ModelProvider, type UsageSummary as ModelUsageSummary, type MultipartCompleteResponse, type MultipartConfig, type MultipartPartUrl, type MultipartPartUrlsResponse, type MultipartStartResponse, type NetworkClass, type OAuthProvider, type OAuthUrl, OrchestratorService, PHOTO_BREAKPOINTS, type PaginatedResponse, type PaginationMetadata, type PaginationParams, type PartResult, type PartUrl, type Participant, type Payment, type PaymentListParams, type PaymentMethod, type PaymentStatusResponse, type Payout, type PayoutSchedule, type PermissionCheck, type PermissionMatrix, PermissionsService, type PhotoInfo, PhotoService, type Pipeline, type PipelineVersion, type Policy, type PresenceCallback, type PresenceEvent, type PresignedUploadResponse, type Price, type Product, type Project, type ProjectDocument, type ProjectGrant, type ProjectMember, type PushToken, type QueryFilter, type QueryOptions, type QuerySort, type QueueJob, QueueService, type ReadStatus, RealtimeService, type RedeemResult, type Refund, type RegisterAgentRequest, type RegisterAgentResponse, type RequestOptions, type ResumeSession, type Role, type RuntimeTemplate, type RuntimeTemplateVersion, type S3MultipartOptions, type S3MultipartResult, type S3SingleUploadOptions, type S3SingleUploadResult, type S3UploadProgress, ScaleMule, ScaleMuleClient, type ScaleMuleConfig, type SchedulerJob, SchedulerService, type SearchResult, SearchService, type SecurityLayers, type ServerlessFunction, type ServiceHealth, ServiceModule, type Session, type SessionArtifact, type SessionInfo, type SessionLog, type SessionPoolEntry, type Severity, type ShortestPathResult, type SignedUrlResponse, type SocialPost, SocialService, type SocialUser, type SsoConfig, type StatusCallback, type StorageAdapter, StorageService, type StrategyResult, type SubmitResult, type Subscription, type TargetingRule, type Task, type TaskAttempt, type TaskTransition, type Team, type TeamInvitation, type TeamMember, TeamsService, type TelemetryPayload, type Tool, type ToolCapability, type ToolIntegration, type TopEvent, type TotpSetup, type Transaction, type TransactionListParams, type TransactionSummary, type TransactionSummaryParams, type Transfer, type TransformOptions, type TransformResult, type TraversalResult, type UpdateFlagRequest, type UpdateRuleRequest, type UpdateSegmentRequest, type UpdateVariantRequest, type UploadCompleteResponse, type UploadEngineConfig, type UploadFailureReport, type UploadFailureReportResponse, type UploadOptions, type UploadPlan, UploadResumeStore, type UploadStrategy, UploadTelemetry, type UploadTelemetryConfig, type UploadTelemetryEvent, type UpsertEnvironmentRequest, type UsageRecord, type UsageSummary$1 as UsageSummary, type UserRank, type VideoInfo, VideoService, type VideoUploadOptions, type Webhook, WebhooksService, type Workflow, type WorkflowExecution, type Workspace$1 as Workspace, type WorkspaceInvitation, type WorkspaceMember, WorkspacesService, buildClientContextHeaders, calculateTotalParts, canPerform, createUploadPlan, ScaleMule as default, detectNetworkClass, extractClientContext, generateUploadSessionId, getMeasuredBandwidthMbps, getPartRange, hasMinRoleLevel, resolveStrategy, uploadMultipartToS3, uploadSingleToS3, validateIP };
|
|
5444
|
+
export { type AccountBalance, AccountsService, type ActiveUsers, type ActivityItem, AgentAuthService, AgentModelsService, type AgentProfile, AgentProjectsService, type AgentResponse, type AgentSecurityPolicy, AgentSessionsService, type AgentSigningKey, type AgentToken, type AgentToolEntitlement, AgentToolsService, type Workspace as AgentWorkspace, AgentsService, type AggregateOptions, type AggregateResult, type AnalyticsEvent, AnalyticsService, type ApiError, type ApiKey, type ApiResponse, type Appeal, type Application, type Attachment, type Attendee, type AuditLog, type AuthRegisterAgentRequest, type AuthRegisterAgentResponse, AuthService, type AuthSession, type AuthUser, type BackupCodes, BillingService, type CacheEntry, CacheService, type CalendarEvent, type CatalogEntry, CatalogService, type ChatMessage, type ChatReaction, ChatService, type ClaimResult, type Client, type ClientContext, type Collection, type Comment, CommunicationService, type CompletedPart, ComplianceService, type CompressionConfig, type ConnectedAccount, type ConnectedAccountSubscription, type ConnectedSetupIntentResponse, type ConnectedSubscriptionListParams, type ConnectionStatus, type ContentFlag, type Conversation, type CostReportDay, type CreateFlagRequest, type CreateRuleRequest, type CreateSegmentRequest, type CreateSessionResponse, type CreateVariantRequest, type Credential, type CredentialScope, type Customer, type DataAccessPolicy, type DataExport, DataService, type DataSource, type DeadLetterJob, type DeviceInfo, type Document, type ErrorCode, ErrorCodes, type EventAggregation, EventsService, type FileInfo, type FlagAuditEntry, type FlagCheck, type FlagCondition, FlagContentService, type FlagDefinition, type FlagDetail, type FlagEnvironment, type FlagEvaluation, type FlagSegment, type FlagVariant, FlagsService, type FollowStatus, type FunctionExecution, type FunctionMetrics, FunctionsService, type Funnel, type FunnelConversion, type GdprRequest, type GrantInfo, type GraphEdge, type GraphNode, GraphService, IdentityService, type IdentityType, type IncomingRequestLike, type Invoice, type JobExecution, type JobStats, type Leaderboard, type LeaderboardEntry, LeaderboardService, type Like, type Listing, ListingsService, type LogEntry, type LogInput, type LogQueryParams, type LogQueryResponse, type LogRecord, LoggerService, type LoginActivitySummary, type LoginDeviceInfo, type LoginHistoryEntry, type LoginRiskInfo, type MessageCallback, type MessageStatus, type MetricDataPoint, type MfaStatus, type Model, type ModelEntitlement, type ModelPricing, type ModelProvider, type UsageSummary as ModelUsageSummary, type MultipartCompleteResponse, type MultipartConfig, type MultipartPartUrl, type MultipartPartUrlsResponse, type MultipartStartResponse, type NetworkClass, type OAuthProvider, type OAuthUrl, OrchestratorService, PHOTO_BREAKPOINTS, type PaginatedResponse, type PaginationMetadata, type PaginationParams, type PartResult, type PartUrl, type Participant, type Payment, type PaymentListParams, type PaymentMethod, type PaymentStatusResponse, type Payout, type PayoutSchedule, type PermissionCheck, type PermissionMatrix, PermissionsService, type PhotoInfo, PhotoService, type Pipeline, type PipelineVersion, type Policy, type PresenceCallback, type PresenceEvent, type PresignedUploadResponse, type Price, type Product, type Project, type ProjectDocument, type ProjectGrant, type ProjectMember, type PushApiFetcher, type PushPreferences, type PushSettings, type PushSubscriptionInfo, type PushToken, type PushTokenAssociationResult, type PushTopic, type QueryFilter, type QueryOptions, type QuerySort, type QueueJob, QueueService, type ReadStatus, RealtimeService, type RedeemResult, type Refund, type RegisterAgentRequest, type RegisterAgentResponse, type RegisterPushTokenData, type RequestOptions, type ResumeSession, type Role, type RuntimeTemplate, type RuntimeTemplateVersion, type S3MultipartOptions, type S3MultipartResult, type S3SingleUploadOptions, type S3SingleUploadResult, type S3UploadProgress, ScaleMule, ScaleMuleClient, type ScaleMuleConfig, type SchedulerJob, SchedulerService, type SearchResult, SearchService, type SecurityLayers, type ServerlessFunction, type ServiceHealth, ServiceModule, type Session, type SessionArtifact, type SessionInfo, type SessionLog, type SessionPoolEntry, type Severity, type ShortestPathResult, type SignedUrlResponse, type SocialPost, SocialService, type SocialUser, type SsoConfig, type StatusCallback, type StorageAdapter, StorageService, type StrategyResult, type SubmitResult, type Subscription, type TargetingRule, type Task, type TaskAttempt, type TaskTransition, type Team, type TeamInvitation, type TeamMember, TeamsService, type TelemetryPayload, type Tool, type ToolCapability, type ToolIntegration, type TopEvent, type TotpSetup, type Transaction, type TransactionListParams, type TransactionSummary, type TransactionSummaryParams, type Transfer, type TransformOptions, type TransformResult, type TraversalResult, type UpdateFlagRequest, type UpdateRuleRequest, type UpdateSegmentRequest, type UpdateVariantRequest, type UploadCompleteResponse, type UploadEngineConfig, type UploadFailureReport, type UploadFailureReportResponse, type UploadOptions, type UploadPlan, UploadResumeStore, type UploadStrategy, UploadTelemetry, type UploadTelemetryConfig, type UploadTelemetryEvent, type UpsertEnvironmentRequest, type UsageRecord, type UsageSummary$1 as UsageSummary, type UserRank, type VideoInfo, VideoService, type VideoUploadOptions, WEB_PUSH_SERVICE_WORKER, WebPushManager, type WebPushManagerOptions, type WebPushSubscriptionData, type Webhook, WebhooksService, type Workflow, type WorkflowExecution, type Workspace$1 as Workspace, type WorkspaceInvitation, type WorkspaceMember, WorkspacesService, buildClientContextHeaders, calculateTotalParts, canPerform, createUploadPlan, ScaleMule as default, detectNetworkClass, extractClientContext, generateUploadSessionId, getMeasuredBandwidthMbps, getPartRange, hasMinRoleLevel, resolveStrategy, uploadMultipartToS3, uploadSingleToS3, validateIP };
|
package/dist/index.d.ts
CHANGED
|
@@ -2534,14 +2534,24 @@ declare class FlagsService extends ServiceModule {
|
|
|
2534
2534
|
* Email, SMS, push notifications with template support.
|
|
2535
2535
|
*
|
|
2536
2536
|
* Routes:
|
|
2537
|
-
* POST /email/send
|
|
2538
|
-
* POST /email/templates/{name}/send
|
|
2539
|
-
* POST /sms/send
|
|
2540
|
-
* POST /sms/templates/{name}/send
|
|
2541
|
-
* POST /push/send
|
|
2542
|
-
* POST /push/register
|
|
2543
|
-
* DELETE /push/tokens/{token}
|
|
2544
|
-
*
|
|
2537
|
+
* POST /email/send → send email
|
|
2538
|
+
* POST /email/templates/{name}/send → send templated email
|
|
2539
|
+
* POST /sms/send → send SMS
|
|
2540
|
+
* POST /sms/templates/{name}/send → send templated SMS
|
|
2541
|
+
* POST /push/send → send push notification
|
|
2542
|
+
* POST /push/register → register push token
|
|
2543
|
+
* DELETE /push/tokens/{token} → unregister push token (legacy)
|
|
2544
|
+
* DELETE /push/tokens/by-id/{id} → unregister push token by ID
|
|
2545
|
+
* PUT /push/tokens/by-id/{id}/user → associate token with authenticated user
|
|
2546
|
+
* DELETE /push/tokens/by-id/{id}/user → disassociate user (logout)
|
|
2547
|
+
* GET /push/settings/me → get push settings for current app
|
|
2548
|
+
* GET /push/topics → list notification topics
|
|
2549
|
+
* POST /push/topics/{id}/subscribe → subscribe to topic
|
|
2550
|
+
* DELETE /push/topics/{id}/subscribe → unsubscribe from topic
|
|
2551
|
+
* GET /push/subscriptions → list subscriptions
|
|
2552
|
+
* GET /push/preferences → get push preferences
|
|
2553
|
+
* PUT /push/preferences → update push preferences
|
|
2554
|
+
* GET /messages/{id} → get message status
|
|
2545
2555
|
*/
|
|
2546
2556
|
|
|
2547
2557
|
interface MessageStatus {
|
|
@@ -2559,10 +2569,68 @@ interface MessageStatus {
|
|
|
2559
2569
|
error_message?: string;
|
|
2560
2570
|
}
|
|
2561
2571
|
interface PushToken {
|
|
2562
|
-
|
|
2563
|
-
platform:
|
|
2572
|
+
id: string;
|
|
2573
|
+
platform: 'ios' | 'android' | 'web';
|
|
2574
|
+
user_id?: string;
|
|
2575
|
+
is_active: boolean;
|
|
2564
2576
|
created_at: string;
|
|
2565
2577
|
}
|
|
2578
|
+
interface PushTokenAssociationResult {
|
|
2579
|
+
id: string;
|
|
2580
|
+
user_id: string;
|
|
2581
|
+
subscriptions_copied: number;
|
|
2582
|
+
}
|
|
2583
|
+
interface PushSettings {
|
|
2584
|
+
push_enabled: boolean;
|
|
2585
|
+
webpush_enabled: boolean;
|
|
2586
|
+
vapid_public_key: string | null;
|
|
2587
|
+
fcm_enabled: boolean;
|
|
2588
|
+
apns_enabled: boolean;
|
|
2589
|
+
silent_push_enabled: boolean;
|
|
2590
|
+
rich_media_enabled: boolean;
|
|
2591
|
+
broadcast_enabled: boolean;
|
|
2592
|
+
max_per_user_per_hour: number;
|
|
2593
|
+
max_per_user_per_day: number;
|
|
2594
|
+
}
|
|
2595
|
+
interface PushTopic {
|
|
2596
|
+
id: string;
|
|
2597
|
+
name: string;
|
|
2598
|
+
display_name: string;
|
|
2599
|
+
description: string | null;
|
|
2600
|
+
is_default: boolean;
|
|
2601
|
+
is_visible: boolean;
|
|
2602
|
+
subscriber_count?: number;
|
|
2603
|
+
}
|
|
2604
|
+
interface PushSubscriptionInfo {
|
|
2605
|
+
id: string;
|
|
2606
|
+
topic_id: string;
|
|
2607
|
+
topic_name?: string;
|
|
2608
|
+
}
|
|
2609
|
+
interface PushPreferences {
|
|
2610
|
+
marketing_enabled: boolean;
|
|
2611
|
+
transactional_enabled: boolean;
|
|
2612
|
+
alert_enabled: boolean;
|
|
2613
|
+
quiet_hours_enabled: boolean;
|
|
2614
|
+
quiet_hours_start: string | null;
|
|
2615
|
+
quiet_hours_end: string | null;
|
|
2616
|
+
quiet_hours_tz: string | null;
|
|
2617
|
+
}
|
|
2618
|
+
interface WebPushSubscriptionData {
|
|
2619
|
+
endpoint: string;
|
|
2620
|
+
keys: {
|
|
2621
|
+
p256dh: string;
|
|
2622
|
+
auth: string;
|
|
2623
|
+
};
|
|
2624
|
+
}
|
|
2625
|
+
interface RegisterPushTokenData {
|
|
2626
|
+
token: string;
|
|
2627
|
+
platform: 'ios' | 'android' | 'web';
|
|
2628
|
+
device_id?: string;
|
|
2629
|
+
subscription?: WebPushSubscriptionData;
|
|
2630
|
+
app_version?: string;
|
|
2631
|
+
os_version?: string;
|
|
2632
|
+
device_model?: string;
|
|
2633
|
+
}
|
|
2566
2634
|
declare class CommunicationService extends ServiceModule {
|
|
2567
2635
|
protected basePath: string;
|
|
2568
2636
|
sendEmail(data: {
|
|
@@ -2590,13 +2658,23 @@ declare class CommunicationService extends ServiceModule {
|
|
|
2590
2658
|
body: string;
|
|
2591
2659
|
data?: Record<string, unknown>;
|
|
2592
2660
|
}, options?: RequestOptions): Promise<ApiResponse<MessageStatus>>;
|
|
2593
|
-
registerPushToken(data:
|
|
2594
|
-
|
|
2595
|
-
platform: string;
|
|
2596
|
-
}, options?: RequestOptions): Promise<ApiResponse<PushToken>>;
|
|
2661
|
+
registerPushToken(data: RegisterPushTokenData, options?: RequestOptions): Promise<ApiResponse<PushToken>>;
|
|
2662
|
+
/** @deprecated Use unregisterPushTokenById() for web push tokens */
|
|
2597
2663
|
unregisterPushToken(token: string, options?: RequestOptions): Promise<ApiResponse<{
|
|
2598
2664
|
unregistered: boolean;
|
|
2599
2665
|
}>>;
|
|
2666
|
+
unregisterPushTokenById(id: string, options?: RequestOptions): Promise<ApiResponse<void>>;
|
|
2667
|
+
associatePushTokenUserById(id: string, options?: RequestOptions): Promise<ApiResponse<PushTokenAssociationResult>>;
|
|
2668
|
+
disassociatePushTokenUser(id: string, options?: RequestOptions): Promise<ApiResponse<void>>;
|
|
2669
|
+
getMyPushSettings(options?: RequestOptions): Promise<ApiResponse<PushSettings>>;
|
|
2670
|
+
listTopics(options?: RequestOptions): Promise<ApiResponse<PushTopic[]>>;
|
|
2671
|
+
subscribeTopic(topicId: string, data?: {
|
|
2672
|
+
push_token_id?: string;
|
|
2673
|
+
}, options?: RequestOptions): Promise<ApiResponse<void>>;
|
|
2674
|
+
unsubscribeTopic(topicId: string, options?: RequestOptions): Promise<ApiResponse<void>>;
|
|
2675
|
+
listSubscriptions(options?: RequestOptions): Promise<ApiResponse<PushSubscriptionInfo[]>>;
|
|
2676
|
+
getPushPreferences(options?: RequestOptions): Promise<ApiResponse<PushPreferences>>;
|
|
2677
|
+
updatePushPreferences(data: Partial<PushPreferences>, options?: RequestOptions): Promise<ApiResponse<PushPreferences>>;
|
|
2600
2678
|
getMessageStatus(id: string, options?: RequestOptions): Promise<ApiResponse<MessageStatus>>;
|
|
2601
2679
|
/** @deprecated Use sendSms() instead */
|
|
2602
2680
|
sendSMS(data: {
|
|
@@ -2612,6 +2690,91 @@ declare class CommunicationService extends ServiceModule {
|
|
|
2612
2690
|
}): Promise<ApiResponse<MessageStatus>>;
|
|
2613
2691
|
}
|
|
2614
2692
|
|
|
2693
|
+
/**
|
|
2694
|
+
* WebPushManager — Browser push notification subscription manager
|
|
2695
|
+
*
|
|
2696
|
+
* Handles service worker registration, Notification permission prompts,
|
|
2697
|
+
* PushManager.subscribe(), and backend token registration.
|
|
2698
|
+
*
|
|
2699
|
+
* All HTTP calls go through an injectable PushApiFetcher — this lets
|
|
2700
|
+
* the NextJS hook inject a fetcher that routes through /api/push/* proxy,
|
|
2701
|
+
* while the React hook injects one that calls the gateway directly.
|
|
2702
|
+
*/
|
|
2703
|
+
|
|
2704
|
+
interface PushApiFetcher {
|
|
2705
|
+
getSettings(): Promise<PushSettings>;
|
|
2706
|
+
registerToken(data: RegisterPushTokenData): Promise<{
|
|
2707
|
+
id: string;
|
|
2708
|
+
}>;
|
|
2709
|
+
unregisterToken(tokenId: string): Promise<void>;
|
|
2710
|
+
associateUser(tokenId: string): Promise<void>;
|
|
2711
|
+
disassociateUser(tokenId: string): Promise<void>;
|
|
2712
|
+
}
|
|
2713
|
+
interface WebPushManagerOptions {
|
|
2714
|
+
/** Service worker URL (default: '/sw.js') */
|
|
2715
|
+
serviceWorkerUrl?: string;
|
|
2716
|
+
/** Required: HTTP transport abstraction */
|
|
2717
|
+
fetcher: PushApiFetcher;
|
|
2718
|
+
}
|
|
2719
|
+
declare class WebPushManager {
|
|
2720
|
+
private fetcher;
|
|
2721
|
+
private swUrl;
|
|
2722
|
+
private state;
|
|
2723
|
+
private registration;
|
|
2724
|
+
constructor(options: WebPushManagerOptions);
|
|
2725
|
+
/** Whether the browser supports Web Push */
|
|
2726
|
+
isSupported(): boolean;
|
|
2727
|
+
/** Current notification permission state */
|
|
2728
|
+
getPermissionState(): NotificationPermission | 'unsupported';
|
|
2729
|
+
/** Request notification permission from the user */
|
|
2730
|
+
requestPermission(): Promise<NotificationPermission>;
|
|
2731
|
+
/**
|
|
2732
|
+
* Full subscribe flow:
|
|
2733
|
+
* 1. Check browser support
|
|
2734
|
+
* 2. Request notification permission
|
|
2735
|
+
* 3. Register service worker
|
|
2736
|
+
* 4. Fetch VAPID public key from backend
|
|
2737
|
+
* 5. PushManager.subscribe() with VAPID key
|
|
2738
|
+
* 6. Register token with backend
|
|
2739
|
+
*
|
|
2740
|
+
* @param deviceId Optional device identifier for anonymous users.
|
|
2741
|
+
* If not provided, generates a random UUID stored in localStorage.
|
|
2742
|
+
*/
|
|
2743
|
+
subscribe(deviceId?: string): Promise<{
|
|
2744
|
+
tokenId: string;
|
|
2745
|
+
endpoint: string;
|
|
2746
|
+
} | null>;
|
|
2747
|
+
/** Unsubscribe from browser push and deregister token */
|
|
2748
|
+
unsubscribe(): Promise<void>;
|
|
2749
|
+
/** Link push token to the currently authenticated user (call after login) */
|
|
2750
|
+
associateUser(): Promise<void>;
|
|
2751
|
+
/** Clear user association from push token (call before logout) */
|
|
2752
|
+
disassociateUser(): Promise<void>;
|
|
2753
|
+
/** Check if currently subscribed to push notifications */
|
|
2754
|
+
isSubscribed(): Promise<boolean>;
|
|
2755
|
+
/** Get the active PushSubscription from the service worker */
|
|
2756
|
+
getSubscription(): Promise<PushSubscription | null>;
|
|
2757
|
+
/** Get the stored token ID (for external use) */
|
|
2758
|
+
getTokenId(): string | null;
|
|
2759
|
+
private persistState;
|
|
2760
|
+
private clearState;
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2763
|
+
/**
|
|
2764
|
+
* Web Push Service Worker Template
|
|
2765
|
+
*
|
|
2766
|
+
* Exports a JavaScript string that can be served as a service worker.
|
|
2767
|
+
* Customers can either:
|
|
2768
|
+
* 1. Use this string with a Next.js API route to serve dynamically
|
|
2769
|
+
* 2. Copy the content into their own public/sw.js
|
|
2770
|
+
*
|
|
2771
|
+
* The service worker handles:
|
|
2772
|
+
* - push events: parse JSON, show notification
|
|
2773
|
+
* - notificationclick: open/focus app window
|
|
2774
|
+
* - message posting to client pages for foreground handling
|
|
2775
|
+
*/
|
|
2776
|
+
declare const WEB_PUSH_SERVICE_WORKER = "\n// ScaleMule Push Notification Service Worker\n\nself.addEventListener('push', function(event) {\n if (!event.data) return;\n\n var data;\n try {\n data = event.data.json();\n } catch (e) {\n data = { title: 'New Notification', body: event.data.text() };\n }\n\n var title = data.title || 'Notification';\n var options = {\n body: data.body || '',\n icon: data.icon || undefined,\n image: data.image || undefined,\n badge: data.badge || undefined,\n data: data.data || data,\n tag: data.tag || undefined,\n actions: data.actions || undefined,\n requireInteraction: data.requireInteraction || false,\n };\n\n // Show the notification\n event.waitUntil(\n self.registration.showNotification(title, options)\n .then(function() {\n // Post message to all client pages for foreground handling\n return self.clients.matchAll({ type: 'window', includeUncontrolled: true });\n })\n .then(function(clients) {\n clients.forEach(function(client) {\n client.postMessage({\n type: 'push-received',\n payload: data,\n });\n });\n })\n );\n});\n\nself.addEventListener('notificationclick', function(event) {\n event.notification.close();\n\n var url = '/';\n if (event.notification.data && event.notification.data.url) {\n url = event.notification.data.url;\n }\n\n // Handle action button clicks\n if (event.action && event.notification.data && event.notification.data.actions) {\n var action = event.notification.data.actions.find(function(a) {\n return a.action === event.action;\n });\n if (action && action.url) {\n url = action.url;\n }\n }\n\n event.waitUntil(\n self.clients.matchAll({ type: 'window', includeUncontrolled: true })\n .then(function(clientList) {\n // Try to focus an existing window\n for (var i = 0; i < clientList.length; i++) {\n var client = clientList[i];\n if (client.url.indexOf(self.registration.scope) !== -1 && 'focus' in client) {\n client.focus();\n client.navigate(url);\n return;\n }\n }\n // Open a new window if none exists\n if (self.clients.openWindow) {\n return self.clients.openWindow(url);\n }\n })\n );\n});\n";
|
|
2777
|
+
|
|
2615
2778
|
/**
|
|
2616
2779
|
* Scheduler Service Module
|
|
2617
2780
|
*
|
|
@@ -5278,4 +5441,4 @@ declare class ScaleMule {
|
|
|
5278
5441
|
getClient(): ScaleMuleClient;
|
|
5279
5442
|
}
|
|
5280
5443
|
|
|
5281
|
-
export { type AccountBalance, AccountsService, type ActiveUsers, type ActivityItem, AgentAuthService, AgentModelsService, type AgentProfile, AgentProjectsService, type AgentResponse, type AgentSecurityPolicy, AgentSessionsService, type AgentSigningKey, type AgentToken, type AgentToolEntitlement, AgentToolsService, type Workspace as AgentWorkspace, AgentsService, type AggregateOptions, type AggregateResult, type AnalyticsEvent, AnalyticsService, type ApiError, type ApiKey, type ApiResponse, type Appeal, type Application, type Attachment, type Attendee, type AuditLog, type AuthRegisterAgentRequest, type AuthRegisterAgentResponse, AuthService, type AuthSession, type AuthUser, type BackupCodes, BillingService, type CacheEntry, CacheService, type CalendarEvent, type CatalogEntry, CatalogService, type ChatMessage, type ChatReaction, ChatService, type ClaimResult, type Client, type ClientContext, type Collection, type Comment, CommunicationService, type CompletedPart, ComplianceService, type CompressionConfig, type ConnectedAccount, type ConnectedAccountSubscription, type ConnectedSetupIntentResponse, type ConnectedSubscriptionListParams, type ConnectionStatus, type ContentFlag, type Conversation, type CostReportDay, type CreateFlagRequest, type CreateRuleRequest, type CreateSegmentRequest, type CreateSessionResponse, type CreateVariantRequest, type Credential, type CredentialScope, type Customer, type DataAccessPolicy, type DataExport, DataService, type DataSource, type DeadLetterJob, type DeviceInfo, type Document, type ErrorCode, ErrorCodes, type EventAggregation, EventsService, type FileInfo, type FlagAuditEntry, type FlagCheck, type FlagCondition, FlagContentService, type FlagDefinition, type FlagDetail, type FlagEnvironment, type FlagEvaluation, type FlagSegment, type FlagVariant, FlagsService, type FollowStatus, type FunctionExecution, type FunctionMetrics, FunctionsService, type Funnel, type FunnelConversion, type GdprRequest, type GrantInfo, type GraphEdge, type GraphNode, GraphService, IdentityService, type IdentityType, type IncomingRequestLike, type Invoice, type JobExecution, type JobStats, type Leaderboard, type LeaderboardEntry, LeaderboardService, type Like, type Listing, ListingsService, type LogEntry, type LogInput, type LogQueryParams, type LogQueryResponse, type LogRecord, LoggerService, type LoginActivitySummary, type LoginDeviceInfo, type LoginHistoryEntry, type LoginRiskInfo, type MessageCallback, type MessageStatus, type MetricDataPoint, type MfaStatus, type Model, type ModelEntitlement, type ModelPricing, type ModelProvider, type UsageSummary as ModelUsageSummary, type MultipartCompleteResponse, type MultipartConfig, type MultipartPartUrl, type MultipartPartUrlsResponse, type MultipartStartResponse, type NetworkClass, type OAuthProvider, type OAuthUrl, OrchestratorService, PHOTO_BREAKPOINTS, type PaginatedResponse, type PaginationMetadata, type PaginationParams, type PartResult, type PartUrl, type Participant, type Payment, type PaymentListParams, type PaymentMethod, type PaymentStatusResponse, type Payout, type PayoutSchedule, type PermissionCheck, type PermissionMatrix, PermissionsService, type PhotoInfo, PhotoService, type Pipeline, type PipelineVersion, type Policy, type PresenceCallback, type PresenceEvent, type PresignedUploadResponse, type Price, type Product, type Project, type ProjectDocument, type ProjectGrant, type ProjectMember, type PushToken, type QueryFilter, type QueryOptions, type QuerySort, type QueueJob, QueueService, type ReadStatus, RealtimeService, type RedeemResult, type Refund, type RegisterAgentRequest, type RegisterAgentResponse, type RequestOptions, type ResumeSession, type Role, type RuntimeTemplate, type RuntimeTemplateVersion, type S3MultipartOptions, type S3MultipartResult, type S3SingleUploadOptions, type S3SingleUploadResult, type S3UploadProgress, ScaleMule, ScaleMuleClient, type ScaleMuleConfig, type SchedulerJob, SchedulerService, type SearchResult, SearchService, type SecurityLayers, type ServerlessFunction, type ServiceHealth, ServiceModule, type Session, type SessionArtifact, type SessionInfo, type SessionLog, type SessionPoolEntry, type Severity, type ShortestPathResult, type SignedUrlResponse, type SocialPost, SocialService, type SocialUser, type SsoConfig, type StatusCallback, type StorageAdapter, StorageService, type StrategyResult, type SubmitResult, type Subscription, type TargetingRule, type Task, type TaskAttempt, type TaskTransition, type Team, type TeamInvitation, type TeamMember, TeamsService, type TelemetryPayload, type Tool, type ToolCapability, type ToolIntegration, type TopEvent, type TotpSetup, type Transaction, type TransactionListParams, type TransactionSummary, type TransactionSummaryParams, type Transfer, type TransformOptions, type TransformResult, type TraversalResult, type UpdateFlagRequest, type UpdateRuleRequest, type UpdateSegmentRequest, type UpdateVariantRequest, type UploadCompleteResponse, type UploadEngineConfig, type UploadFailureReport, type UploadFailureReportResponse, type UploadOptions, type UploadPlan, UploadResumeStore, type UploadStrategy, UploadTelemetry, type UploadTelemetryConfig, type UploadTelemetryEvent, type UpsertEnvironmentRequest, type UsageRecord, type UsageSummary$1 as UsageSummary, type UserRank, type VideoInfo, VideoService, type VideoUploadOptions, type Webhook, WebhooksService, type Workflow, type WorkflowExecution, type Workspace$1 as Workspace, type WorkspaceInvitation, type WorkspaceMember, WorkspacesService, buildClientContextHeaders, calculateTotalParts, canPerform, createUploadPlan, ScaleMule as default, detectNetworkClass, extractClientContext, generateUploadSessionId, getMeasuredBandwidthMbps, getPartRange, hasMinRoleLevel, resolveStrategy, uploadMultipartToS3, uploadSingleToS3, validateIP };
|
|
5444
|
+
export { type AccountBalance, AccountsService, type ActiveUsers, type ActivityItem, AgentAuthService, AgentModelsService, type AgentProfile, AgentProjectsService, type AgentResponse, type AgentSecurityPolicy, AgentSessionsService, type AgentSigningKey, type AgentToken, type AgentToolEntitlement, AgentToolsService, type Workspace as AgentWorkspace, AgentsService, type AggregateOptions, type AggregateResult, type AnalyticsEvent, AnalyticsService, type ApiError, type ApiKey, type ApiResponse, type Appeal, type Application, type Attachment, type Attendee, type AuditLog, type AuthRegisterAgentRequest, type AuthRegisterAgentResponse, AuthService, type AuthSession, type AuthUser, type BackupCodes, BillingService, type CacheEntry, CacheService, type CalendarEvent, type CatalogEntry, CatalogService, type ChatMessage, type ChatReaction, ChatService, type ClaimResult, type Client, type ClientContext, type Collection, type Comment, CommunicationService, type CompletedPart, ComplianceService, type CompressionConfig, type ConnectedAccount, type ConnectedAccountSubscription, type ConnectedSetupIntentResponse, type ConnectedSubscriptionListParams, type ConnectionStatus, type ContentFlag, type Conversation, type CostReportDay, type CreateFlagRequest, type CreateRuleRequest, type CreateSegmentRequest, type CreateSessionResponse, type CreateVariantRequest, type Credential, type CredentialScope, type Customer, type DataAccessPolicy, type DataExport, DataService, type DataSource, type DeadLetterJob, type DeviceInfo, type Document, type ErrorCode, ErrorCodes, type EventAggregation, EventsService, type FileInfo, type FlagAuditEntry, type FlagCheck, type FlagCondition, FlagContentService, type FlagDefinition, type FlagDetail, type FlagEnvironment, type FlagEvaluation, type FlagSegment, type FlagVariant, FlagsService, type FollowStatus, type FunctionExecution, type FunctionMetrics, FunctionsService, type Funnel, type FunnelConversion, type GdprRequest, type GrantInfo, type GraphEdge, type GraphNode, GraphService, IdentityService, type IdentityType, type IncomingRequestLike, type Invoice, type JobExecution, type JobStats, type Leaderboard, type LeaderboardEntry, LeaderboardService, type Like, type Listing, ListingsService, type LogEntry, type LogInput, type LogQueryParams, type LogQueryResponse, type LogRecord, LoggerService, type LoginActivitySummary, type LoginDeviceInfo, type LoginHistoryEntry, type LoginRiskInfo, type MessageCallback, type MessageStatus, type MetricDataPoint, type MfaStatus, type Model, type ModelEntitlement, type ModelPricing, type ModelProvider, type UsageSummary as ModelUsageSummary, type MultipartCompleteResponse, type MultipartConfig, type MultipartPartUrl, type MultipartPartUrlsResponse, type MultipartStartResponse, type NetworkClass, type OAuthProvider, type OAuthUrl, OrchestratorService, PHOTO_BREAKPOINTS, type PaginatedResponse, type PaginationMetadata, type PaginationParams, type PartResult, type PartUrl, type Participant, type Payment, type PaymentListParams, type PaymentMethod, type PaymentStatusResponse, type Payout, type PayoutSchedule, type PermissionCheck, type PermissionMatrix, PermissionsService, type PhotoInfo, PhotoService, type Pipeline, type PipelineVersion, type Policy, type PresenceCallback, type PresenceEvent, type PresignedUploadResponse, type Price, type Product, type Project, type ProjectDocument, type ProjectGrant, type ProjectMember, type PushApiFetcher, type PushPreferences, type PushSettings, type PushSubscriptionInfo, type PushToken, type PushTokenAssociationResult, type PushTopic, type QueryFilter, type QueryOptions, type QuerySort, type QueueJob, QueueService, type ReadStatus, RealtimeService, type RedeemResult, type Refund, type RegisterAgentRequest, type RegisterAgentResponse, type RegisterPushTokenData, type RequestOptions, type ResumeSession, type Role, type RuntimeTemplate, type RuntimeTemplateVersion, type S3MultipartOptions, type S3MultipartResult, type S3SingleUploadOptions, type S3SingleUploadResult, type S3UploadProgress, ScaleMule, ScaleMuleClient, type ScaleMuleConfig, type SchedulerJob, SchedulerService, type SearchResult, SearchService, type SecurityLayers, type ServerlessFunction, type ServiceHealth, ServiceModule, type Session, type SessionArtifact, type SessionInfo, type SessionLog, type SessionPoolEntry, type Severity, type ShortestPathResult, type SignedUrlResponse, type SocialPost, SocialService, type SocialUser, type SsoConfig, type StatusCallback, type StorageAdapter, StorageService, type StrategyResult, type SubmitResult, type Subscription, type TargetingRule, type Task, type TaskAttempt, type TaskTransition, type Team, type TeamInvitation, type TeamMember, TeamsService, type TelemetryPayload, type Tool, type ToolCapability, type ToolIntegration, type TopEvent, type TotpSetup, type Transaction, type TransactionListParams, type TransactionSummary, type TransactionSummaryParams, type Transfer, type TransformOptions, type TransformResult, type TraversalResult, type UpdateFlagRequest, type UpdateRuleRequest, type UpdateSegmentRequest, type UpdateVariantRequest, type UploadCompleteResponse, type UploadEngineConfig, type UploadFailureReport, type UploadFailureReportResponse, type UploadOptions, type UploadPlan, UploadResumeStore, type UploadStrategy, UploadTelemetry, type UploadTelemetryConfig, type UploadTelemetryEvent, type UpsertEnvironmentRequest, type UsageRecord, type UsageSummary$1 as UsageSummary, type UserRank, type VideoInfo, VideoService, type VideoUploadOptions, WEB_PUSH_SERVICE_WORKER, WebPushManager, type WebPushManagerOptions, type WebPushSubscriptionData, type Webhook, WebhooksService, type Workflow, type WorkflowExecution, type Workspace$1 as Workspace, type WorkspaceInvitation, type WorkspaceMember, WorkspacesService, buildClientContextHeaders, calculateTotalParts, canPerform, createUploadPlan, ScaleMule as default, detectNetworkClass, extractClientContext, generateUploadSessionId, getMeasuredBandwidthMbps, getPartRange, hasMinRoleLevel, resolveStrategy, uploadMultipartToS3, uploadSingleToS3, validateIP };
|
package/dist/index.js
CHANGED
|
@@ -337,6 +337,8 @@ __export(index_exports, {
|
|
|
337
337
|
UploadResumeStore: () => UploadResumeStore,
|
|
338
338
|
UploadTelemetry: () => UploadTelemetry,
|
|
339
339
|
VideoService: () => VideoService,
|
|
340
|
+
WEB_PUSH_SERVICE_WORKER: () => WEB_PUSH_SERVICE_WORKER,
|
|
341
|
+
WebPushManager: () => WebPushManager,
|
|
340
342
|
WebhooksService: () => WebhooksService,
|
|
341
343
|
WorkspacesService: () => WorkspacesService,
|
|
342
344
|
buildClientContextHeaders: () => buildClientContextHeaders,
|
|
@@ -3136,7 +3138,6 @@ async function uploadSingleToS3(url, file, options) {
|
|
|
3136
3138
|
const result = await doSinglePut(url, file, options?.onProgress, options?.signal, stallTimeout);
|
|
3137
3139
|
if (result === "success") return { success: true };
|
|
3138
3140
|
if (result === "abort") return { success: false, error: "Upload aborted" };
|
|
3139
|
-
if (result === "stall") return { success: false, error: "Upload stalled \u2014 no progress" };
|
|
3140
3141
|
}
|
|
3141
3142
|
return { success: false, error: "Upload failed after retries" };
|
|
3142
3143
|
}
|
|
@@ -4451,17 +4452,68 @@ var CommunicationService = class extends ServiceModule {
|
|
|
4451
4452
|
return this.post(`/sms/templates/${template}/send`, data, options);
|
|
4452
4453
|
}
|
|
4453
4454
|
// --------------------------------------------------------------------------
|
|
4454
|
-
// Push Notifications
|
|
4455
|
+
// Push Notifications — Send
|
|
4455
4456
|
// --------------------------------------------------------------------------
|
|
4456
4457
|
async sendPush(data, options) {
|
|
4457
4458
|
return this.post("/push/send", data, options);
|
|
4458
4459
|
}
|
|
4460
|
+
// --------------------------------------------------------------------------
|
|
4461
|
+
// Push Notifications — Token Management
|
|
4462
|
+
// --------------------------------------------------------------------------
|
|
4459
4463
|
async registerPushToken(data, options) {
|
|
4460
4464
|
return this.post("/push/register", data, options);
|
|
4461
4465
|
}
|
|
4466
|
+
/** @deprecated Use unregisterPushTokenById() for web push tokens */
|
|
4462
4467
|
async unregisterPushToken(token, options) {
|
|
4463
4468
|
return this.del(`/push/tokens/${token}`, options);
|
|
4464
4469
|
}
|
|
4470
|
+
async unregisterPushTokenById(id, options) {
|
|
4471
|
+
const result = await this.del(`/push/tokens/by-id/${id}`, options);
|
|
4472
|
+
if (result.data && typeof result.data === "object" && !("id" in result.data)) {
|
|
4473
|
+
return { data: void 0, error: null };
|
|
4474
|
+
}
|
|
4475
|
+
return result;
|
|
4476
|
+
}
|
|
4477
|
+
async associatePushTokenUserById(id, options) {
|
|
4478
|
+
return this.put(`/push/tokens/by-id/${id}/user`, {}, options);
|
|
4479
|
+
}
|
|
4480
|
+
async disassociatePushTokenUser(id, options) {
|
|
4481
|
+
const result = await this.del(`/push/tokens/by-id/${id}/user`, options);
|
|
4482
|
+
if (result.data && typeof result.data === "object" && !("id" in result.data)) {
|
|
4483
|
+
return { data: void 0, error: null };
|
|
4484
|
+
}
|
|
4485
|
+
return result;
|
|
4486
|
+
}
|
|
4487
|
+
// --------------------------------------------------------------------------
|
|
4488
|
+
// Push Notifications — Settings
|
|
4489
|
+
// --------------------------------------------------------------------------
|
|
4490
|
+
async getMyPushSettings(options) {
|
|
4491
|
+
return this._get("/push/settings/me", options);
|
|
4492
|
+
}
|
|
4493
|
+
// --------------------------------------------------------------------------
|
|
4494
|
+
// Push Notifications — Topics & Subscriptions
|
|
4495
|
+
// --------------------------------------------------------------------------
|
|
4496
|
+
async listTopics(options) {
|
|
4497
|
+
return this._get("/push/topics", options);
|
|
4498
|
+
}
|
|
4499
|
+
async subscribeTopic(topicId, data, options) {
|
|
4500
|
+
return this.post(`/push/topics/${topicId}/subscribe`, data || {}, options);
|
|
4501
|
+
}
|
|
4502
|
+
async unsubscribeTopic(topicId, options) {
|
|
4503
|
+
return this.del(`/push/topics/${topicId}/subscribe`, options);
|
|
4504
|
+
}
|
|
4505
|
+
async listSubscriptions(options) {
|
|
4506
|
+
return this._get("/push/subscriptions", options);
|
|
4507
|
+
}
|
|
4508
|
+
// --------------------------------------------------------------------------
|
|
4509
|
+
// Push Notifications — Preferences
|
|
4510
|
+
// --------------------------------------------------------------------------
|
|
4511
|
+
async getPushPreferences(options) {
|
|
4512
|
+
return this._get("/push/preferences", options);
|
|
4513
|
+
}
|
|
4514
|
+
async updatePushPreferences(data, options) {
|
|
4515
|
+
return this.put("/push/preferences", data, options);
|
|
4516
|
+
}
|
|
4465
4517
|
// --------------------------------------------------------------------------
|
|
4466
4518
|
// Message Status
|
|
4467
4519
|
// --------------------------------------------------------------------------
|
|
@@ -4481,6 +4533,258 @@ var CommunicationService = class extends ServiceModule {
|
|
|
4481
4533
|
}
|
|
4482
4534
|
};
|
|
4483
4535
|
|
|
4536
|
+
// src/web-push.ts
|
|
4537
|
+
var STORAGE_KEY = "scalemule_push_state";
|
|
4538
|
+
var WebPushManager = class {
|
|
4539
|
+
constructor(options) {
|
|
4540
|
+
this.state = null;
|
|
4541
|
+
this.registration = null;
|
|
4542
|
+
if (typeof window === "undefined") {
|
|
4543
|
+
throw new Error("WebPushManager can only be used in a browser environment");
|
|
4544
|
+
}
|
|
4545
|
+
this.fetcher = options.fetcher;
|
|
4546
|
+
this.swUrl = options.serviceWorkerUrl || "/sw.js";
|
|
4547
|
+
try {
|
|
4548
|
+
const stored = localStorage.getItem(STORAGE_KEY);
|
|
4549
|
+
if (stored) {
|
|
4550
|
+
this.state = JSON.parse(stored);
|
|
4551
|
+
}
|
|
4552
|
+
} catch {
|
|
4553
|
+
}
|
|
4554
|
+
}
|
|
4555
|
+
/** Whether the browser supports Web Push */
|
|
4556
|
+
isSupported() {
|
|
4557
|
+
return typeof window !== "undefined" && "serviceWorker" in navigator && "PushManager" in window && "Notification" in window;
|
|
4558
|
+
}
|
|
4559
|
+
/** Current notification permission state */
|
|
4560
|
+
getPermissionState() {
|
|
4561
|
+
if (!this.isSupported()) return "unsupported";
|
|
4562
|
+
return Notification.permission;
|
|
4563
|
+
}
|
|
4564
|
+
/** Request notification permission from the user */
|
|
4565
|
+
async requestPermission() {
|
|
4566
|
+
if (!this.isSupported()) return "denied";
|
|
4567
|
+
return Notification.requestPermission();
|
|
4568
|
+
}
|
|
4569
|
+
/**
|
|
4570
|
+
* Full subscribe flow:
|
|
4571
|
+
* 1. Check browser support
|
|
4572
|
+
* 2. Request notification permission
|
|
4573
|
+
* 3. Register service worker
|
|
4574
|
+
* 4. Fetch VAPID public key from backend
|
|
4575
|
+
* 5. PushManager.subscribe() with VAPID key
|
|
4576
|
+
* 6. Register token with backend
|
|
4577
|
+
*
|
|
4578
|
+
* @param deviceId Optional device identifier for anonymous users.
|
|
4579
|
+
* If not provided, generates a random UUID stored in localStorage.
|
|
4580
|
+
*/
|
|
4581
|
+
async subscribe(deviceId) {
|
|
4582
|
+
if (!this.isSupported()) return null;
|
|
4583
|
+
const permission = await this.requestPermission();
|
|
4584
|
+
if (permission !== "granted") return null;
|
|
4585
|
+
this.registration = await navigator.serviceWorker.register(this.swUrl);
|
|
4586
|
+
await navigator.serviceWorker.ready;
|
|
4587
|
+
const settings = await this.fetcher.getSettings();
|
|
4588
|
+
if (!settings.webpush_enabled || !settings.vapid_public_key) {
|
|
4589
|
+
throw new Error("Web Push is not enabled for this application");
|
|
4590
|
+
}
|
|
4591
|
+
const applicationServerKey = urlBase64ToUint8Array(settings.vapid_public_key);
|
|
4592
|
+
const pushSubscription = await this.registration.pushManager.subscribe({
|
|
4593
|
+
userVisibleOnly: true,
|
|
4594
|
+
applicationServerKey: applicationServerKey.buffer
|
|
4595
|
+
});
|
|
4596
|
+
const endpoint = pushSubscription.endpoint;
|
|
4597
|
+
const p256dh = arrayBufferToBase64url(pushSubscription.getKey("p256dh"));
|
|
4598
|
+
const auth = arrayBufferToBase64url(pushSubscription.getKey("auth"));
|
|
4599
|
+
const subscription = {
|
|
4600
|
+
endpoint,
|
|
4601
|
+
keys: { p256dh, auth }
|
|
4602
|
+
};
|
|
4603
|
+
const resolvedDeviceId = deviceId || this.state?.deviceId || generateDeviceId();
|
|
4604
|
+
const result = await this.fetcher.registerToken({
|
|
4605
|
+
token: endpoint,
|
|
4606
|
+
platform: "web",
|
|
4607
|
+
device_id: resolvedDeviceId,
|
|
4608
|
+
subscription
|
|
4609
|
+
});
|
|
4610
|
+
this.state = {
|
|
4611
|
+
endpoint,
|
|
4612
|
+
tokenId: result.id,
|
|
4613
|
+
deviceId: resolvedDeviceId
|
|
4614
|
+
};
|
|
4615
|
+
this.persistState();
|
|
4616
|
+
return { tokenId: result.id, endpoint };
|
|
4617
|
+
}
|
|
4618
|
+
/** Unsubscribe from browser push and deregister token */
|
|
4619
|
+
async unsubscribe() {
|
|
4620
|
+
const sub = await this.getSubscription();
|
|
4621
|
+
if (sub) {
|
|
4622
|
+
await sub.unsubscribe();
|
|
4623
|
+
}
|
|
4624
|
+
if (this.state?.tokenId) {
|
|
4625
|
+
try {
|
|
4626
|
+
await this.fetcher.unregisterToken(this.state.tokenId);
|
|
4627
|
+
} catch {
|
|
4628
|
+
}
|
|
4629
|
+
}
|
|
4630
|
+
this.state = null;
|
|
4631
|
+
this.clearState();
|
|
4632
|
+
}
|
|
4633
|
+
/** Link push token to the currently authenticated user (call after login) */
|
|
4634
|
+
async associateUser() {
|
|
4635
|
+
if (!this.state?.tokenId) return;
|
|
4636
|
+
await this.fetcher.associateUser(this.state.tokenId);
|
|
4637
|
+
}
|
|
4638
|
+
/** Clear user association from push token (call before logout) */
|
|
4639
|
+
async disassociateUser() {
|
|
4640
|
+
if (!this.state?.tokenId) return;
|
|
4641
|
+
await this.fetcher.disassociateUser(this.state.tokenId);
|
|
4642
|
+
}
|
|
4643
|
+
/** Check if currently subscribed to push notifications */
|
|
4644
|
+
async isSubscribed() {
|
|
4645
|
+
if (!this.isSupported()) return false;
|
|
4646
|
+
const sub = await this.getSubscription();
|
|
4647
|
+
return sub !== null && this.state !== null;
|
|
4648
|
+
}
|
|
4649
|
+
/** Get the active PushSubscription from the service worker */
|
|
4650
|
+
async getSubscription() {
|
|
4651
|
+
if (!this.isSupported()) return null;
|
|
4652
|
+
try {
|
|
4653
|
+
const reg = await navigator.serviceWorker.getRegistration(this.swUrl);
|
|
4654
|
+
if (!reg) return null;
|
|
4655
|
+
return reg.pushManager.getSubscription();
|
|
4656
|
+
} catch {
|
|
4657
|
+
return null;
|
|
4658
|
+
}
|
|
4659
|
+
}
|
|
4660
|
+
/** Get the stored token ID (for external use) */
|
|
4661
|
+
getTokenId() {
|
|
4662
|
+
return this.state?.tokenId || null;
|
|
4663
|
+
}
|
|
4664
|
+
persistState() {
|
|
4665
|
+
if (this.state) {
|
|
4666
|
+
try {
|
|
4667
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(this.state));
|
|
4668
|
+
} catch {
|
|
4669
|
+
}
|
|
4670
|
+
}
|
|
4671
|
+
}
|
|
4672
|
+
clearState() {
|
|
4673
|
+
try {
|
|
4674
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
4675
|
+
} catch {
|
|
4676
|
+
}
|
|
4677
|
+
}
|
|
4678
|
+
};
|
|
4679
|
+
function urlBase64ToUint8Array(base64String) {
|
|
4680
|
+
const padding = "=".repeat((4 - base64String.length % 4) % 4);
|
|
4681
|
+
const base64 = (base64String + padding).replace(/-/g, "+").replace(/_/g, "/");
|
|
4682
|
+
const rawData = atob(base64);
|
|
4683
|
+
const outputArray = new Uint8Array(rawData.length);
|
|
4684
|
+
for (let i = 0; i < rawData.length; ++i) {
|
|
4685
|
+
outputArray[i] = rawData.charCodeAt(i);
|
|
4686
|
+
}
|
|
4687
|
+
return outputArray;
|
|
4688
|
+
}
|
|
4689
|
+
function arrayBufferToBase64url(buffer) {
|
|
4690
|
+
const bytes = new Uint8Array(buffer);
|
|
4691
|
+
const binary = Array.from(bytes, (b) => String.fromCharCode(b)).join("");
|
|
4692
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
4693
|
+
}
|
|
4694
|
+
function generateDeviceId() {
|
|
4695
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
4696
|
+
return crypto.randomUUID();
|
|
4697
|
+
}
|
|
4698
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
4699
|
+
const r = Math.random() * 16 | 0;
|
|
4700
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
4701
|
+
return v.toString(16);
|
|
4702
|
+
});
|
|
4703
|
+
}
|
|
4704
|
+
|
|
4705
|
+
// src/web-push-sw.ts
|
|
4706
|
+
var WEB_PUSH_SERVICE_WORKER = `
|
|
4707
|
+
// ScaleMule Push Notification Service Worker
|
|
4708
|
+
|
|
4709
|
+
self.addEventListener('push', function(event) {
|
|
4710
|
+
if (!event.data) return;
|
|
4711
|
+
|
|
4712
|
+
var data;
|
|
4713
|
+
try {
|
|
4714
|
+
data = event.data.json();
|
|
4715
|
+
} catch (e) {
|
|
4716
|
+
data = { title: 'New Notification', body: event.data.text() };
|
|
4717
|
+
}
|
|
4718
|
+
|
|
4719
|
+
var title = data.title || 'Notification';
|
|
4720
|
+
var options = {
|
|
4721
|
+
body: data.body || '',
|
|
4722
|
+
icon: data.icon || undefined,
|
|
4723
|
+
image: data.image || undefined,
|
|
4724
|
+
badge: data.badge || undefined,
|
|
4725
|
+
data: data.data || data,
|
|
4726
|
+
tag: data.tag || undefined,
|
|
4727
|
+
actions: data.actions || undefined,
|
|
4728
|
+
requireInteraction: data.requireInteraction || false,
|
|
4729
|
+
};
|
|
4730
|
+
|
|
4731
|
+
// Show the notification
|
|
4732
|
+
event.waitUntil(
|
|
4733
|
+
self.registration.showNotification(title, options)
|
|
4734
|
+
.then(function() {
|
|
4735
|
+
// Post message to all client pages for foreground handling
|
|
4736
|
+
return self.clients.matchAll({ type: 'window', includeUncontrolled: true });
|
|
4737
|
+
})
|
|
4738
|
+
.then(function(clients) {
|
|
4739
|
+
clients.forEach(function(client) {
|
|
4740
|
+
client.postMessage({
|
|
4741
|
+
type: 'push-received',
|
|
4742
|
+
payload: data,
|
|
4743
|
+
});
|
|
4744
|
+
});
|
|
4745
|
+
})
|
|
4746
|
+
);
|
|
4747
|
+
});
|
|
4748
|
+
|
|
4749
|
+
self.addEventListener('notificationclick', function(event) {
|
|
4750
|
+
event.notification.close();
|
|
4751
|
+
|
|
4752
|
+
var url = '/';
|
|
4753
|
+
if (event.notification.data && event.notification.data.url) {
|
|
4754
|
+
url = event.notification.data.url;
|
|
4755
|
+
}
|
|
4756
|
+
|
|
4757
|
+
// Handle action button clicks
|
|
4758
|
+
if (event.action && event.notification.data && event.notification.data.actions) {
|
|
4759
|
+
var action = event.notification.data.actions.find(function(a) {
|
|
4760
|
+
return a.action === event.action;
|
|
4761
|
+
});
|
|
4762
|
+
if (action && action.url) {
|
|
4763
|
+
url = action.url;
|
|
4764
|
+
}
|
|
4765
|
+
}
|
|
4766
|
+
|
|
4767
|
+
event.waitUntil(
|
|
4768
|
+
self.clients.matchAll({ type: 'window', includeUncontrolled: true })
|
|
4769
|
+
.then(function(clientList) {
|
|
4770
|
+
// Try to focus an existing window
|
|
4771
|
+
for (var i = 0; i < clientList.length; i++) {
|
|
4772
|
+
var client = clientList[i];
|
|
4773
|
+
if (client.url.indexOf(self.registration.scope) !== -1 && 'focus' in client) {
|
|
4774
|
+
client.focus();
|
|
4775
|
+
client.navigate(url);
|
|
4776
|
+
return;
|
|
4777
|
+
}
|
|
4778
|
+
}
|
|
4779
|
+
// Open a new window if none exists
|
|
4780
|
+
if (self.clients.openWindow) {
|
|
4781
|
+
return self.clients.openWindow(url);
|
|
4782
|
+
}
|
|
4783
|
+
})
|
|
4784
|
+
);
|
|
4785
|
+
});
|
|
4786
|
+
`;
|
|
4787
|
+
|
|
4484
4788
|
// src/services/scheduler.ts
|
|
4485
4789
|
var SchedulerService = class extends ServiceModule {
|
|
4486
4790
|
constructor() {
|
|
@@ -6081,6 +6385,8 @@ var index_default = ScaleMule;
|
|
|
6081
6385
|
UploadResumeStore,
|
|
6082
6386
|
UploadTelemetry,
|
|
6083
6387
|
VideoService,
|
|
6388
|
+
WEB_PUSH_SERVICE_WORKER,
|
|
6389
|
+
WebPushManager,
|
|
6084
6390
|
WebhooksService,
|
|
6085
6391
|
WorkspacesService,
|
|
6086
6392
|
buildClientContextHeaders,
|
package/dist/index.mjs
CHANGED
|
@@ -2780,7 +2780,6 @@ async function uploadSingleToS3(url, file, options) {
|
|
|
2780
2780
|
const result = await doSinglePut(url, file, options?.onProgress, options?.signal, stallTimeout);
|
|
2781
2781
|
if (result === "success") return { success: true };
|
|
2782
2782
|
if (result === "abort") return { success: false, error: "Upload aborted" };
|
|
2783
|
-
if (result === "stall") return { success: false, error: "Upload stalled \u2014 no progress" };
|
|
2784
2783
|
}
|
|
2785
2784
|
return { success: false, error: "Upload failed after retries" };
|
|
2786
2785
|
}
|
|
@@ -4095,17 +4094,68 @@ var CommunicationService = class extends ServiceModule {
|
|
|
4095
4094
|
return this.post(`/sms/templates/${template}/send`, data, options);
|
|
4096
4095
|
}
|
|
4097
4096
|
// --------------------------------------------------------------------------
|
|
4098
|
-
// Push Notifications
|
|
4097
|
+
// Push Notifications — Send
|
|
4099
4098
|
// --------------------------------------------------------------------------
|
|
4100
4099
|
async sendPush(data, options) {
|
|
4101
4100
|
return this.post("/push/send", data, options);
|
|
4102
4101
|
}
|
|
4102
|
+
// --------------------------------------------------------------------------
|
|
4103
|
+
// Push Notifications — Token Management
|
|
4104
|
+
// --------------------------------------------------------------------------
|
|
4103
4105
|
async registerPushToken(data, options) {
|
|
4104
4106
|
return this.post("/push/register", data, options);
|
|
4105
4107
|
}
|
|
4108
|
+
/** @deprecated Use unregisterPushTokenById() for web push tokens */
|
|
4106
4109
|
async unregisterPushToken(token, options) {
|
|
4107
4110
|
return this.del(`/push/tokens/${token}`, options);
|
|
4108
4111
|
}
|
|
4112
|
+
async unregisterPushTokenById(id, options) {
|
|
4113
|
+
const result = await this.del(`/push/tokens/by-id/${id}`, options);
|
|
4114
|
+
if (result.data && typeof result.data === "object" && !("id" in result.data)) {
|
|
4115
|
+
return { data: void 0, error: null };
|
|
4116
|
+
}
|
|
4117
|
+
return result;
|
|
4118
|
+
}
|
|
4119
|
+
async associatePushTokenUserById(id, options) {
|
|
4120
|
+
return this.put(`/push/tokens/by-id/${id}/user`, {}, options);
|
|
4121
|
+
}
|
|
4122
|
+
async disassociatePushTokenUser(id, options) {
|
|
4123
|
+
const result = await this.del(`/push/tokens/by-id/${id}/user`, options);
|
|
4124
|
+
if (result.data && typeof result.data === "object" && !("id" in result.data)) {
|
|
4125
|
+
return { data: void 0, error: null };
|
|
4126
|
+
}
|
|
4127
|
+
return result;
|
|
4128
|
+
}
|
|
4129
|
+
// --------------------------------------------------------------------------
|
|
4130
|
+
// Push Notifications — Settings
|
|
4131
|
+
// --------------------------------------------------------------------------
|
|
4132
|
+
async getMyPushSettings(options) {
|
|
4133
|
+
return this._get("/push/settings/me", options);
|
|
4134
|
+
}
|
|
4135
|
+
// --------------------------------------------------------------------------
|
|
4136
|
+
// Push Notifications — Topics & Subscriptions
|
|
4137
|
+
// --------------------------------------------------------------------------
|
|
4138
|
+
async listTopics(options) {
|
|
4139
|
+
return this._get("/push/topics", options);
|
|
4140
|
+
}
|
|
4141
|
+
async subscribeTopic(topicId, data, options) {
|
|
4142
|
+
return this.post(`/push/topics/${topicId}/subscribe`, data || {}, options);
|
|
4143
|
+
}
|
|
4144
|
+
async unsubscribeTopic(topicId, options) {
|
|
4145
|
+
return this.del(`/push/topics/${topicId}/subscribe`, options);
|
|
4146
|
+
}
|
|
4147
|
+
async listSubscriptions(options) {
|
|
4148
|
+
return this._get("/push/subscriptions", options);
|
|
4149
|
+
}
|
|
4150
|
+
// --------------------------------------------------------------------------
|
|
4151
|
+
// Push Notifications — Preferences
|
|
4152
|
+
// --------------------------------------------------------------------------
|
|
4153
|
+
async getPushPreferences(options) {
|
|
4154
|
+
return this._get("/push/preferences", options);
|
|
4155
|
+
}
|
|
4156
|
+
async updatePushPreferences(data, options) {
|
|
4157
|
+
return this.put("/push/preferences", data, options);
|
|
4158
|
+
}
|
|
4109
4159
|
// --------------------------------------------------------------------------
|
|
4110
4160
|
// Message Status
|
|
4111
4161
|
// --------------------------------------------------------------------------
|
|
@@ -4125,6 +4175,258 @@ var CommunicationService = class extends ServiceModule {
|
|
|
4125
4175
|
}
|
|
4126
4176
|
};
|
|
4127
4177
|
|
|
4178
|
+
// src/web-push.ts
|
|
4179
|
+
var STORAGE_KEY = "scalemule_push_state";
|
|
4180
|
+
var WebPushManager = class {
|
|
4181
|
+
constructor(options) {
|
|
4182
|
+
this.state = null;
|
|
4183
|
+
this.registration = null;
|
|
4184
|
+
if (typeof window === "undefined") {
|
|
4185
|
+
throw new Error("WebPushManager can only be used in a browser environment");
|
|
4186
|
+
}
|
|
4187
|
+
this.fetcher = options.fetcher;
|
|
4188
|
+
this.swUrl = options.serviceWorkerUrl || "/sw.js";
|
|
4189
|
+
try {
|
|
4190
|
+
const stored = localStorage.getItem(STORAGE_KEY);
|
|
4191
|
+
if (stored) {
|
|
4192
|
+
this.state = JSON.parse(stored);
|
|
4193
|
+
}
|
|
4194
|
+
} catch {
|
|
4195
|
+
}
|
|
4196
|
+
}
|
|
4197
|
+
/** Whether the browser supports Web Push */
|
|
4198
|
+
isSupported() {
|
|
4199
|
+
return typeof window !== "undefined" && "serviceWorker" in navigator && "PushManager" in window && "Notification" in window;
|
|
4200
|
+
}
|
|
4201
|
+
/** Current notification permission state */
|
|
4202
|
+
getPermissionState() {
|
|
4203
|
+
if (!this.isSupported()) return "unsupported";
|
|
4204
|
+
return Notification.permission;
|
|
4205
|
+
}
|
|
4206
|
+
/** Request notification permission from the user */
|
|
4207
|
+
async requestPermission() {
|
|
4208
|
+
if (!this.isSupported()) return "denied";
|
|
4209
|
+
return Notification.requestPermission();
|
|
4210
|
+
}
|
|
4211
|
+
/**
|
|
4212
|
+
* Full subscribe flow:
|
|
4213
|
+
* 1. Check browser support
|
|
4214
|
+
* 2. Request notification permission
|
|
4215
|
+
* 3. Register service worker
|
|
4216
|
+
* 4. Fetch VAPID public key from backend
|
|
4217
|
+
* 5. PushManager.subscribe() with VAPID key
|
|
4218
|
+
* 6. Register token with backend
|
|
4219
|
+
*
|
|
4220
|
+
* @param deviceId Optional device identifier for anonymous users.
|
|
4221
|
+
* If not provided, generates a random UUID stored in localStorage.
|
|
4222
|
+
*/
|
|
4223
|
+
async subscribe(deviceId) {
|
|
4224
|
+
if (!this.isSupported()) return null;
|
|
4225
|
+
const permission = await this.requestPermission();
|
|
4226
|
+
if (permission !== "granted") return null;
|
|
4227
|
+
this.registration = await navigator.serviceWorker.register(this.swUrl);
|
|
4228
|
+
await navigator.serviceWorker.ready;
|
|
4229
|
+
const settings = await this.fetcher.getSettings();
|
|
4230
|
+
if (!settings.webpush_enabled || !settings.vapid_public_key) {
|
|
4231
|
+
throw new Error("Web Push is not enabled for this application");
|
|
4232
|
+
}
|
|
4233
|
+
const applicationServerKey = urlBase64ToUint8Array(settings.vapid_public_key);
|
|
4234
|
+
const pushSubscription = await this.registration.pushManager.subscribe({
|
|
4235
|
+
userVisibleOnly: true,
|
|
4236
|
+
applicationServerKey: applicationServerKey.buffer
|
|
4237
|
+
});
|
|
4238
|
+
const endpoint = pushSubscription.endpoint;
|
|
4239
|
+
const p256dh = arrayBufferToBase64url(pushSubscription.getKey("p256dh"));
|
|
4240
|
+
const auth = arrayBufferToBase64url(pushSubscription.getKey("auth"));
|
|
4241
|
+
const subscription = {
|
|
4242
|
+
endpoint,
|
|
4243
|
+
keys: { p256dh, auth }
|
|
4244
|
+
};
|
|
4245
|
+
const resolvedDeviceId = deviceId || this.state?.deviceId || generateDeviceId();
|
|
4246
|
+
const result = await this.fetcher.registerToken({
|
|
4247
|
+
token: endpoint,
|
|
4248
|
+
platform: "web",
|
|
4249
|
+
device_id: resolvedDeviceId,
|
|
4250
|
+
subscription
|
|
4251
|
+
});
|
|
4252
|
+
this.state = {
|
|
4253
|
+
endpoint,
|
|
4254
|
+
tokenId: result.id,
|
|
4255
|
+
deviceId: resolvedDeviceId
|
|
4256
|
+
};
|
|
4257
|
+
this.persistState();
|
|
4258
|
+
return { tokenId: result.id, endpoint };
|
|
4259
|
+
}
|
|
4260
|
+
/** Unsubscribe from browser push and deregister token */
|
|
4261
|
+
async unsubscribe() {
|
|
4262
|
+
const sub = await this.getSubscription();
|
|
4263
|
+
if (sub) {
|
|
4264
|
+
await sub.unsubscribe();
|
|
4265
|
+
}
|
|
4266
|
+
if (this.state?.tokenId) {
|
|
4267
|
+
try {
|
|
4268
|
+
await this.fetcher.unregisterToken(this.state.tokenId);
|
|
4269
|
+
} catch {
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4272
|
+
this.state = null;
|
|
4273
|
+
this.clearState();
|
|
4274
|
+
}
|
|
4275
|
+
/** Link push token to the currently authenticated user (call after login) */
|
|
4276
|
+
async associateUser() {
|
|
4277
|
+
if (!this.state?.tokenId) return;
|
|
4278
|
+
await this.fetcher.associateUser(this.state.tokenId);
|
|
4279
|
+
}
|
|
4280
|
+
/** Clear user association from push token (call before logout) */
|
|
4281
|
+
async disassociateUser() {
|
|
4282
|
+
if (!this.state?.tokenId) return;
|
|
4283
|
+
await this.fetcher.disassociateUser(this.state.tokenId);
|
|
4284
|
+
}
|
|
4285
|
+
/** Check if currently subscribed to push notifications */
|
|
4286
|
+
async isSubscribed() {
|
|
4287
|
+
if (!this.isSupported()) return false;
|
|
4288
|
+
const sub = await this.getSubscription();
|
|
4289
|
+
return sub !== null && this.state !== null;
|
|
4290
|
+
}
|
|
4291
|
+
/** Get the active PushSubscription from the service worker */
|
|
4292
|
+
async getSubscription() {
|
|
4293
|
+
if (!this.isSupported()) return null;
|
|
4294
|
+
try {
|
|
4295
|
+
const reg = await navigator.serviceWorker.getRegistration(this.swUrl);
|
|
4296
|
+
if (!reg) return null;
|
|
4297
|
+
return reg.pushManager.getSubscription();
|
|
4298
|
+
} catch {
|
|
4299
|
+
return null;
|
|
4300
|
+
}
|
|
4301
|
+
}
|
|
4302
|
+
/** Get the stored token ID (for external use) */
|
|
4303
|
+
getTokenId() {
|
|
4304
|
+
return this.state?.tokenId || null;
|
|
4305
|
+
}
|
|
4306
|
+
persistState() {
|
|
4307
|
+
if (this.state) {
|
|
4308
|
+
try {
|
|
4309
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(this.state));
|
|
4310
|
+
} catch {
|
|
4311
|
+
}
|
|
4312
|
+
}
|
|
4313
|
+
}
|
|
4314
|
+
clearState() {
|
|
4315
|
+
try {
|
|
4316
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
4317
|
+
} catch {
|
|
4318
|
+
}
|
|
4319
|
+
}
|
|
4320
|
+
};
|
|
4321
|
+
function urlBase64ToUint8Array(base64String) {
|
|
4322
|
+
const padding = "=".repeat((4 - base64String.length % 4) % 4);
|
|
4323
|
+
const base64 = (base64String + padding).replace(/-/g, "+").replace(/_/g, "/");
|
|
4324
|
+
const rawData = atob(base64);
|
|
4325
|
+
const outputArray = new Uint8Array(rawData.length);
|
|
4326
|
+
for (let i = 0; i < rawData.length; ++i) {
|
|
4327
|
+
outputArray[i] = rawData.charCodeAt(i);
|
|
4328
|
+
}
|
|
4329
|
+
return outputArray;
|
|
4330
|
+
}
|
|
4331
|
+
function arrayBufferToBase64url(buffer) {
|
|
4332
|
+
const bytes = new Uint8Array(buffer);
|
|
4333
|
+
const binary = Array.from(bytes, (b) => String.fromCharCode(b)).join("");
|
|
4334
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
4335
|
+
}
|
|
4336
|
+
function generateDeviceId() {
|
|
4337
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
4338
|
+
return crypto.randomUUID();
|
|
4339
|
+
}
|
|
4340
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
4341
|
+
const r = Math.random() * 16 | 0;
|
|
4342
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
4343
|
+
return v.toString(16);
|
|
4344
|
+
});
|
|
4345
|
+
}
|
|
4346
|
+
|
|
4347
|
+
// src/web-push-sw.ts
|
|
4348
|
+
var WEB_PUSH_SERVICE_WORKER = `
|
|
4349
|
+
// ScaleMule Push Notification Service Worker
|
|
4350
|
+
|
|
4351
|
+
self.addEventListener('push', function(event) {
|
|
4352
|
+
if (!event.data) return;
|
|
4353
|
+
|
|
4354
|
+
var data;
|
|
4355
|
+
try {
|
|
4356
|
+
data = event.data.json();
|
|
4357
|
+
} catch (e) {
|
|
4358
|
+
data = { title: 'New Notification', body: event.data.text() };
|
|
4359
|
+
}
|
|
4360
|
+
|
|
4361
|
+
var title = data.title || 'Notification';
|
|
4362
|
+
var options = {
|
|
4363
|
+
body: data.body || '',
|
|
4364
|
+
icon: data.icon || undefined,
|
|
4365
|
+
image: data.image || undefined,
|
|
4366
|
+
badge: data.badge || undefined,
|
|
4367
|
+
data: data.data || data,
|
|
4368
|
+
tag: data.tag || undefined,
|
|
4369
|
+
actions: data.actions || undefined,
|
|
4370
|
+
requireInteraction: data.requireInteraction || false,
|
|
4371
|
+
};
|
|
4372
|
+
|
|
4373
|
+
// Show the notification
|
|
4374
|
+
event.waitUntil(
|
|
4375
|
+
self.registration.showNotification(title, options)
|
|
4376
|
+
.then(function() {
|
|
4377
|
+
// Post message to all client pages for foreground handling
|
|
4378
|
+
return self.clients.matchAll({ type: 'window', includeUncontrolled: true });
|
|
4379
|
+
})
|
|
4380
|
+
.then(function(clients) {
|
|
4381
|
+
clients.forEach(function(client) {
|
|
4382
|
+
client.postMessage({
|
|
4383
|
+
type: 'push-received',
|
|
4384
|
+
payload: data,
|
|
4385
|
+
});
|
|
4386
|
+
});
|
|
4387
|
+
})
|
|
4388
|
+
);
|
|
4389
|
+
});
|
|
4390
|
+
|
|
4391
|
+
self.addEventListener('notificationclick', function(event) {
|
|
4392
|
+
event.notification.close();
|
|
4393
|
+
|
|
4394
|
+
var url = '/';
|
|
4395
|
+
if (event.notification.data && event.notification.data.url) {
|
|
4396
|
+
url = event.notification.data.url;
|
|
4397
|
+
}
|
|
4398
|
+
|
|
4399
|
+
// Handle action button clicks
|
|
4400
|
+
if (event.action && event.notification.data && event.notification.data.actions) {
|
|
4401
|
+
var action = event.notification.data.actions.find(function(a) {
|
|
4402
|
+
return a.action === event.action;
|
|
4403
|
+
});
|
|
4404
|
+
if (action && action.url) {
|
|
4405
|
+
url = action.url;
|
|
4406
|
+
}
|
|
4407
|
+
}
|
|
4408
|
+
|
|
4409
|
+
event.waitUntil(
|
|
4410
|
+
self.clients.matchAll({ type: 'window', includeUncontrolled: true })
|
|
4411
|
+
.then(function(clientList) {
|
|
4412
|
+
// Try to focus an existing window
|
|
4413
|
+
for (var i = 0; i < clientList.length; i++) {
|
|
4414
|
+
var client = clientList[i];
|
|
4415
|
+
if (client.url.indexOf(self.registration.scope) !== -1 && 'focus' in client) {
|
|
4416
|
+
client.focus();
|
|
4417
|
+
client.navigate(url);
|
|
4418
|
+
return;
|
|
4419
|
+
}
|
|
4420
|
+
}
|
|
4421
|
+
// Open a new window if none exists
|
|
4422
|
+
if (self.clients.openWindow) {
|
|
4423
|
+
return self.clients.openWindow(url);
|
|
4424
|
+
}
|
|
4425
|
+
})
|
|
4426
|
+
);
|
|
4427
|
+
});
|
|
4428
|
+
`;
|
|
4429
|
+
|
|
4128
4430
|
// src/services/scheduler.ts
|
|
4129
4431
|
var SchedulerService = class extends ServiceModule {
|
|
4130
4432
|
constructor() {
|
|
@@ -5724,6 +6026,8 @@ export {
|
|
|
5724
6026
|
UploadResumeStore,
|
|
5725
6027
|
UploadTelemetry,
|
|
5726
6028
|
VideoService,
|
|
6029
|
+
WEB_PUSH_SERVICE_WORKER,
|
|
6030
|
+
WebPushManager,
|
|
5727
6031
|
WebhooksService,
|
|
5728
6032
|
WorkspacesService,
|
|
5729
6033
|
buildClientContextHeaders,
|