api-def 0.12.0-alpha.39 → 0.12.0-alpha.40
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/cjs/ApiTypes.d.ts +2 -1
- package/cjs/backend/AxiosRequestBackend.js +36 -1
- package/cjs/backend/FetchRequestBackend.js +2 -1
- package/cjs/cache/ClientCacheBackend.d.ts +6 -0
- package/cjs/cache/ClientCaching.d.ts +10 -0
- package/cjs/cache/{Caching.js → ClientCaching.js} +17 -17
- package/cjs/cache/LocalForageClientCacheBackend.d.ts +9 -0
- package/cjs/{tests/state.test.js → cache/LocalForageClientCacheBackend.js} +52 -52
- package/cjs/cache/LocalStorageClientCacheBackend.d.ts +7 -0
- package/cjs/cache/{LocalStorageCacheBackend.js → LocalStorageClientCacheBackend.js} +14 -14
- package/cjs/index.d.ts +4 -4
- package/cjs/index.js +10 -10
- package/cjs/middleware/ClientCacheMiddleware.d.ts +7 -0
- package/cjs/middleware/{CacheMiddleware.js → ClientCacheMiddleware.js} +16 -14
- package/esm/ApiTypes.d.ts +2 -1
- package/esm/backend/AxiosRequestBackend.js +25 -1
- package/esm/backend/FetchRequestBackend.js +2 -1
- package/esm/cache/ClientCacheBackend.d.ts +6 -0
- package/esm/cache/ClientCaching.d.ts +10 -0
- package/esm/cache/{Caching.js → ClientCaching.js} +12 -12
- package/esm/cache/LocalForageClientCacheBackend.d.ts +9 -0
- package/esm/cache/LocalForageClientCacheBackend.js +36 -0
- package/esm/cache/LocalStorageClientCacheBackend.d.ts +7 -0
- package/esm/cache/{LocalStorageCacheBackend.js → LocalStorageClientCacheBackend.js} +8 -8
- package/esm/index.d.ts +4 -4
- package/esm/index.js +4 -4
- package/esm/middleware/ClientCacheMiddleware.d.ts +7 -0
- package/esm/middleware/{CacheMiddleware.js → ClientCacheMiddleware.js} +14 -12
- package/package.json +3 -3
- package/cjs/cache/CacheBackend.d.ts +0 -6
- package/cjs/cache/Caching.d.ts +0 -10
- package/cjs/cache/LocalForageCacheBackend.d.ts +0 -9
- package/cjs/cache/LocalForageCacheBackend.js +0 -23
- package/cjs/cache/LocalStorageCacheBackend.d.ts +0 -7
- package/cjs/middleware/CacheMiddleware.d.ts +0 -7
- package/cjs/tests/api.test.js +0 -166
- package/cjs/tests/axios.test.d.ts +0 -1
- package/cjs/tests/axios.test.js +0 -94
- package/cjs/tests/backend.test.d.ts +0 -1
- package/cjs/tests/backend.test.js +0 -92
- package/cjs/tests/bodyTypes.test.d.ts +0 -1
- package/cjs/tests/bodyTypes.test.js +0 -58
- package/cjs/tests/mock/MockApi.d.ts +0 -16
- package/cjs/tests/mock/MockApi.js +0 -67
- package/cjs/tests/params.test.d.ts +0 -1
- package/cjs/tests/params.test.js +0 -147
- package/cjs/tests/retry.test.d.ts +0 -1
- package/cjs/tests/retry.test.js +0 -134
- package/cjs/tests/state.test.d.ts +0 -1
- package/cjs/tests/streaming.test.d.ts +0 -1
- package/cjs/tests/streaming.test.js +0 -207
- package/cjs/tests/validation.test.d.ts +0 -1
- package/cjs/tests/validation.test.js +0 -124
- package/esm/cache/CacheBackend.d.ts +0 -6
- package/esm/cache/CacheBackend.js +0 -1
- package/esm/cache/Caching.d.ts +0 -10
- package/esm/cache/LocalForageCacheBackend.d.ts +0 -9
- package/esm/cache/LocalForageCacheBackend.js +0 -19
- package/esm/cache/LocalStorageCacheBackend.d.ts +0 -7
- package/esm/middleware/CacheMiddleware.d.ts +0 -7
- package/esm/tests/api.test.d.ts +0 -1
- package/esm/tests/api.test.js +0 -108
- package/esm/tests/axios.test.d.ts +0 -1
- package/esm/tests/axios.test.js +0 -51
- package/esm/tests/backend.test.d.ts +0 -1
- package/esm/tests/backend.test.js +0 -49
- package/esm/tests/bodyTypes.test.d.ts +0 -1
- package/esm/tests/bodyTypes.test.js +0 -21
- package/esm/tests/mock/MockApi.d.ts +0 -16
- package/esm/tests/mock/MockApi.js +0 -64
- package/esm/tests/params.test.d.ts +0 -1
- package/esm/tests/params.test.js +0 -88
- package/esm/tests/retry.test.d.ts +0 -1
- package/esm/tests/retry.test.js +0 -77
- package/esm/tests/state.test.d.ts +0 -1
- package/esm/tests/state.test.js +0 -52
- package/esm/tests/streaming.test.d.ts +0 -1
- package/esm/tests/streaming.test.js +0 -123
- package/esm/tests/validation.test.d.ts +0 -1
- package/esm/tests/validation.test.js +0 -81
- /package/cjs/cache/{CacheBackend.js → ClientCacheBackend.js} +0 -0
- /package/{cjs/tests/api.test.d.ts → esm/cache/ClientCacheBackend.js} +0 -0
|
@@ -1,124 +0,0 @@
|
|
|
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["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 zod = require("zod");
|
|
40
|
-
var Api_1 = require("../Api");
|
|
41
|
-
var api = new Api_1.Api({
|
|
42
|
-
baseUrl: "httpstat.us",
|
|
43
|
-
name: "Example API",
|
|
44
|
-
mocking: {
|
|
45
|
-
enabled: true,
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
var queryReturnEndpoint = api
|
|
49
|
-
.endpoint()
|
|
50
|
-
.queryOf(zod.object({
|
|
51
|
-
test: zod.string(),
|
|
52
|
-
}))
|
|
53
|
-
.responseOf(zod.object({
|
|
54
|
-
name: zod.string(),
|
|
55
|
-
query: zod.object({
|
|
56
|
-
test: zod.string().refine(function (v) { return !Number.isNaN(Number(v)) && Number(v) < 255; }, "below 255"),
|
|
57
|
-
}),
|
|
58
|
-
}))
|
|
59
|
-
.build({
|
|
60
|
-
name: "Get 200",
|
|
61
|
-
id: "200",
|
|
62
|
-
method: "get",
|
|
63
|
-
path: "/200",
|
|
64
|
-
mocking: {
|
|
65
|
-
handler: function (req, res) {
|
|
66
|
-
return res.status(200).send({ name: "Test", query: req.query });
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
it("validation", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
71
|
-
var res, error, e_1, error, e_2;
|
|
72
|
-
var _a, _b;
|
|
73
|
-
return __generator(this, function (_c) {
|
|
74
|
-
switch (_c.label) {
|
|
75
|
-
case 0: return [4 /*yield*/, queryReturnEndpoint.submit({
|
|
76
|
-
query: {
|
|
77
|
-
test: "200",
|
|
78
|
-
},
|
|
79
|
-
})];
|
|
80
|
-
case 1:
|
|
81
|
-
res = _c.sent();
|
|
82
|
-
expect(res.data.query.test).toBe("200");
|
|
83
|
-
error = void 0;
|
|
84
|
-
_c.label = 2;
|
|
85
|
-
case 2:
|
|
86
|
-
_c.trys.push([2, 4, , 5]);
|
|
87
|
-
return [4 /*yield*/, queryReturnEndpoint.submit({
|
|
88
|
-
query: {
|
|
89
|
-
test: {},
|
|
90
|
-
},
|
|
91
|
-
})];
|
|
92
|
-
case 3:
|
|
93
|
-
_c.sent();
|
|
94
|
-
return [3 /*break*/, 5];
|
|
95
|
-
case 4:
|
|
96
|
-
e_1 = _c.sent();
|
|
97
|
-
error = e_1;
|
|
98
|
-
return [3 /*break*/, 5];
|
|
99
|
-
case 5:
|
|
100
|
-
expect(error.code).toBe("validation/query-validate-error");
|
|
101
|
-
expect((_a = error.issues) === null || _a === void 0 ? void 0 : _a[0].code).toBe("invalid_type");
|
|
102
|
-
error = void 0;
|
|
103
|
-
_c.label = 6;
|
|
104
|
-
case 6:
|
|
105
|
-
_c.trys.push([6, 8, , 9]);
|
|
106
|
-
return [4 /*yield*/, queryReturnEndpoint.submit({
|
|
107
|
-
query: {
|
|
108
|
-
test: "300",
|
|
109
|
-
},
|
|
110
|
-
})];
|
|
111
|
-
case 7:
|
|
112
|
-
_c.sent();
|
|
113
|
-
return [3 /*break*/, 9];
|
|
114
|
-
case 8:
|
|
115
|
-
e_2 = _c.sent();
|
|
116
|
-
error = e_2;
|
|
117
|
-
return [3 /*break*/, 9];
|
|
118
|
-
case 9:
|
|
119
|
-
expect(error.code).toBe("validation/response-validate-error");
|
|
120
|
-
expect((_b = error.issues) === null || _b === void 0 ? void 0 : _b[0].message).toBe("below 255");
|
|
121
|
-
return [2 /*return*/];
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}); });
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/cache/Caching.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { CacheBackend } from "./CacheBackend";
|
|
2
|
-
export declare const setCacheBackend: (backend: CacheBackend) => void;
|
|
3
|
-
export declare const DEFAULT_CACHE_EXPIRY: number;
|
|
4
|
-
export declare const clearCache: () => Promise<void>;
|
|
5
|
-
export interface CacheEntry {
|
|
6
|
-
data: any;
|
|
7
|
-
expiry: number | null;
|
|
8
|
-
}
|
|
9
|
-
export declare const setCachedItem: <T>(key: string, value: T, expiry?: number) => Promise<T>;
|
|
10
|
-
export declare const getCachedItem: <T = any>(key: string) => Promise<T | undefined>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { CacheBackend } from "./CacheBackend";
|
|
2
|
-
export default class LocalForageCacheBackend implements CacheBackend {
|
|
3
|
-
private readonly store;
|
|
4
|
-
constructor(localforage: any);
|
|
5
|
-
clear(): Promise<void>;
|
|
6
|
-
getItem<T>(key: string): Promise<T | null>;
|
|
7
|
-
removeItem(key: string): Promise<void>;
|
|
8
|
-
setItem<T>(key: string, value: T): Promise<void>;
|
|
9
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export default class LocalForageCacheBackend {
|
|
2
|
-
constructor(localforage) {
|
|
3
|
-
this.store = localforage.createInstance({
|
|
4
|
-
name: "requestCache",
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
clear() {
|
|
8
|
-
return this.store.clear();
|
|
9
|
-
}
|
|
10
|
-
getItem(key) {
|
|
11
|
-
return this.store.getItem(key);
|
|
12
|
-
}
|
|
13
|
-
removeItem(key) {
|
|
14
|
-
return this.store.removeItem(key);
|
|
15
|
-
}
|
|
16
|
-
setItem(key, value) {
|
|
17
|
-
return this.store.setItem(key, value);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { CacheBackend } from "./CacheBackend";
|
|
2
|
-
export default class LocalStorageCacheBackend implements CacheBackend {
|
|
3
|
-
clear(): Promise<void>;
|
|
4
|
-
getItem<T>(key: string): Promise<T | null>;
|
|
5
|
-
removeItem(key: string): Promise<void>;
|
|
6
|
-
setItem<T>(key: string, value: T): Promise<void>;
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { RequestMiddleware } from "../ApiTypes";
|
|
2
|
-
export interface CacheMiddlewareOptions {
|
|
3
|
-
defaultExpiry?: number;
|
|
4
|
-
predicate?: () => boolean;
|
|
5
|
-
}
|
|
6
|
-
declare const CacheMiddleware: (options?: CacheMiddlewareOptions) => RequestMiddleware;
|
|
7
|
-
export default CacheMiddleware;
|
package/esm/tests/api.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/tests/api.test.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import * as qs from "qs";
|
|
11
|
-
import { Api } from "../Api";
|
|
12
|
-
import { RequestMethod } from "../ApiConstants";
|
|
13
|
-
import { postIdVerifStatus } from "./mock/MockApi";
|
|
14
|
-
const api = new Api({
|
|
15
|
-
baseUrl: "example.com",
|
|
16
|
-
name: "Example API",
|
|
17
|
-
mocking: {
|
|
18
|
-
enabled: true,
|
|
19
|
-
},
|
|
20
|
-
middleware: [
|
|
21
|
-
{
|
|
22
|
-
beforeSend: (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
-
context.updateQuery({
|
|
24
|
-
test: "abc",
|
|
25
|
-
});
|
|
26
|
-
}),
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
});
|
|
30
|
-
const queryReturnEndpoint = api
|
|
31
|
-
.endpoint()
|
|
32
|
-
.queryOf()
|
|
33
|
-
.build({
|
|
34
|
-
name: "Fetch Users",
|
|
35
|
-
id: "fetchUsers",
|
|
36
|
-
method: RequestMethod.GET,
|
|
37
|
-
path: "/users",
|
|
38
|
-
mocking: {
|
|
39
|
-
handler: (req, res) => {
|
|
40
|
-
return res.status(200).send([{ name: "Test", query: req.query }]);
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
it("URL is properly constructed", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
const res = yield postIdVerifStatus.submit({
|
|
46
|
-
body: {
|
|
47
|
-
forceReset: true,
|
|
48
|
-
validationService: 1,
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
expect(res.data.url).toBe("https://example.com/id-verif/verif-status");
|
|
52
|
-
}));
|
|
53
|
-
it("query as string", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
-
const res = yield queryReturnEndpoint.submit({
|
|
55
|
-
query: "test=1&id=3",
|
|
56
|
-
});
|
|
57
|
-
expect(res.data).toEqual([
|
|
58
|
-
{
|
|
59
|
-
name: "Test",
|
|
60
|
-
query: {
|
|
61
|
-
test: "abc",
|
|
62
|
-
id: "3",
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
]);
|
|
66
|
-
}));
|
|
67
|
-
it("qs", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
-
let res = yield queryReturnEndpoint.submit({
|
|
69
|
-
query: "id[0]=1&id[1]=2",
|
|
70
|
-
});
|
|
71
|
-
expect(res.data).toEqual([
|
|
72
|
-
{
|
|
73
|
-
name: "Test",
|
|
74
|
-
query: {
|
|
75
|
-
test: "abc",
|
|
76
|
-
"id[0]": "1",
|
|
77
|
-
"id[1]": "2",
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
]);
|
|
81
|
-
res = yield queryReturnEndpoint.submit({
|
|
82
|
-
query: "id[0]=1&id[1]=2",
|
|
83
|
-
queryHandling: qs,
|
|
84
|
-
});
|
|
85
|
-
expect(res.data).toEqual([
|
|
86
|
-
{
|
|
87
|
-
name: "Test",
|
|
88
|
-
query: {
|
|
89
|
-
test: "abc",
|
|
90
|
-
id: ["1", "2"],
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
]);
|
|
94
|
-
}));
|
|
95
|
-
/*it("infer params in typescript", async (t) => {
|
|
96
|
-
const endpoint = mockApi.endpoint()
|
|
97
|
-
.build({
|
|
98
|
-
method: "get",
|
|
99
|
-
id: "test",
|
|
100
|
-
path: "/test/:id",
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
endpoint.submit({
|
|
104
|
-
params: {
|
|
105
|
-
id: "test",
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
});*/
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/tests/axios.test.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import axios from "axios";
|
|
11
|
-
import { Api, setRequestBackend } from "../Api";
|
|
12
|
-
import AxiosRequestBackend from "../backend/AxiosRequestBackend";
|
|
13
|
-
import FetchRequestBackend from "../backend/FetchRequestBackend";
|
|
14
|
-
const cleanResponse = (response) => {
|
|
15
|
-
response.headers = undefined;
|
|
16
|
-
response.__lowercaseHeaders = undefined;
|
|
17
|
-
return response;
|
|
18
|
-
};
|
|
19
|
-
it("request backends output", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
const api = new Api({
|
|
21
|
-
baseUrl: "httpstat.us",
|
|
22
|
-
name: "Example API",
|
|
23
|
-
requestBackend: new AxiosRequestBackend(axios),
|
|
24
|
-
middleware: [
|
|
25
|
-
{
|
|
26
|
-
beforeSend: (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
-
context.updateQuery({
|
|
28
|
-
id: "abc",
|
|
29
|
-
});
|
|
30
|
-
}),
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
});
|
|
34
|
-
const fetchPage = api.endpoint().queryOf().build({
|
|
35
|
-
name: "Get 200",
|
|
36
|
-
id: "200",
|
|
37
|
-
method: "get",
|
|
38
|
-
path: "/200",
|
|
39
|
-
});
|
|
40
|
-
expect(fetchPage.name).toBe("Get 200");
|
|
41
|
-
setRequestBackend(new FetchRequestBackend());
|
|
42
|
-
const fetchResult = yield fetchPage.submit({
|
|
43
|
-
query: "test",
|
|
44
|
-
});
|
|
45
|
-
setRequestBackend(new AxiosRequestBackend(axios));
|
|
46
|
-
const axiosResult = yield fetchPage.submit({
|
|
47
|
-
query: "test",
|
|
48
|
-
});
|
|
49
|
-
expect(cleanResponse(fetchResult)).toEqual(cleanResponse(axiosResult));
|
|
50
|
-
expect(fetchResult.url).toBe("https://httpstat.us/200?test=true&id=abc");
|
|
51
|
-
}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import axios from "axios";
|
|
11
|
-
import { Api, setRequestBackend } from "../Api";
|
|
12
|
-
import AxiosRequestBackend from "../backend/AxiosRequestBackend";
|
|
13
|
-
import FetchRequestBackend from "../backend/FetchRequestBackend";
|
|
14
|
-
const cleanResponse = (response) => {
|
|
15
|
-
response.headers = undefined;
|
|
16
|
-
response.__lowercaseHeaders = undefined;
|
|
17
|
-
return response;
|
|
18
|
-
};
|
|
19
|
-
it("request backends output", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
const api = new Api({
|
|
21
|
-
baseUrl: "httpstat.us",
|
|
22
|
-
name: "Example API",
|
|
23
|
-
middleware: [
|
|
24
|
-
{
|
|
25
|
-
beforeSend: (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
-
context.updateQuery({
|
|
27
|
-
id: "abc",
|
|
28
|
-
});
|
|
29
|
-
}),
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
});
|
|
33
|
-
const fetchPage = api.endpoint().queryOf().build({
|
|
34
|
-
name: "Get 200",
|
|
35
|
-
id: "200",
|
|
36
|
-
method: "get",
|
|
37
|
-
path: "/200",
|
|
38
|
-
});
|
|
39
|
-
setRequestBackend(new FetchRequestBackend());
|
|
40
|
-
const fetchResult = yield fetchPage.submit({
|
|
41
|
-
query: "test",
|
|
42
|
-
});
|
|
43
|
-
setRequestBackend(new AxiosRequestBackend(axios));
|
|
44
|
-
const axiosResult = yield fetchPage.submit({
|
|
45
|
-
query: "test",
|
|
46
|
-
});
|
|
47
|
-
expect(cleanResponse(fetchResult)).toEqual(cleanResponse(axiosResult));
|
|
48
|
-
expect(fetchResult.url).toBe("https://httpstat.us/200?test=true&id=abc");
|
|
49
|
-
}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { postFormUrlEncoded } from "./mock/MockApi";
|
|
11
|
-
it("correctly parses body for form url encoded request", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
-
const res = yield postFormUrlEncoded.submit({
|
|
13
|
-
body: {
|
|
14
|
-
test: 123,
|
|
15
|
-
b: "test",
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
expect(res.data).toEqual(["test=123&b=test"]);
|
|
19
|
-
}));
|
|
20
|
-
// @ts-expect-error
|
|
21
|
-
const a = { data: 123 };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Api } from "../../Api";
|
|
2
|
-
declare const api: Api;
|
|
3
|
-
export declare const fetchRequiresToken: import("../..").Endpoint<unknown, undefined, undefined, undefined, import("../..").State, "/requires-token", import("../..").RawHeaders | undefined, import("../..").RawHeaders | undefined>;
|
|
4
|
-
export declare const postFormUrlEncoded: import("../..").Endpoint<string[], undefined, undefined, {
|
|
5
|
-
test: number;
|
|
6
|
-
b: string;
|
|
7
|
-
}, import("../..").State, "/send-data", import("../..").RawHeaders | undefined, import("../..").RawHeaders | undefined>;
|
|
8
|
-
export declare const postIdVerifStatus: import("../..").Endpoint<{
|
|
9
|
-
transactionStatus: any;
|
|
10
|
-
transactionId?: string;
|
|
11
|
-
verifPayload?: any;
|
|
12
|
-
}, undefined, undefined, {
|
|
13
|
-
validationService: 1;
|
|
14
|
-
forceReset: boolean;
|
|
15
|
-
}, import("../..").State, "/id-verif/verif-status", import("../..").RawHeaders | undefined, import("../..").RawHeaders | undefined>;
|
|
16
|
-
export default api;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Api } from "../../Api";
|
|
2
|
-
import { RequestMethod } from "../../ApiConstants";
|
|
3
|
-
const api = new Api({
|
|
4
|
-
baseUrl: "example.com",
|
|
5
|
-
name: "Example API",
|
|
6
|
-
mocking: {
|
|
7
|
-
enabled: true,
|
|
8
|
-
},
|
|
9
|
-
});
|
|
10
|
-
export const fetchRequiresToken = api.endpoint().build({
|
|
11
|
-
name: "Requires Token",
|
|
12
|
-
id: "fetchRequiresToken",
|
|
13
|
-
method: RequestMethod.GET,
|
|
14
|
-
path: "/requires-token",
|
|
15
|
-
mocking: {
|
|
16
|
-
handler: (req, res) => {
|
|
17
|
-
if (!req.headers.token) {
|
|
18
|
-
return res.status(400).send({
|
|
19
|
-
code: "auth/invalid-token",
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return res.status(200).send({ hello: true });
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
export const postFormUrlEncoded = api
|
|
27
|
-
.endpoint()
|
|
28
|
-
.bodyOf()
|
|
29
|
-
.responseOf()
|
|
30
|
-
.build({
|
|
31
|
-
id: "sendFormUrlEncoded",
|
|
32
|
-
method: "post",
|
|
33
|
-
path: "/send-data",
|
|
34
|
-
config: {
|
|
35
|
-
headers: {
|
|
36
|
-
"Content-type": "application/x-www-form-urlencoded",
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
mocking: {
|
|
40
|
-
handler: (req, res) => {
|
|
41
|
-
return res.status(200).send([req.body.toString()]);
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
export const postIdVerifStatus = api
|
|
46
|
-
.endpoint()
|
|
47
|
-
.bodyOf()
|
|
48
|
-
.responseOf()
|
|
49
|
-
.build({
|
|
50
|
-
id: "id-verif-status",
|
|
51
|
-
method: RequestMethod.POST,
|
|
52
|
-
path: "/id-verif/verif-status",
|
|
53
|
-
responseType: "json",
|
|
54
|
-
config: {
|
|
55
|
-
acceptableStatus: [200],
|
|
56
|
-
retry: false, // outcome screen has it's own retry
|
|
57
|
-
},
|
|
58
|
-
mocking: {
|
|
59
|
-
handler: (req, res) => {
|
|
60
|
-
return res.status(200).send({ url: req.url });
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
export default api;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/tests/params.test.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { Api } from "../Api";
|
|
11
|
-
import { RequestMethod } from "../ApiConstants";
|
|
12
|
-
const api = new Api({
|
|
13
|
-
baseUrl: "example.com",
|
|
14
|
-
name: "Example API",
|
|
15
|
-
mocking: {
|
|
16
|
-
enabled: true,
|
|
17
|
-
},
|
|
18
|
-
middleware: [
|
|
19
|
-
{
|
|
20
|
-
beforeSend: (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
context.updateQuery({
|
|
22
|
-
test: "abc",
|
|
23
|
-
});
|
|
24
|
-
}),
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
});
|
|
28
|
-
const withColons = api
|
|
29
|
-
.endpoint()
|
|
30
|
-
.paramsOf()
|
|
31
|
-
.build({
|
|
32
|
-
name: "Fetch Users",
|
|
33
|
-
id: "fetchUsers",
|
|
34
|
-
method: RequestMethod.GET,
|
|
35
|
-
path: "/users/:id/:sub_id",
|
|
36
|
-
mocking: {
|
|
37
|
-
handler: (req, res) => {
|
|
38
|
-
return res.status(200).send([{ name: "Test", data: req.url }]);
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
const withBrackets = api
|
|
43
|
-
.endpoint()
|
|
44
|
-
.paramsOf()
|
|
45
|
-
.build({
|
|
46
|
-
name: "Fetch Users",
|
|
47
|
-
id: "fetchUsers",
|
|
48
|
-
method: RequestMethod.GET,
|
|
49
|
-
path: "/users/{id}/{sub_id}",
|
|
50
|
-
mocking: {
|
|
51
|
-
handler: (req, res) => {
|
|
52
|
-
return res.status(200).send([{ name: "Test", data: req.url }]);
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
it("should throw error if missing param", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
-
yield expect((() => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
-
const res = yield withColons.submit({
|
|
59
|
-
params: {
|
|
60
|
-
id: "123",
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
return res;
|
|
64
|
-
}))()).rejects.toThrowError("[api-def] Not all path params have been resolved: '/users/123/:sub_id'");
|
|
65
|
-
yield expect((() => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
-
const res = yield withBrackets.submit({
|
|
67
|
-
params: {
|
|
68
|
-
id: "123",
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
return res;
|
|
72
|
-
}))()).rejects.toThrowError("[api-def] Not all path params have been resolved: '/users/123/{sub_id}'");
|
|
73
|
-
// This should not throw an error
|
|
74
|
-
const res = yield withColons.submit({
|
|
75
|
-
params: {
|
|
76
|
-
id: "123",
|
|
77
|
-
sub_id: "456",
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
expect(res.data).toEqual([{ name: "Test", data: "https://example.com/users/123/456" }]);
|
|
81
|
-
const res2 = yield withBrackets.submit({
|
|
82
|
-
params: {
|
|
83
|
-
id: "123",
|
|
84
|
-
sub_id: "456",
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
expect(res2.data).toEqual([{ name: "Test", data: "https://example.com/users/123/456" }]);
|
|
88
|
-
}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|