integreat 1.6.0-rc.9 → 1.6.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 +434 -370
- package/dist/Instance.d.ts +0 -1
- package/dist/Instance.js +12 -7
- package/dist/Instance.js.map +1 -1
- package/dist/authenticators/token.d.ts +13 -1
- package/dist/authenticators/token.js +43 -3
- package/dist/authenticators/token.js.map +1 -1
- package/dist/dispatch.d.ts +0 -1
- package/dist/dispatch.js +43 -32
- package/dist/dispatch.js.map +1 -1
- package/dist/handlers/expire.js +14 -9
- package/dist/handlers/expire.js.map +1 -1
- package/dist/handlers/getAll.js +2 -2
- package/dist/handlers/getAll.js.map +1 -1
- package/dist/handlers/getIdent.js +19 -20
- package/dist/handlers/getIdent.js.map +1 -1
- package/dist/handlers/getMeta.js +2 -2
- package/dist/handlers/getMeta.js.map +1 -1
- package/dist/handlers/queue.js +1 -1
- package/dist/handlers/queue.js.map +1 -1
- package/dist/handlers/run.js +2 -2
- package/dist/handlers/run.js.map +1 -1
- package/dist/handlers/set.d.ts +14 -14
- package/dist/handlers/setMeta.js +2 -2
- package/dist/handlers/setMeta.js.map +1 -1
- package/dist/handlers/sync.js +20 -18
- package/dist/handlers/sync.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/jobs/Job.d.ts +3 -3
- package/dist/jobs/Job.js +73 -36
- package/dist/jobs/Job.js.map +1 -1
- package/dist/jobs/Schedule.js +5 -3
- package/dist/jobs/Schedule.js.map +1 -1
- package/dist/jobs/Step.d.ts +7 -4
- package/dist/jobs/Step.js +49 -37
- package/dist/jobs/Step.js.map +1 -1
- package/dist/schema/Schema.js.map +1 -1
- package/dist/schema/createCast.js +5 -5
- package/dist/schema/createCast.js.map +1 -1
- package/dist/schema/expandShape.js.map +1 -1
- package/dist/schema/types.d.ts +1 -3
- package/dist/service/Auth.js +2 -2
- package/dist/service/Auth.js.map +1 -1
- package/dist/service/Endpoint.d.ts +3 -5
- package/dist/service/Endpoint.js +14 -11
- package/dist/service/Endpoint.js.map +1 -1
- package/dist/service/Service.d.ts +4 -3
- package/dist/service/Service.js +32 -9
- package/dist/service/Service.js.map +1 -1
- package/dist/service/types.d.ts +2 -3
- package/dist/service/utils/authAction.d.ts +12 -9
- package/dist/service/utils/authData.d.ts +1 -3
- package/dist/service/utils/authData.js.map +1 -1
- package/dist/service/utils/compareEndpoints.d.ts +1 -2
- package/dist/service/utils/compareEndpoints.js +2 -2
- package/dist/service/utils/compareEndpoints.js.map +1 -1
- package/dist/service/utils/incoming.js +23 -13
- package/dist/service/utils/incoming.js.map +1 -1
- package/dist/service/utils/isEndpointMatch.d.ts +3 -0
- package/dist/service/utils/{matchEnpoints.js → isEndpointMatch.js} +13 -13
- package/dist/service/utils/isEndpointMatch.js.map +1 -0
- package/dist/service/utils/options.d.ts +2 -0
- package/dist/types.d.ts +21 -36
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/action.d.ts +47 -23
- package/dist/utils/action.js +18 -1
- package/dist/utils/action.js.map +1 -1
- package/dist/utils/array.d.ts +1 -0
- package/dist/utils/array.js +1 -0
- package/dist/utils/array.js.map +1 -1
- package/dist/utils/composeMiddleware.d.ts +2 -0
- package/dist/utils/composeMiddleware.js +4 -0
- package/dist/utils/composeMiddleware.js.map +1 -0
- package/dist/utils/deep.d.ts +2 -1
- package/dist/utils/is.d.ts +3 -3
- package/dist/utils/is.js +3 -3
- package/dist/utils/is.js.map +1 -1
- package/dist/utils/mergeDefinitions.js +5 -1
- package/dist/utils/mergeDefinitions.js.map +1 -1
- package/dist/utils/modifyOperationObject.js +1 -1
- package/dist/utils/modifyOperationObject.js.map +1 -1
- package/dist/utils/response.js +7 -6
- package/dist/utils/response.js.map +1 -1
- package/dist/utils/unwrapValue.js +2 -1
- package/dist/utils/unwrapValue.js.map +1 -1
- package/dist/utils/validateFilters.js.map +1 -1
- package/dist/utils/validation.d.ts +2 -2
- package/dist/utils/validation.js +1 -2
- package/dist/utils/validation.js.map +1 -1
- package/package.json +23 -21
- package/dist/service/utils/matchEnpoints.d.ts +0 -3
- package/dist/service/utils/matchEnpoints.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
# 
|
|
2
2
|
|
|
3
|
-
An integration layer
|
|
3
|
+
An integration layer written in TypeScript.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/integreat)
|
|
6
6
|
[](https://codeclimate.com/github/integreat-io/integreat/maintainability)
|
|
7
7
|
|
|
8
|
-
The basic idea of Integreat is to make it easy to define how to send data to
|
|
9
|
-
receive data from a set of [**services**](#services), and expose them
|
|
10
|
-
well defined interface, abstracting away the specifics of each
|
|
8
|
+
The basic idea of Integreat is to make it easy to define how to send data to
|
|
9
|
+
and receive data from a set of [**services**](#services), and expose them
|
|
10
|
+
through a well defined interface, abstracting away the specifics of each
|
|
11
|
+
service.
|
|
11
12
|
|
|
12
13
|
There are a few concepts that makes this possible:
|
|
13
14
|
|
|
@@ -17,8 +18,8 @@ There are a few concepts that makes this possible:
|
|
|
17
18
|
deal with familiar JavasScript objects, arrays, and primitive data types,
|
|
18
19
|
regardless of what the service expects.
|
|
19
20
|
- [**Mutation pipelines**](#mutations) let you define how the data coming from
|
|
20
|
-
or going to a service should be transformed. This includes changing the
|
|
21
|
-
structure, renaming properties, transforming and filtering values with
|
|
21
|
+
or going to a service should be transformed. This includes changing the
|
|
22
|
+
overal structure, renaming properties, transforming and filtering values with
|
|
22
23
|
transformer functions, etc. You may also provide your own transformer
|
|
23
24
|
functions.
|
|
24
25
|
- [**Schemas**](#schemas) serve as a common normalization of data between
|
|
@@ -27,9 +28,9 @@ There are a few concepts that makes this possible:
|
|
|
27
28
|
may send it to any service where you have set up the right mutations for this
|
|
28
29
|
schema, again abstracting away all service details.
|
|
29
30
|
|
|
30
|
-
All configuration is done through basic JSON-friendly structures, and you
|
|
31
|
-
your services with different endpoints, mutation pipelines,
|
|
32
|
-
schemes, etc.
|
|
31
|
+
All configuration is done through basic JSON-friendly structures, and you
|
|
32
|
+
define your services with different endpoints, mutation pipelines,
|
|
33
|
+
authentication schemes, etc.
|
|
33
34
|
|
|
34
35
|
Your configuration is spun up as an Integreat instance. To send and retrieve
|
|
35
36
|
data, you dispatch [**actions**](#actions) to your instance and get
|
|
@@ -79,6 +80,9 @@ though, depends on how you define your services.
|
|
|
79
80
|
|
|
80
81
|
Requires node v18.
|
|
81
82
|
|
|
83
|
+
Note: This package is native [ESM](https://nodejs.org/api/esm.html). See this
|
|
84
|
+
guide on how to [convert to or use ESM packages](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
|
|
85
|
+
|
|
82
86
|
Install from npm:
|
|
83
87
|
|
|
84
88
|
```
|
|
@@ -97,8 +101,9 @@ usefulness of Integreat, but it shows you the simplest setup possible.
|
|
|
97
101
|
|
|
98
102
|
Here, we fetch cat facts from the API endpoint
|
|
99
103
|
'https://cat-fact.herokuapp.com/facts', which returns data in JSON and requires
|
|
100
|
-
no authentication. The returned list of facts are mutated and cast to the
|
|
101
|
-
schema. We only fetch data _from_ the service, and no data is sent _to_
|
|
104
|
+
no authentication. The returned list of facts are mutated and cast to the
|
|
105
|
+
`fact` schema. We only fetch data _from_ the service, and no data is sent _to_
|
|
106
|
+
it.
|
|
102
107
|
|
|
103
108
|
```javascript
|
|
104
109
|
import Integreat from 'integreat'
|
|
@@ -183,8 +188,8 @@ The `response` object will look like this:
|
|
|
183
188
|
|
|
184
189
|
# Integreat concepts
|
|
185
190
|
|
|
186
|
-
As mentioned in the introduction, the building blocks of Integreat are
|
|
187
|
-
transporters and adapters, mutation pipelines, and schemas.
|
|
191
|
+
As mentioned in the introduction, the building blocks of Integreat are
|
|
192
|
+
services, transporters and adapters, mutation pipelines, and schemas.
|
|
188
193
|
|
|
189
194
|
## Services
|
|
190
195
|
|
|
@@ -192,18 +197,19 @@ A service is the API, database, FTP server, queue, etc. that you want to get
|
|
|
192
197
|
data from and/or set data to. We pass on a set of service definitions to
|
|
193
198
|
Integreat, specifying what transporter, adapters, authentication schemas it
|
|
194
199
|
requires, in adition to defining the different endpoints available on the
|
|
195
|
-
service, how they should be called, and how data should be mutated in each
|
|
200
|
+
service, how they should be called, and how data should be mutated in each
|
|
201
|
+
case.
|
|
196
202
|
|
|
197
203
|
We'll get back to the details of all of this in turn, but first we want to
|
|
198
204
|
highlight how central the concept of a service is to Integreat. Basically, in
|
|
199
205
|
Integreat "everything is a service". A simple REST/JSON API is a service, a
|
|
200
206
|
database is a service, and everything external you want to communicate with are
|
|
201
|
-
services. Want to set up a queue to handle actions one by one? That's a
|
|
202
|
-
Want to cache data in a memory store? That's a service. Want to
|
|
203
|
-
to run on intervals? That's a service to. By simply defining
|
|
204
|
-
specifics, you may set up a variety of different types of
|
|
205
|
-
the same few building blocks. This is very powerful as
|
|
206
|
-
right mindset.
|
|
207
|
+
services. Want to set up a queue to handle actions one by one? That's a
|
|
208
|
+
service. Want to cache data in a memory store? That's a service. Want to
|
|
209
|
+
schedule actions to run on intervals? That's a service to. By simply defining
|
|
210
|
+
services and their specifics, you may set up a variety of different types of
|
|
211
|
+
configurations with the same few building blocks. This is very powerful as
|
|
212
|
+
soon as you get into the right mindset.
|
|
207
213
|
|
|
208
214
|
Services are configured by service definitions, and tells Integreat how to
|
|
209
215
|
fetch data from a service, how to mutate this data to schemas, and how to send
|
|
@@ -239,10 +245,10 @@ pipeline for a service.
|
|
|
239
245
|
|
|
240
246
|
The `auth` property should normally be set to the id of an
|
|
241
247
|
[auth definition](#service-authentication), if the service requires
|
|
242
|
-
authentication. In cases where the service is authenticated by other means,
|
|
243
|
-
by including username and password in the uri, set the `auth` property to
|
|
244
|
-
to signal that this is an authenticated service. For services accepting
|
|
245
|
-
actions, `auth` should be set to an object with
|
|
248
|
+
authentication. In cases where the service is authenticated by other means,
|
|
249
|
+
e.g. by including username and password in the uri, set the `auth` property to
|
|
250
|
+
`true` to signal that this is an authenticated service. For services accepting
|
|
251
|
+
incoming actions, `auth` should be set to an object with
|
|
246
252
|
`{ outgoing: <auth id | true>, incoming: <auth id | true>}`. To accept several
|
|
247
253
|
incoming actions, provide an array of `<auth id | true>`, and they will be run
|
|
248
254
|
from first to last until one of them returns an ident or an error other than
|
|
@@ -261,8 +267,8 @@ merged with the `options` object on the endpoint. See
|
|
|
261
267
|
|
|
262
268
|
A service will have at least one endpoint, but often there will be several.
|
|
263
269
|
Endpoints are the definitions of the different ways Integreat may interact with
|
|
264
|
-
a service. You decide how you want to set up the endpoints and what is the
|
|
265
|
-
"endpoint design" for a service, but there might be one endpoint for each
|
|
270
|
+
a service. You decide how you want to set up the endpoints and what is the
|
|
271
|
+
right "endpoint design" for a service, but there might be one endpoint for each
|
|
266
272
|
operation that can be done with a type of data.
|
|
267
273
|
|
|
268
274
|
For example, let's say you have a simple REST API with blog articles and
|
|
@@ -283,9 +289,9 @@ different database operations (through the transporter).
|
|
|
283
289
|
|
|
284
290
|
> [!NOTE]
|
|
285
291
|
> This is not to say that Integreat requires you to set up endpoints
|
|
286
|
-
> exactly as described in these examples, it might be that you would like to
|
|
287
|
-
> up an endpoint that handles many of these cases. The intention here is
|
|
288
|
-
> give you an understanding of what an endpoint is in Integreat.
|
|
292
|
+
> exactly as described in these examples, it might be that you would like to
|
|
293
|
+
> set up an endpoint that handles many of these cases. The intention here is
|
|
294
|
+
> just to give you an understanding of what an endpoint is in Integreat.
|
|
289
295
|
|
|
290
296
|
When you dispatch an action, Integreat will figure out what service and what
|
|
291
297
|
endpoint to send the action to. The target service is often specified in the
|
|
@@ -293,9 +299,16 @@ action payload with the `targetService` (or shorthand `service`) property, but
|
|
|
293
299
|
if not, the default service of the schema specified with the payload `type`
|
|
294
300
|
property, will be used.
|
|
295
301
|
|
|
296
|
-
The
|
|
297
|
-
|
|
298
|
-
|
|
302
|
+
The `targetService` property will be set on the the action payload when it is
|
|
303
|
+
sent to the transporter, before it goes through the middleware. There are two
|
|
304
|
+
exceptions to this, however. `targetService` will not be set for a queued
|
|
305
|
+
action (and it will not be removed if it is already set), and it will not be
|
|
306
|
+
set for actions where the `meta.options.doSetTargetService` flag is set to
|
|
307
|
+
`false`.
|
|
308
|
+
|
|
309
|
+
The matching to an endpoint is done by finding the endpoint whose `match`
|
|
310
|
+
object matches the action with most accuracy. The rules of the endpoint
|
|
311
|
+
matching is describe in more details [below](#match-properties).
|
|
299
312
|
|
|
300
313
|
Here's the format of an endpoint definition:
|
|
301
314
|
|
|
@@ -338,16 +351,17 @@ specify a few things:
|
|
|
338
351
|
- `match`: The match object is used to decide the right endpoint for an action.
|
|
339
352
|
More one this in the [Match properties](#match-properties) section.
|
|
340
353
|
- `validate`: This is an array of condition that have to be met in order for
|
|
341
|
-
Integreat to proceed with the endpoint. The `condition` is a mutation
|
|
342
|
-
that should return a truthy value for the validation to pass. Any
|
|
343
|
-
will cause the validation to fail. If `validate` is missing or
|
|
344
|
-
no validation will be done. This may sound similar to `match
|
|
345
|
-
is only processed after a match is found, and if the
|
|
346
|
-
other endpoint is considered. On a failing validation,
|
|
347
|
-
returned as the response from this action, or a
|
|
348
|
-
`failResponse` is provided. There's also a
|
|
349
|
-
`failResponse` to a string, which will be the
|
|
350
|
-
`badrequest` response. The response is passed through
|
|
354
|
+
Integreat to proceed with the endpoint. The `condition` is a mutation
|
|
355
|
+
pipeline that should return a truthy value for the validation to pass. Any
|
|
356
|
+
falsy value will cause the validation to fail. If `validate` is missing or
|
|
357
|
+
an empty array, no validation will be done. This may sound similar to `match
|
|
358
|
+
`, but `validate` is only processed after a match is found, and if the
|
|
359
|
+
validation fails, no other endpoint is considered. On a failing validation,
|
|
360
|
+
the `failResponse` is returned as the response from this action, or a
|
|
361
|
+
`badrequest` response if no `failResponse` is provided. There's also a
|
|
362
|
+
shorthand, where you set `failResponse` to a string, which will be the
|
|
363
|
+
`error` message of the `badrequest` response. The response is passed through
|
|
364
|
+
the mutation pipeline.
|
|
351
365
|
- `mutate`: A mutation pipeline for the endpoint. The pipeline is run for both
|
|
352
366
|
actions going to a service and the response coming back, so keep this in mind
|
|
353
367
|
when you set up this pipeline. See [Mutation pipelines](#mutations)
|
|
@@ -369,10 +383,10 @@ specify a few things:
|
|
|
369
383
|
data is not typed. The default is `false`, expcept for incoming endpoints
|
|
370
384
|
(endpoints where `match` object has `incoming: true`) where the default value
|
|
371
385
|
is `true`.
|
|
372
|
-
- `castWithoutDefaults`: Set to `true` when you don't want to set default
|
|
373
|
-
on casted data. This also means no `id` will be generated and no
|
|
374
|
-
or `updatedAt` will be set – when any of these are missing in
|
|
375
|
-
Default is `false`.
|
|
386
|
+
- `castWithoutDefaults`: Set to `true` when you don't want to set default
|
|
387
|
+
values on casted data. This also means no `id` will be generated and no
|
|
388
|
+
`createdAt` or `updatedAt` will be set – when any of these are missing in
|
|
389
|
+
the data. Default is `false`.
|
|
376
390
|
- `options`: This object is merged with the `options` object on the service
|
|
377
391
|
definition, and provide options for transporters and adapters. See
|
|
378
392
|
[the `options` object](#options-object) for more on this.
|
|
@@ -382,8 +396,8 @@ specify a few things:
|
|
|
382
396
|
An endpoint may specify none or more of the following match properties:
|
|
383
397
|
|
|
384
398
|
- `type`: When set, the endpoint will only be used for actions with the
|
|
385
|
-
specified schema type (the schema's id). `type` may also be an array of
|
|
386
|
-
matching any one of the schemas in the list.
|
|
399
|
+
specified schema type (the schema's id). `type` may also be an array of
|
|
400
|
+
types, matching any one of the schemas in the list.
|
|
387
401
|
- `scope`: May be `member`, `members`, `collection`, or `all`, to specify that
|
|
388
402
|
the endpoint should be used to request one item (member) by id, several items
|
|
389
403
|
by ids (members), or an entire collection of items. Setting this to `member`
|
|
@@ -395,17 +409,19 @@ An endpoint may specify none or more of the following match properties:
|
|
|
395
409
|
match. `action` may also be a list of action types, matching any of these.
|
|
396
410
|
- `params`: This object should list all params that this endpoint supports. A
|
|
397
411
|
param in this context is any property on the action payload except `type`,
|
|
398
|
-
`id`, or `data`. Use the param name as key on this object and set the value
|
|
399
|
-
`true` if it is required, and `false` if it is optional. When matching
|
|
400
|
-
endpoints, an action will only match if it has all the required params, and
|
|
401
|
-
case several match, the endpoint with more specified params will be
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
412
|
+
`id`, or `data`. Use the param name as key on this object and set the value
|
|
413
|
+
to `true` if it is required, and `false` if it is optional. When matching
|
|
414
|
+
endpoints, an action will only match if it has all the required params, and
|
|
415
|
+
in case several match, the endpoint with more specified params will be
|
|
416
|
+
preferred.
|
|
417
|
+
- `incoming`: If this is `true`, it will only match incoming actions, if
|
|
418
|
+
`false` only outgoing, and if not set, it will match both.
|
|
419
|
+
- `conditions`: An array of mutation pipelines that will be run on the action
|
|
420
|
+
to see if it's a fit for this endpoint. If all pipelines return a truthy
|
|
421
|
+
value, the endpoint is chosen (given that the other match properties also
|
|
422
|
+
match). We rely on JavaScript definition of 'truthy' here, so any value that
|
|
423
|
+
is not `false`, `null`, `undefined`, `0`, `NaN`, or `''` will be considered
|
|
424
|
+
truthy.
|
|
409
425
|
|
|
410
426
|
> [!NOTE]
|
|
411
427
|
> There used to be a `filters` property on the endpoint match object. It is
|
|
@@ -416,9 +432,9 @@ An endpoint may specify none or more of the following match properties:
|
|
|
416
432
|
> Editor's note: Describe what incoming actions are, and give more details on
|
|
417
433
|
> filters.
|
|
418
434
|
|
|
419
|
-
There might be cases where several endpoints match an action, and in these
|
|
420
|
-
the endpoint with the highest level of specificity will be used. E.g.,
|
|
421
|
-
`GET` action asking for resources of type `entry`, an endpoint with both
|
|
435
|
+
There might be cases where several endpoints match an action, and in these
|
|
436
|
+
cases the endpoint with the highest level of specificity will be used. E.g.,
|
|
437
|
+
for a `GET` action asking for resources of type `entry`, an endpoint with both
|
|
422
438
|
`action: 'GET'` and `type: 'entry'` is picked over an endpoint matching all
|
|
423
439
|
`GET` actions regardless of type. For `params` and `filters` this is decided by
|
|
424
440
|
the highest number of properties on these objects.
|
|
@@ -489,8 +505,8 @@ Example of an `options` object set on the service definition:
|
|
|
489
505
|
```
|
|
490
506
|
|
|
491
507
|
Any properties set directly on the `options` object or on a `transporter`
|
|
492
|
-
property, are treated as options for the transporter. If there are properties
|
|
493
|
-
both the `options` and a `transporter` object, they will be merged, with the
|
|
508
|
+
property, are treated as options for the transporter. If there are properties
|
|
509
|
+
on both the `options` and a `transporter` object, they will be merged, with the
|
|
494
510
|
`transporter` object having priority if conflicts. This is a shallow merge, so
|
|
495
511
|
objects used in the options will not be merged.
|
|
496
512
|
|
|
@@ -509,9 +525,9 @@ for clarity, but both will work.
|
|
|
509
525
|
Adapter options may be given in an `adapters` object, where each adapter may
|
|
510
526
|
have its own options, set with the id of the adapter as a key. In the example
|
|
511
527
|
above, the `xml` adapter will be given the `namespaces` object. A requirement
|
|
512
|
-
for this, is that the adapter actually have an id. Adapters provided directly
|
|
513
|
-
service definition may not have an id, but all adapters that are referenced
|
|
514
|
-
an id, will also be given options set on that id, which is the common behavior.
|
|
528
|
+
for this, is that the adapter actually have an id. Adapters provided directly
|
|
529
|
+
on service definition may not have an id, but all adapters that are referenced
|
|
530
|
+
by an id, will also be given options set on that id, which is the common behavior.
|
|
515
531
|
|
|
516
532
|
Finally, when all this sorting have been done on options from both the service
|
|
517
533
|
definition and an endpoint, the two options structures are merged before being
|
|
@@ -592,11 +608,12 @@ Integreat supports getting and setting metadata for a service. The most common
|
|
|
592
608
|
use of this is to keep track of when data of a certain type was last synced.
|
|
593
609
|
|
|
594
610
|
Some services may have support for storing their own metadata, but usually you
|
|
595
|
-
set up a dedicated service for storing other services' metadata. A few
|
|
596
|
-
pieces goes into setting up a meta store:
|
|
611
|
+
set up a dedicated service for storing other services' metadata. A few
|
|
612
|
+
different pieces goes into setting up a meta store:
|
|
597
613
|
|
|
598
614
|
- A meta schema with the fields available as metadata
|
|
599
|
-
- A service for storing metadata, with an endpoint suporting the metadata
|
|
615
|
+
- A service for storing metadata, with an endpoint suporting the metadata
|
|
616
|
+
schema
|
|
600
617
|
- Possible a metadata mutation for the metadata service
|
|
601
618
|
|
|
602
619
|
When all of this is set up, you activate the metadata on the service the
|
|
@@ -640,13 +657,13 @@ Integreat has transporters for some common cases, and more may come:
|
|
|
640
657
|
- [MQTT](https://github.com/integreat-io/integreat-transporter-mqtt)
|
|
641
658
|
- [Redis](https://github.com/integreat-io/integreat-transporter-redis)
|
|
642
659
|
|
|
643
|
-
You may write your own transporters if your case is not covered by any of
|
|
644
|
-
Documentation on developing transporters are coming.
|
|
660
|
+
You may write your own transporters if your case is not covered by any of
|
|
661
|
+
these. Documentation on developing transporters are coming.
|
|
645
662
|
|
|
646
663
|
Integreat will handle the transporters based on you configurations, but there
|
|
647
664
|
are some specifics to each transporter, like HTTP needing an `uri` option or
|
|
648
|
-
MongoDb needing a `collection` option. See the documentation of each
|
|
649
|
-
for more.
|
|
665
|
+
MongoDb needing a `collection` option. See the documentation of each
|
|
666
|
+
transporter for more.
|
|
650
667
|
|
|
651
668
|
## Adapters
|
|
652
669
|
|
|
@@ -686,10 +703,10 @@ with the service or a third-party service, like with OAuth2.
|
|
|
686
703
|
When [setting up a service](#services), you may provide it with an auth id that
|
|
687
704
|
refers to a [service authentication definition](#service-authentication), that
|
|
688
705
|
again refers to an authenticator by id. The service auth definition also holds
|
|
689
|
-
options for the authenticator, so when assigning an auth id to a service,
|
|
690
|
-
assigning it an authenticator with those specific options. Another
|
|
691
|
-
use the same authenticator, but with different options, and you
|
|
692
|
-
up with a different service authentication definition.
|
|
706
|
+
options for the authenticator, so when assigning an auth id to a service,
|
|
707
|
+
you're assigning it an authenticator with those specific options. Another
|
|
708
|
+
service may use the same authenticator, but with different options, and you
|
|
709
|
+
would set this up with a different service authentication definition.
|
|
693
710
|
|
|
694
711
|
Authentication for outgoing actions are done when sending the action. When
|
|
695
712
|
authenticated, an auth object is retrieved with the auth-as method specified on
|
|
@@ -697,11 +714,11 @@ the transporter (e.g. `asHttpHeaders` for the http transporter), or on the
|
|
|
697
714
|
`overrideAuthAsMethod` in [auth options](#service-authentication) if set. The
|
|
698
715
|
auth object is passed to the transporter on the action `meta.auth` prop. It is
|
|
699
716
|
applied just before sending it, though, so it will be available to service
|
|
700
|
-
middleware, but not to the mutation pipeline. This is done to expose
|
|
701
|
-
in as few places as possible. If you however _want_ to have the
|
|
702
|
-
mutations, set `authInData` to `true` on the service or
|
|
703
|
-
authentication will be done in the `preflightAction`
|
|
704
|
-
available on `meta.auth` throughout the entire mutation pipeline.
|
|
717
|
+
middleware, but not to the mutation pipeline. This is done to expose
|
|
718
|
+
credentials in as few places as possible. If you however _want_ to have the
|
|
719
|
+
auth object in mutations, set `authInData` to `true` on the service or
|
|
720
|
+
endpoint options, and authentication will be done in the `preflightAction`
|
|
721
|
+
step instead, making it available on `meta.auth` throughout the entire mutation pipeline.
|
|
705
722
|
|
|
706
723
|
For incoming actions, authentication is done when a listening action calls the
|
|
707
724
|
`authenticate()` callback. The `validate()` method on the authenticator is used
|
|
@@ -710,29 +727,30 @@ here, which will provide the transporter with an authorized ident.
|
|
|
710
727
|
Available authenticators:
|
|
711
728
|
|
|
712
729
|
- `action`: Will dispatch an action and use the response data to create an
|
|
713
|
-
authentication. The `options` should have the action type as `action`, and
|
|
714
|
-
entire payload as `payload`. The response data should have an `auth`
|
|
715
|
-
that will be used directly, and an optional `expire` that is a
|
|
716
|
-
which the auth will expire, in milleseconds since Epoc
|
|
717
|
-
`expire` is returned, the `expireIn` option will be used
|
|
718
|
-
given as milliseconds before the auth should expire, or a
|
|
719
|
-
`'1h'`.
|
|
730
|
+
authentication. The `options` should have the action type as `action`, and
|
|
731
|
+
the entire payload as `payload`. The response data should have an `auth`
|
|
732
|
+
object, that will be used directly, and an optional `expire` that is a
|
|
733
|
+
timestamp on which the auth will expire, in milleseconds since Epoc
|
|
734
|
+
(1970-01-01). If no `expire` is returned, the `expireIn` option will be used
|
|
735
|
+
if present. It is given as milliseconds before the auth should expire, or a
|
|
736
|
+
`ms` string like `'1h'`.
|
|
720
737
|
- `http`: Supports http native authentications, like `Basic` and `Bearer`. It's
|
|
721
738
|
included with the
|
|
722
739
|
[HTTP transporter](https://github.com/integreat-io/integreat-transporter-http).
|
|
723
740
|
- `ident`: Will always grant access and `validate()` will return an ident with
|
|
724
741
|
the id provided in `identId` on the `options` object, or `'anonymous'` if no
|
|
725
742
|
`identId` is provided. This is built into Integreat.
|
|
726
|
-
- `options`: Will pass on the options as authentication, so whatever you
|
|
727
|
-
here is the authentication. What options to provide, then, is
|
|
728
|
-
what the relevant transporter requires. For outgoing actions,
|
|
729
|
-
provided as is. Incoming action are validated agains the
|
|
730
|
-
options (the keys may be dot notation paths in this
|
|
731
|
-
excluded). An ident with the `identId` from the
|
|
732
|
-
if the action matches. This is built into
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
743
|
+
- `options`: Will pass on the options as authentication, so whatever you
|
|
744
|
+
provide here is the authentication. What options to provide, then, is
|
|
745
|
+
depending on what the relevant transporter requires. For outgoing actions,
|
|
746
|
+
the options are provided as is. Incoming action are validated agains the
|
|
747
|
+
values given in the options (the keys may be dot notation paths in this
|
|
748
|
+
case, and `identId` is excluded). An ident with the `identId` from the
|
|
749
|
+
options as `id`, is returned if the action matches. This is built into
|
|
750
|
+
Integreat.
|
|
751
|
+
- `token`: A simple way of authenticating with a given token. For HTTP
|
|
752
|
+
requests, the token will be provided as a `Authorization` header, and a
|
|
753
|
+
configurable prefix like `Basic` or `Bearer`. This is built into Integreat.
|
|
736
754
|
- [`jwt`](https://github.com/integreat-io/integreat-authenticator-jwt): Will
|
|
737
755
|
generate and encode a JavaScript Web Token (JWT) based on the options.
|
|
738
756
|
- [`oauth2`](https://github.com/integreat-io/integreat-authenticator-oauth2):
|
|
@@ -741,23 +759,23 @@ Available authenticators:
|
|
|
741
759
|
|
|
742
760
|
## Mutations
|
|
743
761
|
|
|
744
|
-
Both on the service and on endpoints, you define mutation pipelines. The
|
|
745
|
-
mutation is run before the endpoint mutation for data coming from a
|
|
746
|
-
in the oposite order when going to a service.
|
|
762
|
+
Both on the service and on endpoints, you define mutation pipelines. The
|
|
763
|
+
service mutation is run before the endpoint mutation for data coming from a
|
|
764
|
+
service, and in the oposite order when going to a service.
|
|
747
765
|
|
|
748
|
-
A nice - but sometimes complicated - thing about mutations, is that they are
|
|
749
|
-
in both directions. They are by default defined for mutating data coming
|
|
750
|
-
a service, and will be run in reverse for data going _to_ a service. In
|
|
751
|
-
cases this reversing of the pipeline will work as expected without
|
|
752
|
-
-- you define the mutation pipeline for data coming _from_ the
|
|
753
|
-
reversed pipeline works _to_ as well. But many times you need
|
|
754
|
-
adjustments and sometimes you'll have to have separate steps based on
|
|
755
|
-
direction. We'll get into more details in the following.
|
|
766
|
+
A nice - but sometimes complicated - thing about mutations, is that they are
|
|
767
|
+
run in both directions. They are by default defined for mutating data coming
|
|
768
|
+
_from_ a service, and will be run in reverse for data going _to_ a service. In
|
|
769
|
+
some cases this reversing of the pipeline will work as expected without
|
|
770
|
+
modifications -- you define the mutation pipeline for data coming _from_ the
|
|
771
|
+
service, and the reversed pipeline works _to_ as well. But many times you need
|
|
772
|
+
to make adjustments and sometimes you'll have to have separate steps based on
|
|
773
|
+
the direction. We'll get into more details in the following.
|
|
756
774
|
|
|
757
|
-
A mutation pipeline consists of one or more steps that the data will go
|
|
758
|
-
before coming out on the other in the desired shape. It helps
|
|
759
|
-
an actual pipeline. After each step, data will be in a
|
|
760
|
-
is the input to the next step.
|
|
775
|
+
A mutation pipeline consists of one or more steps that the data will go
|
|
776
|
+
through, before coming out on the other in the desired shape. It helps
|
|
777
|
+
picturing this as an actual pipeline. After each step, data will be in a
|
|
778
|
+
different shape, and this is the input to the next step.
|
|
761
779
|
|
|
762
780
|
You define a pipeline in Integreat with an array, although for a pipeline with
|
|
763
781
|
only one step, you may skip the array for simplicity.
|
|
@@ -766,18 +784,18 @@ Each step may be one of the following:
|
|
|
766
784
|
|
|
767
785
|
- [**A dot notation path**](#dot-notation-paths), e.g. `path.to.data`. The data
|
|
768
786
|
at that path will be extracted, and will be provided as the data to the next
|
|
769
|
-
step in the pipeline. When going in reverse, the data will be set on that
|
|
770
|
-
instead.
|
|
787
|
+
step in the pipeline. When going in reverse, the data will be set on that
|
|
788
|
+
path instead.
|
|
771
789
|
- **A mutation object** is an object that basically describes the object you
|
|
772
790
|
want as a result, where the keys are dot notation paths and the values are
|
|
773
791
|
mutation pipelines. Each pipeline on the mutation object will be run on the
|
|
774
792
|
data, and then set on the path, resulting in an object that will be passed on
|
|
775
793
|
to the next step. Setting `$iterate: true` on the object will cause it to
|
|
776
794
|
iterate over items in an array, otherwise it will be applied to the array.
|
|
777
|
-
Setting `$modify: true` will cause any properties on an object in the
|
|
778
|
-
not set in the mutation, to be included, much like the spread in
|
|
779
|
-
Setting `$modify` to a path works the same, but you will spread
|
|
780
|
-
object at the path (`$modify: true` is equal to `$modify: '.'`).
|
|
795
|
+
Setting `$modify: true` will cause any properties on an object in the
|
|
796
|
+
pipeline not set in the mutation, to be included, much like the spread in
|
|
797
|
+
JavaScript. Setting `$modify` to a path works the same, but you will spread
|
|
798
|
+
from the object at the path (`$modify: true` is equal to `$modify: '.'`).
|
|
781
799
|
- **A transform object** letting you run a transformer function on the data,
|
|
782
800
|
e.g. `{ $transform: 'number' }` to transform the value into a number, or
|
|
783
801
|
`undefined` if not possible.
|
|
@@ -836,8 +854,8 @@ return `[{ id: 'john' }]`. Arrays count as one level, so after
|
|
|
836
854
|
A double carret `^^` takes you to the top -- the root -- so after
|
|
837
855
|
`content.articles[0].id`, `^^.content.authors` returns `[{ id: 'john' }]`.
|
|
838
856
|
|
|
839
|
-
Carret notations -- parents and roots -- does not currently work in reverse,
|
|
840
|
-
they might in a future version.
|
|
857
|
+
Carret notations -- parents and roots -- does not currently work in reverse,
|
|
858
|
+
but they might in a future version.
|
|
841
859
|
|
|
842
860
|
### Non-values
|
|
843
861
|
|
|
@@ -867,16 +885,16 @@ configure how data from A will be mutated to a schema, and then have data in
|
|
|
867
885
|
that schema will be mutated and sent to B.
|
|
868
886
|
|
|
869
887
|
This is a useful abstraction, and if you ever need to change one side, you can
|
|
870
|
-
do so without involving the other side. If you need to switch out service B
|
|
871
|
-
service C, you can do so without involving the configuration of service
|
|
872
|
-
you can send data to both B and C, using the same setup for service A.
|
|
888
|
+
do so without involving the other side. If you need to switch out service B
|
|
889
|
+
with service C, you can do so without involving the configuration of service
|
|
890
|
+
A, or you can send data to both B and C, using the same setup for service A.
|
|
873
891
|
|
|
874
892
|
To be clear, you can setup flows without schemas in Integreat, but then you may
|
|
875
893
|
loose this flexibility and maintainability.
|
|
876
894
|
|
|
877
|
-
A schema describe the data you expected to get out of Integreat, or send
|
|
878
|
-
it. You basically define the fields and their types, and may then cast
|
|
879
|
-
that shape. Note that data on an action for a specified type, will be
|
|
895
|
+
A schema describe the data you expected to get out of Integreat, or send
|
|
896
|
+
through it. You basically define the fields and their types, and may then cast
|
|
897
|
+
data to that shape. Note that data on an action for a specified type, will be
|
|
880
898
|
automatically cast to that type.
|
|
881
899
|
|
|
882
900
|
```javascript
|
|
@@ -906,12 +924,13 @@ automatically cast to that type.
|
|
|
906
924
|
`plural: 'entries'`. This is not used by Integreat right now, but it may be
|
|
907
925
|
used in the future for error messages, generating APIs from schemas, etc.
|
|
908
926
|
- `service`: You may specify a default service for the schema when it makes
|
|
909
|
-
sense. This allows you to dispatch an action for a type without specifying
|
|
910
|
-
target service, e.g. `{ type: 'GET', payload: { type: 'article' } }`,
|
|
911
|
-
Integreat use the default service. This is a way of hiding
|
|
912
|
-
details from the code dispatching the actions, and you may
|
|
913
|
-
default service without changing the dispatching code if
|
|
914
|
-
always override this by specifying a `service` on the
|
|
927
|
+
sense. This allows you to dispatch an action for a type without specifying
|
|
928
|
+
the target service, e.g. `{ type: 'GET', payload: { type: 'article' } }`,
|
|
929
|
+
and have Integreat use the default service. This is a way of hiding
|
|
930
|
+
configuration details from the code dispatching the actions, and you may
|
|
931
|
+
also change the default service without changing the dispatching code if
|
|
932
|
+
need be. You may always override this by specifying a `service` on the
|
|
933
|
+
action payload.
|
|
915
934
|
- `shape`: This is where you define all the fields, see
|
|
916
935
|
[the section below](#the-shape-of-a-schema).
|
|
917
936
|
- `generateId`: Set this to `true` to generate a unique id for the `id` field
|
|
@@ -922,15 +941,15 @@ automatically cast to that type.
|
|
|
922
941
|
of data cast to a schema will then be controlled by the rules you set here.
|
|
923
942
|
See [Access rules](#access-rules) below for details on these rules. Note that
|
|
924
943
|
`access` is optional, but when you get data from a service where any form of
|
|
925
|
-
authentication is used to access the data, you will not be able to do
|
|
926
|
-
with the data unless you cast it to a schema with `access` set up
|
|
927
|
-
specifically says that you allow raw data from that endpoint).
|
|
944
|
+
authentication is used to access the data, you will not be able to do
|
|
945
|
+
anything with the data unless you cast it to a schema with `access` set up
|
|
946
|
+
(or specifically says that you allow raw data from that endpoint).
|
|
928
947
|
|
|
929
948
|
### The shape of a schema
|
|
930
949
|
|
|
931
|
-
The shape is defined by an object where each key is the id of a field, which
|
|
932
|
-
contain only alphanumeric characters, and may not start with a digit. A
|
|
933
|
-
cannot have the same id as a primitive type (see list below).
|
|
950
|
+
The shape is defined by an object where each key is the id of a field, which
|
|
951
|
+
may contain only alphanumeric characters, and may not start with a digit. A
|
|
952
|
+
schema cannot have the same id as a primitive type (see list below).
|
|
934
953
|
|
|
935
954
|
The values on this object define the types of the fields and a few other
|
|
936
955
|
optional features:
|
|
@@ -957,9 +976,9 @@ function, the function will be run with no argument, and the returned value is
|
|
|
957
976
|
used as the default value. When no `default` is given, `undefined` is used.
|
|
958
977
|
|
|
959
978
|
The `const` value override any value you provide to the field. It may be useful
|
|
960
|
-
if you want a field to always have a fixed value. Just as for `default`, you
|
|
961
|
-
set it to a function, in which case the function will be run without
|
|
962
|
-
and the returned value will be used.
|
|
979
|
+
if you want a field to always have a fixed value. Just as for `default`, you
|
|
980
|
+
may set it to a function, in which case the function will be run without
|
|
981
|
+
arguments and the returned value will be used.
|
|
963
982
|
|
|
964
983
|
If both `const` and `default` are set, `const` will be used.
|
|
965
984
|
|
|
@@ -1013,9 +1032,9 @@ When data is cast to a schema, the data will be in the following format:
|
|
|
1013
1032
|
universally unique id will be generated for you.
|
|
1014
1033
|
- `$type`: Set to the id of the schema by Integreat. This is a signal that the
|
|
1015
1034
|
data has been cast.
|
|
1016
|
-
- `createdAt`: This is not mandatory, but has special meaning. When a schema
|
|
1017
|
-
a `createdAt` field, but the date is not set in the data, it will be set
|
|
1018
|
-
the same as `updatedAt` (if provided) or to the current date/time.
|
|
1035
|
+
- `createdAt`: This is not mandatory, but has special meaning. When a schema
|
|
1036
|
+
has a `createdAt` field, but the date is not set in the data, it will be set
|
|
1037
|
+
to the same as `updatedAt` (if provided) or to the current date/time.
|
|
1019
1038
|
- `updatedAt`: Just as `createdAt`, this is not mandatory. When a schema has
|
|
1020
1039
|
an `updatedAt` field, and the date is not set in the data, it will be set to
|
|
1021
1040
|
the same as `createdAt` (if provided) or the current date/time.
|
|
@@ -1025,8 +1044,8 @@ When data is cast to a schema, the data will be in the following format:
|
|
|
1025
1044
|
[the endpoint definition](#endpoints). When casting a value results in
|
|
1026
1045
|
`undefined`, it will not be included on the returned object. Fields that has
|
|
1027
1046
|
the `id` of other schemas as their type, will be objects. If only the id is
|
|
1028
|
-
provided in the data, the `{ id: <string>, $ref: <schema id> }` format will
|
|
1029
|
-
used, with `$ref` being the id of the field type schema. When more data is
|
|
1047
|
+
provided in the data, the `{ id: <string>, $ref: <schema id> }` format will
|
|
1048
|
+
be used, with `$ref` being the id of the field type schema. When more data is
|
|
1030
1049
|
provided, Integreat will cast it to the target schema and provide the entire
|
|
1031
1050
|
data object, or array of objects, with the relevant `$type`.
|
|
1032
1051
|
|
|
@@ -1035,10 +1054,11 @@ When data is cast to a schema, the data will be in the following format:
|
|
|
1035
1054
|
Set the `access` property on a schema to enforce permission checking. This
|
|
1036
1055
|
applies to any service that provides data in this schema.
|
|
1037
1056
|
|
|
1038
|
-
The simplest access rule is `auth`, which means that anyone can do anything
|
|
1039
|
-
the data of this schema, as long as they are authenticated. Being
|
|
1040
|
-
in this context, means that the dispatched action has an
|
|
1041
|
-
object. See [the section on idents](#idents) for more on
|
|
1057
|
+
The simplest access rule is `auth`, which means that anyone can do anything
|
|
1058
|
+
with the data of this schema, as long as they are authenticated. Being
|
|
1059
|
+
authenticated, in this context, means that the dispatched action has an
|
|
1060
|
+
`ident` in the `meta` object. See [the section on idents](#idents) for more on
|
|
1061
|
+
this.
|
|
1042
1062
|
|
|
1043
1063
|
Example of a schema with an access rule:
|
|
1044
1064
|
|
|
@@ -1073,16 +1093,16 @@ The following access rule props are available:
|
|
|
1073
1093
|
above, where we provided this string instead of a access rule object.
|
|
1074
1094
|
- `role`: Authorize only idents with this `role`. May also be an array.
|
|
1075
1095
|
- `ident`: Authorize only idents with this precise `id`. May also be an array.
|
|
1076
|
-
- `roleFromField`: Same as `role`, except the role is gotten from a field in
|
|
1077
|
-
schema. When authorizing data cast to this schema, the value of the role
|
|
1078
|
-
needs to be identical to (one of) the role(s) of the ident.
|
|
1096
|
+
- `roleFromField`: Same as `role`, except the role is gotten from a field in
|
|
1097
|
+
the schema. When authorizing data cast to this schema, the value of the role
|
|
1098
|
+
field needs to be identical to (one of) the role(s) of the ident.
|
|
1079
1099
|
- `identFromField` - The same as `roleFromField`, but for an ident id.
|
|
1080
1100
|
|
|
1081
|
-
In addition, you may override the general access rules of a schema with
|
|
1082
|
-
rules for a type of action, by setting an `action` object with access
|
|
1083
|
-
action types. Here's an example of an access definition for allowing
|
|
1084
|
-
authorized idents to `GET` data in a certain shema, requiring the role
|
|
1085
|
-
for `SET`s, and disallowing all other actions with the general rule
|
|
1101
|
+
In addition, you may override the general access rules of a schema with
|
|
1102
|
+
specific rules for a type of action, by setting an `action` object with access
|
|
1103
|
+
rules for action types. Here's an example of an access definition for allowing
|
|
1104
|
+
all authorized idents to `GET` data in a certain shema, requiring the role
|
|
1105
|
+
`admin` for `SET`s, and disallowing all other actions with the general rule
|
|
1086
1106
|
`allow: 'none'`:
|
|
1087
1107
|
|
|
1088
1108
|
```javascript
|
|
@@ -1102,12 +1122,12 @@ for `SET`s, and disallowing all other actions with the general rule
|
|
|
1102
1122
|
```
|
|
1103
1123
|
|
|
1104
1124
|
Note that these action specific rules only applies to actions being sent to a
|
|
1105
|
-
service. Some actions will never reach a service, but will instead trigger
|
|
1106
|
-
actions, and access will be granted or rejected only for the actions
|
|
1107
|
-
about to be sent to a service. E.g. when you dispatch a `SYNC`
|
|
1108
|
-
off by dispatching one or more `GET` actions. The `SYNC`
|
|
1109
|
-
to any access rules, but the `GET` actions are, and so
|
|
1110
|
-
one of the `GET` is rejected.
|
|
1125
|
+
service. Some actions will never reach a service, but will instead trigger
|
|
1126
|
+
other actions, and access will be granted or rejected only for the actions
|
|
1127
|
+
that are about to be sent to a service. E.g. when you dispatch a `SYNC`
|
|
1128
|
+
action, it starts off by dispatching one or more `GET` actions. The `SYNC`
|
|
1129
|
+
action is not subjected to any access rules, but the `GET` actions are, and so
|
|
1130
|
+
the `SYNC` will fail if one of the `GET` is rejected.
|
|
1111
1131
|
|
|
1112
1132
|
Another example, intended for authorizing only the ident matching a user:
|
|
1113
1133
|
|
|
@@ -1147,9 +1167,9 @@ An action looks like this:
|
|
|
1147
1167
|
that comes with Integreat, e.g. `GET`. When you dispatch an action, it is
|
|
1148
1168
|
handed off to this handler (after some inital preperation). You may write
|
|
1149
1169
|
your own action handlers as well.
|
|
1150
|
-
- `payload`: Holds parameters and [data](#typed-data) for this action. There
|
|
1151
|
-
some reserved [payload properties](#payload-properties), and the rest
|
|
1152
|
-
made available to you in the mutation pipeline.
|
|
1170
|
+
- `payload`: Holds parameters and [data](#typed-data) for this action. There
|
|
1171
|
+
are some reserved [payload properties](#payload-properties), and the rest
|
|
1172
|
+
will be made available to you in the mutation pipeline.
|
|
1153
1173
|
- `meta`: Holds information about the action that does not belong in the
|
|
1154
1174
|
payload, like the ident of the user dispatching, action id, etc. There are
|
|
1155
1175
|
some reserved [meta properties](#meta-properties), but you may add your own
|
|
@@ -1166,33 +1186,34 @@ Integreat will keep track of how many actions have been dispatched and are
|
|
|
1166
1186
|
currently being process. The Instance object (`great` in
|
|
1167
1187
|
[the example](#basic-example) at the beginning of this README) has a
|
|
1168
1188
|
`dispatchedCount` property that gives you the number dispatched actions waiting
|
|
1169
|
-
to be completed. Every time all dispatched are completed, a `done` event will
|
|
1170
|
-
emitted.
|
|
1189
|
+
to be completed. Every time all dispatched are completed, a `done` event will
|
|
1190
|
+
be emitted.
|
|
1171
1191
|
|
|
1172
1192
|
### Payload properties
|
|
1173
1193
|
|
|
1174
1194
|
The payload is, together with the action `type`, a description to Integreat and
|
|
1175
1195
|
the service of what to do. A design principle of Integreat has been to have as
|
|
1176
1196
|
little specifics in these payload, so actions may be discpatched to service
|
|
1177
|
-
without knowing how the service works. This is not always possible, at least
|
|
1178
|
-
yet, but it's a good principle to follow, also when you configure services
|
|
1179
|
-
plan what props need to be sent in the action payload.
|
|
1197
|
+
without knowing how the service works. This is not always possible, at least
|
|
1198
|
+
not yet, but it's a good principle to follow, also when you configure services
|
|
1199
|
+
and plan what props need to be sent in the action payload.
|
|
1180
1200
|
|
|
1181
1201
|
You may set any properties on the payload, and they will be be available to you
|
|
1182
|
-
in the service endpoint match and in the service mutations. Some properties
|
|
1183
|
-
special meanings, though, and you should avoid using them for anything
|
|
1202
|
+
in the service endpoint match and in the service mutations. Some properties
|
|
1203
|
+
have special meanings, though, and you should avoid using them for anything
|
|
1204
|
+
else:
|
|
1184
1205
|
|
|
1185
1206
|
- `type`: The type of the data the action sends and/or receives. This refers to
|
|
1186
1207
|
the `id` of a schema, and you will usually want to set this. Data provided
|
|
1187
1208
|
in the payload `data` and response `data` will be cast to this schema. If
|
|
1188
1209
|
you're dealing with several types in one action, you may set an array of
|
|
1189
|
-
types, but will have to cast the data in the mutation yourself. Integreat
|
|
1190
|
-
validate that the data you send and receive is indeed of that type, and
|
|
1191
|
-
give you an auth error if not. (See
|
|
1210
|
+
types, but will have to cast the data in the mutation yourself. Integreat
|
|
1211
|
+
will validate that the data you send and receive is indeed of that type, and
|
|
1212
|
+
will give you an auth error if not. (See
|
|
1192
1213
|
[`allowRawRequest` and `allowRawResponse` on endpoints](#endpoints) for an
|
|
1193
1214
|
exception.)
|
|
1194
|
-
- `id`: You provide an id when you want to address a specific data item,
|
|
1195
|
-
when you want to fetch one data item with an action like
|
|
1215
|
+
- `id`: You provide an id when you want to address a specific data item,
|
|
1216
|
+
usually when you want to fetch one data item with an action like
|
|
1196
1217
|
`{ type: 'GET', payload: { type: 'article', id: '12345' } }`. You may also
|
|
1197
1218
|
supply an array of ids to fetch several data items by id. When setting data,
|
|
1198
1219
|
the id will instead be specified in the `data` when appropriate.
|
|
@@ -1205,11 +1226,11 @@ special meanings, though, and you should avoid using them for anything else:
|
|
|
1205
1226
|
- `targetService`: An alias of `service`.
|
|
1206
1227
|
- `sourceService`: When data comes from a different service and has not been
|
|
1207
1228
|
mutated and cast yet, the `sourceService` property will tell Integreat to run
|
|
1208
|
-
the data through the source service configuration before passing the action
|
|
1209
|
-
to an action handler. An example may be data coming in through an API,
|
|
1210
|
-
the API is configured as a service in Integreat. Note that this
|
|
1211
|
-
usually set by transporters in their `listen()` methods, but you
|
|
1212
|
-
it directly on the action when it makes sense.
|
|
1229
|
+
the data through the source service configuration before passing the action
|
|
1230
|
+
on to an action handler. An example may be data coming in through an API,
|
|
1231
|
+
where the API is configured as a service in Integreat. Note that this
|
|
1232
|
+
property is usually set by transporters in their `listen()` methods, but you
|
|
1233
|
+
may also set it directly on the action when it makes sense.
|
|
1213
1234
|
- `endpoint`: Set this to the `id` of a service endpoint when you want to
|
|
1214
1235
|
override the endpoint match rules of Integreat. This should only be used when
|
|
1215
1236
|
it is really necessary. Normally, you should instead design the match
|
|
@@ -1228,13 +1249,13 @@ page at a time, the following properties may be supported:
|
|
|
1228
1249
|
of items specified in `pageSize`. If you ask for 500 items, the first action
|
|
1229
1250
|
should have `pageOffset: 0` (or not specified), the next action
|
|
1230
1251
|
`pageOffset: 500`, then `pageOffset: 1000`, and so on.
|
|
1231
|
-
- `page`: The index of the page to fetch. Unlike most other indexes, this
|
|
1232
|
-
with `1` being the first page. The effect is the same as
|
|
1233
|
-
just a different way of specifying it. `page: 1` is the
|
|
1234
|
-
`pageOffset: 0`, and `page: 2` is the same as `pageOffset: 500`,
|
|
1235
|
-
`pageSize: 500`. Integreat will actually calculate both before
|
|
1236
|
-
the transporter, as different types of services support
|
|
1237
|
-
pagination.
|
|
1252
|
+
- `page`: The index of the page to fetch. Unlike most other indexes, this
|
|
1253
|
+
starts with `1` being the first page. The effect is the same as
|
|
1254
|
+
`pageOffset`, it's just a different way of specifying it. `page: 1` is the
|
|
1255
|
+
same as `pageOffset: 0`, and `page: 2` is the same as `pageOffset: 500`,
|
|
1256
|
+
given a `pageSize: 500`. Integreat will actually calculate both before
|
|
1257
|
+
sending it to the transporter, as different types of services support
|
|
1258
|
+
different types of pagination.
|
|
1238
1259
|
- `pageAfter`: As an alternative to specifying the number of items to skip, you
|
|
1239
1260
|
may ask for the items after the item with the id you provide as `pageAfter`.
|
|
1240
1261
|
If the last item of the first page is `'12345'`, you may set
|
|
@@ -1251,12 +1272,12 @@ page at a time, the following properties may be supported:
|
|
|
1251
1272
|
> [!IMPORTANT]
|
|
1252
1273
|
> Pagination has to be supported by the service and your
|
|
1253
1274
|
> service configuration, and sometimes also the transporter. Integreat prepares
|
|
1254
|
-
> and passes on these pagination properties, but if the service disregards
|
|
1255
|
-
> there is little Integreat can do – except limiting the number of items
|
|
1275
|
+
> and passes on these pagination properties, but if the service disregards
|
|
1276
|
+
> them, there is little Integreat can do – except limiting the number of items
|
|
1256
1277
|
> returned. It's up to you to figure out how to configure pagination for a
|
|
1257
1278
|
> service, but youshould use these pagination properties to support it, to make
|
|
1258
|
-
> this predictable. It also lets you use actions such as `GET_ALL`, that
|
|
1259
|
-
> pagination.
|
|
1279
|
+
> this predictable. It also lets you use actions such as `GET_ALL`, that
|
|
1280
|
+
> support pagination.
|
|
1260
1281
|
|
|
1261
1282
|
Finally, there are some properties that has no special meaning to Integreat
|
|
1262
1283
|
itself, but that may be set on incoming actions from transporters. These should
|
|
@@ -1281,16 +1302,16 @@ ideally be used in the same way or avoided:
|
|
|
1281
1302
|
|
|
1282
1303
|
### Meta properties
|
|
1283
1304
|
|
|
1284
|
-
The action meta object is for information about an action that does not
|
|
1285
|
-
define the action itself. The difference may be subtle in some cases,
|
|
1286
|
-
general rule is a piece of information affects how the action is run,
|
|
1287
|
-
be in the payload. E.g. the type of items to fetch is in the
|
|
1288
|
-
time the action was dispatched would go in the meta.
|
|
1305
|
+
The action meta object is for information about an action that does not
|
|
1306
|
+
directly define the action itself. The difference may be subtle in some cases,
|
|
1307
|
+
but the general rule is a piece of information affects how the action is run,
|
|
1308
|
+
it should be in the payload. E.g. the type of items to fetch is in the
|
|
1309
|
+
payload, while the time the action was dispatched would go in the meta.
|
|
1289
1310
|
|
|
1290
|
-
This rule does not always hold, e.g. for information on the user dispatching
|
|
1291
|
-
action in `ident` on the meta object. Different idents may result in
|
|
1292
|
-
data being returned from the service, but still the action to
|
|
1293
|
-
same, so it makes sense to have the ident in the meta object.
|
|
1311
|
+
This rule does not always hold, e.g. for information on the user dispatching
|
|
1312
|
+
the action in `ident` on the meta object. Different idents may result in
|
|
1313
|
+
different data being returned from the service, but still the action to
|
|
1314
|
+
perform is the same, so it makes sense to have the ident in the meta object.
|
|
1294
1315
|
|
|
1295
1316
|
You may set your own meta properties, but in most cases you'll probably rather
|
|
1296
1317
|
set payload properties.
|
|
@@ -1303,29 +1324,38 @@ Current meta properties reserved by Integreat:
|
|
|
1303
1324
|
- `id`: The id of the action itself. You may set this yourself or let Integreat
|
|
1304
1325
|
generate a universally unique id for you. Useful for logging and may be used
|
|
1305
1326
|
by queues.
|
|
1306
|
-
- `cid`:
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
will
|
|
1327
|
+
- `cid`: Correlation id. When dispatching an action without `meta.cid`,
|
|
1328
|
+
Integreat will set it to the same as the `meta.id`. All actions that are then
|
|
1329
|
+
dispatched as a consequence of that action (e.g. a `SYNC` or `GET_META`),
|
|
1330
|
+
will have the same `cid`. The `cid` may then be used to group actions
|
|
1331
|
+
belonging together, e.g. when displaying logs. The dispatching code set the
|
|
1332
|
+
`cid` on an action, e.g. to correlate an action and the actions it
|
|
1333
|
+
dispatches, with other operations outside Integreat.
|
|
1334
|
+
- `gid`: Group id. This has some of the same purpose as `cid`, as it may be
|
|
1335
|
+
used to group actions that belong together, but `gid` is not always set, and
|
|
1336
|
+
will be used for smaller groups of actions than `cid`. Right now, `RUN`,
|
|
1337
|
+
`SYNC`, and `GET_ALL` will use the `id` of the original action as `gid` for
|
|
1338
|
+
all actions they dispatched.
|
|
1310
1339
|
- `dispatchedAt`: Timestamp for when the action was dispatched (set by
|
|
1311
1340
|
Integreat).
|
|
1312
|
-
- `queue`: Signals to Integreat that an action may be queued. Set to `true`
|
|
1313
|
-
you want the action to be queued, but executed as soon as possible. Set
|
|
1314
|
-
UNIX timestamp (number) to schedule for a later time. If no queue is
|
|
1315
|
-
the action will be dispatched right away. More on this under
|
|
1341
|
+
- `queue`: Signals to Integreat that an action may be queued. Set to `true`
|
|
1342
|
+
when you want the action to be queued, but executed as soon as possible. Set
|
|
1343
|
+
to a UNIX timestamp (number) to schedule for a later time. If no queue is
|
|
1344
|
+
set up, the action will be dispatched right away. More on this under
|
|
1316
1345
|
[the section on queues](#queues).
|
|
1317
1346
|
- `queuedAt`: Timestamp for when the action was pushed to the queue (set by
|
|
1318
1347
|
Integreat).
|
|
1319
1348
|
- `options`: Used for passing the processed service endpoint options object to
|
|
1320
1349
|
a transporter. The `options` object is available through mutations, so that
|
|
1321
|
-
you may modify it futher before it goes to the transporter. Note that only
|
|
1322
|
-
transporter options are provided here, not the adapter options.
|
|
1350
|
+
you may modify it futher before it goes to the transporter. Note that only
|
|
1351
|
+
the transporter options are provided here, not the adapter options.
|
|
1323
1352
|
- `authorized`: An internal flag signaling that the action has been authorized.
|
|
1324
1353
|
Will be removed from any dispatched actions.
|
|
1325
1354
|
|
|
1326
1355
|
### Action response
|
|
1327
1356
|
|
|
1328
|
-
When you dispatch an action, you will get a response object back in this
|
|
1357
|
+
When you dispatch an action, you will get a response object back in this
|
|
1358
|
+
format:
|
|
1329
1359
|
|
|
1330
1360
|
```javascript
|
|
1331
1361
|
{
|
|
@@ -1359,16 +1389,17 @@ When you dispatch an action, you will get a response object back in this format:
|
|
|
1359
1389
|
this property will hold a code for where the error originated. The goal is to
|
|
1360
1390
|
set it as close to the actual origin as possible. See
|
|
1361
1391
|
[list of origin codes](#origin-codes) below.
|
|
1362
|
-
- `access`: An object holding the `ident` that was actually being used. This
|
|
1363
|
-
be different than the `meta.ident` on the action, as the ident may also
|
|
1364
|
-
mutated or completed with roles etc. along the way.
|
|
1392
|
+
- `access`: An object holding the `ident` that was actually being used. This
|
|
1393
|
+
may be different than the `meta.ident` on the action, as the ident may also
|
|
1394
|
+
be mutated or completed with roles etc. along the way.
|
|
1365
1395
|
- `paging`: For services and transporters that support
|
|
1366
1396
|
[pagination](#pagination), this object will hold information about how to get
|
|
1367
1397
|
the next or previous page, in a `next` or `prev` object. These objects are
|
|
1368
|
-
essentially the payloads you need to dispatch (with the same action `type`
|
|
1369
|
-
meta), to get the next or previous page. If there is no next or previous
|
|
1370
|
-
the corresponding prop will not be set on the `paging` object. When
|
|
1371
|
-
is not relevant or used, the `paging` object may be missing
|
|
1398
|
+
essentially the payloads you need to dispatch (with the same action `type`
|
|
1399
|
+
and meta), to get the next or previous page. If there is no next or previous
|
|
1400
|
+
page, the corresponding prop will not be set on the `paging` object. When
|
|
1401
|
+
pagination is not relevant or used, the `paging` object may be missing
|
|
1402
|
+
completely.
|
|
1372
1403
|
- `params`: Integreat never sets this, but you may set it in your mutations to
|
|
1373
1404
|
provide parameters from a service that does not belong in the `data`.
|
|
1374
1405
|
- `headers`: Integreat never sets this, but you may set it in your mutations to
|
|
@@ -1387,8 +1418,8 @@ the same as `action.meta.id`.
|
|
|
1387
1418
|
|
|
1388
1419
|
### Status codes
|
|
1389
1420
|
|
|
1390
|
-
The `status` property on the action response will be one of the following
|
|
1391
|
-
codes:
|
|
1421
|
+
The `status` property on the action response will be one of the following
|
|
1422
|
+
status codes:
|
|
1392
1423
|
|
|
1393
1424
|
- `ok`: Everything is well, data is returned as expected
|
|
1394
1425
|
- `queued`: The action has been queued. This is regarded as a success status
|
|
@@ -1396,6 +1427,8 @@ codes:
|
|
|
1396
1427
|
sync
|
|
1397
1428
|
- `notfound`: Tried to get or modify a resource that does not exist
|
|
1398
1429
|
- `timeout`: The attempt to perform the action timed out
|
|
1430
|
+
- `toomany`: Too many actions/requests were sent. This is normally used for
|
|
1431
|
+
rate limiting errors from a service.
|
|
1399
1432
|
- `autherror`: An authentication request failed
|
|
1400
1433
|
- `noaccess`: Authentication is required or the provided auth is not enough
|
|
1401
1434
|
- `badrequest`: Request data is not as expected
|
|
@@ -1404,8 +1437,8 @@ codes:
|
|
|
1404
1437
|
|
|
1405
1438
|
### Origin codes
|
|
1406
1439
|
|
|
1407
|
-
The `origin` property is not exclusively defined, but these are some of the
|
|
1408
|
-
common codes:
|
|
1440
|
+
The `origin` property is not exclusively defined, but these are some of the
|
|
1441
|
+
more common codes:
|
|
1409
1442
|
|
|
1410
1443
|
- `service:<service id>`: The error originated in service. There may also be
|
|
1411
1444
|
third level of detail here, if the service sets an origin code of its own.
|
|
@@ -1425,9 +1458,9 @@ common codes:
|
|
|
1425
1458
|
- `auth:service:<service id>:<authenticator id>`: The error occured while
|
|
1426
1459
|
attempting to authorize the service with the given id, through the given
|
|
1427
1460
|
authenticator.
|
|
1428
|
-
- `handler:<handler id>`: The error occurred with the handler with the given
|
|
1429
|
-
e.g. `'handler:GET'`. This means the error did happen in the service or
|
|
1430
|
-
mutation pipelines, but in the internal workings of then handler.
|
|
1461
|
+
- `handler:<handler id>`: The error occurred with the handler with the given
|
|
1462
|
+
id, e.g. `'handler:GET'`. This means the error did happen in the service or
|
|
1463
|
+
the mutation pipelines, but in the internal workings of then handler.
|
|
1431
1464
|
- `validate:service:<service id>:endpoint:<endpoint id>`: Validation of an
|
|
1432
1465
|
action against an endpoint failed. Note that not all endpoints has an id, in
|
|
1433
1466
|
which case that part of the origin code is left out.
|
|
@@ -1453,26 +1486,26 @@ Example ident:
|
|
|
1453
1486
|
}
|
|
1454
1487
|
```
|
|
1455
1488
|
|
|
1456
|
-
- `id`: A unique string identifying the ident. The actual value is irrelevant
|
|
1457
|
-
Integreat, as long as it is a string with A-Z, a-z, 0-9, \_, and -, and
|
|
1458
|
-
unique within one Integreat configuration. This means that mapped
|
|
1459
|
-
services may be used as ident ids, as long as they are unique
|
|
1460
|
-
services.
|
|
1461
|
-
- `tokens`: A list of values that may identify this ident in other services.
|
|
1462
|
-
example, an api that uses GitHub OAuth to identify its users, may provide
|
|
1489
|
+
- `id`: A unique string identifying the ident. The actual value is irrelevant
|
|
1490
|
+
to Integreat, as long as it is a string with A-Z, a-z, 0-9, \_, and -, and
|
|
1491
|
+
it's unique within one Integreat configuration. This means that mapped
|
|
1492
|
+
values from services may be used as ident ids, as long as they are unique
|
|
1493
|
+
among these services.
|
|
1494
|
+
- `tokens`: A list of values that may identify this ident in other services.
|
|
1495
|
+
For example, an api that uses GitHub OAuth to identify its users, may provide
|
|
1463
1496
|
the `'github|23456'` token in the example above, which will be replaced with
|
|
1464
1497
|
this ident when it enters Integreat.
|
|
1465
1498
|
- `roles`: A list of roles or permissions given to this ident. The roles are
|
|
1466
1499
|
custom defined per setup, and may be mapped to roles from other systems. When
|
|
1467
|
-
setting the auth rules for a schema, you specify required rules so that to
|
|
1468
|
-
data cast in this schema, an ident with e.g. the role `admin` must be
|
|
1500
|
+
setting the auth rules for a schema, you specify required rules so that to
|
|
1501
|
+
get data cast in this schema, an ident with e.g. the role `admin` must be
|
|
1469
1502
|
provided.
|
|
1470
1503
|
- `type`: An optional string to signal when this ident is `'ROOT'`, `'SCHED'`,
|
|
1471
|
-
or `'ANON'`. This is used internally by Integreat, but in some
|
|
1472
|
-
want to set this yourself. Make sure, however, that you don't
|
|
1473
|
-
third-parties set `'ROOT'`. Make sure to also set the id, typically to
|
|
1474
|
-
`'root'` or `'anonymous'`. Not setting any `type` is the same as setting it
|
|
1475
|
-
`'CUST'`, which is the default.
|
|
1504
|
+
`'SYST'`, or `'ANON'`. This is used internally by Integreat, but in some
|
|
1505
|
+
cases you may want to set this yourself. Make sure, however, that you don't
|
|
1506
|
+
let third-parties set `'ROOT'`. Make sure to also set the id, typically to
|
|
1507
|
+
`'root'` or `'anonymous'`. Not setting any `type` is the same as setting it
|
|
1508
|
+
to `'CUST'`, which is the default.
|
|
1476
1509
|
- `isCompleted`: A flag to signal that an ident has already been completed, so
|
|
1477
1510
|
that it won't be completed again. Used by the `completeIdent` middleware. You
|
|
1478
1511
|
should normally not need to set this yourself.
|
|
@@ -1481,10 +1514,10 @@ The ident may also hold other custom properties, defined in the
|
|
|
1481
1514
|
`identConfig.mapping` in the definitions passed when created a new Integreat
|
|
1482
1515
|
instance. See description under [Idents](#idents).
|
|
1483
1516
|
|
|
1484
|
-
Actions are authenticated by setting an ident on the `meta.ident` property.
|
|
1485
|
-
up to the code dispatching an action to get hold of the properties of an
|
|
1486
|
-
in a secure way. Once Integreat receives an ident through a dispatch, it
|
|
1487
|
-
assume this is accurate information and uphold its part of the security
|
|
1517
|
+
Actions are authenticated by setting an ident on the `meta.ident` property.
|
|
1518
|
+
It's up to the code dispatching an action to get hold of the properties of an
|
|
1519
|
+
ident in a secure way. Once Integreat receives an ident through a dispatch, it
|
|
1520
|
+
will assume this is accurate information and uphold its part of the security
|
|
1488
1521
|
agreement and only return data and execute actions that the ident have
|
|
1489
1522
|
permissions for.
|
|
1490
1523
|
|
|
@@ -1519,12 +1552,13 @@ is fetched, if it exists:
|
|
|
1519
1552
|
}
|
|
1520
1553
|
```
|
|
1521
1554
|
|
|
1522
|
-
See [the section on payload properties](#payload-properties) for more
|
|
1523
|
-
that may be used with the `GET` action.
|
|
1555
|
+
See [the section on payload properties](#payload-properties) for more
|
|
1556
|
+
properties that may be used with the `GET` action.
|
|
1524
1557
|
|
|
1525
1558
|
#### `GET_ALL`
|
|
1526
1559
|
|
|
1527
|
-
Will run as many `GET` actions as needed to the get all available pages of
|
|
1560
|
+
Will run as many `GET` actions as needed to the get all available pages of
|
|
1561
|
+
data.
|
|
1528
1562
|
|
|
1529
1563
|
The action ...
|
|
1530
1564
|
|
|
@@ -1598,21 +1632,22 @@ Note that the actual behavior is up to how you set up the service and what the
|
|
|
1598
1632
|
service itself supports, but the `UPDATE` action will provide you with a way of
|
|
1599
1633
|
doing this.
|
|
1600
1634
|
|
|
1601
|
-
An `UPDATE` action may be handled in one of two ways, where the first is just
|
|
1602
|
-
run it against a service endpoint, much like a `SET` action (except it will
|
|
1635
|
+
An `UPDATE` action may be handled in one of two ways, where the first is just
|
|
1636
|
+
to run it against a service endpoint, much like a `SET` action (except it will
|
|
1603
1637
|
match different endpoints). Data provided in the payload `data` is mutated and
|
|
1604
|
-
sent to the service according to the endpoint configuration, and any data
|
|
1605
|
-
back, will be provided on `response.data` and mutated.
|
|
1638
|
+
sent to the service according to the endpoint configuration, and any data
|
|
1639
|
+
coming back, will be provided on `response.data` and mutated.
|
|
1606
1640
|
|
|
1607
1641
|
What makes `UPDATE` different from `SET`, though, is the second way we may
|
|
1608
1642
|
handle `UPDATE` actions. Whenever there is no maching `UPDATE` endpoint,
|
|
1609
|
-
Integreat will run the action as a `GET` and then a `SET`, to mimick and
|
|
1610
|
-
The `GET` action will have the same `payload` and `meta` as the
|
|
1611
|
-
The same goes for the `SET` action, but the `payload.data`
|
|
1612
|
-
returned from `GET` merged with the data on the original
|
|
1613
|
-
will be a deep merge, prioritizing properties from the
|
|
1614
|
-
`createdAt` date in the data from `GET` will be kept.
|
|
1615
|
-
in the merged data, it will be overriden by the
|
|
1643
|
+
Integreat will run the action as a `GET` and then a `SET`, to mimick and
|
|
1644
|
+
update. The `GET` action will have the same `payload` and `meta` as the
|
|
1645
|
+
original action. The same goes for the `SET` action, but the `payload.data`
|
|
1646
|
+
will be the data returned from `GET` merged with the data on the original
|
|
1647
|
+
`UPDATE` action. This will be a deep merge, prioritizing properties from the
|
|
1648
|
+
`UPDATE` action, but any `createdAt` date in the data from `GET` will be kept.
|
|
1649
|
+
If there's an `updatedAt` in the merged data, it will be overriden by the
|
|
1650
|
+
current time.
|
|
1616
1651
|
|
|
1617
1652
|
A requirement for this approach to work as expected, is that the data is casted
|
|
1618
1653
|
to the same schema, but that should normally be the case when you use
|
|
@@ -1679,7 +1714,8 @@ You may also `DELETE` one item like this:
|
|
|
1679
1714
|
#### `GET_META`
|
|
1680
1715
|
|
|
1681
1716
|
Get metadata for a service. See
|
|
1682
|
-
[the section on metadata](#configuring-service-metadata) for how to set this
|
|
1717
|
+
[the section on metadata](#configuring-service-metadata) for how to set this
|
|
1718
|
+
up.
|
|
1683
1719
|
|
|
1684
1720
|
The `data` of the response from this aciton contains the `service` (the service
|
|
1685
1721
|
id) and `meta` object with the metadata set as properties.
|
|
@@ -1767,8 +1803,8 @@ See [the section on jobs](#jobs) for more on how to configure jobs.
|
|
|
1767
1803
|
|
|
1768
1804
|
The `SYNC` action will `GET` items from one service and `SET` them on another.
|
|
1769
1805
|
There are different options for how to retrieve items, ranging from a crude
|
|
1770
|
-
retrieval of all items on every sync, to a more fine grained approach where
|
|
1771
|
-
items that have been updated or created since last sync, will be synced.
|
|
1806
|
+
retrieval of all items on every sync, to a more fine grained approach where
|
|
1807
|
+
only items that have been updated or created since last sync, will be synced.
|
|
1772
1808
|
|
|
1773
1809
|
The simplest action definition would look like this, where all items would be
|
|
1774
1810
|
retrieved from the service and set on the target:
|
|
@@ -1793,24 +1829,24 @@ configured.
|
|
|
1793
1829
|
To retrieve only new items, change the `retrieve` property to `updated`. In
|
|
1794
1830
|
this case, the action will dispatch `GET_META` to get the `lastSyncedAt` from
|
|
1795
1831
|
the `from` service, and get only newer items, by passing it the `updatedAfter`
|
|
1796
|
-
param. The action will also filter out older items, in case the service does
|
|
1797
|
-
support `updatedAfter`.
|
|
1832
|
+
param. The action will also filter out older items, in case the service does
|
|
1833
|
+
not support `updatedAfter`.
|
|
1798
1834
|
|
|
1799
1835
|
By setting `retrieve` to `created`, you accomplish the same, but with
|
|
1800
1836
|
`createdAfter`.
|
|
1801
1837
|
|
|
1802
|
-
If you need to include more params in the actions to get from the `from`
|
|
1803
|
-
or set to the `to` service, you may provide a params object for the
|
|
1804
|
-
`to` props, with the service id set as a `service` param. You may
|
|
1805
|
-
different action types than `GET` and `SET`, by setting the
|
|
1806
|
-
the `from` or `to` objects respectively.
|
|
1838
|
+
If you need to include more params in the actions to get from the `from`
|
|
1839
|
+
service or set to the `to` service, you may provide a params object for the
|
|
1840
|
+
`from` or `to` props, with the service id set as a `service` param. You may
|
|
1841
|
+
also provide different action types than `GET` and `SET`, by setting the
|
|
1842
|
+
`action` prop on the `from` or `to` objects respectively.
|
|
1807
1843
|
|
|
1808
1844
|
By default, `SYNC` will send every item gotten from the `from` service to the
|
|
1809
1845
|
`to` service. You can split an array of items into several sets, by setting the
|
|
1810
|
-
`maxPerSet` on the payload object, to a max number of items per set. If you
|
|
1811
|
-
to have one set per individual item, you may set `setMember` to `true` on
|
|
1812
|
-
payload object. (This is almost the same as setting `maxPerSet` to `1`,
|
|
1813
|
-
it won't be wrapped in an array.)
|
|
1846
|
+
`maxPerSet` on the payload object, to a max number of items per set. If you
|
|
1847
|
+
need to have one set per individual item, you may set `setMember` to `true` on
|
|
1848
|
+
the payload object. (This is almost the same as setting `maxPerSet` to `1`,
|
|
1849
|
+
except it won't be wrapped in an array.)
|
|
1814
1850
|
|
|
1815
1851
|
> [!NOTE]
|
|
1816
1852
|
> There are more options than these, and the documentation will be updated to
|
|
@@ -1853,21 +1889,22 @@ Here's an example of an `EXPIRE` action that will dispatch a `DELETE` directly:
|
|
|
1853
1889
|
}
|
|
1854
1890
|
```
|
|
1855
1891
|
|
|
1856
|
-
The `GET` action (or the `DELETE` action when `deleteWithParams` is `true`)
|
|
1857
|
-
have a `timestamp` property with the current time as microseconds since
|
|
1858
|
-
(Januar 1, 1970 UTC), and `isodate` as the current time in the extended
|
|
1859
|
-
format(`YYYY-MM-DDThh:mm:ss.sssZ`).
|
|
1892
|
+
The `GET` action (or the `DELETE` action when `deleteWithParams` is `true`)
|
|
1893
|
+
will have a `timestamp` property with the current time as microseconds since
|
|
1894
|
+
epoc (Januar 1, 1970 UTC), and `isodate` as the current time in the extended
|
|
1895
|
+
ISO 8601 format(`YYYY-MM-DDThh:mm:ss.sssZ`).
|
|
1860
1896
|
|
|
1861
1897
|
To have `timestamp` and `isodate` be a time in the future instead, set
|
|
1862
1898
|
`msFromNow` to a positive number of milliseconds. This will be added to the
|
|
1863
|
-
current time. To have a time in the past, use a negative number for
|
|
1899
|
+
current time. To have a time in the past, use a negative number for
|
|
1900
|
+
`msFromNow`.
|
|
1864
1901
|
|
|
1865
1902
|
#### `SERVICE`
|
|
1866
1903
|
|
|
1867
1904
|
A `SERVICE` action will be sent directly to the specified service without any
|
|
1868
1905
|
intervention by Integreat. This allows for running specialized actions on the
|
|
1869
|
-
service that goes beyond what Integreat supports. It's up to each transporter
|
|
1870
|
-
support such actions, describe what they'll do, and define their payload
|
|
1906
|
+
service that goes beyond what Integreat supports. It's up to each transporter
|
|
1907
|
+
to support such actions, describe what they'll do, and define their payload
|
|
1871
1908
|
properties.
|
|
1872
1909
|
|
|
1873
1910
|
An example of an action that will tell a
|
|
@@ -1898,26 +1935,27 @@ async function (action, { dispatch, getService, setProgress, options }) { ... }
|
|
|
1898
1935
|
|
|
1899
1936
|
- `action`: This is the dispatched action after it has been modified a bit
|
|
1900
1937
|
by the `dispatch()` method and possible after running an incoming mutation on
|
|
1901
|
-
it. The modifications include cleaning up alias fields (e.g. `service` will
|
|
1902
|
-
set as `targetService`), removing sensitive or forbidden fields, and
|
|
1903
|
-
few default or internal fields (like the `dispatchedAt` meta).
|
|
1938
|
+
it. The modifications include cleaning up alias fields (e.g. `service` will
|
|
1939
|
+
be set as `targetService`), removing sensitive or forbidden fields, and
|
|
1940
|
+
setting a few default or internal fields (like the `dispatchedAt` meta).
|
|
1904
1941
|
- `dispatch`: From the handler, you may dispatch your own sub actions to the
|
|
1905
|
-
provided `dispatch()` method. Note that this is an "internal dispatch
|
|
1906
|
-
so it will return an action with the `response` object on it,
|
|
1907
|
-
the `response` object. It's good practice to set the `cid`
|
|
1908
|
-
actions you dispatch, to the `cid` meta prop on the
|
|
1909
|
-
You should also use the same `ident` unless you
|
|
1910
|
-
otherwise, to make sure you don't create
|
|
1942
|
+
provided `dispatch()` method. Note that this is an "internal dispatch
|
|
1943
|
+
method", so it will return an action with the `response` object on it,
|
|
1944
|
+
instead of just the `response` object. It's good practice to set the `cid`
|
|
1945
|
+
meta prop for the actions you dispatch, to the `cid` meta prop on the
|
|
1946
|
+
`action` you're handling. You should also use the same `ident` unless you
|
|
1947
|
+
have very good reasons to do otherwise, to make sure you don't create
|
|
1948
|
+
security holes.
|
|
1911
1949
|
- `getService`: This is a convenience method that will return the relevant
|
|
1912
|
-
service object when you provide it with a type and optional a service id.
|
|
1913
|
-
a service id, you'll get the service with that id, with only the type,
|
|
1914
|
-
get the default service for that type. E.g.: `getService('article')`.
|
|
1950
|
+
service object when you provide it with a type and optional a service id.
|
|
1951
|
+
With a service id, you'll get the service with that id, with only the type,
|
|
1952
|
+
you'll get the default service for that type. E.g.: `getService('article')`.
|
|
1915
1953
|
- `setProgress`: For long running tasks, you may want to set the progress along
|
|
1916
1954
|
the way. Progress is specified as a number between `0` and `1`, e.g.
|
|
1917
|
-
`setProgress(.5)` to signal that you're halfway through. When the your
|
|
1918
|
-
is finished, the progress will automatically be set to `1`. This may
|
|
1919
|
-
by queue implementations etc., to give progress feedback to users
|
|
1920
|
-
the action has not gone stale.
|
|
1955
|
+
`setProgress(.5)` to signal that you're halfway through. When the your
|
|
1956
|
+
handler is finished, the progress will automatically be set to `1`. This may
|
|
1957
|
+
be used by queue implementations etc., to give progress feedback to users
|
|
1958
|
+
and to know the action has not gone stale.
|
|
1921
1959
|
- `options`: This is an object with a few settings: `queueService` is the id of
|
|
1922
1960
|
the service set up as the default queue, and `identConfig` is the config
|
|
1923
1961
|
object used for mapping ident schemas to ids, roles, and tokens (see
|
|
@@ -2021,11 +2059,11 @@ const flowJob = {
|
|
|
2021
2059
|
```
|
|
2022
2060
|
|
|
2023
2061
|
Several things are going on here: First, we have a flow with two actions. We
|
|
2024
|
-
imagine here that we are going to fetch an entry with an id that is found in
|
|
2025
|
-
`store` service, and use the `otherId` retrieved from that service to get
|
|
2026
|
-
entry from `otherService`. The two steps in `flow` look a lot like a job,
|
|
2027
|
-
in one way they are the same, with some differences, that we will get back
|
|
2028
|
-
They are run sequentally in the order they appear in the `flow` array.
|
|
2062
|
+
imagine here that we are going to fetch an entry with an id that is found in
|
|
2063
|
+
the `store` service, and use the `otherId` retrieved from that service to get
|
|
2064
|
+
the entry from `otherService`. The two steps in `flow` look a lot like a job,
|
|
2065
|
+
and in one way they are the same, with some differences, that we will get back
|
|
2066
|
+
to. They are run sequentally in the order they appear in the `flow` array.
|
|
2029
2067
|
|
|
2030
2068
|
Secondly, we have a `premutation` on each step. This is given the `action` and
|
|
2031
2069
|
may mutate it before it is dispatched. As for endpoint mutations, the top level
|
|
@@ -2033,21 +2071,21 @@ has `$modify: true` as default, but we need to modify the sub-objects we
|
|
|
2033
2071
|
include, when that is what we want. In the first step, we set the payload `id`
|
|
2034
2072
|
to the `id` provided in the action that called this job. This job is passed to
|
|
2035
2073
|
mutations on jobs and steps under the name `'action'`, and we prepend it with
|
|
2036
|
-
the root path (`^^`) as it is found on the top level of the data structure
|
|
2037
|
-
mutating.
|
|
2074
|
+
the root path (`^^`) as it is found on the top level of the data structure
|
|
2075
|
+
we're mutating.
|
|
2038
2076
|
|
|
2039
2077
|
The second step is similar, but here we set the payload `id` to the `otherId`
|
|
2040
|
-
found in the response data of the first step. The action and the response from
|
|
2041
|
-
step is available to all following steps by the id of the step, in this case
|
|
2078
|
+
found in the response data of the first step. The action and the response from
|
|
2079
|
+
a step is available to all following steps by the id of the step, in this case
|
|
2042
2080
|
`'getFromStore'`. We have to prepend with the root path (`^^`) here as well.
|
|
2043
|
-
When we say the action and response is available, we find it as an action
|
|
2044
|
-
with any response on a `response` property.
|
|
2081
|
+
When we say the action and response is available, we find it as an action
|
|
2082
|
+
object with any response on a `response` property.
|
|
2045
2083
|
|
|
2046
2084
|
With the action
|
|
2047
2085
|
`{ type: 'RUN', payload: { jobId: 'getEntryFromOtherService', id: '12345' } }`,
|
|
2048
2086
|
the first step will dispatch a `GET` for the id `12345`. If that action
|
|
2049
|
-
succeeds with the data `{ id: '12345', otherId: '67890' }`, the second step
|
|
2050
|
-
dispatch a `GET` for the id `67890`. The response from the last action is
|
|
2087
|
+
succeeds with the data `{ id: '12345', otherId: '67890' }`, the second step
|
|
2088
|
+
will dispatch a `GET` for the id `67890`. The response from the last action is
|
|
2051
2089
|
returned by default.
|
|
2052
2090
|
|
|
2053
2091
|
If any job step fails, the entire job will fail and the error will be returned,
|
|
@@ -2078,76 +2116,101 @@ For both pipelines, an action object is expected, and in the case of
|
|
|
2078
2116
|
`postmutation` the action should have a `response` object which is what will be
|
|
2079
2117
|
used as the response from the job or step.
|
|
2080
2118
|
|
|
2081
|
-
###
|
|
2119
|
+
### Job and step conditions
|
|
2082
2120
|
|
|
2083
|
-
By default, if a step in a flow fails, no more steps are run, and the entire
|
|
2084
|
-
will fail with the response from the failed step. You may however
|
|
2085
|
-
own conditions for when a step should be run and when a step
|
|
2086
|
-
as having failed.
|
|
2121
|
+
By default, if a step in a flow fails, no more steps are run, and the entire
|
|
2122
|
+
job will fail with the response from the failed step. You may, however,
|
|
2123
|
+
provide your own conditions for when a step should be run and when a step
|
|
2124
|
+
should be regarded as having failed.
|
|
2087
2125
|
|
|
2088
|
-
`preconditions`
|
|
2089
|
-
pass in order for the step to be run.
|
|
2090
|
-
property with an array of mutation pipelines,
|
|
2091
|
-
the condition to be regarded as passed. Each
|
|
2092
|
-
|
|
2093
|
-
without the action
|
|
2126
|
+
`preconditions` may be set to an array of condition objects, that must all
|
|
2127
|
+
pass in order for the step to be run. Each condition object must have a
|
|
2128
|
+
`condition` property with an array of mutation pipelines, and all these
|
|
2129
|
+
pipelines must return truthy for the condition to be regarded as passed. Each
|
|
2130
|
+
pipeline is given the same object that is given to `premutation` with action
|
|
2131
|
+
and responses from previous steps, but without the action for this step. See
|
|
2094
2132
|
[the section on mutating jobs](#job-and-step-mutations) for more on this.
|
|
2095
2133
|
|
|
2096
2134
|
The condition object may also have a `failResponse` property with a response
|
|
2097
2135
|
object that will be used as the response from the step if the condition fails.
|
|
2098
2136
|
|
|
2099
2137
|
Finally, the `condition` object may have a `break` property set to `true`, to
|
|
2100
|
-
signal that the entire job should fail if the condition fails. If `break` is
|
|
2101
|
-
set, the step will just be skipped and the job flow continues.
|
|
2138
|
+
signal that the entire job should fail if the condition fails. If `break` is
|
|
2139
|
+
not set, the step will just be skipped and the job flow continues.
|
|
2102
2140
|
|
|
2103
2141
|
> [!NOTE]
|
|
2104
|
-
>
|
|
2105
|
-
>
|
|
2106
|
-
>
|
|
2107
|
-
>
|
|
2108
|
-
>
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
the flow if the previous step failed. By specifying your own `preconditions`,
|
|
2112
|
-
you override this, and only your conditions will be used. But when you set
|
|
2113
|
-
`breakByDefault` to `true` (see note above), this default condition will be
|
|
2114
|
-
set in the `postconditions` instead, so that you may override it there. This
|
|
2115
|
-
way, you may set pre-conditions on a step, whithout overriding the fail-on-error
|
|
2116
|
-
behavior of the step before.
|
|
2142
|
+
> The default behavior of breaking when a step returns an error, is implemented
|
|
2143
|
+
> as a default pre-condition, so if you set your own `preconditions`, you
|
|
2144
|
+
> will also have to handle breaking on error.
|
|
2145
|
+
>
|
|
2146
|
+
> This is not very intuitive, so we have introduced a
|
|
2147
|
+
> `failOnErrorInPostconditions` flag that will change this to what will be the
|
|
2148
|
+
> default in the next major version. [See more below.](#conditions-and-the-failOnErrorInPostconditions-flag)
|
|
2117
2149
|
|
|
2118
2150
|
`postconditions` is also an array of condition objects, but this is used to
|
|
2119
2151
|
decide if the step should be regarded as having failed after its action or flow
|
|
2120
2152
|
has run. The condition pipelines are passed the same object as `postmutation`,
|
|
2121
2153
|
but _after_ `postmutation` has been applied. Just as for `preconditions`, the
|
|
2122
2154
|
`break` property is `false` by default, so to stop the entire job, set it to
|
|
2123
|
-
`true
|
|
2124
|
-
|
|
2125
|
-
|
|
2155
|
+
`true`. An error will usually cause the job to fail even with `break: false`,
|
|
2156
|
+
but the breaking may be handled by the `preconditions` on the next step, as
|
|
2157
|
+
describe above.
|
|
2126
2158
|
|
|
2127
2159
|
Post-conditions specify what is required for a step to be succeessful, and
|
|
2128
|
-
sometimes you
|
|
2129
|
-
a cache and will only continue if a value
|
|
2130
|
-
response status
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
`error` property will be changed to a `warning
|
|
2160
|
+
sometimes you consider a certain error to be an indication of success. An
|
|
2161
|
+
example may be when you're checking a cache and will only continue if a value
|
|
2162
|
+
is _not_ cached, meaning a `notfound` response status is a success in this
|
|
2163
|
+
case. The condition pipeline for this should be straight forward, but as you
|
|
2164
|
+
cannot specify the response that will be used when the condition _passes_, you
|
|
2165
|
+
may wonder what happens with the error response. When an error response causes
|
|
2166
|
+
a post-condition to pass, Integreat will set the status of the response to
|
|
2167
|
+
`ok` and any `error` property will be changed to a `warning` property. Apart
|
|
2168
|
+
from that, the response will be unchanged.
|
|
2169
|
+
|
|
2170
|
+
Jobs may have `preconditions` too, and it will work in the same way as for a
|
|
2171
|
+
step, determining whether a job will run of not. `break` will have no effect
|
|
2172
|
+
for a condition on a job. Jobs may not have `postconditions`, but you can
|
|
2173
|
+
mutate the response with `postmutation` and accomplish the same.
|
|
2174
|
+
|
|
2175
|
+
#### Conditions and the `failOnErrorInPostconditions` flag
|
|
2176
|
+
|
|
2177
|
+
The way `preconditions` controls whether the previous step will break on error,
|
|
2178
|
+
is not very intuitive, so we have introduced a feature flag to change this
|
|
2179
|
+
behavior. The flag is called `failOnErrorInPostconditions`, and is set on the
|
|
2180
|
+
`flags` object in the definitions given to `Integreat.create()`). In the next
|
|
2181
|
+
major version of Integreat, this will be the default behavior, so it may
|
|
2182
|
+
be a good idea to start using it now.
|
|
2183
|
+
|
|
2184
|
+
When the flag is set to `true`, the default break on error behavior is set in
|
|
2185
|
+
`postconditions` instead. This means that you may set your own `preconditions`
|
|
2186
|
+
and still have the previous step break on error, the way you probably would
|
|
2187
|
+
expect it to work. If you set your own `postconditions`, on the other hand,
|
|
2188
|
+
you need to take care of how an error response from that step is handled, but
|
|
2189
|
+
that is often why you would set your own `postconditions` anyway.
|
|
2190
|
+
|
|
2191
|
+
Also, `break` will be `true` by default for `postconditions` with this flag,
|
|
2192
|
+
and you need to set it to `break: false` if you have a post-condition and you
|
|
2193
|
+
don't want it to stop the entire flow.
|
|
2194
|
+
|
|
2195
|
+
For `preconditions`, the `break` flag is `false` by default in all cases.
|
|
2136
2196
|
|
|
2137
2197
|
### Dispatching several actions by iterating over an array
|
|
2138
2198
|
|
|
2139
2199
|
Sometimes you will want to dispatch several actions based on a data array, e.g.
|
|
2140
|
-
when you have an array of data items, but the relevant endpoint only accepts
|
|
2141
|
-
data item. This may be done with `iterate`, which is a special mutation
|
|
2142
|
-
must return an array, and the job action will be dispatched once for
|
|
2143
|
-
in this array. The item will be set as payload `data`.
|
|
2144
|
-
to modify the action before it is dispatched as
|
|
2145
|
-
mutation is applied to every single action, after the
|
|
2200
|
+
when you have an array of data items, but the relevant endpoint only accepts
|
|
2201
|
+
one data item. This may be done with `iterate`, which is a special mutation
|
|
2202
|
+
that is must return an array, and the job action will be dispatched once for
|
|
2203
|
+
every item in this array. The item will be set as payload `data`.
|
|
2204
|
+
`premutation` may be used to modify the action before it is dispatched as
|
|
2205
|
+
usual, but note that the mutation is applied to every single action, after the
|
|
2206
|
+
`iterate`, so to speak.
|
|
2146
2207
|
|
|
2147
2208
|
This applies to both a job with an action and a step with an action in a flow.
|
|
2148
2209
|
|
|
2149
2210
|
The responses of each action are combined and set as a `response` object on the
|
|
2150
|
-
step action (before the iteration), making an iterated step just like any
|
|
2211
|
+
step action (before the iteration), making an iterated step just like any
|
|
2212
|
+
other.
|
|
2213
|
+
|
|
2151
2214
|
When all actions are successful, the response will have status `ok`, and the
|
|
2152
2215
|
response `data` will be an array of the data from each response in the order
|
|
2153
2216
|
they where run. When there are errors, Integreat will use any common status, if
|
|
@@ -2193,13 +2256,13 @@ const great = Integreat.create(
|
|
|
2193
2256
|
```
|
|
2194
2257
|
|
|
2195
2258
|
To queue an action instead of dispatching it right away, you set `queue: true`
|
|
2196
|
-
on the `meta` object. If everything is set up correctly, Integreat will push
|
|
2197
|
-
action to the queue. When the action is later pulled from the queue, it
|
|
2198
|
-
dispatched again, but without the `queue` property.
|
|
2259
|
+
on the `meta` object. If everything is set up correctly, Integreat will push
|
|
2260
|
+
the action to the queue. When the action is later pulled from the queue, it
|
|
2261
|
+
will be dispatched again, but without the `queue` property.
|
|
2199
2262
|
|
|
2200
|
-
You may also set the meta `queue` property to a Unix timestamp, and if the
|
|
2201
|
-
transporter supports it, it will be run at this time instead of being
|
|
2202
|
-
as soon as it is next in line in the queue.
|
|
2263
|
+
You may also set the meta `queue` property to a Unix timestamp, and if the
|
|
2264
|
+
queue transporter supports it, it will be run at this time instead of being
|
|
2265
|
+
processed as soon as it is next in line in the queue.
|
|
2203
2266
|
|
|
2204
2267
|
When a queue is not set up, a dispatched action with `queue: true` will just be
|
|
2205
2268
|
run right away as a normal action.
|
|
@@ -2229,8 +2292,8 @@ Integreat supports middleware, and there are two different middleware
|
|
|
2229
2292
|
_before_ it is mutated, giving you access to the data as it comes from the
|
|
2230
2293
|
service.
|
|
2231
2294
|
|
|
2232
|
-
To set up a logger of what we recieve from and send to a service, you'll use
|
|
2233
|
-
second middleware "pipeline", while a logger of dispatched actions would be
|
|
2295
|
+
To set up a logger of what we recieve from and send to a service, you'll use
|
|
2296
|
+
the second middleware "pipeline", while a logger of dispatched actions would be
|
|
2234
2297
|
placed in the first.
|
|
2235
2298
|
|
|
2236
2299
|
When actions pass through middleware, they may modifiy the actions as
|
|
@@ -2289,10 +2352,11 @@ const great = Integreat.create(
|
|
|
2289
2352
|
- `type`: This is the id of the schema used for getting ident data. This schema
|
|
2290
2353
|
needs to have a `service` specified.
|
|
2291
2354
|
- `props`: You may provide alternative field names for the `id`, `roles`, and
|
|
2292
|
-
`tokens` for an ident in the schema specified on `type`. When the prop and
|
|
2293
|
-
field has the same name, it may be omitted, though it doesn't hurt to
|
|
2294
|
-
it anyway for clarity. For setups that don't need `roles` and/or
|
|
2295
|
-
may set these to `null`. Omitting them will result in the
|
|
2355
|
+
`tokens` for an ident in the schema specified on `type`. When the prop and
|
|
2356
|
+
the field has the same name, it may be omitted, though it doesn't hurt to
|
|
2357
|
+
specify it anyway for clarity. For setups that don't need `roles` and/or
|
|
2358
|
+
`tokens`, you may set these to `null`. Omitting them will result in the
|
|
2359
|
+
default field names.
|
|
2296
2360
|
- `mapping`: When `id`, `roles`, or `tokens` is found on other paths in the
|
|
2297
2361
|
returned user data than the field names set in `props` (or by default), you
|
|
2298
2362
|
may set additional mapping here, to specify at what dot notation path to find
|