@extenshi/pay 0.7.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.
Files changed (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +260 -0
  3. package/dist/api/mock.d.ts +35 -0
  4. package/dist/api/mock.d.ts.map +1 -0
  5. package/dist/api/pay-api.d.ts +16 -0
  6. package/dist/api/pay-api.d.ts.map +1 -0
  7. package/dist/api/transport.d.ts +52 -0
  8. package/dist/api/transport.d.ts.map +1 -0
  9. package/dist/core/config.d.ts +5 -0
  10. package/dist/core/config.d.ts.map +1 -0
  11. package/dist/core/event-emitter.d.ts +10 -0
  12. package/dist/core/event-emitter.d.ts.map +1 -0
  13. package/dist/core/extenshi-pay.d.ts +90 -0
  14. package/dist/core/extenshi-pay.d.ts.map +1 -0
  15. package/dist/core/identity.d.ts +13 -0
  16. package/dist/core/identity.d.ts.map +1 -0
  17. package/dist/core/index.d.ts +25 -0
  18. package/dist/core/index.d.ts.map +1 -0
  19. package/dist/core/storage.d.ts +42 -0
  20. package/dist/core/storage.d.ts.map +1 -0
  21. package/dist/core.d.mts +821 -0
  22. package/dist/core.d.ts +821 -0
  23. package/dist/core.esm.js +1681 -0
  24. package/dist/core.esm.js.map +1 -0
  25. package/dist/core.js +1806 -0
  26. package/dist/core.js.map +1 -0
  27. package/dist/core.mjs +1744 -0
  28. package/dist/core.mjs.map +1 -0
  29. package/dist/extenshi-pay-lite.esm.js +1664 -0
  30. package/dist/extenshi-pay-lite.esm.js.map +1 -0
  31. package/dist/extenshi-pay-lite.js +1743 -0
  32. package/dist/extenshi-pay-lite.js.map +1 -0
  33. package/dist/extenshi-pay-lite.min.js +7 -0
  34. package/dist/extenshi-pay-lite.min.js.map +1 -0
  35. package/dist/extenshi-pay-lite.mjs +1727 -0
  36. package/dist/extenshi-pay-lite.mjs.map +1 -0
  37. package/dist/extenshi-pay.cjs.js +2632 -0
  38. package/dist/extenshi-pay.cjs.js.map +1 -0
  39. package/dist/extenshi-pay.d.ts +32 -0
  40. package/dist/extenshi-pay.d.ts.map +1 -0
  41. package/dist/extenshi-pay.esm.js +2496 -0
  42. package/dist/extenshi-pay.esm.js.map +1 -0
  43. package/dist/extenshi-pay.esm.min.js +7 -0
  44. package/dist/extenshi-pay.esm.min.js.map +1 -0
  45. package/dist/extenshi-pay.js +2638 -0
  46. package/dist/extenshi-pay.js.map +1 -0
  47. package/dist/extenshi-pay.min.js +7 -0
  48. package/dist/extenshi-pay.min.js.map +1 -0
  49. package/dist/extenshi-pay.min.mjs +7 -0
  50. package/dist/extenshi-pay.min.mjs.map +1 -0
  51. package/dist/extenshi-pay.mjs +2559 -0
  52. package/dist/extenshi-pay.mjs.map +1 -0
  53. package/dist/index.d.mts +937 -0
  54. package/dist/index.d.ts +937 -0
  55. package/dist/index.d.ts.map +1 -0
  56. package/dist/lite.d.mts +659 -0
  57. package/dist/lite.d.ts +659 -0
  58. package/dist/lite.d.ts.map +1 -0
  59. package/dist/payment/checkout.d.ts +47 -0
  60. package/dist/payment/checkout.d.ts.map +1 -0
  61. package/dist/payment/entitlement.d.ts +76 -0
  62. package/dist/payment/entitlement.d.ts.map +1 -0
  63. package/dist/payment/features.d.ts +12 -0
  64. package/dist/payment/features.d.ts.map +1 -0
  65. package/dist/payment/recovery.d.ts +29 -0
  66. package/dist/payment/recovery.d.ts.map +1 -0
  67. package/dist/payment/signature.d.ts +12 -0
  68. package/dist/payment/signature.d.ts.map +1 -0
  69. package/dist/paywall/billing-profile-picker.d.ts +8 -0
  70. package/dist/paywall/billing-profile-picker.d.ts.map +1 -0
  71. package/dist/paywall/format.d.ts +13 -0
  72. package/dist/paywall/format.d.ts.map +1 -0
  73. package/dist/paywall/index.d.ts +9 -0
  74. package/dist/paywall/index.d.ts.map +1 -0
  75. package/dist/paywall/license-panel.d.ts +10 -0
  76. package/dist/paywall/license-panel.d.ts.map +1 -0
  77. package/dist/paywall/renderer.d.ts +55 -0
  78. package/dist/paywall/renderer.d.ts.map +1 -0
  79. package/dist/paywall/seller-details.d.ts +5 -0
  80. package/dist/paywall/seller-details.d.ts.map +1 -0
  81. package/dist/paywall/strings.d.ts +10 -0
  82. package/dist/paywall/strings.d.ts.map +1 -0
  83. package/dist/paywall/templates.d.ts +14 -0
  84. package/dist/paywall/templates.d.ts.map +1 -0
  85. package/dist/paywall.d.mts +160 -0
  86. package/dist/paywall.d.ts +160 -0
  87. package/dist/paywall.esm.js +442 -0
  88. package/dist/paywall.esm.js.map +1 -0
  89. package/dist/paywall.js +462 -0
  90. package/dist/paywall.js.map +1 -0
  91. package/dist/paywall.mjs +442 -0
  92. package/dist/paywall.mjs.map +1 -0
  93. package/dist/types/config.d.ts +62 -0
  94. package/dist/types/config.d.ts.map +1 -0
  95. package/dist/types/contract.d.ts +172 -0
  96. package/dist/types/contract.d.ts.map +1 -0
  97. package/dist/types/entitlement.d.ts +71 -0
  98. package/dist/types/entitlement.d.ts.map +1 -0
  99. package/dist/types/errors.d.ts +31 -0
  100. package/dist/types/errors.d.ts.map +1 -0
  101. package/dist/types/events.d.ts +29 -0
  102. package/dist/types/events.d.ts.map +1 -0
  103. package/dist/types/index.d.ts +7 -0
  104. package/dist/types/index.d.ts.map +1 -0
  105. package/dist/types/paywall.d.ts +37 -0
  106. package/dist/types/paywall.d.ts.map +1 -0
  107. package/dist/utils/logger.d.ts +16 -0
  108. package/dist/utils/logger.d.ts.map +1 -0
  109. package/dist/version.d.ts +3 -0
  110. package/dist/version.d.ts.map +1 -0
  111. package/package.json +115 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Maxim Kosterin / Extenshi (extenshi.io)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,260 @@
1
+ # @extenshi/pay
2
+
3
+ Payments for browser extensions, bundled into the extension itself.
4
+
5
+ - **You are the seller.** Money settles on your own Stripe account (Stripe Connect). extenshi keeps the payment ledger and takes 2% per charge on top of Stripe's fee.
6
+ - **Bundled, no iframe, no remote code.** The paywall is rendered from templates compiled into the SDK and shown in a Shadow DOM. Nothing is fetched at runtime except the JSON API, supporting an extension’s restrictive `content_security_policy`. Store approval depends on the whole extension and is not guaranteed.
7
+ - **Anonymous until the payment.** The SDK mints a random `endUserRef` on first run and stores it in `chrome.storage.local`. No account, no e-mail, no fingerprint. The buyer authenticates inside the hosted checkout, never in your extension.
8
+ - **Payment is the truth, the licence is a projection.** Entitlements are computed on the server from payment facts and returned as an Ed25519-signed envelope the SDK caches offline and verifies with WebCrypto.
9
+ - **Provider-agnostic.** The SDK only knows a publishable key. Which payment gateway sits behind it (Stripe today; Paddle / Lemon Squeezy by the same contract) is a server-side detail.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install @extenshi/pay
15
+ ```
16
+
17
+ Create a standalone Pay application in [Dojo Payments](https://dojo.extenshi.io/payments), connect your seller account and configure its offers. Copy the application’s publishable key and entitlement public key into your extension build. Linking an Extenshi development project is optional; your repository, tooling and build can remain elsewhere. The publishable key identifies public payment and license operations for that application; it is not an author management credential.
18
+
19
+ ## Quick start
20
+
21
+ ```ts
22
+ import ExtenshiPay from '@extenshi/pay'
23
+
24
+ const pay = new ExtenshiPay({
25
+ publishableKey: 'pk_ext_…',
26
+ // Copy the raw Ed25519 public key from your Pay application into your build.
27
+ entitlementPublicKey: 'YOUR_BASE64_ED25519_PUBLIC_KEY',
28
+ })
29
+ await pay.initialize()
30
+
31
+ // Gate a feature. The paywall opens when the user has not paid.
32
+ const ok = await pay.requireFeature('pdf-export', {
33
+ onUnlock: () => enablePdfExport(),
34
+ })
35
+ ```
36
+
37
+ `requireFeature()` reads the feature list of the offer the user bought (you define offers and their features in dojo), shows the paywall when it is missing, and resolves `true` once the checkout completes.
38
+
39
+ ### The checkout flow
40
+
41
+ 1. `openCheckout('pro')` asks the backend for a hosted checkout URL and opens it in a **new tab** (`chrome.tabs.create`; `window.open` outside an extension page).
42
+ 2. The buyer pays on the provider's page and lands on `dojo.extenshi.io/pay/return`.
43
+ 3. The SDK polls `claimSession` every 2 s (and immediately when your window regains focus) until the webhook has landed, then caches the new entitlement and emits `checkout:completed`.
44
+
45
+ ```ts
46
+ const result = await pay.openCheckout('pro') // { state: 'complete' | 'canceled' | 'expired' | 'timeout', … }
47
+ ```
48
+
49
+ ### Reading entitlements
50
+
51
+ ```ts
52
+ await pay.isPaid() // any active/grace entitlement
53
+ await pay.isPaid('pro') // this sku
54
+ await pay.hasFeature('sync') // feature from the bought offer
55
+ await pay.getEntitlement() // { items, features, verified, source, … }
56
+ pay.onEntitlementChange((e) => render(e))
57
+ ```
58
+
59
+ The envelope is cached in `chrome.storage.local` (default refresh TTL 1 h). Paid
60
+ access requires a valid Ed25519 signature. Unsigned, modified or unverifiable
61
+ responses never unlock features outside explicit `mock: true` mode. A missing key
62
+ or unsupported WebCrypto Ed25519 implementation reports `VERIFICATION_UNAVAILABLE`
63
+ through `onError`; initialization still resolves with access locked.
64
+
65
+ For offline startup after a browser or extension restart, bundle
66
+ `entitlementPublicKey` in your extension configuration. Obtain it from
67
+ `pay.getOffer` during integration; do not load it from editable extension storage.
68
+ Without a bundled key, the SDK fetches the key from the configured API and needs
69
+ connectivity again after a restart. A pinned key is authoritative: replacing the
70
+ server signing key requires updating the extension's bundled key. Old signatures
71
+ are rejected after that update; the SDK fetches a new projection when online.
72
+
73
+ Each signed envelope is bound to its application publishable key and installation.
74
+ Old caches without signed application scope require one online refresh on upgrade.
75
+ Deploy the backend emitting `payload.publishableKey` before adopting this SDK.
76
+
77
+ Verified paid access lasts for at most 48 hours after the envelope's **signed
78
+ `issuedAt`**, or until the license's `expiresAt`, whichever comes first. Editing
79
+ local `fetchedAt` cannot extend this period. After the offline deadline,
80
+ `requiresOnlineCheck` is true, `features` is empty and `isPaid()` is false; the
81
+ verified license items remain available for display. `offlineUntil` exposes the
82
+ deadline for extension timers. The SDK also emits changes at license expiry while
83
+ its context is alive. Signed issuance permits up to five minutes of server/client
84
+ clock skew; the offline allowance remains bounded by both signed issuance and local
85
+ fetch time. Suspended service workers must check again when they resume.
86
+ Mock mode is exempt from signature and offline limits.
87
+
88
+ The browser must provide Ed25519 in `crypto.subtle` in a secure context. Test your
89
+ minimum target browser with the package; unsupported browsers receive no paid
90
+ access. This protects the cache from modification, not from users patching the
91
+ extension itself or changing their system clock. Authoritative backend services
92
+ must perform their own access checks.
93
+
94
+
95
+ ### Paywall
96
+
97
+ ```ts
98
+ await pay.showPaywall({
99
+ mode: 'modal', // 'modal' | 'inline' | 'sidebar' | 'fullscreen' | 'minimal'
100
+ sku: 'pro', // which offer to feature (default: first)
101
+ title: 'Go Pro',
102
+ features: ['Unlimited exports', 'Sync'],
103
+ theme: { mode: 'auto', primaryColor: '#0ea5e9' },
104
+ container: document.querySelector('#upsell'), // for inline mode
105
+ })
106
+ ```
107
+
108
+ Templates come from `@extenshi/paywall-templates` and are inlined at build time; strings live in `src/paywall/strings.ts` and can be overridden per call (`strings: { upgrade: 'Kaufen' }`). Prices are formatted with `Intl.NumberFormat` in the user's locale.
109
+
110
+ ### Restore a purchase in another browser
111
+
112
+ ```typescript
113
+ const result = await pay.restorePurchase()
114
+ if (result.state === 'complete') {
115
+ console.log(result.entitlement.items)
116
+ }
117
+ ```
118
+
119
+ The hosted page verifies the checkout email using a one-time code. The extension never collects the email. Recovery requires the same application publishable key in every browser build, a configured recovery backend, and an Ed25519-capable browser. The paywall shows **Restore purchase** only when the server advertises `recoveryEnabled`.
120
+
121
+ Run recovery in an extension page or background context. It creates a random claim secret, sends only its SHA-256 challenge when opening the session, and submits the secret in a POST body when claiming the result. The hosted URL contains only the session ID in its fragment. The SDK verifies the returned signature before replacing its installation ID; pending, failed or canceled attempts preserve the old ID.
122
+
123
+ Recovery proofs use `storage.session`, which must retain its default trusted-context access. Do not expose this storage or recovery internals through a content-script message bridge. A suspended service worker can resume on `initialize()`. Restarting the browser, reloading/updating the extension, or using the memory fallback clears the proof: start a new recovery attempt. A custom `recoveryStorage` adapter must provide equivalent isolation. `restorePurchase({ signal, timeoutMs, openUrl })` supports cancellation, a shorter wait and a custom tab opener.
124
+
125
+ Only purchases indexed from matching completed Extenshi Pay checkouts can currently be recovered. Existing purchases require a separately reviewed backfill. This restores license access; it does not sign the user into Supabase or upload extension settings. Recovered billing profiles remain separate and are available through `openCustomerPortal()`.
126
+
127
+ ### License details and author contact
128
+
129
+ ```ts
130
+ await pay.showLicense() // full bundle; call from an extension page
131
+ const summary = await pay.getLicenseSummary() // also available in Lite
132
+ ```
133
+
134
+ The screen shows the offer, access status, expiry, scheduled renewal cancellation,
135
+ restore action, billing portal and the author's public contact/terms. Canceling renewal
136
+ does not by itself end already paid access. Subscription details come from processed
137
+ provider events; offline results are explicitly labeled as saved information.
138
+ `getLicenseSummary()` returns the same verified entitlement view used for feature gating,
139
+ plus public application/seller metadata. `seller: null` means unavailable, never a guessed
140
+ identity from a login email. Old signed caches may omit offer titles and subscription details.
141
+
142
+ Authors configure **Public license provider** on their application in [Dojo Payments](https://dojo.extenshi.io/payments). The full paywall
143
+ shows “License provided by …” before checkout and disables buying when the backend
144
+ explicitly reports `seller: null`. The backend requires these disclosures before checkout, including for older SDKs
145
+ and custom checkout clients.
146
+ These disclosures describe product responsibilities; they do not replace seller terms
147
+ or establish the legal merchant for a payment by themselves.
148
+
149
+ If several extension contexts keep SDK clients alive, a restored installation must also
150
+ refresh the worker's client and local feature projection. Stop and drain old requests
151
+ before replacing the client; do not expose recovery proof through a content-script bridge.
152
+ The Dyslexia pilot documents and tests this adapter separately.
153
+
154
+ ### Customer portal
155
+
156
+ ```ts
157
+ await pay.openCustomerPortal() // full bundle shows a profile chooser when needed
158
+ ```
159
+
160
+ One billing profile opens directly. Multiple profiles require an explicit choice; the full bundle shows a bundled dialog with subscription status and scheduled cancellation. Canceling the dialog returns `null`. These summaries come from the last processed provider event; the provider portal is where payment details and subscription changes are managed.
161
+
162
+ The Lite bundle and background workers supply their own selector:
163
+
164
+ ```ts
165
+ await pay.openCustomerPortal({
166
+ selectAccount: async (accounts) => showYourProfilePicker(accounts), // listed id, or null to cancel
167
+ })
168
+ ```
169
+
170
+ `selectAccount` receives opaque profile IDs, labels, first-recorded dates and subscription summaries. The server rechecks the selected profile against the current installation's buyer, application, provider account and test/live mode. It never accepts a raw provider Customer ID. Existing SDKs receive `url: null` for multiple profiles instead of silently opening the wrong one.
171
+
172
+ ### Lite bundle
173
+
174
+ `@extenshi/pay/lite` has entitlement, feature gating and `openCheckout()` but no paywall UI and no `getOffer()` — for extensions that render their own upgrade screen.
175
+
176
+ ```ts
177
+ import ExtenshiPay from '@extenshi/pay/lite'
178
+ ```
179
+
180
+ `@extenshi/pay/core` exposes the transport, the API client and the checkout manager; `@extenshi/pay/paywall` the renderer alone.
181
+
182
+ ### Mock mode
183
+
184
+ ```ts
185
+ const pay = new ExtenshiPay({
186
+ publishableKey: 'pk_ext_' + '0'.repeat(32),
187
+ mock: true,
188
+ mockData: {
189
+ offers: [{ sku: 'pro', kind: 'one_time', interval: null, amountMinor: 499, currency: 'usd', title: 'Pro', description: null, features: ['pdf-export'] }],
190
+ entitlements: [],
191
+ checkoutEnabled: true,
192
+ claimAfterPolls: 2,
193
+ },
194
+ })
195
+ ```
196
+
197
+ No network, no backend: develop the paywall and the gating offline.
198
+
199
+ ## Configuration
200
+
201
+ | Option | Default | Notes |
202
+ |---|---|---|
203
+ | `publishableKey` | — | required, `pk_ext_` + 32 hex |
204
+ | `entitlementPublicKey` | fetched from API | raw 32-byte Ed25519 public key in base64; bundle it for offline restart |
205
+ | `apiUrl` | `https://bff.extenshi.io` | |
206
+ | `cacheTtlMs` | `3600000` | entitlement cache TTL |
207
+ | `locale` | browser locale | passed to checkout and used for price formatting |
208
+ | `logLevel` | `'warn'` | `'silent' \| 'error' \| 'warn' \| 'info' \| 'debug'` |
209
+ | `theme` | — | `mode`, `primaryColor`, `fontFamily`, `borderRadius`, `customCss` |
210
+ | `mock` / `mockData` | `false` | offline development |
211
+ | `onReady` / `onError` | — | callbacks; the same events are on `pay.on(...)` |
212
+
213
+ Events: `ready`, `entitlement:changed`, `checkout:started`, `checkout:completed`, `checkout:canceled`, `checkout:expired`, `error`.
214
+
215
+ ## What leaves the extension
216
+
217
+ Normal payment calls send `publishableKey`, `endUserRef` (a random UUID), `sku` and `locale`; checkout claims also send `sessionId`. Explicit recovery additionally sends a random session ID, a SHA-256 claim challenge and its installation-held secret (POST body). The checkout email and verification code are entered only on the hosted recovery page. Selecting a billing profile also sends its opaque `customerId`. No fingerprint or extension settings are collected by this SDK. Store privacy disclosures must cover installation/license verification and this optional recovery flow.
218
+
219
+ ## Bundle sizes (gzip)
220
+
221
+ Measured from the built 0.7.0 release candidate (gzip bytes; ESM, before consumer tree shaking):
222
+
223
+ | Bundle | Size |
224
+ |---|---|
225
+ | Full `extenshi-pay.mjs` | 35,474 B |
226
+ | Full minified `extenshi-pay.min.mjs` | 25,107 B |
227
+ | Lite `extenshi-pay-lite.mjs` | 17,022 B |
228
+ | Core `core.mjs` | 17,633 B |
229
+ | Paywall `paywall.mjs` | 14,403 B |
230
+
231
+ The release validation script prints fresh measurements for each build.
232
+
233
+ ## Release validation
234
+
235
+ From the repository root, run `node scripts/pay-sdk-release-check.mjs`. It runs the
236
+ SDK tests, typecheck, lint and build, validates the template package, then installs
237
+ both actual npm tarballs into a temporary directory outside the monorepo. ESM,
238
+ CommonJS and TypeScript NodeNext consumers are checked there. Use
239
+ `--artifacts-dir /absolute/output/path` to retain the validated tarballs and hashes.
240
+
241
+ The **Validate and stage Pay npm packages** workflow saves these artifacts. Its
242
+ manual `stage` option stages existing packages for a maintainer's approval; it does
243
+ not publish. npm staged publishing requires an existing package. First publication
244
+ therefore requires a maintainer to bootstrap each package with the validated
245
+ artifact. A successful build or staging run is not evidence of public availability.
246
+
247
+ ## Development
248
+
249
+ ```bash
250
+ yarn workspace @extenshi/pay test # vitest (jsdom, real WebCrypto)
251
+ yarn workspace @extenshi/pay type-check
252
+ yarn workspace @extenshi/pay lint
253
+ yarn workspace @extenshi/pay build # rollup → dist/
254
+ ```
255
+
256
+ The backend contract lives in `shared-types/pay.ts` of the extenshi.io monorepo; `src/types/contract.ts` mirrors the part the SDK needs.
257
+
258
+ ## License
259
+
260
+ MIT
@@ -0,0 +1,35 @@
1
+ /**
2
+ * In-memory stand-in for the BFF, used when `mock: true`. Lets an extension be
3
+ * developed with no backend: offers and entitlements come from `mockData`, a
4
+ * mock checkout completes after `claimAfterPolls` polls and grants the SKU.
5
+ */
6
+ import type { MockData } from '../types/config.js';
7
+ import { type PayEntitlementItem } from '../types/contract.js';
8
+ import type { ProcedureKind, Transport } from './transport.js';
9
+ type SessionState = 'open' | 'complete' | 'canceled' | 'expired';
10
+ interface MockSession {
11
+ sku: string;
12
+ polls: number;
13
+ state: SessionState;
14
+ }
15
+ export declare class MockTransport implements Transport {
16
+ private entitlements;
17
+ private readonly offers;
18
+ private readonly projectName;
19
+ private readonly checkoutEnabled;
20
+ private readonly claimAfterPolls;
21
+ readonly sessions: Map<string, MockSession>;
22
+ constructor(data?: MockData);
23
+ call<T>(procedure: string, _kind: ProcedureKind, input: Record<string, unknown>): Promise<T>;
24
+ /** Test/dev helpers. */
25
+ setEntitlements(items: PayEntitlementItem[]): void;
26
+ cancelSession(sessionId: string): void;
27
+ expireSession(sessionId: string): void;
28
+ private offerResponse;
29
+ private createCheckout;
30
+ private claim;
31
+ private grant;
32
+ private envelope;
33
+ }
34
+ export {};
35
+ //# sourceMappingURL=mock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../src/api/mock.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAGN,KAAK,kBAAkB,EAIvB,MAAM,sBAAsB,CAAA;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE9D,KAAK,YAAY,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAAA;AAEhE,UAAU,WAAW;IACpB,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,YAAY,CAAA;CACnB;AAID,qBAAa,aAAc,YAAW,SAAS;IAC9C,OAAO,CAAC,YAAY,CAAsB;IAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;IACpC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,QAAQ,CAAC,QAAQ,2BAAiC;gBAEtC,IAAI,GAAE,QAAa;IAQzB,IAAI,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAqBlG,wBAAwB;IACxB,eAAe,CAAC,KAAK,EAAE,kBAAkB,EAAE,GAAG,IAAI;IAIlD,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAKtC,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAKtC,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,cAAc;IAgBtB,OAAO,CAAC,KAAK;IAcb,OAAO,CAAC,KAAK;IAmBb,OAAO,CAAC,QAAQ;CAahB"}
@@ -0,0 +1,16 @@
1
+ /** Typed wrapper over the SDK-facing `pay.*` procedures. Nothing else is ever called. */
2
+ import type { PayCheckoutClaim, PayCheckoutSession, PayOfferResponse, PayPortalResponse, PayRestoreClaimResponse, PayRestoreSessionResponse, SignedEntitlement } from '../types/contract.js';
3
+ import type { Transport } from './transport.js';
4
+ export declare class PayApi {
5
+ private readonly transport;
6
+ private readonly publishableKey;
7
+ constructor(transport: Transport, publishableKey: string);
8
+ createRestoreSession(claimChallenge: string): Promise<PayRestoreSessionResponse>;
9
+ claimRestoreSession(sessionId: string, claimSecret: string): Promise<PayRestoreClaimResponse>;
10
+ getOffer(locale?: string | null): Promise<PayOfferResponse>;
11
+ createCheckout(sku: string, endUserRef: string, locale?: string | null): Promise<PayCheckoutSession>;
12
+ claimSession(sessionId: string, endUserRef: string): Promise<PayCheckoutClaim>;
13
+ getEntitlement(endUserRef: string): Promise<SignedEntitlement>;
14
+ getPortalUrl(endUserRef: string, customerId?: string): Promise<PayPortalResponse>;
15
+ }
16
+ //# sourceMappingURL=pay-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pay-api.d.ts","sourceRoot":"","sources":["../../src/api/pay-api.ts"],"names":[],"mappings":"AAAA,yFAAyF;AAEzF,OAAO,KAAK,EACX,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,uBAAuB,EACvB,yBAAyB,EACzB,iBAAiB,EACjB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C,qBAAa,MAAM;IAEjB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,cAAc;gBADd,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,MAAM;IAGxC,oBAAoB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,CAAC;IAOhF,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAQ7F,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAO3D,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,kBAAkB,CAAC;IASpG,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAQ9E,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAO9D,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAOjF"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * HTTP transport for the BFF's tRPC endpoint (`/api/trpc/<procedure>`).
3
+ *
4
+ * Queries are header-less GETs with `?input=<json>` (a CORS "simple request",
5
+ * so no preflight); mutations POST a JSON body. The only things that leave the
6
+ * extension are payment inputs and optional recovery session/proof inputs
7
+ * and the browser's standard headers — `credentials: 'omit'` keeps cookies out.
8
+ * Queries are retried on network / 5xx errors; mutations never are.
9
+ */
10
+ import { ExtenshiPayError } from '../types/errors.js';
11
+ export type ProcedureKind = 'query' | 'mutation';
12
+ export interface Transport {
13
+ call<T>(procedure: string, kind: ProcedureKind, input: Record<string, unknown>): Promise<T>;
14
+ }
15
+ export interface HttpTransportOptions {
16
+ apiUrl: string;
17
+ /** Per-attempt timeout (default 10 s). */
18
+ timeoutMs?: number;
19
+ /** Extra attempts for queries (default 1). */
20
+ retries?: number;
21
+ fetchImpl?: typeof fetch;
22
+ }
23
+ export declare const TRPC_PATH = "/api/trpc";
24
+ interface TrpcErrorShape {
25
+ message?: string;
26
+ code?: number;
27
+ data?: {
28
+ code?: string;
29
+ httpStatus?: number;
30
+ cause?: {
31
+ code?: string;
32
+ retryAfterSec?: number;
33
+ };
34
+ };
35
+ }
36
+ /**
37
+ * The BFF's error formatter does not forward `cause` for `pay.*` errors, so the
38
+ * tRPC code + message is the primary signal; `data.cause.code` is honoured when
39
+ * present so a future BFF that forwards it needs no SDK change.
40
+ */
41
+ export declare function trpcErrorToPayError(error: TrpcErrorShape, httpStatus?: number): ExtenshiPayError;
42
+ export declare class HttpTransport implements Transport {
43
+ private readonly apiUrl;
44
+ private readonly timeoutMs;
45
+ private readonly retries;
46
+ private readonly fetchImpl;
47
+ constructor(options: HttpTransportOptions);
48
+ call<T>(procedure: string, kind: ProcedureKind, input: Record<string, unknown>): Promise<T>;
49
+ private request;
50
+ }
51
+ export {};
52
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/api/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAA+B,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAGlF,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,UAAU,CAAA;AAEhD,MAAM,WAAW,SAAS;IACzB,IAAI,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,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RE: RegExp;
4
+ export declare function resolveConfig(input: ExtenshiPayConfig): ResolvedConfig;
5
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,iBAAiB,EAEtB,KAAK,cAAc,EACnB,MAAM,oBAAoB,CAAA;AAO3B,6DAA6D;AAC7D,eAAO,MAAM,SAAS,QAAgC,CAAA;AAWtD,wBAAgB,aAAa,CAAC,KAAK,EAAE,iBAAiB,GAAG,cAAc,CA8DtE"}
@@ -0,0 +1,10 @@
1
+ export type Listener<T> = (payload: T) => void;
2
+ export declare class EventEmitter<Events extends object> {
3
+ private readonly listeners;
4
+ on<K extends keyof Events>(event: K, listener: Listener<Events[K]>): () => void;
5
+ once<K extends keyof Events>(event: K, listener: Listener<Events[K]>): () => void;
6
+ off<K extends keyof Events>(event: K, listener: Listener<Events[K]>): void;
7
+ emit<K extends keyof Events>(event: K, payload: Events[K]): void;
8
+ removeAll(): void;
9
+ }
10
+ //# sourceMappingURL=event-emitter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-emitter.d.ts","sourceRoot":"","sources":["../../src/core/event-emitter.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,CAAA;AAG9C,qBAAa,YAAY,CAAC,MAAM,SAAS,MAAM;IAC9C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA4C;IAEtE,EAAE,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IAU/E,IAAI,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IAQjF,GAAG,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;IAI1E,IAAI,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI;IAahE,SAAS,IAAI,IAAI;CAGjB"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * `ExtenshiPayLite` — entitlement, feature gating and hosted checkout, without
3
+ * the paywall UI. This is what the `lite` bundle exports; the full `ExtenshiPay`
4
+ * extends it with `getOffer()` / `showPaywall()`.
5
+ *
6
+ * Data that leaves the extension: `publishableKey`, `endUserRef`, `sku`,
7
+ * `locale` and checkout session IDs. Explicit recovery also sends its session ID,
8
+ * challenge and claim secret (POST body). Email stays on the hosted page.
9
+ */
10
+ import { PayApi } from '../api/pay-api.js';
11
+ import { type Transport } from '../api/transport.js';
12
+ import { CheckoutManager } from '../payment/checkout.js';
13
+ import { EntitlementManager } from '../payment/entitlement.js';
14
+ import { RecoveryManager } from '../payment/recovery.js';
15
+ import type { ExtenshiPayConfig, ResolvedConfig } from '../types/config.js';
16
+ import type { PayOfferResponse } from '../types/contract.js';
17
+ import type { CheckoutOptions, CheckoutResult, CustomerPortalOptions, Entitlement, GetEntitlementOptions, LicenseSummary, RequireFeatureOptions, RestoreOptions, RestoreResult } from '../types/entitlement.js';
18
+ import { ExtenshiPayError } from '../types/errors.js';
19
+ import type { ExtenshiPayEvents } from '../types/events.js';
20
+ import { EventEmitter, type Listener } from './event-emitter.js';
21
+ import { type StorageAdapter } from './storage.js';
22
+ /** Injection points for tests and unusual hosts. */
23
+ export interface ExtenshiPayDeps {
24
+ storage?: StorageAdapter;
25
+ /** Trusted extension-only storage; never share this adapter with content scripts. */
26
+ recoveryStorage?: StorageAdapter;
27
+ transport?: Transport;
28
+ fetch?: typeof fetch;
29
+ openUrl?: (url: string) => void | Promise<void>;
30
+ now?: () => number;
31
+ }
32
+ export declare class ExtenshiPayLite {
33
+ static readonly version = "0.7.0";
34
+ protected readonly config: ResolvedConfig;
35
+ protected readonly emitter: EventEmitter<ExtenshiPayEvents>;
36
+ protected readonly storage: StorageAdapter;
37
+ protected readonly api: PayApi;
38
+ protected readonly entitlements: EntitlementManager;
39
+ protected readonly checkout: CheckoutManager;
40
+ protected readonly recovery: RecoveryManager;
41
+ private readonly now;
42
+ private endUserRef;
43
+ private endUserRefPromise;
44
+ private offer;
45
+ private offerInflight;
46
+ private readyPromise;
47
+ private destroyed;
48
+ constructor(config: ExtenshiPayConfig, deps?: ExtenshiPayDeps);
49
+ get version(): string;
50
+ /**
51
+ * Mints/loads `endUserRef`, loads the cached entitlement, re-verifies it and
52
+ * refreshes it when stale. Resolves once `isPaid()` can answer; network
53
+ * failures fall back to the cache and are reported through `error`.
54
+ */
55
+ initialize(): Promise<void>;
56
+ private doInitialize;
57
+ private afterReady;
58
+ /** The anonymous, random id this install is known by. */
59
+ getEndUserRef(): Promise<string>;
60
+ getCachedEntitlement(): Entitlement | null;
61
+ getEntitlement(options?: GetEntitlementOptions): Promise<Entitlement>;
62
+ /** True when any active/grace entitlement exists, or the given `sku` is active/grace. */
63
+ isPaid(sku?: string): Promise<boolean>;
64
+ hasFeature(feature: string): Promise<boolean>;
65
+ checkFeatures(features: string[]): Promise<Record<string, boolean>>;
66
+ /** Resolves true when the feature is (or becomes) unlocked. */
67
+ requireFeature(feature: string, options?: RequireFeatureOptions): Promise<boolean>;
68
+ /** Lite has no UI: a locked feature stays locked. The full SDK shows the paywall here. */
69
+ protected onFeatureLocked(_feature: string, _options: RequireFeatureOptions): Promise<boolean>;
70
+ /** Opens hosted checkout for `sku` in a new tab and resolves when the session settles. */
71
+ openCheckout(sku: string, options?: CheckoutOptions): Promise<CheckoutResult>;
72
+ /** Opens email verification on the hosted page. No email is collected inside the extension. */
73
+ restorePurchase(options?: RestoreOptions): Promise<RestoreResult>;
74
+ /** Read-only license view. Entitlements retain cache/signature/offline semantics. */
75
+ getLicenseSummary(options?: GetEntitlementOptions): Promise<LicenseSummary>;
76
+ /** Opens the provider's self-service portal; resolves null when the provider has none. */
77
+ openCustomerPortal(options?: CustomerPortalOptions): Promise<string | null>;
78
+ on<K extends keyof ExtenshiPayEvents>(event: K, listener: Listener<ExtenshiPayEvents[K]>): () => void;
79
+ once<K extends keyof ExtenshiPayEvents>(event: K, listener: Listener<ExtenshiPayEvents[K]>): () => void;
80
+ off<K extends keyof ExtenshiPayEvents>(event: K, listener: Listener<ExtenshiPayEvents[K]>): void;
81
+ onEntitlementChange(listener: Listener<Entitlement>): () => void;
82
+ clearCache(): Promise<void>;
83
+ /** Stops background refresh and drops listeners. */
84
+ destroy(): void;
85
+ /** Offer + signing key. Public in the full SDK (`getOffer`), internal here. */
86
+ protected fetchOffer(force?: boolean): Promise<PayOfferResponse>;
87
+ private getPublicKey;
88
+ protected reportError(error: unknown): ExtenshiPayError;
89
+ }
90
+ //# sourceMappingURL=extenshi-pay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extenshi-pay.d.ts","sourceRoot":"","sources":["../../src/core/extenshi-pay.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAqB,MAAM,2BAA2B,CAAA;AAEjF,OAAO,EAAyB,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAE/E,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA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iBAAiB,CAAC,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,cAAc,CAAC;IAgBrF,0FAA0F;IACpF,kBAAkB,CAAC,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAiCrF,EAAE,CAAC,CAAC,SAAS,MAAM,iBAAiB,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IAIrG,IAAI,CAAC,CAAC,SAAS,MAAM,iBAAiB,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IAIvG,GAAG,CAAC,CAAC,SAAS,MAAM,iBAAiB,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI;IAIhG,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,MAAM,IAAI;IAI1D,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAKjC,oDAAoD;IACpD,OAAO,IAAI,IAAI;IAOf,+EAA+E;IAC/E,SAAS,CAAC,UAAU,CAAC,KAAK,UAAQ,GAAG,OAAO,CAAC,gBAAgB,CAAC;YAkBhD,YAAY;IAI1B,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB;CAMvD"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `endUserRef` — the only identity the SDK has.
3
+ *
4
+ * A random UUID minted on first run and kept in the SDK's storage namespace.
5
+ * It is never derived from anything identifying (no fingerprint, no e-mail,
6
+ * no extension-supplied user id) and remains the installation identifier. Explicit recovery also sends a
7
+ * random session ID and proof; it never derives identity from an email locally.
8
+ */
9
+ import type { StorageAdapter } from './storage.js';
10
+ export declare const END_USER_REF_STORAGE_KEY = "extenshi-pay:endUserRef";
11
+ export declare function mintEndUserRef(): string;
12
+ export declare function getOrCreateEndUserRef(storage: StorageAdapter): Promise<string>;
13
+ //# sourceMappingURL=identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/core/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAElD,eAAO,MAAM,wBAAwB,4BAA4B,CAAA;AAEjE,wBAAgB,cAAc,IAAI,MAAM,CAWvC;AAED,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAMpF"}
@@ -0,0 +1,25 @@
1
+ export { MockTransport } from '../api/mock.js';
2
+ export { PayApi } from '../api/pay-api.js';
3
+ export type { HttpTransportOptions, ProcedureKind, Transport } from '../api/transport.js';
4
+ export { HttpTransport, TRPC_PATH, trpcErrorToPayError } from '../api/transport.js';
5
+ export type { CheckoutManagerOptions } from '../payment/checkout.js';
6
+ export { CHECKOUT_POLL_INTERVAL_MS, CHECKOUT_TIMEOUT_MS, CheckoutManager, openInNewTab, } from '../payment/checkout.js';
7
+ export type { EntitlementManagerOptions } from '../payment/entitlement.js';
8
+ export { EntitlementManager, MAX_REFRESH_BACKOFF_MS, MIN_REFRESH_INTERVAL_MS, } from '../payment/entitlement.js';
9
+ export { applyLocalExpiry, checkFeatures, collectFeatures, EMPTY_ENTITLEMENT, hasFeature, isEntitled, isLive, } from '../payment/features.js';
10
+ export type { RecoveryManagerOptions } from '../payment/recovery.js';
11
+ export { createRecoveryStorage, RecoveryManager } from '../payment/recovery.js';
12
+ export type { SignatureVerdict } from '../payment/signature.js';
13
+ export { base64ToBytes, verifyEntitlementSignature } from '../payment/signature.js';
14
+ export * from '../types/index.js';
15
+ export { Logger, logger } from '../utils/logger.js';
16
+ export { VERSION } from '../version.js';
17
+ export { LOCALE_RE, resolveConfig } from './config.js';
18
+ export type { Listener } from './event-emitter.js';
19
+ export { EventEmitter } from './event-emitter.js';
20
+ export type { ExtenshiPayDeps } from './extenshi-pay.js';
21
+ export { ExtenshiPayLite } from './extenshi-pay.js';
22
+ export { END_USER_REF_STORAGE_KEY, getOrCreateEndUserRef, mintEndUserRef } from './identity.js';
23
+ export type { StorageAdapter } from './storage.js';
24
+ export { createStorage, ExtensionStorage, LocalStorageAdapter, MemoryStorage } from './storage.js';
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,YAAY,EAAE,oBAAoB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACzF,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AACnF,YAAY,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAA;AACpE,OAAO,EACN,yBAAyB,EACzB,mBAAmB,EACnB,eAAe,EACf,YAAY,GACZ,MAAM,wBAAwB,CAAA;AAC/B,YAAY,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAA;AAC1E,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,GACvB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACN,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,UAAU,EACV,UAAU,EACV,MAAM,GACN,MAAM,wBAAwB,CAAA;AAC/B,YAAY,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAA;AACpE,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC/E,YAAY,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAA;AACnF,cAAc,mBAAmB,CAAA;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACtD,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC/F,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Persistent key/value storage for the SDK's own namespace.
3
+ *
4
+ * Preference order: `chrome.storage.local` (Chrome/Edge), `browser.storage.local`
5
+ * (Firefox), `localStorage` (non-extension contexts such as a dev page), then
6
+ * memory. Both promise-returning (MV3, Firefox) and callback-only (MV2) storage
7
+ * APIs are supported.
8
+ */
9
+ export interface StorageAdapter {
10
+ get(key: string): Promise<unknown>;
11
+ set(key: string, value: unknown): Promise<void>;
12
+ remove(key: string): Promise<void>;
13
+ }
14
+ type Items = Record<string, unknown>;
15
+ interface StorageArea {
16
+ get(keys: string, callback?: (items: Items) => void): unknown;
17
+ set(items: Items, callback?: () => void): unknown;
18
+ remove(keys: string, callback?: () => void): unknown;
19
+ }
20
+ export declare class ExtensionStorage implements StorageAdapter {
21
+ private readonly area;
22
+ constructor(area: StorageArea);
23
+ get(key: string): Promise<unknown>;
24
+ set(key: string, value: unknown): Promise<void>;
25
+ remove(key: string): Promise<void>;
26
+ }
27
+ export declare class LocalStorageAdapter implements StorageAdapter {
28
+ private readonly store;
29
+ constructor(store: Storage);
30
+ get(key: string): Promise<unknown>;
31
+ set(key: string, value: unknown): Promise<void>;
32
+ remove(key: string): Promise<void>;
33
+ }
34
+ export declare class MemoryStorage implements StorageAdapter {
35
+ private readonly map;
36
+ get(key: string): Promise<unknown>;
37
+ set(key: string, value: unknown): Promise<void>;
38
+ remove(key: string): Promise<void>;
39
+ }
40
+ export declare function createStorage(): StorageAdapter;
41
+ export {};
42
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/core/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,cAAc;IAC9B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAClC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAClC;AAED,KAAK,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEpC,UAAU,WAAW;IACpB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,OAAO,CAAA;IAC7D,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAA;IACjD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAA;CACpD;AA+BD,qBAAa,gBAAiB,YAAW,cAAc;IAC1C,OAA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