Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.

Commit 78767bd

Browse files
committed
update platform with axios
1 parent 434c0b5 commit 78767bd

File tree

10 files changed

+125
-37
lines changed

10 files changed

+125
-37
lines changed

__tests__/$send.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// purposefully test COMPILED platform.js! (just as lambda_maker would)
2-
const { $sendConfigRuntimeTypeChecker } = require("../dist/platform")
2+
const { $sendConfigRuntimeTypeChecker } = require("../dist")
33

44
function randString() {
55
return ""+Math.random()

__tests__/axios.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const { axios } = require("../dist")
2+
3+
describe("axios", () => {
4+
it("should fail as expected", async () => {
5+
const step = {}
6+
await expect(axios(step, {})).rejects.toThrow(step.error) // no url
7+
})
8+
})

dist/axios.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default function (step: any, config: any): Promise<any>;

dist/axios.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
const axios_1 = require("axios");
4+
function observability(resp) {
5+
return {
6+
request: resp.config,
7+
response: {
8+
status: resp.status,
9+
headers: resp.headers,
10+
data: resp.data,
11+
},
12+
};
13+
}
14+
async function default_1(step, config) {
15+
try {
16+
const resp = await axios_1.default(config);
17+
step.axios = observability(resp);
18+
return resp.data;
19+
}
20+
catch (err) {
21+
if (err.isAxiosError) {
22+
step.axios = observability(err.response);
23+
}
24+
else {
25+
step.error = err;
26+
}
27+
throw err;
28+
}
29+
}
30+
exports.default = default_1;

dist/platform.d.ts renamed to dist/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import * as t from "io-ts";
2+
import axios from "./axios";
3+
export { axios };
24
export declare const SendConfigEmail: t.PartialC<{
35
html: t.StringC;
46
subject: t.StringC;
@@ -102,4 +104,3 @@ export declare const END_NEEDLE = "__pd_end";
102104
export declare function $end(message?: string): void;
103105
export declare let $send: SendFunctionsWrapper;
104106
export declare const $sendConfigRuntimeTypeChecker: {};
105-
export {};

dist/platform.js renamed to dist/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
33
const t = require("io-ts");
4+
const axios_1 = require("./axios");
5+
exports.axios = axios_1.default;
46
const SendPayload = t.union([t.string, t.object]);
57
exports.SendConfigEmail = t.partial({
68
html: t.string,

lib/axios.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import axios from "axios"
2+
3+
function observability(resp) {
4+
return {
5+
request: resp.config,
6+
response: {
7+
status: resp.status,
8+
headers: resp.headers,
9+
data: resp.data,
10+
},
11+
}
12+
}
13+
14+
export default async function(step: any, config) {
15+
try {
16+
const resp = await axios(config)
17+
step.axios = observability(resp)
18+
return resp.data
19+
} catch (err) {
20+
if (err.isAxiosError) {
21+
step.axios = observability(err.response)
22+
} else {
23+
step.error = err
24+
}
25+
throw err
26+
}
27+
}

lib/platform.ts renamed to lib/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import * as t from "io-ts"
22

3+
import axios from "./axios"
4+
5+
export { axios }
6+
37
const SendPayload = t.union([t.string, t.object]);
48
type SendPayload = t.TypeOf<typeof SendPayload>;
59

package-lock.json

Lines changed: 46 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"version": "0.0.5",
44
"description": "Pipedream platform globals (typing and runtime type checking)",
55
"homepage": "https://pipedream.com",
6-
"main": "dist/platform.js",
7-
"types": "dist/platform.d.ts",
6+
"main": "dist/index.js",
7+
"types": "dist/index.d.ts",
88
"scripts": {
9-
"build": "tsc",
9+
"build": "rm -rf dist/** && tsc",
1010
"test": "jest"
1111
},
1212
"author": "Pipedream Team",
@@ -16,6 +16,7 @@
1616
"url": "https://github.com/PipedreamHQ/platform.git"
1717
},
1818
"dependencies": {
19+
"axios": "^0.19.0",
1920
"fp-ts": "^2.0.2",
2021
"io-ts": "^2.0.0"
2122
},

0 commit comments

Comments
 (0)