@tekrom/tsoft-app-gate 0.7.0 → 0.8.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.
- package/README.md +13 -2
- package/dist/client.d.ts +6 -0
- package/dist/client.js +3 -0
- package/dist/protocol.d.ts +2 -0
- package/dist/tsoft-app-gate.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,13 +9,13 @@ npm install @tekrom/tsoft-app-gate
|
|
|
9
9
|
Paketleyici kullanmıyorsanız tarayıcı derlemesini `<script>` ile yükleyin; aynı API `TSoftAppGate` global'i altında gelir:
|
|
10
10
|
|
|
11
11
|
```html
|
|
12
|
-
<script src="https://cdn.jsdelivr.net/npm/@tekrom/tsoft-app-gate@0.
|
|
12
|
+
<script src="https://cdn.jsdelivr.net/npm/@tekrom/tsoft-app-gate@0.8/dist/tsoft-app-gate.min.js"></script>
|
|
13
13
|
<script>
|
|
14
14
|
const app = TSoftAppGate.createApp();
|
|
15
15
|
</script>
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
Sürümü sabitleyin (`@0.
|
|
18
|
+
Sürümü sabitleyin (`@0.8` ya da tam sürüm); üretimde dosyayı kendi sunucunuzdan sunmak da mümkündür.
|
|
19
19
|
|
|
20
20
|
## Hızlı başlangıç
|
|
21
21
|
|
|
@@ -193,6 +193,16 @@ const { status } = await app.billing.confirm({ id: charge.id });
|
|
|
193
193
|
if (status === 'active') await refreshCredits(); // sunucu Admin API'den doğrular
|
|
194
194
|
```
|
|
195
195
|
|
|
196
|
+
### `billing.selectPlan()`
|
|
197
|
+
|
|
198
|
+
Panelin plan seçme ekranını açar. Mağaza sahibi, partner panelinde tanımladığınız planları görür, birini seçer ve ücretliyse öder; ardından panel uygulamanızı yeniden açar. Ekran değişirken iframe kapanır, bu yüzden promise sonucu beklemeden çözülür. Yeni planı uygulama yeniden açılınca sunucunuzda Admin API'den (`integration/app-subscriptions`) okuyun ya da `app_subscription.updated` olayını dinleyin.
|
|
199
|
+
|
|
200
|
+
Uygulamanın planı yoksa panel normal kurulum ekranını açar. Eski panellerde `unsupported_type` döner.
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
upgradeButton.onclick = () => app.billing.selectPlan();
|
|
204
|
+
```
|
|
205
|
+
|
|
196
206
|
### `setHeight(height)` ve `autoResize({ target? })`
|
|
197
207
|
|
|
198
208
|
`setHeight` iframe yüksekliğini piksel olarak ayarlar; panel değeri 300–5000 aralığına sıkıştırır. Yükseklik hiç bildirilmezse iframe görünür alanı doldurur.
|
|
@@ -275,6 +285,7 @@ Kurallar:
|
|
|
275
285
|
| `nav.set` | `{ items: [{ label, path }] }` | `{}` | `invalid_payload` |
|
|
276
286
|
| `modal.close` | `{ refresh? }` | `{}` | `unsupported_type` (tam sayfada) |
|
|
277
287
|
| `billing.confirm` | `{ id }` | `{ status }` | `invalid_payload`, `charge_not_found`, `internal_error` |
|
|
288
|
+
| `billing.selectPlan` | `{}` | `{}` (panel plan ekranına geçer) | — |
|
|
278
289
|
| diğer | — | — | `unsupported_type` |
|
|
279
290
|
|
|
280
291
|
`confirm.open`, `resource.pick` ve `billing.confirm` yanıtı kullanıcı işlem yapınca gelir.
|
package/dist/client.d.ts
CHANGED
|
@@ -113,6 +113,12 @@ export interface App {
|
|
|
113
113
|
* sunucunuzda Admin API ile doğrulayın.
|
|
114
114
|
*/
|
|
115
115
|
confirm(options: BillingConfirmOptions): Promise<BillingConfirmResult>;
|
|
116
|
+
/**
|
|
117
|
+
* Panelin plan seçme ekranını açar: mağaza sahibi partner panelinde tanımladığınız planlardan birini
|
|
118
|
+
* seçer, ücretliyse öder; ardından panel uygulamanızı yeniden açar. Promise, panel ekrana geçerken
|
|
119
|
+
* çözülür (iframe kapanır). Yeni planı uygulama açılınca Admin API'den (`app-subscriptions`) okuyun.
|
|
120
|
+
*/
|
|
121
|
+
selectPlan(options?: RequestOptions): Promise<void>;
|
|
116
122
|
};
|
|
117
123
|
/** Panelin seçicisini açar. Varsayılan olarak zaman aşımı yoktur. */
|
|
118
124
|
pickResource(options: PickOptions): Promise<PickResult>;
|
package/dist/client.js
CHANGED
|
@@ -177,6 +177,9 @@ export function createApp(options = {}) {
|
|
|
177
177
|
// Tanınmayan durum, ödenmiş sayılmasın diye `pending` kabul edilir.
|
|
178
178
|
return { status: CHARGE_STATUSES.includes(response.status) ? response.status : 'pending' };
|
|
179
179
|
},
|
|
180
|
+
selectPlan(requestOptions = {}) {
|
|
181
|
+
return empty('billing.selectPlan', {}, requestOptions);
|
|
182
|
+
},
|
|
180
183
|
},
|
|
181
184
|
async pickResource({ type, multiple, ...rest }) {
|
|
182
185
|
const response = await request('resource.pick', { type, multiple: multiple === true }, rest, 0);
|
package/dist/protocol.d.ts
CHANGED
|
@@ -80,6 +80,7 @@ export interface RequestPayloads {
|
|
|
80
80
|
'billing.confirm': {
|
|
81
81
|
id: string;
|
|
82
82
|
};
|
|
83
|
+
'billing.selectPlan': Record<string, never>;
|
|
83
84
|
}
|
|
84
85
|
export interface ResponsePayloads {
|
|
85
86
|
'session-token.get': {
|
|
@@ -103,6 +104,7 @@ export interface ResponsePayloads {
|
|
|
103
104
|
'billing.confirm': {
|
|
104
105
|
status: ChargeStatus;
|
|
105
106
|
};
|
|
107
|
+
'billing.selectPlan': Record<string, never>;
|
|
106
108
|
}
|
|
107
109
|
export type RequestType = keyof RequestPayloads;
|
|
108
110
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var TSoftAppGate=(()=>{var S=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var z=(s,o)=>{for(var i in o)S(s,i,{get:o[i],enumerable:!0})},V=(s,o,i,g)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of D(o))!U.call(s,a)&&a!==i&&S(s,a,{get:()=>o[a],enumerable:!(g=L(o,a))||g.enumerable});return s};var G=s=>V(S({},"__esModule",{value:!0}),s);var J={};z(J,{APP_SOURCE:()=>T,AppBridgeError:()=>p,BRIDGE_VERSION:()=>P,PANEL_ORIGIN_PATTERN:()=>b,PANEL_SOURCE:()=>
|
|
1
|
+
"use strict";var TSoftAppGate=(()=>{var S=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var z=(s,o)=>{for(var i in o)S(s,i,{get:o[i],enumerable:!0})},V=(s,o,i,g)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of D(o))!U.call(s,a)&&a!==i&&S(s,a,{get:()=>o[a],enumerable:!(g=L(o,a))||g.enumerable});return s};var G=s=>V(S({},"__esModule",{value:!0}),s);var J={};z(J,{APP_SOURCE:()=>T,AppBridgeError:()=>p,BRIDGE_VERSION:()=>P,PANEL_ORIGIN_PATTERN:()=>b,PANEL_SOURCE:()=>O,createApp:()=>N,decodeSessionToken:()=>x,isEmbedded:()=>E});var P=1,T="tsoft-app",O="tsoft-panel";var p=class extends Error{constructor(o,i){super(i!=null?i:`T-Soft App Bridge: ${o}`),this.name="AppBridgeError",this.code=o}},M=1e4,F=["pending","active","declined","expired"],j=15e3,b=/^https:\/\/([a-z0-9-]+\.)*(tsoftpanel\.com|tsoftpanel\.net|paneltsoft\.com)$/;function E(){return typeof window!="undefined"&&window.parent!==window}function $(){let s=window.location.ancestorOrigins;if(s&&s.length>0)return s[0];try{return document.referrer?new URL(document.referrer).origin:null}catch(o){return null}}function x(s){try{let o=atob(s.split(".")[1].replace(/-/g,"+").replace(/_/g,"/")),i=JSON.parse(new TextDecoder().decode(Uint8Array.from(o,g=>g.charCodeAt(0))));return i&&typeof i.exp=="number"?i:null}catch(o){return null}}function H(s){return s!==null&&s.expiresAt-j>Date.now()}function N(s={}){var q,C;if(!E())throw new p("not_embedded","T-Soft App Bridge: uygulama panel iframe'i i\xE7inde a\xE7\u0131lmam\u0131\u015F");let o=s.panelOrigin?null:$();if(!s.panelOrigin&&!(o&&b.test(o)))throw new p("not_embedded",`T-Soft App Bridge: \xFCst pencere bir T-Soft paneli de\u011Fil (${o!=null?o:"bilinmiyor"})`);let i=(q=s.panelOrigin)!=null?q:o,g=(C=s.timeout)!=null?C:M,a=new Map,h=new URLSearchParams(window.location.search),v=h.get("session"),I=0,A=!1,l=null,R=null;if(v){let t=x(v);t&&(l={token:v,claims:t,expiresAt:t.exp*1e3,scopes:null})}function k(t){var r;if(t.source!==window.parent||t.origin!==i)return;let e=t.data;if((e==null?void 0:e.source)!==O||(e==null?void 0:e.version)!==1||typeof(e==null?void 0:e.id)!="string")return;let n=a.get(e.id);n&&(a.delete(e.id),clearTimeout(n.timer),e.ok===!0?n.resolve((r=e.payload)!=null?r:{}):n.reject(new p(typeof e.error=="string"?e.error:"internal_error")))}window.addEventListener("message",k);function u(t,e,n={},r=g){var f;if(A)return Promise.reject(new p("destroyed"));let d=`app-${Date.now().toString(36)}-${(I++).toString(36)}`,m=(f=n.timeout)!=null?f:r;return new Promise((y,_)=>{let B={resolve:y,reject:_};m>0&&(B.timer=setTimeout(()=>{a.delete(d),_(new p("timeout"))},m)),a.set(d,B),window.parent.postMessage({source:T,version:1,id:d,type:t,payload:e},i)})}async function w(t={}){return!t.forceRefresh&&H(l)?l:(R!=null||(R=u("session-token.get",{},t).then(e=>(l={token:e.token,claims:x(e.token),expiresAt:Date.now()+e.expires_in*1e3,scopes:Array.isArray(e.scopes)?e.scopes:[]},l)).finally(()=>{R=null})),R)}async function c(t,e,n){await u(t,e,n)}return{panelOrigin:i,get claims(){var t;return(t=l==null?void 0:l.claims)!=null?t:null},installCode:h.get("code"),getSession:w,async getSessionToken(t){return(await w(t)).token},toast(t,{variant:e,...n}={}){return c("toast.show",e?{message:t,variant:e}:{message:t},n)},async confirm(t){let{message:e,title:n,confirmText:r,...d}=typeof t=="string"?{message:t}:t;return(await u("confirm.open",{message:e,title:n,confirmText:r},d,0)).confirmed===!0},navigate:{app(t,e){return c("navigate.app",{path:t},e)},panel(t,e,n){return typeof e=="string"||typeof e=="number"?c("navigate.panel",{resource:t,id:String(e)},n):c("navigate.panel",{resource:t},e)}},nav:{set(t,e){return c("nav.set",{items:t.map(({label:n,path:r})=>({label:n,path:r}))},e)}},modal:{close({refresh:t,...e}={}){return c("modal.close",{refresh:t===!0},e)}},billing:{async confirm({id:t,...e}){let n=await u("billing.confirm",{id:String(t)},e,0);return{status:F.includes(n.status)?n.status:"pending"}},selectPlan(t={}){return c("billing.selectPlan",{},t)}},async pickResource({type:t,multiple:e,...n}){let r=await u("resource.pick",{type:t,multiple:e===!0},n,0);return{ids:Array.isArray(r.ids)?r.ids:[],cancelled:r.cancelled===!0}},setHeight(t,e){return c("size.set",{height:Math.ceil(t)},e)},autoResize({target:t}={}){let e=t!=null?t:document.body,n=0,r=0,d=()=>{r=0;let f=getComputedStyle(e),y=Math.ceil(e.getBoundingClientRect().height+parseFloat(f.marginTop)+parseFloat(f.marginBottom));y!==n&&(n=y,u("size.set",{height:y}).catch(()=>{}))},m=new ResizeObserver(()=>{r||(r=requestAnimationFrame(d))});return m.observe(e),()=>{m.disconnect(),r&&cancelAnimationFrame(r)}},request:u,destroy(){A=!0,window.removeEventListener("message",k);for(let t of a.values())clearTimeout(t.timer),t.reject(new p("destroyed"));a.clear()}}}return G(J);})();
|