@yes2sdk/core 1.0.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/README.md +51 -0
- package/dist/core/core-api.d.ts +127 -0
- package/dist/core/core-api.d.ts.map +1 -0
- package/dist/core/di-container.d.ts +102 -0
- package/dist/core/di-container.d.ts.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/errors/error-handler.d.ts +83 -0
- package/dist/errors/error-handler.d.ts.map +1 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +3 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/core/initialization.d.ts +48 -0
- package/dist/types/core/initialization.d.ts.map +1 -0
- package/dist/types/core/platform.d.ts +19 -0
- package/dist/types/core/platform.d.ts.map +1 -0
- package/dist/types/errors/error-codes.d.ts +33 -0
- package/dist/types/errors/error-codes.d.ts.map +1 -0
- package/dist/types/errors/error-message.d.ts +39 -0
- package/dist/types/errors/error-message.d.ts.map +1 -0
- package/dist/types/errors/index.d.ts +4 -0
- package/dist/types/errors/index.d.ts.map +1 -0
- package/dist/types/errors/validation-result.d.ts +33 -0
- package/dist/types/errors/validation-result.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/utils/event-emitter.d.ts +85 -0
- package/dist/utils/event-emitter.d.ts.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/logger.d.ts +110 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/platform-detector.d.ts +30 -0
- package/dist/utils/platform-detector.d.ts.map +1 -0
- package/dist/utils/validators.d.ts +96 -0
- package/dist/utils/validators.d.ts.map +1 -0
- package/dist/yes2sdk.umd.js +2 -0
- package/dist/yes2sdk.umd.js.map +1 -0
- package/package.json +74 -0
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Yes2SDK
|
|
2
|
+
|
|
3
|
+
Multi-platform game integration SDK for HTML5 games.
|
|
4
|
+
|
|
5
|
+
## Supported Platforms
|
|
6
|
+
|
|
7
|
+
- Facebook Instant Games
|
|
8
|
+
- Yandex Games
|
|
9
|
+
- Poki
|
|
10
|
+
- CrazyGames
|
|
11
|
+
- And more platforms!
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- 🎮 Unified API across 20+ platforms
|
|
16
|
+
- 📱 Ads management (interstitial, rewarded)
|
|
17
|
+
- 👤 Player management and authentication
|
|
18
|
+
- 🏆 Leaderboards
|
|
19
|
+
- 💰 In-app purchases
|
|
20
|
+
- 📊 Analytics tracking
|
|
21
|
+
- 🎯 And much more!
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @yes2sdk/core
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import Yes2SDK from '@yes2sdk/core';
|
|
33
|
+
|
|
34
|
+
// Initialize SDK
|
|
35
|
+
await Yes2SDK.initializeAsync();
|
|
36
|
+
|
|
37
|
+
// Show an ad
|
|
38
|
+
await Yes2SDK.ads.showInterstitial('level-complete');
|
|
39
|
+
|
|
40
|
+
// Get player info
|
|
41
|
+
const playerName = await Yes2SDK.player.getName();
|
|
42
|
+
console.log(`Welcome, ${playerName}!`);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Documentation
|
|
46
|
+
|
|
47
|
+
Soon.
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
MIT
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { Platform, InitializationOptions } from "../types/core";
|
|
2
|
+
import { DIContainer } from "./di-container";
|
|
3
|
+
import { Logger } from "../utils/logger";
|
|
4
|
+
/**
|
|
5
|
+
* SDK events that can be subscribed to.
|
|
6
|
+
*/
|
|
7
|
+
export interface SDKEvents {
|
|
8
|
+
initialized: {
|
|
9
|
+
platform: Platform;
|
|
10
|
+
};
|
|
11
|
+
gameStarted: void;
|
|
12
|
+
error: {
|
|
13
|
+
context: string;
|
|
14
|
+
error: unknown;
|
|
15
|
+
};
|
|
16
|
+
loadingProgress: {
|
|
17
|
+
progress: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* CoreAPI - The main entry point for Yes2SDK.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* This class serves as the facade for the entire SDK. All initialization
|
|
25
|
+
* must go through this class, and all other modules are accessed through it.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import Yes2SDK from '@yes2sdk/core';
|
|
30
|
+
*
|
|
31
|
+
* // Initialize SDK
|
|
32
|
+
* await Yes2SDK.initializeAsync();
|
|
33
|
+
*
|
|
34
|
+
* // Update loading progress
|
|
35
|
+
* Yes2SDK.setLoadingProgress(50);
|
|
36
|
+
*
|
|
37
|
+
* // Start game
|
|
38
|
+
* await Yes2SDK.startGameAsync();
|
|
39
|
+
*
|
|
40
|
+
* // Use other modules
|
|
41
|
+
* Yes2SDK.ads.showInterstitial('next', 'LevelComplete', pauseGame, resumeGame);
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare class CoreAPI {
|
|
45
|
+
private _container;
|
|
46
|
+
private _logger;
|
|
47
|
+
private _events;
|
|
48
|
+
private _state;
|
|
49
|
+
private _platform;
|
|
50
|
+
/**
|
|
51
|
+
* Create a new CoreAPI instance.
|
|
52
|
+
*/
|
|
53
|
+
constructor();
|
|
54
|
+
/**
|
|
55
|
+
* Whether the SDK has been initialized.
|
|
56
|
+
*/
|
|
57
|
+
get isInitialized(): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Initialize the SDK.
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* This must be called before any other SDK functions. It detects the
|
|
63
|
+
* current platform, loads platform-specific code, and initializes
|
|
64
|
+
* the platform SDK.
|
|
65
|
+
*
|
|
66
|
+
* @param options - Optional initialization configuration.
|
|
67
|
+
* @returns Promise that resolves when initialization completes.
|
|
68
|
+
*/
|
|
69
|
+
initializeAsync(options?: InitializationOptions): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Start the game after loading is complete.
|
|
72
|
+
*
|
|
73
|
+
* @remarks
|
|
74
|
+
* This signals to the platform that the game is ready to be displayed.
|
|
75
|
+
* Should be called after all game assets are loaded.
|
|
76
|
+
*
|
|
77
|
+
* @returns Promise that resolves when the game starts.
|
|
78
|
+
*/
|
|
79
|
+
startGameAsync(): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Set the loading progress for the game.
|
|
82
|
+
*
|
|
83
|
+
* @param progress - Loading progress between 0 and 100.
|
|
84
|
+
*/
|
|
85
|
+
setLoadingProgress(progress: number): void;
|
|
86
|
+
/**
|
|
87
|
+
* Perform haptic feedback if supported.
|
|
88
|
+
*/
|
|
89
|
+
performHapticFeedback(): void;
|
|
90
|
+
/**
|
|
91
|
+
* Get the current platform.
|
|
92
|
+
* @returns The detected platform, or null if not initialized.
|
|
93
|
+
*/
|
|
94
|
+
getPlatform(): Platform | null;
|
|
95
|
+
/**
|
|
96
|
+
* Subscribe to SDK events.
|
|
97
|
+
* @param event - The event to subscribe to.
|
|
98
|
+
* @param listener - The listener function.
|
|
99
|
+
* @returns A subscription that can be unsubscribed.
|
|
100
|
+
*/
|
|
101
|
+
on<K extends keyof SDKEvents>(event: K, listener: (data: SDKEvents[K]) => void): {
|
|
102
|
+
unsubscribe: () => void;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Get the logger instance.
|
|
106
|
+
* @returns The logger instance.
|
|
107
|
+
* @internal
|
|
108
|
+
*/
|
|
109
|
+
get _log(): Logger;
|
|
110
|
+
/**
|
|
111
|
+
* Get the DI container.
|
|
112
|
+
* @returns The DI container.
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
get _internalContainer(): DIContainer;
|
|
116
|
+
/**
|
|
117
|
+
* Get the internal platform.
|
|
118
|
+
* @returns The platform identifier.
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
get _internalPlatform(): Platform | null;
|
|
122
|
+
/**
|
|
123
|
+
* Register core services in the DI container.
|
|
124
|
+
*/
|
|
125
|
+
private _registerCoreServices;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=core-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-api.d.ts","sourceRoot":"","sources":["../../src/core/core-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAuB,MAAM,eAAe,CAAC;AAC1F,OAAO,EAAE,WAAW,EAAc,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAY,MAAM,iBAAiB,CAAC;AAMnD;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,WAAW,EAAE;QAAE,QAAQ,EAAE,QAAQ,CAAA;KAAE,CAAC;IACpC,WAAW,EAAE,IAAI,CAAC;IAClB,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC;IAC3C,eAAe,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;CACzC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,OAAO;IAChB,OAAO,CAAC,UAAU,CAAc;IAChC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,SAAS,CAAyB;IAE1C;;OAEG;;IAgBH;;OAEG;IACH,IAAW,aAAa,IAAI,OAAO,CAElC;IAKD;;;;;;;;;;OAUG;IACU,eAAe,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAoC5E;;;;;;;;OAQG;IACU,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IA4B5C;;;;OAIG;IACI,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAkBjD;;OAEG;IACI,qBAAqB,IAAI,IAAI;IAWpC;;;OAGG;IACI,WAAW,IAAI,QAAQ,GAAG,IAAI;IAIrC;;;;;OAKG;IACI,EAAE,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG;QAAE,WAAW,EAAE,MAAM,IAAI,CAAA;KAAE;IAInH;;;;OAIG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAED;;;;OAIG;IACH,IAAW,kBAAkB,IAAI,WAAW,CAE3C;IAED;;;;OAIG;IACH,IAAW,iBAAiB,IAAI,QAAQ,GAAG,IAAI,CAE9C;IAKD;;OAEG;IACH,OAAO,CAAC,qBAAqB;CAMhC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service factory function type.
|
|
3
|
+
*/
|
|
4
|
+
export type ServiceFactory<T> = (container: DIContainer) => T;
|
|
5
|
+
/**
|
|
6
|
+
* Dependency Injection Container for Yes2SDK.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* This container manages service registration and resolution, supporting
|
|
10
|
+
* both singleton and transient services. It enables loose coupling between
|
|
11
|
+
* components and makes the SDK easily testable.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const container = new DIContainer();
|
|
16
|
+
*
|
|
17
|
+
* // Register a singleton service
|
|
18
|
+
* container.register('logger', () => new Logger(), true);
|
|
19
|
+
*
|
|
20
|
+
* // Register a transient service
|
|
21
|
+
* container.register('validator', (c) => new Validator(c.resolve('logger')));
|
|
22
|
+
*
|
|
23
|
+
* // Resolve a service
|
|
24
|
+
* const logger = container.resolve<Logger>('logger');
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class DIContainer {
|
|
28
|
+
private _services;
|
|
29
|
+
private _singletons;
|
|
30
|
+
/**
|
|
31
|
+
* Register a service factory.
|
|
32
|
+
* @param key - Unique identifier for the service.
|
|
33
|
+
* @param factory - Factory function that creates the service.
|
|
34
|
+
* @param singleton - Whether to cache the service as a singleton.
|
|
35
|
+
*/
|
|
36
|
+
register<T>(key: string, factory: ServiceFactory<T>, singleton?: boolean): void;
|
|
37
|
+
/**
|
|
38
|
+
* Resolve a service by key.
|
|
39
|
+
* @param key - The service key to resolve.
|
|
40
|
+
* @returns The resolved service instance.
|
|
41
|
+
* @throws Error if the service is not registered.
|
|
42
|
+
*/
|
|
43
|
+
resolve<T>(key: string): T;
|
|
44
|
+
/**
|
|
45
|
+
* Check if a service is registered.
|
|
46
|
+
* @param key - The service key to check.
|
|
47
|
+
* @returns True if the service is registered.
|
|
48
|
+
*/
|
|
49
|
+
has(key: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Clear all registered services.
|
|
52
|
+
*/
|
|
53
|
+
clear(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Clear singleton cache (useful for testing).
|
|
56
|
+
*/
|
|
57
|
+
clearSingletons(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Unregister a service.
|
|
60
|
+
* @param key - The service key to unregister.
|
|
61
|
+
*/
|
|
62
|
+
unregister(key: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* Get all registered service keys.
|
|
65
|
+
* @returns Array of registered service keys.
|
|
66
|
+
*/
|
|
67
|
+
getRegisteredKeys(): string[];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Service keys used in Yes2SDK.
|
|
71
|
+
*/
|
|
72
|
+
export declare const ServiceKey: {
|
|
73
|
+
readonly LOGGER: "logger";
|
|
74
|
+
readonly EVENT_EMITTER: "eventEmitter";
|
|
75
|
+
readonly PLATFORM: "platform";
|
|
76
|
+
readonly PLATFORM_SDK: "platformSDK";
|
|
77
|
+
readonly ADS_API: "adsAPI";
|
|
78
|
+
readonly PLAYER_API: "playerAPI";
|
|
79
|
+
readonly SESSION_API: "sessionAPI";
|
|
80
|
+
readonly ANALYTICS_API: "analyticsAPI";
|
|
81
|
+
readonly LEADERBOARD_API: "leaderboardAPI";
|
|
82
|
+
readonly IAP_API: "iapAPI";
|
|
83
|
+
readonly CONTEXT_API: "contextAPI";
|
|
84
|
+
readonly ACHIEVEMENTS_API: "achievementsAPI";
|
|
85
|
+
readonly NOTIFICATIONS_API: "notificationsAPI";
|
|
86
|
+
readonly TOURNAMENT_API: "tournamentAPI";
|
|
87
|
+
readonly STATS_API: "statsAPI";
|
|
88
|
+
readonly AUTH_API: "authAPI";
|
|
89
|
+
readonly ADS_STRATEGY: "adsStrategy";
|
|
90
|
+
readonly PLAYER_STRATEGY: "playerStrategy";
|
|
91
|
+
readonly SESSION_STRATEGY: "sessionStrategy";
|
|
92
|
+
readonly ANALYTICS_STRATEGY: "analyticsStrategy";
|
|
93
|
+
readonly LEADERBOARD_STRATEGY: "leaderboardStrategy";
|
|
94
|
+
readonly IAP_STRATEGY: "iapStrategy";
|
|
95
|
+
readonly CONTEXT_STRATEGY: "contextStrategy";
|
|
96
|
+
readonly ACHIEVEMENTS_STRATEGY: "achievementsStrategy";
|
|
97
|
+
readonly NOTIFICATIONS_STRATEGY: "notificationsStrategy";
|
|
98
|
+
readonly TOURNAMENT_STRATEGY: "tournamentStrategy";
|
|
99
|
+
readonly STATS_STRATEGY: "statsStrategy";
|
|
100
|
+
readonly AUTH_STRATEGY: "authStrategy";
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=di-container.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"di-container.d.ts","sourceRoot":"","sources":["../../src/core/di-container.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,KAAK,CAAC,CAAC;AAU9D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,SAAS,CAAwD;IACzE,OAAO,CAAC,WAAW,CAAmC;IAEtD;;;;;OAKG;IACI,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,SAAS,GAAE,OAAe,GAAG,IAAI;IAS7F;;;;;OAKG;IACI,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC;IAuBjC;;;;OAIG;IACI,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIhC;;OAEG;IACI,KAAK,IAAI,IAAI;IAKpB;;OAEG;IACI,eAAe,IAAI,IAAI;IAI9B;;;OAGG;IACI,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAKpC;;;OAGG;IACI,iBAAiB,IAAI,MAAM,EAAE;CAGvC;AAED;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiCb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACzD,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type ErrorCodeType, type ErrorMessage } from "../types/errors";
|
|
2
|
+
/**
|
|
3
|
+
* Documentation URLs for Yes2SDK APIs.
|
|
4
|
+
*/
|
|
5
|
+
declare const API_URL: {
|
|
6
|
+
readonly CORE: "https://docs.yes2sdk.com/api/core";
|
|
7
|
+
readonly ADS: "https://docs.yes2sdk.com/api/ads";
|
|
8
|
+
readonly PLAYER: "https://docs.yes2sdk.com/api/player";
|
|
9
|
+
readonly SESSION: "https://docs.yes2sdk.com/api/session";
|
|
10
|
+
readonly ANALYTICS: "https://docs.yes2sdk.com/api/analytics";
|
|
11
|
+
readonly LEADERBOARD: "https://docs.yes2sdk.com/api/leaderboard";
|
|
12
|
+
readonly IAP: "https://docs.yes2sdk.com/api/iap";
|
|
13
|
+
readonly CONTEXT: "https://docs.yes2sdk.com/api/context";
|
|
14
|
+
readonly ACHIEVEMENTS: "https://docs.yes2sdk.com/api/achievements";
|
|
15
|
+
readonly NOTIFICATIONS: "https://docs.yes2sdk.com/api/notifications";
|
|
16
|
+
readonly TOURNAMENT: "https://docs.yes2sdk.com/api/tournament";
|
|
17
|
+
readonly STATS: "https://docs.yes2sdk.com/api/stats";
|
|
18
|
+
readonly AUTH: "https://docs.yes2sdk.com/api/auth";
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Create an ErrorMessage for invalid parameters.
|
|
22
|
+
* @param message - Description of what was invalid.
|
|
23
|
+
* @param context - The API context where the error occurred.
|
|
24
|
+
* @param url - Optional documentation URL.
|
|
25
|
+
* @returns An ErrorMessage object.
|
|
26
|
+
*/
|
|
27
|
+
export declare function invalidParams(message: string, context: string, url?: string): ErrorMessage;
|
|
28
|
+
/**
|
|
29
|
+
* Create an ErrorMessage for invalid operations.
|
|
30
|
+
* @param message - Description of the invalid operation.
|
|
31
|
+
* @param context - The API context where the error occurred.
|
|
32
|
+
* @param url - Optional documentation URL.
|
|
33
|
+
* @returns An ErrorMessage object.
|
|
34
|
+
*/
|
|
35
|
+
export declare function invalidOperation(message: string, context: string, url?: string): ErrorMessage;
|
|
36
|
+
/**
|
|
37
|
+
* Create an ErrorMessage for uninitialized SDK.
|
|
38
|
+
* @param context - The API context where the error occurred.
|
|
39
|
+
* @returns An ErrorMessage object.
|
|
40
|
+
*/
|
|
41
|
+
export declare function notInitialized(context: string): ErrorMessage;
|
|
42
|
+
/**
|
|
43
|
+
* Create an ErrorMessage for unsupported features.
|
|
44
|
+
* @param feature - The feature that is not supported.
|
|
45
|
+
* @param context - The API context where the error occurred.
|
|
46
|
+
* @returns An ErrorMessage object.
|
|
47
|
+
*/
|
|
48
|
+
export declare function featureNotSupported(feature: string, context: string): ErrorMessage;
|
|
49
|
+
/**
|
|
50
|
+
* Create an ErrorMessage for platform-specific errors.
|
|
51
|
+
* @param message - Description of the platform error.
|
|
52
|
+
* @param context - The API context where the error occurred.
|
|
53
|
+
* @param originalError - The original error from the platform SDK.
|
|
54
|
+
* @returns An ErrorMessage object.
|
|
55
|
+
*/
|
|
56
|
+
export declare function platformError(message: string, context: string, originalError?: unknown): ErrorMessage;
|
|
57
|
+
/**
|
|
58
|
+
* Create an ErrorMessage for network failures.
|
|
59
|
+
* @param message - Description of the network error.
|
|
60
|
+
* @param context - The API context where the error occurred.
|
|
61
|
+
* @param originalError - The original error.
|
|
62
|
+
* @returns An ErrorMessage object.
|
|
63
|
+
*/
|
|
64
|
+
export declare function networkError(message: string, context: string, originalError?: unknown): ErrorMessage;
|
|
65
|
+
/**
|
|
66
|
+
* Create a generic ErrorMessage.
|
|
67
|
+
* @param code - The error code.
|
|
68
|
+
* @param message - Human-readable error message.
|
|
69
|
+
* @param context - The API context where the error occurred.
|
|
70
|
+
* @param url - Optional documentation URL.
|
|
71
|
+
* @param originalError - Optional original error.
|
|
72
|
+
* @returns An ErrorMessage object.
|
|
73
|
+
*/
|
|
74
|
+
export declare function createError(code: ErrorCodeType, message: string, context: string, url?: string, originalError?: unknown): ErrorMessage;
|
|
75
|
+
/**
|
|
76
|
+
* Map a platform SDK error to a Yes2SDK ErrorMessage.
|
|
77
|
+
* @param error - The original error from the platform SDK.
|
|
78
|
+
* @param context - The API context where the error occurred.
|
|
79
|
+
* @returns An ErrorMessage object.
|
|
80
|
+
*/
|
|
81
|
+
export declare function mapPlatformError(error: unknown, context: string): ErrorMessage;
|
|
82
|
+
export { API_URL };
|
|
83
|
+
//# sourceMappingURL=error-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../src/errors/error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEnF;;GAEG;AACH,QAAA,MAAM,OAAO;;;;;;;;;;;;;;CAcH,CAAC;AAEX;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,YAAY,CAE1F;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,YAAY,CAE7F;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAO5D;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,CAMlF;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO,GAAG,YAAY,CAOrG;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO,GAAG,YAAY,CAOpG;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CACvB,IAAI,EAAE,aAAa,EACnB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,GAAG,CAAC,EAAE,MAAM,EACZ,aAAa,CAAC,EAAE,OAAO,GACxB,YAAY,CAQd;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,CAU9E;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Yes2SDK - Multi-platform game integration SDK for HTML5 games.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Yes2SDK provides a unified API for integrating HTML5 games with 20+
|
|
6
|
+
* gaming platforms including Facebook, Yandex, Poki, CrazyGames, and more.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import Yes2SDK from '@yes2sdk/core';
|
|
11
|
+
*
|
|
12
|
+
* // Initialize SDK
|
|
13
|
+
* await Yes2SDK.initializeAsync();
|
|
14
|
+
*
|
|
15
|
+
* // Set loading progress
|
|
16
|
+
* Yes2SDK.setLoadingProgress(100);
|
|
17
|
+
*
|
|
18
|
+
* // Start game
|
|
19
|
+
* await Yes2SDK.startGameAsync();
|
|
20
|
+
*
|
|
21
|
+
* // Show an ad
|
|
22
|
+
* Yes2SDK.ads.showInterstitial('next', 'LevelComplete', pauseGame, resumeGame);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @packageDocumentation
|
|
26
|
+
*/
|
|
27
|
+
import { CoreAPI } from "./core/core-api";
|
|
28
|
+
export * from "./types";
|
|
29
|
+
export * from "./utils";
|
|
30
|
+
export * from "./errors";
|
|
31
|
+
export * from "./core";
|
|
32
|
+
/**
|
|
33
|
+
* The global Yes2SDK instance.
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* This is the main entry point for the SDK. All SDK functionality
|
|
37
|
+
* is accessed through this singleton instance.
|
|
38
|
+
*/
|
|
39
|
+
declare const Yes2SDK: CoreAPI;
|
|
40
|
+
export default Yes2SDK;
|
|
41
|
+
export { Yes2SDK };
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG1C,cAAc,SAAS,CAAC;AAGxB,cAAc,SAAS,CAAC;AAGxB,cAAc,UAAU,CAAC;AAGzB,cAAc,QAAQ,CAAC;AAEvB;;;;;;GAMG;AACH,QAAA,MAAM,OAAO,SAAgB,CAAC;AAE9B,eAAe,OAAO,CAAC;AAGvB,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK initialization options.
|
|
3
|
+
*/
|
|
4
|
+
export interface InitializationOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Enable debug mode for additional logging.
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
debug?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Skip automatic platform SDK initialization.
|
|
12
|
+
* When true, you must manually initialize the platform SDK.
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
manualInit?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Custom game ID override.
|
|
18
|
+
* Some platforms allow specifying a custom game identifier.
|
|
19
|
+
*/
|
|
20
|
+
gameId?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Skip ad preloading during initialization.
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
skipAdPreload?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* SDK initialization state.
|
|
29
|
+
*/
|
|
30
|
+
export interface InitializationState {
|
|
31
|
+
/**
|
|
32
|
+
* Whether the SDK has been initialized.
|
|
33
|
+
*/
|
|
34
|
+
isInitialized: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Whether the game has started (startGameAsync called).
|
|
37
|
+
*/
|
|
38
|
+
isGameStarted: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Current loading progress (0-100).
|
|
41
|
+
*/
|
|
42
|
+
loadingProgress: number;
|
|
43
|
+
/**
|
|
44
|
+
* Error that occurred during initialization, if any.
|
|
45
|
+
*/
|
|
46
|
+
initializationError?: Error;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=initialization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialization.d.ts","sourceRoot":"","sources":["../../../src/types/core/initialization.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAClC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,mBAAmB,CAAC,EAAE,KAAK,CAAC;CAC/B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform identifier for supported gaming platforms.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Each platform has a unique identifier used throughout the SDK
|
|
6
|
+
* to determine platform-specific behavior.
|
|
7
|
+
*/
|
|
8
|
+
export type Platform = "yes2" | "facebook" | "yandex" | "poki" | "crazygames" | "telegram" | "gamemonetize" | "gamedistribution" | "addictinggames" | "gamepix" | "gamesnacks" | "viber" | "mixi" | "tsutaya" | "line" | "gmo" | "xiaomi" | "kantangame" | "telegram-yes2" | "debug";
|
|
9
|
+
/**
|
|
10
|
+
* List of all supported platforms.
|
|
11
|
+
*/
|
|
12
|
+
export declare const PLATFORMS: readonly ["yes2", "facebook", "yandex", "poki", "crazygames", "telegram", "gamemonetize", "gamedistribution", "addictinggames", "gamepix", "gamesnacks", "viber", "mixi", "tsutaya", "line", "gmo", "xiaomi", "kantangame", "telegram-yes2", "debug"];
|
|
13
|
+
/**
|
|
14
|
+
* Type guard to check if a value is a valid Platform.
|
|
15
|
+
* @param value - The value to check.
|
|
16
|
+
* @returns True if the value is a valid Platform.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isPlatform(value: unknown): value is Platform;
|
|
19
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../../src/types/core/platform.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GACd,MAAM,GACN,UAAU,GACV,QAAQ,GACR,MAAM,GACN,YAAY,GACZ,UAAU,GACV,cAAc,GACd,kBAAkB,GAClB,gBAAgB,GAChB,SAAS,GACT,YAAY,GACZ,OAAO,GACP,MAAM,GACN,SAAS,GACT,MAAM,GACN,KAAK,GACL,QAAQ,GACR,YAAY,GACZ,eAAe,GACf,OAAO,CAAC;AAEd;;GAEG;AACH,eAAO,MAAM,SAAS,uPAqBZ,CAAC;AAEX;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAE5D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error codes used throughout Yes2SDK.
|
|
3
|
+
*/
|
|
4
|
+
export declare const ErrorCode: {
|
|
5
|
+
readonly INITIALIZATION_ERROR: "INITIALIZATION_ERROR";
|
|
6
|
+
readonly CLIENT_UNSUPPORTED: "CLIENT_UNSUPPORTED";
|
|
7
|
+
readonly NOT_INITIALIZED: "NOT_INITIALIZED";
|
|
8
|
+
readonly INVALID_PARAM: "INVALID_PARAM";
|
|
9
|
+
readonly INVALID_OPERATION: "INVALID_OPERATION";
|
|
10
|
+
readonly NETWORK_FAILURE: "NETWORK_FAILURE";
|
|
11
|
+
readonly TIMEOUT: "TIMEOUT";
|
|
12
|
+
readonly PLATFORM_ERROR: "PLATFORM_ERROR";
|
|
13
|
+
readonly PLATFORM_NOT_SUPPORTED: "PLATFORM_NOT_SUPPORTED";
|
|
14
|
+
readonly FEATURE_NOT_SUPPORTED: "FEATURE_NOT_SUPPORTED";
|
|
15
|
+
readonly ADS_NOT_LOADED: "ADS_NOT_LOADED";
|
|
16
|
+
readonly ADS_NO_FILL: "ADS_NO_FILL";
|
|
17
|
+
readonly ADS_BLOCKED: "ADS_BLOCKED";
|
|
18
|
+
readonly ADS_FREQUENCY_LIMITED: "ADS_FREQUENCY_LIMITED";
|
|
19
|
+
readonly PLAYER_NOT_AUTHENTICATED: "PLAYER_NOT_AUTHENTICATED";
|
|
20
|
+
readonly PLAYER_DATA_CORRUPTED: "PLAYER_DATA_CORRUPTED";
|
|
21
|
+
readonly STORAGE_ERROR: "STORAGE_ERROR";
|
|
22
|
+
readonly STORAGE_QUOTA_EXCEEDED: "STORAGE_QUOTA_EXCEEDED";
|
|
23
|
+
readonly IAP_NOT_AVAILABLE: "IAP_NOT_AVAILABLE";
|
|
24
|
+
readonly IAP_PURCHASE_FAILED: "IAP_PURCHASE_FAILED";
|
|
25
|
+
readonly IAP_ALREADY_PURCHASED: "IAP_ALREADY_PURCHASED";
|
|
26
|
+
readonly LEADERBOARD_NOT_FOUND: "LEADERBOARD_NOT_FOUND";
|
|
27
|
+
readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Type for error codes.
|
|
31
|
+
*/
|
|
32
|
+
export type ErrorCodeType = (typeof ErrorCode)[keyof typeof ErrorCode];
|
|
33
|
+
//# sourceMappingURL=error-codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../../../src/types/errors/error-codes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;CA2CZ,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ErrorCodeType } from "./error-codes";
|
|
2
|
+
/**
|
|
3
|
+
* Standardized error message structure used throughout Yes2SDK.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* All errors in the SDK follow this structure to provide consistent
|
|
7
|
+
* error handling and debugging information.
|
|
8
|
+
*/
|
|
9
|
+
export interface ErrorMessage {
|
|
10
|
+
/**
|
|
11
|
+
* The error code identifying the type of error.
|
|
12
|
+
* @see ErrorCode
|
|
13
|
+
*/
|
|
14
|
+
code: ErrorCodeType;
|
|
15
|
+
/**
|
|
16
|
+
* Human-readable error message describing what went wrong.
|
|
17
|
+
*/
|
|
18
|
+
message: string;
|
|
19
|
+
/**
|
|
20
|
+
* The API context where the error occurred.
|
|
21
|
+
* Typically the API method name.
|
|
22
|
+
*/
|
|
23
|
+
context: string;
|
|
24
|
+
/**
|
|
25
|
+
* URL to documentation for this error (if available).
|
|
26
|
+
*/
|
|
27
|
+
url?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Original error from the platform SDK (if available).
|
|
30
|
+
*/
|
|
31
|
+
originalError?: unknown;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Type guard to check if a value is an ErrorMessage.
|
|
35
|
+
* @param value - The value to check.
|
|
36
|
+
* @returns True if the value is an ErrorMessage.
|
|
37
|
+
*/
|
|
38
|
+
export declare function isErrorMessage(value: unknown): value is ErrorMessage;
|
|
39
|
+
//# sourceMappingURL=error-message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-message.d.ts","sourceRoot":"","sources":["../../../src/types/errors/error-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IACzB;;;OAGG;IACH,IAAI,EAAE,aAAa,CAAC;IAEpB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAOpE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ErrorMessage } from "./error-message";
|
|
2
|
+
/**
|
|
3
|
+
* Result of a validation operation.
|
|
4
|
+
*
|
|
5
|
+
* @typeParam T - The type of the validated data (when valid).
|
|
6
|
+
*/
|
|
7
|
+
export interface ValidationResult<T = unknown> {
|
|
8
|
+
/**
|
|
9
|
+
* Whether the validation passed.
|
|
10
|
+
*/
|
|
11
|
+
valid: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Error information if validation failed.
|
|
14
|
+
*/
|
|
15
|
+
error?: ErrorMessage;
|
|
16
|
+
/**
|
|
17
|
+
* Validated and possibly transformed data if validation passed.
|
|
18
|
+
*/
|
|
19
|
+
data?: T;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create a successful validation result.
|
|
23
|
+
* @param data - The validated data.
|
|
24
|
+
* @returns A successful validation result.
|
|
25
|
+
*/
|
|
26
|
+
export declare function validResult<T>(data?: T): ValidationResult<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Create a failed validation result.
|
|
29
|
+
* @param error - The error that caused validation to fail.
|
|
30
|
+
* @returns A failed validation result.
|
|
31
|
+
*/
|
|
32
|
+
export declare function invalidResult<T = unknown>(error: ErrorMessage): ValidationResult<T>;
|
|
33
|
+
//# sourceMappingURL=validation-result.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-result.d.ts","sourceRoot":"","sources":["../../../src/types/errors/validation-result.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;;;GAIG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,OAAO;IACzC;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IAEf;;OAEG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC;IAErB;;OAEG;IACH,IAAI,CAAC,EAAE,CAAC,CAAC;CACZ;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAK5D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,YAAY,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAKnF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-safe event listener function.
|
|
3
|
+
*/
|
|
4
|
+
export type EventListener<T = unknown> = (data: T) => void;
|
|
5
|
+
/**
|
|
6
|
+
* Event subscription that can be unsubscribed.
|
|
7
|
+
*/
|
|
8
|
+
export interface EventSubscription {
|
|
9
|
+
/**
|
|
10
|
+
* Unsubscribe from the event.
|
|
11
|
+
*/
|
|
12
|
+
unsubscribe: () => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Type-safe EventEmitter for Yes2SDK.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* This replaces the array-based callback pattern used in the original SDK
|
|
19
|
+
* with a proper EventEmitter that prevents memory leaks and provides
|
|
20
|
+
* better subscription management.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const emitter = new EventEmitter<{
|
|
25
|
+
* 'adLoaded': { adType: string };
|
|
26
|
+
* 'adError': { error: Error };
|
|
27
|
+
* }>();
|
|
28
|
+
*
|
|
29
|
+
* const subscription = emitter.on('adLoaded', (data) => {
|
|
30
|
+
* console.log('Ad loaded:', data.adType);
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* emitter.emit('adLoaded', { adType: 'interstitial' });
|
|
34
|
+
*
|
|
35
|
+
* // Clean up
|
|
36
|
+
* subscription.unsubscribe();
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare class EventEmitter<TEvents = Record<string, unknown>> {
|
|
40
|
+
private _listeners;
|
|
41
|
+
/**
|
|
42
|
+
* Subscribe to an event.
|
|
43
|
+
* @param event - The event name to subscribe to.
|
|
44
|
+
* @param listener - The listener function to call when the event is emitted.
|
|
45
|
+
* @returns A subscription object that can be used to unsubscribe.
|
|
46
|
+
*/
|
|
47
|
+
on<K extends keyof TEvents>(event: K, listener: EventListener<TEvents[K]>): EventSubscription;
|
|
48
|
+
/**
|
|
49
|
+
* Subscribe to an event only once.
|
|
50
|
+
* @param event - The event name to subscribe to.
|
|
51
|
+
* @param listener - The listener function to call when the event is emitted.
|
|
52
|
+
* @returns A subscription object that can be used to unsubscribe.
|
|
53
|
+
*/
|
|
54
|
+
once<K extends keyof TEvents>(event: K, listener: EventListener<TEvents[K]>): EventSubscription;
|
|
55
|
+
/**
|
|
56
|
+
* Unsubscribe from an event.
|
|
57
|
+
* @param event - The event name to unsubscribe from.
|
|
58
|
+
* @param listener - The listener function to remove.
|
|
59
|
+
*/
|
|
60
|
+
off<K extends keyof TEvents>(event: K, listener: EventListener<TEvents[K]>): void;
|
|
61
|
+
/**
|
|
62
|
+
* Emit an event with data.
|
|
63
|
+
* @param event - The event name to emit.
|
|
64
|
+
* @param data - The data to pass to listeners.
|
|
65
|
+
*/
|
|
66
|
+
emit<K extends keyof TEvents>(event: K, data: TEvents[K]): void;
|
|
67
|
+
/**
|
|
68
|
+
* Remove all listeners for an event.
|
|
69
|
+
* @param event - The event name to clear. If not provided, clears all listeners.
|
|
70
|
+
*/
|
|
71
|
+
removeAllListeners<K extends keyof TEvents>(event?: K): void;
|
|
72
|
+
/**
|
|
73
|
+
* Get the number of listeners for an event.
|
|
74
|
+
* @param event - The event name to check.
|
|
75
|
+
* @returns The number of listeners.
|
|
76
|
+
*/
|
|
77
|
+
listenerCount<K extends keyof TEvents>(event: K): number;
|
|
78
|
+
/**
|
|
79
|
+
* Check if there are any listeners for an event.
|
|
80
|
+
* @param event - The event name to check.
|
|
81
|
+
* @returns True if there are listeners.
|
|
82
|
+
*/
|
|
83
|
+
hasListeners<K extends keyof TEvents>(event: K): boolean;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=event-emitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-emitter.d.ts","sourceRoot":"","sources":["../../src/utils/event-emitter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B;;OAEG;IACH,WAAW,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,YAAY,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACvD,OAAO,CAAC,UAAU,CAA8D;IAEhF;;;;;OAKG;IACI,EAAE,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,iBAAiB;IAepG;;;;;OAKG;IACI,IAAI,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,iBAAiB;IAStG;;;;OAIG;IACI,GAAG,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;IAUxF;;;;OAIG;IACI,IAAI,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI;IActE;;;OAGG;IACI,kBAAkB,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI;IAQnE;;;;OAIG;IACI,aAAa,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM;IAI/D;;;;OAIG;IACI,YAAY,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO;CAGlE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { ErrorMessage } from "../types/errors";
|
|
2
|
+
/**
|
|
3
|
+
* Log levels for the SDK logger.
|
|
4
|
+
*/
|
|
5
|
+
export declare enum LogLevel {
|
|
6
|
+
DEBUG = 0,
|
|
7
|
+
INFO = 1,
|
|
8
|
+
WARN = 2,
|
|
9
|
+
ERROR = 3,
|
|
10
|
+
NONE = 4
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Logger configuration.
|
|
14
|
+
*/
|
|
15
|
+
export interface LoggerConfig {
|
|
16
|
+
/**
|
|
17
|
+
* Minimum log level to output.
|
|
18
|
+
* @default LogLevel.WARN
|
|
19
|
+
*/
|
|
20
|
+
level: LogLevel;
|
|
21
|
+
/**
|
|
22
|
+
* Prefix for all log messages.
|
|
23
|
+
* @default "[Yes2SDK]"
|
|
24
|
+
*/
|
|
25
|
+
prefix: string;
|
|
26
|
+
/**
|
|
27
|
+
* Whether to include timestamps in log messages.
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
includeTimestamp: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Logger class for Yes2SDK.
|
|
34
|
+
* Provides consistent logging across the SDK with configurable log levels.
|
|
35
|
+
*/
|
|
36
|
+
export declare class Logger {
|
|
37
|
+
private _config;
|
|
38
|
+
/**
|
|
39
|
+
* Create a new Logger instance.
|
|
40
|
+
* @param config - Optional logger configuration.
|
|
41
|
+
*/
|
|
42
|
+
constructor(config?: Partial<LoggerConfig>);
|
|
43
|
+
/**
|
|
44
|
+
* Set the log level.
|
|
45
|
+
* @param level - The new log level.
|
|
46
|
+
*/
|
|
47
|
+
setLevel(level: LogLevel): void;
|
|
48
|
+
/**
|
|
49
|
+
* Get the current log level.
|
|
50
|
+
* @returns The current log level.
|
|
51
|
+
*/
|
|
52
|
+
getLevel(): LogLevel;
|
|
53
|
+
/**
|
|
54
|
+
* Enable debug mode (sets log level to DEBUG).
|
|
55
|
+
*/
|
|
56
|
+
enableDebug(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Log a debug message.
|
|
59
|
+
* @param message - The message to log.
|
|
60
|
+
* @param data - Optional additional data.
|
|
61
|
+
*/
|
|
62
|
+
debug(message: string, data?: unknown): void;
|
|
63
|
+
/**
|
|
64
|
+
* Log an info message.
|
|
65
|
+
* @param message - The message to log.
|
|
66
|
+
* @param data - Optional additional data.
|
|
67
|
+
*/
|
|
68
|
+
info(message: string, data?: unknown): void;
|
|
69
|
+
/**
|
|
70
|
+
* Log a warning message.
|
|
71
|
+
* @param message - The message to log.
|
|
72
|
+
* @param data - Optional additional data.
|
|
73
|
+
*/
|
|
74
|
+
warn(message: string, data?: unknown): void;
|
|
75
|
+
/**
|
|
76
|
+
* Log an error message.
|
|
77
|
+
* @param message - The message to log.
|
|
78
|
+
* @param error - Optional error object.
|
|
79
|
+
*/
|
|
80
|
+
error(message: string, error?: unknown): void;
|
|
81
|
+
/**
|
|
82
|
+
* Log an API call.
|
|
83
|
+
* @param apiName - The name of the API being called.
|
|
84
|
+
*/
|
|
85
|
+
apiCall(apiName: string): void;
|
|
86
|
+
/**
|
|
87
|
+
* Log an API error.
|
|
88
|
+
* @param apiName - The name of the API that failed.
|
|
89
|
+
* @param error - The error that occurred.
|
|
90
|
+
*/
|
|
91
|
+
apiError(apiName: string, error?: ErrorMessage): void;
|
|
92
|
+
/**
|
|
93
|
+
* Log an exception with full details.
|
|
94
|
+
* @param message - Description of where the exception occurred.
|
|
95
|
+
* @param error - The error or ErrorMessage.
|
|
96
|
+
*/
|
|
97
|
+
exception(message: string, error?: unknown): void;
|
|
98
|
+
/**
|
|
99
|
+
* Internal log method.
|
|
100
|
+
* @param level - The log level.
|
|
101
|
+
* @param message - The message to log.
|
|
102
|
+
* @param data - Optional additional data.
|
|
103
|
+
*/
|
|
104
|
+
private _log;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Default logger instance.
|
|
108
|
+
*/
|
|
109
|
+
export declare const logger: Logger;
|
|
110
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;GAEG;AACH,oBAAY,QAAQ;IAChB,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;IACT,IAAI,IAAI;CACX;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB;;;OAGG;IACH,KAAK,EAAE,QAAQ,CAAC;IAEhB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,gBAAgB,EAAE,OAAO,CAAC;CAC7B;AAED;;;GAGG;AACH,qBAAa,MAAM;IACf,OAAO,CAAC,OAAO,CAAe;IAE9B;;;OAGG;gBACS,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC;IAQ1C;;;OAGG;IACI,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAItC;;;OAGG;IACI,QAAQ,IAAI,QAAQ;IAI3B;;OAEG;IACI,WAAW,IAAI,IAAI;IAI1B;;;;OAIG;IACI,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAMnD;;;;OAIG;IACI,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAMlD;;;;OAIG;IACI,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAMlD;;;;OAIG;IACI,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI;IAMpD;;;OAGG;IACI,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAIrC;;;;OAIG;IACI,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,YAAY,GAAG,IAAI;IAK5D;;;;OAIG;IACI,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI;IAIxD;;;;;OAKG;IACH,OAAO,CAAC,IAAI;CAYf;AAED;;GAEG;AACH,eAAO,MAAM,MAAM,QAAe,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Platform } from "../types/core/platform";
|
|
2
|
+
/**
|
|
3
|
+
* Detect the current gaming platform.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This function uses a series of detection rules to determine which
|
|
7
|
+
* gaming platform the SDK is currently running on. The detection is
|
|
8
|
+
* based on global objects, hostnames, and other platform-specific indicators.
|
|
9
|
+
*
|
|
10
|
+
* @returns The detected platform, or "debug" if no platform is detected.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const platform = detectPlatform();
|
|
15
|
+
* console.log(`Running on: ${platform}`);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function detectPlatform(): Platform;
|
|
19
|
+
/**
|
|
20
|
+
* Check if a platform is supported.
|
|
21
|
+
* @param platform - The platform to check.
|
|
22
|
+
* @returns True if the platform is supported.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isPlatformSupported(platform: string): platform is Platform;
|
|
25
|
+
/**
|
|
26
|
+
* Get all supported platforms.
|
|
27
|
+
* @returns Array of all supported platform identifiers.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getSupportedPlatforms(): readonly Platform[];
|
|
30
|
+
//# sourceMappingURL=platform-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform-detector.d.ts","sourceRoot":"","sources":["../../src/utils/platform-detector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAa,MAAM,wBAAwB,CAAC;AA2JlE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,IAAI,QAAQ,CAazC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,IAAI,QAAQ,CAE1E;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,SAAS,QAAQ,EAAE,CAE3D"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation utilities for Yes2SDK.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* These validators consolidate common validation patterns used throughout
|
|
6
|
+
* the SDK, replacing the duplicated validation logic in the original codebase.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Check if a value is a non-empty string.
|
|
10
|
+
* @param value - The value to check.
|
|
11
|
+
* @returns True if the value is a non-empty string.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isValidString(value: unknown): value is string;
|
|
14
|
+
/**
|
|
15
|
+
* Check if a value is a valid number (not NaN).
|
|
16
|
+
* @param value - The value to check.
|
|
17
|
+
* @returns True if the value is a valid number.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isValidNumber(value: unknown): value is number;
|
|
20
|
+
/**
|
|
21
|
+
* Check if a value is a valid integer.
|
|
22
|
+
* @param value - The value to check.
|
|
23
|
+
* @returns True if the value is a valid integer.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isValidInteger(value: unknown): value is number;
|
|
26
|
+
/**
|
|
27
|
+
* Check if a value is a positive number.
|
|
28
|
+
* @param value - The value to check.
|
|
29
|
+
* @returns True if the value is a positive number.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isPositiveNumber(value: unknown): value is number;
|
|
32
|
+
/**
|
|
33
|
+
* Check if a value is a non-negative number.
|
|
34
|
+
* @param value - The value to check.
|
|
35
|
+
* @returns True if the value is a non-negative number.
|
|
36
|
+
*/
|
|
37
|
+
export declare function isNonNegativeNumber(value: unknown): value is number;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a value is within a range (inclusive).
|
|
40
|
+
* @param value - The value to check.
|
|
41
|
+
* @param min - The minimum value.
|
|
42
|
+
* @param max - The maximum value.
|
|
43
|
+
* @returns True if the value is within the range.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isInRange(value: unknown, min: number, max: number): value is number;
|
|
46
|
+
/**
|
|
47
|
+
* Check if a value is a valid function.
|
|
48
|
+
* @param value - The value to check.
|
|
49
|
+
* @returns True if the value is a function.
|
|
50
|
+
*/
|
|
51
|
+
export declare function isValidFunction(value: unknown): value is (...args: unknown[]) => unknown;
|
|
52
|
+
/**
|
|
53
|
+
* Check if a value is a valid object (not null, not array).
|
|
54
|
+
* @param value - The value to check.
|
|
55
|
+
* @returns True if the value is a valid object.
|
|
56
|
+
*/
|
|
57
|
+
export declare function isValidObject(value: unknown): value is Record<string, unknown>;
|
|
58
|
+
/**
|
|
59
|
+
* Check if a value is a valid array.
|
|
60
|
+
* @param value - The value to check.
|
|
61
|
+
* @returns True if the value is a valid array.
|
|
62
|
+
*/
|
|
63
|
+
export declare function isValidArray(value: unknown): value is unknown[];
|
|
64
|
+
/**
|
|
65
|
+
* Check if a value is a non-empty array.
|
|
66
|
+
* @param value - The value to check.
|
|
67
|
+
* @returns True if the value is a non-empty array.
|
|
68
|
+
*/
|
|
69
|
+
export declare function isNonEmptyArray(value: unknown): value is unknown[];
|
|
70
|
+
/**
|
|
71
|
+
* Check if a value is a valid URL string.
|
|
72
|
+
* @param value - The value to check.
|
|
73
|
+
* @returns True if the value is a valid URL.
|
|
74
|
+
*/
|
|
75
|
+
export declare function isValidUrl(value: unknown): value is string;
|
|
76
|
+
/**
|
|
77
|
+
* Check if a value is null or undefined.
|
|
78
|
+
* @param value - The value to check.
|
|
79
|
+
* @returns True if the value is null or undefined.
|
|
80
|
+
*/
|
|
81
|
+
export declare function isNullOrUndefined(value: unknown): value is null | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Check if a value is defined (not null and not undefined).
|
|
84
|
+
* @param value - The value to check.
|
|
85
|
+
* @returns True if the value is defined.
|
|
86
|
+
*/
|
|
87
|
+
export declare function isDefined<T>(value: T | null | undefined): value is T;
|
|
88
|
+
/**
|
|
89
|
+
* Ensure a value is defined, throwing an error if not.
|
|
90
|
+
* @param value - The value to check.
|
|
91
|
+
* @param name - The name of the value (for error message).
|
|
92
|
+
* @returns The value if defined.
|
|
93
|
+
* @throws Error if the value is null or undefined.
|
|
94
|
+
*/
|
|
95
|
+
export declare function ensureDefined<T>(value: T | null | undefined, name: string): T;
|
|
96
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE7D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE7D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EA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,MAAM,GAAG,CAAC,CAK7E"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Yes2SDK=t():e.Yes2SDK=t()}(Object("undefined"!=typeof self?self:this),()=>(()=>{"use strict";var e={d:(t,i)=>{for(var s in i)e.o(i,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:i[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{default:()=>_});class i{constructor(){this._services=new Map,this._singletons=new Map}register(e,t,i=!1){this._services.set(e,{factory:t,singleton:i}),this._singletons.has(e)&&this._singletons.delete(e)}resolve(e){const t=this._services.get(e);if(!t)throw new Error(`Service "${e}" is not registered.`);if(t.singleton&&this._singletons.has(e))return this._singletons.get(e);const i=t.factory(this);return t.singleton&&this._singletons.set(e,i),i}has(e){return this._services.has(e)}clear(){this._services.clear(),this._singletons.clear()}clearSingletons(){this._singletons.clear()}unregister(e){this._services.delete(e),this._singletons.delete(e)}getRegisteredKeys(){return Array.from(this._services.keys())}}const s="logger",n="eventEmitter",o="platform";var r;!function(e){e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e[e.NONE=4]="NONE"}(r||(r={}));class a{constructor(e){this._config={level:e?.level??r.WARN,prefix:e?.prefix??"[Yes2SDK]",includeTimestamp:e?.includeTimestamp??!1}}setLevel(e){this._config.level=e}getLevel(){return this._config.level}enableDebug(){this._config.level=r.DEBUG}debug(e,t){this._config.level<=r.DEBUG&&this._log("debug",e,t)}info(e,t){this._config.level<=r.INFO&&this._log("info",e,t)}warn(e,t){this._config.level<=r.WARN&&this._log("warn",e,t)}error(e,t){this._config.level<=r.ERROR&&this._log("error",e,t)}apiCall(e){this.debug(`API call: ${e}`)}apiError(e,t){const i=t?`API error: ${e} - ${t.code}: ${t.message}`:`API error: ${e}`;this.error(i,t)}exception(e,t){this.error(e,t)}_log(e,t,i){const s=`${this._config.includeTimestamp?`[${(new Date).toISOString()}] `:""}${this._config.prefix} ${t}`,n=console[e];void 0!==i?n(s,i):n(s)}}new a;class l{constructor(){this._listeners=new Map}on(e,t){this._listeners.has(e)||this._listeners.set(e,new Set);const i=this._listeners.get(e);return i?.add(t),{unsubscribe:()=>{this.off(e,t)}}}once(e,t){const i=s=>{this.off(e,i),t(s)};return this.on(e,i)}off(e,t){const i=this._listeners.get(e);i&&(i.delete(t),0===i.size&&this._listeners.delete(e))}emit(e,t){const i=this._listeners.get(e);i&&i.forEach(e=>{try{e(t)}catch(e){}})}removeAllListeners(e){void 0!==e?this._listeners.delete(e):this._listeners.clear()}listenerCount(e){return this._listeners.get(e)?.size??0}hasListeners(e){return this.listenerCount(e)>0}}const c=[{platform:"facebook",detect:()=>"undefined"!=typeof window&&("FBInstant"in window||window.location.hostname.includes("facebook.com")||window.location.hostname.includes("fb.gg"))},{platform:"yandex",detect:()=>"undefined"!=typeof window&&("YaGames"in window||window.location.hostname.includes("yandex."))},{platform:"poki",detect:()=>"undefined"!=typeof window&&("PokiSDK"in window||window.location.hostname.includes("poki.com"))},{platform:"crazygames",detect:()=>"undefined"!=typeof window&&("CrazyGames"in window||window.location.hostname.includes("crazygames.com"))},{platform:"telegram",detect:()=>"undefined"!=typeof window&&("Telegram"in window||"TelegramWebviewProxy"in window)},{platform:"gamemonetize",detect:()=>"undefined"!=typeof window&&window.location.hostname.includes("gamemonetize.")},{platform:"gamedistribution",detect:()=>"undefined"!=typeof window&&("gdsdk"in window||window.location.hostname.includes("gamedistribution."))},{platform:"addictinggames",detect:()=>"undefined"!=typeof window&&window.location.hostname.includes("addictinggames.")},{platform:"gamepix",detect:()=>"undefined"!=typeof window&&window.location.hostname.includes("gamepix.")},{platform:"gamesnacks",detect:()=>"undefined"!=typeof window&&window.location.hostname.includes("gamesnacks.")},{platform:"viber",detect:()=>"undefined"!=typeof window&&window.location.hostname.includes("viber.")},{platform:"debug",detect:()=>"undefined"!=typeof window&&("localhost"===window.location.hostname||"127.0.0.1"===window.location.hostname)}];const d="NOT_INITIALIZED",g="INVALID_PARAM";const h="https://docs.yes2sdk.com/api/core";function f(e,t,i,s,n){return{code:e,message:t,context:i,url:s,originalError:n}}function m(e){return"number"==typeof e&&!isNaN(e)}const _=new class{constructor(){this._platform=null,this._container=new i,this._logger=new a,this._events=new l,this._state={isInitialized:!1,isGameStarted:!1,loadingProgress:0},this._registerCoreServices()}get isInitialized(){return this._state.isInitialized}async initializeAsync(e){if(this._state.isInitialized)this._logger.warn("Yes2SDK is already initialized.");else{this._logger.apiCall("initializeAsync");try{!0===e?.debug&&this._logger.setLevel(r.DEBUG),this._platform=function(){for(const e of c)try{if(e.detect())return e.platform}catch{}return"debug"}(),this._logger.info(`Platform detected: ${this._platform}`),this._container.register(o,()=>this._platform,!0),this._state.isInitialized=!0,this._events.emit("initialized",{platform:this._platform}),this._logger.info("Yes2SDK initialized successfully.")}catch(e){throw this._state.initializationError=e instanceof Error?e:new Error(String(e)),this._logger.error("Initialization failed",e),this._events.emit("error",{context:"initializeAsync",error:e}),e}}}async startGameAsync(){if(this._logger.apiCall("startGameAsync"),!this._state.isInitialized){const e=f(d,"Yes2SDK has not been initialized. Call Yes2SDK.initializeAsync() first.","startGameAsync",h);throw this._logger.apiError("startGameAsync",e),e}if(this._state.isGameStarted)this._logger.warn("Game has already started.");else try{this._state.isGameStarted=!0,this._events.emit("gameStarted",void 0),this._logger.info("Game started successfully.")}catch(e){throw this._logger.error("Failed to start game",e),this._events.emit("error",{context:"startGameAsync",error:e}),e}}setLoadingProgress(e){if(this._logger.apiCall("setLoadingProgress"),n=0,o=100,!(m(s=e)&&s>=n&&s<=o)){const s=(t=`Progress must be between 0 and 100, received: ${String(e)}`,f(g,t,"setLoadingProgress",i));throw this._logger.apiError("setLoadingProgress",s),s}var t,i,s,n,o;this._state.loadingProgress=e,this._events.emit("loadingProgress",{progress:e})}performHapticFeedback(){this._logger.apiCall("performHapticFeedback"),this._state.isInitialized||this._logger.warn("performHapticFeedback called before initialization.")}getPlatform(){return this._platform}on(e,t){return this._events.on(e,t)}get _log(){return this._logger}get _internalContainer(){return this._container}get _internalPlatform(){return this._platform}_registerCoreServices(){this._container.register(s,()=>this._logger,!0),this._container.register(n,()=>this._events,!0)}};return t=t.default})());
|
|
2
|
+
//# sourceMappingURL=yes2sdk.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yes2sdk.umd.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAiB,QAAID,IAErBD,EAAc,QAAIC,GACnB,CATD,CASGK,OAAuB,oBAATC,KAAuBA,KAAOC,MAAO,I,mBCRtD,IAAIC,EAAsB,CCA1BA,EAAwB,CAACP,EAASQ,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAEV,EAASS,IAC5EL,OAAOO,eAAeX,EAASS,EAAK,CAAEG,YAAY,EAAMC,IAAKL,EAAWC,MCJ3EF,EAAwB,CAACO,EAAKC,IAAUX,OAAOY,UAAUC,eAAeC,KAAKJ,EAAKC,I,4BCmC3E,MAAMI,EAAb,cACY,KAAAC,UAAuD,IAAIC,IAC3D,KAAAC,YAAoC,IAAID,GAsFpD,CA9EW,QAAAE,CAAYd,EAAaV,EAA4ByB,GAAqB,GAC7ElB,KAAKc,UAAUK,IAAIhB,EAAK,CAAEV,UAASyB,cAG/BlB,KAAKgB,YAAYI,IAAIjB,IACrBH,KAAKgB,YAAYK,OAAOlB,EAEhC,CAQO,OAAAmB,CAAWnB,GACd,MAAMoB,EAAevB,KAAKc,UAAUP,IAAIJ,GAExC,IAAKoB,EACD,MAAM,IAAIC,MAAM,YAAYrB,yB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B,EAAYF,EAAyB5C,EG+IhC,qBH/IkDgD,IGkJtD,MADAhG,KAAKuG,QAAQ7C,SAAS,qBAAsBJ,GACtCA,CACV,CHpJD,IAAuBN,EAAkCgD,ECgCtCG,EAAgBoB,EAAaC,EEsH/CxH,KAAKyG,OAAOG,gBAAkBU,EAC9BtH,KAAKwG,QAAQxB,KAAK,kBAAmB,CAAEsC,YAG3C,CAKO,qBAAAG,GACHzH,KAAKuG,QAAQ/C,QAAQ,yBAEhBxD,KAAKyG,OAAOC,eACb1G,KAAKuG,QAAQlD,KAAK,sDAK1B,CAMO,WAAAqE,GACH,OAAO1H,KAAKqG,SAChB,CAQO,EAAAhC,CAA8BC,EAAUC,GAC3C,OAAOvE,KAAKwG,QAAQnC,GAAGC,EAAOC,EAClC,CAOA,QAAWrB,GACP,OAAOlD,KAAKuG,OAChB,CAOA,sBAAWoB,GACP,OAAO3H,KAAKsG,UAChB,CAOA,qBAAWsB,GACP,OAAO5H,KAAKqG,SAChB,CAQQ,qBAAAQ,GACJ7G,KAAKsG,WAAWrF,SAASgB,EAAmB,IAAMjC,KAAKuG,SAAS,GAChEvG,KAAKsG,WAAWrF,SAASgB,EAA0B,IAAMjC,KAAKwG,SAAS,EAC3E,G","sources":["webpack://Yes2SDK/webpack/universalModuleDefinition","webpack://Yes2SDK/webpack/bootstrap","webpack://Yes2SDK/webpack/runtime/define property getters","webpack://Yes2SDK/webpack/runtime/hasOwnProperty shorthand","webpack://Yes2SDK/./src/core/di-container.ts","webpack://Yes2SDK/./src/utils/logger.ts","webpack://Yes2SDK/./src/utils/event-emitter.ts","webpack://Yes2SDK/./src/utils/platform-detector.ts","webpack://Yes2SDK/./src/types/errors/error-codes.ts","webpack://Yes2SDK/./src/errors/error-handler.ts","webpack://Yes2SDK/./src/utils/validators.ts","webpack://Yes2SDK/./src/index.ts","webpack://Yes2SDK/./src/core/core-api.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"Yes2SDK\"] = factory();\n\telse\n\t\troot[\"Yes2SDK\"] = factory();\n})(Object(typeof self !== 'undefined' ? self : this), () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","/**\n * Service factory function type.\n */\nexport type ServiceFactory<T> = (container: DIContainer) => T;\n\n/**\n * Service registration configuration.\n */\ninterface ServiceRegistration<T> {\n factory: ServiceFactory<T>;\n singleton: boolean;\n}\n\n/**\n * Dependency Injection Container for Yes2SDK.\n *\n * @remarks\n * This container manages service registration and resolution, supporting\n * both singleton and transient services. It enables loose coupling between\n * components and makes the SDK easily testable.\n *\n * @example\n * ```typescript\n * const container = new DIContainer();\n *\n * // Register a singleton service\n * container.register('logger', () => new Logger(), true);\n *\n * // Register a transient service\n * container.register('validator', (c) => new Validator(c.resolve('logger')));\n *\n * // Resolve a service\n * const logger = container.resolve<Logger>('logger');\n * ```\n */\nexport class DIContainer {\n private _services: Map<string, ServiceRegistration<unknown>> = new Map();\n private _singletons: Map<string, unknown> = new Map();\n\n /**\n * Register a service factory.\n * @param key - Unique identifier for the service.\n * @param factory - Factory function that creates the service.\n * @param singleton - Whether to cache the service as a singleton.\n */\n public register<T>(key: string, factory: ServiceFactory<T>, singleton: boolean = false): void {\n this._services.set(key, { factory, singleton });\n\n // Clear singleton cache if re-registering\n if (this._singletons.has(key)) {\n this._singletons.delete(key);\n }\n }\n\n /**\n * Resolve a service by key.\n * @param key - The service key to resolve.\n * @returns The resolved service instance.\n * @throws Error if the service is not registered.\n */\n public resolve<T>(key: string): T {\n const registration = this._services.get(key);\n\n if (!registration) {\n throw new Error(`Service \"${key}\" is not registered.`);\n }\n\n // Return cached singleton if available\n if (registration.singleton && this._singletons.has(key)) {\n return this._singletons.get(key) as T;\n }\n\n // Create new instance\n const instance = registration.factory(this) as T;\n\n // Cache singleton\n if (registration.singleton) {\n this._singletons.set(key, instance);\n }\n\n return instance;\n }\n\n /**\n * Check if a service is registered.\n * @param key - The service key to check.\n * @returns True if the service is registered.\n */\n public has(key: string): boolean {\n return this._services.has(key);\n }\n\n /**\n * Clear all registered services.\n */\n public clear(): void {\n this._services.clear();\n this._singletons.clear();\n }\n\n /**\n * Clear singleton cache (useful for testing).\n */\n public clearSingletons(): void {\n this._singletons.clear();\n }\n\n /**\n * Unregister a service.\n * @param key - The service key to unregister.\n */\n public unregister(key: string): void {\n this._services.delete(key);\n this._singletons.delete(key);\n }\n\n /**\n * Get all registered service keys.\n * @returns Array of registered service keys.\n */\n public getRegisteredKeys(): string[] {\n return Array.from(this._services.keys());\n }\n}\n\n/**\n * Service keys used in Yes2SDK.\n */\nexport const ServiceKey = {\n LOGGER: \"logger\",\n EVENT_EMITTER: \"eventEmitter\",\n PLATFORM: \"platform\",\n PLATFORM_SDK: \"platformSDK\",\n\n // API modules\n ADS_API: \"adsAPI\",\n PLAYER_API: \"playerAPI\",\n SESSION_API: \"sessionAPI\",\n ANALYTICS_API: \"analyticsAPI\",\n LEADERBOARD_API: \"leaderboardAPI\",\n IAP_API: \"iapAPI\",\n CONTEXT_API: \"contextAPI\",\n ACHIEVEMENTS_API: \"achievementsAPI\",\n NOTIFICATIONS_API: \"notificationsAPI\",\n TOURNAMENT_API: \"tournamentAPI\",\n STATS_API: \"statsAPI\",\n AUTH_API: \"authAPI\",\n\n // Strategies\n ADS_STRATEGY: \"adsStrategy\",\n PLAYER_STRATEGY: \"playerStrategy\",\n SESSION_STRATEGY: \"sessionStrategy\",\n ANALYTICS_STRATEGY: \"analyticsStrategy\",\n LEADERBOARD_STRATEGY: \"leaderboardStrategy\",\n IAP_STRATEGY: \"iapStrategy\",\n CONTEXT_STRATEGY: \"contextStrategy\",\n ACHIEVEMENTS_STRATEGY: \"achievementsStrategy\",\n NOTIFICATIONS_STRATEGY: \"notificationsStrategy\",\n TOURNAMENT_STRATEGY: \"tournamentStrategy\",\n STATS_STRATEGY: \"statsStrategy\",\n AUTH_STRATEGY: \"authStrategy\",\n} as const;\n","import type { ErrorMessage } from \"../types/errors\";\n\n/**\n * Log levels for the SDK logger.\n */\nexport enum LogLevel {\n DEBUG = 0,\n INFO = 1,\n WARN = 2,\n ERROR = 3,\n NONE = 4,\n}\n\n/**\n * Logger configuration.\n */\nexport interface LoggerConfig {\n /**\n * Minimum log level to output.\n * @default LogLevel.WARN\n */\n level: LogLevel;\n\n /**\n * Prefix for all log messages.\n * @default \"[Yes2SDK]\"\n */\n prefix: string;\n\n /**\n * Whether to include timestamps in log messages.\n * @default false\n */\n includeTimestamp: boolean;\n}\n\n/**\n * Logger class for Yes2SDK.\n * Provides consistent logging across the SDK with configurable log levels.\n */\nexport class Logger {\n private _config: LoggerConfig;\n\n /**\n * Create a new Logger instance.\n * @param config - Optional logger configuration.\n */\n constructor(config?: Partial<LoggerConfig>) {\n this._config = {\n level: config?.level ?? LogLevel.WARN,\n prefix: config?.prefix ?? \"[Yes2SDK]\",\n includeTimestamp: config?.includeTimestamp ?? false,\n };\n }\n\n /**\n * Set the log level.\n * @param level - The new log level.\n */\n public setLevel(level: LogLevel): void {\n this._config.level = level;\n }\n\n /**\n * Get the current log level.\n * @returns The current log level.\n */\n public getLevel(): LogLevel {\n return this._config.level;\n }\n\n /**\n * Enable debug mode (sets log level to DEBUG).\n */\n public enableDebug(): void {\n this._config.level = LogLevel.DEBUG;\n }\n\n /**\n * Log a debug message.\n * @param message - The message to log.\n * @param data - Optional additional data.\n */\n public debug(message: string, data?: unknown): void {\n if (this._config.level <= LogLevel.DEBUG) {\n this._log(\"debug\", message, data);\n }\n }\n\n /**\n * Log an info message.\n * @param message - The message to log.\n * @param data - Optional additional data.\n */\n public info(message: string, data?: unknown): void {\n if (this._config.level <= LogLevel.INFO) {\n this._log(\"info\", message, data);\n }\n }\n\n /**\n * Log a warning message.\n * @param message - The message to log.\n * @param data - Optional additional data.\n */\n public warn(message: string, data?: unknown): void {\n if (this._config.level <= LogLevel.WARN) {\n this._log(\"warn\", message, data);\n }\n }\n\n /**\n * Log an error message.\n * @param message - The message to log.\n * @param error - Optional error object.\n */\n public error(message: string, error?: unknown): void {\n if (this._config.level <= LogLevel.ERROR) {\n this._log(\"error\", message, error);\n }\n }\n\n /**\n * Log an API call.\n * @param apiName - The name of the API being called.\n */\n public apiCall(apiName: string): void {\n this.debug(`API call: ${apiName}`);\n }\n\n /**\n * Log an API error.\n * @param apiName - The name of the API that failed.\n * @param error - The error that occurred.\n */\n public apiError(apiName: string, error?: ErrorMessage): void {\n const message = error ? `API error: ${apiName} - ${error.code}: ${error.message}` : `API error: ${apiName}`;\n this.error(message, error);\n }\n\n /**\n * Log an exception with full details.\n * @param message - Description of where the exception occurred.\n * @param error - The error or ErrorMessage.\n */\n public exception(message: string, error?: unknown): void {\n this.error(message, error);\n }\n\n /**\n * Internal log method.\n * @param level - The log level.\n * @param message - The message to log.\n * @param data - Optional additional data.\n */\n private _log(level: \"debug\" | \"info\" | \"warn\" | \"error\", message: string, data?: unknown): void {\n const timestamp = this._config.includeTimestamp ? `[${new Date().toISOString()}] ` : \"\";\n const formattedMessage = `${timestamp}${this._config.prefix} ${message}`;\n\n // eslint-disable-next-line no-console\n const logFn = console[level];\n if (data !== undefined) {\n logFn(formattedMessage, data);\n } else {\n logFn(formattedMessage);\n }\n }\n}\n\n/**\n * Default logger instance.\n */\nexport const logger = new Logger();\n","/**\n * Type-safe event listener function.\n */\nexport type EventListener<T = unknown> = (data: T) => void;\n\n/**\n * Event subscription that can be unsubscribed.\n */\nexport interface EventSubscription {\n /**\n * Unsubscribe from the event.\n */\n unsubscribe: () => void;\n}\n\n/**\n * Type-safe EventEmitter for Yes2SDK.\n *\n * @remarks\n * This replaces the array-based callback pattern used in the original SDK\n * with a proper EventEmitter that prevents memory leaks and provides\n * better subscription management.\n *\n * @example\n * ```typescript\n * const emitter = new EventEmitter<{\n * 'adLoaded': { adType: string };\n * 'adError': { error: Error };\n * }>();\n *\n * const subscription = emitter.on('adLoaded', (data) => {\n * console.log('Ad loaded:', data.adType);\n * });\n *\n * emitter.emit('adLoaded', { adType: 'interstitial' });\n *\n * // Clean up\n * subscription.unsubscribe();\n * ```\n */\nexport class EventEmitter<TEvents = Record<string, unknown>> {\n private _listeners: Map<keyof TEvents, Set<EventListener<unknown>>> = new Map();\n\n /**\n * Subscribe to an event.\n * @param event - The event name to subscribe to.\n * @param listener - The listener function to call when the event is emitted.\n * @returns A subscription object that can be used to unsubscribe.\n */\n public on<K extends keyof TEvents>(event: K, listener: EventListener<TEvents[K]>): EventSubscription {\n if (!this._listeners.has(event)) {\n this._listeners.set(event, new Set());\n }\n\n const listeners = this._listeners.get(event);\n listeners?.add(listener as EventListener<unknown>);\n\n return {\n unsubscribe: () => {\n this.off(event, listener);\n },\n };\n }\n\n /**\n * Subscribe to an event only once.\n * @param event - The event name to subscribe to.\n * @param listener - The listener function to call when the event is emitted.\n * @returns A subscription object that can be used to unsubscribe.\n */\n public once<K extends keyof TEvents>(event: K, listener: EventListener<TEvents[K]>): EventSubscription {\n const onceListener: EventListener<TEvents[K]> = (data) => {\n this.off(event, onceListener);\n listener(data);\n };\n\n return this.on(event, onceListener);\n }\n\n /**\n * Unsubscribe from an event.\n * @param event - The event name to unsubscribe from.\n * @param listener - The listener function to remove.\n */\n public off<K extends keyof TEvents>(event: K, listener: EventListener<TEvents[K]>): void {\n const listeners = this._listeners.get(event);\n if (listeners) {\n listeners.delete(listener as EventListener<unknown>);\n if (listeners.size === 0) {\n this._listeners.delete(event);\n }\n }\n }\n\n /**\n * Emit an event with data.\n * @param event - The event name to emit.\n * @param data - The data to pass to listeners.\n */\n public emit<K extends keyof TEvents>(event: K, data: TEvents[K]): void {\n const listeners = this._listeners.get(event);\n if (listeners) {\n listeners.forEach((listener) => {\n try {\n listener(data);\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(`[Yes2SDK] Error in event listener for \"${String(event)}\":`, error);\n }\n });\n }\n }\n\n /**\n * Remove all listeners for an event.\n * @param event - The event name to clear. If not provided, clears all listeners.\n */\n public removeAllListeners<K extends keyof TEvents>(event?: K): void {\n if (event !== undefined) {\n this._listeners.delete(event);\n } else {\n this._listeners.clear();\n }\n }\n\n /**\n * Get the number of listeners for an event.\n * @param event - The event name to check.\n * @returns The number of listeners.\n */\n public listenerCount<K extends keyof TEvents>(event: K): number {\n return this._listeners.get(event)?.size ?? 0;\n }\n\n /**\n * Check if there are any listeners for an event.\n * @param event - The event name to check.\n * @returns True if there are listeners.\n */\n public hasListeners<K extends keyof TEvents>(event: K): boolean {\n return this.listenerCount(event) > 0;\n }\n}\n","import { type Platform, PLATFORMS } from \"../types/core/platform\";\n\n/**\n * Platform detection configuration.\n */\ninterface PlatformDetectionRule {\n platform: Platform;\n detect: () => boolean;\n}\n\n/**\n * Platform detection rules in order of priority.\n *\n * @remarks\n * The order matters - the first matching platform will be returned.\n * More specific platforms should be checked before generic ones.\n */\nconst PLATFORM_DETECTION_RULES: PlatformDetectionRule[] = [\n // Facebook Instant Games\n {\n platform: \"facebook\",\n detect: () => {\n if (typeof window === \"undefined\") {\n return false;\n }\n return (\n \"FBInstant\" in window ||\n window.location.hostname.includes(\"facebook.com\") ||\n window.location.hostname.includes(\"fb.gg\")\n );\n },\n },\n\n // Yandex Games\n {\n platform: \"yandex\",\n detect: () => {\n if (typeof window === \"undefined\") {\n return false;\n }\n return \"YaGames\" in window || window.location.hostname.includes(\"yandex.\");\n },\n },\n\n // Poki\n {\n platform: \"poki\",\n detect: () => {\n if (typeof window === \"undefined\") {\n return false;\n }\n return \"PokiSDK\" in window || window.location.hostname.includes(\"poki.com\");\n },\n },\n\n // CrazyGames\n {\n platform: \"crazygames\",\n detect: () => {\n if (typeof window === \"undefined\") {\n return false;\n }\n return \"CrazyGames\" in window || window.location.hostname.includes(\"crazygames.com\");\n },\n },\n\n // Telegram\n {\n platform: \"telegram\",\n detect: () => {\n if (typeof window === \"undefined\") {\n return false;\n }\n return \"Telegram\" in window || \"TelegramWebviewProxy\" in window;\n },\n },\n\n // GameMonetize\n {\n platform: \"gamemonetize\",\n detect: () => {\n if (typeof window === \"undefined\") {\n return false;\n }\n return window.location.hostname.includes(\"gamemonetize.\");\n },\n },\n\n // GameDistribution\n {\n platform: \"gamedistribution\",\n detect: () => {\n if (typeof window === \"undefined\") {\n return false;\n }\n return \"gdsdk\" in window || window.location.hostname.includes(\"gamedistribution.\");\n },\n },\n\n // AddictingGames\n {\n platform: \"addictinggames\",\n detect: () => {\n if (typeof window === \"undefined\") {\n return false;\n }\n return window.location.hostname.includes(\"addictinggames.\");\n },\n },\n\n // GamePix\n {\n platform: \"gamepix\",\n detect: () => {\n if (typeof window === \"undefined\") {\n return false;\n }\n return window.location.hostname.includes(\"gamepix.\");\n },\n },\n\n // GameSnacks\n {\n platform: \"gamesnacks\",\n detect: () => {\n if (typeof window === \"undefined\") {\n return false;\n }\n return window.location.hostname.includes(\"gamesnacks.\");\n },\n },\n\n // Viber\n {\n platform: \"viber\",\n detect: () => {\n if (typeof window === \"undefined\") {\n return false;\n }\n return window.location.hostname.includes(\"viber.\");\n },\n },\n\n // Debug mode (localhost)\n {\n platform: \"debug\",\n detect: () => {\n if (typeof window === \"undefined\") {\n return false;\n }\n return window.location.hostname === \"localhost\" || window.location.hostname === \"127.0.0.1\";\n },\n },\n];\n\n/**\n * Detect the current gaming platform.\n *\n * @remarks\n * This function uses a series of detection rules to determine which\n * gaming platform the SDK is currently running on. The detection is\n * based on global objects, hostnames, and other platform-specific indicators.\n *\n * @returns The detected platform, or \"debug\" if no platform is detected.\n *\n * @example\n * ```typescript\n * const platform = detectPlatform();\n * console.log(`Running on: ${platform}`);\n * ```\n */\nexport function detectPlatform(): Platform {\n for (const rule of PLATFORM_DETECTION_RULES) {\n try {\n if (rule.detect()) {\n return rule.platform;\n }\n } catch {\n // Ignore errors in detection rules and continue\n }\n }\n\n // Default to debug mode\n return \"debug\";\n}\n\n/**\n * Check if a platform is supported.\n * @param platform - The platform to check.\n * @returns True if the platform is supported.\n */\nexport function isPlatformSupported(platform: string): platform is Platform {\n return PLATFORMS.includes(platform as Platform);\n}\n\n/**\n * Get all supported platforms.\n * @returns Array of all supported platform identifiers.\n */\nexport function getSupportedPlatforms(): readonly Platform[] {\n return PLATFORMS;\n}\n","/**\n * Error codes used throughout Yes2SDK.\n */\nexport const ErrorCode = {\n // Initialization errors\n INITIALIZATION_ERROR: \"INITIALIZATION_ERROR\",\n CLIENT_UNSUPPORTED: \"CLIENT_UNSUPPORTED\",\n NOT_INITIALIZED: \"NOT_INITIALIZED\",\n\n // Parameter errors\n INVALID_PARAM: \"INVALID_PARAM\",\n INVALID_OPERATION: \"INVALID_OPERATION\",\n\n // Network errors\n NETWORK_FAILURE: \"NETWORK_FAILURE\",\n TIMEOUT: \"TIMEOUT\",\n\n // Platform errors\n PLATFORM_ERROR: \"PLATFORM_ERROR\",\n PLATFORM_NOT_SUPPORTED: \"PLATFORM_NOT_SUPPORTED\",\n FEATURE_NOT_SUPPORTED: \"FEATURE_NOT_SUPPORTED\",\n\n // Ads errors\n ADS_NOT_LOADED: \"ADS_NOT_LOADED\",\n ADS_NO_FILL: \"ADS_NO_FILL\",\n ADS_BLOCKED: \"ADS_BLOCKED\",\n ADS_FREQUENCY_LIMITED: \"ADS_FREQUENCY_LIMITED\",\n\n // Player errors\n PLAYER_NOT_AUTHENTICATED: \"PLAYER_NOT_AUTHENTICATED\",\n PLAYER_DATA_CORRUPTED: \"PLAYER_DATA_CORRUPTED\",\n\n // Storage errors\n STORAGE_ERROR: \"STORAGE_ERROR\",\n STORAGE_QUOTA_EXCEEDED: \"STORAGE_QUOTA_EXCEEDED\",\n\n // IAP errors\n IAP_NOT_AVAILABLE: \"IAP_NOT_AVAILABLE\",\n IAP_PURCHASE_FAILED: \"IAP_PURCHASE_FAILED\",\n IAP_ALREADY_PURCHASED: \"IAP_ALREADY_PURCHASED\",\n\n // Leaderboard errors\n LEADERBOARD_NOT_FOUND: \"LEADERBOARD_NOT_FOUND\",\n\n // Unknown\n UNKNOWN_ERROR: \"UNKNOWN_ERROR\",\n} as const;\n\n/**\n * Type for error codes.\n */\nexport type ErrorCodeType = (typeof ErrorCode)[keyof typeof ErrorCode];\n","import { ErrorCode, type ErrorCodeType, type ErrorMessage } from \"../types/errors\";\n\n/**\n * Documentation URLs for Yes2SDK APIs.\n */\nconst API_URL = {\n CORE: \"https://docs.yes2sdk.com/api/core\",\n ADS: \"https://docs.yes2sdk.com/api/ads\",\n PLAYER: \"https://docs.yes2sdk.com/api/player\",\n SESSION: \"https://docs.yes2sdk.com/api/session\",\n ANALYTICS: \"https://docs.yes2sdk.com/api/analytics\",\n LEADERBOARD: \"https://docs.yes2sdk.com/api/leaderboard\",\n IAP: \"https://docs.yes2sdk.com/api/iap\",\n CONTEXT: \"https://docs.yes2sdk.com/api/context\",\n ACHIEVEMENTS: \"https://docs.yes2sdk.com/api/achievements\",\n NOTIFICATIONS: \"https://docs.yes2sdk.com/api/notifications\",\n TOURNAMENT: \"https://docs.yes2sdk.com/api/tournament\",\n STATS: \"https://docs.yes2sdk.com/api/stats\",\n AUTH: \"https://docs.yes2sdk.com/api/auth\",\n} as const;\n\n/**\n * Create an ErrorMessage for invalid parameters.\n * @param message - Description of what was invalid.\n * @param context - The API context where the error occurred.\n * @param url - Optional documentation URL.\n * @returns An ErrorMessage object.\n */\nexport function invalidParams(message: string, context: string, url?: string): ErrorMessage {\n return createError(ErrorCode.INVALID_PARAM, message, context, url);\n}\n\n/**\n * Create an ErrorMessage for invalid operations.\n * @param message - Description of the invalid operation.\n * @param context - The API context where the error occurred.\n * @param url - Optional documentation URL.\n * @returns An ErrorMessage object.\n */\nexport function invalidOperation(message: string, context: string, url?: string): ErrorMessage {\n return createError(ErrorCode.INVALID_OPERATION, message, context, url);\n}\n\n/**\n * Create an ErrorMessage for uninitialized SDK.\n * @param context - The API context where the error occurred.\n * @returns An ErrorMessage object.\n */\nexport function notInitialized(context: string): ErrorMessage {\n return createError(\n ErrorCode.NOT_INITIALIZED,\n \"Yes2SDK has not been initialized. Call Yes2SDK.initializeAsync() first.\",\n context,\n API_URL.CORE\n );\n}\n\n/**\n * Create an ErrorMessage for unsupported features.\n * @param feature - The feature that is not supported.\n * @param context - The API context where the error occurred.\n * @returns An ErrorMessage object.\n */\nexport function featureNotSupported(feature: string, context: string): ErrorMessage {\n return createError(\n ErrorCode.FEATURE_NOT_SUPPORTED,\n `${feature} is not supported on the current platform.`,\n context\n );\n}\n\n/**\n * Create an ErrorMessage for platform-specific errors.\n * @param message - Description of the platform error.\n * @param context - The API context where the error occurred.\n * @param originalError - The original error from the platform SDK.\n * @returns An ErrorMessage object.\n */\nexport function platformError(message: string, context: string, originalError?: unknown): ErrorMessage {\n return {\n code: ErrorCode.PLATFORM_ERROR,\n message,\n context,\n originalError,\n };\n}\n\n/**\n * Create an ErrorMessage for network failures.\n * @param message - Description of the network error.\n * @param context - The API context where the error occurred.\n * @param originalError - The original error.\n * @returns An ErrorMessage object.\n */\nexport function networkError(message: string, context: string, originalError?: unknown): ErrorMessage {\n return {\n code: ErrorCode.NETWORK_FAILURE,\n message,\n context,\n originalError,\n };\n}\n\n/**\n * Create a generic ErrorMessage.\n * @param code - The error code.\n * @param message - Human-readable error message.\n * @param context - The API context where the error occurred.\n * @param url - Optional documentation URL.\n * @param originalError - Optional original error.\n * @returns An ErrorMessage object.\n */\nexport function createError(\n code: ErrorCodeType,\n message: string,\n context: string,\n url?: string,\n originalError?: unknown\n): ErrorMessage {\n return {\n code,\n message,\n context,\n url,\n originalError,\n };\n}\n\n/**\n * Map a platform SDK error to a Yes2SDK ErrorMessage.\n * @param error - The original error from the platform SDK.\n * @param context - The API context where the error occurred.\n * @returns An ErrorMessage object.\n */\nexport function mapPlatformError(error: unknown, context: string): ErrorMessage {\n if (error instanceof Error) {\n return platformError(error.message, context, error);\n }\n\n if (typeof error === \"string\") {\n return platformError(error, context);\n }\n\n return platformError(\"An unknown error occurred\", context, error);\n}\n\nexport { API_URL };\n","/**\n * Validation utilities for Yes2SDK.\n *\n * @remarks\n * These validators consolidate common validation patterns used throughout\n * the SDK, replacing the duplicated validation logic in the original codebase.\n */\n\n/**\n * Check if a value is a non-empty string.\n * @param value - The value to check.\n * @returns True if the value is a non-empty string.\n */\nexport function isValidString(value: unknown): value is string {\n return typeof value === \"string\" && value.trim().length > 0;\n}\n\n/**\n * Check if a value is a valid number (not NaN).\n * @param value - The value to check.\n * @returns True if the value is a valid number.\n */\nexport function isValidNumber(value: unknown): value is number {\n return typeof value === \"number\" && !isNaN(value);\n}\n\n/**\n * Check if a value is a valid integer.\n * @param value - The value to check.\n * @returns True if the value is a valid integer.\n */\nexport function isValidInteger(value: unknown): value is number {\n return isValidNumber(value) && Number.isInteger(value);\n}\n\n/**\n * Check if a value is a positive number.\n * @param value - The value to check.\n * @returns True if the value is a positive number.\n */\nexport function isPositiveNumber(value: unknown): value is number {\n return isValidNumber(value) && value > 0;\n}\n\n/**\n * Check if a value is a non-negative number.\n * @param value - The value to check.\n * @returns True if the value is a non-negative number.\n */\nexport function isNonNegativeNumber(value: unknown): value is number {\n return isValidNumber(value) && value >= 0;\n}\n\n/**\n * Check if a value is within a range (inclusive).\n * @param value - The value to check.\n * @param min - The minimum value.\n * @param max - The maximum value.\n * @returns True if the value is within the range.\n */\nexport function isInRange(value: unknown, min: number, max: number): value is number {\n return isValidNumber(value) && value >= min && value <= max;\n}\n\n/**\n * Check if a value is a valid function.\n * @param value - The value to check.\n * @returns True if the value is a function.\n */\nexport function isValidFunction(value: unknown): value is (...args: unknown[]) => unknown {\n return typeof value === \"function\";\n}\n\n/**\n * Check if a value is a valid object (not null, not array).\n * @param value - The value to check.\n * @returns True if the value is a valid object.\n */\nexport function isValidObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Check if a value is a valid array.\n * @param value - The value to check.\n * @returns True if the value is a valid array.\n */\nexport function isValidArray(value: unknown): value is unknown[] {\n return Array.isArray(value);\n}\n\n/**\n * Check if a value is a non-empty array.\n * @param value - The value to check.\n * @returns True if the value is a non-empty array.\n */\nexport function isNonEmptyArray(value: unknown): value is unknown[] {\n return isValidArray(value) && value.length > 0;\n}\n\n/**\n * Check if a value is a valid URL string.\n * @param value - The value to check.\n * @returns True if the value is a valid URL.\n */\nexport function isValidUrl(value: unknown): value is string {\n if (!isValidString(value)) {\n return false;\n }\n\n try {\n new URL(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Check if a value is null or undefined.\n * @param value - The value to check.\n * @returns True if the value is null or undefined.\n */\nexport function isNullOrUndefined(value: unknown): value is null | undefined {\n return value === null || value === undefined;\n}\n\n/**\n * Check if a value is defined (not null and not undefined).\n * @param value - The value to check.\n * @returns True if the value is defined.\n */\nexport function isDefined<T>(value: T | null | undefined): value is T {\n return value !== null && value !== undefined;\n}\n\n/**\n * Ensure a value is defined, throwing an error if not.\n * @param value - The value to check.\n * @param name - The name of the value (for error message).\n * @returns The value if defined.\n * @throws Error if the value is null or undefined.\n */\nexport function ensureDefined<T>(value: T | null | undefined, name: string): T {\n if (!isDefined(value)) {\n throw new Error(`${name} is required but was not provided.`);\n }\n return value;\n}\n","/**\n * Yes2SDK - Multi-platform game integration SDK for HTML5 games.\n *\n * @remarks\n * Yes2SDK provides a unified API for integrating HTML5 games with 20+\n * gaming platforms including Facebook, Yandex, Poki, CrazyGames, and more.\n *\n * @example\n * ```typescript\n * import Yes2SDK from '@yes2sdk/core';\n *\n * // Initialize SDK\n * await Yes2SDK.initializeAsync();\n *\n * // Set loading progress\n * Yes2SDK.setLoadingProgress(100);\n *\n * // Start game\n * await Yes2SDK.startGameAsync();\n *\n * // Show an ad\n * Yes2SDK.ads.showInterstitial('next', 'LevelComplete', pauseGame, resumeGame);\n * ```\n *\n * @packageDocumentation\n */\n\nimport { CoreAPI } from \"./core/core-api\";\n\n// Export types\nexport * from \"./types\";\n\n// Export utilities\nexport * from \"./utils\";\n\n// Export error handling\nexport * from \"./errors\";\n\n// Export core\nexport * from \"./core\";\n\n/**\n * The global Yes2SDK instance.\n *\n * @remarks\n * This is the main entry point for the SDK. All SDK functionality\n * is accessed through this singleton instance.\n */\nconst Yes2SDK = new CoreAPI();\n\nexport default Yes2SDK;\n\n// Also export as named export for flexibility\nexport { Yes2SDK };\n","import type { Platform, InitializationOptions, InitializationState } from \"../types/core\";\nimport { DIContainer, ServiceKey } from \"./di-container\";\nimport { Logger, LogLevel } from \"../utils/logger\";\nimport { EventEmitter } from \"../utils/event-emitter\";\nimport { detectPlatform } from \"../utils/platform-detector\";\nimport { notInitialized, invalidParams } from \"../errors/error-handler\";\nimport { isInRange } from \"../utils/validators\";\n\n/**\n * SDK events that can be subscribed to.\n */\nexport interface SDKEvents {\n initialized: { platform: Platform };\n gameStarted: void;\n error: { context: string; error: unknown };\n loadingProgress: { progress: number };\n}\n\n/**\n * CoreAPI - The main entry point for Yes2SDK.\n *\n * @remarks\n * This class serves as the facade for the entire SDK. All initialization\n * must go through this class, and all other modules are accessed through it.\n *\n * @example\n * ```typescript\n * import Yes2SDK from '@yes2sdk/core';\n *\n * // Initialize SDK\n * await Yes2SDK.initializeAsync();\n *\n * // Update loading progress\n * Yes2SDK.setLoadingProgress(50);\n *\n * // Start game\n * await Yes2SDK.startGameAsync();\n *\n * // Use other modules\n * Yes2SDK.ads.showInterstitial('next', 'LevelComplete', pauseGame, resumeGame);\n * ```\n */\nexport class CoreAPI {\n private _container: DIContainer;\n private _logger: Logger;\n private _events: EventEmitter<SDKEvents>;\n private _state: InitializationState;\n private _platform: Platform | null = null;\n\n /**\n * Create a new CoreAPI instance.\n */\n constructor() {\n this._container = new DIContainer();\n this._logger = new Logger();\n this._events = new EventEmitter<SDKEvents>();\n this._state = {\n isInitialized: false,\n isGameStarted: false,\n loadingProgress: 0,\n };\n\n this._registerCoreServices();\n }\n\n //#region Public Properties\n\n /**\n * Whether the SDK has been initialized.\n */\n public get isInitialized(): boolean {\n return this._state.isInitialized;\n }\n\n //#endregion\n //#region Public API\n\n /**\n * Initialize the SDK.\n *\n * @remarks\n * This must be called before any other SDK functions. It detects the\n * current platform, loads platform-specific code, and initializes\n * the platform SDK.\n *\n * @param options - Optional initialization configuration.\n * @returns Promise that resolves when initialization completes.\n */\n public async initializeAsync(options?: InitializationOptions): Promise<void> {\n if (this._state.isInitialized) {\n this._logger.warn(\"Yes2SDK is already initialized.\");\n return;\n }\n\n this._logger.apiCall(\"initializeAsync\");\n\n try {\n // Enable debug mode if requested\n if (options?.debug === true) {\n this._logger.setLevel(LogLevel.DEBUG);\n }\n\n // Detect platform\n this._platform = detectPlatform();\n this._logger.info(`Platform detected: ${this._platform}`);\n\n // Register platform in container\n this._container.register(ServiceKey.PLATFORM, () => this._platform, true);\n\n // TODO: Load platform SDK and initialize strategies\n // This will be implemented when platform-specific code is added\n\n this._state.isInitialized = true;\n this._events.emit(\"initialized\", { platform: this._platform });\n\n this._logger.info(\"Yes2SDK initialized successfully.\");\n } catch (error) {\n this._state.initializationError = error instanceof Error ? error : new Error(String(error));\n this._logger.error(\"Initialization failed\", error);\n this._events.emit(\"error\", { context: \"initializeAsync\", error });\n throw error;\n }\n }\n\n /**\n * Start the game after loading is complete.\n *\n * @remarks\n * This signals to the platform that the game is ready to be displayed.\n * Should be called after all game assets are loaded.\n *\n * @returns Promise that resolves when the game starts.\n */\n public async startGameAsync(): Promise<void> {\n this._logger.apiCall(\"startGameAsync\");\n\n if (!this._state.isInitialized) {\n const error = notInitialized(\"startGameAsync\");\n this._logger.apiError(\"startGameAsync\", error);\n throw error;\n }\n\n if (this._state.isGameStarted) {\n this._logger.warn(\"Game has already started.\");\n return;\n }\n\n try {\n // TODO: Call platform-specific startGame method\n\n this._state.isGameStarted = true;\n this._events.emit(\"gameStarted\", undefined);\n\n this._logger.info(\"Game started successfully.\");\n } catch (error) {\n this._logger.error(\"Failed to start game\", error);\n this._events.emit(\"error\", { context: \"startGameAsync\", error });\n throw error;\n }\n }\n\n /**\n * Set the loading progress for the game.\n *\n * @param progress - Loading progress between 0 and 100.\n */\n public setLoadingProgress(progress: number): void {\n this._logger.apiCall(\"setLoadingProgress\");\n\n if (!isInRange(progress, 0, 100)) {\n const error = invalidParams(\n `Progress must be between 0 and 100, received: ${String(progress)}`,\n \"setLoadingProgress\"\n );\n this._logger.apiError(\"setLoadingProgress\", error);\n throw error;\n }\n\n this._state.loadingProgress = progress;\n this._events.emit(\"loadingProgress\", { progress });\n\n // TODO: Call platform-specific setLoadingProgress method\n }\n\n /**\n * Perform haptic feedback if supported.\n */\n public performHapticFeedback(): void {\n this._logger.apiCall(\"performHapticFeedback\");\n\n if (!this._state.isInitialized) {\n this._logger.warn(\"performHapticFeedback called before initialization.\");\n return;\n }\n\n // TODO: Call platform-specific haptic feedback method\n }\n\n /**\n * Get the current platform.\n * @returns The detected platform, or null if not initialized.\n */\n public getPlatform(): Platform | null {\n return this._platform;\n }\n\n /**\n * Subscribe to SDK events.\n * @param event - The event to subscribe to.\n * @param listener - The listener function.\n * @returns A subscription that can be unsubscribed.\n */\n public on<K extends keyof SDKEvents>(event: K, listener: (data: SDKEvents[K]) => void): { unsubscribe: () => void } {\n return this._events.on(event, listener);\n }\n\n /**\n * Get the logger instance.\n * @returns The logger instance.\n * @internal\n */\n public get _log(): Logger {\n return this._logger;\n }\n\n /**\n * Get the DI container.\n * @returns The DI container.\n * @internal\n */\n public get _internalContainer(): DIContainer {\n return this._container;\n }\n\n /**\n * Get the internal platform.\n * @returns The platform identifier.\n * @internal\n */\n public get _internalPlatform(): Platform | null {\n return this._platform;\n }\n\n //#endregion\n //#region Private Methods\n\n /**\n * Register core services in the DI container.\n */\n private _registerCoreServices(): void {\n this._container.register(ServiceKey.LOGGER, () => this._logger, true);\n this._container.register(ServiceKey.EVENT_EMITTER, () => this._events, true);\n }\n\n //#endregion\n}\n"],"names":["root","factory","exports","module","define","amd","Object","self","this","__webpack_require__","definition","key","o","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","DIContainer","_services","Map","_singletons","register","singleton","set","has","delete","resolve","registration","Error","instance","clear","clearSingletons","unregister","getRegisteredKeys","Array","from","keys","ServiceKey","LogLevel","Logger","constructor","config","_config","level","WARN","prefix","includeTimestamp","setLevel","getLevel","enableDebug","DEBUG","debug","message","data","_log","info","INFO","warn","error","ERROR","apiCall","apiName","apiError","code","exception","formattedMessage","Date","toISOString","logFn","console","undefined","EventEmitter","_listeners","on","event","listener","Set","listeners","add","unsubscribe","off","once","onceListener","size","emit","forEach","removeAllListeners","listenerCount","hasListeners","PLATFORM_DETECTION_RULES","platform","detect","window","location","hostname","includes","ErrorCode","API_URL","createError","context","url","originalError","isValidNumber","value","isNaN","_platform","_container","_logger","_events","_state","isInitialized","isGameStarted","loadingProgress","_registerCoreServices","initializeAsync","options","rule","detectPlatform","initializationError","String","startGameAsync","setLoadingProgress","progress","min","max","performHapticFeedback","getPlatform","_internalContainer","_internalPlatform"],"sourceRoot":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yes2sdk/core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Multi-platform game integration SDK for HTML5 games. Unified API for 20+ gaming platforms.",
|
|
5
|
+
"main": "dist/yes2sdk.umd.js",
|
|
6
|
+
"module": "dist/yes2sdk.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "webpack --mode production",
|
|
13
|
+
"build:dev": "webpack --mode development",
|
|
14
|
+
"dev": "webpack --mode development --watch",
|
|
15
|
+
"test": "jest",
|
|
16
|
+
"test:watch": "jest --watch",
|
|
17
|
+
"test:coverage": "jest --coverage",
|
|
18
|
+
"lint": "eslint src --ext .ts",
|
|
19
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
20
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
21
|
+
"format:check": "prettier --check \"src/**/*.ts\"",
|
|
22
|
+
"type-check": "tsc --noEmit",
|
|
23
|
+
"clean": "rm -rf dist coverage",
|
|
24
|
+
"prepublishOnly": "npm run clean && npm run lint && npm run test && npm run build"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/swaraadam/yes2sdk-core.git"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"sdk",
|
|
32
|
+
"game",
|
|
33
|
+
"html5",
|
|
34
|
+
"facebook",
|
|
35
|
+
"yandex",
|
|
36
|
+
"poki",
|
|
37
|
+
"crazygames",
|
|
38
|
+
"telegram",
|
|
39
|
+
"ads",
|
|
40
|
+
"leaderboard",
|
|
41
|
+
"iap",
|
|
42
|
+
"analytics"
|
|
43
|
+
],
|
|
44
|
+
"author": "Swara Adam <bimaswaraadam@gmail.com>",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/swaraadam/yes2sdk-core/issues"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://github.com/swaraadam/yes2sdk-core#readme",
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/jest": "^29.5.12",
|
|
52
|
+
"@types/node": "^20.11.0",
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
54
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
55
|
+
"eslint": "^8.57.0",
|
|
56
|
+
"eslint-config-prettier": "^9.1.0",
|
|
57
|
+
"eslint-plugin-jsdoc": "^48.0.0",
|
|
58
|
+
"jest": "^29.7.0",
|
|
59
|
+
"jest-environment-jsdom": "^30.2.0",
|
|
60
|
+
"prettier": "^3.2.0",
|
|
61
|
+
"terser-webpack-plugin": "^5.3.10",
|
|
62
|
+
"ts-jest": "^29.1.2",
|
|
63
|
+
"ts-loader": "^9.5.1",
|
|
64
|
+
"typescript": "^5.4.5",
|
|
65
|
+
"webpack": "^5.91.0",
|
|
66
|
+
"webpack-cli": "^5.1.4"
|
|
67
|
+
},
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"zod": "^3.22.4"
|
|
70
|
+
},
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=18.0.0"
|
|
73
|
+
}
|
|
74
|
+
}
|