@hed-hog/core 0.0.355 → 0.0.358

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 (287) hide show
  1. package/dist/ai/ai.service.d.ts +3 -12
  2. package/dist/ai/ai.service.d.ts.map +1 -1
  3. package/dist/ai/ai.service.js +34 -125
  4. package/dist/ai/ai.service.js.map +1 -1
  5. package/dist/auth/guards/auth.guard.d.ts +6 -1
  6. package/dist/auth/guards/auth.guard.d.ts.map +1 -1
  7. package/dist/auth/guards/auth.guard.js +33 -2
  8. package/dist/auth/guards/auth.guard.js.map +1 -1
  9. package/dist/core.module.d.ts.map +1 -1
  10. package/dist/core.module.js +3 -3
  11. package/dist/core.module.js.map +1 -1
  12. package/dist/file/file.controller.d.ts +4 -2
  13. package/dist/file/file.controller.d.ts.map +1 -1
  14. package/dist/file/file.controller.js +44 -38
  15. package/dist/file/file.controller.js.map +1 -1
  16. package/dist/file/file.service.d.ts +2 -2
  17. package/dist/file/file.service.d.ts.map +1 -1
  18. package/dist/file/file.service.js +58 -89
  19. package/dist/file/file.service.js.map +1 -1
  20. package/dist/file/provider/azure.provider.d.ts.map +1 -1
  21. package/dist/file/provider/azure.provider.js +10 -15
  22. package/dist/file/provider/azure.provider.js.map +1 -1
  23. package/dist/file/provider/gcs.provider.d.ts.map +1 -1
  24. package/dist/file/provider/gcs.provider.js +8 -9
  25. package/dist/file/provider/gcs.provider.js.map +1 -1
  26. package/dist/file/provider/local.provider.d.ts.map +1 -1
  27. package/dist/file/provider/local.provider.js +11 -10
  28. package/dist/file/provider/local.provider.js.map +1 -1
  29. package/dist/file/provider/provider.enum.d.ts +2 -1
  30. package/dist/file/provider/provider.enum.d.ts.map +1 -1
  31. package/dist/file/provider/provider.enum.js +1 -0
  32. package/dist/file/provider/provider.enum.js.map +1 -1
  33. package/dist/file/provider/provider.factory.d.ts +1 -1
  34. package/dist/file/provider/provider.factory.d.ts.map +1 -1
  35. package/dist/file/provider/provider.factory.js +18 -5
  36. package/dist/file/provider/provider.factory.js.map +1 -1
  37. package/dist/file/provider/s3.provider.d.ts.map +1 -1
  38. package/dist/file/provider/s3.provider.js +4 -20
  39. package/dist/file/provider/s3.provider.js.map +1 -1
  40. package/dist/file/provider/spaces.provider.d.ts +27 -0
  41. package/dist/file/provider/spaces.provider.d.ts.map +1 -0
  42. package/dist/file/provider/spaces.provider.js +203 -0
  43. package/dist/file/provider/spaces.provider.js.map +1 -0
  44. package/dist/index.d.ts +4 -3
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +4 -3
  47. package/dist/index.js.map +1 -1
  48. package/dist/integration-profile/dto/create.dto.d.ts +9 -0
  49. package/dist/integration-profile/dto/create.dto.d.ts.map +1 -0
  50. package/dist/integration-profile/dto/create.dto.js +54 -0
  51. package/dist/integration-profile/dto/create.dto.js.map +1 -0
  52. package/dist/integration-profile/dto/export.dto.d.ts +5 -0
  53. package/dist/integration-profile/dto/export.dto.d.ts.map +1 -0
  54. package/dist/integration-profile/dto/export.dto.js +29 -0
  55. package/dist/integration-profile/dto/export.dto.js.map +1 -0
  56. package/dist/integration-profile/dto/import-confirm.dto.d.ts +17 -0
  57. package/dist/integration-profile/dto/import-confirm.dto.d.ts.map +1 -0
  58. package/dist/integration-profile/dto/import-confirm.dto.js +77 -0
  59. package/dist/integration-profile/dto/import-confirm.dto.js.map +1 -0
  60. package/dist/integration-profile/dto/update.dto.d.ts.map +1 -0
  61. package/dist/integration-profile/dto/update.dto.js.map +1 -0
  62. package/dist/integration-profile/integration-profile.controller.d.ts +142 -0
  63. package/dist/integration-profile/integration-profile.controller.d.ts.map +1 -0
  64. package/dist/integration-profile/integration-profile.controller.js +166 -0
  65. package/dist/integration-profile/integration-profile.controller.js.map +1 -0
  66. package/dist/integration-profile/integration-profile.module.d.ts +3 -0
  67. package/dist/integration-profile/integration-profile.module.d.ts.map +1 -0
  68. package/dist/{mail-profile/mail-profile.module.js → integration-profile/integration-profile.module.js} +11 -13
  69. package/dist/integration-profile/integration-profile.module.js.map +1 -0
  70. package/dist/integration-profile/integration-profile.service.d.ts +160 -0
  71. package/dist/integration-profile/integration-profile.service.d.ts.map +1 -0
  72. package/dist/integration-profile/integration-profile.service.js +609 -0
  73. package/dist/integration-profile/integration-profile.service.js.map +1 -0
  74. package/dist/integration-profile/integration-profile.utils.d.ts +30 -0
  75. package/dist/integration-profile/integration-profile.utils.d.ts.map +1 -0
  76. package/dist/integration-profile/integration-profile.utils.js +156 -0
  77. package/dist/integration-profile/integration-profile.utils.js.map +1 -0
  78. package/dist/mail/mail.module.d.ts.map +1 -1
  79. package/dist/mail/mail.module.js +36 -23
  80. package/dist/mail/mail.module.js.map +1 -1
  81. package/dist/mail/mail.service.d.ts +4 -2
  82. package/dist/mail/mail.service.d.ts.map +1 -1
  83. package/dist/mail/mail.service.js +33 -51
  84. package/dist/mail/mail.service.js.map +1 -1
  85. package/dist/mcp/guards/mcp-auth.guard.js +1 -1
  86. package/dist/mcp/guards/mcp-auth.guard.js.map +1 -1
  87. package/dist/mcp/mcp-api-key.controller.d.ts +2 -0
  88. package/dist/mcp/mcp-api-key.controller.d.ts.map +1 -1
  89. package/dist/mcp/mcp-api-key.controller.js +1 -1
  90. package/dist/mcp/mcp-api-key.controller.js.map +1 -1
  91. package/dist/mcp/mcp-api-key.service.d.ts +2 -1
  92. package/dist/mcp/mcp-api-key.service.d.ts.map +1 -1
  93. package/dist/mcp/mcp-api-key.service.js +6 -2
  94. package/dist/mcp/mcp-api-key.service.js.map +1 -1
  95. package/dist/mcp/mcp.module.d.ts.map +1 -1
  96. package/dist/mcp/mcp.module.js +3 -5
  97. package/dist/mcp/mcp.module.js.map +1 -1
  98. package/dist/mcp-chat/mcp-chat.service.d.ts.map +1 -1
  99. package/dist/mcp-chat/mcp-chat.service.js +17 -16
  100. package/dist/mcp-chat/mcp-chat.service.js.map +1 -1
  101. package/dist/oauth/interfaces/OAuthProvider.d.ts +1 -1
  102. package/dist/oauth/interfaces/OAuthProvider.d.ts.map +1 -1
  103. package/dist/oauth/oauth.controller.d.ts +4 -1
  104. package/dist/oauth/oauth.controller.d.ts.map +1 -1
  105. package/dist/oauth/oauth.controller.js +31 -5
  106. package/dist/oauth/oauth.controller.js.map +1 -1
  107. package/dist/oauth/oauth.service.d.ts +12 -1
  108. package/dist/oauth/oauth.service.d.ts.map +1 -1
  109. package/dist/oauth/oauth.service.js +125 -23
  110. package/dist/oauth/oauth.service.js.map +1 -1
  111. package/dist/oauth/providers/abstract.provider.d.ts +1 -1
  112. package/dist/oauth/providers/abstract.provider.d.ts.map +1 -1
  113. package/dist/oauth/providers/facebook.provider.d.ts +5 -2
  114. package/dist/oauth/providers/facebook.provider.d.ts.map +1 -1
  115. package/dist/oauth/providers/facebook.provider.js +34 -19
  116. package/dist/oauth/providers/facebook.provider.js.map +1 -1
  117. package/dist/oauth/providers/github.provider.d.ts +6 -2
  118. package/dist/oauth/providers/github.provider.d.ts.map +1 -1
  119. package/dist/oauth/providers/github.provider.js +43 -20
  120. package/dist/oauth/providers/github.provider.js.map +1 -1
  121. package/dist/oauth/providers/google.provider.d.ts +5 -2
  122. package/dist/oauth/providers/google.provider.d.ts.map +1 -1
  123. package/dist/oauth/providers/google.provider.js +34 -19
  124. package/dist/oauth/providers/google.provider.js.map +1 -1
  125. package/dist/oauth/providers/microsoft-entra-id.provider.d.ts +5 -2
  126. package/dist/oauth/providers/microsoft-entra-id.provider.d.ts.map +1 -1
  127. package/dist/oauth/providers/microsoft-entra-id.provider.js +43 -40
  128. package/dist/oauth/providers/microsoft-entra-id.provider.js.map +1 -1
  129. package/dist/oauth/providers/microsoft.provider.d.ts +5 -2
  130. package/dist/oauth/providers/microsoft.provider.d.ts.map +1 -1
  131. package/dist/oauth/providers/microsoft.provider.js +34 -19
  132. package/dist/oauth/providers/microsoft.provider.js.map +1 -1
  133. package/dist/profile/profile.controller.js +1 -1
  134. package/dist/profile/profile.controller.js.map +1 -1
  135. package/dist/security/security.service.d.ts +2 -0
  136. package/dist/security/security.service.d.ts.map +1 -1
  137. package/dist/security/security.service.js +21 -0
  138. package/dist/security/security.service.js.map +1 -1
  139. package/dist/setting/setting.service.d.ts +26 -1
  140. package/dist/setting/setting.service.d.ts.map +1 -1
  141. package/dist/setting/setting.service.js +240 -7
  142. package/dist/setting/setting.service.js.map +1 -1
  143. package/dist/user/user.controller.d.ts +2 -1
  144. package/dist/user/user.controller.d.ts.map +1 -1
  145. package/dist/user/user.controller.js +5 -4
  146. package/dist/user/user.controller.js.map +1 -1
  147. package/dist/user/user.service.d.ts +4 -2
  148. package/dist/user/user.service.d.ts.map +1 -1
  149. package/dist/user/user.service.js +19 -4
  150. package/dist/user/user.service.js.map +1 -1
  151. package/dist/webhook-integration/dto/webhook-action.dto.d.ts +17 -2
  152. package/dist/webhook-integration/dto/webhook-action.dto.d.ts.map +1 -1
  153. package/dist/webhook-integration/dto/webhook-action.dto.js +93 -2
  154. package/dist/webhook-integration/dto/webhook-action.dto.js.map +1 -1
  155. package/dist/webhook-integration/event-webhook.controller.d.ts +1 -0
  156. package/dist/webhook-integration/event-webhook.controller.d.ts.map +1 -1
  157. package/dist/webhook-integration/event-webhook.controller.js +10 -0
  158. package/dist/webhook-integration/event-webhook.controller.js.map +1 -1
  159. package/dist/webhook-integration/event-webhook.service.d.ts +2 -0
  160. package/dist/webhook-integration/event-webhook.service.d.ts.map +1 -1
  161. package/dist/webhook-integration/event-webhook.service.js +30 -0
  162. package/dist/webhook-integration/event-webhook.service.js.map +1 -1
  163. package/dist/webhook-integration/webhook-command.registry.d.ts +15 -0
  164. package/dist/webhook-integration/webhook-command.registry.d.ts.map +1 -0
  165. package/dist/webhook-integration/webhook-command.registry.js +36 -0
  166. package/dist/webhook-integration/webhook-command.registry.js.map +1 -0
  167. package/dist/webhook-integration/webhook-integration.controller.d.ts +20 -0
  168. package/dist/webhook-integration/webhook-integration.controller.d.ts.map +1 -1
  169. package/dist/webhook-integration/webhook-integration.controller.js +48 -0
  170. package/dist/webhook-integration/webhook-integration.controller.js.map +1 -1
  171. package/dist/webhook-integration/webhook-integration.module.d.ts.map +1 -1
  172. package/dist/webhook-integration/webhook-integration.module.js +5 -0
  173. package/dist/webhook-integration/webhook-integration.module.js.map +1 -1
  174. package/dist/webhook-integration/webhook-integration.service.d.ts +27 -2
  175. package/dist/webhook-integration/webhook-integration.service.d.ts.map +1 -1
  176. package/dist/webhook-integration/webhook-integration.service.js +377 -50
  177. package/dist/webhook-integration/webhook-integration.service.js.map +1 -1
  178. package/hedhog/data/file_provider.yaml +9 -1
  179. package/hedhog/data/integration_provider.yaml +148 -0
  180. package/hedhog/data/integration_type.yaml +29 -0
  181. package/hedhog/data/menu.yaml +6 -21
  182. package/hedhog/data/role.yaml +8 -0
  183. package/hedhog/data/route.yaml +73 -373
  184. package/hedhog/data/setting_group.yaml +209 -365
  185. package/hedhog/data/setting_subgroup.yaml +21 -13
  186. package/hedhog/frontend/app/account/components/connected-accounts.tsx.ejs +25 -20
  187. package/hedhog/frontend/app/account/components/tokens.tsx.ejs +421 -0
  188. package/hedhog/frontend/app/account/layout.tsx.ejs +6 -3
  189. package/hedhog/frontend/app/account/mcp-tokens/page.tsx.ejs +2 -2
  190. package/hedhog/frontend/app/account/tokens/page.tsx.ejs +5 -0
  191. package/hedhog/frontend/app/configurations/[slug]/components/setting-field.tsx.ejs +938 -225
  192. package/hedhog/frontend/app/configurations/layout.tsx.ejs +1 -1
  193. package/hedhog/frontend/app/dashboard/dashboard-home-tabs.tsx.ejs +3 -1
  194. package/hedhog/frontend/app/integration/profiles/page.tsx.ejs +1830 -0
  195. package/hedhog/frontend/app/integrations-webhooks/page.tsx.ejs +829 -128
  196. package/hedhog/frontend/app/mail/profiles/page.tsx.ejs +1 -820
  197. package/hedhog/frontend/app/setting-list/page.tsx.ejs +229 -395
  198. package/hedhog/frontend/app/users/permissions.tsx.ejs +79 -2
  199. package/hedhog/frontend/app/users/user-sheet.tsx.ejs +7 -2
  200. package/hedhog/frontend/messages/en.json +239 -3
  201. package/hedhog/frontend/messages/pt.json +239 -3
  202. package/hedhog/table/file.yaml +1 -1
  203. package/hedhog/table/integration_profile.yaml +34 -0
  204. package/hedhog/table/integration_provider.yaml +23 -0
  205. package/hedhog/table/integration_type.yaml +19 -0
  206. package/hedhog/table/mcp_api_key.yaml +4 -0
  207. package/hedhog/table/webhook_action.yaml +141 -85
  208. package/package.json +4 -3
  209. package/src/ai/ai.service.ts +35 -153
  210. package/src/auth/guards/auth.guard.ts +32 -0
  211. package/src/core.module.ts +3 -3
  212. package/src/file/file.controller.ts +51 -42
  213. package/src/file/file.service.ts +67 -104
  214. package/src/file/provider/azure.provider.ts +14 -28
  215. package/src/file/provider/gcs.provider.ts +9 -9
  216. package/src/file/provider/local.provider.ts +10 -13
  217. package/src/file/provider/provider.enum.ts +1 -0
  218. package/src/file/provider/provider.factory.ts +21 -6
  219. package/src/file/provider/s3.provider.ts +4 -20
  220. package/src/file/provider/spaces.provider.ts +246 -0
  221. package/src/index.ts +6 -3
  222. package/src/integration-profile/dto/create.dto.ts +44 -0
  223. package/src/integration-profile/dto/export.dto.ts +15 -0
  224. package/src/integration-profile/dto/import-confirm.dto.ts +61 -0
  225. package/src/integration-profile/integration-profile.controller.ts +131 -0
  226. package/src/integration-profile/integration-profile.module.ts +16 -0
  227. package/src/integration-profile/integration-profile.service.ts +793 -0
  228. package/src/integration-profile/integration-profile.utils.ts +173 -0
  229. package/src/mail/mail.module.ts +41 -22
  230. package/src/mail/mail.service.ts +40 -64
  231. package/src/mcp/guards/mcp-auth.guard.ts +1 -1
  232. package/src/mcp/mcp-api-key.controller.ts +2 -2
  233. package/src/mcp/mcp-api-key.service.ts +6 -2
  234. package/src/mcp/mcp.module.ts +3 -5
  235. package/src/mcp-chat/mcp-chat.service.ts +23 -20
  236. package/src/oauth/interfaces/OAuthProvider.ts +1 -1
  237. package/src/oauth/oauth.controller.ts +30 -2
  238. package/src/oauth/oauth.service.ts +194 -35
  239. package/src/oauth/providers/abstract.provider.ts +1 -1
  240. package/src/oauth/providers/facebook.provider.ts +36 -20
  241. package/src/oauth/providers/github.provider.ts +46 -23
  242. package/src/oauth/providers/google.provider.ts +36 -20
  243. package/src/oauth/providers/microsoft-entra-id.provider.ts +42 -46
  244. package/src/oauth/providers/microsoft.provider.ts +36 -21
  245. package/src/profile/profile.controller.ts +2 -2
  246. package/src/security/security.service.ts +34 -1
  247. package/src/setting/setting.service.ts +307 -9
  248. package/src/user/user.controller.ts +4 -1
  249. package/src/user/user.service.ts +20 -2
  250. package/src/webhook-integration/dto/webhook-action.dto.ts +85 -4
  251. package/src/webhook-integration/event-webhook.controller.ts +55 -50
  252. package/src/webhook-integration/event-webhook.service.ts +422 -384
  253. package/src/webhook-integration/webhook-command.registry.ts +42 -0
  254. package/src/webhook-integration/webhook-integration.controller.ts +25 -0
  255. package/src/webhook-integration/webhook-integration.module.ts +50 -45
  256. package/src/webhook-integration/webhook-integration.service.ts +444 -53
  257. package/dist/mail-profile/dto/create.dto.d.ts +0 -23
  258. package/dist/mail-profile/dto/create.dto.d.ts.map +0 -1
  259. package/dist/mail-profile/dto/create.dto.js +0 -139
  260. package/dist/mail-profile/dto/create.dto.js.map +0 -1
  261. package/dist/mail-profile/dto/update.dto.d.ts.map +0 -1
  262. package/dist/mail-profile/dto/update.dto.js.map +0 -1
  263. package/dist/mail-profile/mail-profile.controller.d.ts +0 -94
  264. package/dist/mail-profile/mail-profile.controller.d.ts.map +0 -1
  265. package/dist/mail-profile/mail-profile.controller.js +0 -95
  266. package/dist/mail-profile/mail-profile.controller.js.map +0 -1
  267. package/dist/mail-profile/mail-profile.module.d.ts +0 -3
  268. package/dist/mail-profile/mail-profile.module.d.ts.map +0 -1
  269. package/dist/mail-profile/mail-profile.module.js.map +0 -1
  270. package/dist/mail-profile/mail-profile.service.d.ts +0 -109
  271. package/dist/mail-profile/mail-profile.service.d.ts.map +0 -1
  272. package/dist/mail-profile/mail-profile.service.js +0 -278
  273. package/dist/mail-profile/mail-profile.service.js.map +0 -1
  274. package/dist/mcp/tools/core-mail-profile.mcp-tools.d.ts +0 -32
  275. package/dist/mcp/tools/core-mail-profile.mcp-tools.d.ts.map +0 -1
  276. package/dist/mcp/tools/core-mail-profile.mcp-tools.js +0 -178
  277. package/dist/mcp/tools/core-mail-profile.mcp-tools.js.map +0 -1
  278. package/hedhog/data/mail_profile.yaml +0 -18
  279. package/hedhog/table/mail_profile.yaml +0 -75
  280. package/src/mail-profile/dto/create.dto.ts +0 -145
  281. package/src/mail-profile/mail-profile.controller.ts +0 -56
  282. package/src/mail-profile/mail-profile.module.ts +0 -18
  283. package/src/mail-profile/mail-profile.service.ts +0 -308
  284. package/src/mcp/tools/core-mail-profile.mcp-tools.ts +0 -128
  285. /package/dist/{mail-profile → integration-profile}/dto/update.dto.d.ts +0 -0
  286. /package/dist/{mail-profile → integration-profile}/dto/update.dto.js +0 -0
  287. /package/src/{mail-profile → integration-profile}/dto/update.dto.ts +0 -0
@@ -0,0 +1,246 @@
1
+ import {
2
+ DeleteObjectCommand,
3
+ GetObjectCommand,
4
+ HeadBucketCommand,
5
+ HeadObjectCommand,
6
+ PutObjectCommand,
7
+ S3,
8
+ S3Client,
9
+ } from '@aws-sdk/client-s3';
10
+ import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
11
+ import { BadRequestException } from '@nestjs/common';
12
+ import { createReadStream } from 'fs';
13
+ import { basename } from 'path';
14
+ import { Readable } from 'stream';
15
+ import { AbstractProvider } from './abstract.provider';
16
+
17
+ export class SpacesProvider extends AbstractProvider {
18
+ private S3: S3 | undefined;
19
+ private S3Client: S3Client | undefined;
20
+
21
+ constructor(private setting: Record<string, string>) {
22
+ super();
23
+ }
24
+
25
+ private get endpoint() {
26
+ return `https://${this.setting['storage-spaces-region']}.digitaloceanspaces.com`;
27
+ }
28
+
29
+ private get bucketUrl() {
30
+ const cdn = this.setting['storage-spaces-cdn'];
31
+ if (cdn) {
32
+ return cdn.replace(/\/$/, '');
33
+ }
34
+ return `https://${this.setting['storage-spaces-bucket']}.${this.setting['storage-spaces-region']}.digitaloceanspaces.com`;
35
+ }
36
+
37
+ private resolveKey(filepath: string): string {
38
+ if (!filepath) {
39
+ throw new Error('Invalid filepath for DigitalOcean Spaces');
40
+ }
41
+ return filepath;
42
+ }
43
+
44
+ async initValidation() {
45
+ if (!this.setting['storage-spaces-key']) {
46
+ throw new BadRequestException(
47
+ `You must set the storage-spaces-key in the setting.`,
48
+ );
49
+ }
50
+
51
+ if (!this.setting['storage-spaces-secret']) {
52
+ throw new BadRequestException(
53
+ `You must set the storage-spaces-secret in the setting.`,
54
+ );
55
+ }
56
+
57
+ if (!this.setting['storage-spaces-region']) {
58
+ throw new BadRequestException(
59
+ `You must set the storage-spaces-region in the setting.`,
60
+ );
61
+ }
62
+
63
+ if (!this.setting['storage-spaces-bucket']) {
64
+ throw new BadRequestException(
65
+ `You must set the storage-spaces-bucket in the setting.`,
66
+ );
67
+ }
68
+
69
+ const s3 = await this.getClient();
70
+
71
+ try {
72
+ await s3.send(
73
+ new HeadBucketCommand({
74
+ Bucket: this.setting['storage-spaces-bucket'],
75
+ }),
76
+ );
77
+ } catch (error) {
78
+ throw new BadRequestException(
79
+ `The bucket "${this.setting['storage-spaces-bucket']}" does not exist or you do not have access to it.`,
80
+ );
81
+ }
82
+ }
83
+
84
+ async getClient() {
85
+ if (this.S3) {
86
+ return this.S3;
87
+ }
88
+
89
+ const credentials = {
90
+ accessKeyId: this.setting['storage-spaces-key'],
91
+ secretAccessKey: this.setting['storage-spaces-secret'],
92
+ };
93
+
94
+ this.S3Client = new S3Client({
95
+ credentials,
96
+ endpoint: this.endpoint,
97
+ region: this.setting['storage-spaces-region'],
98
+ forcePathStyle: false,
99
+ });
100
+
101
+ return (this.S3 = new S3({
102
+ credentials,
103
+ endpoint: this.endpoint,
104
+ region: this.setting['storage-spaces-region'],
105
+ forcePathStyle: false,
106
+ }));
107
+ }
108
+
109
+ async getS3Client() {
110
+ if (this.S3Client) {
111
+ return this.S3Client;
112
+ }
113
+
114
+ this.S3Client = new S3Client({
115
+ credentials: {
116
+ accessKeyId: this.setting['storage-spaces-key'],
117
+ secretAccessKey: this.setting['storage-spaces-secret'],
118
+ },
119
+ endpoint: this.endpoint,
120
+ region: this.setting['storage-spaces-region'],
121
+ forcePathStyle: false,
122
+ });
123
+
124
+ return this.S3Client;
125
+ }
126
+
127
+ async buffer(filepath: string): Promise<Buffer> {
128
+ const s3 = await this.getClient();
129
+ const key = this.resolveKey(filepath);
130
+ const result = await s3.send(
131
+ new GetObjectCommand({
132
+ Bucket: this.setting['storage-spaces-bucket'],
133
+ Key: key,
134
+ }),
135
+ );
136
+ // @ts-ignore
137
+ const stream = result.Body as Readable;
138
+ const chunks: Buffer[] = [];
139
+ for await (const chunk of stream) {
140
+ chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
141
+ }
142
+ return Buffer.concat(chunks);
143
+ }
144
+
145
+ async upload(destination: string, file: MulterFile): Promise<any> {
146
+ const s3 = await this.getClient();
147
+ const storedFilename = this.getFilename(file.originalname);
148
+ const key = [destination, storedFilename].join('/');
149
+ await s3.send(
150
+ new PutObjectCommand({
151
+ Bucket: this.setting['storage-spaces-bucket'],
152
+ Key: key,
153
+ Body: file.buffer,
154
+ ACL: 'public-read',
155
+ }),
156
+ );
157
+ return storedFilename;
158
+ }
159
+
160
+ async uploadFromString(
161
+ destination: string,
162
+ filename: string,
163
+ fileContent: string,
164
+ ): Promise<any> {
165
+ const s3 = await this.getClient();
166
+ const storedFilename = this.getFilename(filename);
167
+ const key = [destination, storedFilename].join('/');
168
+ await s3.send(
169
+ new PutObjectCommand({
170
+ Bucket: this.setting['storage-spaces-bucket'],
171
+ Key: key,
172
+ Body: fileContent,
173
+ ACL: 'public-read',
174
+ }),
175
+ );
176
+ return storedFilename;
177
+ }
178
+
179
+ async uploadFromPath(
180
+ destination: string,
181
+ filePath: string,
182
+ options?: { filename?: string; mimetype?: string },
183
+ ): Promise<any> {
184
+ const s3 = await this.getClient();
185
+ const originalName = options?.filename ?? basename(filePath);
186
+ const storedFilename = this.getFilename(originalName);
187
+ const key = [destination, storedFilename].join('/');
188
+ await s3.send(
189
+ new PutObjectCommand({
190
+ Bucket: this.setting['storage-spaces-bucket'],
191
+ Key: key,
192
+ Body: createReadStream(filePath),
193
+ ContentType: options?.mimetype,
194
+ ACL: 'public-read',
195
+ }),
196
+ );
197
+ return storedFilename;
198
+ }
199
+
200
+ async delete(filepath: string): Promise<any> {
201
+ const s3 = await this.getClient();
202
+ const key = this.resolveKey(filepath);
203
+ await s3.send(
204
+ new DeleteObjectCommand({
205
+ Bucket: this.setting['storage-spaces-bucket'],
206
+ Key: key,
207
+ }),
208
+ );
209
+ return true;
210
+ }
211
+
212
+ async readStream(filepath: string): Promise<Readable> {
213
+ const s3 = await this.getClient();
214
+ const key = this.resolveKey(filepath);
215
+ const result = await s3.send(
216
+ new GetObjectCommand({
217
+ Bucket: this.setting['storage-spaces-bucket'],
218
+ Key: key,
219
+ }),
220
+ );
221
+ // @ts-ignore
222
+ return result.Body as Readable;
223
+ }
224
+
225
+ async metaData(filepath: string): Promise<any> {
226
+ const s3 = await this.getClient();
227
+ const key = this.resolveKey(filepath);
228
+ const result = await s3.send(
229
+ new HeadObjectCommand({
230
+ Bucket: this.setting['storage-spaces-bucket'],
231
+ Key: key,
232
+ }),
233
+ );
234
+ return result;
235
+ }
236
+
237
+ async tempURL(filepath: string, expires = 3600): Promise<string> {
238
+ const s3Client = await this.getS3Client();
239
+ const key = this.resolveKey(filepath);
240
+ const command = new GetObjectCommand({
241
+ Bucket: this.setting['storage-spaces-bucket'],
242
+ Key: key,
243
+ });
244
+ return await getSignedUrl(s3Client as any, command, { expiresIn: expires });
245
+ }
246
+ }
package/src/index.ts CHANGED
@@ -19,11 +19,13 @@ export * from './screen/screen.service';
19
19
  export * from './user/constants/user.constants';
20
20
  export * from './user/user.service';
21
21
 
22
- export * from './mail-profile/mail-profile.module';
23
- export * from './mail-profile/mail-profile.service';
24
22
  export * from './mail/mail.module';
25
23
  export * from './mail/mail.service';
26
24
 
25
+ export * from './integration-profile/integration-profile.module';
26
+ export * from './integration-profile/integration-profile.service';
27
+ export * from './integration-profile/integration-profile.utils';
28
+
27
29
  export * from './file/file.module';
28
30
  export * from './file/file.service';
29
31
 
@@ -72,6 +74,7 @@ export * from './utils/locale-context';
72
74
 
73
75
 
74
76
  // Notification Module
77
+ export * from './notification/dto/create-notification.dto';
75
78
  export * from './notification/notification.module';
76
79
  export * from './notification/notification.service';
77
- export * from './notification/dto/create-notification.dto';
80
+
@@ -0,0 +1,44 @@
1
+ import { getLocaleText } from '@hed-hog/api-locale';
2
+ import { Transform, Type } from 'class-transformer';
3
+ import {
4
+ IsBoolean,
5
+ IsInt,
6
+ IsObject,
7
+ IsOptional,
8
+ IsString,
9
+ MaxLength,
10
+ Min,
11
+ } from 'class-validator';
12
+
13
+ export class CreateDTO {
14
+ @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
15
+ @MaxLength(255)
16
+ @Transform(({ value }) => String(value ?? '').trim())
17
+ slug: string;
18
+
19
+ @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
20
+ @MaxLength(127)
21
+ @Transform(({ value }) => String(value ?? '').trim())
22
+ name: string;
23
+
24
+ @IsInt()
25
+ @Min(1)
26
+ @Type(() => Number)
27
+ type_id: number;
28
+
29
+ @IsInt()
30
+ @Min(1)
31
+ @Type(() => Number)
32
+ provider_id: number;
33
+
34
+ @IsOptional()
35
+ @IsObject()
36
+ config?: Record<string, unknown> | null;
37
+
38
+ @IsOptional()
39
+ @IsBoolean()
40
+ @Transform(({ value }) =>
41
+ value === true || value === 'true' || value === 1 || value === '1',
42
+ )
43
+ is_active?: boolean;
44
+ }
@@ -0,0 +1,15 @@
1
+ import { Transform } from 'class-transformer';
2
+ import { IsBoolean, IsOptional, IsString } from 'class-validator';
3
+
4
+ export class ExportDTO {
5
+ @IsOptional()
6
+ @IsString()
7
+ ids?: string;
8
+
9
+ @IsOptional()
10
+ @IsBoolean()
11
+ @Transform(({ value }) =>
12
+ value === true || value === 'true' || value === 1 || value === '1',
13
+ )
14
+ include_secrets?: boolean;
15
+ }
@@ -0,0 +1,61 @@
1
+ import { Type } from 'class-transformer';
2
+ import {
3
+ ArrayNotEmpty,
4
+ IsArray,
5
+ IsBoolean,
6
+ IsIn,
7
+ IsObject,
8
+ IsOptional,
9
+ IsString,
10
+ MaxLength,
11
+ ValidateNested,
12
+ } from 'class-validator';
13
+
14
+ export class ImportProfileItemDTO {
15
+ @IsString()
16
+ @MaxLength(255)
17
+ slug: string;
18
+
19
+ @IsString()
20
+ @MaxLength(127)
21
+ name: string;
22
+
23
+ @IsString()
24
+ @MaxLength(255)
25
+ type_slug: string;
26
+
27
+ @IsString()
28
+ @MaxLength(255)
29
+ provider_slug: string;
30
+
31
+ @IsOptional()
32
+ @IsObject()
33
+ config?: Record<string, unknown> | null;
34
+
35
+ @IsOptional()
36
+ @IsBoolean()
37
+ is_active?: boolean;
38
+ }
39
+
40
+ export class ConflictResolutionDTO {
41
+ @IsString()
42
+ @MaxLength(255)
43
+ slug: string;
44
+
45
+ @IsIn(['ignore', 'replace', 'rename_auto'])
46
+ action: 'ignore' | 'replace' | 'rename_auto';
47
+ }
48
+
49
+ export class ImportConfirmDTO {
50
+ @IsArray()
51
+ @ArrayNotEmpty()
52
+ @ValidateNested({ each: true })
53
+ @Type(() => ImportProfileItemDTO)
54
+ profiles: ImportProfileItemDTO[];
55
+
56
+ @IsOptional()
57
+ @IsArray()
58
+ @ValidateNested({ each: true })
59
+ @Type(() => ConflictResolutionDTO)
60
+ conflict_resolutions?: ConflictResolutionDTO[];
61
+ }
@@ -0,0 +1,131 @@
1
+ import { DeleteDTO, Role } from '@hed-hog/api';
2
+ import { Pagination } from '@hed-hog/api-pagination';
3
+ import {
4
+ Body,
5
+ Controller,
6
+ Delete,
7
+ Get,
8
+ Header,
9
+ Inject,
10
+ Param,
11
+ ParseIntPipe,
12
+ Patch,
13
+ Post,
14
+ Query,
15
+ Res,
16
+ UploadedFile,
17
+ UseInterceptors,
18
+ forwardRef,
19
+ } from '@nestjs/common';
20
+ import { FileInterceptor } from '@nestjs/platform-express';
21
+ import { Response } from 'express';
22
+ import { CreateDTO } from './dto/create.dto';
23
+ import { ExportDTO } from './dto/export.dto';
24
+ import { ImportConfirmDTO } from './dto/import-confirm.dto';
25
+ import { UpdateDTO } from './dto/update.dto';
26
+ import { IntegrationProfileService } from './integration-profile.service';
27
+
28
+ @Role()
29
+ @Controller('integration-profile')
30
+ export class IntegrationProfileController {
31
+ constructor(
32
+ @Inject(forwardRef(() => IntegrationProfileService))
33
+ private readonly integrationProfileService: IntegrationProfileService,
34
+ ) {}
35
+
36
+ @Get('types')
37
+ async listTypes() {
38
+ return this.integrationProfileService.listTypes();
39
+ }
40
+
41
+ @Get('providers')
42
+ async listProviders(
43
+ @Query('typeId') typeId?: string,
44
+ @Query('typeSlug') typeSlug?: string,
45
+ ) {
46
+ return this.integrationProfileService.listProviders(
47
+ typeId ? parseInt(typeId, 10) : undefined,
48
+ typeSlug,
49
+ );
50
+ }
51
+
52
+ @Get()
53
+ async list(
54
+ @Pagination() paginationParams,
55
+ @Query('typeId') typeId?: string,
56
+ @Query('typeSlug') typeSlug?: string,
57
+ @Query('providerSlug') providerSlug?: string,
58
+ ) {
59
+ return this.integrationProfileService.list(
60
+ paginationParams,
61
+ typeId ? parseInt(typeId, 10) : undefined,
62
+ typeSlug,
63
+ providerSlug,
64
+ );
65
+ }
66
+
67
+ @Get('export')
68
+ @Header('Content-Type', 'application/octet-stream')
69
+ @Header(
70
+ 'Content-Disposition',
71
+ 'attachment; filename="integration-profiles.hedhog"',
72
+ )
73
+ async export(
74
+ @Query() { ids, include_secrets = false }: ExportDTO,
75
+ @Res() res: Response,
76
+ ) {
77
+ const parsedIds = String(ids ?? '')
78
+ .split(',')
79
+ .map((value) => Number(value.trim()))
80
+ .filter((value) => Number.isInteger(value) && value > 0);
81
+
82
+ const file = await this.integrationProfileService.exportProfiles({
83
+ ids: parsedIds.length > 0 ? parsedIds : undefined,
84
+ includeSecrets: include_secrets,
85
+ });
86
+
87
+ res.send(file);
88
+ }
89
+
90
+ @Get(':id')
91
+ async get(@Param('id', ParseIntPipe) id: number) {
92
+ return this.integrationProfileService.get(id);
93
+ }
94
+
95
+ @Post()
96
+ async create(@Body() data: CreateDTO) {
97
+ return this.integrationProfileService.create(data);
98
+ }
99
+
100
+ @Post('test')
101
+ async test(@Body() data: CreateDTO) {
102
+ return this.integrationProfileService.test(data);
103
+ }
104
+
105
+ @Patch(':id')
106
+ async update(
107
+ @Param('id', ParseIntPipe) id: number,
108
+ @Body() data: UpdateDTO,
109
+ ) {
110
+ return this.integrationProfileService.update({ id, data });
111
+ }
112
+
113
+ @Delete()
114
+ async delete(@Body() data: DeleteDTO) {
115
+ return this.integrationProfileService.delete(data);
116
+ }
117
+
118
+ @UseInterceptors(FileInterceptor('file'))
119
+ @Post('import/validate')
120
+ async validateImport(@UploadedFile() file: MulterFile) {
121
+ return this.integrationProfileService.validateImportFile(file);
122
+ }
123
+
124
+ @Post('import/confirm')
125
+ async confirmImport(@Body() data: ImportConfirmDTO) {
126
+ return this.integrationProfileService.confirmImport({
127
+ profiles: data.profiles,
128
+ conflictResolutions: data.conflict_resolutions,
129
+ });
130
+ }
131
+ }
@@ -0,0 +1,16 @@
1
+ import { PaginationModule } from '@hed-hog/api-pagination';
2
+ import { PrismaModule } from '@hed-hog/api-prisma';
3
+ import { forwardRef, Module } from '@nestjs/common';
4
+ import { IntegrationProfileController } from './integration-profile.controller';
5
+ import { IntegrationProfileService } from './integration-profile.service';
6
+
7
+ @Module({
8
+ imports: [
9
+ forwardRef(() => PrismaModule),
10
+ forwardRef(() => PaginationModule),
11
+ ],
12
+ controllers: [IntegrationProfileController],
13
+ providers: [IntegrationProfileService],
14
+ exports: [IntegrationProfileService],
15
+ })
16
+ export class IntegrationProfileModule {}