@shortcut/client 1.1.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.
@@ -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,45 @@
1
+ import type { AxiosInstance, AxiosRequestConfig, AxiosResponse, ResponseType } from 'axios';
2
+ export 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 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
+ Text = "text/plain"
28
+ }
29
+ /**
30
+ * @internal
31
+ * @private
32
+ */
33
+ export declare class HttpClient<SecurityDataType = unknown> {
34
+ instance: AxiosInstance;
35
+ private securityData;
36
+ private securityWorker?;
37
+ private secure?;
38
+ private format?;
39
+ constructor({ securityWorker, secure, format, ...axiosConfig }?: ApiConfig<SecurityDataType>);
40
+ setSecurityData: (data: SecurityDataType | null) => void;
41
+ protected mergeRequestParams(params1: AxiosRequestConfig, params2?: AxiosRequestConfig): AxiosRequestConfig;
42
+ protected stringifyFormItem(formItem: unknown): string;
43
+ protected createFormData(input: Record<string, unknown>): FormData;
44
+ request: <T = any, _E = any>({ secure, path, type, query, format, body, ...params }: FullRequestParams) => Promise<AxiosResponse<T, any>>;
45
+ }
@@ -0,0 +1,98 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __rest = (this && this.__rest) || function (s, e) {
22
+ var t = {};
23
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
24
+ t[p] = s[p];
25
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
26
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
27
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
28
+ t[p[i]] = s[p[i]];
29
+ }
30
+ return t;
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.HttpClient = exports.ContentType = void 0;
34
+ const axios_1 = require("axios");
35
+ var ContentType;
36
+ (function (ContentType) {
37
+ ContentType["Json"] = "application/json";
38
+ ContentType["FormData"] = "multipart/form-data";
39
+ ContentType["UrlEncoded"] = "application/x-www-form-urlencoded";
40
+ ContentType["Text"] = "text/plain";
41
+ })(ContentType || (exports.ContentType = ContentType = {}));
42
+ /**
43
+ * @internal
44
+ * @private
45
+ */
46
+ class HttpClient {
47
+ constructor(_a = {}) {
48
+ var { securityWorker, secure, format } = _a, axiosConfig = __rest(_a, ["securityWorker", "secure", "format"]);
49
+ this.securityData = null;
50
+ this.setSecurityData = (data) => {
51
+ this.securityData = data;
52
+ };
53
+ this.request = (_b) => __awaiter(this, void 0, void 0, function* () {
54
+ var { secure, path, type, query, format, body } = _b, params = __rest(_b, ["secure", "path", "type", "query", "format", "body"]);
55
+ const secureParams = ((typeof secure === 'boolean' ? secure : this.secure) &&
56
+ this.securityWorker &&
57
+ (yield this.securityWorker(this.securityData))) ||
58
+ {};
59
+ const requestParams = this.mergeRequestParams(params, secureParams);
60
+ const responseFormat = format || this.format || undefined;
61
+ if (type === ContentType.FormData && body && body !== null && typeof body === 'object') {
62
+ body = this.createFormData(body);
63
+ }
64
+ if (type === ContentType.Text && body && body !== null && typeof body !== 'string') {
65
+ body = JSON.stringify(body);
66
+ }
67
+ return this.instance.request(Object.assign(Object.assign({}, requestParams), { headers: Object.assign(Object.assign({}, (requestParams.headers || {})), (type && type !== ContentType.FormData ? { 'Content-Type': type } : {})), params: query, responseType: responseFormat, data: body, url: path }));
68
+ });
69
+ this.instance = axios_1.default.create(Object.assign(Object.assign({}, axiosConfig), { baseURL: axiosConfig.baseURL || 'https://api.app.shortcut.com' }));
70
+ this.secure = secure;
71
+ this.format = format;
72
+ this.securityWorker = securityWorker;
73
+ }
74
+ mergeRequestParams(params1, params2) {
75
+ const method = params1.method || (params2 && params2.method);
76
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, this.instance.defaults), params1), (params2 || {})), { headers: Object.assign(Object.assign(Object.assign({}, ((method && this.instance.defaults.headers[method.toLowerCase()]) || {})), (params1.headers || {})), ((params2 && params2.headers) || {})) });
77
+ }
78
+ stringifyFormItem(formItem) {
79
+ if (typeof formItem === 'object' && formItem !== null) {
80
+ return JSON.stringify(formItem);
81
+ }
82
+ else {
83
+ return `${formItem}`;
84
+ }
85
+ }
86
+ createFormData(input) {
87
+ return Object.keys(input || {}).reduce((formData, key) => {
88
+ const property = input[key];
89
+ const propertyContent = property instanceof Array ? property : [property];
90
+ for (const formItem of propertyContent) {
91
+ const isFileType = formItem instanceof Blob;
92
+ formData.append(key, isFileType ? formItem : this.stringifyFormItem(formItem));
93
+ }
94
+ return formData;
95
+ }, new FormData());
96
+ }
97
+ }
98
+ exports.HttpClient = HttpClient;
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { ShortcutClient as default } from './ShortcutClient';
2
+ export * from './ShortcutClient';
3
+ export * from './generated/data-contracts';
package/lib/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.default = void 0;
18
+ var ShortcutClient_1 = require("./ShortcutClient");
19
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return ShortcutClient_1.ShortcutClient; } });
20
+ __exportStar(require("./ShortcutClient"), exports);
21
+ __exportStar(require("./generated/data-contracts"), exports);
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@shortcut/client",
3
+ "version": "1.1.0",
4
+ "description": "A Promise based library to the Shortcut 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 && yarn build:add-typedoc-comments && tsc",
22
+ "build:client": "swagger-typescript-api -p ./schema/shortcut.swagger.json -o ./src/generated --clean-output --axios --modular --templates ./templates",
23
+ "build:add-typedoc-comments": "npx jscodeshift -t scripts/add-typedoc-comments.ts --extensions=ts --parser=ts src/generated/**",
24
+ "build:docs": "typedoc ./src --exclude 'src/__tests__/**'",
25
+ "validate:examples": "npx tsc examples/*.ts --noEmit",
26
+ "prepublishOnly": "yarn build",
27
+ "sync:schema": "curl --silent https://developer.shortcut.com/api/rest/v3/shortcut.swagger.json --output ./schema/shortcut.swagger.json && yarn validate:schema",
28
+ "validate:schema": "swagger-cli validate ./schema/shortcut.swagger.json",
29
+ "lint": "eslint 'src/**/*.{js,ts}'",
30
+ "test": "jest",
31
+ "format": "prettier --write -l *.{json,md,prettierrc} '{src,scripts}/**/*.ts'",
32
+ "format:check": "prettier --check *.{json,md,prettierrc} '{src,scripts}/**/*.ts'"
33
+ },
34
+ "dependencies": {
35
+ "axios": "^1.5.0"
36
+ },
37
+ "devDependencies": {
38
+ "@types/jest": "^29.5.4",
39
+ "@types/jscodeshift": "0.11.6",
40
+ "@types/node": "^20.5.7",
41
+ "@typescript-eslint/eslint-plugin": "^6.5.0",
42
+ "@typescript-eslint/parser": "^6.5.0",
43
+ "eslint": "^8.48.0",
44
+ "eslint-config-airbnb-base": "^15.0.0",
45
+ "eslint-config-prettier": "^9.0.0",
46
+ "eslint-plugin-import": "^2.28.1",
47
+ "eslint-plugin-jest": "^27.2.3",
48
+ "eslint-plugin-prettier": "^5.0.0",
49
+ "jest": "^29.6.4",
50
+ "jscodeshift": "^0.15.0",
51
+ "prettier": "^3.0.3",
52
+ "rimraf": "^5.0.1",
53
+ "stream-to-blob": "^2.0.1",
54
+ "swagger-cli": "^4.0.4",
55
+ "swagger-typescript-api": "^13.0.3",
56
+ "ts-jest": "^29.1.1",
57
+ "typedoc": "0.25.0",
58
+ "typedoc-plugin-merge-modules": "5.1.0",
59
+ "typescript": "^5.2.2"
60
+ },
61
+ "jest": {
62
+ "preset": "ts-jest",
63
+ "testEnvironment": "node",
64
+ "testPathIgnorePatterns": [
65
+ "<rootDir>/lib/",
66
+ "<rootDir>/node_modules/"
67
+ ]
68
+ }
69
+ }