@reset-framework/sdk 1.2.2 → 1.2.4
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/LICENSE +20 -20
- package/README.md +41 -41
- package/package.json +1 -1
- package/src/client.js +932 -932
- package/src/errors.js +33 -33
- package/src/events.js +123 -123
- package/src/index.d.ts +664 -664
- package/src/index.js +40 -40
- package/src/transport.js +180 -180
package/src/index.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
export {
|
|
2
|
-
app,
|
|
3
|
-
backend,
|
|
4
|
-
clipboard,
|
|
5
|
-
commands,
|
|
6
|
-
createResetClient,
|
|
7
|
-
createResetTransport,
|
|
8
|
-
crypto,
|
|
9
|
-
dialog,
|
|
10
|
-
events,
|
|
11
|
-
fs,
|
|
12
|
-
getResetRuntime,
|
|
13
|
-
invoke,
|
|
14
|
-
invokeRaw,
|
|
15
|
-
isResetRuntimeAvailable,
|
|
16
|
-
menu,
|
|
17
|
-
net,
|
|
18
|
-
notification,
|
|
19
|
-
path,
|
|
20
|
-
power,
|
|
21
|
-
process,
|
|
22
|
-
protocol,
|
|
23
|
-
reset,
|
|
24
|
-
screen,
|
|
25
|
-
shell,
|
|
26
|
-
shortcut,
|
|
27
|
-
storage,
|
|
28
|
-
runtime,
|
|
29
|
-
tray,
|
|
30
|
-
updater,
|
|
31
|
-
webview,
|
|
32
|
-
window
|
|
33
|
-
} from "./client.js"
|
|
34
|
-
|
|
35
|
-
export {
|
|
36
|
-
ResetInvocationError,
|
|
37
|
-
ResetProtocolError,
|
|
38
|
-
ResetRuntimeError,
|
|
39
|
-
ResetRuntimeUnavailableError
|
|
40
|
-
} from "./errors.js"
|
|
1
|
+
export {
|
|
2
|
+
app,
|
|
3
|
+
backend,
|
|
4
|
+
clipboard,
|
|
5
|
+
commands,
|
|
6
|
+
createResetClient,
|
|
7
|
+
createResetTransport,
|
|
8
|
+
crypto,
|
|
9
|
+
dialog,
|
|
10
|
+
events,
|
|
11
|
+
fs,
|
|
12
|
+
getResetRuntime,
|
|
13
|
+
invoke,
|
|
14
|
+
invokeRaw,
|
|
15
|
+
isResetRuntimeAvailable,
|
|
16
|
+
menu,
|
|
17
|
+
net,
|
|
18
|
+
notification,
|
|
19
|
+
path,
|
|
20
|
+
power,
|
|
21
|
+
process,
|
|
22
|
+
protocol,
|
|
23
|
+
reset,
|
|
24
|
+
screen,
|
|
25
|
+
shell,
|
|
26
|
+
shortcut,
|
|
27
|
+
storage,
|
|
28
|
+
runtime,
|
|
29
|
+
tray,
|
|
30
|
+
updater,
|
|
31
|
+
webview,
|
|
32
|
+
window
|
|
33
|
+
} from "./client.js"
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
ResetInvocationError,
|
|
37
|
+
ResetProtocolError,
|
|
38
|
+
ResetRuntimeError,
|
|
39
|
+
ResetRuntimeUnavailableError
|
|
40
|
+
} from "./errors.js"
|
package/src/transport.js
CHANGED
|
@@ -1,180 +1,180 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ResetInvocationError,
|
|
3
|
-
ResetProtocolError,
|
|
4
|
-
ResetRuntimeUnavailableError
|
|
5
|
-
} from "./errors.js"
|
|
6
|
-
|
|
7
|
-
function getDefaultWindowTarget() {
|
|
8
|
-
if (typeof window === "undefined") {
|
|
9
|
-
return undefined
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return window
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function hasOwn(object, key) {
|
|
16
|
-
return Object.prototype.hasOwnProperty.call(object, key)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function isObjectLike(value) {
|
|
20
|
-
return typeof value === "object" && value !== null
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function isRuntimeLike(value) {
|
|
24
|
-
return isObjectLike(value) && typeof value.invoke === "function"
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function createTargetRuntimeResolver(target) {
|
|
28
|
-
return () => {
|
|
29
|
-
if (!isObjectLike(target) || !isRuntimeLike(target.reset)) {
|
|
30
|
-
return undefined
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return target.reset
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function normalizeRuntimeResolver(source) {
|
|
38
|
-
if (source === undefined) {
|
|
39
|
-
return () => {
|
|
40
|
-
const target = getDefaultWindowTarget()
|
|
41
|
-
return isObjectLike(target) && isRuntimeLike(target.reset) ? target.reset : undefined
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (typeof source === "function") {
|
|
46
|
-
return () => {
|
|
47
|
-
const runtime = source()
|
|
48
|
-
return isRuntimeLike(runtime) ? runtime : undefined
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (isRuntimeLike(source)) {
|
|
53
|
-
return () => source
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (isObjectLike(source) && (hasOwn(source, "runtime") || hasOwn(source, "resolveRuntime") || hasOwn(source, "target"))) {
|
|
57
|
-
if (typeof source.resolveRuntime === "function") {
|
|
58
|
-
return () => {
|
|
59
|
-
const runtime = source.resolveRuntime()
|
|
60
|
-
return isRuntimeLike(runtime) ? runtime : undefined
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (isRuntimeLike(source.runtime)) {
|
|
65
|
-
return () => source.runtime
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return createTargetRuntimeResolver(source.target)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return createTargetRuntimeResolver(source)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function assertCommand(command) {
|
|
75
|
-
if (typeof command !== "string" || command.trim() === "") {
|
|
76
|
-
throw new TypeError("Reset command must be a non-empty string.")
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function normalizeResponse(command, response) {
|
|
81
|
-
if (!isObjectLike(response) || typeof response.ok !== "boolean") {
|
|
82
|
-
throw new ResetProtocolError(
|
|
83
|
-
`Reset runtime returned an invalid response envelope for '${command}'.`,
|
|
84
|
-
{ command }
|
|
85
|
-
)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (response.ok === false) {
|
|
89
|
-
if (typeof response.error === "string" && response.error.trim() !== "") {
|
|
90
|
-
return Object.freeze({
|
|
91
|
-
ok: false,
|
|
92
|
-
error: response.error,
|
|
93
|
-
code: undefined,
|
|
94
|
-
details: undefined
|
|
95
|
-
})
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!isObjectLike(response.error)) {
|
|
99
|
-
throw new ResetProtocolError(
|
|
100
|
-
`Reset runtime returned an invalid error response for '${command}'.`,
|
|
101
|
-
{ command }
|
|
102
|
-
)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (typeof response.error.message !== "string" || response.error.message.trim() === "") {
|
|
106
|
-
throw new ResetProtocolError(
|
|
107
|
-
`Reset runtime returned an invalid error response for '${command}'.`,
|
|
108
|
-
{ command }
|
|
109
|
-
)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return Object.freeze({
|
|
113
|
-
ok: false,
|
|
114
|
-
error: response.error.message,
|
|
115
|
-
code: typeof response.error.code === "string" ? response.error.code : undefined,
|
|
116
|
-
details: response.error.details
|
|
117
|
-
})
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return Object.freeze({
|
|
121
|
-
ok: true,
|
|
122
|
-
result: response.result
|
|
123
|
-
})
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function resolveRuntimeOrThrow(resolveRuntime) {
|
|
127
|
-
const runtime = resolveRuntime()
|
|
128
|
-
|
|
129
|
-
if (!isRuntimeLike(runtime)) {
|
|
130
|
-
throw new ResetRuntimeUnavailableError()
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return runtime
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function isResetRuntimeAvailable(source) {
|
|
137
|
-
return isRuntimeLike(normalizeRuntimeResolver(source)())
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export function getResetRuntime(source) {
|
|
141
|
-
return resolveRuntimeOrThrow(normalizeRuntimeResolver(source))
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export async function invokeRaw(command, payload = {}, source) {
|
|
145
|
-
assertCommand(command)
|
|
146
|
-
|
|
147
|
-
const runtime = resolveRuntimeOrThrow(normalizeRuntimeResolver(source))
|
|
148
|
-
const response = await runtime.invoke(command, payload)
|
|
149
|
-
|
|
150
|
-
return normalizeResponse(command, response)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export async function invoke(command, payload = {}, source) {
|
|
154
|
-
const response = await invokeRaw(command, payload, source)
|
|
155
|
-
|
|
156
|
-
if (!response.ok) {
|
|
157
|
-
throw new ResetInvocationError(command, response.error, response)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return response.result
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export function createResetTransport(source) {
|
|
164
|
-
const resolveRuntime = normalizeRuntimeResolver(source)
|
|
165
|
-
|
|
166
|
-
return Object.freeze({
|
|
167
|
-
isAvailable() {
|
|
168
|
-
return isRuntimeLike(resolveRuntime())
|
|
169
|
-
},
|
|
170
|
-
getRuntime() {
|
|
171
|
-
return resolveRuntimeOrThrow(resolveRuntime)
|
|
172
|
-
},
|
|
173
|
-
invokeRaw(command, payload = {}) {
|
|
174
|
-
return invokeRaw(command, payload, resolveRuntime)
|
|
175
|
-
},
|
|
176
|
-
invoke(command, payload = {}) {
|
|
177
|
-
return invoke(command, payload, resolveRuntime)
|
|
178
|
-
}
|
|
179
|
-
})
|
|
180
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
ResetInvocationError,
|
|
3
|
+
ResetProtocolError,
|
|
4
|
+
ResetRuntimeUnavailableError
|
|
5
|
+
} from "./errors.js"
|
|
6
|
+
|
|
7
|
+
function getDefaultWindowTarget() {
|
|
8
|
+
if (typeof window === "undefined") {
|
|
9
|
+
return undefined
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return window
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function hasOwn(object, key) {
|
|
16
|
+
return Object.prototype.hasOwnProperty.call(object, key)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isObjectLike(value) {
|
|
20
|
+
return typeof value === "object" && value !== null
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isRuntimeLike(value) {
|
|
24
|
+
return isObjectLike(value) && typeof value.invoke === "function"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function createTargetRuntimeResolver(target) {
|
|
28
|
+
return () => {
|
|
29
|
+
if (!isObjectLike(target) || !isRuntimeLike(target.reset)) {
|
|
30
|
+
return undefined
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return target.reset
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function normalizeRuntimeResolver(source) {
|
|
38
|
+
if (source === undefined) {
|
|
39
|
+
return () => {
|
|
40
|
+
const target = getDefaultWindowTarget()
|
|
41
|
+
return isObjectLike(target) && isRuntimeLike(target.reset) ? target.reset : undefined
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (typeof source === "function") {
|
|
46
|
+
return () => {
|
|
47
|
+
const runtime = source()
|
|
48
|
+
return isRuntimeLike(runtime) ? runtime : undefined
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (isRuntimeLike(source)) {
|
|
53
|
+
return () => source
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (isObjectLike(source) && (hasOwn(source, "runtime") || hasOwn(source, "resolveRuntime") || hasOwn(source, "target"))) {
|
|
57
|
+
if (typeof source.resolveRuntime === "function") {
|
|
58
|
+
return () => {
|
|
59
|
+
const runtime = source.resolveRuntime()
|
|
60
|
+
return isRuntimeLike(runtime) ? runtime : undefined
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (isRuntimeLike(source.runtime)) {
|
|
65
|
+
return () => source.runtime
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return createTargetRuntimeResolver(source.target)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return createTargetRuntimeResolver(source)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function assertCommand(command) {
|
|
75
|
+
if (typeof command !== "string" || command.trim() === "") {
|
|
76
|
+
throw new TypeError("Reset command must be a non-empty string.")
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function normalizeResponse(command, response) {
|
|
81
|
+
if (!isObjectLike(response) || typeof response.ok !== "boolean") {
|
|
82
|
+
throw new ResetProtocolError(
|
|
83
|
+
`Reset runtime returned an invalid response envelope for '${command}'.`,
|
|
84
|
+
{ command }
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (response.ok === false) {
|
|
89
|
+
if (typeof response.error === "string" && response.error.trim() !== "") {
|
|
90
|
+
return Object.freeze({
|
|
91
|
+
ok: false,
|
|
92
|
+
error: response.error,
|
|
93
|
+
code: undefined,
|
|
94
|
+
details: undefined
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!isObjectLike(response.error)) {
|
|
99
|
+
throw new ResetProtocolError(
|
|
100
|
+
`Reset runtime returned an invalid error response for '${command}'.`,
|
|
101
|
+
{ command }
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (typeof response.error.message !== "string" || response.error.message.trim() === "") {
|
|
106
|
+
throw new ResetProtocolError(
|
|
107
|
+
`Reset runtime returned an invalid error response for '${command}'.`,
|
|
108
|
+
{ command }
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return Object.freeze({
|
|
113
|
+
ok: false,
|
|
114
|
+
error: response.error.message,
|
|
115
|
+
code: typeof response.error.code === "string" ? response.error.code : undefined,
|
|
116
|
+
details: response.error.details
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return Object.freeze({
|
|
121
|
+
ok: true,
|
|
122
|
+
result: response.result
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function resolveRuntimeOrThrow(resolveRuntime) {
|
|
127
|
+
const runtime = resolveRuntime()
|
|
128
|
+
|
|
129
|
+
if (!isRuntimeLike(runtime)) {
|
|
130
|
+
throw new ResetRuntimeUnavailableError()
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return runtime
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function isResetRuntimeAvailable(source) {
|
|
137
|
+
return isRuntimeLike(normalizeRuntimeResolver(source)())
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function getResetRuntime(source) {
|
|
141
|
+
return resolveRuntimeOrThrow(normalizeRuntimeResolver(source))
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export async function invokeRaw(command, payload = {}, source) {
|
|
145
|
+
assertCommand(command)
|
|
146
|
+
|
|
147
|
+
const runtime = resolveRuntimeOrThrow(normalizeRuntimeResolver(source))
|
|
148
|
+
const response = await runtime.invoke(command, payload)
|
|
149
|
+
|
|
150
|
+
return normalizeResponse(command, response)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export async function invoke(command, payload = {}, source) {
|
|
154
|
+
const response = await invokeRaw(command, payload, source)
|
|
155
|
+
|
|
156
|
+
if (!response.ok) {
|
|
157
|
+
throw new ResetInvocationError(command, response.error, response)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return response.result
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function createResetTransport(source) {
|
|
164
|
+
const resolveRuntime = normalizeRuntimeResolver(source)
|
|
165
|
+
|
|
166
|
+
return Object.freeze({
|
|
167
|
+
isAvailable() {
|
|
168
|
+
return isRuntimeLike(resolveRuntime())
|
|
169
|
+
},
|
|
170
|
+
getRuntime() {
|
|
171
|
+
return resolveRuntimeOrThrow(resolveRuntime)
|
|
172
|
+
},
|
|
173
|
+
invokeRaw(command, payload = {}) {
|
|
174
|
+
return invokeRaw(command, payload, resolveRuntime)
|
|
175
|
+
},
|
|
176
|
+
invoke(command, payload = {}) {
|
|
177
|
+
return invoke(command, payload, resolveRuntime)
|
|
178
|
+
}
|
|
179
|
+
})
|
|
180
|
+
}
|