@scryme/chat 2.13.3 → 2.15.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/dist/sdk.d.ts +925 -33
- package/dist/sdk.js +685 -8
- package/package.json +1 -1
- package/src/__tests__/sdk.test.ts +224 -2
- package/src/sdk.ts +1261 -69
package/package.json
CHANGED
|
@@ -41,6 +41,119 @@ vi.mock('../generated/v3-server', () => {
|
|
|
41
41
|
channelsControllerCreateMessage: vi.fn(async (channelId, options) => {
|
|
42
42
|
return { success: true, channelId, options };
|
|
43
43
|
}),
|
|
44
|
+
channelsControllerUpdateMessage: vi.fn(async (channelId, messageId, data, options) => {
|
|
45
|
+
return { success: true, type: 'channel', action: 'update', channelId, messageId, data, options };
|
|
46
|
+
}),
|
|
47
|
+
channelsControllerDeleteMessage: vi.fn(async (channelId, messageId, options) => {
|
|
48
|
+
return { success: true, type: 'channel', action: 'delete', channelId, messageId, options };
|
|
49
|
+
}),
|
|
50
|
+
channelsControllerAddReaction: vi.fn(async (channelId, messageId, data, options) => {
|
|
51
|
+
return { success: true, type: 'channel', action: 'addReaction', channelId, messageId, data, options };
|
|
52
|
+
}),
|
|
53
|
+
channelsControllerRemoveReaction: vi.fn(async (channelId, messageId, emoji, options) => {
|
|
54
|
+
return { success: true, type: 'channel', action: 'removeReaction', channelId, messageId, emoji, options };
|
|
55
|
+
}),
|
|
56
|
+
|
|
57
|
+
// DMs Mock
|
|
58
|
+
dmsControllerGetDms: vi.fn(async (options) => {
|
|
59
|
+
return { success: true, conversations: [], options };
|
|
60
|
+
}),
|
|
61
|
+
dmsControllerCreateDm: vi.fn(async (data, options) => {
|
|
62
|
+
return { success: true, data, options };
|
|
63
|
+
}),
|
|
64
|
+
dmsControllerGetDm: vi.fn(async (dmId, options) => {
|
|
65
|
+
return { success: true, dmId, options };
|
|
66
|
+
}),
|
|
67
|
+
dmsControllerDeleteDm: vi.fn(async (dmId, options) => {
|
|
68
|
+
return { success: true, dmId, options };
|
|
69
|
+
}),
|
|
70
|
+
dmsControllerGetMessages: vi.fn(async (dmId, params, options) => {
|
|
71
|
+
return { success: true, dmId, params, options };
|
|
72
|
+
}),
|
|
73
|
+
dmsControllerCreateMessage: vi.fn(async (dmId, options) => {
|
|
74
|
+
return { success: true, dmId, options };
|
|
75
|
+
}),
|
|
76
|
+
dmsControllerUpdateMessage: vi.fn(async (dmId, messageId, data, options) => {
|
|
77
|
+
return { success: true, type: 'dm', action: 'update', dmId, messageId, data, options };
|
|
78
|
+
}),
|
|
79
|
+
dmsControllerDeleteMessage: vi.fn(async (dmId, messageId, options) => {
|
|
80
|
+
return { success: true, type: 'dm', action: 'delete', dmId, messageId, options };
|
|
81
|
+
}),
|
|
82
|
+
dmsControllerAddReaction: vi.fn(async (dmId, messageId, data, options) => {
|
|
83
|
+
return { success: true, type: 'dm', action: 'addReaction', dmId, messageId, data, options };
|
|
84
|
+
}),
|
|
85
|
+
dmsControllerRemoveReaction: vi.fn(async (dmId, messageId, emoji, options) => {
|
|
86
|
+
return { success: true, type: 'dm', action: 'removeReaction', dmId, messageId, emoji, options };
|
|
87
|
+
}),
|
|
88
|
+
|
|
89
|
+
// Webhooks Mock
|
|
90
|
+
v3WebhooksControllerGetWebhooks: vi.fn(async (slug, options) => {
|
|
91
|
+
return { success: true, slug, options };
|
|
92
|
+
}),
|
|
93
|
+
v3WebhooksControllerCreateWebhook: vi.fn(async (slug, data, options) => {
|
|
94
|
+
return { success: true, slug, data, options };
|
|
95
|
+
}),
|
|
96
|
+
v3WebhooksControllerGetWebhook: vi.fn(async (slug, webhookId, options) => {
|
|
97
|
+
return { success: true, slug, webhookId, options };
|
|
98
|
+
}),
|
|
99
|
+
v3WebhooksControllerUpdateWebhook: vi.fn(async (slug, webhookId, data, options) => {
|
|
100
|
+
return { success: true, slug, webhookId, data, options };
|
|
101
|
+
}),
|
|
102
|
+
v3WebhooksControllerDeleteWebhook: vi.fn(async (slug, webhookId, options) => {
|
|
103
|
+
return { success: true, slug, webhookId, options };
|
|
104
|
+
}),
|
|
105
|
+
|
|
106
|
+
// Channel Incoming Webhooks Mock
|
|
107
|
+
v3ChannelIncomingWebhooksControllerGetChannelWebhooks: vi.fn(async (slug, channelId, options) => {
|
|
108
|
+
return { success: true, slug, channelId, options };
|
|
109
|
+
}),
|
|
110
|
+
v3ChannelIncomingWebhooksControllerCreateChannelWebhook: vi.fn(async (slug, channelId, data, options) => {
|
|
111
|
+
return { success: true, slug, channelId, data, options };
|
|
112
|
+
}),
|
|
113
|
+
v3ChannelIncomingWebhooksControllerGetChannelWebhook: vi.fn(async (slug, channelId, webhookId, options) => {
|
|
114
|
+
return { success: true, slug, channelId, webhookId, options };
|
|
115
|
+
}),
|
|
116
|
+
v3ChannelIncomingWebhooksControllerUpdateChannelWebhook: vi.fn(async (slug, channelId, webhookId, data, options) => {
|
|
117
|
+
return { success: true, slug, channelId, webhookId, data, options };
|
|
118
|
+
}),
|
|
119
|
+
v3ChannelIncomingWebhooksControllerDeleteChannelWebhook: vi.fn(async (slug, channelId, webhookId, options) => {
|
|
120
|
+
return { success: true, slug, channelId, webhookId, options };
|
|
121
|
+
}),
|
|
122
|
+
v3ChannelIncomingWebhooksControllerExecuteWebhookByUrlToken: vi.fn(async (token, data, options) => {
|
|
123
|
+
return { success: true, token, data, options };
|
|
124
|
+
}),
|
|
125
|
+
v3ChannelIncomingWebhooksControllerExecuteWebhookByChannelId: vi.fn(async (channelId, data, params, options) => {
|
|
126
|
+
return { success: true, channelId, data, params, options };
|
|
127
|
+
}),
|
|
128
|
+
|
|
129
|
+
// V3 Workspace M2M Mock
|
|
130
|
+
v3WorkspacesControllerProvisionWorkspace: vi.fn(async (data, options) => {
|
|
131
|
+
return { success: true, data, options };
|
|
132
|
+
}),
|
|
133
|
+
v3WorkspacesControllerUpdateWorkspace: vi.fn(async (slug, data, options) => {
|
|
134
|
+
return { success: true, slug, data, options };
|
|
135
|
+
}),
|
|
136
|
+
v3WorkspacesControllerDeleteWorkspace: vi.fn(async (slug, options) => {
|
|
137
|
+
return { success: true, slug, options };
|
|
138
|
+
}),
|
|
139
|
+
v3WorkspacesControllerGetWorkspaceMembers: vi.fn(async (slug, options) => {
|
|
140
|
+
return { success: true, slug, options };
|
|
141
|
+
}),
|
|
142
|
+
v3WorkspacesControllerAddWorkspaceMember: vi.fn(async (slug, data, options) => {
|
|
143
|
+
return { success: true, slug, data, options };
|
|
144
|
+
}),
|
|
145
|
+
v3WorkspacesControllerGetWorkspaceMember: vi.fn(async (slug, memberId, options) => {
|
|
146
|
+
return { success: true, slug, memberId, options };
|
|
147
|
+
}),
|
|
148
|
+
v3WorkspacesControllerUpdateWorkspaceMember: vi.fn(async (slug, memberId, data, options) => {
|
|
149
|
+
return { success: true, slug, memberId, data, options };
|
|
150
|
+
}),
|
|
151
|
+
v3WorkspacesControllerDeleteWorkspaceMember: vi.fn(async (slug, memberId, options) => {
|
|
152
|
+
return { success: true, slug, memberId, options };
|
|
153
|
+
}),
|
|
154
|
+
v3OAuthControllerGetToken: vi.fn(async (data, options) => {
|
|
155
|
+
return { success: true, data, options };
|
|
156
|
+
}),
|
|
44
157
|
})),
|
|
45
158
|
};
|
|
46
159
|
});
|
|
@@ -220,8 +333,117 @@ describe('ScrymeSDK', () => {
|
|
|
220
333
|
expect(messagesRes.channelId).toBe('chan_123');
|
|
221
334
|
expect(messagesRes.params.limit).toBe(10);
|
|
222
335
|
|
|
223
|
-
|
|
224
|
-
|
|
336
|
+
// Channel message create (with string)
|
|
337
|
+
const createMsgStrRes = await sdk.channel.message.create('chan_123', 'Hello') as any;
|
|
338
|
+
expect(createMsgStrRes.channelId).toBe('chan_123');
|
|
339
|
+
expect(createMsgStrRes.options.data.content).toBe('Hello');
|
|
340
|
+
|
|
341
|
+
// Channel message create (with object)
|
|
342
|
+
const createMsgObjRes = await sdk.channel.message.create('chan_123', { content: 'Hello World' }) as any;
|
|
343
|
+
expect(createMsgObjRes.options.data.content).toBe('Hello World');
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it('should support dm.message namespaces', async () => {
|
|
347
|
+
const sdk = new ScrymeSDK({
|
|
348
|
+
baseURL: 'https://api.test.com',
|
|
349
|
+
token: 'active-token',
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
// DM list
|
|
353
|
+
const listDmsRes = await sdk.dm.list() as any;
|
|
354
|
+
expect(listDmsRes.conversations).toBeDefined();
|
|
355
|
+
|
|
356
|
+
// DM create
|
|
357
|
+
const createDmRes = await sdk.dm.create({ userId: 'user_123' }) as any;
|
|
358
|
+
expect(createDmRes.data.userId).toBe('user_123');
|
|
359
|
+
|
|
360
|
+
// DM message list
|
|
361
|
+
const messagesRes = await sdk.dm.message.list('dm_123', { limit: 5 }) as any;
|
|
362
|
+
expect(messagesRes.dmId).toBe('dm_123');
|
|
363
|
+
expect(messagesRes.params.limit).toBe(5);
|
|
364
|
+
|
|
365
|
+
// DM message create (with string)
|
|
366
|
+
const createMsgStrRes = await sdk.dm.message.create('dm_123', 'Hello DM') as any;
|
|
367
|
+
expect(createMsgStrRes.dmId).toBe('dm_123');
|
|
368
|
+
expect(createMsgStrRes.options.data.content).toBe('Hello DM');
|
|
369
|
+
|
|
370
|
+
// DM message create (with object)
|
|
371
|
+
const createMsgObjRes = await sdk.dm.message.create('dm_123', { content: 'Hello DM Object' }) as any;
|
|
372
|
+
expect(createMsgObjRes.options.data.content).toBe('Hello DM Object');
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it('should route message update/delete/reaction dynamically based on "dm-" prefix', async () => {
|
|
376
|
+
const sdk = new ScrymeSDK({
|
|
377
|
+
baseURL: 'https://api.test.com',
|
|
378
|
+
token: 'active-token',
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
// Standard Channel message update
|
|
382
|
+
const chanUpdate = await sdk.message.update('chan_123', 'msg_1', { content: 'updated content' }) as any;
|
|
383
|
+
expect(chanUpdate.type).toBe('channel');
|
|
384
|
+
expect(chanUpdate.action).toBe('update');
|
|
385
|
+
|
|
386
|
+
// DM message update
|
|
387
|
+
const dmUpdate = await sdk.message.update('dm-123', 'msg_1', { content: 'updated content' }) as any;
|
|
388
|
+
expect(dmUpdate.type).toBe('dm');
|
|
389
|
+
expect(dmUpdate.action).toBe('update');
|
|
390
|
+
|
|
391
|
+
// Standard Channel message delete
|
|
392
|
+
const chanDelete = await sdk.message.delete('chan_123', 'msg_1') as any;
|
|
393
|
+
expect(chanDelete.type).toBe('channel');
|
|
394
|
+
|
|
395
|
+
// DM message delete
|
|
396
|
+
const dmDelete = await sdk.message.delete('dm-123', 'msg_1') as any;
|
|
397
|
+
expect(dmDelete.type).toBe('dm');
|
|
398
|
+
|
|
399
|
+
// Standard Channel message addReaction
|
|
400
|
+
const chanAddReaction = await sdk.message.addReaction('chan_123', 'msg_1', { emoji: '👍' }) as any;
|
|
401
|
+
expect(chanAddReaction.type).toBe('channel');
|
|
402
|
+
|
|
403
|
+
// DM message addReaction
|
|
404
|
+
const dmAddReaction = await sdk.message.addReaction('dm-123', 'msg_1', { emoji: '👍' }) as any;
|
|
405
|
+
expect(dmAddReaction.type).toBe('dm');
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
it('should support webhooks and channel incoming webhooks namespace', async () => {
|
|
409
|
+
const sdk = new ScrymeSDK({
|
|
410
|
+
baseURL: 'https://api.test.com',
|
|
411
|
+
token: 'active-token',
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
// Standard Webhooks
|
|
415
|
+
const createWh = await sdk.webhooks.create('acme', { name: 'wh1', url: 'http://wh', events: ['*'] }) as any;
|
|
416
|
+
expect(createWh.slug).toBe('acme');
|
|
417
|
+
expect(createWh.data.name).toBe('wh1');
|
|
418
|
+
|
|
419
|
+
const listWh = await sdk.webhooks.list('acme') as any;
|
|
420
|
+
expect(listWh.slug).toBe('acme');
|
|
421
|
+
|
|
422
|
+
// Incoming Webhooks
|
|
423
|
+
const createInWh = await sdk.webhooks.incoming.create('acme', 'chan_123', { name: 'incoming_wh' }) as any;
|
|
424
|
+
expect(createInWh.slug).toBe('acme');
|
|
425
|
+
expect(createInWh.channelId).toBe('chan_123');
|
|
426
|
+
expect(createInWh.data.name).toBe('incoming_wh');
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it('should support sdk.m2m operations namespace', async () => {
|
|
430
|
+
const sdk = new ScrymeSDK({
|
|
431
|
+
baseURL: 'https://api.test.com',
|
|
432
|
+
token: 'active-token',
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
// m2m.workspace.provision
|
|
436
|
+
const provRes = await sdk.m2m.workspace.provision({ name: 'Acme', ownerEmail: 'a@acme.com', slug: 'acme' }) as any;
|
|
437
|
+
expect(provRes.data.name).toBe('Acme');
|
|
438
|
+
|
|
439
|
+
// m2m.member.add
|
|
440
|
+
const addMem = await sdk.m2m.member.add('acme', { email: 'user@acme.com', role: 'admin' }) as any;
|
|
441
|
+
expect(addMem.slug).toBe('acme');
|
|
442
|
+
expect(addMem.data.email).toBe('user@acme.com');
|
|
443
|
+
|
|
444
|
+
// m2m.auth.token
|
|
445
|
+
const tokenRes = await sdk.m2m.auth.token('cid', 'sec') as any;
|
|
446
|
+
expect(tokenRes.data.client_id).toBe('cid');
|
|
225
447
|
});
|
|
226
448
|
});
|
|
227
449
|
});
|