recur-tw 0.21.0 → 0.21.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/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/recur.umd.js +1 -1
- package/dist/server.cjs +1 -1
- package/dist/server.js +1 -1
- package/dist/vanilla.js +1 -1
- package/package.json +10 -2
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED
package/dist/recur.umd.js
CHANGED
|
@@ -2245,7 +2245,7 @@ function ee(e,t){if(!w(e)||!e.hasOwnProperty(`raw`))throw Error(`invalid templat
|
|
|
2245
2245
|
<path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"/>
|
|
2246
2246
|
<circle cx="12" cy="7" r="4"/>
|
|
2247
2247
|
</svg>
|
|
2248
|
-
`}setupEventListeners(){let e=this.shadowRoot?.querySelector(`button`);e&&e.addEventListener(`click`,this.handleClick)}redirectToPortal(e){let t=this.getAttribute(`target`);this.dispatchEvent(new CustomEvent(`portal-redirect`,{detail:{url:e},bubbles:!0,composed:!0})),t===`_blank`?window.open(e,`_blank`,`noopener,noreferrer`):window.location.href=e}async fetchAndRedirect(e){let t=this.getAttribute(`customer-id`),n=this.getAttribute(`return-url`);this._isLoading=!0,this.render(),this.setupEventListeners();try{let r={};t&&(r.customerId=t),n&&(r.returnUrl=n);let i=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r)});if(!i.ok){let e=await i.json().catch(()=>({}));throw Error(e.error?.message||e.message||`HTTP ${i.status}: Failed to create portal session`)}let a=await i.json(),o=a.url||a.portalUrl;if(!o)throw Error(`Portal URL not found in response`);this._isLoading=!1,this.render(),this.setupEventListeners(),this.redirectToPortal(o)}catch(e){this._isLoading=!1,this.render(),this.setupEventListeners(),this.dispatchError(e instanceof Error?e.message:`Failed to create portal session`)}}dispatchError(e){console.error(`[recur-portal]`,e),this.dispatchEvent(new CustomEvent(`portal-error`,{detail:{message:e},bubbles:!0,composed:!0}))}},typeof window<`u`&&!customElements.get(`recur-portal`)&&customElements.define(`recur-portal`,nt)}));async function it(){if(typeof window>`u`){console.warn(`[Recur SDK] Cannot register Web Components: window is not defined`);return}await Promise.all([Promise.resolve().then(()=>(o(),i)),Promise.resolve().then(()=>(l(),s)),Promise.resolve().then(()=>(f(),u)),Promise.resolve().then(()=>(h(),p)),Promise.resolve().then(()=>(Se(),ye)),Promise.resolve().then(()=>(Ae(),Oe)),Promise.resolve().then(()=>(Le(),Pe)),Promise.resolve().then(()=>(Ze(),Ye)),Promise.resolve().then(()=>(et(),Qe)),Promise.resolve().then(()=>(rt(),tt))]);let e=[`recur-loading-spinner`,`recur-success-message`,`recur-error-display`,`recur-skeleton-loader`,`recur-payment-form-skeleton`,`recur-toast`,`recur-toast-container`,`recur-einvoice-section`,`recur-payment-form`,`recur-checkout`,`recur-portal`].filter(e=>!customElements.get(e));e.length>0&&console.warn(`[Recur SDK] The following components are not registered:`,e)}typeof window<`u`&&it();function at(e){return e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}function X(e){if(e==null)return e;if(Array.isArray(e))return e.map(e=>X(e));if(e instanceof Date)return e;if(typeof e==`object`){let t={};for(let[n,r]of Object.entries(e)){let e=at(n);t[e]=X(r)}return t}return e}var ot=`0.21.
|
|
2248
|
+
`}setupEventListeners(){let e=this.shadowRoot?.querySelector(`button`);e&&e.addEventListener(`click`,this.handleClick)}redirectToPortal(e){let t=this.getAttribute(`target`);this.dispatchEvent(new CustomEvent(`portal-redirect`,{detail:{url:e},bubbles:!0,composed:!0})),t===`_blank`?window.open(e,`_blank`,`noopener,noreferrer`):window.location.href=e}async fetchAndRedirect(e){let t=this.getAttribute(`customer-id`),n=this.getAttribute(`return-url`);this._isLoading=!0,this.render(),this.setupEventListeners();try{let r={};t&&(r.customerId=t),n&&(r.returnUrl=n);let i=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r)});if(!i.ok){let e=await i.json().catch(()=>({}));throw Error(e.error?.message||e.message||`HTTP ${i.status}: Failed to create portal session`)}let a=await i.json(),o=a.url||a.portalUrl;if(!o)throw Error(`Portal URL not found in response`);this._isLoading=!1,this.render(),this.setupEventListeners(),this.redirectToPortal(o)}catch(e){this._isLoading=!1,this.render(),this.setupEventListeners(),this.dispatchError(e instanceof Error?e.message:`Failed to create portal session`)}}dispatchError(e){console.error(`[recur-portal]`,e),this.dispatchEvent(new CustomEvent(`portal-error`,{detail:{message:e},bubbles:!0,composed:!0}))}},typeof window<`u`&&!customElements.get(`recur-portal`)&&customElements.define(`recur-portal`,nt)}));async function it(){if(typeof window>`u`){console.warn(`[Recur SDK] Cannot register Web Components: window is not defined`);return}await Promise.all([Promise.resolve().then(()=>(o(),i)),Promise.resolve().then(()=>(l(),s)),Promise.resolve().then(()=>(f(),u)),Promise.resolve().then(()=>(h(),p)),Promise.resolve().then(()=>(Se(),ye)),Promise.resolve().then(()=>(Ae(),Oe)),Promise.resolve().then(()=>(Le(),Pe)),Promise.resolve().then(()=>(Ze(),Ye)),Promise.resolve().then(()=>(et(),Qe)),Promise.resolve().then(()=>(rt(),tt))]);let e=[`recur-loading-spinner`,`recur-success-message`,`recur-error-display`,`recur-skeleton-loader`,`recur-payment-form-skeleton`,`recur-toast`,`recur-toast-container`,`recur-einvoice-section`,`recur-payment-form`,`recur-checkout`,`recur-portal`].filter(e=>!customElements.get(e));e.length>0&&console.warn(`[Recur SDK] The following components are not registered:`,e)}typeof window<`u`&&it();function at(e){return e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}function X(e){if(e==null)return e;if(Array.isArray(e))return e.map(e=>X(e));if(e instanceof Date)return e;if(typeof e==`object`){let t={};for(let[n,r]of Object.entries(e)){let e=at(n);t[e]=X(r)}return t}return e}var ot=`0.21.2`;V();let st=ot;var ct=class{constructor(e){if(B(this,`config`,void 0),!e.publishableKey)throw Error(`publishableKey is required`);this.config={baseUrl:`https://api.recur.tw`,...e}}getHeaders(){return{"Content-Type":`application/json`,"X-Recur-Publishable-Key":this.config.publishableKey,"X-Recur-SDK-Type":`vanilla`,"X-Recur-SDK-Version":st,"X-Recur-Source":typeof window<`u`?window.location.origin:`server`}}async createSubscription(e){let{customerName:t,customerEmail:n}=e,r=e.productId||e.planId,i=e.productSlug;if(!r&&!i)throw Error(`Either productId or productSlug is required`);let a={customerName:t,customerEmail:n};r&&(a.productId=r),i&&(a.productSlug=i);let o=await fetch(`${this.config.baseUrl}/v1/subscriptions`,{method:`POST`,headers:this.getHeaders(),body:JSON.stringify(a)});if(!o.ok){let e=await o.json().catch(()=>({}));throw{code:e.error||`CHECKOUT_FAILED`,message:e.message||`Failed to initiate checkout`,details:e}}return X(await o.json())}async fetchProducts(e){let t=new URL(`${this.config.baseUrl}/v1/products`);e?.type&&t.searchParams.set(`type`,e.type);let n=await fetch(t.toString(),{method:`GET`,headers:this.getHeaders()});if(!n.ok){let e=await n.json().catch(()=>({}));throw{code:e.error||`FETCH_PRODUCTS_FAILED`,message:e.message||`Failed to fetch products`,details:e}}return X(await n.json())}async fetchPlans(){return{plans:(await this.fetchProducts({type:`SUBSCRIPTION`})).data}}getConfig(){return{...this.config}}};V();var lt=class{constructor(e,t){if(B(this,`config`,void 0),B(this,`options`,void 0),B(this,`container`,void 0),B(this,`checkoutId`,null),B(this,`sdkToken`,null),B(this,`sdkTimestamp`,null),B(this,`creditToken`,null),B(this,`sdkEnv`,`S`),B(this,`payuniSDK`,null),B(this,`isFormValid`,!1),this.config=e,this.options=t,typeof t.container==`string`){let e=document.querySelector(t.container);if(!e)throw Error(`Container not found: ${t.container}`);this.container=e}else this.container=t.container}async render(){try{await this.initCheckout(),this.renderHTML(),await this.loadPayUniSDK(),await this.initPayUniSDK(),this.setupFormSubmit()}catch(e){this.handleError(e)}}getBaseUrl(){if(this.config.baseUrl)return this.config.baseUrl;if(typeof window<`u`){let e=window.location.hostname;if(e===`localhost`||e.includes(`.test`)||e.includes(`.local`)||e===`127.0.0.1`)return`${window.location.protocol}//${window.location.host}/api`}return`https://api.recur.tw`}async initCheckout(){let e=this.getBaseUrl(),t=await fetch(`${e}/v1/checkouts`,{method:`POST`,headers:{"Content-Type":`application/json`,"X-Recur-Publishable-Key":this.config.publishableKey},body:JSON.stringify({productId:this.options.productId||this.options.planId,customerEmail:this.options.customerEmail,customerName:this.options.customerName})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`Failed to initialize checkout`)}let n=X(await t.json());this.checkoutId=n.checkout.id,this.sdkToken=n.sdkToken,this.sdkTimestamp=n.sdkTimestamp||null,this.creditToken=n.creditToken||null,this.sdkEnv=n.livemode?`P`:`S`}renderHTML(){this.container.innerHTML=`
|
|
2249
2249
|
<div class="recur-embedded-checkout" style="max-width: 400px; margin: 0 auto; padding: 20px; font-family: system-ui, -apple-system, sans-serif;">
|
|
2250
2250
|
<div class="recur-checkout-header" style="margin-bottom: 24px;">
|
|
2251
2251
|
<h2 style="margin: 0 0 8px 0; font-size: 20px; font-weight: 600; color: #111;">Subscribe</h2>
|
package/dist/server.cjs
CHANGED
package/dist/server.js
CHANGED
package/dist/vanilla.js
CHANGED
|
@@ -2245,7 +2245,7 @@ function h(e,t){if(!C(e)||!e.hasOwnProperty(`raw`))throw Error(`invalid template
|
|
|
2245
2245
|
<path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"/>
|
|
2246
2246
|
<circle cx="12" cy="7" r="4"/>
|
|
2247
2247
|
</svg>
|
|
2248
|
-
`}setupEventListeners(){let e=this.shadowRoot?.querySelector(`button`);e&&e.addEventListener(`click`,this.handleClick)}redirectToPortal(e){let t=this.getAttribute(`target`);this.dispatchEvent(new CustomEvent(`portal-redirect`,{detail:{url:e},bubbles:!0,composed:!0})),t===`_blank`?window.open(e,`_blank`,`noopener,noreferrer`):window.location.href=e}async fetchAndRedirect(e){let t=this.getAttribute(`customer-id`),n=this.getAttribute(`return-url`);this._isLoading=!0,this.render(),this.setupEventListeners();try{let r={};t&&(r.customerId=t),n&&(r.returnUrl=n);let i=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r)});if(!i.ok){let e=await i.json().catch(()=>({}));throw Error(e.error?.message||e.message||`HTTP ${i.status}: Failed to create portal session`)}let a=await i.json(),o=a.url||a.portalUrl;if(!o)throw Error(`Portal URL not found in response`);this._isLoading=!1,this.render(),this.setupEventListeners(),this.redirectToPortal(o)}catch(e){this._isLoading=!1,this.render(),this.setupEventListeners(),this.dispatchError(e instanceof Error?e.message:`Failed to create portal session`)}}dispatchError(e){console.error(`[recur-portal]`,e),this.dispatchEvent(new CustomEvent(`portal-error`,{detail:{message:e},bubbles:!0,composed:!0}))}},typeof window<`u`&&!customElements.get(`recur-portal`)&&customElements.define(`recur-portal`,Y)}));async function rt(){if(typeof window>`u`){console.warn(`[Recur SDK] Cannot register Web Components: window is not defined`);return}await Promise.all([Promise.resolve().then(()=>(a(),r)),Promise.resolve().then(()=>(c(),o)),Promise.resolve().then(()=>(d(),l)),Promise.resolve().then(()=>(m(),f)),Promise.resolve().then(()=>(Se(),ye)),Promise.resolve().then(()=>(Ae(),Oe)),Promise.resolve().then(()=>(Le(),Pe)),Promise.resolve().then(()=>(Ze(),Ye)),Promise.resolve().then(()=>(et(),Qe)),Promise.resolve().then(()=>(nt(),tt))]);let e=[`recur-loading-spinner`,`recur-success-message`,`recur-error-display`,`recur-skeleton-loader`,`recur-payment-form-skeleton`,`recur-toast`,`recur-toast-container`,`recur-einvoice-section`,`recur-payment-form`,`recur-checkout`,`recur-portal`].filter(e=>!customElements.get(e));e.length>0&&console.warn(`[Recur SDK] The following components are not registered:`,e)}typeof window<`u`&&rt();function it(e){return e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}function X(e){if(e==null)return e;if(Array.isArray(e))return e.map(e=>X(e));if(e instanceof Date)return e;if(typeof e==`object`){let t={};for(let[n,r]of Object.entries(e)){let e=it(n);t[e]=X(r)}return t}return e}var at=`0.21.
|
|
2248
|
+
`}setupEventListeners(){let e=this.shadowRoot?.querySelector(`button`);e&&e.addEventListener(`click`,this.handleClick)}redirectToPortal(e){let t=this.getAttribute(`target`);this.dispatchEvent(new CustomEvent(`portal-redirect`,{detail:{url:e},bubbles:!0,composed:!0})),t===`_blank`?window.open(e,`_blank`,`noopener,noreferrer`):window.location.href=e}async fetchAndRedirect(e){let t=this.getAttribute(`customer-id`),n=this.getAttribute(`return-url`);this._isLoading=!0,this.render(),this.setupEventListeners();try{let r={};t&&(r.customerId=t),n&&(r.returnUrl=n);let i=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r)});if(!i.ok){let e=await i.json().catch(()=>({}));throw Error(e.error?.message||e.message||`HTTP ${i.status}: Failed to create portal session`)}let a=await i.json(),o=a.url||a.portalUrl;if(!o)throw Error(`Portal URL not found in response`);this._isLoading=!1,this.render(),this.setupEventListeners(),this.redirectToPortal(o)}catch(e){this._isLoading=!1,this.render(),this.setupEventListeners(),this.dispatchError(e instanceof Error?e.message:`Failed to create portal session`)}}dispatchError(e){console.error(`[recur-portal]`,e),this.dispatchEvent(new CustomEvent(`portal-error`,{detail:{message:e},bubbles:!0,composed:!0}))}},typeof window<`u`&&!customElements.get(`recur-portal`)&&customElements.define(`recur-portal`,Y)}));async function rt(){if(typeof window>`u`){console.warn(`[Recur SDK] Cannot register Web Components: window is not defined`);return}await Promise.all([Promise.resolve().then(()=>(a(),r)),Promise.resolve().then(()=>(c(),o)),Promise.resolve().then(()=>(d(),l)),Promise.resolve().then(()=>(m(),f)),Promise.resolve().then(()=>(Se(),ye)),Promise.resolve().then(()=>(Ae(),Oe)),Promise.resolve().then(()=>(Le(),Pe)),Promise.resolve().then(()=>(Ze(),Ye)),Promise.resolve().then(()=>(et(),Qe)),Promise.resolve().then(()=>(nt(),tt))]);let e=[`recur-loading-spinner`,`recur-success-message`,`recur-error-display`,`recur-skeleton-loader`,`recur-payment-form-skeleton`,`recur-toast`,`recur-toast-container`,`recur-einvoice-section`,`recur-payment-form`,`recur-checkout`,`recur-portal`].filter(e=>!customElements.get(e));e.length>0&&console.warn(`[Recur SDK] The following components are not registered:`,e)}typeof window<`u`&&rt();function it(e){return e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}function X(e){if(e==null)return e;if(Array.isArray(e))return e.map(e=>X(e));if(e instanceof Date)return e;if(typeof e==`object`){let t={};for(let[n,r]of Object.entries(e)){let e=it(n);t[e]=X(r)}return t}return e}var at=`0.21.2`;B();const ot=at;var st=class{constructor(e){if(z(this,`config`,void 0),!e.publishableKey)throw Error(`publishableKey is required`);this.config={baseUrl:`https://api.recur.tw`,...e}}getHeaders(){return{"Content-Type":`application/json`,"X-Recur-Publishable-Key":this.config.publishableKey,"X-Recur-SDK-Type":`vanilla`,"X-Recur-SDK-Version":ot,"X-Recur-Source":typeof window<`u`?window.location.origin:`server`}}async createSubscription(e){let{customerName:t,customerEmail:n}=e,r=e.productId||e.planId,i=e.productSlug;if(!r&&!i)throw Error(`Either productId or productSlug is required`);let a={customerName:t,customerEmail:n};r&&(a.productId=r),i&&(a.productSlug=i);let o=await fetch(`${this.config.baseUrl}/v1/subscriptions`,{method:`POST`,headers:this.getHeaders(),body:JSON.stringify(a)});if(!o.ok){let e=await o.json().catch(()=>({}));throw{code:e.error||`CHECKOUT_FAILED`,message:e.message||`Failed to initiate checkout`,details:e}}return X(await o.json())}async fetchProducts(e){let t=new URL(`${this.config.baseUrl}/v1/products`);e?.type&&t.searchParams.set(`type`,e.type);let n=await fetch(t.toString(),{method:`GET`,headers:this.getHeaders()});if(!n.ok){let e=await n.json().catch(()=>({}));throw{code:e.error||`FETCH_PRODUCTS_FAILED`,message:e.message||`Failed to fetch products`,details:e}}return X(await n.json())}async fetchPlans(){return{plans:(await this.fetchProducts({type:`SUBSCRIPTION`})).data}}getConfig(){return{...this.config}}};B();var ct=class{constructor(e,t){if(z(this,`config`,void 0),z(this,`options`,void 0),z(this,`container`,void 0),z(this,`checkoutId`,null),z(this,`sdkToken`,null),z(this,`sdkTimestamp`,null),z(this,`creditToken`,null),z(this,`sdkEnv`,`S`),z(this,`payuniSDK`,null),z(this,`isFormValid`,!1),this.config=e,this.options=t,typeof t.container==`string`){let e=document.querySelector(t.container);if(!e)throw Error(`Container not found: ${t.container}`);this.container=e}else this.container=t.container}async render(){try{await this.initCheckout(),this.renderHTML(),await this.loadPayUniSDK(),await this.initPayUniSDK(),this.setupFormSubmit()}catch(e){this.handleError(e)}}getBaseUrl(){if(this.config.baseUrl)return this.config.baseUrl;if(typeof window<`u`){let e=window.location.hostname;if(e===`localhost`||e.includes(`.test`)||e.includes(`.local`)||e===`127.0.0.1`)return`${window.location.protocol}//${window.location.host}/api`}return`https://api.recur.tw`}async initCheckout(){let e=this.getBaseUrl(),t=await fetch(`${e}/v1/checkouts`,{method:`POST`,headers:{"Content-Type":`application/json`,"X-Recur-Publishable-Key":this.config.publishableKey},body:JSON.stringify({productId:this.options.productId||this.options.planId,customerEmail:this.options.customerEmail,customerName:this.options.customerName})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`Failed to initialize checkout`)}let n=X(await t.json());this.checkoutId=n.checkout.id,this.sdkToken=n.sdkToken,this.sdkTimestamp=n.sdkTimestamp||null,this.creditToken=n.creditToken||null,this.sdkEnv=n.livemode?`P`:`S`}renderHTML(){this.container.innerHTML=`
|
|
2249
2249
|
<div class="recur-embedded-checkout" style="max-width: 400px; margin: 0 auto; padding: 20px; font-family: system-ui, -apple-system, sans-serif;">
|
|
2250
2250
|
<div class="recur-checkout-header" style="margin-bottom: 24px;">
|
|
2251
2251
|
<h2 style="margin: 0 0 8px 0; font-size: 20px; font-weight: 600; color: #111;">Subscribe</h2>
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "recur-tw",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.2",
|
|
4
4
|
"description": "React & Vanilla JS SDK for embedding subscription checkout flows (Taiwan / PAYUNi)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"author": "Recur",
|
|
8
8
|
"license": "Elastic-2.0",
|
|
9
9
|
"keywords": [
|
|
10
|
+
"recur",
|
|
11
|
+
"recur-tw",
|
|
10
12
|
"react",
|
|
11
13
|
"vanilla-js",
|
|
12
14
|
"subscription",
|
|
@@ -20,7 +22,13 @@
|
|
|
20
22
|
"embedded-checkout"
|
|
21
23
|
],
|
|
22
24
|
"homepage": "https://recur.tw/",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/kaikhq/recur.tw.git",
|
|
28
|
+
"directory": "packages/recur-sdk"
|
|
29
|
+
},
|
|
23
30
|
"bugs": {
|
|
31
|
+
"url": "https://github.com/kaikhq/recur.tw/issues",
|
|
24
32
|
"email": "support@recur.tw"
|
|
25
33
|
},
|
|
26
34
|
"main": "./dist/index.js",
|
|
@@ -115,7 +123,7 @@
|
|
|
115
123
|
"tsdown": "^0.22.12",
|
|
116
124
|
"typescript": "^6.0.3",
|
|
117
125
|
"typescript-eslint": "^8.47.0",
|
|
118
|
-
"vitest": "^4.1.
|
|
126
|
+
"vitest": "^4.1.10",
|
|
119
127
|
"@workspace/einvoice": "0.0.1",
|
|
120
128
|
"@workspace/typescript-config": "0.0.0"
|
|
121
129
|
},
|