czech-data-box 0.1.2 → 0.2.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 (81) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +277 -48
  3. package/dist/index.d.ts +5 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +4 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/lib/ISDSBox.d.ts +96 -0
  8. package/dist/lib/ISDSBox.d.ts.map +1 -0
  9. package/dist/lib/ISDSBox.js +662 -0
  10. package/dist/lib/ISDSBox.js.map +1 -0
  11. package/dist/lib/ISDSSentOutFiles.d.ts +14 -0
  12. package/dist/lib/ISDSSentOutFiles.d.ts.map +1 -0
  13. package/dist/lib/ISDSSentOutFiles.js +44 -0
  14. package/dist/lib/ISDSSentOutFiles.js.map +1 -0
  15. package/dist/lib/ISDSSoapClient.d.ts +25 -0
  16. package/dist/lib/ISDSSoapClient.d.ts.map +1 -0
  17. package/dist/lib/ISDSSoapClient.js +178 -0
  18. package/dist/lib/ISDSSoapClient.js.map +1 -0
  19. package/dist/lib/config.d.ts +7 -0
  20. package/dist/lib/config.d.ts.map +1 -0
  21. package/dist/lib/config.js +94 -0
  22. package/dist/lib/config.js.map +1 -0
  23. package/dist/models/DataBox.d.ts +34 -0
  24. package/dist/models/DataBox.d.ts.map +1 -0
  25. package/dist/models/DataBox.js +92 -0
  26. package/dist/models/DataBox.js.map +1 -0
  27. package/dist/models/DataMessage.d.ts +29 -0
  28. package/dist/models/DataMessage.d.ts.map +1 -0
  29. package/dist/models/DataMessage.js +96 -0
  30. package/dist/models/DataMessage.js.map +1 -0
  31. package/dist/models/DataMessageFile.d.ts +22 -0
  32. package/dist/models/DataMessageFile.d.ts.map +1 -0
  33. package/dist/models/DataMessageFile.js +54 -0
  34. package/dist/models/DataMessageFile.js.map +1 -0
  35. package/dist/models/DataMessageFiles.d.ts +9 -0
  36. package/dist/models/DataMessageFiles.d.ts.map +1 -0
  37. package/dist/models/DataMessageFiles.js +17 -0
  38. package/dist/models/DataMessageFiles.js.map +1 -0
  39. package/dist/types.d.ts +420 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/dist/types.js +2 -0
  42. package/dist/types.js.map +1 -0
  43. package/package.json +66 -40
  44. package/resources/wsdl/ChangePassword.wsdl +83 -83
  45. package/resources/wsdl/ChangePasswordTypes.xsd +68 -68
  46. package/resources/wsdl/dbTypes.xsd +1712 -1688
  47. package/resources/wsdl/db_access.wsdl +199 -197
  48. package/resources/wsdl/db_manipulations.wsdl +600 -598
  49. package/resources/wsdl/db_search.wsdl +389 -362
  50. package/resources/wsdl/dmBaseTypes.xsd +1563 -1497
  51. package/resources/wsdl/dm_VoDZ.wsdl +215 -212
  52. package/resources/wsdl/dm_arch.wsdl +77 -0
  53. package/resources/wsdl/dm_info.wsdl +462 -412
  54. package/resources/wsdl/dm_operations.wsdl +252 -242
  55. package/.gitattributes +0 -16
  56. package/.github/workflows/tests.yml +0 -39
  57. package/.nvmrc +0 -1
  58. package/.prettierignore +0 -1
  59. package/.prettierrc.yaml +0 -6
  60. package/.vscode/launch.json +0 -15
  61. package/.vscode/settings.json +0 -5
  62. package/CHANGELOG.md +0 -17
  63. package/CODE_OF_CONDUCT.md +0 -128
  64. package/CONTRIBUTING.md +0 -84
  65. package/eslint.config.js +0 -26
  66. package/examples/db_login_with_certificate.js +0 -27
  67. package/examples/db_search.js +0 -27
  68. package/examples/dm_operations.js +0 -58
  69. package/src/index.js +0 -5
  70. package/src/lib/ISDSBox.js +0 -309
  71. package/src/lib/ISDSSentOutFiles.js +0 -84
  72. package/src/lib/ISDSSoapClient.js +0 -201
  73. package/src/lib/config.js +0 -71
  74. package/src/models/DataBox.js +0 -194
  75. package/src/models/DataMessage.js +0 -153
  76. package/src/models/DataMessageFile.js +0 -69
  77. package/src/models/DataMessageFiles.js +0 -23
  78. package/test/ISDSBox.test.js +0 -129
  79. package/test/ISDSSentOutFiles.test.js +0 -124
  80. package/test/ISDSSoapClient.test.js +0 -81
  81. package/test/communication_test.pdf +0 -0
@@ -0,0 +1,662 @@
1
+ import forge from 'node-forge';
2
+ import DataMessage from '../models/DataMessage.js';
3
+ import { DEBUG, getConnectionModeFromLegacyLoginType, getServiceSoapVersion, getServiceURL, getServiceWSDL, } from './config.js';
4
+ import ISDSSentOutFiles from './ISDSSentOutFiles.js';
5
+ import ISDSSoapClient from './ISDSSoapClient.js';
6
+ function toError(error) {
7
+ return error instanceof Error ? error : new Error(String(error));
8
+ }
9
+ function isRecord(value) {
10
+ return typeof value === 'object' && value !== null;
11
+ }
12
+ function createAbortError() {
13
+ const error = new Error('Operation aborted');
14
+ error.name = 'AbortError';
15
+ return error;
16
+ }
17
+ class ISDSBox {
18
+ productionMode;
19
+ connectionMode;
20
+ loginName;
21
+ password;
22
+ certfilename;
23
+ privateKey;
24
+ publicKey;
25
+ passPhrase;
26
+ pkcs12Certificate;
27
+ debug;
28
+ operationsWS;
29
+ infoWS;
30
+ manipulationsWS;
31
+ accessWS;
32
+ searchWS;
33
+ archiveWS;
34
+ vodzWS;
35
+ constructor(loginTypeOrConnectionMode = 0, loginName = '', password = '', certfilename = '', privateKey = '', publicKey = '', passPhrase = '', pkcs12Certificate = '', production = true, debug = DEBUG) {
36
+ this.productionMode = production;
37
+ this.connectionMode =
38
+ typeof loginTypeOrConnectionMode === 'string'
39
+ ? loginTypeOrConnectionMode
40
+ : getConnectionModeFromLegacyLoginType(loginTypeOrConnectionMode);
41
+ this.loginName = loginName;
42
+ this.password = password;
43
+ this.certfilename = certfilename;
44
+ this.privateKey = privateKey;
45
+ this.publicKey = publicKey;
46
+ this.passPhrase = passPhrase;
47
+ this.pkcs12Certificate = pkcs12Certificate;
48
+ this.debug = debug;
49
+ this.initClients();
50
+ }
51
+ logDebug(message, ...payload) {
52
+ if (this.debug) {
53
+ console.log(message, ...payload);
54
+ }
55
+ }
56
+ createClient(serviceType) {
57
+ return new ISDSSoapClient(getServiceWSDL(serviceType), {
58
+ login: this.loginName,
59
+ password: this.password,
60
+ location: getServiceURL(serviceType, this.connectionMode, this.productionMode),
61
+ connectionMode: this.connectionMode,
62
+ soapVersion: getServiceSoapVersion(serviceType),
63
+ privateKey: this.privateKey,
64
+ publicKey: this.publicKey,
65
+ passPhrase: this.passPhrase,
66
+ debug: this.debug,
67
+ });
68
+ }
69
+ normalizeDateTime(value) {
70
+ if (value === undefined || value === null) {
71
+ return null;
72
+ }
73
+ return value instanceof Date ? value.toISOString() : value;
74
+ }
75
+ normalizeDate(value) {
76
+ if (value === undefined || value === null) {
77
+ return null;
78
+ }
79
+ if (value instanceof Date) {
80
+ return value.toISOString().slice(0, 10);
81
+ }
82
+ return value;
83
+ }
84
+ normalizeMessageListInput(input, orgUnitNum, recipientOrSenderKey) {
85
+ return {
86
+ dmFromTime: this.normalizeDateTime(input.dmFromTime),
87
+ dmToTime: this.normalizeDateTime(input.dmToTime),
88
+ [recipientOrSenderKey]: orgUnitNum ?? null,
89
+ dmStatusFilter: input.dmStatusFilter ?? '',
90
+ dmOffset: input.dmOffset ?? null,
91
+ dmLimit: input.dmLimit ?? null,
92
+ };
93
+ }
94
+ async buildOutgoingFiles(outFilesParams) {
95
+ const files = new ISDSSentOutFiles();
96
+ for (const file of outFilesParams) {
97
+ if ('dmFilePath' in file) {
98
+ const success = await files.addFileFromFilePath(file.dmFilePath, file.dmMimeType, file.dmFileMetaType, file.dmFileDescr, file.dmFileGuid ?? null, file.dmUpFileGuid ?? null, file.dmFormat ?? null);
99
+ if (!success) {
100
+ throw new Error(`Failed to add file from path: ${file.dmFilePath}`);
101
+ }
102
+ continue;
103
+ }
104
+ files.addFileFromMemory(file.dmEncodedContent, file.dmMimeType, file.dmFileMetaType, file.dmFileDescr, file.dmFileGuid ?? null, file.dmUpFileGuid ?? null, file.dmFormat ?? null);
105
+ }
106
+ return files.build();
107
+ }
108
+ buildMessageEnvelope(dataMessageParams) {
109
+ return (dataMessageParams instanceof DataMessage
110
+ ? dataMessageParams
111
+ : new DataMessage(dataMessageParams)).build();
112
+ }
113
+ extractMessageId(record) {
114
+ if (typeof record.dmID === 'string' && record.dmID.trim()) {
115
+ return record.dmID;
116
+ }
117
+ throw new Error('Message record does not contain a valid dmID');
118
+ }
119
+ getMessageId(record) {
120
+ return typeof record.dmID === 'string' && record.dmID.trim() ? record.dmID : null;
121
+ }
122
+ extractNotificationRecords(result) {
123
+ const records = result.ntfRecords?.ntfRecord;
124
+ if (!records) {
125
+ return [];
126
+ }
127
+ return Array.isArray(records) ? records : [records];
128
+ }
129
+ assertNotAborted(signal) {
130
+ if (signal?.aborted) {
131
+ throw createAbortError();
132
+ }
133
+ }
134
+ async sleep(ms, signal) {
135
+ this.assertNotAborted(signal);
136
+ if (ms <= 0) {
137
+ return;
138
+ }
139
+ await new Promise((resolve, reject) => {
140
+ const timeout = setTimeout(() => {
141
+ signal?.removeEventListener('abort', onAbort);
142
+ resolve();
143
+ }, ms);
144
+ const onAbort = () => {
145
+ clearTimeout(timeout);
146
+ signal?.removeEventListener('abort', onAbort);
147
+ reject(createAbortError());
148
+ };
149
+ signal?.addEventListener('abort', onAbort, { once: true });
150
+ });
151
+ }
152
+ initializeNotificationCursor(notifications) {
153
+ if (!notifications) {
154
+ return null;
155
+ }
156
+ return this.normalizeDateTime(notifications.fromTime) ?? new Date().toISOString();
157
+ }
158
+ async shouldPollInboxFromNotifications(notifications, notificationCursor) {
159
+ if (!notifications || !notificationCursor) {
160
+ return {
161
+ shouldPollInbox: false,
162
+ nextCursor: notificationCursor,
163
+ };
164
+ }
165
+ const notificationResult = await this.listNotifications({
166
+ ntfFromTime: notificationCursor,
167
+ ntfScope: notifications.scope,
168
+ });
169
+ const records = this.extractNotificationRecords(notificationResult);
170
+ return {
171
+ shouldPollInbox: records.length > 0 || notificationResult.ntfListContinues === true,
172
+ nextCursor: new Date().toISOString(),
173
+ };
174
+ }
175
+ filterSeenItems(items, seenMessageIds, seenMessageOrder, maxSeenMessageIds) {
176
+ return items.filter((item) => {
177
+ const dmID = this.getMessageId(item.record);
178
+ if (!dmID) {
179
+ return true;
180
+ }
181
+ if (seenMessageIds.has(dmID)) {
182
+ return false;
183
+ }
184
+ seenMessageIds.add(dmID);
185
+ seenMessageOrder.push(dmID);
186
+ while (seenMessageOrder.length > maxSeenMessageIds) {
187
+ const oldest = seenMessageOrder.shift();
188
+ if (oldest) {
189
+ seenMessageIds.delete(oldest);
190
+ }
191
+ }
192
+ return true;
193
+ });
194
+ }
195
+ isVodzMessage(record) {
196
+ if (typeof record.dmVODZ === 'boolean') {
197
+ return record.dmVODZ;
198
+ }
199
+ const attributesCandidates = [record.attributes, record.$attributes, record.$attr];
200
+ for (const candidate of attributesCandidates) {
201
+ if (!isRecord(candidate)) {
202
+ continue;
203
+ }
204
+ const rawValue = candidate.dmVODZ;
205
+ if (typeof rawValue === 'boolean') {
206
+ return rawValue;
207
+ }
208
+ if (typeof rawValue === 'string') {
209
+ return rawValue === 'true' || rawValue === '1';
210
+ }
211
+ }
212
+ return false;
213
+ }
214
+ async requestOn(client, context, method, args) {
215
+ try {
216
+ return await client.request(method, args);
217
+ }
218
+ catch (error) {
219
+ const normalizedError = toError(error);
220
+ console.error(`Error in ${context}:`, normalizedError.message);
221
+ throw normalizedError;
222
+ }
223
+ }
224
+ setConnectionMode(connectionMode) {
225
+ this.connectionMode = connectionMode;
226
+ this.initClients();
227
+ return this;
228
+ }
229
+ setProductionMode() {
230
+ this.productionMode = true;
231
+ this.initClients();
232
+ return this;
233
+ }
234
+ setTestMode() {
235
+ this.productionMode = false;
236
+ this.initClients();
237
+ return this;
238
+ }
239
+ setDebugMode() {
240
+ this.debug = true;
241
+ this.initClients();
242
+ return this;
243
+ }
244
+ setPublicKey(cert) {
245
+ this.publicKey = cert;
246
+ return this;
247
+ }
248
+ setPrivateKey(privateKey) {
249
+ this.privateKey = privateKey;
250
+ return this;
251
+ }
252
+ setPassPhrase(passPhrase) {
253
+ this.passPhrase = passPhrase;
254
+ return this;
255
+ }
256
+ setPkcs12Certificate(pkcs12Certificate, passPhrase) {
257
+ const p12Der = forge.util.decode64(pkcs12Certificate);
258
+ const p12Asn1 = forge.asn1.fromDer(p12Der);
259
+ const p12 = forge.pkcs12.pkcs12FromAsn1(p12Asn1, passPhrase);
260
+ let cert;
261
+ let key;
262
+ for (const safeContents of p12.safeContents) {
263
+ for (const safeBag of safeContents.safeBags) {
264
+ if (safeBag.type === forge.pki.oids.certBag && safeBag.cert) {
265
+ cert = forge.pki.certificateToPem(safeBag.cert);
266
+ }
267
+ else if (safeBag.type === forge.pki.oids.pkcs8ShroudedKeyBag && safeBag.key) {
268
+ key = forge.pki.privateKeyToPem(safeBag.key);
269
+ }
270
+ }
271
+ }
272
+ if (!cert || !key) {
273
+ throw new Error('Invalid PKCS12 certificate bundle');
274
+ }
275
+ this.pkcs12Certificate = pkcs12Certificate;
276
+ this.setPublicKey(cert).setPrivateKey(key).setPassPhrase(passPhrase);
277
+ return this;
278
+ }
279
+ loginWithUsernameAndPassword(loginName, password, productionMode = true) {
280
+ this.productionMode = productionMode;
281
+ this.connectionMode = 'basic';
282
+ this.loginName = loginName;
283
+ this.password = password;
284
+ this.initClients();
285
+ return this;
286
+ }
287
+ loginWithPkcs12Certificate(certFile, passPhrase, productionMode = true) {
288
+ this.productionMode = productionMode;
289
+ this.connectionMode = 'cert';
290
+ this.loginName = '';
291
+ this.password = '';
292
+ this.setPkcs12Certificate(certFile, passPhrase);
293
+ this.initClients();
294
+ return this;
295
+ }
296
+ loginWithUsernamePasswordAndCertificate(loginName, password, certFile, passPhrase, productionMode = true) {
297
+ this.productionMode = productionMode;
298
+ this.connectionMode = 'certds';
299
+ this.loginName = loginName;
300
+ this.password = password;
301
+ this.setPkcs12Certificate(certFile, passPhrase);
302
+ this.initClients();
303
+ return this;
304
+ }
305
+ loginWithHostedSpisServiceCertificate(dataBoxId, certFile, passPhrase, productionMode = true) {
306
+ this.productionMode = productionMode;
307
+ this.connectionMode = 'hspis';
308
+ this.loginName = dataBoxId;
309
+ this.password = '';
310
+ this.setPkcs12Certificate(certFile, passPhrase);
311
+ this.initClients();
312
+ return this;
313
+ }
314
+ initClients() {
315
+ const clients = [
316
+ ['Operations Service URL', 0],
317
+ ['Info Service URL', 1],
318
+ ['Manipulations Service URL', 2],
319
+ ['Access Service URL', 3],
320
+ ['Search Service URL', 4],
321
+ ['Archive Service URL', 5],
322
+ ['VoDZ Service URL', 6],
323
+ ];
324
+ this.logDebug('Service URLs:');
325
+ for (const [label, serviceType] of clients) {
326
+ this.logDebug(`${label}:`, getServiceURL(serviceType, this.connectionMode, this.productionMode));
327
+ }
328
+ this.operationsWS = this.createClient(0);
329
+ this.infoWS = this.createClient(1);
330
+ this.manipulationsWS = this.createClient(2);
331
+ this.accessWS = this.createClient(3);
332
+ this.searchWS = this.createClient(4);
333
+ this.archiveWS = this.createClient(5);
334
+ this.vodzWS = this.createClient(6);
335
+ }
336
+ extractMessageRecords(result) {
337
+ const records = result.dmRecords?.dmRecord;
338
+ if (!records) {
339
+ return [];
340
+ }
341
+ return Array.isArray(records) ? records : [records];
342
+ }
343
+ async createMessage(dataMessageParams, outFilesParams) {
344
+ const message = this.buildMessageEnvelope(dataMessageParams);
345
+ if (!message.dbIDRecipient?.trim()) {
346
+ throw new Error('Missing required field: dbIDRecipient');
347
+ }
348
+ if (!message.dmAnnotation?.trim()) {
349
+ throw new Error('Missing required field: dmAnnotation');
350
+ }
351
+ const input = {
352
+ dmEnvelope: message,
353
+ dmFiles: await this.buildOutgoingFiles(outFilesParams),
354
+ };
355
+ this.logDebug('Final SOAP request body:', JSON.stringify(input, null, 2));
356
+ return this.requestOn(this.operationsWS, 'createMessage', 'CreateMessage', input);
357
+ }
358
+ async createMultipleMessage(envelopeParams, recipients, outFilesParams) {
359
+ if (recipients.length === 0) {
360
+ throw new Error('At least one recipient is required for createMultipleMessage');
361
+ }
362
+ const builtEnvelope = this.buildMessageEnvelope(envelopeParams);
363
+ if (!builtEnvelope.dmAnnotation?.trim()) {
364
+ throw new Error('Missing required field: dmAnnotation');
365
+ }
366
+ const multipleEnvelope = Object.fromEntries(Object.entries(builtEnvelope).filter(([key]) => ![
367
+ 'dbIDRecipient',
368
+ 'dmRecipientOrgUnit',
369
+ 'dmRecipientOrgUnitNum',
370
+ 'dmToHands',
371
+ ].includes(key)));
372
+ return this.requestOn(this.operationsWS, 'createMultipleMessage', 'CreateMultipleMessage', {
373
+ dmRecipients: {
374
+ dmRecipient: recipients.map((recipient) => ({
375
+ dbIDRecipient: recipient.dbIDRecipient,
376
+ dmRecipientOrgUnit: recipient.dmRecipientOrgUnit ?? null,
377
+ dmRecipientOrgUnitNum: recipient.dmRecipientOrgUnitNum ?? null,
378
+ dmToHands: recipient.dmToHands ?? null,
379
+ })),
380
+ },
381
+ dmEnvelope: multipleEnvelope,
382
+ dmFiles: await this.buildOutgoingFiles(outFilesParams),
383
+ });
384
+ }
385
+ async findDataBox(dbOwnerInfo) {
386
+ return this.requestOn(this.searchWS, 'findDataBox', 'FindDataBox', dbOwnerInfo.build());
387
+ }
388
+ async getDataBoxAddress(dbID) {
389
+ return this.requestOn(this.searchWS, 'getDataBoxAddress', 'GetDataBoxAddress', { dbID });
390
+ }
391
+ async getOwnerInfoFromLogin() {
392
+ return this.requestOn(this.accessWS, 'getOwnerInfoFromLogin', 'GetOwnerInfoFromLogin', { dbDummy: '' });
393
+ }
394
+ async getPasswordInfo() {
395
+ return this.requestOn(this.accessWS, 'getPasswordInfo', 'GetPasswordInfo', { dbDummy: '' });
396
+ }
397
+ async verifyMessage(dmID) {
398
+ return this.requestOn(this.infoWS, 'verifyMessage', 'VerifyMessage', { dmID });
399
+ }
400
+ async getDeliveryInfo(dmID) {
401
+ return this.requestOn(this.infoWS, 'getDeliveryInfo', 'GetDeliveryInfo', { dmID });
402
+ }
403
+ async getSignedDeliveryInfo(dmID) {
404
+ return this.requestOn(this.infoWS, 'getSignedDeliveryInfo', 'GetSignedDeliveryInfo', { dmID });
405
+ }
406
+ async listSentMessages(input = {}) {
407
+ return this.requestOn(this.infoWS, 'listSentMessages', 'GetListOfSentMessages', this.normalizeMessageListInput(input, input.dmSenderOrgUnitNum, 'dmSenderOrgUnitNum'));
408
+ }
409
+ async listReceivedMessages(input = {}) {
410
+ return this.requestOn(this.infoWS, 'listReceivedMessages', 'GetListOfReceivedMessages', this.normalizeMessageListInput(input, input.dmRecipientOrgUnitNum, 'dmRecipientOrgUnitNum'));
411
+ }
412
+ async downloadMessage(dmID) {
413
+ return this.requestOn(this.operationsWS, 'downloadMessage', 'MessageDownload', { dmID });
414
+ }
415
+ async downloadMessageEnvelope(dmID) {
416
+ return this.requestOn(this.infoWS, 'downloadMessageEnvelope', 'MessageEnvelopeDownload', { dmID });
417
+ }
418
+ async downloadSignedMessage(dmID) {
419
+ return this.requestOn(this.operationsWS, 'downloadSignedMessage', 'SignedMessageDownload', { dmID });
420
+ }
421
+ async markMessageAsDownloaded(dmID) {
422
+ return this.requestOn(this.infoWS, 'markMessageAsDownloaded', 'MarkMessageAsDownloaded', { dmID });
423
+ }
424
+ async downloadSignedSentMessage(dmID) {
425
+ return this.requestOn(this.operationsWS, 'downloadSignedSentMessage', 'SignedSentMessageDownload', { dmID });
426
+ }
427
+ async getMessageStateChanges(input = {}) {
428
+ return this.requestOn(this.infoWS, 'getMessageStateChanges', 'GetMessageStateChanges', {
429
+ dmFromTime: this.normalizeDateTime(input.dmFromTime),
430
+ dmToTime: this.normalizeDateTime(input.dmToTime),
431
+ });
432
+ }
433
+ async getMessageAuthor(dmID) {
434
+ return this.requestOn(this.infoWS, 'getMessageAuthor', 'GetMessageAuthor', { dmID });
435
+ }
436
+ async getMessageAuthorDetails(dmID) {
437
+ return this.requestOn(this.infoWS, 'getMessageAuthorDetails', 'GetMessageAuthor2', { dmID });
438
+ }
439
+ async eraseMessage(input) {
440
+ return this.requestOn(this.infoWS, 'eraseMessage', 'EraseMessage', input);
441
+ }
442
+ async getErasedMessages(input) {
443
+ const payload = 'dmFromDate' in input
444
+ ? {
445
+ dmFromDate: this.normalizeDate(input.dmFromDate),
446
+ dmToDate: this.normalizeDate(input.dmToDate),
447
+ dmMessageType: input.dmMessageType,
448
+ dmOutFormat: input.dmOutFormat,
449
+ }
450
+ : {
451
+ dmYear: input.dmYear,
452
+ dmMonth: input.dmMonth ?? null,
453
+ dmMessageType: input.dmMessageType,
454
+ dmOutFormat: input.dmOutFormat,
455
+ };
456
+ return this.requestOn(this.infoWS, 'getErasedMessages', 'GetListOfErasedMessages', payload);
457
+ }
458
+ async pickUpAsyncResponse(input) {
459
+ return this.requestOn(this.infoWS, 'pickUpAsyncResponse', 'PickUpAsyncResponse', input);
460
+ }
461
+ async listNotifications(input) {
462
+ return this.requestOn(this.infoWS, 'listNotifications', 'GetListForNotifications', {
463
+ ntfFromTime: this.normalizeDateTime(input.ntfFromTime),
464
+ ntfScope: input.ntfScope,
465
+ });
466
+ }
467
+ async registerForNotifications(action) {
468
+ return this.requestOn(this.infoWS, 'registerForNotifications', 'RegisterForNotifications', { action });
469
+ }
470
+ async getSentMessageEnvelope(dmID) {
471
+ return this.requestOn(this.infoWS, 'getSentMessageEnvelope', 'SentMessageEnvelopeDownload', { dmID });
472
+ }
473
+ async reportSuspiciousMessage(input) {
474
+ return this.requestOn(this.infoWS, 'reportSuspiciousMessage', 'SuspMessageReport', {
475
+ dmID: input.dmID,
476
+ repName: input.repName ?? null,
477
+ repMail: input.repMail ?? null,
478
+ repTel: input.repTel ?? null,
479
+ allowComplete: input.allowComplete,
480
+ note: input.note ?? null,
481
+ });
482
+ }
483
+ async authenticateMessage(dmMessage) {
484
+ return this.requestOn(this.operationsWS, 'authenticateMessage', 'AuthenticateMessage', { dmMessage });
485
+ }
486
+ async reSignIsdsDocument(dmDoc) {
487
+ return this.requestOn(this.operationsWS, 'reSignIsdsDocument', 'Re-signISDSDocument', { dmDoc });
488
+ }
489
+ async dummyOperation(value = '') {
490
+ return this.requestOn(this.operationsWS, 'dummyOperation', 'DummyOperation', { DummyOperation: value });
491
+ }
492
+ async uploadAttachment(input) {
493
+ return this.requestOn(this.vodzWS, 'uploadAttachment', 'UploadAttachment', {
494
+ dmFile: {
495
+ dmEncodedContent: input.dmEncodedContent,
496
+ attributes: {
497
+ dmMimeType: input.dmMimeType,
498
+ dmFileDescr: input.dmFileDescr,
499
+ },
500
+ },
501
+ });
502
+ }
503
+ async downloadAttachment(input) {
504
+ return this.requestOn(this.vodzWS, 'downloadAttachment', 'DownloadAttachment', input);
505
+ }
506
+ async createBigMessage(input) {
507
+ const dmExtFile = input.dmFiles.dmExtFile?.map((file) => ({
508
+ attributes: {
509
+ dmFileMetaType: file.dmFileMetaType,
510
+ dmAttID: file.dmAttID,
511
+ dmAttHash1: file.dmAttHash1,
512
+ dmAttHash1Alg: file.dmAttHash1Alg,
513
+ dmAttHash2: file.dmAttHash2,
514
+ dmAttHash2Alg: file.dmAttHash2Alg,
515
+ ...(file.dmFileGuid ? { dmFileGuid: file.dmFileGuid } : {}),
516
+ ...(file.dmUpFileGuid ? { dmUpFileGuid: file.dmUpFileGuid } : {}),
517
+ },
518
+ }));
519
+ const dmFile = input.dmFiles.dmFile?.map((file) => ({
520
+ dmEncodedContent: file.dmEncodedContent,
521
+ attributes: {
522
+ dmFileMetaType: file.dmFileMetaType,
523
+ dmFileDescr: file.dmFileDescr,
524
+ dmMimeType: file.dmMimeType,
525
+ ...(file.dmFileGuid ? { dmFileGuid: file.dmFileGuid } : {}),
526
+ ...(file.dmUpFileGuid ? { dmUpFileGuid: file.dmUpFileGuid } : {}),
527
+ },
528
+ }));
529
+ return this.requestOn(this.vodzWS, 'createBigMessage', 'CreateBigMessage', {
530
+ dmEnvelope: input.dmEnvelope,
531
+ dmFiles: {
532
+ ...(dmExtFile ? { dmExtFile } : {}),
533
+ ...(dmFile ? { dmFile } : {}),
534
+ },
535
+ });
536
+ }
537
+ async authenticateBigMessage(dmMessage) {
538
+ return this.requestOn(this.vodzWS, 'authenticateBigMessage', 'AuthenticateBigMessage', { dmMessage });
539
+ }
540
+ async downloadSignedBigMessage(dmID) {
541
+ return this.requestOn(this.vodzWS, 'downloadSignedBigMessage', 'SignedBigMessageDownload', { dmID });
542
+ }
543
+ async downloadSignedSentBigMessage(dmID) {
544
+ return this.requestOn(this.vodzWS, 'downloadSignedSentBigMessage', 'SignedSentBigMessageDownload', { dmID });
545
+ }
546
+ async downloadBigMessage(dmID) {
547
+ return this.requestOn(this.vodzWS, 'downloadBigMessage', 'BigMessageDownload', { dmID });
548
+ }
549
+ async archiveIsdsDocument(dmMessage) {
550
+ return this.requestOn(this.archiveWS, 'archiveIsdsDocument', 'ArchiveISDSDocument', { dmMessage });
551
+ }
552
+ async pollReceivedMessages(options = {}) {
553
+ const list = await this.listReceivedMessages(options);
554
+ const records = this.extractMessageRecords(list);
555
+ const items = [];
556
+ for (const record of records) {
557
+ const dmID = this.extractMessageId(record);
558
+ const envelope = options.includeEnvelope
559
+ ? (await this.downloadMessageEnvelope(dmID)).dmReturnedMessageEnvelope
560
+ : undefined;
561
+ const message = options.includeMessage
562
+ ? this.isVodzMessage(record)
563
+ ? (await this.downloadBigMessage(dmID)).dmReturnedMessage
564
+ : (await this.downloadMessage(dmID)).dmReturnedMessage
565
+ : undefined;
566
+ const deliveryInfo = options.includeDeliveryInfo
567
+ ? (await this.getDeliveryInfo(dmID)).dmDelivery
568
+ : undefined;
569
+ let markedAsDownloaded = false;
570
+ if (options.markAsDownloaded) {
571
+ await this.markMessageAsDownloaded(dmID);
572
+ markedAsDownloaded = true;
573
+ }
574
+ const item = {
575
+ record,
576
+ markedAsDownloaded,
577
+ };
578
+ if (envelope !== undefined) {
579
+ item.envelope = envelope;
580
+ }
581
+ if (message !== undefined) {
582
+ item.message = message;
583
+ }
584
+ if (deliveryInfo !== undefined) {
585
+ item.deliveryInfo = deliveryInfo;
586
+ }
587
+ items.push(item);
588
+ }
589
+ return {
590
+ list,
591
+ items,
592
+ };
593
+ }
594
+ async waitForNewMessages(options = {}) {
595
+ const { intervalMs = 30_000, timeoutMs = null, signal, notifications = null, ...pollOptions } = options;
596
+ this.assertNotAborted(signal);
597
+ if (notifications?.registerAction !== undefined &&
598
+ notifications.registerAction !== null) {
599
+ await this.registerForNotifications(notifications.registerAction);
600
+ }
601
+ const startedAt = Date.now();
602
+ let firstIteration = true;
603
+ let notificationCursor = this.initializeNotificationCursor(notifications);
604
+ for (;;) {
605
+ this.assertNotAborted(signal);
606
+ let shouldPollInbox = !notifications || firstIteration;
607
+ if (notifications) {
608
+ const notificationDecision = await this.shouldPollInboxFromNotifications(notifications, notificationCursor);
609
+ shouldPollInbox ||= notificationDecision.shouldPollInbox;
610
+ notificationCursor = notificationDecision.nextCursor;
611
+ }
612
+ if (shouldPollInbox) {
613
+ const batch = await this.pollReceivedMessages(pollOptions);
614
+ if (batch.items.length > 0) {
615
+ return batch;
616
+ }
617
+ }
618
+ if (timeoutMs !== null && Date.now() - startedAt >= timeoutMs) {
619
+ throw new Error('Timed out waiting for new ISDS messages');
620
+ }
621
+ firstIteration = false;
622
+ await this.sleep(intervalMs, signal);
623
+ }
624
+ }
625
+ async *watchReceivedMessages(options = {}) {
626
+ const { intervalMs = 30_000, signal, notifications = null, dedupeByMessageId = true, maxSeenMessageIds = 1000, ...pollOptions } = options;
627
+ this.assertNotAborted(signal);
628
+ if (notifications?.registerAction !== undefined &&
629
+ notifications.registerAction !== null) {
630
+ await this.registerForNotifications(notifications.registerAction);
631
+ }
632
+ const seenMessageIds = new Set();
633
+ const seenMessageOrder = [];
634
+ let firstIteration = true;
635
+ let notificationCursor = this.initializeNotificationCursor(notifications);
636
+ for (;;) {
637
+ this.assertNotAborted(signal);
638
+ let shouldPollInbox = !notifications || firstIteration;
639
+ if (notifications) {
640
+ const notificationDecision = await this.shouldPollInboxFromNotifications(notifications, notificationCursor);
641
+ shouldPollInbox ||= notificationDecision.shouldPollInbox;
642
+ notificationCursor = notificationDecision.nextCursor;
643
+ }
644
+ if (shouldPollInbox) {
645
+ const batch = await this.pollReceivedMessages(pollOptions);
646
+ const items = dedupeByMessageId
647
+ ? this.filterSeenItems(batch.items, seenMessageIds, seenMessageOrder, maxSeenMessageIds)
648
+ : batch.items;
649
+ if (items.length > 0) {
650
+ yield {
651
+ list: batch.list,
652
+ items,
653
+ };
654
+ }
655
+ }
656
+ firstIteration = false;
657
+ await this.sleep(intervalMs, signal);
658
+ }
659
+ }
660
+ }
661
+ export default ISDSBox;
662
+ //# sourceMappingURL=ISDSBox.js.map