@tekrom/tsoft-app-gate 0.4.0 → 0.5.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 +12 -0
- package/dist/client.d.ts +9 -0
- package/dist/client.js +5 -0
- package/dist/protocol.d.ts +4 -0
- package/dist/tsoft-app-gate.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -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.
|
|
@@ -229,6 +240,7 @@ Kurallar:
|
|
|
229
240
|
| `resource.pick` | `{ type, multiple? }` | `{ ids, cancelled? }` | `unsupported_resource`, `missing_scope` |
|
|
230
241
|
| `size.set` | `{ height }` | `{}` | `invalid_payload` |
|
|
231
242
|
| `nav.set` | `{ items: [{ label, path }] }` | `{}` | `invalid_payload` |
|
|
243
|
+
| `modal.close` | `{ refresh? }` | `{}` | `unsupported_type` (tam sayfada) |
|
|
232
244
|
| diğer | — | — | `unsupported_type` |
|
|
233
245
|
|
|
234
246
|
`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
|
@@ -69,6 +69,9 @@ export interface RequestPayloads {
|
|
|
69
69
|
'nav.set': {
|
|
70
70
|
items: NavItem[];
|
|
71
71
|
};
|
|
72
|
+
'modal.close': {
|
|
73
|
+
refresh?: boolean;
|
|
74
|
+
};
|
|
72
75
|
}
|
|
73
76
|
export interface ResponsePayloads {
|
|
74
77
|
'session-token.get': {
|
|
@@ -88,6 +91,7 @@ export interface ResponsePayloads {
|
|
|
88
91
|
};
|
|
89
92
|
'size.set': Record<string, never>;
|
|
90
93
|
'nav.set': Record<string, never>;
|
|
94
|
+
'modal.close': Record<string, never>;
|
|
91
95
|
}
|
|
92
96
|
export type RequestType = keyof RequestPayloads;
|
|
93
97
|
/**
|
|
@@ -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);})();
|