@nosslabs/iap 7.0.0 → 8.0.0-next.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 CHANGED
@@ -5,6 +5,92 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); version
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [8.0.0-next.0] — 2026-08-17
9
+
10
+ **First release of the Capacitor 8 line, on the `@next` npm dist-tag.** The
11
+ Capacitor 7 line continues as `7.x` on `@latest` (and on the new `@latest-7`
12
+ dist-tag); `@latest` stays at `7.1.0` until the 8.x line graduates. Install the
13
+ candidate with `npm install @nosslabs/iap@next`.
14
+
15
+ Note that `@next` previously pointed at `7.0.0-next.0`, a Capacitor 7
16
+ prerelease; it now moves to the Capacitor 8 line. `7.0.0-next.0` remains
17
+ installable by exact version.
18
+
19
+ **Opens the Capacitor 8 line.** Same library, next platform major: the peer
20
+ range moves from Capacitor 7 to Capacitor 8, and nothing else changes. Cap-7
21
+ consumers stay on `7.x` — `^7` ranges don't auto-resolve to `8.x`.
22
+
23
+ ### Changed (BREAKING, vs `7.1.0` — peer range only)
24
+
25
+ - **Anchored the `8.x` line to Capacitor 8.** Peer dependencies moved to
26
+ `@capacitor/core`, `@capacitor/preferences` and (optional) `@capacitor/app`
27
+ at `>=8.0.0` — the forward-open range that upstream `@capacitor/*` plugins
28
+ and `@capgo/native-purchases` themselves declare — and
29
+ `@capgo/native-purchases` at `^8.0.0`, which stays a caret because the
30
+ adapter binds to its method signatures. The Cap-7 ranges
31
+ (`@capacitor/*: ^7.0.0`, `@capgo/native-purchases: ^7.16.2`) are dropped —
32
+ they were the only thing blocking a clean `npm install` in a Capacitor 8 app.
33
+ Upgrading is a peer-dep bump plus `npx cap sync`.
34
+ - **`VERSION` is now typed `string` rather than the literal `"0.1.0"`.** It is
35
+ injected from `package.json` at build time instead of being hard-coded, so
36
+ it finally reports the version that is actually installed.
37
+
38
+ ### Fixed
39
+
40
+ - **CommonJS consumers can type-check again.** The `exports` map declared a
41
+ single top-level `types` entry, so `require()` resolved the CommonJS bundle
42
+ against ESM declarations and `tsc` failed with TS1479 under
43
+ `moduleResolution: node16`/`nodenext`. `types` is now nested per condition,
44
+ with `require` pointing at the `dist/index.d.cts` the build already emitted.
45
+ Affects `7.1.0` and earlier too.
46
+ - **`VERSION` no longer reports `0.1.0`.** It was hard-coded and never updated
47
+ by any publish step, so error reports from every released build
48
+ misattributed their version.
49
+
50
+ ### Notes
51
+
52
+ - **No runtime API changes.** `createIAP({ ... })` config, the `IAP` instance
53
+ surface, the event map, the error codes and the backend contract are all
54
+ byte-for-byte what `7.1.0` shipped. Nothing in `src/` needed a call-site fix:
55
+ every `@capgo/native-purchases` method this library calls
56
+ (`isBillingSupported`, `getProducts`, `purchaseProduct`, `getPurchases`,
57
+ `acknowledgePurchase`, `manageSubscriptions`, `getStorefront`) keeps its
58
+ `7.16.2` signature in `8.6.5`. The plugin's v8 additions — `consumePurchase()`,
59
+ `presentOfferCodeRedeemSheet()`, the `billingPlanType` purchase option, the
60
+ `onlyCurrentEntitlements` filter on `getPurchases()`, and the StoreKit
61
+ commitment/renewal metadata on `Product` and `Transaction` — are all optional
62
+ and none are consumed.
63
+ - **`getStorefront()` keeps its capability probe.** The plugin declares
64
+ `getStorefront()` on its TypeScript interface as of `8.5.0`, but the peer
65
+ range also admits `8.0.0`–`8.4.x`, which don't register the native method. The
66
+ adapter therefore still gates on the Capacitor plugin header rather than the
67
+ declared type, and still resolves `null` when the method is absent — including
68
+ for the plugin's own "storefront unavailable" signal, an empty `countryCode`.
69
+
70
+ ## [7.1.0] — 2026-07-04
71
+
72
+ ### Added
73
+
74
+ - `iap.getStorefront(): Promise<Storefront | null>` — reads the user's App
75
+ Store / Google Play storefront (the country their store account is registered
76
+ to). Returns the new exported `Storefront` type, with `countryCode` normalized
77
+ to ISO 3166-1 alpha-2 across platforms (iOS reports alpha-3, Android alpha-2);
78
+ the raw native value is preserved on `countryCodeRaw`, plus the Apple
79
+ `storefrontId` (iOS only) and `platform`. Resolves `null` on web, when the
80
+ installed `@capgo/native-purchases` build doesn't register the native
81
+ `getStorefront` method, or when the storefront is unavailable (e.g. EU
82
+ alternative distribution). Read it live and treat it as a UX/targeting hint —
83
+ for compliance/entitlement decisions, trust the server-side signed storefront.
84
+
85
+ ### Changed
86
+
87
+ - Anchored the `7.x` line to **Capacitor 7**: peer dependencies narrowed to
88
+ `@capacitor/*: ^7.0.0` and `@capgo/native-purchases: ^7.16.2` (dropping the
89
+ `^8.0.0` allowances). The `^7.16.2` range admits the Capacitor-7 capgo build
90
+ that adds native `getStorefront`. Capacitor-8 support will ship in
91
+ `@nosslabs/iap` v8. (`getStorefront()` itself still degrades gracefully on
92
+ capgo builds that predate the native method.)
93
+
8
94
  ## [7.0.0] — 2026-05-14
9
95
 
10
96
  **GA of the Capacitor 7+ line.** `@latest` on npm moves from `5.0.0`
package/README.md CHANGED
@@ -2,10 +2,15 @@
2
2
 
3
3
  > Thin Capacitor IAP orchestrator. Server-side validation via [Attesto](https://attesto.nossdev.com).
4
4
 
5
- **Status: `7.0.0` — GA on `@latest`** (the Capacitor 7+ line, built on `@capgo/native-purchases`). The Capacitor 5 line (`cordova-plugin-purchase`) continues as `5.x` from the `5.x` branch — `^5` ranges still resolve to `5.x`. See the [CHANGELOG](./CHANGELOG.md) for the GA delta and [Migration](https://iap.nossdev.com/migration/) for upgrading from `5.x`.
5
+ **Status: `8.0.0-next.0` — the Capacitor 8 line, on `@next`** (built on `@capgo/native-purchases@^8`). `@latest` remains `7.1.0` (Capacitor 7) while the 8.x line soaks. The Capacitor 7 line continues as `7.x` (also on `@latest-7`) and the Capacitor 5 line (`cordova-plugin-purchase`) as `5.x` — `^7` and `^5` ranges still resolve to their own lines. See the [CHANGELOG](./CHANGELOG.md) for the `8.0.0-next.0` delta and [Migration](https://iap.nossdev.com/migration/).
6
6
 
7
7
  ```bash
8
- npm install @nosslabs/iap @capgo/native-purchases
8
+ # Capacitor 8 — release candidate, on @next
9
+ npm install @nosslabs/iap@next @capgo/native-purchases
10
+
11
+ # Capacitor 7 — the current @latest line
12
+ npm install @nosslabs/iap @capgo/native-purchases@lts-v7
13
+
9
14
  npx cap sync
10
15
  ```
11
16
 
@@ -77,8 +82,9 @@ It does **not**: talk to Attesto directly, define entitlement business logic, ma
77
82
 
78
83
  | `@nosslabs/iap` | Capacitor | Native plugin | dist-tag | Status |
79
84
  |---|---|---|---|---|
80
- | 7.x | 7.x (also runs on 8.x) | `@capgo/native-purchases 7.16.x` (or `^8` on Cap 8) | `@latest` | **Current** |
81
- | 5.x | 5.x | `cordova-plugin-purchase ^13.x` | (pinned via `^5`) | Maintenance |
85
+ | 8.x | 8.x and later | `@capgo/native-purchases ^8` | `@next` | **Release candidate** — `8.0.0-next.0` |
86
+ | 7.x | 7.x | `@capgo/native-purchases@lts-v7` | `@latest`, `@latest-7` | **Current** |
87
+ | 5.x | 5.x | `cordova-plugin-purchase ^13.x` | `@latest-5` (pin via `^5`) | Maintenance |
82
88
 
83
89
  ## Optional peer dependency
84
90
 
package/dist/index.cjs CHANGED
@@ -139,11 +139,293 @@ var init_platform = __esm({
139
139
  }
140
140
  });
141
141
 
142
+ // src/lib/iso-country.ts
143
+ function toAlpha2(code) {
144
+ if (!code) return null;
145
+ const normalized = code.trim().toUpperCase();
146
+ if (normalized.length === 2) return normalized;
147
+ if (normalized.length === 3) return ALPHA3_TO_ALPHA2[normalized] ?? null;
148
+ return null;
149
+ }
150
+ var ALPHA3_TO_ALPHA2;
151
+ var init_iso_country = __esm({
152
+ "src/lib/iso-country.ts"() {
153
+ ALPHA3_TO_ALPHA2 = {
154
+ ABW: "AW",
155
+ AFG: "AF",
156
+ AGO: "AO",
157
+ AIA: "AI",
158
+ ALA: "AX",
159
+ ALB: "AL",
160
+ AND: "AD",
161
+ ARE: "AE",
162
+ ARG: "AR",
163
+ ARM: "AM",
164
+ ASM: "AS",
165
+ ATA: "AQ",
166
+ ATF: "TF",
167
+ ATG: "AG",
168
+ AUS: "AU",
169
+ AUT: "AT",
170
+ AZE: "AZ",
171
+ BDI: "BI",
172
+ BEL: "BE",
173
+ BEN: "BJ",
174
+ BES: "BQ",
175
+ BFA: "BF",
176
+ BGD: "BD",
177
+ BGR: "BG",
178
+ BHR: "BH",
179
+ BHS: "BS",
180
+ BIH: "BA",
181
+ BLM: "BL",
182
+ BLR: "BY",
183
+ BLZ: "BZ",
184
+ BMU: "BM",
185
+ BOL: "BO",
186
+ BRA: "BR",
187
+ BRB: "BB",
188
+ BRN: "BN",
189
+ BTN: "BT",
190
+ BVT: "BV",
191
+ BWA: "BW",
192
+ CAF: "CF",
193
+ CAN: "CA",
194
+ CCK: "CC",
195
+ CHE: "CH",
196
+ CHL: "CL",
197
+ CHN: "CN",
198
+ CIV: "CI",
199
+ CMR: "CM",
200
+ COD: "CD",
201
+ COG: "CG",
202
+ COK: "CK",
203
+ COL: "CO",
204
+ COM: "KM",
205
+ CPV: "CV",
206
+ CRI: "CR",
207
+ CUB: "CU",
208
+ CUW: "CW",
209
+ CXR: "CX",
210
+ CYM: "KY",
211
+ CYP: "CY",
212
+ CZE: "CZ",
213
+ DEU: "DE",
214
+ DJI: "DJ",
215
+ DMA: "DM",
216
+ DNK: "DK",
217
+ DOM: "DO",
218
+ DZA: "DZ",
219
+ ECU: "EC",
220
+ EGY: "EG",
221
+ ERI: "ER",
222
+ ESH: "EH",
223
+ ESP: "ES",
224
+ EST: "EE",
225
+ ETH: "ET",
226
+ FIN: "FI",
227
+ FJI: "FJ",
228
+ FLK: "FK",
229
+ FRA: "FR",
230
+ FRO: "FO",
231
+ FSM: "FM",
232
+ GAB: "GA",
233
+ GBR: "GB",
234
+ GEO: "GE",
235
+ GGY: "GG",
236
+ GHA: "GH",
237
+ GIB: "GI",
238
+ GIN: "GN",
239
+ GLP: "GP",
240
+ GMB: "GM",
241
+ GNB: "GW",
242
+ GNQ: "GQ",
243
+ GRC: "GR",
244
+ GRD: "GD",
245
+ GRL: "GL",
246
+ GTM: "GT",
247
+ GUF: "GF",
248
+ GUM: "GU",
249
+ GUY: "GY",
250
+ HKG: "HK",
251
+ HMD: "HM",
252
+ HND: "HN",
253
+ HRV: "HR",
254
+ HTI: "HT",
255
+ HUN: "HU",
256
+ IDN: "ID",
257
+ IMN: "IM",
258
+ IND: "IN",
259
+ IOT: "IO",
260
+ IRL: "IE",
261
+ IRN: "IR",
262
+ IRQ: "IQ",
263
+ ISL: "IS",
264
+ ISR: "IL",
265
+ ITA: "IT",
266
+ JAM: "JM",
267
+ JEY: "JE",
268
+ JOR: "JO",
269
+ JPN: "JP",
270
+ KAZ: "KZ",
271
+ KEN: "KE",
272
+ KGZ: "KG",
273
+ KHM: "KH",
274
+ KIR: "KI",
275
+ KNA: "KN",
276
+ KOR: "KR",
277
+ KWT: "KW",
278
+ LAO: "LA",
279
+ LBN: "LB",
280
+ LBR: "LR",
281
+ LBY: "LY",
282
+ LCA: "LC",
283
+ LIE: "LI",
284
+ LKA: "LK",
285
+ LSO: "LS",
286
+ LTU: "LT",
287
+ LUX: "LU",
288
+ LVA: "LV",
289
+ MAC: "MO",
290
+ MAF: "MF",
291
+ MAR: "MA",
292
+ MCO: "MC",
293
+ MDA: "MD",
294
+ MDG: "MG",
295
+ MDV: "MV",
296
+ MEX: "MX",
297
+ MHL: "MH",
298
+ MKD: "MK",
299
+ MLI: "ML",
300
+ MLT: "MT",
301
+ MMR: "MM",
302
+ MNE: "ME",
303
+ MNG: "MN",
304
+ MNP: "MP",
305
+ MOZ: "MZ",
306
+ MRT: "MR",
307
+ MSR: "MS",
308
+ MTQ: "MQ",
309
+ MUS: "MU",
310
+ MWI: "MW",
311
+ MYS: "MY",
312
+ MYT: "YT",
313
+ NAM: "NA",
314
+ NCL: "NC",
315
+ NER: "NE",
316
+ NFK: "NF",
317
+ NGA: "NG",
318
+ NIC: "NI",
319
+ NIU: "NU",
320
+ NLD: "NL",
321
+ NOR: "NO",
322
+ NPL: "NP",
323
+ NRU: "NR",
324
+ NZL: "NZ",
325
+ OMN: "OM",
326
+ PAK: "PK",
327
+ PAN: "PA",
328
+ PCN: "PN",
329
+ PER: "PE",
330
+ PHL: "PH",
331
+ PLW: "PW",
332
+ PNG: "PG",
333
+ POL: "PL",
334
+ PRI: "PR",
335
+ PRK: "KP",
336
+ PRT: "PT",
337
+ PRY: "PY",
338
+ PSE: "PS",
339
+ PYF: "PF",
340
+ QAT: "QA",
341
+ REU: "RE",
342
+ ROU: "RO",
343
+ RUS: "RU",
344
+ RWA: "RW",
345
+ SAU: "SA",
346
+ SDN: "SD",
347
+ SEN: "SN",
348
+ SGP: "SG",
349
+ SGS: "GS",
350
+ SHN: "SH",
351
+ SJM: "SJ",
352
+ SLB: "SB",
353
+ SLE: "SL",
354
+ SLV: "SV",
355
+ SMR: "SM",
356
+ SOM: "SO",
357
+ SPM: "PM",
358
+ SRB: "RS",
359
+ SSD: "SS",
360
+ STP: "ST",
361
+ SUR: "SR",
362
+ SVK: "SK",
363
+ SVN: "SI",
364
+ SWE: "SE",
365
+ SWZ: "SZ",
366
+ SXM: "SX",
367
+ SYC: "SC",
368
+ SYR: "SY",
369
+ TCA: "TC",
370
+ TCD: "TD",
371
+ TGO: "TG",
372
+ THA: "TH",
373
+ TJK: "TJ",
374
+ TKL: "TK",
375
+ TKM: "TM",
376
+ TLS: "TL",
377
+ TON: "TO",
378
+ TTO: "TT",
379
+ TUN: "TN",
380
+ TUR: "TR",
381
+ TUV: "TV",
382
+ TWN: "TW",
383
+ TZA: "TZ",
384
+ UGA: "UG",
385
+ UKR: "UA",
386
+ UMI: "UM",
387
+ URY: "UY",
388
+ USA: "US",
389
+ UZB: "UZ",
390
+ VAT: "VA",
391
+ VCT: "VC",
392
+ VEN: "VE",
393
+ VGB: "VG",
394
+ VIR: "VI",
395
+ VNM: "VN",
396
+ VUT: "VU",
397
+ WLF: "WF",
398
+ WSM: "WS",
399
+ YEM: "YE",
400
+ ZAF: "ZA",
401
+ ZMB: "ZM",
402
+ ZWE: "ZW"
403
+ };
404
+ }
405
+ });
406
+
142
407
  // src/adapters/native/capgo/native-adapter.ts
143
408
  var native_adapter_exports = {};
144
409
  __export(native_adapter_exports, {
145
410
  CapgoNativeAdapter: () => CapgoNativeAdapter
146
411
  });
412
+ function nativeStorefrontRegistered() {
413
+ const headers = core.Capacitor.PluginHeaders;
414
+ return headers?.find((h) => h.name === "NativePurchases")?.methods?.some((m) => m.name === "getStorefront") ?? false;
415
+ }
416
+ function normalizeStorefront(raw) {
417
+ const code = raw?.countryCode?.trim();
418
+ if (!code) return null;
419
+ const platform = getPlatform() === "android" ? "google" : "apple";
420
+ return {
421
+ // alpha-2 when recognized; otherwise the uppercased raw code as a
422
+ // best-effort fallback (see `Storefront.countryCode`).
423
+ countryCode: toAlpha2(code) ?? code.toUpperCase(),
424
+ countryCodeRaw: code,
425
+ storefrontId: raw.storefrontId,
426
+ platform
427
+ };
428
+ }
147
429
  function normalizeProduct(p, type) {
148
430
  const priceMicros = Math.round(p.price * 1e6).toString();
149
431
  return {
@@ -219,6 +501,7 @@ var CapgoNativeAdapter;
219
501
  var init_native_adapter = __esm({
220
502
  "src/adapters/native/capgo/native-adapter.ts"() {
221
503
  init_errors();
504
+ init_iso_country();
222
505
  init_platform();
223
506
  CapgoNativeAdapter = class {
224
507
  async isAvailable() {
@@ -302,6 +585,24 @@ var init_native_adapter = __esm({
302
585
  });
303
586
  }
304
587
  }
588
+ /**
589
+ * Read the current storefront from the native plugin — which is expected to
590
+ * source it from StoreKit 2 `Storefront.current` on iOS (alpha-3) and
591
+ * `getBillingConfigAsync()` on Android (alpha-2) — normalizing `countryCode`
592
+ * to alpha-2. Silent like {@link CapgoNativeAdapter.isAvailable}: any
593
+ * unavailability — older plugin (no native method registered), native
594
+ * rejection, or empty country — resolves to `null` rather than throwing.
595
+ */
596
+ async getStorefront() {
597
+ if (!nativeStorefrontRegistered()) return null;
598
+ const np = nativePurchases.NativePurchases;
599
+ try {
600
+ const raw = await np.getStorefront?.();
601
+ return raw ? normalizeStorefront(raw) : null;
602
+ } catch {
603
+ return null;
604
+ }
605
+ }
305
606
  async dispose() {
306
607
  }
307
608
  };
@@ -832,6 +1133,9 @@ var WebStubAdapter = class {
832
1133
  message: "Subscription management is not supported on the web platform."
833
1134
  });
834
1135
  }
1136
+ async getStorefront() {
1137
+ return null;
1138
+ }
835
1139
  };
836
1140
 
837
1141
  // src/adapters/native/index.ts
@@ -1933,6 +2237,10 @@ function createIAP(input) {
1933
2237
  }
1934
2238
  return state.adapter.getProducts(state.products.map((p) => ({ id: p.id, type: p.type })));
1935
2239
  },
2240
+ async getStorefront() {
2241
+ requireInitialized(state);
2242
+ return state.adapter?.getStorefront?.() ?? null;
2243
+ },
1936
2244
  hasEntitlement(key) {
1937
2245
  return state.entitlements.some((e) => e.key === key);
1938
2246
  },
@@ -1996,7 +2304,7 @@ function requireInitialized(state) {
1996
2304
  init_errors();
1997
2305
 
1998
2306
  // src/version.ts
1999
- var VERSION = "0.1.0";
2307
+ var VERSION = "8.0.0-next.0";
2000
2308
 
2001
2309
  exports.DEFAULT_PERMANENT_ERROR_CODES = DEFAULT_PERMANENT_ERROR_CODES;
2002
2310
  exports.HttpBackendAdapter = HttpBackendAdapter;