cogfy-messenger 0.1.0 → 0.1.2

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.
Files changed (84) hide show
  1. package/dist/clients/base-client.d.ts +8 -0
  2. package/dist/clients/base-client.js +9 -0
  3. package/dist/clients/contacts/contacts-client.d.ts +34 -0
  4. package/dist/clients/contacts/contacts-client.js +66 -0
  5. package/dist/clients/contacts/index.d.ts +2 -0
  6. package/dist/clients/contacts/index.js +18 -0
  7. package/dist/clients/contacts/types/create-contact.d.ts +15 -0
  8. package/dist/clients/contacts/types/create-contact.js +2 -0
  9. package/{src/clients/contacts/types/delete-contact.ts → dist/clients/contacts/types/delete-contact.d.ts} +2 -2
  10. package/dist/clients/contacts/types/delete-contact.js +2 -0
  11. package/dist/clients/contacts/types/get-contact.d.ts +18 -0
  12. package/dist/clients/contacts/types/get-contact.js +2 -0
  13. package/dist/clients/contacts/types/index.d.ts +5 -0
  14. package/dist/clients/contacts/types/index.js +21 -0
  15. package/dist/clients/contacts/types/list-contacts.d.ts +20 -0
  16. package/dist/clients/contacts/types/list-contacts.js +2 -0
  17. package/dist/clients/contacts/types/update-contact.d.ts +14 -0
  18. package/dist/clients/contacts/types/update-contact.js +2 -0
  19. package/dist/clients/conversations/conversations-client.d.ts +24 -0
  20. package/dist/clients/conversations/conversations-client.js +57 -0
  21. package/dist/clients/conversations/index.d.ts +2 -0
  22. package/dist/clients/conversations/index.js +18 -0
  23. package/dist/clients/conversations/types/get-conversation.d.ts +11 -0
  24. package/dist/clients/conversations/types/get-conversation.js +2 -0
  25. package/dist/clients/conversations/types/get-messages.d.ts +35 -0
  26. package/dist/clients/conversations/types/get-messages.js +2 -0
  27. package/dist/clients/conversations/types/index.d.ts +4 -0
  28. package/dist/clients/conversations/types/index.js +20 -0
  29. package/dist/clients/conversations/types/list-conversations.d.ts +30 -0
  30. package/dist/clients/conversations/types/list-conversations.js +2 -0
  31. package/dist/clients/conversations/types/send-message.d.ts +12 -0
  32. package/dist/clients/conversations/types/send-message.js +2 -0
  33. package/dist/clients/index.d.ts +2 -0
  34. package/dist/clients/index.js +18 -0
  35. package/dist/clients/tags/index.d.ts +2 -0
  36. package/dist/clients/tags/index.js +18 -0
  37. package/dist/clients/tags/tags-client.d.ts +34 -0
  38. package/dist/clients/tags/tags-client.js +66 -0
  39. package/{src/clients/tags/types/create-tag.ts → dist/clients/tags/types/create-tag.d.ts} +5 -6
  40. package/dist/clients/tags/types/create-tag.js +2 -0
  41. package/dist/clients/tags/types/delete-tag.d.ts +4 -0
  42. package/dist/clients/tags/types/delete-tag.js +2 -0
  43. package/dist/clients/tags/types/get-tag.d.ts +4 -0
  44. package/dist/clients/tags/types/get-tag.js +2 -0
  45. package/dist/clients/tags/types/index.d.ts +5 -0
  46. package/dist/clients/tags/types/index.js +21 -0
  47. package/dist/clients/tags/types/list-tags.d.ts +6 -0
  48. package/dist/clients/tags/types/list-tags.js +2 -0
  49. package/{src/clients/tags/types/update-tag.ts → dist/clients/tags/types/update-tag.d.ts} +5 -6
  50. package/dist/clients/tags/types/update-tag.js +2 -0
  51. package/dist/cogfy-messenger.d.ts +13 -0
  52. package/dist/cogfy-messenger.js +27 -0
  53. package/dist/index.d.ts +2 -0
  54. package/dist/index.js +18 -0
  55. package/package.json +5 -2
  56. package/.github/workflows/tests.yml +0 -18
  57. package/src/clients/base-client.ts +0 -13
  58. package/src/clients/contacts/contacts-client.test.ts +0 -89
  59. package/src/clients/contacts/contacts-client.ts +0 -49
  60. package/src/clients/contacts/index.ts +0 -2
  61. package/src/clients/contacts/types/create-contact.ts +0 -16
  62. package/src/clients/contacts/types/get-contact.ts +0 -18
  63. package/src/clients/contacts/types/index.ts +0 -5
  64. package/src/clients/contacts/types/list-contacts.ts +0 -20
  65. package/src/clients/contacts/types/update-contact.ts +0 -15
  66. package/src/clients/conversations/conversations-client.test.ts +0 -56
  67. package/src/clients/conversations/conversations-client.ts +0 -41
  68. package/src/clients/conversations/index.ts +0 -2
  69. package/src/clients/conversations/types/get-conversation.ts +0 -11
  70. package/src/clients/conversations/types/get-messages.ts +0 -35
  71. package/src/clients/conversations/types/index.ts +0 -4
  72. package/src/clients/conversations/types/list-conversations.ts +0 -37
  73. package/src/clients/conversations/types/send-message.ts +0 -13
  74. package/src/clients/index.ts +0 -2
  75. package/src/clients/tags/index.ts +0 -2
  76. package/src/clients/tags/tags-client.test.ts +0 -80
  77. package/src/clients/tags/tags-client.ts +0 -49
  78. package/src/clients/tags/types/delete-tag.ts +0 -4
  79. package/src/clients/tags/types/get-tag.ts +0 -4
  80. package/src/clients/tags/types/index.ts +0 -5
  81. package/src/clients/tags/types/list-tags.ts +0 -6
  82. package/src/cogfy-messenger.ts +0 -33
  83. package/src/index.ts +0 -2
  84. package/tsconfig.json +0 -16
@@ -1,37 +0,0 @@
1
- export type ListConversationsParams =
2
- | {
3
- phoneNumberId: string
4
- cursor?: never
5
- }
6
- | {
7
- phoneNumberId?: never
8
- cursor: string
9
- }
10
-
11
- export type ListMessagesParams =
12
- | {
13
- conversationId: string
14
- cursor?: never
15
- }
16
- | {
17
- conversationId?: never
18
- cursor: string
19
- }
20
-
21
- export type ListConversationsResult = {
22
- data: ListConversationsResultData[]
23
- cursors: {
24
- next: string | null
25
- }
26
- }
27
-
28
- export type ListConversationsResultData = {
29
- id: string
30
- workspaceId: string
31
- phoneNumberId: string | null
32
- recipientId: string | null
33
- assigneeId: string | null
34
- lastMessageId: string | null
35
- createDate: string
36
- serviceWindowExpireDate: string | null
37
- }
@@ -1,13 +0,0 @@
1
- export type SendMessageCommand = {
2
- type: 'text' | 'image' | 'document'
3
- content?: string | null
4
- media?: {
5
- name: string | null
6
- mimeType: string
7
- base64: string
8
- } | null
9
- }
10
-
11
- export type SendMessageResult = {
12
- id: string
13
- }
@@ -1,2 +0,0 @@
1
- export * from './contacts/types'
2
- export * from './tags/types'
@@ -1,2 +0,0 @@
1
- export * from './tags-client'
2
- export * from './types'
@@ -1,80 +0,0 @@
1
- import AxiosMockAdapter from 'axios-mock-adapter'
2
- import { TagsClient } from './tags-client'
3
- import axios from 'axios'
4
- import { CogfyMessenger } from '../../cogfy-messenger'
5
- import { faker } from '@faker-js/faker'
6
- import { describe, expect, it, beforeEach } from 'vitest'
7
-
8
- describe(TagsClient, () => {
9
- const axiosMock = new AxiosMockAdapter(axios)
10
- const cogfy = new CogfyMessenger({ apiKey: 'test' })
11
-
12
- beforeEach(() => {
13
- axiosMock.restore()
14
- })
15
-
16
- describe(TagsClient.prototype.create, () => {
17
- it('should call POST /tags endpoint', async () => {
18
- const fakeId = faker.string.uuid()
19
- axiosMock.onPost('/tags').reply(201, { id: fakeId })
20
-
21
- const result = await cogfy.tags.create({
22
- name: faker.lorem.word()
23
- })
24
-
25
- expect(result).toEqual({
26
- id: fakeId
27
- })
28
- })
29
- })
30
-
31
- describe(TagsClient.prototype.delete, () => {
32
- it('should call DELETE /tags/:id endpoint', async () => {
33
- const name = faker.lorem.word()
34
- const id = faker.string.uuid()
35
- axiosMock.onDelete(`/tags/${id}`).reply(200, { id, name })
36
-
37
- const result = await cogfy.tags.delete(id)
38
-
39
- expect(result).toEqual({ id, name })
40
- })
41
- })
42
-
43
- describe(TagsClient.prototype.get, () => {
44
- it('should call GET /tags/:id endpoint', async () => {
45
- const id = faker.string.uuid()
46
- const name = faker.lorem.word()
47
- axiosMock.onGet(`/tags/${id}`).reply(200, { id, name })
48
-
49
- const result = await cogfy.tags.get(id)
50
-
51
- expect(result).toEqual({ id, name })
52
- })
53
- })
54
-
55
- describe(TagsClient.prototype.list, () => {
56
- it('should call GET /tags endpoint', async () => {
57
- const tags = Array.from({ length: 3 }, () => ({
58
- id: faker.string.uuid(),
59
- name: faker.lorem.word()
60
- }))
61
- axiosMock.onGet('/tags').reply(200, { data: tags })
62
-
63
- const result = await cogfy.tags.list()
64
-
65
- expect(result.data).toEqual(tags)
66
- })
67
- })
68
-
69
- describe(TagsClient.prototype.update, () => {
70
- it('should call PATCH /tags/:id endpoint', async () => {
71
- const id = faker.string.uuid()
72
- const name = faker.lorem.word()
73
- axiosMock.onPatch(`/tags/${id}`).reply(200, { id, name })
74
-
75
- const result = await cogfy.tags.update(id, { name })
76
-
77
- expect(result).toEqual({ id, name })
78
- })
79
- })
80
- })
@@ -1,49 +0,0 @@
1
- import { BaseClient } from '../base-client'
2
- import { CreateTagCommand, CreateTagResult, DeleteTagResult, GetTagResult, ListTagsResult, UpdateTagCommand, UpdateTagResult } from './types'
3
-
4
- export class TagsClient extends BaseClient {
5
- /**
6
- * Calls the POST /tags endpoint
7
- * @param payload The tag data to create
8
- * @returns An object with the ID and the name of the newly created tag
9
- */
10
- async create(payload: CreateTagCommand): Promise<CreateTagResult> {
11
- return (await this.axios.post('/tags', payload)).data
12
- }
13
-
14
- /**
15
- * Calls the DELETE /tags/:id endpoint
16
- * @param id The ID of the tag to delete
17
- * @returns An object with the ID and the name of the deleted tag
18
- */
19
- async delete(id: string): Promise<DeleteTagResult> {
20
- return (await this.axios.delete(`/tags/${id}`)).data
21
- }
22
-
23
- /**
24
- * Calls the GET /tags/:id endpoint
25
- * @param id The ID of the tag to retrieve
26
- * @returns The tag with the specified ID
27
- */
28
- async get(id: string): Promise<GetTagResult> {
29
- return (await this.axios.get(`/tags/${id}`)).data
30
- }
31
-
32
- /**
33
- * Calls the GET /tags endpoint
34
- * @returns A list of all tags in the workspace
35
- */
36
- async list(): Promise<ListTagsResult> {
37
- return (await this.axios.get('/tags')).data
38
- }
39
-
40
- /**
41
- * Calls the PATCH /tags/:id endpoint
42
- * @param id The ID of the tag to update
43
- * @param payload The updated tag data
44
- * @returns An object with the ID and the name of the updated tag
45
- */
46
- async update(id: string, payload: UpdateTagCommand): Promise<UpdateTagResult> {
47
- return (await this.axios.patch(`/tags/${id}`, payload)).data
48
- }
49
- }
@@ -1,4 +0,0 @@
1
- export type DeleteTagResult = {
2
- id: string
3
- name: string
4
- }
@@ -1,4 +0,0 @@
1
- export type GetTagResult = {
2
- id: string
3
- name: string
4
- }
@@ -1,5 +0,0 @@
1
- export * from './create-tag'
2
- export * from './delete-tag'
3
- export * from './get-tag'
4
- export * from './list-tags'
5
- export * from './update-tag'
@@ -1,6 +0,0 @@
1
- export type ListTagsResult = {
2
- data: {
3
- id: string
4
- name: string
5
- }[]
6
- }
@@ -1,33 +0,0 @@
1
- import axios from 'axios'
2
- import { ContactsClient } from './clients/contacts'
3
- import { BaseClientOptions } from './clients/base-client'
4
- import { TagsClient } from './clients/tags'
5
- import { ConversationsClient } from './clients/conversations'
6
-
7
- export type CogfyMessengerOptions = {
8
- apiKey: string
9
- baseURL?: string
10
- }
11
-
12
- const DEFAULT_BASE_URL = 'https://messenger-public-api.cogfy.com'
13
-
14
- export class CogfyMessenger {
15
- contacts: ContactsClient
16
- conversations: ConversationsClient
17
- tags: TagsClient
18
-
19
- constructor (options: CogfyMessengerOptions) {
20
- const clientOptions: BaseClientOptions = {
21
- axios: axios.create({
22
- baseURL: options.baseURL || DEFAULT_BASE_URL,
23
- headers: {
24
- 'Authorization': `Bearer ${options.apiKey}`
25
- }
26
- })
27
- }
28
-
29
- this.contacts = new ContactsClient(clientOptions)
30
- this.conversations = new ConversationsClient(clientOptions)
31
- this.tags = new TagsClient(clientOptions)
32
- }
33
- }
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './clients'
2
- export * from './cogfy-messenger'
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "exclude": [
3
- "dist",
4
- "**/*.test.ts"
5
- ],
6
- "compilerOptions": {
7
- "target": "es2016",
8
- "module": "commonjs",
9
- "declaration": true,
10
- "outDir": "./dist",
11
- "esModuleInterop": true,
12
- "forceConsistentCasingInFileNames": true,
13
- "strict": true,
14
- "skipLibCheck": true
15
- }
16
- }