chayns-api 1.2.0-0 → 1.2.0-2
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/dist/chayns-api.js +2 -0
- package/dist/chayns-api.js.LICENSE.txt +51 -0
- package/dist/cjs/components/withCompatMode.js +8 -5
- package/dist/cjs/host/module/utils/loadComponent.js +35 -22
- package/dist/cjs/host/module/utils/useDynamicScript.js +4 -6
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/types/IChaynsReact.js +13 -1
- package/dist/cjs/util/deviceHelper.js +23 -11
- package/dist/cjs/util/is.js +30 -0
- package/dist/cjs/wrapper/AppWrapper.js +33 -5
- package/dist/cjs/wrapper/StaticChaynsApi.js +12 -1
- package/dist/esm/components/withCompatMode.js +8 -5
- package/dist/esm/host/module/utils/loadComponent.js +33 -19
- package/dist/esm/index.js +1 -0
- package/dist/esm/types/IChaynsReact.js +12 -0
- package/dist/esm/util/deviceHelper.js +24 -11
- package/dist/esm/util/is.js +23 -0
- package/dist/esm/wrapper/AppWrapper.js +36 -7
- package/dist/esm/wrapper/StaticChaynsApi.js +11 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/types/IChaynsReact.d.ts +45 -5
- package/dist/types/util/deviceHelper.d.ts +3 -1
- package/dist/types/util/is.d.ts +5 -0
- package/package.json +4 -3
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getDevice } from '../calls';
|
|
2
|
+
import { AppName } from '../types/IChaynsReact';
|
|
3
|
+
export const isApp = () => {
|
|
4
|
+
var _getDevice$app$name, _getDevice$app;
|
|
5
|
+
return ((_getDevice$app$name = (_getDevice$app = getDevice().app) === null || _getDevice$app === void 0 ? void 0 : _getDevice$app.name) !== null && _getDevice$app$name !== void 0 ? _getDevice$app$name : AppName.Unknown) !== AppName.Unknown;
|
|
6
|
+
};
|
|
7
|
+
export const isAppCallSupported = _ref => {
|
|
8
|
+
var _device$app;
|
|
9
|
+
let {
|
|
10
|
+
minAndroidVersion = 1,
|
|
11
|
+
minIOSVersion = 1
|
|
12
|
+
} = _ref;
|
|
13
|
+
if (!isApp()) return false;
|
|
14
|
+
const device = getDevice();
|
|
15
|
+
if (!((_device$app = device.app) !== null && _device$app !== void 0 && _device$app.callVersion) || isNaN(device.app.callVersion)) return false;
|
|
16
|
+
if (device.os && ['iOS', 'Mac OS'].includes(device.os)) {
|
|
17
|
+
return device.app.callVersion >= minIOSVersion;
|
|
18
|
+
}
|
|
19
|
+
if (device.os === 'Android OS') {
|
|
20
|
+
return device.app.callVersion >= minAndroidVersion;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
};
|
|
@@ -13,6 +13,7 @@ import getUserInfo from '../calls/getUserInfo';
|
|
|
13
13
|
import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from '../calls/sendMessage';
|
|
14
14
|
import { addApiListener, dispatchApiEvent, removeApiListener } from '../helper/apiListenerHelper';
|
|
15
15
|
import { DeviceLanguage } from '../constants/languages';
|
|
16
|
+
import { isAppCallSupported } from '../util/is';
|
|
16
17
|
let appWrapperDialogId = 0;
|
|
17
18
|
export class AppWrapper {
|
|
18
19
|
mapOldApiToNew(retVal) {
|
|
@@ -59,7 +60,9 @@ export class AppWrapper {
|
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
return {
|
|
62
|
-
device: getDeviceInfo(navigator.userAgent, 'image/webp'
|
|
63
|
+
device: getDeviceInfo(navigator.userAgent, 'image/webp', {
|
|
64
|
+
imei: Device.IMEI
|
|
65
|
+
}),
|
|
63
66
|
environment: {
|
|
64
67
|
buildEnvironment: Environment.Production,
|
|
65
68
|
runtimeEnvironment: RuntimeEnviroment.Unknown
|
|
@@ -380,6 +383,26 @@ export class AppWrapper {
|
|
|
380
383
|
}
|
|
381
384
|
},
|
|
382
385
|
selectPage: async options => {
|
|
386
|
+
var _this$values, _this$values2;
|
|
387
|
+
if ((_this$values = this.values) !== null && _this$values !== void 0 && (_this$values = _this$values.site) !== null && _this$values !== void 0 && _this$values.id && options.siteId && options.siteId !== ((_this$values2 = this.values) === null || _this$values2 === void 0 || (_this$values2 = _this$values2.site) === null || _this$values2 === void 0 ? void 0 : _this$values2.id)) {
|
|
388
|
+
const url = new URL(`https://chayns.site/${options.siteId}`);
|
|
389
|
+
if (options.id) {
|
|
390
|
+
url.pathname += `/tapp/${options.id}`;
|
|
391
|
+
} else if (options.path) {
|
|
392
|
+
url.pathname += `/${options.path}`;
|
|
393
|
+
}
|
|
394
|
+
if (options.params) {
|
|
395
|
+
Object.entries(options.params).forEach(_ref2 => {
|
|
396
|
+
let [k, v] = _ref2;
|
|
397
|
+
url.searchParams.set(k, v);
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
void this.appCall(9, {
|
|
401
|
+
url: url.toString(),
|
|
402
|
+
checkForChaynsSite: true
|
|
403
|
+
});
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
383
406
|
void this.appCall(2, {
|
|
384
407
|
id: options.id,
|
|
385
408
|
showName: options.showName,
|
|
@@ -389,14 +412,16 @@ export class AppWrapper {
|
|
|
389
412
|
awaitResult: false
|
|
390
413
|
});
|
|
391
414
|
},
|
|
392
|
-
scrollToY: async position => {
|
|
415
|
+
scrollToY: async (position, duration) => {
|
|
393
416
|
window.scrollTo({
|
|
394
|
-
top: position
|
|
417
|
+
top: position,
|
|
418
|
+
behavior: duration ? 'smooth' : 'auto'
|
|
395
419
|
});
|
|
396
420
|
},
|
|
397
421
|
scrollByY: (value, duration) => {
|
|
398
422
|
window.scrollBy({
|
|
399
|
-
top: value
|
|
423
|
+
top: value,
|
|
424
|
+
behavior: duration ? 'smooth' : 'auto'
|
|
400
425
|
});
|
|
401
426
|
},
|
|
402
427
|
sendMessageToGroup: async (groupId, message) => {
|
|
@@ -502,12 +527,16 @@ export class AppWrapper {
|
|
|
502
527
|
},
|
|
503
528
|
openDialog: async (config, callback) => {
|
|
504
529
|
const currentDialogId = appWrapperDialogId++;
|
|
530
|
+
const isSupported = isAppCallSupported({
|
|
531
|
+
minAndroidVersion: 7137,
|
|
532
|
+
minIOSVersion: 6934
|
|
533
|
+
});
|
|
505
534
|
this.appCall(184, {
|
|
506
535
|
dialogContent: {
|
|
507
536
|
apiVersion: 5,
|
|
508
537
|
config
|
|
509
538
|
},
|
|
510
|
-
externalDialogUrl: 'https://tapp.chayns-static.space/api/dialog-v2/v1/index.html'
|
|
539
|
+
externalDialogUrl: isSupported ? undefined : 'https://tapp.chayns-static.space/api/dialog-v2/v1/index.html'
|
|
511
540
|
}, {
|
|
512
541
|
awaitResult: true
|
|
513
542
|
}).then(result => {
|
|
@@ -588,10 +617,10 @@ export class AppWrapper {
|
|
|
588
617
|
this.appCall(254, {
|
|
589
618
|
enabled: true
|
|
590
619
|
}, {
|
|
591
|
-
callback:
|
|
620
|
+
callback: _ref3 => {
|
|
592
621
|
let {
|
|
593
622
|
colorMode
|
|
594
|
-
} =
|
|
623
|
+
} = _ref3;
|
|
595
624
|
this.values.site = {
|
|
596
625
|
...this.values.site,
|
|
597
626
|
colorMode
|
|
@@ -2,9 +2,13 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
2
2
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
3
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
4
4
|
import { moduleWrapper } from '../components/moduleWrapper';
|
|
5
|
+
import { AppName } from '../types/IChaynsReact';
|
|
6
|
+
import getDeviceInfo from '../util/deviceHelper';
|
|
7
|
+
import { AppWrapper } from './AppWrapper';
|
|
5
8
|
import { FrameWrapper } from './FrameWrapper';
|
|
6
9
|
class StaticChaynsApi {
|
|
7
10
|
constructor() {
|
|
11
|
+
var _deviceInfo$app$name, _deviceInfo$app;
|
|
8
12
|
_defineProperty(this, "getUser", () => this._wrapper.values.user);
|
|
9
13
|
_defineProperty(this, "getSite", () => this._wrapper.values.site);
|
|
10
14
|
_defineProperty(this, "getCurrentPage", () => this._wrapper.values.currentPage);
|
|
@@ -13,7 +17,13 @@ class StaticChaynsApi {
|
|
|
13
17
|
_defineProperty(this, "getParameters", () => this._wrapper.values.parameters);
|
|
14
18
|
_defineProperty(this, "getPages", () => this._wrapper.values.pages);
|
|
15
19
|
_defineProperty(this, "getEnvironment", () => this._wrapper.values.environment);
|
|
16
|
-
|
|
20
|
+
let wrapper;
|
|
21
|
+
const deviceInfo = getDeviceInfo(navigator.userAgent, '');
|
|
22
|
+
if ([AppName.Chayns, AppName.ChaynsLauncher, AppName.Sidekick, AppName.TobitChat].includes((_deviceInfo$app$name = (_deviceInfo$app = deviceInfo.app) === null || _deviceInfo$app === void 0 ? void 0 : _deviceInfo$app.name) !== null && _deviceInfo$app$name !== void 0 ? _deviceInfo$app$name : AppName.Unknown) && window.self === window.top) {
|
|
23
|
+
wrapper = new AppWrapper();
|
|
24
|
+
} else {
|
|
25
|
+
wrapper = new FrameWrapper();
|
|
26
|
+
}
|
|
17
27
|
moduleWrapper.current = wrapper;
|
|
18
28
|
this._wrapper = wrapper;
|
|
19
29
|
this.ready = wrapper.init();
|
package/dist/types/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './calls';
|
|
|
7
7
|
export * from './hooks';
|
|
8
8
|
export * from './components/WaitUntil';
|
|
9
9
|
export * from './types/IChaynsReact';
|
|
10
|
+
export * from './util/is';
|
|
10
11
|
export * from './components/withCompatMode';
|
|
11
12
|
export * from './constants';
|
|
12
13
|
export { default as withHydrationBoundary } from './components/withHydrationBoundary';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IBrowser, IEngine } from 'ua-parser-js';
|
|
2
2
|
import DialogHandler from '../handler/DialogHandler';
|
|
3
3
|
import { DialogButtonOld, SelectDialogItem } from './dialog';
|
|
4
4
|
export type DialogButton = {
|
|
@@ -21,6 +21,28 @@ export interface DialogDate {
|
|
|
21
21
|
multiselect?: boolean;
|
|
22
22
|
monthSelect?: boolean;
|
|
23
23
|
yearSelect?: boolean;
|
|
24
|
+
interval?: boolean;
|
|
25
|
+
disabledDates?: Date[];
|
|
26
|
+
disabledIntervals?: {
|
|
27
|
+
start: Date;
|
|
28
|
+
end: Date;
|
|
29
|
+
}[];
|
|
30
|
+
disabledWeekDayIntervals?: {
|
|
31
|
+
weekDay: WeekDayType;
|
|
32
|
+
interval?: {
|
|
33
|
+
start: Date;
|
|
34
|
+
end: Date;
|
|
35
|
+
};
|
|
36
|
+
}[];
|
|
37
|
+
}
|
|
38
|
+
export declare enum WeekDayType {
|
|
39
|
+
SUNDAY = 0,
|
|
40
|
+
MONDAY = 1,
|
|
41
|
+
TUESDAY = 2,
|
|
42
|
+
WEDNESDAY = 3,
|
|
43
|
+
THURSDAY = 4,
|
|
44
|
+
FRIDAY = 5,
|
|
45
|
+
SATURDAY = 6
|
|
24
46
|
}
|
|
25
47
|
export declare enum ToastType {
|
|
26
48
|
NEUTRAL = 1,
|
|
@@ -98,7 +120,8 @@ export interface DialogInput {
|
|
|
98
120
|
export declare enum DialogSelectType {
|
|
99
121
|
DEFAULT = 0,
|
|
100
122
|
ICON = 1,
|
|
101
|
-
IMAGE = 2
|
|
123
|
+
IMAGE = 2,
|
|
124
|
+
SIMPLE = 3
|
|
102
125
|
}
|
|
103
126
|
export type DialogSelectListItemType = {
|
|
104
127
|
id: number;
|
|
@@ -115,6 +138,9 @@ export type DialogSelectListItemType = {
|
|
|
115
138
|
export interface DialogSelect {
|
|
116
139
|
type: DialogType.SELECT;
|
|
117
140
|
list: DialogSelectListItemType[];
|
|
141
|
+
fixedItem?: DialogSelectListItemType & {
|
|
142
|
+
position?: 'top' | 'bottom';
|
|
143
|
+
};
|
|
118
144
|
multiselect?: boolean;
|
|
119
145
|
quickfind?: boolean;
|
|
120
146
|
selectType?: DialogSelectType;
|
|
@@ -129,6 +155,7 @@ export declare enum DialogButtonType {
|
|
|
129
155
|
export type ChaynsApiUser = {
|
|
130
156
|
firstName?: string;
|
|
131
157
|
lastName?: string;
|
|
158
|
+
nickName?: string;
|
|
132
159
|
gender?: Gender;
|
|
133
160
|
uacGroups?: UacGroup[];
|
|
134
161
|
userId?: number;
|
|
@@ -154,27 +181,39 @@ export type ChaynsApiSite = {
|
|
|
154
181
|
originSiteId?: string;
|
|
155
182
|
};
|
|
156
183
|
export declare enum ScreenSize {
|
|
184
|
+
/** screen width smaller than or equal 556px */
|
|
157
185
|
XS = 0,
|
|
186
|
+
/** screen width between 557px and 769px */
|
|
158
187
|
SM = 1,
|
|
188
|
+
/** screen width between 770px and 993px */
|
|
159
189
|
MD = 2,
|
|
190
|
+
/** screen width between 994px and 1200px */
|
|
160
191
|
LG = 3,
|
|
192
|
+
/** screen width larger than 1200px */
|
|
161
193
|
XL = 4
|
|
162
194
|
}
|
|
163
195
|
export type ChaynsApiDevice = {
|
|
164
196
|
app?: {
|
|
165
197
|
name: AppName;
|
|
198
|
+
/** @deprecated same value as callVersion */
|
|
166
199
|
version: number;
|
|
200
|
+
/** the actual app version according to the app name */
|
|
201
|
+
appVersion: number;
|
|
202
|
+
/** the version of the chayns call interface */
|
|
203
|
+
callVersion: number;
|
|
167
204
|
storePackageName?: string;
|
|
168
205
|
};
|
|
169
206
|
browser?: {
|
|
170
|
-
name?:
|
|
207
|
+
name?: IBrowser["name"] | 'bot' | null;
|
|
171
208
|
version?: string | null;
|
|
172
209
|
majorVersion: number;
|
|
173
210
|
isWebPSupported: boolean;
|
|
174
211
|
};
|
|
212
|
+
engine?: IEngine;
|
|
175
213
|
imei?: string;
|
|
176
214
|
accessToken?: string;
|
|
177
|
-
os?:
|
|
215
|
+
os?: 'AIX' | 'Amiga OS' | 'Android OS' | 'Arch' | 'Bada' | 'BeOS' | 'BlackBerry' | 'CentOS' | 'Chromium OS' | 'Contiki' | 'Fedora' | 'Firefox OS' | 'FreeBSD' | 'Debian' | 'DragonFly' | 'Gentoo' | 'GNU' | 'Haiku' | 'Hurd' | 'iOS' | 'Joli' | 'Linpus' | 'Linux' | 'Mac OS' | 'Mageia' | 'Mandriva' | 'MeeGo' | 'Minix' | 'Mint' | 'Morph OS' | 'NetBSD' | 'Nintendo' | 'OpenBSD' | 'OpenVMS' | 'OS/2' | 'Palm' | 'PCLinuxOS' | 'Plan9' | 'Playstation' | 'QNX' | 'RedHat' | 'RIM Tablet OS' | 'RISC OS' | 'Sailfish' | 'Series40' | 'Slackware' | 'Solaris' | 'SUSE' | 'Symbian' | 'Tizen' | 'Ubuntu' | 'UNIX' | 'VectorLinux' | 'WebOS' | 'Windows' | 'Windows Phone' | 'Windows Mobile' | 'Zenwalk' | null;
|
|
216
|
+
osVersion?: string;
|
|
178
217
|
isTouch: boolean;
|
|
179
218
|
screenSize: ScreenSize;
|
|
180
219
|
};
|
|
@@ -729,7 +768,8 @@ export declare enum RuntimeEnviroment {
|
|
|
729
768
|
ChaynsWeb = 2,
|
|
730
769
|
ChaynsRuntime = 3,
|
|
731
770
|
IntercomPlugin = 4,
|
|
732
|
-
PagemakerPlugin = 5
|
|
771
|
+
PagemakerPlugin = 5,
|
|
772
|
+
Dialog = 6
|
|
733
773
|
}
|
|
734
774
|
export declare enum DeviceOs {
|
|
735
775
|
Unknown = "unknown",
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ChaynsApiDevice, ScreenSize } from '../types/IChaynsReact';
|
|
2
|
-
declare const getDeviceInfo: (userAgent: string, acceptHeader: string
|
|
2
|
+
declare const getDeviceInfo: (userAgent: string, acceptHeader: string, { imei }?: {
|
|
3
|
+
imei?: string | undefined;
|
|
4
|
+
}) => ChaynsApiDevice;
|
|
3
5
|
export declare const getClientDeviceInfo: () => {
|
|
4
6
|
isTouch: boolean;
|
|
5
7
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chayns-api",
|
|
3
|
-
"version": "1.2.0-
|
|
3
|
+
"version": "1.2.0-2",
|
|
4
4
|
"description": "new chayns api",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -42,16 +42,16 @@
|
|
|
42
42
|
"extends": "@chayns-toolkit"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@module-federation/runtime": "^0.
|
|
45
|
+
"@module-federation/runtime": "^0.6.9",
|
|
46
46
|
"@types/semver": "^7.5.8",
|
|
47
47
|
"comlink": "4.3.1",
|
|
48
|
-
"detect-browser": "^5.2.1",
|
|
49
48
|
"htmlescape": "^1.1.1",
|
|
50
49
|
"lodash.throttle": "^4.1.1",
|
|
51
50
|
"prop-types": "^15.7.2",
|
|
52
51
|
"scheduler": "^0.23.0",
|
|
53
52
|
"semaphore-async-await": "^1.5.1",
|
|
54
53
|
"semver": "^7.6.0",
|
|
54
|
+
"ua-parser-js": "^1.0.38",
|
|
55
55
|
"use-context-selector": "^1.4.4",
|
|
56
56
|
"util": "^0.12.5"
|
|
57
57
|
},
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"@types/prop-types": "^15.7.12",
|
|
69
69
|
"@types/react": "^18.2.78",
|
|
70
70
|
"@types/react-dom": "^18.2.25",
|
|
71
|
+
"@types/ua-parser-js": "^0.7.39",
|
|
71
72
|
"@typescript-eslint/parser": "^7.6.0",
|
|
72
73
|
"chayns-toolkit": "^2.0.9",
|
|
73
74
|
"concurrently": "^8.2.2",
|