@whitewall/blip-sdk 0.0.167 → 0.0.169
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/client.js +4 -1
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/index.js +4 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/namespaces/account.js +23 -7
- package/dist/cjs/namespaces/account.js.map +1 -1
- package/dist/cjs/namespaces/analytics.js +4 -5
- package/dist/cjs/namespaces/analytics.js.map +1 -1
- package/dist/cjs/namespaces/desk.js +2 -2
- package/dist/cjs/namespaces/desk.js.map +1 -1
- package/dist/cjs/schemas/index.js +0 -16
- package/dist/cjs/schemas/index.js.map +1 -1
- package/dist/cjs/schemas/webhook.js +20 -6
- package/dist/cjs/schemas/webhook.js.map +1 -1
- package/dist/cjs/sender/index.js +4 -4
- package/dist/cjs/sender/index.js.map +1 -1
- package/dist/cjs/sender/sessionnegotiator.js +2 -2
- package/dist/cjs/sender/sessionnegotiator.js.map +1 -1
- package/dist/cjs/sender/tcp/tcpsender.js +1 -1
- package/dist/cjs/sender/tcp/tcpsender.js.map +1 -1
- package/dist/cjs/types/index.js +9 -9
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/message.js.map +1 -1
- package/dist/cjs/types/webhook.js +2 -0
- package/dist/cjs/types/webhook.js.map +1 -1
- package/dist/cjs/utils/logger.js +1 -0
- package/dist/cjs/utils/logger.js.map +1 -1
- package/dist/esm/client.js +4 -1
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/namespaces/account.js +23 -7
- package/dist/esm/namespaces/account.js.map +1 -1
- package/dist/esm/namespaces/analytics.js +4 -5
- package/dist/esm/namespaces/analytics.js.map +1 -1
- package/dist/esm/namespaces/desk.js +2 -2
- package/dist/esm/namespaces/desk.js.map +1 -1
- package/dist/esm/schemas/index.js +0 -14
- package/dist/esm/schemas/index.js.map +1 -1
- package/dist/esm/schemas/webhook.js +18 -5
- package/dist/esm/schemas/webhook.js.map +1 -1
- package/dist/esm/sender/enveloperesolver.js +1 -1
- package/dist/esm/sender/enveloperesolver.js.map +1 -1
- package/dist/esm/sender/index.js +4 -4
- package/dist/esm/sender/index.js.map +1 -1
- package/dist/esm/sender/sessionnegotiator.js +2 -2
- package/dist/esm/sender/sessionnegotiator.js.map +1 -1
- package/dist/esm/sender/tcp/tcpsender.js +1 -1
- package/dist/esm/sender/tcp/tcpsender.js.map +1 -1
- package/dist/esm/types/index.js +9 -9
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/message.js.map +1 -1
- package/dist/esm/types/webhook.js +1 -1
- package/dist/esm/types/webhook.js.map +1 -1
- package/dist/esm/utils/logger.js +1 -0
- package/dist/esm/utils/logger.js.map +1 -1
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/namespaces/account.d.ts.map +1 -1
- package/dist/types/namespaces/analytics.d.ts +4 -5
- package/dist/types/namespaces/analytics.d.ts.map +1 -1
- package/dist/types/namespaces/desk.d.ts.map +1 -1
- package/dist/types/schemas/index.d.ts +0 -3
- package/dist/types/schemas/index.d.ts.map +1 -1
- package/dist/types/schemas/webhook.d.ts +10 -7
- package/dist/types/schemas/webhook.d.ts.map +1 -1
- package/dist/types/sender/enveloperesolver.d.ts.map +1 -1
- package/dist/types/sender/index.d.ts +4 -4
- package/dist/types/sender/index.d.ts.map +1 -1
- package/dist/types/sender/sessionnegotiator.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +9 -9
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/types/message.d.ts +1 -1
- package/dist/types/types/message.d.ts.map +1 -1
- package/dist/types/types/webhook.d.ts +5 -4
- package/dist/types/types/webhook.d.ts.map +1 -1
- package/dist/types/utils/logger.d.ts.map +1 -1
- package/package.json +6 -3
- package/src/client.ts +5 -1
- package/src/index.ts +4 -4
- package/src/namespaces/account.ts +35 -22
- package/src/namespaces/analytics.ts +6 -7
- package/src/namespaces/desk.ts +5 -6
- package/src/schemas/index.ts +0 -19
- package/src/schemas/webhook.ts +20 -5
- package/src/sender/enveloperesolver.ts +3 -3
- package/src/sender/index.ts +4 -4
- package/src/sender/sessionnegotiator.ts +3 -6
- package/src/sender/tcp/tcpsender.ts +1 -1
- package/src/types/index.ts +9 -9
- package/src/types/message.ts +1 -1
- package/src/types/webhook.ts +6 -4
- package/src/utils/logger.ts +1 -0
package/src/namespaces/desk.ts
CHANGED
|
@@ -364,7 +364,7 @@ export class DeskNamespace extends Namespace {
|
|
|
364
364
|
audience: {
|
|
365
365
|
recipient: phoneNumber,
|
|
366
366
|
recipientType: 'phoneNumber',
|
|
367
|
-
channelType: '
|
|
367
|
+
channelType: 'whatsapp',
|
|
368
368
|
messageParams: { ...message.variables },
|
|
369
369
|
},
|
|
370
370
|
message: {
|
|
@@ -637,12 +637,11 @@ export class DeskNamespace extends Namespace {
|
|
|
637
637
|
) {
|
|
638
638
|
delete extensions[id]
|
|
639
639
|
}
|
|
640
|
-
|
|
641
|
-
return await this.blipClient.account.setConfigurations(
|
|
642
|
-
{ Extensions: JSON.stringify(extensions) },
|
|
643
|
-
{ ...opts, ownerIdentity: this.identity },
|
|
644
|
-
)
|
|
645
640
|
}
|
|
641
|
+
return await this.blipClient.account.setConfigurations(
|
|
642
|
+
{ Extensions: JSON.stringify(extensions) },
|
|
643
|
+
{ ...opts, ownerIdentity: this.identity },
|
|
644
|
+
)
|
|
646
645
|
}
|
|
647
646
|
}
|
|
648
647
|
|
package/src/schemas/index.ts
CHANGED
|
@@ -1,20 +1 @@
|
|
|
1
|
-
import './utils/validate.ts'
|
|
2
|
-
|
|
3
1
|
export * from './webhook.ts'
|
|
4
|
-
|
|
5
|
-
import type { WebhookTypes } from '../types/webhook.ts'
|
|
6
|
-
|
|
7
|
-
import { contactSchema, eventSchema, messageSchema } from './webhook.ts'
|
|
8
|
-
|
|
9
|
-
export const isWebhookType = <T extends keyof WebhookTypes>(type: T, data: unknown): data is WebhookTypes[T] => {
|
|
10
|
-
switch (type) {
|
|
11
|
-
case 'contacts':
|
|
12
|
-
return !eventSchema.safeParse(data).success && contactSchema.safeParse(data).success
|
|
13
|
-
case 'messages':
|
|
14
|
-
return messageSchema.safeParse(data).success
|
|
15
|
-
case 'events':
|
|
16
|
-
return eventSchema.safeParse(data).success
|
|
17
|
-
default:
|
|
18
|
-
return false
|
|
19
|
-
}
|
|
20
|
-
}
|
package/src/schemas/webhook.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
2
|
import type { UnknownMessage } from '../types/index.ts'
|
|
3
|
+
import './utils/validate.ts'
|
|
4
|
+
import type { WebhookTypes } from '../types/webhook.ts'
|
|
3
5
|
|
|
4
|
-
export const
|
|
6
|
+
export const contactsSchema = z.object({
|
|
5
7
|
identity: z.string().identity(),
|
|
6
8
|
name: z.string().optional(),
|
|
7
9
|
group: z.string().optional(),
|
|
@@ -13,9 +15,9 @@ export const contactSchema = z.object({
|
|
|
13
15
|
extras: z.record(z.string(), z.string().or(z.null())).optional(),
|
|
14
16
|
})
|
|
15
17
|
|
|
16
|
-
export const
|
|
18
|
+
export const messagesSchema = z
|
|
17
19
|
.object({
|
|
18
|
-
id: z.string()
|
|
20
|
+
id: z.string(),
|
|
19
21
|
type: z.string(),
|
|
20
22
|
from: z.string().identity(),
|
|
21
23
|
to: z.string().identity(),
|
|
@@ -31,7 +33,7 @@ export const messageSchema = z
|
|
|
31
33
|
},
|
|
32
34
|
)
|
|
33
35
|
|
|
34
|
-
export const
|
|
36
|
+
export const eventtrackingsSchema = z.object({
|
|
35
37
|
identity: z.string().identity().optional(),
|
|
36
38
|
messageId: z.string().optional(),
|
|
37
39
|
category: z.string(),
|
|
@@ -44,4 +46,17 @@ export const eventSchema = z.object({
|
|
|
44
46
|
|
|
45
47
|
// The order is important here. We must try to parse more specific types first.
|
|
46
48
|
// e.g., if contact came before event, no event would be ever caught as such
|
|
47
|
-
export const blipWebhookSchema =
|
|
49
|
+
export const blipWebhookSchema = eventtrackingsSchema.or(messagesSchema).or(contactsSchema)
|
|
50
|
+
|
|
51
|
+
export const isWebhookType = <T extends keyof WebhookTypes>(type: T, data: unknown): data is WebhookTypes[T] => {
|
|
52
|
+
switch (type) {
|
|
53
|
+
case 'contacts':
|
|
54
|
+
return !eventtrackingsSchema.safeParse(data).success && contactsSchema.safeParse(data).success
|
|
55
|
+
case 'messages':
|
|
56
|
+
return messagesSchema.safeParse(data).success
|
|
57
|
+
case 'eventtrackings':
|
|
58
|
+
return eventtrackingsSchema.safeParse(data).success
|
|
59
|
+
default:
|
|
60
|
+
return false
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -2,15 +2,15 @@ import {
|
|
|
2
2
|
type CommonNotification,
|
|
3
3
|
type Envelope,
|
|
4
4
|
type FailedNotification,
|
|
5
|
+
isCommand,
|
|
6
|
+
isMessage,
|
|
7
|
+
isNotification,
|
|
5
8
|
type Json,
|
|
6
9
|
type MaybePromise,
|
|
7
10
|
Node,
|
|
8
11
|
type Notification,
|
|
9
12
|
type UnknownCommand,
|
|
10
13
|
type UnknownMessage,
|
|
11
|
-
isCommand,
|
|
12
|
-
isMessage,
|
|
13
|
-
isNotification,
|
|
14
14
|
} from '../types/index.ts'
|
|
15
15
|
import { ReasonCodes } from '../types/reason.ts'
|
|
16
16
|
import { RetryableError } from './retryableerror.ts'
|
package/src/sender/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './sender.ts'
|
|
2
1
|
export * from './bliperror.ts'
|
|
3
2
|
export * from './gateway/customgatewaysender.ts'
|
|
4
|
-
export * from './
|
|
3
|
+
export * from './http/httpsender.ts'
|
|
5
4
|
export * from './multi/multisender.ts'
|
|
6
|
-
export * from './
|
|
5
|
+
export * from './plugin/pluginsender.ts'
|
|
6
|
+
export * from './sender.ts'
|
|
7
7
|
export * from './tcp/tcpsender.ts'
|
|
8
|
-
export * from './
|
|
8
|
+
export * from './websocket/websocketsender.ts'
|
|
@@ -23,13 +23,10 @@ export class SessionNegotiator {
|
|
|
23
23
|
private readonly sendSession: (session: Session) => void,
|
|
24
24
|
) {}
|
|
25
25
|
|
|
26
|
-
public async negotiate(options: {
|
|
27
|
-
|
|
28
|
-
authentication: Authentication
|
|
29
|
-
}): Promise<void> {
|
|
30
|
-
const timeout = setTimeout(() => {
|
|
26
|
+
public async negotiate(options: { node: NodeLike; authentication: Authentication }): Promise<void> {
|
|
27
|
+
const timeout = setTimeout(async () => {
|
|
31
28
|
if (this.negotiating) {
|
|
32
|
-
this.sender.close()
|
|
29
|
+
await this.sender.close()
|
|
33
30
|
throw new Error('Negotiation timeout')
|
|
34
31
|
}
|
|
35
32
|
}, 60000) // 60 seconds
|
|
@@ -33,7 +33,7 @@ export class TCPSender extends OpenConnectionSender {
|
|
|
33
33
|
this.connectionHandle = new TCPHandle<Envelope>(
|
|
34
34
|
`${prefix}tcp.${this.domain}`,
|
|
35
35
|
443,
|
|
36
|
-
|
|
36
|
+
(socket) => {
|
|
37
37
|
this.sessionNegotiator = new SessionNegotiator(this, (session) => {
|
|
38
38
|
socket.write(JSON.stringify(session))
|
|
39
39
|
})
|
package/src/types/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './account.ts'
|
|
2
|
+
export * from './analytics.ts'
|
|
3
|
+
export * from './command.ts'
|
|
4
|
+
export * from './commons.ts'
|
|
5
|
+
export * from './desk.ts'
|
|
2
6
|
export * from './envelope.ts'
|
|
7
|
+
export * from './flow.ts'
|
|
3
8
|
export * from './message.ts'
|
|
4
|
-
export * from './
|
|
9
|
+
export * from './node.ts'
|
|
5
10
|
export * from './notification.ts'
|
|
6
|
-
export * from './desk.ts'
|
|
7
|
-
export * from './account.ts'
|
|
8
|
-
export * from './whatsapp.ts'
|
|
9
|
-
export * from './portal.ts'
|
|
10
11
|
export * from './plugins.ts'
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './commons.ts'
|
|
12
|
+
export * from './portal.ts'
|
|
13
|
+
export * from './whatsapp.ts'
|
package/src/types/message.ts
CHANGED
|
@@ -101,7 +101,7 @@ export const isMessage = (envelope: Envelope): envelope is UnknownMessage =>
|
|
|
101
101
|
'type' in envelope && 'content' in envelope && typeof envelope.type === 'string'
|
|
102
102
|
|
|
103
103
|
export const isMessageOfType = <Type extends MessageTypes>(
|
|
104
|
-
message:
|
|
104
|
+
message: UnknownMessage,
|
|
105
105
|
type: Type,
|
|
106
106
|
): message is Message<Type> => message.type === type
|
|
107
107
|
|
package/src/types/webhook.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { z } from 'zod'
|
|
2
|
-
import type {
|
|
2
|
+
import type { contactsSchema, eventtrackingsSchema, messagesSchema } from '../schemas/index.ts'
|
|
3
3
|
|
|
4
4
|
export type WebhookTypes = {
|
|
5
|
-
contacts: z.TypeOf<typeof
|
|
6
|
-
messages: z.TypeOf<typeof
|
|
7
|
-
|
|
5
|
+
contacts: z.TypeOf<typeof contactsSchema>
|
|
6
|
+
messages: z.TypeOf<typeof messagesSchema>
|
|
7
|
+
eventtrackings: z.TypeOf<typeof eventtrackingsSchema>
|
|
8
8
|
}
|
|
9
|
+
|
|
10
|
+
export const webhookTypes = ['contacts', 'messages', 'eventtrackings'] as const satisfies Array<keyof WebhookTypes>
|
package/src/utils/logger.ts
CHANGED
|
@@ -23,6 +23,7 @@ export const logger = {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const prefix = `[${module}] ${message}`
|
|
26
|
+
// biome-ignore lint/suspicious/noConsole: it is the logger
|
|
26
27
|
console[level].apply(console, [prefix, ...args])
|
|
27
28
|
},
|
|
28
29
|
error: function (module: string, message: string, ...args: Array<unknown>): void {
|