@holochain/conductor-api
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -21,3 +21,3 @@ /// <reference types="node" /> | ||
app: InstalledAppInfo; | ||
errors: Array<[CellId, String]>; | ||
errors: Array<[CellId, string]>; | ||
}; | ||
@@ -31,3 +31,3 @@ export declare type DisableAppRequest = { | ||
}; | ||
export declare type StartAppResponse = Boolean; | ||
export declare type StartAppResponse = boolean; | ||
export declare type DumpStateRequest = { | ||
@@ -84,3 +84,3 @@ cell_id: CellId; | ||
} | { | ||
disabled: {}; | ||
disabled: Record<string, never>; | ||
}; | ||
@@ -87,0 +87,0 @@ export declare type HoloHashB64 = string; |
@@ -50,2 +50,2 @@ /// <reference types="node" /> | ||
export declare type MembraneProof = Buffer; | ||
export declare const fakeAgentPubKey: (x: any) => Buffer; | ||
export declare const fakeAgentPubKey: () => Buffer; |
@@ -1,4 +0,4 @@ | ||
export const fakeAgentPubKey = (x) => Buffer.from([0x84, 0x20, 0x24].concat("000000000000000000000000000000000000" | ||
export const fakeAgentPubKey = () => Buffer.from([0x84, 0x20, 0x24].concat("000000000000000000000000000000000000" | ||
.split("") | ||
.map((x) => parseInt(x, 10)))); | ||
//# sourceMappingURL=types.js.map |
@@ -33,4 +33,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
const isBrowser = typeof window !== "undefined"; | ||
const isJest = process && process.env && process.env.JEST_WORKER_ID !== undefined; | ||
let promise; | ||
if (isBrowser) { | ||
if (isBrowser && !isJest) { | ||
promise = fetchLauncherEnvironment().catch(console.error); | ||
@@ -37,0 +38,0 @@ } |
@@ -82,3 +82,3 @@ /** | ||
}, | ||
output: (res) => res | ||
output: (res) => res, | ||
}; | ||
@@ -89,3 +89,3 @@ const dumpStateTransform = { | ||
return JSON.parse(res); | ||
} | ||
}, | ||
}; | ||
@@ -96,19 +96,19 @@ function getAppStatusInApiForm(status_filter) { | ||
return { | ||
Running: null | ||
Running: null, | ||
}; | ||
case Api.AppStatusFilter.Enabled: | ||
return { | ||
Enabled: null | ||
Enabled: null, | ||
}; | ||
case Api.AppStatusFilter.Paused: | ||
return { | ||
Paused: null | ||
Paused: null, | ||
}; | ||
case Api.AppStatusFilter.Disabled: | ||
return { | ||
Disabled: null | ||
Disabled: null, | ||
}; | ||
case Api.AppStatusFilter.Stopped: | ||
return { | ||
Stopped: null | ||
Stopped: null, | ||
}; | ||
@@ -115,0 +115,0 @@ } |
@@ -59,3 +59,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return decode(res); | ||
} | ||
}, | ||
}; | ||
@@ -66,3 +66,3 @@ const appInfoTransform = (overrideInstalledAppId) => ({ | ||
return { | ||
installed_app_id: overrideInstalledAppId | ||
installed_app_id: overrideInstalledAppId, | ||
}; | ||
@@ -74,4 +74,4 @@ } | ||
return res; | ||
} | ||
}, | ||
}); | ||
//# sourceMappingURL=app.js.map |
@@ -1,3 +0,3 @@ | ||
/// <reference types="ws" /> | ||
import Websocket from "isomorphic-ws"; | ||
import { decode } from "@msgpack/msgpack"; | ||
import { AppSignalCb } from "../api/app"; | ||
@@ -13,4 +13,4 @@ /** | ||
pendingRequests: Record<number, { | ||
fulfill: Function; | ||
reject: Function; | ||
fulfill: (msg: unknown) => ReturnType<typeof decode>; | ||
reject: (error: Error) => void; | ||
}>; | ||
@@ -17,0 +17,0 @@ index: number; |
@@ -35,2 +35,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
const decodedMessage = decode(msg.data); | ||
if (!decodedMessage.App) { | ||
// We have received a system signal, do nothing | ||
return; | ||
} | ||
// Note: holochain currently returns signals as an array of two values: cellId and the serialized signal payload | ||
@@ -50,7 +54,7 @@ // and this array is nested within the App key within the returned message. | ||
if (!this.alreadyWarnedNoSignalCb) | ||
console.log(`Received signal but no signal callback was set in constructor`); | ||
console.log('Received signal but no signal callback was set in constructor'); | ||
this.alreadyWarnedNoSignalCb = true; | ||
} | ||
} | ||
else if (msg.type === "Response") { | ||
else if (msg.type === 'Response') { | ||
this.handleResponse(msg); | ||
@@ -65,3 +69,3 @@ } | ||
const encodedMsg = encode({ | ||
type: "Signal", | ||
type: 'Signal', | ||
data: encode(data), | ||
@@ -72,7 +76,7 @@ }); | ||
request(data) { | ||
let id = this.index; | ||
const id = this.index; | ||
this.index += 1; | ||
const encodedMsg = encode({ | ||
id, | ||
type: "Request", | ||
type: 'Request', | ||
data: encode(data), | ||
@@ -87,3 +91,3 @@ }); | ||
else { | ||
return Promise.reject(new Error(`Socket is not open`)); | ||
return Promise.reject(new Error('Socket is not open')); | ||
} | ||
@@ -97,3 +101,3 @@ return promise; | ||
if (msg.data === null || msg.data === undefined) { | ||
this.pendingRequests[id].reject(new Error(`Response canceled by responder`)); | ||
this.pendingRequests[id].reject(new Error('Response canceled by responder')); | ||
} | ||
@@ -113,3 +117,3 @@ else { | ||
awaitClose() { | ||
return new Promise((resolve) => this.socket.on("close", resolve)); | ||
return new Promise((resolve) => this.socket.on('close', resolve)); | ||
} | ||
@@ -122,3 +126,3 @@ static connect(url, signalCb) { | ||
// with uncaught exception | ||
socket.onerror = (e) => { | ||
socket.onerror = () => { | ||
reject(new Error(`could not connect to holochain conductor, please check that a conductor service is running and available at ${url}`)); | ||
@@ -125,0 +129,0 @@ }; |
@@ -10,3 +10,3 @@ const ERROR_TYPE = 'error'; | ||
let id; | ||
let timeout = new Promise((resolve, reject) => { | ||
const timeout = new Promise((_, reject) => { | ||
id = setTimeout(() => { | ||
@@ -13,0 +13,0 @@ clearTimeout(id); |
@@ -21,3 +21,3 @@ /// <reference types="node" /> | ||
app: InstalledAppInfo; | ||
errors: Array<[CellId, String]>; | ||
errors: Array<[CellId, string]>; | ||
}; | ||
@@ -31,3 +31,3 @@ export declare type DisableAppRequest = { | ||
}; | ||
export declare type StartAppResponse = Boolean; | ||
export declare type StartAppResponse = boolean; | ||
export declare type DumpStateRequest = { | ||
@@ -84,3 +84,3 @@ cell_id: CellId; | ||
} | { | ||
disabled: {}; | ||
disabled: Record<string, never>; | ||
}; | ||
@@ -87,0 +87,0 @@ export declare type HoloHashB64 = string; |
@@ -50,2 +50,2 @@ /// <reference types="node" /> | ||
export declare type MembraneProof = Buffer; | ||
export declare const fakeAgentPubKey: (x: any) => Buffer; | ||
export declare const fakeAgentPubKey: () => Buffer; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fakeAgentPubKey = void 0; | ||
exports.fakeAgentPubKey = (x) => Buffer.from([0x84, 0x20, 0x24].concat("000000000000000000000000000000000000" | ||
exports.fakeAgentPubKey = () => Buffer.from([0x84, 0x20, 0x24].concat("000000000000000000000000000000000000" | ||
.split("") | ||
.map((x) => parseInt(x, 10)))); | ||
//# sourceMappingURL=types.js.map |
@@ -39,4 +39,5 @@ "use strict"; | ||
const isBrowser = typeof window !== "undefined"; | ||
const isJest = process && process.env && process.env.JEST_WORKER_ID !== undefined; | ||
let promise; | ||
if (isBrowser) { | ||
if (isBrowser && !isJest) { | ||
promise = fetchLauncherEnvironment().catch(console.error); | ||
@@ -43,0 +44,0 @@ } |
@@ -105,3 +105,3 @@ "use strict"; | ||
}, | ||
output: (res) => res | ||
output: (res) => res, | ||
}; | ||
@@ -112,3 +112,3 @@ const dumpStateTransform = { | ||
return JSON.parse(res); | ||
} | ||
}, | ||
}; | ||
@@ -119,19 +119,19 @@ function getAppStatusInApiForm(status_filter) { | ||
return { | ||
Running: null | ||
Running: null, | ||
}; | ||
case Api.AppStatusFilter.Enabled: | ||
return { | ||
Enabled: null | ||
Enabled: null, | ||
}; | ||
case Api.AppStatusFilter.Paused: | ||
return { | ||
Paused: null | ||
Paused: null, | ||
}; | ||
case Api.AppStatusFilter.Disabled: | ||
return { | ||
Disabled: null | ||
Disabled: null, | ||
}; | ||
case Api.AppStatusFilter.Stopped: | ||
return { | ||
Stopped: null | ||
Stopped: null, | ||
}; | ||
@@ -138,0 +138,0 @@ } |
@@ -63,3 +63,3 @@ "use strict"; | ||
return msgpack_1.decode(res); | ||
} | ||
}, | ||
}; | ||
@@ -70,3 +70,3 @@ const appInfoTransform = (overrideInstalledAppId) => ({ | ||
return { | ||
installed_app_id: overrideInstalledAppId | ||
installed_app_id: overrideInstalledAppId, | ||
}; | ||
@@ -78,4 +78,4 @@ } | ||
return res; | ||
} | ||
}, | ||
}); | ||
//# sourceMappingURL=app.js.map |
@@ -1,3 +0,3 @@ | ||
/// <reference types="ws" /> | ||
import Websocket from "isomorphic-ws"; | ||
import { decode } from "@msgpack/msgpack"; | ||
import { AppSignalCb } from "../api/app"; | ||
@@ -13,4 +13,4 @@ /** | ||
pendingRequests: Record<number, { | ||
fulfill: Function; | ||
reject: Function; | ||
fulfill: (msg: unknown) => ReturnType<typeof decode>; | ||
reject: (error: Error) => void; | ||
}>; | ||
@@ -17,0 +17,0 @@ index: number; |
@@ -41,2 +41,6 @@ "use strict"; | ||
const decodedMessage = msgpack_1.decode(msg.data); | ||
if (!decodedMessage.App) { | ||
// We have received a system signal, do nothing | ||
return; | ||
} | ||
// Note: holochain currently returns signals as an array of two values: cellId and the serialized signal payload | ||
@@ -56,7 +60,7 @@ // and this array is nested within the App key within the returned message. | ||
if (!this.alreadyWarnedNoSignalCb) | ||
console.log(`Received signal but no signal callback was set in constructor`); | ||
console.log('Received signal but no signal callback was set in constructor'); | ||
this.alreadyWarnedNoSignalCb = true; | ||
} | ||
} | ||
else if (msg.type === "Response") { | ||
else if (msg.type === 'Response') { | ||
this.handleResponse(msg); | ||
@@ -71,3 +75,3 @@ } | ||
const encodedMsg = msgpack_1.encode({ | ||
type: "Signal", | ||
type: 'Signal', | ||
data: msgpack_1.encode(data), | ||
@@ -78,7 +82,7 @@ }); | ||
request(data) { | ||
let id = this.index; | ||
const id = this.index; | ||
this.index += 1; | ||
const encodedMsg = msgpack_1.encode({ | ||
id, | ||
type: "Request", | ||
type: 'Request', | ||
data: msgpack_1.encode(data), | ||
@@ -93,3 +97,3 @@ }); | ||
else { | ||
return Promise.reject(new Error(`Socket is not open`)); | ||
return Promise.reject(new Error('Socket is not open')); | ||
} | ||
@@ -103,3 +107,3 @@ return promise; | ||
if (msg.data === null || msg.data === undefined) { | ||
this.pendingRequests[id].reject(new Error(`Response canceled by responder`)); | ||
this.pendingRequests[id].reject(new Error('Response canceled by responder')); | ||
} | ||
@@ -119,3 +123,3 @@ else { | ||
awaitClose() { | ||
return new Promise((resolve) => this.socket.on("close", resolve)); | ||
return new Promise((resolve) => this.socket.on('close', resolve)); | ||
} | ||
@@ -128,3 +132,3 @@ static connect(url, signalCb) { | ||
// with uncaught exception | ||
socket.onerror = (e) => { | ||
socket.onerror = () => { | ||
reject(new Error(`could not connect to holochain conductor, please check that a conductor service is running and available at ${url}`)); | ||
@@ -131,0 +135,0 @@ }; |
@@ -13,3 +13,3 @@ "use strict"; | ||
let id; | ||
let timeout = new Promise((resolve, reject) => { | ||
const timeout = new Promise((_, reject) => { | ||
id = setTimeout(() => { | ||
@@ -16,0 +16,0 @@ clearTimeout(id); |
{ | ||
"name": "@holochain/conductor-api", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Encode/decode messages to/from the Holochain Conductor API over Websocket", | ||
@@ -25,3 +25,4 @@ "repository": { | ||
"test:raw": "RUST_LOG=error RUST_BACKTRACE=1 ts-node test", | ||
"example": "ts-node examples/zome-call" | ||
"example": "ts-node examples/zome-call", | ||
"lint": "eslint src/** test/** --fix" | ||
}, | ||
@@ -31,3 +32,2 @@ "author": "", | ||
"@msgpack/msgpack": "2.4.0", | ||
"@types/ws": "^7.2.4", | ||
"cross-fetch": "^3.1.4", | ||
@@ -39,7 +39,11 @@ "isomorphic-ws": "^4.0.1", | ||
"devDependencies": { | ||
"@types/node": "^14.0", | ||
"@detools/tap-diff": "^0.2.2", | ||
"@types/node": "^14.17.32", | ||
"@types/tape": "^4.13.0", | ||
"@types/ws": "^7.2.4", | ||
"@typescript-eslint/eslint-plugin": "^4.29.0", | ||
"@typescript-eslint/parser": "^4.29.0", | ||
"eslint": "^7.32.0", | ||
"js-yaml": "^3.14.0", | ||
"rimraf": "^3.0.2", | ||
"@detools/tap-diff": "^0.2.2", | ||
"tape": "^5.0", | ||
@@ -46,0 +50,0 @@ "ts-node": "^8.10.2", |
@@ -1,2 +0,2 @@ | ||
import { Requester } from "./common"; | ||
import { Requester } from "./common" | ||
import { | ||
@@ -11,4 +11,4 @@ HoloHash, | ||
InstalledAppInfo, | ||
SlotId, | ||
} from "./types"; | ||
SlotId | ||
} from "./types" | ||
@@ -31,3 +31,3 @@ export type AttachAppInterfaceRequest = { port: number }; | ||
app: InstalledAppInfo; | ||
errors: Array<[CellId, String]>; | ||
errors: Array<[CellId, string]>; | ||
}; | ||
@@ -39,3 +39,3 @@ | ||
export type StartAppRequest = { installed_app_id: InstalledAppId }; | ||
export type StartAppResponse = Boolean; | ||
export type StartAppResponse = boolean; | ||
@@ -90,25 +90,25 @@ export type DumpStateRequest = { cell_id: CellId }; | ||
| { | ||
/// Always create a new Cell when installing this App | ||
create: { deferred: boolean }; | ||
} | ||
/// Always create a new Cell when installing this App | ||
create: { deferred: boolean }; | ||
} | ||
| { | ||
/// Always create a new Cell when installing the App, | ||
/// and use a unique UID to ensure a distinct DHT network | ||
create_clone: { deferred: boolean }; | ||
} | ||
/// Always create a new Cell when installing the App, | ||
/// and use a unique UID to ensure a distinct DHT network | ||
create_clone: { deferred: boolean }; | ||
} | ||
| { | ||
/// Require that a Cell is already installed which matches the DNA version | ||
/// spec, and which has an Agent that's associated with this App's agent | ||
/// via DPKI. If no such Cell exists, *app installation fails*. | ||
use_existing: { deferred: boolean }; | ||
} | ||
/// Require that a Cell is already installed which matches the DNA version | ||
/// spec, and which has an Agent that's associated with this App's agent | ||
/// via DPKI. If no such Cell exists, *app installation fails*. | ||
use_existing: { deferred: boolean }; | ||
} | ||
| { | ||
/// Try `UseExisting`, and if that fails, fallback to `Create` | ||
create_if_no_exists: { deferred: boolean }; | ||
} | ||
/// Try `UseExisting`, and if that fails, fallback to `Create` | ||
create_if_no_exists: { deferred: boolean }; | ||
} | ||
| { | ||
/// Disallow provisioning altogether. In this case, we expect | ||
/// `clone_limit > 0`: otherwise, no Cells will ever be created. | ||
disabled: {}; | ||
}; | ||
/// Disallow provisioning altogether. In this case, we expect | ||
/// `clone_limit > 0`: otherwise, no Cells will ever be created. | ||
disabled: Record<string, never>; | ||
}; | ||
@@ -119,7 +119,7 @@ export type HoloHashB64 = string; | ||
| { | ||
singleton: HoloHashB64; | ||
} | ||
singleton: HoloHashB64; | ||
} | ||
| { | ||
multiple: DnaVersionSpec; | ||
}; | ||
multiple: DnaVersionSpec; | ||
}; | ||
export type AppSlotDnaManifest = { | ||
@@ -261,13 +261,13 @@ location?: Location; | ||
| { | ||
/// Expect file to be part of this bundle | ||
bundled: string; | ||
} | ||
/// Expect file to be part of this bundle | ||
bundled: string; | ||
} | ||
| { | ||
/// Get file from local filesystem (not bundled) | ||
path: string; | ||
} | ||
/// Get file from local filesystem (not bundled) | ||
path: string; | ||
} | ||
| { | ||
/// Get file from URL | ||
url: string; | ||
}; | ||
/// Get file from URL | ||
url: string; | ||
}; | ||
@@ -305,10 +305,10 @@ export type ZomeManifest = { | ||
| { | ||
hash: HoloHash; | ||
} | ||
hash: HoloHash; | ||
} | ||
| { | ||
path: string; | ||
} | ||
path: string; | ||
} | ||
| { | ||
bundle: DnaBundle; | ||
}; | ||
bundle: DnaBundle; | ||
}; | ||
@@ -315,0 +315,0 @@ export interface HoloHashed<T> { |
@@ -13,9 +13,9 @@ | ||
) => ( | ||
async (req: ReqO, timeout?: number) => { | ||
const input = { type: tag, data: transform.input(req) } | ||
const response = await requester(input, timeout) | ||
const output = transform.output(response.data) | ||
return output | ||
} | ||
) | ||
async (req: ReqO, timeout?: number) => { | ||
const input = { type: tag, data: transform.input(req) } | ||
const response = await requester(input, timeout) | ||
const output = transform.output(response.data) | ||
return output | ||
} | ||
) | ||
@@ -22,0 +22,0 @@ export type Transformer<ReqO, ReqI, ResI, ResO> = { |
@@ -25,4 +25,4 @@ export type HoloHash = Buffer; // length 39 | ||
| { | ||
never_started: null; | ||
} | ||
never_started: null; | ||
} | ||
| { user: null } | ||
@@ -33,12 +33,12 @@ | { error: string }; | ||
| { | ||
paused: { reason: PausedAppReason }; | ||
} | ||
paused: { reason: PausedAppReason }; | ||
} | ||
| { | ||
disabled: { | ||
reason: DisabledAppReason; | ||
}; | ||
} | ||
disabled: { | ||
reason: DisabledAppReason; | ||
}; | ||
} | ||
| { | ||
running: null; | ||
}; | ||
running: null; | ||
}; | ||
@@ -52,3 +52,3 @@ export type InstalledAppInfo = { | ||
export const fakeAgentPubKey = (x: any) => | ||
export const fakeAgentPubKey = () => | ||
Buffer.from( | ||
@@ -60,2 +60,2 @@ [0x84, 0x20, 0x24].concat( | ||
) | ||
); | ||
) |
@@ -1,6 +0,6 @@ | ||
import { InstalledAppId } from "../api/types"; | ||
import fetch from "cross-fetch"; | ||
import { InstalledAppId } from "../api/types" | ||
import fetch from "cross-fetch" | ||
// This is coupled with https://github.com/holochain/launcher/blob/develop/src-tauri/src/uis/caddy.rs#L13 | ||
export const LAUNCHER_ENV_URL = "/.launcher-env.json"; | ||
export const LAUNCHER_ENV_URL = "/.launcher-env.json" | ||
@@ -15,8 +15,8 @@ export interface LauncherEnvironment { | ||
LauncherEnvironment | undefined | ||
> { | ||
const env = await fetch(LAUNCHER_ENV_URL); | ||
> { | ||
const env = await fetch(LAUNCHER_ENV_URL) | ||
if (env.ok) { | ||
const launcherEnvironment = await env.json(); | ||
return launcherEnvironment; | ||
const launcherEnvironment = await env.json() | ||
return launcherEnvironment | ||
} else { | ||
@@ -27,8 +27,8 @@ // We are not in the launcher environment | ||
"[@holochain/conductor-api]: you are in a development environment. When this UI is run in the Holochain Launcher, `AppWebsocket.connect()`, `AdminWebsocket.connect()` and `appWebsocket.appInfo()` will have their parameters ignored and substituted by the ones provided by the Holochain Launcher." | ||
); | ||
return undefined; | ||
) | ||
return undefined | ||
} else { | ||
throw new Error( | ||
`Error trying to fetch the launcher environment: ${env.statusText}` | ||
); | ||
) | ||
} | ||
@@ -38,7 +38,10 @@ } | ||
const isBrowser = typeof window !== "undefined"; | ||
let promise: Promise<any>; | ||
const isBrowser = typeof window !== "undefined" | ||
const isJest = | ||
process && process.env && process.env.JEST_WORKER_ID !== undefined | ||
if (isBrowser) { | ||
promise = fetchLauncherEnvironment().catch(console.error); | ||
let promise: Promise<any> | ||
if (isBrowser && !isJest) { | ||
promise = fetchLauncherEnvironment().catch(console.error) | ||
} | ||
@@ -48,8 +51,8 @@ | ||
LauncherEnvironment | undefined | ||
> { | ||
> { | ||
if (isBrowser) { | ||
return promise; | ||
return promise | ||
} else { | ||
return undefined; | ||
return undefined | ||
} | ||
} |
@@ -22,4 +22,3 @@ /** | ||
import { Transformer, requesterTransformer, Requester } from '../api/common' | ||
import {ListAppInterfacesRequest} from "../api/admin"; | ||
import { getLauncherEnvironment } from '../environments/launcher'; | ||
import { getLauncherEnvironment } from '../environments/launcher' | ||
@@ -94,3 +93,3 @@ export class AdminWebsocket implements Api.AdminApi { | ||
listAppInterfaces: Requester<Api.ListAppInterfacesRequest, Api.ListAppInterfacesResponse> | ||
= this._requester('list_app_interfaces') | ||
= this._requester('list_app_interfaces') | ||
requestAgentInfo: Requester<Api.RequestAgentInfoRequest, Api.RequestAgentInfoResponse> | ||
@@ -104,7 +103,7 @@ = this._requester('request_agent_info') | ||
status_filter?: | ||
{Running: null} | ||
| {Enabled: null} | ||
| {Paused: null} | ||
| {Disabled: null} | ||
| {Stopped: null} | ||
{ Running: null } | ||
| { Enabled: null } | ||
| { Paused: null } | ||
| { Disabled: null } | ||
| { Stopped: null } | ||
} | ||
@@ -114,3 +113,3 @@ | ||
input: (req) => { | ||
const args: InternalListAppsRequest = {}; | ||
const args: InternalListAppsRequest = {} | ||
@@ -123,3 +122,3 @@ if (req.status_filter) { | ||
}, | ||
output: (res) => res | ||
output: (res) => res, | ||
} | ||
@@ -131,3 +130,3 @@ | ||
return JSON.parse(res) | ||
} | ||
}, | ||
} | ||
@@ -137,23 +136,23 @@ | ||
switch (status_filter) { | ||
case Api.AppStatusFilter.Running: | ||
case Api.AppStatusFilter.Running: | ||
return { | ||
Running: null | ||
Running: null, | ||
} | ||
case Api.AppStatusFilter.Enabled: | ||
case Api.AppStatusFilter.Enabled: | ||
return { | ||
Enabled: null | ||
Enabled: null, | ||
} | ||
case Api.AppStatusFilter.Paused: | ||
case Api.AppStatusFilter.Paused: | ||
return { | ||
Paused: null | ||
Paused: null, | ||
} | ||
case Api.AppStatusFilter.Disabled: | ||
case Api.AppStatusFilter.Disabled: | ||
return { | ||
Disabled: null | ||
Disabled: null, | ||
} | ||
case Api.AppStatusFilter.Stopped: | ||
case Api.AppStatusFilter.Stopped: | ||
return { | ||
Stopped: null | ||
Stopped: null, | ||
} | ||
} | ||
} |
@@ -18,10 +18,10 @@ /** | ||
*/ | ||
import { encode, decode} from '@msgpack/msgpack'; | ||
import { encode, decode } from '@msgpack/msgpack' | ||
import { AppApi, CallZomeRequest, CallZomeResponse, AppInfoRequest, AppInfoResponse, CallZomeRequestGeneric, CallZomeResponseGeneric, AppSignalCb } from '../api/app' | ||
import { AppApi, AppInfoRequest, AppInfoResponse, CallZomeRequestGeneric, CallZomeResponseGeneric, AppSignalCb } from '../api/app' | ||
import { WsClient } from './client' | ||
import { catchError, promiseTimeout, DEFAULT_TIMEOUT } from './common' | ||
import { Transformer, requesterTransformer, Requester } from '../api/common' | ||
import { getLauncherEnvironment } from '../environments/launcher'; | ||
import { InstalledAppId } from '../api/types'; | ||
import { getLauncherEnvironment } from '../environments/launcher' | ||
import { InstalledAppId } from '../api/types' | ||
@@ -63,6 +63,6 @@ export class AppWebsocket implements AppApi { | ||
const callZomeTransform: Transformer<CallZomeRequestGeneric<any>, CallZomeRequestGeneric<Uint8Array>, CallZomeResponseGeneric<Uint8Array>, CallZomeResponseGeneric<any>> = { | ||
input: (req: CallZomeRequestGeneric<any>): CallZomeRequestGeneric<Uint8Array> => { | ||
input: (req: CallZomeRequestGeneric<any>): CallZomeRequestGeneric<Uint8Array> => { | ||
return { | ||
...req, | ||
payload: encode(req.payload) | ||
payload: encode(req.payload), | ||
} | ||
@@ -72,3 +72,3 @@ }, | ||
return decode(res) | ||
} | ||
}, | ||
} | ||
@@ -80,4 +80,4 @@ | ||
return { | ||
installed_app_id: overrideInstalledAppId | ||
}; | ||
installed_app_id: overrideInstalledAppId, | ||
} | ||
} | ||
@@ -89,3 +89,3 @@ | ||
return res | ||
} | ||
}, | ||
}) |
@@ -1,5 +0,4 @@ | ||
import Websocket from "isomorphic-ws"; | ||
import { encode, decode } from "@msgpack/msgpack"; | ||
import { nanoid } from "nanoid"; | ||
import { AppSignal, AppSignalCb, SignalResponseGeneric } from "../api/app"; | ||
import Websocket from "isomorphic-ws" | ||
import { encode, decode } from "@msgpack/msgpack" | ||
import { AppSignal, AppSignalCb, SignalResponseGeneric } from "../api/app" | ||
@@ -14,3 +13,3 @@ /** | ||
socket: Websocket; | ||
pendingRequests: Record<number, { fulfill: Function; reject: Function }>; | ||
pendingRequests: Record<number, { fulfill: (msg: unknown) => ReturnType<typeof decode>; reject: (error: Error) => void }>; | ||
index: number; | ||
@@ -20,16 +19,16 @@ alreadyWarnedNoSignalCb: boolean; | ||
constructor(socket: any, signalCb?: AppSignalCb) { | ||
this.socket = socket; | ||
this.pendingRequests = {}; | ||
this.index = 0; | ||
this.socket = socket | ||
this.pendingRequests = {} | ||
this.index = 0 | ||
// TODO: allow adding signal handlers later | ||
this.alreadyWarnedNoSignalCb = false; | ||
this.alreadyWarnedNoSignalCb = false | ||
socket.onmessage = async (encodedMsg: any) => { | ||
let data = encodedMsg.data; | ||
let data = encodedMsg.data | ||
// If data is not a buffer (nodejs), it will be a blob (browser) | ||
if (typeof Buffer === "undefined" || !Buffer.isBuffer(data)) { | ||
data = await data.arrayBuffer(); | ||
data = await data.arrayBuffer() | ||
} | ||
const msg: any = decode(data); | ||
const msg: any = decode(data) | ||
if (msg.type === "Signal") { | ||
@@ -39,9 +38,14 @@ if (signalCb) { | ||
msg.data | ||
); | ||
) | ||
if (!decodedMessage.App) { | ||
// We have received a system signal, do nothing | ||
return | ||
} | ||
// Note: holochain currently returns signals as an array of two values: cellId and the serialized signal payload | ||
// and this array is nested within the App key within the returned message. | ||
const decodedCellId = decodedMessage.App[0]; | ||
const decodedCellId = decodedMessage.App[0] | ||
// Note:In order to return readible content to the UI, the signal payload must also be decoded. | ||
const decodedPayload = signalTransform(decodedMessage.App[1]); | ||
const decodedPayload = signalTransform(decodedMessage.App[1]) | ||
@@ -52,17 +56,17 @@ // Return a uniform format to UI (ie: { type, data } - the same format as with callZome and appInfo...) | ||
data: { cellId: decodedCellId, payload: decodedPayload }, | ||
}; | ||
signalCb(signal); | ||
} | ||
signalCb(signal) | ||
} else { | ||
if (!this.alreadyWarnedNoSignalCb) | ||
console.log( | ||
`Received signal but no signal callback was set in constructor` | ||
); | ||
this.alreadyWarnedNoSignalCb = true; | ||
'Received signal but no signal callback was set in constructor' | ||
) | ||
this.alreadyWarnedNoSignalCb = true | ||
} | ||
} else if (msg.type === "Response") { | ||
this.handleResponse(msg); | ||
} else if (msg.type === 'Response') { | ||
this.handleResponse(msg) | ||
} else { | ||
console.error(`Got unrecognized Websocket message type: ${msg.type}`); | ||
console.error(`Got unrecognized Websocket message type: ${msg.type}`) | ||
} | ||
}; | ||
} | ||
} | ||
@@ -72,29 +76,29 @@ | ||
const encodedMsg = encode({ | ||
type: "Signal", | ||
type: 'Signal', | ||
data: encode(data), | ||
}); | ||
this.socket.send(encodedMsg); | ||
}) | ||
this.socket.send(encodedMsg) | ||
} | ||
request<Req, Res>(data: Req): Promise<Res> { | ||
let id = this.index; | ||
this.index += 1; | ||
const id = this.index | ||
this.index += 1 | ||
const encodedMsg = encode({ | ||
id, | ||
type: "Request", | ||
type: 'Request', | ||
data: encode(data), | ||
}); | ||
}) | ||
const promise = new Promise((fulfill, reject) => { | ||
this.pendingRequests[id] = { fulfill, reject }; | ||
}); | ||
this.pendingRequests[id] = { fulfill, reject } | ||
}) | ||
if (this.socket.readyState === this.socket.OPEN) { | ||
this.socket.send(encodedMsg); | ||
this.socket.send(encodedMsg) | ||
} else { | ||
return Promise.reject(new Error(`Socket is not open`)); | ||
return Promise.reject(new Error('Socket is not open')) | ||
} | ||
return promise as Promise<Res>; | ||
return promise as Promise<Res> | ||
} | ||
handleResponse(msg: any) { | ||
const id = msg.id; | ||
const id = msg.id | ||
if (this.pendingRequests[id]) { | ||
@@ -104,9 +108,9 @@ // resolve response | ||
this.pendingRequests[id].reject( | ||
new Error(`Response canceled by responder`) | ||
); | ||
new Error('Response canceled by responder') | ||
) | ||
} else { | ||
this.pendingRequests[id].fulfill(decode(msg.data)); | ||
this.pendingRequests[id].fulfill(decode(msg.data)) | ||
} | ||
} else { | ||
console.error(`Got response with no matching request. id=${id}`); | ||
console.error(`Got response with no matching request. id=${id}`) | ||
} | ||
@@ -116,8 +120,8 @@ } | ||
close(): Promise<void> { | ||
this.socket.close(); | ||
return this.awaitClose(); | ||
this.socket.close() | ||
return this.awaitClose() | ||
} | ||
awaitClose(): Promise<void> { | ||
return new Promise((resolve) => this.socket.on("close", resolve)); | ||
return new Promise((resolve) => this.socket.on('close', resolve)) | ||
} | ||
@@ -127,7 +131,7 @@ | ||
return new Promise((resolve, reject) => { | ||
const socket = new Websocket(url); | ||
const socket = new Websocket(url) | ||
// make sure that there are no uncaught connection | ||
// errors because that causes nodejs thread to crash | ||
// with uncaught exception | ||
socket.onerror = (e) => { | ||
socket.onerror = () => { | ||
reject( | ||
@@ -137,8 +141,8 @@ new Error( | ||
) | ||
); | ||
}; | ||
) | ||
} | ||
socket.onopen = () => { | ||
resolve(new WsClient(socket, signalCb)); | ||
}; | ||
}); | ||
resolve(new WsClient(socket, signalCb)) | ||
} | ||
}) | ||
} | ||
@@ -150,3 +154,3 @@ } | ||
): SignalResponseGeneric<any> => { | ||
return decode(res); | ||
}; | ||
return decode(res) | ||
} |
@@ -13,5 +13,5 @@ const ERROR_TYPE = 'error' | ||
let timeout = new Promise((resolve, reject) => { | ||
const timeout = new Promise((_, reject) => { | ||
id = setTimeout(() => { | ||
clearTimeout(id); | ||
clearTimeout(id) | ||
reject(new Error(`Timed out in ${ms}ms: ${tag}`)) | ||
@@ -26,9 +26,9 @@ }, ms) | ||
]).then((a) => { | ||
clearTimeout(id); | ||
clearTimeout(id) | ||
return res(a) | ||
}) | ||
.catch(e => { | ||
return rej(e) | ||
}); | ||
.catch(e => { | ||
return rej(e) | ||
}) | ||
}) | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
129053
5
2570
12
4
- Removed@types/ws@^7.2.4
- Removed@types/node@22.8.6(transitive)
- Removed@types/ws@7.4.7(transitive)
- Removedundici-types@6.19.8(transitive)