cozy-client 34.11.1 → 35.1.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.
- package/dist/CozyClient.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.node.js +1 -1
- package/dist/models/account.js +91 -15
- package/dist/models/account.spec.js +82 -1
- package/dist/models/manifest.js +239 -0
- package/dist/models/manifest.spec.js +446 -0
- package/dist/models/trigger.js +120 -27
- package/dist/models/trigger.spec.js +67 -0
- package/dist/types.js +63 -3
- package/package.json +3 -3
- package/types/index.d.ts +1 -1
- package/types/index.node.d.ts +1 -1
- package/types/models/account.d.ts +7 -5
- package/types/models/manifest.d.ts +23 -0
- package/types/models/trigger.d.ts +16 -10
- package/types/types.d.ts +150 -4
- package/dist/manifest.js +0 -83
- package/dist/manifest.spec.js +0 -135
- package/types/manifest.d.ts +0 -12
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import {
|
|
2
|
+
sanitizeCategories,
|
|
3
|
+
sanitize as sanitizeManifest,
|
|
4
|
+
getIdentifier
|
|
5
|
+
} from './manifest'
|
|
6
|
+
|
|
7
|
+
describe('sanitizeCategories', () => {
|
|
8
|
+
it('should return the list of the provided expected categories correctly', () => {
|
|
9
|
+
// all of these categories is authorized by config/categories.json
|
|
10
|
+
// so it won't be filtered
|
|
11
|
+
const categories = [
|
|
12
|
+
'cozy',
|
|
13
|
+
'isp',
|
|
14
|
+
'partners',
|
|
15
|
+
'press',
|
|
16
|
+
'shopping',
|
|
17
|
+
'telecom'
|
|
18
|
+
]
|
|
19
|
+
expect(sanitizeCategories(categories)).toEqual(categories)
|
|
20
|
+
})
|
|
21
|
+
it('should filter unwanted categories', () => {
|
|
22
|
+
// pressingggg is not allowed as category
|
|
23
|
+
const categories = [
|
|
24
|
+
'cozy',
|
|
25
|
+
'isp',
|
|
26
|
+
'partners',
|
|
27
|
+
'pressingggg',
|
|
28
|
+
'shopping',
|
|
29
|
+
'telecom'
|
|
30
|
+
]
|
|
31
|
+
expect(sanitizeCategories(categories)).toEqual(
|
|
32
|
+
categories.filter(c => c !== 'pressingggg')
|
|
33
|
+
)
|
|
34
|
+
})
|
|
35
|
+
it('should return "others" as category if no categories provided', () => {
|
|
36
|
+
expect(sanitizeCategories([])).toEqual(['others'])
|
|
37
|
+
expect(sanitizeCategories(null)).toEqual(['others'])
|
|
38
|
+
})
|
|
39
|
+
it('should return "others" as category if categories after filtering is empty', () => {
|
|
40
|
+
// pressingggg is not allowed as category
|
|
41
|
+
expect(sanitizeCategories(['pressingggg'])).toEqual(['others'])
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
describe('sanitizeManifest', () => {
|
|
46
|
+
const baseMan = { slug: 'mock' }
|
|
47
|
+
|
|
48
|
+
it('should handle legacy category property', () => {
|
|
49
|
+
const testCategory = 'cozy'
|
|
50
|
+
expect(
|
|
51
|
+
sanitizeManifest({ slug: 'mock', category: testCategory })
|
|
52
|
+
).toStrictEqual({
|
|
53
|
+
slug: 'mock',
|
|
54
|
+
categories: [testCategory]
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
it('should handle legacy name property locales ("en" only)', () => {
|
|
58
|
+
const testName = 'Mock'
|
|
59
|
+
expect(
|
|
60
|
+
sanitizeManifest({
|
|
61
|
+
slug: 'mock',
|
|
62
|
+
name: {
|
|
63
|
+
en: testName
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
).toEqual(
|
|
67
|
+
expect.objectContaining({
|
|
68
|
+
slug: 'mock',
|
|
69
|
+
name: testName
|
|
70
|
+
})
|
|
71
|
+
)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('should transform available_version property to availableVersion', () => {
|
|
75
|
+
const testVersion = '3.0.0'
|
|
76
|
+
const man = sanitizeManifest({
|
|
77
|
+
slug: 'mock',
|
|
78
|
+
available_version: testVersion
|
|
79
|
+
})
|
|
80
|
+
expect(man.availableVersion).toBe('3.0.0')
|
|
81
|
+
expect(man).not.toHaveProperty('available_version')
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('should remove "fields" if fields is null', () => {
|
|
85
|
+
const current = {
|
|
86
|
+
fields: null
|
|
87
|
+
}
|
|
88
|
+
const result = sanitizeManifest(current)
|
|
89
|
+
expect(result.fields).toBe(null)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it("shouldn't modify if fields is undefined", () => {
|
|
93
|
+
const current = {}
|
|
94
|
+
const result = sanitizeManifest(current)
|
|
95
|
+
expect(result.fields).toBe(undefined)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('should not mutate source manifest', () => {
|
|
99
|
+
const current = {
|
|
100
|
+
fields: {
|
|
101
|
+
username: {
|
|
102
|
+
type: 'text',
|
|
103
|
+
required: {
|
|
104
|
+
value: 'true'
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
passphrase: {
|
|
108
|
+
type: 'password'
|
|
109
|
+
},
|
|
110
|
+
birthdate: {
|
|
111
|
+
type: 'date'
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
sanitizeManifest(current)
|
|
117
|
+
expect(current).toEqual({
|
|
118
|
+
fields: {
|
|
119
|
+
username: {
|
|
120
|
+
type: 'text',
|
|
121
|
+
required: {
|
|
122
|
+
value: 'true'
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
passphrase: {
|
|
126
|
+
type: 'password'
|
|
127
|
+
},
|
|
128
|
+
birthdate: {
|
|
129
|
+
type: 'date'
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
it('should remove old property advancedFields in fields', () => {
|
|
136
|
+
const oldManifest = {
|
|
137
|
+
fields: {
|
|
138
|
+
login: {
|
|
139
|
+
type: 'text'
|
|
140
|
+
},
|
|
141
|
+
password: {
|
|
142
|
+
type: 'password'
|
|
143
|
+
},
|
|
144
|
+
advancedFields: {
|
|
145
|
+
folderPath: {
|
|
146
|
+
advanced: true,
|
|
147
|
+
isRequired: false
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const result = sanitizeManifest(oldManifest)
|
|
154
|
+
expect(result.fields.advancedFields).toBeUndefined()
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
it('should not add any identifier', () => {
|
|
158
|
+
const current = {
|
|
159
|
+
fields: {
|
|
160
|
+
passphrase: {
|
|
161
|
+
required: true,
|
|
162
|
+
type: 'password'
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const result = sanitizeManifest(current)
|
|
168
|
+
expect(result.fields.passphrase.role).not.toBe('identifier')
|
|
169
|
+
expect(Object.keys(result.fields).length).toBe(1)
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
it('should set role=identifier for login', () => {
|
|
173
|
+
const current = {
|
|
174
|
+
fields: {
|
|
175
|
+
login: { type: 'text' },
|
|
176
|
+
password: { type: 'password' }
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const result = sanitizeManifest(current)
|
|
180
|
+
expect(result.fields.login.role).toBe('identifier')
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
it('should set first non-password field as role=identifier', () => {
|
|
184
|
+
const current = {
|
|
185
|
+
fields: {
|
|
186
|
+
password: { type: 'password' },
|
|
187
|
+
plop: { type: 'text' },
|
|
188
|
+
foo: { type: 'date' }
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const result = sanitizeManifest(current)
|
|
192
|
+
expect(result.fields.plop.role).toBe('identifier')
|
|
193
|
+
expect(result.fields.foo.role).not.toBe('identifier')
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
const legacyLoginFieldsTest = [
|
|
197
|
+
'login',
|
|
198
|
+
'identifier',
|
|
199
|
+
'new_identifier',
|
|
200
|
+
'email'
|
|
201
|
+
]
|
|
202
|
+
for (let name of legacyLoginFieldsTest) {
|
|
203
|
+
let inputLegacy = {
|
|
204
|
+
fields: {
|
|
205
|
+
password: { type: 'password' },
|
|
206
|
+
plop: { type: 'text' }
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
inputLegacy.fields[name] = { type: 'text' }
|
|
210
|
+
it('should set role=identifier to ' + name, () => {
|
|
211
|
+
const result = sanitizeManifest(inputLegacy)
|
|
212
|
+
expect(result.fields[name].role).toBe('identifier')
|
|
213
|
+
expect(result.fields.plop.role).not.toBe('identifier')
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
it('should set only one identifier', () => {
|
|
218
|
+
const current = {
|
|
219
|
+
fields: {
|
|
220
|
+
identifier: { type: 'text' },
|
|
221
|
+
mail: { type: 'email' },
|
|
222
|
+
login: { type: 'text' },
|
|
223
|
+
new_identifier: { type: 'text' }
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const result = sanitizeManifest(current)
|
|
227
|
+
const identifiers = Object.keys(result.fields).filter(
|
|
228
|
+
name => result.fields[name].role === 'identifier'
|
|
229
|
+
)
|
|
230
|
+
expect(identifiers.length).toBe(1)
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
it('should set only one identifier even if there is many role=identifier in the manifest', () => {
|
|
234
|
+
const current = {
|
|
235
|
+
fields: {
|
|
236
|
+
identifier: { type: 'text' },
|
|
237
|
+
mail: { type: 'email', role: 'identifier' },
|
|
238
|
+
login: { type: 'text', role: 'identifier' },
|
|
239
|
+
new_identifier: { type: 'text', role: 'identifier' }
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const result = sanitizeManifest(current)
|
|
243
|
+
const identifiers = Object.keys(result.fields).filter(
|
|
244
|
+
name => result.fields[name].role === 'identifier'
|
|
245
|
+
)
|
|
246
|
+
expect(identifiers.length).toBe(1)
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
it('should set only one identifier even if there is no password fields', () => {
|
|
250
|
+
const current = {
|
|
251
|
+
fields: {
|
|
252
|
+
plop1: { type: 'text' },
|
|
253
|
+
plop2: { type: 'text' },
|
|
254
|
+
plop3: { type: 'text' },
|
|
255
|
+
plop4: { type: 'text' }
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const result = sanitizeManifest(current)
|
|
259
|
+
const identifiers = Object.keys(result.fields).filter(
|
|
260
|
+
name => result.fields[name].role === 'identifier'
|
|
261
|
+
)
|
|
262
|
+
expect(identifiers.length).toBe(1)
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
it('should keep the identifier priority', () => {
|
|
266
|
+
const current = {
|
|
267
|
+
fields: {
|
|
268
|
+
identifier: { type: 'text' },
|
|
269
|
+
mail: { type: 'email' },
|
|
270
|
+
login: { type: 'text' },
|
|
271
|
+
new_identifier: { type: 'text' }
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const result = sanitizeManifest(current)
|
|
275
|
+
expect(result.fields.login.required).toBe(true)
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
it('should set required=true as default value in fields', () => {
|
|
279
|
+
const current = {
|
|
280
|
+
fields: {
|
|
281
|
+
login: { type: 'text' },
|
|
282
|
+
password: { type: 'password' },
|
|
283
|
+
gender: { type: 'text', required: false },
|
|
284
|
+
country: { type: 'text' }
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
const result = sanitizeManifest(current)
|
|
288
|
+
expect(result.fields.login.required).toBe(true)
|
|
289
|
+
expect(result.fields.password.required).toBe(true)
|
|
290
|
+
expect(result.fields.gender.required).toBe(false)
|
|
291
|
+
expect(result.fields.country.required).toBe(true)
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
it('should handle legacy property isRequired in fields', () => {
|
|
295
|
+
const current = {
|
|
296
|
+
fields: {
|
|
297
|
+
login: { type: 'text' },
|
|
298
|
+
password: { type: 'password' },
|
|
299
|
+
gender: { type: 'text', isRequired: false },
|
|
300
|
+
country: { type: 'text' }
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
const result = sanitizeManifest(current)
|
|
304
|
+
expect(result.fields.login.required).toBe(true)
|
|
305
|
+
expect(result.fields.password.required).toBe(true)
|
|
306
|
+
expect(result.fields.gender.required).toBe(false)
|
|
307
|
+
expect(result.fields.country.required).toBe(true)
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
it('should set encrypted for type=password fields', () => {
|
|
311
|
+
const current = {
|
|
312
|
+
fields: {
|
|
313
|
+
username: { type: 'text' },
|
|
314
|
+
passphrase: { type: 'password' }
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const result = sanitizeManifest(current)
|
|
319
|
+
expect(result.fields.passphrase.encrypted).toBe(true)
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
const legacyEncryptedFieldsTest = [
|
|
323
|
+
'secret',
|
|
324
|
+
'dob',
|
|
325
|
+
'code',
|
|
326
|
+
'answer',
|
|
327
|
+
'access_token',
|
|
328
|
+
'refresh_token',
|
|
329
|
+
'appSecret'
|
|
330
|
+
]
|
|
331
|
+
|
|
332
|
+
for (let name of legacyEncryptedFieldsTest) {
|
|
333
|
+
let legacyManifest = {
|
|
334
|
+
fields: {
|
|
335
|
+
[name]: { type: 'text' },
|
|
336
|
+
password: { type: 'password' },
|
|
337
|
+
plop: { type: 'text' }
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
it('should set encrypted=true to ' + name, () => {
|
|
342
|
+
const result = sanitizeManifest(legacyManifest)
|
|
343
|
+
expect(result.fields[name].encrypted).toBe(true)
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
it('should keep encrypted value', () => {
|
|
347
|
+
const current = {
|
|
348
|
+
fields: {
|
|
349
|
+
[name]: { type: 'text', encrypted: false },
|
|
350
|
+
passphrase: { type: 'password', encrypted: true }
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
const result = sanitizeManifest(current)
|
|
354
|
+
expect(result.fields[name].encrypted).toBe(false)
|
|
355
|
+
expect(result.fields.passphrase.encrypted).toBe(true)
|
|
356
|
+
})
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
describe('terms', () => {
|
|
360
|
+
it('should remove incomplete terms', () => {
|
|
361
|
+
const incompleteTerms = {
|
|
362
|
+
id: 'mock-terms'
|
|
363
|
+
}
|
|
364
|
+
expect(
|
|
365
|
+
sanitizeManifest({ ...baseMan, terms: incompleteTerms })
|
|
366
|
+
).not.toHaveProperty('terms')
|
|
367
|
+
expect(sanitizeManifest({ ...baseMan, terms: {} })).not.toHaveProperty(
|
|
368
|
+
'terms'
|
|
369
|
+
)
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
it('should keep complete terms', () => {
|
|
373
|
+
const completeTerms = {
|
|
374
|
+
id: 'mock-terms',
|
|
375
|
+
url: 'mock://terms',
|
|
376
|
+
version: 'mock001'
|
|
377
|
+
}
|
|
378
|
+
const man = { ...baseMan, terms: completeTerms }
|
|
379
|
+
|
|
380
|
+
expect(sanitizeManifest(man)).toEqual(expect.objectContaining(man))
|
|
381
|
+
})
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
describe('partnership', () => {
|
|
385
|
+
it('should remove incomplete', () => {
|
|
386
|
+
const incompletePartnership = {
|
|
387
|
+
icon: 'icon.svg' // icon is optional
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
expect(
|
|
391
|
+
sanitizeManifest({
|
|
392
|
+
...baseMan,
|
|
393
|
+
partnership: {}
|
|
394
|
+
})
|
|
395
|
+
).not.toHaveProperty('partnership')
|
|
396
|
+
|
|
397
|
+
expect(
|
|
398
|
+
sanitizeManifest({
|
|
399
|
+
...baseMan,
|
|
400
|
+
partnership: incompletePartnership
|
|
401
|
+
})
|
|
402
|
+
).not.toHaveProperty('partnership')
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
it('should keep complete', () => {
|
|
406
|
+
const completePartnership = {
|
|
407
|
+
description: 'A partnership text here' // description is mandatory
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const man = { ...baseMan, partnership: completePartnership }
|
|
411
|
+
expect(sanitizeManifest(man)).toEqual(expect.objectContaining(man))
|
|
412
|
+
})
|
|
413
|
+
})
|
|
414
|
+
})
|
|
415
|
+
|
|
416
|
+
describe('getIdentifier', () => {
|
|
417
|
+
it('should return field having role=identifier', () => {
|
|
418
|
+
const fields = {
|
|
419
|
+
username: {
|
|
420
|
+
type: 'text'
|
|
421
|
+
},
|
|
422
|
+
id: {
|
|
423
|
+
type: 'text',
|
|
424
|
+
role: 'identifier'
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
expect(getIdentifier(fields)).toBe('id')
|
|
428
|
+
})
|
|
429
|
+
|
|
430
|
+
it('should return the first field', () => {
|
|
431
|
+
const fields = {
|
|
432
|
+
username: {
|
|
433
|
+
type: 'text'
|
|
434
|
+
},
|
|
435
|
+
id: {
|
|
436
|
+
type: 'text'
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
expect(getIdentifier(fields)).toBe('username')
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
it('should return null if there is no match', () => {
|
|
444
|
+
expect(getIdentifier({})).toBe(null)
|
|
445
|
+
})
|
|
446
|
+
})
|
package/dist/models/trigger.js
CHANGED
|
@@ -7,43 +7,92 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.triggers = exports.triggerStates = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
|
|
12
12
|
var _account = require("./account");
|
|
13
13
|
|
|
14
14
|
var _logger = _interopRequireDefault(require("../logger"));
|
|
15
15
|
|
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
17
|
+
|
|
18
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
19
|
+
|
|
16
20
|
var actionableErrors = ['CHALLENGE_ASKED', 'DISK_QUOTA_EXCEEDED', 'TERMS_VERSION_MISMATCH', 'USER_ACTION_NEEDED', 'USER_ACTION_NEEDED.CHANGE_PASSWORD', 'USER_ACTION_NEEDED.ACCOUNT_REMOVED', 'USER_ACTION_NEEDED.WEBAUTH_REQUIRED', 'USER_ACTION_NEEDED.SCA_REQUIRED', 'LOGIN_FAILED'];
|
|
17
21
|
/** Trigger states come from /jobs/triggers */
|
|
18
22
|
|
|
19
23
|
var triggerStates = {
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Returns when the trigger was last executed
|
|
26
|
+
*
|
|
27
|
+
* @param {import('../types').IOCozyTrigger} trigger - trigger object
|
|
28
|
+
* @returns {String} last execution date of any job related to the given trigger
|
|
29
|
+
*/
|
|
30
|
+
getLastExecution: function getLastExecution(trigger) {
|
|
31
|
+
var _trigger$current_stat;
|
|
32
|
+
|
|
33
|
+
return trigger === null || trigger === void 0 ? void 0 : (_trigger$current_stat = trigger.current_state) === null || _trigger$current_stat === void 0 ? void 0 : _trigger$current_stat.last_execution;
|
|
23
34
|
},
|
|
24
|
-
getLastsuccess: function getLastsuccess(triggerState) {
|
|
25
|
-
_logger.default.warn('Deprecated, please use getLastSuccess instead of getLastsuccess');
|
|
26
35
|
|
|
27
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Returns when the trigger was last executed with success
|
|
38
|
+
*
|
|
39
|
+
* @param {import('../types').IOCozyTrigger} trigger - trigger object
|
|
40
|
+
* @returns {String} last execution date of any job related to the given trigger and with success
|
|
41
|
+
*/
|
|
42
|
+
getLastSuccess: function getLastSuccess(trigger) {
|
|
43
|
+
var _trigger$current_stat2;
|
|
44
|
+
|
|
45
|
+
return trigger === null || trigger === void 0 ? void 0 : (_trigger$current_stat2 = trigger.current_state) === null || _trigger$current_stat2 === void 0 ? void 0 : _trigger$current_stat2.last_success;
|
|
28
46
|
},
|
|
29
47
|
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Returns when the trigger was last executed with success
|
|
50
|
+
*
|
|
51
|
+
* @param {import('../types').IOCozyTrigger} trigger - trigger object
|
|
52
|
+
* @returns {String} last execution date of any job related to the given trigger and with success
|
|
53
|
+
*/
|
|
54
|
+
getLastsuccess: function getLastsuccess(trigger) {
|
|
55
|
+
var _trigger$current_stat3;
|
|
56
|
+
|
|
57
|
+
_logger.default.warn('Deprecated, please use getLastSuccess instead of getLastsuccess');
|
|
58
|
+
|
|
59
|
+
return trigger === null || trigger === void 0 ? void 0 : (_trigger$current_stat3 = trigger.current_state) === null || _trigger$current_stat3 === void 0 ? void 0 : _trigger$current_stat3.last_success;
|
|
33
60
|
},
|
|
34
61
|
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Returns whether last job failed
|
|
64
|
+
*
|
|
65
|
+
* @param {import('../types').IOCozyTrigger} trigger - trigger object
|
|
66
|
+
* @returns {Boolean}
|
|
67
|
+
*/
|
|
68
|
+
isErrored: function isErrored(trigger) {
|
|
69
|
+
var _trigger$current_stat4;
|
|
70
|
+
|
|
71
|
+
return (trigger === null || trigger === void 0 ? void 0 : (_trigger$current_stat4 = trigger.current_state) === null || _trigger$current_stat4 === void 0 ? void 0 : _trigger$current_stat4.status) === 'errored';
|
|
38
72
|
},
|
|
39
73
|
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Returns the type of the last error to occur
|
|
76
|
+
*
|
|
77
|
+
* @param {import('../types').IOCozyTrigger} trigger - trigger object
|
|
78
|
+
* @returns {String}
|
|
79
|
+
*/
|
|
80
|
+
getLastErrorType: function getLastErrorType(trigger) {
|
|
81
|
+
var _trigger$current_stat5;
|
|
82
|
+
|
|
83
|
+
return trigger === null || trigger === void 0 ? void 0 : (_trigger$current_stat5 = trigger.current_state) === null || _trigger$current_stat5 === void 0 ? void 0 : _trigger$current_stat5.last_error;
|
|
43
84
|
}
|
|
44
85
|
};
|
|
45
86
|
exports.triggerStates = triggerStates;
|
|
87
|
+
var DEFAULT_CRON = '0 0 0 * * 0'; // Once a week, sunday at midnight
|
|
88
|
+
|
|
46
89
|
var triggers = {
|
|
90
|
+
/**
|
|
91
|
+
* Returns whether the given trigger is associated to a konnector or not
|
|
92
|
+
*
|
|
93
|
+
* @param {import('../types').IOCozyTrigger} trigger - trigger object
|
|
94
|
+
* @returns {Boolean}
|
|
95
|
+
*/
|
|
47
96
|
isKonnectorWorker: function isKonnectorWorker(trigger) {
|
|
48
97
|
return trigger.worker === 'konnector';
|
|
49
98
|
},
|
|
@@ -51,7 +100,7 @@ var triggers = {
|
|
|
51
100
|
/**
|
|
52
101
|
* Returns the konnector slug that executed a trigger
|
|
53
102
|
*
|
|
54
|
-
* @param {
|
|
103
|
+
* @param {import('../types').IOCozyTrigger} trigger - io.cozy.triggers
|
|
55
104
|
*
|
|
56
105
|
* @returns {string|void} A konnector slug
|
|
57
106
|
*/
|
|
@@ -72,28 +121,32 @@ var triggers = {
|
|
|
72
121
|
/**
|
|
73
122
|
* getAccountId - Returns the account id for a trigger
|
|
74
123
|
*
|
|
75
|
-
* @param {
|
|
124
|
+
* @param {import('../types').IOCozyTrigger} trigger io.cozy.triggers
|
|
76
125
|
*
|
|
77
|
-
* @returns {
|
|
126
|
+
* @returns {String} Id for an io.cozy.accounts
|
|
78
127
|
*/
|
|
79
128
|
getAccountId: function getAccountId(trigger) {
|
|
80
|
-
var
|
|
129
|
+
var _trigger$message;
|
|
130
|
+
|
|
131
|
+
var legacyData = trigger === null || trigger === void 0 ? void 0 : (_trigger$message = trigger.message) === null || _trigger$message === void 0 ? void 0 : _trigger$message.Data;
|
|
81
132
|
|
|
82
133
|
if (legacyData) {
|
|
83
134
|
var message = JSON.parse(atob(legacyData));
|
|
84
135
|
return message.account;
|
|
85
136
|
} else {
|
|
86
|
-
|
|
137
|
+
var _trigger$message2;
|
|
138
|
+
|
|
139
|
+
return trigger === null || trigger === void 0 ? void 0 : (_trigger$message2 = trigger.message) === null || _trigger$message2 === void 0 ? void 0 : _trigger$message2.account;
|
|
87
140
|
}
|
|
88
141
|
},
|
|
89
142
|
|
|
90
143
|
/**
|
|
91
144
|
* Checks if the triggers current error has been muted in the corresponding io.cozy.accounts
|
|
92
145
|
*
|
|
93
|
-
* @param {
|
|
94
|
-
* @param {
|
|
146
|
+
* @param {import('../types').IOCozyTrigger} trigger io.cozy.triggers
|
|
147
|
+
* @param {import('../types').IOCozyAccount} account io.cozy.accounts used by the trigger
|
|
95
148
|
*
|
|
96
|
-
* @returns {
|
|
149
|
+
* @returns {Boolean} Whether the error is muted or not
|
|
97
150
|
*/
|
|
98
151
|
isLatestErrorMuted: function isLatestErrorMuted(trigger, account) {
|
|
99
152
|
var lastErrorType = triggerStates.getLastErrorType(trigger);
|
|
@@ -109,12 +162,52 @@ var triggers = {
|
|
|
109
162
|
/**
|
|
110
163
|
* Returns whether the error in trigger can be solved by the user
|
|
111
164
|
*
|
|
112
|
-
* @param {
|
|
165
|
+
* @param {import('../types').IOCozyTrigger} trigger io.cozy.triggers
|
|
113
166
|
*
|
|
114
|
-
* @returns {
|
|
167
|
+
* @returns {Boolean} Whether the error is muted or not
|
|
115
168
|
*/
|
|
116
169
|
hasActionableError: function hasActionableError(trigger) {
|
|
117
|
-
|
|
170
|
+
var _trigger$current_stat6;
|
|
171
|
+
|
|
172
|
+
return actionableErrors.includes(trigger === null || trigger === void 0 ? void 0 : (_trigger$current_stat6 = trigger.current_state) === null || _trigger$current_stat6 === void 0 ? void 0 : _trigger$current_stat6.last_error);
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Build trigger attributes given konnector and account
|
|
177
|
+
*
|
|
178
|
+
* @param {Object} options - options object
|
|
179
|
+
* @param {import('../types').IOCozyKonnector} options.konnector - konnector object
|
|
180
|
+
* @param {import('../types').IOCozyAccount} options.account - account object
|
|
181
|
+
* @param {String} [options.cron] - cron string. Defaults to '0 0 0 * * 0'
|
|
182
|
+
* @param {object} [options.folder] - folder object
|
|
183
|
+
* @returns {import('../types').IOCozyTrigger} created trigger
|
|
184
|
+
*/
|
|
185
|
+
buildTriggerAttributes: function buildTriggerAttributes(_ref) {
|
|
186
|
+
var account = _ref.account,
|
|
187
|
+
_ref$cron = _ref.cron,
|
|
188
|
+
cron = _ref$cron === void 0 ? DEFAULT_CRON : _ref$cron,
|
|
189
|
+
folder = _ref.folder,
|
|
190
|
+
konnector = _ref.konnector;
|
|
191
|
+
var message = {
|
|
192
|
+
account: account._id,
|
|
193
|
+
konnector: konnector.slug
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
if (folder) {
|
|
197
|
+
message['folder_to_save'] = folder._id;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
var result = {
|
|
201
|
+
worker: 'konnector',
|
|
202
|
+
message: message
|
|
203
|
+
};
|
|
204
|
+
var options = konnector.clientSide ? {
|
|
205
|
+
type: '@client'
|
|
206
|
+
} : {
|
|
207
|
+
type: '@cron',
|
|
208
|
+
arguments: cron
|
|
209
|
+
};
|
|
210
|
+
return _objectSpread(_objectSpread({}, result), options);
|
|
118
211
|
}
|
|
119
212
|
};
|
|
120
213
|
exports.triggers = triggers;
|