@tusi-ai/plugins 0.0.0-stage → 0.0.1-beta.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.
Files changed (38) hide show
  1. package/README.md +87 -2
  2. package/dist/calendar/index.cjs +119 -0
  3. package/dist/calendar/index.d.mts +30 -0
  4. package/dist/calendar/index.d.ts +30 -0
  5. package/dist/calendar/index.js +117 -0
  6. package/dist/camera/index.cjs +351 -0
  7. package/dist/camera/index.d.mts +98 -0
  8. package/dist/camera/index.d.ts +98 -0
  9. package/dist/camera/index.js +349 -0
  10. package/dist/clipboard/index.cjs +139 -0
  11. package/dist/clipboard/index.d.mts +41 -0
  12. package/dist/clipboard/index.d.ts +41 -0
  13. package/dist/clipboard/index.js +137 -0
  14. package/dist/contact-picker/index.cjs +100 -0
  15. package/dist/contact-picker/index.d.mts +37 -0
  16. package/dist/contact-picker/index.d.ts +37 -0
  17. package/dist/contact-picker/index.js +98 -0
  18. package/dist/filesystem/index.cjs +447 -0
  19. package/dist/filesystem/index.d.mts +202 -0
  20. package/dist/filesystem/index.d.ts +202 -0
  21. package/dist/filesystem/index.js +445 -0
  22. package/dist/geolocation/index.cjs +114 -0
  23. package/dist/geolocation/index.d.mts +49 -0
  24. package/dist/geolocation/index.d.ts +49 -0
  25. package/dist/geolocation/index.js +112 -0
  26. package/dist/index.cjs +40 -0
  27. package/dist/index.d.mts +29 -0
  28. package/dist/index.d.ts +29 -0
  29. package/dist/index.js +38 -0
  30. package/dist/local-notifications/index.cjs +152 -0
  31. package/dist/local-notifications/index.d.mts +84 -0
  32. package/dist/local-notifications/index.d.ts +84 -0
  33. package/dist/local-notifications/index.js +150 -0
  34. package/dist/share/index.cjs +145 -0
  35. package/dist/share/index.d.mts +45 -0
  36. package/dist/share/index.d.ts +45 -0
  37. package/dist/share/index.js +143 -0
  38. package/package.json +123 -3
@@ -0,0 +1,114 @@
1
+ 'use strict';
2
+
3
+ var core = require('@tusi-ai/core');
4
+
5
+ // src/geolocation/index.ts
6
+ var BaseAdapter = class {
7
+ /**
8
+ * 绑定插件名,后续原生调用会拼成 `pluginName.method`。
9
+ *
10
+ * @param pluginName - JSB 插件名,例如 `Camera`
11
+ */
12
+ constructor(pluginName) {
13
+ this.pluginName = pluginName;
14
+ }
15
+ /**
16
+ * 调用 `pluginName.method`。只给原生适配器使用。
17
+ *
18
+ * @param method - 插件内的方法名,例如 `getPhoto`
19
+ * @param params - 原样交给 {@link bridge}
20
+ * @returns 客户端响应的 `data`
21
+ */
22
+ callNative(method, params) {
23
+ return core.bridge.call(`${this.pluginName}.${method}`, params);
24
+ }
25
+ /**
26
+ * 当前环境没有这个能力。在进入 bridge 之前抛出。
27
+ *
28
+ * @param method - 插件内的方法名
29
+ * @throws {@link TusiError} {@link ErrorCode.Unsupported}
30
+ */
31
+ unsupported(method) {
32
+ throw new core.TusiError(
33
+ core.ErrorCode.Unsupported,
34
+ `${this.pluginName}.${method} is not supported`,
35
+ `${this.pluginName}.${method}`
36
+ );
37
+ }
38
+ };
39
+
40
+ // src/geolocation/adapter.ts
41
+ var GeolocationAdapter = class extends BaseAdapter {
42
+ constructor() {
43
+ super("Geolocation");
44
+ }
45
+ };
46
+
47
+ // src/geolocation/browser.ts
48
+ var BrowserGeolocationAdapter = class extends GeolocationAdapter {
49
+ getCurrentPos(options) {
50
+ if (typeof navigator === "undefined" || !navigator.geolocation) {
51
+ this.unsupported("getCurrentPos");
52
+ }
53
+ return new Promise((resolve, reject) => {
54
+ navigator.geolocation.getCurrentPosition(
55
+ (position) => resolve(toPosition(position, options)),
56
+ (error) => {
57
+ const code = error.code === error.PERMISSION_DENIED ? core.ErrorCode.PermissionDenied : core.ErrorCode.NativeFailure;
58
+ reject(new core.TusiError(code, error.message, "Geolocation.getCurrentPos", error));
59
+ },
60
+ {
61
+ enableHighAccuracy: options == null ? void 0 : options.enableHighAccuracy,
62
+ timeout: options == null ? void 0 : options.timeout,
63
+ maximumAge: options == null ? void 0 : options.maximumAge
64
+ }
65
+ );
66
+ });
67
+ }
68
+ };
69
+ function toPosition(position, options) {
70
+ const { coords } = position;
71
+ return {
72
+ latitude: coords.latitude,
73
+ longitude: coords.longitude,
74
+ accuracy: coords.accuracy,
75
+ altitude: optionalNumber(coords.altitude),
76
+ altitudeAccuracy: optionalNumber(coords.altitudeAccuracy),
77
+ speed: optionalNumber(coords.speed),
78
+ bearing: optionalNumber(coords.heading),
79
+ time: position.timestamp,
80
+ provider: (options == null ? void 0 : options.enableHighAccuracy) ? "gps" : "network"
81
+ };
82
+ }
83
+ function optionalNumber(value) {
84
+ return value === null ? void 0 : value;
85
+ }
86
+
87
+ // src/geolocation/native.ts
88
+ var NativeGeolocationAdapter = class extends GeolocationAdapter {
89
+ getCurrentPos(options) {
90
+ return this.callNative("getCurrentPos", options);
91
+ }
92
+ };
93
+
94
+ // src/geolocation/index.ts
95
+ var adapter;
96
+ function getAdapter() {
97
+ adapter != null ? adapter : adapter = core.getRuntimeEnv() === core.RuntimeEnv.Browser ? new BrowserGeolocationAdapter() : new NativeGeolocationAdapter();
98
+ return adapter;
99
+ }
100
+ var Geolocation = {
101
+ /**
102
+ * 读取当前坐标。
103
+ *
104
+ * @param options - 精度、超时和缓存年龄
105
+ * @returns 当前位置。`provider` 为 `gps`、`network` 或 `passive`
106
+ * @throws {@link TusiError}
107
+ * {@link ErrorCode.PermissionDenied} 用户拒绝,{@link ErrorCode.NativeFailure} 超时或定位失败
108
+ */
109
+ getCurrentPos(options) {
110
+ return getAdapter().getCurrentPos(options);
111
+ }
112
+ };
113
+
114
+ exports.Geolocation = Geolocation;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * {@link Geolocation.getCurrentPos} 的入参。权限在该方法内部申请。
3
+ */
4
+ interface GetCurrentPosOptions {
5
+ /** 为真时优先使用 GPS。 */
6
+ enableHighAccuracy?: boolean;
7
+ /** 超时,单位毫秒。 */
8
+ timeout?: number;
9
+ /** 可接受的缓存定位年龄,单位毫秒。 */
10
+ maximumAge?: number;
11
+ }
12
+ /** 一次定位结果。`provider` 为 `gps`、`network` 或 `passive`。 */
13
+ interface Position {
14
+ /** 纬度。 */
15
+ latitude: number;
16
+ /** 经度。 */
17
+ longitude: number;
18
+ /** 水平精度,单位米。 */
19
+ accuracy: number;
20
+ /** 海拔,单位米。 */
21
+ altitude?: number;
22
+ /** 海拔精度,单位米。 */
23
+ altitudeAccuracy?: number;
24
+ /** 速度,单位米每秒。 */
25
+ speed?: number;
26
+ /** 方向,单位度。 */
27
+ bearing?: number;
28
+ /** 定位时间,UTC 毫秒。 */
29
+ time: number;
30
+ /** 定位来源。 */
31
+ provider: string;
32
+ }
33
+
34
+ /**
35
+ * 定位插件。只提供一次性定位,不单独暴露权限方法。
36
+ */
37
+ declare const Geolocation: {
38
+ /**
39
+ * 读取当前坐标。
40
+ *
41
+ * @param options - 精度、超时和缓存年龄
42
+ * @returns 当前位置。`provider` 为 `gps`、`network` 或 `passive`
43
+ * @throws {@link TusiError}
44
+ * {@link ErrorCode.PermissionDenied} 用户拒绝,{@link ErrorCode.NativeFailure} 超时或定位失败
45
+ */
46
+ getCurrentPos(options?: GetCurrentPosOptions): Promise<Position>;
47
+ };
48
+
49
+ export { Geolocation, type GetCurrentPosOptions, type Position };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * {@link Geolocation.getCurrentPos} 的入参。权限在该方法内部申请。
3
+ */
4
+ interface GetCurrentPosOptions {
5
+ /** 为真时优先使用 GPS。 */
6
+ enableHighAccuracy?: boolean;
7
+ /** 超时,单位毫秒。 */
8
+ timeout?: number;
9
+ /** 可接受的缓存定位年龄,单位毫秒。 */
10
+ maximumAge?: number;
11
+ }
12
+ /** 一次定位结果。`provider` 为 `gps`、`network` 或 `passive`。 */
13
+ interface Position {
14
+ /** 纬度。 */
15
+ latitude: number;
16
+ /** 经度。 */
17
+ longitude: number;
18
+ /** 水平精度,单位米。 */
19
+ accuracy: number;
20
+ /** 海拔,单位米。 */
21
+ altitude?: number;
22
+ /** 海拔精度,单位米。 */
23
+ altitudeAccuracy?: number;
24
+ /** 速度,单位米每秒。 */
25
+ speed?: number;
26
+ /** 方向,单位度。 */
27
+ bearing?: number;
28
+ /** 定位时间,UTC 毫秒。 */
29
+ time: number;
30
+ /** 定位来源。 */
31
+ provider: string;
32
+ }
33
+
34
+ /**
35
+ * 定位插件。只提供一次性定位,不单独暴露权限方法。
36
+ */
37
+ declare const Geolocation: {
38
+ /**
39
+ * 读取当前坐标。
40
+ *
41
+ * @param options - 精度、超时和缓存年龄
42
+ * @returns 当前位置。`provider` 为 `gps`、`network` 或 `passive`
43
+ * @throws {@link TusiError}
44
+ * {@link ErrorCode.PermissionDenied} 用户拒绝,{@link ErrorCode.NativeFailure} 超时或定位失败
45
+ */
46
+ getCurrentPos(options?: GetCurrentPosOptions): Promise<Position>;
47
+ };
48
+
49
+ export { Geolocation, type GetCurrentPosOptions, type Position };
@@ -0,0 +1,112 @@
1
+ import { getRuntimeEnv, RuntimeEnv, ErrorCode, TusiError, bridge } from '@tusi-ai/core';
2
+
3
+ // src/geolocation/index.ts
4
+ var BaseAdapter = class {
5
+ /**
6
+ * 绑定插件名,后续原生调用会拼成 `pluginName.method`。
7
+ *
8
+ * @param pluginName - JSB 插件名,例如 `Camera`
9
+ */
10
+ constructor(pluginName) {
11
+ this.pluginName = pluginName;
12
+ }
13
+ /**
14
+ * 调用 `pluginName.method`。只给原生适配器使用。
15
+ *
16
+ * @param method - 插件内的方法名,例如 `getPhoto`
17
+ * @param params - 原样交给 {@link bridge}
18
+ * @returns 客户端响应的 `data`
19
+ */
20
+ callNative(method, params) {
21
+ return bridge.call(`${this.pluginName}.${method}`, params);
22
+ }
23
+ /**
24
+ * 当前环境没有这个能力。在进入 bridge 之前抛出。
25
+ *
26
+ * @param method - 插件内的方法名
27
+ * @throws {@link TusiError} {@link ErrorCode.Unsupported}
28
+ */
29
+ unsupported(method) {
30
+ throw new TusiError(
31
+ ErrorCode.Unsupported,
32
+ `${this.pluginName}.${method} is not supported`,
33
+ `${this.pluginName}.${method}`
34
+ );
35
+ }
36
+ };
37
+
38
+ // src/geolocation/adapter.ts
39
+ var GeolocationAdapter = class extends BaseAdapter {
40
+ constructor() {
41
+ super("Geolocation");
42
+ }
43
+ };
44
+
45
+ // src/geolocation/browser.ts
46
+ var BrowserGeolocationAdapter = class extends GeolocationAdapter {
47
+ getCurrentPos(options) {
48
+ if (typeof navigator === "undefined" || !navigator.geolocation) {
49
+ this.unsupported("getCurrentPos");
50
+ }
51
+ return new Promise((resolve, reject) => {
52
+ navigator.geolocation.getCurrentPosition(
53
+ (position) => resolve(toPosition(position, options)),
54
+ (error) => {
55
+ const code = error.code === error.PERMISSION_DENIED ? ErrorCode.PermissionDenied : ErrorCode.NativeFailure;
56
+ reject(new TusiError(code, error.message, "Geolocation.getCurrentPos", error));
57
+ },
58
+ {
59
+ enableHighAccuracy: options == null ? void 0 : options.enableHighAccuracy,
60
+ timeout: options == null ? void 0 : options.timeout,
61
+ maximumAge: options == null ? void 0 : options.maximumAge
62
+ }
63
+ );
64
+ });
65
+ }
66
+ };
67
+ function toPosition(position, options) {
68
+ const { coords } = position;
69
+ return {
70
+ latitude: coords.latitude,
71
+ longitude: coords.longitude,
72
+ accuracy: coords.accuracy,
73
+ altitude: optionalNumber(coords.altitude),
74
+ altitudeAccuracy: optionalNumber(coords.altitudeAccuracy),
75
+ speed: optionalNumber(coords.speed),
76
+ bearing: optionalNumber(coords.heading),
77
+ time: position.timestamp,
78
+ provider: (options == null ? void 0 : options.enableHighAccuracy) ? "gps" : "network"
79
+ };
80
+ }
81
+ function optionalNumber(value) {
82
+ return value === null ? void 0 : value;
83
+ }
84
+
85
+ // src/geolocation/native.ts
86
+ var NativeGeolocationAdapter = class extends GeolocationAdapter {
87
+ getCurrentPos(options) {
88
+ return this.callNative("getCurrentPos", options);
89
+ }
90
+ };
91
+
92
+ // src/geolocation/index.ts
93
+ var adapter;
94
+ function getAdapter() {
95
+ adapter != null ? adapter : adapter = getRuntimeEnv() === RuntimeEnv.Browser ? new BrowserGeolocationAdapter() : new NativeGeolocationAdapter();
96
+ return adapter;
97
+ }
98
+ var Geolocation = {
99
+ /**
100
+ * 读取当前坐标。
101
+ *
102
+ * @param options - 精度、超时和缓存年龄
103
+ * @returns 当前位置。`provider` 为 `gps`、`network` 或 `passive`
104
+ * @throws {@link TusiError}
105
+ * {@link ErrorCode.PermissionDenied} 用户拒绝,{@link ErrorCode.NativeFailure} 超时或定位失败
106
+ */
107
+ getCurrentPos(options) {
108
+ return getAdapter().getCurrentPos(options);
109
+ }
110
+ };
111
+
112
+ export { Geolocation };
package/dist/index.cjs ADDED
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ var core = require('@tusi-ai/core');
4
+
5
+ // src/base-adapter.ts
6
+ var BaseAdapter = class {
7
+ /**
8
+ * 绑定插件名,后续原生调用会拼成 `pluginName.method`。
9
+ *
10
+ * @param pluginName - JSB 插件名,例如 `Camera`
11
+ */
12
+ constructor(pluginName) {
13
+ this.pluginName = pluginName;
14
+ }
15
+ /**
16
+ * 调用 `pluginName.method`。只给原生适配器使用。
17
+ *
18
+ * @param method - 插件内的方法名,例如 `getPhoto`
19
+ * @param params - 原样交给 {@link bridge}
20
+ * @returns 客户端响应的 `data`
21
+ */
22
+ callNative(method, params) {
23
+ return core.bridge.call(`${this.pluginName}.${method}`, params);
24
+ }
25
+ /**
26
+ * 当前环境没有这个能力。在进入 bridge 之前抛出。
27
+ *
28
+ * @param method - 插件内的方法名
29
+ * @throws {@link TusiError} {@link ErrorCode.Unsupported}
30
+ */
31
+ unsupported(method) {
32
+ throw new core.TusiError(
33
+ core.ErrorCode.Unsupported,
34
+ `${this.pluginName}.${method} is not supported`,
35
+ `${this.pluginName}.${method}`
36
+ );
37
+ }
38
+ };
39
+
40
+ exports.BaseAdapter = BaseAdapter;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * 插件适配器基类。浏览器实现和原生实现各有一个子类,页面入口只选其中一个。
3
+ */
4
+ declare abstract class BaseAdapter {
5
+ protected readonly pluginName: string;
6
+ /**
7
+ * 绑定插件名,后续原生调用会拼成 `pluginName.method`。
8
+ *
9
+ * @param pluginName - JSB 插件名,例如 `Camera`
10
+ */
11
+ constructor(pluginName: string);
12
+ /**
13
+ * 调用 `pluginName.method`。只给原生适配器使用。
14
+ *
15
+ * @param method - 插件内的方法名,例如 `getPhoto`
16
+ * @param params - 原样交给 {@link bridge}
17
+ * @returns 客户端响应的 `data`
18
+ */
19
+ protected callNative<T>(method: string, params?: unknown): Promise<T>;
20
+ /**
21
+ * 当前环境没有这个能力。在进入 bridge 之前抛出。
22
+ *
23
+ * @param method - 插件内的方法名
24
+ * @throws {@link TusiError} {@link ErrorCode.Unsupported}
25
+ */
26
+ protected unsupported(method: string): never;
27
+ }
28
+
29
+ export { BaseAdapter };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * 插件适配器基类。浏览器实现和原生实现各有一个子类,页面入口只选其中一个。
3
+ */
4
+ declare abstract class BaseAdapter {
5
+ protected readonly pluginName: string;
6
+ /**
7
+ * 绑定插件名,后续原生调用会拼成 `pluginName.method`。
8
+ *
9
+ * @param pluginName - JSB 插件名,例如 `Camera`
10
+ */
11
+ constructor(pluginName: string);
12
+ /**
13
+ * 调用 `pluginName.method`。只给原生适配器使用。
14
+ *
15
+ * @param method - 插件内的方法名,例如 `getPhoto`
16
+ * @param params - 原样交给 {@link bridge}
17
+ * @returns 客户端响应的 `data`
18
+ */
19
+ protected callNative<T>(method: string, params?: unknown): Promise<T>;
20
+ /**
21
+ * 当前环境没有这个能力。在进入 bridge 之前抛出。
22
+ *
23
+ * @param method - 插件内的方法名
24
+ * @throws {@link TusiError} {@link ErrorCode.Unsupported}
25
+ */
26
+ protected unsupported(method: string): never;
27
+ }
28
+
29
+ export { BaseAdapter };
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ import { bridge, TusiError, ErrorCode } from '@tusi-ai/core';
2
+
3
+ // src/base-adapter.ts
4
+ var BaseAdapter = class {
5
+ /**
6
+ * 绑定插件名,后续原生调用会拼成 `pluginName.method`。
7
+ *
8
+ * @param pluginName - JSB 插件名,例如 `Camera`
9
+ */
10
+ constructor(pluginName) {
11
+ this.pluginName = pluginName;
12
+ }
13
+ /**
14
+ * 调用 `pluginName.method`。只给原生适配器使用。
15
+ *
16
+ * @param method - 插件内的方法名,例如 `getPhoto`
17
+ * @param params - 原样交给 {@link bridge}
18
+ * @returns 客户端响应的 `data`
19
+ */
20
+ callNative(method, params) {
21
+ return bridge.call(`${this.pluginName}.${method}`, params);
22
+ }
23
+ /**
24
+ * 当前环境没有这个能力。在进入 bridge 之前抛出。
25
+ *
26
+ * @param method - 插件内的方法名
27
+ * @throws {@link TusiError} {@link ErrorCode.Unsupported}
28
+ */
29
+ unsupported(method) {
30
+ throw new TusiError(
31
+ ErrorCode.Unsupported,
32
+ `${this.pluginName}.${method} is not supported`,
33
+ `${this.pluginName}.${method}`
34
+ );
35
+ }
36
+ };
37
+
38
+ export { BaseAdapter };
@@ -0,0 +1,152 @@
1
+ 'use strict';
2
+
3
+ var core = require('@tusi-ai/core');
4
+
5
+ var __async = (__this, __arguments, generator) => {
6
+ return new Promise((resolve, reject) => {
7
+ var fulfilled = (value) => {
8
+ try {
9
+ step(generator.next(value));
10
+ } catch (e) {
11
+ reject(e);
12
+ }
13
+ };
14
+ var rejected = (value) => {
15
+ try {
16
+ step(generator.throw(value));
17
+ } catch (e) {
18
+ reject(e);
19
+ }
20
+ };
21
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
22
+ step((generator = generator.apply(__this, __arguments)).next());
23
+ });
24
+ };
25
+ var BaseAdapter = class {
26
+ /**
27
+ * 绑定插件名,后续原生调用会拼成 `pluginName.method`。
28
+ *
29
+ * @param pluginName - JSB 插件名,例如 `Camera`
30
+ */
31
+ constructor(pluginName) {
32
+ this.pluginName = pluginName;
33
+ }
34
+ /**
35
+ * 调用 `pluginName.method`。只给原生适配器使用。
36
+ *
37
+ * @param method - 插件内的方法名,例如 `getPhoto`
38
+ * @param params - 原样交给 {@link bridge}
39
+ * @returns 客户端响应的 `data`
40
+ */
41
+ callNative(method, params) {
42
+ return core.bridge.call(`${this.pluginName}.${method}`, params);
43
+ }
44
+ /**
45
+ * 当前环境没有这个能力。在进入 bridge 之前抛出。
46
+ *
47
+ * @param method - 插件内的方法名
48
+ * @throws {@link TusiError} {@link ErrorCode.Unsupported}
49
+ */
50
+ unsupported(method) {
51
+ throw new core.TusiError(
52
+ core.ErrorCode.Unsupported,
53
+ `${this.pluginName}.${method} is not supported`,
54
+ `${this.pluginName}.${method}`
55
+ );
56
+ }
57
+ };
58
+
59
+ // src/local-notifications/adapter.ts
60
+ var LocalNotificationsAdapter = class extends BaseAdapter {
61
+ constructor() {
62
+ super("LocalNotifications");
63
+ }
64
+ };
65
+
66
+ // src/local-notifications/browser.ts
67
+ var BrowserLocalNotificationsAdapter = class extends LocalNotificationsAdapter {
68
+ schedule(_request) {
69
+ this.unsupported("schedule");
70
+ }
71
+ cancel(_reminderIds) {
72
+ this.unsupported("cancel");
73
+ }
74
+ getPending() {
75
+ this.unsupported("getPending");
76
+ }
77
+ };
78
+
79
+ // src/local-notifications/native.ts
80
+ var NativeLocalNotificationsAdapter = class extends LocalNotificationsAdapter {
81
+ schedule(request) {
82
+ return this.callNative("schedule", request);
83
+ }
84
+ cancel(reminderIds) {
85
+ return this.callNative("cancel", reminderIds);
86
+ }
87
+ getPending() {
88
+ return this.callNative("getPending");
89
+ }
90
+ };
91
+
92
+ // src/local-notifications/index.ts
93
+ var adapter;
94
+ function getAdapter() {
95
+ adapter != null ? adapter : adapter = core.getRuntimeEnv() === core.RuntimeEnv.Browser ? new BrowserLocalNotificationsAdapter() : new NativeLocalNotificationsAdapter();
96
+ return adapter;
97
+ }
98
+ function invalid(method, message) {
99
+ throw new core.TusiError(core.ErrorCode.InvalidParams, message, method);
100
+ }
101
+ function assertRequest(request) {
102
+ var _a, _b;
103
+ if (!(request == null ? void 0 : request.reminderId) || !request.title || request.triggerAt === void 0) {
104
+ invalid("LocalNotifications.schedule", "reminderId, title and triggerAt are required");
105
+ }
106
+ if (((_a = request.repeat) == null ? void 0 : _a.type) === "weekly" && !((_b = request.repeat.weekdays) == null ? void 0 : _b.length)) {
107
+ invalid("LocalNotifications.schedule", "weekly repeat requires weekdays");
108
+ }
109
+ }
110
+ var LocalNotifications = {
111
+ /**
112
+ * 调度一条提醒。相同 `reminderId` 覆盖旧提醒。
113
+ *
114
+ * @param request - 标题、时间和重复规则
115
+ * @returns 调度结果
116
+ * @throws {@link TusiError}
117
+ * {@link ErrorCode.InvalidParams} 参数不合法,{@link ErrorCode.Unsupported} 浏览器不能做系统调度
118
+ */
119
+ schedule(request) {
120
+ return __async(this, null, function* () {
121
+ assertRequest(request);
122
+ return getAdapter().schedule(request);
123
+ });
124
+ },
125
+ /**
126
+ * 撤销尚未触发的提醒。
127
+ *
128
+ * @param reminderIds - 要撤销的 ID,直接传数组
129
+ * @returns 撤销结果
130
+ * @throws {@link TusiError} {@link ErrorCode.InvalidParams} 参数不是字符串数组
131
+ */
132
+ cancel(reminderIds) {
133
+ return __async(this, null, function* () {
134
+ if (!Array.isArray(reminderIds) || reminderIds.some((id) => typeof id !== "string" || !id)) {
135
+ invalid("LocalNotifications.cancel", "reminderIds must be a string array");
136
+ }
137
+ return getAdapter().cancel(reminderIds);
138
+ });
139
+ },
140
+ /**
141
+ * 列出尚未触发的提醒。
142
+ *
143
+ * @returns 待触发列表。成功时直接是数组
144
+ */
145
+ getPending() {
146
+ return __async(this, null, function* () {
147
+ return getAdapter().getPending();
148
+ });
149
+ }
150
+ };
151
+
152
+ exports.LocalNotifications = LocalNotifications;
@@ -0,0 +1,84 @@
1
+ /** 重复规则。不传时只触发一次。 */
2
+ interface NotificationRepeat {
3
+ /** 一次、每天或每周。 */
4
+ type: 'once' | 'daily' | 'weekly';
5
+ /** 每周重复的星期。1 是周一,7 是周日。`weekly` 时必填。 */
6
+ weekdays?: number[];
7
+ }
8
+ /** {@link LocalNotifications.schedule} 的入参。 */
9
+ interface LocalNotificationRequest {
10
+ /** 业务稳定 ID。相同 ID 再次调度会覆盖原提醒。 */
11
+ reminderId: string;
12
+ /** 通知标题。 */
13
+ title: string;
14
+ /** 通知正文。 */
15
+ body?: string;
16
+ /** 触发时间,Unix 毫秒。 */
17
+ triggerAt: number;
18
+ /** 重复规则。 */
19
+ repeat?: NotificationRepeat;
20
+ }
21
+ /** 调度结果。 */
22
+ interface ScheduleResult {
23
+ /** 端上的结果码。成功为 0。 */
24
+ code: number;
25
+ /** 已调度的 ID。 */
26
+ reminderId?: string;
27
+ /** 失败原因。 */
28
+ errMsg?: string;
29
+ }
30
+ /** {@link LocalNotifications.cancel} 的结果。 */
31
+ interface CancelResult {
32
+ /** 端上的结果码。成功为 0。 */
33
+ code: number;
34
+ /** 实际撤销的 ID。 */
35
+ cancelledIds?: string[];
36
+ /** 撤销数量。 */
37
+ canceledCount?: number;
38
+ /** 失败原因。 */
39
+ errMsg?: string;
40
+ }
41
+ /** 一条尚未触发的提醒。 */
42
+ interface PendingNotification {
43
+ /** 业务 ID。 */
44
+ reminderId: string;
45
+ /** 通知标题。 */
46
+ title: string;
47
+ /** 通知正文。 */
48
+ body?: string;
49
+ /** 触发时间,Unix 毫秒。 */
50
+ triggerAt: number;
51
+ /** 重复规则。 */
52
+ repeat?: NotificationRepeat;
53
+ }
54
+
55
+ /**
56
+ * 本地通知插件。提醒由系统调度,页面关闭后仍然触发。
57
+ */
58
+ declare const LocalNotifications: {
59
+ /**
60
+ * 调度一条提醒。相同 `reminderId` 覆盖旧提醒。
61
+ *
62
+ * @param request - 标题、时间和重复规则
63
+ * @returns 调度结果
64
+ * @throws {@link TusiError}
65
+ * {@link ErrorCode.InvalidParams} 参数不合法,{@link ErrorCode.Unsupported} 浏览器不能做系统调度
66
+ */
67
+ schedule(request: LocalNotificationRequest): Promise<ScheduleResult>;
68
+ /**
69
+ * 撤销尚未触发的提醒。
70
+ *
71
+ * @param reminderIds - 要撤销的 ID,直接传数组
72
+ * @returns 撤销结果
73
+ * @throws {@link TusiError} {@link ErrorCode.InvalidParams} 参数不是字符串数组
74
+ */
75
+ cancel(reminderIds: string[]): Promise<CancelResult>;
76
+ /**
77
+ * 列出尚未触发的提醒。
78
+ *
79
+ * @returns 待触发列表。成功时直接是数组
80
+ */
81
+ getPending(): Promise<PendingNotification[]>;
82
+ };
83
+
84
+ export { type CancelResult, type LocalNotificationRequest, LocalNotifications, type NotificationRepeat, type PendingNotification, type ScheduleResult };