@mpgd/platform 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 imjlk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,121 @@
1
+ export type PlatformTarget = 'browser' | 'android' | 'ios' | 'ait' | 'reddit' | 'telegram' | 'tauri';
2
+ export type LogicalProductId = 'COINS_100' | 'COINS_500' | 'REMOVE_ADS';
3
+ export type LogicalAdPlacementId = 'CONTINUE_AFTER_FAIL' | 'STAGE_END_INTERSTITIAL';
4
+ export type ProductType = 'consumable' | 'non_consumable' | 'subscription';
5
+ export interface ProductInfo {
6
+ readonly id: LogicalProductId;
7
+ readonly type: ProductType;
8
+ readonly title: string;
9
+ readonly description: string;
10
+ readonly price: {
11
+ readonly formatted: string;
12
+ readonly currencyCode: string;
13
+ };
14
+ }
15
+ export interface Entitlement {
16
+ readonly id: string;
17
+ readonly source: 'purchase' | 'promotion' | 'admin';
18
+ readonly grantedAt: string;
19
+ readonly expiresAt?: string;
20
+ }
21
+ export interface PurchaseResult {
22
+ readonly status: 'completed' | 'cancelled' | 'pending' | 'failed';
23
+ readonly transactionId?: string;
24
+ readonly entitlementIds: readonly string[];
25
+ }
26
+ export interface PurchaseRestoreResult {
27
+ readonly restoredEntitlements: readonly Entitlement[];
28
+ }
29
+ export interface RewardedAdResult {
30
+ readonly status: 'completed' | 'skipped' | 'unavailable' | 'failed';
31
+ readonly rewardGranted: boolean;
32
+ readonly ledgerEntryId?: string;
33
+ }
34
+ export interface InterstitialAdResult {
35
+ readonly status: 'shown' | 'skipped' | 'unavailable';
36
+ }
37
+ export interface CommerceAdapter {
38
+ getProducts(): Promise<readonly ProductInfo[]>;
39
+ purchase(input: {
40
+ readonly productId: LogicalProductId;
41
+ readonly source: 'shop' | 'stage_fail' | 'result' | 'event';
42
+ readonly idempotencyKey: string;
43
+ }): Promise<PurchaseResult>;
44
+ restore?(): Promise<PurchaseRestoreResult>;
45
+ getEntitlements(): Promise<readonly Entitlement[]>;
46
+ }
47
+ export interface AdAdapter {
48
+ preload(input: {
49
+ readonly placementId: LogicalAdPlacementId;
50
+ }): Promise<void>;
51
+ showRewarded(input: {
52
+ readonly placementId: LogicalAdPlacementId;
53
+ readonly idempotencyKey: string;
54
+ }): Promise<RewardedAdResult>;
55
+ showInterstitial?(input: {
56
+ readonly placementId: LogicalAdPlacementId;
57
+ }): Promise<InterstitialAdResult>;
58
+ }
59
+ export interface LeaderboardScoreInput {
60
+ readonly leaderboardId: string;
61
+ readonly score: number;
62
+ readonly runId: string;
63
+ readonly submittedAt: string;
64
+ }
65
+ export interface LeaderboardSubmitResult {
66
+ readonly submitted: boolean;
67
+ readonly rank?: number;
68
+ }
69
+ export interface LeaderboardAdapter {
70
+ submitScore(input: LeaderboardScoreInput): Promise<LeaderboardSubmitResult>;
71
+ open(input?: {
72
+ readonly leaderboardId?: string;
73
+ }): Promise<void>;
74
+ }
75
+ export interface PlatformCapabilities {
76
+ readonly nativeIap: boolean;
77
+ readonly nativeAds: boolean;
78
+ readonly rewardedAds: boolean;
79
+ readonly interstitialAds: boolean;
80
+ readonly nativeLeaderboard: boolean;
81
+ readonly achievements: boolean;
82
+ readonly cloudSave: boolean;
83
+ readonly socialShare: boolean;
84
+ readonly haptics: boolean;
85
+ readonly localizedContent: boolean;
86
+ }
87
+ export interface PlayerIdentity {
88
+ readonly playerId: string;
89
+ readonly displayName?: string;
90
+ readonly avatarUrl?: string;
91
+ }
92
+ export interface IdentityAdapter {
93
+ getPlayer(): Promise<PlayerIdentity | null>;
94
+ }
95
+ export interface LifecycleAdapter {
96
+ onPause(callback: () => void): () => void;
97
+ onResume(callback: () => void): () => void;
98
+ }
99
+ export interface StorageLoadResult {
100
+ readonly value: unknown;
101
+ }
102
+ export interface StorageAdapter {
103
+ load(input: {
104
+ readonly key: string;
105
+ }): Promise<StorageLoadResult | null>;
106
+ save(input: {
107
+ readonly key: string;
108
+ readonly value: unknown;
109
+ }): Promise<void>;
110
+ }
111
+ export interface PlatformGateway {
112
+ readonly target: PlatformTarget;
113
+ getCapabilities(): Promise<PlatformCapabilities>;
114
+ readonly identity: IdentityAdapter;
115
+ readonly commerce: CommerceAdapter;
116
+ readonly ads: AdAdapter;
117
+ readonly leaderboard: LeaderboardAdapter;
118
+ readonly lifecycle: LifecycleAdapter;
119
+ readonly storage: StorageAdapter;
120
+ }
121
+ export declare function createUnsupportedCapabilities(): PlatformCapabilities;
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ export function createUnsupportedCapabilities() {
2
+ return {
3
+ nativeIap: false,
4
+ nativeAds: false,
5
+ rewardedAds: false,
6
+ interstitialAds: false,
7
+ nativeLeaderboard: false,
8
+ achievements: false,
9
+ cloudSave: false,
10
+ socialShare: false,
11
+ haptics: false,
12
+ localizedContent: false,
13
+ };
14
+ }
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@mpgd/platform",
3
+ "version": "0.1.0",
4
+ "description": "Shared platform gateway, monetization, ads, leaderboard, identity, lifecycle, and storage contracts for mpgd games.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/imjlk/mpgd-kit.git",
9
+ "directory": "packages/platform"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/imjlk/mpgd-kit/issues"
13
+ },
14
+ "homepage": "https://github.com/imjlk/mpgd-kit#readme",
15
+ "keywords": [
16
+ "mpgd",
17
+ "phaser",
18
+ "vite",
19
+ "typescript",
20
+ "capacitor",
21
+ "apps-in-toss",
22
+ "game-development",
23
+ "game-distribution"
24
+ ],
25
+ "type": "module",
26
+ "sideEffects": false,
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.js"
31
+ }
32
+ },
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "devDependencies": {
37
+ "ttsc": "0.16.9",
38
+ "typescript": "7.0.1-rc"
39
+ },
40
+ "main": "./dist/index.js",
41
+ "types": "./dist/index.d.ts",
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "scripts": {
46
+ "check": "ttsc --noEmit",
47
+ "lint": "ttsc --noEmit",
48
+ "format": "ttsc format",
49
+ "fix": "ttsc fix"
50
+ }
51
+ }