@whitewall/blip-warehouse 0.0.10 → 0.0.12
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/api/src/client.d.ts +2 -1
- package/dist/api/src/index.d.ts +1 -1
- package/dist/api/src/types.d.ts +20 -0
- package/dist/cjs/{chunk-U64pC571.js → chunk-BW_iTze1.js} +1 -1
- package/dist/cjs/index.js +60 -12
- package/dist/cjs/{undici-AlvjFlUK.js → undici-9GacOgVB.js} +586 -495
- package/dist/esm/{chunk-Cpt029wX.js → chunk-C8JhGJ3N.js} +2 -2
- package/dist/esm/index.js +59 -12
- package/dist/esm/{undici-C2YCJDeQ.js → undici-BtPcTDHV.js} +586 -495
- package/dist/src/warehouse/types.d.ts +1 -1
- package/package.json +24 -22
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -26,7 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
}) : target, mod));
|
|
27
27
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
28
28
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
29
|
-
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function.");
|
|
29
|
+
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
//#endregion
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as __toESM } from "./chunk-
|
|
1
|
+
import { r as __toESM } from "./chunk-C8JhGJ3N.js";
|
|
2
2
|
|
|
3
3
|
//#region src/client.ts
|
|
4
4
|
var BlipWarehouseClient = class {
|
|
@@ -27,6 +27,12 @@ var BlipWarehouseClient = class {
|
|
|
27
27
|
const path = `/warehouse/contacts/${encodeURIComponent(identity)}/messages${queryString ? `?${queryString}` : ""}`;
|
|
28
28
|
return this.request(path);
|
|
29
29
|
}
|
|
30
|
+
async blipSearch(request) {
|
|
31
|
+
return this.request("/blip/search", {
|
|
32
|
+
method: "POST",
|
|
33
|
+
body: JSON.stringify(request)
|
|
34
|
+
});
|
|
35
|
+
}
|
|
30
36
|
async createToken(request) {
|
|
31
37
|
return this.request("/auth/tokens", {
|
|
32
38
|
method: "POST",
|
|
@@ -34,10 +40,22 @@ var BlipWarehouseClient = class {
|
|
|
34
40
|
});
|
|
35
41
|
}
|
|
36
42
|
async historicalIngest(request, onProgress) {
|
|
43
|
+
const parseJson = (value) => {
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(value);
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const toErrorMessage = (value) => {
|
|
51
|
+
if (value && typeof value === "object" && "error" in value && typeof value.error === "string") return value.error;
|
|
52
|
+
if (typeof value === "string") return value;
|
|
53
|
+
return "Unknown ingest error";
|
|
54
|
+
};
|
|
37
55
|
const url = `${this.baseUrl}/blip/historical-ingest`;
|
|
38
56
|
let dispatcher;
|
|
39
57
|
if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
40
|
-
const { Agent } = await import("./undici-
|
|
58
|
+
const { Agent } = await import("./undici-BtPcTDHV.js").then((m) => /* @__PURE__ */ __toESM(m.default));
|
|
41
59
|
dispatcher = new Agent({
|
|
42
60
|
connectTimeout: 6e4 * 30,
|
|
43
61
|
bodyTimeout: 6e4 * 30
|
|
@@ -47,6 +65,7 @@ var BlipWarehouseClient = class {
|
|
|
47
65
|
method: "POST",
|
|
48
66
|
headers: {
|
|
49
67
|
"Content-Type": "application/json",
|
|
68
|
+
Accept: "text/event-stream",
|
|
50
69
|
Authorization: `Bearer ${this.token}`
|
|
51
70
|
},
|
|
52
71
|
body: JSON.stringify({
|
|
@@ -65,22 +84,50 @@ var BlipWarehouseClient = class {
|
|
|
65
84
|
const decoder = new TextDecoder();
|
|
66
85
|
let buffer = "";
|
|
67
86
|
let result = { success: false };
|
|
87
|
+
const handleEvent = (event, rawData) => {
|
|
88
|
+
const payload = rawData.trim();
|
|
89
|
+
if (!payload) return;
|
|
90
|
+
const data = parseJson(payload);
|
|
91
|
+
if (data && typeof data === "object") {
|
|
92
|
+
if ("contactsProcessed" in data) {
|
|
93
|
+
onProgress?.(data);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if ("success" in data) {
|
|
97
|
+
result = data;
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if ("error" in data) throw new Error(toErrorMessage(data));
|
|
101
|
+
}
|
|
102
|
+
if (event === "error") throw new Error(toErrorMessage(data ?? payload));
|
|
103
|
+
};
|
|
104
|
+
const flushBuffer = (onlyCompleteEvents) => {
|
|
105
|
+
const chunks = buffer.replace(/\r\n?/g, "\n").split("\n\n");
|
|
106
|
+
const events = onlyCompleteEvents ? chunks.slice(0, -1) : chunks;
|
|
107
|
+
buffer = onlyCompleteEvents ? chunks[chunks.length - 1] ?? "" : "";
|
|
108
|
+
for (const eventChunk of events) {
|
|
109
|
+
if (!eventChunk.trim()) continue;
|
|
110
|
+
let event = null;
|
|
111
|
+
const dataLines = [];
|
|
112
|
+
for (const line of eventChunk.split("\n")) {
|
|
113
|
+
if (line.startsWith(":")) continue;
|
|
114
|
+
if (line.startsWith("event:")) {
|
|
115
|
+
event = line.slice(6).trim();
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (line.startsWith("data:")) dataLines.push(line.slice(5).trimStart());
|
|
119
|
+
}
|
|
120
|
+
if (dataLines.length > 0) handleEvent(event, dataLines.join("\n"));
|
|
121
|
+
}
|
|
122
|
+
};
|
|
68
123
|
try {
|
|
69
124
|
while (true) {
|
|
70
125
|
const { done, value } = await reader.read();
|
|
71
126
|
if (done) break;
|
|
72
127
|
buffer += decoder.decode(value, { stream: true });
|
|
73
|
-
|
|
74
|
-
buffer = lines.pop() ?? "";
|
|
75
|
-
for (const line of lines) {
|
|
76
|
-
if (line.startsWith("event:")) continue;
|
|
77
|
-
if (line.startsWith("data:")) {
|
|
78
|
-
const data = JSON.parse(line.slice(5).trim());
|
|
79
|
-
if ("contactsProcessed" in data) onProgress?.(data);
|
|
80
|
-
else if ("success" in data) result = data;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
128
|
+
flushBuffer(true);
|
|
83
129
|
}
|
|
130
|
+
flushBuffer(false);
|
|
84
131
|
return result;
|
|
85
132
|
} catch (error) {
|
|
86
133
|
throw new Error(`SSE stream failed: ${error instanceof Error ? error.message : "Unknown streaming error"}`);
|