@usions/sdk 2.24.2 → 2.25.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/package.json +1 -1
- package/src/browser.js +80 -1
- package/src/modules/core.js +10 -1
- package/src/modules/host-tabs.js +66 -0
- package/src/modules/index.js +4 -0
- package/types/index.d.ts +23 -0
package/package.json
CHANGED
package/src/browser.js
CHANGED
|
@@ -191,7 +191,7 @@ var Usion = (function () {
|
|
|
191
191
|
* Core Usion object with init, _post, _request
|
|
192
192
|
*/
|
|
193
193
|
const core = {
|
|
194
|
-
version: '2.
|
|
194
|
+
version: '2.25.0', // synced from package.json by scripts/sync-version.mjs
|
|
195
195
|
config: {},
|
|
196
196
|
_initialized: false,
|
|
197
197
|
_initCallback: null,
|
|
@@ -365,6 +365,15 @@ var Usion = (function () {
|
|
|
365
365
|
self.bot._messageHandler(data.message);
|
|
366
366
|
}
|
|
367
367
|
|
|
368
|
+
// Handle host tab navigation (hybrid tabbed services). Keep launchPath
|
|
369
|
+
// truthful so getLaunchParams().path always reflects the current tab.
|
|
370
|
+
if (data.type === 'HOST_NAVIGATE' && typeof data.path === 'string') {
|
|
371
|
+
if (self.config) self.config.launchPath = data.path;
|
|
372
|
+
if (self._hostNavigateCallback) {
|
|
373
|
+
self._hostNavigateCallback({ path: data.path, tab: data.tab || null });
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
368
377
|
// Handle backend server-push events relayed by the host (embedded mode).
|
|
369
378
|
if (data.type === 'BACKEND_EVENT' && data.event && self._backendHandlers) {
|
|
370
379
|
const h = self._backendHandlers[data.event];
|
|
@@ -1140,6 +1149,73 @@ var Usion = (function () {
|
|
|
1140
1149
|
};
|
|
1141
1150
|
}
|
|
1142
1151
|
|
|
1152
|
+
/**
|
|
1153
|
+
* Usion SDK Host Tabs — hybrid tabbed services (SDK ≥ 2.25)
|
|
1154
|
+
*
|
|
1155
|
+
* A hybrid service registers `tabs`: the platform renders its native bot chat
|
|
1156
|
+
* as one tab and this app's own pages as the others, inside ONE persistent
|
|
1157
|
+
* iframe/WebView. These methods are the two-way bridge with that host screen:
|
|
1158
|
+
*
|
|
1159
|
+
* - Host → app: `onHostNavigate(cb)` receives tab switches as `{ path, tab }`.
|
|
1160
|
+
* Subscribing tells the host it can navigate in place; apps that never
|
|
1161
|
+
* subscribe get remounted with the new path as `getLaunchParams().path`.
|
|
1162
|
+
* - App → host: `openChat({ prefill })` jumps to the native chat tab with the
|
|
1163
|
+
* composer pre-filled (the user still presses send themselves), and
|
|
1164
|
+
* `reportPath(path)` keeps the host's tab highlight in sync when the user
|
|
1165
|
+
* navigates inside the app.
|
|
1166
|
+
*/
|
|
1167
|
+
|
|
1168
|
+
function createHostTabsMethods(Usion) {
|
|
1169
|
+
return {
|
|
1170
|
+
/**
|
|
1171
|
+
* Subscribe to host tab navigation. Called when the user taps one of this
|
|
1172
|
+
* service's tabs in the host tab bar (or a deep link targets a tab).
|
|
1173
|
+
* Subscribing signals the host that this app navigates in place — without
|
|
1174
|
+
* a subscription the host reloads the app with the new launch path instead.
|
|
1175
|
+
* @param {function} callback - Called with { path, tab } (tab may be null)
|
|
1176
|
+
*/
|
|
1177
|
+
onHostNavigate: function(callback) {
|
|
1178
|
+
Usion._hostNavigateCallback = callback;
|
|
1179
|
+
Usion._post({ type: 'HOST_NAVIGATE_SUBSCRIBED' });
|
|
1180
|
+
},
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* Unsubscribe from host tab navigation (the host falls back to remounting
|
|
1184
|
+
* the app on the next tab switch).
|
|
1185
|
+
*/
|
|
1186
|
+
offHostNavigate: function() {
|
|
1187
|
+
Usion._hostNavigateCallback = null;
|
|
1188
|
+
Usion._post({ type: 'HOST_NAVIGATE_UNSUBSCRIBED' });
|
|
1189
|
+
},
|
|
1190
|
+
|
|
1191
|
+
/**
|
|
1192
|
+
* Ask the host to switch to the native chat tab, optionally pre-filling
|
|
1193
|
+
* the message composer. The text is NEVER sent automatically — the user
|
|
1194
|
+
* reviews it and presses send. No-op outside a hybrid tabbed host screen.
|
|
1195
|
+
* @param {object} [opts]
|
|
1196
|
+
* @param {string} [opts.prefill] - Draft text for the chat composer
|
|
1197
|
+
*/
|
|
1198
|
+
openChat: function(opts) {
|
|
1199
|
+
opts = opts || {};
|
|
1200
|
+
Usion._post({
|
|
1201
|
+
type: 'OPEN_CHAT_TAB',
|
|
1202
|
+
prefill: typeof opts.prefill === 'string' ? opts.prefill : undefined
|
|
1203
|
+
});
|
|
1204
|
+
},
|
|
1205
|
+
|
|
1206
|
+
/**
|
|
1207
|
+
* Report the app's current internal path so the host can keep its tab
|
|
1208
|
+
* highlight in sync with in-app navigation. Fire-and-forget; the host
|
|
1209
|
+
* never echoes a navigation back for a reported path.
|
|
1210
|
+
* @param {string} path - Current path inside the app (e.g. "/explore")
|
|
1211
|
+
*/
|
|
1212
|
+
reportPath: function(path) {
|
|
1213
|
+
if (typeof path !== 'string' || !path) return;
|
|
1214
|
+
Usion._post({ type: 'TAB_CHANGED', path: path });
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1143
1219
|
/**
|
|
1144
1220
|
* Usion SDK UI Utilities — DOM helpers for mini apps
|
|
1145
1221
|
*/
|
|
@@ -6707,6 +6783,9 @@ var Usion = (function () {
|
|
|
6707
6783
|
// Attach back button methods directly on Usion
|
|
6708
6784
|
Object.assign(Usion, createBackButtonMethods(Usion));
|
|
6709
6785
|
|
|
6786
|
+
// Attach hybrid tabbed-service methods directly on Usion
|
|
6787
|
+
Object.assign(Usion, createHostTabsMethods(Usion));
|
|
6788
|
+
|
|
6710
6789
|
// Attach UI utilities directly on Usion
|
|
6711
6790
|
Object.assign(Usion, uiMethods);
|
|
6712
6791
|
|
package/src/modules/core.js
CHANGED
|
@@ -68,7 +68,7 @@ export function isTrustedMessageSource(event) {
|
|
|
68
68
|
* Core Usion object with init, _post, _request
|
|
69
69
|
*/
|
|
70
70
|
export const core = {
|
|
71
|
-
version: '2.
|
|
71
|
+
version: '2.25.0', // synced from package.json by scripts/sync-version.mjs
|
|
72
72
|
config: {},
|
|
73
73
|
_initialized: false,
|
|
74
74
|
_initCallback: null,
|
|
@@ -242,6 +242,15 @@ export const core = {
|
|
|
242
242
|
self.bot._messageHandler(data.message);
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
+
// Handle host tab navigation (hybrid tabbed services). Keep launchPath
|
|
246
|
+
// truthful so getLaunchParams().path always reflects the current tab.
|
|
247
|
+
if (data.type === 'HOST_NAVIGATE' && typeof data.path === 'string') {
|
|
248
|
+
if (self.config) self.config.launchPath = data.path;
|
|
249
|
+
if (self._hostNavigateCallback) {
|
|
250
|
+
self._hostNavigateCallback({ path: data.path, tab: data.tab || null });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
245
254
|
// Handle backend server-push events relayed by the host (embedded mode).
|
|
246
255
|
if (data.type === 'BACKEND_EVENT' && data.event && self._backendHandlers) {
|
|
247
256
|
const h = self._backendHandlers[data.event];
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usion SDK Host Tabs — hybrid tabbed services (SDK ≥ 2.25)
|
|
3
|
+
*
|
|
4
|
+
* A hybrid service registers `tabs`: the platform renders its native bot chat
|
|
5
|
+
* as one tab and this app's own pages as the others, inside ONE persistent
|
|
6
|
+
* iframe/WebView. These methods are the two-way bridge with that host screen:
|
|
7
|
+
*
|
|
8
|
+
* - Host → app: `onHostNavigate(cb)` receives tab switches as `{ path, tab }`.
|
|
9
|
+
* Subscribing tells the host it can navigate in place; apps that never
|
|
10
|
+
* subscribe get remounted with the new path as `getLaunchParams().path`.
|
|
11
|
+
* - App → host: `openChat({ prefill })` jumps to the native chat tab with the
|
|
12
|
+
* composer pre-filled (the user still presses send themselves), and
|
|
13
|
+
* `reportPath(path)` keeps the host's tab highlight in sync when the user
|
|
14
|
+
* navigates inside the app.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export function createHostTabsMethods(Usion) {
|
|
18
|
+
return {
|
|
19
|
+
/**
|
|
20
|
+
* Subscribe to host tab navigation. Called when the user taps one of this
|
|
21
|
+
* service's tabs in the host tab bar (or a deep link targets a tab).
|
|
22
|
+
* Subscribing signals the host that this app navigates in place — without
|
|
23
|
+
* a subscription the host reloads the app with the new launch path instead.
|
|
24
|
+
* @param {function} callback - Called with { path, tab } (tab may be null)
|
|
25
|
+
*/
|
|
26
|
+
onHostNavigate: function(callback) {
|
|
27
|
+
Usion._hostNavigateCallback = callback;
|
|
28
|
+
Usion._post({ type: 'HOST_NAVIGATE_SUBSCRIBED' });
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Unsubscribe from host tab navigation (the host falls back to remounting
|
|
33
|
+
* the app on the next tab switch).
|
|
34
|
+
*/
|
|
35
|
+
offHostNavigate: function() {
|
|
36
|
+
Usion._hostNavigateCallback = null;
|
|
37
|
+
Usion._post({ type: 'HOST_NAVIGATE_UNSUBSCRIBED' });
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Ask the host to switch to the native chat tab, optionally pre-filling
|
|
42
|
+
* the message composer. The text is NEVER sent automatically — the user
|
|
43
|
+
* reviews it and presses send. No-op outside a hybrid tabbed host screen.
|
|
44
|
+
* @param {object} [opts]
|
|
45
|
+
* @param {string} [opts.prefill] - Draft text for the chat composer
|
|
46
|
+
*/
|
|
47
|
+
openChat: function(opts) {
|
|
48
|
+
opts = opts || {};
|
|
49
|
+
Usion._post({
|
|
50
|
+
type: 'OPEN_CHAT_TAB',
|
|
51
|
+
prefill: typeof opts.prefill === 'string' ? opts.prefill : undefined
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Report the app's current internal path so the host can keep its tab
|
|
57
|
+
* highlight in sync with in-app navigation. Fire-and-forget; the host
|
|
58
|
+
* never echoes a navigation back for a reported path.
|
|
59
|
+
* @param {string} path - Current path inside the app (e.g. "/explore")
|
|
60
|
+
*/
|
|
61
|
+
reportPath: function(path) {
|
|
62
|
+
if (typeof path !== 'string' || !path) return;
|
|
63
|
+
Usion._post({ type: 'TAB_CHANGED', path: path });
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
package/src/modules/index.js
CHANGED
|
@@ -21,6 +21,7 @@ import { createChatModule } from './chat.js';
|
|
|
21
21
|
import { createBotModule } from './bot.js';
|
|
22
22
|
import { createResultsMethods } from './results.js';
|
|
23
23
|
import { createBackButtonMethods } from './back-button.js';
|
|
24
|
+
import { createHostTabsMethods } from './host-tabs.js';
|
|
24
25
|
import { uiMethods } from './ui.js';
|
|
25
26
|
import { miscMethods } from './misc.js';
|
|
26
27
|
import { createFileStorageModule } from './file-storage.js';
|
|
@@ -69,6 +70,9 @@ Object.assign(Usion, createResultsMethods(Usion));
|
|
|
69
70
|
// Attach back button methods directly on Usion
|
|
70
71
|
Object.assign(Usion, createBackButtonMethods(Usion));
|
|
71
72
|
|
|
73
|
+
// Attach hybrid tabbed-service methods directly on Usion
|
|
74
|
+
Object.assign(Usion, createHostTabsMethods(Usion));
|
|
75
|
+
|
|
72
76
|
// Attach UI utilities directly on Usion
|
|
73
77
|
Object.assign(Usion, uiMethods);
|
|
74
78
|
|
package/types/index.d.ts
CHANGED
|
@@ -1071,6 +1071,29 @@ export interface UsionSDK {
|
|
|
1071
1071
|
claimBackButton(callback: () => void): void;
|
|
1072
1072
|
releaseBackButton(): void;
|
|
1073
1073
|
|
|
1074
|
+
// Hybrid tabbed services (SDK ≥ 2.25)
|
|
1075
|
+
/**
|
|
1076
|
+
* Subscribe to host tab navigation on a hybrid tabbed service. Called with
|
|
1077
|
+
* `{ path, tab }` when the user taps one of this service's tabs in the host
|
|
1078
|
+
* tab bar (or a deep link targets a tab). Subscribing signals the host that
|
|
1079
|
+
* the app navigates in place; apps that never subscribe are remounted with
|
|
1080
|
+
* the new path as `getLaunchParams().path` instead. (SDK ≥ 2.25)
|
|
1081
|
+
*/
|
|
1082
|
+
onHostNavigate(callback: (nav: { path: string; tab: string | null }) => void): void;
|
|
1083
|
+
/** Unsubscribe from host tab navigation. (SDK ≥ 2.25) */
|
|
1084
|
+
offHostNavigate(): void;
|
|
1085
|
+
/**
|
|
1086
|
+
* Ask the host to switch to the native chat tab, optionally pre-filling the
|
|
1087
|
+
* message composer. The text is never sent automatically — the user reviews
|
|
1088
|
+
* it and presses send. No-op outside a hybrid tabbed host screen. (SDK ≥ 2.25)
|
|
1089
|
+
*/
|
|
1090
|
+
openChat(opts?: { prefill?: string }): void;
|
|
1091
|
+
/**
|
|
1092
|
+
* Report the app's current internal path so the host keeps its tab highlight
|
|
1093
|
+
* in sync with in-app navigation. Fire-and-forget. (SDK ≥ 2.25)
|
|
1094
|
+
*/
|
|
1095
|
+
reportPath(path: string): void;
|
|
1096
|
+
|
|
1074
1097
|
// Download
|
|
1075
1098
|
download(url: string, filename?: string): Promise<{ success?: boolean; error?: string }>;
|
|
1076
1099
|
|