@tekrom/tsoft-app-gate 0.6.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # T-Soft App Gate
2
2
 
3
- T-Soft paneli içinde (iframe) açılan uygulamalar için **App Bridge** istemcisi. Uygulama, panelden oturum token'ı alır; panelin bildirim, onay penceresi, ürün seçici ve gezinme bileşenlerini kullanır; iframe yüksekliğini ayarlar. Tüm çağrılar promise döner, zaman aşımına ve hata kodlarına sahiptir.
3
+ T-Soft paneli içinde (iframe) açılan uygulamalar için **App Bridge** istemcisi. Uygulama, panelden oturum token'ı alır; panelin bildirim, onay penceresi, ürün seçici, ödeme onayı ve gezinme bileşenlerini kullanır; iframe yüksekliğini ayarlar. Tüm çağrılar promise döner, zaman aşımına ve hata kodlarına sahiptir.
4
4
 
5
5
  ```bash
6
6
  npm install @tekrom/tsoft-app-gate
@@ -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.5/dist/tsoft-app-gate.min.js"></script>
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.4` ya da tam sürüm); üretimde dosyayı kendi sunucunuzdan sunmak da mümkündür.
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
 
@@ -56,6 +56,9 @@ await app.nav.set([
56
56
  ]);
57
57
 
58
58
  const stop = app.autoResize();
59
+
60
+ // Tek seferlik ücret: sunucunuz Admin API ile ücreti oluşturur, kimliği buraya verir.
61
+ const { status } = await app.billing.confirm({ id: chargeId });
59
62
  ```
60
63
 
61
64
  ## API
@@ -170,6 +173,36 @@ try {
170
173
  }
171
174
  ``` Seçici açıkken yeni bir seçim istenirse önceki istek `cancelled: true` ile kapanır.
172
175
 
176
+ ### `billing.confirm({ id })`
177
+
178
+ Tek seferlik ücretin (Admin API `app-one-time-charges`) onay ekranını panelde açar. Mağaza sahibi uygulama adını, ücretin adını, KDV hariç fiyatı, KDV'yi ve toplamı görür; onaylarsa panel ödeme ekranını açar. Sonuç `{ status }`:
179
+
180
+ | `status` | Anlamı |
181
+ |---|---|
182
+ | `active` | Onaylandı ve ödendi (test ücretinde hemen). |
183
+ | `declined` | Mağaza sahibi reddetti. |
184
+ | `pending` | Ekran ödeme bitmeden kapatıldı; ödeme sonradan tamamlanabilir. |
185
+ | `expired` | Ücret 48 saat içinde onaylanmadı; yenisini oluşturun. |
186
+
187
+ Ödeme dakikalar sürebildiği için **varsayılan olarak zaman aşımı yoktur.** Dönen durum yalnız arayüz içindir; hizmeti açmadan önce durumu **sunucunuzda Admin API ile doğrulayın.** `pending` dönen ücret sonradan `active` olabilir.
188
+
189
+ Kimlik başka bir uygulamanın ücretine aitse ya da bulunamazsa `charge_not_found` döner. Eski panellerde `unsupported_type` döner; o durumda mağaza sahibini ücretin onay sayfasına (`/apps/charges/{id}`) yönlendirebilirsiniz.
190
+
191
+ ```ts
192
+ const { status } = await app.billing.confirm({ id: charge.id });
193
+ if (status === 'active') await refreshCredits(); // sunucu Admin API'den doğrular
194
+ ```
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
+
173
206
  ### `setHeight(height)` ve `autoResize({ target? })`
174
207
 
175
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.
@@ -196,6 +229,7 @@ Tüm reddedilen promise'ler `AppBridgeError` taşır; `code` alanı aşağıdaki
196
229
  | `missing_scope` | panel | Uygulamanın bu iş için gereken kapsamı yok. |
197
230
  | `unsupported_resource` | panel | `pickResource` türü desteklenmiyor. |
198
231
  | `unsupported_type` | panel | Panel bu mesaj tipini tanımıyor (eski panel sürümü). |
232
+ | `charge_not_found` | panel | `billing.confirm` kimliği bu uygulamanın bir ücreti değil. |
199
233
  | `internal_error` | panel | Panel isteği işlerken hata aldı (ör. token alınamadı). |
200
234
  | `timeout` | istemci | Süre içinde yanıt gelmedi. |
201
235
  | `not_embedded` | istemci | Uygulama panel iframe'i içinde değil ya da üst pencere bir T-Soft paneli değil. |
@@ -250,9 +284,11 @@ Kurallar:
250
284
  | `size.set` | `{ height }` | `{}` | `invalid_payload` |
251
285
  | `nav.set` | `{ items: [{ label, path }] }` | `{}` | `invalid_payload` |
252
286
  | `modal.close` | `{ refresh? }` | `{}` | `unsupported_type` (tam sayfada) |
287
+ | `billing.confirm` | `{ id }` | `{ status }` | `invalid_payload`, `charge_not_found`, `internal_error` |
288
+ | `billing.selectPlan` | `{}` | `{}` (panel plan ekranına geçer) | — |
253
289
  | diğer | — | — | `unsupported_type` |
254
290
 
255
- `confirm.open` ve `resource.pick` yanıtı kullanıcı işlem yapınca gelir.
291
+ `confirm.open`, `resource.pick` ve `billing.confirm` yanıtı kullanıcı işlem yapınca gelir.
256
292
 
257
293
  ### Eski token mesajı
258
294
 
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type BridgeErrorCode, type NavItem, type PanelDetailResource, type PanelListResource, type PickableResource, type RequestPayloads, type RequestType, type ResponsePayloads, type ToastVariant } from './protocol.js';
1
+ import { type BridgeErrorCode, type ChargeStatus, type NavItem, type PanelDetailResource, type PanelListResource, type PickableResource, type RequestPayloads, type RequestType, type ResponsePayloads, type ToastVariant } from './protocol.js';
2
2
  export declare class AppBridgeError extends Error {
3
3
  readonly code: BridgeErrorCode;
4
4
  constructor(code: BridgeErrorCode, message?: string);
@@ -57,6 +57,13 @@ export interface PickResult {
57
57
  ids: Array<string | number>;
58
58
  cancelled: boolean;
59
59
  }
60
+ export interface BillingConfirmOptions extends RequestOptions {
61
+ /** Uygulamanın sunucusunun Admin API ile oluşturduğu tek seferlik ücretin kimliği. */
62
+ id: string;
63
+ }
64
+ export interface BillingConfirmResult {
65
+ status: ChargeStatus;
66
+ }
60
67
  export interface AutoResizeOptions {
61
68
  /** Yüksekliği ölçülecek öğe. Varsayılan `document.body`. */
62
69
  target?: Element;
@@ -98,6 +105,21 @@ export interface App {
98
105
  refresh?: boolean;
99
106
  } & RequestOptions): Promise<void>;
100
107
  };
108
+ billing: {
109
+ /**
110
+ * Tek seferlik ücretin onay ekranını panelde açar; kullanıcı onaylar ve öderse `active`,
111
+ * reddederse `declined`, ekranı kapatırsa son bilinen durum (çoğunlukla `pending`) döner.
112
+ * Ödeme dakikalar sürebileceği için varsayılan olarak zaman aşımı yoktur. Sonucu her zaman
113
+ * sunucunuzda Admin API ile doğrulayın.
114
+ */
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>;
122
+ };
101
123
  /** Panelin seçicisini açar. Varsayılan olarak zaman aşımı yoktur. */
102
124
  pickResource(options: PickOptions): Promise<PickResult>;
103
125
  /** iframe yüksekliğini ayarlar; panel 300–5000 px aralığına sıkıştırır. */
package/dist/client.js CHANGED
@@ -7,6 +7,7 @@ export class AppBridgeError extends Error {
7
7
  }
8
8
  }
9
9
  const DEFAULT_TIMEOUT = 10000;
10
+ const CHARGE_STATUSES = ['pending', 'active', 'declined', 'expired'];
10
11
  // Token 60 sn yaşar; sunucuya giderken süresi dolmasın diye 15 sn kala yenilenir.
11
12
  const REFRESH_MARGIN = 15000;
12
13
  /** Panelin yayınlandığı alan adları (t-panel `PANEL_DOMAINS`). */
@@ -170,6 +171,16 @@ export function createApp(options = {}) {
170
171
  return empty('modal.close', { refresh: refresh === true }, requestOptions);
171
172
  },
172
173
  },
174
+ billing: {
175
+ async confirm({ id, ...rest }) {
176
+ const response = await request('billing.confirm', { id: String(id) }, rest, 0);
177
+ // Tanınmayan durum, ödenmiş sayılmasın diye `pending` kabul edilir.
178
+ return { status: CHARGE_STATUSES.includes(response.status) ? response.status : 'pending' };
179
+ },
180
+ selectPlan(requestOptions = {}) {
181
+ return empty('billing.selectPlan', {}, requestOptions);
182
+ },
183
+ },
173
184
  async pickResource({ type, multiple, ...rest }) {
174
185
  const response = await request('resource.pick', { type, multiple: multiple === true }, rest, 0);
175
186
  return { ids: Array.isArray(response.ids) ? response.ids : [], cancelled: response.cancelled === true };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { createApp, isEmbedded, decodeSessionToken, AppBridgeError, PANEL_ORIGIN_PATTERN } from './client.js';
2
- export type { App, AppOptions, AutoResizeOptions, ConfirmOptions, PickOptions, PickResult, RequestOptions, SessionClaims, SessionToken, ToastOptions, } from './client.js';
2
+ export type { App, AppOptions, AutoResizeOptions, BillingConfirmOptions, BillingConfirmResult, ConfirmOptions, PickOptions, PickResult, RequestOptions, SessionClaims, SessionToken, ToastOptions, } from './client.js';
3
3
  export { BRIDGE_VERSION, APP_SOURCE, PANEL_SOURCE } from './protocol.js';
4
- export type { BridgeErrorCode, BridgeRequest, BridgeResponse, NavItem, PanelDetailResource, PanelListResource, PanelResource, PickableResource, RequestPayloads, RequestType, ResponsePayloads, ToastVariant, } from './protocol.js';
4
+ export type { BridgeErrorCode, BridgeRequest, BridgeResponse, ChargeStatus, NavItem, PanelDetailResource, PanelListResource, PanelResource, PickableResource, RequestPayloads, RequestType, ResponsePayloads, ToastVariant, } from './protocol.js';
@@ -35,6 +35,8 @@ export type PanelResource = PanelListResource | PanelDetailResource;
35
35
  * `category` eski panellerde `unsupported_resource` döner.
36
36
  */
37
37
  export type PickableResource = 'product' | 'category';
38
+ /** Tek seferlik ücretin durumu. */
39
+ export type ChargeStatus = 'pending' | 'active' | 'declined' | 'expired';
38
40
  /**
39
41
  * Panelin sol menüsünde uygulamanın adı altında görünen bağlantı. `path` uygulamanın
40
42
  * kendi adresi altında `/` ile başlayan yol olmalı (`/orders?status=1` gibi); etiket
@@ -75,6 +77,10 @@ export interface RequestPayloads {
75
77
  'modal.close': {
76
78
  refresh?: boolean;
77
79
  };
80
+ 'billing.confirm': {
81
+ id: string;
82
+ };
83
+ 'billing.selectPlan': Record<string, never>;
78
84
  }
79
85
  export interface ResponsePayloads {
80
86
  'session-token.get': {
@@ -95,10 +101,14 @@ export interface ResponsePayloads {
95
101
  'size.set': Record<string, never>;
96
102
  'nav.set': Record<string, never>;
97
103
  'modal.close': Record<string, never>;
104
+ 'billing.confirm': {
105
+ status: ChargeStatus;
106
+ };
107
+ 'billing.selectPlan': Record<string, never>;
98
108
  }
99
109
  export type RequestType = keyof RequestPayloads;
100
110
  /**
101
111
  * Panelin döndürdüğü hata kodları ile istemcinin kendi ürettikleri.
102
112
  * Bilinmeyen kodlar da string olarak geçer.
103
113
  */
104
- export type BridgeErrorCode = 'invalid_payload' | 'invalid_path' | 'invalid_route' | 'missing_scope' | 'unsupported_resource' | 'unsupported_type' | 'internal_error' | 'timeout' | 'not_embedded' | 'destroyed' | (string & {});
114
+ export type BridgeErrorCode = 'invalid_payload' | 'invalid_path' | 'invalid_route' | 'missing_scope' | 'unsupported_resource' | 'unsupported_type' | 'charge_not_found' | 'internal_error' | 'timeout' | 'not_embedded' | 'destroyed' | (string & {});
@@ -1 +1 @@
1
- "use strict";var TSoftAppGate=(()=>{var E=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var z=(n,o)=>{for(var i in o)E(n,i,{get:o[i],enumerable:!0})},V=(n,o,i,d)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of D(o))!U.call(n,a)&&a!==i&&E(n,a,{get:()=>o[a],enumerable:!(d=L(o,a))||d.enumerable});return n};var G=n=>V(E({},"__esModule",{value:!0}),n);var H={};z(H,{APP_SOURCE:()=>T,AppBridgeError:()=>p,BRIDGE_VERSION:()=>P,PANEL_ORIGIN_PATTERN:()=>b,PANEL_SOURCE:()=>O,createApp:()=>B,decodeSessionToken:()=>v,isEmbedded:()=>S});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=15e3,b=/^https:\/\/([a-z0-9-]+\.)*(tsoftpanel\.com|tsoftpanel\.net|paneltsoft\.com)$/;function S(){return typeof window!="undefined"&&window.parent!==window}function j(){let n=window.location.ancestorOrigins;if(n&&n.length>0)return n[0];try{return document.referrer?new URL(document.referrer).origin:null}catch(o){return null}}function v(n){try{let o=atob(n.split(".")[1].replace(/-/g,"+").replace(/_/g,"/")),i=JSON.parse(new TextDecoder().decode(Uint8Array.from(o,d=>d.charCodeAt(0))));return i&&typeof i.exp=="number"?i:null}catch(o){return null}}function $(n){return n!==null&&n.expiresAt-F>Date.now()}function B(n={}){var q,_;if(!S())throw new p("not_embedded","T-Soft App Bridge: uygulama panel iframe'i i\xE7inde a\xE7\u0131lmam\u0131\u015F");let o=n.panelOrigin?null:j();if(!n.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=n.panelOrigin)!=null?q:o,d=(_=n.timeout)!=null?_:M,a=new Map,k=new URLSearchParams(window.location.search),x=k.get("session"),I=0,A=!1,l=null,R=null;if(x){let t=v(x);t&&(l={token:x,claims:t,expiresAt:t.exp*1e3,scopes:null})}function w(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 s=a.get(e.id);s&&(a.delete(e.id),clearTimeout(s.timer),e.ok===!0?s.resolve((r=e.payload)!=null?r:{}):s.reject(new p(typeof e.error=="string"?e.error:"internal_error")))}window.addEventListener("message",w);function m(t,e,s={},r=d){var f;if(A)return Promise.reject(new p("destroyed"));let u=`app-${Date.now().toString(36)}-${(I++).toString(36)}`,g=(f=s.timeout)!=null?f:r;return new Promise((y,C)=>{let N={resolve:y,reject:C};g>0&&(N.timer=setTimeout(()=>{a.delete(u),C(new p("timeout"))},g)),a.set(u,N),window.parent.postMessage({source:T,version:1,id:u,type:t,payload:e},i)})}async function h(t={}){return!t.forceRefresh&&$(l)?l:(R!=null||(R=m("session-token.get",{},t).then(e=>(l={token:e.token,claims:v(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,s){await m(t,e,s)}return{panelOrigin:i,get claims(){var t;return(t=l==null?void 0:l.claims)!=null?t:null},installCode:k.get("code"),getSession:h,async getSessionToken(t){return(await h(t)).token},toast(t,{variant:e,...s}={}){return c("toast.show",e?{message:t,variant:e}:{message:t},s)},async confirm(t){let{message:e,title:s,confirmText:r,...u}=typeof t=="string"?{message:t}:t;return(await m("confirm.open",{message:e,title:s,confirmText:r},u,0)).confirmed===!0},navigate:{app(t,e){return c("navigate.app",{path:t},e)},panel(t,e,s){return typeof e=="string"||typeof e=="number"?c("navigate.panel",{resource:t,id:String(e)},s):c("navigate.panel",{resource:t},e)}},nav:{set(t,e){return c("nav.set",{items:t.map(({label:s,path:r})=>({label:s,path:r}))},e)}},modal:{close({refresh:t,...e}={}){return c("modal.close",{refresh:t===!0},e)}},async pickResource({type:t,multiple:e,...s}){let r=await m("resource.pick",{type:t,multiple:e===!0},s,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,s=0,r=0,u=()=>{r=0;let f=getComputedStyle(e),y=Math.ceil(e.getBoundingClientRect().height+parseFloat(f.marginTop)+parseFloat(f.marginBottom));y!==s&&(s=y,m("size.set",{height:y}).catch(()=>{}))},g=new ResizeObserver(()=>{r||(r=requestAnimationFrame(u))});return g.observe(e),()=>{g.disconnect(),r&&cancelAnimationFrame(r)}},request:m,destroy(){A=!0,window.removeEventListener("message",w);for(let t of a.values())clearTimeout(t.timer),t.reject(new p("destroyed"));a.clear()}}}return G(H);})();
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);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tekrom/tsoft-app-gate",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "T-Soft paneli içinde açılan uygulamalar için App Bridge istemcisi",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",