@pixels-online/pixels-client-js-sdk 1.0.2
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/LICENSE.md +675 -0
- package/README.md +1 -0
- package/dist/core/CustomEventSource.d.ts +42 -0
- package/dist/core/OfferStore.d.ts +55 -0
- package/dist/core/OfferwallClient.d.ts +63 -0
- package/dist/core/SSEConnection.d.ts +30 -0
- package/dist/core/TokenManager.d.ts +33 -0
- package/dist/events/EventEmitter.d.ts +13 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.esm.js +1541 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +1551 -0
- package/dist/index.js.map +1 -0
- package/dist/offerwall-sdk.umd.js +1557 -0
- package/dist/offerwall-sdk.umd.js.map +1 -0
- package/dist/types/connection.d.ts +20 -0
- package/dist/types/events.d.ts +42 -0
- package/dist/types/hooks.d.ts +21 -0
- package/dist/types/index.d.ts +23 -0
- package/dist/types/offer.d.ts +142 -0
- package/dist/types/player.d.ts +185 -0
- package/dist/types/reward.d.ts +22 -0
- package/dist/utils/Logger.d.ts +18 -0
- package/dist/utils/assets.d.ts +9 -0
- package/dist/utils/conditions.d.ts +34 -0
- package/package.json +76 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom EventSource implementation that supports headers
|
|
3
|
+
* This is needed because the native EventSource API doesn't support custom headers
|
|
4
|
+
*/
|
|
5
|
+
export declare enum ReadyState {
|
|
6
|
+
CONNECTING = 0,
|
|
7
|
+
OPEN = 1,
|
|
8
|
+
CLOSED = 2
|
|
9
|
+
}
|
|
10
|
+
export interface CustomEventSourceInit {
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
export declare class CustomEventSource {
|
|
14
|
+
private url;
|
|
15
|
+
private headers;
|
|
16
|
+
private readyState;
|
|
17
|
+
private eventListeners;
|
|
18
|
+
onopen: ((event: Event) => void) | null;
|
|
19
|
+
onerror: ((event: Event) => void) | null;
|
|
20
|
+
onmessage: ((event: MessageEvent) => void) | null;
|
|
21
|
+
private reader;
|
|
22
|
+
private decoder;
|
|
23
|
+
private eventBuffer;
|
|
24
|
+
private abortController;
|
|
25
|
+
private lastEventId;
|
|
26
|
+
private reconnectTime;
|
|
27
|
+
onRetryUpdate: ((time: number) => void) | null;
|
|
28
|
+
constructor(url: string, init?: CustomEventSourceInit);
|
|
29
|
+
private connect;
|
|
30
|
+
private readStream;
|
|
31
|
+
private processBuffer;
|
|
32
|
+
private dispatchEvent;
|
|
33
|
+
private handleError;
|
|
34
|
+
addEventListener(type: string, listener: (event: MessageEvent) => void): void;
|
|
35
|
+
removeEventListener(type: string, listener: (event: MessageEvent) => void): void;
|
|
36
|
+
close(): void;
|
|
37
|
+
get CONNECTING(): number;
|
|
38
|
+
get OPEN(): number;
|
|
39
|
+
get CLOSED(): number;
|
|
40
|
+
getReadyState(): ReadyState;
|
|
41
|
+
getReconnectTime(): number;
|
|
42
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { OfferwallConfig } from '../types';
|
|
2
|
+
import { IClientOffer, PlayerOfferStatus } from '../types/offer';
|
|
3
|
+
import { IClientPlayerSnapshot } from '../types/player';
|
|
4
|
+
export declare class OfferStore {
|
|
5
|
+
private offers;
|
|
6
|
+
private playerSnapshot;
|
|
7
|
+
private logger;
|
|
8
|
+
constructor(config: OfferwallConfig);
|
|
9
|
+
getSnapshot(): IClientPlayerSnapshot | null;
|
|
10
|
+
setSnapshot(snapshot: IClientPlayerSnapshot): void;
|
|
11
|
+
/**
|
|
12
|
+
* Set all offers (replaces existing)
|
|
13
|
+
*/
|
|
14
|
+
setOffers(offers: IClientOffer[]): void;
|
|
15
|
+
/**
|
|
16
|
+
* Add or update a single offer
|
|
17
|
+
*/
|
|
18
|
+
upsertOffer(offer: IClientOffer): IClientOffer | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Remove an offer
|
|
21
|
+
*/
|
|
22
|
+
removeOffer(offerId: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Get a single offer
|
|
25
|
+
*/
|
|
26
|
+
getOffer(offerId: string): IClientOffer | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Get all offers
|
|
29
|
+
*/
|
|
30
|
+
getAllOffers(): IClientOffer[];
|
|
31
|
+
/**
|
|
32
|
+
* Get offers filtered by status
|
|
33
|
+
*/
|
|
34
|
+
getOffersByStatus(status: PlayerOfferStatus): IClientOffer[];
|
|
35
|
+
/**
|
|
36
|
+
* Get active offers (not expired, not claimed)
|
|
37
|
+
*/
|
|
38
|
+
getActiveOffers(): IClientOffer[];
|
|
39
|
+
/**
|
|
40
|
+
* Get claimable offers
|
|
41
|
+
*/
|
|
42
|
+
getClaimableOffers(): IClientOffer[];
|
|
43
|
+
/**
|
|
44
|
+
* Check if an offer has expired
|
|
45
|
+
*/
|
|
46
|
+
isOfferExpired(offerId: string): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Clear all offers
|
|
49
|
+
*/
|
|
50
|
+
clear(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Get offer count
|
|
53
|
+
*/
|
|
54
|
+
get size(): number;
|
|
55
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { EventEmitter } from '../events/EventEmitter';
|
|
2
|
+
import { OfferStore } from './OfferStore';
|
|
3
|
+
import { AssetHelper } from '../utils/assets';
|
|
4
|
+
import { OfferwallConfig } from '../types';
|
|
5
|
+
import { ConnectionState } from '../types/connection';
|
|
6
|
+
export declare class OfferwallClient {
|
|
7
|
+
private config;
|
|
8
|
+
private eventEmitter;
|
|
9
|
+
private sseConnection;
|
|
10
|
+
private offerStore;
|
|
11
|
+
private tokenManager;
|
|
12
|
+
private assetHelper;
|
|
13
|
+
private hooks;
|
|
14
|
+
private logger;
|
|
15
|
+
private isInitializing;
|
|
16
|
+
constructor(config: OfferwallConfig);
|
|
17
|
+
/**
|
|
18
|
+
* Get the offer store instance
|
|
19
|
+
*/
|
|
20
|
+
get store(): OfferStore;
|
|
21
|
+
/**
|
|
22
|
+
* Get the event emitter instance for event handling
|
|
23
|
+
*/
|
|
24
|
+
get events(): EventEmitter;
|
|
25
|
+
/**
|
|
26
|
+
* Get asset helper for resolving offer/reward content
|
|
27
|
+
*/
|
|
28
|
+
get assets(): AssetHelper;
|
|
29
|
+
/**
|
|
30
|
+
* Initialize the offerwall client and connect
|
|
31
|
+
*/
|
|
32
|
+
initialize(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Connect to the offerwall SSE endpoint
|
|
35
|
+
*/
|
|
36
|
+
private connect;
|
|
37
|
+
/**
|
|
38
|
+
* Disconnect from the offerwall
|
|
39
|
+
*/
|
|
40
|
+
disconnect(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Claim rewards for an offer
|
|
43
|
+
*/
|
|
44
|
+
claimReward(instanceId: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Check if connected
|
|
47
|
+
*/
|
|
48
|
+
isConnected(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Get current connection state
|
|
51
|
+
*/
|
|
52
|
+
getConnectionState(): ConnectionState;
|
|
53
|
+
private setupInternalListeners;
|
|
54
|
+
/**
|
|
55
|
+
* Helper to POST to an endpoint with JWT and handle token expiry/retry logic
|
|
56
|
+
*/
|
|
57
|
+
private postWithAuth;
|
|
58
|
+
private claimOfferAPI;
|
|
59
|
+
refreshOffersAndSnapshot(): Promise<void>;
|
|
60
|
+
private getOffersAndSnapshot;
|
|
61
|
+
getAuthLinkToken(): Promise<string>;
|
|
62
|
+
private handleError;
|
|
63
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { EventEmitter } from '../events/EventEmitter';
|
|
2
|
+
import { OfferwallConfig } from '../types';
|
|
3
|
+
import { ConnectionState } from '../types/connection';
|
|
4
|
+
import { TokenManager } from './TokenManager';
|
|
5
|
+
export declare class SSEConnection {
|
|
6
|
+
private config;
|
|
7
|
+
private eventEmitter;
|
|
8
|
+
private tokenManager;
|
|
9
|
+
private eventSource;
|
|
10
|
+
private reconnectAttempts;
|
|
11
|
+
private reconnectTimeout;
|
|
12
|
+
private isConnecting;
|
|
13
|
+
private connectionState;
|
|
14
|
+
private logger;
|
|
15
|
+
private serverSuggestedRetryTime;
|
|
16
|
+
constructor(config: OfferwallConfig, eventEmitter: EventEmitter, tokenManager: TokenManager);
|
|
17
|
+
/**
|
|
18
|
+
* Get current connection state
|
|
19
|
+
*/
|
|
20
|
+
getConnectionState(): ConnectionState;
|
|
21
|
+
/**
|
|
22
|
+
* Set connection state and emit change event
|
|
23
|
+
*/
|
|
24
|
+
private setConnectionState;
|
|
25
|
+
connect(): Promise<void>;
|
|
26
|
+
private handleMessage;
|
|
27
|
+
private handleReconnect;
|
|
28
|
+
disconnect(): void;
|
|
29
|
+
isConnected(): boolean;
|
|
30
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { OfferwallConfig } from "../types";
|
|
2
|
+
type JWTPayload = {
|
|
3
|
+
sub: string;
|
|
4
|
+
iss: string;
|
|
5
|
+
exp: number;
|
|
6
|
+
iat: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Manages JWT tokens for the offerwall client
|
|
10
|
+
* Handles token storage, validation, and refresh logic
|
|
11
|
+
*/
|
|
12
|
+
export declare class TokenManager {
|
|
13
|
+
private config;
|
|
14
|
+
private currentToken;
|
|
15
|
+
private logger;
|
|
16
|
+
constructor(config: OfferwallConfig);
|
|
17
|
+
/**
|
|
18
|
+
* Get the current stored token
|
|
19
|
+
*/
|
|
20
|
+
getCurrentToken(): string | null;
|
|
21
|
+
/**
|
|
22
|
+
* Clear the stored token
|
|
23
|
+
*/
|
|
24
|
+
clearToken(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Get current token or fetch a new one if needed
|
|
27
|
+
*/
|
|
28
|
+
getTokenForConnection(): Promise<string>;
|
|
29
|
+
private fetchToken;
|
|
30
|
+
private validateToken;
|
|
31
|
+
parseJWT(token: string): JWTPayload;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OfferwallConfig } from '../types';
|
|
2
|
+
import { OfferEvent, OfferEventMap, OfferEventHandler } from '../types/events';
|
|
3
|
+
export declare class EventEmitter {
|
|
4
|
+
private events;
|
|
5
|
+
private logger;
|
|
6
|
+
constructor(config: OfferwallConfig);
|
|
7
|
+
on<T extends OfferEvent>(event: T, handler: OfferEventHandler<T>): void;
|
|
8
|
+
off<T extends OfferEvent>(event: T, handler: OfferEventHandler<T>): void;
|
|
9
|
+
emit<T extends OfferEvent>(event: T, data: OfferEventMap[T]): void;
|
|
10
|
+
once<T extends OfferEvent>(event: T, handler: OfferEventHandler<T>): void;
|
|
11
|
+
removeAllListeners(event?: OfferEvent): void;
|
|
12
|
+
listenerCount(event: OfferEvent): number;
|
|
13
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { OfferwallClient } from './core/OfferwallClient';
|
|
2
|
+
export { EventEmitter } from './events/EventEmitter';
|
|
3
|
+
export { SSEConnection } from './core/SSEConnection';
|
|
4
|
+
export { OfferStore } from './core/OfferStore';
|
|
5
|
+
export { AssetHelper } from './utils/assets';
|
|
6
|
+
export * from './utils/conditions';
|
|
7
|
+
export * from './types';
|
|
8
|
+
export * from './types/offer';
|
|
9
|
+
export * from './types/reward';
|
|
10
|
+
export * from './types/events';
|
|
11
|
+
export * from './types/hooks';
|
|
12
|
+
export * from './types/player';
|