@whitewall/blip-warehouse 0.0.1
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 +13 -0
- package/dist/api/src/index.d.ts +2 -0
- package/dist/api/src/types.d.ts +14 -0
- package/dist/index.cjs +50 -0
- package/dist/index.js +49 -0
- package/dist/src/warehouse/schemas.d.ts +4 -0
- package/dist/src/warehouse/types.d.ts +47 -0
- package/package.json +27 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { GetMessagesOptions, MessagesByIdentityResult, SearchRequest, SearchResult } from './types';
|
|
2
|
+
export declare class WarehouseClient {
|
|
3
|
+
private readonly baseUrl;
|
|
4
|
+
private readonly token;
|
|
5
|
+
constructor(config: {
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
token: string;
|
|
8
|
+
});
|
|
9
|
+
private request;
|
|
10
|
+
getContactsCount(): Promise<number>;
|
|
11
|
+
search(request: SearchRequest): Promise<SearchResult>;
|
|
12
|
+
getMessagesByIdentity(identity: string, options?: GetMessagesOptions): Promise<MessagesByIdentityResult>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type { IndexedContact, IndexedMessage, MessageRow, MessagesByIdentityResult, PaginationCursor, SearchResult, } from '../../src/warehouse/types.js';
|
|
2
|
+
import type { PaginationCursor } from '../../src/warehouse/types.js';
|
|
3
|
+
export interface ContactsCountResponse {
|
|
4
|
+
count: number;
|
|
5
|
+
}
|
|
6
|
+
export interface SearchRequest {
|
|
7
|
+
query: string;
|
|
8
|
+
limit?: number;
|
|
9
|
+
cursor?: PaginationCursor;
|
|
10
|
+
}
|
|
11
|
+
export interface GetMessagesOptions {
|
|
12
|
+
limit?: number;
|
|
13
|
+
cursor?: string;
|
|
14
|
+
}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/client.ts
|
|
3
|
+
var WarehouseClient = class {
|
|
4
|
+
baseUrl;
|
|
5
|
+
token;
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.baseUrl = config.baseUrl?.replace(/\/$/, "") ?? "https://api.warehouse.whitewall.dev";
|
|
8
|
+
this.token = config.token;
|
|
9
|
+
}
|
|
10
|
+
async request(path, options = {}) {
|
|
11
|
+
const url = `${this.baseUrl}${path}`;
|
|
12
|
+
const response = await fetch(url, {
|
|
13
|
+
...options,
|
|
14
|
+
headers: {
|
|
15
|
+
"Content-Type": "application/json",
|
|
16
|
+
Authorization: `Bearer ${this.token}`,
|
|
17
|
+
...options.headers
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
|
|
22
|
+
throw new Error(`API request failed: ${response.status} ${response.statusText} - ${JSON.stringify(errorData)}`);
|
|
23
|
+
}
|
|
24
|
+
return response.json();
|
|
25
|
+
}
|
|
26
|
+
async getContactsCount() {
|
|
27
|
+
return (await this.request("/warehouse/contacts")).count;
|
|
28
|
+
}
|
|
29
|
+
async search(request) {
|
|
30
|
+
return this.request("/warehouse/search", {
|
|
31
|
+
method: "POST",
|
|
32
|
+
body: JSON.stringify({
|
|
33
|
+
query: request.query,
|
|
34
|
+
limit: request.limit ?? 10,
|
|
35
|
+
cursor: request.cursor
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async getMessagesByIdentity(identity, options = {}) {
|
|
40
|
+
const params = new URLSearchParams();
|
|
41
|
+
if (options.limit !== void 0) params.append("limit", options.limit.toString());
|
|
42
|
+
if (options.cursor) params.append("cursor", options.cursor);
|
|
43
|
+
const queryString = params.toString();
|
|
44
|
+
const path = `/warehouse/contacts/${encodeURIComponent(identity)}/messages${queryString ? `?${queryString}` : ""}`;
|
|
45
|
+
return this.request(path);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
exports.WarehouseClient = WarehouseClient;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region src/client.ts
|
|
2
|
+
var WarehouseClient = class {
|
|
3
|
+
baseUrl;
|
|
4
|
+
token;
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.baseUrl = config.baseUrl?.replace(/\/$/, "") ?? "https://api.warehouse.whitewall.dev";
|
|
7
|
+
this.token = config.token;
|
|
8
|
+
}
|
|
9
|
+
async request(path, options = {}) {
|
|
10
|
+
const url = `${this.baseUrl}${path}`;
|
|
11
|
+
const response = await fetch(url, {
|
|
12
|
+
...options,
|
|
13
|
+
headers: {
|
|
14
|
+
"Content-Type": "application/json",
|
|
15
|
+
Authorization: `Bearer ${this.token}`,
|
|
16
|
+
...options.headers
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
|
|
21
|
+
throw new Error(`API request failed: ${response.status} ${response.statusText} - ${JSON.stringify(errorData)}`);
|
|
22
|
+
}
|
|
23
|
+
return response.json();
|
|
24
|
+
}
|
|
25
|
+
async getContactsCount() {
|
|
26
|
+
return (await this.request("/warehouse/contacts")).count;
|
|
27
|
+
}
|
|
28
|
+
async search(request) {
|
|
29
|
+
return this.request("/warehouse/search", {
|
|
30
|
+
method: "POST",
|
|
31
|
+
body: JSON.stringify({
|
|
32
|
+
query: request.query,
|
|
33
|
+
limit: request.limit ?? 10,
|
|
34
|
+
cursor: request.cursor
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async getMessagesByIdentity(identity, options = {}) {
|
|
39
|
+
const params = new URLSearchParams();
|
|
40
|
+
if (options.limit !== void 0) params.append("limit", options.limit.toString());
|
|
41
|
+
if (options.cursor) params.append("cursor", options.cursor);
|
|
42
|
+
const queryString = params.toString();
|
|
43
|
+
const path = `/warehouse/contacts/${encodeURIComponent(identity)}/messages${queryString ? `?${queryString}` : ""}`;
|
|
44
|
+
return this.request(path);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { WarehouseClient };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Contact, UnknownMessage } from '@whitewall/blip-sdk';
|
|
2
|
+
import type z from 'zod';
|
|
3
|
+
import type { cursorSchema } from './schemas.ts';
|
|
4
|
+
type Nullable<T> = {
|
|
5
|
+
[K in keyof T]: T[K] | null;
|
|
6
|
+
};
|
|
7
|
+
export type IndexedMessage = UnknownMessage & {
|
|
8
|
+
botIdentifier: string;
|
|
9
|
+
created: string;
|
|
10
|
+
};
|
|
11
|
+
export type IndexedContact = Nullable<NonNullable<Omit<Contact, 'source' | 'group' | 'city'>>> & {
|
|
12
|
+
botIdentifier: string;
|
|
13
|
+
created: string;
|
|
14
|
+
};
|
|
15
|
+
export type SearchResultTypes = {
|
|
16
|
+
contacts: IndexedContact;
|
|
17
|
+
messages: IndexedMessage;
|
|
18
|
+
};
|
|
19
|
+
export type PaginationCursor = z.infer<typeof cursorSchema>;
|
|
20
|
+
export type SearchResult = {
|
|
21
|
+
items: Array<{
|
|
22
|
+
index: keyof SearchResultTypes;
|
|
23
|
+
data: SearchResultTypes[keyof SearchResultTypes];
|
|
24
|
+
}>;
|
|
25
|
+
total: number;
|
|
26
|
+
cursor?: PaginationCursor;
|
|
27
|
+
};
|
|
28
|
+
export type SearchParams = {
|
|
29
|
+
limit: number;
|
|
30
|
+
cursor?: PaginationCursor;
|
|
31
|
+
};
|
|
32
|
+
export type MessageRow = {
|
|
33
|
+
id: string;
|
|
34
|
+
type: string;
|
|
35
|
+
from: string;
|
|
36
|
+
to: string;
|
|
37
|
+
content: string;
|
|
38
|
+
metadata: Record<string, unknown> | null;
|
|
39
|
+
botIdentifier: string;
|
|
40
|
+
created: string;
|
|
41
|
+
};
|
|
42
|
+
export type MessagesByIdentityResult = {
|
|
43
|
+
items: Array<MessageRow>;
|
|
44
|
+
total: number;
|
|
45
|
+
cursor?: PaginationCursor;
|
|
46
|
+
};
|
|
47
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@whitewall/blip-warehouse",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "rolldown --config rolldown.config.ts && tsc --emitDeclarationOnly",
|
|
20
|
+
"dev": "rolldown --config rolldown.config.ts --watch"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"rolldown": "1.0.0-beta.52",
|
|
25
|
+
"typescript": "5.7.2"
|
|
26
|
+
}
|
|
27
|
+
}
|