@proofchain/sdk 2.14.0 → 2.15.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 CHANGED
@@ -3128,6 +3128,16 @@ interface IngestionClientOptions {
3128
3128
  ingestUrl?: string;
3129
3129
  timeout?: number;
3130
3130
  }
3131
+ interface EndUserIngestionClientOptions {
3132
+ /** End-user JWT from your auth provider (Auth0, Firebase, Clerk, etc.) */
3133
+ userToken: string;
3134
+ /** Proofchain tenant slug or client_id */
3135
+ tenantId: string;
3136
+ /** Base URL for the tenant API (default: https://api.proofchain.co.za) */
3137
+ apiUrl?: string;
3138
+ /** Request timeout in ms (default: 30000) */
3139
+ timeout?: number;
3140
+ }
3131
3141
  /**
3132
3142
  * High-performance ingestion client for the Rust ingestion API.
3133
3143
  *
@@ -3176,6 +3186,47 @@ declare class IngestionClient {
3176
3186
  ipfsHash?: string;
3177
3187
  }>;
3178
3188
  }
3189
+ /**
3190
+ * End-user ingestion client that routes events through the tenant-api JWKS proxy.
3191
+ * Events are validated (JWT + user_id enforcement) then forwarded to the Rust
3192
+ * ingestion pipeline for consistent processing.
3193
+ *
3194
+ * @example
3195
+ * ```typescript
3196
+ * const ingestion = new EndUserIngestionClient({
3197
+ * userToken: auth.getIdToken(),
3198
+ * tenantId: 'my-tenant-slug',
3199
+ * });
3200
+ *
3201
+ * // Submit event (user_id MUST match the JWT's user identity)
3202
+ * const result = await ingestion.ingest({
3203
+ * userId: 'user-123',
3204
+ * eventType: 'page_view',
3205
+ * data: { page: '/home' },
3206
+ * });
3207
+ * ```
3208
+ */
3209
+ declare class EndUserIngestionClient {
3210
+ private userToken;
3211
+ private tenantId;
3212
+ private apiUrl;
3213
+ private timeout;
3214
+ constructor(options: EndUserIngestionClientOptions);
3215
+ /** Update the end-user JWT token (e.g., after token refresh). */
3216
+ setToken(userToken: string): void;
3217
+ private getHeaders;
3218
+ private handleResponse;
3219
+ /**
3220
+ * Submit a single event as an authenticated end-user.
3221
+ * The userId MUST match the JWT's user identity or the request will be rejected with 403.
3222
+ */
3223
+ ingest(request: IngestEventRequest): Promise<IngestEventResponse>;
3224
+ /**
3225
+ * Submit a batch of events as an authenticated end-user (up to 100 events).
3226
+ * ALL events must have userId matching the JWT's user identity.
3227
+ */
3228
+ ingestBatch(request: BatchIngestRequest): Promise<BatchIngestResponse>;
3229
+ }
3179
3230
 
3180
3231
  /**
3181
3232
  * ProofChain SDK Error Classes
@@ -3217,4 +3268,4 @@ declare class TimeoutError extends ProofChainError {
3217
3268
  constructor(message?: string);
3218
3269
  }
3219
3270
 
3220
- 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 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, DocumentsResource, type DualWallets, type EarnedReward, type EndUser, 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 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 };
3271
+ 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 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, 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 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 };
package/dist/index.d.ts CHANGED
@@ -3128,6 +3128,16 @@ interface IngestionClientOptions {
3128
3128
  ingestUrl?: string;
3129
3129
  timeout?: number;
3130
3130
  }
3131
+ interface EndUserIngestionClientOptions {
3132
+ /** End-user JWT from your auth provider (Auth0, Firebase, Clerk, etc.) */
3133
+ userToken: string;
3134
+ /** Proofchain tenant slug or client_id */
3135
+ tenantId: string;
3136
+ /** Base URL for the tenant API (default: https://api.proofchain.co.za) */
3137
+ apiUrl?: string;
3138
+ /** Request timeout in ms (default: 30000) */
3139
+ timeout?: number;
3140
+ }
3131
3141
  /**
3132
3142
  * High-performance ingestion client for the Rust ingestion API.
3133
3143
  *
@@ -3176,6 +3186,47 @@ declare class IngestionClient {
3176
3186
  ipfsHash?: string;
3177
3187
  }>;
3178
3188
  }
3189
+ /**
3190
+ * End-user ingestion client that routes events through the tenant-api JWKS proxy.
3191
+ * Events are validated (JWT + user_id enforcement) then forwarded to the Rust
3192
+ * ingestion pipeline for consistent processing.
3193
+ *
3194
+ * @example
3195
+ * ```typescript
3196
+ * const ingestion = new EndUserIngestionClient({
3197
+ * userToken: auth.getIdToken(),
3198
+ * tenantId: 'my-tenant-slug',
3199
+ * });
3200
+ *
3201
+ * // Submit event (user_id MUST match the JWT's user identity)
3202
+ * const result = await ingestion.ingest({
3203
+ * userId: 'user-123',
3204
+ * eventType: 'page_view',
3205
+ * data: { page: '/home' },
3206
+ * });
3207
+ * ```
3208
+ */
3209
+ declare class EndUserIngestionClient {
3210
+ private userToken;
3211
+ private tenantId;
3212
+ private apiUrl;
3213
+ private timeout;
3214
+ constructor(options: EndUserIngestionClientOptions);
3215
+ /** Update the end-user JWT token (e.g., after token refresh). */
3216
+ setToken(userToken: string): void;
3217
+ private getHeaders;
3218
+ private handleResponse;
3219
+ /**
3220
+ * Submit a single event as an authenticated end-user.
3221
+ * The userId MUST match the JWT's user identity or the request will be rejected with 403.
3222
+ */
3223
+ ingest(request: IngestEventRequest): Promise<IngestEventResponse>;
3224
+ /**
3225
+ * Submit a batch of events as an authenticated end-user (up to 100 events).
3226
+ * ALL events must have userId matching the JWT's user identity.
3227
+ */
3228
+ ingestBatch(request: BatchIngestRequest): Promise<BatchIngestResponse>;
3229
+ }
3179
3230
 
3180
3231
  /**
3181
3232
  * ProofChain SDK Error Classes
@@ -3217,4 +3268,4 @@ declare class TimeoutError extends ProofChainError {
3217
3268
  constructor(message?: string);
3218
3269
  }
3219
3270
 
3220
- 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 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, DocumentsResource, type DualWallets, type EarnedReward, type EndUser, 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 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 };
3271
+ 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 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, 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 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 };
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ __export(index_exports, {
27
27
  CohortLeaderboardClient: () => CohortLeaderboardClient,
28
28
  DataViewsClient: () => DataViewsClient,
29
29
  DocumentsResource: () => DocumentsResource,
30
+ EndUserIngestionClient: () => EndUserIngestionClient,
30
31
  EndUsersClient: () => EndUsersClient,
31
32
  EventsResource: () => EventsResource,
32
33
  FanpassLeaderboardClient: () => FanpassLeaderboardClient,
@@ -2552,6 +2553,135 @@ var IngestionClient = class {
2552
2553
  }
2553
2554
  }
2554
2555
  };
2556
+ var EndUserIngestionClient = class {
2557
+ constructor(options) {
2558
+ this.userToken = options.userToken;
2559
+ this.tenantId = options.tenantId;
2560
+ this.apiUrl = (options.apiUrl || "https://api.proofchain.co.za").replace(/\/$/, "");
2561
+ this.timeout = options.timeout || 3e4;
2562
+ }
2563
+ /** Update the end-user JWT token (e.g., after token refresh). */
2564
+ setToken(userToken) {
2565
+ this.userToken = userToken;
2566
+ }
2567
+ getHeaders() {
2568
+ return {
2569
+ "Authorization": `Bearer ${this.userToken}`,
2570
+ "X-Tenant-ID": this.tenantId,
2571
+ "Content-Type": "application/json",
2572
+ "User-Agent": USER_AGENT2
2573
+ };
2574
+ }
2575
+ async handleResponse(response) {
2576
+ const contentType = response.headers.get("content-type");
2577
+ const isJson = contentType?.includes("application/json");
2578
+ if (response.ok) {
2579
+ if (response.status === 204 || !isJson) {
2580
+ return {};
2581
+ }
2582
+ return response.json();
2583
+ }
2584
+ const body = isJson ? await response.json().catch(() => ({})) : {};
2585
+ const message = body.detail || body.message || `HTTP ${response.status}`;
2586
+ switch (response.status) {
2587
+ case 401:
2588
+ throw new AuthenticationError(message);
2589
+ case 403:
2590
+ throw new ProofChainError(message, 403, body);
2591
+ case 422:
2592
+ case 400:
2593
+ throw new ValidationError(message, body.errors);
2594
+ case 429:
2595
+ const retryAfter = response.headers.get("Retry-After");
2596
+ throw new RateLimitError(retryAfter ? parseInt(retryAfter, 10) : void 0);
2597
+ default:
2598
+ if (response.status >= 500) {
2599
+ throw new ServerError(message, response.status);
2600
+ }
2601
+ throw new ProofChainError(message, response.status, body);
2602
+ }
2603
+ }
2604
+ /**
2605
+ * Submit a single event as an authenticated end-user.
2606
+ * The userId MUST match the JWT's user identity or the request will be rejected with 403.
2607
+ */
2608
+ async ingest(request) {
2609
+ const controller = new AbortController();
2610
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
2611
+ try {
2612
+ const response = await fetch(`${this.apiUrl}/end-user/events/ingest`, {
2613
+ method: "POST",
2614
+ headers: this.getHeaders(),
2615
+ body: JSON.stringify({
2616
+ user_id: request.userId,
2617
+ event_type: request.eventType,
2618
+ data: request.data || {},
2619
+ event_source: request.eventSource || "end_user_sdk"
2620
+ }),
2621
+ signal: controller.signal
2622
+ });
2623
+ const result = await this.handleResponse(response);
2624
+ return {
2625
+ eventId: result.event_id,
2626
+ certificateId: result.certificate_id,
2627
+ status: result.status,
2628
+ queuePosition: result.queue_position,
2629
+ estimatedConfirmation: result.estimated_confirmation
2630
+ };
2631
+ } catch (error) {
2632
+ if (error instanceof Error && error.name === "AbortError") {
2633
+ throw new NetworkError("Request timed out");
2634
+ }
2635
+ throw error;
2636
+ } finally {
2637
+ clearTimeout(timeoutId);
2638
+ }
2639
+ }
2640
+ /**
2641
+ * Submit a batch of events as an authenticated end-user (up to 100 events).
2642
+ * ALL events must have userId matching the JWT's user identity.
2643
+ */
2644
+ async ingestBatch(request) {
2645
+ if (request.events.length > 100) {
2646
+ throw new ValidationError("End-user batch size cannot exceed 100 events");
2647
+ }
2648
+ const controller = new AbortController();
2649
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout * 2);
2650
+ try {
2651
+ const response = await fetch(`${this.apiUrl}/end-user/events/ingest/batch`, {
2652
+ method: "POST",
2653
+ headers: this.getHeaders(),
2654
+ body: JSON.stringify({
2655
+ events: request.events.map((e) => ({
2656
+ user_id: e.userId,
2657
+ event_type: e.eventType,
2658
+ data: e.data || {},
2659
+ event_source: e.eventSource || "end_user_sdk"
2660
+ }))
2661
+ }),
2662
+ signal: controller.signal
2663
+ });
2664
+ const result = await this.handleResponse(response);
2665
+ return {
2666
+ totalEvents: result.total_events || result.total,
2667
+ queued: result.queued,
2668
+ failed: result.failed,
2669
+ results: (result.results || result.responses || []).map((r) => ({
2670
+ eventId: r.event_id,
2671
+ certificateId: r.certificate_id,
2672
+ status: r.status
2673
+ }))
2674
+ };
2675
+ } catch (error) {
2676
+ if (error instanceof Error && error.name === "AbortError") {
2677
+ throw new NetworkError("Request timed out");
2678
+ }
2679
+ throw error;
2680
+ } finally {
2681
+ clearTimeout(timeoutId);
2682
+ }
2683
+ }
2684
+ };
2555
2685
  // Annotate the CommonJS export names for ESM import in node:
2556
2686
  0 && (module.exports = {
2557
2687
  AuthenticationError,
@@ -2561,6 +2691,7 @@ var IngestionClient = class {
2561
2691
  CohortLeaderboardClient,
2562
2692
  DataViewsClient,
2563
2693
  DocumentsResource,
2694
+ EndUserIngestionClient,
2564
2695
  EndUsersClient,
2565
2696
  EventsResource,
2566
2697
  FanpassLeaderboardClient,
package/dist/index.mjs CHANGED
@@ -2498,6 +2498,135 @@ var IngestionClient = class {
2498
2498
  }
2499
2499
  }
2500
2500
  };
2501
+ var EndUserIngestionClient = class {
2502
+ constructor(options) {
2503
+ this.userToken = options.userToken;
2504
+ this.tenantId = options.tenantId;
2505
+ this.apiUrl = (options.apiUrl || "https://api.proofchain.co.za").replace(/\/$/, "");
2506
+ this.timeout = options.timeout || 3e4;
2507
+ }
2508
+ /** Update the end-user JWT token (e.g., after token refresh). */
2509
+ setToken(userToken) {
2510
+ this.userToken = userToken;
2511
+ }
2512
+ getHeaders() {
2513
+ return {
2514
+ "Authorization": `Bearer ${this.userToken}`,
2515
+ "X-Tenant-ID": this.tenantId,
2516
+ "Content-Type": "application/json",
2517
+ "User-Agent": USER_AGENT2
2518
+ };
2519
+ }
2520
+ async handleResponse(response) {
2521
+ const contentType = response.headers.get("content-type");
2522
+ const isJson = contentType?.includes("application/json");
2523
+ if (response.ok) {
2524
+ if (response.status === 204 || !isJson) {
2525
+ return {};
2526
+ }
2527
+ return response.json();
2528
+ }
2529
+ const body = isJson ? await response.json().catch(() => ({})) : {};
2530
+ const message = body.detail || body.message || `HTTP ${response.status}`;
2531
+ switch (response.status) {
2532
+ case 401:
2533
+ throw new AuthenticationError(message);
2534
+ case 403:
2535
+ throw new ProofChainError(message, 403, body);
2536
+ case 422:
2537
+ case 400:
2538
+ throw new ValidationError(message, body.errors);
2539
+ case 429:
2540
+ const retryAfter = response.headers.get("Retry-After");
2541
+ throw new RateLimitError(retryAfter ? parseInt(retryAfter, 10) : void 0);
2542
+ default:
2543
+ if (response.status >= 500) {
2544
+ throw new ServerError(message, response.status);
2545
+ }
2546
+ throw new ProofChainError(message, response.status, body);
2547
+ }
2548
+ }
2549
+ /**
2550
+ * Submit a single event as an authenticated end-user.
2551
+ * The userId MUST match the JWT's user identity or the request will be rejected with 403.
2552
+ */
2553
+ async ingest(request) {
2554
+ const controller = new AbortController();
2555
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
2556
+ try {
2557
+ const response = await fetch(`${this.apiUrl}/end-user/events/ingest`, {
2558
+ method: "POST",
2559
+ headers: this.getHeaders(),
2560
+ body: JSON.stringify({
2561
+ user_id: request.userId,
2562
+ event_type: request.eventType,
2563
+ data: request.data || {},
2564
+ event_source: request.eventSource || "end_user_sdk"
2565
+ }),
2566
+ signal: controller.signal
2567
+ });
2568
+ const result = await this.handleResponse(response);
2569
+ return {
2570
+ eventId: result.event_id,
2571
+ certificateId: result.certificate_id,
2572
+ status: result.status,
2573
+ queuePosition: result.queue_position,
2574
+ estimatedConfirmation: result.estimated_confirmation
2575
+ };
2576
+ } catch (error) {
2577
+ if (error instanceof Error && error.name === "AbortError") {
2578
+ throw new NetworkError("Request timed out");
2579
+ }
2580
+ throw error;
2581
+ } finally {
2582
+ clearTimeout(timeoutId);
2583
+ }
2584
+ }
2585
+ /**
2586
+ * Submit a batch of events as an authenticated end-user (up to 100 events).
2587
+ * ALL events must have userId matching the JWT's user identity.
2588
+ */
2589
+ async ingestBatch(request) {
2590
+ if (request.events.length > 100) {
2591
+ throw new ValidationError("End-user batch size cannot exceed 100 events");
2592
+ }
2593
+ const controller = new AbortController();
2594
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout * 2);
2595
+ try {
2596
+ const response = await fetch(`${this.apiUrl}/end-user/events/ingest/batch`, {
2597
+ method: "POST",
2598
+ headers: this.getHeaders(),
2599
+ body: JSON.stringify({
2600
+ events: request.events.map((e) => ({
2601
+ user_id: e.userId,
2602
+ event_type: e.eventType,
2603
+ data: e.data || {},
2604
+ event_source: e.eventSource || "end_user_sdk"
2605
+ }))
2606
+ }),
2607
+ signal: controller.signal
2608
+ });
2609
+ const result = await this.handleResponse(response);
2610
+ return {
2611
+ totalEvents: result.total_events || result.total,
2612
+ queued: result.queued,
2613
+ failed: result.failed,
2614
+ results: (result.results || result.responses || []).map((r) => ({
2615
+ eventId: r.event_id,
2616
+ certificateId: r.certificate_id,
2617
+ status: r.status
2618
+ }))
2619
+ };
2620
+ } catch (error) {
2621
+ if (error instanceof Error && error.name === "AbortError") {
2622
+ throw new NetworkError("Request timed out");
2623
+ }
2624
+ throw error;
2625
+ } finally {
2626
+ clearTimeout(timeoutId);
2627
+ }
2628
+ }
2629
+ };
2501
2630
  export {
2502
2631
  AuthenticationError,
2503
2632
  AuthorizationError,
@@ -2506,6 +2635,7 @@ export {
2506
2635
  CohortLeaderboardClient,
2507
2636
  DataViewsClient,
2508
2637
  DocumentsResource,
2638
+ EndUserIngestionClient,
2509
2639
  EndUsersClient,
2510
2640
  EventsResource,
2511
2641
  FanpassLeaderboardClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proofchain/sdk",
3
- "version": "2.14.0",
3
+ "version": "2.15.0",
4
4
  "description": "Official JavaScript/TypeScript SDK for ProofChain - blockchain-anchored document attestation",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",