@jskit-ai/store-purchases-web 0.0.0-stage → 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/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ - New package: the `client.store-purchases` capability (`StorePurchasesClientProvider`) and the `storePurchases.device` interface over `@capgo/native-purchases` ^9.0.0 (an optional peer): store prices, buying with the server's purchase intent as Apple's appAccountToken and Google's obfuscatedAccountId, restoring, and each transaction confirmed by `@jskit-ai/store-purchases-core` before it is finished.
package/README.md CHANGED
@@ -1,3 +1,12 @@
1
- # Temporary Holding Version
1
+ # @jskit-ai/store-purchases-web
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ App Store and Google Play purchases inside a JSKIT app built with `@jskit-ai/mobile-capacitor`, beside
4
+ `@jskit-ai/store-purchases-core` on the server. It reaches StoreKit 2 and Play Billing through
5
+ `@capgo/native-purchases` (^9.0.0, which the app installs) and only collects: the server confirms every transaction
6
+ with its store, records it and grants it, and the phone finishes it only after that.
7
+
8
+ `client.store-purchases`: `offers()` (the products with the store's own title and price), `buy({ productId, subjectId })`
9
+ (the server's intent first, then the store's purchase with it as the account token, then the server's confirmation),
10
+ and `restore()`. Transactions the store delivers itself (renewals, Ask to Buy approvals) are confirmed as they arrive.
11
+ `useStoreProducts(storePurchases)` loads the offers for a screen. On the web it answers that purchases are made in the
12
+ app; the web pays through `@jskit-ai/payments-web`.
@@ -0,0 +1,9 @@
1
+ {
2
+ "jskit": {
3
+ "storePurchases": {
4
+ "device": {
5
+ "unavailable": "Purchases are made in the app from the App Store or Google Play."
6
+ }
7
+ }
8
+ }
9
+ }
package/package.json CHANGED
@@ -1,6 +1,69 @@
1
1
  {
2
2
  "name": "@jskit-ai/store-purchases-web",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "scripts": {
6
+ "test": "jskit test"
7
+ },
8
+ "exports": {
9
+ "./client": "./src/client/index.js",
10
+ "./client/types": "./src/client/types.js",
11
+ "./locales/en.json": "./locales/en.json"
12
+ },
13
+ "description": "App Store and Google Play purchases in the app: the store's own prices, buying with the server's intent, restoring, and every transaction confirmed by the server before it is finished.",
14
+ "jskit": {
15
+ "kind": "runtime",
16
+ "capabilities": {
17
+ "provides": [
18
+ "client.store-purchases"
19
+ ],
20
+ "requires": [
21
+ "store-purchases.core"
22
+ ]
23
+ },
24
+ "runtime": {
25
+ "server": {
26
+ "providers": []
27
+ },
28
+ "client": {
29
+ "providers": [
30
+ {
31
+ "entrypoint": "src/client/StorePurchasesClientProvider.js",
32
+ "export": "StorePurchasesClientProvider"
33
+ }
34
+ ]
35
+ }
36
+ },
37
+ "metadata": {
38
+ "apiSummary": {
39
+ "surfaces": [
40
+ {
41
+ "subpath": "./client",
42
+ "summary": "Exports StorePurchasesClientProvider, useStoreProducts() and the storePurchases.device interface (createStoreDevice, NO_STORE_DEVICE)."
43
+ },
44
+ {
45
+ "subpath": "./client/types",
46
+ "summary": "Types of the client.store-purchases capability, store products, offers and transactions."
47
+ }
48
+ ],
49
+ "capabilities": [
50
+ "client.store-purchases"
51
+ ]
52
+ }
53
+ }
54
+ },
55
+ "dependencies": {
56
+ "@jskit-ai/store-purchases-core": "0.1.0"
57
+ },
58
+ "peerDependencies": {
59
+ "@capgo/native-purchases": "^9.0.0",
60
+ "@jskit-ai/http-web": "0.2.83",
61
+ "@jskit-ai/kernel": "0.2.41",
62
+ "vue": "^3.5.44"
63
+ },
64
+ "peerDependenciesMeta": {
65
+ "@capgo/native-purchases": {
66
+ "optional": true
67
+ }
68
+ }
69
+ }
@@ -0,0 +1,75 @@
1
+ import { defineProvider } from "@jskit-ai/kernel/shared/capabilities";
2
+ import { getHttpWebClient } from "@jskit-ai/http-web/client";
3
+ import { NATIVE_PURCHASES, NO_STORE_DEVICE, createStoreDevice } from "./native/storeDevice.js";
4
+ import { createStorePurchase } from "./purchase.js";
5
+
6
+ /**
7
+ * The page's store purchases: products with the store's own prices, buying, restoring, and the store's own
8
+ * transactions (renewals, approvals) confirmed as they arrive. On the web every call answers that purchases are made
9
+ * in the app; the web pays through payments-web.
10
+ * @param {{ mobile: import("./types.js").StorePurchasesMobile | null, logger: import("@jskit-ai/kernel/client/types").ClientLogger }} options
11
+ */
12
+ function createStorePurchasesClient({ mobile, logger }) {
13
+ const device = mobile?.appShell?.native === true
14
+ ? createStoreDevice({ plugin: mobile.nativePlugin(NATIVE_PURCHASES), platform: mobile.appShell.platform })
15
+ : NO_STORE_DEVICE;
16
+ const purchases = createStorePurchase({ device, request: (path, options) => getHttpWebClient().request(path, options) });
17
+ let stopListening = () => {};
18
+
19
+ /** The products for sale with the store's title and price in the person's country. */
20
+ async function offers() {
21
+ return device.offers(await purchases.products());
22
+ }
23
+
24
+ function start() {
25
+ stopListening = device.onTransaction((transaction) => {
26
+ purchases.confirm(transaction).catch((error) => {
27
+ logger.warn({ error: String(error?.message || error) }, "A store transaction could not be confirmed; restoring confirms it again.");
28
+ });
29
+ });
30
+ }
31
+
32
+ function stop() {
33
+ stopListening();
34
+ }
35
+
36
+ return Object.freeze({
37
+ available: device.available,
38
+ offers,
39
+ buy: purchases.buy,
40
+ restore: purchases.restore,
41
+ start,
42
+ stop
43
+ });
44
+ }
45
+
46
+ const StorePurchasesClientProvider = defineProvider({
47
+ id: "store-purchases.web.client",
48
+ requires: {
49
+ logger: "client.logger"
50
+ },
51
+ optional: {
52
+ mobile: "client.mobile"
53
+ },
54
+ provides: {
55
+ storePurchases: "client.store-purchases"
56
+ },
57
+ /**
58
+ * @param {object} capabilities
59
+ * @param {import("@jskit-ai/kernel/client/types").ClientLogger} capabilities.logger
60
+ * @param {import("./types.js").StorePurchasesMobile | null} capabilities.mobile
61
+ */
62
+ setup({ logger, mobile }) {
63
+ return { storePurchases: createStorePurchasesClient({ mobile, logger }) };
64
+ },
65
+ /** @param {unknown} _capabilities @param {{ outputs: { storePurchases: import("./types.js").StorePurchasesClient } }} lifecycle */
66
+ boot(_capabilities, { outputs }) {
67
+ outputs.storePurchases.start();
68
+ },
69
+ /** @param {unknown} _capabilities @param {{ outputs: { storePurchases: import("./types.js").StorePurchasesClient } }} lifecycle */
70
+ shutdown(_capabilities, { outputs }) {
71
+ outputs.storePurchases.stop();
72
+ }
73
+ });
74
+
75
+ export { StorePurchasesClientProvider, createStorePurchasesClient };
@@ -0,0 +1,7 @@
1
+ import { createTextError, registerJskitMessages } from "@jskit-ai/kernel/client/i18n";
2
+ import en from "../../locales/en.json" with { type: "json" };
3
+
4
+ // store-purchases-web's English, registered on import so its errors render in the user's language.
5
+ registerJskitMessages(en);
6
+
7
+ export { createTextError };
@@ -0,0 +1,3 @@
1
+ export { StorePurchasesClientProvider } from "./StorePurchasesClientProvider.js";
2
+ export { NO_STORE_DEVICE, createStoreDevice } from "./native/storeDevice.js";
3
+ export { useStoreProducts } from "./useStoreProducts.js";
@@ -0,0 +1,115 @@
1
+ import { createTextError } from "../i18n.js";
2
+
3
+ // The `storePurchases.device` interface: the phone's own store, StoreKit 2 on iOS and Play Billing on Android, through
4
+ // @capgo/native-purchases, which JSKIT reaches through Capacitor's bridge as "NativePurchases". It only collects:
5
+ // the signed transaction (iOS) or the purchase token (Android) goes to the server, which decides and grants. The
6
+ // server acknowledges Play purchases, so the device never does; the app finishes an iOS transaction once the server
7
+ // has granted it.
8
+
9
+ const NATIVE_PURCHASES = "NativePurchases";
10
+
11
+ /**
12
+ * @typedef {object} StoreDevice
13
+ * @property {boolean} available
14
+ * @property {"ios" | "android" | "web"} platform
15
+ * @property {(products: ReadonlyArray<import("../types.js").StoreProduct>) => Promise<ReadonlyArray<import("../types.js").StoreOffer>>} offers
16
+ * @property {(product: import("../types.js").StoreProduct, accountToken: string) => Promise<import("../types.js").StoreTransaction>} purchase
17
+ * @property {(transactionId: string) => Promise<void>} finish
18
+ * @property {() => Promise<ReadonlyArray<import("../types.js").StoreTransaction>>} restore
19
+ * @property {(handler: (transaction: import("../types.js").StoreTransaction) => void) => () => void} onTransaction
20
+ */
21
+
22
+ /** @type {StoreDevice} */
23
+ const NO_STORE_DEVICE = Object.freeze({
24
+ available: false,
25
+ platform: "web",
26
+ offers: async () => Object.freeze([]),
27
+ purchase: async () => {
28
+ throw createTextError("jskit.storePurchases.device.unavailable");
29
+ },
30
+ finish: async () => {},
31
+ restore: async () => Object.freeze([]),
32
+ onTransaction: () => () => {}
33
+ });
34
+
35
+ /**
36
+ * @param {object} options
37
+ * @param {import("../types.js").NativePurchasesPlugin | null} options.plugin null on the web and when the app has not installed it.
38
+ * @param {"ios" | "android"} options.platform
39
+ */
40
+ function createStoreDevice({ plugin, platform }) {
41
+ if (plugin === null) return NO_STORE_DEVICE;
42
+ const storeIdOf = (product) => (platform === "ios" ? product.appStoreProductId : product.playProductId);
43
+ const typeOf = (product) => (product.kind === "subscription" ? "subs" : "inapp");
44
+
45
+ /** What the server confirms: the signed transaction on iOS, the purchase token on Android. */
46
+ function transactionOf(transaction) {
47
+ return Object.freeze({
48
+ platform,
49
+ transactionId: String(transaction.transactionId || ""),
50
+ storeProductId: String(transaction.productIdentifier || ""),
51
+ signedTransaction: platform === "ios" ? String(transaction.jwsRepresentation || "") : "",
52
+ purchaseToken: platform === "android" ? String(transaction.purchaseToken || "") : ""
53
+ });
54
+ }
55
+
56
+ /** The products' prices and titles as the store shows them in the person's country. */
57
+ async function offers(products) {
58
+ const found = [];
59
+ for (const kind of ["inapp", "subs"]) {
60
+ const wanted = products.filter((product) => typeOf(product) === kind && storeIdOf(product));
61
+ if (!wanted.length) continue;
62
+ const { products: details } = await plugin.getProducts({ productIdentifiers: wanted.map(storeIdOf), productType: kind });
63
+ for (const detail of details) {
64
+ const product = wanted.find((item) => storeIdOf(item) === detail.identifier || storeIdOf(item) === detail.planIdentifier);
65
+ if (product) found.push(Object.freeze({ productId: product.id, title: String(detail.title || ""), price: String(detail.priceString || ""), currency: String(detail.currencyCode || "") }));
66
+ }
67
+ }
68
+ return Object.freeze(found);
69
+ }
70
+
71
+ /** Buys a product with the server's intent as the account token; answers what the server confirms. */
72
+ async function purchase(product, accountToken) {
73
+ await plugin.configure({ autoFinishTransactions: false });
74
+ const transaction = await plugin.purchaseProduct({
75
+ productIdentifier: storeIdOf(product),
76
+ productType: typeOf(product),
77
+ appAccountToken: accountToken,
78
+ isConsumable: false,
79
+ autoAcknowledgePurchases: false
80
+ });
81
+ return transactionOf(transaction);
82
+ }
83
+
84
+ /** Finishes an iOS transaction once the server granted it; Android's the server acknowledged itself. */
85
+ async function finish(transactionId) {
86
+ if (platform === "ios" && transactionId) await plugin.finishTransaction({ transactionId });
87
+ }
88
+
89
+ /** Asks the store again for the person's purchases, then answers each one, for the server to confirm. */
90
+ async function restore() {
91
+ await plugin.restorePurchases();
92
+ const { purchases } = await plugin.getPurchases({});
93
+ return Object.freeze(purchases.map(transactionOf));
94
+ }
95
+
96
+ /** Transactions the store delivers on its own (a renewal, an Ask to Buy approval, a purchase finished elsewhere). */
97
+ function onTransaction(handler) {
98
+ const listener = Promise.resolve(plugin.addListener("transactionUpdated", (transaction) => handler(transactionOf(transaction))));
99
+ return () => {
100
+ void listener.then((handle) => handle.remove());
101
+ };
102
+ }
103
+
104
+ return Object.freeze({
105
+ available: true,
106
+ platform,
107
+ offers,
108
+ purchase,
109
+ finish,
110
+ restore,
111
+ onTransaction
112
+ });
113
+ }
114
+
115
+ export { NATIVE_PURCHASES, NO_STORE_DEVICE, createStoreDevice };
@@ -0,0 +1,59 @@
1
+ // A store purchase from start to grant: the server's intent, the store's purchase with it, the server's confirmation,
2
+ // and only then the transaction finished on the phone. Restoring and the store's own transactions confirm the same way.
3
+
4
+ const PATHS = Object.freeze({
5
+ PRODUCTS: "/api/store-purchases/products",
6
+ INTENTS: "/api/store-purchases/intents",
7
+ APPLE: "/api/store-purchases/apple/transactions",
8
+ GOOGLE: "/api/store-purchases/google/purchases"
9
+ });
10
+
11
+ /**
12
+ * @param {object} options
13
+ * @param {import("./native/storeDevice.js").StoreDevice} options.device
14
+ * @param {(path: string, options?: object) => Promise<any>} options.request The page's HTTP client's request.
15
+ */
16
+ function createStorePurchase({ device, request }) {
17
+ let catalogue = null;
18
+
19
+ /** The products for sale, read once from the server. */
20
+ async function products() {
21
+ catalogue ??= request(PATHS.PRODUCTS, { method: "GET" });
22
+ return catalogue;
23
+ }
24
+
25
+ /** The server's confirmation of one transaction; the phone finishes it once it is granted. */
26
+ async function confirm(transaction) {
27
+ const answer = transaction.platform === "ios"
28
+ ? await request(PATHS.APPLE, { method: "POST", body: { signedTransaction: transaction.signedTransaction } })
29
+ : await request(PATHS.GOOGLE, { method: "POST", body: { productId: transaction.storeProductId, purchaseToken: transaction.purchaseToken } });
30
+ if (answer.finish) await device.finish(transaction.transactionId);
31
+ return answer;
32
+ }
33
+
34
+ /**
35
+ * Buys a product for an account the signed-in person may buy for (`subjectId`, by the web checkout's rule).
36
+ * @param {{ productId: string, subjectId: string }} input
37
+ */
38
+ async function buy({ productId, subjectId }) {
39
+ const product = (await products()).find((item) => item.id === productId);
40
+ const intent = await request(PATHS.INTENTS, { method: "POST", body: { productId, subjectId } });
41
+ return confirm(await device.purchase(product, intent.appAccountToken));
42
+ }
43
+
44
+ /** Restores the person's purchases: each confirmed again, which grants nothing twice. */
45
+ async function restore() {
46
+ const results = [];
47
+ for (const transaction of await device.restore()) results.push(await confirm(transaction));
48
+ return Object.freeze(results);
49
+ }
50
+
51
+ return Object.freeze({
52
+ products,
53
+ buy,
54
+ restore,
55
+ confirm
56
+ });
57
+ }
58
+
59
+ export { createStorePurchase };
@@ -0,0 +1,30 @@
1
+ // The types of store-purchases-web's `client.store-purchases` capability.
2
+
3
+ /** @typedef {ReturnType<typeof import("./StorePurchasesClientProvider.js").createStorePurchasesClient>} StorePurchasesClient */
4
+
5
+ /** @typedef {{ id: string, kind: "subscription" | "consumable" | "nonConsumable", appStoreProductId: string, playProductId: string }} StoreProduct */
6
+
7
+ /** @typedef {{ productId: string, title: string, price: string, currency: string }} StoreOffer */
8
+
9
+ /** @typedef {{ platform: "ios" | "android", transactionId: string, storeProductId: string, signedTransaction: string, purchaseToken: string }} StoreTransaction */
10
+
11
+ /**
12
+ * The part of @capgo/native-purchases store-purchases-web calls.
13
+ * @typedef {object} NativePurchasesPlugin
14
+ * @property {(options: { autoFinishTransactions: boolean }) => Promise<void>} configure
15
+ * @property {(options: { productIdentifiers: string[], productType: string }) => Promise<{ products: Array<Record<string, any>> }>} getProducts
16
+ * @property {(options: Record<string, unknown>) => Promise<Record<string, any>>} purchaseProduct
17
+ * @property {(options: { transactionId: string }) => Promise<void>} finishTransaction
18
+ * @property {() => Promise<void>} restorePurchases
19
+ * @property {(options: object) => Promise<{ purchases: Array<Record<string, any>> }>} getPurchases
20
+ * @property {(event: string, listener: (value: any) => void) => Promise<{ remove: () => Promise<void> }>} addListener
21
+ */
22
+
23
+ /**
24
+ * The part of the optional `client.mobile` capability store-purchases-web uses.
25
+ * @typedef {object} StorePurchasesMobile
26
+ * @property {{ native: boolean, platform: "web" | "ios" | "android" }} appShell
27
+ * @property {<T>(name: string) => T | null} nativePlugin
28
+ */
29
+
30
+ export {};
@@ -0,0 +1,29 @@
1
+ import { onMounted, ref } from "vue";
2
+
3
+ /**
4
+ * The products for sale with the store's own title and price, for a screen that sells them: `offers` once loaded,
5
+ * `loading`, and `error` when the store or the server did not answer (`reload` tries again).
6
+ * @param {import("./types.js").StorePurchasesClient} storePurchases
7
+ */
8
+ function useStoreProducts(storePurchases) {
9
+ const offers = ref([]);
10
+ const loading = ref(true);
11
+ const error = ref(null);
12
+
13
+ async function reload() {
14
+ loading.value = true;
15
+ error.value = null;
16
+ try {
17
+ offers.value = await storePurchases.offers();
18
+ } catch (failure) {
19
+ error.value = failure;
20
+ } finally {
21
+ loading.value = false;
22
+ }
23
+ }
24
+
25
+ onMounted(reload);
26
+ return { offers, loading, error, reload };
27
+ }
28
+
29
+ export { useStoreProducts };
@@ -0,0 +1,16 @@
1
+ import assert from "node:assert/strict";
2
+ import path from "node:path";
3
+ import test from "node:test";
4
+ import { fileURLToPath } from "node:url";
5
+ import { evaluateI18nCatalogContract } from "../../../tooling/test-support/i18nCatalogContract.mjs";
6
+
7
+ const TEST_DIRECTORY = path.dirname(fileURLToPath(import.meta.url));
8
+ const REPO_ROOT = path.resolve(TEST_DIRECTORY, "..", "..", "..");
9
+
10
+ test("store-purchases-web English catalog matches its source", () => {
11
+ const { problems } = evaluateI18nCatalogContract({
12
+ repoRoot: REPO_ROOT,
13
+ packageDir: path.join(REPO_ROOT, "packages", "store-purchases-web")
14
+ });
15
+ assert.deepEqual(problems, []);
16
+ });
@@ -0,0 +1,84 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { createStoreDevice } from "../src/client/native/storeDevice.js";
4
+ import { createStorePurchase } from "../src/client/purchase.js";
5
+
6
+ const PRODUCTS = [
7
+ { id: "credits-100", kind: "consumable", appStoreProductId: "com.example.credits100", playProductId: "credits_100" },
8
+ { id: "pro-monthly", kind: "subscription", appStoreProductId: "com.example.pro.monthly", playProductId: "pro_monthly" }
9
+ ];
10
+
11
+ /** @capgo/native-purchases as the bridge gives it, recording each call. */
12
+ function fakeNativePurchases(transaction) {
13
+ const calls = [];
14
+ const listeners = new Map();
15
+ return {
16
+ calls,
17
+ listeners,
18
+ async configure(options) { calls.push(["configure", options]); },
19
+ async getProducts({ productIdentifiers, productType }) {
20
+ calls.push(["getProducts", productType, productIdentifiers]);
21
+ return { products: productIdentifiers.map((identifier) => ({ identifier, title: `Title ${identifier}`, priceString: "€4.99", currencyCode: "EUR" })) };
22
+ },
23
+ async purchaseProduct(options) { calls.push(["purchaseProduct", options]); return transaction; },
24
+ async finishTransaction(options) { calls.push(["finishTransaction", options.transactionId]); },
25
+ async restorePurchases() { calls.push(["restorePurchases"]); },
26
+ async getPurchases() { return { purchases: [transaction] }; },
27
+ async addListener(event, listener) {
28
+ listeners.set(event, listener);
29
+ return { remove: async () => listeners.delete(event) };
30
+ }
31
+ };
32
+ }
33
+
34
+ /** The server as the device sees it: products, intents, confirmations; records each request. */
35
+ function fakeServer(answer = { status: "granted", finish: true }) {
36
+ const sent = [];
37
+ return {
38
+ sent,
39
+ request: async (path, options) => {
40
+ sent.push([options.method, path, options.body]);
41
+ if (path === "/api/store-purchases/products") return PRODUCTS;
42
+ if (path === "/api/store-purchases/intents") return { appAccountToken: "11111111-1111-4111-8111-111111111111" };
43
+ return answer;
44
+ }
45
+ };
46
+ }
47
+
48
+ test("on iOS a purchase carries the server's intent, sends the signed transaction, and is finished only after the grant", async () => {
49
+ const plugin = fakeNativePurchases({ transactionId: "2000000000000001", productIdentifier: "com.example.credits100", jwsRepresentation: "eyJ.signed.jws" });
50
+ const device = createStoreDevice({ plugin, platform: "ios" });
51
+ const server = fakeServer();
52
+ const result = await createStorePurchase({ device, request: server.request }).buy({ productId: "credits-100", subjectId: "own-1" });
53
+ assert.equal(result.status, "granted");
54
+ assert.deepEqual(plugin.calls.find(([name]) => name === "purchaseProduct")[1], {
55
+ productIdentifier: "com.example.credits100", productType: "inapp", appAccountToken: "11111111-1111-4111-8111-111111111111", isConsumable: false, autoAcknowledgePurchases: false
56
+ });
57
+ assert.deepEqual(server.sent.slice(1), [
58
+ ["POST", "/api/store-purchases/intents", { productId: "credits-100", subjectId: "own-1" }],
59
+ ["POST", "/api/store-purchases/apple/transactions", { signedTransaction: "eyJ.signed.jws" }]
60
+ ]);
61
+ assert.deepEqual(plugin.calls.at(-1), ["finishTransaction", "2000000000000001"]);
62
+ });
63
+
64
+ test("on Android the purchase token goes to the server, which acknowledges it; nothing is finished before a grant", async () => {
65
+ const plugin = fakeNativePurchases({ transactionId: "GPA.1", productIdentifier: "pro_monthly", purchaseToken: "play-token" });
66
+ const device = createStoreDevice({ plugin, platform: "android" });
67
+ const server = fakeServer({ status: "unattributed" });
68
+ await createStorePurchase({ device, request: server.request }).buy({ productId: "pro-monthly", subjectId: "team" });
69
+ assert.equal(plugin.calls.find(([name]) => name === "purchaseProduct")[1].productType, "subs");
70
+ assert.deepEqual(server.sent.at(-1), ["POST", "/api/store-purchases/google/purchases", { productId: "pro_monthly", purchaseToken: "play-token" }]);
71
+ assert.ok(!plugin.calls.some(([name]) => name === "finishTransaction"));
72
+ });
73
+
74
+ test("offers show the store's own prices; restoring confirms each purchase again", async () => {
75
+ const plugin = fakeNativePurchases({ transactionId: "7", productIdentifier: "com.example.credits100", jwsRepresentation: "jws-7" });
76
+ const device = createStoreDevice({ plugin, platform: "ios" });
77
+ const offers = await device.offers(PRODUCTS);
78
+ assert.deepEqual(offers.map((offer) => [offer.productId, offer.price]), [["credits-100", "€4.99"], ["pro-monthly", "€4.99"]]);
79
+ const server = fakeServer();
80
+ const restored = await createStorePurchase({ device, request: server.request }).restore();
81
+ assert.equal(restored.length, 1);
82
+ assert.deepEqual(server.sent.at(-1), ["POST", "/api/store-purchases/apple/transactions", { signedTransaction: "jws-7" }]);
83
+ assert.equal(createStoreDevice({ plugin: null, platform: "ios" }).available, false);
84
+ });