appmesh 3.1.20 → 3.1.22
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/README.md +1 -1
- package/dist/appmesh.esm.js +1 -1
- package/package.json +2 -2
- package/src/appmesh.js +60 -44
- package/src/appmesh_tcp.js +154 -104
- package/src/request_signature.js +11 -10
- package/src/worker.js +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "appmesh",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.22",
|
|
4
4
|
"description": "JavaScript SDK for App Mesh (https://github.com/laoshanxi/app-mesh)",
|
|
5
5
|
"main": "./src/appmesh.js",
|
|
6
6
|
"module": "./dist/appmesh.esm.js",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"scripts": {
|
|
10
10
|
"lint": "prettier --write .",
|
|
11
|
-
"test": "node test/unit_test.js && node test/
|
|
11
|
+
"test": "node test/unit_test.js && node test/run_sync_test.js && node test/subscribe_test.js && node test/stream_forward_test.js && node test/appmesh_test.js",
|
|
12
12
|
"test:subscribe": "node test/subscribe_test.js",
|
|
13
13
|
"build": "webpack --config webpack.config.cjs --mode production",
|
|
14
14
|
"prepare": "npm run build",
|
package/src/appmesh.js
CHANGED
|
@@ -832,7 +832,7 @@ class AppMeshClient {
|
|
|
832
832
|
return Buffer.from(JSON.stringify(data), 'utf8');
|
|
833
833
|
}
|
|
834
834
|
throw new AppMeshError(
|
|
835
|
-
'cannot sign a streaming request body; only the /appmesh/
|
|
835
|
+
'cannot sign a streaming request body; only the /appmesh/files endpoints accept unbound bodies');
|
|
836
836
|
}
|
|
837
837
|
|
|
838
838
|
/** Return the current in-memory access token from the attached provider. */
|
|
@@ -905,7 +905,7 @@ class AppMeshClient {
|
|
|
905
905
|
|
|
906
906
|
/** Return the verified principal represented by the current bearer. */
|
|
907
907
|
async getCurrentPrincipal() {
|
|
908
|
-
return (await this._request("get", "/appmesh/
|
|
908
|
+
return (await this._request("get", "/appmesh/principals/self")).data;
|
|
909
909
|
}
|
|
910
910
|
|
|
911
911
|
/**
|
|
@@ -913,7 +913,7 @@ class AppMeshClient {
|
|
|
913
913
|
* @returns {Object} All apps info
|
|
914
914
|
*/
|
|
915
915
|
async listApps() {
|
|
916
|
-
const response = await this._request("get", "/appmesh/
|
|
916
|
+
const response = await this._request("get", "/appmesh/apps");
|
|
917
917
|
return response.data;
|
|
918
918
|
}
|
|
919
919
|
|
|
@@ -923,7 +923,7 @@ class AppMeshClient {
|
|
|
923
923
|
* @returns {Object} App config
|
|
924
924
|
*/
|
|
925
925
|
async getApp(name) {
|
|
926
|
-
const response = await this._request("get", `/appmesh/
|
|
926
|
+
const response = await this._request("get", `/appmesh/apps/${name}`);
|
|
927
927
|
return response.data;
|
|
928
928
|
}
|
|
929
929
|
|
|
@@ -934,7 +934,7 @@ class AppMeshClient {
|
|
|
934
934
|
* @throws {AppMeshError} On auth/missing-app/server errors (non-200) or network/transport failure
|
|
935
935
|
*/
|
|
936
936
|
async checkAppHealth(name) {
|
|
937
|
-
const response = await this._request("get", `/appmesh/
|
|
937
|
+
const response = await this._request("get", `/appmesh/apps/${name}/health`);
|
|
938
938
|
return parseInt(response.data, 10) === 0;
|
|
939
939
|
}
|
|
940
940
|
|
|
@@ -977,7 +977,7 @@ class AppMeshClient {
|
|
|
977
977
|
* await client.addApp("ping", appConfig);
|
|
978
978
|
*/
|
|
979
979
|
async addApp(name, appJson) {
|
|
980
|
-
const response = await this._request("put", `/appmesh/
|
|
980
|
+
const response = await this._request("put", `/appmesh/apps/${name}`, appJson);
|
|
981
981
|
return response.data;
|
|
982
982
|
}
|
|
983
983
|
|
|
@@ -988,7 +988,7 @@ class AppMeshClient {
|
|
|
988
988
|
*/
|
|
989
989
|
async deleteApp(name) {
|
|
990
990
|
try {
|
|
991
|
-
const response = await this._request("delete", `/appmesh/
|
|
991
|
+
const response = await this._request("delete", `/appmesh/apps/${name}`);
|
|
992
992
|
return response.status === 200;
|
|
993
993
|
} catch (error) {
|
|
994
994
|
if (error.statusCode === 404) return false;
|
|
@@ -1002,7 +1002,7 @@ class AppMeshClient {
|
|
|
1002
1002
|
* @returns {Promise<boolean>} true on success; failures throw AppMeshError
|
|
1003
1003
|
*/
|
|
1004
1004
|
async enableApp(name) {
|
|
1005
|
-
await this._request("post", `/appmesh/
|
|
1005
|
+
await this._request("post", `/appmesh/apps/${name}/enable`);
|
|
1006
1006
|
return true;
|
|
1007
1007
|
}
|
|
1008
1008
|
|
|
@@ -1012,7 +1012,7 @@ class AppMeshClient {
|
|
|
1012
1012
|
* @returns {Promise<boolean>} true on success; failures throw AppMeshError
|
|
1013
1013
|
*/
|
|
1014
1014
|
async disableApp(name) {
|
|
1015
|
-
await this._request("post", `/appmesh/
|
|
1015
|
+
await this._request("post", `/appmesh/apps/${name}/disable`);
|
|
1016
1016
|
return true;
|
|
1017
1017
|
}
|
|
1018
1018
|
|
|
@@ -1037,7 +1037,7 @@ class AppMeshClient {
|
|
|
1037
1037
|
timeout: parseDuration(timeout).toString()
|
|
1038
1038
|
};
|
|
1039
1039
|
|
|
1040
|
-
const response = await this._request("get", `/appmesh/
|
|
1040
|
+
const response = await this._request("get", `/appmesh/apps/${app_name}/output`, null, { params });
|
|
1041
1041
|
// axios lowercases header names; the TCP transport keeps the daemon's exact case
|
|
1042
1042
|
const outPositionHeader = _getHeader(response.headers, CONSTANTS.HTTP_HEADER_KEY_X_OUTPUT_POSITION);
|
|
1043
1043
|
const exitCodeHeader = _getHeader(response.headers, CONSTANTS.HTTP_HEADER_KEY_X_EXIT_CODE);
|
|
@@ -1064,11 +1064,14 @@ class AppMeshClient {
|
|
|
1064
1064
|
lifecycle = CONSTANTS.DEFAULT_RUN_APP_LIFECYCLE_SECONDS, maxOutputBytes = null) {
|
|
1065
1065
|
const params = {
|
|
1066
1066
|
timeout: parseDuration(maxTime),
|
|
1067
|
-
lifecycle: parseDuration(lifecycle)
|
|
1067
|
+
lifecycle: parseDuration(lifecycle),
|
|
1068
|
+
// Blocking variant of the shared run endpoint: without it the daemon answers
|
|
1069
|
+
// immediately with the process uuid (runAppAsync).
|
|
1070
|
+
sync: 1
|
|
1068
1071
|
};
|
|
1069
1072
|
|
|
1070
1073
|
// Raw bytes: pages are joined as bytes and decoded once (a character may span pages).
|
|
1071
|
-
const response = await this._request("post", "/appmesh/
|
|
1074
|
+
const response = await this._request("post", "/appmesh/apps/run", app, {
|
|
1072
1075
|
params, config: { responseType: "arraybuffer" }
|
|
1073
1076
|
});
|
|
1074
1077
|
let exitCode = null;
|
|
@@ -1094,8 +1097,16 @@ class AppMeshClient {
|
|
|
1094
1097
|
}
|
|
1095
1098
|
}
|
|
1096
1099
|
|
|
1100
|
+
const bytes = _toBytes(response.data);
|
|
1101
|
+
if (maxOutputBytes !== null && maxOutputBytes !== undefined && bytes.byteLength > maxOutputBytes) {
|
|
1102
|
+
throw new AppMeshRequestError(
|
|
1103
|
+
`run output exceeds maxOutputBytes=${maxOutputBytes} (${bytes.byteLength} bytes)`,
|
|
1104
|
+
response.status
|
|
1105
|
+
);
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1097
1108
|
if (stdoutHandler) {
|
|
1098
|
-
stdoutHandler(_decodeBytes(
|
|
1109
|
+
stdoutHandler(_decodeBytes(bytes, _charsetOf(_responseContentType(response))), 0);
|
|
1099
1110
|
}
|
|
1100
1111
|
|
|
1101
1112
|
return exitCode;
|
|
@@ -1130,7 +1141,7 @@ class AppMeshClient {
|
|
|
1130
1141
|
let complete = false;
|
|
1131
1142
|
try {
|
|
1132
1143
|
while (true) {
|
|
1133
|
-
const page = await this._request("get", `/appmesh/
|
|
1144
|
+
const page = await this._request("get", `/appmesh/apps/${runName}/output`, null, {
|
|
1134
1145
|
params: { stdout_position: String(position) }, config: { responseType: "arraybuffer" }
|
|
1135
1146
|
});
|
|
1136
1147
|
const bytes = _toBytes(page.data);
|
|
@@ -1170,7 +1181,7 @@ class AppMeshClient {
|
|
|
1170
1181
|
lifecycle: parseDuration(lifecycle)
|
|
1171
1182
|
};
|
|
1172
1183
|
|
|
1173
|
-
const response = await this._request("post", "/appmesh/
|
|
1184
|
+
const response = await this._request("post", "/appmesh/apps/run", app, { params });
|
|
1174
1185
|
return new AppRun(this, response.data.name, response.data.process_uuid);
|
|
1175
1186
|
}
|
|
1176
1187
|
|
|
@@ -1227,7 +1238,7 @@ class AppMeshClient {
|
|
|
1227
1238
|
if (timeout <= 0) {
|
|
1228
1239
|
timeout = 300;
|
|
1229
1240
|
}
|
|
1230
|
-
const response = await this._request("post", `/appmesh/
|
|
1241
|
+
const response = await this._request("post", `/appmesh/apps/${appName}/task`, data, {
|
|
1231
1242
|
params: { timeout: timeout.toString() }
|
|
1232
1243
|
});
|
|
1233
1244
|
return response.data;
|
|
@@ -1239,7 +1250,7 @@ class AppMeshClient {
|
|
|
1239
1250
|
* @returns {Promise<boolean>} true on success; failures throw AppMeshError
|
|
1240
1251
|
*/
|
|
1241
1252
|
async cancelTask(appName) {
|
|
1242
|
-
await this._request("delete", `/appmesh/
|
|
1253
|
+
await this._request("delete", `/appmesh/apps/${appName}/task`);
|
|
1243
1254
|
return true;
|
|
1244
1255
|
}
|
|
1245
1256
|
|
|
@@ -1270,7 +1281,7 @@ class AppMeshClient {
|
|
|
1270
1281
|
if (processUuid) {
|
|
1271
1282
|
params.process_uuid = processUuid;
|
|
1272
1283
|
}
|
|
1273
|
-
const response = await this._sseRequest("get", `/appmesh/
|
|
1284
|
+
const response = await this._sseRequest("get", `/appmesh/apps/${appName}/output/stream`, { params });
|
|
1274
1285
|
let end = null;
|
|
1275
1286
|
try {
|
|
1276
1287
|
for await (const [event, payload] of _iterSseEvents(response.data)) {
|
|
@@ -1313,7 +1324,7 @@ class AppMeshClient {
|
|
|
1313
1324
|
async *runTaskStream(appName, data, opts = {}) {
|
|
1314
1325
|
const { timeout = 300 } = opts;
|
|
1315
1326
|
const params = timeout && timeout > 0 ? { timeout: String(timeout) } : {};
|
|
1316
|
-
const response = await this._sseRequest("post", `/appmesh/
|
|
1327
|
+
const response = await this._sseRequest("post", `/appmesh/apps/${appName}/task/stream`, { params, body: data });
|
|
1317
1328
|
let end = null;
|
|
1318
1329
|
let finalResult = null;
|
|
1319
1330
|
try {
|
|
@@ -1397,7 +1408,7 @@ class AppMeshClient {
|
|
|
1397
1408
|
const { close = false, processUuid = '' } = opts;
|
|
1398
1409
|
const headers = close ? { [CONSTANTS.HTTP_HEADER_KEY_X_INPUT_CLOSE]: "true" } : {};
|
|
1399
1410
|
const params = processUuid ? { process_uuid: processUuid } : {};
|
|
1400
|
-
const response = await this._request("post", `/appmesh/
|
|
1411
|
+
const response = await this._request("post", `/appmesh/apps/${appName}/input`, data, { headers, params });
|
|
1401
1412
|
return parseInt(response.data?.bytes_written ?? 0, 10);
|
|
1402
1413
|
}
|
|
1403
1414
|
|
|
@@ -1424,7 +1435,7 @@ class AppMeshClient {
|
|
|
1424
1435
|
if (!localFile) localFile = filePath.split(/[\\/]/).pop();
|
|
1425
1436
|
const headers = { [CONSTANTS.HTTP_HEADER_KEY_X_FILE_PATH]: encodeURIComponent(filePath) };
|
|
1426
1437
|
// Node streams the body to disk; the browser needs the whole buffer for Blob.
|
|
1427
|
-
const response = await this._request("get", "/appmesh/
|
|
1438
|
+
const response = await this._request("get", "/appmesh/files", null, {
|
|
1428
1439
|
headers,
|
|
1429
1440
|
config: {
|
|
1430
1441
|
responseType: ENV.isNode ? "stream" : "arraybuffer"
|
|
@@ -1550,7 +1561,7 @@ class AppMeshClient {
|
|
|
1550
1561
|
}
|
|
1551
1562
|
}
|
|
1552
1563
|
|
|
1553
|
-
const response = await this._request("post", "/appmesh/
|
|
1564
|
+
const response = await this._request("post", "/appmesh/files", body, {
|
|
1554
1565
|
headers,
|
|
1555
1566
|
config: {
|
|
1556
1567
|
maxBodyLength: Infinity,
|
|
@@ -1589,11 +1600,11 @@ class AppMeshClient {
|
|
|
1589
1600
|
|
|
1590
1601
|
/**
|
|
1591
1602
|
* Apply a partial config update and return the merged server config.
|
|
1592
|
-
* @param {Object} config - Partial config document to
|
|
1603
|
+
* @param {Object} config - Partial config document to PUT to `/appmesh/config`
|
|
1593
1604
|
* @returns {Object} Updated config
|
|
1594
1605
|
*/
|
|
1595
1606
|
async setConfig(config) {
|
|
1596
|
-
const response = await this._request("
|
|
1607
|
+
const response = await this._request("put", "/appmesh/config", config);
|
|
1597
1608
|
return response.data;
|
|
1598
1609
|
}
|
|
1599
1610
|
|
|
@@ -1614,7 +1625,7 @@ class AppMeshClient {
|
|
|
1614
1625
|
* @returns {Promise<boolean>} true on success; failures throw AppMeshError
|
|
1615
1626
|
*/
|
|
1616
1627
|
async addLabel(labelName, labelValue) {
|
|
1617
|
-
await this._request("put", `/appmesh/
|
|
1628
|
+
await this._request("put", `/appmesh/labels/${labelName}`, null, { params: { value: labelValue } });
|
|
1618
1629
|
return true;
|
|
1619
1630
|
}
|
|
1620
1631
|
|
|
@@ -1625,7 +1636,7 @@ class AppMeshClient {
|
|
|
1625
1636
|
* @returns {Promise<boolean>} true on success; failures throw AppMeshError
|
|
1626
1637
|
*/
|
|
1627
1638
|
async deleteLabel(labelName) {
|
|
1628
|
-
await this._request("delete", `/appmesh/
|
|
1639
|
+
await this._request("delete", `/appmesh/labels/${labelName}`);
|
|
1629
1640
|
return true;
|
|
1630
1641
|
}
|
|
1631
1642
|
|
|
@@ -1647,13 +1658,13 @@ class AppMeshClient {
|
|
|
1647
1658
|
|
|
1648
1659
|
/** Update an Engine authorization overlay; never mutate IdP account data. */
|
|
1649
1660
|
async updatePrincipal(principalId, policy) {
|
|
1650
|
-
await this._request("
|
|
1661
|
+
await this._request("patch", `/appmesh/principals/${encodeURIComponent(principalId)}`, policy);
|
|
1651
1662
|
return true;
|
|
1652
1663
|
}
|
|
1653
1664
|
|
|
1654
1665
|
/** Delete only an Engine authorization overlay. */
|
|
1655
1666
|
async deletePrincipal(principalId) {
|
|
1656
|
-
await this._request("delete", `/appmesh/
|
|
1667
|
+
await this._request("delete", `/appmesh/principals/${encodeURIComponent(principalId)}`);
|
|
1657
1668
|
return true;
|
|
1658
1669
|
}
|
|
1659
1670
|
|
|
@@ -1673,7 +1684,7 @@ class AppMeshClient {
|
|
|
1673
1684
|
|
|
1674
1685
|
/** Get effective permissions for the current verified principal. */
|
|
1675
1686
|
async getPrincipalPermissions() {
|
|
1676
|
-
const response = await this._request("get", "/appmesh/
|
|
1687
|
+
const response = await this._request("get", "/appmesh/principals/self/permissions");
|
|
1677
1688
|
return response.data;
|
|
1678
1689
|
}
|
|
1679
1690
|
|
|
@@ -1698,7 +1709,7 @@ class AppMeshClient {
|
|
|
1698
1709
|
* @returns {Promise<boolean>} true on success; failures throw AppMeshError
|
|
1699
1710
|
*/
|
|
1700
1711
|
async updateRole(roleName, rolePermissionJson) {
|
|
1701
|
-
await this._request("
|
|
1712
|
+
await this._request("put", `/appmesh/roles/${roleName}`, rolePermissionJson);
|
|
1702
1713
|
return true;
|
|
1703
1714
|
}
|
|
1704
1715
|
|
|
@@ -1708,7 +1719,7 @@ class AppMeshClient {
|
|
|
1708
1719
|
* @returns {Promise<boolean>} true on success; failures throw AppMeshError
|
|
1709
1720
|
*/
|
|
1710
1721
|
async deleteRole(roleName) {
|
|
1711
|
-
await this._request("delete", `/appmesh/
|
|
1722
|
+
await this._request("delete", `/appmesh/roles/${roleName}`);
|
|
1712
1723
|
return true;
|
|
1713
1724
|
}
|
|
1714
1725
|
|
|
@@ -1745,7 +1756,7 @@ class AppMeshClient {
|
|
|
1745
1756
|
* Perform a raw App Mesh REST request using this client's transport, auth and error handling.
|
|
1746
1757
|
* Stable seam for worker-role wrappers (AppMeshWorker) and advanced callers.
|
|
1747
1758
|
* @param {string} method - HTTP method (get, post, put, delete, ...)
|
|
1748
|
-
* @param {string} path - Endpoint path (e.g. "/appmesh/
|
|
1759
|
+
* @param {string} path - Endpoint path (e.g. "/appmesh/apps")
|
|
1749
1760
|
* @param {Object|string|Buffer} [body=null] - Request payload
|
|
1750
1761
|
* @param {Object} [options={}] - Request options: { headers, params, config }
|
|
1751
1762
|
* @returns {Promise<any>} Response object ({ status, headers, data, ... })
|
|
@@ -1932,24 +1943,14 @@ class AppMeshClient {
|
|
|
1932
1943
|
try {
|
|
1933
1944
|
const textDecoder = new TextDecoder("utf-8");
|
|
1934
1945
|
const text = textDecoder.decode(responseData);
|
|
1935
|
-
|
|
1936
|
-
const parsedJson = JSON.parse(text);
|
|
1937
|
-
return parsedJson.message || parsedJson.error || "Binary response error";
|
|
1938
|
-
} catch (e) {
|
|
1939
|
-
return text; // not json, return raw text
|
|
1940
|
-
}
|
|
1946
|
+
return text ? this._extractJsonErrorText(text) : "Unknown error";
|
|
1941
1947
|
} catch (e) {
|
|
1942
1948
|
return 'Binary response error (could not decode)';
|
|
1943
1949
|
}
|
|
1944
1950
|
}
|
|
1945
1951
|
|
|
1946
1952
|
if (typeof responseData === 'string') {
|
|
1947
|
-
|
|
1948
|
-
const parsedJson = JSON.parse(responseData);
|
|
1949
|
-
return parsedJson.message || parsedJson.error || responseData;
|
|
1950
|
-
} catch (e) {
|
|
1951
|
-
return responseData;
|
|
1952
|
-
}
|
|
1953
|
+
return this._extractJsonErrorText(responseData);
|
|
1953
1954
|
}
|
|
1954
1955
|
|
|
1955
1956
|
if (typeof responseData === 'object') {
|
|
@@ -1959,6 +1960,21 @@ class AppMeshClient {
|
|
|
1959
1960
|
return String(responseData);
|
|
1960
1961
|
}
|
|
1961
1962
|
|
|
1963
|
+
_extractJsonErrorText(text) {
|
|
1964
|
+
try {
|
|
1965
|
+
const parsed = JSON.parse(text);
|
|
1966
|
+
if (parsed && typeof parsed === 'object') {
|
|
1967
|
+
return parsed.message || parsed.error || text;
|
|
1968
|
+
}
|
|
1969
|
+
if (typeof parsed === 'string') {
|
|
1970
|
+
return parsed;
|
|
1971
|
+
}
|
|
1972
|
+
return text;
|
|
1973
|
+
} catch (e) {
|
|
1974
|
+
return text;
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1962
1978
|
/**
|
|
1963
1979
|
* Comprehensive error handler for all client errors.
|
|
1964
1980
|
* The default implementation only normalizes the error type; override this
|