@nosslabs/iap 7.0.0-next.0 → 7.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/CHANGELOG.md +65 -0
- package/README.md +4 -4
- package/dist/index.cjs +22 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -8
- package/dist/index.d.ts +1 -8
- package/dist/index.js +22 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -844,10 +844,6 @@ interface EventMap<TEntitlement extends EntitlementBase = EntitlementBase> {
|
|
|
844
844
|
entitlements: TEntitlement[];
|
|
845
845
|
previous: TEntitlement[];
|
|
846
846
|
};
|
|
847
|
-
'price-stale': {
|
|
848
|
-
productId: string;
|
|
849
|
-
lastFetchedAt: number;
|
|
850
|
-
};
|
|
851
847
|
/**
|
|
852
848
|
* Recovery classified an `unfinished_transactions` entry as permanently
|
|
853
849
|
* invalid (per `options.permanentErrorCodes`) and removed it from
|
|
@@ -866,9 +862,6 @@ interface EventMap<TEntitlement extends EntitlementBase = EntitlementBase> {
|
|
|
866
862
|
error: string;
|
|
867
863
|
message?: string;
|
|
868
864
|
};
|
|
869
|
-
error: {
|
|
870
|
-
error: IAPError;
|
|
871
|
-
};
|
|
872
865
|
}
|
|
873
866
|
type EventName<TEntitlement extends EntitlementBase = EntitlementBase> = keyof EventMap<TEntitlement>;
|
|
874
867
|
type EventPayload<K extends EventName<TEntitlement>, TEntitlement extends EntitlementBase = EntitlementBase> = EventMap<TEntitlement>[K];
|
|
@@ -1221,4 +1214,4 @@ declare class HttpBackendAdapter<TEntitlement extends EntitlementBase = Entitlem
|
|
|
1221
1214
|
listProducts(): Promise<ConfiguredProduct[]>;
|
|
1222
1215
|
}
|
|
1223
1216
|
|
|
1224
|
-
export { type AppUserId, type BackendAdapter, type BackendConfig, type BackendConfigInput, type ConfiguredProduct, DEFAULT_PERMANENT_ERROR_CODES, type DefaultEntitlement, type EntitlementBase, type EventMap, type EventName, type EventPayload, HttpBackendAdapter, HttpClient, type HttpRequest, type IAP, type IAPConfig, type IAPConfigInput, IAPError, IAPErrorCode, type LogLevel, type Logger, type NativeTransaction, type OptionsConfig, type Platform, type Product, type ProductType, type PurchaseOptions, type PurchaseResult, type RestoreRequest, type RestoreRequestTransaction, type RestoreResponse, type RestoreResult, type StorageConfig, type Unsubscribe, VERSION, type VerifiedTransaction, type VerifyAppleRequest, type VerifyGoogleRequest, type VerifyResponse, createIAP, errorHint, isIAPError };
|
|
1217
|
+
export { type AppUserId, type AppUserIdFetcherContext, type BackendAdapter, type BackendConfig, type BackendConfigInput, type ConfiguredProduct, DEFAULT_PERMANENT_ERROR_CODES, type DefaultEntitlement, type EntitlementBase, type EventMap, type EventName, type EventPayload, HttpBackendAdapter, HttpClient, type HttpRequest, type IAP, type IAPConfig, type IAPConfigInput, IAPError, IAPErrorCode, type LogLevel, type Logger, type NativeTransaction, type OptionsConfig, type Platform, type Product, type ProductType, type PurchaseOptions, type PurchaseResult, type RestoreRequest, type RestoreRequestTransaction, type RestoreResponse, type RestoreResult, type StorageConfig, type Unsubscribe, VERSION, type VerifiedTransaction, type VerifyAppleRequest, type VerifyGoogleRequest, type VerifyResponse, createIAP, errorHint, isIAPError };
|
package/dist/index.d.ts
CHANGED
|
@@ -844,10 +844,6 @@ interface EventMap<TEntitlement extends EntitlementBase = EntitlementBase> {
|
|
|
844
844
|
entitlements: TEntitlement[];
|
|
845
845
|
previous: TEntitlement[];
|
|
846
846
|
};
|
|
847
|
-
'price-stale': {
|
|
848
|
-
productId: string;
|
|
849
|
-
lastFetchedAt: number;
|
|
850
|
-
};
|
|
851
847
|
/**
|
|
852
848
|
* Recovery classified an `unfinished_transactions` entry as permanently
|
|
853
849
|
* invalid (per `options.permanentErrorCodes`) and removed it from
|
|
@@ -866,9 +862,6 @@ interface EventMap<TEntitlement extends EntitlementBase = EntitlementBase> {
|
|
|
866
862
|
error: string;
|
|
867
863
|
message?: string;
|
|
868
864
|
};
|
|
869
|
-
error: {
|
|
870
|
-
error: IAPError;
|
|
871
|
-
};
|
|
872
865
|
}
|
|
873
866
|
type EventName<TEntitlement extends EntitlementBase = EntitlementBase> = keyof EventMap<TEntitlement>;
|
|
874
867
|
type EventPayload<K extends EventName<TEntitlement>, TEntitlement extends EntitlementBase = EntitlementBase> = EventMap<TEntitlement>[K];
|
|
@@ -1221,4 +1214,4 @@ declare class HttpBackendAdapter<TEntitlement extends EntitlementBase = Entitlem
|
|
|
1221
1214
|
listProducts(): Promise<ConfiguredProduct[]>;
|
|
1222
1215
|
}
|
|
1223
1216
|
|
|
1224
|
-
export { type AppUserId, type BackendAdapter, type BackendConfig, type BackendConfigInput, type ConfiguredProduct, DEFAULT_PERMANENT_ERROR_CODES, type DefaultEntitlement, type EntitlementBase, type EventMap, type EventName, type EventPayload, HttpBackendAdapter, HttpClient, type HttpRequest, type IAP, type IAPConfig, type IAPConfigInput, IAPError, IAPErrorCode, type LogLevel, type Logger, type NativeTransaction, type OptionsConfig, type Platform, type Product, type ProductType, type PurchaseOptions, type PurchaseResult, type RestoreRequest, type RestoreRequestTransaction, type RestoreResponse, type RestoreResult, type StorageConfig, type Unsubscribe, VERSION, type VerifiedTransaction, type VerifyAppleRequest, type VerifyGoogleRequest, type VerifyResponse, createIAP, errorHint, isIAPError };
|
|
1217
|
+
export { type AppUserId, type AppUserIdFetcherContext, type BackendAdapter, type BackendConfig, type BackendConfigInput, type ConfiguredProduct, DEFAULT_PERMANENT_ERROR_CODES, type DefaultEntitlement, type EntitlementBase, type EventMap, type EventName, type EventPayload, HttpBackendAdapter, HttpClient, type HttpRequest, type IAP, type IAPConfig, type IAPConfigInput, IAPError, IAPErrorCode, type LogLevel, type Logger, type NativeTransaction, type OptionsConfig, type Platform, type Product, type ProductType, type PurchaseOptions, type PurchaseResult, type RestoreRequest, type RestoreRequestTransaction, type RestoreResponse, type RestoreResult, type StorageConfig, type Unsubscribe, VERSION, type VerifiedTransaction, type VerifyAppleRequest, type VerifyGoogleRequest, type VerifyResponse, createIAP, errorHint, isIAPError };
|
package/dist/index.js
CHANGED
|
@@ -200,7 +200,7 @@ function mapPurchaseError(error, productId) {
|
|
|
200
200
|
cause: error
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
|
-
if (lower.includes("product not found")) {
|
|
203
|
+
if (lower.includes("product not found") || lower.includes("cannot find product")) {
|
|
204
204
|
return new IAPError({
|
|
205
205
|
code: IAPErrorCode.PRODUCT_NOT_FOUND,
|
|
206
206
|
message: `Product "${productId}" was not found in the store catalog.`,
|
|
@@ -1735,6 +1735,24 @@ function createIAP(input) {
|
|
|
1735
1735
|
cachedAt: null,
|
|
1736
1736
|
products: Object.freeze([...config.products ?? []])
|
|
1737
1737
|
};
|
|
1738
|
+
async function refreshEntitlements() {
|
|
1739
|
+
requireInitialized(state);
|
|
1740
|
+
const previous = state.entitlements;
|
|
1741
|
+
const fetched = await state.backend.getEntitlements();
|
|
1742
|
+
const next = freezeAll(fetched);
|
|
1743
|
+
try {
|
|
1744
|
+
state.cachedAt = await state.cache.save(next);
|
|
1745
|
+
} catch (error) {
|
|
1746
|
+
state.logger.warn(
|
|
1747
|
+
"Failed to persist refreshed entitlements; in-memory state still updated.",
|
|
1748
|
+
error
|
|
1749
|
+
);
|
|
1750
|
+
}
|
|
1751
|
+
state.entitlements = next;
|
|
1752
|
+
if (!entitlementsEqual(previous, next)) {
|
|
1753
|
+
state.emitter.emit("entitlements-changed", { entitlements: next, previous });
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1738
1756
|
return {
|
|
1739
1757
|
async initialize() {
|
|
1740
1758
|
if (state.destroyed) {
|
|
@@ -1836,7 +1854,7 @@ function createIAP(input) {
|
|
|
1836
1854
|
logger: state.logger,
|
|
1837
1855
|
onResume: async () => {
|
|
1838
1856
|
try {
|
|
1839
|
-
await
|
|
1857
|
+
await refreshEntitlements();
|
|
1840
1858
|
} catch (error) {
|
|
1841
1859
|
state.logger.warn("refreshOnResume: refresh() failed.", error);
|
|
1842
1860
|
}
|
|
@@ -1847,7 +1865,7 @@ function createIAP(input) {
|
|
|
1847
1865
|
state.logger.debug("Cache exceeds TTL; scheduling background refresh.");
|
|
1848
1866
|
queueMicrotask(() => {
|
|
1849
1867
|
if (!state.initialized || state.destroyed) return;
|
|
1850
|
-
|
|
1868
|
+
refreshEntitlements().catch((error) => {
|
|
1851
1869
|
state.logger.warn("TTL background refresh failed.", error);
|
|
1852
1870
|
});
|
|
1853
1871
|
});
|
|
@@ -1855,24 +1873,7 @@ function createIAP(input) {
|
|
|
1855
1873
|
state.initialized = true;
|
|
1856
1874
|
state.emitter.emit("ready", void 0);
|
|
1857
1875
|
},
|
|
1858
|
-
|
|
1859
|
-
requireInitialized(state);
|
|
1860
|
-
const previous = state.entitlements;
|
|
1861
|
-
const fetched = await state.backend.getEntitlements();
|
|
1862
|
-
const next = freezeAll(fetched);
|
|
1863
|
-
try {
|
|
1864
|
-
state.cachedAt = await state.cache.save(next);
|
|
1865
|
-
} catch (error) {
|
|
1866
|
-
state.logger.warn(
|
|
1867
|
-
"Failed to persist refreshed entitlements; in-memory state still updated.",
|
|
1868
|
-
error
|
|
1869
|
-
);
|
|
1870
|
-
}
|
|
1871
|
-
state.entitlements = next;
|
|
1872
|
-
if (!entitlementsEqual(previous, next)) {
|
|
1873
|
-
state.emitter.emit("entitlements-changed", { entitlements: next, previous });
|
|
1874
|
-
}
|
|
1875
|
-
},
|
|
1876
|
+
refresh: refreshEntitlements,
|
|
1876
1877
|
async destroy() {
|
|
1877
1878
|
if (state.destroyed) return;
|
|
1878
1879
|
state.destroyed = true;
|