@tekrom/tsoft-app-gate 0.2.0 → 0.3.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 +50 -15
- package/dist/client.d.ts +28 -2
- package/dist/client.js +27 -14
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/tsoft-app-gate.min.js +1 -0
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -6,13 +6,30 @@ T-Soft paneli içinde (iframe) açılan uygulamalar için **App Bridge** istemci
|
|
|
6
6
|
npm install @tekrom/tsoft-app-gate
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
+
Paketleyici kullanmıyorsanız tarayıcı derlemesini `<script>` ile yükleyin; aynı API `TSoftAppGate` global'i altında gelir:
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<script src="https://cdn.jsdelivr.net/npm/@tekrom/tsoft-app-gate@0.3/dist/tsoft-app-gate.min.js"></script>
|
|
13
|
+
<script>
|
|
14
|
+
const app = TSoftAppGate.createApp();
|
|
15
|
+
</script>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Sürümü sabitleyin (`@0.3` ya da tam sürüm); üretimde dosyayı kendi sunucunuzdan sunmak da mümkündür.
|
|
19
|
+
|
|
9
20
|
## Hızlı başlangıç
|
|
10
21
|
|
|
11
22
|
```ts
|
|
12
|
-
import { createApp, AppBridgeError } from '@tekrom/tsoft-app-gate';
|
|
23
|
+
import { createApp, isEmbedded, AppBridgeError } from '@tekrom/tsoft-app-gate';
|
|
24
|
+
|
|
25
|
+
if (!isEmbedded()) {
|
|
26
|
+
// Panel dışında açıldı: kendi giriş akışınızı gösterin.
|
|
27
|
+
}
|
|
13
28
|
|
|
14
29
|
const app = createApp();
|
|
15
30
|
|
|
31
|
+
app.claims?.store_id; // hangi mağaza (doğrulamayı sunucuda yapın)
|
|
32
|
+
|
|
16
33
|
// Arka uca giden her istekte taze token kullanın.
|
|
17
34
|
const token = await app.getSessionToken();
|
|
18
35
|
await fetch('/api/settings', { headers: { Authorization: `Bearer ${token}` } });
|
|
@@ -42,27 +59,32 @@ const stop = app.autoResize();
|
|
|
42
59
|
|
|
43
60
|
| Seçenek | Varsayılan | Açıklama |
|
|
44
61
|
|---|---|---|
|
|
45
|
-
| `panelOrigin` | otomatik | Panelin origin'i. Verilmezse `location.ancestorOrigins`, yoksa `document.referrer` kullanılır (panel iframe'i `referrerpolicy="strict-origin"` ile açar). |
|
|
62
|
+
| `panelOrigin` | otomatik | Panelin origin'i. Verilmezse `location.ancestorOrigins`, yoksa `document.referrer` kullanılır (panel iframe'i `referrerpolicy="strict-origin"` ile açar) ve T-Soft panel alan adlarından biri olmalıdır. Elle verilen değer denetlenmez; yalnız yerel geliştirmede kullanın. |
|
|
46
63
|
| `timeout` | `10000` | Kullanıcı etkileşimi beklemeyen isteklerin zaman aşımı (ms). |
|
|
47
64
|
|
|
48
|
-
|
|
65
|
+
Panel alan adları `PANEL_ORIGIN_PATTERN` ile denetlenir: `tsoftpanel.com`, `tsoftpanel.net`, `paneltsoft.com` ve bunların alt alan adları, yalnız `https`. Böylece uygulamanızı başka bir siteye gömen biri panel gibi yanıt veremez.
|
|
66
|
+
|
|
67
|
+
Uygulama bir iframe içinde değilse ya da üst pencere bir T-Soft paneli değilse `AppBridgeError('not_embedded')` fırlatır. Önceden bakmak için `isEmbedded()` kullanın.
|
|
49
68
|
|
|
50
69
|
Dönen nesnede ayrıca şunlar vardır:
|
|
51
70
|
|
|
52
71
|
- `panelOrigin`: Mesajların gönderildiği ve yanıtların kabul edildiği origin.
|
|
72
|
+
- `claims`: Elimizdeki son oturum token'ının içeriği (`store_id`, `dest`, `sub`, `aud`, `exp`…); token yoksa `null`. Token yenilendikçe güncellenir.
|
|
53
73
|
- `installCode`: Panelin kurulumdan hemen sonra eklediği `?code=` değeri; yoksa `null`.
|
|
54
74
|
|
|
55
75
|
### Oturum token'ı
|
|
56
76
|
|
|
57
77
|
```ts
|
|
58
78
|
app.getSessionToken(options?): Promise<string>
|
|
59
|
-
app.getSession(options?): Promise<{ token, expiresAt, scopes }>
|
|
79
|
+
app.getSession(options?): Promise<{ token, claims, expiresAt, scopes }>
|
|
80
|
+
decodeSessionToken(token): SessionClaims | null
|
|
60
81
|
```
|
|
61
82
|
|
|
62
83
|
- Panel uygulamayı `?session=<jwt>` ile açar. Bu token süresi dolmamışsa ilk çağrıda panele gidilmeden kullanılır; bu durumda `scopes` `null` olur.
|
|
63
|
-
- Token
|
|
84
|
+
- Token 60 saniye yaşar. Bitmesine 15 saniyeden az kaldıysa panelden yenisi istenir; aynı anda gelen yenileme çağrıları tek isteğe bağlanır. Her sunucu isteğinden önce `getSessionToken()` çağırmanız yeterlidir.
|
|
64
85
|
- `forceRefresh: true` önbelleği atlar; `scopes` her zaman panelden gelen güncel listeyi içerir.
|
|
65
|
-
- Token ES256 imzalı bir JWT'dir (`aud` = uygulama prefix'i, `store_id`, `dest` = mağaza alan adı, `
|
|
86
|
+
- Token ES256 imzalı bir JWT'dir (`iss`, `aud` = uygulama prefix'i, `sub` = panel kullanıcısı, `store_id`, `dest` = mağaza alan adı, `iat`, `nbf`, `exp`, `jti`). İstemci içeriği imza doğrulamadan okur; **imzayı sunucunuzda JWKS ile doğrulayın** (`https://api.tsoftapps.com/api/integration/v3/apps/jwks.json`, ayrıntı: [Panele Gömülü Uygulamalar](https://developer.tsoft.com.tr/uygulama-gelistirme/embedded-uygulamalar)).
|
|
87
|
+
- Oturum token'ı Admin API için değildir; uygulamanın kendi sunucusuyla konuşması içindir.
|
|
66
88
|
|
|
67
89
|
### `toast(message, { variant? })`
|
|
68
90
|
|
|
@@ -134,7 +156,7 @@ Tüm reddedilen promise'ler `AppBridgeError` taşır; `code` alanı aşağıdaki
|
|
|
134
156
|
| `unsupported_type` | panel | Panel bu mesaj tipini tanımıyor (eski panel sürümü). |
|
|
135
157
|
| `internal_error` | panel | Panel isteği işlerken hata aldı (ör. token alınamadı). |
|
|
136
158
|
| `timeout` | istemci | Süre içinde yanıt gelmedi. |
|
|
137
|
-
| `not_embedded` | istemci | Uygulama panel iframe'i içinde değil. |
|
|
159
|
+
| `not_embedded` | istemci | Uygulama panel iframe'i içinde değil ya da üst pencere bir T-Soft paneli değil. |
|
|
138
160
|
| `destroyed` | istemci | `destroy()` çağrıldıktan sonra istek yapıldı. |
|
|
139
161
|
|
|
140
162
|
## Protokol
|
|
@@ -171,7 +193,7 @@ Kurallar:
|
|
|
171
193
|
- Panel yalnız `event.origin` uygulama origin'ine eşit ve `event.source` kendi iframe'i olan mesajları işler.
|
|
172
194
|
- `source`, `version` (1), `type` (string) ve `id` (string) zorunludur; uymayan mesaj sessizce yok sayılır, yanıt dönmez.
|
|
173
195
|
- `id` panel tarafında 64 karaktere kesilir; yanıt bu kesilmiş kimlikle döner. 64 karakteri aşmayın.
|
|
174
|
-
- Uygulama da yanıtları yalnız `event.source === window.parent` ve `event.origin
|
|
196
|
+
- Uygulama da mesajı `targetOrigin` olarak panel origin'iyle göndermeli, yanıtları yalnız `event.source === window.parent` ve `event.origin` panel alan adlarından biriyse kabul etmelidir.
|
|
175
197
|
|
|
176
198
|
### Mesaj tipleri
|
|
177
199
|
|
|
@@ -198,15 +220,28 @@ window.parent.postMessage({ type: 'tsoft:session-token:request' }, panelOrigin);
|
|
|
198
220
|
// hata: { type: 'tsoft:session-token:error' }
|
|
199
221
|
```
|
|
200
222
|
|
|
201
|
-
##
|
|
223
|
+
## Geçiş
|
|
202
224
|
|
|
203
|
-
|
|
225
|
+
### `developer.tsoft.com.tr/app-bridge/v1` script'inden
|
|
204
226
|
|
|
205
|
-
|
|
|
227
|
+
| `TSoftBridge` | `TSoftAppGate` / npm |
|
|
206
228
|
|---|---|
|
|
207
|
-
| `
|
|
208
|
-
| `
|
|
209
|
-
| `
|
|
229
|
+
| `TSoftBridge.create()` | `createApp()` |
|
|
230
|
+
| `bridge.claims` | `app.claims` |
|
|
231
|
+
| `bridge.sessionToken()` | `app.getSessionToken()` |
|
|
232
|
+
| `bridge.toast(message, 'error')` | `app.toast(message, { variant: 'error' })` |
|
|
233
|
+
| `bridge.confirm(opts)` | `app.confirm(opts)` |
|
|
234
|
+
| `bridge.pickProducts({ multiple })` | `app.pickResource({ type: 'product', multiple })` |
|
|
235
|
+
| `bridge.navigate(path)` | `app.navigate.app(path)` |
|
|
236
|
+
| `bridge.openPanel(resource, id)` | `app.navigate.panel(resource, id)` |
|
|
237
|
+
| `bridge.setHeight(h)` / `bridge.autoResize()` | `app.setHeight(h)` / `app.autoResize()` |
|
|
238
|
+
| `Error.message` | `AppBridgeError.code` |
|
|
239
|
+
|
|
240
|
+
Script panel dışında açılınca ilk istekte hata veriyordu; `createApp()` ise hemen `not_embedded` fırlatır.
|
|
241
|
+
|
|
242
|
+
### 0.1.x'ten
|
|
243
|
+
|
|
244
|
+
0.1.x'teki `createApp({ apiKey, shopId, host })`, `setNavigationMenu` ve `showToast` panelin tanımadığı bir mesaj biçimi (`T_SOFT_APP_BRIDGE`) gönderiyordu; kaldırıldı. `showToast(app, opts)` yerine `app.toast(message, opts)` kullanın; uygulama menüsünün karşılığı yok.
|
|
210
245
|
|
|
211
246
|
## Geliştirme
|
|
212
247
|
|
|
@@ -216,4 +251,4 @@ npm test # derler ve node --test ile testleri koşar (Node 23.6+)
|
|
|
216
251
|
npm run build
|
|
217
252
|
```
|
|
218
253
|
|
|
219
|
-
`dist/` yalnız npm paketine girer, repoya eklenmez. `prepublishOnly` yayın öncesi derlemeyi çalıştırır.
|
|
254
|
+
Derleme iki çıktı üretir: `tsc` ile ESM + tipler (`dist/index.js`) ve `esbuild` ile tarayıcı derlemesi (`dist/tsoft-app-gate.min.js`). `dist/` yalnız npm paketine girer, repoya eklenmez. `prepublishOnly` yayın öncesi derlemeyi çalıştırır.
|
package/dist/client.d.ts
CHANGED
|
@@ -5,8 +5,9 @@ export declare class AppBridgeError extends Error {
|
|
|
5
5
|
}
|
|
6
6
|
export interface AppOptions {
|
|
7
7
|
/**
|
|
8
|
-
* Panelin origin'i
|
|
9
|
-
*
|
|
8
|
+
* Panelin origin'i. Verilmezse `location.ancestorOrigins` ya da `document.referrer`
|
|
9
|
+
* üzerinden bulunur ve T-Soft panel alan adlarından biri olmalıdır. Elle verilen
|
|
10
|
+
* değer bu listeyle denetlenmez; yerel geliştirme içindir.
|
|
10
11
|
*/
|
|
11
12
|
panelOrigin?: string;
|
|
12
13
|
/** Kullanıcı etkileşimi beklemeyen isteklerin zaman aşımı (ms). Varsayılan 10000. */
|
|
@@ -16,8 +17,25 @@ export interface RequestOptions {
|
|
|
16
17
|
/** Bu isteğin zaman aşımı (ms). `0` zaman aşımını kapatır. */
|
|
17
18
|
timeout?: number;
|
|
18
19
|
}
|
|
20
|
+
/** Oturum token'ının içeriği. İmza doğrulanmadan okunur; güvenmeden önce sunucuda doğrulayın. */
|
|
21
|
+
export interface SessionClaims {
|
|
22
|
+
iss: string;
|
|
23
|
+
/** Uygulamanın prefix'i. */
|
|
24
|
+
aud: string;
|
|
25
|
+
/** Uygulamayı açan panel kullanıcısı. */
|
|
26
|
+
sub: string;
|
|
27
|
+
store_id: string;
|
|
28
|
+
/** Mağaza alan adı. */
|
|
29
|
+
dest: string;
|
|
30
|
+
iat: number;
|
|
31
|
+
nbf: number;
|
|
32
|
+
exp: number;
|
|
33
|
+
jti: string;
|
|
34
|
+
[claim: string]: unknown;
|
|
35
|
+
}
|
|
19
36
|
export interface SessionToken {
|
|
20
37
|
token: string;
|
|
38
|
+
claims: SessionClaims | null;
|
|
21
39
|
/** Token'ın geçerliliğini yitirdiği an (epoch ms). */
|
|
22
40
|
expiresAt: number;
|
|
23
41
|
/** Panelden alınmışsa uygulamanın kapsamları; URL'deki token için `null`. */
|
|
@@ -45,6 +63,8 @@ export interface AutoResizeOptions {
|
|
|
45
63
|
}
|
|
46
64
|
export interface App {
|
|
47
65
|
readonly panelOrigin: string;
|
|
66
|
+
/** Elimizdeki son oturum token'ının içeriği; token yoksa `null`. */
|
|
67
|
+
readonly claims: SessionClaims | null;
|
|
48
68
|
/** Panelin kurulumdan hemen sonra URL'e eklediği `?code=` değeri. */
|
|
49
69
|
readonly installCode: string | null;
|
|
50
70
|
getSessionToken(options?: {
|
|
@@ -73,4 +93,10 @@ export interface App {
|
|
|
73
93
|
/** Dinleyicileri kaldırır, bekleyen istekleri `destroyed` ile reddeder. */
|
|
74
94
|
destroy(): void;
|
|
75
95
|
}
|
|
96
|
+
/** Panelin yayınlandığı alan adları (t-panel `PANEL_DOMAINS`). */
|
|
97
|
+
export declare const PANEL_ORIGIN_PATTERN: RegExp;
|
|
98
|
+
/** Sayfa bir iframe içinde mi açılmış. */
|
|
99
|
+
export declare function isEmbedded(): boolean;
|
|
100
|
+
/** JWT gövdesini imza doğrulamadan okur. */
|
|
101
|
+
export declare function decodeSessionToken(token: string): SessionClaims | null;
|
|
76
102
|
export declare function createApp(options?: AppOptions): App;
|
package/dist/client.js
CHANGED
|
@@ -7,7 +7,14 @@ export class AppBridgeError extends Error {
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
const DEFAULT_TIMEOUT = 10000;
|
|
10
|
-
|
|
10
|
+
// Token 60 sn yaşar; sunucuya giderken süresi dolmasın diye 15 sn kala yenilenir.
|
|
11
|
+
const REFRESH_MARGIN = 15000;
|
|
12
|
+
/** Panelin yayınlandığı alan adları (t-panel `PANEL_DOMAINS`). */
|
|
13
|
+
export const PANEL_ORIGIN_PATTERN = /^https:\/\/([a-z0-9-]+\.)*(tsoftpanel\.com|tsoftpanel\.net|paneltsoft\.com)$/;
|
|
14
|
+
/** Sayfa bir iframe içinde mi açılmış. */
|
|
15
|
+
export function isEmbedded() {
|
|
16
|
+
return typeof window !== 'undefined' && window.parent !== window;
|
|
17
|
+
}
|
|
11
18
|
function detectPanelOrigin() {
|
|
12
19
|
const ancestors = window.location.ancestorOrigins;
|
|
13
20
|
if (ancestors && ancestors.length > 0) {
|
|
@@ -20,13 +27,12 @@ function detectPanelOrigin() {
|
|
|
20
27
|
return null;
|
|
21
28
|
}
|
|
22
29
|
}
|
|
23
|
-
/** JWT
|
|
24
|
-
function
|
|
30
|
+
/** JWT gövdesini imza doğrulamadan okur. */
|
|
31
|
+
export function decodeSessionToken(token) {
|
|
25
32
|
try {
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
return typeof exp === 'number' ? exp * 1000 : null;
|
|
33
|
+
const binary = atob(token.split('.')[1].replace(/-/g, '+').replace(/_/g, '/'));
|
|
34
|
+
const claims = JSON.parse(new TextDecoder().decode(Uint8Array.from(binary, (c) => c.charCodeAt(0))));
|
|
35
|
+
return claims && typeof claims.exp === 'number' ? claims : null;
|
|
30
36
|
}
|
|
31
37
|
catch (_a) {
|
|
32
38
|
return null;
|
|
@@ -37,13 +43,14 @@ function isFresh(session) {
|
|
|
37
43
|
}
|
|
38
44
|
export function createApp(options = {}) {
|
|
39
45
|
var _a, _b;
|
|
40
|
-
if (
|
|
46
|
+
if (!isEmbedded()) {
|
|
41
47
|
throw new AppBridgeError('not_embedded', 'T-Soft App Bridge: uygulama panel iframe\'i içinde açılmamış');
|
|
42
48
|
}
|
|
43
|
-
const
|
|
44
|
-
if (!panelOrigin) {
|
|
45
|
-
throw new AppBridgeError('not_embedded',
|
|
49
|
+
const detected = options.panelOrigin ? null : detectPanelOrigin();
|
|
50
|
+
if (!options.panelOrigin && !(detected && PANEL_ORIGIN_PATTERN.test(detected))) {
|
|
51
|
+
throw new AppBridgeError('not_embedded', `T-Soft App Bridge: üst pencere bir T-Soft paneli değil (${detected !== null && detected !== void 0 ? detected : 'bilinmiyor'})`);
|
|
46
52
|
}
|
|
53
|
+
const panelOrigin = ((_a = options.panelOrigin) !== null && _a !== void 0 ? _a : detected);
|
|
47
54
|
const defaultTimeout = (_b = options.timeout) !== null && _b !== void 0 ? _b : DEFAULT_TIMEOUT;
|
|
48
55
|
const pending = new Map();
|
|
49
56
|
const params = new URLSearchParams(window.location.search);
|
|
@@ -53,9 +60,9 @@ export function createApp(options = {}) {
|
|
|
53
60
|
let session = null;
|
|
54
61
|
let refreshing = null;
|
|
55
62
|
if (urlToken) {
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
58
|
-
session = { token: urlToken, expiresAt, scopes: null };
|
|
63
|
+
const claims = decodeSessionToken(urlToken);
|
|
64
|
+
if (claims) {
|
|
65
|
+
session = { token: urlToken, claims, expiresAt: claims.exp * 1000, scopes: null };
|
|
59
66
|
}
|
|
60
67
|
}
|
|
61
68
|
function onMessage(event) {
|
|
@@ -106,8 +113,10 @@ export function createApp(options = {}) {
|
|
|
106
113
|
}
|
|
107
114
|
refreshing !== null && refreshing !== void 0 ? refreshing : (refreshing = request('session-token.get', {}, sessionOptions)
|
|
108
115
|
.then((response) => {
|
|
116
|
+
// expires_in görece olduğu için istemci saatindeki kaymadan etkilenmez.
|
|
109
117
|
session = {
|
|
110
118
|
token: response.token,
|
|
119
|
+
claims: decodeSessionToken(response.token),
|
|
111
120
|
expiresAt: Date.now() + response.expires_in * 1000,
|
|
112
121
|
scopes: Array.isArray(response.scopes) ? response.scopes : [],
|
|
113
122
|
};
|
|
@@ -123,6 +132,10 @@ export function createApp(options = {}) {
|
|
|
123
132
|
}
|
|
124
133
|
return {
|
|
125
134
|
panelOrigin,
|
|
135
|
+
get claims() {
|
|
136
|
+
var _a;
|
|
137
|
+
return (_a = session === null || session === void 0 ? void 0 : session.claims) !== null && _a !== void 0 ? _a : null;
|
|
138
|
+
},
|
|
126
139
|
installCode: params.get('code'),
|
|
127
140
|
getSession,
|
|
128
141
|
async getSessionToken(sessionOptions) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createApp, AppBridgeError } from './client.js';
|
|
2
|
-
export type { App, AppOptions, AutoResizeOptions, ConfirmOptions, PickOptions, PickResult, RequestOptions, SessionToken, ToastOptions, } from './client.js';
|
|
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';
|
|
3
3
|
export { BRIDGE_VERSION, APP_SOURCE, PANEL_SOURCE } from './protocol.js';
|
|
4
4
|
export type { BridgeErrorCode, BridgeRequest, BridgeResponse, PanelDetailResource, PanelListResource, PanelResource, PickableResource, RequestPayloads, RequestType, ResponsePayloads, ToastVariant, } from './protocol.js';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createApp, AppBridgeError } from './client.js';
|
|
1
|
+
export { createApp, isEmbedded, decodeSessionToken, AppBridgeError, PANEL_ORIGIN_PATTERN } from './client.js';
|
|
2
2
|
export { BRIDGE_VERSION, APP_SOURCE, PANEL_SOURCE } from './protocol.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var TSoftAppGate=(()=>{var S=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var z=(n,o)=>{for(var r in o)S(n,r,{get:o[r],enumerable:!0})},V=(n,o,r,u)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of I(o))!U.call(n,a)&&a!==r&&S(n,a,{get:()=>o[a],enumerable:!(u=D(o,a))||u.enumerable});return n};var G=n=>V(S({},"__esModule",{value:!0}),n);var H={};z(H,{APP_SOURCE:()=>T,AppBridgeError:()=>p,BRIDGE_VERSION:()=>P,PANEL_ORIGIN_PATTERN:()=>k,PANEL_SOURCE:()=>O,createApp:()=>L,decodeSessionToken:()=>x,isEmbedded:()=>b});var P=1,T="tsoft-app",O="tsoft-panel";var p=class extends Error{constructor(o,r){super(r!=null?r:`T-Soft App Bridge: ${o}`),this.name="AppBridgeError",this.code=o}},M=1e4,F=15e3,k=/^https:\/\/([a-z0-9-]+\.)*(tsoftpanel\.com|tsoftpanel\.net|paneltsoft\.com)$/;function b(){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 x(n){try{let o=atob(n.split(".")[1].replace(/-/g,"+").replace(/_/g,"/")),r=JSON.parse(new TextDecoder().decode(Uint8Array.from(o,u=>u.charCodeAt(0))));return r&&typeof r.exp=="number"?r:null}catch(o){return null}}function $(n){return n!==null&&n.expiresAt-F>Date.now()}function L(n={}){var _,h;if(!b())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&&k.test(o)))throw new p("not_embedded",`T-Soft App Bridge: \xFCst pencere bir T-Soft paneli de\u011Fil (${o!=null?o:"bilinmiyor"})`);let r=(_=n.panelOrigin)!=null?_:o,u=(h=n.timeout)!=null?h:M,a=new Map,A=new URLSearchParams(window.location.search),E=A.get("session"),N=0,w=!1,l=null,m=null;if(E){let t=x(E);t&&(l={token:E,claims:t,expiresAt:t.exp*1e3,scopes:null})}function v(t){var i;if(t.source!==window.parent||t.origin!==r)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((i=e.payload)!=null?i:{}):s.reject(new p(typeof e.error=="string"?e.error:"internal_error")))}window.addEventListener("message",v);function d(t,e,s={},i=u){var y;if(w)return Promise.reject(new p("destroyed"));let c=`app-${Date.now().toString(36)}-${(N++).toString(36)}`,g=(y=s.timeout)!=null?y:i;return new Promise((f,C)=>{let B={resolve:f,reject:C};g>0&&(B.timer=setTimeout(()=>{a.delete(c),C(new p("timeout"))},g)),a.set(c,B),window.parent.postMessage({source:T,version:1,id:c,type:t,payload:e},r)})}async function q(t={}){return!t.forceRefresh&&$(l)?l:(m!=null||(m=d("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(()=>{m=null})),m)}async function R(t,e,s){await d(t,e,s)}return{panelOrigin:r,get claims(){var t;return(t=l==null?void 0:l.claims)!=null?t:null},installCode:A.get("code"),getSession:q,async getSessionToken(t){return(await q(t)).token},toast(t,{variant:e,...s}={}){return R("toast.show",e?{message:t,variant:e}:{message:t},s)},async confirm(t){let{message:e,title:s,confirmText:i,...c}=typeof t=="string"?{message:t}:t;return(await d("confirm.open",{message:e,title:s,confirmText:i},c,0)).confirmed===!0},navigate:{app(t,e){return R("navigate.app",{path:t},e)},panel(t,e,s){return typeof e=="string"||typeof e=="number"?R("navigate.panel",{resource:t,id:String(e)},s):R("navigate.panel",{resource:t},e)}},async pickResource({type:t,multiple:e,...s}){let i=await d("resource.pick",{type:t,multiple:e===!0},s,0);return{ids:Array.isArray(i.ids)?i.ids:[],cancelled:i.cancelled===!0}},setHeight(t,e){return R("size.set",{height:Math.ceil(t)},e)},autoResize({target:t}={}){let e=t!=null?t:document.body,s=0,i=0,c=()=>{i=0;let y=getComputedStyle(e),f=Math.ceil(e.getBoundingClientRect().height+parseFloat(y.marginTop)+parseFloat(y.marginBottom));f!==s&&(s=f,d("size.set",{height:f}).catch(()=>{}))},g=new ResizeObserver(()=>{i||(i=requestAnimationFrame(c))});return g.observe(e),()=>{g.disconnect(),i&&cancelAnimationFrame(i)}},request:d,destroy(){w=!0,window.removeEventListener("message",v);for(let t of a.values())clearTimeout(t.timer),t.reject(new p("destroyed"));a.clear()}}}return G(H);})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tekrom/tsoft-app-gate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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",
|
|
@@ -9,14 +9,17 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"import": "./dist/index.js"
|
|
12
|
-
}
|
|
12
|
+
},
|
|
13
|
+
"./browser": "./dist/tsoft-app-gate.min.js"
|
|
13
14
|
},
|
|
15
|
+
"unpkg": "./dist/tsoft-app-gate.min.js",
|
|
16
|
+
"jsdelivr": "./dist/tsoft-app-gate.min.js",
|
|
14
17
|
"files": [
|
|
15
18
|
"dist"
|
|
16
19
|
],
|
|
17
20
|
"sideEffects": false,
|
|
18
21
|
"scripts": {
|
|
19
|
-
"build": "tsc",
|
|
22
|
+
"build": "tsc && esbuild src/index.ts --bundle --format=iife --global-name=TSoftAppGate --target=es2018 --minify --outfile=dist/tsoft-app-gate.min.js",
|
|
20
23
|
"test": "npm run build && node --test test/",
|
|
21
24
|
"prepublishOnly": "npm run build"
|
|
22
25
|
},
|
|
@@ -33,6 +36,7 @@
|
|
|
33
36
|
"author": "T-Soft",
|
|
34
37
|
"license": "MIT",
|
|
35
38
|
"devDependencies": {
|
|
39
|
+
"esbuild": "^0.25.10",
|
|
36
40
|
"typescript": "^5.9.3"
|
|
37
41
|
}
|
|
38
42
|
}
|