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 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
- let data = null;
13
- let error = null;
14
- await fetch(this.ENSEND_BASE_URL + options.path, {
15
- headers: {
16
- "Content-Type": "application/json",
17
- Authorization: `Bearer ${this.PROJECT_SECRET}`,
18
- },
19
- method: options.method,
20
- body: options.method === "POST" ? JSON.stringify(options.body) : undefined,
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 = responseData;
23
+ return { data: responseData, error: null };
26
24
  }
27
- else {
28
- error = responseData;
29
- }
30
- })
31
- .catch((error) => {
32
- error = {
33
- message: error.message,
34
- statusCode: 500,
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) {
@@ -3,7 +3,7 @@ export type HttpClientOptions = {
3
3
  path: string;
4
4
  body: Record<string, any>;
5
5
  };
6
- export type HttpClientResponse<T = undefined> = {
6
+ export type HttpClientResponse<T = null> = {
7
7
  message: string;
8
8
  statusCode: number;
9
9
  data: T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ensend",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "description": "Official Typescript/Javascript SDK for the new Ensend API. See completed documentation at https://docs.ensend.co",