@whitewall/blip-warehouse 0.0.9 → 0.0.11
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/cjs/{chunk-DYk-Zboy.js → chunk-BW_iTze1.js} +3 -4
- package/dist/cjs/index.js +54 -14
- package/dist/cjs/{undici-CNAV_IlA.js → undici-9GacOgVB.js} +5064 -3995
- package/dist/esm/{chunk-CLyj0VIr.js → chunk-C8JhGJ3N.js} +3 -4
- package/dist/esm/index.js +53 -14
- package/dist/esm/{undici-a1nz442l.js → undici-BtPcTDHV.js} +5064 -3995
- package/dist/src/warehouse/types.d.ts +9 -3
- 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;
|
|
@@ -24,7 +24,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
value: mod,
|
|
25
25
|
enumerable: true
|
|
26
26
|
}) : target, mod));
|
|
27
|
-
var __toDynamicImportESM = (isNodeMode) => (mod) => __toESM(mod.default, isNodeMode);
|
|
28
27
|
|
|
29
28
|
//#endregion
|
|
30
29
|
|
|
@@ -34,9 +33,9 @@ Object.defineProperty(exports, '__commonJSMin', {
|
|
|
34
33
|
return __commonJSMin;
|
|
35
34
|
}
|
|
36
35
|
});
|
|
37
|
-
Object.defineProperty(exports, '
|
|
36
|
+
Object.defineProperty(exports, '__toESM', {
|
|
38
37
|
enumerable: true,
|
|
39
38
|
get: function () {
|
|
40
|
-
return
|
|
39
|
+
return __toESM;
|
|
41
40
|
}
|
|
42
41
|
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_chunk = require('./chunk-BW_iTze1.js');
|
|
2
3
|
|
|
3
4
|
//#region src/client.ts
|
|
4
5
|
var BlipWarehouseClient = class {
|
|
5
|
-
baseUrl;
|
|
6
|
-
token;
|
|
7
6
|
constructor(config) {
|
|
8
7
|
this.baseUrl = config.baseUrl?.replace(/\/$/, "") ?? "https://api.warehouse.whitewall.dev";
|
|
9
8
|
this.token = config.token;
|
|
@@ -36,10 +35,22 @@ var BlipWarehouseClient = class {
|
|
|
36
35
|
});
|
|
37
36
|
}
|
|
38
37
|
async historicalIngest(request, onProgress) {
|
|
38
|
+
const parseJson = (value) => {
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(value);
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const toErrorMessage = (value) => {
|
|
46
|
+
if (value && typeof value === "object" && "error" in value && typeof value.error === "string") return value.error;
|
|
47
|
+
if (typeof value === "string") return value;
|
|
48
|
+
return "Unknown ingest error";
|
|
49
|
+
};
|
|
39
50
|
const url = `${this.baseUrl}/blip/historical-ingest`;
|
|
40
51
|
let dispatcher;
|
|
41
52
|
if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
42
|
-
const { Agent } = await Promise.resolve().then(() => require_chunk.
|
|
53
|
+
const { Agent } = await Promise.resolve().then(() => /* @__PURE__ */ require_chunk.__toESM(require("./undici-9GacOgVB.js").default));
|
|
43
54
|
dispatcher = new Agent({
|
|
44
55
|
connectTimeout: 6e4 * 30,
|
|
45
56
|
bodyTimeout: 6e4 * 30
|
|
@@ -49,6 +60,7 @@ var BlipWarehouseClient = class {
|
|
|
49
60
|
method: "POST",
|
|
50
61
|
headers: {
|
|
51
62
|
"Content-Type": "application/json",
|
|
63
|
+
Accept: "text/event-stream",
|
|
52
64
|
Authorization: `Bearer ${this.token}`
|
|
53
65
|
},
|
|
54
66
|
body: JSON.stringify({
|
|
@@ -67,22 +79,50 @@ var BlipWarehouseClient = class {
|
|
|
67
79
|
const decoder = new TextDecoder();
|
|
68
80
|
let buffer = "";
|
|
69
81
|
let result = { success: false };
|
|
82
|
+
const handleEvent = (event, rawData) => {
|
|
83
|
+
const payload = rawData.trim();
|
|
84
|
+
if (!payload) return;
|
|
85
|
+
const data = parseJson(payload);
|
|
86
|
+
if (data && typeof data === "object") {
|
|
87
|
+
if ("contactsProcessed" in data) {
|
|
88
|
+
onProgress?.(data);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if ("success" in data) {
|
|
92
|
+
result = data;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if ("error" in data) throw new Error(toErrorMessage(data));
|
|
96
|
+
}
|
|
97
|
+
if (event === "error") throw new Error(toErrorMessage(data ?? payload));
|
|
98
|
+
};
|
|
99
|
+
const flushBuffer = (onlyCompleteEvents) => {
|
|
100
|
+
const chunks = buffer.replace(/\r\n?/g, "\n").split("\n\n");
|
|
101
|
+
const events = onlyCompleteEvents ? chunks.slice(0, -1) : chunks;
|
|
102
|
+
buffer = onlyCompleteEvents ? chunks[chunks.length - 1] ?? "" : "";
|
|
103
|
+
for (const eventChunk of events) {
|
|
104
|
+
if (!eventChunk.trim()) continue;
|
|
105
|
+
let event = null;
|
|
106
|
+
const dataLines = [];
|
|
107
|
+
for (const line of eventChunk.split("\n")) {
|
|
108
|
+
if (line.startsWith(":")) continue;
|
|
109
|
+
if (line.startsWith("event:")) {
|
|
110
|
+
event = line.slice(6).trim();
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (line.startsWith("data:")) dataLines.push(line.slice(5).trimStart());
|
|
114
|
+
}
|
|
115
|
+
if (dataLines.length > 0) handleEvent(event, dataLines.join("\n"));
|
|
116
|
+
}
|
|
117
|
+
};
|
|
70
118
|
try {
|
|
71
119
|
while (true) {
|
|
72
120
|
const { done, value } = await reader.read();
|
|
73
121
|
if (done) break;
|
|
74
122
|
buffer += decoder.decode(value, { stream: true });
|
|
75
|
-
|
|
76
|
-
buffer = lines.pop() ?? "";
|
|
77
|
-
for (const line of lines) {
|
|
78
|
-
if (line.startsWith("event:")) continue;
|
|
79
|
-
if (line.startsWith("data:")) {
|
|
80
|
-
const data = JSON.parse(line.slice(5).trim());
|
|
81
|
-
if ("contactsProcessed" in data) onProgress?.(data);
|
|
82
|
-
else if ("success" in data) result = data;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
123
|
+
flushBuffer(true);
|
|
85
124
|
}
|
|
125
|
+
flushBuffer(false);
|
|
86
126
|
return result;
|
|
87
127
|
} catch (error) {
|
|
88
128
|
throw new Error(`SSE stream failed: ${error instanceof Error ? error.message : "Unknown streaming error"}`);
|