@pickleball/server-sdk 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,206 @@
1
+ type SdkErrorCode = "PERMISSION_DENIED" | "NETWORK_UNAVAILABLE" | "TOKEN_EXPIRED" | "SDK_UPGRADE_REQUIRED" | "SESSION_CONFLICT" | "RECORDING_FAILED" | "CONSENT_REQUIRED" | "SDK_DISABLED" | "UNKNOWN";
2
+ type ServerSdkErrorCode = SdkErrorCode | "CONFIGURATION_ERROR" | "TIMEOUT" | "NETWORK_ERROR" | "HTTP_ERROR" | "INVALID_RESPONSE" | "WEBHOOK_VERIFICATION_FAILED";
3
+ declare class PickleballLiveError extends Error {
4
+ readonly code: ServerSdkErrorCode;
5
+ constructor(message: string, code: ServerSdkErrorCode, options?: ErrorOptions);
6
+ }
7
+ declare class PickleballConfigurationError extends PickleballLiveError {
8
+ constructor(message: string);
9
+ }
10
+ declare class PickleballApiError extends PickleballLiveError {
11
+ readonly status: number;
12
+ constructor(message: string,
13
+ /** Stable allowlisted code. Unknown server codes are normalized to UNKNOWN. */
14
+ code: SdkErrorCode, status: number);
15
+ }
16
+ declare class PickleballHttpError extends PickleballLiveError {
17
+ readonly status: number;
18
+ constructor(status: number);
19
+ }
20
+ declare class PickleballInvalidResponseError extends PickleballLiveError {
21
+ constructor();
22
+ }
23
+ declare class PickleballTimeoutError extends PickleballLiveError {
24
+ constructor();
25
+ }
26
+ declare class PickleballNetworkError extends PickleballLiveError {
27
+ constructor();
28
+ }
29
+ declare class PickleballWebhookVerificationError extends PickleballLiveError {
30
+ constructor(message?: string);
31
+ }
32
+
33
+ interface BootstrapInput {
34
+ sdkVersion: string;
35
+ platform: "ios" | "android";
36
+ bundleId: string;
37
+ installationId: string;
38
+ }
39
+ interface SdkRemoteConfig {
40
+ enabled: boolean;
41
+ protocolVersion: 1;
42
+ minSdkVersion: string;
43
+ recommendedSdkVersion: string;
44
+ videoQuality: 720 | 1080;
45
+ reconnectTimeoutMs: number;
46
+ backgroundGraceMs: number;
47
+ telemetryIntervalMs: number;
48
+ maxSessionDurationMs: number;
49
+ /** Tự kết thúc phiên nếu thiết bị ngồi standby quá lâu (mặc định 15 phút). */
50
+ standbyTimeoutMs?: number;
51
+ }
52
+ interface SdkBootstrap {
53
+ config: SdkRemoteConfig;
54
+ serverTime: number;
55
+ rolloutEnabled: boolean;
56
+ message?: string;
57
+ }
58
+ interface StartLivestreamInput {
59
+ externalSessionId: string;
60
+ title: string;
61
+ visibility?: "public" | "private";
62
+ consentVersion: string;
63
+ metadata?: Record<string, string>;
64
+ /**
65
+ * true: thiết bị vào phòng ở chế độ chờ (không publish) — server giữ status
66
+ * "scheduled" và KHÔNG khởi động recording egress cho tới khi publish.
67
+ */
68
+ standby?: boolean;
69
+ }
70
+ interface SdkTelemetryCredentials {
71
+ endpoint: string;
72
+ token: string;
73
+ expiresAt: number;
74
+ }
75
+ interface SdkSessionGrant {
76
+ sessionId: string;
77
+ serverUrl: string;
78
+ participantToken: string;
79
+ playbackUrl: string | null;
80
+ tokenExpiresAt: number;
81
+ telemetry: SdkTelemetryCredentials;
82
+ config: SdkRemoteConfig;
83
+ }
84
+ interface SdkSessionRefresh {
85
+ participantToken?: string;
86
+ tokenExpiresAt?: number;
87
+ telemetry?: SdkTelemetryCredentials;
88
+ config: SdkRemoteConfig;
89
+ }
90
+ interface EndLivestreamInput {
91
+ sessionId: string;
92
+ reason: "user" | "background_timeout" | "network_timeout" | "standby_timeout" | "error";
93
+ }
94
+ /** Kết quả chuyển trạng thái publish/unpublish (standby ↔ live). */
95
+ interface SdkPublishState {
96
+ sessionId: string;
97
+ status: "scheduled" | "live";
98
+ }
99
+ type SessionStatus = "scheduled" | "live" | "ended";
100
+ type SessionVisibility = "public" | "private";
101
+ type RecordingType = "clean" | "derived" | "device";
102
+ interface ApiLiveSession {
103
+ id: string;
104
+ title: string;
105
+ status: SessionStatus;
106
+ visibility: SessionVisibility;
107
+ matchRef: string | null;
108
+ playbackUrl: string | null;
109
+ /** Link trang xem web (`/watch/{id}`); null nếu chưa cấu hình WEB_PUBLIC_BASE_URL. */
110
+ watchUrl: string | null;
111
+ scheduledAt: number | null;
112
+ startedAt: number | null;
113
+ endedAt: number | null;
114
+ viewerCount: number;
115
+ likeCount: number;
116
+ shareCount: number;
117
+ }
118
+ interface ApiRecording {
119
+ id: string;
120
+ sessionId: string;
121
+ type: RecordingType;
122
+ status: "recording" | "ready" | "failed";
123
+ url: string | null;
124
+ durationSec: number | null;
125
+ }
126
+ type StartSdkSessionInput = BootstrapInput & StartLivestreamInput & {
127
+ idempotencyKey: string;
128
+ };
129
+ declare const SDK_TELEMETRY_EVENT_NAMES: readonly ["state_changed", "connection_quality", "reconnect", "error", "heartbeat", "session_ended"];
130
+ type SdkTelemetryEventName = (typeof SDK_TELEMETRY_EVENT_NAMES)[number];
131
+ interface SdkTelemetryEvent {
132
+ sessionId: string;
133
+ at: number;
134
+ name: SdkTelemetryEventName;
135
+ data?: Record<string, unknown>;
136
+ }
137
+ interface LivestreamSessionProvider {
138
+ bootstrap(input: BootstrapInput): Promise<SdkBootstrap>;
139
+ start(input: StartLivestreamInput): Promise<SdkSessionGrant>;
140
+ refresh(sessionId: string): Promise<SdkSessionRefresh>;
141
+ end(input: EndLivestreamInput): Promise<void>;
142
+ /**
143
+ * Báo server bắt đầu phát thật (standby → live) — bật recording egress +
144
+ * chuyển status live trước khi thiết bị publish track. Optional để giữ
145
+ * tương thích provider cũ.
146
+ */
147
+ publish?(sessionId: string): Promise<void>;
148
+ /** Báo server tạm dừng phát (live → standby): dừng egress, status về chờ. */
149
+ unpublish?(sessionId: string): Promise<void>;
150
+ }
151
+ type LivestreamState = "idle" | "preparing" | "preview" | "connecting" | "standby" | "live" | "reconnecting" | "ending" | "ended" | "error";
152
+ interface SdkError {
153
+ code: SdkErrorCode;
154
+ message: string;
155
+ }
156
+
157
+ type WebhookRawBody = string | Uint8Array;
158
+ type WebhookHeaders = Headers | Record<string, string | string[] | undefined>;
159
+ interface VerifyWebhookOptions {
160
+ toleranceSeconds?: number;
161
+ /** Epoch milliseconds; primarily useful for deterministic verification. */
162
+ now?: number;
163
+ }
164
+ interface WebhookPayload {
165
+ event: string;
166
+ [key: string]: unknown;
167
+ }
168
+ interface VerifiedWebhook<T extends WebhookPayload = WebhookPayload> {
169
+ /** Unsigned delivery metadata. Do not use this value alone for deduplication. */
170
+ transportId: string;
171
+ /** Stable SHA-256 key derived from the authenticated raw body. */
172
+ dedupeKey: string;
173
+ event: string;
174
+ timestamp: number;
175
+ body: T;
176
+ }
177
+ declare function verifyWebhook<T extends WebhookPayload = WebhookPayload>(rawBody: WebhookRawBody, headers: WebhookHeaders, secret: string, options?: VerifyWebhookOptions): Promise<VerifiedWebhook<T>>;
178
+
179
+ interface PickleballLiveClientOptions {
180
+ baseUrl: string;
181
+ appId: string;
182
+ apiKey: string;
183
+ fetch?: typeof globalThis.fetch;
184
+ timeoutMs?: number;
185
+ maxRetries?: number;
186
+ }
187
+ interface PickleballLiveClient {
188
+ apps: {
189
+ bootstrap(input: BootstrapInput): Promise<SdkBootstrap>;
190
+ };
191
+ sessions: {
192
+ start(input: StartSdkSessionInput): Promise<SdkSessionGrant>;
193
+ refresh(sessionId: string, input: BootstrapInput): Promise<SdkSessionRefresh>;
194
+ end(input: EndLivestreamInput): Promise<void>;
195
+ publish(sessionId: string): Promise<SdkPublishState>;
196
+ unpublish(sessionId: string): Promise<SdkPublishState>;
197
+ get(sessionId: string): Promise<ApiLiveSession>;
198
+ getRecordings(sessionId: string): Promise<ApiRecording[]>;
199
+ };
200
+ webhooks: {
201
+ verify<T extends WebhookPayload = WebhookPayload>(rawBody: WebhookRawBody, headers: WebhookHeaders, secret: string, options?: VerifyWebhookOptions): Promise<VerifiedWebhook<T>>;
202
+ };
203
+ }
204
+ declare function createPickleballLiveClient(options: PickleballLiveClientOptions): PickleballLiveClient;
205
+
206
+ export { type ApiLiveSession, type ApiRecording, type BootstrapInput, type EndLivestreamInput, type LivestreamSessionProvider, type LivestreamState, PickleballApiError, PickleballConfigurationError, PickleballHttpError, PickleballInvalidResponseError, type PickleballLiveClient, type PickleballLiveClientOptions, PickleballLiveError, PickleballNetworkError, PickleballTimeoutError, PickleballWebhookVerificationError, type RecordingType, SDK_TELEMETRY_EVENT_NAMES, type SdkBootstrap, type SdkError, type SdkErrorCode, type SdkPublishState, type SdkRemoteConfig, type SdkSessionGrant, type SdkSessionRefresh, type SdkTelemetryCredentials, type SdkTelemetryEvent, type SdkTelemetryEventName, type ServerSdkErrorCode, type SessionStatus, type SessionVisibility, type StartLivestreamInput, type StartSdkSessionInput, type VerifiedWebhook, type VerifyWebhookOptions, type WebhookHeaders, type WebhookPayload, type WebhookRawBody, createPickleballLiveClient, verifyWebhook };
@@ -0,0 +1,206 @@
1
+ type SdkErrorCode = "PERMISSION_DENIED" | "NETWORK_UNAVAILABLE" | "TOKEN_EXPIRED" | "SDK_UPGRADE_REQUIRED" | "SESSION_CONFLICT" | "RECORDING_FAILED" | "CONSENT_REQUIRED" | "SDK_DISABLED" | "UNKNOWN";
2
+ type ServerSdkErrorCode = SdkErrorCode | "CONFIGURATION_ERROR" | "TIMEOUT" | "NETWORK_ERROR" | "HTTP_ERROR" | "INVALID_RESPONSE" | "WEBHOOK_VERIFICATION_FAILED";
3
+ declare class PickleballLiveError extends Error {
4
+ readonly code: ServerSdkErrorCode;
5
+ constructor(message: string, code: ServerSdkErrorCode, options?: ErrorOptions);
6
+ }
7
+ declare class PickleballConfigurationError extends PickleballLiveError {
8
+ constructor(message: string);
9
+ }
10
+ declare class PickleballApiError extends PickleballLiveError {
11
+ readonly status: number;
12
+ constructor(message: string,
13
+ /** Stable allowlisted code. Unknown server codes are normalized to UNKNOWN. */
14
+ code: SdkErrorCode, status: number);
15
+ }
16
+ declare class PickleballHttpError extends PickleballLiveError {
17
+ readonly status: number;
18
+ constructor(status: number);
19
+ }
20
+ declare class PickleballInvalidResponseError extends PickleballLiveError {
21
+ constructor();
22
+ }
23
+ declare class PickleballTimeoutError extends PickleballLiveError {
24
+ constructor();
25
+ }
26
+ declare class PickleballNetworkError extends PickleballLiveError {
27
+ constructor();
28
+ }
29
+ declare class PickleballWebhookVerificationError extends PickleballLiveError {
30
+ constructor(message?: string);
31
+ }
32
+
33
+ interface BootstrapInput {
34
+ sdkVersion: string;
35
+ platform: "ios" | "android";
36
+ bundleId: string;
37
+ installationId: string;
38
+ }
39
+ interface SdkRemoteConfig {
40
+ enabled: boolean;
41
+ protocolVersion: 1;
42
+ minSdkVersion: string;
43
+ recommendedSdkVersion: string;
44
+ videoQuality: 720 | 1080;
45
+ reconnectTimeoutMs: number;
46
+ backgroundGraceMs: number;
47
+ telemetryIntervalMs: number;
48
+ maxSessionDurationMs: number;
49
+ /** Tự kết thúc phiên nếu thiết bị ngồi standby quá lâu (mặc định 15 phút). */
50
+ standbyTimeoutMs?: number;
51
+ }
52
+ interface SdkBootstrap {
53
+ config: SdkRemoteConfig;
54
+ serverTime: number;
55
+ rolloutEnabled: boolean;
56
+ message?: string;
57
+ }
58
+ interface StartLivestreamInput {
59
+ externalSessionId: string;
60
+ title: string;
61
+ visibility?: "public" | "private";
62
+ consentVersion: string;
63
+ metadata?: Record<string, string>;
64
+ /**
65
+ * true: thiết bị vào phòng ở chế độ chờ (không publish) — server giữ status
66
+ * "scheduled" và KHÔNG khởi động recording egress cho tới khi publish.
67
+ */
68
+ standby?: boolean;
69
+ }
70
+ interface SdkTelemetryCredentials {
71
+ endpoint: string;
72
+ token: string;
73
+ expiresAt: number;
74
+ }
75
+ interface SdkSessionGrant {
76
+ sessionId: string;
77
+ serverUrl: string;
78
+ participantToken: string;
79
+ playbackUrl: string | null;
80
+ tokenExpiresAt: number;
81
+ telemetry: SdkTelemetryCredentials;
82
+ config: SdkRemoteConfig;
83
+ }
84
+ interface SdkSessionRefresh {
85
+ participantToken?: string;
86
+ tokenExpiresAt?: number;
87
+ telemetry?: SdkTelemetryCredentials;
88
+ config: SdkRemoteConfig;
89
+ }
90
+ interface EndLivestreamInput {
91
+ sessionId: string;
92
+ reason: "user" | "background_timeout" | "network_timeout" | "standby_timeout" | "error";
93
+ }
94
+ /** Kết quả chuyển trạng thái publish/unpublish (standby ↔ live). */
95
+ interface SdkPublishState {
96
+ sessionId: string;
97
+ status: "scheduled" | "live";
98
+ }
99
+ type SessionStatus = "scheduled" | "live" | "ended";
100
+ type SessionVisibility = "public" | "private";
101
+ type RecordingType = "clean" | "derived" | "device";
102
+ interface ApiLiveSession {
103
+ id: string;
104
+ title: string;
105
+ status: SessionStatus;
106
+ visibility: SessionVisibility;
107
+ matchRef: string | null;
108
+ playbackUrl: string | null;
109
+ /** Link trang xem web (`/watch/{id}`); null nếu chưa cấu hình WEB_PUBLIC_BASE_URL. */
110
+ watchUrl: string | null;
111
+ scheduledAt: number | null;
112
+ startedAt: number | null;
113
+ endedAt: number | null;
114
+ viewerCount: number;
115
+ likeCount: number;
116
+ shareCount: number;
117
+ }
118
+ interface ApiRecording {
119
+ id: string;
120
+ sessionId: string;
121
+ type: RecordingType;
122
+ status: "recording" | "ready" | "failed";
123
+ url: string | null;
124
+ durationSec: number | null;
125
+ }
126
+ type StartSdkSessionInput = BootstrapInput & StartLivestreamInput & {
127
+ idempotencyKey: string;
128
+ };
129
+ declare const SDK_TELEMETRY_EVENT_NAMES: readonly ["state_changed", "connection_quality", "reconnect", "error", "heartbeat", "session_ended"];
130
+ type SdkTelemetryEventName = (typeof SDK_TELEMETRY_EVENT_NAMES)[number];
131
+ interface SdkTelemetryEvent {
132
+ sessionId: string;
133
+ at: number;
134
+ name: SdkTelemetryEventName;
135
+ data?: Record<string, unknown>;
136
+ }
137
+ interface LivestreamSessionProvider {
138
+ bootstrap(input: BootstrapInput): Promise<SdkBootstrap>;
139
+ start(input: StartLivestreamInput): Promise<SdkSessionGrant>;
140
+ refresh(sessionId: string): Promise<SdkSessionRefresh>;
141
+ end(input: EndLivestreamInput): Promise<void>;
142
+ /**
143
+ * Báo server bắt đầu phát thật (standby → live) — bật recording egress +
144
+ * chuyển status live trước khi thiết bị publish track. Optional để giữ
145
+ * tương thích provider cũ.
146
+ */
147
+ publish?(sessionId: string): Promise<void>;
148
+ /** Báo server tạm dừng phát (live → standby): dừng egress, status về chờ. */
149
+ unpublish?(sessionId: string): Promise<void>;
150
+ }
151
+ type LivestreamState = "idle" | "preparing" | "preview" | "connecting" | "standby" | "live" | "reconnecting" | "ending" | "ended" | "error";
152
+ interface SdkError {
153
+ code: SdkErrorCode;
154
+ message: string;
155
+ }
156
+
157
+ type WebhookRawBody = string | Uint8Array;
158
+ type WebhookHeaders = Headers | Record<string, string | string[] | undefined>;
159
+ interface VerifyWebhookOptions {
160
+ toleranceSeconds?: number;
161
+ /** Epoch milliseconds; primarily useful for deterministic verification. */
162
+ now?: number;
163
+ }
164
+ interface WebhookPayload {
165
+ event: string;
166
+ [key: string]: unknown;
167
+ }
168
+ interface VerifiedWebhook<T extends WebhookPayload = WebhookPayload> {
169
+ /** Unsigned delivery metadata. Do not use this value alone for deduplication. */
170
+ transportId: string;
171
+ /** Stable SHA-256 key derived from the authenticated raw body. */
172
+ dedupeKey: string;
173
+ event: string;
174
+ timestamp: number;
175
+ body: T;
176
+ }
177
+ declare function verifyWebhook<T extends WebhookPayload = WebhookPayload>(rawBody: WebhookRawBody, headers: WebhookHeaders, secret: string, options?: VerifyWebhookOptions): Promise<VerifiedWebhook<T>>;
178
+
179
+ interface PickleballLiveClientOptions {
180
+ baseUrl: string;
181
+ appId: string;
182
+ apiKey: string;
183
+ fetch?: typeof globalThis.fetch;
184
+ timeoutMs?: number;
185
+ maxRetries?: number;
186
+ }
187
+ interface PickleballLiveClient {
188
+ apps: {
189
+ bootstrap(input: BootstrapInput): Promise<SdkBootstrap>;
190
+ };
191
+ sessions: {
192
+ start(input: StartSdkSessionInput): Promise<SdkSessionGrant>;
193
+ refresh(sessionId: string, input: BootstrapInput): Promise<SdkSessionRefresh>;
194
+ end(input: EndLivestreamInput): Promise<void>;
195
+ publish(sessionId: string): Promise<SdkPublishState>;
196
+ unpublish(sessionId: string): Promise<SdkPublishState>;
197
+ get(sessionId: string): Promise<ApiLiveSession>;
198
+ getRecordings(sessionId: string): Promise<ApiRecording[]>;
199
+ };
200
+ webhooks: {
201
+ verify<T extends WebhookPayload = WebhookPayload>(rawBody: WebhookRawBody, headers: WebhookHeaders, secret: string, options?: VerifyWebhookOptions): Promise<VerifiedWebhook<T>>;
202
+ };
203
+ }
204
+ declare function createPickleballLiveClient(options: PickleballLiveClientOptions): PickleballLiveClient;
205
+
206
+ export { type ApiLiveSession, type ApiRecording, type BootstrapInput, type EndLivestreamInput, type LivestreamSessionProvider, type LivestreamState, PickleballApiError, PickleballConfigurationError, PickleballHttpError, PickleballInvalidResponseError, type PickleballLiveClient, type PickleballLiveClientOptions, PickleballLiveError, PickleballNetworkError, PickleballTimeoutError, PickleballWebhookVerificationError, type RecordingType, SDK_TELEMETRY_EVENT_NAMES, type SdkBootstrap, type SdkError, type SdkErrorCode, type SdkPublishState, type SdkRemoteConfig, type SdkSessionGrant, type SdkSessionRefresh, type SdkTelemetryCredentials, type SdkTelemetryEvent, type SdkTelemetryEventName, type ServerSdkErrorCode, type SessionStatus, type SessionVisibility, type StartLivestreamInput, type StartSdkSessionInput, type VerifiedWebhook, type VerifyWebhookOptions, type WebhookHeaders, type WebhookPayload, type WebhookRawBody, createPickleballLiveClient, verifyWebhook };
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
1
+ import {
2
+ PickleballApiError,
3
+ PickleballConfigurationError,
4
+ PickleballHttpError,
5
+ PickleballInvalidResponseError,
6
+ PickleballLiveError,
7
+ PickleballNetworkError,
8
+ PickleballTimeoutError,
9
+ PickleballWebhookVerificationError,
10
+ SDK_TELEMETRY_EVENT_NAMES,
11
+ createPickleballLiveClient,
12
+ verifyWebhook
13
+ } from "./chunk-HBTNLURN.js";
14
+ export {
15
+ PickleballApiError,
16
+ PickleballConfigurationError,
17
+ PickleballHttpError,
18
+ PickleballInvalidResponseError,
19
+ PickleballLiveError,
20
+ PickleballNetworkError,
21
+ PickleballTimeoutError,
22
+ PickleballWebhookVerificationError,
23
+ SDK_TELEMETRY_EVENT_NAMES,
24
+ createPickleballLiveClient,
25
+ verifyWebhook
26
+ };