@bugmail-js/core 0.1.4 → 0.1.5
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/bugmail-core-client.js +13 -1
- package/package.json +1 -1
package/bugmail-core-client.js
CHANGED
|
@@ -22,6 +22,15 @@ export class BugMailCoreClient {
|
|
|
22
22
|
'Content-Type': 'application/json',
|
|
23
23
|
...(context.headers || {})
|
|
24
24
|
};
|
|
25
|
+
|
|
26
|
+
// If an API key is provided in the client config, ensure the request
|
|
27
|
+
// includes the expected header unless the caller already supplied one.
|
|
28
|
+
if (this.config && this.config.apiKey) {
|
|
29
|
+
const hasApiKeyHeader = Object.keys(headers).some(h => h.toLowerCase() === 'x-bugmail-api-key');
|
|
30
|
+
if (!hasApiKeyHeader) {
|
|
31
|
+
headers['X-BugMail-API-Key'] = this.config.apiKey;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
25
34
|
const payload = context.payload || {};
|
|
26
35
|
|
|
27
36
|
try {
|
|
@@ -33,7 +42,10 @@ export class BugMailCoreClient {
|
|
|
33
42
|
try {
|
|
34
43
|
// Use require-like dynamic import only in Node; bundlers should not include node-fetch for browser builds
|
|
35
44
|
if (typeof process !== 'undefined' && process.versions && process.versions.node) {
|
|
36
|
-
|
|
45
|
+
// Construct the module name at runtime to avoid bundlers statically
|
|
46
|
+
// resolving/including `node-fetch` in browser builds (Vite/Rollup).
|
|
47
|
+
const nodeFetchName = 'node' + '-fetch';
|
|
48
|
+
fetchFn = (await import(nodeFetchName)).default;
|
|
37
49
|
} else {
|
|
38
50
|
console.error('[BugMail] fetch is not available in this environment.');
|
|
39
51
|
return;
|