files.com 1.0.149 → 1.0.150

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.
@@ -1,221 +0,0 @@
1
- import Api from '../Api'
2
- import Logger from '../Logger'
3
- import { getType, isArray, isBrowser, isInt, isObject, isString } from '../utils'
4
-
5
- /**
6
- * Class As2Key
7
- */
8
- class As2Key {
9
- attributes = {}
10
- options = {}
11
-
12
- constructor(attributes = {}, options = {}) {
13
- Object.entries(attributes).forEach(([key, value]) => {
14
- const normalizedKey = key.replace('?', '')
15
-
16
- this.attributes[normalizedKey] = value
17
-
18
- Object.defineProperty(this, normalizedKey, { value, writable: false })
19
- })
20
-
21
- this.options = { ...options }
22
- }
23
-
24
- isLoaded = () => !!this.attributes.id
25
- // int64 # AS2 Key ID
26
- getId = () => this.attributes.id
27
-
28
- setId = value => {
29
- this.attributes.id = value
30
- }
31
-
32
- // string # AS2 Partnership Name
33
- getAs2PartnershipName = () => this.attributes.as2_partnership_name
34
-
35
- setAs2PartnershipName = value => {
36
- this.attributes.as2_partnership_name = value
37
- }
38
-
39
- // date-time # AS2 Key created at date/time
40
- getCreatedAt = () => this.attributes.created_at
41
-
42
- // string # Public key fingerprint
43
- getFingerprint = () => this.attributes.fingerprint
44
-
45
- setFingerprint = value => {
46
- this.attributes.fingerprint = value
47
- }
48
-
49
- // int64 # User ID. Provide a value of `0` to operate the current session's user.
50
- getUserId = () => this.attributes.user_id
51
-
52
- setUserId = value => {
53
- this.attributes.user_id = value
54
- }
55
-
56
- // string # Actual contents of Public key.
57
- getPublicKey = () => this.attributes.public_key
58
-
59
- setPublicKey = value => {
60
- this.attributes.public_key = value
61
- }
62
-
63
-
64
- // Parameters:
65
- // as2_partnership_name (required) - string - AS2 Partnership Name
66
- update = async (params = {}) => {
67
- if (!this.attributes.id) {
68
- throw new Error('Current object has no id')
69
- }
70
-
71
- if (!isObject(params)) {
72
- throw new Error(`Bad parameter: params must be of type object, received ${getType(params)}`)
73
- }
74
-
75
- params.id = this.attributes.id
76
- if (params['id'] && !isInt(params['id'])) {
77
- throw new Error(`Bad parameter: id must be of type Int, received ${getType(id)}`)
78
- }
79
- if (params['as2_partnership_name'] && !isString(params['as2_partnership_name'])) {
80
- throw new Error(`Bad parameter: as2_partnership_name must be of type String, received ${getType(as2_partnership_name)}`)
81
- }
82
-
83
- if (!params['id']) {
84
- if (this.attributes.id) {
85
- params['id'] = this.id
86
- } else {
87
- throw new Error('Parameter missing: id')
88
- }
89
- }
90
-
91
- if (!params['as2_partnership_name']) {
92
- if (this.attributes.as2_partnership_name) {
93
- params['as2_partnership_name'] = this.as2_partnership_name
94
- } else {
95
- throw new Error('Parameter missing: as2_partnership_name')
96
- }
97
- }
98
-
99
- return Api.sendRequest(`/as2_keys/${params['id']}`, 'PATCH', params, this.options)
100
- }
101
-
102
- delete = async (params = {}) => {
103
- if (!this.attributes.id) {
104
- throw new Error('Current object has no id')
105
- }
106
-
107
- if (!isObject(params)) {
108
- throw new Error(`Bad parameter: params must be of type object, received ${getType(params)}`)
109
- }
110
-
111
- params.id = this.attributes.id
112
- if (params['id'] && !isInt(params['id'])) {
113
- throw new Error(`Bad parameter: id must be of type Int, received ${getType(id)}`)
114
- }
115
-
116
- if (!params['id']) {
117
- if (this.attributes.id) {
118
- params['id'] = this.id
119
- } else {
120
- throw new Error('Parameter missing: id')
121
- }
122
- }
123
-
124
- return Api.sendRequest(`/as2_keys/${params['id']}`, 'DELETE', params, this.options)
125
- }
126
-
127
- destroy = (params = {}) =>
128
- this.delete(params)
129
-
130
- save = () => {
131
- if (this.attributes['id']) {
132
- return this.update(this.attributes)
133
- } else {
134
- const newObject = As2Key.create(this.attributes, this.options)
135
- this.attributes = { ...newObject.attributes }
136
- return true
137
- }
138
- }
139
-
140
- // Parameters:
141
- // user_id - int64 - User ID. Provide a value of `0` to operate the current session's user.
142
- // cursor - string - Used for pagination. Send a cursor value to resume an existing list from the point at which you left off. Get a cursor from an existing list via either the X-Files-Cursor-Next header or the X-Files-Cursor-Prev header.
143
- // per_page - int64 - Number of records to show per page. (Max: 10,000, 1,000 or less is recommended).
144
- static list = async (params = {}, options = {}) => {
145
- if (params['user_id'] && !isInt(params['user_id'])) {
146
- throw new Error(`Bad parameter: user_id must be of type Int, received ${getType(user_id)}`)
147
- }
148
-
149
- if (params['cursor'] && !isString(params['cursor'])) {
150
- throw new Error(`Bad parameter: cursor must be of type String, received ${getType(cursor)}`)
151
- }
152
-
153
- if (params['per_page'] && !isInt(params['per_page'])) {
154
- throw new Error(`Bad parameter: per_page must be of type Int, received ${getType(per_page)}`)
155
- }
156
-
157
- const response = await Api.sendRequest(`/as2_keys`, 'GET', params, options)
158
-
159
- return response?.data?.map(obj => new As2Key(obj, options)) || []
160
- }
161
-
162
- static all = (params = {}, options = {}) =>
163
- As2Key.list(params, options)
164
-
165
- // Parameters:
166
- // id (required) - int64 - As2 Key ID.
167
- static find = async (id, params = {}, options = {}) => {
168
- if (!isObject(params)) {
169
- throw new Error(`Bad parameter: params must be of type object, received ${getType(params)}`)
170
- }
171
-
172
- params['id'] = id
173
-
174
- if (!params['id']) {
175
- throw new Error('Parameter missing: id')
176
- }
177
-
178
- if (params['id'] && !isInt(params['id'])) {
179
- throw new Error(`Bad parameter: id must be of type Int, received ${getType(id)}`)
180
- }
181
-
182
- const response = await Api.sendRequest(`/as2_keys/${params['id']}`, 'GET', params, options)
183
-
184
- return new As2Key(response?.data, options)
185
- }
186
-
187
- static get = (id, params = {}, options = {}) =>
188
- As2Key.find(id, params, options)
189
-
190
- // Parameters:
191
- // user_id - int64 - User ID. Provide a value of `0` to operate the current session's user.
192
- // as2_partnership_name (required) - string - AS2 Partnership Name
193
- // public_key (required) - string - Actual contents of Public key.
194
- static create = async (params = {}, options = {}) => {
195
- if (!params['as2_partnership_name']) {
196
- throw new Error('Parameter missing: as2_partnership_name')
197
- }
198
-
199
- if (!params['public_key']) {
200
- throw new Error('Parameter missing: public_key')
201
- }
202
-
203
- if (params['user_id'] && !isInt(params['user_id'])) {
204
- throw new Error(`Bad parameter: user_id must be of type Int, received ${getType(user_id)}`)
205
- }
206
-
207
- if (params['as2_partnership_name'] && !isString(params['as2_partnership_name'])) {
208
- throw new Error(`Bad parameter: as2_partnership_name must be of type String, received ${getType(as2_partnership_name)}`)
209
- }
210
-
211
- if (params['public_key'] && !isString(params['public_key'])) {
212
- throw new Error(`Bad parameter: public_key must be of type String, received ${getType(public_key)}`)
213
- }
214
-
215
- const response = await Api.sendRequest(`/as2_keys`, 'POST', params, options)
216
-
217
- return new As2Key(response?.data, options)
218
- }
219
- }
220
-
221
- export default As2Key