@tekrom/tsoft-app-gate 0.5.0 → 0.7.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 +39 -5
- package/dist/client.d.ts +17 -1
- package/dist/client.js +8 -0
- package/dist/index.d.ts +2 -2
- package/dist/protocol.d.ts +14 -3
- package/dist/tsoft-app-gate.min.js +1 -1
- package/package.json +1 -1
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.
|
|
12
|
+
<script src="https://cdn.jsdelivr.net/npm/@tekrom/tsoft-app-gate@0.7/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.7` 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
|
|
@@ -158,8 +161,37 @@ Panelin seçicisini açar, seçilen kayıtların kimliklerini döner: `{ ids, ca
|
|
|
158
161
|
| `type` | Gerekli kapsam |
|
|
159
162
|
|---|---|
|
|
160
163
|
| `product` | `read_products` |
|
|
164
|
+
| `category` | `read_products` (panel kategori ağacı; eski panellerde `unsupported_resource`) |
|
|
165
|
+
|
|
166
|
+
Kapsam yoksa `missing_scope`, bilinmeyen tür `unsupported_resource` döner. Kategori seçicisi yeni bir türdür; desteklemeyen panelde kendi seçicinize düşün:
|
|
167
|
+
|
|
168
|
+
```js
|
|
169
|
+
try {
|
|
170
|
+
const { ids, cancelled } = await app.pickResource({ type: 'category' });
|
|
171
|
+
} catch (e) {
|
|
172
|
+
if (e.code === 'unsupported_resource') openOwnCategoryPicker();
|
|
173
|
+
}
|
|
174
|
+
``` Seçici açıkken yeni bir seçim istenirse önceki istek `cancelled: true` ile kapanır.
|
|
175
|
+
|
|
176
|
+
### `billing.confirm({ id })`
|
|
161
177
|
|
|
162
|
-
|
|
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
|
+
```
|
|
163
195
|
|
|
164
196
|
### `setHeight(height)` ve `autoResize({ target? })`
|
|
165
197
|
|
|
@@ -187,6 +219,7 @@ Tüm reddedilen promise'ler `AppBridgeError` taşır; `code` alanı aşağıdaki
|
|
|
187
219
|
| `missing_scope` | panel | Uygulamanın bu iş için gereken kapsamı yok. |
|
|
188
220
|
| `unsupported_resource` | panel | `pickResource` türü desteklenmiyor. |
|
|
189
221
|
| `unsupported_type` | panel | Panel bu mesaj tipini tanımıyor (eski panel sürümü). |
|
|
222
|
+
| `charge_not_found` | panel | `billing.confirm` kimliği bu uygulamanın bir ücreti değil. |
|
|
190
223
|
| `internal_error` | panel | Panel isteği işlerken hata aldı (ör. token alınamadı). |
|
|
191
224
|
| `timeout` | istemci | Süre içinde yanıt gelmedi. |
|
|
192
225
|
| `not_embedded` | istemci | Uygulama panel iframe'i içinde değil ya da üst pencere bir T-Soft paneli değil. |
|
|
@@ -241,9 +274,10 @@ Kurallar:
|
|
|
241
274
|
| `size.set` | `{ height }` | `{}` | `invalid_payload` |
|
|
242
275
|
| `nav.set` | `{ items: [{ label, path }] }` | `{}` | `invalid_payload` |
|
|
243
276
|
| `modal.close` | `{ refresh? }` | `{}` | `unsupported_type` (tam sayfada) |
|
|
277
|
+
| `billing.confirm` | `{ id }` | `{ status }` | `invalid_payload`, `charge_not_found`, `internal_error` |
|
|
244
278
|
| diğer | — | — | `unsupported_type` |
|
|
245
279
|
|
|
246
|
-
`confirm.open` ve `
|
|
280
|
+
`confirm.open`, `resource.pick` ve `billing.confirm` yanıtı kullanıcı işlem yapınca gelir.
|
|
247
281
|
|
|
248
282
|
### Eski token mesajı
|
|
249
283
|
|
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,15 @@ 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
|
+
};
|
|
101
117
|
/** Panelin seçicisini açar. Varsayılan olarak zaman aşımı yoktur. */
|
|
102
118
|
pickResource(options: PickOptions): Promise<PickResult>;
|
|
103
119
|
/** 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,13 @@ 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
|
+
},
|
|
173
181
|
async pickResource({ type, multiple, ...rest }) {
|
|
174
182
|
const response = await request('resource.pick', { type, multiple: multiple === true }, rest, 0);
|
|
175
183
|
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';
|
package/dist/protocol.d.ts
CHANGED
|
@@ -30,8 +30,13 @@ export type PanelListResource = 'orders' | 'products' | 'apps';
|
|
|
30
30
|
/** Kimlikle açılan panel sayfaları; kimlik `^[A-Za-z0-9_-]{1,64}$` olmalı. */
|
|
31
31
|
export type PanelDetailResource = 'order' | 'product';
|
|
32
32
|
export type PanelResource = PanelListResource | PanelDetailResource;
|
|
33
|
-
/**
|
|
34
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Seçici türü ve istediği kapsam: `product` ve `category` → `read_products`.
|
|
35
|
+
* `category` eski panellerde `unsupported_resource` döner.
|
|
36
|
+
*/
|
|
37
|
+
export type PickableResource = 'product' | 'category';
|
|
38
|
+
/** Tek seferlik ücretin durumu. */
|
|
39
|
+
export type ChargeStatus = 'pending' | 'active' | 'declined' | 'expired';
|
|
35
40
|
/**
|
|
36
41
|
* Panelin sol menüsünde uygulamanın adı altında görünen bağlantı. `path` uygulamanın
|
|
37
42
|
* kendi adresi altında `/` ile başlayan yol olmalı (`/orders?status=1` gibi); etiket
|
|
@@ -72,6 +77,9 @@ export interface RequestPayloads {
|
|
|
72
77
|
'modal.close': {
|
|
73
78
|
refresh?: boolean;
|
|
74
79
|
};
|
|
80
|
+
'billing.confirm': {
|
|
81
|
+
id: string;
|
|
82
|
+
};
|
|
75
83
|
}
|
|
76
84
|
export interface ResponsePayloads {
|
|
77
85
|
'session-token.get': {
|
|
@@ -92,10 +100,13 @@ export interface ResponsePayloads {
|
|
|
92
100
|
'size.set': Record<string, never>;
|
|
93
101
|
'nav.set': Record<string, never>;
|
|
94
102
|
'modal.close': Record<string, never>;
|
|
103
|
+
'billing.confirm': {
|
|
104
|
+
status: ChargeStatus;
|
|
105
|
+
};
|
|
95
106
|
}
|
|
96
107
|
export type RequestType = keyof RequestPayloads;
|
|
97
108
|
/**
|
|
98
109
|
* Panelin döndürdüğü hata kodları ile istemcinin kendi ürettikleri.
|
|
99
110
|
* Bilinmeyen kodlar da string olarak geçer.
|
|
100
111
|
*/
|
|
101
|
-
export type BridgeErrorCode = 'invalid_payload' | 'invalid_path' | 'invalid_route' | 'missing_scope' | 'unsupported_resource' | 'unsupported_type' | 'internal_error' | 'timeout' | 'not_embedded' | 'destroyed' | (string & {});
|
|
112
|
+
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
|
|
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:()=>x,createApp:()=>N,decodeSessionToken:()=>O,isEmbedded:()=>E});var P=1,T="tsoft-app",x="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 O(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=O(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)!==x||(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 c(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=c("session-token.get",{},t).then(e=>(l={token:e.token,claims:O(e.token),expiresAt:Date.now()+e.expires_in*1e3,scopes:Array.isArray(e.scopes)?e.scopes:[]},l)).finally(()=>{R=null})),R)}async function u(t,e,n){await c(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 u("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 c("confirm.open",{message:e,title:n,confirmText:r},d,0)).confirmed===!0},navigate:{app(t,e){return u("navigate.app",{path:t},e)},panel(t,e,n){return typeof e=="string"||typeof e=="number"?u("navigate.panel",{resource:t,id:String(e)},n):u("navigate.panel",{resource:t},e)}},nav:{set(t,e){return u("nav.set",{items:t.map(({label:n,path:r})=>({label:n,path:r}))},e)}},modal:{close({refresh:t,...e}={}){return u("modal.close",{refresh:t===!0},e)}},billing:{async confirm({id:t,...e}){let n=await c("billing.confirm",{id:String(t)},e,0);return{status:F.includes(n.status)?n.status:"pending"}}},async pickResource({type:t,multiple:e,...n}){let r=await c("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 u("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,c("size.set",{height:y}).catch(()=>{}))},m=new ResizeObserver(()=>{r||(r=requestAnimationFrame(d))});return m.observe(e),()=>{m.disconnect(),r&&cancelAnimationFrame(r)}},request:c,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);})();
|