kalai-attach 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +451 -0
  3. package/_i18n/i18n.properties +6 -0
  4. package/_i18n/i18n_ar.properties +6 -0
  5. package/_i18n/i18n_bg.properties +6 -0
  6. package/_i18n/i18n_cs.properties +6 -0
  7. package/_i18n/i18n_da.properties +6 -0
  8. package/_i18n/i18n_de.properties +6 -0
  9. package/_i18n/i18n_el.properties +6 -0
  10. package/_i18n/i18n_en.properties +6 -0
  11. package/_i18n/i18n_en_US_saptrc.properties +6 -0
  12. package/_i18n/i18n_es.properties +6 -0
  13. package/_i18n/i18n_es_MX.properties +6 -0
  14. package/_i18n/i18n_fi.properties +6 -0
  15. package/_i18n/i18n_fr.properties +6 -0
  16. package/_i18n/i18n_he.properties +6 -0
  17. package/_i18n/i18n_hr.properties +6 -0
  18. package/_i18n/i18n_hu.properties +6 -0
  19. package/_i18n/i18n_it.properties +6 -0
  20. package/_i18n/i18n_ja.properties +6 -0
  21. package/_i18n/i18n_kk.properties +6 -0
  22. package/_i18n/i18n_ko.properties +6 -0
  23. package/_i18n/i18n_ms.properties +6 -0
  24. package/_i18n/i18n_nl.properties +6 -0
  25. package/_i18n/i18n_no.properties +6 -0
  26. package/_i18n/i18n_pl.properties +6 -0
  27. package/_i18n/i18n_pt.properties +6 -0
  28. package/_i18n/i18n_ro.properties +6 -0
  29. package/_i18n/i18n_ru.properties +6 -0
  30. package/_i18n/i18n_sh.properties +6 -0
  31. package/_i18n/i18n_sk.properties +6 -0
  32. package/_i18n/i18n_sl.properties +6 -0
  33. package/_i18n/i18n_sv.properties +6 -0
  34. package/_i18n/i18n_th.properties +6 -0
  35. package/_i18n/i18n_tr.properties +6 -0
  36. package/_i18n/i18n_uk.properties +6 -0
  37. package/_i18n/i18n_vi.properties +6 -0
  38. package/_i18n/i18n_zh_CN.properties +6 -0
  39. package/_i18n/i18n_zh_TW.properties +6 -0
  40. package/_i18n/messages.properties +6 -0
  41. package/_i18n/messages_en_US_saptrc.properties +4 -0
  42. package/cds-plugin.js +4 -0
  43. package/db/data/sap.attachments-ScanStates.csv +6 -0
  44. package/db/data/sap.attachments-ScanStates_texts.csv +6 -0
  45. package/db/data/sap.attachments-ScanStates_texts_ar.csv +6 -0
  46. package/db/data/sap.attachments-ScanStates_texts_bg.csv +6 -0
  47. package/db/data/sap.attachments-ScanStates_texts_cs.csv +6 -0
  48. package/db/data/sap.attachments-ScanStates_texts_da.csv +6 -0
  49. package/db/data/sap.attachments-ScanStates_texts_de.csv +6 -0
  50. package/db/data/sap.attachments-ScanStates_texts_el.csv +6 -0
  51. package/db/data/sap.attachments-ScanStates_texts_en.csv +6 -0
  52. package/db/data/sap.attachments-ScanStates_texts_en_US_saptrc.csv +6 -0
  53. package/db/data/sap.attachments-ScanStates_texts_es.csv +6 -0
  54. package/db/data/sap.attachments-ScanStates_texts_es_MX.csv +6 -0
  55. package/db/data/sap.attachments-ScanStates_texts_fi.csv +6 -0
  56. package/db/data/sap.attachments-ScanStates_texts_fr.csv +6 -0
  57. package/db/data/sap.attachments-ScanStates_texts_he.csv +6 -0
  58. package/db/data/sap.attachments-ScanStates_texts_hr.csv +6 -0
  59. package/db/data/sap.attachments-ScanStates_texts_hu.csv +6 -0
  60. package/db/data/sap.attachments-ScanStates_texts_it.csv +6 -0
  61. package/db/data/sap.attachments-ScanStates_texts_ja.csv +6 -0
  62. package/db/data/sap.attachments-ScanStates_texts_kk.csv +6 -0
  63. package/db/data/sap.attachments-ScanStates_texts_ko.csv +6 -0
  64. package/db/data/sap.attachments-ScanStates_texts_ms.csv +6 -0
  65. package/db/data/sap.attachments-ScanStates_texts_nl.csv +6 -0
  66. package/db/data/sap.attachments-ScanStates_texts_no.csv +6 -0
  67. package/db/data/sap.attachments-ScanStates_texts_pl.csv +6 -0
  68. package/db/data/sap.attachments-ScanStates_texts_pt.csv +6 -0
  69. package/db/data/sap.attachments-ScanStates_texts_ro.csv +6 -0
  70. package/db/data/sap.attachments-ScanStates_texts_ru.csv +6 -0
  71. package/db/data/sap.attachments-ScanStates_texts_sh.csv +6 -0
  72. package/db/data/sap.attachments-ScanStates_texts_sk.csv +6 -0
  73. package/db/data/sap.attachments-ScanStates_texts_sl.csv +6 -0
  74. package/db/data/sap.attachments-ScanStates_texts_sv.csv +6 -0
  75. package/db/data/sap.attachments-ScanStates_texts_th.csv +6 -0
  76. package/db/data/sap.attachments-ScanStates_texts_tr.csv +6 -0
  77. package/db/data/sap.attachments-ScanStates_texts_uk.csv +6 -0
  78. package/db/data/sap.attachments-ScanStates_texts_vi.csv +6 -0
  79. package/db/data/sap.attachments-ScanStates_texts_zh_CN.csv +6 -0
  80. package/db/data/sap.attachments-ScanStates_texts_zh_TW.csv +6 -0
  81. package/db/index.cds +85 -0
  82. package/index.cds +1 -0
  83. package/lib/csn-runtime-extension.js +31 -0
  84. package/lib/generic-handlers.js +199 -0
  85. package/lib/helper.js +407 -0
  86. package/lib/mtx/server.js +583 -0
  87. package/lib/plugin.js +112 -0
  88. package/package.json +67 -0
  89. package/srv/aws-s3.js +249 -0
  90. package/srv/azure-blob-storage.js +202 -0
  91. package/srv/basic.js +331 -0
  92. package/srv/gcp.js +226 -0
  93. package/srv/malwareScanner-mocked.cds +3 -0
  94. package/srv/malwareScanner-mocked.js +127 -0
  95. package/srv/malwareScanner.cds +23 -0
  96. package/srv/malwareScanner.js +151 -0
  97. package/srv/object-store.js +44 -0
  98. package/srv/standard.js +3 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,451 @@
1
+ [![REUSE status](https://api.reuse.software/badge/github.com/cap-js/attachments)](https://api.reuse.software/info/github.com/cap-js/attachments)
2
+
3
+ # Attachments Plugin
4
+
5
+ The `kalai-attach` package is a [CDS plugin](https://cap.cloud.sap/docs/node.js/cds-plugins#cds-plugin-packages) that provides out-of-the box asset storage and handling by using an [*aspect*](https://cap.cloud.sap/docs/cds/cdl#aspects) called `Attachments`. It also provides a CAP-level, easy-to-use integration of the [SAP Object Store](https://help.sap.com/docs/object-store/object-store-service-on-sap-btp/what-is-object-store).
6
+
7
+ ### Table of Contents
8
+
9
+ <!-- TOC -->
10
+
11
+ * [Usage](#usage)
12
+ * [Quick Start](#quick-start)
13
+ * [Local Walk-Through](#local-walk-through)
14
+ * [Changes in the CDS Models](#changes-in-the-cds-models)
15
+ * [Storage Targets](#storage-targets)
16
+ * [Malware Scanner](#malware-scanner)
17
+ * [Visibility Control](#visibility-control-for-attachments-ui-facet-generation)
18
+ * [Non-Draft Uploading](#non-draft-upload)
19
+ * [Releases](#releases)
20
+ * [Minimum UI5 and CAP NodeJS Version](#minimum-ui5-and-cap-nodejs-version)
21
+ * [Architecture Overview](#architecture-overview)
22
+ * [Multitenancy](#multitenancy)
23
+ * [Object Stores](#object-stores)
24
+ * [Model Texts](#model-texts)
25
+ * [Monitoring & Logging](#monitoring--logging)
26
+ * [Support, Feedback, Contributing ](#support-feedback-and-contributing)
27
+ * [Code of Conduct](#code-of-conduct)
28
+ * [Licensing](#licensing)
29
+
30
+ ## Usage
31
+
32
+ ### Quick Start
33
+
34
+ For a quick local development setup with in-memory storage:
35
+
36
+ - The plugin is self-configuring as described, see the following details section. To enable attachments, simply add the plugin package to your project:
37
+ ```sh
38
+ npm add kalai-attach
39
+ ```
40
+
41
+ <details>
42
+ The attachments plugin needs to be referenced in the package.json of the consuming CAP NodeJS application:
43
+
44
+ ```cds
45
+ "devDependencies": {
46
+ "kalai-attach": "<latest-version>",
47
+ // (...)
48
+ }
49
+ ```
50
+
51
+ In addition, different profiles can be found in `package.json` as well, such as:
52
+
53
+ ```json
54
+ "cds": {
55
+ "requires": {
56
+ // (...)
57
+ "[hybrid]": {
58
+ "attachments": {
59
+ "kind": "standard"
60
+ // (...)
61
+ }
62
+ }
63
+ }
64
+ }
65
+ ```
66
+ </details>
67
+
68
+ - To use Attachments, extend a CDS model by adding an element that refers to the pre-defined Attachments type (see [Changes in the CDS Models](#changes-in-the-cds-models) for more details):
69
+
70
+ ```cds
71
+ using { Attachments } from 'kalai-attach';
72
+
73
+ entity Incidents {
74
+ // (...)
75
+ attachments: Composition of many Attachments;
76
+ }
77
+ ```
78
+
79
+ In this guide, we use the [Incidents Management reference sample app](https://github.com/cap-js/incidents-app) as the base application to provide a demonstration how to use this plugin. A miniature version of this app can be found within the [tests](./tests/incidents-app) directory for local testing.
80
+
81
+ For productive use, a valid object store binding is required, see [Object Stores](#object-stores) and [Storage Targets](#storage-targets).
82
+
83
+ ### Local Walk-Through
84
+
85
+ With the steps above, we have successfully set up asset handling for our reference application. To test the application locally, use the following steps.
86
+
87
+ > [!NOTE]
88
+ > For local testing, the attachment objects are stored in a [local database](https://cap.cloud.sap/docs/guides/databases-sqlite).
89
+
90
+ 1. **Start the server**:
91
+
92
+ - *Default* scenario (In memory database):
93
+ ```sh
94
+ cds watch
95
+ ```
96
+
97
+ 2. **Navigate to the object page** of the incident `Solar panel broken`:
98
+ Go to object page for incident **Solar panel broken**
99
+
100
+ 3. The `Attachments` type has generated an out-of-the-box Attachments table (see 1) at the bottom of the Object page:
101
+ <img width="1300" alt="Attachments Table" style="border-radius:0.5rem;" src="etc/facet.png">
102
+
103
+ 4. **Upload a file** by going into Edit mode and either using the **Upload** button on the Attachments table or by drag/drop. Then click the **Save** button to have that file stored that file in the dedicated resource (database, S3 bucket, etc.). We demonstrate this by uploading the PDF file from [_tests/integration/content/sample.pdf_](./tests/integration/content/sample.pdf):
104
+ <img width="1300" alt="Upload an attachment" style="border-radius:0.5rem;" src="etc/upload.gif">
105
+
106
+ 5. **Delete a file** by going into Edit mode, selecting the file, and pressing the **Delete** button above the Attachments table. Clicking the **Save** button will then delete that file from the resource (database, S3 bucket, etc.).
107
+ <img width="1300" alt="Delete an attachment" style="border-radius:0.5rem;" src="etc/delete.gif">
108
+
109
+ ### Changes in the CDS Models
110
+
111
+ To use the aspect `Attachments` on an existing entity, the corresponding entity needs to either include attachments as an element in the model definition or be extended in a CDS file in the `srv` module. In the quick start, the former was done, adding an element to the model definition:
112
+
113
+ ```cds
114
+ using { Attachments } from 'kalai-attach';
115
+
116
+ entity Incidents {
117
+ // ...
118
+ attachments: Composition of many Attachments;
119
+ }
120
+ ```
121
+
122
+ The entity Incidents can also be extended in the `srv` module, as seen in the following example:
123
+
124
+ ```cds
125
+ using { Attachments } from 'kalai-attach';
126
+
127
+ extend my.Incidents with {
128
+ attachments: Composition of many Attachments;
129
+ }
130
+
131
+ service ProcessorService {
132
+ entity Incidents as projection on my.Incidents
133
+ }
134
+ ```
135
+
136
+ Both methods directly add the respective UI Facet. To use the plugin with an SAP Fiori elements UI, be sure that [`draft` is enabled](https://cap.cloud.sap/docs/advanced/fiori#enabling-draft-with-odata-draft-enabled) for the entity using `@odata.draft.enabled`. For example:
137
+
138
+ ```cds
139
+ annotate service.Incidents with @odata.draft.enabled;
140
+ ```
141
+
142
+ ### Storage Targets
143
+
144
+ When testing locally, the plugin operates without a dedicated storage target, storing attachments directly in the underlying database. In a hybrid setup, a dedicated storage target is preferred. You can bind it by using the `cds bind` command as described in the [CAP documentation for hybrid testing].(https://cap.cloud.sap/docs/advanced/hybrid-testing#services-on-cloud-foundry).
145
+
146
+ Meanwhile, with a dedicated storage target the attachment is not stored in the underlying database; instead, it is saved on the specified storage target and only a reference to the file including metadata is kept in the database, as defined in the CDS model.
147
+
148
+ For using an Object Store in BTP, you must already have an SAP Object Store service instance on the appropriate landscape created. To bind it in a hybrid setup, follow this setup:
149
+
150
+ 1. Log in to Cloud Foundry:
151
+
152
+ ```sh
153
+ cf login -a <CF-API> -o <ORG-NAME> -s <SPACE-NAME> --sso
154
+
155
+ 2. To bind to the service, generate a new file _.cdsrc-private.json in the project directory by running:
156
+
157
+ ```sh
158
+ cds bind <HybridObjectStoreName> --to <RemoteObjectStoreName>
159
+
160
+ Where `HybridObjectStoreName` can be any name given by the user here and `RemoteObjectStoreName` is the name of your object store instance in SAP BTP.
161
+
162
+ 3. To run the application in hybrid mode, run the command:
163
+
164
+ ```bash
165
+ cds watch --profile hybrid
166
+ ```
167
+
168
+ See [Object Stores](#object-stores) for further information on SAP Object Store.
169
+
170
+ ### Malware Scanner
171
+
172
+ The BTP malware scanning service is used in the `AttachmentService` to scan attachments for vulnerabilities.
173
+
174
+ For using [SAP Malware Scanning Service](https://discovery-center.cloud.sap/serviceCatalog/malware-scanning-service), you must already have a service instance which you can access. To bind it, run the following command:
175
+
176
+ ```sh
177
+ cds bind <HybridMalwareScannerName> --to <RemoteMalwareScannerName>
178
+ ```
179
+
180
+ By default, malware scanning is enabled for all profiles if a storage provider has been specified. You can configure malware scanning by setting:
181
+
182
+ ```json
183
+ {
184
+ "cds": {
185
+ // (...)
186
+ "attachments": {
187
+ "scan": true
188
+ }
189
+ }
190
+ }
191
+ ```
192
+
193
+ If there is no malware scanner available and the scanner is not disabled, then the upload will fail.
194
+
195
+ Scan status codes:
196
+ - `Unscanned`: Attachment is still unscanned.
197
+ - `Scanning`: Immediately after upload, the attachment is marked as Scanning. Depending on processing speed, it may already appear as Clean when the page is reloaded.
198
+ - `Clean`: Only attachments with the status Clean are accessible.
199
+ - `Infected`: The attachment is infected.
200
+ - `Failed`: Scanning failed.
201
+
202
+ > [!Note]
203
+ > The malware scanner supports mTLS authentication which requires an annual renewal of the certificate. Previously, basic authentication was used which has now been deprecated.
204
+
205
+ > [!Note]
206
+ > If the malware scanner reports a file size larger than the limit specified via [@Validation.Maximum](#specify-the-maximum-file-size) it removes the file and sets the status of the attachment metadata to failed.
207
+
208
+
209
+ ### Visibility Control for Attachments UI Facet Generation
210
+
211
+ By setting the `@UI.Hidden` property to `true`, developers can hide the visibility of the plugin in the UI. This feature is particularly useful in scenarios where the visibility of the plugin needs to be dynamically controlled based on certain conditions.
212
+
213
+ #### Example Usage
214
+
215
+ ```cds
216
+ entity Incidents {
217
+ // ...
218
+ @UI.Hidden
219
+ attachments: Composition of many Attachments;
220
+ }
221
+ ```
222
+
223
+ In this example, the `@UI.Hidden` is set to `true`, which means the plugin will be hidden by default. You can also use dynamic expressions which are then added to the facet.
224
+
225
+ ```cds
226
+ entity Incidents {
227
+ // ...
228
+ status : Integer enum {
229
+ submitted = 1;
230
+ fulfilled = 2;
231
+ shipped = 3;
232
+ canceled = -1;
233
+ };
234
+ @UI.Hidden : (status = #canceled ? true : false)
235
+ attachments: Composition of many Attachments;
236
+ }
237
+ ```
238
+
239
+ ### Non-Draft Upload
240
+
241
+ For scenarios where the entity is not draft-enabled, for example [`tests/non-draft-request.http`](./tests/non-draft-request.http), separate HTTP requests for metadata creation and asset uploading need to be performed manually.
242
+
243
+ The typical sequence includes:
244
+
245
+ 1. **POST** -> create attachment metadata, returns ID
246
+ 2. **PUT** -> upload file content using the ID
247
+
248
+ ### Specify the maximum file size
249
+
250
+ You can specify the maximum file size by annotating the attachments content property with `@Validation.Maximum`
251
+
252
+ ```cds
253
+ entity Incidents {
254
+ ...
255
+ attachments: Composition of many Attachments;
256
+ }
257
+
258
+ annotate Incidents.attachments with {
259
+ content @Validation.Maximum : '20MB';
260
+ }
261
+ ```
262
+
263
+ The default is 400MB
264
+
265
+ ### Restrict allowed MIME types
266
+
267
+ You can restrict which MIME types are allowed for attachments by annotating the content property with `@Core.AcceptableMediaTypes`. This validation is performed during file upload.
268
+
269
+ ```cds
270
+ entity Incidents {
271
+ ...
272
+ attachments: Composition of many Attachments;
273
+ }
274
+
275
+ annotate Incidents.attachments with {
276
+ content @Core.AcceptableMediaTypes : ['image/jpeg', 'image/png', 'application/pdf'];
277
+ }
278
+ ```
279
+
280
+ Wildcard patterns are supported:
281
+
282
+ ```cds
283
+ annotate Incidents.attachments with {
284
+ content @Core.AcceptableMediaTypes : ['image/*', 'application/pdf'];
285
+ }
286
+ ```
287
+
288
+ To allow all MIME types (default behavior), either omit the annotation or use:
289
+
290
+ ```cds
291
+ annotate Incidents.attachments with {
292
+ content @Core.AcceptableMediaTypes : ['*/*'];
293
+ }
294
+ ```
295
+
296
+ When a file with a disallowed MIME type is uploaded, the request will be rejected with a `400` error.
297
+
298
+ ## Releases
299
+
300
+ - The plugin is released to [NPM Registry](https://www.npmjs.com/package/kalai-attach).
301
+ - See the [changelog](./CHANGELOG.md) or [GitHub Releases](https://github.com/cap-js/attachments/releases) for the latest changes.
302
+
303
+ ## Minimum UI5 and CAP NodeJS Version
304
+
305
+ | Component | Minimum Version |
306
+ |-----------|-----------------|
307
+ | CAP Node | 8.0.0 |
308
+ | UI5 | 1.136.0 |
309
+
310
+ ## Architecture Overview
311
+ ### Multitenancy
312
+
313
+ The plugin supports multi-tenancy scenarios, allowing both shared and tenant-specific object store instances.
314
+
315
+ > [!Note]
316
+ > Starting from version 2.1.0, **separate mode** for object store instances is the default setting for multi-tenancy.
317
+
318
+ For multi-tenant applications, `kalai-attach` must be included in the dependencies of both the application-level and _mtx/sidecar/package.json_ files.
319
+
320
+ #### Separate object store instances
321
+
322
+ By default the plugin creates for each tenant its own object store instance during the tenants subscription.
323
+
324
+ When the tenant unsubscribes the object store instance is deleted.
325
+
326
+ > [!WARNING]
327
+ > When you remove the plugin from an application after separate object stores already have been created, the object stores are not automatically removed!
328
+
329
+ #### Shared Object Store Instance
330
+
331
+ To configure a shared object store instance, modify both the package.json files as follows:
332
+
333
+ ```json
334
+ "cds": {
335
+ "requires": {
336
+ "attachments": {
337
+ "objectStore": {
338
+ "kind": "shared"
339
+ }
340
+ }
341
+ }
342
+ }
343
+ ```
344
+ To ensure tenant identification when using a shared object store instance, the plugin prefixes attachment URLs with the tenant ID. Be sure the shared object store instance is bound to the `mtx` application module before deployment.
345
+
346
+ ### Object Stores
347
+
348
+ A valid object store service binding is required, typically one provisioned through SAP BTP. See [Storage Targets](#storage-targets) and [Deployment to Cloud Foundry](#deployment-to-cloud-foundry) on how to use this object store service binding.
349
+
350
+ #### Deployment to Cloud Foundry
351
+
352
+ The corresponding entry in the [mta-file](https://cap.cloud.sap/docs/guides/deployment/to-cf#add-mta-yaml) possibly looks like:
353
+
354
+ ```
355
+ _schema-version: '0.1'
356
+ ID: consuming-app
357
+ version: 1.0.0
358
+ description: "App consuming the attachments plugin with an object store"
359
+ parameters:
360
+ ...
361
+ modules:
362
+ - name: consuming-app-srv
363
+ # ------------------------------------------------------------
364
+ type: nodejs
365
+ path: srv
366
+ parameters:
367
+ ...
368
+ properties:
369
+ ...
370
+ build-parameters:
371
+ ...
372
+ requires:
373
+ - name: consuming-app-hdi-container
374
+ - name: consuming-app-uaa
375
+ - name: cf-logging
376
+ - name: **object-store-service**
377
+ ...
378
+ resources:
379
+ ...
380
+ - name: **object-store-service**
381
+ type: org.cloudfoundry.managed-service
382
+ parameters:
383
+ service: objectstore
384
+ service-plan: standard
385
+ ```
386
+
387
+
388
+ ##### Tests
389
+
390
+ The unit tests in this module do not need a binding to the respective object stores, run them with `npm install`. To achieve a clean install, the command `rm -rf node_modules` should be used before installation.
391
+
392
+ The integration tests need a binding to a real object store. Run them with `npm run test`.
393
+ To set the binding, please see the section [Storage Targets](#storage-targets).
394
+
395
+ ##### Supported Storage Provider
396
+
397
+ - **Standard** (`kind: "standard"`) | Depending on the bound object store credentials, uses AWS S3, Azure Blob Storage or GCP Cloud Storage. You can manually specify the implementation by adjusting the type to:
398
+ - **AWS S3** (`kind: "s3"`)
399
+ - **Azure Blob Storage** (`kind: "azure"`)
400
+ - **GCP Cloud Storage** (`kind: "gcp"`)
401
+
402
+ ### Model Texts
403
+
404
+ In the model, several fields are annotated with the `@title` annotation. Default texts are provided in [2 languages](./_i18n). If these defaults are not sufficient for an application, they can be overwritten by applications with custom texts or translations.
405
+
406
+ The following table gives an overview of the fields and the i18n codes:
407
+
408
+ | Field Name | i18n Code |
409
+ |------------|--------------|
410
+ | `mimeType` | `MediaType` |
411
+ | `fileName` | `FileName` |
412
+ | `status` | `ScanStatus` |
413
+ | `note` | `note` |
414
+
415
+ In addition to the field names, header information (`@UI.HeaderInfo`) are also annotated:
416
+
417
+ | Header Info | i18n Code |
418
+ |------------------|---------------|
419
+ | `TypeName` | `Attachment` |
420
+ | `TypeNamePlural` | `Attachments` |
421
+
422
+
423
+ ## Monitoring & Logging
424
+
425
+ To configure logging for the attachments plugin, add the following configuration to the `package.json` of the consuming application:
426
+
427
+ ```json
428
+ {
429
+ "cds": {
430
+ "log": {
431
+ "levels": {
432
+ // (...)
433
+ "attachments": "debug"
434
+ }
435
+ }
436
+ }
437
+ }
438
+ ...
439
+ ```
440
+
441
+ ## Support, Feedback, and Contributing
442
+
443
+ This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/cap-js/attachments/issues). Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, the **local development setup**, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md).
444
+
445
+ ## Code of Conduct
446
+
447
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its [Code of Conduct](CODE_OF_CONDUCT.md) at all times.
448
+
449
+ ## Licensing
450
+
451
+ Copyright 2024 SAP SE or an SAP affiliate company and contributors. Please see our [LICENSE](LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/cap-js/attachmentstea).
@@ -0,0 +1,6 @@
1
+ Attachment=Attachment
2
+ Attachments=Attachments
3
+ Note=Note
4
+ ScanStatus=Scan status
5
+ FileName=File name
6
+ MediaType=Media type
@@ -0,0 +1,6 @@
1
+ Attachment=\u0627\u0644\u0645\u0631\u0641\u0642
2
+ Attachments=\u0627\u0644\u0645\u0631\u0641\u0642\u0627\u062A
3
+ Note=\u0645\u0644\u0627\u062D\u0638\u0629
4
+ ScanStatus=\u062D\u0627\u0644\u0629 \u0627\u0644\u0645\u0633\u062D \u0627\u0644\u0636\u0648\u0626\u064A
5
+ FileName=\u0627\u0633\u0645 \u0627\u0644\u0645\u0644\u0641
6
+ MediaType=\u0646\u0648\u0639 \u0627\u0644\u0648\u0633\u0627\u0626\u0637
@@ -0,0 +1,6 @@
1
+ Attachment=\u041F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u0435
2
+ Attachments=\u041F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u044F
3
+ Note=\u0417\u0430\u0431\u0435\u043B\u0435\u0436\u043A\u0430
4
+ ScanStatus=\u0421\u0442\u0430\u0442\u0443\u0441 \u043D\u0430 \u0441\u043A\u0430\u043D\u0438\u0440\u0430\u043D\u0435
5
+ FileName=\u0418\u043C\u0435 \u043D\u0430 \u0444\u0430\u0439\u043B
6
+ MediaType=\u0412\u0438\u0434 \u043C\u0435\u0434\u0438\u044F
@@ -0,0 +1,6 @@
1
+ Attachment=P\u0159\u00EDloha
2
+ Attachments=P\u0159\u00EDlohy
3
+ Note=Pozn\u00E1mka
4
+ ScanStatus=Status skenov\u00E1n\u00ED
5
+ FileName=N\u00E1zev souboru
6
+ MediaType=Typ m\u00E9dia