@entitlehub/sdk 0.1.2 → 0.1.3
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 +6 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@entitlehub/sdk`. Adheres to [Semantic Versioning](https://semver.org/).
|
|
4
4
|
|
|
5
|
+
## 0.1.3 — 2026-07-18
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- `reportPurchase` accepts `stripeSubscriptionId` — EntitleHub validates the subscription against
|
|
9
|
+
your Stripe secret key (active/trialing → granted, current period end as the expiry).
|
|
10
|
+
|
|
5
11
|
## 0.1.2 — 2026-07-18
|
|
6
12
|
|
|
7
13
|
### Changed
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var x=(n,
|
|
1
|
+
"use strict";var d=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var x=(n,t)=>{for(var e in t)d(n,e,{get:t[e],enumerable:!0})},v=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of k(t))!E.call(n,i)&&i!==e&&d(n,i,{get:()=>t[i],enumerable:!(r=C(t,i))||r.enumerable});return n};var _=n=>v(d({},"__esModule",{value:!0}),n);var T={};x(T,{CustomerInfo:()=>a,EntitleHub:()=>l,EntitleHubError:()=>s,EntitleHubServer:()=>f});module.exports=_(T);var a=class{constructor(t){this.appUserId=t.app_user_id,this.entitlements=t.active_entitlements??[];let e={};for(let r of this.entitlements)e[r.entitlement]=r;this.active=e}isActive(t){return!!this.active[t]}get activeEntitlementIds(){return Object.keys(this.active)}expirationDate(t){let e=this.active[t];if(e)return e.expires_at?new Date(e.expires_at):null}};var s=class extends Error{constructor(t,e,r="error"){super(t),this.name="EntitleHubError",this.status=e,this.code=r}},O=n=>new Promise(t=>setTimeout(t,n));async function c(n,t,e,r){let i=n.fetchImpl??globalThis.fetch;if(!i)throw new s("No fetch implementation available. On Node <18, pass fetchImpl.",0,"no_fetch");let h=`${n.baseUrl.replace(/\/$/,"")}${e}`,y=t==="GET"?n.retries??2:0,m;for(let u=0;u<=y;u++){let b=new AbortController,g=n.timeoutMs?setTimeout(()=>b.abort(),n.timeoutMs):void 0;try{let o=await i(h,{method:t,headers:{Authorization:`Bearer ${n.apiKey}`,...r?{"Content-Type":"application/json"}:{}},body:r?JSON.stringify(r):void 0,signal:b.signal}),I=await o.text(),p=I?P(I):{};if(!o.ok){let w=`HTTP ${o.status}`;throw p&&typeof p=="object"&&"error"in p&&(w=String(p.error)),new s(w,o.status,o.status===401||o.status===403?"auth":"http")}return p}catch(o){if(m=o,o instanceof s)throw o;u<y&&await O(250*(u+1))}finally{g&&clearTimeout(g)}}throw new s(`Network request failed: ${String(m?.message??m)}`,0,"network")}function P(n){try{return JSON.parse(n)}catch{return{}}}var l=class{constructor(t){this.listeners=new Set;if(!t.apiKey)throw new s("apiKey is required.",0,"config");if(!t.appUserId)throw new s("appUserId is required.",0,"config");if(t.apiKey.startsWith("sk_"))throw new s("Never use a secret (sk_) key in the client SDK \u2014 use your publishable (pk_) key.",0,"config");this.appUserId=t.appUserId,this.cacheTtlMs=t.cacheTtlMs??5*6e4,this.http={baseUrl:t.baseUrl??"https://entitlehub.com/v1",apiKey:t.apiKey,fetchImpl:t.fetchImpl,timeoutMs:15e3}}get currentAppUserId(){return this.appUserId}async logIn(t){return this.appUserId=t,this.cached=void 0,this.getCustomerInfo({fetchPolicy:"network-only"})}logOut(){this.cached=void 0}async getCustomerInfo(t={}){if((t.fetchPolicy??"cache-first")==="cache-first"&&this.cached&&Date.now()-this.cached.at<this.cacheTtlMs)return this.cached.info;let r=await c(this.http,"GET",`/subscribers/${encodeURIComponent(this.appUserId)}`),i=new a(r);this.cached={info:i,at:Date.now()};for(let h of this.listeners)try{h(i)}catch{}return i}async isEntitled(t){return(await this.getCustomerInfo()).isActive(t)}async checkEntitlement(t,e={}){return c(this.http,"POST","/check",{app_user_id:this.appUserId,entitlement:t,sandbox:!!e.sandbox})}async getOfferings(){return c(this.http,"GET","/offerings")}addCustomerInfoUpdateListener(t){return this.listeners.add(t),()=>this.listeners.delete(t)}};var f=class{constructor(t){if(!t.apiKey)throw new s("apiKey is required.",0,"config");if(!t.apiKey.startsWith("sk_"))throw new s("EntitleHubServer needs a secret (sk_) key. For client reads, use the EntitleHub class with a pk_ key.",0,"config");this.http={baseUrl:t.baseUrl??"https://entitlehub.com/v1",apiKey:t.apiKey,fetchImpl:t.fetchImpl,timeoutMs:15e3}}async reportPurchase(t,e){let r=await c(this.http,"POST",`/subscribers/${encodeURIComponent(t)}/purchases`,{store:e.store,store_product_id:e.storeProductId,is_sandbox:!!e.isSandbox,transaction_id:e.transactionId??"",purchase_token:e.purchaseToken??"",is_subscription:!!e.isSubscription,signed_transaction:e.signedTransaction??"",stripe_subscription_id:e.stripeSubscriptionId??""});return new a(r)}async grantEntitlement(t,e,r={}){let i=await c(this.http,"POST",`/subscribers/${encodeURIComponent(t)}/grant`,{entitlement:e,duration_days:r.durationDays??0,is_sandbox:!!r.isSandbox});return new a(i)}async getCustomerInfo(t){let e=await c(this.http,"GET",`/subscribers/${encodeURIComponent(t)}`);return new a(e)}async check(t,e,r={}){return c(this.http,"POST","/check",{app_user_id:t,entitlement:e,sandbox:!!r.sandbox})}};0&&(module.exports={CustomerInfo,EntitleHub,EntitleHubError,EntitleHubServer});
|
package/dist/index.d.cts
CHANGED
|
@@ -72,6 +72,11 @@ interface PurchaseInput {
|
|
|
72
72
|
* `storeProductId`, so a client can't forge a purchase.
|
|
73
73
|
*/
|
|
74
74
|
signedTransaction?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Stripe subscription id. When set, EntitleHub validates it against the project's Stripe
|
|
77
|
+
* secret key (active/trialing → granted, with the current period end as the expiry).
|
|
78
|
+
*/
|
|
79
|
+
stripeSubscriptionId?: string;
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
/**
|
|
@@ -169,6 +174,7 @@ declare class EntitleHubServer {
|
|
|
169
174
|
* Three modes (pick one):
|
|
170
175
|
* • Google (validated): { store:"play", storeProductId, purchaseToken, isSubscription }
|
|
171
176
|
* • Apple (validated): { signedTransaction } — store/product are read from the JWS
|
|
177
|
+
* • Stripe (validated): { stripeSubscriptionId } — validated via your Stripe secret key
|
|
172
178
|
* • Trusted server-report: { store, storeProductId } — no store validation; only when you've
|
|
173
179
|
* already validated the receipt elsewhere.
|
|
174
180
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -72,6 +72,11 @@ interface PurchaseInput {
|
|
|
72
72
|
* `storeProductId`, so a client can't forge a purchase.
|
|
73
73
|
*/
|
|
74
74
|
signedTransaction?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Stripe subscription id. When set, EntitleHub validates it against the project's Stripe
|
|
77
|
+
* secret key (active/trialing → granted, with the current period end as the expiry).
|
|
78
|
+
*/
|
|
79
|
+
stripeSubscriptionId?: string;
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
/**
|
|
@@ -169,6 +174,7 @@ declare class EntitleHubServer {
|
|
|
169
174
|
* Three modes (pick one):
|
|
170
175
|
* • Google (validated): { store:"play", storeProductId, purchaseToken, isSubscription }
|
|
171
176
|
* • Apple (validated): { signedTransaction } — store/product are read from the JWS
|
|
177
|
+
* • Stripe (validated): { stripeSubscriptionId } — validated via your Stripe secret key
|
|
172
178
|
* • Trusted server-report: { store, storeProductId } — no store validation; only when you've
|
|
173
179
|
* already validated the receipt elsewhere.
|
|
174
180
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var o=class{constructor(
|
|
1
|
+
var o=class{constructor(t){this.appUserId=t.app_user_id,this.entitlements=t.active_entitlements??[];let e={};for(let n of this.entitlements)e[n.entitlement]=n;this.active=e}isActive(t){return!!this.active[t]}get activeEntitlementIds(){return Object.keys(this.active)}expirationDate(t){let e=this.active[t];if(e)return e.expires_at?new Date(e.expires_at):null}};var s=class extends Error{constructor(t,e,n="error"){super(t),this.name="EntitleHubError",this.status=e,this.code=n}},w=r=>new Promise(t=>setTimeout(t,r));async function a(r,t,e,n){let c=r.fetchImpl??globalThis.fetch;if(!c)throw new s("No fetch implementation available. On Node <18, pass fetchImpl.",0,"no_fetch");let l=`${r.baseUrl.replace(/\/$/,"")}${e}`,d=t==="GET"?r.retries??2:0,f;for(let u=0;u<=d;u++){let y=new AbortController,b=r.timeoutMs?setTimeout(()=>y.abort(),r.timeoutMs):void 0;try{let i=await c(l,{method:t,headers:{Authorization:`Bearer ${r.apiKey}`,...n?{"Content-Type":"application/json"}:{}},body:n?JSON.stringify(n):void 0,signal:y.signal}),g=await i.text(),p=g?C(g):{};if(!i.ok){let I=`HTTP ${i.status}`;throw p&&typeof p=="object"&&"error"in p&&(I=String(p.error)),new s(I,i.status,i.status===401||i.status===403?"auth":"http")}return p}catch(i){if(f=i,i instanceof s)throw i;u<d&&await w(250*(u+1))}finally{b&&clearTimeout(b)}}throw new s(`Network request failed: ${String(f?.message??f)}`,0,"network")}function C(r){try{return JSON.parse(r)}catch{return{}}}var h=class{constructor(t){this.listeners=new Set;if(!t.apiKey)throw new s("apiKey is required.",0,"config");if(!t.appUserId)throw new s("appUserId is required.",0,"config");if(t.apiKey.startsWith("sk_"))throw new s("Never use a secret (sk_) key in the client SDK \u2014 use your publishable (pk_) key.",0,"config");this.appUserId=t.appUserId,this.cacheTtlMs=t.cacheTtlMs??5*6e4,this.http={baseUrl:t.baseUrl??"https://entitlehub.com/v1",apiKey:t.apiKey,fetchImpl:t.fetchImpl,timeoutMs:15e3}}get currentAppUserId(){return this.appUserId}async logIn(t){return this.appUserId=t,this.cached=void 0,this.getCustomerInfo({fetchPolicy:"network-only"})}logOut(){this.cached=void 0}async getCustomerInfo(t={}){if((t.fetchPolicy??"cache-first")==="cache-first"&&this.cached&&Date.now()-this.cached.at<this.cacheTtlMs)return this.cached.info;let n=await a(this.http,"GET",`/subscribers/${encodeURIComponent(this.appUserId)}`),c=new o(n);this.cached={info:c,at:Date.now()};for(let l of this.listeners)try{l(c)}catch{}return c}async isEntitled(t){return(await this.getCustomerInfo()).isActive(t)}async checkEntitlement(t,e={}){return a(this.http,"POST","/check",{app_user_id:this.appUserId,entitlement:t,sandbox:!!e.sandbox})}async getOfferings(){return a(this.http,"GET","/offerings")}addCustomerInfoUpdateListener(t){return this.listeners.add(t),()=>this.listeners.delete(t)}};var m=class{constructor(t){if(!t.apiKey)throw new s("apiKey is required.",0,"config");if(!t.apiKey.startsWith("sk_"))throw new s("EntitleHubServer needs a secret (sk_) key. For client reads, use the EntitleHub class with a pk_ key.",0,"config");this.http={baseUrl:t.baseUrl??"https://entitlehub.com/v1",apiKey:t.apiKey,fetchImpl:t.fetchImpl,timeoutMs:15e3}}async reportPurchase(t,e){let n=await a(this.http,"POST",`/subscribers/${encodeURIComponent(t)}/purchases`,{store:e.store,store_product_id:e.storeProductId,is_sandbox:!!e.isSandbox,transaction_id:e.transactionId??"",purchase_token:e.purchaseToken??"",is_subscription:!!e.isSubscription,signed_transaction:e.signedTransaction??"",stripe_subscription_id:e.stripeSubscriptionId??""});return new o(n)}async grantEntitlement(t,e,n={}){let c=await a(this.http,"POST",`/subscribers/${encodeURIComponent(t)}/grant`,{entitlement:e,duration_days:n.durationDays??0,is_sandbox:!!n.isSandbox});return new o(c)}async getCustomerInfo(t){let e=await a(this.http,"GET",`/subscribers/${encodeURIComponent(t)}`);return new o(e)}async check(t,e,n={}){return a(this.http,"POST","/check",{app_user_id:t,entitlement:e,sandbox:!!n.sandbox})}};export{o as CustomerInfo,h as EntitleHub,s as EntitleHubError,m as EntitleHubServer};
|
package/package.json
CHANGED