@useshortcut/client 1.0.0-beta.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 +80 -0
- package/lib/ShortcutApi.d.ts +5 -0
- package/lib/ShortcutApi.js +45 -0
- package/lib/generated/Api.d.ts +955 -0
- package/lib/generated/Api.js +1309 -0
- package/lib/generated/data-contracts.d.ts +4418 -0
- package/lib/generated/data-contracts.js +12 -0
- package/lib/generated/http-client.d.ts +39 -0
- package/lib/generated/http-client.js +134 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +14 -0
- package/package.json +65 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/*
|
|
5
|
+
* ---------------------------------------------------------------
|
|
6
|
+
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
|
|
7
|
+
* ## ##
|
|
8
|
+
* ## AUTHOR: acacode ##
|
|
9
|
+
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
|
|
10
|
+
* ---------------------------------------------------------------
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig, AxiosResponse, ResponseType } from "axios";
|
|
2
|
+
export declare type QueryParamsType = Record<string | number, any>;
|
|
3
|
+
export interface FullRequestParams extends Omit<AxiosRequestConfig, "data" | "params" | "url" | "responseType"> {
|
|
4
|
+
/** set parameter to `true` for call `securityWorker` for this request */
|
|
5
|
+
secure?: boolean;
|
|
6
|
+
/** request path */
|
|
7
|
+
path: string;
|
|
8
|
+
/** content type of request body */
|
|
9
|
+
type?: ContentType;
|
|
10
|
+
/** query params */
|
|
11
|
+
query?: QueryParamsType;
|
|
12
|
+
/** format of response (i.e. response.json() -> format: "json") */
|
|
13
|
+
format?: ResponseType;
|
|
14
|
+
/** request body */
|
|
15
|
+
body?: unknown;
|
|
16
|
+
}
|
|
17
|
+
export declare type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">;
|
|
18
|
+
export interface ApiConfig<SecurityDataType = unknown> extends Omit<AxiosRequestConfig, "data" | "cancelToken"> {
|
|
19
|
+
securityWorker?: (securityData: SecurityDataType | null) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void;
|
|
20
|
+
secure?: boolean;
|
|
21
|
+
format?: ResponseType;
|
|
22
|
+
}
|
|
23
|
+
export declare enum ContentType {
|
|
24
|
+
Json = "application/json",
|
|
25
|
+
FormData = "multipart/form-data",
|
|
26
|
+
UrlEncoded = "application/x-www-form-urlencoded"
|
|
27
|
+
}
|
|
28
|
+
export declare class HttpClient<SecurityDataType = unknown> {
|
|
29
|
+
instance: AxiosInstance;
|
|
30
|
+
private securityData;
|
|
31
|
+
private securityWorker?;
|
|
32
|
+
private secure?;
|
|
33
|
+
private format?;
|
|
34
|
+
constructor({ securityWorker, secure, format, ...axiosConfig }?: ApiConfig<SecurityDataType>);
|
|
35
|
+
setSecurityData: (data: SecurityDataType | null) => void;
|
|
36
|
+
private mergeRequestParams;
|
|
37
|
+
private createFormData;
|
|
38
|
+
request: <T = any, _E = any>({ secure, path, type, query, format, body, ...params }: FullRequestParams) => Promise<AxiosResponse<T>>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/* tslint:disable */
|
|
4
|
+
/*
|
|
5
|
+
* ---------------------------------------------------------------
|
|
6
|
+
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
|
|
7
|
+
* ## ##
|
|
8
|
+
* ## AUTHOR: acacode ##
|
|
9
|
+
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
|
|
10
|
+
* ---------------------------------------------------------------
|
|
11
|
+
*/
|
|
12
|
+
var __assign = (this && this.__assign) || function () {
|
|
13
|
+
__assign = Object.assign || function(t) {
|
|
14
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
15
|
+
s = arguments[i];
|
|
16
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
17
|
+
t[p] = s[p];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
return __assign.apply(this, arguments);
|
|
22
|
+
};
|
|
23
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
24
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
25
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
26
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
27
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
28
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
33
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
34
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
35
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
36
|
+
function step(op) {
|
|
37
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
38
|
+
while (_) try {
|
|
39
|
+
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;
|
|
40
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
41
|
+
switch (op[0]) {
|
|
42
|
+
case 0: case 1: t = op; break;
|
|
43
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
44
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
45
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
46
|
+
default:
|
|
47
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
48
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
49
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
50
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
51
|
+
if (t[2]) _.ops.pop();
|
|
52
|
+
_.trys.pop(); continue;
|
|
53
|
+
}
|
|
54
|
+
op = body.call(thisArg, _);
|
|
55
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
56
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
60
|
+
var t = {};
|
|
61
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
62
|
+
t[p] = s[p];
|
|
63
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
64
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
65
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
66
|
+
t[p[i]] = s[p[i]];
|
|
67
|
+
}
|
|
68
|
+
return t;
|
|
69
|
+
};
|
|
70
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
71
|
+
exports.HttpClient = exports.ContentType = void 0;
|
|
72
|
+
var axios_1 = require("axios");
|
|
73
|
+
var FormData = require("form-data");
|
|
74
|
+
var ContentType;
|
|
75
|
+
(function (ContentType) {
|
|
76
|
+
ContentType["Json"] = "application/json";
|
|
77
|
+
ContentType["FormData"] = "multipart/form-data";
|
|
78
|
+
ContentType["UrlEncoded"] = "application/x-www-form-urlencoded";
|
|
79
|
+
})(ContentType = exports.ContentType || (exports.ContentType = {}));
|
|
80
|
+
var HttpClient = /** @class */ (function () {
|
|
81
|
+
function HttpClient(_a) {
|
|
82
|
+
var _this = this;
|
|
83
|
+
if (_a === void 0) { _a = {}; }
|
|
84
|
+
var securityWorker = _a.securityWorker, secure = _a.secure, format = _a.format, axiosConfig = __rest(_a, ["securityWorker", "secure", "format"]);
|
|
85
|
+
this.securityData = null;
|
|
86
|
+
this.setSecurityData = function (data) {
|
|
87
|
+
_this.securityData = data;
|
|
88
|
+
};
|
|
89
|
+
this.request = function (_a) { return __awaiter(_this, void 0, void 0, function () {
|
|
90
|
+
var secureParams, _b, requestParams, responseFormat;
|
|
91
|
+
var secure = _a.secure, path = _a.path, type = _a.type, query = _a.query, format = _a.format, body = _a.body, params = __rest(_a, ["secure", "path", "type", "query", "format", "body"]);
|
|
92
|
+
return __generator(this, function (_c) {
|
|
93
|
+
switch (_c.label) {
|
|
94
|
+
case 0:
|
|
95
|
+
_b = (typeof secure === "boolean" ? secure : this.secure) &&
|
|
96
|
+
this.securityWorker;
|
|
97
|
+
if (!_b) return [3 /*break*/, 2];
|
|
98
|
+
return [4 /*yield*/, this.securityWorker(this.securityData)];
|
|
99
|
+
case 1:
|
|
100
|
+
_b = (_c.sent());
|
|
101
|
+
_c.label = 2;
|
|
102
|
+
case 2:
|
|
103
|
+
secureParams = (_b) ||
|
|
104
|
+
{};
|
|
105
|
+
requestParams = this.mergeRequestParams(params, secureParams);
|
|
106
|
+
responseFormat = (format && this.format) || void 0;
|
|
107
|
+
if (type === ContentType.FormData && body && body !== null && typeof body === "object") {
|
|
108
|
+
requestParams.headers.common = { Accept: "*/*" };
|
|
109
|
+
requestParams.headers.post = {};
|
|
110
|
+
requestParams.headers.put = {};
|
|
111
|
+
body = this.createFormData(body);
|
|
112
|
+
}
|
|
113
|
+
return [2 /*return*/, this.instance.request(__assign(__assign({}, requestParams), { headers: __assign(__assign(__assign({}, (type && type !== ContentType.FormData ? { "Content-Type": type } : {})), (body instanceof FormData ? { "Content-Type": body.getHeaders()["content-type"] } : {})), (requestParams.headers || {})), params: query, responseType: responseFormat, data: body, url: path }))];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}); };
|
|
117
|
+
this.instance = axios_1.default.create(__assign(__assign({}, axiosConfig), { baseURL: axiosConfig.baseURL || "https://api.app.shortcut.com" }));
|
|
118
|
+
this.secure = secure;
|
|
119
|
+
this.format = format;
|
|
120
|
+
this.securityWorker = securityWorker;
|
|
121
|
+
}
|
|
122
|
+
HttpClient.prototype.mergeRequestParams = function (params1, params2) {
|
|
123
|
+
return __assign(__assign(__assign(__assign({}, this.instance.defaults), params1), (params2 || {})), { headers: __assign(__assign(__assign({}, (this.instance.defaults.headers || {})), (params1.headers || {})), ((params2 && params2.headers) || {})) });
|
|
124
|
+
};
|
|
125
|
+
HttpClient.prototype.createFormData = function (input) {
|
|
126
|
+
return Object.keys(input || {}).reduce(function (formData, key) {
|
|
127
|
+
var property = input[key];
|
|
128
|
+
formData.append(key, property);
|
|
129
|
+
return formData;
|
|
130
|
+
}, new FormData());
|
|
131
|
+
};
|
|
132
|
+
return HttpClient;
|
|
133
|
+
}());
|
|
134
|
+
exports.HttpClient = HttpClient;
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./ShortcutApi"), exports);
|
|
14
|
+
__exportStar(require("./generated/data-contracts"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@useshortcut/client",
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
|
+
"description": "A Promise based library to the Shortcut (formerly Clubhouse) REST API",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib"
|
|
9
|
+
],
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/useshortcut/shortcut-client-js/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/useshortcut/shortcut-client-js",
|
|
14
|
+
"readme": "https://github.com/useshortcut/shortcut-client-js#readme",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/useshortcut/shortcut-client-js.git"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "yarn build:client && tsc",
|
|
22
|
+
"build:client": "swagger-typescript-api -p ./schema/shortcut.swagger.json -o ./src/generated --clean-output --axios --modular --templates ./templates",
|
|
23
|
+
"build:docs": "typedoc ./src",
|
|
24
|
+
"sync:schema": "wget https://shortcut.com/api/rest/v3/shortcut.swagger.json --destination ./schema/shortcut.swagger.json && yarn validate:schema",
|
|
25
|
+
"validate:schema": "swagger-cli validate ./schema/shortcut.swagger.json",
|
|
26
|
+
"validate:examples": "npx tsc examples/*.ts --noEmit",
|
|
27
|
+
"lint": "eslint 'src/**/*.{js,ts}'",
|
|
28
|
+
"test": "jest",
|
|
29
|
+
"prepublishOnly": "yarn build"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"axios": "^0.21.4",
|
|
33
|
+
"form-data": "^4.0.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/jest": "^27.0.1",
|
|
37
|
+
"@types/node": "^16.9.2",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^4.31.1",
|
|
39
|
+
"@typescript-eslint/parser": "^4.31.1",
|
|
40
|
+
"eslint": "^7.32.0",
|
|
41
|
+
"eslint-config-airbnb-base": "^14.2.1",
|
|
42
|
+
"eslint-config-prettier": "^8.3.0",
|
|
43
|
+
"eslint-plugin-import": "^2.24.2",
|
|
44
|
+
"eslint-plugin-jest": "^24.4.2",
|
|
45
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
46
|
+
"jest": "^27.2.0",
|
|
47
|
+
"node-wget": "^0.4.3",
|
|
48
|
+
"prettier": "2.4.1",
|
|
49
|
+
"rimraf": "^3.0.2",
|
|
50
|
+
"swagger-cli": "^4.0.4",
|
|
51
|
+
"swagger-typescript-api": "9.2.0",
|
|
52
|
+
"ts-jest": "^27.0.5",
|
|
53
|
+
"typedoc": "0.21.9",
|
|
54
|
+
"typedoc-plugin-merge-modules": "3.0.1",
|
|
55
|
+
"typescript": "4.4.3"
|
|
56
|
+
},
|
|
57
|
+
"jest": {
|
|
58
|
+
"preset": "ts-jest",
|
|
59
|
+
"testEnvironment": "node",
|
|
60
|
+
"testPathIgnorePatterns": [
|
|
61
|
+
"<rootDir>/lib/",
|
|
62
|
+
"<rootDir>/node_modules/"
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
}
|