@zapyapi/sdk 1.0.0-beta.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/README.md +308 -0
- package/index.cjs +1176 -0
- package/index.js +1149 -0
- package/package.json +55 -0
- package/src/client.d.ts +98 -0
- package/src/client.d.ts.map +1 -0
- package/src/errors.d.ts +70 -0
- package/src/errors.d.ts.map +1 -0
- package/src/generated/Api.d.ts +1542 -0
- package/src/generated/Api.d.ts.map +1 -0
- package/src/index.d.ts +38 -0
- package/src/index.d.ts.map +1 -0
- package/src/resources/base.resource.d.ts +17 -0
- package/src/resources/base.resource.d.ts.map +1 -0
- package/src/resources/index.d.ts +8 -0
- package/src/resources/index.d.ts.map +1 -0
- package/src/resources/instances.resource.d.ts +75 -0
- package/src/resources/instances.resource.d.ts.map +1 -0
- package/src/resources/messages.resource.d.ts +159 -0
- package/src/resources/messages.resource.d.ts.map +1 -0
- package/src/resources/webhooks.resource.d.ts +115 -0
- package/src/resources/webhooks.resource.d.ts.map +1 -0
- package/src/types/common.types.d.ts +89 -0
- package/src/types/common.types.d.ts.map +1 -0
- package/src/types/enums.d.ts +142 -0
- package/src/types/enums.d.ts.map +1 -0
- package/src/types/index.d.ts +11 -0
- package/src/types/index.d.ts.map +1 -0
- package/src/types/instances.types.d.ts +114 -0
- package/src/types/instances.types.d.ts.map +1 -0
- package/src/types/messages.types.d.ts +166 -0
- package/src/types/messages.types.d.ts.map +1 -0
- package/src/types/webhook-config.types.d.ts +60 -0
- package/src/types/webhook-config.types.d.ts.map +1 -0
- package/src/types/webhook-events.types.d.ts +232 -0
- package/src/types/webhook-events.types.d.ts.map +1 -0
- package/src/utils/index.d.ts +6 -0
- package/src/utils/index.d.ts.map +1 -0
- package/src/utils/phone.d.ts +38 -0
- package/src/utils/phone.d.ts.map +1 -0
- package/src/utils/webhook-signature.d.ts +69 -0
- package/src/utils/webhook-signature.d.ts.map +1 -0
- package/src/version.d.ts +3 -0
- package/src/version.d.ts.map +1 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhook event type definitions
|
|
3
|
+
* Types for webhook payloads sent by ZapyAPI
|
|
4
|
+
*/
|
|
5
|
+
import type { MessageType, MessageAckStatus, ConnectionStatus, WebhookEventType as WebhookEventTypeEnum } from './enums';
|
|
6
|
+
/**
|
|
7
|
+
* Re-export the enum type for convenience
|
|
8
|
+
*/
|
|
9
|
+
export type WebhookEventType = WebhookEventTypeEnum;
|
|
10
|
+
/**
|
|
11
|
+
* Base webhook event payload
|
|
12
|
+
* All webhook events include these fields
|
|
13
|
+
*/
|
|
14
|
+
export interface WebhookEventBase<T extends WebhookEventType = WebhookEventType> {
|
|
15
|
+
/** Event type identifier */
|
|
16
|
+
event: T;
|
|
17
|
+
/** Instance ID that generated the event */
|
|
18
|
+
instanceId: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Message sender/recipient info
|
|
22
|
+
*/
|
|
23
|
+
export interface MessageParticipant {
|
|
24
|
+
/** WhatsApp ID (e.g., "5511999999999@c.us") */
|
|
25
|
+
id: string;
|
|
26
|
+
/** Phone number (e.g., "5511999999999") */
|
|
27
|
+
phone: string;
|
|
28
|
+
/** Display name if available */
|
|
29
|
+
name?: string;
|
|
30
|
+
/** Push name (user's WhatsApp name) */
|
|
31
|
+
pushName?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Media information in messages
|
|
35
|
+
*/
|
|
36
|
+
export interface MediaInfo {
|
|
37
|
+
/** MIME type of the media */
|
|
38
|
+
mimeType: string;
|
|
39
|
+
/** File name if available */
|
|
40
|
+
fileName?: string;
|
|
41
|
+
/** File size in bytes */
|
|
42
|
+
fileSize?: number;
|
|
43
|
+
/** Media URL (temporary, expires) */
|
|
44
|
+
url?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Message webhook event data
|
|
48
|
+
*/
|
|
49
|
+
export interface MessageEventData {
|
|
50
|
+
/** WhatsApp message ID */
|
|
51
|
+
messageId: string;
|
|
52
|
+
/** Message sender */
|
|
53
|
+
from: MessageParticipant;
|
|
54
|
+
/** Message recipient (your number/instance) */
|
|
55
|
+
to: MessageParticipant;
|
|
56
|
+
/** Message content type */
|
|
57
|
+
type: MessageType;
|
|
58
|
+
/** Text content (for text messages) */
|
|
59
|
+
text?: string;
|
|
60
|
+
/** Caption (for media messages) */
|
|
61
|
+
caption?: string;
|
|
62
|
+
/** Media information (for media messages) */
|
|
63
|
+
media?: MediaInfo;
|
|
64
|
+
/** Whether this is a group message */
|
|
65
|
+
isGroup: boolean;
|
|
66
|
+
/** Group participant who sent the message (for group messages) */
|
|
67
|
+
participant?: MessageParticipant;
|
|
68
|
+
/** ID of quoted/replied message */
|
|
69
|
+
quotedMessageId?: string;
|
|
70
|
+
/** Message timestamp (Unix ms) */
|
|
71
|
+
timestamp: number;
|
|
72
|
+
/** Whether this is a forwarded message */
|
|
73
|
+
isForwarded?: boolean;
|
|
74
|
+
/** Whether this is a broadcast message */
|
|
75
|
+
isBroadcast?: boolean;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Message webhook event
|
|
79
|
+
*/
|
|
80
|
+
export interface MessageWebhookEvent extends WebhookEventBase<'message'> {
|
|
81
|
+
data: MessageEventData;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Message status update event data
|
|
85
|
+
*/
|
|
86
|
+
export interface MessageStatusEventData {
|
|
87
|
+
/** WhatsApp message ID */
|
|
88
|
+
messageId: string;
|
|
89
|
+
/** New acknowledgment status */
|
|
90
|
+
ack: MessageAckStatus;
|
|
91
|
+
/** Sender of the original message */
|
|
92
|
+
from: string;
|
|
93
|
+
/** Recipient of the original message */
|
|
94
|
+
to: string;
|
|
95
|
+
/** Timestamp of status update (Unix ms) */
|
|
96
|
+
timestamp: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Message acknowledgment/status webhook event
|
|
100
|
+
*/
|
|
101
|
+
export interface MessageAckWebhookEvent extends WebhookEventBase<'message-status'> {
|
|
102
|
+
data: MessageStatusEventData;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* QR code update event data
|
|
106
|
+
*/
|
|
107
|
+
export interface QRCodeEventData {
|
|
108
|
+
/** QR code as base64 data URL */
|
|
109
|
+
qrCode: string;
|
|
110
|
+
/** QR code generation attempt number */
|
|
111
|
+
attempt: number;
|
|
112
|
+
/** Expiration timestamp (Unix ms) */
|
|
113
|
+
expiresAt: number;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* QR code update webhook event
|
|
117
|
+
*/
|
|
118
|
+
export interface QRCodeWebhookEvent extends WebhookEventBase<'qr-code'> {
|
|
119
|
+
data: QRCodeEventData;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Contact information
|
|
123
|
+
*/
|
|
124
|
+
export interface ContactInfo {
|
|
125
|
+
/** WhatsApp ID */
|
|
126
|
+
id: string;
|
|
127
|
+
/** Phone number */
|
|
128
|
+
phone: string;
|
|
129
|
+
/** Contact name */
|
|
130
|
+
name?: string;
|
|
131
|
+
/** Push name (WhatsApp display name) */
|
|
132
|
+
pushName?: string;
|
|
133
|
+
/** Profile picture URL */
|
|
134
|
+
profilePicUrl?: string;
|
|
135
|
+
/** Whether this is a business account */
|
|
136
|
+
isBusiness?: boolean;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Contact created event data
|
|
140
|
+
*/
|
|
141
|
+
export interface ContactCreatedEventData {
|
|
142
|
+
/** The new contact */
|
|
143
|
+
contact: ContactInfo;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Contact created webhook event
|
|
147
|
+
*/
|
|
148
|
+
export interface ContactCreatedWebhookEvent extends WebhookEventBase<'contact-created'> {
|
|
149
|
+
data: ContactCreatedEventData;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Contact updated event data
|
|
153
|
+
*/
|
|
154
|
+
export interface ContactUpdatedEventData {
|
|
155
|
+
/** The updated contact */
|
|
156
|
+
contact: ContactInfo;
|
|
157
|
+
/** Fields that were updated */
|
|
158
|
+
updatedFields: string[];
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Contact updated webhook event
|
|
162
|
+
*/
|
|
163
|
+
export interface ContactUpdatedWebhookEvent extends WebhookEventBase<'contact-updated'> {
|
|
164
|
+
data: ContactUpdatedEventData;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Contact deduplicated event data
|
|
168
|
+
*/
|
|
169
|
+
export interface ContactDeduplicatedEventData {
|
|
170
|
+
/** The primary contact that was kept */
|
|
171
|
+
primaryContact: ContactInfo;
|
|
172
|
+
/** The duplicate contact that was merged */
|
|
173
|
+
duplicateContact: ContactInfo;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Contact deduplicated webhook event
|
|
177
|
+
*/
|
|
178
|
+
export interface ContactDeduplicatedWebhookEvent extends WebhookEventBase<'contact-deduplicated'> {
|
|
179
|
+
data: ContactDeduplicatedEventData;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Connection status update event data
|
|
183
|
+
* @deprecated Connection events are now sent as instance status changes
|
|
184
|
+
*/
|
|
185
|
+
export interface ConnectionEventData {
|
|
186
|
+
/** Connection status */
|
|
187
|
+
status: ConnectionStatus;
|
|
188
|
+
/** Reason for status change */
|
|
189
|
+
reason?: string;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Connection status webhook event
|
|
193
|
+
* @deprecated Connection events are now sent as instance status changes
|
|
194
|
+
*/
|
|
195
|
+
export interface ConnectionWebhookEvent {
|
|
196
|
+
event: 'connection.update';
|
|
197
|
+
instanceId: string;
|
|
198
|
+
data: ConnectionEventData;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Union type for all webhook events
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* import { WebhookEvent, WebhookEventType } from '@zapyapi/sdk';
|
|
206
|
+
*
|
|
207
|
+
* function handleWebhook(event: WebhookEvent) {
|
|
208
|
+
* switch (event.event) {
|
|
209
|
+
* case 'message':
|
|
210
|
+
* console.log('New message:', event.data.text);
|
|
211
|
+
* break;
|
|
212
|
+
* case 'message-status':
|
|
213
|
+
* console.log('Status update:', event.data.ack);
|
|
214
|
+
* break;
|
|
215
|
+
* }
|
|
216
|
+
* }
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
export type WebhookEvent = MessageWebhookEvent | MessageAckWebhookEvent | QRCodeWebhookEvent | ContactCreatedWebhookEvent | ContactUpdatedWebhookEvent | ContactDeduplicatedWebhookEvent;
|
|
220
|
+
/** Type guard for message events */
|
|
221
|
+
export declare function isMessageEvent(event: WebhookEvent): event is MessageWebhookEvent;
|
|
222
|
+
/** Type guard for message status events */
|
|
223
|
+
export declare function isMessageStatusEvent(event: WebhookEvent): event is MessageAckWebhookEvent;
|
|
224
|
+
/** Type guard for QR code events */
|
|
225
|
+
export declare function isQRCodeEvent(event: WebhookEvent): event is QRCodeWebhookEvent;
|
|
226
|
+
/** Type guard for contact created events */
|
|
227
|
+
export declare function isContactCreatedEvent(event: WebhookEvent): event is ContactCreatedWebhookEvent;
|
|
228
|
+
/** Type guard for contact updated events */
|
|
229
|
+
export declare function isContactUpdatedEvent(event: WebhookEvent): event is ContactUpdatedWebhookEvent;
|
|
230
|
+
/** Type guard for contact deduplicated events */
|
|
231
|
+
export declare function isContactDeduplicatedEvent(event: WebhookEvent): event is ContactDeduplicatedWebhookEvent;
|
|
232
|
+
//# sourceMappingURL=webhook-events.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook-events.types.d.ts","sourceRoot":"","sources":["../../../../../libs/sdk/src/types/webhook-events.types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,g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A+B,CAAC;AAEpC,oCAAoC;AACpC,wBAAgB,cAAc,CAAC,KAAK,EAAE,YAAY,GAAG,KAAK,IAAI,mBAAmB,CAEhF;AAED,2CAA2C;AAC3C,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,YAAY,GAAG,KAAK,IAAI,sBAAsB,CAEzF;AAED,oCAAoC;AACpC,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,KAAK,IAAI,kBAAkB,CAE9E;AAED,4CAA4C;AAC5C,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,YAAY,GAAG,KAAK,IAAI,0BAA0B,CAE9F;AAED,4CAA4C;AAC5C,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,YAAY,GAAG,KAAK,IAAI,0BAA0B,CAE9F;AAED,iDAAiD;AACjD,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,YAAY,GAAG,KAAK,IAAI,+BAA+B,CAExG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../libs/sdk/src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phone number utilities for @zapyapi/sdk
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Normalize a phone number to the format expected by the API
|
|
6
|
+
*
|
|
7
|
+
* @param phone - Phone number in various formats
|
|
8
|
+
* @returns Normalized phone number
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* normalizePhone('11999999999') // '5511999999999'
|
|
12
|
+
* normalizePhone('5511999999999') // '5511999999999'
|
|
13
|
+
* normalizePhone('+5511999999999') // '5511999999999'
|
|
14
|
+
* normalizePhone('5511999999999@c.us') // '5511999999999@c.us'
|
|
15
|
+
*/
|
|
16
|
+
export declare function normalizePhone(phone: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Validate if a string is a valid phone number format
|
|
19
|
+
*
|
|
20
|
+
* @param phone - Phone number to validate
|
|
21
|
+
* @returns Whether the phone number is valid
|
|
22
|
+
*/
|
|
23
|
+
export declare function isValidPhone(phone: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Check if a WhatsApp ID is a group
|
|
26
|
+
*
|
|
27
|
+
* @param jid - WhatsApp ID (JID)
|
|
28
|
+
* @returns Whether the JID is a group
|
|
29
|
+
*/
|
|
30
|
+
export declare function isGroup(jid: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Extract the phone number from a WhatsApp ID
|
|
33
|
+
*
|
|
34
|
+
* @param jid - WhatsApp ID (JID)
|
|
35
|
+
* @returns Phone number without the @suffix
|
|
36
|
+
*/
|
|
37
|
+
export declare function extractPhone(jid: string): string;
|
|
38
|
+
//# sourceMappingURL=phone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone.d.ts","sourceRoot":"","sources":["../../../../../libs/sdk/src/utils/phone.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAqBpD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAYnD;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE5C;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGhD"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhook signature verification utilities
|
|
3
|
+
* HMAC-SHA256 signature verification for webhook payloads
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Verify webhook signature (synchronous)
|
|
7
|
+
*
|
|
8
|
+
* For best results, pass the raw request body as a string.
|
|
9
|
+
*
|
|
10
|
+
* @param payload - The webhook payload (raw body string recommended)
|
|
11
|
+
* @param signature - The X-Webhook-Signature header value
|
|
12
|
+
* @param secret - Your webhook secret
|
|
13
|
+
* @returns true if the signature is valid
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { verifyWebhookSignature } from '@zapyapi/sdk';
|
|
18
|
+
*
|
|
19
|
+
* app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
|
|
20
|
+
* const signature = req.headers['x-webhook-signature'] as string;
|
|
21
|
+
* const isValid = verifyWebhookSignature(
|
|
22
|
+
* req.body.toString('utf8'),
|
|
23
|
+
* signature,
|
|
24
|
+
* process.env.WEBHOOK_SECRET!
|
|
25
|
+
* );
|
|
26
|
+
*
|
|
27
|
+
* if (!isValid) {
|
|
28
|
+
* return res.status(401).send('Invalid signature');
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* const event = JSON.parse(req.body.toString('utf8'));
|
|
32
|
+
* res.status(200).send('OK');
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function verifyWebhookSignature(payload: string | object, signature: string | undefined, secret: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Verify webhook signature (async - recommended for ESM)
|
|
39
|
+
*
|
|
40
|
+
* Uses dynamic import() for ESM compatibility.
|
|
41
|
+
*
|
|
42
|
+
* @param payload - The webhook payload (raw body string recommended)
|
|
43
|
+
* @param signature - The X-Webhook-Signature header value
|
|
44
|
+
* @param secret - Your webhook secret
|
|
45
|
+
* @returns Promise resolving to true if valid
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* import { verifyWebhookSignatureAsync } from '@zapyapi/sdk';
|
|
50
|
+
*
|
|
51
|
+
* app.post('/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
|
|
52
|
+
* const signature = req.headers['x-webhook-signature'] as string;
|
|
53
|
+
* const isValid = await verifyWebhookSignatureAsync(
|
|
54
|
+
* req.body.toString('utf8'),
|
|
55
|
+
* signature,
|
|
56
|
+
* process.env.WEBHOOK_SECRET!
|
|
57
|
+
* );
|
|
58
|
+
*
|
|
59
|
+
* if (!isValid) {
|
|
60
|
+
* return res.status(401).send('Invalid signature');
|
|
61
|
+
* }
|
|
62
|
+
*
|
|
63
|
+
* const event = JSON.parse(req.body.toString('utf8'));
|
|
64
|
+
* res.status(200).send('OK');
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function verifyWebhookSignatureAsync(payload: string | object, signature: string | undefined, secret: string): Promise<boolean>;
|
|
69
|
+
//# sourceMappingURL=webhook-signature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook-signature.d.ts","sourceRoot":"","sources":["../../../../../libs/sdk/src/utils/webhook-signature.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,MAAM,EAAE,MAAM,GACb,OAAO,CAgBT;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC,CAelB"}
|
package/src/version.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../../libs/sdk/src/version.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,eAAO,MAAM,WAAW,iBAAiB,CAAC"}
|