spec-3nweb-server 1.3.8 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/build/3nstorage/3nstorage-app.js +4 -4
  2. package/build/3nstorage/owner.js +21 -21
  3. package/build/3nstorage/resources/store.js +25 -24
  4. package/build/3nstorage/resources/users.js +2 -2
  5. package/build/3nstorage/routes/owner/archive-obj-version.d.ts +2 -2
  6. package/build/3nstorage/routes/owner/archive-obj-version.js +3 -2
  7. package/build/3nstorage/routes/owner/cancel-trans.js +1 -1
  8. package/build/3nstorage/routes/owner/delete-obj.js +1 -1
  9. package/build/3nstorage/routes/owner/get-archived-obj-ver.js +2 -2
  10. package/build/3nstorage/routes/owner/get-current-obj.js +2 -2
  11. package/build/3nstorage/routes/owner/list-obj-archive.js +3 -2
  12. package/build/3nstorage/routes/owner/param-getter.js +3 -2
  13. package/build/3nstorage/routes/owner/param-setter.js +3 -2
  14. package/build/3nstorage/routes/owner/put-current-obj.js +12 -10
  15. package/build/3nstorage/routes/owner/session-params.js +4 -3
  16. package/build/admin/admin-app.js +5 -5
  17. package/build/admin/resources/users.js +42 -42
  18. package/build/admin/routes/add.js +3 -3
  19. package/build/admin/signup-tokens.js +8 -8
  20. package/build/asmail/asmail-app.js +7 -7
  21. package/build/asmail/config.js +9 -8
  22. package/build/asmail/delivery.js +10 -9
  23. package/build/asmail/resources/delivery-sessions.js +4 -3
  24. package/build/asmail/resources/inbox.d.ts +1 -1
  25. package/build/asmail/resources/inbox.js +22 -22
  26. package/build/asmail/resources/recipients.d.ts +2 -1
  27. package/build/asmail/resources/recipients.js +4 -4
  28. package/build/asmail/resources/sessions.js +2 -1
  29. package/build/asmail/retrieval.js +13 -8
  30. package/build/asmail/routes/config/param-getter.js +3 -2
  31. package/build/asmail/routes/config/param-setter.js +3 -2
  32. package/build/asmail/routes/delivery/finalize-delivery.js +3 -2
  33. package/build/asmail/routes/delivery/pre-flight.js +5 -4
  34. package/build/asmail/routes/delivery/provide-recipient-pubkey.js +3 -2
  35. package/build/asmail/routes/delivery/put-metadata.js +3 -2
  36. package/build/asmail/routes/delivery/put-obj.js +4 -4
  37. package/build/asmail/routes/delivery/restart-session.js +4 -3
  38. package/build/asmail/routes/delivery/sender-authorization.d.ts +1 -3
  39. package/build/asmail/routes/delivery/sender-authorization.js +3 -2
  40. package/build/asmail/routes/delivery/start-session.js +5 -4
  41. package/build/asmail/routes/retrieval/get-message-meta.js +3 -2
  42. package/build/asmail/routes/retrieval/get-message-obj.js +4 -3
  43. package/build/asmail/routes/retrieval/list-messages.js +3 -2
  44. package/build/asmail/routes/retrieval/remove-message.js +3 -2
  45. package/build/lib-common/async-fs-node.js +13 -13
  46. package/build/lib-common/byte-streaming/common.js +9 -9
  47. package/build/lib-common/canonical-address.js +1 -1
  48. package/build/lib-common/ipc/generic-ipc.js +12 -12
  49. package/build/lib-common/ipc/ws-ipc.js +2 -2
  50. package/build/lib-common/mid-sigs-NaCl-Ed.js +14 -14
  51. package/build/lib-common/objs-on-disk/file-layout.js +10 -10
  52. package/build/lib-common/objs-on-disk/obj-file.js +11 -11
  53. package/build/lib-common/objs-on-disk/utils.js +3 -3
  54. package/build/lib-common/processes.js +1 -1
  55. package/build/lib-common/random-node.js +7 -7
  56. package/build/lib-common/service-api/3nstorage/owner.d.ts +5 -4
  57. package/build/lib-common/service-api/3nstorage/owner.js +11 -10
  58. package/build/lib-common/service-api/asmail/delivery.js +2 -2
  59. package/build/lib-common/service-api/asmail/retrieval.js +1 -1
  60. package/build/lib-server/conf-util.js +2 -1
  61. package/build/lib-server/middleware/body-parsers.js +16 -16
  62. package/build/lib-server/middleware/error-handler.js +1 -1
  63. package/build/lib-server/resources/mailerid-authorizer.js +3 -3
  64. package/build/lib-server/resources/mem-backed-sessions-factory.js +3 -3
  65. package/build/lib-server/resources/server-data-folders.js +23 -23
  66. package/build/lib-server/resources/sessions.js +5 -5
  67. package/build/lib-server/resources/user-files.js +8 -8
  68. package/build/lib-server/routes/pub-key-login/complete-exchange.js +4 -3
  69. package/build/lib-server/routes/pub-key-login/start-exchange.js +7 -6
  70. package/build/lib-server/routes/sessions/mid-auth.js +6 -5
  71. package/build/lib-server/routes/sessions/start.js +4 -3
  72. package/build/lib-server/web-sockets/app.js +6 -5
  73. package/build/lib-server/web-sockets/server-events.js +5 -4
  74. package/build/mailerId/mailerId-app.js +7 -7
  75. package/build/mailerId/resources/certifier.d.ts +4 -6
  76. package/build/mailerId/resources/certifier.js +8 -7
  77. package/build/mailerId/resources/compute-login-dhshared-key.js +2 -1
  78. package/build/mailerId/resources/sessions.js +2 -1
  79. package/build/mailerId/resources/users.js +4 -4
  80. package/build/mailerId/routes/certify.js +1 -1
  81. package/build/main.js +10 -10
  82. package/build/mock/dns.js +1 -1
  83. package/build/mock/mock-as-child-proc.js +10 -10
  84. package/build/mock/node-child-ipc.js +2 -2
  85. package/build/mock/run-in-proc.js +7 -7
  86. package/build/run-config.js +10 -10
  87. package/build/run.js +4 -4
  88. package/build/services.js +5 -5
  89. package/package.json +7 -4
@@ -84,26 +84,26 @@ async function writeJson(path, json) {
84
84
  return fs.writeFile(path, JSON.stringify(json), { encoding: 'utf8', flag: 'w', mode: '660' });
85
85
  }
86
86
  function writeJsonSync(path, json) {
87
- fs_1.writeFileSync(path, JSON.stringify(json), { encoding: 'utf8', flag: 'w', mode: '660' });
87
+ (0, fs_1.writeFileSync)(path, JSON.stringify(json), { encoding: 'utf8', flag: 'w', mode: '660' });
88
88
  }
89
89
  function setGeneralDefaults(defaults) {
90
90
  const infoFolder = defaults.info.path;
91
- writeJsonSync(path_1.join(infoFolder, 'quota'), 100 * 1024 * 1024 * 1024);
91
+ writeJsonSync((0, path_1.join)(infoFolder, 'quota'), 100 * 1024 * 1024 * 1024);
92
92
  }
93
93
  function setStoreDefaults(store) {
94
94
  const sp = store.params.path;
95
- writeJsonSync(path_1.join(sp, 'key-deriv'), null);
95
+ writeJsonSync((0, path_1.join)(sp, 'key-deriv'), null);
96
96
  }
97
97
  function setMailDefaults(mail) {
98
- writeJsonSync(path_1.join(mail.params.path, 'pubkey'), null);
98
+ writeJsonSync((0, path_1.join)(mail.params.path, 'pubkey'), null);
99
99
  const anonFolder = mail.params.anonymous.path;
100
100
  const anonPolicy = {
101
101
  accept: true,
102
102
  acceptWithInvitesOnly: false,
103
103
  defaultMsgSize: 1024 * 1024
104
104
  };
105
- writeJsonSync(path_1.join(anonFolder, 'policy'), anonPolicy);
106
- writeJsonSync(path_1.join(anonFolder, 'invites'), {});
105
+ writeJsonSync((0, path_1.join)(anonFolder, 'policy'), anonPolicy);
106
+ writeJsonSync((0, path_1.join)(anonFolder, 'invites'), {});
107
107
  const authFolder = mail.params.authenticated.path;
108
108
  const authPolicy = {
109
109
  acceptWithInvitesOnly: false,
@@ -111,10 +111,10 @@ function setMailDefaults(mail) {
111
111
  applyBlackList: true,
112
112
  defaultMsgSize: 1024 * 1024
113
113
  };
114
- writeJsonSync(path_1.join(authFolder, 'policy'), authPolicy);
115
- writeJsonSync(path_1.join(authFolder, 'whitelist'), {});
116
- writeJsonSync(path_1.join(authFolder, 'blacklist'), {});
117
- writeJsonSync(path_1.join(authFolder, 'invites'), {});
114
+ writeJsonSync((0, path_1.join)(authFolder, 'policy'), authPolicy);
115
+ writeJsonSync((0, path_1.join)(authFolder, 'whitelist'), {});
116
+ writeJsonSync((0, path_1.join)(authFolder, 'blacklist'), {});
117
+ writeJsonSync((0, path_1.join)(authFolder, 'invites'), {});
118
118
  }
119
119
  class Users {
120
120
  constructor(rootFolder, noTokenFile) {
@@ -122,25 +122,25 @@ class Users {
122
122
  if (!fs.existsFolderSync(rootFolder)) {
123
123
  throw new Error(`Given root folder does not exist: ${rootFolder}`);
124
124
  }
125
- const folders = server_data_folders_1.treeInRootFolder(rootFolder);
126
- server_data_folders_1.createFolderTreeSync(folders);
125
+ const folders = (0, server_data_folders_1.treeInRootFolder)(rootFolder);
126
+ (0, server_data_folders_1.createFolderTreeSync)(folders);
127
127
  this.users = folders.users.path;
128
128
  this.defaults = folders.defaults.path;
129
129
  this.tokens = folders.tokens.path;
130
130
  this.populateDefaultsIfEmpty();
131
131
  }
132
132
  populateDefaultsIfEmpty() {
133
- if (fs_1.readdirSync(this.defaults).length > 0) {
133
+ if ((0, fs_1.readdirSync)(this.defaults).length > 0) {
134
134
  return;
135
135
  }
136
- const defaults = server_data_folders_1.treeInDefaultsFolder(this.defaults);
137
- server_data_folders_1.createFolderTreeSync(defaults);
136
+ const defaults = (0, server_data_folders_1.treeInDefaultsFolder)(this.defaults);
137
+ (0, server_data_folders_1.createFolderTreeSync)(defaults);
138
138
  setGeneralDefaults(defaults);
139
139
  setMailDefaults(defaults.mail);
140
140
  setStoreDefaults(defaults.store);
141
141
  }
142
142
  userFolderPath(userId) {
143
- return path_1.join(this.users, server_data_folders_1.addressToFName(userId));
143
+ return (0, path_1.join)(this.users, (0, server_data_folders_1.addressToFName)(userId));
144
144
  }
145
145
  async add(userId, midParams, storeKeyDerivParams, signupToken) {
146
146
  if (!validateUserMidParams(midParams)) {
@@ -161,16 +161,16 @@ class Users {
161
161
  });
162
162
  try {
163
163
  // make folder tree
164
- const tree = server_data_folders_1.treeInUserFolder(userFolder);
165
- await server_data_folders_1.createFolderTree(tree);
164
+ const tree = (0, server_data_folders_1.treeInUserFolder)(userFolder);
165
+ await (0, server_data_folders_1.createFolderTree)(tree);
166
166
  // record user id
167
- await fs.writeFile(path_1.join(tree.info.path, 'userid'), userId, { encoding: 'utf8', flag: 'w', mode: '440' });
167
+ await fs.writeFile((0, path_1.join)(tree.info.path, 'userid'), userId, { encoding: 'utf8', flag: 'w', mode: '440' });
168
168
  // copy defaults
169
169
  await fs.copyTree(this.defaults, userFolder);
170
170
  // record mid parameters
171
- await writeJson(path_1.join(tree.info.path, 'mid-params'), midParams);
171
+ await writeJson((0, path_1.join)(tree.info.path, 'mid-params'), midParams);
172
172
  // record storage params
173
- await writeJson(path_1.join(tree.store.params.path, 'key-deriv'), storeKeyDerivParams);
173
+ await writeJson((0, path_1.join)(tree.store.params.path, 'key-deriv'), storeKeyDerivParams);
174
174
  if (rmToken) {
175
175
  await rmToken();
176
176
  }
@@ -182,21 +182,21 @@ class Users {
182
182
  }
183
183
  async checkIfCreationAllowed(userId, signupToken) {
184
184
  if (signupToken) {
185
- const t = signup_tokens_1.parseToken(signupToken);
185
+ const t = (0, signup_tokens_1.parseToken)(signupToken);
186
186
  if (!t) {
187
187
  throw exports.SC.CREATION_UNAUTHORIZED;
188
188
  }
189
- const ctxFilePath = path_1.join(this.tokens, t.tokenFile);
189
+ const ctxFilePath = (0, path_1.join)(this.tokens, t.tokenFile);
190
190
  const str = await fs.readFile(ctxFilePath, { encoding: 'utf8' })
191
191
  .catch((exc) => {
192
192
  throw (exc.notFound ? exports.SC.CREATION_UNAUTHORIZED : exc);
193
193
  });
194
194
  try {
195
195
  const ctx = JSON.parse(str);
196
- if (ctx.token && !signup_tokens_1.areTokensSame(t.tokenBytes, ctx.token)) {
196
+ if (ctx.token && !(0, signup_tokens_1.areTokensSame)(t.tokenBytes, ctx.token)) {
197
197
  throw exports.SC.CREATION_UNAUTHORIZED;
198
198
  }
199
- if (signup_tokens_1.canCreateUser(userId, ctx)) {
199
+ if ((0, signup_tokens_1.canCreateUser)(userId, ctx)) {
200
200
  if (ctx.type === 'single-user') {
201
201
  return () => fs.unlink(ctxFilePath).catch(noop);
202
202
  }
@@ -206,20 +206,20 @@ class Users {
206
206
  }
207
207
  }
208
208
  catch (err) {
209
- throw error_1.errWithCause(err, `Error occured in using file ${ctxFilePath} as a signup context.`);
209
+ throw (0, error_1.errWithCause)(err, `Error occured in using file ${ctxFilePath} as a signup context.`);
210
210
  }
211
211
  }
212
212
  else if (this.noTokenFile) {
213
213
  try {
214
214
  const str = await fs.readFile(this.noTokenFile, { encoding: 'utf8' });
215
215
  const ctx = JSON.parse(str);
216
- if (signup_tokens_1.canCreateUser(userId, ctx)) {
216
+ if ((0, signup_tokens_1.canCreateUser)(userId, ctx)) {
217
217
  return;
218
218
  }
219
219
  }
220
220
  catch (exc) {
221
221
  if (!exc.notFound) {
222
- throw error_1.errWithCause(exc, `Error occured in using file ${this.noTokenFile} as a no-token signup context.`);
222
+ throw (0, error_1.errWithCause)(exc, `Error occured in using file ${this.noTokenFile} as a no-token signup context.`);
223
223
  }
224
224
  }
225
225
  }
@@ -227,11 +227,11 @@ class Users {
227
227
  }
228
228
  async getAvailableDomains(signupToken) {
229
229
  if (signupToken) {
230
- const t = signup_tokens_1.parseToken(signupToken);
230
+ const t = (0, signup_tokens_1.parseToken)(signupToken);
231
231
  if (!t) {
232
232
  return [];
233
233
  }
234
- const ctxFilePath = path_1.join(this.tokens, t.tokenFile);
234
+ const ctxFilePath = (0, path_1.join)(this.tokens, t.tokenFile);
235
235
  const str = await fs.readFile(ctxFilePath, { encoding: 'utf8' })
236
236
  .catch((exc) => {
237
237
  if (exc.notFound) {
@@ -247,7 +247,7 @@ class Users {
247
247
  try {
248
248
  const ctx = JSON.parse(str);
249
249
  if ((ctx.type === 'single-user')
250
- || (ctx.token && !signup_tokens_1.areTokensSame(t.tokenBytes, ctx.token))) {
250
+ || (ctx.token && !(0, signup_tokens_1.areTokensSame)(t.tokenBytes, ctx.token))) {
251
251
  return [];
252
252
  }
253
253
  else {
@@ -255,7 +255,7 @@ class Users {
255
255
  }
256
256
  }
257
257
  catch (err) {
258
- throw error_1.errWithCause(err, `Error occured in using file ${ctxFilePath} as a signup context.`);
258
+ throw (0, error_1.errWithCause)(err, `Error occured in using file ${ctxFilePath} as a signup context.`);
259
259
  }
260
260
  }
261
261
  else if (this.noTokenFile) {
@@ -269,7 +269,7 @@ class Users {
269
269
  return [];
270
270
  }
271
271
  else {
272
- throw error_1.errWithCause(exc, `Error occured in using file ${this.noTokenFile} as a no-token signup context.`);
272
+ throw (0, error_1.errWithCause)(exc, `Error occured in using file ${this.noTokenFile} as a no-token signup context.`);
273
273
  }
274
274
  }
275
275
  }
@@ -279,11 +279,11 @@ class Users {
279
279
  }
280
280
  async getAvailableAddresses(name, signupToken) {
281
281
  if (signupToken) {
282
- const t = signup_tokens_1.parseToken(signupToken);
282
+ const t = (0, signup_tokens_1.parseToken)(signupToken);
283
283
  if (!t) {
284
284
  return [];
285
285
  }
286
- const ctxFilePath = path_1.join(this.tokens, t.tokenFile);
286
+ const ctxFilePath = (0, path_1.join)(this.tokens, t.tokenFile);
287
287
  const str = await fs.readFile(ctxFilePath, { encoding: 'utf8' })
288
288
  .catch((exc) => {
289
289
  if (exc.notFound) {
@@ -298,13 +298,13 @@ class Users {
298
298
  }
299
299
  try {
300
300
  const ctx = JSON.parse(str);
301
- if (ctx.token && !signup_tokens_1.areTokensSame(t.tokenBytes, ctx.token)) {
301
+ if (ctx.token && !(0, signup_tokens_1.areTokensSame)(t.tokenBytes, ctx.token)) {
302
302
  return [];
303
303
  }
304
304
  return this.availableAddressInCtx(name, ctx);
305
305
  }
306
306
  catch (err) {
307
- throw error_1.errWithCause(err, `Error occured in using file ${ctxFilePath} as a signup context.`);
307
+ throw (0, error_1.errWithCause)(err, `Error occured in using file ${ctxFilePath} as a signup context.`);
308
308
  }
309
309
  }
310
310
  else if (this.noTokenFile) {
@@ -318,7 +318,7 @@ class Users {
318
318
  return [];
319
319
  }
320
320
  else {
321
- throw error_1.errWithCause(exc, `Error occured in using file ${this.noTokenFile} as a no-token signup context.`);
321
+ throw (0, error_1.errWithCause)(exc, `Error occured in using file ${this.noTokenFile} as a no-token signup context.`);
322
322
  }
323
323
  }
324
324
  }
@@ -327,7 +327,7 @@ class Users {
327
327
  }
328
328
  }
329
329
  async availableAddressInCtx(name, ctx) {
330
- const allIds = signup_tokens_1.addressesForName(name, ctx);
330
+ const allIds = (0, signup_tokens_1.addressesForName)(name, ctx);
331
331
  if (!allIds) {
332
332
  return [];
333
333
  }
@@ -357,9 +357,9 @@ class Users {
357
357
  }
358
358
  wrap() {
359
359
  const wrap = {
360
- getAvailableDomains: binding_1.bind(this, this.getAvailableDomains),
361
- getAvailableAddresses: binding_1.bind(this, this.getAvailableAddresses),
362
- add: binding_1.bind(this, this.add),
360
+ getAvailableDomains: (0, binding_1.bind)(this, this.getAvailableDomains),
361
+ getAvailableAddresses: (0, binding_1.bind)(this, this.getAvailableAddresses),
362
+ add: (0, binding_1.bind)(this, this.add),
363
363
  };
364
364
  Object.freeze(wrap);
365
365
  return wrap;
@@ -24,15 +24,15 @@ function addUser(addUserFunc) {
24
24
  return async function (req, res, next) {
25
25
  const { mailerId, storage, userId, signupToken } = req.body;
26
26
  if (('string' !== typeof userId)
27
- || !canonical_address_1.checkAndTransformAddress(userId)) {
27
+ || !(0, canonical_address_1.checkAndTransformAddress)(userId)) {
28
28
  res.status(signup_1.ERR_SC.malformed).send('Given user id is malformed.');
29
29
  return;
30
30
  }
31
- if (!users_1.validateUserMidParams(mailerId)) {
31
+ if (!(0, users_1.validateUserMidParams)(mailerId)) {
32
32
  res.status(signup_1.ERR_SC.malformed).send('MailerId parameters are malformed.');
33
33
  return;
34
34
  }
35
- if (!users_1.validateUserStorageParams(storage)) {
35
+ if (!(0, users_1.validateUserStorageParams)(storage)) {
36
36
  res.status(signup_1.ERR_SC.malformed).send('Storage parameters are malformed.');
37
37
  return;
38
38
  }
@@ -31,7 +31,7 @@ function canCreateUser(userId, ctx) {
31
31
  return false;
32
32
  }
33
33
  }
34
- const cAddr = canonical_address_1.toCanonicalAddress(userId);
34
+ const cAddr = (0, canonical_address_1.toCanonicalAddress)(userId);
35
35
  if (ctx.type === 'single-user') {
36
36
  return (cAddr === ctx.userId);
37
37
  }
@@ -52,7 +52,7 @@ function addressesForName(name, ctx) {
52
52
  }
53
53
  if (ctx.type === 'single-user') {
54
54
  const userId = `${name}${ctx.userId.substring(ctx.userId.indexOf('@'))}`;
55
- return ((canonical_address_1.toCanonicalAddress(userId) === ctx.userId) ?
55
+ return (((0, canonical_address_1.toCanonicalAddress)(userId) === ctx.userId) ?
56
56
  [userId] : []);
57
57
  }
58
58
  else if (ctx.type === 'multi-domain') {
@@ -67,7 +67,7 @@ function makeSingleUserSignupCtx(token, userId, validitySecs) {
67
67
  const ctx = {
68
68
  token,
69
69
  type: 'single-user',
70
- userId: canonical_address_1.toCanonicalAddress(userId)
70
+ userId: (0, canonical_address_1.toCanonicalAddress)(userId)
71
71
  };
72
72
  if (validitySecs) {
73
73
  ctx.validTill = Math.floor(Date.now() / 1000) + validitySecs;
@@ -76,11 +76,11 @@ function makeSingleUserSignupCtx(token, userId, validitySecs) {
76
76
  }
77
77
  exports.makeSingleUserSignupCtx = makeSingleUserSignupCtx;
78
78
  function makeMultiDomainSignupCtx(signupDomains, token, validitySecs) {
79
- assert_1.assert(Array.isArray(signupDomains));
79
+ (0, assert_1.assert)(Array.isArray(signupDomains));
80
80
  const ctx = {
81
81
  token,
82
82
  type: 'multi-domain',
83
- domains: signupDomains.map(d => canonical_address_1.toCanonicalAddress(d).substring(1))
83
+ domains: signupDomains.map(d => (0, canonical_address_1.toCanonicalAddress)(d).substring(1))
84
84
  };
85
85
  if (validitySecs) {
86
86
  ctx.validTill = Math.floor(Date.now() / 1000) + validitySecs;
@@ -91,7 +91,7 @@ exports.makeMultiDomainSignupCtx = makeMultiDomainSignupCtx;
91
91
  const TOKEN_BYTES_LEN = 30;
92
92
  const TOKEN_FILE_NAME_LEN = 10;
93
93
  async function generateToken() {
94
- const tokenBytes = await random_node_1.bytes(TOKEN_BYTES_LEN);
94
+ const tokenBytes = await (0, random_node_1.bytes)(TOKEN_BYTES_LEN);
95
95
  const token = buffer_utils_1.base64urlSafe.pack(tokenBytes);
96
96
  return token;
97
97
  }
@@ -111,13 +111,13 @@ function tokenFileName(token) {
111
111
  return token.substring(0, TOKEN_FILE_NAME_LEN);
112
112
  }
113
113
  function tokenPath(rootFolder, token) {
114
- return path_1.join(server_data_folders_1.tokensInRootFolder(rootFolder), tokenFileName(token));
114
+ return (0, path_1.join)((0, server_data_folders_1.tokensInRootFolder)(rootFolder), tokenFileName(token));
115
115
  }
116
116
  exports.tokenPath = tokenPath;
117
117
  function areTokensSame(t1, t2) {
118
118
  try {
119
119
  const t2Bytes = buffer_utils_1.base64urlSafe.open(t2);
120
- return ecma_nacl_1.compareVectors(t1, t2Bytes);
120
+ return (0, ecma_nacl_1.compareVectors)(t1, t2Bytes);
121
121
  }
122
122
  catch (err) {
123
123
  return false;
@@ -49,14 +49,14 @@ function setupStaticEntryRoute(app) {
49
49
  function makeApp(rootFolder, domain, midAuthorizer) {
50
50
  const app = new app_1.AppWithWSs();
51
51
  const mailDeliverySessions = delivery_sessions_1.DeliverySessions.make(5 * 60);
52
- const recipientsSessions = sessions_1.makeSessionFactory(10 * 60);
53
- const userSettingSessions = sessions_1.makeSessionFactory(10 * 60);
54
- const recipients = recipients_1.makeFactory(rootFolder);
52
+ const recipientsSessions = (0, sessions_1.makeSessionFactory)(10 * 60);
53
+ const userSettingSessions = (0, sessions_1.makeSessionFactory)(10 * 60);
54
+ const recipients = (0, recipients_1.makeFactory)(rootFolder);
55
55
  setupStaticEntryRoute(app.http);
56
- app.http.use(PATHS.delivery, delivery_1.makeApp(domain, mailDeliverySessions, recipients, midAuthorizer));
57
- app.use(PATHS.retrieval, retrieval_1.makeApp(domain, recipientsSessions, recipients, midAuthorizer));
58
- app.http.use(PATHS.config, config_1.makeApp(domain, userSettingSessions, recipients, midAuthorizer));
59
- app.http.use(error_handler_1.makeErrHandler((err, req) => {
56
+ app.http.use(PATHS.delivery, (0, delivery_1.makeApp)(domain, mailDeliverySessions, recipients, midAuthorizer));
57
+ app.use(PATHS.retrieval, (0, retrieval_1.makeApp)(domain, recipientsSessions, recipients, midAuthorizer));
58
+ app.http.use(PATHS.config, (0, config_1.makeApp)(domain, userSettingSessions, recipients, midAuthorizer));
59
+ app.http.use((0, error_handler_1.makeErrHandler)((err, req) => {
60
60
  if (typeof err.status !== 'number') {
61
61
  console.error(`\n --- Error occured in asmail, when handling ${req.method} request to ${req.originalUrl}`);
62
62
  console.error(err);
@@ -13,7 +13,8 @@
13
13
  See the GNU General Public License for more details.
14
14
 
15
15
  You should have received a copy of the GNU General Public License along with
16
- this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
17
18
  Object.defineProperty(exports, "__esModule", { value: true });
18
19
  exports.makeApp = void 0;
19
20
  /**
@@ -33,17 +34,17 @@ const api = require("../lib-common/service-api/asmail/config");
33
34
  function makeApp(domain, sessions, recipients, midAuthorizer) {
34
35
  const app = express();
35
36
  app.disable('etag');
36
- app.post('/' + api.midLogin.START_URL_END, sessions.checkSession(), body_parsers_1.json('1kb'), start_1.startSession(recipients.exists, sessions.generate));
37
- app.post('/' + api.midLogin.AUTH_URL_END, sessions.ensureOpenedSession(), body_parsers_1.json('4kb'), mid_auth_1.midLogin(domain, midAuthorizer));
37
+ app.post('/' + api.midLogin.START_URL_END, sessions.checkSession(), (0, body_parsers_1.json)('1kb'), (0, start_1.startSession)(recipients.exists, sessions.generate));
38
+ app.post('/' + api.midLogin.AUTH_URL_END, sessions.ensureOpenedSession(), (0, body_parsers_1.json)('4kb'), (0, mid_auth_1.midLogin)(domain, midAuthorizer));
38
39
  // *** Require authorized session for everything below ***
39
40
  app.use(sessions.ensureAuthorizedSession());
40
- app.post('/' + api.closeSession.URL_END, body_parsers_1.emptyBody(), close_1.closeSession());
41
+ app.post('/' + api.closeSession.URL_END, (0, body_parsers_1.emptyBody)(), (0, close_1.closeSession)());
41
42
  app.route('/' + api.p.initPubKey.URL_END)
42
- .get(param_getter_1.getParam(recipients.getPubKey))
43
- .put(body_parsers_1.json('4kb', true), param_setter_1.setParam(recipients.setPubKey));
43
+ .get((0, param_getter_1.getParam)(recipients.getPubKey))
44
+ .put((0, body_parsers_1.json)('4kb', true), (0, param_setter_1.setParam)(recipients.setPubKey));
44
45
  app.route('/' + api.p.anonSenderInvites.URL_END)
45
- .get(param_getter_1.getParam(recipients.getAnonSenderInvites))
46
- .put(body_parsers_1.json('4kb', true), param_setter_1.setParam(recipients.setAnonSenderInvites));
46
+ .get((0, param_getter_1.getParam)(recipients.getAnonSenderInvites))
47
+ .put((0, body_parsers_1.json)('4kb', true), (0, param_setter_1.setParam)(recipients.setAnonSenderInvites));
47
48
  return app;
48
49
  }
49
50
  exports.makeApp = makeApp;
@@ -13,7 +13,8 @@
13
13
  See the GNU General Public License for more details.
14
14
 
15
15
  You should have received a copy of the GNU General Public License along with
16
- this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
17
18
  Object.defineProperty(exports, "__esModule", { value: true });
18
19
  exports.makeApp = void 0;
19
20
  /**
@@ -37,16 +38,16 @@ const MAX_CHUNK_SIZE = '0.5mb';
37
38
  function makeApp(domain, sessions, recipients, midAuthorizer) {
38
39
  const app = express();
39
40
  app.disable('etag');
40
- app.post('/' + api.sessionStart.URL_END, sessions.checkSession(), body_parsers_1.json('1kb'), start_session_1.startSession(recipients.allowedMaxMsgSize, sessions.generate));
41
- app.post('/' + api.preFlight.URL_END, sessions.checkSession(), body_parsers_1.json('1kb'), pre_flight_1.preFlight(recipients.allowedMaxMsgSize));
42
- app.post('/' + api.sessionRestart.URL_END, sessions.checkSession(), body_parsers_1.json('1kb'), restart_session_1.restartSession(sessions.generate, sessions.getSessionForMsg, recipients.incompleteMsgDeliveryParams, MAX_CHUNK_SIZE));
43
- app.post('/' + api.authSender.URL_END, sessions.ensureOpenedSession(), body_parsers_1.json('4kb'), sender_authorization_1.authorize(domain, midAuthorizer));
41
+ app.post('/' + api.sessionStart.URL_END, sessions.checkSession(), (0, body_parsers_1.json)('1kb'), (0, start_session_1.startSession)(recipients.allowedMaxMsgSize, sessions.generate));
42
+ app.post('/' + api.preFlight.URL_END, sessions.checkSession(), (0, body_parsers_1.json)('1kb'), (0, pre_flight_1.preFlight)(recipients.allowedMaxMsgSize));
43
+ app.post('/' + api.sessionRestart.URL_END, sessions.checkSession(), (0, body_parsers_1.json)('1kb'), (0, restart_session_1.restartSession)(sessions.generate, sessions.getSessionForMsg, recipients.incompleteMsgDeliveryParams, MAX_CHUNK_SIZE));
44
+ app.post('/' + api.authSender.URL_END, sessions.ensureOpenedSession(), (0, body_parsers_1.json)('4kb'), (0, sender_authorization_1.authorize)(domain, midAuthorizer));
44
45
  // *** Require authorized session for everything below ***
45
46
  app.use(sessions.ensureAuthorizedSession());
46
- app.get('/' + api.initPubKey.URL_END, provide_recipient_pubkey_1.getRecipientPubKey(recipients.getPubKey));
47
- app.put('/' + api.msgMeta.URL_END, body_parsers_1.json('16kb'), put_metadata_1.saveMetadata(recipients.setMsgStorage, MAX_CHUNK_SIZE));
48
- app.put('/' + api.msgObj.EXPRESS_URL_END, put_obj_1.saveMsgObj(recipients.saveObj, MAX_CHUNK_SIZE));
49
- app.post('/' + api.completion.URL_END, body_parsers_1.emptyBody(), finalize_delivery_1.finalizeDelivery(recipients.finalizeDelivery));
47
+ app.get('/' + api.initPubKey.URL_END, (0, provide_recipient_pubkey_1.getRecipientPubKey)(recipients.getPubKey));
48
+ app.put('/' + api.msgMeta.URL_END, (0, body_parsers_1.json)('16kb'), (0, put_metadata_1.saveMetadata)(recipients.setMsgStorage, MAX_CHUNK_SIZE));
49
+ app.put('/' + api.msgObj.EXPRESS_URL_END, (0, put_obj_1.saveMsgObj)(recipients.saveObj, MAX_CHUNK_SIZE));
50
+ app.post('/' + api.completion.URL_END, (0, body_parsers_1.emptyBody)(), (0, finalize_delivery_1.finalizeDelivery)(recipients.finalizeDelivery));
50
51
  return app;
51
52
  }
52
53
  exports.makeApp = makeApp;
@@ -13,7 +13,8 @@
13
13
  See the GNU General Public License for more details.
14
14
 
15
15
  You should have received a copy of the GNU General Public License along with
16
- this program. If not, see <http://www.gnu.org/licenses/>. */
16
+ this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
17
18
  Object.defineProperty(exports, "__esModule", { value: true });
18
19
  exports.DeliverySessions = void 0;
19
20
  /**
@@ -82,8 +83,8 @@ class DeliverySessions extends mem_backed_sessions_factory_1.InMemorySessions {
82
83
  */
83
84
  static make(timeout) {
84
85
  const factory = new DeliverySessions(timeout);
85
- const wrap = sessions_1.wrapFactory(factory);
86
- wrap.getSessionForMsg = binding_1.bind(factory, factory.getSessionForMsg);
86
+ const wrap = (0, sessions_1.wrapFactory)(factory);
87
+ wrap.getSessionForMsg = (0, binding_1.bind)(factory, factory.getSessionForMsg);
87
88
  return Object.freeze(wrap);
88
89
  }
89
90
  }
@@ -53,7 +53,7 @@ export declare class Inbox extends UserFiles {
53
53
  * @param completeMsg flag, true for complete messages, and false for
54
54
  * incomplete (in-delivery) messages.
55
55
  */
56
- getMsgMeta(msgId: string, completeMsg: any): Promise<MsgMeta>;
56
+ getMsgMeta(msgId: string, completeMsg: boolean): Promise<MsgMeta>;
57
57
  startSavingObj(msgId: string, objId: string, bytes: Readable, bytesLen: number, opts: deliveryApi.PutObjFirstQueryOpts): Promise<void>;
58
58
  continueSavingObj(msgId: string, objId: string, bytes: Readable, bytesLen: number, opts: deliveryApi.PutObjSecondQueryOpts): Promise<void>;
59
59
  /**
@@ -63,7 +63,7 @@ async function genMsgIdAndMakeFolder(delivPath, msgsFolder) {
63
63
  const msgId = await random.stringOfB64UrlSafeChars(MSG_ID_LEN);
64
64
  // make msg folder among deliveries
65
65
  try {
66
- await fs.mkdir(path_1.join(delivPath, msgId));
66
+ await fs.mkdir((0, path_1.join)(delivPath, msgId));
67
67
  }
68
68
  catch (exc) {
69
69
  if (exc.alreadyExists) {
@@ -75,8 +75,8 @@ async function genMsgIdAndMakeFolder(delivPath, msgsFolder) {
75
75
  }
76
76
  // ensure that msgId does not belong to any existing message
77
77
  try {
78
- await fs.stat(path_1.join(msgsFolder, msgId));
79
- await fs.rmdir(path_1.join(delivPath, msgId));
78
+ await fs.stat((0, path_1.join)(msgsFolder, msgId));
79
+ await fs.rmdir((0, path_1.join)(delivPath, msgId));
80
80
  return genMsgIdAndMakeFolder(delivPath, msgsFolder);
81
81
  }
82
82
  catch (exc) { }
@@ -85,13 +85,13 @@ async function genMsgIdAndMakeFolder(delivPath, msgsFolder) {
85
85
  class Inbox extends user_files_1.UserFiles {
86
86
  constructor(userId, path, mailEventsSink, writeBufferSize, readBufferSize) {
87
87
  super(userId, path, writeBufferSize, readBufferSize);
88
- this.metas = new MsgMetas(5 * 60 * 1000, path_1.join(this.path, 'delivery'), path_1.join(this.path, 'messages'));
88
+ this.metas = new MsgMetas(5 * 60 * 1000, (0, path_1.join)(this.path, 'delivery'), (0, path_1.join)(this.path, 'messages'));
89
89
  this.objFiles = new ObjFiles(5 * 60 * 1000, this.metas.deliveryFolder, this.metas.readyMsgsFolder);
90
90
  this.mailEventsSink = mailEventsSink;
91
91
  Object.freeze(this);
92
92
  }
93
93
  static async make(userFolder, userId, mailEventsSink, writeBufferSize, readBufferSize) {
94
- const path = path_1.join(userFolder, 'mail');
94
+ const path = (0, path_1.join)(userFolder, 'mail');
95
95
  const inbox = new Inbox(userId, path, mailEventsSink, writeBufferSize, readBufferSize);
96
96
  await inbox.ensureUserExistsOnDisk();
97
97
  return inbox;
@@ -153,8 +153,8 @@ class Inbox extends user_files_1.UserFiles {
153
153
  throw exports.SC.WRONG_OBJ_STATE;
154
154
  }
155
155
  const file = await this.objFiles.forNewFile(msgId, objId);
156
- const chunks = utils_1.chunksInOrderedStream(bytesLen, opts.header, 0);
157
- await utils_1.streamToObjFile(file, chunks, bytes, this.fileWritingBufferSize);
156
+ const chunks = (0, utils_1.chunksInOrderedStream)(bytesLen, opts.header, 0);
157
+ await (0, utils_1.streamToObjFile)(file, chunks, bytes, this.fileWritingBufferSize);
158
158
  // set obj status in meta
159
159
  meta.objs[objId] = {
160
160
  size: {
@@ -191,8 +191,8 @@ class Inbox extends user_files_1.UserFiles {
191
191
  }
192
192
  }
193
193
  const file = await this.objFiles.forExistingFile(msgId, objId, true);
194
- const chunks = utils_1.chunksInOrderedStream(bytesLen, undefined, opts.ofs);
195
- await utils_1.streamToObjFile(file, chunks, bytes, this.fileWritingBufferSize);
194
+ const chunks = (0, utils_1.chunksInOrderedStream)(bytesLen, undefined, opts.ofs);
195
+ await (0, utils_1.streamToObjFile)(file, chunks, bytes, this.fileWritingBufferSize);
196
196
  // update meta
197
197
  objStatus.size.segments += bytesLen;
198
198
  if (opts.last) {
@@ -221,8 +221,8 @@ class Inbox extends user_files_1.UserFiles {
221
221
  meta.deliveryCompletion = Date.now();
222
222
  await this.metas.set(msgId, meta);
223
223
  // move message folder to a place with completed messages
224
- const srcFolder = path_1.join(this.metas.deliveryFolder, msgId);
225
- const dstFolder = path_1.join(this.metas.readyMsgsFolder, msgId);
224
+ const srcFolder = (0, path_1.join)(this.metas.deliveryFolder, msgId);
225
+ const dstFolder = (0, path_1.join)(this.metas.readyMsgsFolder, msgId);
226
226
  await fs.rename(srcFolder, dstFolder);
227
227
  this.objFiles.changeToReadingPathsInMsg(msgId);
228
228
  // raise event about completion of receiving a message
@@ -267,7 +267,7 @@ class Inbox extends user_files_1.UserFiles {
267
267
  this.metas.uncache(msgId);
268
268
  this.objFiles.uncache(msgId);
269
269
  try {
270
- const msgPath = path_1.join(this.metas.readyMsgsFolder, msgId);
270
+ const msgPath = (0, path_1.join)(this.metas.readyMsgsFolder, msgId);
271
271
  const rmPath = `${msgPath}~remove`;
272
272
  await fs.rename(msgPath, rmPath);
273
273
  await fs.rmDirWithContent(rmPath);
@@ -315,14 +315,14 @@ class Inbox extends user_files_1.UserFiles {
315
315
  len: (segBytesToRead + headerLen),
316
316
  segsLen,
317
317
  headerLen,
318
- pipe: utils_1.makeNoBaseObjPipe(file, true, segsOfs, segBytesToRead)
318
+ pipe: (0, utils_1.makeNoBaseObjPipe)(file, true, segsOfs, segBytesToRead)
319
319
  };
320
320
  }
321
321
  else {
322
322
  reader = {
323
323
  len: segBytesToRead,
324
324
  segsLen,
325
- pipe: utils_1.makeNoBaseObjPipe(file, false, segsOfs, segBytesToRead)
325
+ pipe: (0, utils_1.makeNoBaseObjPipe)(file, false, segsOfs, segBytesToRead)
326
326
  };
327
327
  }
328
328
  Object.freeze(reader);
@@ -342,9 +342,9 @@ class Inbox extends user_files_1.UserFiles {
342
342
  }
343
343
  else {
344
344
  const isOK = (typeof initKeyCerts === 'object') && !!initKeyCerts &&
345
- jwkeys_1.isLikeSignedKeyCert(initKeyCerts.pkeyCert) &&
346
- jwkeys_1.isLikeSignedKeyCert(initKeyCerts.userCert) &&
347
- jwkeys_1.isLikeSignedKeyCert(initKeyCerts.provCert);
345
+ (0, jwkeys_1.isLikeSignedKeyCert)(initKeyCerts.pkeyCert) &&
346
+ (0, jwkeys_1.isLikeSignedKeyCert)(initKeyCerts.userCert) &&
347
+ (0, jwkeys_1.isLikeSignedKeyCert)(initKeyCerts.provCert);
348
348
  if (!isOK) {
349
349
  return false;
350
350
  }
@@ -565,10 +565,10 @@ class ObjFiles {
565
565
  return objFile;
566
566
  }
567
567
  objFileWritingPath(msgId, objId) {
568
- return path_1.join(this.deliveryFolder, msgId, objId);
568
+ return (0, path_1.join)(this.deliveryFolder, msgId, objId);
569
569
  }
570
570
  objFileReadingPath(msgId, objId) {
571
- return path_1.join(this.readyMsgsFolder, msgId, objId);
571
+ return (0, path_1.join)(this.readyMsgsFolder, msgId, objId);
572
572
  }
573
573
  changeToReadingPathsInMsg(msgId) {
574
574
  const msgObjs = this.cache.get(msgId);
@@ -608,7 +608,7 @@ class MsgMetas {
608
608
  return meta;
609
609
  }
610
610
  async fromFile(msgId, completeMsg) {
611
- const filePath = path_1.join((completeMsg ? this.readyMsgsFolder : this.deliveryFolder), msgId, META_FILE);
611
+ const filePath = (0, path_1.join)((completeMsg ? this.readyMsgsFolder : this.deliveryFolder), msgId, META_FILE);
612
612
  const str = await fs.readFile(filePath, { encoding: 'utf8', flag: 'r' })
613
613
  .catch((exc) => {
614
614
  if (exc.notFound) {
@@ -620,7 +620,7 @@ class MsgMetas {
620
620
  return JSON.parse(str);
621
621
  }
622
622
  catch (err) {
623
- throw error_1.errWithCause(err, `Can't parse content of message meta file`);
623
+ throw (0, error_1.errWithCause)(err, `Can't parse content of message meta file`);
624
624
  }
625
625
  }
626
626
  async set(msgId, meta) {
@@ -628,7 +628,7 @@ class MsgMetas {
628
628
  await this.saveToFile(msgId, meta);
629
629
  }
630
630
  async saveToFile(msgId, meta) {
631
- const filePath = path_1.join(this.deliveryFolder, msgId, META_FILE);
631
+ const filePath = (0, path_1.join)(this.deliveryFolder, msgId, META_FILE);
632
632
  await this.saveProcs.startOrChain(msgId, () => fs.writeFile(filePath, JSON.stringify(meta), { encoding: 'utf8', flag: 'w' }));
633
633
  }
634
634
  uncache(msgId) {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Readable } from 'stream';
3
- import { ObjReader, MailEventsSink } from './inbox';
3
+ import { Inbox, ObjReader, MailEventsSink } from './inbox';
4
4
  import * as deliveryApi from '../../lib-common/service-api/asmail/delivery';
5
5
  import * as configApi from '../../lib-common/service-api/asmail/config';
6
6
  import * as retrievalApi from '../../lib-common/service-api/asmail/retrieval';
@@ -92,4 +92,5 @@ export interface Factory {
92
92
  setAnonSenderInvites: SetAnonSenderInvites;
93
93
  setMailEventsSink(sink: EventsSink): void;
94
94
  }
95
+ export declare type StaticSetter<T> = (inbox: Inbox, param: T, setDefault: boolean) => Promise<boolean>;
95
96
  export declare function makeFactory(rootFolder: string, writeBufferSize?: string | number, readBufferSize?: string | number): Factory;