@monetize.software/sdk-extension 3.0.0-alpha.1 → 3.0.0-alpha.2
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/dist/chunks/{chrome-port-BXHR4SOG.js → chrome-port-DPFUj1MP.js} +144 -98
- package/dist/chunks/chrome-port-DPFUj1MP.js.map +1 -0
- package/dist/chunks/{chrome-port-EtYqHf3p.js → chrome-port-MoMohiHB.js} +2 -2
- package/dist/chunks/chrome-port-MoMohiHB.js.map +1 -0
- package/dist/content.cjs +2 -2
- package/dist/content.cjs.map +1 -1
- package/dist/content.js +37 -17
- package/dist/content.js.map +1 -1
- package/dist/offscreen.cjs +1 -1
- package/dist/offscreen.js +1 -1
- package/package.json +1 -1
- package/dist/chunks/chrome-port-BXHR4SOG.js.map +0 -1
- package/dist/chunks/chrome-port-EtYqHf3p.js.map +0 -1
package/dist/offscreen.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./chunks/chrome-port-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./chunks/chrome-port-MoMohiHB.js"),d=require("./chunks/port-name-qwB109u9.js");class u{constructor(){this.handlers=new Map,this.channels=new Set,this.active=new WeakMap,this.on("handshake",()=>({protocolVersion:r.PROTOCOL_VERSION,offscreenReady:!0}))}on(e,t){this.handlers.set(e,t)}off(e){this.handlers.delete(e)}accept(e){this.channels.add(e),this.active.set(e,new Map),e.onMessage(t=>this.dispatch(e,t)),e.onDisconnect(()=>{this.channels.delete(e);const t=this.active.get(e);if(t)for(const s of t.values())s.abort();this.active.delete(e)})}broadcast(e,t){const s={type:"event",kind:e,payload:t};for(const i of this.channels)try{i.send(s)}catch(l){console.error("[sdk-extension] broadcast send failed",l)}}get connectionCount(){return this.channels.size}async dispatch(e,t){if(p(t)){const a=this.active.get(e),h=a?.get(t.id);h&&(h.abort(),a.delete(t.id));return}if(!g(t))return;const s=this.handlers.get(t.kind);if(!s){this.respondErr(e,t.id,new Error(`Unknown request kind: ${t.kind}`));return}const i=new AbortController,l=this.active.get(e);l?.set(t.id,i);try{const a=await s(t.params,{signal:i.signal});this.respondOk(e,t.id,a)}catch(a){this.respondErr(e,t.id,a)}finally{l?.delete(t.id)}}respondOk(e,t,s){try{e.send({type:"response",id:t,ok:!0,result:s})}catch(i){console.error("[sdk-extension] respond send failed",i)}}respondErr(e,t,s){try{e.send({type:"response",id:t,ok:!1,error:r.serializeError(s)})}catch(i){console.error("[sdk-extension] respond err send failed",i)}}}function g(n){return typeof n!="object"||n===null?!1:n.type==="request"}function p(n){return typeof n!="object"||n===null?!1:n.type==="cancel"}class f{constructor(e){this.transport=new u,this.connectListener=null,this.userUnsub=null,this.balanceUnsub=null,this.authUnsub=null,e.auth&&(this.auth=new r.AuthClient({paywallId:e.paywallId,apiOrigin:e.apiOrigin})),this.billing=new r.BillingClient({paywallId:e.paywallId,apiOrigin:e.apiOrigin,auth:this.auth}),this.tracker=y(e,this.billing),this.registerBillingHandlers(),this.auth&&this.registerAuthHandlers(this.auth),this.tracker&&this.registerTrackerHandlers(this.tracker),this.bridgeBroadcasts()}registerTrackerHandlers(e){this.transport.on("tracker.track",t=>{e.track(t.name,t.props)})}registerBillingHandlers(){this.transport.on("billing.bootstrap",async(t,s)=>this.billing.bootstrap({force:t.force,signal:s.signal})),this.transport.on("billing.getCachedBootstrap",()=>this.billing.getCachedBootstrap()),this.transport.on("billing.getVisitorId",async()=>this.billing.getVisitorId()),this.transport.on("billing.getUser",async(t,s)=>this.billing.getUser({force:t.force,signal:s.signal})),this.transport.on("billing.getCachedUser",()=>this.billing.getCachedUser()),this.transport.on("billing.getBalances",async(t,s)=>this.billing.getBalances({force:t.force,signal:s.signal})),this.transport.on("billing.getCachedBalances",()=>this.billing.getCachedBalances()),this.transport.on("billing.createCheckout",async(t,s)=>this.billing.createCheckout({...t,signal:s.signal})),this.transport.on("billing.listPurchases",async(t,s)=>this.billing.listPurchases({signal:s.signal})),this.transport.on("billing.cancelSubscription",async(t,s)=>this.billing.cancelSubscription({...t,signal:s.signal})),this.transport.on("billing.getIdentity",()=>this.billing.getIdentity()??null),this.transport.on("billing.setIdentity",t=>{this.billing.setIdentity(t.identity??void 0)});const e=this.billing.getStorage();this.transport.on("storage.get",async t=>e.getItem(t.key)),this.transport.on("storage.set",async t=>{await e.setItem(t.key,t.value)}),this.transport.on("storage.remove",async t=>{await e.removeItem(t.key)}),this.transport.on("trial.check",async t=>c(t.paywallId,()=>this.makeTrialStore(t.paywallId,t.config).check())),this.transport.on("trial.recordBlock",async t=>c(t.paywallId,()=>this.makeTrialStore(t.paywallId,t.config).recordBlock())),this.transport.on("trial.reset",async t=>c(t.paywallId,()=>this.makeTrialStore(t.paywallId,t.config).reset()))}makeTrialStore(e,t){return r.createTrialStore(this.billing.getStorage(),e,t)}registerAuthHandlers(e){this.transport.on("auth.signInWithEmail",async t=>e.signInWithEmail(t)),this.transport.on("auth.signUp",async t=>e.signUp(t)),this.transport.on("auth.signOut",async()=>e.signOut()),this.transport.on("auth.refresh",async()=>e.refresh()),this.transport.on("auth.getCachedSession",()=>e.getCachedSession()),this.transport.on("auth.requestPasswordReset",async t=>e.requestPasswordReset(t)),this.transport.on("auth.updatePassword",async t=>e.updatePassword(t)),this.transport.on("auth.sendOtp",async t=>e.sendOtp(t)),this.transport.on("auth.verifyOtp",async t=>e.verifyOtp(t)),this.transport.on("auth.resendConfirmation",async t=>e.resendConfirmation(t)),this.transport.on("auth.revokeAllSessions",async()=>e.revokeAllSessions()),this.transport.on("auth.oauthStart",async t=>{const{authorize_url:s,state:i}=await e.startOAuthFlow({provider:t.provider,scopes:t.scopes,userMeta:t.userMeta});return{authorizeUrl:s,state:i}}),this.transport.on("auth.oauthExchange",async t=>e.completeOAuthFlow({state:t.state,code:t.code})),this.transport.on("auth.getAccessToken",async()=>e.getAccessToken()),this.transport.on("auth.signInAnonymously",async t=>e.signInAnonymously({captchaToken:t.captchaToken,userMeta:t.userMeta,forceCaptcha:t.forceCaptcha}))}bridgeBroadcasts(){this.userUnsub=this.billing.onUserChange(e=>this.transport.broadcast("userChange",e),{immediate:"none"}),this.balanceUnsub=this.billing.onBalanceChange(e=>this.transport.broadcast("balancesChange",e),{immediate:"none"}),this.auth&&(this.authUnsub=this.auth.onAuthChange(e=>this.transport.broadcast("authChange",e)))}start(){this.connectListener||(this.connectListener=e=>{e.name===d.PORT_NAME&&this.transport.accept(r.portToChannel(e))},chrome.runtime.onConnect.addListener(this.connectListener))}stop(){this.connectListener&&(chrome.runtime.onConnect.removeListener(this.connectListener),this.connectListener=null),this.userUnsub?.(),this.balanceUnsub?.(),this.authUnsub?.(),this.userUnsub=null,this.balanceUnsub=null,this.authUnsub=null,this.tracker?.destroy()}}async function c(n,e){return typeof navigator<"u"&&navigator.locks?.request?navigator.locks.request(`@monetize.software/sdk-extension:trial:${n}`,e):e()}function y(n,e){if(n.analytics===!1)return;const t=typeof n.analytics=="object"&&n.analytics!==null?n.analytics:{},s=t.endpoint??`${e.apiOrigin}/api/v1/paywall/${e.paywallId}/events`;return new r.EventTracker({endpoint:s,paywallId:e.paywallId,capabilities:e.capabilities,getVisitorId:()=>e.getVisitorId(),getCachedVisitorId:()=>e.getCachedVisitorId(),getUserId:()=>e.getIdentity()?.userId??null,flushIntervalMs:t.flushIntervalMs,maxBufferSize:t.maxBufferSize})}let o=null;function b(n){if(typeof chrome>"u"||!chrome.runtime)throw new Error("@monetize.software/sdk-extension/offscreen requires chrome.runtime");return o||(o=new f(n),o.start(),o)}exports.startOffscreenServer=b;
|
|
2
2
|
//# sourceMappingURL=offscreen.cjs.map
|
package/dist/offscreen.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as h, s as d, A as g, B as u, c as p, p as f, E as y } from "./chunks/chrome-port-
|
|
1
|
+
import { a as h, s as d, A as g, B as u, c as p, p as f, E as y } from "./chunks/chrome-port-DPFUj1MP.js";
|
|
2
2
|
import { P as b } from "./chunks/port-name-BPfQKtdb.js";
|
|
3
3
|
class k {
|
|
4
4
|
constructor() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monetize.software/sdk-extension",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.2",
|
|
4
4
|
"description": "Monetize SDK for Chrome extensions — single source of truth via offscreen document, drop-in compatible with @monetize.software/sdk public API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|