@valtimo/resource 0.0.0-test

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.
@@ -0,0 +1,676 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Injectable, NgModule } from '@angular/core';
3
+ import { map as map$1, tap, switchMap } from 'rxjs/operators';
4
+ import { map, of, Subject } from 'rxjs';
5
+ import * as i1 from '@angular/common/http';
6
+ import { HttpHeaders } from '@angular/common/http';
7
+ import * as i2 from '@valtimo/shared';
8
+ import { UploadProvider } from '@valtimo/shared';
9
+ import { v4 } from 'uuid';
10
+ import * as i2$1 from 'ngx-logger';
11
+
12
+ /*
13
+ * Copyright 2015-2025 Ritense BV, the Netherlands.
14
+ *
15
+ * Licensed under EUPL, Version 1.2 (the "License");
16
+ * you may not use this file except in compliance with the License.
17
+ * You may obtain a copy of the License at
18
+ *
19
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software
22
+ * distributed under the License is distributed on an "AS IS" basis,
23
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ * See the License for the specific language governing permissions and
25
+ * limitations under the License.
26
+ */
27
+
28
+ /*
29
+ * Copyright 2015-2025 Ritense BV, the Netherlands.
30
+ *
31
+ * Licensed under EUPL, Version 1.2 (the "License");
32
+ * you may not use this file except in compliance with the License.
33
+ * You may obtain a copy of the License at
34
+ *
35
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
36
+ *
37
+ * Unless required by applicable law or agreed to in writing, software
38
+ * distributed under the License is distributed on an "AS IS" basis,
39
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40
+ * See the License for the specific language governing permissions and
41
+ * limitations under the License.
42
+ */
43
+ class S3Resource {
44
+ constructor(file, preSignedUrl, documentId) {
45
+ this.id = null;
46
+ this.extension = null;
47
+ this.createdOn = null;
48
+ this.key = decodeURIComponent(preSignedUrl.pathname.substring(1));
49
+ this.name = file.name;
50
+ this.sizeInBytes = file.size;
51
+ if (!documentId) {
52
+ return;
53
+ }
54
+ this.documentId = documentId;
55
+ }
56
+ }
57
+
58
+ /*
59
+ * Copyright 2015-2025 Ritense BV, the Netherlands.
60
+ *
61
+ * Licensed under EUPL, Version 1.2 (the "License");
62
+ * you may not use this file except in compliance with the License.
63
+ * You may obtain a copy of the License at
64
+ *
65
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
66
+ *
67
+ * Unless required by applicable law or agreed to in writing, software
68
+ * distributed under the License is distributed on an "AS IS" basis,
69
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
70
+ * See the License for the specific language governing permissions and
71
+ * limitations under the License.
72
+ */
73
+ var Archiefnominatie;
74
+ (function (Archiefnominatie) {
75
+ Archiefnominatie["blijvend_bewaren"] = "blijven_bewaren";
76
+ Archiefnominatie["vernietigen"] = "vernietigen";
77
+ })(Archiefnominatie || (Archiefnominatie = {}));
78
+ var Afleidingswijze;
79
+ (function (Afleidingswijze) {
80
+ Afleidingswijze["afgehandeld"] = "afgehandeld";
81
+ Afleidingswijze["ander_datumkenmerk"] = "ander_datumkenmerk";
82
+ Afleidingswijze["eigenschap"] = "eigenschap";
83
+ Afleidingswijze["gerelateerde_zaak"] = "gerelateerde_zaak";
84
+ Afleidingswijze["hoofdzaak"] = "hoofdzaak";
85
+ Afleidingswijze["ingangsdatum_besluit"] = "ingangsdatum_besluit";
86
+ Afleidingswijze["termijn"] = "termijn";
87
+ Afleidingswijze["vervaldatum_besluit"] = "vervaldatum_besluit";
88
+ Afleidingswijze["zaakobject"] = "zaakobject";
89
+ })(Afleidingswijze || (Afleidingswijze = {}));
90
+ var Objecttype;
91
+ (function (Objecttype) {
92
+ Objecttype["adres"] = "adres";
93
+ Objecttype["besluit"] = "besluit";
94
+ Objecttype["buurt"] = "buurt";
95
+ Objecttype["enkelvoudig_document"] = "enkelvoudig_document";
96
+ Objecttype["gemeente"] = "gemeente";
97
+ Objecttype["gemeentelijke_openbare_ruimte"] = "gemeentelijke_openbare_ruimte";
98
+ Objecttype["huishouden"] = "huishouden";
99
+ Objecttype["inrichtingselement"] = "inrichtingselement";
100
+ Objecttype["kadastrale_onroerende_zaak"] = "kadastrale_onroerende_zaak";
101
+ Objecttype["kunstwerkdeel"] = "kunstwerkdeel";
102
+ Objecttype["maatschappelijke_activiteit"] = "maatschappelijke_activiteit";
103
+ Objecttype["medewerker"] = "medewerker";
104
+ Objecttype["natuurlijk_persoon"] = "natuurlijk_persoon";
105
+ Objecttype["niet_natuurlijk_persoon"] = "niet_natuurlijk_persoon";
106
+ Objecttype["openbare_ruimte"] = "openbare_ruimte";
107
+ Objecttype["organisatorische_eenheid"] = "organisatorische_eenheid";
108
+ Objecttype["pand"] = "pand";
109
+ Objecttype["spoorbaandeel"] = "spoorbaandeel";
110
+ Objecttype["status"] = "status";
111
+ Objecttype["terreindeel"] = "terreindeel";
112
+ Objecttype["terrein_gebouwd_object"] = "terrein_gebouwd_object";
113
+ Objecttype["vestiging"] = "vestiging";
114
+ Objecttype["waterdeel"] = "waterdeel";
115
+ Objecttype["wegdeel"] = "wegdeel";
116
+ Objecttype["wijk"] = "wijk";
117
+ Objecttype["woonplaats"] = "woonplaats";
118
+ Objecttype["woz_deelobject"] = "woz_deelobject";
119
+ Objecttype["woz_object"] = "woz_object";
120
+ Objecttype["woz_waarde"] = "woz_waarde";
121
+ Objecttype["zakelijk_recht"] = "zakelijk_recht";
122
+ Objecttype["overige"] = "overige";
123
+ })(Objecttype || (Objecttype = {}));
124
+
125
+ /*
126
+ * Copyright 2015-2025 Ritense BV, the Netherlands.
127
+ *
128
+ * Licensed under EUPL, Version 1.2 (the "License");
129
+ * you may not use this file except in compliance with the License.
130
+ * You may obtain a copy of the License at
131
+ *
132
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
133
+ *
134
+ * Unless required by applicable law or agreed to in writing, software
135
+ * distributed under the License is distributed on an "AS IS" basis,
136
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137
+ * See the License for the specific language governing permissions and
138
+ * limitations under the License.
139
+ */
140
+
141
+ /*
142
+ * Copyright 2015-2025 Ritense BV, the Netherlands.
143
+ *
144
+ * Licensed under EUPL, Version 1.2 (the "License");
145
+ * you may not use this file except in compliance with the License.
146
+ * You may obtain a copy of the License at
147
+ *
148
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
149
+ *
150
+ * Unless required by applicable law or agreed to in writing, software
151
+ * distributed under the License is distributed on an "AS IS" basis,
152
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
153
+ * See the License for the specific language governing permissions and
154
+ * limitations under the License.
155
+ */
156
+ class OpenZaakService {
157
+ constructor(http, configService) {
158
+ this.http = http;
159
+ this.configService = configService;
160
+ this.valtimoApiConfig = this.configService.config.valtimoApi;
161
+ }
162
+ getResource(resourceId) {
163
+ return this.http.get(`${this.valtimoApiConfig.endpointUri}v1/resource/${resourceId}`);
164
+ }
165
+ getResources(documentId) {
166
+ return this.http
167
+ .get(`${this.valtimoApiConfig.endpointUri}v2/zaken-api/document/${documentId}/files`)
168
+ .pipe(map(page => page.content.map(file => ({
169
+ filename: file.bestandsnaam,
170
+ id: file.fileId,
171
+ }))));
172
+ }
173
+ getZaakTypes() {
174
+ return this.http.get(`${this.valtimoApiConfig.endpointUri}management/v1/zgw/zaaktype`);
175
+ }
176
+ getZaakTypeLink(caseDefinitionKey, caseVersionTag) {
177
+ return this.http.get(`${this.valtimoApiConfig.endpointUri}management/v1/case-definition/${caseDefinitionKey}/version/${caseVersionTag}/zaak-type-link`);
178
+ }
179
+ createZaakTypeLink(request) {
180
+ return this.http.post(`${this.valtimoApiConfig.endpointUri}management/v1/case-definition/${request.caseDefinitionKey}/version/${request.caseVersionTag}/zaak-type-link`, request);
181
+ }
182
+ deleteZaakTypeLink(caseDefinitionKey, caseVersionTag) {
183
+ return this.http.delete(`${this.valtimoApiConfig.endpointUri}management/v1/case-definition/${caseDefinitionKey}/version/${caseVersionTag}/zaak-type-link`);
184
+ }
185
+ getZaakTypeLinkListByProcess(processDefinitionKey) {
186
+ return this.http.get(`${this.valtimoApiConfig.endpointUri}management/v1/zaak-type-link/process/${processDefinitionKey}`);
187
+ }
188
+ upload(file, caseDefinitionKey) {
189
+ return this.uploadTempFileWithMetadata(file, { caseDefinitionKey });
190
+ }
191
+ uploadWithMetadata(file, documentId, metadata) {
192
+ const formData = new FormData();
193
+ formData.append('file', file);
194
+ formData.append('documentId', documentId);
195
+ Object.keys(metadata).forEach(metaDataKey => {
196
+ const metadataValue = metadata[metaDataKey];
197
+ if (metadataValue) {
198
+ formData.append(metaDataKey, metadataValue);
199
+ }
200
+ });
201
+ return this.http.post(`${this.valtimoApiConfig.endpointUri}v1/resource/temp`, formData, {
202
+ reportProgress: true,
203
+ responseType: 'json',
204
+ });
205
+ }
206
+ uploadTempFileWithMetadata(file, metadata) {
207
+ const formData = new FormData();
208
+ formData.append('file', file);
209
+ Object.keys(metadata).forEach(metaDataKey => {
210
+ const metadataValue = metadata[metaDataKey];
211
+ if (metadataValue) {
212
+ formData.append(metaDataKey, metadataValue);
213
+ }
214
+ });
215
+ return this.http.post(`${this.valtimoApiConfig.endpointUri}v1/resource/temp`, formData, {
216
+ reportProgress: true,
217
+ responseType: 'json',
218
+ });
219
+ }
220
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: OpenZaakService, deps: [{ token: i1.HttpClient }, { token: i2.ConfigService }], target: i0.ɵɵFactoryTarget.Injectable }); }
221
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: OpenZaakService, providedIn: 'root' }); }
222
+ }
223
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: OpenZaakService, decorators: [{
224
+ type: Injectable,
225
+ args: [{
226
+ providedIn: 'root',
227
+ }]
228
+ }], ctorParameters: () => [{ type: i1.HttpClient }, { type: i2.ConfigService }] });
229
+
230
+ /*
231
+ * Copyright 2015-2025 Ritense BV, the Netherlands.
232
+ *
233
+ * Licensed under EUPL, Version 1.2 (the "License");
234
+ * you may not use this file except in compliance with the License.
235
+ * You may obtain a copy of the License at
236
+ *
237
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
238
+ *
239
+ * Unless required by applicable law or agreed to in writing, software
240
+ * distributed under the License is distributed on an "AS IS" basis,
241
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
242
+ * See the License for the specific language governing permissions and
243
+ * limitations under the License.
244
+ */
245
+ class OpenZaakUploadService {
246
+ constructor(openZaakService, http, configService) {
247
+ this.openZaakService = openZaakService;
248
+ this.http = http;
249
+ this.configService = configService;
250
+ this.valtimoApiConfig = configService.config.valtimoApi;
251
+ }
252
+ uploadFile(file, caseDefinitionKey) {
253
+ return this.openZaakService
254
+ .upload(new File([file], file.name, { type: file.type }), caseDefinitionKey)
255
+ .pipe(map$1(result => this.getResourceFile(result)));
256
+ }
257
+ uploadFileWithMetadata(file, documentId, metadata) {
258
+ return this.openZaakService.uploadWithMetadata(new File([file], metadata?.bestandsnaam || file.name, { type: file.type }), documentId, metadata);
259
+ }
260
+ uploadTempFileWithMetadata(file, metadata) {
261
+ return this.openZaakService.uploadTempFileWithMetadata(new File([file], metadata?.bestandsnaam || file.name, { type: file.type }), metadata);
262
+ }
263
+ getResource(resourceId) {
264
+ return this.openZaakService.getResource(resourceId);
265
+ }
266
+ getResources(documentId) {
267
+ return this.openZaakService.getResources(documentId);
268
+ }
269
+ checkUploadProcessLink(caseDefinitionKey) {
270
+ return this.http
271
+ .get(`${this.valtimoApiConfig.endpointUri}v1/uploadprocess/case/${caseDefinitionKey}/check-link`)
272
+ .pipe(map$1(res => res.processCaseLinkExists));
273
+ }
274
+ getResourceFile(result) {
275
+ const extension = result.filename && result.filename.includes('.')
276
+ ? result.filename.split('.').pop() || ''
277
+ : '';
278
+ return {
279
+ customUpload: true,
280
+ originalName: result.filename,
281
+ size: result.sizeInBytes,
282
+ url: `/api/v1/resource/${result.id}/download`,
283
+ storage: 'openZaak',
284
+ type: extension,
285
+ data: {
286
+ createdOn: Date(),
287
+ name: result.filename,
288
+ sizeInBytes: result.sizeInBytes,
289
+ resourceId: result.id,
290
+ extension: extension,
291
+ },
292
+ };
293
+ }
294
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: OpenZaakUploadService, deps: [{ token: OpenZaakService }, { token: i1.HttpClient }, { token: i2.ConfigService }], target: i0.ɵɵFactoryTarget.Injectable }); }
295
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: OpenZaakUploadService }); }
296
+ }
297
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: OpenZaakUploadService, decorators: [{
298
+ type: Injectable
299
+ }], ctorParameters: () => [{ type: OpenZaakService }, { type: i1.HttpClient }, { type: i2.ConfigService }] });
300
+
301
+ /*
302
+ * Copyright 2015-2025 Ritense BV, the Netherlands.
303
+ *
304
+ * Licensed under EUPL, Version 1.2 (the "License");
305
+ * you may not use this file except in compliance with the License.
306
+ * You may obtain a copy of the License at
307
+ *
308
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
309
+ *
310
+ * Unless required by applicable law or agreed to in writing, software
311
+ * distributed under the License is distributed on an "AS IS" basis,
312
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
313
+ * See the License for the specific language governing permissions and
314
+ * limitations under the License.
315
+ */
316
+ class S3Service {
317
+ constructor(http, configService) {
318
+ this.http = http;
319
+ this.configService = configService;
320
+ this.valtimoApiConfig = configService.config.valtimoApi;
321
+ }
322
+ getPreSignedUrl(fileName) {
323
+ const headers = new HttpHeaders().set('Content-Type', 'text/plain; charset=utf-8');
324
+ const options = { headers, responseType: 'text' };
325
+ return this.http.get(`${this.valtimoApiConfig.endpointUri}v1/resource/pre-signed-url/${fileName}`, options);
326
+ }
327
+ upload(url, file) {
328
+ const headers = new HttpHeaders().set('Content-Type', file.type);
329
+ return this.http.put(url.toString(), file, { headers });
330
+ }
331
+ registerResource(s3ResourceDTO) {
332
+ return this.http.put(`${this.valtimoApiConfig.endpointUri}v1/resource`, s3ResourceDTO);
333
+ }
334
+ get(resourceId) {
335
+ const headers = new HttpHeaders().set('Content-Type', 'application/json;charset=UTF-8');
336
+ return this.http.get(`${this.valtimoApiConfig.endpointUri}v1/resource/${resourceId}`, { headers });
337
+ }
338
+ delete(resourceId) {
339
+ const headers = new HttpHeaders().set('Content-Type', 'application/json;charset=UTF-8');
340
+ return this.http.delete(`${this.valtimoApiConfig.endpointUri}v1/resource/${resourceId}`, {
341
+ headers,
342
+ });
343
+ }
344
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: S3Service, deps: [{ token: i1.HttpClient }, { token: i2.ConfigService }], target: i0.ɵɵFactoryTarget.Injectable }); }
345
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: S3Service, providedIn: 'root' }); }
346
+ }
347
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: S3Service, decorators: [{
348
+ type: Injectable,
349
+ args: [{
350
+ providedIn: 'root',
351
+ }]
352
+ }], ctorParameters: () => [{ type: i1.HttpClient }, { type: i2.ConfigService }] });
353
+
354
+ class S3UploadService {
355
+ constructor(s3Service, configService, http) {
356
+ this.s3Service = s3Service;
357
+ this.configService = configService;
358
+ this.http = http;
359
+ this.valtimoEndpointUri = this.configService.config.valtimoApi.endpointUri;
360
+ }
361
+ uploadFile(file, _, documentId) {
362
+ let resourceUrl;
363
+ const fileName = file.name;
364
+ const splitFileName = fileName.split('.');
365
+ const fileNameWithUUID = `${splitFileName[0]}-${v4()}.${splitFileName[1]}`;
366
+ const renamedFile = new File([file], fileNameWithUUID, { type: file.type });
367
+ return this.s3Service.getPreSignedUrl(renamedFile.name).pipe(map$1(url => new URL(url)), tap(url => (resourceUrl = url)), switchMap(url => this.s3Service.upload(url, renamedFile)), map$1(() => new S3Resource(file, resourceUrl, documentId)), switchMap(s3Resource => this.s3Service.registerResource(s3Resource)), switchMap(s3Resource => this.s3Service.get(s3Resource.id)), map$1(result => ({ ...result, originalName: file.name })), map$1(result => this.getResourceFile(result)));
368
+ }
369
+ getResource(resourceId) {
370
+ return this.s3Service.get(resourceId);
371
+ }
372
+ getResources(documentId) {
373
+ return this.http.get(`${this.valtimoEndpointUri}v1/document/${documentId}`).pipe(map$1(document => document.relatedFiles ?? []), map$1(resources => resources.map(relatedFile => ({
374
+ filename: relatedFile.fileName,
375
+ id: relatedFile.fileId,
376
+ }))));
377
+ }
378
+ getResourceFile(result) {
379
+ return {
380
+ customUpload: true,
381
+ originalName: result.originalName,
382
+ url: result.url,
383
+ size: result.resource.sizeInBytes,
384
+ storage: 'url',
385
+ type: result.resource.extension,
386
+ data: {
387
+ key: result.resource.key,
388
+ bucketName: result.resource.name,
389
+ createdOn: result.resource.createdOn,
390
+ name: result.originalName,
391
+ sizeInBytes: result.resource.sizeInBytes,
392
+ resourceId: result.resource.id.split('ResourceId(id=')[1].slice(0, -1),
393
+ },
394
+ };
395
+ }
396
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: S3UploadService, deps: [{ token: S3Service }, { token: i2.ConfigService }, { token: i1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
397
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: S3UploadService }); }
398
+ }
399
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: S3UploadService, decorators: [{
400
+ type: Injectable
401
+ }], ctorParameters: () => [{ type: S3Service }, { type: i2.ConfigService }, { type: i1.HttpClient }] });
402
+
403
+ /*
404
+ * Copyright 2015-2025 Ritense BV, the Netherlands.
405
+ *
406
+ * Licensed under EUPL, Version 1.2 (the "License");
407
+ * you may not use this file except in compliance with the License.
408
+ * You may obtain a copy of the License at
409
+ *
410
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
411
+ *
412
+ * Unless required by applicable law or agreed to in writing, software
413
+ * distributed under the License is distributed on an "AS IS" basis,
414
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
415
+ * See the License for the specific language governing permissions and
416
+ * limitations under the License.
417
+ */
418
+ class UploadProviderService {
419
+ constructor(configService, injector, logger) {
420
+ this.configService = configService;
421
+ this.injector = injector;
422
+ this.logger = logger;
423
+ let uploadService;
424
+ switch (configService.config.uploadProvider) {
425
+ case UploadProvider.S3:
426
+ uploadService = injector.get(S3UploadService);
427
+ break;
428
+ case UploadProvider.OPEN_ZAAK:
429
+ uploadService = injector.get(OpenZaakUploadService);
430
+ break;
431
+ case UploadProvider.DOCUMENTEN_API:
432
+ uploadService = injector.get(OpenZaakUploadService);
433
+ break;
434
+ }
435
+ this.uploadService = uploadService;
436
+ this.logger.debug('Loading UploadService as', this.uploadService);
437
+ }
438
+ uploadFile(file, caseDefinitionKey, documentId) {
439
+ return this.uploadService.uploadFile(file, caseDefinitionKey, documentId);
440
+ }
441
+ getResource(resourceId) {
442
+ return this.uploadService.getResource(resourceId);
443
+ }
444
+ getResources(documentId) {
445
+ return this.uploadService.getResources(documentId);
446
+ }
447
+ checkUploadProcessLink(caseDefinitionKey) {
448
+ if (this.uploadService.checkUploadProcessLink) {
449
+ return this.uploadService.checkUploadProcessLink(caseDefinitionKey);
450
+ }
451
+ return of(false);
452
+ }
453
+ uploadFileWithMetadata(file, documentId, metadata) {
454
+ if (this.uploadService.uploadFileWithMetadata) {
455
+ return this.uploadService.uploadFileWithMetadata(file, documentId, metadata);
456
+ }
457
+ return of(null);
458
+ }
459
+ uploadTempFileWithMetadata(file, metadata) {
460
+ if (this.uploadService.uploadTempFileWithMetadata) {
461
+ return this.uploadService.uploadTempFileWithMetadata(file, metadata);
462
+ }
463
+ return of(null);
464
+ }
465
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: UploadProviderService, deps: [{ token: i2.ConfigService }, { token: i0.Injector }, { token: i2$1.NGXLogger }], target: i0.ɵɵFactoryTarget.Injectable }); }
466
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: UploadProviderService, providedIn: 'root' }); }
467
+ }
468
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: UploadProviderService, decorators: [{
469
+ type: Injectable,
470
+ args: [{
471
+ providedIn: 'root',
472
+ }]
473
+ }], ctorParameters: () => [{ type: i2.ConfigService }, { type: i0.Injector }, { type: i2$1.NGXLogger }] });
474
+
475
+ /*
476
+ * Copyright 2015-2025 Ritense BV, the Netherlands.
477
+ *
478
+ * Licensed under EUPL, Version 1.2 (the "License");
479
+ * you may not use this file except in compliance with the License.
480
+ * You may obtain a copy of the License at
481
+ *
482
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
483
+ *
484
+ * Unless required by applicable law or agreed to in writing, software
485
+ * distributed under the License is distributed on an "AS IS" basis,
486
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
487
+ * See the License for the specific language governing permissions and
488
+ * limitations under the License.
489
+ */
490
+ class DownloadService {
491
+ constructor(http, configService) {
492
+ this.http = http;
493
+ this.configService = configService;
494
+ }
495
+ downloadFile(url, name, forceDownload) {
496
+ const finishedSubject$ = new Subject();
497
+ if (url.startsWith(this.configService.config.valtimoApi.endpointUri) ||
498
+ url.startsWith(window.location.origin) ||
499
+ url.startsWith('/api/')) {
500
+ // if download url is on backend use angular to get the content so access token is used
501
+ this.http.get(url, { responseType: 'blob' }).subscribe(content => {
502
+ const downloadUrl = window.URL.createObjectURL(content);
503
+ if (!this.isFileTypeSupportedForNewWindow(name) || forceDownload) {
504
+ this.openDownloadLink(downloadUrl, name);
505
+ }
506
+ else {
507
+ this.openBlobInNewTab(downloadUrl, name);
508
+ }
509
+ finishedSubject$.next(null);
510
+ });
511
+ }
512
+ else {
513
+ // download links to external services (like amazon s3) open in a new window
514
+ this.openDownloadLink(url, name);
515
+ finishedSubject$.next(null);
516
+ }
517
+ return finishedSubject$;
518
+ }
519
+ /**
520
+ * A window.open won't work for blobs because ad blocker extensions will immediately
521
+ * close the tab again. The method used below will prevent this from happening.
522
+ */
523
+ openBlobInNewTab(url, name) {
524
+ const newWindow = window.open('/');
525
+ // newWindow will be null if the browser blocks the opening of a new tab.
526
+ if (newWindow != null) {
527
+ newWindow.location = url;
528
+ }
529
+ else {
530
+ // In case the tab is blocked it will just download the file.
531
+ this.openDownloadLink(url, name);
532
+ }
533
+ }
534
+ openDownloadLink(url, name) {
535
+ const link = document.createElement('a');
536
+ link.href = url;
537
+ link.download = name;
538
+ link.target = '_blank';
539
+ link.click();
540
+ link.remove();
541
+ }
542
+ isFileTypeSupportedForNewWindow(name) {
543
+ const supportedFileTypes = this.configService?.config
544
+ ?.supportedDocumentFileTypesToViewInBrowser || ['pdf', 'jpg', 'png', 'svg'];
545
+ return supportedFileTypes.some(function (suffix) {
546
+ return name.toUpperCase().endsWith(suffix.toUpperCase());
547
+ });
548
+ }
549
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: DownloadService, deps: [{ token: i1.HttpClient }, { token: i2.ConfigService }], target: i0.ɵɵFactoryTarget.Injectable }); }
550
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: DownloadService, providedIn: 'root' }); }
551
+ }
552
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: DownloadService, decorators: [{
553
+ type: Injectable,
554
+ args: [{
555
+ providedIn: 'root',
556
+ }]
557
+ }], ctorParameters: () => [{ type: i1.HttpClient }, { type: i2.ConfigService }] });
558
+
559
+ /*
560
+ * Copyright 2015-2025 Ritense BV, the Netherlands.
561
+ *
562
+ * Licensed under EUPL, Version 1.2 (the "License");
563
+ * you may not use this file except in compliance with the License.
564
+ * You may obtain a copy of the License at
565
+ *
566
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
567
+ *
568
+ * Unless required by applicable law or agreed to in writing, software
569
+ * distributed under the License is distributed on an "AS IS" basis,
570
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
571
+ * See the License for the specific language governing permissions and
572
+ * limitations under the License.
573
+ */
574
+ class ResourceModule {
575
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: ResourceModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
576
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.20", ngImport: i0, type: ResourceModule }); }
577
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: ResourceModule, providers: [
578
+ OpenZaakUploadService,
579
+ S3UploadService,
580
+ UploadProviderService,
581
+ OpenZaakService,
582
+ S3Service,
583
+ DownloadService,
584
+ ] }); }
585
+ }
586
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: ResourceModule, decorators: [{
587
+ type: NgModule,
588
+ args: [{
589
+ declarations: [],
590
+ imports: [],
591
+ exports: [],
592
+ providers: [
593
+ OpenZaakUploadService,
594
+ S3UploadService,
595
+ UploadProviderService,
596
+ OpenZaakService,
597
+ S3Service,
598
+ DownloadService,
599
+ ],
600
+ }]
601
+ }] });
602
+
603
+ /*
604
+ * Copyright 2015-2025 Ritense BV, the Netherlands.
605
+ *
606
+ * Licensed under EUPL, Version 1.2 (the "License");
607
+ * you may not use this file except in compliance with the License.
608
+ * You may obtain a copy of the License at
609
+ *
610
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
611
+ *
612
+ * Unless required by applicable law or agreed to in writing, software
613
+ * distributed under the License is distributed on an "AS IS" basis,
614
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
615
+ * See the License for the specific language governing permissions and
616
+ * limitations under the License.
617
+ */
618
+ var PERMISSION_ACTION;
619
+ (function (PERMISSION_ACTION) {
620
+ PERMISSION_ACTION["view"] = "view";
621
+ PERMISSION_ACTION["view_list"] = "view_list";
622
+ PERMISSION_ACTION["create"] = "create";
623
+ PERMISSION_ACTION["modify"] = "modify";
624
+ PERMISSION_ACTION["delete"] = "delete";
625
+ })(PERMISSION_ACTION || (PERMISSION_ACTION = {}));
626
+ var RESOURCE_PERMISSION_RESOURCE;
627
+ (function (RESOURCE_PERMISSION_RESOURCE) {
628
+ RESOURCE_PERMISSION_RESOURCE["resourcePermission"] = "com.ritense.resource.authorization.ResourcePermission";
629
+ RESOURCE_PERMISSION_RESOURCE["jsonSchemaDocument"] = "com.ritense.document.domain.impl.JsonSchemaDocument";
630
+ })(RESOURCE_PERMISSION_RESOURCE || (RESOURCE_PERMISSION_RESOURCE = {}));
631
+ const CAN_VIEW_RESOURCE_PERMISSION = {
632
+ action: PERMISSION_ACTION.view,
633
+ resource: RESOURCE_PERMISSION_RESOURCE.resourcePermission,
634
+ };
635
+ const CAN_VIEW_LIST_RESOURCE_PERMISSION = {
636
+ action: PERMISSION_ACTION.view_list,
637
+ resource: RESOURCE_PERMISSION_RESOURCE.resourcePermission,
638
+ };
639
+ const CAN_CREATE_RESOURCE_PERMISSION = {
640
+ action: PERMISSION_ACTION.create,
641
+ resource: RESOURCE_PERMISSION_RESOURCE.resourcePermission,
642
+ };
643
+ const CAN_MODIFY_RESOURCE_PERMISSION = {
644
+ action: PERMISSION_ACTION.modify,
645
+ resource: RESOURCE_PERMISSION_RESOURCE.resourcePermission,
646
+ };
647
+ const CAN_DELETE_RESOURCE_PERMISSION = {
648
+ action: PERMISSION_ACTION.delete,
649
+ resource: RESOURCE_PERMISSION_RESOURCE.resourcePermission,
650
+ };
651
+
652
+ /*
653
+ * Copyright 2015-2025 Ritense BV, the Netherlands.
654
+ *
655
+ * Licensed under EUPL, Version 1.2 (the "License");
656
+ * you may not use this file except in compliance with the License.
657
+ * You may obtain a copy of the License at
658
+ *
659
+ * https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
660
+ *
661
+ * Unless required by applicable law or agreed to in writing, software
662
+ * distributed under the License is distributed on an "AS IS" basis,
663
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
664
+ * See the License for the specific language governing permissions and
665
+ * limitations under the License.
666
+ */
667
+ /*
668
+ * Public API Surface of upload
669
+ */
670
+
671
+ /**
672
+ * Generated bundle index. Do not edit.
673
+ */
674
+
675
+ export { Afleidingswijze, Archiefnominatie, CAN_CREATE_RESOURCE_PERMISSION, CAN_DELETE_RESOURCE_PERMISSION, CAN_MODIFY_RESOURCE_PERMISSION, CAN_VIEW_LIST_RESOURCE_PERMISSION, CAN_VIEW_RESOURCE_PERMISSION, DownloadService, Objecttype, OpenZaakService, RESOURCE_PERMISSION_RESOURCE, ResourceModule, S3Resource, S3Service, UploadProviderService };
676
+ //# sourceMappingURL=valtimo-resource.mjs.map