juggle-client 1.0.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.
package/README.md ADDED
File without changes
package/cjs/index.js ADDED
@@ -0,0 +1,132 @@
1
+ 'use strict';
2
+
3
+ var fetch = require('node-fetch');
4
+ var qs = require('query-string');
5
+
6
+ /*! *****************************************************************************
7
+ Copyright (c) Microsoft Corporation.
8
+
9
+ Permission to use, copy, modify, and/or distribute this software for any
10
+ purpose with or without fee is hereby granted.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
13
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
+ PERFORMANCE OF THIS SOFTWARE.
19
+ ***************************************************************************** */
20
+ /* global Reflect, Promise */
21
+
22
+
23
+ var __assign = function() {
24
+ __assign = Object.assign || function __assign(t) {
25
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
26
+ s = arguments[i];
27
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
28
+ }
29
+ return t;
30
+ };
31
+ return __assign.apply(this, arguments);
32
+ };
33
+
34
+ function __awaiter(thisArg, _arguments, P, generator) {
35
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
36
+ return new (P || (P = Promise))(function (resolve, reject) {
37
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
38
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
39
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
40
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
41
+ });
42
+ }
43
+
44
+ function __generator(thisArg, body) {
45
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
46
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
47
+ function verb(n) { return function (v) { return step([n, v]); }; }
48
+ function step(op) {
49
+ if (f) throw new TypeError("Generator is already executing.");
50
+ while (_) try {
51
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
52
+ if (y = 0, t) op = [op[0] & 2, t.value];
53
+ switch (op[0]) {
54
+ case 0: case 1: t = op; break;
55
+ case 4: _.label++; return { value: op[1], done: false };
56
+ case 5: _.label++; y = op[1]; op = [0]; continue;
57
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
58
+ default:
59
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
60
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
61
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
62
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
63
+ if (t[2]) _.ops.pop();
64
+ _.trys.pop(); continue;
65
+ }
66
+ op = body.call(thisArg, _);
67
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
68
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
69
+ }
70
+ }
71
+
72
+ function get(url_1) {
73
+ return __awaiter(this, arguments, void 0, function (url, headers) {
74
+ var response;
75
+ if (headers === void 0) { headers = {}; }
76
+ return __generator(this, function (_a) {
77
+ switch (_a.label) {
78
+ case 0: return [4 /*yield*/, fetch(url, {
79
+ method: 'GET',
80
+ headers: __assign({ 'Content-Type': 'application/json' }, headers),
81
+ })];
82
+ case 1:
83
+ response = _a.sent();
84
+ return [2 /*return*/, response.json()];
85
+ }
86
+ });
87
+ });
88
+ }
89
+
90
+ var TRIGGER_FLOW_URL = '/v1/open/flow/trigger';
91
+ var GET_ASYNC_FLOW_RESULT_URL = '/v1/open/flow/getAsyncFlowResult';
92
+ var JuggleClient = /** @class */ (function () {
93
+ function JuggleClient(config) {
94
+ this.config = config;
95
+ }
96
+ JuggleClient.prototype.triggerFlow = function (flowVersion, flowKey, triggerData, flowData) {
97
+ return __awaiter(this, void 0, void 0, function () {
98
+ var url, response;
99
+ return __generator(this, function (_a) {
100
+ switch (_a.label) {
101
+ case 0:
102
+ url = "".concat(this.config.serverAddr).concat(TRIGGER_FLOW_URL, "/").concat(flowVersion, "/").concat(flowKey) +
103
+ qs.stringify(triggerData);
104
+ return [4 /*yield*/, get(url, {
105
+ 'Juggle-Token': this.config.accessToken,
106
+ })];
107
+ case 1:
108
+ response = _a.sent();
109
+ return [2 /*return*/, response];
110
+ }
111
+ });
112
+ });
113
+ };
114
+ JuggleClient.prototype.getAsyncFlowResult = function (flowInstanceId) {
115
+ return __awaiter(this, void 0, void 0, function () {
116
+ var response;
117
+ return __generator(this, function (_a) {
118
+ switch (_a.label) {
119
+ case 0: return [4 /*yield*/, get("".concat(this.config.serverAddr).concat(GET_ASYNC_FLOW_RESULT_URL, "/").concat(flowInstanceId), {
120
+ 'Juggle-Token': this.config.accessToken,
121
+ })];
122
+ case 1:
123
+ response = _a.sent();
124
+ return [2 /*return*/, response];
125
+ }
126
+ });
127
+ });
128
+ };
129
+ return JuggleClient;
130
+ }());
131
+
132
+ module.exports = JuggleClient;
package/esm/index.js ADDED
@@ -0,0 +1,130 @@
1
+ import fetch from 'node-fetch';
2
+ import qs from 'query-string';
3
+
4
+ /*! *****************************************************************************
5
+ Copyright (c) Microsoft Corporation.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
+ PERFORMANCE OF THIS SOFTWARE.
17
+ ***************************************************************************** */
18
+ /* global Reflect, Promise */
19
+
20
+
21
+ var __assign = function() {
22
+ __assign = Object.assign || function __assign(t) {
23
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
24
+ s = arguments[i];
25
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
26
+ }
27
+ return t;
28
+ };
29
+ return __assign.apply(this, arguments);
30
+ };
31
+
32
+ function __awaiter(thisArg, _arguments, P, generator) {
33
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
+ return new (P || (P = Promise))(function (resolve, reject) {
35
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
36
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
37
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
38
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
39
+ });
40
+ }
41
+
42
+ function __generator(thisArg, body) {
43
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
44
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
45
+ function verb(n) { return function (v) { return step([n, v]); }; }
46
+ function step(op) {
47
+ if (f) throw new TypeError("Generator is already executing.");
48
+ while (_) try {
49
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
50
+ if (y = 0, t) op = [op[0] & 2, t.value];
51
+ switch (op[0]) {
52
+ case 0: case 1: t = op; break;
53
+ case 4: _.label++; return { value: op[1], done: false };
54
+ case 5: _.label++; y = op[1]; op = [0]; continue;
55
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
56
+ default:
57
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
58
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
59
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
60
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
61
+ if (t[2]) _.ops.pop();
62
+ _.trys.pop(); continue;
63
+ }
64
+ op = body.call(thisArg, _);
65
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
66
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
67
+ }
68
+ }
69
+
70
+ function get(url_1) {
71
+ return __awaiter(this, arguments, void 0, function (url, headers) {
72
+ var response;
73
+ if (headers === void 0) { headers = {}; }
74
+ return __generator(this, function (_a) {
75
+ switch (_a.label) {
76
+ case 0: return [4 /*yield*/, fetch(url, {
77
+ method: 'GET',
78
+ headers: __assign({ 'Content-Type': 'application/json' }, headers),
79
+ })];
80
+ case 1:
81
+ response = _a.sent();
82
+ return [2 /*return*/, response.json()];
83
+ }
84
+ });
85
+ });
86
+ }
87
+
88
+ var TRIGGER_FLOW_URL = '/v1/open/flow/trigger';
89
+ var GET_ASYNC_FLOW_RESULT_URL = '/v1/open/flow/getAsyncFlowResult';
90
+ var JuggleClient = /** @class */ (function () {
91
+ function JuggleClient(config) {
92
+ this.config = config;
93
+ }
94
+ JuggleClient.prototype.triggerFlow = function (flowVersion, flowKey, triggerData, flowData) {
95
+ return __awaiter(this, void 0, void 0, function () {
96
+ var url, response;
97
+ return __generator(this, function (_a) {
98
+ switch (_a.label) {
99
+ case 0:
100
+ url = "".concat(this.config.serverAddr).concat(TRIGGER_FLOW_URL, "/").concat(flowVersion, "/").concat(flowKey) +
101
+ qs.stringify(triggerData);
102
+ return [4 /*yield*/, get(url, {
103
+ 'Juggle-Token': this.config.accessToken,
104
+ })];
105
+ case 1:
106
+ response = _a.sent();
107
+ return [2 /*return*/, response];
108
+ }
109
+ });
110
+ });
111
+ };
112
+ JuggleClient.prototype.getAsyncFlowResult = function (flowInstanceId) {
113
+ return __awaiter(this, void 0, void 0, function () {
114
+ var response;
115
+ return __generator(this, function (_a) {
116
+ switch (_a.label) {
117
+ case 0: return [4 /*yield*/, get("".concat(this.config.serverAddr).concat(GET_ASYNC_FLOW_RESULT_URL, "/").concat(flowInstanceId), {
118
+ 'Juggle-Token': this.config.accessToken,
119
+ })];
120
+ case 1:
121
+ response = _a.sent();
122
+ return [2 /*return*/, response];
123
+ }
124
+ });
125
+ });
126
+ };
127
+ return JuggleClient;
128
+ }());
129
+
130
+ export { JuggleClient as default };
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "juggle-client",
3
+ "version": "1.0.0",
4
+ "description": "juggle (https://juggle.plus) nodejs sdk",
5
+ "scripts": {
6
+ "test": "ts-node test.ts",
7
+ "clear": "rimraf dist types",
8
+ "build-types": "tsc --declaration -p . -t es2015 --emitDeclarationOnly --outDir types",
9
+ "build": "rollup -c",
10
+ "contributors": "contributors -f plain -o AUTHORS",
11
+ "clean": "lerna clean --yes; rm -rf ./packages/**/package-lock.json",
12
+ "bootstrap": "rm -f ./packages/.DS*; lerna bootstrap --no-ci",
13
+ "release": "rm -f ./packages/.DS*; sh scripts/publish.sh"
14
+ },
15
+ "types": "types/index.d.ts",
16
+ "main": "./cjs/index.js",
17
+ "module": "./esm/index.js",
18
+ "exports": {
19
+ ".": {
20
+ "require": "./cjs/index.js",
21
+ "import": "./esm/index.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "cjs/",
26
+ "esm/",
27
+ "types/",
28
+ "README.md"
29
+ ],
30
+ "license": "Apache-2.0",
31
+ "bugs": {
32
+ "url": "https://github.com/somta/Juggle/issues"
33
+ },
34
+ "homepage": "https://juggle.plus",
35
+ "engines": {
36
+ "node": ">= 18"
37
+ },
38
+ "ci": {
39
+ "type": "travis",
40
+ "version": "8, 10"
41
+ },
42
+ "devDependencies": {
43
+ "@rollup/plugin-commonjs": "^28.0.1",
44
+ "@rollup/plugin-terser": "^0.4.4",
45
+ "@rollup/plugin-typescript": "^12.1.1",
46
+ "@types/node-fetch": "2",
47
+ "contributors": "^0.5.1",
48
+ "lerna": "^3.4.3",
49
+ "lerna-relinker": "^1.5.0",
50
+ "rimraf": "^6.0.1",
51
+ "rollup": "^4.24.0",
52
+ "ts-node": "^10.9.2",
53
+ "typescript": "^5.6.3"
54
+ },
55
+ "dependencies": {
56
+ "node-fetch": "2",
57
+ "query-string": "^7.1.3"
58
+ }
59
+ }
@@ -0,0 +1,13 @@
1
+ export interface IConfig {
2
+ /** 密钥 */
3
+ accessToken: string;
4
+ /** 服务地址 */
5
+ serverAddr: string;
6
+ }
7
+ export type FlowTriggerDataParam = Record<string, any>;
8
+ export default class JuggleClient {
9
+ config: IConfig;
10
+ constructor(config: IConfig);
11
+ triggerFlow(flowVersion: string, flowKey: string, triggerData: FlowTriggerDataParam): Promise<any>;
12
+ getAsyncFlowResult(flowInstanceId: string): Promise<any>;
13
+ }
@@ -0,0 +1,2 @@
1
+ export declare function get(url: string, headers?: {}): Promise<any>;
2
+ export declare function post(url: string, data?: Record<string, any>, headers?: {}): Promise<any>;