@webiny/webhooks 6.4.0-beta.1 → 6.4.0-beta.3

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 (208) hide show
  1. package/admin/WebhookRoutes.js +21 -3
  2. package/admin/WebhookRoutes.js.map +1 -1
  3. package/admin/Webhooks.js +11 -0
  4. package/admin/Webhooks.js.map +1 -1
  5. package/admin/features/getWebhookSettings/GetWebhookSettingsGateway.d.ts +12 -0
  6. package/admin/features/getWebhookSettings/GetWebhookSettingsGateway.js +40 -0
  7. package/admin/features/getWebhookSettings/GetWebhookSettingsGateway.js.map +1 -0
  8. package/admin/features/getWebhookSettings/GetWebhookSettingsUseCase.d.ts +11 -0
  9. package/admin/features/getWebhookSettings/GetWebhookSettingsUseCase.js +18 -0
  10. package/admin/features/getWebhookSettings/GetWebhookSettingsUseCase.js.map +1 -0
  11. package/admin/features/getWebhookSettings/abstractions.d.ts +15 -0
  12. package/admin/features/getWebhookSettings/abstractions.js +6 -0
  13. package/admin/features/getWebhookSettings/abstractions.js.map +1 -0
  14. package/admin/features/getWebhookSettings/feature.d.ts +3 -0
  15. package/admin/features/getWebhookSettings/feature.js +19 -0
  16. package/admin/features/getWebhookSettings/feature.js.map +1 -0
  17. package/admin/features/getWebhookSettings/index.d.ts +2 -0
  18. package/admin/features/getWebhookSettings/index.js +2 -0
  19. package/admin/features/updateWebhookSettings/UpdateWebhookSettingsGateway.d.ts +12 -0
  20. package/admin/features/updateWebhookSettings/UpdateWebhookSettingsGateway.js +43 -0
  21. package/admin/features/updateWebhookSettings/UpdateWebhookSettingsGateway.js.map +1 -0
  22. package/admin/features/updateWebhookSettings/UpdateWebhookSettingsUseCase.d.ts +11 -0
  23. package/admin/features/updateWebhookSettings/UpdateWebhookSettingsUseCase.js +18 -0
  24. package/admin/features/updateWebhookSettings/UpdateWebhookSettingsUseCase.js.map +1 -0
  25. package/admin/features/updateWebhookSettings/abstractions.d.ts +18 -0
  26. package/admin/features/updateWebhookSettings/abstractions.js +6 -0
  27. package/admin/features/updateWebhookSettings/abstractions.js.map +1 -0
  28. package/admin/features/updateWebhookSettings/feature.d.ts +3 -0
  29. package/admin/features/updateWebhookSettings/feature.js +19 -0
  30. package/admin/features/updateWebhookSettings/feature.js.map +1 -0
  31. package/admin/features/updateWebhookSettings/index.d.ts +2 -0
  32. package/admin/features/updateWebhookSettings/index.js +2 -0
  33. package/admin/presentation/WebhookForm/WebhookFormPresenter.d.ts +6 -2
  34. package/admin/presentation/WebhookForm/WebhookFormPresenter.js +87 -14
  35. package/admin/presentation/WebhookForm/WebhookFormPresenter.js.map +1 -1
  36. package/admin/presentation/WebhookForm/abstractions.d.ts +0 -4
  37. package/admin/presentation/WebhookForm/abstractions.js.map +1 -1
  38. package/admin/presentation/WebhookForm/components/WebhookFormView.js +5 -11
  39. package/admin/presentation/WebhookForm/components/WebhookFormView.js.map +1 -1
  40. package/admin/presentation/WebhookList/components/WebhookListView.js +28 -21
  41. package/admin/presentation/WebhookList/components/WebhookListView.js.map +1 -1
  42. package/admin/presentation/WebhookSettings/WebhookSettingsPresenter.d.ts +21 -0
  43. package/admin/presentation/WebhookSettings/WebhookSettingsPresenter.js +83 -0
  44. package/admin/presentation/WebhookSettings/WebhookSettingsPresenter.js.map +1 -0
  45. package/admin/presentation/WebhookSettings/abstractions.d.ts +16 -0
  46. package/admin/presentation/WebhookSettings/abstractions.js +5 -0
  47. package/admin/presentation/WebhookSettings/abstractions.js.map +1 -0
  48. package/admin/presentation/WebhookSettings/components/WebhookSettingsView.d.ts +2 -0
  49. package/admin/presentation/WebhookSettings/components/WebhookSettingsView.js +56 -0
  50. package/admin/presentation/WebhookSettings/components/WebhookSettingsView.js.map +1 -0
  51. package/admin/presentation/WebhookSettings/feature.d.ts +3 -0
  52. package/admin/presentation/WebhookSettings/feature.js +17 -0
  53. package/admin/presentation/WebhookSettings/feature.js.map +1 -0
  54. package/admin/presentation/WebhookSettings/index.d.ts +2 -0
  55. package/admin/presentation/WebhookSettings/index.js +2 -0
  56. package/admin/routes.d.ts +1 -0
  57. package/admin/routes.js +4 -0
  58. package/admin/routes.js.map +1 -1
  59. package/admin/shared/types.d.ts +3 -0
  60. package/api/WebhooksFeature.js +10 -0
  61. package/api/WebhooksFeature.js.map +1 -1
  62. package/api/domain/WebhookSettings.d.ts +3 -0
  63. package/api/domain/WebhookSettings.js +0 -0
  64. package/api/domain/constants.d.ts +1 -0
  65. package/api/domain/constants.js +2 -1
  66. package/api/domain/constants.js.map +1 -1
  67. package/api/domain/errors.d.ts +7 -2
  68. package/api/domain/errors.js +16 -3
  69. package/api/domain/errors.js.map +1 -1
  70. package/api/features/CreateWebhook/CreateWebhookUseCase.d.ts +3 -3
  71. package/api/features/CreateWebhook/CreateWebhookUseCase.js +10 -19
  72. package/api/features/CreateWebhook/CreateWebhookUseCase.js.map +1 -1
  73. package/api/features/CreateWebhook/abstractions.d.ts +1 -1
  74. package/api/features/CreateWebhook/abstractions.js.map +1 -1
  75. package/api/features/CreateWebhook/schema.d.ts +10 -0
  76. package/api/features/CreateWebhook/schema.js +16 -0
  77. package/api/features/CreateWebhook/schema.js.map +1 -0
  78. package/api/features/DeleteWebhook/DeleteWebhookUseCase.d.ts +3 -3
  79. package/api/features/DeleteWebhook/DeleteWebhookUseCase.js +8 -3
  80. package/api/features/DeleteWebhook/DeleteWebhookUseCase.js.map +1 -1
  81. package/api/features/DeleteWebhook/abstractions.d.ts +2 -2
  82. package/api/features/DeleteWebhook/abstractions.js.map +1 -1
  83. package/api/features/DeleteWebhook/schema.d.ts +4 -0
  84. package/api/features/DeleteWebhook/schema.js +7 -0
  85. package/api/features/DeleteWebhook/schema.js.map +1 -0
  86. package/api/features/GetWebhook/GetWebhookUseCase.d.ts +2 -2
  87. package/api/features/GetWebhook/GetWebhookUseCase.js +7 -2
  88. package/api/features/GetWebhook/GetWebhookUseCase.js.map +1 -1
  89. package/api/features/GetWebhook/abstractions.d.ts +2 -2
  90. package/api/features/GetWebhook/abstractions.js.map +1 -1
  91. package/api/features/GetWebhook/schema.d.ts +4 -0
  92. package/api/features/GetWebhook/schema.js +7 -0
  93. package/api/features/GetWebhook/schema.js.map +1 -0
  94. package/api/features/GetWebhookDelivery/GetWebhookDeliveryUseCase.d.ts +2 -2
  95. package/api/features/GetWebhookDelivery/GetWebhookDeliveryUseCase.js +7 -2
  96. package/api/features/GetWebhookDelivery/GetWebhookDeliveryUseCase.js.map +1 -1
  97. package/api/features/GetWebhookDelivery/abstractions.d.ts +2 -2
  98. package/api/features/GetWebhookDelivery/abstractions.js.map +1 -1
  99. package/api/features/GetWebhookDelivery/schema.d.ts +4 -0
  100. package/api/features/GetWebhookDelivery/schema.js +7 -0
  101. package/api/features/GetWebhookDelivery/schema.js.map +1 -0
  102. package/api/features/GetWebhookSettings/GetWebhookSettingsRepository.d.ts +19 -0
  103. package/api/features/GetWebhookSettings/GetWebhookSettingsRepository.js +55 -0
  104. package/api/features/GetWebhookSettings/GetWebhookSettingsRepository.js.map +1 -0
  105. package/api/features/GetWebhookSettings/abstractions.d.ts +13 -0
  106. package/api/features/GetWebhookSettings/abstractions.js +5 -0
  107. package/api/features/GetWebhookSettings/abstractions.js.map +1 -0
  108. package/api/features/GetWebhookSettings/feature.d.ts +4 -0
  109. package/api/features/GetWebhookSettings/feature.js +11 -0
  110. package/api/features/GetWebhookSettings/feature.js.map +1 -0
  111. package/api/features/ListWebhookDeliveries/ListWebhookDeliveriesUseCase.d.ts +2 -2
  112. package/api/features/ListWebhookDeliveries/ListWebhookDeliveriesUseCase.js +4 -1
  113. package/api/features/ListWebhookDeliveries/ListWebhookDeliveriesUseCase.js.map +1 -1
  114. package/api/features/ListWebhookDeliveries/abstractions.d.ts +2 -2
  115. package/api/features/ListWebhookDeliveries/abstractions.js.map +1 -1
  116. package/api/features/ListWebhookDeliveries/schema.d.ts +7 -0
  117. package/api/features/ListWebhookDeliveries/schema.js +10 -0
  118. package/api/features/ListWebhookDeliveries/schema.js.map +1 -0
  119. package/api/features/ListWebhooks/ListWebhooksUseCase.d.ts +2 -2
  120. package/api/features/ListWebhooks/ListWebhooksUseCase.js +4 -1
  121. package/api/features/ListWebhooks/ListWebhooksUseCase.js.map +1 -1
  122. package/api/features/ListWebhooks/abstractions.d.ts +2 -2
  123. package/api/features/ListWebhooks/abstractions.js.map +1 -1
  124. package/api/features/ListWebhooks/schema.d.ts +7 -0
  125. package/api/features/ListWebhooks/schema.js +10 -0
  126. package/api/features/ListWebhooks/schema.js.map +1 -0
  127. package/api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.d.ts +5 -5
  128. package/api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.js +7 -2
  129. package/api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.js.map +1 -1
  130. package/api/features/ResendWebhookDelivery/abstractions.d.ts +2 -2
  131. package/api/features/ResendWebhookDelivery/abstractions.js.map +1 -1
  132. package/api/features/ResendWebhookDelivery/schema.d.ts +4 -0
  133. package/api/features/ResendWebhookDelivery/schema.js +7 -0
  134. package/api/features/ResendWebhookDelivery/schema.js.map +1 -0
  135. package/api/features/SendWebhookTask/SendWebhookTask.d.ts +6 -2
  136. package/api/features/SendWebhookTask/SendWebhookTask.js +45 -33
  137. package/api/features/SendWebhookTask/SendWebhookTask.js.map +1 -1
  138. package/api/features/SendWebhookTask/types.d.ts +1 -0
  139. package/api/features/TriggerWebhook/TriggerWebhookUseCase.js +8 -2
  140. package/api/features/TriggerWebhook/TriggerWebhookUseCase.js.map +1 -1
  141. package/api/features/TriggerWebhook/abstractions.d.ts +2 -2
  142. package/api/features/TriggerWebhook/abstractions.js.map +1 -1
  143. package/api/features/TriggerWebhook/schema.d.ts +5 -0
  144. package/api/features/TriggerWebhook/schema.js +8 -0
  145. package/api/features/TriggerWebhook/schema.js.map +1 -0
  146. package/api/features/UpdateWebhook/UpdateWebhookUseCase.d.ts +4 -4
  147. package/api/features/UpdateWebhook/UpdateWebhookUseCase.js +9 -33
  148. package/api/features/UpdateWebhook/UpdateWebhookUseCase.js.map +1 -1
  149. package/api/features/UpdateWebhook/abstractions.d.ts +0 -1
  150. package/api/features/UpdateWebhook/abstractions.js.map +1 -1
  151. package/api/features/UpdateWebhook/schema.d.ts +9 -0
  152. package/api/features/UpdateWebhook/schema.js +15 -0
  153. package/api/features/UpdateWebhook/schema.js.map +1 -0
  154. package/api/features/UpdateWebhookSettings/UpdateWebhookSettingsRepository.d.ts +21 -0
  155. package/api/features/UpdateWebhookSettings/UpdateWebhookSettingsRepository.js +60 -0
  156. package/api/features/UpdateWebhookSettings/UpdateWebhookSettingsRepository.js.map +1 -0
  157. package/api/features/UpdateWebhookSettings/UpdateWebhookSettingsUseCase.d.ts +14 -0
  158. package/api/features/UpdateWebhookSettings/UpdateWebhookSettingsUseCase.js +27 -0
  159. package/api/features/UpdateWebhookSettings/UpdateWebhookSettingsUseCase.js.map +1 -0
  160. package/api/features/UpdateWebhookSettings/abstractions.d.ts +26 -0
  161. package/api/features/UpdateWebhookSettings/abstractions.js +6 -0
  162. package/api/features/UpdateWebhookSettings/abstractions.js.map +1 -0
  163. package/api/features/UpdateWebhookSettings/feature.d.ts +4 -0
  164. package/api/features/UpdateWebhookSettings/feature.js +13 -0
  165. package/api/features/UpdateWebhookSettings/feature.js.map +1 -0
  166. package/api/features/UpdateWebhookSettings/schema.d.ts +4 -0
  167. package/api/features/UpdateWebhookSettings/schema.js +7 -0
  168. package/api/features/UpdateWebhookSettings/schema.js.map +1 -0
  169. package/api/features/WebhookDeliver/WebhookDeliver.d.ts +13 -0
  170. package/api/features/WebhookDeliver/WebhookDeliver.js +79 -0
  171. package/api/features/WebhookDeliver/WebhookDeliver.js.map +1 -0
  172. package/api/features/WebhookDeliver/abstractions.d.ts +24 -0
  173. package/api/features/WebhookDeliver/abstractions.js +5 -0
  174. package/api/features/WebhookDeliver/abstractions.js.map +1 -0
  175. package/api/features/WebhookDeliver/feature.d.ts +4 -0
  176. package/api/features/WebhookDeliver/feature.js +11 -0
  177. package/api/features/WebhookDeliver/feature.js.map +1 -0
  178. package/api/features/WebhookDeliver/index.d.ts +2 -0
  179. package/api/features/WebhookDeliver/index.js +2 -0
  180. package/api/features/WebhookSignPayload/WebhookSignPayload.d.ts +1 -0
  181. package/api/features/WebhookSignPayload/WebhookSignPayload.js +7 -1
  182. package/api/features/WebhookSignPayload/WebhookSignPayload.js.map +1 -1
  183. package/api/graphql/WebhookCrudSchema.js +1 -2
  184. package/api/graphql/WebhookCrudSchema.js.map +1 -1
  185. package/api/graphql/WebhookEventSchema.js +1 -0
  186. package/api/graphql/WebhookEventSchema.js.map +1 -1
  187. package/api/graphql/WebhookSettingsSchema.d.ts +8 -0
  188. package/api/graphql/WebhookSettingsSchema.js +60 -0
  189. package/api/graphql/WebhookSettingsSchema.js.map +1 -0
  190. package/api/models/WebhookDeliveryModel.js +4 -4
  191. package/api/models/WebhookDeliveryModel.js.map +1 -1
  192. package/api/models/WebhookModel.js +1 -1
  193. package/api/models/WebhookModel.js.map +1 -1
  194. package/api/models/WebhookSettingsModel.d.ts +8 -0
  195. package/api/models/WebhookSettingsModel.js +27 -0
  196. package/api/models/WebhookSettingsModel.js.map +1 -0
  197. package/api/utils/isValidEndpointUrl.d.ts +1 -0
  198. package/api/utils/isValidEndpointUrl.js +13 -0
  199. package/api/utils/isValidEndpointUrl.js.map +1 -0
  200. package/exports/api/webhooks.d.ts +0 -1
  201. package/exports/api/webhooks.js +0 -1
  202. package/package.json +22 -20
  203. package/admin/SecurityPermission.d.ts +0 -2
  204. package/admin/SecurityPermission.js +0 -15
  205. package/admin/SecurityPermission.js.map +0 -1
  206. package/admin/presentation/WebhookForm/components/EventsSelector.d.ts +0 -12
  207. package/admin/presentation/WebhookForm/components/EventsSelector.js +0 -44
  208. package/admin/presentation/WebhookForm/components/EventsSelector.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin/presentation/WebhookSettings/WebhookSettingsPresenter.js","sources":["../../../../src/admin/presentation/WebhookSettings/WebhookSettingsPresenter.ts"],"sourcesContent":["import { computed, makeAutoObservable, runInAction } from \"mobx\";\nimport {\n WebhookSettingsPresenter as Abstraction,\n type IWebhookSettingsPresenter,\n type IWebhookSettingsViewModel\n} from \"./abstractions.js\";\nimport { GetWebhookSettingsUseCase } from \"~/admin/features/getWebhookSettings/abstractions.js\";\nimport { UpdateWebhookSettingsUseCase } from \"~/admin/features/updateWebhookSettings/abstractions.js\";\nimport {\n FormModelFactory,\n type IFormModel\n} from \"@webiny/app-admin/features/formModel/abstractions.js\";\n\nclass WebhookSettingsPresenterImpl implements IWebhookSettingsPresenter {\n private _loading = false;\n private _saving = false;\n private _form: IFormModel;\n\n public get vm(): IWebhookSettingsViewModel {\n return {\n loading: this._loading,\n saving: this._saving,\n form: this._form.vm\n };\n }\n\n public constructor(\n private readonly formModelFactory: FormModelFactory.Interface,\n private readonly getWebhookSettingsUseCase: GetWebhookSettingsUseCase.Interface,\n private readonly updateWebhookSettingsUseCase: UpdateWebhookSettingsUseCase.Interface\n ) {\n this._form = this.buildForm();\n\n makeAutoObservable(this, { vm: computed });\n }\n\n private buildForm(): IFormModel {\n return this.formModelFactory.create({\n fields: fields => ({\n signingSecret: fields\n .text()\n .label(\"Signing Secret\")\n .placeholder(\"Enter a signing secret for webhook payloads\")\n .description(\n \"Used to sign webhook payloads so receivers can verify authenticity.\"\n )\n }),\n layout: layout => [layout.row(\"signingSecret\")]\n });\n }\n\n public async save() {\n const data = await this._form.submit<Record<string, unknown>>();\n if (data === false) {\n return false;\n }\n\n this._saving = true;\n\n try {\n const settings = await this.updateWebhookSettingsUseCase.execute({\n signingSecret: (data.signingSecret as string) || undefined\n });\n\n runInAction(() => {\n this._form.setData({\n signingSecret: settings.signingSecret ?? \"\"\n });\n });\n } finally {\n runInAction(() => {\n this._saving = false;\n });\n }\n\n return true;\n }\n\n public async init(): Promise<void> {\n this._loading = true;\n\n try {\n const settings = await this.getWebhookSettingsUseCase.execute();\n\n runInAction(() => {\n this._form = this.buildForm();\n this._form.setData({\n signingSecret: settings.signingSecret ?? \"\"\n });\n this._loading = false;\n });\n } catch {\n runInAction(() => {\n this._loading = false;\n });\n }\n }\n}\n\nexport const WebhookSettingsPresenter = Abstraction.createImplementation({\n implementation: WebhookSettingsPresenterImpl,\n dependencies: [FormModelFactory, GetWebhookSettingsUseCase, UpdateWebhookSettingsUseCase]\n});\n"],"names":["WebhookSettingsPresenterImpl","formModelFactory","getWebhookSettingsUseCase","updateWebhookSettingsUseCase","makeAutoObservable","computed","fields","layout","data","settings","undefined","runInAction","WebhookSettingsPresenter","Abstraction","FormModelFactory","GetWebhookSettingsUseCase","UpdateWebhookSettingsUseCase"],"mappings":";;;;;AAaA,MAAMA;IAKF,IAAW,KAAgC;QACvC,OAAO;YACH,SAAS,IAAI,CAAC,QAAQ;YACtB,QAAQ,IAAI,CAAC,OAAO;YACpB,MAAM,IAAI,CAAC,KAAK,CAAC,EAAE;QACvB;IACJ;IAEA,YACqBC,gBAA4C,EAC5CC,yBAA8D,EAC9DC,4BAAoE,CACvF;aAHmBF,gBAAgB,GAAhBA;aACAC,yBAAyB,GAAzBA;aACAC,4BAA4B,GAA5BA;aAfb,QAAQ,GAAG;aACX,OAAO,GAAG;QAgBd,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS;QAE3BC,mBAAmB,IAAI,EAAE;YAAE,IAAIC;QAAS;IAC5C;IAEQ,YAAwB;QAC5B,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC;YAChC,QAAQC,CAAAA,SAAW;oBACf,eAAeA,OACV,IAAI,GACJ,KAAK,CAAC,kBACN,WAAW,CAAC,+CACZ,WAAW,CACR;gBAEZ;YACA,QAAQC,CAAAA,SAAU;oBAACA,OAAO,GAAG,CAAC;iBAAiB;QACnD;IACJ;IAEA,MAAa,OAAO;QAChB,MAAMC,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM;QACpC,IAAIA,AAAS,UAATA,MACA,OAAO;QAGX,IAAI,CAAC,OAAO,GAAG;QAEf,IAAI;YACA,MAAMC,WAAW,MAAM,IAAI,CAAC,4BAA4B,CAAC,OAAO,CAAC;gBAC7D,eAAgBD,KAAK,aAAa,IAAeE;YACrD;YAEAC,YAAY;gBACR,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;oBACf,eAAeF,SAAS,aAAa,IAAI;gBAC7C;YACJ;QACJ,SAAU;YACNE,YAAY;gBACR,IAAI,CAAC,OAAO,GAAG;YACnB;QACJ;QAEA,OAAO;IACX;IAEA,MAAa,OAAsB;QAC/B,IAAI,CAAC,QAAQ,GAAG;QAEhB,IAAI;YACA,MAAMF,WAAW,MAAM,IAAI,CAAC,yBAAyB,CAAC,OAAO;YAE7DE,YAAY;gBACR,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS;gBAC3B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;oBACf,eAAeF,SAAS,aAAa,IAAI;gBAC7C;gBACA,IAAI,CAAC,QAAQ,GAAG;YACpB;QACJ,EAAE,OAAM;YACJE,YAAY;gBACR,IAAI,CAAC,QAAQ,GAAG;YACpB;QACJ;IACJ;AACJ;AAEO,MAAMC,oDAA2BC,yBAAAA,oBAAgC,CAAC;IACrE,gBAAgBb;IAChB,cAAc;QAACc;QAAkBC;QAA2BC;KAA6B;AAC7F"}
@@ -0,0 +1,16 @@
1
+ import type { IFormVM } from "@webiny/app-admin/features/formModel/abstractions.js";
2
+ export interface IWebhookSettingsViewModel {
3
+ loading: boolean;
4
+ saving: boolean;
5
+ form: IFormVM;
6
+ }
7
+ export interface IWebhookSettingsPresenter {
8
+ vm: IWebhookSettingsViewModel;
9
+ save(): Promise<boolean>;
10
+ init(): void;
11
+ }
12
+ export declare const WebhookSettingsPresenter: import("@webiny/di").Abstraction<IWebhookSettingsPresenter>;
13
+ export declare namespace WebhookSettingsPresenter {
14
+ type Interface = IWebhookSettingsPresenter;
15
+ type ViewModel = IWebhookSettingsViewModel;
16
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/admin";
2
+ const WebhookSettingsPresenter = createAbstraction("WebhookSettingsPresenter");
3
+ export { WebhookSettingsPresenter };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin/presentation/WebhookSettings/abstractions.js","sources":["../../../../src/admin/presentation/WebhookSettings/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { IFormVM } from \"@webiny/app-admin/features/formModel/abstractions.js\";\n\nexport interface IWebhookSettingsViewModel {\n loading: boolean;\n saving: boolean;\n form: IFormVM;\n}\n\nexport interface IWebhookSettingsPresenter {\n vm: IWebhookSettingsViewModel;\n save(): Promise<boolean>;\n init(): void;\n}\n\nexport const WebhookSettingsPresenter = createAbstraction<IWebhookSettingsPresenter>(\n \"WebhookSettingsPresenter\"\n);\n\nexport namespace WebhookSettingsPresenter {\n export type Interface = IWebhookSettingsPresenter;\n export type ViewModel = IWebhookSettingsViewModel;\n}\n"],"names":["WebhookSettingsPresenter","createAbstraction"],"mappings":";AAeO,MAAMA,2BAA2BC,kBACpC"}
@@ -0,0 +1,2 @@
1
+ import React from "react";
2
+ export declare const WebhookSettingsView: () => React.JSX.Element;
@@ -0,0 +1,56 @@
1
+ import react, { useEffect, useMemo } from "react";
2
+ import { observer } from "mobx-react-lite";
3
+ import { DiContainerProvider, useContainer, useFeature } from "@webiny/app";
4
+ import { CenteredView, FormErrors, SimpleForm, SimpleFormContent, SimpleFormFooter, SimpleFormHeader } from "@webiny/app-admin";
5
+ import { Button, OverlayLoader, useToast } from "@webiny/admin-ui";
6
+ import { FormView } from "@webiny/app-admin/features/formModel/FormView.js";
7
+ import { WebhookSettingsPresenterFeature } from "../feature.js";
8
+ import { GetWebhookSettingsFeature } from "../../../features/getWebhookSettings/feature.js";
9
+ import { UpdateWebhookSettingsFeature } from "../../../features/updateWebhookSettings/feature.js";
10
+ const WebhookSettingsView_WebhookSettingsViewInner = observer(function() {
11
+ const { presenter } = useFeature(WebhookSettingsPresenterFeature);
12
+ const toast = useToast();
13
+ useEffect(()=>{
14
+ presenter.init();
15
+ }, [
16
+ presenter
17
+ ]);
18
+ const { vm } = presenter;
19
+ const handleSave = async ()=>{
20
+ const success = await presenter.save();
21
+ if (success) toast.showSuccessToast({
22
+ title: "Webhooks settings saved successfully!"
23
+ });
24
+ };
25
+ return /*#__PURE__*/ react.createElement(CenteredView, null, /*#__PURE__*/ react.createElement(FormErrors, {
26
+ form: vm.form
27
+ }), /*#__PURE__*/ react.createElement(SimpleForm, null, vm.loading ? /*#__PURE__*/ react.createElement(OverlayLoader, {
28
+ text: "Loading settings..."
29
+ }) : null, vm.saving ? /*#__PURE__*/ react.createElement(OverlayLoader, {
30
+ text: "Saving settings..."
31
+ }) : null, /*#__PURE__*/ react.createElement(SimpleFormHeader, {
32
+ title: "Webhooks Settings"
33
+ }), /*#__PURE__*/ react.createElement(SimpleFormContent, null, /*#__PURE__*/ react.createElement(FormView, {
34
+ name: "WebhooksSettings",
35
+ form: vm.form
36
+ })), /*#__PURE__*/ react.createElement(SimpleFormFooter, null, /*#__PURE__*/ react.createElement(Button, {
37
+ text: "Save settings",
38
+ onClick: handleSave
39
+ }))));
40
+ });
41
+ const WebhookSettingsView = ()=>{
42
+ const container = useContainer();
43
+ const scopedContainer = useMemo(()=>{
44
+ const child = container.createChildContainer();
45
+ GetWebhookSettingsFeature.register(child);
46
+ UpdateWebhookSettingsFeature.register(child);
47
+ WebhookSettingsPresenterFeature.register(child);
48
+ return child;
49
+ }, []);
50
+ return /*#__PURE__*/ react.createElement(DiContainerProvider, {
51
+ container: scopedContainer
52
+ }, /*#__PURE__*/ react.createElement(WebhookSettingsView_WebhookSettingsViewInner, null));
53
+ };
54
+ export { WebhookSettingsView };
55
+
56
+ //# sourceMappingURL=WebhookSettingsView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin/presentation/WebhookSettings/components/WebhookSettingsView.js","sources":["../../../../../src/admin/presentation/WebhookSettings/components/WebhookSettingsView.tsx"],"sourcesContent":["import React, { useEffect, useMemo } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { DiContainerProvider, useContainer, useFeature } from \"@webiny/app\";\nimport { CenteredView, FormErrors } from \"@webiny/app-admin\";\nimport { Button, OverlayLoader } from \"@webiny/admin-ui\";\nimport { FormView } from \"@webiny/app-admin/features/formModel/FormView.js\";\nimport { SimpleFormHeader } from \"@webiny/app-admin\";\nimport { SimpleFormFooter } from \"@webiny/app-admin\";\nimport { SimpleFormContent } from \"@webiny/app-admin\";\nimport { SimpleForm } from \"@webiny/app-admin\";\nimport { useToast } from \"@webiny/admin-ui\";\nimport { WebhookSettingsPresenterFeature } from \"../feature.js\";\nimport { GetWebhookSettingsFeature } from \"~/admin/features/getWebhookSettings/feature.js\";\nimport { UpdateWebhookSettingsFeature } from \"~/admin/features/updateWebhookSettings/feature.js\";\n\nconst WebhookSettingsViewInner = observer(function WebhookSettingsViewInner() {\n const { presenter } = useFeature(WebhookSettingsPresenterFeature);\n const toast = useToast();\n\n useEffect(() => {\n void presenter.init();\n }, [presenter]);\n\n const { vm } = presenter;\n\n const handleSave = async () => {\n const success = await presenter.save();\n if (success) {\n toast.showSuccessToast({\n title: \"Webhooks settings saved successfully!\"\n });\n }\n };\n\n return (\n <CenteredView>\n <FormErrors form={vm.form} />\n <SimpleForm>\n {vm.loading ? <OverlayLoader text={\"Loading settings...\"} /> : null}\n {vm.saving ? <OverlayLoader text={\"Saving settings...\"} /> : null}\n <SimpleFormHeader title=\"Webhooks Settings\" />\n <SimpleFormContent>\n <FormView name=\"WebhooksSettings\" form={vm.form} />\n </SimpleFormContent>\n <SimpleFormFooter>\n <Button text={\"Save settings\"} onClick={handleSave} />\n </SimpleFormFooter>\n </SimpleForm>\n </CenteredView>\n );\n});\n\nexport const WebhookSettingsView = () => {\n const container = useContainer();\n\n const scopedContainer = useMemo(() => {\n const child = container.createChildContainer();\n GetWebhookSettingsFeature.register(child);\n UpdateWebhookSettingsFeature.register(child);\n WebhookSettingsPresenterFeature.register(child);\n return child;\n }, []);\n\n return (\n <DiContainerProvider container={scopedContainer}>\n <WebhookSettingsViewInner />\n </DiContainerProvider>\n );\n};\n"],"names":["WebhookSettingsViewInner","observer","presenter","useFeature","WebhookSettingsPresenterFeature","toast","useToast","useEffect","vm","handleSave","success","CenteredView","FormErrors","SimpleForm","OverlayLoader","SimpleFormHeader","SimpleFormContent","FormView","SimpleFormFooter","Button","WebhookSettingsView","container","useContainer","scopedContainer","useMemo","child","GetWebhookSettingsFeature","UpdateWebhookSettingsFeature","DiContainerProvider"],"mappings":";;;;;;;;;AAeA,MAAMA,+CAA2BC,SAAS;IACtC,MAAM,EAAEC,SAAS,EAAE,GAAGC,WAAWC;IACjC,MAAMC,QAAQC;IAEdC,UAAU;QACDL,UAAU,IAAI;IACvB,GAAG;QAACA;KAAU;IAEd,MAAM,EAAEM,EAAE,EAAE,GAAGN;IAEf,MAAMO,aAAa;QACf,MAAMC,UAAU,MAAMR,UAAU,IAAI;QACpC,IAAIQ,SACAL,MAAM,gBAAgB,CAAC;YACnB,OAAO;QACX;IAER;IAEA,OAAO,WAAP,GACI,oBAACM,cAAYA,MAAAA,WAAAA,GACT,oBAACC,YAAUA;QAAC,MAAMJ,GAAG,IAAI;sBACzB,oBAACK,YAAUA,MACNL,GAAG,OAAO,GAAG,WAAH,GAAG,oBAACM,eAAaA;QAAC,MAAM;SAA4B,MAC9DN,GAAG,MAAM,GAAG,WAAH,GAAG,oBAACM,eAAaA;QAAC,MAAM;SAA2B,oBAC7D,oBAACC,kBAAgBA;QAAC,OAAM;sBACxB,oBAACC,mBAAiBA,MAAAA,WAAAA,GACd,oBAACC,UAAQA;QAAC,MAAK;QAAmB,MAAMT,GAAG,IAAI;uBAEnD,oBAACU,kBAAgBA,MAAAA,WAAAA,GACb,oBAACC,QAAMA;QAAC,MAAM;QAAiB,SAASV;;AAK5D;AAEO,MAAMW,sBAAsB;IAC/B,MAAMC,YAAYC;IAElB,MAAMC,kBAAkBC,QAAQ;QAC5B,MAAMC,QAAQJ,UAAU,oBAAoB;QAC5CK,0BAA0B,QAAQ,CAACD;QACnCE,6BAA6B,QAAQ,CAACF;QACtCrB,gCAAgC,QAAQ,CAACqB;QACzC,OAAOA;IACX,GAAG,EAAE;IAEL,OAAO,WAAP,GACI,oBAACG,qBAAmBA;QAAC,WAAWL;qBAC5B,oBAACvB,8CAAwBA;AAGrC"}
@@ -0,0 +1,3 @@
1
+ export declare const WebhookSettingsPresenterFeature: import("@webiny/feature/admin").FeatureDefinition<{
2
+ presenter: import("./abstractions.js").IWebhookSettingsPresenter;
3
+ }, []>;
@@ -0,0 +1,17 @@
1
+ import { createFeature } from "@webiny/feature/admin";
2
+ import { WebhookSettingsPresenter } from "./abstractions.js";
3
+ import { WebhookSettingsPresenter as external_WebhookSettingsPresenter_js_WebhookSettingsPresenter } from "./WebhookSettingsPresenter.js";
4
+ const WebhookSettingsPresenterFeature = createFeature({
5
+ name: "Webhooks/WebhookSettingsPresenter",
6
+ register (container) {
7
+ container.register(external_WebhookSettingsPresenter_js_WebhookSettingsPresenter).inSingletonScope();
8
+ },
9
+ resolve (container) {
10
+ return {
11
+ presenter: container.resolve(WebhookSettingsPresenter)
12
+ };
13
+ }
14
+ });
15
+ export { WebhookSettingsPresenterFeature };
16
+
17
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin/presentation/WebhookSettings/feature.js","sources":["../../../../src/admin/presentation/WebhookSettings/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/admin\";\nimport { WebhookSettingsPresenter as PresenterAbstraction } from \"./abstractions.js\";\nimport { WebhookSettingsPresenter } from \"./WebhookSettingsPresenter.js\";\n\nexport const WebhookSettingsPresenterFeature = createFeature({\n name: \"Webhooks/WebhookSettingsPresenter\",\n register(container) {\n container.register(WebhookSettingsPresenter).inSingletonScope();\n },\n resolve(container) {\n return {\n presenter: container.resolve(PresenterAbstraction)\n };\n }\n});\n"],"names":["WebhookSettingsPresenterFeature","createFeature","container","WebhookSettingsPresenter","PresenterAbstraction"],"mappings":";;;AAIO,MAAMA,kCAAkCC,cAAc;IACzD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,+DAA0B,gBAAgB;IACjE;IACA,SAAQD,SAAS;QACb,OAAO;YACH,WAAWA,UAAU,OAAO,CAACE;QACjC;IACJ;AACJ"}
@@ -0,0 +1,2 @@
1
+ export { WebhookSettingsPresenter } from "./abstractions.js";
2
+ export { WebhookSettingsPresenterFeature } from "./feature.js";
@@ -0,0 +1,2 @@
1
+ export { WebhookSettingsPresenter } from "./abstractions.js";
2
+ export { WebhookSettingsPresenterFeature } from "./feature.js";
package/admin/routes.d.ts CHANGED
@@ -4,4 +4,5 @@ export declare const Routes: {
4
4
  Form: Route<{
5
5
  id: import("zod").ZodString;
6
6
  }>;
7
+ Settings: Route<undefined>;
7
8
  };
package/admin/routes.js CHANGED
@@ -10,6 +10,10 @@ const Routes = {
10
10
  params: (zod)=>({
11
11
  id: zod.string()
12
12
  })
13
+ }),
14
+ Settings: new Route({
15
+ name: "Webhooks/Settings",
16
+ path: "/webhooks/settings"
13
17
  })
14
18
  };
15
19
  export { Routes };
@@ -1 +1 @@
1
- {"version":3,"file":"admin/routes.js","sources":["../../src/admin/routes.ts"],"sourcesContent":["import { Route } from \"@webiny/app-admin\";\n\nexport const Routes = {\n List: new Route({\n name: \"Webhooks/List\",\n path: \"/webhooks\"\n }),\n Form: new Route({\n name: \"Webhooks/Form\",\n path: \"/webhooks/:id\",\n params: zod => ({\n id: zod.string()\n })\n })\n};\n"],"names":["Routes","Route","zod"],"mappings":";AAEO,MAAMA,SAAS;IAClB,MAAM,IAAIC,MAAM;QACZ,MAAM;QACN,MAAM;IACV;IACA,MAAM,IAAIA,MAAM;QACZ,MAAM;QACN,MAAM;QACN,QAAQC,CAAAA,MAAQ;gBACZ,IAAIA,IAAI,MAAM;YAClB;IACJ;AACJ"}
1
+ {"version":3,"file":"admin/routes.js","sources":["../../src/admin/routes.ts"],"sourcesContent":["import { Route } from \"@webiny/app-admin\";\n\nexport const Routes = {\n List: new Route({\n name: \"Webhooks/List\",\n path: \"/webhooks\"\n }),\n Form: new Route({\n name: \"Webhooks/Form\",\n path: \"/webhooks/:id\",\n params: zod => ({\n id: zod.string()\n })\n }),\n Settings: new Route({\n name: \"Webhooks/Settings\",\n path: \"/webhooks/settings\"\n })\n};\n"],"names":["Routes","Route","zod"],"mappings":";AAEO,MAAMA,SAAS;IAClB,MAAM,IAAIC,MAAM;QACZ,MAAM;QACN,MAAM;IACV;IACA,MAAM,IAAIA,MAAM;QACZ,MAAM;QACN,MAAM;QACN,QAAQC,CAAAA,MAAQ;gBACZ,IAAIA,IAAI,MAAM;YAClB;IACJ;IACA,UAAU,IAAID,MAAM;QAChB,MAAM;QACN,MAAM;IACV;AACJ"}
@@ -3,3 +3,6 @@ export type { ListWebhooksParams, ListWebhooksResult } from "@webiny/sdk";
3
3
  export type { ListWebhookDeliveriesParams, ListWebhookDeliveriesResult } from "@webiny/sdk";
4
4
  export type { CreateWebhookParams } from "@webiny/sdk";
5
5
  export type { UpdateWebhookParams } from "@webiny/sdk";
6
+ export interface WebhookSettings {
7
+ signingSecret: string | undefined;
8
+ }
@@ -1,6 +1,7 @@
1
1
  import { createFeature } from "@webiny/feature/api";
2
2
  import { WebhookModel } from "./models/WebhookModel.js";
3
3
  import { WebhookDeliveryModel } from "./models/WebhookDeliveryModel.js";
4
+ import { WebhookSettingsModel } from "./models/WebhookSettingsModel.js";
4
5
  import { WebhookCrudSchema } from "./graphql/WebhookCrudSchema.js";
5
6
  import { WebhookDeliverySchema } from "./graphql/WebhookDeliverySchema.js";
6
7
  import { WebhookEventSchema } from "./graphql/WebhookEventSchema.js";
@@ -19,21 +20,28 @@ import { TriggerWebhookFeature } from "./features/TriggerWebhook/feature.js";
19
20
  import { ListAvailableWebhookEventsFeature } from "./features/ListAvailableWebhookEvents/feature.js";
20
21
  import { WebhookPermissionsFeature } from "./features/WebhookPermissions/feature.js";
21
22
  import { WebhookSignPayloadFeature } from "./features/WebhookSignPayload/feature.js";
23
+ import { WebhookDeliverFeature } from "./features/WebhookDeliver/feature.js";
22
24
  import { WebhookDispatcherFeature } from "./features/WebhookDispatcher/feature.js";
23
25
  import { SendWebhookTaskFeature } from "./features/SendWebhookTask/feature.js";
24
26
  import { WebhooksTransformerFeature } from "./features/Transformers/feature.js";
27
+ import { GetWebhookSettingsFeature } from "./features/GetWebhookSettings/feature.js";
28
+ import { UpdateWebhookSettingsFeature } from "./features/UpdateWebhookSettings/feature.js";
29
+ import { WebhookSettingsSchema } from "./graphql/WebhookSettingsSchema.js";
25
30
  const WebhooksFeature = createFeature({
26
31
  name: "WebhookManagement",
27
32
  register (container) {
28
33
  container.register(WebhookModel);
29
34
  container.register(WebhookDeliveryModel);
35
+ container.register(WebhookSettingsModel);
30
36
  WebhooksTransformerFeature.register(container);
31
37
  container.register(WebhookCrudSchema);
32
38
  container.register(WebhookDeliverySchema);
33
39
  container.register(WebhookEventSchema);
34
40
  container.register(WebhookTriggerSchema);
41
+ container.register(WebhookSettingsSchema);
35
42
  WebhookPermissionsFeature.register(container);
36
43
  WebhookSignPayloadFeature.register(container);
44
+ WebhookDeliverFeature.register(container);
37
45
  WebhookDispatcherFeature.register(container);
38
46
  SendWebhookTaskFeature.register(container);
39
47
  CreateWebhookFeature.register(container);
@@ -48,6 +56,8 @@ const WebhooksFeature = createFeature({
48
56
  ResendWebhookDeliveryFeature.register(container);
49
57
  TriggerWebhookFeature.register(container);
50
58
  ListAvailableWebhookEventsFeature.register(container);
59
+ GetWebhookSettingsFeature.register(container);
60
+ UpdateWebhookSettingsFeature.register(container);
51
61
  }
52
62
  });
53
63
  export { WebhooksFeature };
@@ -1 +1 @@
1
- {"version":3,"file":"api/WebhooksFeature.js","sources":["../../src/api/WebhooksFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { WebhookModel } from \"./models/WebhookModel.js\";\nimport { WebhookDeliveryModel } from \"./models/WebhookDeliveryModel.js\";\nimport { WebhookCrudSchema } from \"./graphql/WebhookCrudSchema.js\";\nimport { WebhookDeliverySchema } from \"./graphql/WebhookDeliverySchema.js\";\nimport { WebhookEventSchema } from \"./graphql/WebhookEventSchema.js\";\nimport { WebhookTriggerSchema } from \"./graphql/WebhookTriggerSchema.js\";\nimport { CreateWebhookFeature } from \"./features/CreateWebhook/feature.js\";\nimport { GetWebhookFeature } from \"./features/GetWebhook/feature.js\";\nimport { ListWebhooksFeature } from \"./features/ListWebhooks/feature.js\";\nimport { UpdateWebhookFeature } from \"./features/UpdateWebhook/feature.js\";\nimport { DeleteWebhookFeature } from \"./features/DeleteWebhook/feature.js\";\nimport { CreateWebhookDeliveryFeature } from \"./features/CreateWebhookDelivery/feature.js\";\nimport { UpdateWebhookDeliveryFeature } from \"./features/UpdateWebhookDelivery/feature.js\";\nimport { GetWebhookDeliveryFeature } from \"./features/GetWebhookDelivery/feature.js\";\nimport { ListWebhookDeliveriesFeature } from \"./features/ListWebhookDeliveries/feature.js\";\nimport { ResendWebhookDeliveryFeature } from \"./features/ResendWebhookDelivery/feature.js\";\nimport { TriggerWebhookFeature } from \"./features/TriggerWebhook/feature.js\";\nimport { ListAvailableWebhookEventsFeature } from \"./features/ListAvailableWebhookEvents/feature.js\";\nimport { WebhookPermissionsFeature } from \"./features/WebhookPermissions/feature.js\";\nimport { WebhookSignPayloadFeature } from \"./features/WebhookSignPayload/feature.js\";\nimport { WebhookDispatcherFeature } from \"./features/WebhookDispatcher/feature.js\";\nimport { SendWebhookTaskFeature } from \"./features/SendWebhookTask/feature.js\";\nimport { WebhooksTransformerFeature } from \"./features/Transformers/feature.js\";\n\nexport const WebhooksFeature = createFeature({\n name: \"WebhookManagement\",\n register(container) {\n // CMS models.\n container.register(WebhookModel);\n container.register(WebhookDeliveryModel);\n\n // Transformers\n WebhooksTransformerFeature.register(container);\n\n // GraphQL.\n container.register(WebhookCrudSchema);\n container.register(WebhookDeliverySchema);\n container.register(WebhookEventSchema);\n container.register(WebhookTriggerSchema);\n\n // Core implementations.\n WebhookPermissionsFeature.register(container);\n WebhookSignPayloadFeature.register(container);\n WebhookDispatcherFeature.register(container);\n SendWebhookTaskFeature.register(container);\n\n // Webhook CRUD.\n CreateWebhookFeature.register(container);\n GetWebhookFeature.register(container);\n ListWebhooksFeature.register(container);\n UpdateWebhookFeature.register(container);\n DeleteWebhookFeature.register(container);\n\n // Delivery log.\n CreateWebhookDeliveryFeature.register(container);\n UpdateWebhookDeliveryFeature.register(container);\n GetWebhookDeliveryFeature.register(container);\n ListWebhookDeliveriesFeature.register(container);\n ResendWebhookDeliveryFeature.register(container);\n\n // Trigger + events.\n TriggerWebhookFeature.register(container);\n ListAvailableWebhookEventsFeature.register(container);\n }\n});\n"],"names":["WebhooksFeature","createFeature","container","WebhookModel","WebhookDeliveryModel","WebhooksTransformerFeature","WebhookCrudSchema","WebhookDeliverySchema","WebhookEventSchema","WebhookTriggerSchema","WebhookPermissionsFeature","WebhookSignPayloadFeature","WebhookDispatcherFeature","SendWebhookTaskFeature","CreateWebhookFeature","GetWebhookFeature","ListWebhooksFeature","UpdateWebhookFeature","DeleteWebhookFeature","CreateWebhookDeliveryFeature","UpdateWebhookDeliveryFeature","GetWebhookDeliveryFeature","ListWebhookDeliveriesFeature","ResendWebhookDeliveryFeature","TriggerWebhookFeature","ListAvailableWebhookEventsFeature"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyBO,MAAMA,kBAAkBC,cAAc;IACzC,MAAM;IACN,UAASC,SAAS;QAEdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QAGnBC,2BAA2B,QAAQ,CAACH;QAGpCA,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QAGnBC,0BAA0B,QAAQ,CAACR;QACnCS,0BAA0B,QAAQ,CAACT;QACnCU,yBAAyB,QAAQ,CAACV;QAClCW,uBAAuB,QAAQ,CAACX;QAGhCY,qBAAqB,QAAQ,CAACZ;QAC9Ba,kBAAkB,QAAQ,CAACb;QAC3Bc,oBAAoB,QAAQ,CAACd;QAC7Be,qBAAqB,QAAQ,CAACf;QAC9BgB,qBAAqB,QAAQ,CAAChB;QAG9BiB,6BAA6B,QAAQ,CAACjB;QACtCkB,6BAA6B,QAAQ,CAAClB;QACtCmB,0BAA0B,QAAQ,CAACnB;QACnCoB,6BAA6B,QAAQ,CAACpB;QACtCqB,6BAA6B,QAAQ,CAACrB;QAGtCsB,sBAAsB,QAAQ,CAACtB;QAC/BuB,kCAAkC,QAAQ,CAACvB;IAC/C;AACJ"}
1
+ {"version":3,"file":"api/WebhooksFeature.js","sources":["../../src/api/WebhooksFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { WebhookModel } from \"./models/WebhookModel.js\";\nimport { WebhookDeliveryModel } from \"./models/WebhookDeliveryModel.js\";\nimport { WebhookSettingsModel } from \"./models/WebhookSettingsModel.js\";\nimport { WebhookCrudSchema } from \"./graphql/WebhookCrudSchema.js\";\nimport { WebhookDeliverySchema } from \"./graphql/WebhookDeliverySchema.js\";\nimport { WebhookEventSchema } from \"./graphql/WebhookEventSchema.js\";\nimport { WebhookTriggerSchema } from \"./graphql/WebhookTriggerSchema.js\";\nimport { CreateWebhookFeature } from \"./features/CreateWebhook/feature.js\";\nimport { GetWebhookFeature } from \"./features/GetWebhook/feature.js\";\nimport { ListWebhooksFeature } from \"./features/ListWebhooks/feature.js\";\nimport { UpdateWebhookFeature } from \"./features/UpdateWebhook/feature.js\";\nimport { DeleteWebhookFeature } from \"./features/DeleteWebhook/feature.js\";\nimport { CreateWebhookDeliveryFeature } from \"./features/CreateWebhookDelivery/feature.js\";\nimport { UpdateWebhookDeliveryFeature } from \"./features/UpdateWebhookDelivery/feature.js\";\nimport { GetWebhookDeliveryFeature } from \"./features/GetWebhookDelivery/feature.js\";\nimport { ListWebhookDeliveriesFeature } from \"./features/ListWebhookDeliveries/feature.js\";\nimport { ResendWebhookDeliveryFeature } from \"./features/ResendWebhookDelivery/feature.js\";\nimport { TriggerWebhookFeature } from \"./features/TriggerWebhook/feature.js\";\nimport { ListAvailableWebhookEventsFeature } from \"./features/ListAvailableWebhookEvents/feature.js\";\nimport { WebhookPermissionsFeature } from \"./features/WebhookPermissions/feature.js\";\nimport { WebhookSignPayloadFeature } from \"./features/WebhookSignPayload/feature.js\";\nimport { WebhookDeliverFeature } from \"./features/WebhookDeliver/feature.js\";\nimport { WebhookDispatcherFeature } from \"./features/WebhookDispatcher/feature.js\";\nimport { SendWebhookTaskFeature } from \"./features/SendWebhookTask/feature.js\";\nimport { WebhooksTransformerFeature } from \"./features/Transformers/feature.js\";\nimport { GetWebhookSettingsFeature } from \"./features/GetWebhookSettings/feature.js\";\nimport { UpdateWebhookSettingsFeature } from \"./features/UpdateWebhookSettings/feature.js\";\nimport { WebhookSettingsSchema } from \"./graphql/WebhookSettingsSchema.js\";\n\nexport const WebhooksFeature = createFeature({\n name: \"WebhookManagement\",\n register(container) {\n // CMS models.\n container.register(WebhookModel);\n container.register(WebhookDeliveryModel);\n container.register(WebhookSettingsModel);\n\n // Transformers\n WebhooksTransformerFeature.register(container);\n\n // GraphQL.\n container.register(WebhookCrudSchema);\n container.register(WebhookDeliverySchema);\n container.register(WebhookEventSchema);\n container.register(WebhookTriggerSchema);\n container.register(WebhookSettingsSchema);\n\n // Core implementations.\n WebhookPermissionsFeature.register(container);\n WebhookSignPayloadFeature.register(container);\n WebhookDeliverFeature.register(container);\n WebhookDispatcherFeature.register(container);\n SendWebhookTaskFeature.register(container);\n\n // Webhook CRUD.\n CreateWebhookFeature.register(container);\n GetWebhookFeature.register(container);\n ListWebhooksFeature.register(container);\n UpdateWebhookFeature.register(container);\n DeleteWebhookFeature.register(container);\n\n // Delivery log.\n CreateWebhookDeliveryFeature.register(container);\n UpdateWebhookDeliveryFeature.register(container);\n GetWebhookDeliveryFeature.register(container);\n ListWebhookDeliveriesFeature.register(container);\n ResendWebhookDeliveryFeature.register(container);\n\n // Trigger + events.\n TriggerWebhookFeature.register(container);\n ListAvailableWebhookEventsFeature.register(container);\n\n // Settings.\n GetWebhookSettingsFeature.register(container);\n UpdateWebhookSettingsFeature.register(container);\n }\n});\n"],"names":["WebhooksFeature","createFeature","container","WebhookModel","WebhookDeliveryModel","WebhookSettingsModel","WebhooksTransformerFeature","WebhookCrudSchema","WebhookDeliverySchema","WebhookEventSchema","WebhookTriggerSchema","WebhookSettingsSchema","WebhookPermissionsFeature","WebhookSignPayloadFeature","WebhookDeliverFeature","WebhookDispatcherFeature","SendWebhookTaskFeature","CreateWebhookFeature","GetWebhookFeature","ListWebhooksFeature","UpdateWebhookFeature","DeleteWebhookFeature","CreateWebhookDeliveryFeature","UpdateWebhookDeliveryFeature","GetWebhookDeliveryFeature","ListWebhookDeliveriesFeature","ResendWebhookDeliveryFeature","TriggerWebhookFeature","ListAvailableWebhookEventsFeature","GetWebhookSettingsFeature","UpdateWebhookSettingsFeature"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BO,MAAMA,kBAAkBC,cAAc;IACzC,MAAM;IACN,UAASC,SAAS;QAEdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QAGnBC,2BAA2B,QAAQ,CAACJ;QAGpCA,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;QACnBR,UAAU,QAAQ,CAACS;QAGnBC,0BAA0B,QAAQ,CAACV;QACnCW,0BAA0B,QAAQ,CAACX;QACnCY,sBAAsB,QAAQ,CAACZ;QAC/Ba,yBAAyB,QAAQ,CAACb;QAClCc,uBAAuB,QAAQ,CAACd;QAGhCe,qBAAqB,QAAQ,CAACf;QAC9BgB,kBAAkB,QAAQ,CAAChB;QAC3BiB,oBAAoB,QAAQ,CAACjB;QAC7BkB,qBAAqB,QAAQ,CAAClB;QAC9BmB,qBAAqB,QAAQ,CAACnB;QAG9BoB,6BAA6B,QAAQ,CAACpB;QACtCqB,6BAA6B,QAAQ,CAACrB;QACtCsB,0BAA0B,QAAQ,CAACtB;QACnCuB,6BAA6B,QAAQ,CAACvB;QACtCwB,6BAA6B,QAAQ,CAACxB;QAGtCyB,sBAAsB,QAAQ,CAACzB;QAC/B0B,kCAAkC,QAAQ,CAAC1B;QAG3C2B,0BAA0B,QAAQ,CAAC3B;QACnC4B,6BAA6B,QAAQ,CAAC5B;IAC1C;AACJ"}
@@ -0,0 +1,3 @@
1
+ export interface IWebhookSettings {
2
+ signingSecret: string | undefined;
3
+ }
File without changes
@@ -1,4 +1,5 @@
1
1
  export declare const WEBHOOK_MODEL_ID = "webhook";
2
2
  export declare const WEBHOOK_DELIVERY_MODEL_ID = "webhookDelivery";
3
+ export declare const WEBHOOK_SETTINGS_MODEL_ID = "webhookSettings";
3
4
  export declare const SEND_WEBHOOK_TASK = "sendWebhook";
4
5
  export declare const WEBHOOK_DELIVERY_RETENTION_DAYS = 90;
@@ -1,7 +1,8 @@
1
1
  const WEBHOOK_MODEL_ID = "webhook";
2
2
  const WEBHOOK_DELIVERY_MODEL_ID = "webhookDelivery";
3
+ const WEBHOOK_SETTINGS_MODEL_ID = "webhookSettings";
3
4
  const SEND_WEBHOOK_TASK = "sendWebhook";
4
5
  const WEBHOOK_DELIVERY_RETENTION_DAYS = 90;
5
- export { SEND_WEBHOOK_TASK, WEBHOOK_DELIVERY_MODEL_ID, WEBHOOK_DELIVERY_RETENTION_DAYS, WEBHOOK_MODEL_ID };
6
+ export { SEND_WEBHOOK_TASK, WEBHOOK_DELIVERY_MODEL_ID, WEBHOOK_DELIVERY_RETENTION_DAYS, WEBHOOK_MODEL_ID, WEBHOOK_SETTINGS_MODEL_ID };
6
7
 
7
8
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"api/domain/constants.js","sources":["../../../src/api/domain/constants.ts"],"sourcesContent":["export const WEBHOOK_MODEL_ID = \"webhook\";\nexport const WEBHOOK_DELIVERY_MODEL_ID = \"webhookDelivery\";\nexport const SEND_WEBHOOK_TASK = \"sendWebhook\";\nexport const WEBHOOK_DELIVERY_RETENTION_DAYS = 90;\n"],"names":["WEBHOOK_MODEL_ID","WEBHOOK_DELIVERY_MODEL_ID","SEND_WEBHOOK_TASK","WEBHOOK_DELIVERY_RETENTION_DAYS"],"mappings":"AAAO,MAAMA,mBAAmB;AACzB,MAAMC,4BAA4B;AAClC,MAAMC,oBAAoB;AAC1B,MAAMC,kCAAkC"}
1
+ {"version":3,"file":"api/domain/constants.js","sources":["../../../src/api/domain/constants.ts"],"sourcesContent":["export const WEBHOOK_MODEL_ID = \"webhook\";\nexport const WEBHOOK_DELIVERY_MODEL_ID = \"webhookDelivery\";\nexport const WEBHOOK_SETTINGS_MODEL_ID = \"webhookSettings\";\nexport const SEND_WEBHOOK_TASK = \"sendWebhook\";\nexport const WEBHOOK_DELIVERY_RETENTION_DAYS = 90;\n"],"names":["WEBHOOK_MODEL_ID","WEBHOOK_DELIVERY_MODEL_ID","WEBHOOK_SETTINGS_MODEL_ID","SEND_WEBHOOK_TASK","WEBHOOK_DELIVERY_RETENTION_DAYS"],"mappings":"AAAO,MAAMA,mBAAmB;AACzB,MAAMC,4BAA4B;AAClC,MAAMC,4BAA4B;AAClC,MAAMC,oBAAoB;AAC1B,MAAMC,kCAAkC"}
@@ -1,4 +1,6 @@
1
1
  import { BaseError } from "@webiny/feature/api";
2
+ import type { ZodError } from "zod";
3
+ import type { ValidationIssue } from "@webiny/utils";
2
4
  export declare class WebhookNotFoundError extends BaseError {
3
5
  readonly code: "WEBHOOK_NOT_FOUND";
4
6
  constructor(id: string);
@@ -7,9 +9,12 @@ export declare class WebhookDeliveryNotFoundError extends BaseError {
7
9
  readonly code: "WEBHOOK_DELIVERY_NOT_FOUND";
8
10
  constructor(id: string);
9
11
  }
10
- export declare class WebhookValidationError extends BaseError {
12
+ interface WebhookValidationErrorData {
13
+ issues: ValidationIssue[];
14
+ }
15
+ export declare class WebhookValidationError extends BaseError<WebhookValidationErrorData> {
11
16
  readonly code: "WEBHOOK_VALIDATION_ERROR";
12
- constructor(message: string);
17
+ constructor(error: string | ZodError);
13
18
  }
14
19
  interface WebhookPersistenceErrorData {
15
20
  originalMessage: string;
@@ -1,4 +1,5 @@
1
1
  import { BaseError } from "@webiny/feature/api";
2
+ import { parseZodError } from "@webiny/utils";
2
3
  class WebhookNotFoundError extends BaseError {
3
4
  constructor(id){
4
5
  super({
@@ -14,10 +15,22 @@ class WebhookDeliveryNotFoundError extends BaseError {
14
15
  }
15
16
  }
16
17
  class WebhookValidationError extends BaseError {
17
- constructor(message){
18
- super({
19
- message
18
+ constructor(error){
19
+ if ("string" == typeof error) super({
20
+ message: error,
21
+ data: {
22
+ issues: []
23
+ }
20
24
  }), this.code = "WEBHOOK_VALIDATION_ERROR";
25
+ else {
26
+ const issues = parseZodError(error);
27
+ super({
28
+ message: "Validation failed.",
29
+ data: {
30
+ issues
31
+ }
32
+ }), this.code = "WEBHOOK_VALIDATION_ERROR";
33
+ }
21
34
  }
22
35
  }
23
36
  class WebhookPersistenceError extends BaseError {
@@ -1 +1 @@
1
- {"version":3,"file":"api/domain/errors.js","sources":["../../../src/api/domain/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\nexport class WebhookNotFoundError extends BaseError {\n override readonly code = \"WEBHOOK_NOT_FOUND\" as const;\n\n constructor(id: string) {\n super({ message: `Webhook \"${id}\" was not found.` });\n }\n}\n\nexport class WebhookDeliveryNotFoundError extends BaseError {\n override readonly code = \"WEBHOOK_DELIVERY_NOT_FOUND\" as const;\n\n constructor(id: string) {\n super({ message: `Webhook delivery \"${id}\" was not found.` });\n }\n}\n\nexport class WebhookValidationError extends BaseError {\n override readonly code = \"WEBHOOK_VALIDATION_ERROR\" as const;\n\n constructor(message: string) {\n super({ message });\n }\n}\n\ninterface WebhookPersistenceErrorData {\n originalMessage: string;\n originalCode?: string;\n originalData?: unknown;\n}\n\nexport class WebhookPersistenceError extends BaseError<WebhookPersistenceErrorData> {\n override readonly code = \"WEBHOOK_PERSISTENCE_ERROR\" as const;\n\n constructor(error: Error) {\n super({ message: error.message, data: { originalMessage: error.message } });\n }\n\n static from(error: unknown): WebhookPersistenceError {\n if (error instanceof Error) {\n const instance = new WebhookPersistenceError(error);\n const data: WebhookPersistenceErrorData = {\n originalMessage: error.message,\n originalCode: (error as any).code,\n originalData: (error as any).data\n };\n (instance as any).data = data;\n instance.stack = error.stack;\n return instance;\n }\n\n return new WebhookPersistenceError(new Error(String(error)));\n }\n}\n\nexport class WebhookModelNotFoundError extends BaseError {\n override readonly code = \"WEBHOOK_MODEL_NOT_FOUND\" as const;\n\n constructor(modelId: string) {\n super({ message: `Webhook model \"${modelId}\" was not found.` });\n }\n}\n\nexport class WebhookVerificationFailedError extends BaseError {\n override readonly code = \"WEBHOOK_VERIFICATION_FAILED\" as const;\n\n constructor(message: string) {\n super({ message });\n }\n}\n\nexport class WebhookNotAuthorizedError extends BaseError {\n override readonly code = \"WEBHOOK_NOT_AUTHORIZED\" as const;\n\n constructor() {\n super({ message: \"Not authorized!\" });\n }\n}\n"],"names":["WebhookNotFoundError","BaseError","id","WebhookDeliveryNotFoundError","WebhookValidationError","message","WebhookPersistenceError","error","Error","instance","data","String","WebhookModelNotFoundError","modelId","WebhookVerificationFailedError","WebhookNotAuthorizedError"],"mappings":";AAEO,MAAMA,6BAA6BC;IAGtC,YAAYC,EAAU,CAAE;QACpB,KAAK,CAAC;YAAE,SAAS,CAAC,SAAS,EAAEA,GAAG,gBAAgB,CAAC;QAAC,SAHpC,IAAI,GAAG;IAIzB;AACJ;AAEO,MAAMC,qCAAqCF;IAG9C,YAAYC,EAAU,CAAE;QACpB,KAAK,CAAC;YAAE,SAAS,CAAC,kBAAkB,EAAEA,GAAG,gBAAgB,CAAC;QAAC,SAH7C,IAAI,GAAG;IAIzB;AACJ;AAEO,MAAME,+BAA+BH;IAGxC,YAAYI,OAAe,CAAE;QACzB,KAAK,CAAC;YAAEA;QAAQ,SAHF,IAAI,GAAG;IAIzB;AACJ;AAQO,MAAMC,gCAAgCL;IAGzC,YAAYM,KAAY,CAAE;QACtB,KAAK,CAAC;YAAE,SAASA,MAAM,OAAO;YAAE,MAAM;gBAAE,iBAAiBA,MAAM,OAAO;YAAC;QAAE,SAH3D,IAAI,GAAG;IAIzB;IAEA,OAAO,KAAKA,KAAc,EAA2B;QACjD,IAAIA,iBAAiBC,OAAO;YACxB,MAAMC,WAAW,IAAIH,wBAAwBC;YAC7C,MAAMG,OAAoC;gBACtC,iBAAiBH,MAAM,OAAO;gBAC9B,cAAeA,MAAc,IAAI;gBACjC,cAAeA,MAAc,IAAI;YACrC;YACCE,SAAiB,IAAI,GAAGC;YACzBD,SAAS,KAAK,GAAGF,MAAM,KAAK;YAC5B,OAAOE;QACX;QAEA,OAAO,IAAIH,wBAAwB,IAAIE,MAAMG,OAAOJ;IACxD;AACJ;AAEO,MAAMK,kCAAkCX;IAG3C,YAAYY,OAAe,CAAE;QACzB,KAAK,CAAC;YAAE,SAAS,CAAC,eAAe,EAAEA,QAAQ,gBAAgB,CAAC;QAAC,SAH/C,IAAI,GAAG;IAIzB;AACJ;AAEO,MAAMC,uCAAuCb;IAGhD,YAAYI,OAAe,CAAE;QACzB,KAAK,CAAC;YAAEA;QAAQ,SAHF,IAAI,GAAG;IAIzB;AACJ;AAEO,MAAMU,kCAAkCd;IAG3C,aAAc;QACV,KAAK,CAAC;YAAE,SAAS;QAAkB,SAHrB,IAAI,GAAG;IAIzB;AACJ"}
1
+ {"version":3,"file":"api/domain/errors.js","sources":["../../../src/api/domain/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\nimport type { ZodError } from \"zod\";\nimport { parseZodError } from \"@webiny/utils\";\nimport type { ValidationIssue } from \"@webiny/utils\";\n\nexport class WebhookNotFoundError extends BaseError {\n override readonly code = \"WEBHOOK_NOT_FOUND\" as const;\n\n constructor(id: string) {\n super({ message: `Webhook \"${id}\" was not found.` });\n }\n}\n\nexport class WebhookDeliveryNotFoundError extends BaseError {\n override readonly code = \"WEBHOOK_DELIVERY_NOT_FOUND\" as const;\n\n constructor(id: string) {\n super({ message: `Webhook delivery \"${id}\" was not found.` });\n }\n}\n\ninterface WebhookValidationErrorData {\n issues: ValidationIssue[];\n}\n\nexport class WebhookValidationError extends BaseError<WebhookValidationErrorData> {\n override readonly code = \"WEBHOOK_VALIDATION_ERROR\" as const;\n\n constructor(error: string | ZodError) {\n if (typeof error === \"string\") {\n super({ message: error, data: { issues: [] } });\n } else {\n const issues = parseZodError(error);\n super({ message: \"Validation failed.\", data: { issues } });\n }\n }\n}\n\ninterface WebhookPersistenceErrorData {\n originalMessage: string;\n originalCode?: string;\n originalData?: unknown;\n}\n\nexport class WebhookPersistenceError extends BaseError<WebhookPersistenceErrorData> {\n override readonly code = \"WEBHOOK_PERSISTENCE_ERROR\" as const;\n\n constructor(error: Error) {\n super({ message: error.message, data: { originalMessage: error.message } });\n }\n\n static from(error: unknown): WebhookPersistenceError {\n if (error instanceof Error) {\n const instance = new WebhookPersistenceError(error);\n const data: WebhookPersistenceErrorData = {\n originalMessage: error.message,\n originalCode: (error as any).code,\n originalData: (error as any).data\n };\n (instance as any).data = data;\n instance.stack = error.stack;\n return instance;\n }\n\n return new WebhookPersistenceError(new Error(String(error)));\n }\n}\n\nexport class WebhookModelNotFoundError extends BaseError {\n override readonly code = \"WEBHOOK_MODEL_NOT_FOUND\" as const;\n\n constructor(modelId: string) {\n super({ message: `Webhook model \"${modelId}\" was not found.` });\n }\n}\n\nexport class WebhookVerificationFailedError extends BaseError {\n override readonly code = \"WEBHOOK_VERIFICATION_FAILED\" as const;\n\n constructor(message: string) {\n super({ message });\n }\n}\n\nexport class WebhookNotAuthorizedError extends BaseError {\n override readonly code = \"WEBHOOK_NOT_AUTHORIZED\" as const;\n\n constructor() {\n super({ message: \"Not authorized!\" });\n }\n}\n"],"names":["WebhookNotFoundError","BaseError","id","WebhookDeliveryNotFoundError","WebhookValidationError","error","issues","parseZodError","WebhookPersistenceError","Error","instance","data","String","WebhookModelNotFoundError","modelId","WebhookVerificationFailedError","message","WebhookNotAuthorizedError"],"mappings":";;AAKO,MAAMA,6BAA6BC;IAGtC,YAAYC,EAAU,CAAE;QACpB,KAAK,CAAC;YAAE,SAAS,CAAC,SAAS,EAAEA,GAAG,gBAAgB,CAAC;QAAC,SAHpC,IAAI,GAAG;IAIzB;AACJ;AAEO,MAAMC,qCAAqCF;IAG9C,YAAYC,EAAU,CAAE;QACpB,KAAK,CAAC;YAAE,SAAS,CAAC,kBAAkB,EAAEA,GAAG,gBAAgB,CAAC;QAAC,SAH7C,IAAI,GAAG;IAIzB;AACJ;AAMO,MAAME,+BAA+BH;IAGxC,YAAYI,KAAwB,CAAE;QAClC,IAAI,AAAiB,YAAjB,OAAOA,OACP,KAAK,CAAC;YAAE,SAASA;YAAO,MAAM;gBAAE,QAAQ,EAAE;YAAC;QAAE,SAJnC,IAAI,GAAG;aAKd;YACH,MAAMC,SAASC,cAAcF;YAC7B,KAAK,CAAC;gBAAE,SAAS;gBAAsB,MAAM;oBAAEC;gBAAO;YAAE,SAP9C,IAAI,GAAG;QAQrB;IACJ;AACJ;AAQO,MAAME,gCAAgCP;IAGzC,YAAYI,KAAY,CAAE;QACtB,KAAK,CAAC;YAAE,SAASA,MAAM,OAAO;YAAE,MAAM;gBAAE,iBAAiBA,MAAM,OAAO;YAAC;QAAE,SAH3D,IAAI,GAAG;IAIzB;IAEA,OAAO,KAAKA,KAAc,EAA2B;QACjD,IAAIA,iBAAiBI,OAAO;YACxB,MAAMC,WAAW,IAAIF,wBAAwBH;YAC7C,MAAMM,OAAoC;gBACtC,iBAAiBN,MAAM,OAAO;gBAC9B,cAAeA,MAAc,IAAI;gBACjC,cAAeA,MAAc,IAAI;YACrC;YACCK,SAAiB,IAAI,GAAGC;YACzBD,SAAS,KAAK,GAAGL,MAAM,KAAK;YAC5B,OAAOK;QACX;QAEA,OAAO,IAAIF,wBAAwB,IAAIC,MAAMG,OAAOP;IACxD;AACJ;AAEO,MAAMQ,kCAAkCZ;IAG3C,YAAYa,OAAe,CAAE;QACzB,KAAK,CAAC;YAAE,SAAS,CAAC,eAAe,EAAEA,QAAQ,gBAAgB,CAAC;QAAC,SAH/C,IAAI,GAAG;IAIzB;AACJ;AAEO,MAAMC,uCAAuCd;IAGhD,YAAYe,OAAe,CAAE;QACzB,KAAK,CAAC;YAAEA;QAAQ,SAHF,IAAI,GAAG;IAIzB;AACJ;AAEO,MAAMC,kCAAkChB;IAG3C,aAAc;QACV,KAAK,CAAC;YAAE,SAAS;QAAkB,SAHrB,IAAI,GAAG;IAIzB;AACJ"}
@@ -4,9 +4,9 @@ import { ListWebhooksRepository } from "../../../api/features/ListWebhooks/abstr
4
4
  import { WebhookPermissions } from "../../../api/features/WebhookPermissions/abstractions.js";
5
5
  import type { Webhook } from "../../../api/domain/Webhook.js";
6
6
  declare class CreateWebhookUseCaseImpl implements UseCaseAbstraction.Interface {
7
- private permissions;
8
- private repository;
9
- private listWebhooksRepository;
7
+ private readonly permissions;
8
+ private readonly repository;
9
+ private readonly listWebhooksRepository;
10
10
  constructor(permissions: WebhookPermissions.Interface, repository: CreateWebhookRepository.Interface, listWebhooksRepository: ListWebhooksRepository.Interface);
11
11
  execute(input: UseCaseAbstraction.Input): Promise<Result<Webhook, UseCaseAbstraction.Error>>;
12
12
  }
@@ -1,19 +1,10 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { CreateWebhookRepository, CreateWebhookUseCase } from "./abstractions.js";
3
+ import { CreateWebhookInputSchema } from "./schema.js";
3
4
  import { ListWebhooksRepository } from "../ListWebhooks/abstractions.js";
4
5
  import { WebhookPermissions } from "../WebhookPermissions/abstractions.js";
5
6
  import { WebhookNotAuthorizedError, WebhookValidationError } from "../../domain/errors.js";
6
7
  const generateSlug = (name)=>name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 64);
7
- const isValidEndpointUrl = (url)=>{
8
- try {
9
- const parsed = new URL(url);
10
- if ("https:" === parsed.protocol) return true;
11
- if ("http:" === parsed.protocol && ("localhost" === parsed.hostname || "127.0.0.1" === parsed.hostname)) return true;
12
- return false;
13
- } catch {
14
- return false;
15
- }
16
- };
17
8
  class CreateWebhookUseCaseImpl {
18
9
  constructor(permissions, repository, listWebhooksRepository){
19
10
  this.permissions = permissions;
@@ -22,9 +13,9 @@ class CreateWebhookUseCaseImpl {
22
13
  }
23
14
  async execute(input) {
24
15
  if (!await this.permissions.canCreate("webhook")) return Result.fail(new WebhookNotAuthorizedError());
25
- if (!isValidEndpointUrl(input.endpointUrl)) return Result.fail(new WebhookValidationError("Endpoint URL must use HTTPS. HTTP is only allowed for localhost."));
26
- if (!input.events || 0 === input.events.length) return Result.fail(new WebhookValidationError("At least one event must be selected."));
27
- const slug = (input.slug || "").trim() || generateSlug(input.name);
16
+ const parsed = CreateWebhookInputSchema.safeParse(input);
17
+ if (!parsed.success) return Result.fail(new WebhookValidationError(parsed.error));
18
+ const slug = (parsed.data.slug || "").trim() || generateSlug(parsed.data.name);
28
19
  const listResult = await this.listWebhooksRepository.execute({
29
20
  where: {
30
21
  slug
@@ -33,13 +24,13 @@ class CreateWebhookUseCaseImpl {
33
24
  });
34
25
  if (listResult.isOk() && listResult.value.items.length > 0) return Result.fail(new WebhookValidationError(`Slug "${slug}" is already taken.`));
35
26
  const webhook = {
36
- name: input.name,
27
+ name: parsed.data.name,
37
28
  slug,
38
- endpointUrl: input.endpointUrl,
39
- description: input.description,
40
- enabled: input.enabled ?? false,
41
- events: input.events,
42
- signingSecret: input.signingSecret
29
+ endpointUrl: parsed.data.endpointUrl,
30
+ description: parsed.data.description,
31
+ enabled: parsed.data.enabled ?? false,
32
+ events: parsed.data.events,
33
+ signingSecret: parsed.data.signingSecret ?? ""
43
34
  };
44
35
  return this.repository.execute(webhook);
45
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/CreateWebhook/CreateWebhookUseCase.js","sources":["../../../../src/api/features/CreateWebhook/CreateWebhookUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n CreateWebhookRepository,\n CreateWebhookUseCase as UseCaseAbstraction\n} from \"./abstractions.js\";\nimport { ListWebhooksRepository } from \"~/api/features/ListWebhooks/abstractions.js\";\nimport { WebhookPermissions } from \"~/api/features/WebhookPermissions/abstractions.js\";\nimport { WebhookNotAuthorizedError, WebhookValidationError } from \"~/api/domain/errors.js\";\nimport type { Webhook, WebhookCmsEntryValues } from \"~/api/domain/Webhook.js\";\n\nconst generateSlug = (name: string): string => {\n return name\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-|-$/g, \"\")\n .slice(0, 64);\n};\n\nconst isValidEndpointUrl = (url: string): boolean => {\n try {\n const parsed = new URL(url);\n if (parsed.protocol === \"https:\") {\n return true;\n } else if (\n parsed.protocol === \"http:\" &&\n (parsed.hostname === \"localhost\" || parsed.hostname === \"127.0.0.1\")\n ) {\n return true;\n }\n return false;\n } catch {\n return false;\n }\n};\n\nclass CreateWebhookUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private permissions: WebhookPermissions.Interface,\n private repository: CreateWebhookRepository.Interface,\n private listWebhooksRepository: ListWebhooksRepository.Interface\n ) {}\n\n async execute(\n input: UseCaseAbstraction.Input\n ): Promise<Result<Webhook, UseCaseAbstraction.Error>> {\n if (!(await this.permissions.canCreate(\"webhook\"))) {\n return Result.fail(new WebhookNotAuthorizedError());\n }\n\n if (!isValidEndpointUrl(input.endpointUrl)) {\n return Result.fail(\n new WebhookValidationError(\n \"Endpoint URL must use HTTPS. HTTP is only allowed for localhost.\"\n )\n );\n }\n\n if (!input.events || input.events.length === 0) {\n return Result.fail(new WebhookValidationError(\"At least one event must be selected.\"));\n }\n\n const slug = (input.slug || \"\").trim() || generateSlug(input.name);\n\n const listResult = await this.listWebhooksRepository.execute({\n where: {\n slug\n },\n limit: 1\n });\n if (listResult.isOk() && listResult.value.items.length > 0) {\n return Result.fail(new WebhookValidationError(`Slug \"${slug}\" is already taken.`));\n }\n\n const webhook: WebhookCmsEntryValues = {\n name: input.name,\n slug,\n endpointUrl: input.endpointUrl,\n description: input.description,\n enabled: input.enabled ?? false,\n events: input.events,\n signingSecret: input.signingSecret\n };\n\n return this.repository.execute(webhook);\n }\n}\n\nexport const CreateWebhookUseCase = UseCaseAbstraction.createImplementation({\n implementation: CreateWebhookUseCaseImpl,\n dependencies: [WebhookPermissions, CreateWebhookRepository, ListWebhooksRepository]\n});\n"],"names":["generateSlug","name","isValidEndpointUrl","url","parsed","URL","CreateWebhookUseCaseImpl","permissions","repository","listWebhooksRepository","input","Result","WebhookNotAuthorizedError","WebhookValidationError","slug","listResult","webhook","CreateWebhookUseCase","UseCaseAbstraction","WebhookPermissions","CreateWebhookRepository","ListWebhooksRepository"],"mappings":";;;;;AAUA,MAAMA,eAAe,CAACC,OACXA,KACF,WAAW,GACX,OAAO,CAAC,eAAe,KACvB,OAAO,CAAC,UAAU,IAClB,KAAK,CAAC,GAAG;AAGlB,MAAMC,qBAAqB,CAACC;IACxB,IAAI;QACA,MAAMC,SAAS,IAAIC,IAAIF;QACvB,IAAIC,AAAoB,aAApBA,OAAO,QAAQ,EACf,OAAO;QACJ,IACHA,AAAoB,YAApBA,OAAO,QAAQ,IACdA,CAAAA,AAAoB,gBAApBA,OAAO,QAAQ,IAAoBA,AAAoB,gBAApBA,OAAO,QAAQ,AAAe,GAElE,OAAO;QAEX,OAAO;IACX,EAAE,OAAM;QACJ,OAAO;IACX;AACJ;AAEA,MAAME;IACF,YACYC,WAAyC,EACzCC,UAA6C,EAC7CC,sBAAwD,CAClE;aAHUF,WAAW,GAAXA;aACAC,UAAU,GAAVA;aACAC,sBAAsB,GAAtBA;IACT;IAEH,MAAM,QACFC,KAA+B,EACmB;QAClD,IAAI,CAAE,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,YACnC,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,IAAI,CAACV,mBAAmBQ,MAAM,WAAW,GACrC,OAAOC,OAAO,IAAI,CACd,IAAIE,uBACA;QAKZ,IAAI,CAACH,MAAM,MAAM,IAAIA,AAAwB,MAAxBA,MAAM,MAAM,CAAC,MAAM,EACpC,OAAOC,OAAO,IAAI,CAAC,IAAIE,uBAAuB;QAGlD,MAAMC,OAAQJ,AAAAA,CAAAA,MAAM,IAAI,IAAI,EAAC,EAAG,IAAI,MAAMV,aAAaU,MAAM,IAAI;QAEjE,MAAMK,aAAa,MAAM,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC;YACzD,OAAO;gBACHD;YACJ;YACA,OAAO;QACX;QACA,IAAIC,WAAW,IAAI,MAAMA,WAAW,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,GACrD,OAAOJ,OAAO,IAAI,CAAC,IAAIE,uBAAuB,CAAC,MAAM,EAAEC,KAAK,mBAAmB,CAAC;QAGpF,MAAME,UAAiC;YACnC,MAAMN,MAAM,IAAI;YAChBI;YACA,aAAaJ,MAAM,WAAW;YAC9B,aAAaA,MAAM,WAAW;YAC9B,SAASA,MAAM,OAAO,IAAI;YAC1B,QAAQA,MAAM,MAAM;YACpB,eAAeA,MAAM,aAAa;QACtC;QAEA,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAACM;IACnC;AACJ;AAEO,MAAMC,4CAAuBC,qBAAAA,oBAAuC,CAAC;IACxE,gBAAgBZ;IAChB,cAAc;QAACa;QAAoBC;QAAyBC;KAAuB;AACvF"}
1
+ {"version":3,"file":"api/features/CreateWebhook/CreateWebhookUseCase.js","sources":["../../../../src/api/features/CreateWebhook/CreateWebhookUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n CreateWebhookRepository,\n CreateWebhookUseCase as UseCaseAbstraction\n} from \"./abstractions.js\";\nimport { CreateWebhookInputSchema } from \"./schema.js\";\nimport { ListWebhooksRepository } from \"~/api/features/ListWebhooks/abstractions.js\";\nimport { WebhookPermissions } from \"~/api/features/WebhookPermissions/abstractions.js\";\nimport { WebhookNotAuthorizedError, WebhookValidationError } from \"~/api/domain/errors.js\";\nimport type { Webhook, WebhookCmsEntryValues } from \"~/api/domain/Webhook.js\";\n\nconst generateSlug = (name: string): string => {\n return name\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-|-$/g, \"\")\n .slice(0, 64);\n};\n\nclass CreateWebhookUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private readonly permissions: WebhookPermissions.Interface,\n private readonly repository: CreateWebhookRepository.Interface,\n private readonly listWebhooksRepository: ListWebhooksRepository.Interface\n ) {}\n\n async execute(\n input: UseCaseAbstraction.Input\n ): Promise<Result<Webhook, UseCaseAbstraction.Error>> {\n if (!(await this.permissions.canCreate(\"webhook\"))) {\n return Result.fail(new WebhookNotAuthorizedError());\n }\n\n const parsed = CreateWebhookInputSchema.safeParse(input);\n if (!parsed.success) {\n return Result.fail(new WebhookValidationError(parsed.error));\n }\n\n const slug = (parsed.data.slug || \"\").trim() || generateSlug(parsed.data.name);\n\n const listResult = await this.listWebhooksRepository.execute({\n where: {\n slug\n },\n limit: 1\n });\n if (listResult.isOk() && listResult.value.items.length > 0) {\n return Result.fail(new WebhookValidationError(`Slug \"${slug}\" is already taken.`));\n }\n\n const webhook: WebhookCmsEntryValues = {\n name: parsed.data.name,\n slug,\n endpointUrl: parsed.data.endpointUrl,\n description: parsed.data.description,\n enabled: parsed.data.enabled ?? false,\n events: parsed.data.events,\n signingSecret: parsed.data.signingSecret ?? \"\"\n };\n\n return this.repository.execute(webhook);\n }\n}\n\nexport const CreateWebhookUseCase = UseCaseAbstraction.createImplementation({\n implementation: CreateWebhookUseCaseImpl,\n dependencies: [WebhookPermissions, CreateWebhookRepository, ListWebhooksRepository]\n});\n"],"names":["generateSlug","name","CreateWebhookUseCaseImpl","permissions","repository","listWebhooksRepository","input","Result","WebhookNotAuthorizedError","parsed","CreateWebhookInputSchema","WebhookValidationError","slug","listResult","webhook","CreateWebhookUseCase","UseCaseAbstraction","WebhookPermissions","CreateWebhookRepository","ListWebhooksRepository"],"mappings":";;;;;;AAWA,MAAMA,eAAe,CAACC,OACXA,KACF,WAAW,GACX,OAAO,CAAC,eAAe,KACvB,OAAO,CAAC,UAAU,IAClB,KAAK,CAAC,GAAG;AAGlB,MAAMC;IACF,YACqBC,WAAyC,EACzCC,UAA6C,EAC7CC,sBAAwD,CAC3E;aAHmBF,WAAW,GAAXA;aACAC,UAAU,GAAVA;aACAC,sBAAsB,GAAtBA;IAClB;IAEH,MAAM,QACFC,KAA+B,EACmB;QAClD,IAAI,CAAE,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,YACnC,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,SAASC,yBAAyB,SAAS,CAACJ;QAClD,IAAI,CAACG,OAAO,OAAO,EACf,OAAOF,OAAO,IAAI,CAAC,IAAII,uBAAuBF,OAAO,KAAK;QAG9D,MAAMG,OAAQH,AAAAA,CAAAA,OAAO,IAAI,CAAC,IAAI,IAAI,EAAC,EAAG,IAAI,MAAMT,aAAaS,OAAO,IAAI,CAAC,IAAI;QAE7E,MAAMI,aAAa,MAAM,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC;YACzD,OAAO;gBACHD;YACJ;YACA,OAAO;QACX;QACA,IAAIC,WAAW,IAAI,MAAMA,WAAW,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,GACrD,OAAON,OAAO,IAAI,CAAC,IAAII,uBAAuB,CAAC,MAAM,EAAEC,KAAK,mBAAmB,CAAC;QAGpF,MAAME,UAAiC;YACnC,MAAML,OAAO,IAAI,CAAC,IAAI;YACtBG;YACA,aAAaH,OAAO,IAAI,CAAC,WAAW;YACpC,aAAaA,OAAO,IAAI,CAAC,WAAW;YACpC,SAASA,OAAO,IAAI,CAAC,OAAO,IAAI;YAChC,QAAQA,OAAO,IAAI,CAAC,MAAM;YAC1B,eAAeA,OAAO,IAAI,CAAC,aAAa,IAAI;QAChD;QAEA,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAACK;IACnC;AACJ;AAEO,MAAMC,4CAAuBC,qBAAAA,oBAAuC,CAAC;IACxE,gBAAgBd;IAChB,cAAc;QAACe;QAAoBC;QAAyBC;KAAuB;AACvF"}
@@ -8,7 +8,7 @@ export interface ICreateWebhookInput {
8
8
  description?: string;
9
9
  enabled?: boolean;
10
10
  events: string[];
11
- signingSecret: string;
11
+ signingSecret?: string;
12
12
  }
13
13
  type IError = WebhookValidationError | WebhookPersistenceError | WebhookModelNotFoundError | WebhookNotAuthorizedError;
14
14
  export interface ICreateWebhookUseCase {
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/CreateWebhook/abstractions.js","sources":["../../../../src/api/features/CreateWebhook/abstractions.ts"],"sourcesContent":["import { createAbstraction, type Result } from \"@webiny/feature/api\";\nimport type { Webhook, WebhookCmsEntryValues } from \"~/api/domain/Webhook.js\";\nimport type {\n WebhookModelNotFoundError,\n WebhookNotAuthorizedError,\n WebhookPersistenceError,\n WebhookValidationError\n} from \"~/api/domain/errors.js\";\n\nexport interface ICreateWebhookInput {\n name: string;\n slug?: string;\n endpointUrl: string;\n description?: string;\n enabled?: boolean;\n events: string[];\n signingSecret: string;\n}\n\ntype IError =\n | WebhookValidationError\n | WebhookPersistenceError\n | WebhookModelNotFoundError\n | WebhookNotAuthorizedError;\n\nexport interface ICreateWebhookUseCase {\n execute(input: ICreateWebhookInput): Promise<Result<Webhook, IError>>;\n}\n\nexport const CreateWebhookUseCase = createAbstraction<ICreateWebhookUseCase>(\n \"Webhooks/CreateWebhookUseCase\"\n);\n\nexport namespace CreateWebhookUseCase {\n export type Interface = ICreateWebhookUseCase;\n export type Input = ICreateWebhookInput;\n export type Error = IError;\n}\n\nexport type ICreateWebhookRepositoryResponse = Result<\n Webhook,\n WebhookPersistenceError | WebhookModelNotFoundError\n>;\n\nexport interface ICreateWebhookRepository {\n execute(input: WebhookCmsEntryValues): Promise<ICreateWebhookRepositoryResponse>;\n}\n\nexport const CreateWebhookRepository = createAbstraction<ICreateWebhookRepository>(\n \"Webhooks/CreateWebhookRepository\"\n);\n\nexport namespace CreateWebhookRepository {\n export type Interface = ICreateWebhookRepository;\n export type Response = ICreateWebhookRepositoryResponse;\n export type Error = WebhookPersistenceError | WebhookModelNotFoundError;\n}\n"],"names":["CreateWebhookUseCase","createAbstraction","CreateWebhookRepository"],"mappings":";AA6BO,MAAMA,uBAAuBC,kBAChC;AAkBG,MAAMC,0BAA0BD,kBACnC"}
1
+ {"version":3,"file":"api/features/CreateWebhook/abstractions.js","sources":["../../../../src/api/features/CreateWebhook/abstractions.ts"],"sourcesContent":["import { createAbstraction, type Result } from \"@webiny/feature/api\";\nimport type { Webhook, WebhookCmsEntryValues } from \"~/api/domain/Webhook.js\";\nimport type {\n WebhookModelNotFoundError,\n WebhookNotAuthorizedError,\n WebhookPersistenceError,\n WebhookValidationError\n} from \"~/api/domain/errors.js\";\n\nexport interface ICreateWebhookInput {\n name: string;\n slug?: string;\n endpointUrl: string;\n description?: string;\n enabled?: boolean;\n events: string[];\n signingSecret?: string;\n}\n\ntype IError =\n | WebhookValidationError\n | WebhookPersistenceError\n | WebhookModelNotFoundError\n | WebhookNotAuthorizedError;\n\nexport interface ICreateWebhookUseCase {\n execute(input: ICreateWebhookInput): Promise<Result<Webhook, IError>>;\n}\n\nexport const CreateWebhookUseCase = createAbstraction<ICreateWebhookUseCase>(\n \"Webhooks/CreateWebhookUseCase\"\n);\n\nexport namespace CreateWebhookUseCase {\n export type Interface = ICreateWebhookUseCase;\n export type Input = ICreateWebhookInput;\n export type Error = IError;\n}\n\nexport type ICreateWebhookRepositoryResponse = Result<\n Webhook,\n WebhookPersistenceError | WebhookModelNotFoundError\n>;\n\nexport interface ICreateWebhookRepository {\n execute(input: WebhookCmsEntryValues): Promise<ICreateWebhookRepositoryResponse>;\n}\n\nexport const CreateWebhookRepository = createAbstraction<ICreateWebhookRepository>(\n \"Webhooks/CreateWebhookRepository\"\n);\n\nexport namespace CreateWebhookRepository {\n export type Interface = ICreateWebhookRepository;\n export type Response = ICreateWebhookRepositoryResponse;\n export type Error = WebhookPersistenceError | WebhookModelNotFoundError;\n}\n"],"names":["CreateWebhookUseCase","createAbstraction","CreateWebhookRepository"],"mappings":";AA6BO,MAAMA,uBAAuBC,kBAChC;AAkBG,MAAMC,0BAA0BD,kBACnC"}
@@ -0,0 +1,10 @@
1
+ import { z } from "zod";
2
+ export declare const CreateWebhookInputSchema: z.ZodObject<{
3
+ name: z.ZodString;
4
+ slug: z.ZodOptional<z.ZodString>;
5
+ endpointUrl: z.ZodString;
6
+ description: z.ZodOptional<z.ZodString>;
7
+ enabled: z.ZodOptional<z.ZodBoolean>;
8
+ events: z.ZodArray<z.ZodString>;
9
+ signingSecret: z.ZodOptional<z.ZodString>;
10
+ }, z.core.$strip>;
@@ -0,0 +1,16 @@
1
+ import { z } from "zod";
2
+ import { isValidEndpointUrl } from "../../utils/isValidEndpointUrl.js";
3
+ const CreateWebhookInputSchema = z.object({
4
+ name: z.string().min(1, "Name is required."),
5
+ slug: z.string().optional(),
6
+ endpointUrl: z.string().refine(isValidEndpointUrl, {
7
+ message: "Endpoint URL must use HTTPS. HTTP is only allowed for localhost."
8
+ }),
9
+ description: z.string().optional(),
10
+ enabled: z.boolean().optional(),
11
+ events: z.array(z.string()).min(1, "At least one event must be selected."),
12
+ signingSecret: z.string().optional()
13
+ });
14
+ export { CreateWebhookInputSchema };
15
+
16
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/features/CreateWebhook/schema.js","sources":["../../../../src/api/features/CreateWebhook/schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { isValidEndpointUrl } from \"~/api/utils/isValidEndpointUrl.js\";\n\nexport const CreateWebhookInputSchema = z.object({\n name: z.string().min(1, \"Name is required.\"),\n slug: z.string().optional(),\n endpointUrl: z.string().refine(isValidEndpointUrl, {\n message: \"Endpoint URL must use HTTPS. HTTP is only allowed for localhost.\"\n }),\n description: z.string().optional(),\n enabled: z.boolean().optional(),\n events: z.array(z.string()).min(1, \"At least one event must be selected.\"),\n signingSecret: z.string().optional()\n});\n"],"names":["CreateWebhookInputSchema","z","isValidEndpointUrl"],"mappings":";;AAGO,MAAMA,2BAA2BC,EAAE,MAAM,CAAC;IAC7C,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG;IACxB,MAAMA,EAAE,MAAM,GAAG,QAAQ;IACzB,aAAaA,EAAE,MAAM,GAAG,MAAM,CAACC,oBAAoB;QAC/C,SAAS;IACb;IACA,aAAaD,EAAE,MAAM,GAAG,QAAQ;IAChC,SAASA,EAAE,OAAO,GAAG,QAAQ;IAC7B,QAAQA,EAAE,KAAK,CAACA,EAAE,MAAM,IAAI,GAAG,CAAC,GAAG;IACnC,eAAeA,EAAE,MAAM,GAAG,QAAQ;AACtC"}
@@ -3,9 +3,9 @@ import { DeleteWebhookUseCase as UseCaseAbstraction, DeleteWebhookRepository } f
3
3
  import { GetWebhookRepository } from "../../../api/features/GetWebhook/abstractions.js";
4
4
  import { WebhookPermissions } from "../../../api/features/WebhookPermissions/abstractions.js";
5
5
  declare class DeleteWebhookUseCaseImpl implements UseCaseAbstraction.Interface {
6
- private permissions;
7
- private getWebhookRepository;
8
- private deleteRepository;
6
+ private readonly permissions;
7
+ private readonly getWebhookRepository;
8
+ private readonly deleteRepository;
9
9
  constructor(permissions: WebhookPermissions.Interface, getWebhookRepository: GetWebhookRepository.Interface, deleteRepository: DeleteWebhookRepository.Interface);
10
10
  execute(id: string): Promise<Result<boolean, UseCaseAbstraction.Error>>;
11
11
  }
@@ -1,8 +1,9 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { DeleteWebhookRepository, DeleteWebhookUseCase } from "./abstractions.js";
3
+ import { DeleteWebhookInputSchema } from "./schema.js";
3
4
  import { GetWebhookRepository } from "../GetWebhook/abstractions.js";
4
5
  import { WebhookPermissions } from "../WebhookPermissions/abstractions.js";
5
- import { WebhookNotAuthorizedError } from "../../domain/errors.js";
6
+ import { WebhookNotAuthorizedError, WebhookValidationError } from "../../domain/errors.js";
6
7
  class DeleteWebhookUseCaseImpl {
7
8
  constructor(permissions, getWebhookRepository, deleteRepository){
8
9
  this.permissions = permissions;
@@ -11,9 +12,13 @@ class DeleteWebhookUseCaseImpl {
11
12
  }
12
13
  async execute(id) {
13
14
  if (!await this.permissions.canDelete("webhook")) return Result.fail(new WebhookNotAuthorizedError());
14
- const getResult = await this.getWebhookRepository.execute(id);
15
+ const parsed = DeleteWebhookInputSchema.safeParse({
16
+ id
17
+ });
18
+ if (!parsed.success) return Result.fail(new WebhookValidationError(parsed.error));
19
+ const getResult = await this.getWebhookRepository.execute(parsed.data.id);
15
20
  if (getResult.isFail()) return Result.fail(getResult.error);
16
- return this.deleteRepository.execute(id);
21
+ return this.deleteRepository.execute(parsed.data.id);
17
22
  }
18
23
  }
19
24
  const DeleteWebhookUseCase_DeleteWebhookUseCase = DeleteWebhookUseCase.createImplementation({
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/DeleteWebhook/DeleteWebhookUseCase.js","sources":["../../../../src/api/features/DeleteWebhook/DeleteWebhookUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n DeleteWebhookUseCase as UseCaseAbstraction,\n DeleteWebhookRepository\n} from \"./abstractions.js\";\nimport { GetWebhookRepository } from \"~/api/features/GetWebhook/abstractions.js\";\nimport { WebhookPermissions } from \"~/api/features/WebhookPermissions/abstractions.js\";\nimport { WebhookNotAuthorizedError } from \"~/api/domain/errors.js\";\n\nclass DeleteWebhookUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private permissions: WebhookPermissions.Interface,\n private getWebhookRepository: GetWebhookRepository.Interface,\n private deleteRepository: DeleteWebhookRepository.Interface\n ) {}\n\n async execute(id: string): Promise<Result<boolean, UseCaseAbstraction.Error>> {\n if (!(await this.permissions.canDelete(\"webhook\"))) {\n return Result.fail(new WebhookNotAuthorizedError());\n }\n const getResult = await this.getWebhookRepository.execute(id);\n if (getResult.isFail()) {\n return Result.fail(getResult.error);\n }\n return this.deleteRepository.execute(id);\n }\n}\n\nexport const DeleteWebhookUseCase = UseCaseAbstraction.createImplementation({\n implementation: DeleteWebhookUseCaseImpl,\n dependencies: [WebhookPermissions, GetWebhookRepository, DeleteWebhookRepository]\n});\n"],"names":["DeleteWebhookUseCaseImpl","permissions","getWebhookRepository","deleteRepository","id","Result","WebhookNotAuthorizedError","getResult","DeleteWebhookUseCase","UseCaseAbstraction","WebhookPermissions","GetWebhookRepository","DeleteWebhookRepository"],"mappings":";;;;;AASA,MAAMA;IACF,YACYC,WAAyC,EACzCC,oBAAoD,EACpDC,gBAAmD,CAC7D;aAHUF,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;aACAC,gBAAgB,GAAhBA;IACT;IAEH,MAAM,QAAQC,EAAU,EAAsD;QAC1E,IAAI,CAAE,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,YACnC,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAE3B,MAAMC,YAAY,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAACH;QAC1D,IAAIG,UAAU,MAAM,IAChB,OAAOF,OAAO,IAAI,CAACE,UAAU,KAAK;QAEtC,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAACH;IACzC;AACJ;AAEO,MAAMI,4CAAuBC,qBAAAA,oBAAuC,CAAC;IACxE,gBAAgBT;IAChB,cAAc;QAACU;QAAoBC;QAAsBC;KAAwB;AACrF"}
1
+ {"version":3,"file":"api/features/DeleteWebhook/DeleteWebhookUseCase.js","sources":["../../../../src/api/features/DeleteWebhook/DeleteWebhookUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n DeleteWebhookUseCase as UseCaseAbstraction,\n DeleteWebhookRepository\n} from \"./abstractions.js\";\nimport { DeleteWebhookInputSchema } from \"./schema.js\";\nimport { GetWebhookRepository } from \"~/api/features/GetWebhook/abstractions.js\";\nimport { WebhookPermissions } from \"~/api/features/WebhookPermissions/abstractions.js\";\nimport { WebhookNotAuthorizedError, WebhookValidationError } from \"~/api/domain/errors.js\";\n\nclass DeleteWebhookUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private readonly permissions: WebhookPermissions.Interface,\n private readonly getWebhookRepository: GetWebhookRepository.Interface,\n private readonly deleteRepository: DeleteWebhookRepository.Interface\n ) {}\n\n async execute(id: string): Promise<Result<boolean, UseCaseAbstraction.Error>> {\n if (!(await this.permissions.canDelete(\"webhook\"))) {\n return Result.fail(new WebhookNotAuthorizedError());\n }\n\n const parsed = DeleteWebhookInputSchema.safeParse({ id });\n if (!parsed.success) {\n return Result.fail(new WebhookValidationError(parsed.error));\n }\n\n const getResult = await this.getWebhookRepository.execute(parsed.data.id);\n if (getResult.isFail()) {\n return Result.fail(getResult.error);\n }\n\n return this.deleteRepository.execute(parsed.data.id);\n }\n}\n\nexport const DeleteWebhookUseCase = UseCaseAbstraction.createImplementation({\n implementation: DeleteWebhookUseCaseImpl,\n dependencies: [WebhookPermissions, GetWebhookRepository, DeleteWebhookRepository]\n});\n"],"names":["DeleteWebhookUseCaseImpl","permissions","getWebhookRepository","deleteRepository","id","Result","WebhookNotAuthorizedError","parsed","DeleteWebhookInputSchema","WebhookValidationError","getResult","DeleteWebhookUseCase","UseCaseAbstraction","WebhookPermissions","GetWebhookRepository","DeleteWebhookRepository"],"mappings":";;;;;;AAUA,MAAMA;IACF,YACqBC,WAAyC,EACzCC,oBAAoD,EACpDC,gBAAmD,CACtE;aAHmBF,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;aACAC,gBAAgB,GAAhBA;IAClB;IAEH,MAAM,QAAQC,EAAU,EAAsD;QAC1E,IAAI,CAAE,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,YACnC,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,SAASC,yBAAyB,SAAS,CAAC;YAAEJ;QAAG;QACvD,IAAI,CAACG,OAAO,OAAO,EACf,OAAOF,OAAO,IAAI,CAAC,IAAII,uBAAuBF,OAAO,KAAK;QAG9D,MAAMG,YAAY,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAACH,OAAO,IAAI,CAAC,EAAE;QACxE,IAAIG,UAAU,MAAM,IAChB,OAAOL,OAAO,IAAI,CAACK,UAAU,KAAK;QAGtC,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAACH,OAAO,IAAI,CAAC,EAAE;IACvD;AACJ;AAEO,MAAMI,4CAAuBC,qBAAAA,oBAAuC,CAAC;IACxE,gBAAgBZ;IAChB,cAAc;QAACa;QAAoBC;QAAsBC;KAAwB;AACrF"}