@mission_sciences/provider-sdk 0.2.0-dev.dfda459 → 0.3.0-dev.31ea3d4
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/adapters/vue/useMarketplaceSession.d.ts +2 -0
- package/dist/adapters/vue/useMarketplaceSession.d.ts.map +1 -1
- package/dist/core/MarketplaceSDK.d.ts +6 -0
- package/dist/core/MarketplaceSDK.d.ts.map +1 -1
- package/dist/core/PurchaseStateManager.d.ts +28 -0
- package/dist/core/PurchaseStateManager.d.ts.map +1 -0
- package/dist/marketplace-sdk.es.js +64 -0
- package/dist/marketplace-sdk.es.js.map +1 -1
- package/dist/marketplace-sdk.umd.js +1 -1
- package/dist/marketplace-sdk.umd.js.map +1 -1
- package/dist/types/index.d.ts +32 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -22,6 +22,7 @@ export declare function useMarketplaceSession(options?: UseMarketplaceSessionOpt
|
|
|
22
22
|
getFormattedTime: () => string;
|
|
23
23
|
getFormattedTimeWithHours: () => string;
|
|
24
24
|
isTimerRunning: () => boolean;
|
|
25
|
+
getPurchaseStateManager: () => import('../../core/PurchaseStateManager').PurchaseStateManager;
|
|
25
26
|
destroy: () => void;
|
|
26
27
|
} | null, MarketplaceSDK | {
|
|
27
28
|
on: <K extends keyof import('../../types').SDKEvents>(event: K, handler: import('../../types').SDKEvents[K]) => void;
|
|
@@ -37,6 +38,7 @@ export declare function useMarketplaceSession(options?: UseMarketplaceSessionOpt
|
|
|
37
38
|
getFormattedTime: () => string;
|
|
38
39
|
getFormattedTimeWithHours: () => string;
|
|
39
40
|
isTimerRunning: () => boolean;
|
|
41
|
+
getPurchaseStateManager: () => import('../../core/PurchaseStateManager').PurchaseStateManager;
|
|
40
42
|
destroy: () => void;
|
|
41
43
|
} | null>;
|
|
42
44
|
session: import('vue').Ref<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMarketplaceSession.d.ts","sourceRoot":"","sources":["../../../src/adapters/vue/useMarketplaceSession.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAElG,MAAM,WAAW,4BAA6B,SAAQ,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5E,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxE,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,KAAK,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;CAC5B;AAED,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,4BAAiE
|
|
1
|
+
{"version":3,"file":"useMarketplaceSession.d.ts","sourceRoot":"","sources":["../../../src/adapters/vue/useMarketplaceSession.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAElG,MAAM,WAAW,4BAA6B,SAAQ,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5E,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxE,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,KAAK,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;CAC5B;AAED,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,4BAAiE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4F/G"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PurchaseStateManager } from './PurchaseStateManager';
|
|
1
2
|
import { SDKConfig, SDKEvents, SessionData } from '../types';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -20,6 +21,7 @@ export declare class MarketplaceSDK {
|
|
|
20
21
|
private sessionData;
|
|
21
22
|
private jwtToken;
|
|
22
23
|
private endReason;
|
|
24
|
+
private purchaseStateManager;
|
|
23
25
|
constructor(config: SDKConfig);
|
|
24
26
|
/**
|
|
25
27
|
* Register event handlers
|
|
@@ -97,6 +99,10 @@ export declare class MarketplaceSDK {
|
|
|
97
99
|
* Check if timer is running
|
|
98
100
|
*/
|
|
99
101
|
isTimerRunning(): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Get purchase state manager for item purchase state checking
|
|
104
|
+
*/
|
|
105
|
+
getPurchaseStateManager(): PurchaseStateManager;
|
|
100
106
|
/**
|
|
101
107
|
* Cleanup and destroy SDK instance
|
|
102
108
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarketplaceSDK.d.ts","sourceRoot":"","sources":["../../src/core/MarketplaceSDK.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MarketplaceSDK.d.ts","sourceRoot":"","sources":["../../src/core/MarketplaceSDK.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAI9D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAiG,MAAM,UAAU,CAAC;AAE5J;;;;;;;GAOG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAsB;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H,gBAAgB,IAAI,MAAM;IAI1B;;OAEG;IACH,yBAAyB,IAAI,MAAM;IAInC;;OAEG;IACH,cAAc,IAAI,OAAO;IAIzB;;OAEG;IACH,uBAAuB,IAAI,oBAAoB;IAI/C;;OAEG;IACH,OAAO,IAAI,IAAI;CAgBhB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PurchaseStateResponse } from '../types/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for PurchaseStateManager
|
|
5
|
+
*/
|
|
6
|
+
export interface PurchaseStateManagerConfig {
|
|
7
|
+
apiEndpoint: string;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Manages purchase state logic and API interactions
|
|
12
|
+
* Handles data filtering to expose only safe data to publisher apps
|
|
13
|
+
*/
|
|
14
|
+
export declare class PurchaseStateManager {
|
|
15
|
+
private config;
|
|
16
|
+
constructor(config: PurchaseStateManagerConfig);
|
|
17
|
+
/**
|
|
18
|
+
* Check purchase state for a specific item
|
|
19
|
+
* Filters raw API response to expose only safe data to publisher apps
|
|
20
|
+
*/
|
|
21
|
+
checkItemPurchaseState(itemId: string): Promise<PurchaseStateResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* Filters raw API response to expose only safe data to publisher apps
|
|
24
|
+
* CRITICAL: Raw privyEligibility map must NEVER be exposed to apps
|
|
25
|
+
*/
|
|
26
|
+
private filterPurchaseStateResponse;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=PurchaseStateManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PurchaseStateManager.d.ts","sourceRoot":"","sources":["../../src/core/PurchaseStateManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,qBAAqB,EAAqD,MAAM,mBAAmB,CAAC;AAE5H;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAA6B;gBAE/B,MAAM,EAAE,0BAA0B;IAO9C;;;OAGG;IACG,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IA2B5E;;;OAGG;IACH,OAAO,CAAC,2BAA2B;CAmBpC"}
|
|
@@ -20,6 +20,12 @@ class SDKError extends Error {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
+
var PurchaseState = /* @__PURE__ */ ((PurchaseState2) => {
|
|
24
|
+
PurchaseState2["AVAILABLE"] = "AVAILABLE";
|
|
25
|
+
PurchaseState2["PRIVY_REQUIRED"] = "PRIVY_REQUIRED";
|
|
26
|
+
PurchaseState2["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
|
|
27
|
+
return PurchaseState2;
|
|
28
|
+
})(PurchaseState || {});
|
|
23
29
|
class JWTParser {
|
|
24
30
|
/**
|
|
25
31
|
* Decode JWT payload without verification
|
|
@@ -2017,6 +2023,55 @@ class TabSyncManager {
|
|
|
2017
2023
|
this.logger.log("Tab sync destroyed");
|
|
2018
2024
|
}
|
|
2019
2025
|
}
|
|
2026
|
+
class PurchaseStateManager {
|
|
2027
|
+
constructor(config) {
|
|
2028
|
+
this.config = {
|
|
2029
|
+
timeout: 5e3,
|
|
2030
|
+
...config
|
|
2031
|
+
};
|
|
2032
|
+
}
|
|
2033
|
+
/**
|
|
2034
|
+
* Check purchase state for a specific item
|
|
2035
|
+
* Filters raw API response to expose only safe data to publisher apps
|
|
2036
|
+
*/
|
|
2037
|
+
async checkItemPurchaseState(itemId) {
|
|
2038
|
+
try {
|
|
2039
|
+
const response = await fetch(`${this.config.apiEndpoint}/items/${itemId}/purchase-state`, {
|
|
2040
|
+
method: "GET",
|
|
2041
|
+
headers: {
|
|
2042
|
+
"Content-Type": "application/json"
|
|
2043
|
+
},
|
|
2044
|
+
signal: AbortSignal.timeout(this.config.timeout)
|
|
2045
|
+
});
|
|
2046
|
+
if (!response.ok) {
|
|
2047
|
+
throw new Error(`API request failed: ${response.status} ${response.statusText}`);
|
|
2048
|
+
}
|
|
2049
|
+
const rawData = await response.json();
|
|
2050
|
+
return this.filterPurchaseStateResponse(rawData);
|
|
2051
|
+
} catch (error) {
|
|
2052
|
+
if (error instanceof Error) {
|
|
2053
|
+
throw error;
|
|
2054
|
+
}
|
|
2055
|
+
throw new Error("Unknown error occurred while checking purchase state");
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
/**
|
|
2059
|
+
* Filters raw API response to expose only safe data to publisher apps
|
|
2060
|
+
* CRITICAL: Raw privyEligibility map must NEVER be exposed to apps
|
|
2061
|
+
*/
|
|
2062
|
+
filterPurchaseStateResponse(rawResponse) {
|
|
2063
|
+
const filteredResponse = {
|
|
2064
|
+
state: rawResponse.state
|
|
2065
|
+
};
|
|
2066
|
+
if (rawResponse.state === PurchaseState.PRIVY_REQUIRED && rawResponse.privyEligibility) {
|
|
2067
|
+
const requiredLevels = Object.values(rawResponse.privyEligibility).filter((details) => details.requiresUpgrade).map((details) => details.requiredLevel);
|
|
2068
|
+
if (requiredLevels.length > 0) {
|
|
2069
|
+
filteredResponse.requiredLevel = Math.max(...requiredLevels);
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
return filteredResponse;
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2020
2075
|
const lightTheme = {
|
|
2021
2076
|
colors: {
|
|
2022
2077
|
// Background
|
|
@@ -2537,6 +2592,9 @@ class MarketplaceSDK {
|
|
|
2537
2592
|
};
|
|
2538
2593
|
this.validator = new JWKSValidator(this.config.jwksUri, this.config.debug);
|
|
2539
2594
|
this.logger = new Logger(this.config.debug, "[MarketplaceSDK]");
|
|
2595
|
+
this.purchaseStateManager = new PurchaseStateManager({
|
|
2596
|
+
apiEndpoint: this.config.apiEndpoint
|
|
2597
|
+
});
|
|
2540
2598
|
this.logger.info("SDK initialized with config:", {
|
|
2541
2599
|
jwksUri: this.config.jwksUri,
|
|
2542
2600
|
jwtParamName: this.config.jwtParamName,
|
|
@@ -3046,6 +3104,12 @@ class MarketplaceSDK {
|
|
|
3046
3104
|
isTimerRunning() {
|
|
3047
3105
|
return this.timer?.isRunning() ?? false;
|
|
3048
3106
|
}
|
|
3107
|
+
/**
|
|
3108
|
+
* Get purchase state manager for item purchase state checking
|
|
3109
|
+
*/
|
|
3110
|
+
getPurchaseStateManager() {
|
|
3111
|
+
return this.purchaseStateManager;
|
|
3112
|
+
}
|
|
3049
3113
|
/**
|
|
3050
3114
|
* Cleanup and destroy SDK instance
|
|
3051
3115
|
*/
|