integreat 1.3.0 → 1.3.1
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/README.md +8 -4
- package/SECURITY.md +2 -2
- package/dist/handlers/update.js +23 -3
- package/dist/handlers/update.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1533,10 +1533,14 @@ Integreat will run the action as a `GET` and then a `SET`, to mimick and update.
|
|
|
1533
1533
|
The `GET` action will have the same `payload` and `meta` as the original action.
|
|
1534
1534
|
The same goes for the `SET` action, but the `payload.data` will be the data
|
|
1535
1535
|
returned from `GET` merged with the data on the original `UPDATE` action. This
|
|
1536
|
-
will be a deep merge, prioritizing properties from the `UPDATE` action
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1536
|
+
will be a deep merge, prioritizing properties from the `UPDATE` action, but any
|
|
1537
|
+
`createdAt` date in the data from `GET` will be kept. If there's an `updatedAt`
|
|
1538
|
+
in the merged data, it will be overriden by the current time.
|
|
1539
|
+
|
|
1540
|
+
A requirement for this approach to work as expected, is that the data is casted
|
|
1541
|
+
to the same schema, but that should normally be the case when you use
|
|
1542
|
+
`payload.type` and don't set `allowRawRequest` or `allowRawResponse` on the
|
|
1543
|
+
endpoint.
|
|
1540
1544
|
|
|
1541
1545
|
When a `GET` fail, the `UPDATE` will fail with the same status and error.
|
|
1542
1546
|
|
package/SECURITY.md
CHANGED
package/dist/handlers/update.js
CHANGED
|
@@ -3,7 +3,7 @@ import mutateAndSend from '../utils/mutateAndSend.js';
|
|
|
3
3
|
import { createErrorResponse, createUnknownServiceError, } from '../utils/response.js';
|
|
4
4
|
import { getTypeAndId, setIdAndTypeOnAction } from './set.js';
|
|
5
5
|
import { deepMergeItems } from '../utils/deep.js';
|
|
6
|
-
import { isErrorResponse } from '../utils/is.js';
|
|
6
|
+
import { isErrorResponse, isTypedData } from '../utils/is.js';
|
|
7
7
|
const debug = debugLib('great');
|
|
8
8
|
const createGetAction = (action) => ({ ...action, type: 'GET' });
|
|
9
9
|
const createSetAction = (action, data) => ({
|
|
@@ -11,7 +11,12 @@ const createSetAction = (action, data) => ({
|
|
|
11
11
|
type: 'SET',
|
|
12
12
|
payload: { ...action.payload, data },
|
|
13
13
|
});
|
|
14
|
-
|
|
14
|
+
function isUpdateEndpoint(endpoint) {
|
|
15
|
+
const actionType = endpoint?.match?.action;
|
|
16
|
+
return Array.isArray(actionType)
|
|
17
|
+
? actionType.includes('UPDATE')
|
|
18
|
+
: actionType === 'UPDATE';
|
|
19
|
+
}
|
|
15
20
|
async function dispatchAction(service, action) {
|
|
16
21
|
const endpoint = await service.endpointFromAction(action);
|
|
17
22
|
if (!endpoint) {
|
|
@@ -25,6 +30,21 @@ async function dispatchAction(service, action) {
|
|
|
25
30
|
return response;
|
|
26
31
|
}
|
|
27
32
|
}
|
|
33
|
+
const updateDatesInItem = (original, merged) => isTypedData(original) && isTypedData(merged)
|
|
34
|
+
? {
|
|
35
|
+
...merged,
|
|
36
|
+
createdAt: original.createdAt,
|
|
37
|
+
...(merged.updatedAt ? { updatedAt: new Date() } : {}),
|
|
38
|
+
}
|
|
39
|
+
: merged;
|
|
40
|
+
function keepCreatedAt(original, merged) {
|
|
41
|
+
if (Array.isArray(original) && Array.isArray(merged)) {
|
|
42
|
+
return original.map((item, index) => updateDatesInItem(item, merged[index]));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return updateDatesInItem(original, merged);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
28
48
|
async function updateWithGetAndSet(service, action) {
|
|
29
49
|
const getAction = createGetAction(action);
|
|
30
50
|
const getResponse = await dispatchAction(service, getAction);
|
|
@@ -33,7 +53,7 @@ async function updateWithGetAndSet(service, action) {
|
|
|
33
53
|
}
|
|
34
54
|
let data;
|
|
35
55
|
try {
|
|
36
|
-
data = deepMergeItems(getResponse.data, action.payload.data);
|
|
56
|
+
data = keepCreatedAt(getResponse.data, deepMergeItems(getResponse.data, action.payload.data));
|
|
37
57
|
}
|
|
38
58
|
catch (error) {
|
|
39
59
|
return createErrorResponse(error, 'handler:UPDATE');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/handlers/update.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,OAAO,CAAA;AAC5B,OAAO,aAAa,MAAM,2BAA2B,CAAA;AACrD,OAAO,EACL,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/handlers/update.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,OAAO,CAAA;AAC5B,OAAO,aAAa,MAAM,2BAA2B,CAAA;AACrD,OAAO,EACL,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAK7D,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;AAE/B,MAAM,eAAe,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;AAExE,MAAM,eAAe,GAAG,CAAC,MAAc,EAAE,IAAa,EAAE,EAAE,CAAC,CAAC;IAC1D,GAAG,MAAM;IACT,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE,IAA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G,MAAM,CAAC,OAAO,CAAA;IAElB,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAE/C,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;IAC3C,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,yBAAyB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAA;KAC5D;IAED,MAAM,aAAa,GAAG,UAAU,CAAC,CAAC,CAAC,gBAAgB,UAAU,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;IACrE,KAAK,CAAC,4BAA4B,EAAE,OAAO,CAAC,EAAE,EAAE,aAAa,CAAC,CAAA;IAE9D,MAAM,UAAU,GAAG,oBAAoB,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,CAAC,CAAA;IACzD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAA;IAE7D,IAAI,gBAAgB,CAAC,QAAQ,CAAC,EAAE;QAC9B,OAAO,MAAM,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAA;KAC1D;SAAM;QACL,OAAO,MAAM,mBAAmB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;KACtD;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "integreat",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Node.js integration layer",
|
|
5
5
|
"author": "Kjell-Morten Bratsberg Thorsen <kjellmorten@integreat.io> (https://integreat.io/)",
|
|
6
6
|
"license": "ISC",
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@types/debug": "^4.1.8",
|
|
43
|
-
"@types/luxon": "^3.3.
|
|
43
|
+
"@types/luxon": "^3.3.2",
|
|
44
44
|
"ajv": "^8.12.0",
|
|
45
45
|
"cron-parser": "^4.9.0",
|
|
46
46
|
"debug": "^4.3.4",
|
|
47
47
|
"deepmerge-ts": "^5.1.0",
|
|
48
48
|
"map-any": "^1.0.0",
|
|
49
|
-
"map-transform": "^1.0.
|
|
49
|
+
"map-transform": "^1.0.3",
|
|
50
50
|
"ms": "^2.1.3",
|
|
51
51
|
"nanoid": "^4.0.2",
|
|
52
52
|
"p-limit": "^4.0.0",
|