@mpgd/platform 0.3.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
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';
2
+ export type StarterLogicalProductId = 'COINS_100' | 'COINS_500' | 'REMOVE_ADS';
3
+ export type LogicalProductId = StarterLogicalProductId | (string & Record<never, never>);
4
+ export type StarterLogicalAdPlacementId = 'CONTINUE_AFTER_FAIL' | 'STAGE_END_INTERSTITIAL';
5
+ export type LogicalAdPlacementId = StarterLogicalAdPlacementId | (string & Record<never, never>);
4
6
  export type ProductType = 'consumable' | 'non_consumable' | 'subscription';
5
7
  export interface ProductInfo {
6
8
  readonly id: LogicalProductId;
@@ -89,8 +91,79 @@ export interface PlayerIdentity {
89
91
  readonly displayName?: string;
90
92
  readonly avatarUrl?: string;
91
93
  }
94
+ export type IdentityLevel = 'guest' | 'platform-anonymous' | 'authenticated';
95
+ export type IdentityTrustLevel = 'local' | 'platform-asserted' | 'server-verified';
96
+ export interface IdentitySession {
97
+ readonly identityLevel: IdentityLevel;
98
+ readonly playerId?: string;
99
+ readonly trustLevel: IdentityTrustLevel;
100
+ }
101
+ export type IdentityUpgradeReason = 'save' | 'leaderboard' | 'share' | 'notifications';
102
+ export interface IdentityUpgradeResult {
103
+ readonly status: 'completed' | 'cancelled' | 'unavailable';
104
+ readonly reloadExpected: boolean;
105
+ }
92
106
  export interface IdentityAdapter {
93
107
  getPlayer(): Promise<PlayerIdentity | null>;
108
+ getSession?(): Promise<IdentitySession>;
109
+ requestUpgrade?(input: {
110
+ readonly reason: IdentityUpgradeReason;
111
+ }): Promise<IdentityUpgradeResult>;
112
+ }
113
+ export type LaunchEntry = 'home' | 'daily' | 'practice' | 'free-play' | 'continue' | 'leaderboard' | 'friend-challenge';
114
+ export interface LaunchIntent {
115
+ readonly entry: LaunchEntry;
116
+ readonly puzzleId?: string;
117
+ readonly referralToken?: string;
118
+ }
119
+ export type PresentationResult = 'opened' | 'already-fullscreen' | 'unavailable';
120
+ export interface PresentationAdapter {
121
+ getLaunchIntent(): Promise<LaunchIntent>;
122
+ requestGameSurface(intent: LaunchIntent): Promise<PresentationResult>;
123
+ }
124
+ export interface SharePayload {
125
+ readonly puzzleId?: string;
126
+ readonly challengeToken?: string;
127
+ }
128
+ export interface ShareIntent {
129
+ readonly kind: 'daily-result' | 'friend-challenge' | 'invite';
130
+ readonly title: string;
131
+ readonly text: string;
132
+ readonly deepLink: string;
133
+ readonly payload?: SharePayload;
134
+ readonly previewImageUrl?: string;
135
+ }
136
+ /**
137
+ * Evidence available after a platform reports a successful share operation.
138
+ * `presented` means the platform share surface opened, not that the user
139
+ * finished sharing. `completed` means the adapter observed completion.
140
+ */
141
+ export type ShareCompletion = 'presented' | 'completed';
142
+ export interface ShareResult {
143
+ readonly status: 'shared' | 'cancelled' | 'unavailable';
144
+ /**
145
+ * Optional for backward compatibility. A legacy `shared` result without this
146
+ * field normalizes to `completed`; new adapters should set it explicitly when
147
+ * they can only prove that a share surface was presented.
148
+ */
149
+ readonly completion?: ShareCompletion;
150
+ }
151
+ export declare function resolveShareCompletion(result: ShareResult): ShareCompletion | undefined;
152
+ export declare function isShareCompleted(result: ShareResult): boolean;
153
+ export interface InboundShare {
154
+ readonly puzzleId?: string;
155
+ readonly challengeToken?: string;
156
+ }
157
+ export interface ShareAdapter {
158
+ share?(intent: ShareIntent): Promise<ShareResult>;
159
+ readInboundShare?(): Promise<InboundShare | null>;
160
+ }
161
+ export type NotificationTopic = 'daily-ready' | 'streak-at-risk' | 'friend-challenge';
162
+ export type NotificationSubscriptionStatus = 'subscribed' | 'not-subscribed' | 'approval-required' | 'configuration-required' | 'unsupported';
163
+ export type NotificationSubscriptionResult = 'subscribed' | 'rejected' | 'unavailable';
164
+ export interface NotificationSubscriptionAdapter {
165
+ getStatus(topic: NotificationTopic): Promise<NotificationSubscriptionStatus>;
166
+ requestSubscription(topic: NotificationTopic): Promise<NotificationSubscriptionResult>;
94
167
  }
95
168
  export interface LifecycleAdapter {
96
169
  onPause(callback: () => void): () => void;
@@ -117,5 +190,8 @@ export interface PlatformGateway {
117
190
  readonly leaderboard: LeaderboardAdapter;
118
191
  readonly lifecycle: LifecycleAdapter;
119
192
  readonly storage: StorageAdapter;
193
+ readonly presentation?: PresentationAdapter;
194
+ readonly sharing?: ShareAdapter;
195
+ readonly notifications?: NotificationSubscriptionAdapter;
120
196
  }
121
197
  export declare function createUnsupportedCapabilities(): PlatformCapabilities;
package/dist/index.js CHANGED
@@ -1,3 +1,12 @@
1
+ export function resolveShareCompletion(result) {
2
+ if (result.status !== 'shared') {
3
+ return undefined;
4
+ }
5
+ return result.completion ?? 'completed';
6
+ }
7
+ export function isShareCompleted(result) {
8
+ return resolveShareCompletion(result) === 'completed';
9
+ }
1
10
  export function createUnsupportedCapabilities() {
2
11
  return {
3
12
  nativeIap: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpgd/platform",
3
- "version": "0.3.2",
3
+ "version": "0.5.0",
4
4
  "description": "Shared platform gateway, monetization, ads, leaderboard, identity, lifecycle, and storage contracts for mpgd games.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -35,7 +35,8 @@
35
35
  ],
36
36
  "devDependencies": {
37
37
  "ttsc": "0.16.9",
38
- "typescript": "7.0.1-rc"
38
+ "typescript": "7.0.1-rc",
39
+ "vitest": "^4.0.0"
39
40
  },
40
41
  "main": "./dist/index.js",
41
42
  "types": "./dist/index.d.ts",
@@ -46,6 +47,7 @@
46
47
  "check": "ttsc --noEmit",
47
48
  "lint": "ttsc --noEmit",
48
49
  "format": "ttsc format",
49
- "fix": "ttsc fix"
50
+ "fix": "ttsc fix",
51
+ "test": "vitest run"
50
52
  }
51
53
  }