snaptrade-typescript-sdk 1.0.1 → 2.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/.konfig/generate-id.txt +1 -0
- package/.konfigignore +2 -0
- package/README.md +57 -36
- package/api.ts +2190 -1889
- package/base.ts +2 -2
- package/common.ts +2 -2
- package/configuration.ts +2 -2
- package/dist/api.d.ts +1481 -1098
- package/dist/api.js +1679 -1833
- package/dist/api.js.map +1 -1
- package/dist/base.d.ts +2 -2
- package/dist/base.js +2 -2
- package/dist/common.d.ts +2 -2
- package/dist/common.js +3 -3
- package/dist/configuration.d.ts +2 -2
- package/dist/configuration.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +105 -0
- package/dist/index.test.js.map +1 -0
- package/dist/jest.config.d.ts +3 -0
- package/dist/jest.config.js +13 -0
- package/dist/jest.config.js.map +1 -0
- package/git_push.sh +2 -2
- package/index.test.ts +70 -0
- package/index.ts +2 -2
- package/jest.config.ts +11 -0
- package/package.json +13 -8
- package/tsconfig.test.json +6 -0
- package/.openapi-generator/FILES +0 -12
- package/.openapi-generator/VERSION +0 -1
- package/.openapi-generator-ignore +0 -23
- package/.vscode/settings.json +0 -3
package/dist/base.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* The version of the OpenAPI document: 1.0.0
|
|
6
6
|
* Contact: api@snaptrade.com
|
|
7
7
|
*
|
|
8
|
-
* NOTE: This class is auto generated by
|
|
9
|
-
* https://
|
|
8
|
+
* NOTE: This class is auto generated by Konfig (https://konfigthis.com).
|
|
9
|
+
* https://konfigthis.com
|
|
10
10
|
* Do not edit the class manually.
|
|
11
11
|
*/
|
|
12
12
|
import { Configuration } from "./configuration";
|
package/dist/base.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* The version of the OpenAPI document: 1.0.0
|
|
9
9
|
* Contact: api@snaptrade.com
|
|
10
10
|
*
|
|
11
|
-
* NOTE: This class is auto generated by
|
|
12
|
-
* https://
|
|
11
|
+
* NOTE: This class is auto generated by Konfig (https://konfigthis.com).
|
|
12
|
+
* https://konfigthis.com
|
|
13
13
|
* Do not edit the class manually.
|
|
14
14
|
*/
|
|
15
15
|
var __extends = (this && this.__extends) || (function () {
|
package/dist/common.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* The version of the OpenAPI document: 1.0.0
|
|
6
6
|
* Contact: api@snaptrade.com
|
|
7
7
|
*
|
|
8
|
-
* NOTE: This class is auto generated by
|
|
9
|
-
* https://
|
|
8
|
+
* NOTE: This class is auto generated by Konfig (https://konfigthis.com).
|
|
9
|
+
* https://konfigthis.com
|
|
10
10
|
* Do not edit the class manually.
|
|
11
11
|
*/
|
|
12
12
|
import { Configuration } from "./configuration";
|
package/dist/common.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* The version of the OpenAPI document: 1.0.0
|
|
9
9
|
* Contact: api@snaptrade.com
|
|
10
10
|
*
|
|
11
|
-
* NOTE: This class is auto generated by
|
|
12
|
-
* https://
|
|
11
|
+
* NOTE: This class is auto generated by Konfig (https://konfigthis.com).
|
|
12
|
+
* https://konfigthis.com
|
|
13
13
|
* Do not edit the class manually.
|
|
14
14
|
*/
|
|
15
15
|
var __assign = (this && this.__assign) || function () {
|
|
@@ -38,7 +38,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
39
39
|
function step(op) {
|
|
40
40
|
if (f) throw new TypeError("Generator is already executing.");
|
|
41
|
-
while (_) try {
|
|
41
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
42
42
|
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;
|
|
43
43
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
44
44
|
switch (op[0]) {
|
package/dist/configuration.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* The version of the OpenAPI document: 1.0.0
|
|
6
6
|
* Contact: api@snaptrade.com
|
|
7
7
|
*
|
|
8
|
-
* NOTE: This class is auto generated by
|
|
9
|
-
* https://
|
|
8
|
+
* NOTE: This class is auto generated by Konfig (https://konfigthis.com).
|
|
9
|
+
* https://konfigthis.com
|
|
10
10
|
* Do not edit the class manually.
|
|
11
11
|
*/
|
|
12
12
|
export interface ConfigurationParameters {
|
package/dist/configuration.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* The version of the OpenAPI document: 1.0.0
|
|
9
9
|
* Contact: api@snaptrade.com
|
|
10
10
|
*
|
|
11
|
-
* NOTE: This class is auto generated by
|
|
12
|
-
* https://
|
|
11
|
+
* NOTE: This class is auto generated by Konfig (https://konfigthis.com).
|
|
12
|
+
* https://konfigthis.com
|
|
13
13
|
* Do not edit the class manually.
|
|
14
14
|
*/
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* The version of the OpenAPI document: 1.0.0
|
|
6
6
|
* Contact: api@snaptrade.com
|
|
7
7
|
*
|
|
8
|
-
* NOTE: This class is auto generated by
|
|
9
|
-
* https://
|
|
8
|
+
* NOTE: This class is auto generated by Konfig (https://konfigthis.com).
|
|
9
|
+
* https://konfigthis.com
|
|
10
10
|
* Do not edit the class manually.
|
|
11
11
|
*/
|
|
12
12
|
export * from "./api";
|
package/dist/index.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* The version of the OpenAPI document: 1.0.0
|
|
9
9
|
* Contact: api@snaptrade.com
|
|
10
10
|
*
|
|
11
|
-
* NOTE: This class is auto generated by
|
|
12
|
-
* https://
|
|
11
|
+
* NOTE: This class is auto generated by Konfig (https://konfigthis.com).
|
|
12
|
+
* https://konfigthis.com
|
|
13
13
|
* Do not edit the class manually.
|
|
14
14
|
*/
|
|
15
15
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
var api_1 = require("./api");
|
|
40
|
+
var configuration_1 = require("./configuration");
|
|
41
|
+
function uuid() {
|
|
42
|
+
var d = new Date().getTime(); //Timestamp
|
|
43
|
+
var d2 = (typeof performance !== "undefined" &&
|
|
44
|
+
performance.now &&
|
|
45
|
+
performance.now() * 1000) ||
|
|
46
|
+
0; //Time in microseconds since page-load or 0 if unsupported
|
|
47
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
48
|
+
var r = Math.random() * 16; //random number between 0 and 16
|
|
49
|
+
if (d > 0) {
|
|
50
|
+
//Use timestamp until depleted
|
|
51
|
+
r = (d + r) % 16 | 0;
|
|
52
|
+
d = Math.floor(d / 16);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
//Use microseconds since page-load if supported
|
|
56
|
+
r = (d2 + r) % 16 | 0;
|
|
57
|
+
d2 = Math.floor(d2 / 16);
|
|
58
|
+
}
|
|
59
|
+
return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
it("getting started", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
63
|
+
var config, apiStatusApiInst, status, userId, authenticationApiInst, userSecret, data, accountInformationApi, holdings, deleteResponse;
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
switch (_a.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
config = new configuration_1.Configuration({
|
|
68
|
+
consumerKey: process.env.SNAPTRADE_CONSUMER_KEY,
|
|
69
|
+
clientId: process.env.SNAPTRADE_CLIENT_ID,
|
|
70
|
+
});
|
|
71
|
+
apiStatusApiInst = new api_1.APIStatusApi(config);
|
|
72
|
+
return [4 /*yield*/, apiStatusApiInst.check()];
|
|
73
|
+
case 1:
|
|
74
|
+
status = _a.sent();
|
|
75
|
+
console.log("status:", status.data);
|
|
76
|
+
userId = uuid();
|
|
77
|
+
authenticationApiInst = new api_1.AuthenticationApi(config);
|
|
78
|
+
return [4 /*yield*/, authenticationApiInst.registerSnapTradeUser({
|
|
79
|
+
userId: userId,
|
|
80
|
+
})];
|
|
81
|
+
case 2:
|
|
82
|
+
userSecret = (_a.sent()).data.userSecret;
|
|
83
|
+
// Note: A user secret is only generated once. It's required to access
|
|
84
|
+
// resources for certain endpoints.
|
|
85
|
+
console.log("userSecret:", userSecret);
|
|
86
|
+
return [4 /*yield*/, authenticationApiInst.loginSnapTradeUser(userId, userSecret)];
|
|
87
|
+
case 3:
|
|
88
|
+
data = (_a.sent()).data;
|
|
89
|
+
if (!("redirectURI" in data))
|
|
90
|
+
throw Error("Should have gotten redirect URI");
|
|
91
|
+
console.log("redirectURI:", data.redirectURI);
|
|
92
|
+
accountInformationApi = new api_1.AccountInformationApi(config);
|
|
93
|
+
return [4 /*yield*/, accountInformationApi.getAllUserHoldings(userId, userSecret)];
|
|
94
|
+
case 4:
|
|
95
|
+
holdings = (_a.sent()).data;
|
|
96
|
+
console.log("holdings:", holdings);
|
|
97
|
+
return [4 /*yield*/, authenticationApiInst.deleteSnapTradeUser(userId)];
|
|
98
|
+
case 5:
|
|
99
|
+
deleteResponse = (_a.sent()).data;
|
|
100
|
+
console.log("deleteResponse:", deleteResponse);
|
|
101
|
+
return [2 /*return*/];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}); });
|
|
105
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../index.test.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var config = {
|
|
4
|
+
verbose: true,
|
|
5
|
+
preset: "ts-jest",
|
|
6
|
+
testEnvironment: "node",
|
|
7
|
+
testPathIgnorePatterns: ["dist/"],
|
|
8
|
+
transform: {
|
|
9
|
+
"^.+\\.ts?$": ["ts-jest", { tsconfig: "./tsconfig.test.json" }],
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
exports.default = config;
|
|
13
|
+
//# sourceMappingURL=jest.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jest.config.js","sourceRoot":"","sources":["../jest.config.ts"],"names":[],"mappings":";;AACA,IAAM,MAAM,GAA0B;IACpC,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,SAAS;IACjB,eAAe,EAAE,MAAM;IACvB,sBAAsB,EAAE,CAAC,OAAO,CAAC;IACjC,SAAS,EAAE;QACT,YAAY,EAAE,CAAC,SAAS,EAAE,EAAE,QAAQ,EAAE,sBAAsB,EAAE,CAAC;KAChE;CACF,CAAC;AACF,kBAAe,MAAM,CAAC"}
|
package/git_push.sh
CHANGED
|
@@ -14,12 +14,12 @@ if [ "$git_host" = "" ]; then
|
|
|
14
14
|
fi
|
|
15
15
|
|
|
16
16
|
if [ "$git_user_id" = "" ]; then
|
|
17
|
-
git_user_id="
|
|
17
|
+
git_user_id="passiv"
|
|
18
18
|
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
|
|
19
19
|
fi
|
|
20
20
|
|
|
21
21
|
if [ "$git_repo_id" = "" ]; then
|
|
22
|
-
git_repo_id="
|
|
22
|
+
git_repo_id="snaptrade-sdks/tree/main/sdks/typescript"
|
|
23
23
|
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
|
|
24
24
|
fi
|
|
25
25
|
|
package/index.test.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { APIStatusApi, AuthenticationApi, AccountInformationApi } from "./api";
|
|
2
|
+
import { Configuration } from "./configuration";
|
|
3
|
+
|
|
4
|
+
function uuid() {
|
|
5
|
+
var d = new Date().getTime(); //Timestamp
|
|
6
|
+
var d2 =
|
|
7
|
+
(typeof performance !== "undefined" &&
|
|
8
|
+
performance.now &&
|
|
9
|
+
performance.now() * 1000) ||
|
|
10
|
+
0; //Time in microseconds since page-load or 0 if unsupported
|
|
11
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
12
|
+
var r = Math.random() * 16; //random number between 0 and 16
|
|
13
|
+
if (d > 0) {
|
|
14
|
+
//Use timestamp until depleted
|
|
15
|
+
r = (d + r) % 16 | 0;
|
|
16
|
+
d = Math.floor(d / 16);
|
|
17
|
+
} else {
|
|
18
|
+
//Use microseconds since page-load if supported
|
|
19
|
+
r = (d2 + r) % 16 | 0;
|
|
20
|
+
d2 = Math.floor(d2 / 16);
|
|
21
|
+
}
|
|
22
|
+
return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
it("getting started", async () => {
|
|
27
|
+
// 1) Initialize a configuration with your clientID and consumerKey.
|
|
28
|
+
const config = new Configuration({
|
|
29
|
+
consumerKey: process.env.SNAPTRADE_CONSUMER_KEY,
|
|
30
|
+
clientId: process.env.SNAPTRADE_CLIENT_ID,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// 2) Check that the client is able to make a request to the API server.
|
|
34
|
+
const apiStatusApiInst = new APIStatusApi(config);
|
|
35
|
+
const status = await apiStatusApiInst.check();
|
|
36
|
+
console.log("status:", status.data);
|
|
37
|
+
|
|
38
|
+
// 3) Create a new user on SnapTrade
|
|
39
|
+
const userId = uuid();
|
|
40
|
+
const authenticationApiInst = new AuthenticationApi(config);
|
|
41
|
+
const { userSecret } = (
|
|
42
|
+
await authenticationApiInst.registerSnapTradeUser({
|
|
43
|
+
userId,
|
|
44
|
+
})
|
|
45
|
+
).data;
|
|
46
|
+
|
|
47
|
+
// Note: A user secret is only generated once. It's required to access
|
|
48
|
+
// resources for certain endpoints.
|
|
49
|
+
console.log("userSecret:", userSecret);
|
|
50
|
+
|
|
51
|
+
// 4) Get a redirect URI. Users will need this to connect
|
|
52
|
+
const data = (
|
|
53
|
+
await authenticationApiInst.loginSnapTradeUser(userId, userSecret)
|
|
54
|
+
).data;
|
|
55
|
+
if (!("redirectURI" in data)) throw Error("Should have gotten redirect URI");
|
|
56
|
+
console.log("redirectURI:", data.redirectURI);
|
|
57
|
+
|
|
58
|
+
// 5) Obtaining account holdings data
|
|
59
|
+
const accountInformationApi = new AccountInformationApi(config);
|
|
60
|
+
const holdings = (
|
|
61
|
+
await accountInformationApi.getAllUserHoldings(userId, userSecret)
|
|
62
|
+
).data;
|
|
63
|
+
console.log("holdings:", holdings);
|
|
64
|
+
|
|
65
|
+
// 6) Deleting a user
|
|
66
|
+
const deleteResponse = (
|
|
67
|
+
await authenticationApiInst.deleteSnapTradeUser(userId)
|
|
68
|
+
).data;
|
|
69
|
+
console.log("deleteResponse:", deleteResponse);
|
|
70
|
+
});
|
package/index.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* The version of the OpenAPI document: 1.0.0
|
|
8
8
|
* Contact: api@snaptrade.com
|
|
9
9
|
*
|
|
10
|
-
* NOTE: This class is auto generated by
|
|
11
|
-
* https://
|
|
10
|
+
* NOTE: This class is auto generated by Konfig (https://konfigthis.com).
|
|
11
|
+
* https://konfigthis.com
|
|
12
12
|
* Do not edit the class manually.
|
|
13
13
|
*/
|
|
14
14
|
|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Config } from "@jest/types";
|
|
2
|
+
const config: Config.InitialOptions = {
|
|
3
|
+
verbose: true,
|
|
4
|
+
preset: "ts-jest",
|
|
5
|
+
testEnvironment: "node",
|
|
6
|
+
testPathIgnorePatterns: ["dist/"],
|
|
7
|
+
transform: {
|
|
8
|
+
"^.+\\.ts?$": ["ts-jest", { tsconfig: "./tsconfig.test.json" }],
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
export default config;
|
package/package.json
CHANGED
|
@@ -1,31 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "snaptrade-typescript-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"author": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Client for SnapTrade",
|
|
5
|
+
"author": "Konfig",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/
|
|
8
|
+
"url": "https://github.com/passiv/snaptrade-sdks/tree/main/sdks/typescript"
|
|
9
9
|
},
|
|
10
10
|
"keywords": [
|
|
11
11
|
"axios",
|
|
12
12
|
"typescript",
|
|
13
|
-
"
|
|
14
|
-
"openapi-generator",
|
|
13
|
+
"konfig",
|
|
15
14
|
"snaptrade-typescript-sdk"
|
|
16
15
|
],
|
|
17
16
|
"license": "Unlicense",
|
|
18
17
|
"main": "./dist/index.js",
|
|
19
18
|
"typings": "./dist/index.d.ts",
|
|
20
19
|
"scripts": {
|
|
21
|
-
"build": "tsc
|
|
22
|
-
"
|
|
20
|
+
"build": "npm run clean && tsc",
|
|
21
|
+
"clean": "rm -rf dist/",
|
|
22
|
+
"prepare": "npm run build",
|
|
23
|
+
"test": "jest"
|
|
23
24
|
},
|
|
24
25
|
"dependencies": {
|
|
25
26
|
"axios": "^0.26.1"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
29
|
+
"@types/jest": "^29.2.4",
|
|
28
30
|
"@types/node": "^12.11.5",
|
|
31
|
+
"jest": "^29.3.1",
|
|
32
|
+
"ts-jest": "^29.0.3",
|
|
33
|
+
"ts-node": "^10.9.1",
|
|
29
34
|
"typescript": "^4.0"
|
|
30
35
|
}
|
|
31
36
|
}
|
package/.openapi-generator/FILES
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
6.2.1
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# OpenAPI Generator Ignore
|
|
2
|
-
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
|
3
|
-
|
|
4
|
-
# Use this file to prevent files from being overwritten by the generator.
|
|
5
|
-
# The patterns follow closely to .gitignore or .dockerignore.
|
|
6
|
-
|
|
7
|
-
# As an example, the C# client generator defines ApiClient.cs.
|
|
8
|
-
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
|
9
|
-
#ApiClient.cs
|
|
10
|
-
|
|
11
|
-
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
|
12
|
-
#foo/*/qux
|
|
13
|
-
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
|
14
|
-
|
|
15
|
-
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
|
16
|
-
#foo/**/qux
|
|
17
|
-
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
|
18
|
-
|
|
19
|
-
# You can also negate patterns with an exclamation (!).
|
|
20
|
-
# For example, you can ignore all files in a docs folder with the file extension .md:
|
|
21
|
-
#docs/*.md
|
|
22
|
-
# Then explicitly reverse the ignore rule for a single file:
|
|
23
|
-
#!docs/README.md
|
package/.vscode/settings.json
DELETED