@webda/core 2.0.0-beta.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/lib/application.d.ts +5 -5
  2. package/lib/application.js +71 -84
  3. package/lib/application.js.map +1 -1
  4. package/lib/application.spec.js +121 -140
  5. package/lib/application.spec.js.map +1 -1
  6. package/lib/core.d.ts +20 -24
  7. package/lib/core.js +222 -315
  8. package/lib/core.js.map +1 -1
  9. package/lib/core.spec.js +332 -406
  10. package/lib/core.spec.js.map +1 -1
  11. package/lib/index.d.ts +49 -48
  12. package/lib/index.js +53 -70
  13. package/lib/index.js.map +1 -1
  14. package/lib/models/aclmodel.d.ts +2 -2
  15. package/lib/models/aclmodel.js +63 -90
  16. package/lib/models/aclmodel.js.map +1 -1
  17. package/lib/models/aclmodel.spec.js +127 -152
  18. package/lib/models/aclmodel.spec.js.map +1 -1
  19. package/lib/models/coremodel.d.ts +7 -6
  20. package/lib/models/coremodel.js +65 -113
  21. package/lib/models/coremodel.js.map +1 -1
  22. package/lib/models/coremodel.spec.js +88 -107
  23. package/lib/models/coremodel.spec.js.map +1 -1
  24. package/lib/models/deployment.js +1 -2
  25. package/lib/models/ident.d.ts +3 -3
  26. package/lib/models/ident.js +4 -9
  27. package/lib/models/ident.js.map +1 -1
  28. package/lib/models/ident.spec.js +9 -11
  29. package/lib/models/ident.spec.js.map +1 -1
  30. package/lib/models/ownermodel.d.ts +2 -2
  31. package/lib/models/ownermodel.js +39 -62
  32. package/lib/models/ownermodel.js.map +1 -1
  33. package/lib/models/ownermodel.spec.js +126 -168
  34. package/lib/models/ownermodel.spec.js.map +1 -1
  35. package/lib/models/rolemodel.d.ts +1 -1
  36. package/lib/models/rolemodel.js +24 -40
  37. package/lib/models/rolemodel.js.map +1 -1
  38. package/lib/models/rolemodel.spec.js +44 -63
  39. package/lib/models/rolemodel.spec.js.map +1 -1
  40. package/lib/models/user.d.ts +3 -3
  41. package/lib/models/user.js +3 -8
  42. package/lib/models/user.js.map +1 -1
  43. package/lib/models/user.spec.js +14 -16
  44. package/lib/models/user.spec.js.map +1 -1
  45. package/lib/queues/filequeue.d.ts +2 -2
  46. package/lib/queues/filequeue.js +72 -93
  47. package/lib/queues/filequeue.js.map +1 -1
  48. package/lib/queues/filequeue.spec.js +53 -70
  49. package/lib/queues/filequeue.spec.js.map +1 -1
  50. package/lib/queues/memoryqueue.d.ts +2 -2
  51. package/lib/queues/memoryqueue.js +37 -61
  52. package/lib/queues/memoryqueue.js.map +1 -1
  53. package/lib/queues/memoryqueue.spec.js +142 -165
  54. package/lib/queues/memoryqueue.spec.js.map +1 -1
  55. package/lib/queues/pubsubservice.d.ts +2 -2
  56. package/lib/queues/pubsubservice.js +3 -7
  57. package/lib/queues/pubsubservice.js.map +1 -1
  58. package/lib/queues/queue.spec.d.ts +1 -1
  59. package/lib/queues/queue.spec.js +42 -56
  60. package/lib/queues/queue.spec.js.map +1 -1
  61. package/lib/queues/queueservice.d.ts +3 -3
  62. package/lib/queues/queueservice.js +51 -67
  63. package/lib/queues/queueservice.js.map +1 -1
  64. package/lib/router.d.ts +3 -3
  65. package/lib/router.js +46 -47
  66. package/lib/router.js.map +1 -1
  67. package/lib/router.spec.js +64 -61
  68. package/lib/router.spec.js.map +1 -1
  69. package/lib/services/asyncevents.d.ts +2 -2
  70. package/lib/services/asyncevents.js +44 -64
  71. package/lib/services/asyncevents.js.map +1 -1
  72. package/lib/services/asyncevents.spec.js +81 -98
  73. package/lib/services/asyncevents.spec.js.map +1 -1
  74. package/lib/services/authentication.d.ts +23 -13
  75. package/lib/services/authentication.js +537 -563
  76. package/lib/services/authentication.js.map +1 -1
  77. package/lib/services/authentication.spec.js +411 -447
  78. package/lib/services/authentication.spec.js.map +1 -1
  79. package/lib/services/binary.d.ts +7 -5
  80. package/lib/services/binary.js +211 -244
  81. package/lib/services/binary.js.map +1 -1
  82. package/lib/services/binary.spec.d.ts +3 -3
  83. package/lib/services/binary.spec.js +390 -443
  84. package/lib/services/binary.spec.js.map +1 -1
  85. package/lib/services/cloudbinary.d.ts +3 -3
  86. package/lib/services/cloudbinary.js +45 -70
  87. package/lib/services/cloudbinary.js.map +1 -1
  88. package/lib/services/cloudbinary.spec.d.ts +3 -3
  89. package/lib/services/cloudbinary.spec.js +133 -162
  90. package/lib/services/cloudbinary.spec.js.map +1 -1
  91. package/lib/services/configuration.d.ts +1 -1
  92. package/lib/services/configuration.js +78 -105
  93. package/lib/services/configuration.js.map +1 -1
  94. package/lib/services/configuration.spec.js +63 -83
  95. package/lib/services/configuration.spec.js.map +1 -1
  96. package/lib/services/cron.d.ts +3 -2
  97. package/lib/services/cron.js +9 -13
  98. package/lib/services/cron.js.map +1 -1
  99. package/lib/services/cron.spec.js +18 -21
  100. package/lib/services/cron.spec.js.map +1 -1
  101. package/lib/services/cryptoservice.d.ts +9 -4
  102. package/lib/services/cryptoservice.js +187 -221
  103. package/lib/services/cryptoservice.js.map +1 -1
  104. package/lib/services/cryptoservice.spec.js +88 -115
  105. package/lib/services/cryptoservice.spec.js.map +1 -1
  106. package/lib/services/debugmailer.d.ts +1 -1
  107. package/lib/services/debugmailer.js +13 -34
  108. package/lib/services/debugmailer.js.map +1 -1
  109. package/lib/services/debugmailer.spec.js +16 -29
  110. package/lib/services/debugmailer.spec.js.map +1 -1
  111. package/lib/services/echo.d.ts +2 -2
  112. package/lib/services/echo.js +15 -31
  113. package/lib/services/echo.js.map +1 -1
  114. package/lib/services/echo.spec.js +27 -40
  115. package/lib/services/echo.spec.js.map +1 -1
  116. package/lib/services/filebinary.d.ts +5 -5
  117. package/lib/services/filebinary.js +165 -210
  118. package/lib/services/filebinary.js.map +1 -1
  119. package/lib/services/filebinary.spec.d.ts +2 -1
  120. package/lib/services/filebinary.spec.js +106 -116
  121. package/lib/services/filebinary.spec.js.map +1 -1
  122. package/lib/services/fileconfiguration.d.ts +1 -1
  123. package/lib/services/fileconfiguration.js +25 -44
  124. package/lib/services/fileconfiguration.js.map +1 -1
  125. package/lib/services/fileconfiguration.spec.js +79 -109
  126. package/lib/services/fileconfiguration.spec.js.map +1 -1
  127. package/lib/services/invitationservice.d.ts +7 -7
  128. package/lib/services/invitationservice.js +274 -314
  129. package/lib/services/invitationservice.js.map +1 -1
  130. package/lib/services/invitationservice.spec.js +442 -448
  131. package/lib/services/invitationservice.spec.js.map +1 -1
  132. package/lib/services/kubernetesconfiguration.d.ts +1 -1
  133. package/lib/services/kubernetesconfiguration.js +41 -60
  134. package/lib/services/kubernetesconfiguration.js.map +1 -1
  135. package/lib/services/kubernetesconfiguration.spec.js +80 -98
  136. package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
  137. package/lib/services/mailer.d.ts +4 -4
  138. package/lib/services/mailer.js +62 -86
  139. package/lib/services/mailer.js.map +1 -1
  140. package/lib/services/mailer.spec.js +86 -127
  141. package/lib/services/mailer.spec.js.map +1 -1
  142. package/lib/services/notificationservice.d.ts +3 -3
  143. package/lib/services/notificationservice.js +21 -42
  144. package/lib/services/notificationservice.js.map +1 -1
  145. package/lib/services/notificationservice.spec.js +47 -73
  146. package/lib/services/notificationservice.spec.js.map +1 -1
  147. package/lib/services/oauth.d.ts +4 -4
  148. package/lib/services/oauth.js +68 -83
  149. package/lib/services/oauth.js.map +1 -1
  150. package/lib/services/oauth.spec.js +130 -156
  151. package/lib/services/oauth.spec.js.map +1 -1
  152. package/lib/services/proxy.d.ts +2 -6
  153. package/lib/services/proxy.js +45 -58
  154. package/lib/services/proxy.js.map +1 -1
  155. package/lib/services/proxy.spec.js +34 -53
  156. package/lib/services/proxy.spec.js.map +1 -1
  157. package/lib/services/resource.d.ts +2 -2
  158. package/lib/services/resource.js +12 -18
  159. package/lib/services/resource.js.map +1 -1
  160. package/lib/services/resource.spec.js +67 -99
  161. package/lib/services/resource.spec.js.map +1 -1
  162. package/lib/services/service.d.ts +26 -3
  163. package/lib/services/service.js +68 -40
  164. package/lib/services/service.js.map +1 -1
  165. package/lib/services/service.spec.js +62 -67
  166. package/lib/services/service.spec.js.map +1 -1
  167. package/lib/services/version.d.ts +1 -1
  168. package/lib/services/version.js +3 -8
  169. package/lib/services/version.js.map +1 -1
  170. package/lib/services/version.spec.js +11 -24
  171. package/lib/services/version.spec.js.map +1 -1
  172. package/lib/stores/aggregator.d.ts +2 -2
  173. package/lib/stores/aggregator.js +37 -58
  174. package/lib/stores/aggregator.js.map +1 -1
  175. package/lib/stores/file.d.ts +3 -3
  176. package/lib/stores/file.js +93 -131
  177. package/lib/stores/file.js.map +1 -1
  178. package/lib/stores/file.spec.d.ts +2 -2
  179. package/lib/stores/file.spec.js +261 -289
  180. package/lib/stores/file.spec.js.map +1 -1
  181. package/lib/stores/mapper.d.ts +3 -3
  182. package/lib/stores/mapper.js +110 -137
  183. package/lib/stores/mapper.js.map +1 -1
  184. package/lib/stores/mapper.spec.js +131 -150
  185. package/lib/stores/mapper.spec.js.map +1 -1
  186. package/lib/stores/memory.d.ts +3 -3
  187. package/lib/stores/memory.js +98 -144
  188. package/lib/stores/memory.js.map +1 -1
  189. package/lib/stores/memory.spec.d.ts +2 -2
  190. package/lib/stores/memory.spec.js +124 -145
  191. package/lib/stores/memory.spec.js.map +1 -1
  192. package/lib/stores/store.d.ts +17 -13
  193. package/lib/stores/store.js +819 -847
  194. package/lib/stores/store.js.map +1 -1
  195. package/lib/stores/store.spec.d.ts +5 -4
  196. package/lib/stores/store.spec.js +624 -669
  197. package/lib/stores/store.spec.js.map +1 -1
  198. package/lib/stores/webdaql/WebdaQLLexer.d.ts +4 -4
  199. package/lib/stores/webdaql/WebdaQLLexer.js +9 -13
  200. package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -1
  201. package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +4 -4
  202. package/lib/stores/webdaql/WebdaQLParserLexer.js +9 -13
  203. package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -1
  204. package/lib/stores/webdaql/WebdaQLParserListener.d.ts +2 -2
  205. package/lib/stores/webdaql/WebdaQLParserListener.js +1 -2
  206. package/lib/stores/webdaql/WebdaQLParserListener.js.map +1 -1
  207. package/lib/stores/webdaql/WebdaQLParserParser.d.ts +10 -10
  208. package/lib/stores/webdaql/WebdaQLParserParser.js +62 -91
  209. package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -1
  210. package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +2 -2
  211. package/lib/stores/webdaql/WebdaQLParserVisitor.js +1 -2
  212. package/lib/stores/webdaql/WebdaQLParserVisitor.js.map +1 -1
  213. package/lib/stores/webdaql/query.d.ts +4 -5
  214. package/lib/stores/webdaql/query.js +16 -19
  215. package/lib/stores/webdaql/query.js.map +1 -1
  216. package/lib/stores/webdaql/query.spec.js +30 -32
  217. package/lib/stores/webdaql/query.spec.js.map +1 -1
  218. package/lib/test.d.ts +3 -3
  219. package/lib/test.js +73 -100
  220. package/lib/test.js.map +1 -1
  221. package/lib/unpackedapplication.d.ts +1 -1
  222. package/lib/unpackedapplication.js +25 -31
  223. package/lib/unpackedapplication.js.map +1 -1
  224. package/lib/utils/abstractdeployer.js +1 -5
  225. package/lib/utils/abstractdeployer.js.map +1 -1
  226. package/lib/utils/abstractdeployer.spec.js +6 -8
  227. package/lib/utils/abstractdeployer.spec.js.map +1 -1
  228. package/lib/utils/context.d.ts +7 -5
  229. package/lib/utils/context.js +95 -103
  230. package/lib/utils/context.js.map +1 -1
  231. package/lib/utils/context.spec.js +139 -163
  232. package/lib/utils/context.spec.js.map +1 -1
  233. package/lib/utils/cookie.d.ts +3 -3
  234. package/lib/utils/cookie.js +42 -61
  235. package/lib/utils/cookie.js.map +1 -1
  236. package/lib/utils/cookie.spec.js +42 -64
  237. package/lib/utils/cookie.spec.js.map +1 -1
  238. package/lib/utils/esm.d.ts +4 -0
  239. package/lib/utils/esm.js +10 -0
  240. package/lib/utils/esm.js.map +1 -0
  241. package/lib/utils/httpcontext.d.ts +3 -0
  242. package/lib/utils/httpcontext.js +48 -65
  243. package/lib/utils/httpcontext.js.map +1 -1
  244. package/lib/utils/httpcontext.spec.js +37 -56
  245. package/lib/utils/httpcontext.spec.js.map +1 -1
  246. package/lib/utils/logger.d.ts +2 -2
  247. package/lib/utils/logger.js +15 -28
  248. package/lib/utils/logger.js.map +1 -1
  249. package/lib/utils/logger.spec.js +9 -11
  250. package/lib/utils/logger.spec.js.map +1 -1
  251. package/lib/utils/serializers.js +17 -20
  252. package/lib/utils/serializers.js.map +1 -1
  253. package/lib/utils/serializers.spec.js +43 -44
  254. package/lib/utils/serializers.spec.js.map +1 -1
  255. package/lib/utils/session.d.ts +6 -6
  256. package/lib/utils/session.js +37 -59
  257. package/lib/utils/session.js.map +1 -1
  258. package/lib/utils/session.spec.js +38 -51
  259. package/lib/utils/session.spec.js.map +1 -1
  260. package/lib/utils/waiter.d.ts +1 -1
  261. package/lib/utils/waiter.js +32 -52
  262. package/lib/utils/waiter.js.map +1 -1
  263. package/lib/utils/waiter.spec.js +75 -92
  264. package/lib/utils/waiter.spec.js.map +1 -1
  265. package/package.json +17 -12
  266. package/test/config-invitation.json +1 -3
  267. package/test/config.json +1 -2
  268. package/test/config.old.json +1 -2
  269. package/test/moddas/annotatedservice.js +5 -5
  270. package/test/moddas/debugmailer.js +2 -3
  271. package/test/moddas/fakeservice.js +2 -3
  272. package/test/moddas/voidstore.js +6 -4
  273. package/test/models/ident.js +2 -6
  274. package/test/models/task.js +3 -7
  275. package/test/package.json +2 -1
  276. package/webda.module.json +956 -189
@@ -1,40 +1,27 @@
1
- "use strict";
2
1
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
2
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
3
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
6
  };
8
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.InvitationParameters = void 0;
19
- const index_1 = require("../index");
20
- const service_1 = require("./service");
7
+ import { Ident } from "../index.js";
8
+ import { Inject, Service, ServiceParameters } from "./service.js";
21
9
  /**
22
10
  *
23
11
  */
24
- class InvitationParameters extends service_1.ServiceParameters {
12
+ export class InvitationParameters extends ServiceParameters {
25
13
  constructor(params) {
26
- var _a, _b, _c, _d;
27
14
  super(params);
28
- (_a = this.authenticationService) !== null && _a !== void 0 ? _a : (this.authenticationService = "Authentication");
15
+ this.authenticationService ?? (this.authenticationService = "Authentication");
29
16
  if (typeof this.mapFields === "string") {
30
17
  this.mapFields = this.mapFields.split(",");
31
18
  }
32
- (_b = this.mapFields) !== null && _b !== void 0 ? _b : (this.mapFields = []);
33
- (_c = this.multiple) !== null && _c !== void 0 ? _c : (this.multiple = true);
19
+ this.mapFields ?? (this.mapFields = []);
20
+ this.multiple ?? (this.multiple = true);
34
21
  if (!this.attribute.startsWith("_")) {
35
22
  throw new Error(`Attribute '${this.attribute}' needs to start with a _ to be only modified by server`);
36
23
  }
37
- (_d = this.pendingAttribute) !== null && _d !== void 0 ? _d : (this.pendingAttribute = `${this.attribute}Pending`);
24
+ this.pendingAttribute ?? (this.pendingAttribute = `${this.attribute}Pending`);
38
25
  if (!this.pendingAttribute.startsWith("_")) {
39
26
  throw new Error(`Attribute '${this.pendingAttribute}' needs to start with a _ to be only modified by server`);
40
27
  }
@@ -43,7 +30,6 @@ class InvitationParameters extends service_1.ServiceParameters {
43
30
  }
44
31
  }
45
32
  }
46
- exports.InvitationParameters = InvitationParameters;
47
33
  /**
48
34
  * Allow to use invitation on AclModel
49
35
  *
@@ -52,7 +38,7 @@ exports.InvitationParameters = InvitationParameters;
52
38
  *
53
39
  * @WebdaModda
54
40
  */
55
- class InvitationService extends service_1.Service {
41
+ export default class InvitationService extends Service {
56
42
  /**
57
43
  * @inheritdoc
58
44
  */
@@ -73,58 +59,51 @@ class InvitationService extends service_1.Service {
73
59
  /**
74
60
  * @inheritdoc
75
61
  */
76
- init() {
77
- const _super = Object.create(null, {
78
- init: { get: () => super.init }
79
- });
80
- return __awaiter(this, void 0, void 0, function* () {
81
- yield _super.init.call(this);
82
- if (this.parameters.notification &&
83
- !(yield this.notificationService.hasNotification(this.parameters.notification))) {
84
- throw new Error(`Email template should exist`);
85
- }
86
- return this;
87
- });
62
+ async init() {
63
+ await super.init();
64
+ if (this.parameters.notification &&
65
+ !(await this.notificationService.hasNotification(this.parameters.notification))) {
66
+ throw new Error(`Email template should exist`);
67
+ }
68
+ return this;
88
69
  }
89
70
  /**
90
71
  * Accept or refuse for an invitation
91
72
  * @param ctx
92
73
  * @param model
93
74
  */
94
- answerInvitation(ctx, model) {
95
- return __awaiter(this, void 0, void 0, function* () {
96
- let body = yield ctx.getRequestBody();
97
- // Need to specify if you accept or not
98
- if (typeof body.accept !== "boolean") {
99
- throw 400;
100
- }
101
- // Invitation on the model is gone
102
- if (model === undefined) {
103
- yield this.removeInvitationFromUser(ctx.getCurrentUserId(), ctx.getParameters().uuid);
104
- throw 410;
105
- }
106
- const user = yield ctx.getCurrentUser();
107
- let metadata = undefined;
108
- user.getIdents().forEach(i => {
109
- if (model[this.parameters.pendingAttribute][`ident_${i.getUuid()}`]) {
110
- metadata = model[this.parameters.pendingAttribute][`ident_${i.getUuid()}`];
111
- delete model[this.parameters.pendingAttribute][`ident_${i.getUuid()}`];
112
- }
113
- });
114
- if (model[this.parameters.pendingAttribute][`user_${user.getUuid()}`]) {
115
- metadata = model[this.parameters.pendingAttribute][`user_${user.getUuid()}`];
116
- delete model[this.parameters.pendingAttribute][`user_${user.getUuid()}`];
117
- }
118
- if (metadata && body.accept) {
119
- model[this.parameters.attribute][user.getUuid()] = metadata;
75
+ async answerInvitation(ctx, model) {
76
+ let body = await ctx.getRequestBody();
77
+ // Need to specify if you accept or not
78
+ if (typeof body.accept !== "boolean") {
79
+ throw 400;
80
+ }
81
+ // Invitation on the model is gone
82
+ if (model === undefined) {
83
+ await this.removeInvitationFromUser(ctx.getCurrentUserId(), ctx.getParameters().uuid);
84
+ throw 410;
85
+ }
86
+ const user = await ctx.getCurrentUser();
87
+ let metadata = undefined;
88
+ user.getIdents().forEach(i => {
89
+ if (model[this.parameters.pendingAttribute][`ident_${i.getUuid()}`]) {
90
+ metadata = model[this.parameters.pendingAttribute][`ident_${i.getUuid()}`];
91
+ delete model[this.parameters.pendingAttribute][`ident_${i.getUuid()}`];
120
92
  }
121
- yield this.updateModel(model);
122
- this.emit("Invitation.Accepted", {
123
- metadata,
124
- model,
125
- context: ctx,
126
- accept: body.accept
127
- });
93
+ });
94
+ if (model[this.parameters.pendingAttribute][`user_${user.getUuid()}`]) {
95
+ metadata = model[this.parameters.pendingAttribute][`user_${user.getUuid()}`];
96
+ delete model[this.parameters.pendingAttribute][`user_${user.getUuid()}`];
97
+ }
98
+ if (metadata && body.accept) {
99
+ model[this.parameters.attribute][user.getUuid()] = metadata;
100
+ }
101
+ await this.updateModel(model);
102
+ this.emit("Invitation.Accepted", {
103
+ metadata,
104
+ model,
105
+ context: ctx,
106
+ accept: body.accept
128
107
  });
129
108
  }
130
109
  /**
@@ -132,12 +111,10 @@ class InvitationService extends service_1.Service {
132
111
  *
133
112
  * @param model
134
113
  */
135
- updateModel(model) {
136
- return __awaiter(this, void 0, void 0, function* () {
137
- yield model.update({
138
- [this.parameters.attribute]: model[this.parameters.attribute],
139
- [this.parameters.pendingAttribute]: model[this.parameters.pendingAttribute]
140
- });
114
+ async updateModel(model) {
115
+ await model.update({
116
+ [this.parameters.attribute]: model[this.parameters.attribute],
117
+ [this.parameters.pendingAttribute]: model[this.parameters.pendingAttribute]
141
118
  });
142
119
  }
143
120
  /**
@@ -145,75 +122,70 @@ class InvitationService extends service_1.Service {
145
122
  * @param ctx
146
123
  * @param model
147
124
  */
148
- uninvite(ctx, model) {
149
- var _a, _b;
150
- return __awaiter(this, void 0, void 0, function* () {
151
- const body = yield ctx.getRequestBody();
152
- (_a = body.users) !== null && _a !== void 0 ? _a : (body.users = []);
153
- (_b = body.idents) !== null && _b !== void 0 ? _b : (body.idents = []);
154
- const promises = [];
155
- let invitedIdents = [];
156
- let invitedUsers = [];
157
- for (const ident of body.idents) {
158
- if (model[this.parameters.pendingAttribute][`ident_${ident}`]) {
159
- // Remove from pending on the object
160
- delete model[this.parameters.pendingAttribute][`ident_${ident}`];
161
- // Remove from pending from the invitation store
162
- promises.push(this.invitationStore.removeAttribute(`${ident}_${this.getName()}`, this.getInvitationAttribute(model.getUuid())));
163
- invitedIdents.push(ident);
164
- }
165
- else {
166
- // Remove user
167
- promises.push((() => __awaiter(this, void 0, void 0, function* () {
168
- const id = yield this.authenticationService.getIdentStore().get(ident);
169
- if (id && id.getUser()) {
170
- delete model[this.parameters.attribute][id.getUser()];
171
- yield this.removeInvitationFromUser(id.getUser(), model.getUuid());
172
- invitedUsers.push(id.getUser());
173
- }
174
- }))());
175
- }
125
+ async uninvite(ctx, model) {
126
+ const body = await ctx.getRequestBody();
127
+ body.users ?? (body.users = []);
128
+ body.idents ?? (body.idents = []);
129
+ const promises = [];
130
+ let invitedIdents = [];
131
+ let invitedUsers = [];
132
+ for (const ident of body.idents) {
133
+ if (model[this.parameters.pendingAttribute][`ident_${ident}`]) {
134
+ // Remove from pending on the object
135
+ delete model[this.parameters.pendingAttribute][`ident_${ident}`];
136
+ // Remove from pending from the invitation store
137
+ promises.push(this.invitationStore.removeAttribute(`${ident}_${this.getName()}`, this.getInvitationAttribute(model.getUuid())));
138
+ invitedIdents.push(ident);
176
139
  }
177
- for (const user of body.users) {
178
- if (model[this.parameters.pendingAttribute][`user_${user}`]) {
179
- delete model[this.parameters.pendingAttribute][`user_${user}`];
180
- }
181
- else if (model[this.parameters.attribute][user]) {
182
- delete model[this.parameters.attribute][user];
183
- }
184
- promises.push(this.removeInvitationFromUser(user, model.getUuid()));
185
- invitedUsers.push(user);
140
+ else {
141
+ // Remove user
142
+ promises.push((async () => {
143
+ const id = await this.authenticationService.getIdentStore().get(ident);
144
+ if (id && id.getUser()) {
145
+ delete model[this.parameters.attribute][id.getUser()];
146
+ await this.removeInvitationFromUser(id.getUser(), model.getUuid());
147
+ invitedUsers.push(id.getUser());
148
+ }
149
+ })());
186
150
  }
187
- yield Promise.all(promises);
188
- //
189
- yield this.updateModel(model);
190
- this.emit("Invitation.Removed", {
191
- metadata: body.metadata,
192
- users: invitedUsers,
193
- idents: invitedIdents,
194
- model,
195
- context: ctx
196
- });
151
+ }
152
+ for (const user of body.users) {
153
+ if (model[this.parameters.pendingAttribute][`user_${user}`]) {
154
+ delete model[this.parameters.pendingAttribute][`user_${user}`];
155
+ }
156
+ else if (model[this.parameters.attribute][user]) {
157
+ delete model[this.parameters.attribute][user];
158
+ }
159
+ promises.push(this.removeInvitationFromUser(user, model.getUuid()));
160
+ invitedUsers.push(user);
161
+ }
162
+ await Promise.all(promises);
163
+ //
164
+ await this.updateModel(model);
165
+ this.emit("Invitation.Removed", {
166
+ metadata: body.metadata,
167
+ users: invitedUsers,
168
+ idents: invitedIdents,
169
+ model,
170
+ context: ctx
197
171
  });
198
172
  }
199
173
  /**
200
174
  * Remove a model invitation from user
201
175
  * @param user
202
176
  */
203
- removeInvitationFromUser(user, model) {
204
- return __awaiter(this, void 0, void 0, function* () {
205
- let userModel = yield this.authenticationService.getUserStore().get(user);
206
- let index = 0;
207
- for (let invit of userModel[this.parameters.mapAttribute] || []) {
208
- if (invit.model === model) {
209
- yield this.authenticationService
210
- .getUserStore()
211
- .deleteItemFromCollection(user, this.parameters.mapAttribute, index, model, "model");
212
- return;
213
- }
214
- index++;
177
+ async removeInvitationFromUser(user, model) {
178
+ let userModel = await this.authenticationService.getUserStore().get(user);
179
+ let index = 0;
180
+ for (let invit of userModel[this.parameters.mapAttribute] || []) {
181
+ if (invit.model === model) {
182
+ await this.authenticationService
183
+ .getUserStore()
184
+ .deleteItemFromCollection(user, this.parameters.mapAttribute, index, model, "model");
185
+ return;
215
186
  }
216
- });
187
+ index++;
188
+ }
217
189
  }
218
190
  /**
219
191
  * Handle invitations all methods
@@ -221,152 +193,143 @@ class InvitationService extends service_1.Service {
221
193
  * @param ctx
222
194
  * @returns
223
195
  */
224
- invite(ctx) {
225
- var _a, _b, _c, _d;
226
- var _e, _f, _g;
227
- return __awaiter(this, void 0, void 0, function* () {
228
- let model = yield this.modelStore.get(ctx.getParameters().uuid);
229
- if (ctx.getHttpContext().getMethod() === "PUT") {
230
- return this.answerInvitation(ctx, model);
231
- }
232
- let inviter = yield ctx.getCurrentUser();
233
- if (!model) {
234
- throw 404;
235
- }
236
- (_a = model[_e = this.parameters.attribute]) !== null && _a !== void 0 ? _a : (model[_e] = {});
237
- (_b = model[_f = this.parameters.pendingAttribute]) !== null && _b !== void 0 ? _b : (model[_f] = {});
238
- if (ctx.getHttpContext().getMethod() === "DELETE") {
239
- yield model.canAct(ctx, "uninvite");
240
- return this.uninvite(ctx, model);
241
- }
242
- yield model.canAct(ctx, "invite");
243
- // Retrieve invitation useful when invitation are hidden with a __
244
- if (ctx.getHttpContext().getMethod() === "GET") {
245
- ctx.write(model[this.parameters.pendingAttribute] || {});
246
- return;
247
- }
248
- const body = yield ctx.getRequestBody();
249
- // For each ident
250
- const identsStore = this.authenticationService.getIdentStore();
251
- // Load all idents with orignal
252
- const invitations = yield Promise.all((body.idents || []).map((i) => __awaiter(this, void 0, void 0, function* () {
253
- return ({
254
- ident: yield identsStore.get(i),
255
- invitation: i
256
- });
257
- })));
258
- let invitedIdents = [];
259
- let invitedUsers = [];
260
- let promises = [];
261
- const metadata = {};
262
- this.parameters.mapFields.forEach(f => (metadata[f] = model[f]));
263
- for (const invitation of invitations) {
264
- // User is known
265
- if (invitation.ident) {
266
- if (this.parameters.autoAccept) {
267
- model[this.parameters.attribute][invitation.ident.getUser()] = body.metadata;
268
- }
269
- else if (!model[this.parameters.attribute][invitation.ident.getUser()]) {
270
- // Add to the user
271
- model[this.parameters.pendingAttribute][`user_${invitation.ident.getUser()}`] = body.metadata;
272
- }
273
- promises.push((() => __awaiter(this, void 0, void 0, function* () {
274
- const user = yield this.authenticationService.getUserStore().get(invitation.ident.getUser());
275
- invitedUsers.push(user);
276
- yield this.addInvitationToUser(model, user, inviter, metadata, body.notification);
277
- }))());
278
- continue;
279
- }
280
- // User is unknown to the platform
281
- invitedIdents.push(invitation.invitation);
282
- let invitUuid = `${invitation.invitation}_${this.getName()}`;
283
- (_c = model[_g = this.parameters.pendingAttribute]) !== null && _c !== void 0 ? _c : (model[_g] = {});
284
- model[this.parameters.pendingAttribute][`ident_${invitation.invitation}`] = body.metadata;
285
- const invitInfo = {
286
- inviter: inviter.toPublicEntry(),
287
- metadata: body.metadata
288
- };
289
- if (yield this.invitationStore.exists(invitUuid)) {
290
- promises.push(this.invitationStore.setAttribute(invitUuid, this.getInvitationAttribute(model.getUuid()), invitInfo));
291
- }
292
- else {
293
- promises.push(this.invitationStore.save({
294
- uuid: invitUuid,
295
- [this.getInvitationAttribute(model.getUuid())]: invitInfo
296
- }));
297
- }
298
- // Notify ident
299
- let ident = invitation.invitation.split("_");
300
- yield this.sendNotification(index_1.Ident.init(ident.pop(), ident.join("_")), {
301
- model,
302
- metadata,
303
- notification: body.notification,
304
- inviter: inviter.toPublicEntry(),
305
- pending: !this.parameters.autoAccept,
306
- registered: true
307
- });
308
- }
309
- // Check user direct invite
310
- (_d = body.users) !== null && _d !== void 0 ? _d : (body.users = []);
311
- promises.push(...body.users.map((u) => __awaiter(this, void 0, void 0, function* () {
312
- let user = yield this.authenticationService.getUserStore().get(u);
313
- if (!user) {
314
- return;
315
- }
196
+ async invite(ctx) {
197
+ var _a, _b, _c;
198
+ let model = await this.modelStore.get(ctx.getParameters().uuid);
199
+ if (ctx.getHttpContext().getMethod() === "PUT") {
200
+ return this.answerInvitation(ctx, model);
201
+ }
202
+ let inviter = await ctx.getCurrentUser();
203
+ if (!model) {
204
+ throw 404;
205
+ }
206
+ model[_a = this.parameters.attribute] ?? (model[_a] = {});
207
+ model[_b = this.parameters.pendingAttribute] ?? (model[_b] = {});
208
+ if (ctx.getHttpContext().getMethod() === "DELETE") {
209
+ await model.canAct(ctx, "uninvite");
210
+ return this.uninvite(ctx, model);
211
+ }
212
+ await model.canAct(ctx, "invite");
213
+ // Retrieve invitation useful when invitation are hidden with a __
214
+ if (ctx.getHttpContext().getMethod() === "GET") {
215
+ ctx.write(model[this.parameters.pendingAttribute] || {});
216
+ return;
217
+ }
218
+ const body = await ctx.getRequestBody();
219
+ // For each ident
220
+ const identsStore = this.authenticationService.getIdentStore();
221
+ // Load all idents with orignal
222
+ const invitations = await Promise.all((body.idents || []).map(async (i) => ({
223
+ ident: await identsStore.get(i),
224
+ invitation: i
225
+ })));
226
+ let invitedIdents = [];
227
+ let invitedUsers = [];
228
+ let promises = [];
229
+ const metadata = {};
230
+ this.parameters.mapFields.forEach(f => (metadata[f] = model[f]));
231
+ for (const invitation of invitations) {
232
+ // User is known
233
+ if (invitation.ident) {
316
234
  if (this.parameters.autoAccept) {
317
- model[this.parameters.attribute][u] = body.metadata;
235
+ model[this.parameters.attribute][invitation.ident.getUser()] = body.metadata;
318
236
  }
319
- else if (!model[this.parameters.attribute][u]) {
320
- model[this.parameters.pendingAttribute][`user_${u}`] = body.metadata;
237
+ else if (!model[this.parameters.attribute][invitation.ident.getUser()]) {
238
+ // Add to the user
239
+ model[this.parameters.pendingAttribute][`user_${invitation.ident.getUser()}`] = body.metadata;
321
240
  }
322
- invitedUsers.push(user);
323
- yield this.addInvitationToUser(model, user, inviter, metadata, body.notification);
324
- })));
325
- yield Promise.all(promises);
326
- // Update model now
327
- yield this.updateModel(model);
328
- this.emit("Invitation.Sent", {
329
- metadata: body.metadata,
330
- notification: body.notification,
331
- users: invitedUsers,
332
- idents: invitedIdents,
333
- model,
334
- context: ctx
335
- });
336
- });
337
- }
338
- addInvitationToUser(model, user, inviter, metadata, notification = {}) {
339
- return __awaiter(this, void 0, void 0, function* () {
340
- if ((user[this.parameters.mapAttribute] || []).filter(p => p.model === model.getUuid()).length) {
341
- return;
241
+ promises.push((async () => {
242
+ const user = await this.authenticationService.getUserStore().get(invitation.ident.getUser());
243
+ invitedUsers.push(user);
244
+ await this.addInvitationToUser(model, user, inviter, metadata, body.notification);
245
+ })());
246
+ continue;
342
247
  }
343
- yield this.authenticationService
344
- .getUserStore()
345
- .upsertItemToCollection(user.getUuid(), this.parameters.mapAttribute, {
346
- model: model.getUuid(),
347
- metadata,
248
+ // User is unknown to the platform
249
+ invitedIdents.push(invitation.invitation);
250
+ let invitUuid = `${invitation.invitation}_${this.getName()}`;
251
+ model[_c = this.parameters.pendingAttribute] ?? (model[_c] = {});
252
+ model[this.parameters.pendingAttribute][`ident_${invitation.invitation}`] = body.metadata;
253
+ const invitInfo = {
348
254
  inviter: inviter.toPublicEntry(),
349
- pending: !this.parameters.autoAccept
350
- });
351
- // Notify user
352
- yield this.sendNotification(user, {
255
+ metadata: body.metadata
256
+ };
257
+ if (await this.invitationStore.exists(invitUuid)) {
258
+ promises.push(this.invitationStore.setAttribute(invitUuid, this.getInvitationAttribute(model.getUuid()), invitInfo));
259
+ }
260
+ else {
261
+ promises.push(this.invitationStore.save({
262
+ uuid: invitUuid,
263
+ [this.getInvitationAttribute(model.getUuid())]: invitInfo
264
+ }));
265
+ }
266
+ // Notify ident
267
+ let ident = invitation.invitation.split("_");
268
+ await this.sendNotification(Ident.init(ident.pop(), ident.join("_")), {
353
269
  model,
354
270
  metadata,
355
- notification,
271
+ notification: body.notification,
356
272
  inviter: inviter.toPublicEntry(),
357
273
  pending: !this.parameters.autoAccept,
358
274
  registered: true
359
275
  });
360
- });
361
- }
362
- sendNotification(user, replacements) {
363
- return __awaiter(this, void 0, void 0, function* () {
364
- if (!this.parameters.notification) {
276
+ }
277
+ // Check user direct invite
278
+ body.users ?? (body.users = []);
279
+ promises.push(...body.users.map(async (u) => {
280
+ let user = await this.authenticationService.getUserStore().get(u);
281
+ if (!user) {
365
282
  return;
366
283
  }
367
- yield this.notificationService.sendNotification(user, this.parameters.notification, replacements);
284
+ if (this.parameters.autoAccept) {
285
+ model[this.parameters.attribute][u] = body.metadata;
286
+ }
287
+ else if (!model[this.parameters.attribute][u]) {
288
+ model[this.parameters.pendingAttribute][`user_${u}`] = body.metadata;
289
+ }
290
+ invitedUsers.push(user);
291
+ await this.addInvitationToUser(model, user, inviter, metadata, body.notification);
292
+ }));
293
+ await Promise.all(promises);
294
+ // Update model now
295
+ await this.updateModel(model);
296
+ this.emit("Invitation.Sent", {
297
+ metadata: body.metadata,
298
+ notification: body.notification,
299
+ users: invitedUsers,
300
+ idents: invitedIdents,
301
+ model,
302
+ context: ctx
368
303
  });
369
304
  }
305
+ async addInvitationToUser(model, user, inviter, metadata, notification = {}) {
306
+ if ((user[this.parameters.mapAttribute] || []).filter(p => p.model === model.getUuid()).length) {
307
+ return;
308
+ }
309
+ await this.authenticationService
310
+ .getUserStore()
311
+ .upsertItemToCollection(user.getUuid(), this.parameters.mapAttribute, {
312
+ model: model.getUuid(),
313
+ metadata,
314
+ inviter: inviter.toPublicEntry(),
315
+ pending: !this.parameters.autoAccept
316
+ });
317
+ // Notify user
318
+ await this.sendNotification(user, {
319
+ model,
320
+ metadata,
321
+ notification,
322
+ inviter: inviter.toPublicEntry(),
323
+ pending: !this.parameters.autoAccept,
324
+ registered: true
325
+ });
326
+ }
327
+ async sendNotification(user, replacements) {
328
+ if (!this.parameters.notification) {
329
+ return;
330
+ }
331
+ await this.notificationService.sendNotification(user, this.parameters.notification, replacements);
332
+ }
370
333
  /**
371
334
  * Return which attribute would be used to store the invitation on ident invitation object
372
335
  * @param uuid
@@ -381,66 +344,63 @@ class InvitationService extends service_1.Service {
381
344
  * @param evt
382
345
  * @returns
383
346
  */
384
- registrationListener(evt) {
385
- var _a;
386
- var _b, _c;
387
- return __awaiter(this, void 0, void 0, function* () {
388
- let uuid = `${evt.identId}_${this.getName()}`;
389
- const invitations = yield this.invitationStore.get(uuid);
390
- if (!invitations) {
391
- return;
392
- }
393
- this.log("DEBUG", `Resolving invitation for ident ${evt.identId}`);
394
- // Load all models invited too
395
- const infos = yield Promise.all(Object.keys(invitations)
396
- .filter(k => k.startsWith("invit_"))
397
- .map((k) => __awaiter(this, void 0, void 0, function* () {
398
- return (Object.assign(Object.assign({}, invitations[k]), { model: yield this.modelStore.get(k.substring(6)) }));
399
- })));
400
- // autoAccept is on so move to __acls
401
- const promises = [];
402
- // If autoAccept is false, just copy the pending invitation in the user
403
- (_a = (_b = evt.user)[_c = this.parameters.mapAttribute]) !== null && _a !== void 0 ? _a : (_b[_c] = []);
404
- evt.user[this.parameters.mapAttribute].push(...infos
405
- .filter(m => m.model !== undefined)
406
- .map(m => {
407
- const metadata = {};
408
- this.parameters.mapFields.forEach(f => (metadata[f] = m.model[f]));
409
- return {
410
- model: m.model.getUuid(),
411
- metadata,
412
- inviter: m.inviter,
413
- pending: !this.parameters.autoAccept
414
- };
415
- }));
416
- if (this.parameters.autoAccept) {
417
- for (const info of infos) {
418
- if (!info.model) {
419
- continue;
420
- }
421
- // Set the metadata
422
- info.model[this.parameters.attribute][evt.user.getUuid()] = info.metadata;
423
- // Remove pending
424
- delete info.model[this.parameters.pendingAttribute][`ident_${evt.identId}`];
425
- promises.push(this.updateModel(info.model));
347
+ async registrationListener(evt) {
348
+ var _a, _b;
349
+ let uuid = `${evt.identId}_${this.getName()}`;
350
+ const invitations = await this.invitationStore.get(uuid);
351
+ if (!invitations) {
352
+ return;
353
+ }
354
+ this.log("DEBUG", `Resolving invitation for ident ${evt.identId}`);
355
+ // Load all models invited too
356
+ const infos = await Promise.all(Object.keys(invitations)
357
+ .filter(k => k.startsWith("invit_"))
358
+ .map(async (k) => ({
359
+ ...invitations[k],
360
+ model: await this.modelStore.get(k.substring(6))
361
+ })));
362
+ // autoAccept is on so move to __acls
363
+ const promises = [];
364
+ // If autoAccept is false, just copy the pending invitation in the user
365
+ (_a = evt.user)[_b = this.parameters.mapAttribute] ?? (_a[_b] = []);
366
+ evt.user[this.parameters.mapAttribute].push(...infos
367
+ .filter(m => m.model !== undefined)
368
+ .map(m => {
369
+ const metadata = {};
370
+ this.parameters.mapFields.forEach(f => (metadata[f] = m.model[f]));
371
+ return {
372
+ model: m.model.getUuid(),
373
+ metadata,
374
+ inviter: m.inviter,
375
+ pending: !this.parameters.autoAccept
376
+ };
377
+ }));
378
+ if (this.parameters.autoAccept) {
379
+ for (const info of infos) {
380
+ if (!info.model) {
381
+ continue;
426
382
  }
383
+ // Set the metadata
384
+ info.model[this.parameters.attribute][evt.user.getUuid()] = info.metadata;
385
+ // Remove pending
386
+ delete info.model[this.parameters.pendingAttribute][`ident_${evt.identId}`];
387
+ promises.push(this.updateModel(info.model));
427
388
  }
428
- promises.push(invitations.delete());
429
- yield Promise.all(promises);
430
- });
389
+ }
390
+ promises.push(invitations.delete());
391
+ await Promise.all(promises);
431
392
  }
432
393
  }
433
394
  __decorate([
434
- (0, service_1.Inject)("params:authenticationService")
395
+ Inject("params:authenticationService")
435
396
  ], InvitationService.prototype, "authenticationService", void 0);
436
397
  __decorate([
437
- (0, service_1.Inject)("params:notificationService", true)
398
+ Inject("params:notificationService", true)
438
399
  ], InvitationService.prototype, "notificationService", void 0);
439
400
  __decorate([
440
- (0, service_1.Inject)("params:invitationStore")
401
+ Inject("params:invitationStore")
441
402
  ], InvitationService.prototype, "invitationStore", void 0);
442
403
  __decorate([
443
- (0, service_1.Inject)("params:modelStore")
404
+ Inject("params:modelStore")
444
405
  ], InvitationService.prototype, "modelStore", void 0);
445
- exports.default = InvitationService;
446
406
  //# sourceMappingURL=invitationservice.js.map