@whitewall/blip-sdk 0.0.136 → 0.0.137
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/package.json +2 -2
- package/src/client.ts +117 -0
- package/src/index.ts +6 -0
- package/src/namespaces/account.ts +729 -0
- package/src/namespaces/activecampaign.ts +285 -0
- package/src/namespaces/analytics.ts +230 -0
- package/src/namespaces/billing.ts +17 -0
- package/src/namespaces/builder.ts +52 -0
- package/src/namespaces/configurations.ts +19 -0
- package/src/namespaces/context.ts +67 -0
- package/src/namespaces/desk.ts +679 -0
- package/src/namespaces/media.ts +39 -0
- package/src/namespaces/namespace.ts +125 -0
- package/src/namespaces/plugins.ts +223 -0
- package/src/namespaces/portal.ts +402 -0
- package/src/namespaces/scheduler.ts +88 -0
- package/src/namespaces/whatsapp.ts +383 -0
- package/src/sender/bliperror.ts +42 -0
- package/src/sender/enveloperesolver.ts +148 -0
- package/src/sender/gateway/customgatewaysender.ts +43 -0
- package/src/sender/http/httpsender.ts +94 -0
- package/src/sender/index.ts +7 -0
- package/src/sender/plugin/communication.ts +72 -0
- package/src/sender/plugin/pluginsender.ts +75 -0
- package/src/sender/security.ts +33 -0
- package/src/sender/sender.ts +145 -0
- package/src/sender/sessionnegotiator.ts +175 -0
- package/src/sender/tcp/tcpsender.ts +252 -0
- package/src/sender/throttler.ts +36 -0
- package/src/sender/websocket/websocketsender.ts +175 -0
- package/src/types/account.ts +84 -0
- package/src/types/analytics.ts +18 -0
- package/src/types/billing.ts +15 -0
- package/src/types/command.ts +47 -0
- package/src/types/commons.ts +16 -0
- package/src/types/desk.ts +51 -0
- package/src/types/envelope.ts +9 -0
- package/src/types/flow.ts +327 -0
- package/src/types/index.ts +13 -0
- package/src/types/message.ts +116 -0
- package/src/types/node.ts +86 -0
- package/src/types/notification.ts +18 -0
- package/src/types/plugins.ts +51 -0
- package/src/types/portal.ts +39 -0
- package/src/types/reason.ts +22 -0
- package/src/types/session.ts +22 -0
- package/src/types/whatsapp.ts +84 -0
- package/src/utils/odata.ts +114 -0
- package/src/utils/random.ts +3 -0
- package/src/utils/uri.ts +46 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whitewall/blip-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.137",
|
|
4
4
|
"description": "Blip API wrapper",
|
|
5
5
|
"exports": {
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"lint:nofix": "biome ci .",
|
|
18
18
|
"test": "node --experimental-transform-types --test ./test/*.spec.ts"
|
|
19
19
|
},
|
|
20
|
-
"files": ["dist/*"],
|
|
20
|
+
"files": ["dist/*", "src/*"],
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@biomejs/biome": "1.9.4",
|
|
23
23
|
"@types/node": "22.14.1",
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { AccountNamespace } from './namespaces/account.ts'
|
|
2
|
+
import { ActiveCampaignNamespace } from './namespaces/activecampaign.ts'
|
|
3
|
+
import { AnalyticsNamespace } from './namespaces/analytics.ts'
|
|
4
|
+
import { BillingNamespace } from './namespaces/billing.ts'
|
|
5
|
+
import { BuilderNamespace } from './namespaces/builder.ts'
|
|
6
|
+
import { ContextNamespace } from './namespaces/context.ts'
|
|
7
|
+
import { DeskNamespace } from './namespaces/desk.ts'
|
|
8
|
+
import { MediaNamespace } from './namespaces/media.ts'
|
|
9
|
+
import type { SendCommandOptions } from './namespaces/namespace.ts'
|
|
10
|
+
import { PluginsNamespace } from './namespaces/plugins.ts'
|
|
11
|
+
import { PortalNamespace } from './namespaces/portal.ts'
|
|
12
|
+
import { SchedulerNamespace } from './namespaces/scheduler.ts'
|
|
13
|
+
import { WhatsAppNamespace } from './namespaces/whatsapp.ts'
|
|
14
|
+
import { HttpSender } from './sender/http/httpsender.ts'
|
|
15
|
+
import { type ConnectionSenderConstructor, OpenConnectionSender, type Sender } from './sender/sender.ts'
|
|
16
|
+
import type { Message, MessageTypes } from './types/message.ts'
|
|
17
|
+
import { type BlipDomain, type Identity, Node } from './types/node.ts'
|
|
18
|
+
import { randomId } from './utils/random.ts'
|
|
19
|
+
|
|
20
|
+
export class BlipClient<TSender extends Sender = Sender> {
|
|
21
|
+
constructor(
|
|
22
|
+
public readonly sender: TSender,
|
|
23
|
+
defaultOptions?: SendCommandOptions,
|
|
24
|
+
) {
|
|
25
|
+
this.account = new AccountNamespace(this, defaultOptions)
|
|
26
|
+
this.builder = new BuilderNamespace(this, defaultOptions)
|
|
27
|
+
this.desk = new DeskNamespace(this, defaultOptions)
|
|
28
|
+
this.media = new MediaNamespace(this, defaultOptions)
|
|
29
|
+
this.whatsapp = new WhatsAppNamespace(this, defaultOptions)
|
|
30
|
+
this.scheduler = new SchedulerNamespace(this, defaultOptions)
|
|
31
|
+
this.analytics = new AnalyticsNamespace(this, defaultOptions)
|
|
32
|
+
this.activecampaign = new ActiveCampaignNamespace(this, defaultOptions)
|
|
33
|
+
this.portal = new PortalNamespace(this, defaultOptions)
|
|
34
|
+
this.plugins = new PluginsNamespace(this, defaultOptions)
|
|
35
|
+
this.context = new ContextNamespace(this, defaultOptions)
|
|
36
|
+
this.billing = new BillingNamespace(this, defaultOptions)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public readonly account!: AccountNamespace
|
|
40
|
+
public readonly builder!: BuilderNamespace
|
|
41
|
+
public readonly desk!: DeskNamespace
|
|
42
|
+
public readonly media!: MediaNamespace
|
|
43
|
+
public readonly whatsapp!: WhatsAppNamespace
|
|
44
|
+
public readonly scheduler!: SchedulerNamespace
|
|
45
|
+
public readonly analytics!: AnalyticsNamespace
|
|
46
|
+
public readonly activecampaign!: ActiveCampaignNamespace
|
|
47
|
+
public readonly portal!: PortalNamespace
|
|
48
|
+
public readonly plugins!: PluginsNamespace
|
|
49
|
+
public readonly context!: ContextNamespace
|
|
50
|
+
public readonly billing!: BillingNamespace
|
|
51
|
+
|
|
52
|
+
public as(identityOrBotIdentifier: string | Identity): BlipClient<TSender> {
|
|
53
|
+
return new BlipClient<TSender>(this.sender, {
|
|
54
|
+
ownerIdentity: Node.from(identityOrBotIdentifier, 'msging.net').toIdentity(),
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public sendMessage<Type extends MessageTypes>(message: Omit<Message<Type>, 'id'>): Promise<void> {
|
|
59
|
+
return this.sender.sendMessage({
|
|
60
|
+
id: randomId(),
|
|
61
|
+
...message,
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// TODO: use async disposable?
|
|
66
|
+
public close(): Promise<void> {
|
|
67
|
+
if (this.sender instanceof OpenConnectionSender) {
|
|
68
|
+
return this.sender.close()
|
|
69
|
+
}
|
|
70
|
+
return Promise.resolve()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public static http(bot: string | Identity, accessKey: string, tenantId?: string): BlipClient
|
|
74
|
+
public static http(token: string, tenantId?: string): BlipClient
|
|
75
|
+
public static http(...parameters: Array<unknown>): BlipClient {
|
|
76
|
+
return new BlipClient(HttpSender.login.apply(null, parameters as Parameters<typeof HttpSender.login>))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public static async createAccountAndConnect<TSender extends Sender>(
|
|
80
|
+
sender: ConnectionSenderConstructor<TSender>,
|
|
81
|
+
identity: Identity,
|
|
82
|
+
password: string,
|
|
83
|
+
tenantId?: string,
|
|
84
|
+
) {
|
|
85
|
+
const domain = Node.from(identity).domain as BlipDomain
|
|
86
|
+
const guest = new BlipClient<TSender>(
|
|
87
|
+
new sender({
|
|
88
|
+
// guests should always be a guid otherwise the server will reject the authentication
|
|
89
|
+
node: new Node(crypto.randomUUID(), domain),
|
|
90
|
+
authentication: {
|
|
91
|
+
scheme: 'guest',
|
|
92
|
+
},
|
|
93
|
+
tenantId,
|
|
94
|
+
}),
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
await guest.account.setAccount(
|
|
98
|
+
{
|
|
99
|
+
password,
|
|
100
|
+
},
|
|
101
|
+
{ ownerIdentity: identity },
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
await guest.close()
|
|
105
|
+
|
|
106
|
+
return new BlipClient(
|
|
107
|
+
new sender({
|
|
108
|
+
node: identity,
|
|
109
|
+
authentication: {
|
|
110
|
+
scheme: 'plain',
|
|
111
|
+
password,
|
|
112
|
+
},
|
|
113
|
+
tenantId,
|
|
114
|
+
}),
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
}
|