integreat 0.8.9 → 1.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +185 -37
- package/dist/authenticators/anonymous.d.ts +3 -0
- package/dist/authenticators/anonymous.js +22 -0
- package/dist/authenticators/anonymous.js.map +1 -0
- package/dist/authenticators/index.d.ts +1 -0
- package/dist/authenticators/index.js +1 -0
- package/dist/authenticators/index.js.map +1 -1
- package/dist/authenticators/options.d.ts +1 -1
- package/dist/authenticators/options.js +2 -2
- package/dist/authenticators/options.js.map +1 -1
- package/dist/authenticators/token.d.ts +1 -1
- package/dist/authenticators/token.js +2 -2
- package/dist/authenticators/token.js.map +1 -1
- package/dist/close.d.ts +1 -1
- package/dist/dispatch.d.ts +4 -4
- package/dist/dispatch.js +68 -71
- package/dist/dispatch.js.map +1 -1
- package/dist/dispatchScheduled.d.ts +2 -6
- package/dist/dispatchScheduled.js +7 -8
- package/dist/dispatchScheduled.js.map +1 -1
- package/dist/handlers/delete.js +4 -5
- package/dist/handlers/delete.js.map +1 -1
- package/dist/handlers/expire.js +5 -5
- package/dist/handlers/expire.js.map +1 -1
- package/dist/handlers/get.js +7 -6
- package/dist/handlers/get.js.map +1 -1
- package/dist/handlers/getAll.js +3 -3
- package/dist/handlers/getAll.js.map +1 -1
- package/dist/handlers/getIdent.js +10 -10
- package/dist/handlers/getIdent.js.map +1 -1
- package/dist/handlers/getMeta.js +6 -6
- package/dist/handlers/getMeta.js.map +1 -1
- package/dist/handlers/index.js +1 -1
- package/dist/handlers/index.js.map +1 -1
- package/dist/handlers/queue.js +6 -4
- package/dist/handlers/queue.js.map +1 -1
- package/dist/handlers/run.d.ts +3 -6
- package/dist/handlers/run.js +8 -272
- package/dist/handlers/run.js.map +1 -1
- package/dist/handlers/service.js +3 -6
- package/dist/handlers/service.js.map +1 -1
- package/dist/handlers/set.js +2 -2
- package/dist/handlers/set.js.map +1 -1
- package/dist/handlers/setMeta.js +2 -2
- package/dist/handlers/setMeta.js.map +1 -1
- package/dist/handlers/sync.js +6 -6
- package/dist/handlers/sync.js.map +1 -1
- package/dist/index.d.ts +8 -9
- package/dist/index.js +5 -6
- package/dist/index.js.map +1 -1
- package/dist/instance.d.ts +20 -0
- package/dist/instance.js +106 -0
- package/dist/instance.js.map +1 -0
- package/dist/jobs/Job.d.ts +10 -0
- package/dist/jobs/Job.js +109 -0
- package/dist/jobs/Job.js.map +1 -0
- package/dist/jobs/Schedule.d.ts +7 -0
- package/dist/jobs/Schedule.js +29 -0
- package/dist/jobs/Schedule.js.map +1 -0
- package/dist/jobs/Step.d.ts +14 -0
- package/dist/jobs/Step.js +256 -0
- package/dist/jobs/Step.js.map +1 -0
- package/dist/jobs/types.d.ts +23 -0
- package/dist/{service/endpoints → jobs}/types.js.map +1 -1
- package/dist/listen.d.ts +1 -1
- package/dist/middleware/completeIdent.js +1 -1
- package/dist/middleware/completeIdent.js.map +1 -1
- package/dist/schema/Schema.d.ts +12 -0
- package/dist/schema/Schema.js +34 -0
- package/dist/schema/Schema.js.map +1 -0
- package/dist/schema/accessForAction.d.ts +1 -1
- package/dist/schema/accessForAction.js +2 -3
- package/dist/schema/accessForAction.js.map +1 -1
- package/dist/schema/castFns/boolean.d.ts +1 -0
- package/dist/schema/castFns/boolean.js +9 -0
- package/dist/schema/castFns/boolean.js.map +1 -0
- package/dist/schema/castFns/date.d.ts +1 -0
- package/dist/{transformers/builtIns → schema/castFns}/date.js +1 -4
- package/dist/schema/castFns/date.js.map +1 -0
- package/dist/schema/castFns/integer.d.ts +1 -0
- package/dist/{transformers/builtIns → schema/castFns}/integer.js +1 -4
- package/dist/schema/castFns/integer.js.map +1 -0
- package/dist/schema/castFns/nonPrimitive.d.ts +2 -0
- package/dist/schema/castFns/nonPrimitive.js +58 -0
- package/dist/schema/castFns/nonPrimitive.js.map +1 -0
- package/dist/schema/castFns/number.d.ts +1 -0
- package/dist/{transformers/builtIns → schema/castFns}/number.js +1 -4
- package/dist/schema/castFns/number.js.map +1 -0
- package/dist/schema/castFns/object.d.ts +1 -0
- package/dist/schema/castFns/object.js +10 -0
- package/dist/schema/castFns/object.js.map +1 -0
- package/dist/schema/castFns/string.d.ts +1 -0
- package/dist/{transformers/builtIns → schema/castFns}/string.js +1 -4
- package/dist/schema/castFns/string.js.map +1 -0
- package/dist/schema/createCast.d.ts +3 -0
- package/dist/schema/createCast.js +125 -0
- package/dist/schema/createCast.js.map +1 -0
- package/dist/schema/expandShape.d.ts +2 -0
- package/dist/schema/expandShape.js +34 -0
- package/dist/schema/expandShape.js.map +1 -0
- package/dist/schema/types.d.ts +8 -2
- package/dist/service/Auth.d.ts +4 -7
- package/dist/service/Auth.js +18 -2
- package/dist/service/Auth.js.map +1 -1
- package/dist/service/Connection.d.ts +2 -2
- package/dist/service/Connection.js.map +1 -1
- package/dist/service/Endpoint.d.ts +20 -0
- package/dist/service/Endpoint.js +85 -0
- package/dist/service/Endpoint.js.map +1 -0
- package/dist/service/Service.d.ts +30 -0
- package/dist/service/Service.js +178 -0
- package/dist/service/Service.js.map +1 -0
- package/dist/service/types.d.ts +34 -28
- package/dist/service/utils/authAction.d.ts +26 -0
- package/dist/service/{authorize/action.js → utils/authAction.js} +19 -8
- package/dist/service/utils/authAction.js.map +1 -0
- package/dist/service/utils/authData.d.ts +7 -0
- package/dist/service/{authorize/data.js → utils/authData.js} +17 -13
- package/dist/service/utils/authData.js.map +1 -0
- package/dist/service/utils/cast.d.ts +7 -0
- package/dist/service/utils/cast.js +21 -0
- package/dist/service/utils/cast.js.map +1 -0
- package/dist/service/{endpoints/compare.d.ts → utils/compareEndpoints.d.ts} +1 -1
- package/dist/service/{endpoints/compare.js → utils/compareEndpoints.js} +3 -1
- package/dist/service/utils/compareEndpoints.js.map +1 -0
- package/dist/service/utils/incoming.d.ts +5 -0
- package/dist/service/utils/incoming.js +81 -0
- package/dist/service/utils/incoming.js.map +1 -0
- package/dist/service/utils/matchEnpoints.d.ts +3 -0
- package/dist/service/{endpoints/match.js → utils/matchEnpoints.js} +24 -5
- package/dist/service/utils/matchEnpoints.js.map +1 -0
- package/dist/service/utils/options.d.ts +17 -0
- package/dist/service/utils/options.js +41 -0
- package/dist/service/utils/options.js.map +1 -0
- package/dist/service/utils/resolveAuth.d.ts +5 -0
- package/dist/service/utils/resolveAuth.js +34 -0
- package/dist/service/utils/resolveAuth.js.map +1 -0
- package/dist/service/utils/send.d.ts +3 -0
- package/dist/service/utils/send.js +15 -0
- package/dist/service/utils/send.js.map +1 -0
- package/dist/transformers/index.js +0 -6
- package/dist/transformers/index.js.map +1 -1
- package/dist/types.d.ts +50 -55
- package/dist/utils/action.d.ts +4 -2
- package/dist/utils/action.js +18 -3
- package/dist/utils/action.js.map +1 -1
- package/dist/utils/array.d.ts +1 -0
- package/dist/utils/array.js +4 -0
- package/dist/utils/array.js.map +1 -1
- package/dist/utils/createMapOptions.d.ts +4 -4
- package/dist/utils/createMapOptions.js +10 -5
- package/dist/utils/createMapOptions.js.map +1 -1
- package/dist/utils/createUnknownServiceError.js +1 -1
- package/dist/utils/createUnknownServiceError.js.map +1 -1
- package/dist/utils/getField.d.ts +1 -1
- package/dist/utils/getField.js +1 -1
- package/dist/utils/getField.js.map +1 -1
- package/dist/utils/getService.d.ts +3 -3
- package/dist/utils/getService.js +1 -1
- package/dist/utils/getService.js.map +1 -1
- package/dist/utils/indexUtils.d.ts +2 -1
- package/dist/utils/indexUtils.js +6 -2
- package/dist/utils/indexUtils.js.map +1 -1
- package/dist/utils/is.d.ts +5 -8
- package/dist/utils/is.js +9 -13
- package/dist/utils/is.js.map +1 -1
- package/dist/utils/mergeDefinitions.d.ts +1 -1
- package/dist/utils/mergeResources.d.ts +1 -1
- package/dist/utils/modifyOperationObject.d.ts +1 -0
- package/dist/utils/modifyOperationObject.js +11 -0
- package/dist/utils/modifyOperationObject.js.map +1 -0
- package/dist/utils/mutateAndSend.d.ts +2 -2
- package/dist/utils/mutationHelpers.js +12 -11
- package/dist/utils/mutationHelpers.js.map +1 -1
- package/dist/utils/validateFilters.d.ts +1 -1
- package/dist/utils/validateFilters.js +3 -5
- package/dist/utils/validateFilters.js.map +1 -1
- package/dist/utils/validation.d.ts +3 -0
- package/dist/utils/validation.js +34 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +9 -8
- package/dist/adapters/index.d.ts +0 -1
- package/dist/adapters/index.js +0 -2
- package/dist/adapters/index.js.map +0 -1
- package/dist/adapters/uri.d.ts +0 -3
- package/dist/adapters/uri.js +0 -23
- package/dist/adapters/uri.js.map +0 -1
- package/dist/create.d.ts +0 -40
- package/dist/create.js +0 -79
- package/dist/create.js.map +0 -1
- package/dist/mutations/exchangeForm.d.ts +0 -9
- package/dist/mutations/exchangeForm.js +0 -5
- package/dist/mutations/exchangeForm.js.map +0 -1
- package/dist/mutations/exchangeJson.d.ts +0 -47
- package/dist/mutations/exchangeJson.js +0 -40
- package/dist/mutations/exchangeJson.js.map +0 -1
- package/dist/mutations/exchangeUri.d.ts +0 -16
- package/dist/mutations/exchangeUri.js +0 -13
- package/dist/mutations/exchangeUri.js.map +0 -1
- package/dist/mutations/index.d.ts +0 -72
- package/dist/mutations/index.js +0 -9
- package/dist/mutations/index.js.map +0 -1
- package/dist/schema/createCastMapping.d.ts +0 -3
- package/dist/schema/createCastMapping.js +0 -133
- package/dist/schema/createCastMapping.js.map +0 -1
- package/dist/schema/index.d.ts +0 -13
- package/dist/schema/index.js +0 -43
- package/dist/schema/index.js.map +0 -1
- package/dist/service/authorize/action.d.ts +0 -4
- package/dist/service/authorize/action.js.map +0 -1
- package/dist/service/authorize/data.d.ts +0 -7
- package/dist/service/authorize/data.js.map +0 -1
- package/dist/service/endpoints/compare.js.map +0 -1
- package/dist/service/endpoints/create.d.ts +0 -8
- package/dist/service/endpoints/create.js +0 -78
- package/dist/service/endpoints/create.js.map +0 -1
- package/dist/service/endpoints/index.d.ts +0 -6
- package/dist/service/endpoints/index.js +0 -15
- package/dist/service/endpoints/index.js.map +0 -1
- package/dist/service/endpoints/match.d.ts +0 -3
- package/dist/service/endpoints/match.js.map +0 -1
- package/dist/service/endpoints/types.d.ts +0 -36
- package/dist/service/index.d.ts +0 -18
- package/dist/service/index.js +0 -250
- package/dist/service/index.js.map +0 -1
- package/dist/transformers/builtIns/boolean.d.ts +0 -3
- package/dist/transformers/builtIns/boolean.js +0 -12
- package/dist/transformers/builtIns/boolean.js.map +0 -1
- package/dist/transformers/builtIns/date.d.ts +0 -4
- package/dist/transformers/builtIns/date.js.map +0 -1
- package/dist/transformers/builtIns/index.d.ts +0 -3
- package/dist/transformers/builtIns/index.js +0 -20
- package/dist/transformers/builtIns/index.js.map +0 -1
- package/dist/transformers/builtIns/integer.d.ts +0 -3
- package/dist/transformers/builtIns/integer.js.map +0 -1
- package/dist/transformers/builtIns/number.d.ts +0 -4
- package/dist/transformers/builtIns/number.js.map +0 -1
- package/dist/transformers/builtIns/object.d.ts +0 -3
- package/dist/transformers/builtIns/object.js +0 -13
- package/dist/transformers/builtIns/object.js.map +0 -1
- package/dist/transformers/builtIns/reference.d.ts +0 -3
- package/dist/transformers/builtIns/reference.js +0 -48
- package/dist/transformers/builtIns/reference.js.map +0 -1
- package/dist/transformers/builtIns/string.d.ts +0 -3
- package/dist/transformers/builtIns/string.js.map +0 -1
- package/dist/transformers/builtIns/unarray.d.ts +0 -3
- package/dist/transformers/builtIns/unarray.js +0 -9
- package/dist/transformers/builtIns/unarray.js.map +0 -1
- package/dist/transformers/form.d.ts +0 -3
- package/dist/transformers/form.js +0 -33
- package/dist/transformers/form.js.map +0 -1
- package/dist/transformers/generateUri.d.ts +0 -9
- package/dist/transformers/generateUri.js +0 -66
- package/dist/transformers/generateUri.js.map +0 -1
- package/dist/transformers/json.d.ts +0 -3
- package/dist/transformers/json.js +0 -20
- package/dist/transformers/json.js.map +0 -1
- package/dist/utils/createSchedule.d.ts +0 -7
- package/dist/utils/createSchedule.js +0 -26
- package/dist/utils/createSchedule.js.map +0 -1
- package/dist/utils/xor.d.ts +0 -1
- package/dist/utils/xor.js +0 -4
- package/dist/utils/xor.js.map +0 -1
- /package/dist/{service/endpoints → jobs}/types.js +0 -0
package/README.md
CHANGED
|
@@ -111,8 +111,10 @@ const services = [
|
|
|
111
111
|
transporter: 'http', // Use the http transporter
|
|
112
112
|
adapters: ['json'], // Run the request and the response through the json adapter
|
|
113
113
|
options: {
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
transporter: {
|
|
115
|
+
// Options for the transporter
|
|
116
|
+
uri: 'https://cat-fact.herokuapp.com/facts', // Only the uri is needed here
|
|
117
|
+
},
|
|
116
118
|
},
|
|
117
119
|
endpoints: [
|
|
118
120
|
{
|
|
@@ -204,7 +206,7 @@ for transporters, adapters, etc.
|
|
|
204
206
|
id: <service id>,
|
|
205
207
|
transporter: <transporter id>,
|
|
206
208
|
adapters: [<adapter id>, <adapter id>, ...],
|
|
207
|
-
auth: <auth
|
|
209
|
+
auth: <auth config>,
|
|
208
210
|
meta: <type id>,
|
|
209
211
|
options: {...},
|
|
210
212
|
mutation: <mutation pipeline>,
|
|
@@ -226,7 +228,17 @@ The `auth` property should normally be set to the id of an
|
|
|
226
228
|
[auth definition](#service-authentication), if the service requires
|
|
227
229
|
authentication. In cases where the service is authenticated by other means, e.g.
|
|
228
230
|
by including username and password in the uri, set the `auth` property to `true`
|
|
229
|
-
to signal that this is an authenticated service.
|
|
231
|
+
to signal that this is an authenticated service. For services accepting incoming
|
|
232
|
+
actions, `auth` should be set to an object with
|
|
233
|
+
`{ outgoing: <auth id | true>, incoming: <auth id | true>}`.
|
|
234
|
+
|
|
235
|
+
**Note:** When connecting to a service for listening, the `outgoing` auth is
|
|
236
|
+
used. `incoming` is only used for validating the actions being dispatched "back"
|
|
237
|
+
from the service.
|
|
238
|
+
|
|
239
|
+
In `options`, you may provide options for transporters and adapters. It is
|
|
240
|
+
merged with the `options` object on the endpoint. See
|
|
241
|
+
[the `options` object](#options-object) for more on this.
|
|
230
242
|
|
|
231
243
|
### Endpoints
|
|
232
244
|
|
|
@@ -278,18 +290,18 @@ Here's the format of an endpoint definition:
|
|
|
278
290
|
action: <action type>,
|
|
279
291
|
params: {...},
|
|
280
292
|
incoming: <boolean>,
|
|
281
|
-
|
|
293
|
+
conditions: [...]
|
|
282
294
|
},
|
|
283
295
|
validate: [
|
|
284
296
|
{
|
|
285
297
|
condition: <mutation pipeline>,
|
|
286
298
|
failResponse: <response object>
|
|
287
299
|
}
|
|
288
|
-
]
|
|
289
|
-
|
|
290
|
-
options: {...},
|
|
300
|
+
],
|
|
301
|
+
mutate: <mutation pipeline>,
|
|
291
302
|
allowRawRequest: <boolean>,
|
|
292
303
|
allowRawResponse: <boolean>
|
|
304
|
+
options: {...},
|
|
293
305
|
}
|
|
294
306
|
```
|
|
295
307
|
|
|
@@ -305,31 +317,29 @@ specify a few things:
|
|
|
305
317
|
- `match`: The match object is used to decide the right endpoint for an action.
|
|
306
318
|
More one this in the [Match properties](#match-properties) section.
|
|
307
319
|
- `validate`: This is an array of condition that have to be met in order for
|
|
308
|
-
Integreat to proceed with the endpoint.
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
320
|
+
Integreat to proceed with the endpoint. The `condition` is a mutation pipeline
|
|
321
|
+
that should return a truthy value for the validation to pass. Any falsy value
|
|
322
|
+
will cause the validation to fail. If `validate` is missing or an empty array,
|
|
323
|
+
no validation will be done. This may sound similar to `match`, but `validate`
|
|
324
|
+
is only processed after a match is found, and if the validation fails, no
|
|
325
|
+
other endpoint is considered. On a failing validation, the `failResponse` is
|
|
326
|
+
returned as the response from this action, or a `badrequest` response if no
|
|
327
|
+
`failResponse` is provided. There's also a shorthand, where you set
|
|
328
|
+
`failResponse` to a string, which will be the `error` message of the
|
|
329
|
+
`badrequest` response. The response is passed through the mutation pipeline.
|
|
330
|
+
- `mutate`: A mutation pipeline for the endpoint. The pipeline is run for both
|
|
317
331
|
actions going to a service and the response coming back, so keep this in mind
|
|
318
332
|
when you set up this pipeline. See [Mutation pipelines](#mutations)
|
|
319
|
-
for more on how to define the mutation.
|
|
320
|
-
- `options`: This object will be passed on to the transporter and may contain
|
|
321
|
-
any properties that are meaningful to the transporter. You may also add other
|
|
322
|
-
properties for use in your mutations, but keep in mind that they will be sent
|
|
323
|
-
to the transporter. The endpoint `options` object is merged with the service
|
|
324
|
-
`options` object. Endpoint properties will override equally named service
|
|
325
|
-
properties, but this is done through deep merging, so child objects will be
|
|
326
|
-
merged as well.
|
|
333
|
+
for more on how to define the mutation. `mutation` is an alias for `mutate`.
|
|
327
334
|
- `allowRawRequest`: When set to `true`, payload `data` sent to this endpoint
|
|
328
335
|
will not by cast automatically nor will an error be returned if the data is
|
|
329
336
|
not typed.
|
|
330
337
|
- `allowRawResponse`: When set to `true`, response `data` coming from this
|
|
331
338
|
endpoint will not by cast automatically nor will an error be returned if the
|
|
332
339
|
data is not typed.
|
|
340
|
+
- `options`: This object is merged with the `options` object on the service
|
|
341
|
+
definition, and provide options for transporters and adapters. See
|
|
342
|
+
[the `options` object](#options-object) for more on this.
|
|
333
343
|
|
|
334
344
|
#### Match properties
|
|
335
345
|
|
|
@@ -355,10 +365,15 @@ An endpoint may specify none or more of the following match properties:
|
|
|
355
365
|
case several match, the endpoint with more specified params will be preferred.
|
|
356
366
|
- `incoming`: If this is `true`, it will only match incoming actions, if `false`
|
|
357
367
|
only outgoing, and if not set, it will match both.
|
|
358
|
-
- `
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
368
|
+
- `conditions`: An array of mutation pipelines that will be run on the action to
|
|
369
|
+
see if it's a fit for this endpoint. If all pipelines return a truthy value,
|
|
370
|
+
the endpoint is chosen (given that the other match properties also match). We
|
|
371
|
+
rely on JavaScript definition of 'truthy' here, so any value that is not
|
|
372
|
+
`false`, `null`, `undefined`, `0`, `NaN`, or `''` will be considered truthy.
|
|
373
|
+
|
|
374
|
+
> There used to be a `filters` property on the endpoint match object. It is
|
|
375
|
+
> still supported, but it's deprecated and will be removed in v1.1. Please use
|
|
376
|
+
> `conditions` instead.
|
|
362
377
|
|
|
363
378
|
> Editor's note: Describe what incoming actions are, and give more details on
|
|
364
379
|
> filters.
|
|
@@ -399,7 +414,9 @@ Example service definition with endpoint match object:
|
|
|
399
414
|
}
|
|
400
415
|
},
|
|
401
416
|
options: {
|
|
402
|
-
|
|
417
|
+
transporter: {
|
|
418
|
+
uri: 'https://example.api.com/1.0/{author}/{type}_log?archive={archive}'
|
|
419
|
+
}
|
|
403
420
|
}
|
|
404
421
|
}
|
|
405
422
|
],
|
|
@@ -407,6 +424,97 @@ Example service definition with endpoint match object:
|
|
|
407
424
|
}
|
|
408
425
|
```
|
|
409
426
|
|
|
427
|
+
### Options object
|
|
428
|
+
|
|
429
|
+
A service defintion may have `options` object in two places: Direction on the
|
|
430
|
+
service definition and on any of the endpoints. When an action is sent to an
|
|
431
|
+
endpoint, the combination of the two `options` are used. Also, there may be
|
|
432
|
+
different options for the transporter and for the adapters.
|
|
433
|
+
|
|
434
|
+
Example of an `options` object set on the service definition:
|
|
435
|
+
|
|
436
|
+
```javascript
|
|
437
|
+
{
|
|
438
|
+
id: 'entries',
|
|
439
|
+
options: {
|
|
440
|
+
uri: 'https://ourapi.com/v1',
|
|
441
|
+
transporter: {
|
|
442
|
+
method: 'POST',
|
|
443
|
+
incoming: { port: 3000 }
|
|
444
|
+
},
|
|
445
|
+
adapters: {
|
|
446
|
+
xml: { namespaces: { ... } },
|
|
447
|
+
// ...
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
Any properties set directly on the `options` object or on a `transporter`
|
|
454
|
+
property, are treated as options for the transporter. If there are properties on
|
|
455
|
+
both the `options` and a `transporter` object, they will be merged, with the
|
|
456
|
+
`transporter` object having priority if conflicts. This is a shallow merge, so
|
|
457
|
+
objects used in the options will not be merged.
|
|
458
|
+
|
|
459
|
+
In the example above, the options passed to the transporter will include `uri`,
|
|
460
|
+
`method`, and `incoming`.
|
|
461
|
+
|
|
462
|
+
The `incoming` object on the transporter options is a bit special, as it holds
|
|
463
|
+
separate options for transporters that support incoming requests trough the
|
|
464
|
+
`listen()` method. If there are `incoming` objects on both the `options` and
|
|
465
|
+
`transporter` objects, they will be merged, again with priority to the one on
|
|
466
|
+
the `transporter` object.
|
|
467
|
+
|
|
468
|
+
Note that we recommend setting transporter options on the `transporter` object
|
|
469
|
+
for clarity, but both will work.
|
|
470
|
+
|
|
471
|
+
Adapter options may be given in an `adapters` object, where each adapter may
|
|
472
|
+
have its own options, set with the id of the adapter as a key. In the example
|
|
473
|
+
above, the `xml` adapter will be given the `namespaces` object. A requirement
|
|
474
|
+
for this, is that the adapter actually have an id. Adapters provided directly on
|
|
475
|
+
service definition may not have an id, but all adapters that are referenced by
|
|
476
|
+
an id, will also be given options set on that id, which is the common behavior.
|
|
477
|
+
|
|
478
|
+
Finally, when all this sorting have been done on options from both the service
|
|
479
|
+
definition and an endpoint, the two options structures are merged before being
|
|
480
|
+
used. Here, the endpoint options take priority, so that you may set a general
|
|
481
|
+
option on the service, and override it on the endpoint.
|
|
482
|
+
|
|
483
|
+
Example of endpoint options overriding service options:
|
|
484
|
+
|
|
485
|
+
```javascript
|
|
486
|
+
{
|
|
487
|
+
id: 'entries',
|
|
488
|
+
options: {
|
|
489
|
+
transporter: {
|
|
490
|
+
uri: 'https://ourapi.com/v1',
|
|
491
|
+
method: 'GET',
|
|
492
|
+
}
|
|
493
|
+
},
|
|
494
|
+
endpoints: [
|
|
495
|
+
{
|
|
496
|
+
match: { ... }
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
match: { ... },
|
|
500
|
+
options: {
|
|
501
|
+
transporter: {
|
|
502
|
+
method: 'POST'
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
]
|
|
507
|
+
}
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
Here, the first enpoint will be given `method: 'GET'`, while the next will get
|
|
511
|
+
`method: 'POST'`.
|
|
512
|
+
|
|
513
|
+
Before actions are passed through mutations and finally passed to the
|
|
514
|
+
transporter, the merged transporter options is set on an `options` property in
|
|
515
|
+
the `meta` object of the action. This way, you may also mutate these options
|
|
516
|
+
before they reach the transporter.
|
|
517
|
+
|
|
410
518
|
### Service authentication
|
|
411
519
|
|
|
412
520
|
This definition format is used to authenticate with a service:
|
|
@@ -431,6 +539,8 @@ This definition format is used to authenticate with a service:
|
|
|
431
539
|
|
|
432
540
|
Available authenticators:
|
|
433
541
|
|
|
542
|
+
- `anonymous`: Will always grant access and return an ident with id
|
|
543
|
+
`'anonymous'` on validation. This is built into Integreat.
|
|
434
544
|
- `options`: Will pass on the options as authentication, so whatever you provide
|
|
435
545
|
here is the authentication. What options to provide, then, is depending on
|
|
436
546
|
what the relevant transporter requires. This is built into Integreat.
|
|
@@ -810,7 +920,7 @@ Set the `access` property on a schema to enforce permission checking. This
|
|
|
810
920
|
applies to any service that provides data in this schema.
|
|
811
921
|
|
|
812
922
|
The simplest access rule is `auth`, which means that anyone can do anything with
|
|
813
|
-
the data of this schema, as long as they are authenticated. Being authenticated
|
|
923
|
+
the data of this schema, as long as they are authenticated. Being authenticated,
|
|
814
924
|
in this context, means that the dispatched action has an `ident` in the `meta`
|
|
815
925
|
object. See [the section on idents](#idents) for more on this.
|
|
816
926
|
|
|
@@ -1084,7 +1194,8 @@ Current meta properties reserved by Integreat:
|
|
|
1084
1194
|
Integreat).
|
|
1085
1195
|
- `options`: Used for passing the processed service endpoint options object to
|
|
1086
1196
|
a transporter. The `options` object is available through mutations, so that
|
|
1087
|
-
you may modify it futher before it goes to the transporter.
|
|
1197
|
+
you may modify it futher before it goes to the transporter. Note that only the
|
|
1198
|
+
transporter options are provided here, not the adapter options.
|
|
1088
1199
|
- `authorized`: An internal flag signaling that the action has been authorized.
|
|
1089
1200
|
Will be removed from any dispatched actions.
|
|
1090
1201
|
|
|
@@ -1098,12 +1209,12 @@ When you dispatch an action, you will get a response object back in this format:
|
|
|
1098
1209
|
data: <data from the service, usually mutated>,
|
|
1099
1210
|
error: <error message>,
|
|
1100
1211
|
warning: <warning message>,
|
|
1101
|
-
|
|
1212
|
+
origin: <code telling where an error originated>
|
|
1213
|
+
access: <holds the ident actually being used>,
|
|
1102
1214
|
paging: <pagination objects>,
|
|
1103
1215
|
params: <key/value pairs>,
|
|
1104
1216
|
headers: <key/value pairs>,
|
|
1105
1217
|
responses: <array of sub-responses when relevant>,
|
|
1106
|
-
meta: <meta object>
|
|
1107
1218
|
}
|
|
1108
1219
|
```
|
|
1109
1220
|
|
|
@@ -1120,6 +1231,13 @@ When you dispatch an action, you will get a response object back in this format:
|
|
|
1120
1231
|
should know, the warning message is where you'll get noticed. An example is
|
|
1121
1232
|
when you get an array of data items, but some of them was removed due to the
|
|
1122
1233
|
access of the ident on the action.
|
|
1234
|
+
- `origin`: When the response is an error (status is not `'ok'` or `'queue'`),
|
|
1235
|
+
this property will hold a code for where the error originated. The goal is to
|
|
1236
|
+
set it as close to the actual origin as possible. See
|
|
1237
|
+
[list of origin codes](#origin-codes) below.
|
|
1238
|
+
- `access`: An object holding the `ident` that was actually being used. This may
|
|
1239
|
+
be different than the `meta.ident` on the action, as the ident may also be
|
|
1240
|
+
mutated or completed with roles etc. along the way.
|
|
1123
1241
|
- `paging`: For services and transporters that support
|
|
1124
1242
|
[pagination](#pagination), this object will hold information about how to get
|
|
1125
1243
|
the next or previous page, in a `next` or `prev` object. These objects are
|
|
@@ -1136,8 +1254,6 @@ When you dispatch an action, you will get a response object back in this format:
|
|
|
1136
1254
|
`SYNC` or `RUN`. The action handlers _may_ then provide an array of all the
|
|
1137
1255
|
sub-response objects here.
|
|
1138
1256
|
|
|
1139
|
-
> Editor's note: Do we return access in responses?
|
|
1140
|
-
> Editor's note: Do we return meta in responses?
|
|
1141
1257
|
> Editor's note: Is it correct that queues return the id in the data?
|
|
1142
1258
|
|
|
1143
1259
|
When the status is `queued`, the id of the queued action may found in
|
|
@@ -1146,7 +1262,8 @@ the same as `action.meta.id`.
|
|
|
1146
1262
|
|
|
1147
1263
|
### Status codes
|
|
1148
1264
|
|
|
1149
|
-
The `status`
|
|
1265
|
+
The `status` property on the action response will be one of the following status
|
|
1266
|
+
codes:
|
|
1150
1267
|
|
|
1151
1268
|
- `ok`: Everything is well, data is returned as expected
|
|
1152
1269
|
- `queued`: The action has been queued. This is regarded as a success status
|
|
@@ -1160,6 +1277,37 @@ The `status` or the action response will be one of the following status codes:
|
|
|
1160
1277
|
- `badresponse`: Response data is not as expected
|
|
1161
1278
|
- `error`: Any other error
|
|
1162
1279
|
|
|
1280
|
+
### Origin codes
|
|
1281
|
+
|
|
1282
|
+
The `origin` property is not exclusively defined, but these are some of the more
|
|
1283
|
+
common codes:
|
|
1284
|
+
|
|
1285
|
+
- `service:<service id>`: The error originated in service. There may also be
|
|
1286
|
+
third level of detail here, if the service sets an origin code of its own.
|
|
1287
|
+
E.g. `'service:entries:handshake`.
|
|
1288
|
+
- `middleware:service:<service id>`: The error happened in the middleware chain
|
|
1289
|
+
on the service side.
|
|
1290
|
+
- `internal:service:<service id>`: Used for errors in the service class, that
|
|
1291
|
+
has nothing to do with the actual service, e.g. if the service class is not
|
|
1292
|
+
configured correctly.
|
|
1293
|
+
- `mutate:request`: The error was set in a request mutation pipeline.
|
|
1294
|
+
- `mutate:response`: The error was set in a response mutation pipeline.
|
|
1295
|
+
- `auth:action`: The error occured while attempting to authorize the action.
|
|
1296
|
+
- `auth:data`: The error occured while attempting to authorize data in an
|
|
1297
|
+
action payload or a response.
|
|
1298
|
+
- `auth:service:<service id>`: The error occured while attempting to authorize
|
|
1299
|
+
the service with the given id.
|
|
1300
|
+
- `auth:service:<service id>:<authenticator id>`: The error occured while
|
|
1301
|
+
attempting to authorize the service with the given id, through the given
|
|
1302
|
+
authenticator.
|
|
1303
|
+
- `handler:<handler id>`: The error occurred with the handler with the given id,
|
|
1304
|
+
e.g. `'handler:GET'`. This means the error did happen in the service or the
|
|
1305
|
+
mutation pipelines, but in the internal workings of then handler.
|
|
1306
|
+
- `middleware:dispatch`: The error happened within the middleware chain, on the
|
|
1307
|
+
`dispatch()` end (not on the service end).
|
|
1308
|
+
- `dispatch`: This is the lowest level of origin, as the error happened within
|
|
1309
|
+
the `dispatch()` method.
|
|
1310
|
+
|
|
1163
1311
|
### Idents
|
|
1164
1312
|
|
|
1165
1313
|
An ident in Integreat is basically an id unique to one participant in the
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const anonymousAuth = {
|
|
2
|
+
id: 'anonymous',
|
|
3
|
+
async authenticate(_options) {
|
|
4
|
+
return { status: 'granted' };
|
|
5
|
+
},
|
|
6
|
+
isAuthenticated(_authentication) {
|
|
7
|
+
return true;
|
|
8
|
+
},
|
|
9
|
+
async validate(_authentication) {
|
|
10
|
+
return { id: 'anonymous' };
|
|
11
|
+
},
|
|
12
|
+
authentication: {
|
|
13
|
+
asObject(_authentication) {
|
|
14
|
+
return {};
|
|
15
|
+
},
|
|
16
|
+
asHttpHeaders(_authentication) {
|
|
17
|
+
return {};
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
export default anonymousAuth;
|
|
22
|
+
//# sourceMappingURL=anonymous.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anonymous.js","sourceRoot":"","sources":["../../src/authenticators/anonymous.ts"],"names":[],"mappings":"AAKA,MAAM,aAAa,GAAkB;IACnC,EAAE,EAAE,WAAW;IAOf,KAAK,CAAC,YAAY,CAAC,QAAQ;QACzB,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAA;IAC9B,CAAC;IAMD,eAAe,CAAC,eAAe;QAC7B,OAAO,IAAI,CAAA;IACb,CAAC;IAMD,KAAK,CAAC,QAAQ,CAAC,eAAe;QAC5B,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,CAAA;IAC5B,CAAC;IAED,cAAc,EAAE;QAMd,QAAQ,CAAC,eAAe;YACtB,OAAO,EAAE,CAAA;QACX,CAAC;QAOD,aAAa,CAAC,eAAe;YAC3B,OAAO,EAAE,CAAA;QACX,CAAC;KACF;CACF,CAAA;AAED,eAAe,aAAa,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authenticators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authenticators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { isObject } from '../utils/is.js';
|
|
2
2
|
const optionsAuth = {
|
|
3
|
-
async authenticate(options
|
|
3
|
+
async authenticate(options) {
|
|
4
4
|
return { status: 'granted', ...options };
|
|
5
5
|
},
|
|
6
|
-
isAuthenticated(authentication
|
|
6
|
+
isAuthenticated(authentication) {
|
|
7
7
|
return !!(authentication && authentication.status === 'granted');
|
|
8
8
|
},
|
|
9
9
|
authentication: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/authenticators/options.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/authenticators/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAQzC,MAAM,WAAW,GAAkB;IAQjC,KAAK,CAAC,YAAY,CAAC,OAAO;QACxB,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,EAAE,CAAA;IAC1C,CAAC;IAOD,eAAe,CAAC,cAAc;QAC5B,OAAO,CAAC,CAAC,CAAC,cAAc,IAAI,cAAc,CAAC,MAAM,KAAK,SAAS,CAAC,CAAA;IAClE,CAAC;IAED,cAAc,EAAE;QAOd,QAAQ,CAAC,cAAqC;YAC5C,IAAI,QAAQ,CAAC,cAAc,CAAC,EAAE;gBAC5B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,GAAG,cAAc,CAAA;gBAC7C,IAAI,MAAM,KAAK,SAAS,EAAE;oBACxB,OAAO,OAAO,CAAA;iBACf;aACF;YACD,OAAO,EAAE,CAAA;QACX,CAAC;QAOD,aAAa,CACX,cAAqC;YAErC,IAAI,QAAQ,CAAC,cAAc,CAAC,EAAE;gBAC5B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,GAAG,cAAc,CAAA;gBAC7C,IAAI,MAAM,KAAK,SAAS,EAAE;oBACxB,OAAO,OAAO,CAAA;iBACf;aACF;YACD,OAAO,EAAE,CAAA;QACX,CAAC;KACF;CACF,CAAA;AAED,eAAe,WAAW,CAAA"}
|
|
@@ -9,13 +9,13 @@ const getTypeAndToken = (authentication) => {
|
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
11
|
const tokenAuth = {
|
|
12
|
-
async authenticate(options
|
|
12
|
+
async authenticate(options) {
|
|
13
13
|
const { token = null, type, encode = false } = options || {};
|
|
14
14
|
return token
|
|
15
15
|
? { status: 'granted', token, type, encode }
|
|
16
16
|
: { status: 'refused' };
|
|
17
17
|
},
|
|
18
|
-
isAuthenticated(authentication
|
|
18
|
+
isAuthenticated(authentication) {
|
|
19
19
|
return !!(authentication &&
|
|
20
20
|
authentication.status === 'granted' &&
|
|
21
21
|
authentication.token);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/authenticators/token.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/authenticators/token.ts"],"names":[],"mappings":"AAkBA,MAAM,eAAe,GAAG,CAAC,cAA0C,EAAE,EAAE;IACrE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,cAAc,IAAI,EAAE,CAAA;IAC5D,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,KAAK,EAAE;QAClC,OAAO,EAAE,CAAA;KACV;IACD,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK;QAC7D,IAAI;KACL,CAAA;AACH,CAAC,CAAA;AAKD,MAAM,SAAS,GAAkB;IAO/B,KAAK,CAAC,YAAY,CAAC,OAAO;QACxB,MAAM,EAAE,KAAK,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,EAAE,GAAG,OAAO,IAAI,EAAE,CAAA;QAC5D,OAAO,KAAK;YACV,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE;YAC5C,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAA;IAC3B,CAAC;IAOD,eAAe,CAAC,cAAc;QAC5B,OAAO,CAAC,CAAC,CACP,cAAc;YACd,cAAc,CAAC,MAAM,KAAK,SAAS;YACnC,cAAc,CAAC,KAAK,CACrB,CAAA;IACH,CAAC;IAED,cAAc,EAAE;QAOd,QAAQ,CAAC,cAA0C;YACjD,OAAO,eAAe,CAAC,cAAc,CAAC,CAAA;QACxC,CAAC;QAQD,aAAa,CAAC,cAA0C;YACtD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,eAAe,CAAC,cAAc,CAAC,CAAA;YACvD,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;QAC1E,CAAC;KACF;CACF,CAAA;AAED,eAAe,SAAS,CAAA"}
|
package/dist/close.d.ts
CHANGED
package/dist/dispatch.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Dispatch, Middleware, ActionHandler, HandlerOptions } from './types.js';
|
|
2
|
-
import type
|
|
3
|
-
import type
|
|
4
|
-
export declare const compose: (...fns: Middleware[]) => Middleware;
|
|
2
|
+
import type Service from './service/Service.js';
|
|
3
|
+
import type Schema from './schema/Schema.js';
|
|
5
4
|
export interface Resources {
|
|
6
5
|
handlers: Record<string, ActionHandler>;
|
|
7
|
-
schemas:
|
|
6
|
+
schemas: Map<string, Schema>;
|
|
8
7
|
services: Record<string, Service>;
|
|
9
8
|
middleware?: Middleware[];
|
|
10
9
|
options: HandlerOptions;
|
|
11
10
|
}
|
|
11
|
+
export declare const compose: (...fns: Middleware[]) => Middleware;
|
|
12
12
|
export default function createDispatch({ handlers, schemas, services, middleware, options, }: Resources): Dispatch;
|