@whitewall/blip-warehouse 0.0.4 → 0.0.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/dist/api/src/client.d.ts +2 -2
- package/dist/api/src/index.d.ts +1 -1
- package/dist/api/src/types.d.ts +3 -0
- package/dist/cjs/chunk-DYk-Zboy.js +42 -0
- package/dist/cjs/index.js +108 -0
- package/dist/cjs/undici-CNAV_IlA.js +19609 -0
- package/dist/esm/chunk-CLyj0VIr.js +34 -0
- package/dist/esm/index.js +108 -0
- package/dist/esm/undici-a1nz442l.js +19604 -0
- package/package.json +22 -20
- package/dist/index.cjs +0 -62
- package/dist/index.js +0 -61
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
var __toDynamicImportESM = (isNodeMode) => (mod) => __toESM(mod.default, isNodeMode);
|
|
28
|
+
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) {
|
|
29
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
30
|
+
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function.");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { __require as n, __toDynamicImportESM as r, __commonJSMin as t };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { r as __toDynamicImportESM } from "./chunk-CLyj0VIr.js";
|
|
2
|
+
|
|
3
|
+
//#region src/client.ts
|
|
4
|
+
var BlipWarehouseClient = class {
|
|
5
|
+
baseUrl;
|
|
6
|
+
token;
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.baseUrl = config.baseUrl?.replace(/\/$/, "") ?? "https://api.warehouse.whitewall.dev";
|
|
9
|
+
this.token = config.token;
|
|
10
|
+
}
|
|
11
|
+
async getContactsCount() {
|
|
12
|
+
return (await this.request("/warehouse/contacts")).count;
|
|
13
|
+
}
|
|
14
|
+
async search(request) {
|
|
15
|
+
return this.request("/warehouse/search", {
|
|
16
|
+
method: "POST",
|
|
17
|
+
body: JSON.stringify({
|
|
18
|
+
query: request.query,
|
|
19
|
+
limit: request.limit ?? 10,
|
|
20
|
+
cursor: request.cursor
|
|
21
|
+
})
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async getMessagesByIdentity(identity, options = {}) {
|
|
25
|
+
const params = new URLSearchParams();
|
|
26
|
+
if (options.limit !== void 0) params.append("limit", options.limit.toString());
|
|
27
|
+
if (options.cursor) params.append("cursor", options.cursor);
|
|
28
|
+
const queryString = params.toString();
|
|
29
|
+
const path = `/warehouse/contacts/${encodeURIComponent(identity)}/messages${queryString ? `?${queryString}` : ""}`;
|
|
30
|
+
return this.request(path);
|
|
31
|
+
}
|
|
32
|
+
async createToken(request) {
|
|
33
|
+
return this.request("/auth/tokens", {
|
|
34
|
+
method: "POST",
|
|
35
|
+
body: JSON.stringify(request)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async historicalIngest(request, onProgress) {
|
|
39
|
+
const url = `${this.baseUrl}/blip/historical-ingest`;
|
|
40
|
+
let dispatcher;
|
|
41
|
+
if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
42
|
+
const { Agent } = await import("./undici-a1nz442l.js").then(__toDynamicImportESM());
|
|
43
|
+
dispatcher = new Agent({
|
|
44
|
+
connectTimeout: 6e4 * 30,
|
|
45
|
+
bodyTimeout: 6e4 * 30
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const response = await fetch(url, {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: {
|
|
51
|
+
"Content-Type": "application/json",
|
|
52
|
+
Authorization: `Bearer ${this.token}`
|
|
53
|
+
},
|
|
54
|
+
body: JSON.stringify(request),
|
|
55
|
+
dispatcher
|
|
56
|
+
});
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
|
|
59
|
+
throw new Error(`API request failed: ${response.status} ${response.statusText} - ${JSON.stringify(errorData)}`);
|
|
60
|
+
}
|
|
61
|
+
const reader = response.body?.getReader();
|
|
62
|
+
if (!reader) throw new Error("Response body is not readable");
|
|
63
|
+
const decoder = new TextDecoder();
|
|
64
|
+
let buffer = "";
|
|
65
|
+
let result = { success: false };
|
|
66
|
+
try {
|
|
67
|
+
while (true) {
|
|
68
|
+
const { done, value } = await reader.read();
|
|
69
|
+
if (done) break;
|
|
70
|
+
buffer += decoder.decode(value, { stream: true });
|
|
71
|
+
const lines = buffer.split("\n");
|
|
72
|
+
buffer = lines.pop() ?? "";
|
|
73
|
+
for (const line of lines) {
|
|
74
|
+
if (line.startsWith("event:")) continue;
|
|
75
|
+
if (line.startsWith("data:")) {
|
|
76
|
+
const data = JSON.parse(line.slice(5).trim());
|
|
77
|
+
if ("contactsProcessed" in data) onProgress?.(data);
|
|
78
|
+
else if ("success" in data) result = data;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
throw new Error(`SSE stream failed: ${error instanceof Error ? error.message : "Unknown streaming error"}`);
|
|
85
|
+
} finally {
|
|
86
|
+
reader.releaseLock();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async request(path, options = {}) {
|
|
90
|
+
const url = `${this.baseUrl}${path}`;
|
|
91
|
+
const response = await fetch(url, {
|
|
92
|
+
...options,
|
|
93
|
+
headers: {
|
|
94
|
+
"Content-Type": "application/json",
|
|
95
|
+
Authorization: `Bearer ${this.token}`,
|
|
96
|
+
...options.headers
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
if (!response.ok) {
|
|
100
|
+
const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
|
|
101
|
+
throw new Error(`API request failed: ${response.status} ${response.statusText} - ${JSON.stringify(errorData)}`);
|
|
102
|
+
}
|
|
103
|
+
return response.json();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
export { BlipWarehouseClient };
|