meta-cloud-api 0.2.12 → 0.2.14

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 (297) hide show
  1. package/README.md +5 -2
  2. package/dist/api/index.d.mts +495 -27
  3. package/dist/api/index.mjs +1 -1
  4. package/dist/api/index.mjs.map +1 -1
  5. package/dist/chunk-KZQQJAPX.mjs +2 -0
  6. package/dist/chunk-KZQQJAPX.mjs.map +1 -0
  7. package/dist/chunk-N7A7DQDX.mjs +2 -0
  8. package/dist/chunk-N7A7DQDX.mjs.map +1 -0
  9. package/dist/chunk-QE4PKOSW.mjs +2 -0
  10. package/dist/chunk-QE4PKOSW.mjs.map +1 -0
  11. package/dist/chunk-R4CFE2XP.mjs +2 -0
  12. package/dist/chunk-R4CFE2XP.mjs.map +1 -0
  13. package/dist/chunk-XVYL7ZTG.mjs +2 -0
  14. package/dist/chunk-XVYL7ZTG.mjs.map +1 -0
  15. package/dist/index.d.mts +142 -43
  16. package/dist/index.mjs +2 -2
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/types/index.d.mts +512 -19
  19. package/dist/types/index.mjs +1 -1
  20. package/dist/types/index.mjs.map +1 -1
  21. package/dist/utils/index.d.mts +70 -21
  22. package/dist/utils/index.mjs +1 -1
  23. package/dist/utils/index.mjs.map +1 -1
  24. package/dist/waba-RRlZTQUG.d.mts +2229 -0
  25. package/dist/{types/whatsapp.d.ts → whatsapp-BNHXjrds.d.mts} +2 -17
  26. package/package.json +52 -18
  27. package/dist/api/base.d.mts +0 -15
  28. package/dist/api/base.d.ts +0 -15
  29. package/dist/api/base.js +0 -2
  30. package/dist/api/base.js.map +0 -1
  31. package/dist/api/base.mjs +0 -2
  32. package/dist/api/base.mjs.map +0 -1
  33. package/dist/api/businessProfile.d.mts +0 -145
  34. package/dist/api/businessProfile.d.ts +0 -145
  35. package/dist/api/businessProfile.js +0 -2
  36. package/dist/api/businessProfile.js.map +0 -1
  37. package/dist/api/businessProfile.mjs +0 -2
  38. package/dist/api/businessProfile.mjs.map +0 -1
  39. package/dist/api/encryption.d.mts +0 -15
  40. package/dist/api/encryption.d.ts +0 -15
  41. package/dist/api/encryption.js +0 -2
  42. package/dist/api/encryption.js.map +0 -1
  43. package/dist/api/encryption.mjs +0 -2
  44. package/dist/api/encryption.mjs.map +0 -1
  45. package/dist/api/flow.d.mts +0 -126
  46. package/dist/api/flow.d.ts +0 -126
  47. package/dist/api/flow.js +0 -2
  48. package/dist/api/flow.js.map +0 -1
  49. package/dist/api/flow.mjs +0 -2
  50. package/dist/api/flow.mjs.map +0 -1
  51. package/dist/api/index.d.ts +0 -28
  52. package/dist/api/index.js +0 -2
  53. package/dist/api/index.js.map +0 -1
  54. package/dist/api/media.d.mts +0 -17
  55. package/dist/api/media.d.ts +0 -17
  56. package/dist/api/media.js +0 -2
  57. package/dist/api/media.js.map +0 -1
  58. package/dist/api/media.mjs +0 -2
  59. package/dist/api/media.mjs.map +0 -1
  60. package/dist/api/messages.d.mts +0 -193
  61. package/dist/api/messages.d.ts +0 -193
  62. package/dist/api/messages.js +0 -2
  63. package/dist/api/messages.js.map +0 -1
  64. package/dist/api/messages.mjs +0 -2
  65. package/dist/api/messages.mjs.map +0 -1
  66. package/dist/api/phoneNumber.d.mts +0 -17
  67. package/dist/api/phoneNumber.d.ts +0 -17
  68. package/dist/api/phoneNumber.js +0 -2
  69. package/dist/api/phoneNumber.js.map +0 -1
  70. package/dist/api/phoneNumber.mjs +0 -2
  71. package/dist/api/phoneNumber.mjs.map +0 -1
  72. package/dist/api/qrCode.d.mts +0 -18
  73. package/dist/api/qrCode.d.ts +0 -18
  74. package/dist/api/qrCode.js +0 -2
  75. package/dist/api/qrCode.js.map +0 -1
  76. package/dist/api/qrCode.mjs +0 -2
  77. package/dist/api/qrCode.mjs.map +0 -1
  78. package/dist/api/registration.d.mts +0 -14
  79. package/dist/api/registration.d.ts +0 -14
  80. package/dist/api/registration.js +0 -2
  81. package/dist/api/registration.js.map +0 -1
  82. package/dist/api/registration.mjs +0 -2
  83. package/dist/api/registration.mjs.map +0 -1
  84. package/dist/api/template.d.mts +0 -18
  85. package/dist/api/template.d.ts +0 -18
  86. package/dist/api/template.js +0 -2
  87. package/dist/api/template.js.map +0 -1
  88. package/dist/api/template.mjs +0 -2
  89. package/dist/api/template.mjs.map +0 -1
  90. package/dist/api/twoStepVerification.d.mts +0 -13
  91. package/dist/api/twoStepVerification.d.ts +0 -13
  92. package/dist/api/twoStepVerification.js +0 -2
  93. package/dist/api/twoStepVerification.js.map +0 -1
  94. package/dist/api/twoStepVerification.mjs +0 -2
  95. package/dist/api/twoStepVerification.mjs.map +0 -1
  96. package/dist/api/waba.d.mts +0 -16
  97. package/dist/api/waba.d.ts +0 -16
  98. package/dist/api/waba.js +0 -2
  99. package/dist/api/waba.js.map +0 -1
  100. package/dist/api/waba.mjs +0 -2
  101. package/dist/api/waba.mjs.map +0 -1
  102. package/dist/enums-CI7vzKhn.d.mts +0 -687
  103. package/dist/enums-CI7vzKhn.d.ts +0 -687
  104. package/dist/httpsClient.d.mts +0 -22
  105. package/dist/httpsClient.d.ts +0 -22
  106. package/dist/httpsClient.js +0 -2
  107. package/dist/httpsClient.js.map +0 -1
  108. package/dist/httpsClient.mjs +0 -2
  109. package/dist/httpsClient.mjs.map +0 -1
  110. package/dist/index.d.ts +0 -46
  111. package/dist/index.js +0 -3
  112. package/dist/index.js.map +0 -1
  113. package/dist/request.d.mts +0 -25
  114. package/dist/request.d.ts +0 -25
  115. package/dist/request.js +0 -2
  116. package/dist/request.js.map +0 -1
  117. package/dist/request.mjs +0 -2
  118. package/dist/request.mjs.map +0 -1
  119. package/dist/types/base.d.mts +0 -8
  120. package/dist/types/base.d.ts +0 -8
  121. package/dist/types/base.js +0 -2
  122. package/dist/types/base.js.map +0 -1
  123. package/dist/types/base.mjs +0 -1
  124. package/dist/types/base.mjs.map +0 -1
  125. package/dist/types/businessProfile.d.mts +0 -153
  126. package/dist/types/businessProfile.d.ts +0 -153
  127. package/dist/types/businessProfile.js +0 -2
  128. package/dist/types/businessProfile.js.map +0 -1
  129. package/dist/types/businessProfile.mjs +0 -1
  130. package/dist/types/businessProfile.mjs.map +0 -1
  131. package/dist/types/config.d.mts +0 -62
  132. package/dist/types/config.d.ts +0 -62
  133. package/dist/types/config.js +0 -2
  134. package/dist/types/config.js.map +0 -1
  135. package/dist/types/config.mjs +0 -1
  136. package/dist/types/config.mjs.map +0 -1
  137. package/dist/types/encryption.d.mts +0 -13
  138. package/dist/types/encryption.d.ts +0 -13
  139. package/dist/types/encryption.js +0 -2
  140. package/dist/types/encryption.js.map +0 -1
  141. package/dist/types/encryption.mjs +0 -1
  142. package/dist/types/encryption.mjs.map +0 -1
  143. package/dist/types/enums.d.mts +0 -1
  144. package/dist/types/enums.d.ts +0 -1
  145. package/dist/types/enums.js +0 -2
  146. package/dist/types/enums.js.map +0 -1
  147. package/dist/types/enums.mjs +0 -2
  148. package/dist/types/enums.mjs.map +0 -1
  149. package/dist/types/flow.d.mts +0 -404
  150. package/dist/types/flow.d.ts +0 -404
  151. package/dist/types/flow.js +0 -2
  152. package/dist/types/flow.js.map +0 -1
  153. package/dist/types/flow.mjs +0 -2
  154. package/dist/types/flow.mjs.map +0 -1
  155. package/dist/types/httpsClient.d.mts +0 -19
  156. package/dist/types/httpsClient.d.ts +0 -19
  157. package/dist/types/httpsClient.js +0 -2
  158. package/dist/types/httpsClient.js.map +0 -1
  159. package/dist/types/httpsClient.mjs +0 -1
  160. package/dist/types/httpsClient.mjs.map +0 -1
  161. package/dist/types/index.d.ts +0 -20
  162. package/dist/types/index.js +0 -2
  163. package/dist/types/index.js.map +0 -1
  164. package/dist/types/logger.d.mts +0 -9
  165. package/dist/types/logger.d.ts +0 -9
  166. package/dist/types/logger.js +0 -2
  167. package/dist/types/logger.js.map +0 -1
  168. package/dist/types/logger.mjs +0 -1
  169. package/dist/types/logger.mjs.map +0 -1
  170. package/dist/types/media.d.mts +0 -31
  171. package/dist/types/media.d.ts +0 -31
  172. package/dist/types/media.js +0 -2
  173. package/dist/types/media.js.map +0 -1
  174. package/dist/types/media.mjs +0 -1
  175. package/dist/types/media.mjs.map +0 -1
  176. package/dist/types/messages.d.mts +0 -558
  177. package/dist/types/messages.d.ts +0 -558
  178. package/dist/types/messages.js +0 -2
  179. package/dist/types/messages.js.map +0 -1
  180. package/dist/types/messages.mjs +0 -1
  181. package/dist/types/messages.mjs.map +0 -1
  182. package/dist/types/phoneNumber.d.mts +0 -82
  183. package/dist/types/phoneNumber.d.ts +0 -82
  184. package/dist/types/phoneNumber.js +0 -2
  185. package/dist/types/phoneNumber.js.map +0 -1
  186. package/dist/types/phoneNumber.mjs +0 -1
  187. package/dist/types/phoneNumber.mjs.map +0 -1
  188. package/dist/types/qrCode.d.mts +0 -27
  189. package/dist/types/qrCode.d.ts +0 -27
  190. package/dist/types/qrCode.js +0 -2
  191. package/dist/types/qrCode.js.map +0 -1
  192. package/dist/types/qrCode.mjs +0 -1
  193. package/dist/types/qrCode.mjs.map +0 -1
  194. package/dist/types/registration.d.mts +0 -14
  195. package/dist/types/registration.d.ts +0 -14
  196. package/dist/types/registration.js +0 -2
  197. package/dist/types/registration.js.map +0 -1
  198. package/dist/types/registration.mjs +0 -1
  199. package/dist/types/registration.mjs.map +0 -1
  200. package/dist/types/request.d.mts +0 -50
  201. package/dist/types/request.d.ts +0 -50
  202. package/dist/types/request.js +0 -2
  203. package/dist/types/request.js.map +0 -1
  204. package/dist/types/request.mjs +0 -1
  205. package/dist/types/request.mjs.map +0 -1
  206. package/dist/types/template.d.mts +0 -106
  207. package/dist/types/template.d.ts +0 -106
  208. package/dist/types/template.js +0 -2
  209. package/dist/types/template.js.map +0 -1
  210. package/dist/types/template.mjs +0 -1
  211. package/dist/types/template.mjs.map +0 -1
  212. package/dist/types/twoStepVerification.d.mts +0 -11
  213. package/dist/types/twoStepVerification.d.ts +0 -11
  214. package/dist/types/twoStepVerification.js +0 -2
  215. package/dist/types/twoStepVerification.js.map +0 -1
  216. package/dist/types/twoStepVerification.mjs +0 -1
  217. package/dist/types/twoStepVerification.mjs.map +0 -1
  218. package/dist/types/waba.d.mts +0 -78
  219. package/dist/types/waba.d.ts +0 -78
  220. package/dist/types/waba.js +0 -2
  221. package/dist/types/waba.js.map +0 -1
  222. package/dist/types/waba.mjs +0 -2
  223. package/dist/types/waba.mjs.map +0 -1
  224. package/dist/types/webhook.d.mts +0 -486
  225. package/dist/types/webhook.d.ts +0 -486
  226. package/dist/types/webhook.js +0 -2
  227. package/dist/types/webhook.js.map +0 -1
  228. package/dist/types/webhook.mjs +0 -2
  229. package/dist/types/webhook.mjs.map +0 -1
  230. package/dist/types/whatsapp.d.mts +0 -61
  231. package/dist/types/whatsapp.js +0 -2
  232. package/dist/types/whatsapp.js.map +0 -1
  233. package/dist/types/whatsapp.mjs +0 -1
  234. package/dist/types/whatsapp.mjs.map +0 -1
  235. package/dist/utils/buildFieldsQueryString.d.mts +0 -3
  236. package/dist/utils/buildFieldsQueryString.d.ts +0 -3
  237. package/dist/utils/buildFieldsQueryString.js +0 -2
  238. package/dist/utils/buildFieldsQueryString.js.map +0 -1
  239. package/dist/utils/buildFieldsQueryString.mjs +0 -2
  240. package/dist/utils/buildFieldsQueryString.mjs.map +0 -1
  241. package/dist/utils/filters.d.mts +0 -144
  242. package/dist/utils/filters.d.ts +0 -144
  243. package/dist/utils/filters.js +0 -2
  244. package/dist/utils/filters.js.map +0 -1
  245. package/dist/utils/filters.mjs +0 -2
  246. package/dist/utils/filters.mjs.map +0 -1
  247. package/dist/utils/flowTypeGuards.d.mts +0 -46
  248. package/dist/utils/flowTypeGuards.d.ts +0 -46
  249. package/dist/utils/flowTypeGuards.js +0 -2
  250. package/dist/utils/flowTypeGuards.js.map +0 -1
  251. package/dist/utils/flowTypeGuards.mjs +0 -2
  252. package/dist/utils/flowTypeGuards.mjs.map +0 -1
  253. package/dist/utils/generateXHub256Sig.d.mts +0 -3
  254. package/dist/utils/generateXHub256Sig.d.ts +0 -3
  255. package/dist/utils/generateXHub256Sig.js +0 -2
  256. package/dist/utils/generateXHub256Sig.js.map +0 -1
  257. package/dist/utils/generateXHub256Sig.mjs +0 -2
  258. package/dist/utils/generateXHub256Sig.mjs.map +0 -1
  259. package/dist/utils/importConfig.d.mts +0 -21
  260. package/dist/utils/importConfig.d.ts +0 -21
  261. package/dist/utils/importConfig.js +0 -2
  262. package/dist/utils/importConfig.js.map +0 -1
  263. package/dist/utils/importConfig.mjs +0 -2
  264. package/dist/utils/importConfig.mjs.map +0 -1
  265. package/dist/utils/index.d.ts +0 -22
  266. package/dist/utils/index.js +0 -2
  267. package/dist/utils/index.js.map +0 -1
  268. package/dist/utils/isMetaError.d.mts +0 -21
  269. package/dist/utils/isMetaError.d.ts +0 -21
  270. package/dist/utils/isMetaError.js +0 -2
  271. package/dist/utils/isMetaError.js.map +0 -1
  272. package/dist/utils/isMetaError.mjs +0 -2
  273. package/dist/utils/isMetaError.mjs.map +0 -1
  274. package/dist/utils/logger.d.mts +0 -13
  275. package/dist/utils/logger.d.ts +0 -13
  276. package/dist/utils/logger.js +0 -2
  277. package/dist/utils/logger.js.map +0 -1
  278. package/dist/utils/logger.mjs +0 -2
  279. package/dist/utils/logger.mjs.map +0 -1
  280. package/dist/utils/objectToQueryString.d.mts +0 -3
  281. package/dist/utils/objectToQueryString.d.ts +0 -3
  282. package/dist/utils/objectToQueryString.js +0 -2
  283. package/dist/utils/objectToQueryString.js.map +0 -1
  284. package/dist/utils/objectToQueryString.mjs +0 -2
  285. package/dist/utils/objectToQueryString.mjs.map +0 -1
  286. package/dist/webhook.d.mts +0 -123
  287. package/dist/webhook.d.ts +0 -123
  288. package/dist/webhook.js +0 -3
  289. package/dist/webhook.js.map +0 -1
  290. package/dist/webhook.mjs +0 -3
  291. package/dist/webhook.mjs.map +0 -1
  292. package/dist/whatsapp.d.mts +0 -58
  293. package/dist/whatsapp.d.ts +0 -58
  294. package/dist/whatsapp.js +0 -2
  295. package/dist/whatsapp.js.map +0 -1
  296. package/dist/whatsapp.mjs +0 -2
  297. package/dist/whatsapp.mjs.map +0 -1
@@ -1,2 +0,0 @@
1
- var S=class{name;debug;constructor(R,t=!1){this.name=R,this.debug=t}log(...R){if(this.debug){let t=`[ ${Date.now()} ]`;this.name&&(t+=` - ${this.name}`),console.log.apply(console,[t,": ",...R])}}error(...R){let t=`[ ${Date.now()} ] - ERROR`;this.name&&(t+=` - ${this.name}`),console.error.apply(console,[t,": ",...R])}warn(...R){let t=`[ ${Date.now()} ] - WARN`;this.name&&(t+=` - ${this.name}`),console.warn.apply(console,[t,": ",...R])}info(...R){let t=`[ ${Date.now()} ] - INFO`;this.name&&(t+=` - ${this.name}`),console.info.apply(console,[t,": ",...R])}};var U="BaseAPI",G=!1,O=new S(U,process.env.DEBUG==="true"||G),D=class{config;client;constructor(R,t){this.config=R,this.client=t,O.log("Initialized with HTTPSClient")}sendJson(R,t,A,P){return this.client.getJson(R,t,A,P)}sendFormData(R,t,A,P){return this.client.sendFormData(R,t,A,P)}sendUrlEncodedForm(R,t,A,P){return this.client.sendUrlEncodedForm(R,t,A,P)}};var N=class extends D{endpoint="whatsapp_business_encryption";constructor(R,t){super(R,t)}async getEncryptionPublicKey(){return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async setEncryptionPublicKey(R){let t=new FormData;return t.append("business_public_key",R),this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,t)}};export{N as default};
2
- //# sourceMappingURL=encryption.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/logger.ts","../../src/api/base.ts","../../src/api/encryption.ts"],"sourcesContent":["// @ts-nocheck\nimport type { LoggerInterface } from '../types/logger';\n\nexport default class Logger implements LoggerInterface {\n private name: string;\n private debug: boolean;\n\n constructor(name: string, debug: boolean = false) {\n this.name = name;\n this.debug = debug;\n }\n\n log(...data: any[]) {\n if (this.debug) {\n let prefix = `[ ${Date.now()} ]`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.log.apply(console, [prefix, ': ', ...data]);\n }\n }\n\n error(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - ERROR`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.error.apply(console, [prefix, ': ', ...data]);\n }\n\n warn(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - WARN`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.warn.apply(console, [prefix, ': ', ...data]);\n }\n\n info(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - INFO`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.info.apply(console, [prefix, ': ', ...data]);\n }\n}\n","import { HttpMethodsEnum } from '../types/enums';\nimport type { BaseClass } from '../types/base';\nimport type { WabaConfigType } from '../types/config';\nimport type { RequesterClass } from '../types/request';\nimport Logger from '../utils/logger';\n\nconst LIB_NAME = 'BaseAPI';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\n\nexport default class BaseAPI implements BaseClass {\n protected config: WabaConfigType;\n protected client: RequesterClass;\n\n constructor(config: WabaConfigType, client: RequesterClass) {\n this.config = config;\n this.client = client;\n LOGGER.log('Initialized with HTTPSClient');\n }\n\n protected sendJson<T>(method: HttpMethodsEnum, endpoint: string, timeout: number, body?: any): Promise<T> {\n return this.client.getJson<T>(method, endpoint, timeout, body);\n }\n\n protected sendFormData<T>(method: HttpMethodsEnum, endpoint: string, timeout: number, body?: any): Promise<T> {\n return this.client.sendFormData<T>(method, endpoint, timeout, body);\n }\n\n protected sendUrlEncodedForm<T>(\n method: HttpMethodsEnum,\n endpoint: string,\n timeout: number,\n body?: any,\n ): Promise<T> {\n return this.client.sendUrlEncodedForm<T>(method, endpoint, timeout, body);\n }\n}\n","import type { WabaConfigType } from '../types/config';\nimport type { EncryptionClass, EncryptionPublicKeyResponse } from '../types/encryption';\nimport { HttpMethodsEnum, WabaConfigEnum } from '../types/enums';\nimport type { RequesterClass, RequesterResponseInterface, ResponseSuccess } from '../types/request';\nimport BaseAPI from './base';\n\nexport default class EncryptionAPI extends BaseAPI implements EncryptionClass {\n private readonly endpoint = 'whatsapp_business_encryption';\n\n constructor(config: WabaConfigType, client: RequesterClass) {\n super(config, client);\n }\n\n async getEncryptionPublicKey(): Promise<EncryptionPublicKeyResponse> {\n return this.sendJson(\n HttpMethodsEnum.Get,\n `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}`,\n this.config[WabaConfigEnum.RequestTimeout],\n null,\n );\n }\n\n async setEncryptionPublicKey(businessPublicKey: string): Promise<ResponseSuccess> {\n const formData = new FormData();\n formData.append('business_public_key', businessPublicKey);\n\n return this.sendJson(\n HttpMethodsEnum.Post,\n `${this.config[WabaConfigEnum.PhoneNumberId]}/${this.endpoint}`,\n this.config[WabaConfigEnum.RequestTimeout],\n formData,\n );\n }\n}\n"],"mappings":"AAGA,IAAqBA,EAArB,KAAuD,CAC3C,KACA,MAER,YAAYC,EAAcC,EAAiB,GAAO,CAC9C,KAAK,KAAOD,EACZ,KAAK,MAAQC,CACjB,CAEA,OAAOC,EAAa,CAChB,GAAI,KAAK,MAAO,CACZ,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,KACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,IAAI,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACtD,CACJ,CAEA,SAASA,EAAa,CAClB,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,aACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,MAAM,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACxD,CAEA,QAAQA,EAAa,CACjB,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,YACxB,KAAK,OACLA,GAAU,MAAM,KAAK,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AC7D,KAAK,OAAO,gBACZC,CACJ,CACJ,CACJ","names":["Logger","name","debug","data","prefix","LIB_NAME","LOG_LOCAL","LOGGER","Logger","BaseAPI","config","client","method","endpoint","timeout","body","EncryptionAPI","BaseAPI","config","client","businessPublicKey","formData"]}
@@ -1,126 +0,0 @@
1
- import { WabaConfigType } from '../types/config.mjs';
2
- import { FlowClass, FlowsListResponse, FlowCategoryEnum, CreateFlowResponse, Flow, FlowPreviewResponse, FlowAssetsResponse, UpdateFlowResponse, ValidateFlowJsonResponse, FlowMigrationResponse } from '../types/flow.mjs';
3
- import { RequesterClass, ResponseSuccess } from '../types/request.mjs';
4
- import BaseAPI from './base.mjs';
5
- import '../enums-CI7vzKhn.mjs';
6
- import 'http';
7
- import '../types/base.mjs';
8
-
9
- declare class FlowAPI extends BaseAPI implements FlowClass {
10
- constructor(config: WabaConfigType, client: RequesterClass);
11
- /**
12
- * List Flows
13
- *
14
- * @param wabaId - The WABA ID
15
- * @returns Promise with the list of flows
16
- */
17
- listFlows(wabaId: string): Promise<FlowsListResponse>;
18
- /**
19
- * Create Flow
20
- *
21
- * @param wabaId - The WABA ID
22
- * @param data - The flow data including name, categories, endpoint_uri, and optional clone_flow_id
23
- * @returns Promise with the created flow ID and validation errors if any
24
- */
25
- createFlow(wabaId: string, data: {
26
- name: string;
27
- categories?: FlowCategoryEnum[];
28
- endpoint_uri?: string;
29
- clone_flow_id?: string;
30
- flow_json?: string;
31
- publish?: boolean;
32
- }): Promise<CreateFlowResponse>;
33
- /**
34
- * Get Flow details
35
- *
36
- * @param flowId - The flow ID
37
- * @param fields - Optional fields to return (e.g., 'name,status,preview.invalidate(false)')
38
- * @param dateFormat - Optional date format
39
- * @returns Promise with the flow details or preview response
40
- */
41
- getFlow(flowId: string, fields?: string, dateFormat?: string): Promise<Flow | FlowPreviewResponse>;
42
- /**
43
- * Get Flow Preview URL
44
- *
45
- * @param flowId - The flow ID
46
- * @param invalidate - Optional. If true, invalidates existing preview and generates a new one. Defaults to false.
47
- * @returns Promise with the flow preview details
48
- */
49
- getFlowPreview(flowId: string, invalidate?: boolean): Promise<FlowPreviewResponse>;
50
- /**
51
- * Update Flow Metadata
52
- *
53
- * @param flowId - The flow ID
54
- * @param data - The flow metadata to update (name, categories, endpoint_uri, application_id)
55
- * @returns Promise with the success status
56
- */
57
- updateFlowMetadata(flowId: string, data: {
58
- name?: string;
59
- categories?: FlowCategoryEnum[];
60
- endpoint_uri?: string;
61
- application_id?: string;
62
- }): Promise<ResponseSuccess>;
63
- /**
64
- * Delete Flow (only works if the Flow is in DRAFT status)
65
- *
66
- * @param flowId - The flow ID
67
- * @returns Promise with the success status
68
- */
69
- deleteFlow(flowId: string): Promise<ResponseSuccess>;
70
- /**
71
- * List Assets (e.g., get Flow JSON download URL)
72
- *
73
- * @param flowId - The flow ID
74
- * @returns Promise with the list of assets
75
- */
76
- listAssets(flowId: string): Promise<FlowAssetsResponse>;
77
- /**
78
- * Update Flow JSON by uploading a file, buffer, JSON object, or Blob.
79
- *
80
- * @param flowId - The flow ID
81
- * @param data - Object containing the file data and optional name.
82
- * @param data.file - The Flow JSON content as a Buffer, JSON object, or Blob.
83
- * @param data.name - Optional name for the asset, defaults to 'flow.json'.
84
- * @returns Promise with the success status and validation errors, if any.
85
- */
86
- updateFlowJson(flowId: string, data: {
87
- file: Blob | Buffer | object;
88
- name?: string;
89
- }): Promise<UpdateFlowResponse>;
90
- /**
91
- * Validate Flow JSON by attempting an update without publishing.
92
- * This is a convenience method; the API doesn't have a dedicated validation endpoint.
93
- *
94
- * @param flowId - The ID of the Flow (must exist, can be in DRAFT status).
95
- * @param flowJsonData - The Flow JSON content as a file path (string), Buffer, JSON object, or Blob.
96
- * @returns Promise indicating if the JSON is valid and includes validation errors if any.
97
- */
98
- validateFlowJson(flowId: string, flowJsonData: Blob | Buffer | object): Promise<ValidateFlowJsonResponse>;
99
- /**
100
- * Publish Flow
101
- *
102
- * @param flowId - The flow ID
103
- * @returns Promise with the success status
104
- */
105
- publishFlow(flowId: string): Promise<ResponseSuccess>;
106
- /**
107
- * Deprecate Flow
108
- *
109
- * @param flowId - The flow ID
110
- * @returns Promise with the success status
111
- */
112
- deprecateFlow(flowId: string): Promise<ResponseSuccess>;
113
- /**
114
- * Migrate Flows between WABAs
115
- *
116
- * @param destinationWabaId - The destination WABA ID
117
- * @param data - The migration data including source_waba_id and optional source_flow_names
118
- * @returns Promise with migration results (successes and failures)
119
- */
120
- migrateFlows(destinationWabaId: string, data: {
121
- source_waba_id: string;
122
- source_flow_names?: string[];
123
- }): Promise<FlowMigrationResponse>;
124
- }
125
-
126
- export { FlowAPI as default };
@@ -1,126 +0,0 @@
1
- import { WabaConfigType } from '../types/config.js';
2
- import { FlowClass, FlowsListResponse, FlowCategoryEnum, CreateFlowResponse, Flow, FlowPreviewResponse, FlowAssetsResponse, UpdateFlowResponse, ValidateFlowJsonResponse, FlowMigrationResponse } from '../types/flow.js';
3
- import { RequesterClass, ResponseSuccess } from '../types/request.js';
4
- import BaseAPI from './base.js';
5
- import '../enums-CI7vzKhn.js';
6
- import 'http';
7
- import '../types/base.js';
8
-
9
- declare class FlowAPI extends BaseAPI implements FlowClass {
10
- constructor(config: WabaConfigType, client: RequesterClass);
11
- /**
12
- * List Flows
13
- *
14
- * @param wabaId - The WABA ID
15
- * @returns Promise with the list of flows
16
- */
17
- listFlows(wabaId: string): Promise<FlowsListResponse>;
18
- /**
19
- * Create Flow
20
- *
21
- * @param wabaId - The WABA ID
22
- * @param data - The flow data including name, categories, endpoint_uri, and optional clone_flow_id
23
- * @returns Promise with the created flow ID and validation errors if any
24
- */
25
- createFlow(wabaId: string, data: {
26
- name: string;
27
- categories?: FlowCategoryEnum[];
28
- endpoint_uri?: string;
29
- clone_flow_id?: string;
30
- flow_json?: string;
31
- publish?: boolean;
32
- }): Promise<CreateFlowResponse>;
33
- /**
34
- * Get Flow details
35
- *
36
- * @param flowId - The flow ID
37
- * @param fields - Optional fields to return (e.g., 'name,status,preview.invalidate(false)')
38
- * @param dateFormat - Optional date format
39
- * @returns Promise with the flow details or preview response
40
- */
41
- getFlow(flowId: string, fields?: string, dateFormat?: string): Promise<Flow | FlowPreviewResponse>;
42
- /**
43
- * Get Flow Preview URL
44
- *
45
- * @param flowId - The flow ID
46
- * @param invalidate - Optional. If true, invalidates existing preview and generates a new one. Defaults to false.
47
- * @returns Promise with the flow preview details
48
- */
49
- getFlowPreview(flowId: string, invalidate?: boolean): Promise<FlowPreviewResponse>;
50
- /**
51
- * Update Flow Metadata
52
- *
53
- * @param flowId - The flow ID
54
- * @param data - The flow metadata to update (name, categories, endpoint_uri, application_id)
55
- * @returns Promise with the success status
56
- */
57
- updateFlowMetadata(flowId: string, data: {
58
- name?: string;
59
- categories?: FlowCategoryEnum[];
60
- endpoint_uri?: string;
61
- application_id?: string;
62
- }): Promise<ResponseSuccess>;
63
- /**
64
- * Delete Flow (only works if the Flow is in DRAFT status)
65
- *
66
- * @param flowId - The flow ID
67
- * @returns Promise with the success status
68
- */
69
- deleteFlow(flowId: string): Promise<ResponseSuccess>;
70
- /**
71
- * List Assets (e.g., get Flow JSON download URL)
72
- *
73
- * @param flowId - The flow ID
74
- * @returns Promise with the list of assets
75
- */
76
- listAssets(flowId: string): Promise<FlowAssetsResponse>;
77
- /**
78
- * Update Flow JSON by uploading a file, buffer, JSON object, or Blob.
79
- *
80
- * @param flowId - The flow ID
81
- * @param data - Object containing the file data and optional name.
82
- * @param data.file - The Flow JSON content as a Buffer, JSON object, or Blob.
83
- * @param data.name - Optional name for the asset, defaults to 'flow.json'.
84
- * @returns Promise with the success status and validation errors, if any.
85
- */
86
- updateFlowJson(flowId: string, data: {
87
- file: Blob | Buffer | object;
88
- name?: string;
89
- }): Promise<UpdateFlowResponse>;
90
- /**
91
- * Validate Flow JSON by attempting an update without publishing.
92
- * This is a convenience method; the API doesn't have a dedicated validation endpoint.
93
- *
94
- * @param flowId - The ID of the Flow (must exist, can be in DRAFT status).
95
- * @param flowJsonData - The Flow JSON content as a file path (string), Buffer, JSON object, or Blob.
96
- * @returns Promise indicating if the JSON is valid and includes validation errors if any.
97
- */
98
- validateFlowJson(flowId: string, flowJsonData: Blob | Buffer | object): Promise<ValidateFlowJsonResponse>;
99
- /**
100
- * Publish Flow
101
- *
102
- * @param flowId - The flow ID
103
- * @returns Promise with the success status
104
- */
105
- publishFlow(flowId: string): Promise<ResponseSuccess>;
106
- /**
107
- * Deprecate Flow
108
- *
109
- * @param flowId - The flow ID
110
- * @returns Promise with the success status
111
- */
112
- deprecateFlow(flowId: string): Promise<ResponseSuccess>;
113
- /**
114
- * Migrate Flows between WABAs
115
- *
116
- * @param destinationWabaId - The destination WABA ID
117
- * @param data - The migration data including source_waba_id and optional source_flow_names
118
- * @returns Promise with migration results (successes and failures)
119
- */
120
- migrateFlows(destinationWabaId: string, data: {
121
- source_waba_id: string;
122
- source_flow_names?: string[];
123
- }): Promise<FlowMigrationResponse>;
124
- }
125
-
126
- export { FlowAPI as default };
package/dist/api/flow.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";var N=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var U=(A,i)=>{for(var t in i)N(A,t,{get:i[t],enumerable:!0})},F=(A,i,t,R)=>{if(i&&typeof i=="object"||typeof i=="function")for(let l of _(i))!G.call(A,l)&&l!==t&&N(A,l,{get:()=>i[l],enumerable:!(R=O(i,l))||R.enumerable});return A};var f=A=>F(N({},"__esModule",{value:!0}),A);var M={};U(M,{default:()=>D});module.exports=f(M);var P=class{name;debug;constructor(i,t=!1){this.name=i,this.debug=t}log(...i){if(this.debug){let t=`[ ${Date.now()} ]`;this.name&&(t+=` - ${this.name}`),console.log.apply(console,[t,": ",...i])}}error(...i){let t=`[ ${Date.now()} ] - ERROR`;this.name&&(t+=` - ${this.name}`),console.error.apply(console,[t,": ",...i])}warn(...i){let t=`[ ${Date.now()} ] - WARN`;this.name&&(t+=` - ${this.name}`),console.warn.apply(console,[t,": ",...i])}info(...i){let t=`[ ${Date.now()} ] - INFO`;this.name&&(t+=` - ${this.name}`),console.info.apply(console,[t,": ",...i])}};var w="BaseAPI",T=!1,I=new P(w,process.env.DEBUG==="true"||T),S=class{config;client;constructor(i,t){this.config=i,this.client=t,I.log("Initialized with HTTPSClient")}sendJson(i,t,R,l){return this.client.getJson(i,t,R,l)}sendFormData(i,t,R,l){return this.client.sendFormData(i,t,R,l)}sendUrlEncodedForm(i,t,R,l){return this.client.sendUrlEncodedForm(i,t,R,l)}};var K="FlowAPI",h=!1,B=new P(K,process.env.DEBUG==="true"||h),D=class extends S{constructor(i,t){super(i,t),B.log("FlowAPI initialized")}async listFlows(i){return this.sendJson("GET",`/${i}/flows`,this.config.REQUEST_TIMEOUT,null)}async createFlow(i,t){let R={name:t.name,categories:t.categories,...t.endpoint_uri&&{endpoint_uri:t.endpoint_uri},...t.clone_flow_id&&{clone_flow_id:t.clone_flow_id},...t.flow_json&&{flow_json:t.flow_json},...t.publish!==void 0&&{publish:t.publish}};return this.sendJson("POST",`/${i}/flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(R))}async getFlow(i,t,R){let l=new URLSearchParams;t&&l.append("fields",t),R&&l.append("date_format",R);let p=l.toString()?`?${l.toString()}`:"";return this.sendJson("GET",`/${i}${p}`,this.config.REQUEST_TIMEOUT,null)}async getFlowPreview(i,t=!1){let R=`preview.invalidate(${t})`;return this.getFlow(i,R)}async updateFlowMetadata(i,t){let R={...t.name&&{name:t.name},...t.categories&&{categories:t.categories},...t.endpoint_uri&&{endpoint_uri:t.endpoint_uri},...t.application_id&&{application_id:t.application_id}};return this.sendJson("POST",`/${i}`,this.config.REQUEST_TIMEOUT,JSON.stringify(R))}async deleteFlow(i){return this.sendJson("DELETE",`/${i}`,this.config.REQUEST_TIMEOUT,null)}async listAssets(i){return this.sendJson("GET",`/${i}/assets`,this.config.REQUEST_TIMEOUT,null)}async updateFlowJson(i,t){let R=new FormData,l;if(t.file instanceof Buffer)l=new globalThis.Blob([t.file]),R.append("file",l);else if(typeof t.file=="object"&&!(t.file instanceof Blob))try{l=new globalThis.Blob([JSON.stringify(t.file,null,2)],{type:"application/json"}),R.append("file",l)}catch{throw new Error("Failed to stringify JSON object for Flow JSON update.")}else if(t.file instanceof Blob)l=t.file,R.append("file",l);else throw new Error("Invalid file type provided for Flow JSON update. Must be a Buffer, JSON object, or Blob.");return R.append("asset_type","FLOW_JSON"),R.append("name",t.name||"flow.json"),this.sendFormData("POST",`/${i}/assets`,this.config.REQUEST_TIMEOUT,R)}async validateFlowJson(i,t){try{let R=await this.updateFlowJson(i,{file:t}),l=!R.validation_errors||R.validation_errors.length===0;return{...R,valid:l}}catch(R){throw B.error("Error during Flow JSON validation attempt:",R),R}}async publishFlow(i){return this.sendJson("POST",`/${i}/publish`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async deprecateFlow(i){return this.sendJson("POST",`/${i}/deprecate`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async migrateFlows(i,t){let R={source_waba_id:t.source_waba_id,...t.source_flow_names&&{source_flow_names:t.source_flow_names}};return this.sendJson("POST",`/${i}/migrate_flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(R))}};
2
- //# sourceMappingURL=flow.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/api/flow.ts","../../src/utils/logger.ts","../../src/api/base.ts"],"sourcesContent":["import { WabaConfigType } from '../types/config';\nimport { HttpMethodsEnum, WabaConfigEnum } from '../types/enums';\nimport {\n CreateFlowResponse,\n Flow,\n FlowAssetsResponse,\n FlowCategoryEnum,\n FlowClass,\n FlowMigrationResponse,\n FlowPreviewResponse,\n FlowsListResponse,\n UpdateFlowResponse,\n ValidateFlowJsonResponse,\n} from '../types/flow';\nimport { RequesterClass, ResponseSuccess } from '../types/request';\nimport Logger from '../utils/logger';\nimport BaseAPI from './base';\n\nconst LIB_NAME = 'FlowAPI';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\n\nexport default class FlowAPI extends BaseAPI implements FlowClass {\n constructor(config: WabaConfigType, client: RequesterClass) {\n super(config, client);\n LOGGER.log('FlowAPI initialized');\n }\n\n /**\n * List Flows\n *\n * @param wabaId - The WABA ID\n * @returns Promise with the list of flows\n */\n async listFlows(wabaId: string): Promise<FlowsListResponse> {\n return this.sendJson(HttpMethodsEnum.Get, `/${wabaId}/flows`, this.config[WabaConfigEnum.RequestTimeout], null);\n }\n\n /**\n * Create Flow\n *\n * @param wabaId - The WABA ID\n * @param data - The flow data including name, categories, endpoint_uri, and optional clone_flow_id\n * @returns Promise with the created flow ID and validation errors if any\n */\n async createFlow(\n wabaId: string,\n data: {\n name: string;\n categories?: FlowCategoryEnum[];\n endpoint_uri?: string;\n clone_flow_id?: string;\n flow_json?: string; // Flow JSON as a string\n publish?: boolean;\n },\n ): Promise<CreateFlowResponse> {\n // The API expects application/json for this endpoint based on documentation examples\n // Let's ensure we send JSON, not FormData, unless specifically required by an endpoint variation.\n const payload = {\n name: data.name,\n categories: data.categories,\n ...(data.endpoint_uri && { endpoint_uri: data.endpoint_uri }),\n ...(data.clone_flow_id && { clone_flow_id: data.clone_flow_id }),\n ...(data.flow_json && { flow_json: data.flow_json }),\n ...(data.publish !== undefined && { publish: data.publish }),\n };\n\n return this.sendJson(\n HttpMethodsEnum.Post,\n `/${wabaId}/flows`,\n this.config[WabaConfigEnum.RequestTimeout],\n JSON.stringify(payload), // Send as JSON\n );\n }\n\n /**\n * Get Flow details\n *\n * @param flowId - The flow ID\n * @param fields - Optional fields to return (e.g., 'name,status,preview.invalidate(false)')\n * @param dateFormat - Optional date format\n * @returns Promise with the flow details or preview response\n */\n async getFlow(flowId: string, fields?: string, dateFormat?: string): Promise<Flow | FlowPreviewResponse> {\n const params = new URLSearchParams();\n if (fields) params.append('fields', fields);\n if (dateFormat) params.append('date_format', dateFormat);\n\n const queryString = params.toString() ? `?${params.toString()}` : '';\n return this.sendJson(\n HttpMethodsEnum.Get,\n `/${flowId}${queryString}`,\n this.config[WabaConfigEnum.RequestTimeout],\n null,\n );\n }\n\n /**\n * Get Flow Preview URL\n *\n * @param flowId - The flow ID\n * @param invalidate - Optional. If true, invalidates existing preview and generates a new one. Defaults to false.\n * @returns Promise with the flow preview details\n */\n async getFlowPreview(flowId: string, invalidate: boolean = false): Promise<FlowPreviewResponse> {\n const fields = `preview.invalidate(${invalidate})`;\n // Type assertion needed as getFlow can return Flow or FlowPreviewResponse\n return this.getFlow(flowId, fields) as Promise<FlowPreviewResponse>;\n }\n\n /**\n * Update Flow Metadata\n *\n * @param flowId - The flow ID\n * @param data - The flow metadata to update (name, categories, endpoint_uri, application_id)\n * @returns Promise with the success status\n */\n async updateFlowMetadata(\n flowId: string,\n data: {\n name?: string;\n categories?: FlowCategoryEnum[];\n endpoint_uri?: string;\n application_id?: string;\n },\n ): Promise<ResponseSuccess> {\n // The API expects application/json for this endpoint based on documentation examples\n const payload = {\n ...(data.name && { name: data.name }),\n ...(data.categories && { categories: data.categories }),\n ...(data.endpoint_uri && { endpoint_uri: data.endpoint_uri }),\n ...(data.application_id && { application_id: data.application_id }),\n };\n\n return this.sendJson(\n HttpMethodsEnum.Post,\n `/${flowId}`,\n this.config[WabaConfigEnum.RequestTimeout],\n JSON.stringify(payload), // Send as JSON\n );\n }\n\n /**\n * Delete Flow (only works if the Flow is in DRAFT status)\n *\n * @param flowId - The flow ID\n * @returns Promise with the success status\n */\n async deleteFlow(flowId: string): Promise<ResponseSuccess> {\n return this.sendJson(HttpMethodsEnum.Delete, `/${flowId}`, this.config[WabaConfigEnum.RequestTimeout], null);\n }\n\n /**\n * List Assets (e.g., get Flow JSON download URL)\n *\n * @param flowId - The flow ID\n * @returns Promise with the list of assets\n */\n async listAssets(flowId: string): Promise<FlowAssetsResponse> {\n return this.sendJson(\n HttpMethodsEnum.Get,\n `/${flowId}/assets`,\n this.config[WabaConfigEnum.RequestTimeout],\n null,\n );\n }\n\n /**\n * Update Flow JSON by uploading a file, buffer, JSON object, or Blob.\n *\n * @param flowId - The flow ID\n * @param data - Object containing the file data and optional name.\n * @param data.file - The Flow JSON content as a Buffer, JSON object, or Blob.\n * @param data.name - Optional name for the asset, defaults to 'flow.json'.\n * @returns Promise with the success status and validation errors, if any.\n */\n async updateFlowJson(\n flowId: string,\n data: {\n file: Blob | Buffer | object; // JSON object, Buffer, or Blob\n name?: string; // Default to \"flow.json\"\n },\n ): Promise<UpdateFlowResponse> {\n const formData = new FormData();\n let fileContent: Blob;\n\n // Handle different input types for the file\n if (data.file instanceof Buffer) {\n // Buffer\n // Create a Blob from the Buffer and cast it to the global Blob type\n fileContent = new globalThis.Blob([data.file]);\n formData.append('file', fileContent as unknown as Blob);\n } else if (typeof data.file === 'object' && !(data.file instanceof Blob)) {\n // JSON object - stringify and create Blob\n try {\n // Create a Blob from the JSON string and cast it to the global Blob type\n fileContent = new globalThis.Blob([JSON.stringify(data.file, null, 2)], { type: 'application/json' });\n formData.append('file', fileContent as unknown as Blob);\n } catch (e) {\n throw new Error('Failed to stringify JSON object for Flow JSON update.');\n }\n } else if (data.file instanceof Blob) {\n // Blob (already in correct format)\n fileContent = data.file;\n formData.append('file', fileContent as unknown as Blob);\n } else {\n throw new Error('Invalid file type provided for Flow JSON update. Must be a Buffer, JSON object, or Blob.');\n }\n\n formData.append('asset_type', 'FLOW_JSON'); // Required by API\n formData.append('name', data.name || 'flow.json'); // Required by API\n\n return this.sendFormData(\n HttpMethodsEnum.Post,\n `/${flowId}/assets`,\n this.config[WabaConfigEnum.RequestTimeout],\n formData,\n );\n }\n\n /**\n * Validate Flow JSON by attempting an update without publishing.\n * This is a convenience method; the API doesn't have a dedicated validation endpoint.\n *\n * @param flowId - The ID of the Flow (must exist, can be in DRAFT status).\n * @param flowJsonData - The Flow JSON content as a file path (string), Buffer, JSON object, or Blob.\n * @returns Promise indicating if the JSON is valid and includes validation errors if any.\n */\n async validateFlowJson(flowId: string, flowJsonData: Blob | Buffer | object): Promise<ValidateFlowJsonResponse> {\n try {\n const result = await this.updateFlowJson(flowId, {\n file: flowJsonData,\n });\n\n const isValid = !result.validation_errors || result.validation_errors.length === 0;\n\n const enhancedResponse = {\n ...result,\n valid: isValid,\n };\n\n return enhancedResponse;\n } catch (error) {\n LOGGER.error('Error during Flow JSON validation attempt:', error);\n throw error;\n }\n }\n\n /**\n * Publish Flow\n *\n * @param flowId - The flow ID\n * @returns Promise with the success status\n */\n async publishFlow(flowId: string): Promise<ResponseSuccess> {\n // This endpoint expects an empty JSON body or no body\n return this.sendJson(\n HttpMethodsEnum.Post,\n `/${flowId}/publish`,\n this.config[WabaConfigEnum.RequestTimeout],\n JSON.stringify({}), // Send empty JSON object\n );\n }\n\n /**\n * Deprecate Flow\n *\n * @param flowId - The flow ID\n * @returns Promise with the success status\n */\n async deprecateFlow(flowId: string): Promise<ResponseSuccess> {\n // This endpoint expects an empty JSON body or no body\n return this.sendJson(\n HttpMethodsEnum.Post,\n `/${flowId}/deprecate`,\n this.config[WabaConfigEnum.RequestTimeout],\n JSON.stringify({}), // Send empty JSON object\n );\n }\n\n /**\n * Migrate Flows between WABAs\n *\n * @param destinationWabaId - The destination WABA ID\n * @param data - The migration data including source_waba_id and optional source_flow_names\n * @returns Promise with migration results (successes and failures)\n */\n async migrateFlows(\n destinationWabaId: string,\n data: {\n source_waba_id: string;\n source_flow_names?: string[];\n },\n ): Promise<FlowMigrationResponse> {\n // API documentation suggests this endpoint might expect application/json\n // Let's double-check or assume JSON based on typical Graph API patterns unless FormData is confirmed.\n // Assuming JSON for now:\n const payload = {\n source_waba_id: data.source_waba_id,\n ...(data.source_flow_names && { source_flow_names: data.source_flow_names }),\n };\n\n return this.sendJson(\n HttpMethodsEnum.Post,\n `/${destinationWabaId}/migrate_flows`,\n this.config[WabaConfigEnum.RequestTimeout],\n JSON.stringify(payload),\n );\n }\n}\n","// @ts-nocheck\nimport type { LoggerInterface } from '../types/logger';\n\nexport default class Logger implements LoggerInterface {\n private name: string;\n private debug: boolean;\n\n constructor(name: string, debug: boolean = false) {\n this.name = name;\n this.debug = debug;\n }\n\n log(...data: any[]) {\n if (this.debug) {\n let prefix = `[ ${Date.now()} ]`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.log.apply(console, [prefix, ': ', ...data]);\n }\n }\n\n error(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - ERROR`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.error.apply(console, [prefix, ': ', ...data]);\n }\n\n warn(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - WARN`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.warn.apply(console, [prefix, ': ', ...data]);\n }\n\n info(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - INFO`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.info.apply(console, [prefix, ': ', ...data]);\n }\n}\n","import { HttpMethodsEnum } from '../types/enums';\nimport type { BaseClass } from '../types/base';\nimport type { WabaConfigType } from '../types/config';\nimport type { RequesterClass } from '../types/request';\nimport Logger from '../utils/logger';\n\nconst LIB_NAME = 'BaseAPI';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\n\nexport default class BaseAPI implements BaseClass {\n protected config: WabaConfigType;\n protected client: RequesterClass;\n\n constructor(config: WabaConfigType, client: RequesterClass) {\n this.config = config;\n this.client = client;\n LOGGER.log('Initialized with HTTPSClient');\n }\n\n protected sendJson<T>(method: HttpMethodsEnum, endpoint: string, timeout: number, body?: any): Promise<T> {\n return this.client.getJson<T>(method, endpoint, timeout, body);\n }\n\n protected sendFormData<T>(method: HttpMethodsEnum, endpoint: string, timeout: number, body?: any): Promise<T> {\n return this.client.sendFormData<T>(method, endpoint, timeout, body);\n }\n\n protected sendUrlEncodedForm<T>(\n method: HttpMethodsEnum,\n endpoint: string,\n timeout: number,\n body?: any,\n ): Promise<T> {\n return this.client.sendUrlEncodedForm<T>(method, endpoint, timeout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E,SACOT,EAAK,gBAAgB,KAE5BS,EAAcT,EAAK,KACnBQ,EAAS,OAAO,OAAQC,CAA8B,MAEtD,OAAM,IAAI,MAAM,0FAA0F,EAG9G,OAAAD,EAAS,OAAO,aAAc,WAAW,EACzCA,EAAS,OAAO,OAAQR,EAAK,MAAQ,WAAW,EAEzC,KAAK,oBAER,IAAIE,CAAM,UACV,KAAK,OAAO,gBACZM,CACJ,CACJ,CAUA,MAAM,iBAAiBN,EAAgBQ,EAAyE,CAC5G,GAAI,CACA,IAAMC,EAAS,MAAM,KAAK,eAAeT,EAAQ,CAC7C,KAAMQ,CACV,CAAC,EAEKE,EAAU,CAACD,EAAO,mBAAqBA,EAAO,kBAAkB,SAAW,EAOjF,MALyB,CACrB,GAAGA,EACH,MAAOC,CACX,CAGJ,OAASC,EAAO,CACZ,MAAApB,EAAO,MAAM,6CAA8CoB,CAAK,EAC1DA,CACV,CACJ,CAQA,MAAM,YAAYX,EAA0C,CAExD,OAAO,KAAK,gBAER,IAAIA,CAAM,WACV,KAAK,OAAO,gBACZ,KAAK,UAAU,CAAC,CAAC,CACrB,CACJ,CAQA,MAAM,cAAcA,EAA0C,CAE1D,OAAO,KAAK,gBAER,IAAIA,CAAM,aACV,KAAK,OAAO,gBACZ,KAAK,UAAU,CAAC,CAAC,CACrB,CACJ,CASA,MAAM,aACFY,EACAd,EAI8B,CAI9B,IAAMC,EAAU,CACZ,eAAgBD,EAAK,eACrB,GAAIA,EAAK,mBAAqB,CAAE,kBAAmBA,EAAK,iBAAkB,CAC9E,EAEA,OAAO,KAAK,gBAER,IAAIc,CAAiB,iBACrB,KAAK,OAAO,gBACZ,KAAK,UAAUb,CAAO,CAC1B,CACJ,CACJ","names":["flow_exports","__export","FlowAPI","__toCommonJS","Logger","name","debug","data","prefix","LIB_NAME","LOG_LOCAL","LOGGER","Logger","BaseAPI","config","client","method","endpoint","timeout","body","LIB_NAME","LOG_LOCAL","LOGGER","Logger","FlowAPI","BaseAPI","config","client","wabaId","data","payload","flowId","fields","dateFormat","params","queryString","invalidate","formData","fileContent","flowJsonData","result","isValid","error","destinationWabaId"]}
package/dist/api/flow.mjs DELETED
@@ -1,2 +0,0 @@
1
- var A=class{name;debug;constructor(i,t=!1){this.name=i,this.debug=t}log(...i){if(this.debug){let t=`[ ${Date.now()} ]`;this.name&&(t+=` - ${this.name}`),console.log.apply(console,[t,": ",...i])}}error(...i){let t=`[ ${Date.now()} ] - ERROR`;this.name&&(t+=` - ${this.name}`),console.error.apply(console,[t,": ",...i])}warn(...i){let t=`[ ${Date.now()} ] - WARN`;this.name&&(t+=` - ${this.name}`),console.warn.apply(console,[t,": ",...i])}info(...i){let t=`[ ${Date.now()} ] - INFO`;this.name&&(t+=` - ${this.name}`),console.info.apply(console,[t,": ",...i])}};var B="BaseAPI",O=!1,_=new A(B,process.env.DEBUG==="true"||O),P=class{config;client;constructor(i,t){this.config=i,this.client=t,_.log("Initialized with HTTPSClient")}sendJson(i,t,R,l){return this.client.getJson(i,t,R,l)}sendFormData(i,t,R,l){return this.client.sendFormData(i,t,R,l)}sendUrlEncodedForm(i,t,R,l){return this.client.sendUrlEncodedForm(i,t,R,l)}};var G="FlowAPI",U=!1,N=new A(G,process.env.DEBUG==="true"||U),D=class extends P{constructor(i,t){super(i,t),N.log("FlowAPI initialized")}async listFlows(i){return this.sendJson("GET",`/${i}/flows`,this.config.REQUEST_TIMEOUT,null)}async createFlow(i,t){let R={name:t.name,categories:t.categories,...t.endpoint_uri&&{endpoint_uri:t.endpoint_uri},...t.clone_flow_id&&{clone_flow_id:t.clone_flow_id},...t.flow_json&&{flow_json:t.flow_json},...t.publish!==void 0&&{publish:t.publish}};return this.sendJson("POST",`/${i}/flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(R))}async getFlow(i,t,R){let l=new URLSearchParams;t&&l.append("fields",t),R&&l.append("date_format",R);let S=l.toString()?`?${l.toString()}`:"";return this.sendJson("GET",`/${i}${S}`,this.config.REQUEST_TIMEOUT,null)}async getFlowPreview(i,t=!1){let R=`preview.invalidate(${t})`;return this.getFlow(i,R)}async updateFlowMetadata(i,t){let R={...t.name&&{name:t.name},...t.categories&&{categories:t.categories},...t.endpoint_uri&&{endpoint_uri:t.endpoint_uri},...t.application_id&&{application_id:t.application_id}};return this.sendJson("POST",`/${i}`,this.config.REQUEST_TIMEOUT,JSON.stringify(R))}async deleteFlow(i){return this.sendJson("DELETE",`/${i}`,this.config.REQUEST_TIMEOUT,null)}async listAssets(i){return this.sendJson("GET",`/${i}/assets`,this.config.REQUEST_TIMEOUT,null)}async updateFlowJson(i,t){let R=new FormData,l;if(t.file instanceof Buffer)l=new globalThis.Blob([t.file]),R.append("file",l);else if(typeof t.file=="object"&&!(t.file instanceof Blob))try{l=new globalThis.Blob([JSON.stringify(t.file,null,2)],{type:"application/json"}),R.append("file",l)}catch{throw new Error("Failed to stringify JSON object for Flow JSON update.")}else if(t.file instanceof Blob)l=t.file,R.append("file",l);else throw new Error("Invalid file type provided for Flow JSON update. Must be a Buffer, JSON object, or Blob.");return R.append("asset_type","FLOW_JSON"),R.append("name",t.name||"flow.json"),this.sendFormData("POST",`/${i}/assets`,this.config.REQUEST_TIMEOUT,R)}async validateFlowJson(i,t){try{let R=await this.updateFlowJson(i,{file:t}),l=!R.validation_errors||R.validation_errors.length===0;return{...R,valid:l}}catch(R){throw N.error("Error during Flow JSON validation attempt:",R),R}}async publishFlow(i){return this.sendJson("POST",`/${i}/publish`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async deprecateFlow(i){return this.sendJson("POST",`/${i}/deprecate`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async migrateFlows(i,t){let R={source_waba_id:t.source_waba_id,...t.source_flow_names&&{source_flow_names:t.source_flow_names}};return this.sendJson("POST",`/${i}/migrate_flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(R))}};export{D as default};
2
- //# sourceMappingURL=flow.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/logger.ts","../../src/api/base.ts","../../src/api/flow.ts"],"sourcesContent":["// @ts-nocheck\nimport type { LoggerInterface } from '../types/logger';\n\nexport default class Logger implements LoggerInterface {\n private name: string;\n private debug: boolean;\n\n constructor(name: string, debug: boolean = false) {\n this.name = name;\n this.debug = debug;\n }\n\n log(...data: any[]) {\n if (this.debug) {\n let prefix = `[ ${Date.now()} ]`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.log.apply(console, [prefix, ': ', ...data]);\n }\n }\n\n error(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - ERROR`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.error.apply(console, [prefix, ': ', ...data]);\n }\n\n warn(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - WARN`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.warn.apply(console, [prefix, ': ', ...data]);\n }\n\n info(...data: any[]) {\n let prefix = `[ ${Date.now()} ] - INFO`;\n if (this.name) {\n prefix += ` - ${this.name}`;\n }\n console.info.apply(console, [prefix, ': ', ...data]);\n }\n}\n","import { HttpMethodsEnum } from '../types/enums';\nimport type { BaseClass } from '../types/base';\nimport type { WabaConfigType } from '../types/config';\nimport type { RequesterClass } from '../types/request';\nimport Logger from '../utils/logger';\n\nconst LIB_NAME = 'BaseAPI';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\n\nexport default class BaseAPI implements BaseClass {\n protected config: WabaConfigType;\n protected client: RequesterClass;\n\n constructor(config: WabaConfigType, client: RequesterClass) {\n this.config = config;\n this.client = client;\n LOGGER.log('Initialized with HTTPSClient');\n }\n\n protected sendJson<T>(method: HttpMethodsEnum, endpoint: string, timeout: number, body?: any): Promise<T> {\n return this.client.getJson<T>(method, endpoint, timeout, body);\n }\n\n protected sendFormData<T>(method: HttpMethodsEnum, endpoint: string, timeout: number, body?: any): Promise<T> {\n return this.client.sendFormData<T>(method, endpoint, timeout, body);\n }\n\n protected sendUrlEncodedForm<T>(\n method: HttpMethodsEnum,\n endpoint: string,\n timeout: number,\n body?: any,\n ): Promise<T> {\n return this.client.sendUrlEncodedForm<T>(method, endpoint, timeout, body);\n }\n}\n","import { WabaConfigType } from '../types/config';\nimport { HttpMethodsEnum, WabaConfigEnum } from '../types/enums';\nimport {\n CreateFlowResponse,\n Flow,\n FlowAssetsResponse,\n FlowCategoryEnum,\n FlowClass,\n FlowMigrationResponse,\n FlowPreviewResponse,\n FlowsListResponse,\n UpdateFlowResponse,\n ValidateFlowJsonResponse,\n} from '../types/flow';\nimport { RequesterClass, ResponseSuccess } from '../types/request';\nimport Logger from '../utils/logger';\nimport BaseAPI from './base';\n\nconst LIB_NAME = 'FlowAPI';\nconst LOG_LOCAL = false;\nconst LOGGER = new Logger(LIB_NAME, process.env.DEBUG === 'true' || LOG_LOCAL);\n\nexport default class FlowAPI extends BaseAPI implements FlowClass {\n constructor(config: WabaConfigType, client: RequesterClass) {\n super(config, client);\n LOGGER.log('FlowAPI initialized');\n }\n\n /**\n * List Flows\n *\n * @param wabaId - The WABA ID\n * @returns Promise with the list of flows\n */\n async listFlows(wabaId: string): Promise<FlowsListResponse> {\n return this.sendJson(HttpMethodsEnum.Get, `/${wabaId}/flows`, this.config[WabaConfigEnum.RequestTimeout], null);\n }\n\n /**\n * Create Flow\n *\n * @param wabaId - The WABA ID\n * @param data - The flow data including name, categories, endpoint_uri, and optional clone_flow_id\n * @returns Promise with the created flow ID and validation errors if any\n */\n async createFlow(\n wabaId: string,\n data: {\n name: string;\n categories?: FlowCategoryEnum[];\n endpoint_uri?: string;\n clone_flow_id?: string;\n flow_json?: string; // Flow JSON as a string\n publish?: boolean;\n },\n ): Promise<CreateFlowResponse> {\n // The API expects application/json for this endpoint based on documentation examples\n // Let's ensure we send JSON, not FormData, unless specifically required by an endpoint variation.\n const payload = {\n name: data.name,\n categories: data.categories,\n ...(data.endpoint_uri && { endpoint_uri: data.endpoint_uri }),\n ...(data.clone_flow_id && { clone_flow_id: data.clone_flow_id }),\n ...(data.flow_json && { flow_json: data.flow_json }),\n ...(data.publish !== undefined && { publish: data.publish }),\n };\n\n return this.sendJson(\n HttpMethodsEnum.Post,\n `/${wabaId}/flows`,\n this.config[WabaConfigEnum.RequestTimeout],\n JSON.stringify(payload), // Send as JSON\n );\n }\n\n /**\n * Get Flow details\n *\n * @param flowId - The flow ID\n * @param fields - Optional fields to return (e.g., 'name,status,preview.invalidate(false)')\n * @param dateFormat - Optional date format\n * @returns Promise with the flow details or preview response\n */\n async getFlow(flowId: string, fields?: string, dateFormat?: string): Promise<Flow | FlowPreviewResponse> {\n const params = new URLSearchParams();\n if (fields) params.append('fields', fields);\n if (dateFormat) params.append('date_format', dateFormat);\n\n const queryString = params.toString() ? `?${params.toString()}` : '';\n return this.sendJson(\n HttpMethodsEnum.Get,\n `/${flowId}${queryString}`,\n this.config[WabaConfigEnum.RequestTimeout],\n null,\n );\n }\n\n /**\n * Get Flow Preview URL\n *\n * @param flowId - The flow ID\n * @param invalidate - Optional. If true, invalidates existing preview and generates a new one. Defaults to false.\n * @returns Promise with the flow preview details\n */\n async getFlowPreview(flowId: string, invalidate: boolean = false): Promise<FlowPreviewResponse> {\n const fields = `preview.invalidate(${invalidate})`;\n // Type assertion needed as getFlow can return Flow or FlowPreviewResponse\n return this.getFlow(flowId, fields) as Promise<FlowPreviewResponse>;\n }\n\n /**\n * Update Flow Metadata\n *\n * @param flowId - The flow ID\n * @param data - The flow metadata to update (name, categories, endpoint_uri, application_id)\n * @returns Promise with the success status\n */\n async updateFlowMetadata(\n flowId: string,\n data: {\n name?: string;\n categories?: FlowCategoryEnum[];\n endpoint_uri?: string;\n application_id?: string;\n },\n ): Promise<ResponseSuccess> {\n // The API expects application/json for this endpoint based on documentation examples\n const payload = {\n ...(data.name && { name: data.name }),\n ...(data.categories && { categories: data.categories }),\n ...(data.endpoint_uri && { endpoint_uri: data.endpoint_uri }),\n ...(data.application_id && { application_id: data.application_id }),\n };\n\n return this.sendJson(\n HttpMethodsEnum.Post,\n `/${flowId}`,\n this.config[WabaConfigEnum.RequestTimeout],\n JSON.stringify(payload), // Send as JSON\n );\n }\n\n /**\n * Delete Flow (only works if the Flow is in DRAFT status)\n *\n * @param flowId - The flow ID\n * @returns Promise with the success status\n */\n async deleteFlow(flowId: string): Promise<ResponseSuccess> {\n return this.sendJson(HttpMethodsEnum.Delete, `/${flowId}`, this.config[WabaConfigEnum.RequestTimeout], null);\n }\n\n /**\n * List Assets (e.g., get Flow JSON download URL)\n *\n * @param flowId - The flow ID\n * @returns Promise with the list of assets\n */\n async listAssets(flowId: string): Promise<FlowAssetsResponse> {\n return this.sendJson(\n HttpMethodsEnum.Get,\n `/${flowId}/assets`,\n this.config[WabaConfigEnum.RequestTimeout],\n null,\n );\n }\n\n /**\n * Update Flow JSON by uploading a file, buffer, JSON object, or Blob.\n *\n * @param flowId - The flow ID\n * @param data - Object containing the file data and optional name.\n * @param data.file - The Flow JSON content as a Buffer, JSON object, or Blob.\n * @param data.name - Optional name for the asset, defaults to 'flow.json'.\n * @returns Promise with the success status and validation errors, if any.\n */\n async updateFlowJson(\n flowId: string,\n data: {\n file: Blob | Buffer | object; // JSON object, Buffer, or Blob\n name?: string; // Default to \"flow.json\"\n },\n ): Promise<UpdateFlowResponse> {\n const formData = new FormData();\n let fileContent: Blob;\n\n // Handle different input types for the file\n if (data.file instanceof Buffer) {\n // Buffer\n // Create a Blob from the Buffer and cast it to the global Blob type\n fileContent = new globalThis.Blob([data.file]);\n formData.append('file', fileContent as unknown as Blob);\n } else if (typeof data.file === 'object' && !(data.file instanceof Blob)) {\n // JSON object - stringify and create Blob\n try {\n // Create a Blob from the JSON string and cast it to the global Blob type\n fileContent = new globalThis.Blob([JSON.stringify(data.file, null, 2)], { type: 'application/json' });\n formData.append('file', fileContent as unknown as Blob);\n } catch (e) {\n throw new Error('Failed to stringify JSON object for Flow JSON update.');\n }\n } else if (data.file instanceof Blob) {\n // Blob (already in correct format)\n fileContent = data.file;\n formData.append('file', fileContent as unknown as Blob);\n } else {\n throw new Error('Invalid file type provided for Flow JSON update. Must be a Buffer, JSON object, or Blob.');\n }\n\n formData.append('asset_type', 'FLOW_JSON'); // Required by API\n formData.append('name', data.name || 'flow.json'); // Required by API\n\n return this.sendFormData(\n HttpMethodsEnum.Post,\n `/${flowId}/assets`,\n this.config[WabaConfigEnum.RequestTimeout],\n formData,\n );\n }\n\n /**\n * Validate Flow JSON by attempting an update without publishing.\n * This is a convenience method; the API doesn't have a dedicated validation endpoint.\n *\n * @param flowId - The ID of the Flow (must exist, can be in DRAFT status).\n * @param flowJsonData - The Flow JSON content as a file path (string), Buffer, JSON object, or Blob.\n * @returns Promise indicating if the JSON is valid and includes validation errors if any.\n */\n async validateFlowJson(flowId: string, flowJsonData: Blob | Buffer | object): Promise<ValidateFlowJsonResponse> {\n try {\n const result = await this.updateFlowJson(flowId, {\n file: flowJsonData,\n });\n\n const isValid = !result.validation_errors || result.validation_errors.length === 0;\n\n const enhancedResponse = {\n ...result,\n valid: isValid,\n };\n\n return enhancedResponse;\n } catch (error) {\n LOGGER.error('Error during Flow JSON validation attempt:', error);\n throw error;\n }\n }\n\n /**\n * Publish Flow\n *\n * @param flowId - The flow ID\n * @returns Promise with the success status\n */\n async publishFlow(flowId: string): Promise<ResponseSuccess> {\n // This endpoint expects an empty JSON body or no body\n return this.sendJson(\n HttpMethodsEnum.Post,\n `/${flowId}/publish`,\n this.config[WabaConfigEnum.RequestTimeout],\n JSON.stringify({}), // Send empty JSON object\n );\n }\n\n /**\n * Deprecate Flow\n *\n * @param flowId - The flow ID\n * @returns Promise with the success status\n */\n async deprecateFlow(flowId: string): Promise<ResponseSuccess> {\n // This endpoint expects an empty JSON body or no body\n return this.sendJson(\n HttpMethodsEnum.Post,\n `/${flowId}/deprecate`,\n this.config[WabaConfigEnum.RequestTimeout],\n JSON.stringify({}), // Send empty JSON object\n );\n }\n\n /**\n * Migrate Flows between WABAs\n *\n * @param destinationWabaId - The destination WABA ID\n * @param data - The migration data including source_waba_id and optional source_flow_names\n * @returns Promise with migration results (successes and failures)\n */\n async migrateFlows(\n destinationWabaId: string,\n data: {\n source_waba_id: string;\n source_flow_names?: string[];\n },\n ): Promise<FlowMigrationResponse> {\n // API documentation suggests this endpoint might expect application/json\n // Let's double-check or assume JSON based on typical Graph API patterns unless FormData is confirmed.\n // Assuming JSON for now:\n const payload = {\n source_waba_id: data.source_waba_id,\n ...(data.source_flow_names && { source_flow_names: data.source_flow_names }),\n };\n\n return this.sendJson(\n HttpMethodsEnum.Post,\n `/${destinationWabaId}/migrate_flows`,\n this.config[WabaConfigEnum.RequestTimeout],\n JSON.stringify(payload),\n );\n }\n}\n"],"mappings":"AAGA,IAAqBA,EAArB,KAAuD,CAC3C,KACA,MAER,YAAYC,EAAcC,EAAiB,GAAO,CAC9C,KAAK,KAAOD,EACZ,KAAK,MAAQC,CACjB,CAEA,OAAOC,EAAa,CAChB,GAAI,KAAK,MAAO,CACZ,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,KACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,IAAI,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACtD,CACJ,CAEA,SAASA,EAAa,CAClB,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,aACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,MAAM,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACxD,CAEA,QAAQA,EAAa,CACjB,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,YACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,QAAQ,KAAK,MAAM,QAAS,CAACA,EAAQ,KAAM,GAAGD,CAAI,CAAC,CACvD,CAEA,QAAQA,EAAa,CACjB,IAAIC,EAAS,KAAK,KAAK,IAAI,CAAC,YACxB,KAAK,OACLA,GAAU,MAAM,KAAK,IAAI,IAE7B,Q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IA,EAAK,mBAAqB,CAAE,kBAAmBA,EAAK,iBAAkB,CAC9E,EAEA,OAAO,KAAK,gBAER,IAAIc,CAAiB,iBACrB,KAAK,OAAO,gBACZ,KAAK,UAAUb,CAAO,CAC1B,CACJ,CACJ","names":["Logger","name","debug","data","prefix","LIB_NAME","LOG_LOCAL","LOGGER","Logger","BaseAPI","config","client","method","endpoint","timeout","body","LIB_NAME","LOG_LOCAL","LOGGER","Logger","FlowAPI","BaseAPI","config","client","wabaId","data","payload","flowId","fields","dateFormat","params","queryString","invalidate","formData","fileContent","flowJsonData","result","isValid","error","destinationWabaId"]}
@@ -1,28 +0,0 @@
1
- export { default as BaseAPI } from './base.js';
2
- export { default as BusinessProfileAPI } from './businessProfile.js';
3
- export { default as EncryptionAPI } from './encryption.js';
4
- export { default as FlowAPI } from './flow.js';
5
- export { default as MediaAPI } from './media.js';
6
- export { default as MessagesAPI } from './messages.js';
7
- export { default as PhoneNumberAPI } from './phoneNumber.js';
8
- export { default as QrCodeAPI } from './qrCode.js';
9
- export { default as RegistrationAPI } from './registration.js';
10
- export { default as TemplateAPI } from './template.js';
11
- export { default as TwoStepVerificationAPI } from './twoStepVerification.js';
12
- export { default as WabaAPI } from './waba.js';
13
- import '../enums-CI7vzKhn.js';
14
- import '../types/base.js';
15
- import '../types/config.js';
16
- import '../types/request.js';
17
- import '../types/businessProfile.js';
18
- import '../types/encryption.js';
19
- import '../types/flow.js';
20
- import 'http';
21
- import '../types/media.js';
22
- import '../types/messages.js';
23
- import '../types/phoneNumber.js';
24
- import '../types/qrCode.js';
25
- import '../types/registration.js';
26
- import '../types/template.js';
27
- import '../types/twoStepVerification.js';
28
- import '../types/waba.js';
package/dist/api/index.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";var B=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var U=(o,t)=>{for(var e in t)B(o,e,{get:t[e],enumerable:!0})},w=(o,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of D(t))!m.call(o,i)&&i!==e&&B(o,i,{get:()=>t[i],enumerable:!(s=_(t,i))||s.enumerable});return o};var G=o=>w(B({},"__esModule",{value:!0}),o);var H={};U(H,{BaseAPI:()=>a,BusinessProfileAPI:()=>f,EncryptionAPI:()=>P,FlowAPI:()=>h,MediaAPI:()=>c,MessagesAPI:()=>g,PhoneNumberAPI:()=>S,QrCodeAPI:()=>T,RegistrationAPI:()=>d,TemplateAPI:()=>A,TwoStepVerificationAPI:()=>b,WabaAPI:()=>I});module.exports=G(H);var n=class{name;debug;constructor(t,e=!1){this.name=t,this.debug=e}log(...t){if(this.debug){let e=`[ ${Date.now()} ]`;this.name&&(e+=` - ${this.name}`),console.log.apply(console,[e,": ",...t])}}error(...t){let e=`[ ${Date.now()} ] - ERROR`;this.name&&(e+=` - ${this.name}`),console.error.apply(console,[e,": ",...t])}warn(...t){let e=`[ ${Date.now()} ] - WARN`;this.name&&(e+=` - ${this.name}`),console.warn.apply(console,[e,": ",...t])}info(...t){let e=`[ ${Date.now()} ] - INFO`;this.name&&(e+=` - ${this.name}`),console.info.apply(console,[e,": ",...t])}};var F="BaseAPI",q=!1,J=new n(F,process.env.DEBUG==="true"||q),a=class{config;client;constructor(t,e){this.config=t,this.client=e,J.log("Initialized with HTTPSClient")}sendJson(t,e,s,i){return this.client.getJson(t,e,s,i)}sendFormData(t,e,s,i){return this.client.sendFormData(t,e,s,i)}sendUrlEncodedForm(t,e,s,i){return this.client.sendUrlEncodedForm(t,e,s,i)}};function N(o){if(!o)return"";let t="";return Array.isArray(o)?t=o.join(","):t=Object.entries(o).filter(([e,s])=>s).map(([e])=>e).join(","),t?`?fields=${t}`:""}var R=o=>{if(!o||Object.keys(o).length===0)return"";let t=new URLSearchParams;for(let[s,i]of Object.entries(o))i!==void 0&&t.append(s,String(i));let e=t.toString();return e?`?${e}`:""};var f=class extends a{endpoint="whatsapp_business_profile";constructor(t,e){super(t,e)}async getBusinessProfile(t){return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}${N(t)}`,this.config.REQUEST_TIMEOUT,null)}async updateBusinessProfile(t){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async createUploadSession(t,e,s){let i=R({file_length:t,file_type:e,file_name:s});return this.sendJson("POST",`app/uploads/${i}`,this.config.REQUEST_TIMEOUT,null)}async uploadMedia(t,e){return this.sendJson("POST",`${t}`,this.config.REQUEST_TIMEOUT,e)}async getUploadHandle(t){return this.sendJson("GET",`${t}`,this.config.REQUEST_TIMEOUT,null)}};var P=class extends a{endpoint="whatsapp_business_encryption";constructor(t,e){super(t,e)}async getEncryptionPublicKey(){return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async setEncryptionPublicKey(t){let e=new FormData;return e.append("business_public_key",t),this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,e)}};var x="FlowAPI",K=!1,O=new n(x,process.env.DEBUG==="true"||K),h=class extends a{constructor(t,e){super(t,e),O.log("FlowAPI initialized")}async listFlows(t){return this.sendJson("GET",`/${t}/flows`,this.config.REQUEST_TIMEOUT,null)}async createFlow(t,e){let s={name:e.name,categories:e.categories,...e.endpoint_uri&&{endpoint_uri:e.endpoint_uri},...e.clone_flow_id&&{clone_flow_id:e.clone_flow_id},...e.flow_json&&{flow_json:e.flow_json},...e.publish!==void 0&&{publish:e.publish}};return this.sendJson("POST",`/${t}/flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(s))}async getFlow(t,e,s){let i=new URLSearchParams;e&&i.append("fields",e),s&&i.append("date_format",s);let p=i.toString()?`?${i.toString()}`:"";return this.sendJson("GET",`/${t}${p}`,this.config.REQUEST_TIMEOUT,null)}async getFlowPreview(t,e=!1){let s=`preview.invalidate(${e})`;return this.getFlow(t,s)}async updateFlowMetadata(t,e){let s={...e.name&&{name:e.name},...e.categories&&{categories:e.categories},...e.endpoint_uri&&{endpoint_uri:e.endpoint_uri},...e.application_id&&{application_id:e.application_id}};return this.sendJson("POST",`/${t}`,this.config.REQUEST_TIMEOUT,JSON.stringify(s))}async deleteFlow(t){return this.sendJson("DELETE",`/${t}`,this.config.REQUEST_TIMEOUT,null)}async listAssets(t){return this.sendJson("GET",`/${t}/assets`,this.config.REQUEST_TIMEOUT,null)}async updateFlowJson(t,e){let s=new FormData,i;if(e.file instanceof Buffer)i=new globalThis.Blob([e.file]),s.append("file",i);else if(typeof e.file=="object"&&!(e.file instanceof Blob))try{i=new globalThis.Blob([JSON.stringify(e.file,null,2)],{type:"application/json"}),s.append("file",i)}catch{throw new Error("Failed to stringify JSON object for Flow JSON update.")}else if(e.file instanceof Blob)i=e.file,s.append("file",i);else throw new Error("Invalid file type provided for Flow JSON update. Must be a Buffer, JSON object, or Blob.");return s.append("asset_type","FLOW_JSON"),s.append("name",e.name||"flow.json"),this.sendFormData("POST",`/${t}/assets`,this.config.REQUEST_TIMEOUT,s)}async validateFlowJson(t,e){try{let s=await this.updateFlowJson(t,{file:e}),i=!s.validation_errors||s.validation_errors.length===0;return{...s,valid:i}}catch(s){throw O.error("Error during Flow JSON validation attempt:",s),s}}async publishFlow(t){return this.sendJson("POST",`/${t}/publish`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async deprecateFlow(t){return this.sendJson("POST",`/${t}/deprecate`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async migrateFlows(t,e){let s={source_waba_id:e.source_waba_id,...e.source_flow_names&&{source_flow_names:e.source_flow_names}};return this.sendJson("POST",`/${t}/migrate_flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(s))}};var c=class extends a{endpoint="media";constructor(t,e){super(t,e)}async getMediaById(t){return this.sendJson("GET",`${t}`,this.config.REQUEST_TIMEOUT,null)}async uploadMedia(t,e="whatsapp"){let s=new FormData;return s.append("file",t),s.append("messaging_product",e),s.append("type",t.type),this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,s)}async deleteMedia(t){return this.sendJson("DELETE",`${t}`,this.config.REQUEST_TIMEOUT,null)}async downloadMedia(t){return this.sendJson("GET",t,this.config.REQUEST_TIMEOUT,null)}};var g=class extends a{commonMethod="POST";commonEndpoint="messages";constructor(t,e){super(t,e)}bodyBuilder(t,e,s,i){let p={messaging_product:"whatsapp",recipient_type:"individual",to:s,type:t,[t]:e};return i&&(p.context={message_id:i}),p}send(t){return this.sendJson(this.commonMethod,`${this.config.WA_PHONE_NUMBER_ID}/${this.commonEndpoint}`,this.config.REQUEST_TIMEOUT,t)}async audio(t){let{body:e,to:s,replyMessageId:i}=t;return this.send(JSON.stringify(this.bodyBuilder("audio",e,s,i)))}async contacts(t){let{body:e,to:s,replyMessageId:i}=t;return this.send(JSON.stringify(this.bodyBuilder("contacts",e,s,i)))}async document(t){let{body:e,to:s,replyMessageId:i}=t;return this.send(JSON.stringify(this.bodyBuilder("document",e,s,i)))}async image(t){let{body:e,to:s,replyMessageId:i}=t;return this.send(JSON.stringify(this.bodyBuilder("image",e,s,i)))}async interactive(t){let{body:e,to:s,replyMessageId:i}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",e,s,i)))}async location(t){let{body:e,to:s,replyMessageId:i}=t;return this.send(JSON.stringify(this.bodyBuilder("location",e,s,i)))}async sticker(t){let{body:e,to:s,replyMessageId:i}=t;return this.send(JSON.stringify(this.bodyBuilder("sticker",e,s,i)))}async template(t){let{body:e,to:s,replyMessageId:i}=t;return this.send(JSON.stringify(this.bodyBuilder("template",e,s,i)))}async text(t){let{body:e,previewUrl:s,to:i,replyMessageId:p}=t,M;return typeof e=="string"?M={body:e,preview_url:s}:M=e,this.send(JSON.stringify(this.bodyBuilder("text",M,i,p)))}async video(t){let{body:e,to:s,replyMessageId:i}=t;return this.send(JSON.stringify(this.bodyBuilder("video",e,s,i)))}async status(t){let{status:e,messageId:s,typingIndicator:i}=t,p={messaging_product:"whatsapp",status:e,message_id:s,...i&&{typing_indicator:i}};return this.send(JSON.stringify(p))}async markAsRead(t){return this.status({status:"read",messageId:t.messageId})}async showTypingIndicator(t){return this.status({status:"read",messageId:t.messageId,typingIndicator:{type:"text"}})}async interactiveList(t){let{body:e,to:s,replyMessageId:i}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",e,s,i)))}async interactiveCtaUrl(t){let{body:e,to:s,replyMessageId:i}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",e,s,i)))}async interactiveLocationRequest(t){let{body:e,to:s,replyMessageId:i}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",e,s,i)))}async interactiveAddressMessage(t){let{body:e,to:s,replyMessageId:i}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",e,s,i)))}async interactiveReplyButtons(t){let{body:e,to:s,replyMessageId:i}=t;return this.send(JSON.stringify(this.bodyBuilder("interactive",e,s,i)))}async interactiveFlow(t){let{body:e,to:s,replyMessageId:i}=t;return e.action.parameters.flow_message_version===void 0&&(e.action.parameters.flow_message_version="3"),e.action.parameters.mode===void 0&&(e.action.parameters.mode="published"),e.action.parameters.flow_action===void 0&&(e.action.parameters.flow_action="navigate"),e.action.parameters.flow_action==="navigate"?e.action.parameters.flow_action_payload?.screen===void 0&&(e.action.parameters.flow_action_payload={...e.action.parameters.flow_action_payload,screen:"INIT"}):e.action.parameters.flow_action==="data_exchange"&&delete e.action.parameters.flow_action_payload,this.send(JSON.stringify(this.bodyBuilder("interactive",e,s,i)))}async reaction(t){let{messageId:e,emoji:s,to:i}=t,p={messaging_product:"whatsapp",recipient_type:"individual",to:i,type:"reaction",reaction:{message_id:e,emoji:s}};return this.send(JSON.stringify(p))}};var S=class extends a{endpoint="phone_numbers";constructor(t,e){super(t,e)}async getPhoneNumberById(t){let e=t?R({fields:t}):"";return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}${e}`,this.config.REQUEST_TIMEOUT,null)}async getPhoneNumbers(){return this.sendJson("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async requestVerificationCode(t){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/request_code`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async verifyCode(t){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/verify_code`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}};var T=class extends a{endpoint="message_qrdls";constructor(t,e){super(t,e)}async createQrCode(t){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async getQrCodes(){return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,null)}async getQrCode(t){return this.sendJson("GET",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}/${t}`,this.config.REQUEST_TIMEOUT,null)}async updateQrCode(t){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async deleteQrCode(t){return this.sendJson("DELETE",`${this.config.WA_PHONE_NUMBER_ID}/${this.endpoint}/${t}`,this.config.REQUEST_TIMEOUT,null)}};var d=class extends a{constructor(t,e){super(t,e)}async register(t,e){let s={messaging_product:"whatsapp",pin:t,...e&&{data_localization_region:e}};return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/register`,this.config.REQUEST_TIMEOUT,JSON.stringify(s))}async deregister(){return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}/deregister`,this.config.REQUEST_TIMEOUT,null)}};var A=class extends a{endpoint="message_templates";constructor(t,e){super(t,e)}async getTemplate(t){return this.sendJson("GET",`${t}`,this.config.REQUEST_TIMEOUT,null)}async updateTemplate(t,e){return this.sendJson("POST",`${t}`,this.config.REQUEST_TIMEOUT,JSON.stringify(e))}async getTemplates(t){return this.sendJson("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}${R(t)}`,this.config.REQUEST_TIMEOUT,null)}async createTemplate(t){return this.sendJson("POST",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}`,this.config.REQUEST_TIMEOUT,JSON.stringify(t))}async deleteTemplate(t){return this.sendJson("DELETE",`${this.config.WA_BUSINESS_ACCOUNT_ID}/${this.endpoint}${R(t)}`,this.config.REQUEST_TIMEOUT,null)}};var b=class extends a{constructor(t,e){super(t,e)}async setTwoStepVerificationCode(t){let e={pin:t};return this.sendJson("POST",`${this.config.WA_PHONE_NUMBER_ID}`,this.config.REQUEST_TIMEOUT,JSON.stringify(e))}};var I=class extends a{constructor(t,e){super(t,e)}async getWabaAccount(t){let e=N(t)?.replace(/,/g,"%2C");return this.sendJson("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}${e}`,this.config.REQUEST_TIMEOUT,null)}async getAllWabaSubscriptions(){return this.sendJson("GET",`${this.config.WA_BUSINESS_ACCOUNT_ID}/subscribed_apps`,this.config.REQUEST_TIMEOUT,null)}async updateWabaSubscription({override_callback_uri:t,verify_token:e}){let s={override_callback_uri:t,verify_token:e};return this.sendJson("POST",`${this.config.WA_BUSINESS_ACCOUNT_ID}/subscribed_apps`,this.config.REQUEST_TIMEOUT,JSON.stringify(s))}async unsubscribeFromWaba(){return this.sendJson("DELETE",`${this.config.WA_BUSINESS_ACCOUNT_ID}/subscribed_apps`,this.config.REQUEST_TIMEOUT,null)}};0&&(module.exports={BaseAPI,BusinessProfileAPI,EncryptionAPI,FlowAPI,MediaAPI,MessagesAPI,PhoneNumberAPI,QrCodeAPI,RegistrationAPI,TemplateAPI,TwoStepVerificationAPI,WabaAPI});
2
- //# sourceMappingURL=index.js.map