@whitewall/blip-sdk 0.0.190 → 0.0.192
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.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/flow.js +13 -8
- package/dist/cjs/types/flow.js.map +1 -1
- package/dist/cjs/utils/builder.js +40 -21
- package/dist/cjs/utils/builder.js.map +1 -1
- package/dist/cjs/utils/minifier.js +460 -0
- package/dist/cjs/utils/minifier.js.map +1 -0
- package/dist/cjs/utils/whatsapp.js +7 -0
- package/dist/cjs/utils/whatsapp.js.map +1 -1
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/flow.js +11 -6
- package/dist/esm/types/flow.js.map +1 -1
- package/dist/esm/utils/builder.js +38 -19
- package/dist/esm/utils/builder.js.map +1 -1
- package/dist/esm/utils/minifier.js +455 -0
- package/dist/esm/utils/minifier.js.map +1 -0
- package/dist/esm/utils/whatsapp.js +6 -0
- package/dist/esm/utils/whatsapp.js.map +1 -1
- package/dist/types/client.d.ts +2 -1
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/namespaces/account.d.ts +20 -20
- package/dist/types/types/flow.d.ts +253 -96
- package/dist/types/types/flow.d.ts.map +1 -1
- package/dist/types/utils/builder.d.ts +28 -16
- package/dist/types/utils/builder.d.ts.map +1 -1
- package/dist/types/utils/minifier.d.ts +2565 -0
- package/dist/types/utils/minifier.d.ts.map +1 -0
- package/dist/types/utils/whatsapp.d.ts +2 -0
- package/dist/types/utils/whatsapp.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +2 -1
- package/src/index.ts +1 -0
- package/src/types/flow.ts +12 -6
- package/src/utils/builder.ts +62 -41
- package/src/utils/minifier.ts +554 -0
- package/src/ut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,EAAE,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,CAmIrF"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { type PossiblyNode } from '../types/node.ts';
|
|
1
2
|
import type { MessageTemplate, MessageTemplatePreview, MessageTemplateVariable } from '../types/whatsapp.ts';
|
|
3
|
+
export declare function isWhatsAppGuidIdentity(identity: PossiblyNode): boolean;
|
|
2
4
|
type TemplateHeaderFormat = NonNullable<MessageTemplatePreview['headerFormat']>;
|
|
3
5
|
type TemplateHeaderComponent = {
|
|
4
6
|
type: 'HEADER';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"whatsapp.d.ts","sourceRoot":"","sources":["../../../src/utils/whatsapp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"whatsapp.d.ts","sourceRoot":"","sources":["../../../src/utils/whatsapp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAI5G,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAEtE;AAED,KAAK,oBAAoB,GAAG,WAAW,CAAC,sBAAsB,CAAC,cAAc,CAAC,CAAC,CAAA;AAE/E,KAAK,uBAAuB,GAAG;IAC3B,IAAI,EAAE,QAAQ,CAAA;IACd,MAAM,EAAE,oBAAoB,CAAA;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE;QACN,WAAW,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAC3B,aAAa,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;KAChC,CAAA;CACJ,CAAA;AAED,KAAK,qBAAqB,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MAAM,CAAA;CACrB,CAAA;AAED,wBAAsB,4BAA4B,CAC9C,KAAK,EAAE,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC,GAAG;IAC7D,UAAU,EAAE,KAAK,CAAC,mCAAmC,CAAC,CAAA;CACzD,EACD,OAAO,CAAC,EAAE;IACN,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CACvE,GACF,OAAO,CAAC;IACP,QAAQ,EAAE,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,GAAG,YAAY,CAAC,CAAA;IAChF,mBAAmB,EAAE,KAAK,CAAC,kCAAkC,CAAC,CAAA;CACjE,CAAC,CAqBD;AAED,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,KAAK,CAAC,iBAAiB,CAAC,GAAG,KAAK,CAAC,uBAAuB,CAAC,CAuChH;AAED,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,KAAK,CAAC,iBAAiB,CAAC,GAAG,sBAAsB,CAatG"}
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { TunnelNamespace } from './namespaces/tunnel.ts'
|
|
|
13
13
|
import { WhatsAppNamespace } from './namespaces/whatsapp.ts'
|
|
14
14
|
import { isClosable } from './sender/closable.ts'
|
|
15
15
|
import { HttpSender } from './sender/http/httpsender.ts'
|
|
16
|
+
import type { NonTransportAuthentication } from './sender/security.ts'
|
|
16
17
|
import type { ConnectionSender, ConnectionSenderConstructor, Sender } from './sender/sender.ts'
|
|
17
18
|
import type { Message, MessageTypes } from './types/message.ts'
|
|
18
19
|
import { type BlipDomain, type Domain, type Identity, Node } from './types/node.ts'
|
|
@@ -76,7 +77,7 @@ export class BlipClient<TSender extends Sender = Sender> {
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
public static async createAccountAndConnect<TSender extends Sender>(
|
|
79
|
-
sender: ConnectionSenderConstructor<TSender>,
|
|
80
|
+
sender: ConnectionSenderConstructor<TSender, NonTransportAuthentication>,
|
|
80
81
|
identity: Identity,
|
|
81
82
|
password: string,
|
|
82
83
|
tenantId?: string,
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './sender/index.ts'
|
|
|
5
5
|
export * from './types/index.ts'
|
|
6
6
|
export * from './utils/builder.ts'
|
|
7
7
|
export * from './utils/desk.ts'
|
|
8
|
+
export * from './utils/minifier.ts'
|
|
8
9
|
export * from './utils/odata.ts'
|
|
9
10
|
export * from './utils/thread.ts'
|
|
10
11
|
export * from './utils/uri.ts'
|
package/src/types/flow.ts
CHANGED
|
@@ -44,6 +44,8 @@ const CONDITION_SOURCES = ['input', 'context'] as const
|
|
|
44
44
|
const LOGICAL_OPERATORS = ['or', 'and'] as const
|
|
45
45
|
const TYPE_OF_STATE_ID = ['state', 'variable'] as const
|
|
46
46
|
|
|
47
|
+
export const ROOT_STATE_ID = 'onboarding'
|
|
48
|
+
|
|
47
49
|
const createVariableNameSchema = (description: string) => z.string().describe(description)
|
|
48
50
|
|
|
49
51
|
const plainTextSchema = z.string()
|
|
@@ -142,7 +144,10 @@ const sendMessageActionSettingsSchema = z.object({
|
|
|
142
144
|
|
|
143
145
|
const sendRawMessageActionSettingsSchema = z.object({
|
|
144
146
|
$invalid: z.boolean().optional(),
|
|
145
|
-
type
|
|
147
|
+
// The media type the runtime deserializes the raw content as, so it is not
|
|
148
|
+
// restricted to application/json: a document assembled at runtime is sent as
|
|
149
|
+
// its own lime type, which is how a dynamic menu is rendered.
|
|
150
|
+
type: z.string().optional(),
|
|
146
151
|
// Useful to send raw channel payloads, such as WhatsApp interactive content.
|
|
147
152
|
rawContent: z.string(),
|
|
148
153
|
})
|
|
@@ -190,7 +195,7 @@ export const conditionSchema = z.object({
|
|
|
190
195
|
values: z.array(z.string()),
|
|
191
196
|
})
|
|
192
197
|
|
|
193
|
-
const baseActionSchema = z.object({
|
|
198
|
+
export const baseActionSchema = z.object({
|
|
194
199
|
$id: z.string(),
|
|
195
200
|
// Should only exist for SendMessage and SendRawMessage actions. When it is
|
|
196
201
|
// omitted, GET responses usually return an empty string.
|
|
@@ -206,8 +211,9 @@ const baseActionSchema = z.object({
|
|
|
206
211
|
position: z.literal('left'),
|
|
207
212
|
document: z.object({
|
|
208
213
|
id: z.string(),
|
|
209
|
-
// Must match the type defined in the action settings
|
|
210
|
-
type
|
|
214
|
+
// Must match the type defined in the action settings, which for a
|
|
215
|
+
// raw message can be any media type.
|
|
216
|
+
type: z.string(),
|
|
211
217
|
// Must match the content defined in the action settings.
|
|
212
218
|
content: flowMessageContentSchema.or(z.string()),
|
|
213
219
|
textContent: z.string().optional(),
|
|
@@ -218,7 +224,7 @@ const baseActionSchema = z.object({
|
|
|
218
224
|
continueOnError: z.boolean().optional(),
|
|
219
225
|
})
|
|
220
226
|
|
|
221
|
-
const actionTypeSchema = z.discriminatedUnion('type', [
|
|
227
|
+
export const actionTypeSchema = z.discriminatedUnion('type', [
|
|
222
228
|
z.object({
|
|
223
229
|
type: z.literal('SendMessage'),
|
|
224
230
|
settings: sendMessageActionSettingsSchema,
|
|
@@ -361,7 +367,7 @@ export const stateSchema = z.object({
|
|
|
361
367
|
}),
|
|
362
368
|
),
|
|
363
369
|
id: z.string().optional(),
|
|
364
|
-
//
|
|
370
|
+
// Set on the entry point, which the builder always keys as ROOT_STATE_ID.
|
|
365
371
|
root: z.boolean().optional(),
|
|
366
372
|
$title: z.string(),
|
|
367
373
|
$position: z
|
package/src/utils/builder.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Lossy, read-only projection of a builder flow, meant for presenting a state to
|
|
3
|
+
* a human or an LLM. It renames the `$`-prefixed keys to readable ones, drops
|
|
4
|
+
* layout metadata and denormalizes state names, so it cannot be pushed back to
|
|
5
|
+
* the builder. For the round-trippable format, see `./minifier.ts`.
|
|
6
|
+
*/
|
|
7
|
+
import { type Action, type ContentActionItem, ROOT_STATE_ID, type State } from '../types/flow.ts'
|
|
8
|
+
|
|
9
|
+
export type ActionDigest = {
|
|
4
10
|
type: string
|
|
5
11
|
settings: Record<string, unknown>
|
|
6
12
|
conditions?: Array<{
|
|
@@ -12,35 +18,35 @@ export type MinifiedAction = {
|
|
|
12
18
|
}>
|
|
13
19
|
}
|
|
14
20
|
|
|
15
|
-
export type
|
|
21
|
+
export type InputDigest = {
|
|
16
22
|
bypass: boolean
|
|
17
23
|
variable?: string
|
|
18
24
|
validation?: { rule: string; regex?: string; type?: string; error: string }
|
|
19
25
|
expiration?: string
|
|
20
|
-
conditions?:
|
|
26
|
+
conditions?: ActionDigest['conditions']
|
|
21
27
|
}
|
|
22
28
|
|
|
23
|
-
export type
|
|
29
|
+
export type OutputDigest = {
|
|
24
30
|
stateId: string
|
|
25
31
|
stateName?: string
|
|
26
32
|
typeOfStateId?: string
|
|
27
|
-
conditions?:
|
|
33
|
+
conditions?: ActionDigest['conditions']
|
|
28
34
|
}
|
|
29
35
|
|
|
30
|
-
export type
|
|
36
|
+
export type StateDigest = {
|
|
31
37
|
id: string
|
|
32
38
|
name: string
|
|
33
39
|
root?: boolean
|
|
34
|
-
enteringActions?: Array<
|
|
35
|
-
contentActions?: Array<{ action?:
|
|
36
|
-
leavingActions?: Array<
|
|
37
|
-
outputs?: Array<
|
|
40
|
+
enteringActions?: Array<ActionDigest>
|
|
41
|
+
contentActions?: Array<{ action?: ActionDigest; input?: InputDigest }>
|
|
42
|
+
leavingActions?: Array<ActionDigest>
|
|
43
|
+
outputs?: Array<OutputDigest>
|
|
38
44
|
defaultOutput: { stateId: string; stateName?: string; typeOfStateId?: string }
|
|
39
|
-
afterStateChangedActions?: Array<
|
|
40
|
-
localActions?: Array<
|
|
45
|
+
afterStateChangedActions?: Array<ActionDigest>
|
|
46
|
+
localActions?: Array<ActionDigest>
|
|
41
47
|
}
|
|
42
48
|
|
|
43
|
-
function
|
|
49
|
+
function digestConditions(
|
|
44
50
|
conditions?: Array<{
|
|
45
51
|
source: string
|
|
46
52
|
variable?: string
|
|
@@ -48,7 +54,7 @@ function minifyConditions(
|
|
|
48
54
|
operator?: string
|
|
49
55
|
values: Array<string>
|
|
50
56
|
}>,
|
|
51
|
-
):
|
|
57
|
+
): ActionDigest['conditions'] | undefined {
|
|
52
58
|
if (!conditions || conditions.length === 0) return undefined
|
|
53
59
|
return conditions.map((c) => ({
|
|
54
60
|
source: c.source,
|
|
@@ -59,26 +65,26 @@ function minifyConditions(
|
|
|
59
65
|
}))
|
|
60
66
|
}
|
|
61
67
|
|
|
62
|
-
function
|
|
68
|
+
function digestActionSettings(settings: Record<string, unknown>): Record<string, unknown> {
|
|
63
69
|
const clone = { ...settings }
|
|
64
70
|
delete clone.$invalid
|
|
65
71
|
delete clone.id
|
|
66
72
|
return clone
|
|
67
73
|
}
|
|
68
74
|
|
|
69
|
-
export function
|
|
70
|
-
const result:
|
|
75
|
+
export function digestAction(action: Action): ActionDigest {
|
|
76
|
+
const result: ActionDigest = {
|
|
71
77
|
type: action.type,
|
|
72
|
-
settings:
|
|
78
|
+
settings: digestActionSettings(action.settings as Record<string, unknown>),
|
|
73
79
|
}
|
|
74
|
-
const conditions =
|
|
80
|
+
const conditions = digestConditions(action.conditions as ActionDigest['conditions'])
|
|
75
81
|
if (conditions) result.conditions = conditions
|
|
76
82
|
return result
|
|
77
83
|
}
|
|
78
84
|
|
|
79
|
-
function
|
|
85
|
+
function digestInput(input: ContentActionItem['input']): InputDigest | undefined {
|
|
80
86
|
if (!input) return undefined
|
|
81
|
-
const result:
|
|
87
|
+
const result: InputDigest = { bypass: input.bypass }
|
|
82
88
|
if (input.variable) result.variable = input.variable
|
|
83
89
|
if (input.validation) {
|
|
84
90
|
result.validation = {
|
|
@@ -89,13 +95,26 @@ function minifyInput(input: ContentActionItem['input']): MinifiedInput | undefin
|
|
|
89
95
|
}
|
|
90
96
|
}
|
|
91
97
|
if (input.expiration) result.expiration = input.expiration
|
|
92
|
-
const conditions =
|
|
98
|
+
const conditions = digestConditions(input.conditions as ActionDigest['conditions'])
|
|
93
99
|
if (conditions) result.conditions = conditions
|
|
94
100
|
return result
|
|
95
101
|
}
|
|
96
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Typing indicators are noise in every projection of a flow, so both the digest
|
|
105
|
+
* and the minifier drop them. The two signals are checked because `$typeOfContent`
|
|
106
|
+
* is absent from a minified flow and can come back empty from a GET, while the
|
|
107
|
+
* settings mime type is absent from a hand-written action.
|
|
108
|
+
*/
|
|
97
109
|
export function isChatStateSendMessage(item: ContentActionItem): boolean {
|
|
98
|
-
|
|
110
|
+
if (item.action?.type !== 'SendMessage') {
|
|
111
|
+
return false
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
item.action.$typeOfContent === 'chat-state' ||
|
|
116
|
+
item.action.settings.type === 'application/vnd.lime.chatstate+json'
|
|
117
|
+
)
|
|
99
118
|
}
|
|
100
119
|
|
|
101
120
|
export function resolveStateName(stateId: string, flow: Record<string, State>): string | undefined {
|
|
@@ -103,24 +122,24 @@ export function resolveStateName(stateId: string, flow: Record<string, State>):
|
|
|
103
122
|
return state?.$title
|
|
104
123
|
}
|
|
105
124
|
|
|
106
|
-
function
|
|
125
|
+
function digestOutput(
|
|
107
126
|
output: { stateId: string; typeOfStateId?: string; conditions?: Array<unknown>; $invalid?: boolean },
|
|
108
127
|
flow: Record<string, State>,
|
|
109
|
-
):
|
|
110
|
-
const result:
|
|
128
|
+
): OutputDigest {
|
|
129
|
+
const result: OutputDigest = {
|
|
111
130
|
stateId: output.stateId,
|
|
112
131
|
}
|
|
113
132
|
const name = resolveStateName(output.stateId, flow)
|
|
114
133
|
if (name) result.stateName = name
|
|
115
134
|
if (output.typeOfStateId) result.typeOfStateId = output.typeOfStateId
|
|
116
135
|
if ('conditions' in output && Array.isArray(output.conditions) && output.conditions.length > 0) {
|
|
117
|
-
result.conditions =
|
|
136
|
+
result.conditions = digestConditions(output.conditions as ActionDigest['conditions'])
|
|
118
137
|
}
|
|
119
138
|
return result
|
|
120
139
|
}
|
|
121
140
|
|
|
122
|
-
export function
|
|
123
|
-
const result:
|
|
141
|
+
export function digestState(stateId: string, state: State, flow: Record<string, State>): StateDigest {
|
|
142
|
+
const result: StateDigest = {
|
|
124
143
|
id: stateId,
|
|
125
144
|
name: state.$title,
|
|
126
145
|
defaultOutput: {
|
|
@@ -132,33 +151,35 @@ export function minifyState(stateId: string, state: State, flow: Record<string,
|
|
|
132
151
|
},
|
|
133
152
|
}
|
|
134
153
|
|
|
135
|
-
|
|
154
|
+
// Derived from the id so the digest reads the same whether it is handed a
|
|
155
|
+
// full flow or a minified one, which no longer carries `root`.
|
|
156
|
+
if (state.root || stateId === ROOT_STATE_ID) result.root = true
|
|
136
157
|
|
|
137
|
-
const enteringActions = state.$enteringCustomActions.map(
|
|
158
|
+
const enteringActions = state.$enteringCustomActions.map(digestAction)
|
|
138
159
|
if (enteringActions.length > 0) result.enteringActions = enteringActions
|
|
139
160
|
|
|
140
161
|
const contentActions = state.$contentActions
|
|
141
162
|
.filter((item: ContentActionItem) => !isChatStateSendMessage(item))
|
|
142
163
|
.map((item: ContentActionItem) => {
|
|
143
|
-
const entry: { action?:
|
|
144
|
-
if (item.action) entry.action =
|
|
145
|
-
const input =
|
|
164
|
+
const entry: { action?: ActionDigest; input?: InputDigest } = {}
|
|
165
|
+
if (item.action) entry.action = digestAction(item.action)
|
|
166
|
+
const input = digestInput(item.input)
|
|
146
167
|
if (input) entry.input = input
|
|
147
168
|
return entry
|
|
148
169
|
})
|
|
149
|
-
.filter((entry: { action?:
|
|
170
|
+
.filter((entry: { action?: ActionDigest; input?: InputDigest }) => entry.action || entry.input)
|
|
150
171
|
if (contentActions.length > 0) result.contentActions = contentActions
|
|
151
172
|
|
|
152
|
-
const leavingActions = state.$leavingCustomActions.map(
|
|
173
|
+
const leavingActions = state.$leavingCustomActions.map(digestAction)
|
|
153
174
|
if (leavingActions.length > 0) result.leavingActions = leavingActions
|
|
154
175
|
|
|
155
|
-
const outputs = state.$conditionOutputs.map((o: State['$conditionOutputs'][number]) =>
|
|
176
|
+
const outputs = state.$conditionOutputs.map((o: State['$conditionOutputs'][number]) => digestOutput(o, flow))
|
|
156
177
|
if (outputs.length > 0) result.outputs = outputs
|
|
157
178
|
|
|
158
|
-
const afterStateChangedActions = (state.$afterStateChangedActions ?? []).map(
|
|
179
|
+
const afterStateChangedActions = (state.$afterStateChangedActions ?? []).map(digestAction)
|
|
159
180
|
if (afterStateChangedActions.length > 0) result.afterStateChangedActions = afterStateChangedActions
|
|
160
181
|
|
|
161
|
-
const localActions = (state.$localCustomActions ?? []).map(
|
|
182
|
+
const localActions = (state.$localCustomActions ?? []).map(digestAction)
|
|
162
183
|
if (localActions.length > 0) result.localActions = localActions
|
|
163
184
|
|
|
164
185
|
return result
|