@natyapp/meta 1.6.7 → 1.7.0

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 (89) hide show
  1. package/.github/copilot-instructions.md +1540 -0
  2. package/README.md +122 -1
  3. package/dist/index.d.ts +7 -2
  4. package/dist/index.js +11 -2
  5. package/dist/interfaces/IConnection.d.ts +2 -2
  6. package/dist/interfaces/ILog.d.ts +2 -2
  7. package/dist/interfaces/ILogger.d.ts +62 -0
  8. package/dist/interfaces/ILogger.js +2 -0
  9. package/dist/interfaces/ISdk.d.ts +4 -2
  10. package/dist/interfaces/IWebhook.d.ts +2 -2
  11. package/dist/interfaces/index.d.ts +1 -0
  12. package/dist/interfaces/index.js +1 -0
  13. package/dist/queue/messageQueue.d.ts +1 -1
  14. package/dist/queue/messageQueue.js +45 -0
  15. package/dist/routes/webhooks/methods/connection.js +78 -11
  16. package/dist/routes/webhooks/methods/messages.js +18 -3
  17. package/dist/services/axiosInstances.d.ts +14 -5
  18. package/dist/services/axiosInstances.js +111 -23
  19. package/dist/services/middlewares/validations.d.ts +2 -2
  20. package/dist/services/middlewares/validations.js +1 -2
  21. package/dist/services/mutations/connection.js +1 -1
  22. package/dist/services/mutations/logs.js +1 -1
  23. package/dist/services/mutations/messages.js +1 -1
  24. package/dist/services/mutations/validation.d.ts +1 -1
  25. package/dist/services/mutations/validation.js +1 -1
  26. package/dist/services/mutations/webhooks.js +1 -1
  27. package/dist/types/logs.d.ts +1 -1
  28. package/dist/types/requestTypes.d.ts +2 -0
  29. package/dist/useCases/connection/index.d.ts +9 -9
  30. package/dist/useCases/connection/index.js +156 -7
  31. package/dist/useCases/events/NatyEvents.d.ts +4 -2
  32. package/dist/useCases/events/NatyEvents.js +13 -1
  33. package/dist/useCases/log/index.d.ts +5 -5
  34. package/dist/useCases/log/index.js +65 -3
  35. package/dist/useCases/message/whatsappResponse.d.ts +33 -23
  36. package/dist/useCases/message/whatsappResponse.js +655 -109
  37. package/dist/useCases/messages/index.d.ts +5 -5
  38. package/dist/useCases/messages/index.js +66 -3
  39. package/dist/useCases/sdk/index.d.ts +8 -4
  40. package/dist/useCases/sdk/index.js +38 -6
  41. package/dist/useCases/webhook/index.d.ts +9 -9
  42. package/dist/useCases/webhook/index.js +154 -7
  43. package/dist/utils/consoleLogger.d.ts +20 -0
  44. package/dist/utils/consoleLogger.js +51 -0
  45. package/dist/utils/index.d.ts +6 -0
  46. package/dist/utils/index.js +6 -0
  47. package/dist/utils/loggerContext.d.ts +57 -0
  48. package/dist/utils/loggerContext.js +90 -0
  49. package/dist/utils/methodContext.d.ts +34 -0
  50. package/dist/utils/methodContext.js +48 -0
  51. package/dist/utils/parseError.d.ts +12 -0
  52. package/dist/utils/parseError.js +27 -3
  53. package/dist/utils/pinoAdapter.d.ts +30 -0
  54. package/dist/utils/pinoAdapter.js +68 -0
  55. package/dist/utils/sanitize.d.ts +42 -0
  56. package/dist/utils/sanitize.js +120 -0
  57. package/dist/utils/tryCatch.d.ts +10 -1
  58. package/dist/utils/tryCatch.js +40 -5
  59. package/docs/01-visao-geral.md +355 -0
  60. package/docs/02-contexto-negocio.md +596 -0
  61. package/docs/03-arquitetura.md +925 -0
  62. package/docs/04-fluxos-funcionais.md +887 -0
  63. package/docs/05-integracoes.md +960 -0
  64. package/docs/06-entidades.md +849 -0
  65. package/docs/07-guia-pratico.md +1133 -0
  66. package/docs/08-troubleshooting.md +816 -0
  67. package/docs/README.md +125 -0
  68. package/examples/logger-example.ts +279 -0
  69. package/package.json +2 -2
  70. /package/dist/{Entities → entities}/Logs.d.ts +0 -0
  71. /package/dist/{Entities → entities}/Logs.js +0 -0
  72. /package/dist/{Entities → entities}/connection.d.ts +0 -0
  73. /package/dist/{Entities → entities}/connection.js +0 -0
  74. /package/dist/{Entities → entities}/errorLogs.d.ts +0 -0
  75. /package/dist/{Entities → entities}/errorLogs.js +0 -0
  76. /package/dist/{Entities → entities}/index.d.ts +0 -0
  77. /package/dist/{Entities → entities}/index.js +0 -0
  78. /package/dist/{Entities → entities}/messages.d.ts +0 -0
  79. /package/dist/{Entities → entities}/messages.js +0 -0
  80. /package/dist/{Entities → entities}/webhooks.d.ts +0 -0
  81. /package/dist/{Entities → entities}/webhooks.js +0 -0
  82. /package/dist/{Entities → entities}/whatsappMessage.d.ts +0 -0
  83. /package/dist/{Entities → entities}/whatsappMessage.js +0 -0
  84. /package/dist/{Errors → errors}/Either.d.ts +0 -0
  85. /package/dist/{Errors → errors}/Either.js +0 -0
  86. /package/dist/{Errors → errors}/ErrorHandling.d.ts +0 -0
  87. /package/dist/{Errors → errors}/ErrorHandling.js +0 -0
  88. /package/dist/{Errors → errors}/index.d.ts +0 -0
  89. /package/dist/{Errors → errors}/index.js +0 -0
@@ -1,11 +1,12 @@
1
- import { MessageEntity } from "../../Entities/messages";
2
- import { WhatsappMessage } from "../../Entities/whatsappMessage";
1
+ import { LogsEntity } from "../../entities/Logs";
2
+ import { WhatsappMessage } from "../../entities/whatsappMessage";
3
3
  import { Button } from "../../elements/button";
4
4
  import { List } from "../../elements/list";
5
5
  import { ISendMessageReturn } from "../../interfaces";
6
6
  import { getAllReturn } from "../../types";
7
7
  import { contactType } from "../../types/whatsappTypes";
8
8
  import { connectionEvent } from "../events/NatyEvents";
9
+ import { Either } from "../../errors/Either";
9
10
  export declare class WhatsappResponse {
10
11
  companyId: string;
11
12
  phone_number_id: string;
@@ -15,55 +16,64 @@ export declare class WhatsappResponse {
15
16
  messageType: string;
16
17
  private apiCall;
17
18
  token: string;
19
+ private logger;
20
+ private _initialized;
21
+ private _initializationPromise;
18
22
  constructor(companyId: string, phone_number_id: string, clientNumber?: string, message?: WhatsappMessage | undefined);
23
+ /**
24
+ * Ensures the WhatsappResponse instance is initialized with valid token.
25
+ * This method implements lazy initialization and is idempotent.
26
+ * @returns Either with error or void on success
27
+ */
28
+ private ensureInitialized;
19
29
  private getApiInstanceToken;
20
30
  updateClientNumber(clientNumber: string): Promise<void>;
21
- get_account_info(): Promise<connectionEvent["accountInfo"] | null>;
31
+ get_account_info(): Promise<Either<Error, connectionEvent["accountInfo"]>>;
22
32
  get_old_messages({ page, size, }: {
23
33
  page: number;
24
34
  size: number;
25
- }): Promise<getAllReturn<MessageEntity> | null>;
26
- send_text_message(text: string): Promise<ISendMessageReturn | null>;
27
- send_button(btn: Button): Promise<ISendMessageReturn | null>;
28
- send_list(list: List): Promise<ISendMessageReturn | null>;
35
+ }): Promise<Either<Error, getAllReturn<LogsEntity>>>;
36
+ send_text_message(text: string): Promise<Either<Error, ISendMessageReturn>>;
37
+ send_button(btn: Button): Promise<Either<Error, ISendMessageReturn>>;
38
+ send_list(list: List): Promise<Either<Error, ISendMessageReturn>>;
29
39
  reply({ type, toReply, messageToReply, }: {
30
40
  type: "text" | "interactive";
31
41
  toReply: string | Button | List;
32
42
  messageToReply?: string;
33
- }): Promise<ISendMessageReturn | null>;
34
- mark_as_read(): Promise<boolean>;
43
+ }): Promise<Either<Error, ISendMessageReturn>>;
44
+ mark_as_read(): Promise<Either<Error, boolean>>;
35
45
  send_reaction(emoji?: string): Promise<ISendMessageReturn | null>;
36
46
  send_location({ long, lat, name, address, }: {
37
47
  long?: number;
38
48
  lat?: number;
39
49
  name: string;
40
50
  address: string;
41
- }): Promise<ISendMessageReturn | null>;
42
- send_contacts(contacts: contactType[]): Promise<ISendMessageReturn | null>;
43
- createMedia(stream: string, fileType: string): Promise<any>;
51
+ }): Promise<Either<Error, ISendMessageReturn>>;
52
+ send_contacts(contacts: contactType[]): Promise<Either<Error, ISendMessageReturn>>;
53
+ createMedia(stream: string, fileType: string): Promise<Either<Error, any>>;
44
54
  sendLink(link: string, linkType: "image" | "document" | "audio" | "video" | "sticker", linkData?: {
45
55
  caption?: string;
46
56
  filename?: string;
47
- }): Promise<ISendMessageReturn | null>;
57
+ }): Promise<Either<Error, ISendMessageReturn>>;
48
58
  send_image(stream: string, filetype: "image/jpeg" | "image/png" | "link", fileData: {
49
59
  description: string;
50
- }): Promise<ISendMessageReturn | null>;
60
+ }): Promise<Either<Error, ISendMessageReturn>>;
51
61
  send_document(stream: string, filetype: "text/plain" | "application/pdf" | "application/vnd.ms-powerpoint" | "application/msword" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "link", fileData: {
52
62
  fileName: string;
53
63
  description: string;
54
- }): Promise<ISendMessageReturn | null>;
64
+ }): Promise<Either<Error, ISendMessageReturn>>;
55
65
  send_video(stream: string, filetype: "video/mp4" | "video/3gp" | "link", fileData: {
56
66
  description: string;
57
- }): Promise<ISendMessageReturn | null>;
58
- send_sticker(stream: string, filetype: "image/webp" | "link"): Promise<ISendMessageReturn | null>;
59
- send_audio(stream: string, filetype: "audio/aac" | "audio/mp4" | "audio/mpeg" | "audio/amr" | "audio/ogg" | "link"): Promise<ISendMessageReturn | null>;
60
- download_media(url: string, mimetype: string): Promise<any>;
61
- get_media_url(media_id: string): Promise<any>;
62
- update_long_lived_token(client_id: string, client_secret: string, fb_exchange_token: string): Promise<string | undefined>;
67
+ }): Promise<Either<Error, ISendMessageReturn>>;
68
+ send_sticker(stream: string, filetype: "image/webp" | "link"): Promise<Either<Error, ISendMessageReturn>>;
69
+ send_audio(stream: string, filetype: "audio/aac" | "audio/mp4" | "audio/mpeg" | "audio/amr" | "audio/ogg" | "link"): Promise<Either<Error, ISendMessageReturn>>;
70
+ download_media(url: string, mimetype: string): Promise<Either<Error, any>>;
71
+ get_media_url(media_id: string): Promise<Either<Error, any>>;
72
+ update_long_lived_token(client_id: string, client_secret: string, fb_exchange_token: string): Promise<Either<Error, string>>;
63
73
  send_template_text_message(template: string, language: string, bodyParameters?: Array<{
64
74
  type: string;
65
75
  text: string;
66
- }>): Promise<ISendMessageReturn | null>;
76
+ }>): Promise<Either<Error, ISendMessageReturn>>;
67
77
  send_template_media_message(template: string, language: string, options: {
68
78
  header?: {
69
79
  type: "image" | "video" | "document";
@@ -76,5 +86,5 @@ export declare class WhatsappResponse {
76
86
  type: string;
77
87
  text: string;
78
88
  }>;
79
- }): Promise<ISendMessageReturn | null>;
89
+ }): Promise<Either<Error, ISendMessageReturn>>;
80
90
  }