@proofchain/sdk 2.16.0 → 2.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +91 -1
- package/dist/index.d.ts +91 -1
- package/dist/index.js +98 -0
- package/dist/index.mjs +97 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2948,6 +2948,94 @@ declare class FanpassLeaderboardClient {
|
|
|
2948
2948
|
}): Promise<FanpassUserComparisonResponse>;
|
|
2949
2949
|
}
|
|
2950
2950
|
|
|
2951
|
+
/**
|
|
2952
|
+
* Notifications Client
|
|
2953
|
+
*
|
|
2954
|
+
* Provides real-time notification streaming via Server-Sent Events (SSE).
|
|
2955
|
+
* Notifications are pushed from the backend when quest/reward events occur.
|
|
2956
|
+
*
|
|
2957
|
+
* @example
|
|
2958
|
+
* ```typescript
|
|
2959
|
+
* // Subscribe to notifications
|
|
2960
|
+
* const unsub = client.notifications.subscribe('user-123', (event) => {
|
|
2961
|
+
* switch (event.event) {
|
|
2962
|
+
* case 'quest_step_completed':
|
|
2963
|
+
* showToast(`Step completed: ${event.data.step_name}`);
|
|
2964
|
+
* break;
|
|
2965
|
+
* case 'quest_completed':
|
|
2966
|
+
* showToast(`Quest completed: ${event.data.quest_name}!`);
|
|
2967
|
+
* break;
|
|
2968
|
+
* case 'badge_earned':
|
|
2969
|
+
* showBadgeModal(event.data);
|
|
2970
|
+
* break;
|
|
2971
|
+
* case 'reward_claimable':
|
|
2972
|
+
* showClaimButton(event.data);
|
|
2973
|
+
* break;
|
|
2974
|
+
* }
|
|
2975
|
+
* });
|
|
2976
|
+
*
|
|
2977
|
+
* // Later, unsubscribe
|
|
2978
|
+
* unsub();
|
|
2979
|
+
* ```
|
|
2980
|
+
*/
|
|
2981
|
+
|
|
2982
|
+
/** Notification event types pushed by the server. */
|
|
2983
|
+
type NotificationEventType = 'connected' | 'quest_step_completed' | 'quest_completed' | 'reward_earned' | 'reward_distributed' | 'reward_claimable' | 'points_awarded' | 'badge_earned' | 'level_up';
|
|
2984
|
+
/** A notification event received from the SSE stream. */
|
|
2985
|
+
interface NotificationEvent {
|
|
2986
|
+
/** Unique event ID */
|
|
2987
|
+
id: string;
|
|
2988
|
+
/** Event type */
|
|
2989
|
+
event: NotificationEventType;
|
|
2990
|
+
/** Event-specific payload */
|
|
2991
|
+
data: Record<string, any>;
|
|
2992
|
+
/** Tenant ID */
|
|
2993
|
+
tenant_id: string;
|
|
2994
|
+
/** User ID */
|
|
2995
|
+
user_id: string;
|
|
2996
|
+
/** ISO timestamp */
|
|
2997
|
+
timestamp: string;
|
|
2998
|
+
}
|
|
2999
|
+
/** Callback invoked for each notification event. */
|
|
3000
|
+
type NotificationCallback = (event: NotificationEvent) => void;
|
|
3001
|
+
/** Options for the subscribe method. */
|
|
3002
|
+
interface SubscribeOptions {
|
|
3003
|
+
/** Called when the connection is established */
|
|
3004
|
+
onConnect?: () => void;
|
|
3005
|
+
/** Called when the connection is lost (will auto-reconnect) */
|
|
3006
|
+
onDisconnect?: () => void;
|
|
3007
|
+
/** Called on error */
|
|
3008
|
+
onError?: (error: Error) => void;
|
|
3009
|
+
/** Auto-reconnect on disconnect (default: true) */
|
|
3010
|
+
autoReconnect?: boolean;
|
|
3011
|
+
/** Reconnect delay in ms (default: 3000) */
|
|
3012
|
+
reconnectDelay?: number;
|
|
3013
|
+
}
|
|
3014
|
+
/** Function to call to unsubscribe / close the SSE connection. */
|
|
3015
|
+
type Unsubscribe = () => void;
|
|
3016
|
+
declare class NotificationsClient {
|
|
3017
|
+
private baseUrl;
|
|
3018
|
+
private authHeaders;
|
|
3019
|
+
constructor(http: HttpClient);
|
|
3020
|
+
/**
|
|
3021
|
+
* Subscribe to real-time notifications for a user.
|
|
3022
|
+
*
|
|
3023
|
+
* Opens a Server-Sent Events connection and calls the callback
|
|
3024
|
+
* for each notification event (quest progress, rewards, etc.).
|
|
3025
|
+
*
|
|
3026
|
+
* Returns an unsubscribe function to close the connection.
|
|
3027
|
+
*
|
|
3028
|
+
* **Browser usage:** Works out of the box with EventSource.
|
|
3029
|
+
* **Node.js usage:** Requires the `eventsource` package.
|
|
3030
|
+
*
|
|
3031
|
+
* @param userId - The external user ID to subscribe for
|
|
3032
|
+
* @param callback - Function called for each notification event
|
|
3033
|
+
* @param options - Connection options (reconnect, callbacks)
|
|
3034
|
+
* @returns Unsubscribe function to close the connection
|
|
3035
|
+
*/
|
|
3036
|
+
subscribe(userId: string, callback: NotificationCallback, options?: SubscribeOptions): Unsubscribe;
|
|
3037
|
+
}
|
|
3038
|
+
|
|
2951
3039
|
/**
|
|
2952
3040
|
* ProofChain Client
|
|
2953
3041
|
*/
|
|
@@ -3142,6 +3230,8 @@ declare class ProofChain {
|
|
|
3142
3230
|
cohorts: CohortLeaderboardClient;
|
|
3143
3231
|
/** Fanpass leaderboard client for composite score leaderboards */
|
|
3144
3232
|
fanpassLeaderboard: FanpassLeaderboardClient;
|
|
3233
|
+
/** Notifications client for real-time SSE streaming */
|
|
3234
|
+
notifications: NotificationsClient;
|
|
3145
3235
|
constructor(options: ProofChainOptions);
|
|
3146
3236
|
/**
|
|
3147
3237
|
* Create a client for end-user JWT authentication (PWA/frontend use).
|
|
@@ -3357,4 +3447,4 @@ declare class TimeoutError extends ProofChainError {
|
|
|
3357
3447
|
constructor(message?: string);
|
|
3358
3448
|
}
|
|
3359
3449
|
|
|
3360
|
-
export { type Achievement, type ActivitySummaryView, type AddNFTRequest, type ApiKey, type AttestRequest, type AttestationMode, type AttestationResult, AuthenticationError, AuthorizationError, type AvailableView, type Badge, type BatchIngestRequest, type BatchIngestResponse, type BatchVerifyResult, type BlockchainProof, type BlockchainStats, type Certificate, type CertificateVerifyResult, CertificatesResource, type Channel, type ChannelState, type ChannelStatus, ChannelsResource, type ClaimNFTResult, type ClaimRewardResult, type CohortDefinition, type CohortGroupStats, CohortLeaderboardClient, type CohortLeaderboardEntry, type CohortLeaderboardOptions, type CohortLeaderboardResponse, type ComprehensiveWalletInfo, type CreateAchievementRequest, type CreateApiKeyRequest, type CreateBadgeRequest, type CreateChannelRequest, type CreateDataViewRequest, type CreateDualWalletsRequest, type CreateEndUserRequest, type CreateEventRequest, type CreatePassportDefinitionRequest, type CreatePassportRequest, type CreateQuestRequest, type CreateQuestStepRequest, type CreateRewardDefinitionRequest, type CreateSchemaRequest, type CreateTemplateFieldRequest, type CreateTemplateRequest, type CreateWalletRequest as CreateUserWalletRequest, type CreateWalletRequest$1 as CreateWalletRequest, type CreateWebhookRequest, type DataViewColumn, type DataViewComputation, type DataViewDetail, type DataViewExecuteResult, type DataViewInfo, type DataViewListResponse, type DataViewPreviewRequest, type DataViewPreviewResult, type DataViewSummary, DataViewsClient, type DistributeResult, DocumentsResource, type DualWallets, type EarnedReward, type EndUser, EndUserIngestionClient, type EndUserIngestionClientOptions, type EndUserListResponse, EndUsersClient, type Event, type EventBatchProof, type EventMetadata, type EventStatus, EventsResource, type ExecuteSwapRequest, type Facet, type FacetsResponse, type FanProfileView, type FanpassGroupStats, FanpassLeaderboardClient, type FanpassLeaderboardEntry, type FanpassLeaderboardOptions, type FanpassLeaderboardResponse, type FanpassUserComparisonResponse, type FieldValue, type GDPRDeletionRequest, type GDPRDeletionResponse, type GDPRPreviewResponse, type IngestEventRequest, type IngestEventResponse, IngestionClient, type IngestionClientOptions, type IssueCertificateRequest, type LeaderboardUserProfile$1 as LeaderboardUserProfile, type LinkWalletRequest, type ListCertificatesRequest, type ListCohortsOptions, type ListEndUsersOptions, type ListEventsRequest, type ListQuestsOptions, type ListRewardsOptions, type ListSchemasOptions, type ManualRewardRequest, type MergeUsersRequest, type Milestone, type NFT, NetworkError, NotFoundError, type Passport, PassportClient, type PassportDefinition, type PassportFieldValue, type PassportHistory, type PassportTemplate, type PassportV2Data, type PassportWithFields, ProofChain, ProofChainError, type ProofChainOptions, type ProofVerifyResult, type Quest, type QuestStep, type QuestWithProgress, QuestsClient, RateLimitError, type RegisterWalletRequest, type RevokeResult, type RewardAsset, type RewardDefinition, type RewardEarned, RewardsClient, type Schema, type SchemaDetail, type SchemaField, type SchemaListResponse, type ValidationError$1 as SchemaValidationError, SchemasClient, type SearchFilters, type SearchQueryRequest, type SearchRequest, SearchResource, type SearchResponse, type SearchResult, type SearchStats, ServerError, type SetProfileRequest, type Settlement, type StepCompletionResult, type StepProgress, type StreamAck, type StreamEventRequest, type SwapQuote, type SwapQuoteRequest, type SwapResult, type TemplateField, type TenantInfo, TenantResource, type TierDefinition, TimeoutError, type TokenBalance, type TransferRequest, type TransferResult, type UpdateDataViewRequest, type UpdateEndUserRequest, type UpdatePassportRequest, type UpdateWebhookRequest, type UsageStats, type UserAchievement, type UserActivity, type UserActivityResponse, type UserBadge, type UserBreakdownResponse, type UserCohortBreakdownEntry, type UserQuestProgress, type UserReward$1 as UserReward, type UserRewardsResponse, type UserWalletSummary, type UserWithWallets, type UsersWithWalletsResponse, type ValidateDataRequest, ValidationError, type ValidationErrorDetail, type ValidationResult, type VaultFile, type VaultFolder, type VaultListResponse, VaultResource, type VaultStats, type VaultUploadRequest, type VerificationResult, VerifyResource, type ViewColumn, type ViewTemplate, type Wallet, type WalletBalance, WalletClient, type WalletCreationResult, type WalletStats, type Webhook, WebhooksResource };
|
|
3450
|
+
export { type Achievement, type ActivitySummaryView, type AddNFTRequest, type ApiKey, type AttestRequest, type AttestationMode, type AttestationResult, AuthenticationError, AuthorizationError, type AvailableView, type Badge, type BatchIngestRequest, type BatchIngestResponse, type BatchVerifyResult, type BlockchainProof, type BlockchainStats, type Certificate, type CertificateVerifyResult, CertificatesResource, type Channel, type ChannelState, type ChannelStatus, ChannelsResource, type ClaimNFTResult, type ClaimRewardResult, type CohortDefinition, type CohortGroupStats, CohortLeaderboardClient, type CohortLeaderboardEntry, type CohortLeaderboardOptions, type CohortLeaderboardResponse, type ComprehensiveWalletInfo, type CreateAchievementRequest, type CreateApiKeyRequest, type CreateBadgeRequest, type CreateChannelRequest, type CreateDataViewRequest, type CreateDualWalletsRequest, type CreateEndUserRequest, type CreateEventRequest, type CreatePassportDefinitionRequest, type CreatePassportRequest, type CreateQuestRequest, type CreateQuestStepRequest, type CreateRewardDefinitionRequest, type CreateSchemaRequest, type CreateTemplateFieldRequest, type CreateTemplateRequest, type CreateWalletRequest as CreateUserWalletRequest, type CreateWalletRequest$1 as CreateWalletRequest, type CreateWebhookRequest, type DataViewColumn, type DataViewComputation, type DataViewDetail, type DataViewExecuteResult, type DataViewInfo, type DataViewListResponse, type DataViewPreviewRequest, type DataViewPreviewResult, type DataViewSummary, DataViewsClient, type DistributeResult, DocumentsResource, type DualWallets, type EarnedReward, type EndUser, EndUserIngestionClient, type EndUserIngestionClientOptions, type EndUserListResponse, EndUsersClient, type Event, type EventBatchProof, type EventMetadata, type EventStatus, EventsResource, type ExecuteSwapRequest, type Facet, type FacetsResponse, type FanProfileView, type FanpassGroupStats, FanpassLeaderboardClient, type FanpassLeaderboardEntry, type FanpassLeaderboardOptions, type FanpassLeaderboardResponse, type FanpassUserComparisonResponse, type FieldValue, type GDPRDeletionRequest, type GDPRDeletionResponse, type GDPRPreviewResponse, type IngestEventRequest, type IngestEventResponse, IngestionClient, type IngestionClientOptions, type IssueCertificateRequest, type LeaderboardUserProfile$1 as LeaderboardUserProfile, type LinkWalletRequest, type ListCertificatesRequest, type ListCohortsOptions, type ListEndUsersOptions, type ListEventsRequest, type ListQuestsOptions, type ListRewardsOptions, type ListSchemasOptions, type ManualRewardRequest, type MergeUsersRequest, type Milestone, type NFT, NetworkError, NotFoundError, type NotificationCallback, type NotificationEvent, type NotificationEventType, NotificationsClient, type Passport, PassportClient, type PassportDefinition, type PassportFieldValue, type PassportHistory, type PassportTemplate, type PassportV2Data, type PassportWithFields, ProofChain, ProofChainError, type ProofChainOptions, type ProofVerifyResult, type Quest, type QuestStep, type QuestWithProgress, QuestsClient, RateLimitError, type RegisterWalletRequest, type RevokeResult, type RewardAsset, type RewardDefinition, type RewardEarned, RewardsClient, type Schema, type SchemaDetail, type SchemaField, type SchemaListResponse, type ValidationError$1 as SchemaValidationError, SchemasClient, type SearchFilters, type SearchQueryRequest, type SearchRequest, SearchResource, type SearchResponse, type SearchResult, type SearchStats, ServerError, type SetProfileRequest, type Settlement, type StepCompletionResult, type StepProgress, type StreamAck, type StreamEventRequest, type SubscribeOptions, type SwapQuote, type SwapQuoteRequest, type SwapResult, type TemplateField, type TenantInfo, TenantResource, type TierDefinition, TimeoutError, type TokenBalance, type TransferRequest, type TransferResult, type Unsubscribe, type UpdateDataViewRequest, type UpdateEndUserRequest, type UpdatePassportRequest, type UpdateWebhookRequest, type UsageStats, type UserAchievement, type UserActivity, type UserActivityResponse, type UserBadge, type UserBreakdownResponse, type UserCohortBreakdownEntry, type UserQuestProgress, type UserReward$1 as UserReward, type UserRewardsResponse, type UserWalletSummary, type UserWithWallets, type UsersWithWalletsResponse, type ValidateDataRequest, ValidationError, type ValidationErrorDetail, type ValidationResult, type VaultFile, type VaultFolder, type VaultListResponse, VaultResource, type VaultStats, type VaultUploadRequest, type VerificationResult, VerifyResource, type ViewColumn, type ViewTemplate, type Wallet, type WalletBalance, WalletClient, type WalletCreationResult, type WalletStats, type Webhook, WebhooksResource };
|
package/dist/index.d.ts
CHANGED
|
@@ -2948,6 +2948,94 @@ declare class FanpassLeaderboardClient {
|
|
|
2948
2948
|
}): Promise<FanpassUserComparisonResponse>;
|
|
2949
2949
|
}
|
|
2950
2950
|
|
|
2951
|
+
/**
|
|
2952
|
+
* Notifications Client
|
|
2953
|
+
*
|
|
2954
|
+
* Provides real-time notification streaming via Server-Sent Events (SSE).
|
|
2955
|
+
* Notifications are pushed from the backend when quest/reward events occur.
|
|
2956
|
+
*
|
|
2957
|
+
* @example
|
|
2958
|
+
* ```typescript
|
|
2959
|
+
* // Subscribe to notifications
|
|
2960
|
+
* const unsub = client.notifications.subscribe('user-123', (event) => {
|
|
2961
|
+
* switch (event.event) {
|
|
2962
|
+
* case 'quest_step_completed':
|
|
2963
|
+
* showToast(`Step completed: ${event.data.step_name}`);
|
|
2964
|
+
* break;
|
|
2965
|
+
* case 'quest_completed':
|
|
2966
|
+
* showToast(`Quest completed: ${event.data.quest_name}!`);
|
|
2967
|
+
* break;
|
|
2968
|
+
* case 'badge_earned':
|
|
2969
|
+
* showBadgeModal(event.data);
|
|
2970
|
+
* break;
|
|
2971
|
+
* case 'reward_claimable':
|
|
2972
|
+
* showClaimButton(event.data);
|
|
2973
|
+
* break;
|
|
2974
|
+
* }
|
|
2975
|
+
* });
|
|
2976
|
+
*
|
|
2977
|
+
* // Later, unsubscribe
|
|
2978
|
+
* unsub();
|
|
2979
|
+
* ```
|
|
2980
|
+
*/
|
|
2981
|
+
|
|
2982
|
+
/** Notification event types pushed by the server. */
|
|
2983
|
+
type NotificationEventType = 'connected' | 'quest_step_completed' | 'quest_completed' | 'reward_earned' | 'reward_distributed' | 'reward_claimable' | 'points_awarded' | 'badge_earned' | 'level_up';
|
|
2984
|
+
/** A notification event received from the SSE stream. */
|
|
2985
|
+
interface NotificationEvent {
|
|
2986
|
+
/** Unique event ID */
|
|
2987
|
+
id: string;
|
|
2988
|
+
/** Event type */
|
|
2989
|
+
event: NotificationEventType;
|
|
2990
|
+
/** Event-specific payload */
|
|
2991
|
+
data: Record<string, any>;
|
|
2992
|
+
/** Tenant ID */
|
|
2993
|
+
tenant_id: string;
|
|
2994
|
+
/** User ID */
|
|
2995
|
+
user_id: string;
|
|
2996
|
+
/** ISO timestamp */
|
|
2997
|
+
timestamp: string;
|
|
2998
|
+
}
|
|
2999
|
+
/** Callback invoked for each notification event. */
|
|
3000
|
+
type NotificationCallback = (event: NotificationEvent) => void;
|
|
3001
|
+
/** Options for the subscribe method. */
|
|
3002
|
+
interface SubscribeOptions {
|
|
3003
|
+
/** Called when the connection is established */
|
|
3004
|
+
onConnect?: () => void;
|
|
3005
|
+
/** Called when the connection is lost (will auto-reconnect) */
|
|
3006
|
+
onDisconnect?: () => void;
|
|
3007
|
+
/** Called on error */
|
|
3008
|
+
onError?: (error: Error) => void;
|
|
3009
|
+
/** Auto-reconnect on disconnect (default: true) */
|
|
3010
|
+
autoReconnect?: boolean;
|
|
3011
|
+
/** Reconnect delay in ms (default: 3000) */
|
|
3012
|
+
reconnectDelay?: number;
|
|
3013
|
+
}
|
|
3014
|
+
/** Function to call to unsubscribe / close the SSE connection. */
|
|
3015
|
+
type Unsubscribe = () => void;
|
|
3016
|
+
declare class NotificationsClient {
|
|
3017
|
+
private baseUrl;
|
|
3018
|
+
private authHeaders;
|
|
3019
|
+
constructor(http: HttpClient);
|
|
3020
|
+
/**
|
|
3021
|
+
* Subscribe to real-time notifications for a user.
|
|
3022
|
+
*
|
|
3023
|
+
* Opens a Server-Sent Events connection and calls the callback
|
|
3024
|
+
* for each notification event (quest progress, rewards, etc.).
|
|
3025
|
+
*
|
|
3026
|
+
* Returns an unsubscribe function to close the connection.
|
|
3027
|
+
*
|
|
3028
|
+
* **Browser usage:** Works out of the box with EventSource.
|
|
3029
|
+
* **Node.js usage:** Requires the `eventsource` package.
|
|
3030
|
+
*
|
|
3031
|
+
* @param userId - The external user ID to subscribe for
|
|
3032
|
+
* @param callback - Function called for each notification event
|
|
3033
|
+
* @param options - Connection options (reconnect, callbacks)
|
|
3034
|
+
* @returns Unsubscribe function to close the connection
|
|
3035
|
+
*/
|
|
3036
|
+
subscribe(userId: string, callback: NotificationCallback, options?: SubscribeOptions): Unsubscribe;
|
|
3037
|
+
}
|
|
3038
|
+
|
|
2951
3039
|
/**
|
|
2952
3040
|
* ProofChain Client
|
|
2953
3041
|
*/
|
|
@@ -3142,6 +3230,8 @@ declare class ProofChain {
|
|
|
3142
3230
|
cohorts: CohortLeaderboardClient;
|
|
3143
3231
|
/** Fanpass leaderboard client for composite score leaderboards */
|
|
3144
3232
|
fanpassLeaderboard: FanpassLeaderboardClient;
|
|
3233
|
+
/** Notifications client for real-time SSE streaming */
|
|
3234
|
+
notifications: NotificationsClient;
|
|
3145
3235
|
constructor(options: ProofChainOptions);
|
|
3146
3236
|
/**
|
|
3147
3237
|
* Create a client for end-user JWT authentication (PWA/frontend use).
|
|
@@ -3357,4 +3447,4 @@ declare class TimeoutError extends ProofChainError {
|
|
|
3357
3447
|
constructor(message?: string);
|
|
3358
3448
|
}
|
|
3359
3449
|
|
|
3360
|
-
export { type Achievement, type ActivitySummaryView, type AddNFTRequest, type ApiKey, type AttestRequest, type AttestationMode, type AttestationResult, AuthenticationError, AuthorizationError, type AvailableView, type Badge, type BatchIngestRequest, type BatchIngestResponse, type BatchVerifyResult, type BlockchainProof, type BlockchainStats, type Certificate, type CertificateVerifyResult, CertificatesResource, type Channel, type ChannelState, type ChannelStatus, ChannelsResource, type ClaimNFTResult, type ClaimRewardResult, type CohortDefinition, type CohortGroupStats, CohortLeaderboardClient, type CohortLeaderboardEntry, type CohortLeaderboardOptions, type CohortLeaderboardResponse, type ComprehensiveWalletInfo, type CreateAchievementRequest, type CreateApiKeyRequest, type CreateBadgeRequest, type CreateChannelRequest, type CreateDataViewRequest, type CreateDualWalletsRequest, type CreateEndUserRequest, type CreateEventRequest, type CreatePassportDefinitionRequest, type CreatePassportRequest, type CreateQuestRequest, type CreateQuestStepRequest, type CreateRewardDefinitionRequest, type CreateSchemaRequest, type CreateTemplateFieldRequest, type CreateTemplateRequest, type CreateWalletRequest as CreateUserWalletRequest, type CreateWalletRequest$1 as CreateWalletRequest, type CreateWebhookRequest, type DataViewColumn, type DataViewComputation, type DataViewDetail, type DataViewExecuteResult, type DataViewInfo, type DataViewListResponse, type DataViewPreviewRequest, type DataViewPreviewResult, type DataViewSummary, DataViewsClient, type DistributeResult, DocumentsResource, type DualWallets, type EarnedReward, type EndUser, EndUserIngestionClient, type EndUserIngestionClientOptions, type EndUserListResponse, EndUsersClient, type Event, type EventBatchProof, type EventMetadata, type EventStatus, EventsResource, type ExecuteSwapRequest, type Facet, type FacetsResponse, type FanProfileView, type FanpassGroupStats, FanpassLeaderboardClient, type FanpassLeaderboardEntry, type FanpassLeaderboardOptions, type FanpassLeaderboardResponse, type FanpassUserComparisonResponse, type FieldValue, type GDPRDeletionRequest, type GDPRDeletionResponse, type GDPRPreviewResponse, type IngestEventRequest, type IngestEventResponse, IngestionClient, type IngestionClientOptions, type IssueCertificateRequest, type LeaderboardUserProfile$1 as LeaderboardUserProfile, type LinkWalletRequest, type ListCertificatesRequest, type ListCohortsOptions, type ListEndUsersOptions, type ListEventsRequest, type ListQuestsOptions, type ListRewardsOptions, type ListSchemasOptions, type ManualRewardRequest, type MergeUsersRequest, type Milestone, type NFT, NetworkError, NotFoundError, type Passport, PassportClient, type PassportDefinition, type PassportFieldValue, type PassportHistory, type PassportTemplate, type PassportV2Data, type PassportWithFields, ProofChain, ProofChainError, type ProofChainOptions, type ProofVerifyResult, type Quest, type QuestStep, type QuestWithProgress, QuestsClient, RateLimitError, type RegisterWalletRequest, type RevokeResult, type RewardAsset, type RewardDefinition, type RewardEarned, RewardsClient, type Schema, type SchemaDetail, type SchemaField, type SchemaListResponse, type ValidationError$1 as SchemaValidationError, SchemasClient, type SearchFilters, type SearchQueryRequest, type SearchRequest, SearchResource, type SearchResponse, type SearchResult, type SearchStats, ServerError, type SetProfileRequest, type Settlement, type StepCompletionResult, type StepProgress, type StreamAck, type StreamEventRequest, type SwapQuote, type SwapQuoteRequest, type SwapResult, type TemplateField, type TenantInfo, TenantResource, type TierDefinition, TimeoutError, type TokenBalance, type TransferRequest, type TransferResult, type UpdateDataViewRequest, type UpdateEndUserRequest, type UpdatePassportRequest, type UpdateWebhookRequest, type UsageStats, type UserAchievement, type UserActivity, type UserActivityResponse, type UserBadge, type UserBreakdownResponse, type UserCohortBreakdownEntry, type UserQuestProgress, type UserReward$1 as UserReward, type UserRewardsResponse, type UserWalletSummary, type UserWithWallets, type UsersWithWalletsResponse, type ValidateDataRequest, ValidationError, type ValidationErrorDetail, type ValidationResult, type VaultFile, type VaultFolder, type VaultListResponse, VaultResource, type VaultStats, type VaultUploadRequest, type VerificationResult, VerifyResource, type ViewColumn, type ViewTemplate, type Wallet, type WalletBalance, WalletClient, type WalletCreationResult, type WalletStats, type Webhook, WebhooksResource };
|
|
3450
|
+
export { type Achievement, type ActivitySummaryView, type AddNFTRequest, type ApiKey, type AttestRequest, type AttestationMode, type AttestationResult, AuthenticationError, AuthorizationError, type AvailableView, type Badge, type BatchIngestRequest, type BatchIngestResponse, type BatchVerifyResult, type BlockchainProof, type BlockchainStats, type Certificate, type CertificateVerifyResult, CertificatesResource, type Channel, type ChannelState, type ChannelStatus, ChannelsResource, type ClaimNFTResult, type ClaimRewardResult, type CohortDefinition, type CohortGroupStats, CohortLeaderboardClient, type CohortLeaderboardEntry, type CohortLeaderboardOptions, type CohortLeaderboardResponse, type ComprehensiveWalletInfo, type CreateAchievementRequest, type CreateApiKeyRequest, type CreateBadgeRequest, type CreateChannelRequest, type CreateDataViewRequest, type CreateDualWalletsRequest, type CreateEndUserRequest, type CreateEventRequest, type CreatePassportDefinitionRequest, type CreatePassportRequest, type CreateQuestRequest, type CreateQuestStepRequest, type CreateRewardDefinitionRequest, type CreateSchemaRequest, type CreateTemplateFieldRequest, type CreateTemplateRequest, type CreateWalletRequest as CreateUserWalletRequest, type CreateWalletRequest$1 as CreateWalletRequest, type CreateWebhookRequest, type DataViewColumn, type DataViewComputation, type DataViewDetail, type DataViewExecuteResult, type DataViewInfo, type DataViewListResponse, type DataViewPreviewRequest, type DataViewPreviewResult, type DataViewSummary, DataViewsClient, type DistributeResult, DocumentsResource, type DualWallets, type EarnedReward, type EndUser, EndUserIngestionClient, type EndUserIngestionClientOptions, type EndUserListResponse, EndUsersClient, type Event, type EventBatchProof, type EventMetadata, type EventStatus, EventsResource, type ExecuteSwapRequest, type Facet, type FacetsResponse, type FanProfileView, type FanpassGroupStats, FanpassLeaderboardClient, type FanpassLeaderboardEntry, type FanpassLeaderboardOptions, type FanpassLeaderboardResponse, type FanpassUserComparisonResponse, type FieldValue, type GDPRDeletionRequest, type GDPRDeletionResponse, type GDPRPreviewResponse, type IngestEventRequest, type IngestEventResponse, IngestionClient, type IngestionClientOptions, type IssueCertificateRequest, type LeaderboardUserProfile$1 as LeaderboardUserProfile, type LinkWalletRequest, type ListCertificatesRequest, type ListCohortsOptions, type ListEndUsersOptions, type ListEventsRequest, type ListQuestsOptions, type ListRewardsOptions, type ListSchemasOptions, type ManualRewardRequest, type MergeUsersRequest, type Milestone, type NFT, NetworkError, NotFoundError, type NotificationCallback, type NotificationEvent, type NotificationEventType, NotificationsClient, type Passport, PassportClient, type PassportDefinition, type PassportFieldValue, type PassportHistory, type PassportTemplate, type PassportV2Data, type PassportWithFields, ProofChain, ProofChainError, type ProofChainOptions, type ProofVerifyResult, type Quest, type QuestStep, type QuestWithProgress, QuestsClient, RateLimitError, type RegisterWalletRequest, type RevokeResult, type RewardAsset, type RewardDefinition, type RewardEarned, RewardsClient, type Schema, type SchemaDetail, type SchemaField, type SchemaListResponse, type ValidationError$1 as SchemaValidationError, SchemasClient, type SearchFilters, type SearchQueryRequest, type SearchRequest, SearchResource, type SearchResponse, type SearchResult, type SearchStats, ServerError, type SetProfileRequest, type Settlement, type StepCompletionResult, type StepProgress, type StreamAck, type StreamEventRequest, type SubscribeOptions, type SwapQuote, type SwapQuoteRequest, type SwapResult, type TemplateField, type TenantInfo, TenantResource, type TierDefinition, TimeoutError, type TokenBalance, type TransferRequest, type TransferResult, type Unsubscribe, type UpdateDataViewRequest, type UpdateEndUserRequest, type UpdatePassportRequest, type UpdateWebhookRequest, type UsageStats, type UserAchievement, type UserActivity, type UserActivityResponse, type UserBadge, type UserBreakdownResponse, type UserCohortBreakdownEntry, type UserQuestProgress, type UserReward$1 as UserReward, type UserRewardsResponse, type UserWalletSummary, type UserWithWallets, type UsersWithWalletsResponse, type ValidateDataRequest, ValidationError, type ValidationErrorDetail, type ValidationResult, type VaultFile, type VaultFolder, type VaultListResponse, VaultResource, type VaultStats, type VaultUploadRequest, type VerificationResult, VerifyResource, type ViewColumn, type ViewTemplate, type Wallet, type WalletBalance, WalletClient, type WalletCreationResult, type WalletStats, type Webhook, WebhooksResource };
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(index_exports, {
|
|
|
34
34
|
IngestionClient: () => IngestionClient,
|
|
35
35
|
NetworkError: () => NetworkError,
|
|
36
36
|
NotFoundError: () => NotFoundError,
|
|
37
|
+
NotificationsClient: () => NotificationsClient,
|
|
37
38
|
PassportClient: () => PassportClient,
|
|
38
39
|
ProofChain: () => ProofChain,
|
|
39
40
|
ProofChainError: () => ProofChainError,
|
|
@@ -2149,6 +2150,101 @@ var FanpassLeaderboardClient = class {
|
|
|
2149
2150
|
}
|
|
2150
2151
|
};
|
|
2151
2152
|
|
|
2153
|
+
// src/notifications.ts
|
|
2154
|
+
var NotificationsClient = class {
|
|
2155
|
+
constructor(http) {
|
|
2156
|
+
this.baseUrl = http.baseUrl || "https://api.proofchain.co.za";
|
|
2157
|
+
this.authHeaders = () => {
|
|
2158
|
+
const headers = {};
|
|
2159
|
+
if (http.apiKey) {
|
|
2160
|
+
headers["X-API-Key"] = http.apiKey;
|
|
2161
|
+
}
|
|
2162
|
+
if (http.userToken) {
|
|
2163
|
+
headers["Authorization"] = `Bearer ${http.userToken}`;
|
|
2164
|
+
if (http.tenantId) {
|
|
2165
|
+
headers["X-Tenant-ID"] = http.tenantId;
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
return headers;
|
|
2169
|
+
};
|
|
2170
|
+
}
|
|
2171
|
+
/**
|
|
2172
|
+
* Subscribe to real-time notifications for a user.
|
|
2173
|
+
*
|
|
2174
|
+
* Opens a Server-Sent Events connection and calls the callback
|
|
2175
|
+
* for each notification event (quest progress, rewards, etc.).
|
|
2176
|
+
*
|
|
2177
|
+
* Returns an unsubscribe function to close the connection.
|
|
2178
|
+
*
|
|
2179
|
+
* **Browser usage:** Works out of the box with EventSource.
|
|
2180
|
+
* **Node.js usage:** Requires the `eventsource` package.
|
|
2181
|
+
*
|
|
2182
|
+
* @param userId - The external user ID to subscribe for
|
|
2183
|
+
* @param callback - Function called for each notification event
|
|
2184
|
+
* @param options - Connection options (reconnect, callbacks)
|
|
2185
|
+
* @returns Unsubscribe function to close the connection
|
|
2186
|
+
*/
|
|
2187
|
+
subscribe(userId, callback, options = {}) {
|
|
2188
|
+
const {
|
|
2189
|
+
onConnect,
|
|
2190
|
+
onDisconnect,
|
|
2191
|
+
onError,
|
|
2192
|
+
autoReconnect = true,
|
|
2193
|
+
reconnectDelay = 3e3
|
|
2194
|
+
} = options;
|
|
2195
|
+
let eventSource = null;
|
|
2196
|
+
let closed = false;
|
|
2197
|
+
let reconnectTimer = null;
|
|
2198
|
+
const connect = () => {
|
|
2199
|
+
if (closed) return;
|
|
2200
|
+
const headers = this.authHeaders();
|
|
2201
|
+
const params = new URLSearchParams({ user_id: userId });
|
|
2202
|
+
if (headers["X-API-Key"]) {
|
|
2203
|
+
params.append("api_key", headers["X-API-Key"]);
|
|
2204
|
+
}
|
|
2205
|
+
if (headers["Authorization"]) {
|
|
2206
|
+
params.append("token", headers["Authorization"].replace("Bearer ", ""));
|
|
2207
|
+
}
|
|
2208
|
+
if (headers["X-Tenant-ID"]) {
|
|
2209
|
+
params.append("tenant_id", headers["X-Tenant-ID"]);
|
|
2210
|
+
}
|
|
2211
|
+
const url = `${this.baseUrl}/notifications/stream?${params.toString()}`;
|
|
2212
|
+
const ES = typeof EventSource !== "undefined" ? EventSource : (() => {
|
|
2213
|
+
throw new Error('EventSource not available. Install the "eventsource" package for Node.js.');
|
|
2214
|
+
})();
|
|
2215
|
+
eventSource = new ES(url);
|
|
2216
|
+
eventSource.onmessage = (e) => {
|
|
2217
|
+
try {
|
|
2218
|
+
const event = JSON.parse(e.data);
|
|
2219
|
+
if (event.event === "connected") {
|
|
2220
|
+
onConnect?.();
|
|
2221
|
+
} else {
|
|
2222
|
+
callback(event);
|
|
2223
|
+
}
|
|
2224
|
+
} catch (err) {
|
|
2225
|
+
onError?.(new Error(`Failed to parse notification: ${e.data}`));
|
|
2226
|
+
}
|
|
2227
|
+
};
|
|
2228
|
+
eventSource.onerror = () => {
|
|
2229
|
+
if (closed) return;
|
|
2230
|
+
onDisconnect?.();
|
|
2231
|
+
if (eventSource?.readyState === 2 && autoReconnect) {
|
|
2232
|
+
reconnectTimer = setTimeout(connect, reconnectDelay);
|
|
2233
|
+
}
|
|
2234
|
+
};
|
|
2235
|
+
};
|
|
2236
|
+
connect();
|
|
2237
|
+
return () => {
|
|
2238
|
+
closed = true;
|
|
2239
|
+
if (reconnectTimer) clearTimeout(reconnectTimer);
|
|
2240
|
+
if (eventSource) {
|
|
2241
|
+
eventSource.close();
|
|
2242
|
+
eventSource = null;
|
|
2243
|
+
}
|
|
2244
|
+
};
|
|
2245
|
+
}
|
|
2246
|
+
};
|
|
2247
|
+
|
|
2152
2248
|
// src/client.ts
|
|
2153
2249
|
var DocumentsResource = class {
|
|
2154
2250
|
constructor(http) {
|
|
@@ -2446,6 +2542,7 @@ var ProofChain = class _ProofChain {
|
|
|
2446
2542
|
this.dataViews = new DataViewsClient(this.http);
|
|
2447
2543
|
this.cohorts = new CohortLeaderboardClient(this.http);
|
|
2448
2544
|
this.fanpassLeaderboard = new FanpassLeaderboardClient(this.http);
|
|
2545
|
+
this.notifications = new NotificationsClient(this.http);
|
|
2449
2546
|
}
|
|
2450
2547
|
/**
|
|
2451
2548
|
* Create a client for end-user JWT authentication (PWA/frontend use).
|
|
@@ -2789,6 +2886,7 @@ var EndUserIngestionClient = class {
|
|
|
2789
2886
|
IngestionClient,
|
|
2790
2887
|
NetworkError,
|
|
2791
2888
|
NotFoundError,
|
|
2889
|
+
NotificationsClient,
|
|
2792
2890
|
PassportClient,
|
|
2793
2891
|
ProofChain,
|
|
2794
2892
|
ProofChainError,
|
package/dist/index.mjs
CHANGED
|
@@ -2094,6 +2094,101 @@ var FanpassLeaderboardClient = class {
|
|
|
2094
2094
|
}
|
|
2095
2095
|
};
|
|
2096
2096
|
|
|
2097
|
+
// src/notifications.ts
|
|
2098
|
+
var NotificationsClient = class {
|
|
2099
|
+
constructor(http) {
|
|
2100
|
+
this.baseUrl = http.baseUrl || "https://api.proofchain.co.za";
|
|
2101
|
+
this.authHeaders = () => {
|
|
2102
|
+
const headers = {};
|
|
2103
|
+
if (http.apiKey) {
|
|
2104
|
+
headers["X-API-Key"] = http.apiKey;
|
|
2105
|
+
}
|
|
2106
|
+
if (http.userToken) {
|
|
2107
|
+
headers["Authorization"] = `Bearer ${http.userToken}`;
|
|
2108
|
+
if (http.tenantId) {
|
|
2109
|
+
headers["X-Tenant-ID"] = http.tenantId;
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
return headers;
|
|
2113
|
+
};
|
|
2114
|
+
}
|
|
2115
|
+
/**
|
|
2116
|
+
* Subscribe to real-time notifications for a user.
|
|
2117
|
+
*
|
|
2118
|
+
* Opens a Server-Sent Events connection and calls the callback
|
|
2119
|
+
* for each notification event (quest progress, rewards, etc.).
|
|
2120
|
+
*
|
|
2121
|
+
* Returns an unsubscribe function to close the connection.
|
|
2122
|
+
*
|
|
2123
|
+
* **Browser usage:** Works out of the box with EventSource.
|
|
2124
|
+
* **Node.js usage:** Requires the `eventsource` package.
|
|
2125
|
+
*
|
|
2126
|
+
* @param userId - The external user ID to subscribe for
|
|
2127
|
+
* @param callback - Function called for each notification event
|
|
2128
|
+
* @param options - Connection options (reconnect, callbacks)
|
|
2129
|
+
* @returns Unsubscribe function to close the connection
|
|
2130
|
+
*/
|
|
2131
|
+
subscribe(userId, callback, options = {}) {
|
|
2132
|
+
const {
|
|
2133
|
+
onConnect,
|
|
2134
|
+
onDisconnect,
|
|
2135
|
+
onError,
|
|
2136
|
+
autoReconnect = true,
|
|
2137
|
+
reconnectDelay = 3e3
|
|
2138
|
+
} = options;
|
|
2139
|
+
let eventSource = null;
|
|
2140
|
+
let closed = false;
|
|
2141
|
+
let reconnectTimer = null;
|
|
2142
|
+
const connect = () => {
|
|
2143
|
+
if (closed) return;
|
|
2144
|
+
const headers = this.authHeaders();
|
|
2145
|
+
const params = new URLSearchParams({ user_id: userId });
|
|
2146
|
+
if (headers["X-API-Key"]) {
|
|
2147
|
+
params.append("api_key", headers["X-API-Key"]);
|
|
2148
|
+
}
|
|
2149
|
+
if (headers["Authorization"]) {
|
|
2150
|
+
params.append("token", headers["Authorization"].replace("Bearer ", ""));
|
|
2151
|
+
}
|
|
2152
|
+
if (headers["X-Tenant-ID"]) {
|
|
2153
|
+
params.append("tenant_id", headers["X-Tenant-ID"]);
|
|
2154
|
+
}
|
|
2155
|
+
const url = `${this.baseUrl}/notifications/stream?${params.toString()}`;
|
|
2156
|
+
const ES = typeof EventSource !== "undefined" ? EventSource : (() => {
|
|
2157
|
+
throw new Error('EventSource not available. Install the "eventsource" package for Node.js.');
|
|
2158
|
+
})();
|
|
2159
|
+
eventSource = new ES(url);
|
|
2160
|
+
eventSource.onmessage = (e) => {
|
|
2161
|
+
try {
|
|
2162
|
+
const event = JSON.parse(e.data);
|
|
2163
|
+
if (event.event === "connected") {
|
|
2164
|
+
onConnect?.();
|
|
2165
|
+
} else {
|
|
2166
|
+
callback(event);
|
|
2167
|
+
}
|
|
2168
|
+
} catch (err) {
|
|
2169
|
+
onError?.(new Error(`Failed to parse notification: ${e.data}`));
|
|
2170
|
+
}
|
|
2171
|
+
};
|
|
2172
|
+
eventSource.onerror = () => {
|
|
2173
|
+
if (closed) return;
|
|
2174
|
+
onDisconnect?.();
|
|
2175
|
+
if (eventSource?.readyState === 2 && autoReconnect) {
|
|
2176
|
+
reconnectTimer = setTimeout(connect, reconnectDelay);
|
|
2177
|
+
}
|
|
2178
|
+
};
|
|
2179
|
+
};
|
|
2180
|
+
connect();
|
|
2181
|
+
return () => {
|
|
2182
|
+
closed = true;
|
|
2183
|
+
if (reconnectTimer) clearTimeout(reconnectTimer);
|
|
2184
|
+
if (eventSource) {
|
|
2185
|
+
eventSource.close();
|
|
2186
|
+
eventSource = null;
|
|
2187
|
+
}
|
|
2188
|
+
};
|
|
2189
|
+
}
|
|
2190
|
+
};
|
|
2191
|
+
|
|
2097
2192
|
// src/client.ts
|
|
2098
2193
|
var DocumentsResource = class {
|
|
2099
2194
|
constructor(http) {
|
|
@@ -2391,6 +2486,7 @@ var ProofChain = class _ProofChain {
|
|
|
2391
2486
|
this.dataViews = new DataViewsClient(this.http);
|
|
2392
2487
|
this.cohorts = new CohortLeaderboardClient(this.http);
|
|
2393
2488
|
this.fanpassLeaderboard = new FanpassLeaderboardClient(this.http);
|
|
2489
|
+
this.notifications = new NotificationsClient(this.http);
|
|
2394
2490
|
}
|
|
2395
2491
|
/**
|
|
2396
2492
|
* Create a client for end-user JWT authentication (PWA/frontend use).
|
|
@@ -2733,6 +2829,7 @@ export {
|
|
|
2733
2829
|
IngestionClient,
|
|
2734
2830
|
NetworkError,
|
|
2735
2831
|
NotFoundError,
|
|
2832
|
+
NotificationsClient,
|
|
2736
2833
|
PassportClient,
|
|
2737
2834
|
ProofChain,
|
|
2738
2835
|
ProofChainError,
|
package/package.json
CHANGED