@nosslabs/iap 0.3.0 → 0.3.1

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,39 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); version
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [0.3.1] — 2026-05-06
9
+
10
+ ### Added
11
+
12
+ - **`appUserId` async fetcher may now accept an optional `ctx`
13
+ parameter.** The library passes `{ authHeaders }` populated from
14
+ `backend.getAuthHeaders()` (resolved fresh per purchase), letting
15
+ consumers reuse the same auth they configured for IAP-backend
16
+ requests when their UUID-minting endpoint uses that same auth.
17
+ The parameter is optional convenience, not contract — zero-arg
18
+ fetchers from 0.2.x continue to work unchanged. Ignore the
19
+ parameter when your UUID endpoint uses different auth and close
20
+ over your own auth state instead. For consumers using a custom
21
+ `BackendAdapter` (no `getAuthHeaders` configured), `ctx.authHeaders`
22
+ is `{}`.
23
+
24
+ ```ts
25
+ // before — still valid
26
+ appUserId: async () => {
27
+ const r = await fetch('/api/iap/uuid', { headers: authHeaders() });
28
+ return (await r.json()).uuid;
29
+ }
30
+
31
+ // after — equivalent, no helper duplication
32
+ appUserId: async ({ authHeaders }) => {
33
+ const r = await fetch('/api/iap/uuid', { headers: authHeaders });
34
+ return (await r.json()).uuid;
35
+ }
36
+ ```
37
+
38
+ See `docs/guide/getting-started.md` (Pre-attaching a user identifier)
39
+ and `docs/api/types.md` (`AppUserId`) for the updated reference.
40
+
8
41
  ## [0.3.0] — 2026-05-06
9
42
 
10
43
  ### Changed (BREAKING)
package/dist/index.cjs CHANGED
@@ -1232,7 +1232,11 @@ var PurchaseOrchestrator = class {
1232
1232
  message: `Product "${productId}" is not in the configured catalog.`
1233
1233
  });
1234
1234
  }
1235
- const resolvedAppUserId = appUserId !== void 0 ? await resolveAppUserId(appUserId) : void 0;
1235
+ let resolvedAppUserId;
1236
+ if (appUserId !== void 0) {
1237
+ const ctx = typeof appUserId === "function" ? { authHeaders: await this.deps.getAuthHeaders() } : { authHeaders: {} };
1238
+ resolvedAppUserId = await resolveAppUserId(appUserId, ctx);
1239
+ }
1236
1240
  this.inFlight.add(productId);
1237
1241
  this.deps.emitter.emit("purchase-started", { productId });
1238
1242
  try {
@@ -1349,11 +1353,11 @@ var PurchaseOrchestrator = class {
1349
1353
  return { status: "verification_failed", productId, error: iapError };
1350
1354
  }
1351
1355
  };
1352
- async function resolveAppUserId(supply) {
1356
+ async function resolveAppUserId(supply, ctx) {
1353
1357
  let resolved;
1354
1358
  if (typeof supply === "function") {
1355
1359
  try {
1356
- resolved = await supply();
1360
+ resolved = await supply(ctx);
1357
1361
  } catch (cause) {
1358
1362
  throw new exports.IAPError({
1359
1363
  code: exports.IAPErrorCode.APP_USER_ID_FETCH_FAILED,
@@ -1851,6 +1855,8 @@ function createIAP(input) {
1851
1855
  state.logger.debug(`Resolved ${validated.data.length} product(s) from backend manifest.`);
1852
1856
  }
1853
1857
  state.adapter = await selectNativeAdapter({ products: state.products });
1858
+ const configGetAuthHeaders = state.config.backend.getAuthHeaders;
1859
+ const getAuthHeaders = configGetAuthHeaders ? async () => configGetAuthHeaders() : async () => ({});
1854
1860
  const sharedDeps = {
1855
1861
  nativeAdapter: state.adapter,
1856
1862
  backend: state.backend,
@@ -1864,7 +1870,8 @@ function createIAP(input) {
1864
1870
  },
1865
1871
  setCachePersisted: (cachedAt) => {
1866
1872
  state.cachedAt = cachedAt;
1867
- }
1873
+ },
1874
+ getAuthHeaders
1868
1875
  };
1869
1876
  state.orchestrator = new PurchaseOrchestrator({
1870
1877
  ...sharedDeps,