@tekrom/tsoft-app-gate 0.4.0 → 0.6.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 +23 -2
- package/dist/client.d.ts +9 -0
- package/dist/client.js +5 -0
- package/dist/protocol.d.ts +9 -2
- package/dist/tsoft-app-gate.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ 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.5/dist/tsoft-app-gate.min.js"></script>
|
|
13
13
|
<script>
|
|
14
14
|
const app = TSoftAppGate.createApp();
|
|
15
15
|
</script>
|
|
@@ -140,6 +140,17 @@ Panel son gönderilen listeyi uygulama başına tarayıcıda saklar; menü bir s
|
|
|
140
140
|
await app.nav.set([{ label: 'Gönderiler', path: '/shipments' }, { label: 'Ayarlar', path: '/settings' }]);
|
|
141
141
|
```
|
|
142
142
|
|
|
143
|
+
### `modal.close({ refresh? })`
|
|
144
|
+
|
|
145
|
+
Uygulama bir **modal aksiyondan** (`[[extensions]]` hedefi `admin.{order,product,customer}.detail.action`) açıldıysa modalı kapatır. `refresh: true` panelin o sayfanın verisini (sipariş, ürün, müşteri) yeniden yüklemesini ister; örneğin uygulama siparişe fatura yazdıysa. Uygulama tam sayfada (`/apps/open`) açıldıysa `unsupported_type` döner.
|
|
146
|
+
|
|
147
|
+
Modalda `navigate.app` panel adresini değiştirmez; `navigate.panel` modalı kapatıp panelde o sayfaya gider. Diğer bütün çağrılar tam sayfadaki gibi çalışır.
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
await saveInvoice();
|
|
151
|
+
await app.modal.close({ refresh: true });
|
|
152
|
+
```
|
|
153
|
+
|
|
143
154
|
### `pickResource({ type, multiple? })`
|
|
144
155
|
|
|
145
156
|
Panelin seçicisini açar, seçilen kayıtların kimliklerini döner: `{ ids, cancelled }`. Kullanıcı pencereyi kapatırsa `{ ids: [], cancelled: true }`. Varsayılan olarak zaman aşımı yoktur.
|
|
@@ -147,8 +158,17 @@ Panelin seçicisini açar, seçilen kayıtların kimliklerini döner: `{ ids, ca
|
|
|
147
158
|
| `type` | Gerekli kapsam |
|
|
148
159
|
|---|---|
|
|
149
160
|
| `product` | `read_products` |
|
|
161
|
+
| `category` | `read_products` (panel kategori ağacı; eski panellerde `unsupported_resource`) |
|
|
162
|
+
|
|
163
|
+
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:
|
|
150
164
|
|
|
151
|
-
|
|
165
|
+
```js
|
|
166
|
+
try {
|
|
167
|
+
const { ids, cancelled } = await app.pickResource({ type: 'category' });
|
|
168
|
+
} catch (e) {
|
|
169
|
+
if (e.code === 'unsupported_resource') openOwnCategoryPicker();
|
|
170
|
+
}
|
|
171
|
+
``` Seçici açıkken yeni bir seçim istenirse önceki istek `cancelled: true` ile kapanır.
|
|
152
172
|
|
|
153
173
|
### `setHeight(height)` ve `autoResize({ target? })`
|
|
154
174
|
|
|
@@ -229,6 +249,7 @@ Kurallar:
|
|
|
229
249
|
| `resource.pick` | `{ type, multiple? }` | `{ ids, cancelled? }` | `unsupported_resource`, `missing_scope` |
|
|
230
250
|
| `size.set` | `{ height }` | `{}` | `invalid_payload` |
|
|
231
251
|
| `nav.set` | `{ items: [{ label, path }] }` | `{}` | `invalid_payload` |
|
|
252
|
+
| `modal.close` | `{ refresh? }` | `{}` | `unsupported_type` (tam sayfada) |
|
|
232
253
|
| diğer | — | — | `unsupported_type` |
|
|
233
254
|
|
|
234
255
|
`confirm.open` ve `resource.pick` yanıtı kullanıcı işlem yapınca gelir.
|
package/dist/client.d.ts
CHANGED
|
@@ -89,6 +89,15 @@ export interface App {
|
|
|
89
89
|
*/
|
|
90
90
|
set(items: NavItem[], options?: RequestOptions): Promise<void>;
|
|
91
91
|
};
|
|
92
|
+
modal: {
|
|
93
|
+
/**
|
|
94
|
+
* Uygulama bir modal aksiyondan (`[[extensions]]` `.detail.action`) açıldıysa modalı kapatır.
|
|
95
|
+
* `refresh: true` panelin o sayfanın verisini yeniden yüklemesini ister. Tam sayfada açılmışsa `unsupported_type`.
|
|
96
|
+
*/
|
|
97
|
+
close(options?: {
|
|
98
|
+
refresh?: boolean;
|
|
99
|
+
} & RequestOptions): Promise<void>;
|
|
100
|
+
};
|
|
92
101
|
/** Panelin seçicisini açar. Varsayılan olarak zaman aşımı yoktur. */
|
|
93
102
|
pickResource(options: PickOptions): Promise<PickResult>;
|
|
94
103
|
/** iframe yüksekliğini ayarlar; panel 300–5000 px aralığına sıkıştırır. */
|
package/dist/client.js
CHANGED
|
@@ -165,6 +165,11 @@ export function createApp(options = {}) {
|
|
|
165
165
|
return empty('nav.set', { items: items.map(({ label, path }) => ({ label, path })) }, requestOptions);
|
|
166
166
|
},
|
|
167
167
|
},
|
|
168
|
+
modal: {
|
|
169
|
+
close({ refresh, ...requestOptions } = {}) {
|
|
170
|
+
return empty('modal.close', { refresh: refresh === true }, requestOptions);
|
|
171
|
+
},
|
|
172
|
+
},
|
|
168
173
|
async pickResource({ type, multiple, ...rest }) {
|
|
169
174
|
const response = await request('resource.pick', { type, multiple: multiple === true }, rest, 0);
|
|
170
175
|
return { ids: Array.isArray(response.ids) ? response.ids : [], cancelled: response.cancelled === true };
|
package/dist/protocol.d.ts
CHANGED
|
@@ -30,8 +30,11 @@ 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';
|
|
35
38
|
/**
|
|
36
39
|
* Panelin sol menüsünde uygulamanın adı altında görünen bağlantı. `path` uygulamanın
|
|
37
40
|
* kendi adresi altında `/` ile başlayan yol olmalı (`/orders?status=1` gibi); etiket
|
|
@@ -69,6 +72,9 @@ export interface RequestPayloads {
|
|
|
69
72
|
'nav.set': {
|
|
70
73
|
items: NavItem[];
|
|
71
74
|
};
|
|
75
|
+
'modal.close': {
|
|
76
|
+
refresh?: boolean;
|
|
77
|
+
};
|
|
72
78
|
}
|
|
73
79
|
export interface ResponsePayloads {
|
|
74
80
|
'session-token.get': {
|
|
@@ -88,6 +94,7 @@ export interface ResponsePayloads {
|
|
|
88
94
|
};
|
|
89
95
|
'size.set': Record<string, never>;
|
|
90
96
|
'nav.set': Record<string, never>;
|
|
97
|
+
'modal.close': Record<string, never>;
|
|
91
98
|
}
|
|
92
99
|
export type RequestType = keyof RequestPayloads;
|
|
93
100
|
/**
|
|
@@ -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=(o
|
|
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);})();
|