ensend 0.0.7 → 0.0.9
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/dist/client.js +21 -23
- package/dist/lib/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -2,39 +2,37 @@ import fetch from "node-fetch-native";
|
|
|
2
2
|
import { SendApi } from "./apis/SendApi";
|
|
3
3
|
export class Client {
|
|
4
4
|
constructor(options) {
|
|
5
|
-
this.ENSEND_BASE_URL = typeof process !== "undefined"
|
|
5
|
+
this.ENSEND_BASE_URL = typeof process !== "undefined" && process.env.ENSEND_BASE_URL
|
|
6
6
|
? process.env.ENSEND_BASE_URL
|
|
7
7
|
: "https://api.ensend.co";
|
|
8
8
|
this.PROJECT_SECRET = typeof process !== "undefined"
|
|
9
9
|
? process?.env?.ENSEND_PROJECT_SECRET
|
|
10
10
|
: undefined;
|
|
11
11
|
this.http = async (options) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
})
|
|
22
|
-
.then(async (res) => {
|
|
12
|
+
try {
|
|
13
|
+
const res = await fetch(this.ENSEND_BASE_URL + options.path, {
|
|
14
|
+
headers: {
|
|
15
|
+
"Content-Type": "application/json",
|
|
16
|
+
Authorization: `Bearer ${this.PROJECT_SECRET}`,
|
|
17
|
+
},
|
|
18
|
+
method: options.method,
|
|
19
|
+
body: options.method === "POST" ? JSON.stringify(options.body) : undefined,
|
|
20
|
+
});
|
|
23
21
|
const responseData = await res.json();
|
|
24
22
|
if (res.status === 200) {
|
|
25
|
-
data
|
|
23
|
+
return { data: responseData, error: null };
|
|
26
24
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
return { data: null, error: responseData };
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
return {
|
|
29
|
+
data: null,
|
|
30
|
+
error: {
|
|
31
|
+
message: err.message,
|
|
32
|
+
statusCode: 500,
|
|
33
|
+
},
|
|
35
34
|
};
|
|
36
|
-
}
|
|
37
|
-
return { data, error };
|
|
35
|
+
}
|
|
38
36
|
};
|
|
39
37
|
this.SendApi = new SendApi(this.http);
|
|
40
38
|
if (options?.secret) {
|
package/dist/lib/types.d.ts
CHANGED