@arkyn/server 2.0.1-beta.9 → 2.0.1
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/LICENSE.txt +24 -0
- package/README.md +116 -0
- package/dist/api/__test__/deleteRequest.spec.d.ts +2 -0
- package/dist/api/__test__/deleteRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/deleteRequest.spec.js +84 -0
- package/dist/api/__test__/getRequest.spec.d.ts +2 -0
- package/dist/api/__test__/getRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/getRequest.spec.js +62 -0
- package/dist/api/__test__/inboxFlowRequest.spec.d.ts +2 -0
- package/dist/api/__test__/inboxFlowRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/inboxFlowRequest.spec.js +96 -0
- package/dist/api/__test__/makeRequest.spec.d.ts +2 -0
- package/dist/api/__test__/makeRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/makeRequest.spec.js +80 -0
- package/dist/api/__test__/patchRequest.spec.d.ts +2 -0
- package/dist/api/__test__/patchRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/patchRequest.spec.js +84 -0
- package/dist/api/__test__/postRequest.spec.d.ts +2 -0
- package/dist/api/__test__/postRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/postRequest.spec.js +84 -0
- package/dist/api/__test__/putRequest.spec.d.ts +2 -0
- package/dist/api/__test__/putRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/putRequest.spec.js +84 -0
- package/dist/api/deleteRequest.d.ts +13 -0
- package/dist/api/deleteRequest.d.ts.map +1 -0
- package/dist/api/deleteRequest.js +14 -0
- package/dist/api/getRequest.d.ts +12 -0
- package/dist/api/getRequest.d.ts.map +1 -0
- package/dist/api/getRequest.js +13 -0
- package/dist/api/inboxFlowRequest.d.ts +40 -0
- package/dist/api/inboxFlowRequest.d.ts.map +1 -0
- package/dist/api/inboxFlowRequest.js +63 -0
- package/dist/api/makeRequest.d.ts +38 -0
- package/dist/api/makeRequest.d.ts.map +1 -0
- package/dist/api/makeRequest.js +103 -0
- package/dist/api/patchRequest.d.ts +13 -0
- package/dist/api/patchRequest.d.ts.map +1 -0
- package/dist/api/patchRequest.js +14 -0
- package/dist/api/postRequest.d.ts +13 -0
- package/dist/api/postRequest.d.ts.map +1 -0
- package/dist/api/postRequest.js +14 -0
- package/dist/api/putRequest.d.ts +13 -0
- package/dist/api/putRequest.d.ts.map +1 -0
- package/dist/api/putRequest.js +14 -0
- package/dist/config/__test__/apiInstance.spec.d.ts +2 -0
- package/dist/config/__test__/apiInstance.spec.d.ts.map +1 -0
- package/dist/config/__test__/apiInstance.spec.js +86 -0
- package/dist/config/__test__/inboxFlowInstance.spec.d.ts +2 -0
- package/dist/config/__test__/inboxFlowInstance.spec.d.ts.map +1 -0
- package/dist/config/__test__/inboxFlowInstance.spec.js +48 -0
- package/dist/config/apiInstance.d.ts +80 -0
- package/dist/config/apiInstance.d.ts.map +1 -0
- package/dist/config/apiInstance.js +111 -0
- package/dist/config/inboxFlowInstance.d.ts +44 -0
- package/dist/config/inboxFlowInstance.d.ts.map +1 -0
- package/dist/config/inboxFlowInstance.js +46 -0
- package/dist/http/badResponses/__test__/badGateway.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/badGateway.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/badGateway.spec.js +42 -0
- package/dist/http/badResponses/__test__/badRequest.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/badRequest.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/badRequest.spec.js +40 -0
- package/dist/http/badResponses/__test__/conflict.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/conflict.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/conflict.spec.js +40 -0
- package/dist/http/badResponses/__test__/forbidden.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/forbidden.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/forbidden.spec.js +40 -0
- package/dist/http/badResponses/__test__/notFound.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/notFound.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/notFound.spec.js +40 -0
- package/dist/http/badResponses/__test__/notImplemented.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/notImplemented.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/notImplemented.spec.js +40 -0
- package/dist/http/badResponses/__test__/serverError.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/serverError.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/serverError.spec.js +40 -0
- package/dist/http/badResponses/__test__/unauthorized.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/unauthorized.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/unauthorized.spec.js +40 -0
- package/dist/http/badResponses/__test__/unprocessableEntity.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/unprocessableEntity.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/unprocessableEntity.spec.js +66 -0
- package/dist/http/badResponses/badGateway.d.ts +23 -0
- package/dist/http/badResponses/badGateway.d.ts.map +1 -1
- package/dist/http/badResponses/badGateway.js +24 -1
- package/dist/http/badResponses/badRequest.d.ts +23 -0
- package/dist/http/badResponses/badRequest.d.ts.map +1 -1
- package/dist/http/badResponses/badRequest.js +24 -1
- package/dist/http/badResponses/conflict.d.ts +23 -0
- package/dist/http/badResponses/conflict.d.ts.map +1 -1
- package/dist/http/badResponses/conflict.js +24 -1
- package/dist/http/badResponses/forbidden.d.ts +23 -0
- package/dist/http/badResponses/forbidden.d.ts.map +1 -1
- package/dist/http/badResponses/forbidden.js +25 -2
- package/dist/http/badResponses/notFound.d.ts +23 -0
- package/dist/http/badResponses/notFound.d.ts.map +1 -1
- package/dist/http/badResponses/notFound.js +24 -1
- package/dist/http/badResponses/notImplemented.d.ts +23 -0
- package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
- package/dist/http/badResponses/notImplemented.js +24 -1
- package/dist/http/badResponses/serverError.d.ts +23 -0
- package/dist/http/badResponses/serverError.d.ts.map +1 -1
- package/dist/http/badResponses/serverError.js +24 -1
- package/dist/http/badResponses/unauthorized.d.ts +23 -0
- package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
- package/dist/http/badResponses/unauthorized.js +24 -1
- package/dist/http/badResponses/unprocessableEntity.d.ts +28 -1
- package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
- package/dist/http/badResponses/unprocessableEntity.js +30 -3
- package/dist/http/successResponses/__test__/created.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/created.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/created.spec.js +57 -0
- package/dist/http/successResponses/__test__/found.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/found.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/found.spec.js +57 -0
- package/dist/http/successResponses/__test__/noContent.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/noContent.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/noContent.spec.js +40 -0
- package/dist/http/successResponses/__test__/success.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/success.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/success.spec.js +60 -0
- package/dist/http/successResponses/__test__/updated.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/updated.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/updated.spec.js +60 -0
- package/dist/http/successResponses/created.d.ts +25 -0
- package/dist/http/successResponses/created.d.ts.map +1 -1
- package/dist/http/successResponses/created.js +25 -0
- package/dist/http/successResponses/found.d.ts +28 -0
- package/dist/http/successResponses/found.d.ts.map +1 -1
- package/dist/http/successResponses/found.js +28 -0
- package/dist/http/successResponses/noContent.d.ts +16 -1
- package/dist/http/successResponses/noContent.d.ts.map +1 -1
- package/dist/http/successResponses/noContent.js +16 -8
- package/dist/http/successResponses/success.d.ts +25 -0
- package/dist/http/successResponses/success.d.ts.map +1 -1
- package/dist/http/successResponses/success.js +25 -0
- package/dist/http/successResponses/updated.d.ts +25 -0
- package/dist/http/successResponses/updated.d.ts.map +1 -1
- package/dist/http/successResponses/updated.js +25 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/services/__test__/decodeRequestBody.spec.d.ts +2 -0
- package/dist/services/__test__/decodeRequestBody.spec.d.ts.map +1 -0
- package/dist/services/__test__/decodeRequestBody.spec.js +39 -0
- package/dist/services/__test__/errorHandler.spec.d.ts +2 -0
- package/dist/services/__test__/errorHandler.spec.d.ts.map +1 -0
- package/dist/services/__test__/errorHandler.spec.js +115 -0
- package/dist/services/__test__/formParse.spec.d.ts +2 -0
- package/dist/services/__test__/formParse.spec.d.ts.map +1 -0
- package/dist/services/__test__/formParse.spec.js +78 -0
- package/dist/services/__test__/getCaller.spec.d.ts +2 -0
- package/dist/services/__test__/getCaller.spec.d.ts.map +1 -0
- package/dist/services/__test__/getCaller.spec.js +60 -0
- package/dist/services/__test__/getScopedParams.spec.d.ts +2 -0
- package/dist/services/__test__/getScopedParams.spec.d.ts.map +1 -0
- package/dist/services/__test__/getScopedParams.spec.js +51 -0
- package/dist/services/__test__/schemaValidator.spec.d.ts +2 -0
- package/dist/services/__test__/schemaValidator.spec.d.ts.map +1 -0
- package/dist/services/__test__/schemaValidator.spec.js +89 -0
- package/dist/services/decodeErrorMessageFromRequest.d.ts +17 -0
- package/dist/services/decodeErrorMessageFromRequest.d.ts.map +1 -0
- package/dist/services/decodeErrorMessageFromRequest.js +30 -0
- package/dist/services/decodeRequestBody.d.ts.map +1 -1
- package/dist/services/decodeRequestBody.js +12 -16
- package/dist/services/errorHandler.d.ts +42 -1
- package/dist/services/errorHandler.d.ts.map +1 -1
- package/dist/services/errorHandler.js +42 -0
- package/dist/services/formParse.d.ts.map +1 -1
- package/dist/services/formParse.js +4 -2
- package/dist/services/getCaller.d.ts +17 -0
- package/dist/services/getCaller.d.ts.map +1 -0
- package/dist/services/getCaller.js +45 -0
- package/dist/services/httpDebug.d.ts +35 -0
- package/dist/services/httpDebug.d.ts.map +1 -0
- package/dist/services/httpDebug.js +56 -0
- package/dist/services/schemaValidator.d.ts +13 -0
- package/dist/services/schemaValidator.d.ts.map +1 -0
- package/dist/services/schemaValidator.js +51 -0
- package/package.json +11 -5
- package/src/api/__test__/deleteRequest.spec.ts +107 -0
- package/src/api/__test__/getRequest.spec.ts +76 -0
- package/src/api/__test__/inboxFlowRequest.spec.ts +125 -0
- package/src/api/__test__/makeRequest.spec.ts +121 -0
- package/src/api/__test__/patchRequest.spec.ts +125 -0
- package/src/api/__test__/postRequest.spec.ts +125 -0
- package/src/api/__test__/putRequest.spec.ts +125 -0
- package/src/api/deleteRequest.ts +22 -0
- package/src/api/getRequest.ts +20 -0
- package/src/api/inboxFlowRequest.ts +76 -0
- package/src/api/makeRequest.ts +117 -0
- package/src/api/patchRequest.ts +22 -0
- package/src/api/postRequest.ts +22 -0
- package/src/api/putRequest.ts +22 -0
- package/src/config/__test__/apiInstance.spec.ts +129 -0
- package/src/config/__test__/inboxFlowInstance.spec.ts +61 -0
- package/src/config/apiInstance.ts +148 -0
- package/src/config/inboxFlowInstance.ts +65 -0
- package/src/http/badResponses/__test__/badGateway.spec.ts +50 -0
- package/src/http/badResponses/__test__/badRequest.spec.ts +50 -0
- package/src/http/badResponses/__test__/conflict.spec.ts +50 -0
- package/src/http/badResponses/__test__/forbidden.spec.ts +50 -0
- package/src/http/badResponses/__test__/notFound.spec.ts +50 -0
- package/src/http/badResponses/__test__/notImplemented.spec.ts +50 -0
- package/src/http/badResponses/__test__/serverError.spec.ts +50 -0
- package/src/http/badResponses/__test__/unauthorized.spec.ts +50 -0
- package/src/http/badResponses/__test__/unprocessableEntity.spec.ts +76 -0
- package/src/http/badResponses/badGateway.ts +29 -2
- package/src/http/badResponses/badRequest.ts +29 -2
- package/src/http/badResponses/conflict.ts +29 -2
- package/src/http/badResponses/forbidden.ts +30 -3
- package/src/http/badResponses/notFound.ts +29 -2
- package/src/http/badResponses/notImplemented.ts +29 -2
- package/src/http/badResponses/serverError.ts +29 -2
- package/src/http/badResponses/unauthorized.ts +29 -2
- package/src/http/badResponses/unprocessableEntity.ts +33 -2
- package/src/http/successResponses/__test__/created.spec.ts +65 -0
- package/src/http/successResponses/__test__/found.spec.ts +65 -0
- package/src/http/successResponses/__test__/noContent.spec.ts +49 -0
- package/src/http/successResponses/__test__/success.spec.ts +68 -0
- package/src/http/successResponses/__test__/updated.spec.ts +68 -0
- package/src/http/successResponses/created.ts +31 -2
- package/src/http/successResponses/found.ts +32 -0
- package/src/http/successResponses/noContent.ts +20 -11
- package/src/http/successResponses/success.ts +31 -2
- package/src/http/successResponses/updated.ts +31 -2
- package/src/index.ts +9 -1
- package/src/services/__test__/decodeRequestBody.spec.ts +51 -0
- package/src/services/__test__/errorHandler.spec.ts +133 -0
- package/src/services/__test__/formParse.spec.ts +96 -0
- package/src/services/__test__/getCaller.spec.ts +78 -0
- package/src/services/__test__/getScopedParams.spec.ts +68 -0
- package/src/services/__test__/schemaValidator.spec.ts +106 -0
- package/src/services/decodeErrorMessageFromRequest.ts +36 -0
- package/src/services/decodeRequestBody.ts +11 -15
- package/src/services/errorHandler.ts +45 -1
- package/src/services/formParse.ts +4 -5
- package/src/services/getCaller.ts +39 -18
- package/src/services/httpDebug.ts +46 -5
- package/vitest.config.ts +5 -0
- package/dist/http/httpDebug.d.ts +0 -3
- package/dist/http/httpDebug.d.ts.map +0 -1
- package/dist/http/httpDebug.js +0 -15
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { postRequest } from "../postRequest";
|
|
3
|
+
global.fetch = vi.fn();
|
|
4
|
+
describe("postRequest", () => {
|
|
5
|
+
it("should return success response for a successful POST request", async () => {
|
|
6
|
+
const mockResponse = { message: "Resource created successfully" };
|
|
7
|
+
const mockBody = { name: "New Resource" };
|
|
8
|
+
fetch.mockResolvedValueOnce({
|
|
9
|
+
ok: true,
|
|
10
|
+
status: 201,
|
|
11
|
+
json: async () => mockResponse,
|
|
12
|
+
});
|
|
13
|
+
const response = await postRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
14
|
+
expect(response).toEqual({
|
|
15
|
+
success: true,
|
|
16
|
+
status: 201,
|
|
17
|
+
message: "Resource created successfully",
|
|
18
|
+
response: mockResponse,
|
|
19
|
+
cause: null,
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
it("should return failed response for a failed POST request", async () => {
|
|
23
|
+
const mockErrorResponse = { error: "Invalid data" };
|
|
24
|
+
const mockBody = { name: "" };
|
|
25
|
+
fetch.mockResolvedValueOnce({
|
|
26
|
+
ok: false,
|
|
27
|
+
status: 400,
|
|
28
|
+
json: async () => mockErrorResponse,
|
|
29
|
+
});
|
|
30
|
+
const response = await postRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
31
|
+
expect(response.success).toBe(false);
|
|
32
|
+
expect(response.status).toBe(400);
|
|
33
|
+
expect(response.response).toEqual(mockErrorResponse);
|
|
34
|
+
expect(response.message).toBeDefined();
|
|
35
|
+
});
|
|
36
|
+
it("should handle network errors gracefully", async () => {
|
|
37
|
+
const mockBody = { name: "New Resource" };
|
|
38
|
+
fetch.mockRejectedValueOnce(new Error("Network Error"));
|
|
39
|
+
const response = await postRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
40
|
+
expect(response).toEqual({
|
|
41
|
+
success: false,
|
|
42
|
+
status: 0,
|
|
43
|
+
message: "Network error or request failed",
|
|
44
|
+
response: null,
|
|
45
|
+
cause: "Network Error",
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
it("should handle invalid JSON response gracefully", async () => {
|
|
49
|
+
const mockBody = { name: "New Resource" };
|
|
50
|
+
fetch.mockResolvedValueOnce({
|
|
51
|
+
ok: true,
|
|
52
|
+
status: 201,
|
|
53
|
+
json: async () => {
|
|
54
|
+
throw new Error("Invalid JSON");
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
const response = await postRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
58
|
+
expect(response).toEqual({
|
|
59
|
+
success: true,
|
|
60
|
+
status: 201,
|
|
61
|
+
message: "Resource created successfully",
|
|
62
|
+
response: null,
|
|
63
|
+
cause: null,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
it("should send headers and body correctly", async () => {
|
|
67
|
+
const mockResponse = { message: "Resource created successfully" };
|
|
68
|
+
const mockBody = { name: "New Resource" };
|
|
69
|
+
const mockHeaders = { Authorization: "Bearer token" };
|
|
70
|
+
fetch.mockResolvedValueOnce({
|
|
71
|
+
ok: true,
|
|
72
|
+
status: 201,
|
|
73
|
+
json: async () => mockResponse,
|
|
74
|
+
});
|
|
75
|
+
const response = await postRequest("https://api.example.com/resource", mockHeaders, mockBody);
|
|
76
|
+
expect(response).toEqual({
|
|
77
|
+
success: true,
|
|
78
|
+
status: 201,
|
|
79
|
+
message: "Resource created successfully",
|
|
80
|
+
response: mockResponse,
|
|
81
|
+
cause: null,
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"putRequest.spec.d.ts","sourceRoot":"","sources":["../../../src/api/__test__/putRequest.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from "vitest";
|
|
2
|
+
import { putRequest } from "../putRequest";
|
|
3
|
+
global.fetch = vi.fn();
|
|
4
|
+
describe("putRequest", () => {
|
|
5
|
+
it("should return success response for a successful PUT request", async () => {
|
|
6
|
+
const mockResponse = { message: "Resource updated successfully" };
|
|
7
|
+
const mockBody = { name: "Updated Resource" };
|
|
8
|
+
fetch.mockResolvedValueOnce({
|
|
9
|
+
ok: true,
|
|
10
|
+
status: 200,
|
|
11
|
+
json: async () => mockResponse,
|
|
12
|
+
});
|
|
13
|
+
const response = await putRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
14
|
+
expect(response).toEqual({
|
|
15
|
+
success: true,
|
|
16
|
+
status: 200,
|
|
17
|
+
message: "Resource updated successfully",
|
|
18
|
+
response: mockResponse,
|
|
19
|
+
cause: null,
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
it("should return failed response for a failed PUT request", async () => {
|
|
23
|
+
const mockErrorResponse = { error: "Invalid data" };
|
|
24
|
+
const mockBody = { name: "" };
|
|
25
|
+
fetch.mockResolvedValueOnce({
|
|
26
|
+
ok: false,
|
|
27
|
+
status: 400,
|
|
28
|
+
json: async () => mockErrorResponse,
|
|
29
|
+
});
|
|
30
|
+
const response = await putRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
31
|
+
expect(response.success).toBe(false);
|
|
32
|
+
expect(response.status).toBe(400);
|
|
33
|
+
expect(response.response).toEqual(mockErrorResponse);
|
|
34
|
+
expect(response.message).toBeDefined();
|
|
35
|
+
});
|
|
36
|
+
it("should handle network errors gracefully", async () => {
|
|
37
|
+
const mockBody = { name: "Updated Resource" };
|
|
38
|
+
fetch.mockRejectedValueOnce(new Error("Network Error"));
|
|
39
|
+
const response = await putRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
40
|
+
expect(response).toEqual({
|
|
41
|
+
success: false,
|
|
42
|
+
status: 0,
|
|
43
|
+
message: "Network error or request failed",
|
|
44
|
+
response: null,
|
|
45
|
+
cause: "Network Error",
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
it("should handle invalid JSON response gracefully", async () => {
|
|
49
|
+
const mockBody = { name: "Updated Resource" };
|
|
50
|
+
fetch.mockResolvedValueOnce({
|
|
51
|
+
ok: true,
|
|
52
|
+
status: 200,
|
|
53
|
+
json: async () => {
|
|
54
|
+
throw new Error("Invalid JSON");
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
const response = await putRequest("https://api.example.com/resource", { "Content-Type": "application/json" }, mockBody);
|
|
58
|
+
expect(response).toEqual({
|
|
59
|
+
success: true,
|
|
60
|
+
status: 200,
|
|
61
|
+
message: "Resource updated successfully",
|
|
62
|
+
response: null,
|
|
63
|
+
cause: null,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
it("should send headers and body correctly", async () => {
|
|
67
|
+
const mockResponse = { message: "Resource updated successfully" };
|
|
68
|
+
const mockBody = { name: "Updated Resource" };
|
|
69
|
+
const mockHeaders = { Authorization: "Bearer token" };
|
|
70
|
+
fetch.mockResolvedValueOnce({
|
|
71
|
+
ok: true,
|
|
72
|
+
status: 200,
|
|
73
|
+
json: async () => mockResponse,
|
|
74
|
+
});
|
|
75
|
+
const response = await putRequest("https://api.example.com/resource", mockHeaders, mockBody);
|
|
76
|
+
expect(response).toEqual({
|
|
77
|
+
success: true,
|
|
78
|
+
status: 200,
|
|
79
|
+
message: "Resource updated successfully",
|
|
80
|
+
response: mockResponse,
|
|
81
|
+
cause: null,
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ApiResponseDTO } from "@arkyn/types";
|
|
2
|
+
/**
|
|
3
|
+
* Sends a DELETE request to the specified URL with optional headers and body.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The expected type of the response data.
|
|
6
|
+
* @param {string} url - The URL to send the DELETE request to.
|
|
7
|
+
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
+
* @param {any} [body] - Optional body to include in the request.
|
|
9
|
+
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
10
|
+
*/
|
|
11
|
+
declare function deleteRequest<T = any>(url: string, headers?: HeadersInit, body?: any): Promise<ApiResponseDTO<T>>;
|
|
12
|
+
export { deleteRequest };
|
|
13
|
+
//# sourceMappingURL=deleteRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteRequest.d.ts","sourceRoot":"","sources":["../../src/api/deleteRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGnD;;;;;;;;GAQG;AAEH,iBAAe,aAAa,CAAC,CAAC,GAAG,GAAG,EAClC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,EACzB,IAAI,CAAC,EAAE,GAAG,GACT,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAE5B;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { makeRequest } from "./makeRequest";
|
|
2
|
+
/**
|
|
3
|
+
* Sends a DELETE request to the specified URL with optional headers and body.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The expected type of the response data.
|
|
6
|
+
* @param {string} url - The URL to send the DELETE request to.
|
|
7
|
+
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
+
* @param {any} [body] - Optional body to include in the request.
|
|
9
|
+
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
10
|
+
*/
|
|
11
|
+
async function deleteRequest(url, headers = {}, body) {
|
|
12
|
+
return makeRequest("DELETE", url, headers, body);
|
|
13
|
+
}
|
|
14
|
+
export { deleteRequest };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ApiResponseDTO } from "@arkyn/types";
|
|
2
|
+
/**
|
|
3
|
+
* Sends a GET request to the specified URL with optional headers.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The expected type of the response data.
|
|
6
|
+
* @param {string} url - The URL to send the GET request to.
|
|
7
|
+
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
+
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
9
|
+
*/
|
|
10
|
+
declare function getRequest<T = any>(url: string, headers?: HeadersInit): Promise<ApiResponseDTO<T>>;
|
|
11
|
+
export { getRequest };
|
|
12
|
+
//# sourceMappingURL=getRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRequest.d.ts","sourceRoot":"","sources":["../../src/api/getRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGnD;;;;;;;GAOG;AAEH,iBAAe,UAAU,CAAC,CAAC,GAAG,GAAG,EAC/B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAE5B;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { makeRequest } from "./makeRequest";
|
|
2
|
+
/**
|
|
3
|
+
* Sends a GET request to the specified URL with optional headers.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The expected type of the response data.
|
|
6
|
+
* @param {string} url - The URL to send the GET request to.
|
|
7
|
+
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
+
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
9
|
+
*/
|
|
10
|
+
async function getRequest(url, headers = {}) {
|
|
11
|
+
return makeRequest("GET", url, headers);
|
|
12
|
+
}
|
|
13
|
+
export { getRequest };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
type ConfigProps = {
|
|
2
|
+
status: number;
|
|
3
|
+
method: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | "ERROR";
|
|
4
|
+
request: string;
|
|
5
|
+
response: string;
|
|
6
|
+
token: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Sends a request to the inbox flow API with the provided configuration.
|
|
10
|
+
*
|
|
11
|
+
* @param config - The configuration object for the request.
|
|
12
|
+
* @param config.status - The HTTP status code associated with the request.
|
|
13
|
+
* @param config.method - The HTTP method used for the request. Can be "POST", "GET", "PUT", "DELETE", "PATCH", or "ERROR".
|
|
14
|
+
* @param config.request - The request payload or details as a string.
|
|
15
|
+
* @param config.response - The response payload or details as a string.
|
|
16
|
+
* @param config.token - The token associated with the request for authentication or identification.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* - This function retrieves the inbox flow configuration using `InboxFlowInstance.getInboxConfig()`.
|
|
20
|
+
* - If the configuration is not available, the function will return early without performing any action.
|
|
21
|
+
* - In a development environment (`NODE_ENV === "development"`), the function will also return early.
|
|
22
|
+
* - The request is sent as a POST request to the inbox API URL with the provided configuration details.
|
|
23
|
+
* - If an error occurs during the request, it will be logged using the `httpDebug` service.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const config = {
|
|
28
|
+
* status: 200,
|
|
29
|
+
* method: "POST",
|
|
30
|
+
* request: JSON.stringify({ key: "value" }),
|
|
31
|
+
* response: JSON.stringify({ success: true }),
|
|
32
|
+
* token: "example-token",
|
|
33
|
+
* };
|
|
34
|
+
*
|
|
35
|
+
* await inboxFlowRequest(config);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
declare function inboxFlowRequest(config: ConfigProps): Promise<void>;
|
|
39
|
+
export { inboxFlowRequest };
|
|
40
|
+
//# sourceMappingURL=inboxFlowRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inboxFlowRequest.d.ts","sourceRoot":"","sources":["../../src/api/inboxFlowRequest.ts"],"names":[],"mappings":"AAGA,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,iBAAe,gBAAgB,CAAC,MAAM,EAAE,WAAW,iBA+BlD;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { InboxFlowInstance } from "../config/inboxFlowInstance";
|
|
2
|
+
import { httpDebug } from "../services/httpDebug";
|
|
3
|
+
/**
|
|
4
|
+
* Sends a request to the inbox flow API with the provided configuration.
|
|
5
|
+
*
|
|
6
|
+
* @param config - The configuration object for the request.
|
|
7
|
+
* @param config.status - The HTTP status code associated with the request.
|
|
8
|
+
* @param config.method - The HTTP method used for the request. Can be "POST", "GET", "PUT", "DELETE", "PATCH", or "ERROR".
|
|
9
|
+
* @param config.request - The request payload or details as a string.
|
|
10
|
+
* @param config.response - The response payload or details as a string.
|
|
11
|
+
* @param config.token - The token associated with the request for authentication or identification.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* - This function retrieves the inbox flow configuration using `InboxFlowInstance.getInboxConfig()`.
|
|
15
|
+
* - If the configuration is not available, the function will return early without performing any action.
|
|
16
|
+
* - In a development environment (`NODE_ENV === "development"`), the function will also return early.
|
|
17
|
+
* - The request is sent as a POST request to the inbox API URL with the provided configuration details.
|
|
18
|
+
* - If an error occurs during the request, it will be logged using the `httpDebug` service.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const config = {
|
|
23
|
+
* status: 200,
|
|
24
|
+
* method: "POST",
|
|
25
|
+
* request: JSON.stringify({ key: "value" }),
|
|
26
|
+
* response: JSON.stringify({ success: true }),
|
|
27
|
+
* token: "example-token",
|
|
28
|
+
* };
|
|
29
|
+
*
|
|
30
|
+
* await inboxFlowRequest(config);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
async function inboxFlowRequest(config) {
|
|
34
|
+
const inboxFlowInstance = InboxFlowInstance.getInboxConfig();
|
|
35
|
+
if (!inboxFlowInstance)
|
|
36
|
+
return;
|
|
37
|
+
const { inboxChannelId, inboxUserToken, inboxApiUrl } = inboxFlowInstance;
|
|
38
|
+
const { status, method, request, response, token } = config;
|
|
39
|
+
if (process.env.NODE_ENV === "development")
|
|
40
|
+
return;
|
|
41
|
+
try {
|
|
42
|
+
const body = JSON.stringify({
|
|
43
|
+
status,
|
|
44
|
+
channelId: inboxChannelId,
|
|
45
|
+
method,
|
|
46
|
+
token,
|
|
47
|
+
request,
|
|
48
|
+
response,
|
|
49
|
+
});
|
|
50
|
+
await fetch(inboxApiUrl, {
|
|
51
|
+
method: "POST",
|
|
52
|
+
body,
|
|
53
|
+
headers: {
|
|
54
|
+
"Content-Type": "application/json",
|
|
55
|
+
Authorization: `Bearer ${inboxUserToken}`,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
httpDebug("inboxFlowRequest", "Error sending inbox flow request", err);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export { inboxFlowRequest };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ApiResponseDTO } from "@arkyn/types";
|
|
2
|
+
/**
|
|
3
|
+
* Makes an HTTP request using the Fetch API and returns a standardized response.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The expected type of the response data.
|
|
6
|
+
* @param method - The HTTP method to use for the request. Supported methods are:
|
|
7
|
+
* - "POST": Create a new resource.
|
|
8
|
+
* - "PUT": Update an existing resource.
|
|
9
|
+
* - "DELETE": Remove a resource.
|
|
10
|
+
* - "PATCH": Partially update a resource.
|
|
11
|
+
* - "GET": Retrieve a resource.
|
|
12
|
+
* @param url - The URL to which the request is sent.
|
|
13
|
+
* @param headers - Optional headers to include in the request. Defaults to an empty object.
|
|
14
|
+
* @param body - Optional body to include in the request. Should be serializable to JSON.
|
|
15
|
+
* @returns A promise that resolves to an `ApiResponseDTO<T>` object containing:
|
|
16
|
+
* - `success`: A boolean indicating whether the request was successful.
|
|
17
|
+
* - `status`: The HTTP status code of the response.
|
|
18
|
+
* - `message`: A message describing the result of the request.
|
|
19
|
+
* - `response`: The parsed JSON response data, or `null` if parsing fails.
|
|
20
|
+
* - `cause`: Additional error information, if applicable.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { makeRequest } from "./makeRequest";
|
|
25
|
+
*
|
|
26
|
+
* async function fetchData() {
|
|
27
|
+
* const response = await makeRequest("GET", "https://api.example.com/data");
|
|
28
|
+
* if (response.success) {
|
|
29
|
+
* console.log("Data:", response.response);
|
|
30
|
+
* } else {
|
|
31
|
+
* console.error("Error:", response.message);
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare function makeRequest<T = any>(method: "POST" | "PUT" | "DELETE" | "PATCH" | "GET", url: string, headers?: HeadersInit, body?: any): Promise<ApiResponseDTO<T>>;
|
|
37
|
+
export { makeRequest };
|
|
38
|
+
//# sourceMappingURL=makeRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeRequest.d.ts","sourceRoot":"","sources":["../../src/api/makeRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAInD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,iBAAe,WAAW,CAAC,CAAC,GAAG,GAAG,EAChC,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,EACnD,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,EACzB,IAAI,CAAC,EAAE,GAAG,GACT,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAsE5B;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { InboxFlowInstance } from "../config/inboxFlowInstance";
|
|
2
|
+
import { inboxFlowRequest } from "./inboxFlowRequest";
|
|
3
|
+
/**
|
|
4
|
+
* Makes an HTTP request using the Fetch API and returns a standardized response.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The expected type of the response data.
|
|
7
|
+
* @param method - The HTTP method to use for the request. Supported methods are:
|
|
8
|
+
* - "POST": Create a new resource.
|
|
9
|
+
* - "PUT": Update an existing resource.
|
|
10
|
+
* - "DELETE": Remove a resource.
|
|
11
|
+
* - "PATCH": Partially update a resource.
|
|
12
|
+
* - "GET": Retrieve a resource.
|
|
13
|
+
* @param url - The URL to which the request is sent.
|
|
14
|
+
* @param headers - Optional headers to include in the request. Defaults to an empty object.
|
|
15
|
+
* @param body - Optional body to include in the request. Should be serializable to JSON.
|
|
16
|
+
* @returns A promise that resolves to an `ApiResponseDTO<T>` object containing:
|
|
17
|
+
* - `success`: A boolean indicating whether the request was successful.
|
|
18
|
+
* - `status`: The HTTP status code of the response.
|
|
19
|
+
* - `message`: A message describing the result of the request.
|
|
20
|
+
* - `response`: The parsed JSON response data, or `null` if parsing fails.
|
|
21
|
+
* - `cause`: Additional error information, if applicable.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { makeRequest } from "./makeRequest";
|
|
26
|
+
*
|
|
27
|
+
* async function fetchData() {
|
|
28
|
+
* const response = await makeRequest("GET", "https://api.example.com/data");
|
|
29
|
+
* if (response.success) {
|
|
30
|
+
* console.log("Data:", response.response);
|
|
31
|
+
* } else {
|
|
32
|
+
* console.error("Error:", response.message);
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
async function makeRequest(method, url, headers = {}, body) {
|
|
38
|
+
const successMessage = {
|
|
39
|
+
POST: "Resource created successfully",
|
|
40
|
+
PUT: "Resource updated successfully",
|
|
41
|
+
DELETE: "Resource deleted successfully",
|
|
42
|
+
PATCH: "Resource patched successfully",
|
|
43
|
+
GET: "Request successful",
|
|
44
|
+
};
|
|
45
|
+
try {
|
|
46
|
+
const response = await fetch(url, {
|
|
47
|
+
method,
|
|
48
|
+
headers: {
|
|
49
|
+
...headers,
|
|
50
|
+
"Content-Type": "application/json",
|
|
51
|
+
},
|
|
52
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
53
|
+
});
|
|
54
|
+
const status = response.status;
|
|
55
|
+
let data = null;
|
|
56
|
+
try {
|
|
57
|
+
data = await response.json();
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
data = null;
|
|
61
|
+
}
|
|
62
|
+
inboxFlowRequest({
|
|
63
|
+
method,
|
|
64
|
+
status,
|
|
65
|
+
request: JSON.stringify(response.headers),
|
|
66
|
+
response: JSON.stringify(data),
|
|
67
|
+
token: headers?.Authorization || "TOKEN_NOT_FOUND",
|
|
68
|
+
});
|
|
69
|
+
if (!response.ok) {
|
|
70
|
+
return {
|
|
71
|
+
success: false,
|
|
72
|
+
status,
|
|
73
|
+
message: data?.message || response.statusText || "Request failed",
|
|
74
|
+
response: data,
|
|
75
|
+
cause: null,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
success: true,
|
|
80
|
+
status,
|
|
81
|
+
message: data?.message || successMessage[method],
|
|
82
|
+
response: data,
|
|
83
|
+
cause: null,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
inboxFlowRequest({
|
|
88
|
+
method,
|
|
89
|
+
request: JSON.stringify(headers),
|
|
90
|
+
response: String(err),
|
|
91
|
+
status: 500,
|
|
92
|
+
token: "TOKEN_NOT_FOUND",
|
|
93
|
+
});
|
|
94
|
+
return {
|
|
95
|
+
success: false,
|
|
96
|
+
status: 0,
|
|
97
|
+
message: "Network error or request failed",
|
|
98
|
+
response: null,
|
|
99
|
+
cause: err instanceof Error ? err.message : String(err),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export { makeRequest };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ApiResponseDTO } from "@arkyn/types";
|
|
2
|
+
/**
|
|
3
|
+
* Sends a PATCH request to the specified URL with optional headers and body.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The expected type of the response data.
|
|
6
|
+
* @param {string} url - The URL to send the PATCH request to.
|
|
7
|
+
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
+
* @param {any} body - The body to include in the request.
|
|
9
|
+
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
10
|
+
*/
|
|
11
|
+
declare function patchRequest<T = any>(url: string, headers: HeadersInit | undefined, body: any): Promise<ApiResponseDTO<T>>;
|
|
12
|
+
export { patchRequest };
|
|
13
|
+
//# sourceMappingURL=patchRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patchRequest.d.ts","sourceRoot":"","sources":["../../src/api/patchRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGnD;;;;;;;;GAQG;AAEH,iBAAe,YAAY,CAAC,CAAC,GAAG,GAAG,EACjC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,WAAW,YAAK,EACzB,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAE5B;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { makeRequest } from "./makeRequest";
|
|
2
|
+
/**
|
|
3
|
+
* Sends a PATCH request to the specified URL with optional headers and body.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The expected type of the response data.
|
|
6
|
+
* @param {string} url - The URL to send the PATCH request to.
|
|
7
|
+
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
+
* @param {any} body - The body to include in the request.
|
|
9
|
+
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
10
|
+
*/
|
|
11
|
+
async function patchRequest(url, headers = {}, body) {
|
|
12
|
+
return makeRequest("PATCH", url, headers, body);
|
|
13
|
+
}
|
|
14
|
+
export { patchRequest };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ApiResponseDTO } from "@arkyn/types";
|
|
2
|
+
/**
|
|
3
|
+
* Sends a PATCH request to the specified URL with optional headers and body.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The expected type of the response data.
|
|
6
|
+
* @param {string} url - The URL to send the PATCH request to.
|
|
7
|
+
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
+
* @param {any} body - The body to include in the request.
|
|
9
|
+
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
10
|
+
*/
|
|
11
|
+
declare function postRequest<T = any>(url: string, headers: HeadersInit | undefined, body: any): Promise<ApiResponseDTO<T>>;
|
|
12
|
+
export { postRequest };
|
|
13
|
+
//# sourceMappingURL=postRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postRequest.d.ts","sourceRoot":"","sources":["../../src/api/postRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGnD;;;;;;;;GAQG;AAEH,iBAAe,WAAW,CAAC,CAAC,GAAG,GAAG,EAChC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,WAAW,YAAK,EACzB,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAE5B;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { makeRequest } from "./makeRequest";
|
|
2
|
+
/**
|
|
3
|
+
* Sends a PATCH request to the specified URL with optional headers and body.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The expected type of the response data.
|
|
6
|
+
* @param {string} url - The URL to send the PATCH request to.
|
|
7
|
+
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
+
* @param {any} body - The body to include in the request.
|
|
9
|
+
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
10
|
+
*/
|
|
11
|
+
async function postRequest(url, headers = {}, body) {
|
|
12
|
+
return makeRequest("POST", url, headers, body);
|
|
13
|
+
}
|
|
14
|
+
export { postRequest };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ApiResponseDTO } from "@arkyn/types";
|
|
2
|
+
/**
|
|
3
|
+
* Sends a PATCH request to the specified URL with optional headers and body.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The expected type of the response data.
|
|
6
|
+
* @param {string} url - The URL to send the PATCH request to.
|
|
7
|
+
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
+
* @param {any} body - The body to include in the request.
|
|
9
|
+
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
10
|
+
*/
|
|
11
|
+
declare function putRequest<T = any>(url: string, headers: HeadersInit | undefined, body: any): Promise<ApiResponseDTO<T>>;
|
|
12
|
+
export { putRequest };
|
|
13
|
+
//# sourceMappingURL=putRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"putRequest.d.ts","sourceRoot":"","sources":["../../src/api/putRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGnD;;;;;;;;GAQG;AAEH,iBAAe,UAAU,CAAC,CAAC,GAAG,GAAG,EAC/B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,WAAW,YAAK,EACzB,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAE5B;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { makeRequest } from "./makeRequest";
|
|
2
|
+
/**
|
|
3
|
+
* Sends a PATCH request to the specified URL with optional headers and body.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The expected type of the response data.
|
|
6
|
+
* @param {string} url - The URL to send the PATCH request to.
|
|
7
|
+
* @param {HeadersInit} [headers={}] - Optional headers to include in the request.
|
|
8
|
+
* @param {any} body - The body to include in the request.
|
|
9
|
+
* @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.
|
|
10
|
+
*/
|
|
11
|
+
async function putRequest(url, headers = {}, body) {
|
|
12
|
+
return makeRequest("PUT", url, headers, body);
|
|
13
|
+
}
|
|
14
|
+
export { putRequest };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiInstance.spec.d.ts","sourceRoot":"","sources":["../../../src/config/__test__/apiInstance.spec.ts"],"names":[],"mappings":""}
|