@eulab/connect 0.0.0-stage → 0.8.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.
@@ -0,0 +1,150 @@
1
+ import type { InteractiveContent, ProviderCommand, ProviderOperation, ConversationContact, CallIdentity, CallCapabilities, CallSnapshot, CallActionResult } from './interactive.js';
2
+ import type { IVRInput, IVRChannel, VoiceIVRSession } from './bot.js';
3
+ import type { RealtimeConfig, WhatsAppSubscribeOptions } from './realtime.js';
4
+ import type { WhatsAppBotDefinition, WhatsAppBotState, WhatsAppBot, WhatsAppBotTurn } from './bot.js';
5
+ export interface WhatsAppSession {
6
+ id: string;
7
+ created_at: string;
8
+ number: string | null;
9
+ state: string;
10
+ archive_id: string | null;
11
+ runner_id: string;
12
+ runner_online: boolean;
13
+ closed_at: string | null;
14
+ delete_requested: boolean;
15
+ sync_count: number;
16
+ sync_status: string;
17
+ sync_limit: string;
18
+ }
19
+ export interface WhatsAppArchive {
20
+ id: string;
21
+ number: string;
22
+ installation_id: string;
23
+ }
24
+ export interface Conversation {
25
+ chat_id: string;
26
+ messages: number;
27
+ last_message_at: string;
28
+ preview: string;
29
+ kind: string;
30
+ direction: string;
31
+ contact: ConversationContact | null;
32
+ }
33
+ export interface WhatsAppMessage {
34
+ id: string;
35
+ chat_id: string;
36
+ direction: string;
37
+ kind: string;
38
+ occurred_at: string;
39
+ body: {
40
+ text?: string;
41
+ media?: string;
42
+ mediaAvailable?: boolean;
43
+ filename?: string;
44
+ mimetype?: string;
45
+ selectedButtonId?: string;
46
+ interactive?: InteractiveContent;
47
+ senderName?: string;
48
+ quotedText?: string;
49
+ };
50
+ }
51
+ export type WhatsAppPayload = {
52
+ kind: 'interactive';
53
+ to: string;
54
+ content: InteractiveContent;
55
+ } | {
56
+ kind: 'text';
57
+ to: string;
58
+ text: string;
59
+ } | {
60
+ kind: 'image' | 'document' | 'audio' | 'video';
61
+ to: string;
62
+ data: string;
63
+ filename: string;
64
+ caption?: string;
65
+ } | {
66
+ kind: 'poll';
67
+ to: string;
68
+ question: string;
69
+ options: string[];
70
+ };
71
+ export type Request = <T = any>(path: string, method?: string, body?: unknown, headers?: Record<string, string>) => Promise<T>;
72
+ export declare function whatsappClient(request: Request, installationId: string, realtime?: RealtimeConfig): {
73
+ subscribe: (options: WhatsAppSubscribeOptions) => import("./realtime.js").WhatsAppSubscription;
74
+ bot: {
75
+ get: (archiveId: string) => Promise<WhatsAppBot>;
76
+ configure: (archiveId: string, definition: WhatsAppBotDefinition, expectedRevision: number) => Promise<WhatsAppBot>;
77
+ activate: (archiveId: string, enabled: boolean, expectedRevision: number) => Promise<WhatsAppBot>;
78
+ preview: (definition: WhatsAppBotDefinition, input: string | IVRInput, state?: WhatsAppBotState | null, channel?: IVRChannel) => Promise<WhatsAppBotTurn & {
79
+ sent: false;
80
+ }>;
81
+ };
82
+ ivr: {
83
+ get: (archiveId: string, id: string) => Promise<VoiceIVRSession>;
84
+ start: (archiveId: string, callId: string, idempotencyKey?: `${string}-${string}-${string}-${string}-${string}`) => Promise<VoiceIVRSession>;
85
+ advance: (archiveId: string, id: string, input: IVRInput, expectedTurn: number, idempotencyKey?: `${string}-${string}-${string}-${string}-${string}`) => Promise<VoiceIVRSession>;
86
+ };
87
+ operations: {
88
+ get: <T = unknown>(id: string) => Promise<ProviderOperation<T>>;
89
+ list: () => Promise<ProviderOperation<unknown>[]>;
90
+ submit: (id: string, command: ProviderCommand, idempotencyKey?: `${string}-${string}-${string}-${string}-${string}`) => Promise<ProviderOperation<unknown>>;
91
+ };
92
+ calls: {
93
+ inspect: (id: string) => Promise<ProviderOperation<{
94
+ capabilities: CallCapabilities;
95
+ active: CallSnapshot | null;
96
+ }>>;
97
+ start: (id: string, to: string, key?: `${string}-${string}-${string}-${string}-${string}`) => Promise<ProviderOperation<CallActionResult>>;
98
+ control: (id: string, action: "accept" | "reject" | "end" | "mute", call: CallIdentity, muted?: boolean, key?: `${string}-${string}-${string}-${string}-${string}`) => Promise<ProviderOperation<CallActionResult>>;
99
+ };
100
+ refreshContact: (id: string, chatId: string) => Promise<ProviderOperation<ConversationContact>>;
101
+ sessions: () => Promise<WhatsAppSession[]>;
102
+ connect: () => Promise<{
103
+ id: string;
104
+ state: string;
105
+ }>;
106
+ qr: (id: string) => Promise<{
107
+ state: string;
108
+ qr: string | null;
109
+ }>;
110
+ send: (id: string, payload: WhatsAppPayload, idempotencyKey?: `${string}-${string}-${string}-${string}-${string}`) => Promise<{
111
+ id: string;
112
+ state: string;
113
+ }>;
114
+ test: (id: string, payload: WhatsAppPayload) => Promise<{
115
+ valid: boolean;
116
+ kind: string;
117
+ to: string;
118
+ connected: boolean;
119
+ sent: false;
120
+ }>;
121
+ outbox: () => Promise<{
122
+ id: string;
123
+ session_id: string;
124
+ state: string;
125
+ provider_id: string | null;
126
+ error: string | null;
127
+ created_at: string;
128
+ }[]>;
129
+ sendText: (id: string, to: string, text: string, idempotencyKey?: `${string}-${string}-${string}-${string}-${string}`) => Promise<{
130
+ id: string;
131
+ state: string;
132
+ }>;
133
+ reconnect: (id: string) => Promise<any>;
134
+ disconnect: (id: string) => Promise<any>;
135
+ deleteConnection: (id: string) => Promise<{
136
+ removed: boolean;
137
+ state: string;
138
+ }>;
139
+ deleteArchive: (id: string) => Promise<{
140
+ removed: boolean;
141
+ state: string;
142
+ }>;
143
+ archives: () => Promise<WhatsAppArchive[]>;
144
+ messages: (id: string, before?: string, chat?: string) => Promise<WhatsAppMessage[]>;
145
+ conversations: (id: string) => Promise<Conversation[]>;
146
+ media: (archiveId: string, messageId: string) => Promise<{
147
+ data: string | null;
148
+ state: "available" | "queued";
149
+ }>;
150
+ };
@@ -0,0 +1,44 @@
1
+ import { subscribeWhatsApp } from './realtime.js';
2
+ export function whatsappClient(request, installationId, realtime = { apiUrl: '' }) {
3
+ const root = `/v1/installations/${encodeURIComponent(installationId)}/whatsapp`;
4
+ const session = (id) => root + `/sessions/${encodeURIComponent(id)}`;
5
+ const archive = (id) => root + `/archives/${encodeURIComponent(id)}`;
6
+ return {
7
+ subscribe: (options) => subscribeWhatsApp(request, root, realtime, options),
8
+ bot: {
9
+ get: (archiveId) => request(archive(archiveId) + '/bot'),
10
+ configure: (archiveId, definition, expectedRevision) => request(archive(archiveId) + '/bot', 'PUT', { definition, expectedRevision }),
11
+ activate: (archiveId, enabled, expectedRevision) => request(archive(archiveId) + '/bot/activation', 'PUT', { enabled, expectedRevision }),
12
+ preview: (definition, input, state = null, channel = 'whatsapp') => request(root + '/bot/preview', 'POST', { definition, input, state, channel })
13
+ },
14
+ ivr: {
15
+ get: (archiveId, id) => request(archive(archiveId) + `/bot/voice-sessions/${encodeURIComponent(id)}`),
16
+ start: (archiveId, callId, idempotencyKey = crypto.randomUUID()) => request(archive(archiveId) + '/bot/voice-sessions', 'POST', { callId }, { 'Idempotency-Key': idempotencyKey }),
17
+ advance: (archiveId, id, input, expectedTurn, idempotencyKey = crypto.randomUUID()) => request(archive(archiveId) + `/bot/voice-sessions/${encodeURIComponent(id)}/turns`, 'POST', { input, expectedTurn }, { 'Idempotency-Key': idempotencyKey })
18
+ },
19
+ operations: {
20
+ get: (id) => request(root + `/operations/${encodeURIComponent(id)}`),
21
+ list: () => request(root + '/operations'),
22
+ submit: (id, command, idempotencyKey = crypto.randomUUID()) => request(session(id) + '/operations', 'POST', command, { 'Idempotency-Key': idempotencyKey })
23
+ },
24
+ calls: {
25
+ inspect: (id) => request(session(id) + '/operations', 'POST', { kind: 'call.inspect' }, { 'Idempotency-Key': crypto.randomUUID() }),
26
+ start: (id, to, key = crypto.randomUUID()) => request(session(id) + '/operations', 'POST', { kind: 'call.start', to }, { 'Idempotency-Key': key }),
27
+ control: (id, action, call, muted = false, key = crypto.randomUUID()) => request(session(id) + '/operations', 'POST', { kind: 'call.' + action, call, ...action === 'mute' ? { muted } : {} }, { 'Idempotency-Key': key })
28
+ },
29
+ refreshContact: (id, chatId) => request(session(id) + '/operations', 'POST', { kind: 'contact.refresh', chatId }, { 'Idempotency-Key': crypto.randomUUID() }),
30
+ sessions: () => request(root + '/sessions'), connect: () => request(root + '/sessions', 'POST'),
31
+ qr: (id) => request(session(id) + '/qr'),
32
+ send: (id, payload, idempotencyKey = crypto.randomUUID()) => request(session(id) + '/messages', 'POST', payload, { 'Idempotency-Key': idempotencyKey }),
33
+ test: (id, payload) => request(session(id) + '/messages/test', 'POST', payload),
34
+ outbox: () => request(root + '/outbox'),
35
+ sendText: (id, to, text, idempotencyKey = crypto.randomUUID()) => request(session(id) + '/messages', 'POST', { kind: 'text', to, text }, { 'Idempotency-Key': idempotencyKey }),
36
+ reconnect: (id) => request(session(id) + '/reconnect', 'POST'), disconnect: (id) => request(session(id) + '/disconnect', 'POST'),
37
+ deleteConnection: (id) => request(session(id), 'DELETE'),
38
+ deleteArchive: (id) => request(archive(id), 'DELETE'),
39
+ archives: () => request(root + '/archives'),
40
+ messages: (id, before, chat) => request(archive(id) + `/messages?${new URLSearchParams({ ...before ? { before } : {}, ...chat ? { chat } : {} })}`),
41
+ conversations: (id) => request(archive(id) + '/conversations'),
42
+ media: (archiveId, messageId) => request(archive(archiveId) + `/messages/${encodeURIComponent(messageId)}/media`)
43
+ };
44
+ }
package/package.json CHANGED
@@ -1,6 +1,21 @@
1
1
  {
2
2
  "name": "@eulab/connect",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.8.1",
4
+ "description": "SDK EULab Connect per browser e server: SSO, permessi e WhatsApp",
5
+ "author": "EULAB",
6
+ "type": "module",
7
+ "exports": {
8
+ "./browser": {"types": "./dist/browser.d.ts", "import": "./dist/browser.js"},
9
+ "./server": {"types": "./dist/server.d.ts", "import": "./dist/server.js"}
10
+ },
11
+ "scripts": {
12
+ "build": "tsc -p tsconfig.json",
13
+ "prepack": "npm run build"
14
+ },
15
+ "publishConfig": {"access": "public", "registry": "https://registry.npmjs.org/"},
16
+ "engines": {"node": ">=22"},
17
+ "files": [
18
+ "dist",
19
+ "!dist/**/*.map"
20
+ ]
21
+ }