btechworks-sdk 1.0.1 → 1.0.2
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/index.d.mts +1 -6
- package/dist/index.d.ts +1 -6
- package/dist/index.js +11 -24
- package/dist/index.mjs +10 -22
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -61,11 +61,6 @@ interface BroadcastResponse {
|
|
|
61
61
|
message: string;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
declare class BTechWorksError extends Error {
|
|
65
|
-
statusCode: number;
|
|
66
|
-
details?: Record<string, unknown>;
|
|
67
|
-
constructor(message: string, statusCode: number, details?: Record<string, unknown>);
|
|
68
|
-
}
|
|
69
64
|
declare class BTechWorksClient {
|
|
70
65
|
private apiKey;
|
|
71
66
|
private secretKey;
|
|
@@ -81,4 +76,4 @@ declare class BTechWorksClient {
|
|
|
81
76
|
broadcast(options: BroadcastOptions): Promise<BroadcastResponse>;
|
|
82
77
|
}
|
|
83
78
|
|
|
84
|
-
export { type ApiResponse, BTechWorksClient, type BTechWorksConfig,
|
|
79
|
+
export { type ApiResponse, BTechWorksClient, type BTechWorksConfig, type BroadcastOptions, type BroadcastResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendVideoOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -61,11 +61,6 @@ interface BroadcastResponse {
|
|
|
61
61
|
message: string;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
declare class BTechWorksError extends Error {
|
|
65
|
-
statusCode: number;
|
|
66
|
-
details?: Record<string, unknown>;
|
|
67
|
-
constructor(message: string, statusCode: number, details?: Record<string, unknown>);
|
|
68
|
-
}
|
|
69
64
|
declare class BTechWorksClient {
|
|
70
65
|
private apiKey;
|
|
71
66
|
private secretKey;
|
|
@@ -81,4 +76,4 @@ declare class BTechWorksClient {
|
|
|
81
76
|
broadcast(options: BroadcastOptions): Promise<BroadcastResponse>;
|
|
82
77
|
}
|
|
83
78
|
|
|
84
|
-
export { type ApiResponse, BTechWorksClient, type BTechWorksConfig,
|
|
79
|
+
export { type ApiResponse, BTechWorksClient, type BTechWorksConfig, type BroadcastOptions, type BroadcastResponse, type SendDocumentOptions, type SendMessageOptions, type SendPhotoOptions, type SendTemplateOptions, type SendVideoOptions };
|
package/dist/index.js
CHANGED
|
@@ -20,20 +20,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
BTechWorksClient: () => BTechWorksClient
|
|
24
|
-
BTechWorksError: () => BTechWorksError
|
|
23
|
+
BTechWorksClient: () => BTechWorksClient
|
|
25
24
|
});
|
|
26
25
|
module.exports = __toCommonJS(index_exports);
|
|
27
26
|
|
|
28
27
|
// src/client.ts
|
|
29
|
-
var BTechWorksError = class extends Error {
|
|
30
|
-
constructor(message, statusCode, details) {
|
|
31
|
-
super(message);
|
|
32
|
-
this.name = "BTechWorksError";
|
|
33
|
-
this.statusCode = statusCode;
|
|
34
|
-
this.details = details;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
28
|
var BTechWorksClient = class {
|
|
38
29
|
constructor(config) {
|
|
39
30
|
if (!config.apiKey) {
|
|
@@ -47,7 +38,6 @@ var BTechWorksClient = class {
|
|
|
47
38
|
this.baseUrl = (config.baseUrl || "https://api.btechworks.io").replace(/\/+$/, "");
|
|
48
39
|
this.timeout = config.timeout || 3e4;
|
|
49
40
|
}
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
41
|
async request(path, options = {}) {
|
|
52
42
|
const url = `${this.baseUrl}${path}`;
|
|
53
43
|
const headers = {
|
|
@@ -66,22 +56,20 @@ var BTechWorksClient = class {
|
|
|
66
56
|
});
|
|
67
57
|
const data = await response.json();
|
|
68
58
|
if (!response.ok) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
response.status
|
|
72
|
-
|
|
73
|
-
);
|
|
59
|
+
return {
|
|
60
|
+
success: false,
|
|
61
|
+
message: data.message || data.error || `Request failed with status ${response.status}`
|
|
62
|
+
};
|
|
74
63
|
}
|
|
75
64
|
return data;
|
|
76
65
|
} catch (error) {
|
|
77
|
-
if (error instanceof BTechWorksError) throw error;
|
|
78
66
|
if (error instanceof DOMException && error.name === "AbortError") {
|
|
79
|
-
|
|
67
|
+
return { success: false, message: "Request timeout" };
|
|
80
68
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
69
|
+
return {
|
|
70
|
+
success: false,
|
|
71
|
+
message: error instanceof Error ? error.message : "Unknown error"
|
|
72
|
+
};
|
|
85
73
|
} finally {
|
|
86
74
|
clearTimeout(timeoutId);
|
|
87
75
|
}
|
|
@@ -154,6 +142,5 @@ var BTechWorksClient = class {
|
|
|
154
142
|
};
|
|
155
143
|
// Annotate the CommonJS export names for ESM import in node:
|
|
156
144
|
0 && (module.exports = {
|
|
157
|
-
BTechWorksClient
|
|
158
|
-
BTechWorksError
|
|
145
|
+
BTechWorksClient
|
|
159
146
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
// src/client.ts
|
|
2
|
-
var BTechWorksError = class extends Error {
|
|
3
|
-
constructor(message, statusCode, details) {
|
|
4
|
-
super(message);
|
|
5
|
-
this.name = "BTechWorksError";
|
|
6
|
-
this.statusCode = statusCode;
|
|
7
|
-
this.details = details;
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
2
|
var BTechWorksClient = class {
|
|
11
3
|
constructor(config) {
|
|
12
4
|
if (!config.apiKey) {
|
|
@@ -20,7 +12,6 @@ var BTechWorksClient = class {
|
|
|
20
12
|
this.baseUrl = (config.baseUrl || "https://api.btechworks.io").replace(/\/+$/, "");
|
|
21
13
|
this.timeout = config.timeout || 3e4;
|
|
22
14
|
}
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
15
|
async request(path, options = {}) {
|
|
25
16
|
const url = `${this.baseUrl}${path}`;
|
|
26
17
|
const headers = {
|
|
@@ -39,22 +30,20 @@ var BTechWorksClient = class {
|
|
|
39
30
|
});
|
|
40
31
|
const data = await response.json();
|
|
41
32
|
if (!response.ok) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
response.status
|
|
45
|
-
|
|
46
|
-
);
|
|
33
|
+
return {
|
|
34
|
+
success: false,
|
|
35
|
+
message: data.message || data.error || `Request failed with status ${response.status}`
|
|
36
|
+
};
|
|
47
37
|
}
|
|
48
38
|
return data;
|
|
49
39
|
} catch (error) {
|
|
50
|
-
if (error instanceof BTechWorksError) throw error;
|
|
51
40
|
if (error instanceof DOMException && error.name === "AbortError") {
|
|
52
|
-
|
|
41
|
+
return { success: false, message: "Request timeout" };
|
|
53
42
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
43
|
+
return {
|
|
44
|
+
success: false,
|
|
45
|
+
message: error instanceof Error ? error.message : "Unknown error"
|
|
46
|
+
};
|
|
58
47
|
} finally {
|
|
59
48
|
clearTimeout(timeoutId);
|
|
60
49
|
}
|
|
@@ -126,6 +115,5 @@ var BTechWorksClient = class {
|
|
|
126
115
|
}
|
|
127
116
|
};
|
|
128
117
|
export {
|
|
129
|
-
BTechWorksClient
|
|
130
|
-
BTechWorksError
|
|
118
|
+
BTechWorksClient
|
|
131
119
|
};
|
package/package.json
CHANGED