@reset-framework/sdk 1.2.1 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reset-framework/sdk",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "type": "module",
5
5
  "description": "Browser-side SDK for Reset Framework applications.",
6
6
  "license": "MIT",
package/src/client.js CHANGED
@@ -193,6 +193,32 @@ function normalizeProtocolInfo(payload, command) {
193
193
  })
194
194
  }
195
195
 
196
+ function normalizeBackendInfo(payload, command) {
197
+ const record = requireObject(payload, command)
198
+ const runtime = isObjectLike(record.runtime) ? record.runtime : {}
199
+
200
+ return Object.freeze({
201
+ supported: requireBooleanField(record, "supported", command),
202
+ configured: requireBooleanField(record, "configured", command),
203
+ running: requireBooleanField(record, "running", command),
204
+ available: requireBooleanField(record, "available", command),
205
+ protocol: requireStringField(record, "protocol", command),
206
+ pid: typeof record.pid === "number" ? record.pid : null,
207
+ entryPath: optionalStringField(record, "entryPath", "", command),
208
+ runnerPath: optionalStringField(record, "runnerPath", "", command),
209
+ executablePath: optionalStringField(record, "executablePath", "", command),
210
+ workingDirectory: optionalStringField(record, "workingDirectory", "", command),
211
+ methods: normalizeStringArray(record.methods ?? [], "methods", command),
212
+ runtime: Object.freeze({
213
+ name: optionalStringField(runtime, "name", "", command),
214
+ version: optionalStringField(runtime, "version", "", command),
215
+ platform: optionalStringField(runtime, "platform", "", command),
216
+ arch: optionalStringField(runtime, "arch", "", command)
217
+ }),
218
+ lastError: optionalStringField(record, "lastError", "", command)
219
+ })
220
+ }
221
+
196
222
  function createCommandApi(transport) {
197
223
  return Object.freeze({
198
224
  invoke(command, payload = {}) {
@@ -717,6 +743,63 @@ function createNetApi(transport) {
717
743
  })
718
744
  }
719
745
 
746
+ function createBackendApi(transport, events) {
747
+ const normalizeEventName = (eventName) => {
748
+ if (typeof eventName !== "string" || eventName.trim() === "") {
749
+ throw new TypeError("Reset backend event name must be a non-empty string.")
750
+ }
751
+
752
+ return eventName.startsWith("backend.") ? eventName : `backend.${eventName}`
753
+ }
754
+
755
+ const invokeBackend = (method, params = {}) =>
756
+ transport.invoke("backend.invoke", {
757
+ method,
758
+ params
759
+ })
760
+
761
+ const processApi = Object.freeze({
762
+ spawn(options) {
763
+ return invokeBackend("process.spawn", options)
764
+ },
765
+ run(options) {
766
+ return invokeBackend("process.run", options)
767
+ },
768
+ write(processId, data) {
769
+ return invokeBackend("process.write", { processId, data })
770
+ },
771
+ kill(processId, options = {}) {
772
+ return invokeBackend("process.kill", {
773
+ processId,
774
+ ...options
775
+ })
776
+ },
777
+ list() {
778
+ return invokeBackend("process.list", {})
779
+ }
780
+ })
781
+
782
+ return Object.freeze({
783
+ async getInfo() {
784
+ return normalizeBackendInfo(await transport.invoke("backend.getInfo"), "backend.getInfo")
785
+ },
786
+ async isAvailable() {
787
+ const info = await transport.invoke("backend.getInfo")
788
+ return normalizeBackendInfo(info, "backend.getInfo").available
789
+ },
790
+ invoke(method, params = {}) {
791
+ return invokeBackend(method, params)
792
+ },
793
+ listen(eventName, handler) {
794
+ return events.listen(normalizeEventName(eventName), handler)
795
+ },
796
+ once(eventName, handler) {
797
+ return events.once(normalizeEventName(eventName), handler)
798
+ },
799
+ process: processApi
800
+ })
801
+ }
802
+
720
803
  function scheduleFrontendReadySignal(transport) {
721
804
  const target = typeof globalThis === "object" ? globalThis.window : undefined
722
805
 
@@ -775,6 +858,7 @@ export function createResetClient(source) {
775
858
  const protocol = createProtocolApi(transport, events)
776
859
  const updater = createUpdaterApi(transport)
777
860
  const net = createNetApi(transport)
861
+ const backend = createBackendApi(transport, events)
778
862
  const client = Object.freeze({
779
863
  isAvailable() {
780
864
  return transport.isAvailable()
@@ -804,7 +888,8 @@ export function createResetClient(source) {
804
888
  shortcut,
805
889
  protocol,
806
890
  updater,
807
- net
891
+ net,
892
+ backend
808
893
  })
809
894
 
810
895
  scheduleFrontendReadySignal(transport)
@@ -844,3 +929,4 @@ export const shortcut = reset.shortcut
844
929
  export const protocol = reset.protocol
845
930
  export const updater = reset.updater
846
931
  export const net = reset.net
932
+ export const backend = reset.backend
package/src/index.d.ts CHANGED
@@ -319,6 +319,94 @@ export interface ResetProcessApi {
319
319
  getInfo(): Promise<ResetProcessInfo>;
320
320
  }
321
321
 
322
+ export interface ResetBackendRuntimeInfo {
323
+ name: string;
324
+ version: string;
325
+ platform: string;
326
+ arch: string;
327
+ }
328
+
329
+ export interface ResetBackendInfo {
330
+ supported: boolean;
331
+ configured: boolean;
332
+ running: boolean;
333
+ available: boolean;
334
+ protocol: string;
335
+ pid: number | null;
336
+ entryPath: string;
337
+ runnerPath: string;
338
+ executablePath: string;
339
+ workingDirectory: string;
340
+ methods: ReadonlyArray<string>;
341
+ runtime: ResetBackendRuntimeInfo;
342
+ lastError: string;
343
+ }
344
+
345
+ export interface ResetBackendProcessInfo {
346
+ id: string;
347
+ pid: number;
348
+ command: string;
349
+ args: string[];
350
+ cwd: string;
351
+ running: boolean;
352
+ startedAt: string;
353
+ }
354
+
355
+ export interface ResetBackendProcessRunOptions {
356
+ command: string;
357
+ args?: string[];
358
+ cwd?: string;
359
+ env?: Record<string, string>;
360
+ shell?: boolean;
361
+ input?: string;
362
+ timeoutMs?: number;
363
+ maxBufferBytes?: number;
364
+ }
365
+
366
+ export interface ResetBackendProcessRunResult {
367
+ command: string;
368
+ args: string[];
369
+ cwd: string;
370
+ exitCode: number | null;
371
+ signal: string | null;
372
+ stdout: string;
373
+ stderr: string;
374
+ timedOut: boolean;
375
+ failed: boolean;
376
+ }
377
+
378
+ export interface ResetBackendProcessApi {
379
+ spawn(options: {
380
+ command: string;
381
+ args?: string[];
382
+ cwd?: string;
383
+ env?: Record<string, string>;
384
+ shell?: boolean;
385
+ }): Promise<ResetBackendProcessInfo>;
386
+ run(options: ResetBackendProcessRunOptions): Promise<ResetBackendProcessRunResult>;
387
+ write(processId: string, data: string): Promise<{ written: boolean }>;
388
+ kill(
389
+ processId: string,
390
+ options?: { signal?: string }
391
+ ): Promise<{ killed: boolean }>;
392
+ list(): Promise<{ processes: ResetBackendProcessInfo[] }>;
393
+ }
394
+
395
+ export interface ResetBackendApi {
396
+ getInfo(): Promise<ResetBackendInfo>;
397
+ isAvailable(): Promise<boolean>;
398
+ invoke<TResult = unknown>(method: string, params?: unknown): Promise<TResult>;
399
+ listen<T = unknown>(
400
+ eventName: string,
401
+ handler: (payload: T) => void
402
+ ): () => void;
403
+ once<T = unknown>(
404
+ eventName: string,
405
+ handler: (payload: T) => void
406
+ ): () => void;
407
+ process: ResetBackendProcessApi;
408
+ }
409
+
322
410
  export interface ResetPowerInfo {
323
411
  supported: boolean;
324
412
  lowPowerMode: boolean;
@@ -473,6 +561,7 @@ export interface ResetClient {
473
561
  protocol: ResetProtocolApi;
474
562
  updater: ResetUpdaterApi;
475
563
  net: ResetNetApi;
564
+ backend: ResetBackendApi;
476
565
  }
477
566
 
478
567
  export interface ResetEventApi {
@@ -572,3 +661,4 @@ export const shortcut: ResetShortcutApi;
572
661
  export const protocol: ResetProtocolApi;
573
662
  export const updater: ResetUpdaterApi;
574
663
  export const net: ResetNetApi;
664
+ export const backend: ResetBackendApi;
package/src/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export {
2
2
  app,
3
+ backend,
3
4
  clipboard,
4
5
  commands,
5
6
  createResetClient,