procedere-mq-sdk 0.2.0 → 0.3.0
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/README.md +11 -2
- package/index.d.ts +3 -0
- package/index.js +16 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,7 +20,10 @@ npm install procedere-mq-sdk
|
|
|
20
20
|
const { LiteMQClient } = require("procedere-mq-sdk");
|
|
21
21
|
|
|
22
22
|
async function main() {
|
|
23
|
-
const client = new LiteMQClient("http://127.0.0.1:65090"
|
|
23
|
+
const client = new LiteMQClient("http://127.0.0.1:65090", {
|
|
24
|
+
username: "api-user",
|
|
25
|
+
password: "senha-forte-api",
|
|
26
|
+
});
|
|
24
27
|
const producer = client.producer("emails");
|
|
25
28
|
|
|
26
29
|
const job = await producer.publish(
|
|
@@ -40,7 +43,10 @@ main().catch(console.error);
|
|
|
40
43
|
const { LiteMQClient, QueueEmptyError } = require("procedere-mq-sdk");
|
|
41
44
|
|
|
42
45
|
async function main() {
|
|
43
|
-
const client = new LiteMQClient("http://127.0.0.1:65090"
|
|
46
|
+
const client = new LiteMQClient("http://127.0.0.1:65090", {
|
|
47
|
+
username: "api-user",
|
|
48
|
+
password: "senha-forte-api",
|
|
49
|
+
});
|
|
44
50
|
const consumer = client.consumer("emails");
|
|
45
51
|
|
|
46
52
|
try {
|
|
@@ -64,6 +70,9 @@ main().catch(console.error);
|
|
|
64
70
|
- `baseUrl`: endereco HTTP do ProcedereMQ
|
|
65
71
|
- `options.timeout`: timeout em milissegundos
|
|
66
72
|
- `options.fetchImpl`: implementacao customizada de `fetch`
|
|
73
|
+
- `options.apiKey`: bearer customizado, se voce precisar compatibilidade externa
|
|
74
|
+
- `options.username`: usuario para autenticar com Basic Auth
|
|
75
|
+
- `options.password`: senha para autenticar com Basic Auth
|
|
67
76
|
|
|
68
77
|
### `client.producer(queue)`
|
|
69
78
|
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -61,6 +61,9 @@ class LiteMQClient {
|
|
|
61
61
|
this.baseUrl = normalizeBaseUrl(baseUrl);
|
|
62
62
|
this.timeout = options.timeout ?? 10000;
|
|
63
63
|
this.fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
64
|
+
this.apiKey = isNonEmptyString(options.apiKey) ? options.apiKey.trim() : "";
|
|
65
|
+
this.username = isNonEmptyString(options.username) ? options.username.trim() : "";
|
|
66
|
+
this.password = typeof options.password === "string" ? options.password : "";
|
|
64
67
|
|
|
65
68
|
if (typeof this.fetchImpl !== "function") {
|
|
66
69
|
throw new LiteMQError("fetch API is not available in this runtime");
|
|
@@ -123,6 +126,11 @@ class LiteMQClient {
|
|
|
123
126
|
signal: controller.signal,
|
|
124
127
|
headers: {},
|
|
125
128
|
};
|
|
129
|
+
if (this.apiKey) {
|
|
130
|
+
init.headers.Authorization = `Bearer ${this.apiKey}`;
|
|
131
|
+
} else if (this.username && this.password) {
|
|
132
|
+
init.headers.Authorization = `Basic ${encodeBase64(`${this.username}:${this.password}`)}`;
|
|
133
|
+
}
|
|
126
134
|
|
|
127
135
|
if (options.body !== undefined) {
|
|
128
136
|
init.headers["Content-Type"] = "application/json";
|
|
@@ -162,6 +170,7 @@ class LiteMQClient {
|
|
|
162
170
|
}
|
|
163
171
|
return { data };
|
|
164
172
|
}
|
|
173
|
+
|
|
165
174
|
}
|
|
166
175
|
|
|
167
176
|
async function extractError(response) {
|
|
@@ -219,6 +228,13 @@ function isPlainObject(value) {
|
|
|
219
228
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
220
229
|
}
|
|
221
230
|
|
|
231
|
+
function encodeBase64(value) {
|
|
232
|
+
if (typeof Buffer !== "undefined") {
|
|
233
|
+
return Buffer.from(value, "utf8").toString("base64");
|
|
234
|
+
}
|
|
235
|
+
throw new LiteMQError("base64 encoder is not available in this runtime");
|
|
236
|
+
}
|
|
237
|
+
|
|
222
238
|
module.exports = {
|
|
223
239
|
Consumer,
|
|
224
240
|
LiteMQClient,
|