@molecule/app-iap 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/LICENSE +115 -0
- package/dist/iap.d.ts +12 -0
- package/dist/iap.d.ts.map +1 -0
- package/dist/iap.js +103 -0
- package/dist/iap.js.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +87 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +102 -0
- package/dist/provider.js.map +1 -0
- package/dist/translations.d.ts +25 -0
- package/dist/translations.d.ts.map +1 -0
- package/dist/translations.js +25 -0
- package/dist/translations.js.map +1 -0
- package/dist/types.d.ts +311 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/utilities.d.ts +21 -0
- package/dist/utilities.d.ts.map +1 -0
- package/dist/utilities.js +39 -0
- package/dist/utilities.js.map +1 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the
|
|
45
|
+
original version of the Work and any modifications or additions
|
|
46
|
+
to that Work, that is intentionally submitted to the Licensor for
|
|
47
|
+
inclusion in the Work by the copyright owner or by an individual or
|
|
48
|
+
Legal Entity authorized to submit on behalf of the copyright owner.
|
|
49
|
+
|
|
50
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
52
|
+
subsequently incorporated within the Work.
|
|
53
|
+
|
|
54
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
55
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
58
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
59
|
+
Work and such Derivative Works in Source or Object form.
|
|
60
|
+
|
|
61
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
patent license to make, have made, use, offer to sell, sell, import,
|
|
65
|
+
and otherwise transfer the Work.
|
|
66
|
+
|
|
67
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
69
|
+
modifications, and in Source or Object form, provided that You
|
|
70
|
+
meet the following conditions:
|
|
71
|
+
|
|
72
|
+
(a) You must give any other recipients of the Work or
|
|
73
|
+
Derivative Works a copy of this License; and
|
|
74
|
+
|
|
75
|
+
(b) You must cause any modified files to carry prominent notices
|
|
76
|
+
stating that You changed the files; and
|
|
77
|
+
|
|
78
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
79
|
+
that You distribute, all copyright, patent, trademark, and
|
|
80
|
+
attribution notices from the Source form of the Work,
|
|
81
|
+
excluding those notices that do not pertain to any part of
|
|
82
|
+
the Derivative Works; and
|
|
83
|
+
|
|
84
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
|
+
distribution, then any Derivative Works that You distribute must
|
|
86
|
+
include a readable copy of the attribution notices contained
|
|
87
|
+
within such NOTICE file.
|
|
88
|
+
|
|
89
|
+
5. Submission of Contributions.
|
|
90
|
+
|
|
91
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
93
|
+
|
|
94
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
+
agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
|
|
96
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
|
|
97
|
+
|
|
98
|
+
8. Limitation of Liability. In no event and under no legal theory shall
|
|
99
|
+
any Contributor be liable to You for damages.
|
|
100
|
+
|
|
101
|
+
9. Accepting Warranty or Additional Liability.
|
|
102
|
+
|
|
103
|
+
Copyright 2026 Molecule Dev, Inc.
|
|
104
|
+
|
|
105
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
|
+
you may not use this file except in compliance with the License.
|
|
107
|
+
You may obtain a copy of the License at
|
|
108
|
+
|
|
109
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
110
|
+
|
|
111
|
+
Unless required by applicable law or agreed to in writing, software
|
|
112
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
113
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
114
|
+
See the License for the specific language governing permissions and
|
|
115
|
+
limitations under the License.
|
package/dist/iap.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* No-op IAP provider implementation for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { IAPProvider } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Creates a no-op IAP provider for web/testing.
|
|
9
|
+
* @returns A no-op IAP provider that stubs all purchase operations.
|
|
10
|
+
*/
|
|
11
|
+
export declare const createNoopIAPProvider: () => IAPProvider;
|
|
12
|
+
//# sourceMappingURL=iap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iap.d.ts","sourceRoot":"","sources":["../src/iap.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAA6B,WAAW,EAA8B,MAAM,YAAY,CAAA;AAEpG;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAAO,WA4GxC,CAAA"}
|
package/dist/iap.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* No-op IAP provider implementation for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { t } from '@molecule/app-i18n';
|
|
7
|
+
/**
|
|
8
|
+
* Creates a no-op IAP provider for web/testing.
|
|
9
|
+
* @returns A no-op IAP provider that stubs all purchase operations.
|
|
10
|
+
*/
|
|
11
|
+
export const createNoopIAPProvider = () => {
|
|
12
|
+
const products = new Map();
|
|
13
|
+
const handlers = new Map();
|
|
14
|
+
return {
|
|
15
|
+
async initialize() {
|
|
16
|
+
// No-op
|
|
17
|
+
},
|
|
18
|
+
register(definitions) {
|
|
19
|
+
for (const def of definitions) {
|
|
20
|
+
products.set(def.id, {
|
|
21
|
+
id: def.id,
|
|
22
|
+
alias: def.alias,
|
|
23
|
+
type: def.type,
|
|
24
|
+
state: 'registered',
|
|
25
|
+
title: def.alias,
|
|
26
|
+
description: '',
|
|
27
|
+
price: '$0.00',
|
|
28
|
+
priceMicros: 0,
|
|
29
|
+
currency: 'USD',
|
|
30
|
+
canPurchase: false,
|
|
31
|
+
owned: false,
|
|
32
|
+
group: def.group,
|
|
33
|
+
});
|
|
34
|
+
products.set(def.alias, products.get(def.id));
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
async refresh() {
|
|
38
|
+
// No-op
|
|
39
|
+
},
|
|
40
|
+
get(idOrAlias) {
|
|
41
|
+
return products.get(idOrAlias);
|
|
42
|
+
},
|
|
43
|
+
getAll() {
|
|
44
|
+
return Array.from(new Set(products.values()));
|
|
45
|
+
},
|
|
46
|
+
canPurchase() {
|
|
47
|
+
return false;
|
|
48
|
+
},
|
|
49
|
+
async order() {
|
|
50
|
+
return {
|
|
51
|
+
success: false,
|
|
52
|
+
error: {
|
|
53
|
+
code: 'E_NOT_AVAILABLE',
|
|
54
|
+
message: t('iap.error.E_NOT_AVAILABLE', undefined, {
|
|
55
|
+
defaultValue: 'In-app purchases are not available.',
|
|
56
|
+
}),
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
finish() {
|
|
61
|
+
// No-op
|
|
62
|
+
},
|
|
63
|
+
async verify() {
|
|
64
|
+
return { valid: false };
|
|
65
|
+
},
|
|
66
|
+
async restore() {
|
|
67
|
+
return [];
|
|
68
|
+
},
|
|
69
|
+
manageSubscriptions() {
|
|
70
|
+
// No-op
|
|
71
|
+
},
|
|
72
|
+
when() {
|
|
73
|
+
return {
|
|
74
|
+
updated: () => { },
|
|
75
|
+
approved: () => { },
|
|
76
|
+
finished: () => { },
|
|
77
|
+
cancelled: () => { },
|
|
78
|
+
error: () => { },
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
on(event, handler) {
|
|
82
|
+
if (!handlers.has(event)) {
|
|
83
|
+
handlers.set(event, new Set());
|
|
84
|
+
}
|
|
85
|
+
handlers.get(event).add(handler);
|
|
86
|
+
return () => handlers.get(event)?.delete(handler);
|
|
87
|
+
},
|
|
88
|
+
off(handler) {
|
|
89
|
+
handlers.forEach((set) => set.delete(handler));
|
|
90
|
+
},
|
|
91
|
+
getPlatform() {
|
|
92
|
+
return 'web';
|
|
93
|
+
},
|
|
94
|
+
isAvailable() {
|
|
95
|
+
return false;
|
|
96
|
+
},
|
|
97
|
+
destroy() {
|
|
98
|
+
products.clear();
|
|
99
|
+
handlers.clear();
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=iap.js.map
|
package/dist/iap.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iap.js","sourceRoot":"","sources":["../src/iap.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAItC;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAgB,EAAE;IACrD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAmB,CAAA;IAC3C,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAgC,CAAA;IAExD,OAAO;QACL,KAAK,CAAC,UAAU;YACd,QAAQ;QACV,CAAC;QAED,QAAQ,CAAC,WAAgC;YACvC,KAAK,MAAM,GAAG,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|
4
|
+
* Provides a unified API for in-app purchases that works across
|
|
5
|
+
* different platforms (iOS App Store, Google Play, web Stripe).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { createNoopIAPProvider, initialize, order, finish,
|
|
10
|
+
* register, refresh, setProvider, verify } from '@molecule/app-iap'
|
|
11
|
+
*
|
|
12
|
+
* // Wire the provider at app startup (swap for an iOS/Android bond in production)
|
|
13
|
+
* setProvider(createNoopIAPProvider())
|
|
14
|
+
* await initialize()
|
|
15
|
+
* register([{ id: 'com.example.pro_monthly', alias: 'pro_monthly', type: 'subscription' }])
|
|
16
|
+
* await refresh()
|
|
17
|
+
*
|
|
18
|
+
* const result = await order('pro_monthly')
|
|
19
|
+
* if (result.success && result.product) {
|
|
20
|
+
* await verify(result.product, '/api/iap/verify')
|
|
21
|
+
* finish(result.product)
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
* @remarks
|
|
25
|
+
* - NO store provider ships with the fleet yet: the only built-in
|
|
26
|
+
* implementation is `createNoopIAPProvider()`, and `getProvider()` silently
|
|
27
|
+
* self-bonds it when nothing is wired — so without a real provider
|
|
28
|
+
* `order()` ALWAYS fails with `E_NOT_AVAILABLE`, `verify()` returns
|
|
29
|
+
* `{ valid: false }`, and `isAvailable()` is `false`. To sell on iOS /
|
|
30
|
+
* Android, implement `IAPProvider` yourself (e.g. wrapping
|
|
31
|
+
* cordova-plugin-purchase, StoreKit 2, or Play Billing) and wire it with
|
|
32
|
+
* `setProvider()` at startup.
|
|
33
|
+
* - `verify()` POSTs the purchase to YOUR server: implement the endpoint with
|
|
34
|
+
* `@molecule/api-payments-apple` / `@molecule/api-payments-google` (receipt
|
|
35
|
+
* validation) and call `finish()` only after the server says the receipt is
|
|
36
|
+
* valid — finishing first loses the purchase if validation fails.
|
|
37
|
+
* - Error messages route through `t('iap.error.*')` with English fallbacks;
|
|
38
|
+
* the `@molecule/app-locales-iap` bond supplies 79 translations.
|
|
39
|
+
*
|
|
40
|
+
* @module
|
|
41
|
+
*/
|
|
42
|
+
export * from './iap.js';
|
|
43
|
+
export * from './provider.js';
|
|
44
|
+
export * from './types.js';
|
|
45
|
+
export * from './utilities.js';
|
|
46
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-App Purchases interface for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* Provides a unified API for in-app purchases that works across
|
|
5
|
+
* different platforms (iOS App Store, Google Play, web Stripe).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { createNoopIAPProvider, initialize, order, finish,
|
|
10
|
+
* register, refresh, setProvider, verify } from '@molecule/app-iap'
|
|
11
|
+
*
|
|
12
|
+
* // Wire the provider at app startup (swap for an iOS/Android bond in production)
|
|
13
|
+
* setProvider(createNoopIAPProvider())
|
|
14
|
+
* await initialize()
|
|
15
|
+
* register([{ id: 'com.example.pro_monthly', alias: 'pro_monthly', type: 'subscription' }])
|
|
16
|
+
* await refresh()
|
|
17
|
+
*
|
|
18
|
+
* const result = await order('pro_monthly')
|
|
19
|
+
* if (result.success && result.product) {
|
|
20
|
+
* await verify(result.product, '/api/iap/verify')
|
|
21
|
+
* finish(result.product)
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
* @remarks
|
|
25
|
+
* - NO store provider ships with the fleet yet: the only built-in
|
|
26
|
+
* implementation is `createNoopIAPProvider()`, and `getProvider()` silently
|
|
27
|
+
* self-bonds it when nothing is wired — so without a real provider
|
|
28
|
+
* `order()` ALWAYS fails with `E_NOT_AVAILABLE`, `verify()` returns
|
|
29
|
+
* `{ valid: false }`, and `isAvailable()` is `false`. To sell on iOS /
|
|
30
|
+
* Android, implement `IAPProvider` yourself (e.g. wrapping
|
|
31
|
+
* cordova-plugin-purchase, StoreKit 2, or Play Billing) and wire it with
|
|
32
|
+
* `setProvider()` at startup.
|
|
33
|
+
* - `verify()` POSTs the purchase to YOUR server: implement the endpoint with
|
|
34
|
+
* `@molecule/api-payments-apple` / `@molecule/api-payments-google` (receipt
|
|
35
|
+
* validation) and call `finish()` only after the server says the receipt is
|
|
36
|
+
* valid — finishing first loses the purchase if validation fails.
|
|
37
|
+
* - Error messages route through `t('iap.error.*')` with English fallbacks;
|
|
38
|
+
* the `@molecule/app-locales-iap` bond supplies 79 translations.
|
|
39
|
+
*
|
|
40
|
+
* @module
|
|
41
|
+
*/
|
|
42
|
+
export * from './iap.js';
|
|
43
|
+
export * from './provider.js';
|
|
44
|
+
export * from './types.js';
|
|
45
|
+
export * from './utilities.js';
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IAP provider management for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { IAPProvider, Product, ProductDefinition, PurchaseResult, VerificationResult } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Sets the IAP provider.
|
|
9
|
+
* @param provider - The IAP provider implementation to bond.
|
|
10
|
+
*/
|
|
11
|
+
export declare const setProvider: (provider: IAPProvider) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Gets the current IAP provider. Falls back to a no-op provider if none has been
|
|
14
|
+
* bonded — on web this is correct (no store exists), but on iOS/Android a missing
|
|
15
|
+
* real provider means every `order()` reports unavailable. The fallback warns when
|
|
16
|
+
* it engages so the omission is visible rather than a silent failure.
|
|
17
|
+
* @returns The active IAP provider instance.
|
|
18
|
+
*/
|
|
19
|
+
export declare const getProvider: () => IAPProvider;
|
|
20
|
+
/**
|
|
21
|
+
* Checks if an IAP provider has been bonded.
|
|
22
|
+
* @returns Whether an IAP provider is currently registered.
|
|
23
|
+
*/
|
|
24
|
+
export declare const hasProvider: () => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Initializes the IAP system via the active provider.
|
|
27
|
+
* @returns A promise that resolves when initialization is complete.
|
|
28
|
+
*/
|
|
29
|
+
export declare const initialize: () => Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Registers product definitions with the IAP provider.
|
|
32
|
+
* @param products - The product definitions to register for purchase availability.
|
|
33
|
+
* @returns Nothing.
|
|
34
|
+
*/
|
|
35
|
+
export declare const register: (products: ProductDefinition[]) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Refreshes product information from the store.
|
|
38
|
+
* @returns A promise that resolves when product data has been refreshed.
|
|
39
|
+
*/
|
|
40
|
+
export declare const refresh: () => Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Gets a product by its store ID or registered alias.
|
|
43
|
+
* @param idOrAlias - The product store ID or alias to look up.
|
|
44
|
+
* @returns The matching product, or undefined if not found.
|
|
45
|
+
*/
|
|
46
|
+
export declare const get: (idOrAlias: string) => Product | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Gets all registered products.
|
|
49
|
+
* @returns An array of all available products.
|
|
50
|
+
*/
|
|
51
|
+
export declare const getAll: () => Product[];
|
|
52
|
+
/**
|
|
53
|
+
* Initiates a purchase order for a product.
|
|
54
|
+
* @param idOrAlias - The product store ID or alias to purchase.
|
|
55
|
+
* @returns A promise that resolves with the purchase result.
|
|
56
|
+
*/
|
|
57
|
+
export declare const order: (idOrAlias: string) => Promise<PurchaseResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Finishes a pending transaction, acknowledging delivery to the store.
|
|
60
|
+
* @param product - The product whose transaction should be finalized.
|
|
61
|
+
* @returns Nothing.
|
|
62
|
+
*/
|
|
63
|
+
export declare const finish: (product: Product) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Verifies a purchase receipt with a server endpoint.
|
|
66
|
+
* @param product - The product whose purchase receipt to verify.
|
|
67
|
+
* @param verifyUrl - The server URL to send the verification request to.
|
|
68
|
+
* @param additionalData - Extra data to include in the verification payload.
|
|
69
|
+
* @returns A promise that resolves with the server verification result.
|
|
70
|
+
*/
|
|
71
|
+
export declare const verify: (product: Product, verifyUrl: string, additionalData?: Record<string, unknown>) => Promise<VerificationResult>;
|
|
72
|
+
/**
|
|
73
|
+
* Restores previously completed purchases from the store.
|
|
74
|
+
* @returns A promise that resolves with an array of restored products.
|
|
75
|
+
*/
|
|
76
|
+
export declare const restore: () => Promise<Product[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Opens the platform's subscription management UI.
|
|
79
|
+
* @returns Nothing.
|
|
80
|
+
*/
|
|
81
|
+
export declare const manageSubscriptions: () => void;
|
|
82
|
+
/**
|
|
83
|
+
* Checks if in-app purchases are available on the current platform.
|
|
84
|
+
* @returns Whether the IAP system is available and functional.
|
|
85
|
+
*/
|
|
86
|
+
export declare const isAvailable: () => boolean;
|
|
87
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EACV,WAAW,EACX,OAAO,EACP,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EACnB,MAAM,YAAY,C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
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { bond, get as bondGet, isBonded } from '@molecule/app-bond';
|
|
7
|
+
import { createNoopIAPProvider } from './iap.js';
|
|
8
|
+
const BOND_TYPE = 'iap';
|
|
9
|
+
/**
|
|
10
|
+
* Sets the IAP provider.
|
|
11
|
+
* @param provider - The IAP provider implementation to bond.
|
|
12
|
+
*/
|
|
13
|
+
export const setProvider = (provider) => {
|
|
14
|
+
bond(BOND_TYPE, provider);
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Gets the current IAP provider. Falls back to a no-op provider if none has been
|
|
18
|
+
* bonded — on web this is correct (no store exists), but on iOS/Android a missing
|
|
19
|
+
* real provider means every `order()` reports unavailable. The fallback warns when
|
|
20
|
+
* it engages so the omission is visible rather than a silent failure.
|
|
21
|
+
* @returns The active IAP provider instance.
|
|
22
|
+
*/
|
|
23
|
+
export const getProvider = () => {
|
|
24
|
+
if (!isBonded(BOND_TYPE)) {
|
|
25
|
+
console.warn('[@molecule/app-iap] No IAP provider bonded — using the no-op provider, so ' +
|
|
26
|
+
'purchases report unavailable and order() always fails. No store provider ' +
|
|
27
|
+
'ships with the fleet: implement the IAPProvider interface (StoreKit 2 / ' +
|
|
28
|
+
'Play Billing / cordova-plugin-purchase) and call setProvider() at startup.');
|
|
29
|
+
bond(BOND_TYPE, createNoopIAPProvider());
|
|
30
|
+
}
|
|
31
|
+
return bondGet(BOND_TYPE);
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Checks if an IAP provider has been bonded.
|
|
35
|
+
* @returns Whether an IAP provider is currently registered.
|
|
36
|
+
*/
|
|
37
|
+
export const hasProvider = () => {
|
|
38
|
+
return isBonded(BOND_TYPE);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Initializes the IAP system via the active provider.
|
|
42
|
+
* @returns A promise that resolves when initialization is complete.
|
|
43
|
+
*/
|
|
44
|
+
export const initialize = () => getProvider().initialize();
|
|
45
|
+
/**
|
|
46
|
+
* Registers product definitions with the IAP provider.
|
|
47
|
+
* @param products - The product definitions to register for purchase availability.
|
|
48
|
+
* @returns Nothing.
|
|
49
|
+
*/
|
|
50
|
+
export const register = (products) => getProvider().register(products);
|
|
51
|
+
/**
|
|
52
|
+
* Refreshes product information from the store.
|
|
53
|
+
* @returns A promise that resolves when product data has been refreshed.
|
|
54
|
+
*/
|
|
55
|
+
export const refresh = () => getProvider().refresh();
|
|
56
|
+
/**
|
|
57
|
+
* Gets a product by its store ID or registered alias.
|
|
58
|
+
* @param idOrAlias - The product store ID or alias to look up.
|
|
59
|
+
* @returns The matching product, or undefined if not found.
|
|
60
|
+
*/
|
|
61
|
+
export const get = (idOrAlias) => getProvider().get(idOrAlias);
|
|
62
|
+
/**
|
|
63
|
+
* Gets all registered products.
|
|
64
|
+
* @returns An array of all available products.
|
|
65
|
+
*/
|
|
66
|
+
export const getAll = () => getProvider().getAll();
|
|
67
|
+
/**
|
|
68
|
+
* Initiates a purchase order for a product.
|
|
69
|
+
* @param idOrAlias - The product store ID or alias to purchase.
|
|
70
|
+
* @returns A promise that resolves with the purchase result.
|
|
71
|
+
*/
|
|
72
|
+
export const order = (idOrAlias) => getProvider().order(idOrAlias);
|
|
73
|
+
/**
|
|
74
|
+
* Finishes a pending transaction, acknowledging delivery to the store.
|
|
75
|
+
* @param product - The product whose transaction should be finalized.
|
|
76
|
+
* @returns Nothing.
|
|
77
|
+
*/
|
|
78
|
+
export const finish = (product) => getProvider().finish(product);
|
|
79
|
+
/**
|
|
80
|
+
* Verifies a purchase receipt with a server endpoint.
|
|
81
|
+
* @param product - The product whose purchase receipt to verify.
|
|
82
|
+
* @param verifyUrl - The server URL to send the verification request to.
|
|
83
|
+
* @param additionalData - Extra data to include in the verification payload.
|
|
84
|
+
* @returns A promise that resolves with the server verification result.
|
|
85
|
+
*/
|
|
86
|
+
export const verify = (product, verifyUrl, additionalData) => getProvider().verify(product, verifyUrl, additionalData);
|
|
87
|
+
/**
|
|
88
|
+
* Restores previously completed purchases from the store.
|
|
89
|
+
* @returns A promise that resolves with an array of restored products.
|
|
90
|
+
*/
|
|
91
|
+
export const restore = () => getProvider().restore();
|
|
92
|
+
/**
|
|
93
|
+
* Opens the platform's subscription management UI.
|
|
94
|
+
* @returns Nothing.
|
|
95
|
+
*/
|
|
96
|
+
export const manageSubscriptions = () => getProvider().manageSubscriptions();
|
|
97
|
+
/**
|
|
98
|
+
* Checks if in-app purchases are available on the current platform.
|
|
99
|
+
* @returns Whether the IAP system is available and functional.
|
|
100
|
+
*/
|
|
101
|
+
export const isAvailable = () => getProvider().isAvailable();
|
|
102
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAEnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAShD,MAAM,SAAS,GAAG,KAAK,CAAA;AAEvB;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,QAAqB,EAAQ,EAAE;IACzD,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;AAC3B,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAgB,EAAE;IAC3C,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QACzB,OAAO,CAAC,IAAI,CACV,4EAA4E;YAC1E,2EAA2E;YAC3E,0EAA0E;YAC1E,4EAA4E,CAC/E,CAAA;QACD,IAAI,CAAC,SAAS,EAAE,qBAAqB,EAAE,CAAC,CAAA;IAC1C,CAAC;IACD,OAAO,OAAO,CAAc,SAAS,CAAE,CAAA;AACzC,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,WA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G;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAS,EAAE,CAAC,WAAW,EAAE,CAAC,mBAAmB,EAAE,CAAA;AAElF;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAY,EAAE,CAAC,WAAW,EAAE,CAAC,WAAW,EAAE,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default English translations for IAP error utilities.
|
|
3
|
+
*
|
|
4
|
+
* Used as inline fallbacks when no i18n provider is available.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The default translations.
|
|
10
|
+
*/
|
|
11
|
+
export declare const defaultTranslations: {
|
|
12
|
+
readonly en: {
|
|
13
|
+
readonly 'iap.error.E_UNKNOWN': "An unknown error occurred.";
|
|
14
|
+
readonly 'iap.error.E_NOT_AVAILABLE': "In-app purchases are not available.";
|
|
15
|
+
readonly 'iap.error.E_USER_CANCELLED': "Purchase was cancelled.";
|
|
16
|
+
readonly 'iap.error.E_ITEM_UNAVAILABLE': "This item is not available for purchase.";
|
|
17
|
+
readonly 'iap.error.E_NETWORK': "A network error occurred. Please try again.";
|
|
18
|
+
readonly 'iap.error.E_SERVICE_ERROR': "The store service encountered an error.";
|
|
19
|
+
readonly 'iap.error.E_ALREADY_OWNED': "You already own this item.";
|
|
20
|
+
readonly 'iap.error.E_NOT_OWNED': "You do not own this item.";
|
|
21
|
+
readonly 'iap.error.E_VERIFICATION_FAILED': "Purchase verification failed.";
|
|
22
|
+
readonly 'iap.error.E_DEFERRED': "Purchase is pending approval.";
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=translations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translations.d.ts","sourceRoot":"","sources":["../src/translations.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;CAatB,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default English translations for IAP error utilities.
|
|
3
|
+
*
|
|
4
|
+
* Used as inline fallbacks when no i18n provider is available.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The default translations.
|
|
10
|
+
*/
|
|
11
|
+
export const defaultTranslations = {
|
|
12
|
+
en: {
|
|
13
|
+
'iap.error.E_UNKNOWN': 'An unknown error occurred.',
|
|
14
|
+
'iap.error.E_NOT_AVAILABLE': 'In-app purchases are not available.',
|
|
15
|
+
'iap.error.E_USER_CANCELLED': 'Purchase was cancelled.',
|
|
16
|
+
'iap.error.E_ITEM_UNAVAILABLE': 'This item is not available for purchase.',
|
|
17
|
+
'iap.error.E_NETWORK': 'A network error occurred. Please try again.',
|
|
18
|
+
'iap.error.E_SERVICE_ERROR': 'The store service encountered an error.',
|
|
19
|
+
'iap.error.E_ALREADY_OWNED': 'You already own this item.',
|
|
20
|
+
'iap.error.E_NOT_OWNED': 'You do not own this item.',
|
|
21
|
+
'iap.error.E_VERIFICATION_FAILED': 'Purchase verification failed.',
|
|
22
|
+
'iap.error.E_DEFERRED': 'Purchase is pending approval.',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=translations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translations.js","sourceRoot":"","sources":["../src/translations.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,EAAE,EAAE;QACF,qBAAqB,EAAE,4BAA4B;QACnD,2BAA2B,EAAE,qCAAqC;QAClE,4BAA4B,EAAE,yBAAyB;QACvD,8BAA8B,EAAE,0CAA0C;QAC1E,qBAAqB,EAAE,6CAA6C;QACpE,2BAA2B,EAAE,yCAAyC;QACtE,2BAA2B,EAAE,4BAA4B;QACzD,uBAAuB,EAAE,2BAA2B;QACpD,iCAAiC,EAAE,+BAA+B;QAClE,sBAAsB,EAAE,+BAA+B;KACxD;CACO,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-App Purchases types for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* In-app purchase product categories: one-time consumable, permanent non-consumable, or recurring subscription.
|
|
8
|
+
*/
|
|
9
|
+
export type ProductType = 'consumable' | 'non-consumable' | 'subscription';
|
|
10
|
+
/**
|
|
11
|
+
* Purchase lifecycle state of an in-app product (registered, valid, approved, owned, cancelled, etc.).
|
|
12
|
+
*/
|
|
13
|
+
export type ProductState = 'registered' | 'valid' | 'invalid' | 'requested' | 'initiated' | 'approved' | 'finished' | 'owned' | 'cancelled' | 'downloading';
|
|
14
|
+
/**
|
|
15
|
+
* Subscription billing interval: weekly, monthly, yearly, or lifetime.
|
|
16
|
+
*/
|
|
17
|
+
export type SubscriptionPeriod = 'weekly' | 'monthly' | 'yearly' | 'lifetime';
|
|
18
|
+
/**
|
|
19
|
+
* Product definition for registration.
|
|
20
|
+
*/
|
|
21
|
+
export interface ProductDefinition {
|
|
22
|
+
/**
|
|
23
|
+
* Product ID (SKU) - platform-specific identifier.
|
|
24
|
+
*/
|
|
25
|
+
id: string;
|
|
26
|
+
/**
|
|
27
|
+
* Product alias - cross-platform identifier.
|
|
28
|
+
*/
|
|
29
|
+
alias: string;
|
|
30
|
+
/**
|
|
31
|
+
* Product type.
|
|
32
|
+
*/
|
|
33
|
+
type: ProductType;
|
|
34
|
+
/**
|
|
35
|
+
* Product group (for subscription grouping).
|
|
36
|
+
*/
|
|
37
|
+
group?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Full in-app product details (ID, type, state, pricing, ownership, transaction, subscription info).
|
|
41
|
+
*/
|
|
42
|
+
export interface Product {
|
|
43
|
+
/**
|
|
44
|
+
* Product ID (SKU).
|
|
45
|
+
*/
|
|
46
|
+
id: string;
|
|
47
|
+
/**
|
|
48
|
+
* Product alias.
|
|
49
|
+
*/
|
|
50
|
+
alias: string;
|
|
51
|
+
/**
|
|
52
|
+
* Product type.
|
|
53
|
+
*/
|
|
54
|
+
type: ProductType;
|
|
55
|
+
/**
|
|
56
|
+
* Product state.
|
|
57
|
+
*/
|
|
58
|
+
state: ProductState;
|
|
59
|
+
/**
|
|
60
|
+
* Product title.
|
|
61
|
+
*/
|
|
62
|
+
title: string;
|
|
63
|
+
/**
|
|
64
|
+
* Product description.
|
|
65
|
+
*/
|
|
66
|
+
description: string;
|
|
67
|
+
/**
|
|
68
|
+
* Formatted price string.
|
|
69
|
+
*/
|
|
70
|
+
price: string;
|
|
71
|
+
/**
|
|
72
|
+
* Price in micros (cents * 10000).
|
|
73
|
+
*/
|
|
74
|
+
priceMicros: number;
|
|
75
|
+
/**
|
|
76
|
+
* Currency code (ISO 4217).
|
|
77
|
+
*/
|
|
78
|
+
currency: string;
|
|
79
|
+
/**
|
|
80
|
+
* Whether the product can be purchased.
|
|
81
|
+
*/
|
|
82
|
+
canPurchase: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Whether the product is owned.
|
|
85
|
+
*/
|
|
86
|
+
owned: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Transaction information (if applicable).
|
|
89
|
+
*/
|
|
90
|
+
transaction?: Transaction;
|
|
91
|
+
/**
|
|
92
|
+
* Subscription period (for subscriptions).
|
|
93
|
+
*/
|
|
94
|
+
subscriptionPeriod?: SubscriptionPeriod;
|
|
95
|
+
/**
|
|
96
|
+
* Introductory price (for subscriptions with trial).
|
|
97
|
+
*/
|
|
98
|
+
introPrice?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Trial period in days.
|
|
101
|
+
*/
|
|
102
|
+
trialPeriodDays?: number;
|
|
103
|
+
/**
|
|
104
|
+
* Product group.
|
|
105
|
+
*/
|
|
106
|
+
group?: string;
|
|
107
|
+
/**
|
|
108
|
+
* Raw platform-specific data.
|
|
109
|
+
*/
|
|
110
|
+
raw?: unknown;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Purchase transaction record (ID, receipt, purchase token, timestamps, validity).
|
|
114
|
+
*/
|
|
115
|
+
export interface Transaction {
|
|
116
|
+
/**
|
|
117
|
+
* Transaction ID.
|
|
118
|
+
*/
|
|
119
|
+
id: string;
|
|
120
|
+
/**
|
|
121
|
+
* Platform-specific receipt.
|
|
122
|
+
*/
|
|
123
|
+
receipt?: string;
|
|
124
|
+
/**
|
|
125
|
+
* App Store receipt (iOS).
|
|
126
|
+
*/
|
|
127
|
+
appStoreReceipt?: string;
|
|
128
|
+
/**
|
|
129
|
+
* Purchase token (Android).
|
|
130
|
+
*/
|
|
131
|
+
purchaseToken?: string;
|
|
132
|
+
/**
|
|
133
|
+
* Purchase time.
|
|
134
|
+
*/
|
|
135
|
+
purchaseTime?: Date;
|
|
136
|
+
/**
|
|
137
|
+
* Expiration time (for subscriptions).
|
|
138
|
+
*/
|
|
139
|
+
expirationTime?: Date;
|
|
140
|
+
/**
|
|
141
|
+
* Whether the purchase is valid.
|
|
142
|
+
*/
|
|
143
|
+
isValid?: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Raw platform-specific data.
|
|
146
|
+
*/
|
|
147
|
+
raw?: unknown;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* In-app purchase error with error code, product ID, and platform-specific details.
|
|
151
|
+
*/
|
|
152
|
+
export interface IAPError {
|
|
153
|
+
/**
|
|
154
|
+
* Error code.
|
|
155
|
+
*/
|
|
156
|
+
code: string | number;
|
|
157
|
+
/**
|
|
158
|
+
* Error message.
|
|
159
|
+
*/
|
|
160
|
+
message: string;
|
|
161
|
+
/**
|
|
162
|
+
* Product ID (if applicable).
|
|
163
|
+
*/
|
|
164
|
+
productId?: string;
|
|
165
|
+
/**
|
|
166
|
+
* Raw error.
|
|
167
|
+
*/
|
|
168
|
+
raw?: unknown;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Outcome of a purchase attempt (success flag, product, transaction, or error).
|
|
172
|
+
*/
|
|
173
|
+
export interface PurchaseResult {
|
|
174
|
+
/**
|
|
175
|
+
* Whether the purchase was successful.
|
|
176
|
+
*/
|
|
177
|
+
success: boolean;
|
|
178
|
+
/**
|
|
179
|
+
* The purchased product.
|
|
180
|
+
*/
|
|
181
|
+
product?: Product;
|
|
182
|
+
/**
|
|
183
|
+
* Transaction information.
|
|
184
|
+
*/
|
|
185
|
+
transaction?: Transaction;
|
|
186
|
+
/**
|
|
187
|
+
* Error (if purchase failed).
|
|
188
|
+
*/
|
|
189
|
+
error?: IAPError;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Verification result from server.
|
|
193
|
+
*/
|
|
194
|
+
export interface VerificationResult {
|
|
195
|
+
/**
|
|
196
|
+
* Whether the receipt is valid.
|
|
197
|
+
*/
|
|
198
|
+
valid: boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Subscription expiration time.
|
|
201
|
+
*/
|
|
202
|
+
expirationTime?: Date;
|
|
203
|
+
/**
|
|
204
|
+
* Whether the subscription is active.
|
|
205
|
+
*/
|
|
206
|
+
isActive?: boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Plan/tier information.
|
|
209
|
+
*/
|
|
210
|
+
plan?: string;
|
|
211
|
+
/**
|
|
212
|
+
* Server response data.
|
|
213
|
+
*/
|
|
214
|
+
data?: unknown;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* IAP lifecycle events: ready, product-updated, approved, finished, cancelled, error, pending, expired, restored.
|
|
218
|
+
*/
|
|
219
|
+
export type IAPEvent = 'ready' | 'product-updated' | 'approved' | 'finished' | 'cancelled' | 'error' | 'pending' | 'expired' | 'restored';
|
|
220
|
+
/**
|
|
221
|
+
* Generic event handler for IAP events.
|
|
222
|
+
*/
|
|
223
|
+
export type IAPEventHandler<T = unknown> = (data: T) => void;
|
|
224
|
+
/**
|
|
225
|
+
* Event handler called with a Product when a product-related event occurs.
|
|
226
|
+
*/
|
|
227
|
+
export type ProductEventHandler = (product: Product) => void;
|
|
228
|
+
/**
|
|
229
|
+
* Event handler called with an IAPError when a purchase error occurs.
|
|
230
|
+
*/
|
|
231
|
+
export type ErrorEventHandler = (error: IAPError) => void;
|
|
232
|
+
/**
|
|
233
|
+
* In-App Purchases provider interface.
|
|
234
|
+
*/
|
|
235
|
+
export interface IAPProvider {
|
|
236
|
+
/**
|
|
237
|
+
* Initializes the IAP system.
|
|
238
|
+
*/
|
|
239
|
+
initialize(): Promise<void>;
|
|
240
|
+
/**
|
|
241
|
+
* Registers products for purchase.
|
|
242
|
+
*/
|
|
243
|
+
register(products: ProductDefinition[]): void;
|
|
244
|
+
/**
|
|
245
|
+
* Refreshes product information from the store.
|
|
246
|
+
*/
|
|
247
|
+
refresh(): Promise<void>;
|
|
248
|
+
/**
|
|
249
|
+
* Gets a product by ID or alias.
|
|
250
|
+
*/
|
|
251
|
+
get(idOrAlias: string): Product | undefined;
|
|
252
|
+
/**
|
|
253
|
+
* Gets all registered products.
|
|
254
|
+
*/
|
|
255
|
+
getAll(): Product[];
|
|
256
|
+
/**
|
|
257
|
+
* Checks if a product can be purchased.
|
|
258
|
+
*/
|
|
259
|
+
canPurchase(idOrAlias: string): boolean;
|
|
260
|
+
/**
|
|
261
|
+
* Initiates a purchase.
|
|
262
|
+
*/
|
|
263
|
+
order(idOrAlias: string): Promise<PurchaseResult>;
|
|
264
|
+
/**
|
|
265
|
+
* Finishes a transaction (must be called after successful verification).
|
|
266
|
+
*/
|
|
267
|
+
finish(product: Product): void;
|
|
268
|
+
/**
|
|
269
|
+
* Verifies a purchase with the server.
|
|
270
|
+
*/
|
|
271
|
+
verify(product: Product, verifyUrl: string, additionalData?: Record<string, unknown>): Promise<VerificationResult>;
|
|
272
|
+
/**
|
|
273
|
+
* Restores previous purchases.
|
|
274
|
+
*/
|
|
275
|
+
restore(): Promise<Product[]>;
|
|
276
|
+
/**
|
|
277
|
+
* Opens the subscription management page.
|
|
278
|
+
*/
|
|
279
|
+
manageSubscriptions(): void;
|
|
280
|
+
/**
|
|
281
|
+
* Subscribes to product events.
|
|
282
|
+
*/
|
|
283
|
+
when(idOrAlias: string): {
|
|
284
|
+
updated: (handler: ProductEventHandler) => void;
|
|
285
|
+
approved: (handler: ProductEventHandler) => void;
|
|
286
|
+
finished: (handler: ProductEventHandler) => void;
|
|
287
|
+
cancelled: (handler: ProductEventHandler) => void;
|
|
288
|
+
error: (handler: ErrorEventHandler) => void;
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* Subscribes to global events.
|
|
292
|
+
*/
|
|
293
|
+
on(event: IAPEvent, handler: IAPEventHandler): () => void;
|
|
294
|
+
/**
|
|
295
|
+
* Unsubscribes from events.
|
|
296
|
+
*/
|
|
297
|
+
off(handler: IAPEventHandler): void;
|
|
298
|
+
/**
|
|
299
|
+
* Gets the platform name.
|
|
300
|
+
*/
|
|
301
|
+
getPlatform(): 'ios' | 'android' | 'web' | 'unknown';
|
|
302
|
+
/**
|
|
303
|
+
* Checks if IAP is available.
|
|
304
|
+
*/
|
|
305
|
+
isAvailable(): boolean;
|
|
306
|
+
/**
|
|
307
|
+
* Destroys the IAP system.
|
|
308
|
+
*/
|
|
309
|
+
destroy(): void;
|
|
310
|
+
}
|
|
311
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,gBAAgB,GAAG,cAAc,CAAA;AAE1E;;GAEG;AACH,MAAM,MAAM,YAAY,GACpB,YAAY,GACZ,OAAO,GACP,SAAS,GACT,WAAW,GACX,WAAW,GACX,UAAU,GACV,UAAU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OAAO,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAAA;QAC/C,QAAQ,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAAA;QAChD,QAAQ,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAAA;QAChD,SAAS,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAAA;QACjD,KAAK,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,CAAA;KAC5C,CAAA;IAED;;OAEG;IACH,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,GAAG,MAAM,IAAI,CAAA;IAEzD;;OAEG;IACH,GAAG,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAAA;IAEnC;;OAEG;IACH,WAAW,IAAI,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,CAAA;IAEpD;;OAEG;IACH,WAAW,IAAI,OAAO,CAAA;IAEtB;;OAEG;IACH,OAAO,IAAI,IAAI,CAAA;CAChB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-App Purchases utilities for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { IAPError } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Error code mapping for user-friendly messages.
|
|
9
|
+
* Derived from defaultTranslations to avoid duplicating strings.
|
|
10
|
+
*/
|
|
11
|
+
export declare const errorMessages: Record<string, string>;
|
|
12
|
+
/**
|
|
13
|
+
* Gets a user-friendly error message.
|
|
14
|
+
* @param error - The IAP error object or unknown thrown value to translate.
|
|
15
|
+
* @param t - Optional i18n translation function for localized messages.
|
|
16
|
+
* @returns A user-friendly error message string.
|
|
17
|
+
*/
|
|
18
|
+
export declare const getErrorMessage: (error: IAPError | unknown, t?: (key: string, values?: Record<string, unknown>, options?: {
|
|
19
|
+
defaultValue?: string;
|
|
20
|
+
}) => string) => string;
|
|
21
|
+
//# sourceMappingURL=utilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAKhD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAC1B,OAAO,QAAQ,GAAG,OAAO,EACzB,IAAI,CACF,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,OAAO,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,KAChC,MAAM,KACV,MAqBF,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-App Purchases utilities for molecule.dev.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { defaultTranslations } from './translations.js';
|
|
7
|
+
/**
|
|
8
|
+
* Error code mapping for user-friendly messages.
|
|
9
|
+
* Derived from defaultTranslations to avoid duplicating strings.
|
|
10
|
+
*/
|
|
11
|
+
export const errorMessages = Object.fromEntries(Object.entries(defaultTranslations.en).map(([key, value]) => [
|
|
12
|
+
key.replace('iap.error.', ''),
|
|
13
|
+
value,
|
|
14
|
+
]));
|
|
15
|
+
/**
|
|
16
|
+
* Gets a user-friendly error message.
|
|
17
|
+
* @param error - The IAP error object or unknown thrown value to translate.
|
|
18
|
+
* @param t - Optional i18n translation function for localized messages.
|
|
19
|
+
* @returns A user-friendly error message string.
|
|
20
|
+
*/
|
|
21
|
+
export const getErrorMessage = (error, t) => {
|
|
22
|
+
if (typeof error === 'object' && error !== null) {
|
|
23
|
+
const e = error;
|
|
24
|
+
const code = String(e.code || '');
|
|
25
|
+
if (errorMessages[code]) {
|
|
26
|
+
const defaultMsg = errorMessages[code];
|
|
27
|
+
return t ? t(`iap.error.${code}`, undefined, { defaultValue: defaultMsg }) : defaultMsg;
|
|
28
|
+
}
|
|
29
|
+
if (e.message) {
|
|
30
|
+
return e.message;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (typeof error === 'string') {
|
|
34
|
+
return error;
|
|
35
|
+
}
|
|
36
|
+
const fallback = errorMessages.E_UNKNOWN;
|
|
37
|
+
return t ? t('iap.error.E_UNKNOWN', undefined, { defaultValue: fallback }) : fallback;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=utilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.js","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAGvD;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAA2B,MAAM,CAAC,WAAW,CACrE,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;IAC3D,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;IAC7B,KAAK;CACN,CAAC,CACH,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,KAAyB,EACzB,CAIW,EACH,EAAE;IACV,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,MAAM,CAAC,GAAG,KAAiB,CAAA;QAC3B,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAA;QAEjC,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;YACtC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,IAAI,EAAE,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAA;QACzF,CAAC;QAED,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;YACd,OAAO,CAAC,CAAC,OAAO,CAAA;QAClB,CAAC;IACH,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM,QAAQ,GAAG,aAAa,CAAC,SAAS,CAAA;IACxC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,qBAAqB,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;AACvF,CAAC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@molecule/app-iap",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "In-App Purchases interface for molecule.dev",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"molecule",
|
|
24
|
+
"iap",
|
|
25
|
+
"in-app-purchases",
|
|
26
|
+
"app-store",
|
|
27
|
+
"play-store",
|
|
28
|
+
"subscriptions"
|
|
29
|
+
],
|
|
30
|
+
"license": "Apache-2.0",
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@molecule/app-bond": "^1.0.0",
|
|
33
|
+
"@molecule/app-i18n": "^1.0.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@molecule/app-bond": "1.0.0",
|
|
37
|
+
"@molecule/app-i18n": "1.0.0",
|
|
38
|
+
"@types/node": "26.1.2",
|
|
39
|
+
"typescript": "6.0.3",
|
|
40
|
+
"vitest": "4.1.10"
|
|
41
|
+
},
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
45
|
+
"directory": "packages/app/features/iap"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/molecule-dev/molecule/tree/main/packages/app/features/iap",
|
|
48
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
}
|
|
52
|
+
}
|