integreat 1.1.1 → 1.2.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 +100 -32
- package/dist/Instance.js +121 -0
- package/dist/Instance.js.map +1 -0
- package/dist/authenticators/options.d.ts +4 -0
- package/dist/authenticators/options.js +43 -0
- package/dist/authenticators/options.js.map +1 -1
- package/dist/dispatch.js +2 -1
- package/dist/dispatch.js.map +1 -1
- package/dist/handlers/delete.js +2 -2
- package/dist/handlers/delete.js.map +1 -1
- package/dist/handlers/expire.js +1 -1
- package/dist/handlers/expire.js.map +1 -1
- package/dist/handlers/get.js +29 -35
- package/dist/handlers/get.js.map +1 -1
- package/dist/handlers/getAll.js +1 -1
- package/dist/handlers/getAll.js.map +1 -1
- package/dist/handlers/getIdent.js +1 -1
- package/dist/handlers/getIdent.js.map +1 -1
- package/dist/handlers/getMeta.js +1 -1
- 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 +1 -1
- package/dist/handlers/run.js.map +1 -1
- package/dist/handlers/service.js +1 -2
- package/dist/handlers/service.js.map +1 -1
- package/dist/handlers/set.js +1 -2
- package/dist/handlers/set.js.map +1 -1
- package/dist/handlers/setMeta.js +1 -1
- package/dist/handlers/setMeta.js.map +1 -1
- package/dist/handlers/sync.js +1 -1
- package/dist/handlers/sync.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/jobs/Job.js +1 -1
- package/dist/jobs/Job.js.map +1 -1
- package/dist/jobs/Step.js +2 -1
- package/dist/jobs/Step.js.map +1 -1
- package/dist/service/Auth.d.ts +4 -4
- package/dist/service/Auth.js +26 -20
- package/dist/service/Auth.js.map +1 -1
- package/dist/service/Endpoint.js +1 -1
- package/dist/service/Endpoint.js.map +1 -1
- package/dist/service/Service.d.ts +2 -2
- package/dist/service/Service.js +22 -6
- package/dist/service/Service.js.map +1 -1
- package/dist/service/types.d.ts +1 -0
- package/dist/service/utils/incoming.js +2 -1
- package/dist/service/utils/incoming.js.map +1 -1
- package/dist/service/utils/resolveAuth.js +1 -1
- package/dist/service/utils/send.js +1 -1
- package/dist/service/utils/send.js.map +1 -1
- package/dist/types.d.ts +2 -1
- package/dist/utils/action.d.ts +0 -3
- package/dist/utils/action.js +1 -43
- package/dist/utils/action.js.map +1 -1
- package/dist/utils/is.d.ts +1 -0
- package/dist/utils/is.js +1 -0
- package/dist/utils/is.js.map +1 -1
- package/dist/utils/mutateAndSend.js +4 -8
- package/dist/utils/mutateAndSend.js.map +1 -1
- package/dist/utils/response.d.ts +5 -0
- package/dist/utils/response.js +73 -0
- package/dist/utils/response.js.map +1 -0
- package/package.json +1 -1
- package/dist/instance.js +0 -106
- package/dist/instance.js.map +0 -1
- package/dist/utils/createUnknownServiceError.d.ts +0 -2
- package/dist/utils/createUnknownServiceError.js +0 -11
- package/dist/utils/createUnknownServiceError.js.map +0 -1
- /package/dist/{instance.d.ts → Instance.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -55,6 +55,24 @@ action. A ground principle is that nothing that enters Integreat from an
|
|
|
55
55
|
authenticated service, will leave Integreat unauthenticated. What this means,
|
|
56
56
|
though, depends on how you define your services.
|
|
57
57
|
|
|
58
|
+
# Table of contents
|
|
59
|
+
|
|
60
|
+
1. [Usage](#usage)
|
|
61
|
+
1. [Install](#install)
|
|
62
|
+
2. [Basic example](#basic-example)
|
|
63
|
+
2. [Integreat concepts](#integreat-concepts)
|
|
64
|
+
1. [Services](#services)
|
|
65
|
+
2. [Transporters](#transporters)
|
|
66
|
+
3. [Adapters](#adapters)
|
|
67
|
+
4. [Authenticators](#authenticators)
|
|
68
|
+
5. [Mutations](#mutations)
|
|
69
|
+
6. [Schemas](#schemas)
|
|
70
|
+
7. [Actions](#actions)
|
|
71
|
+
8. [Jobs](#jobs)
|
|
72
|
+
9. [Queues](#queues)
|
|
73
|
+
10. [Middleware](#middleware)
|
|
74
|
+
3. [Debugging](#debugging)
|
|
75
|
+
|
|
58
76
|
# Usage
|
|
59
77
|
|
|
60
78
|
## Install
|
|
@@ -523,34 +541,28 @@ This definition format is used to authenticate with a service:
|
|
|
523
541
|
authenticator: <authenticator id>,
|
|
524
542
|
options: {
|
|
525
543
|
// ...
|
|
526
|
-
}
|
|
544
|
+
},
|
|
545
|
+
overrideAuthAsMethod: <auth-as method>,
|
|
527
546
|
}
|
|
528
547
|
```
|
|
529
548
|
|
|
530
549
|
- `id`: The id used to reference this authentication, especially from the
|
|
531
550
|
[service definition](#services).
|
|
532
|
-
- `authenticator`: The id of an authenticator used to
|
|
533
|
-
Integreat comes with a few basic ones built in, and
|
|
534
|
-
available.
|
|
551
|
+
- `authenticator`: The id of an [authenticator](#authenticators) used to
|
|
552
|
+
authenticate requests. Integreat comes with a few basic ones built in, and
|
|
553
|
+
there are others available.
|
|
535
554
|
- `options`: An object of values meaningful to the authenticator. See the
|
|
536
555
|
documentation of each authenticator to learn how it should be configured.
|
|
556
|
+
- `overrideAuthAsMethod`: Transporters specify a default method for getting an
|
|
557
|
+
auth object that makes sense for authenticating with the service. For
|
|
558
|
+
instance, the HTTP transporter has `asHttpHeaders` as the default, to get the
|
|
559
|
+
relevant auth headers to send with the request. With `overrideAuthAsMethod`,
|
|
560
|
+
you may override this in the service auth definition when relevant. Default
|
|
561
|
+
value is `undefined`, meaning "no override". Note that we say "method" here,
|
|
562
|
+
but the value is a string with the name of the auth-as method to use.
|
|
537
563
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
- `ident`: Will always grant access and `validate()` will return an ident with
|
|
541
|
-
the id provided in `identId` on the `options` object, or `'anonymous'` if no
|
|
542
|
-
`identId` is provided. This is built into Integreat.
|
|
543
|
-
- `options`: Will pass on the options as authentication, so whatever you provide
|
|
544
|
-
here is the authentication. What options to provide, then, is depending on
|
|
545
|
-
what the relevant transporter requires. This is built into Integreat.
|
|
546
|
-
- `token`: A simple way of authenticating with a given token. For HTTP requests,
|
|
547
|
-
the token will be provided as a `Authorization` header, and a configurable
|
|
548
|
-
prefix like `Basic` or `Bearer`. This is built into Integreat.
|
|
549
|
-
- [`jwt`](https://github.com/integreat-io/integreat-authenticator-jwt): Will
|
|
550
|
-
generate and encode a JavaScript Web Token (JWT) based on the options.
|
|
551
|
-
- [`oauth2`](https://github.com/integreat-io/integreat-authenticator-oauth2):
|
|
552
|
-
Will run the balett of calling different OAuth2 endpoints and receive a token
|
|
553
|
-
based on the provided options.
|
|
564
|
+
The authenticator is responsible for doing all the heavy-lifting, based on the
|
|
565
|
+
options provided in the service authentication definition.
|
|
554
566
|
|
|
555
567
|
### Configuring service metadata
|
|
556
568
|
|
|
@@ -642,6 +654,61 @@ Integreat currently have the following adapters:
|
|
|
642
654
|
|
|
643
655
|
You may write your own adapters as well, and documentation on this is coming.
|
|
644
656
|
|
|
657
|
+
## Authenticators
|
|
658
|
+
|
|
659
|
+
At its simplest, an authenticator will provide necessary credientials to an
|
|
660
|
+
outgoing action, or an ident to an incoming action. Some authenticators do this
|
|
661
|
+
based only on the options provided, while others will do a more complex dance
|
|
662
|
+
with the service or a third-party service, like with OAuth2.
|
|
663
|
+
|
|
664
|
+
When [setting up a service](#services), you may provide it with an auth id that
|
|
665
|
+
refers to a [service authentication definition](#service-authentication), that
|
|
666
|
+
again refers to an authenticator by id. The service auth definition also holds
|
|
667
|
+
options for the authenticator, so when assigning an auth id to a service, you're
|
|
668
|
+
assigning it an authenticator with those specific options. Another service may
|
|
669
|
+
use the same authenticator, but with different options, and you would set this
|
|
670
|
+
up with a different service authentication definition.
|
|
671
|
+
|
|
672
|
+
Authentication for outgoing actions are done when sending the action. When
|
|
673
|
+
authenticated, an auth object is retrieved with the auth-as method specified on
|
|
674
|
+
the transporter (e.g. `asHttpHeaders` for the http transporter), or on the
|
|
675
|
+
`overrideAuthAsMethod` in [auth options](#service-authentication) if set. The
|
|
676
|
+
auth object is passed to the transporter on the action `meta.auth` prop. It is
|
|
677
|
+
applied just before sending it, though, so it will be available to service
|
|
678
|
+
middleware, but not to the mutation pipeline. This is done to expose credentials
|
|
679
|
+
in as few places as possible. If you however _want_ to have the auth object in
|
|
680
|
+
mutations, set `authInData` to `true` on the service or endpoint options, and
|
|
681
|
+
authentication will be done in the `preflightAction` step instead, making it
|
|
682
|
+
available on `meta.auth` throughout the entire mutation pipeline.
|
|
683
|
+
|
|
684
|
+
For incoming actions, authentication is done when a listening action calls the
|
|
685
|
+
`authenticate()` callback. The `validate()` method on the authenticator is used
|
|
686
|
+
here, which will provide the transporter with an authorized ident.
|
|
687
|
+
|
|
688
|
+
Available authenticators:
|
|
689
|
+
|
|
690
|
+
- `http`: Supports http native authentications, like `Basic` and `Bearer`. It's
|
|
691
|
+
included with the
|
|
692
|
+
[HTTP transporter](https://github.com/integreat-io/integreat-transporter-http).
|
|
693
|
+
- `ident`: Will always grant access and `validate()` will return an ident with
|
|
694
|
+
the id provided in `identId` on the `options` object, or `'anonymous'` if no
|
|
695
|
+
`identId` is provided. This is built into Integreat.
|
|
696
|
+
- `options`: Will pass on the options as authentication, so whatever you provide
|
|
697
|
+
here is the authentication. What options to provide, then, is depending on
|
|
698
|
+
what the relevant transporter requires. For outgoing actions, the options are
|
|
699
|
+
provided as is. Incoming action are validated agains the values given in the
|
|
700
|
+
options (the keys may be dot notation paths in this case, and `identId` is
|
|
701
|
+
excluded). An ident with the `identId` from the options as `id`, is returned
|
|
702
|
+
if the action matches. This is built into Integreat.
|
|
703
|
+
- `token`: A simple way of authenticating with a given token. For HTTP requests,
|
|
704
|
+
the token will be provided as a `Authorization` header, and a configurable
|
|
705
|
+
prefix like `Basic` or `Bearer`. This is built into Integreat.
|
|
706
|
+
- [`jwt`](https://github.com/integreat-io/integreat-authenticator-jwt): Will
|
|
707
|
+
generate and encode a JavaScript Web Token (JWT) based on the options.
|
|
708
|
+
- [`oauth2`](https://github.com/integreat-io/integreat-authenticator-oauth2):
|
|
709
|
+
Will run the balett of calling different OAuth2 endpoints and receive a token
|
|
710
|
+
based on the provided options.
|
|
711
|
+
|
|
645
712
|
## Mutations
|
|
646
713
|
|
|
647
714
|
Both on the service and on endpoints, you define mutation pipelines. The service
|
|
@@ -742,10 +809,6 @@ A double carret `^^` takes you to the top -- the root -- so after
|
|
|
742
809
|
Carret notations -- parents and roots -- does not currently work in reverse, but
|
|
743
810
|
they might in a future version.
|
|
744
811
|
|
|
745
|
-
### Jobs
|
|
746
|
-
|
|
747
|
-
> Editor's note: Write this.
|
|
748
|
-
|
|
749
812
|
## Schemas
|
|
750
813
|
|
|
751
814
|
A central idea to Integreat, is that any integration has two sides; the getting
|
|
@@ -804,7 +867,8 @@ automatically cast to that type.
|
|
|
804
867
|
[the section below](#the-shape-of-a-schema).
|
|
805
868
|
- `generateId`: Set this to `true` to generate a unique id for the `id` field
|
|
806
869
|
when the data being cast does not provide an `id`. Default is `false`, which
|
|
807
|
-
will just set `id: null
|
|
870
|
+
will just set `id: null`. The id will be 36 chars and consist of A-Z, a-z,
|
|
871
|
+
0-9, underscore `'_'`, and hyphen `'-'`.
|
|
808
872
|
- `access`: Integreat lets you define authorization schemes per schema. All use
|
|
809
873
|
of data cast to a schema will then be controlled by the rules you set here.
|
|
810
874
|
See [Access rules](#access-rules) below for details on these rules. Note that
|
|
@@ -1315,15 +1379,15 @@ common codes:
|
|
|
1315
1379
|
|
|
1316
1380
|
An ident in Integreat is basically an id unique to one participant in the
|
|
1317
1381
|
security scheme. It is represented by an object that may also have other
|
|
1318
|
-
properties to describe the ident's
|
|
1319
|
-
to identities in other services.
|
|
1382
|
+
properties to describe the ident's access, like `roles`, or to make it possible
|
|
1383
|
+
to match to identities in other services.
|
|
1320
1384
|
|
|
1321
1385
|
Example ident:
|
|
1322
1386
|
|
|
1323
1387
|
```javascript
|
|
1324
1388
|
{
|
|
1325
1389
|
id: 'ident1',
|
|
1326
|
-
tokens: ['
|
|
1390
|
+
tokens: ['auth0|12345', 'github|23456'],
|
|
1327
1391
|
roles: ['admin']
|
|
1328
1392
|
}
|
|
1329
1393
|
```
|
|
@@ -1335,7 +1399,7 @@ Example ident:
|
|
|
1335
1399
|
services.
|
|
1336
1400
|
- `tokens`: A list of values that may identify this ident in other services. For
|
|
1337
1401
|
example, an api that uses Twitter OAuth to identify its users, may provide
|
|
1338
|
-
the `'
|
|
1402
|
+
the `'github|23456'` token in the example above, which will be replaced with
|
|
1339
1403
|
this ident when it enters Integreat.
|
|
1340
1404
|
- `roles`: A list of roles or permissions given to this ident. The roles are
|
|
1341
1405
|
custom defined per setup, and may be mapped to roles from other systems. When
|
|
@@ -1728,6 +1792,10 @@ already used by one of Integreat's built-in action handlers, the custom handler
|
|
|
1728
1792
|
will have precedence. So be careful when you choose an action type, if your
|
|
1729
1793
|
intention is not to replace an existing action handler.
|
|
1730
1794
|
|
|
1795
|
+
## Jobs
|
|
1796
|
+
|
|
1797
|
+
> **Editor's note:** Write this section.
|
|
1798
|
+
|
|
1731
1799
|
## Queues
|
|
1732
1800
|
|
|
1733
1801
|
As everything else in Integreat, a queue is also a service. You configure a
|
|
@@ -1872,7 +1940,7 @@ actions like this:
|
|
|
1872
1940
|
type: 'GET',
|
|
1873
1941
|
payload: {
|
|
1874
1942
|
type: 'user',
|
|
1875
|
-
tokens: '
|
|
1943
|
+
tokens: 'github|23456'
|
|
1876
1944
|
}
|
|
1877
1945
|
}
|
|
1878
1946
|
```
|
|
@@ -1895,7 +1963,7 @@ the ident with this id is loaded, otherwise a `withToken` is used to load the
|
|
|
1895
1963
|
ident with the specified token. If no ident is found, the original ident is
|
|
1896
1964
|
kept.
|
|
1897
1965
|
|
|
1898
|
-
|
|
1966
|
+
### Writing middleware
|
|
1899
1967
|
|
|
1900
1968
|
You may write middleware to intercept dispatched actions. This may be useful
|
|
1901
1969
|
for logging, debugging, and situations where you need to make adjustments to
|
|
@@ -1919,7 +1987,7 @@ const logger = (next) => async (action) => {
|
|
|
1919
1987
|
}
|
|
1920
1988
|
```
|
|
1921
1989
|
|
|
1922
|
-
|
|
1990
|
+
# Debugging
|
|
1923
1991
|
|
|
1924
1992
|
Run Integreat with env variable `DEBUG=great`, to receive debug messages.
|
|
1925
1993
|
|
package/dist/Instance.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import EventEmitter from 'node:events';
|
|
2
|
+
import Auth from './service/Auth.js';
|
|
3
|
+
import builtinHandlers from './handlers/index.js';
|
|
4
|
+
import runFn from './handlers/run.js';
|
|
5
|
+
import Schema from './schema/Schema.js';
|
|
6
|
+
import Service from './service/Service.js';
|
|
7
|
+
import { ensureArray } from './utils/array.js';
|
|
8
|
+
import createMapOptions from './utils/createMapOptions.js';
|
|
9
|
+
import { lookupById } from './utils/indexUtils.js';
|
|
10
|
+
import createDispatch from './dispatch.js';
|
|
11
|
+
import listen from './listen.js';
|
|
12
|
+
import close from './close.js';
|
|
13
|
+
import { indexById } from './utils/indexUtils.js';
|
|
14
|
+
import Job from './jobs/Job.js';
|
|
15
|
+
import createDispatchScheduled from './dispatchScheduled.js';
|
|
16
|
+
export const setUpAuth = (authenticators) => function setUpAuth(def) {
|
|
17
|
+
const authenticator = lookupById(def.authenticator, authenticators);
|
|
18
|
+
if (!authenticator) {
|
|
19
|
+
throw new Error(`Auth config '${def.id}' references an unknown authenticator id '${def.authenticator}'`);
|
|
20
|
+
}
|
|
21
|
+
return new Auth(def.id, authenticator, def.options, def.overrideAuthAsMethod);
|
|
22
|
+
};
|
|
23
|
+
const setAdapterIds = (adapters) => adapters
|
|
24
|
+
? Object.fromEntries(Object.entries(adapters).map(([id, adapter]) => [
|
|
25
|
+
id,
|
|
26
|
+
{ ...adapter, id },
|
|
27
|
+
]))
|
|
28
|
+
: {};
|
|
29
|
+
const isJobWithSchedule = (job) => !!job.schedule;
|
|
30
|
+
function prepareSchemas(schemaDefs) {
|
|
31
|
+
const schemas = new Map();
|
|
32
|
+
schemaDefs.forEach((def) => {
|
|
33
|
+
schemas.set(def.id, new Schema(def, schemas));
|
|
34
|
+
});
|
|
35
|
+
return schemas;
|
|
36
|
+
}
|
|
37
|
+
const setIdOnAuthenticators = (authenticators) => Object.fromEntries(Object.entries(authenticators ?? {}).map(([id, auth]) => [
|
|
38
|
+
id,
|
|
39
|
+
{ ...auth, id },
|
|
40
|
+
]));
|
|
41
|
+
const createAuthObjects = (authDefs, authenticators) => authDefs
|
|
42
|
+
.map(setUpAuth(authenticators))
|
|
43
|
+
.reduce(indexById, {});
|
|
44
|
+
function prepareJobs(jobDefs, mapOptions) {
|
|
45
|
+
const jobs = new Map();
|
|
46
|
+
ensureArray(jobDefs).forEach((job) => {
|
|
47
|
+
if (typeof job.id === 'string') {
|
|
48
|
+
jobs.set(job.id, new Job(job, mapOptions));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return jobs;
|
|
52
|
+
}
|
|
53
|
+
const combineHandlers = (handlers, jobs) => ({
|
|
54
|
+
...builtinHandlers,
|
|
55
|
+
...handlers,
|
|
56
|
+
RUN: runFn(jobs),
|
|
57
|
+
});
|
|
58
|
+
const handlerOptionsFromDefs = (defs) => ({
|
|
59
|
+
identConfig: defs.identConfig,
|
|
60
|
+
queueService: defs.queueService,
|
|
61
|
+
});
|
|
62
|
+
function createServices(defs, resources, schemas, mapOptions, middlewareForService, emit) {
|
|
63
|
+
const authenticators = setIdOnAuthenticators(resources.authenticators || {});
|
|
64
|
+
const auths = createAuthObjects(defs.auths || [], authenticators);
|
|
65
|
+
return defs.services
|
|
66
|
+
.map((def) => new Service(def, {
|
|
67
|
+
transporters: resources.transporters,
|
|
68
|
+
adapters: setAdapterIds(resources.adapters),
|
|
69
|
+
authenticators: authenticators,
|
|
70
|
+
auths,
|
|
71
|
+
schemas,
|
|
72
|
+
mapOptions,
|
|
73
|
+
middleware: middlewareForService,
|
|
74
|
+
emit,
|
|
75
|
+
}))
|
|
76
|
+
.reduce(indexById, {});
|
|
77
|
+
}
|
|
78
|
+
function setupServicesAndDispatch(defs, resources, schemas, middlewareForDispatch, middlewareForService, emit) {
|
|
79
|
+
const mapOptions = createMapOptions(schemas, defs.mutations, resources.transformers, defs.dictionaries);
|
|
80
|
+
const services = createServices(defs, resources, schemas, mapOptions, middlewareForService, emit);
|
|
81
|
+
const jobs = prepareJobs(defs.jobs || [], mapOptions);
|
|
82
|
+
const dispatch = createDispatch({
|
|
83
|
+
schemas,
|
|
84
|
+
services,
|
|
85
|
+
handlers: combineHandlers(resources.handlers || {}, jobs),
|
|
86
|
+
middleware: middlewareForDispatch,
|
|
87
|
+
options: handlerOptionsFromDefs(defs),
|
|
88
|
+
});
|
|
89
|
+
const dispatchScheduled = createDispatchScheduled(dispatch, [...jobs.values()].filter(isJobWithSchedule));
|
|
90
|
+
return { services, dispatch, dispatchScheduled };
|
|
91
|
+
}
|
|
92
|
+
export default class Instance extends EventEmitter {
|
|
93
|
+
id;
|
|
94
|
+
services;
|
|
95
|
+
schemas;
|
|
96
|
+
identType;
|
|
97
|
+
queueService;
|
|
98
|
+
dispatch;
|
|
99
|
+
dispatchScheduled;
|
|
100
|
+
constructor(defs, resources, middlewareForDispatch = [], middlewareForService = []) {
|
|
101
|
+
super();
|
|
102
|
+
if (!Array.isArray(defs.services) || !Array.isArray(defs.schemas)) {
|
|
103
|
+
throw new TypeError('Please provide Integreat with at least services and schemas');
|
|
104
|
+
}
|
|
105
|
+
this.id = defs.id;
|
|
106
|
+
this.identType = defs.identConfig?.type;
|
|
107
|
+
this.queueService = defs.queueService;
|
|
108
|
+
this.schemas = prepareSchemas(defs.schemas);
|
|
109
|
+
const { services, dispatch, dispatchScheduled } = setupServicesAndDispatch(defs, resources, this.schemas, middlewareForDispatch, middlewareForService, this.emit.bind(this));
|
|
110
|
+
this.services = services;
|
|
111
|
+
this.dispatch = dispatch;
|
|
112
|
+
this.dispatchScheduled = dispatchScheduled;
|
|
113
|
+
}
|
|
114
|
+
async listen() {
|
|
115
|
+
return listen(Object.values(this.services), this.dispatch);
|
|
116
|
+
}
|
|
117
|
+
async close() {
|
|
118
|
+
return close(Object.values(this.services));
|
|
119
|
+
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AC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;YACjE,MAAM,IAAI,SAAS,CACjB,6DAA6D,CAC9D,CAAA;SACF;QAED,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAA;QACjB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,IAAI,CAAA;QACvC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAA;QACrC,IAAI,CAAC,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAE3C,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,EAAE,GAAG,wBAAwB,CACxE,IAAI,EACJ,SAAS,EACT,IAAI,CAAC,OAAO,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CACrB,CAAA;QAED,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;IAC5C,CAAC;IAED,KAAK,CAAC,MAAM;QACV,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC5D,CAAC;IAED,KAAK,CAAC,KAAK;QACT,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAA;IAC5C,CAAC;CACF"}
|
|
@@ -1,4 +1,27 @@
|
|
|
1
|
+
import mapTransform from 'map-transform';
|
|
1
2
|
import { isObject } from '../utils/is.js';
|
|
3
|
+
const compareValues = (expected, value) => expected !== undefined && Array.isArray(expected)
|
|
4
|
+
? expected.includes(value)
|
|
5
|
+
: expected === value;
|
|
6
|
+
const getIsMatchCount = (matches) => matches.filter(([match]) => !!match).length;
|
|
7
|
+
const getHasPropsCount = (matches) => matches.filter(([, exists]) => !!exists).length;
|
|
8
|
+
async function validateOptions(options, action) {
|
|
9
|
+
if (action === null) {
|
|
10
|
+
return [false, false];
|
|
11
|
+
}
|
|
12
|
+
const pathAndExpectedArr = Object.entries(options);
|
|
13
|
+
if (pathAndExpectedArr.length === 0) {
|
|
14
|
+
return [true, false];
|
|
15
|
+
}
|
|
16
|
+
const matches = await Promise.all(pathAndExpectedArr.map(async function ([path, expected]) {
|
|
17
|
+
const value = await mapTransform(path)(action);
|
|
18
|
+
return [compareValues(expected, value), value !== undefined];
|
|
19
|
+
}));
|
|
20
|
+
return [
|
|
21
|
+
getIsMatchCount(matches) === pathAndExpectedArr.length,
|
|
22
|
+
getHasPropsCount(matches) > 0,
|
|
23
|
+
];
|
|
24
|
+
}
|
|
2
25
|
const optionsAuth = {
|
|
3
26
|
async authenticate(options) {
|
|
4
27
|
return { status: 'granted', ...options };
|
|
@@ -6,6 +29,26 @@ const optionsAuth = {
|
|
|
6
29
|
isAuthenticated(authentication, _options, _action) {
|
|
7
30
|
return !!(authentication && authentication.status === 'granted');
|
|
8
31
|
},
|
|
32
|
+
async validate(_authentication, options, action) {
|
|
33
|
+
const { identId, ...authOptions } = options || {};
|
|
34
|
+
const [isValid, hasProps] = await validateOptions(authOptions, action);
|
|
35
|
+
if (isValid) {
|
|
36
|
+
return { status: 'ok', access: { ident: { id: identId } } };
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return hasProps
|
|
40
|
+
? {
|
|
41
|
+
status: 'autherror',
|
|
42
|
+
error: 'Invalid credentials',
|
|
43
|
+
reason: 'invalidauth',
|
|
44
|
+
}
|
|
45
|
+
: {
|
|
46
|
+
status: 'noaccess',
|
|
47
|
+
error: 'Authentication required',
|
|
48
|
+
reason: 'noauth',
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
},
|
|
9
52
|
authentication: {
|
|
10
53
|
asObject(authentication) {
|
|
11
54
|
if (isObject(authentication)) {
|
|
@@ -1 +1 @@
|
|
|
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,EAAE,QAAQ,EAAE,OAAO;QAC/C,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"}
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/authenticators/options.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAQzC,MAAM,aAAa,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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"}
|
package/dist/dispatch.js
CHANGED
|
@@ -3,7 +3,8 @@ import pProgress from 'p-progress';
|
|
|
3
3
|
import debugLib from 'debug';
|
|
4
4
|
import { QUEUE_SYMBOL } from './handlers/index.js';
|
|
5
5
|
import setupGetService from './utils/getService.js';
|
|
6
|
-
import { setErrorOnAction,
|
|
6
|
+
import { setErrorOnAction, setResponseOnAction, setOptionsOnAction, } from './utils/action.js';
|
|
7
|
+
import { createErrorResponse, setOrigin } from './utils/response.js';
|
|
7
8
|
const debug = debugLib('great');
|
|
8
9
|
export const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
|
|
9
10
|
const shouldQueue = (action, options) => action.meta?.queue === true && !!options.queueService;
|
package/dist/dispatch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../src/dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,SAAS,MAAM,YAAY,CAAA;AAClC,OAAO,QAAQ,MAAM,OAAO,CAAA;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,eAAe,MAAM,uBAAuB,CAAA;AACnD,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../src/dispatch.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C,EAAE;oBAGnC,QAAQ,GAAG,MAAM,YAAY,CAC3B,YAAY,EACZ,MAAM,EACN,SAAS,EACT,QAAQ,CACT,CAAA;iBACF;qBAAM;oBAGL,MAAM,IAAI,GAAG,KAAK,EAAE,MAAc,EAAE,EAAE,CACpC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAA;oBACxD,QAAQ,GAAG,SAAS,CAClB,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,EAChC,qBAAqB,CACtB,CAAA;iBACF;aACF;YAAC,OAAO,GAAG,EAAE;gBACZ,QAAQ,GAAG,mBAAmB,CAC5B,6BACE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CACjD,EAAE,EACF,UAAU,CACX,CAAA;aACF;SACF;QAED,OAAO,oCAAoC,CACzC,MAAM,sBAAsB,CAC1B,mBAAmB,CAAC,SAAS,EAAE,QAAQ,CAAC,EACxC,eAAe,EACf,gBAAgB,CACjB,EACD,MAAM,CAAC,IAAI,EAAE,KAAK,CACnB,CAAA;IACH,CAAC,CAAC,CAAA;IAEJ,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
package/dist/handlers/delete.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import debugLib from 'debug';
|
|
2
2
|
import mutateAndSend from '../utils/mutateAndSend.js';
|
|
3
3
|
import { isTypedData } from '../utils/is.js';
|
|
4
|
-
import { setDataOnActionPayload
|
|
5
|
-
import createUnknownServiceError from '../utils/
|
|
4
|
+
import { setDataOnActionPayload } from '../utils/action.js';
|
|
5
|
+
import { createErrorResponse, createUnknownServiceError, } from '../utils/response.js';
|
|
6
6
|
const debug = debugLib('great');
|
|
7
7
|
const prepareData = ({ type, id, data }) => type && id
|
|
8
8
|
? { id, $type: type }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../src/handlers/delete.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,OAAO,CAAA;AAC5B,OAAO,aAAa,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../src/handlers/delete.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,OAAO,CAAA;AAC5B,OAAO,aAAa,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,EACL,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAA;AAQ7B,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;AAE/B,MAAM,WAAW,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAW,EAAE,EAAE,CAClD,IAAI,IAAI,EAAE;IACR,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE;IACrB,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QACrB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QAC1B,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC;YACnB,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,SAAS,CAAA;AAKf,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,QAAQ,CACpC,MAAc,EACd,EAAE,UAAU,EAA0B;IAEtC,MAAM,EACJ,IAAI,EACJ,EAAE,EACF,aAAa,EAAE,SAAS,EACxB,QAAQ,EAAE,UAAU,GACrB,GAAG,MAAM,CAAC,OAAO,CAAA;IAElB,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;IAC3C,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,yBAAyB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAA;KAC5D;IAED,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACxC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE;QACvD,OAAO,mBAAmB,CACxB,oCAAoC,OAAO,CAAC,EAAE,GAAG,EACjD,gBAAgB,EAChB,UAAU,CACX,CAAA;KACF;IAED,MAAM,aAAa,GAAG,UAAU;QAC9B,CAAC,CAAC,aAAa,UAAU,GAAG;QAC5B,CAAC,CAAC,qBAAqB,IAAI,QAAQ,EAAE,EAAE,CAAA;IACzC,KAAK,CAAC,yCAAyC,EAAE,OAAO,CAAC,EAAE,EAAE,aAAa,CAAC,CAAA;IAE3E,MAAM,UAAU,GAAG,sBAAsB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IACvD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAA;IAC7D,IAAI,CAAC,QAAQ,EAAE;QACb,OAAO,mBAAmB,CACxB,wBAAwB,UAAU,CAAC,IAAI,wBAAwB,SAAS,IAAI,EAC5E,gBAAgB,EAChB,YAAY,CACb,CAAA;KACF;IAED,OAAO,MAAM,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAA;AAC3D,CAAC"}
|
package/dist/handlers/expire.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createErrorResponse } from '../utils/
|
|
1
|
+
import { createErrorResponse } from '../utils/response.js';
|
|
2
2
|
import { isTypedData } from '../utils/is.js';
|
|
3
3
|
const isTypedDataArray = (value) => Array.isArray(value) && isTypedData(value[0]);
|
|
4
4
|
const getExpired = async (targetService, type, endpointId, msFromNow, dispatch, cid, ident) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expire.js","sourceRoot":"","sources":["../../src/handlers/expire.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"expire.js","sourceRoot":"","sources":["../../src/handlers/expire.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAU5C,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAwB,EAAE,CAChE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAE/C,MAAM,UAAU,GAAG,KAAK,EACtB,aAAqB,EACrB,IAAuB,EACvB,UAAkB,EAClB,SAAiB,EACjB,QAAyB,EACzB,GAAY,EACZ,KAAa,EACM,EAAE;IACrB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAA;IACxC,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAA;IACjD,OAAO,QAAQ,CAAC;QACd,IAAI,EAAE,KAAK;QACX,OAAO,EAAE;YACP,IAAI;YACJ,SAAS;YACT,OAAO;YACP,aAAa;YACb,QAAQ,EAAE,UAAU;SACrB;QACD,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE;KACrB,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,MAAM,aAAa,GAAG,KAAK,EACzB,IAAiB,EACjB,aAAqB,EACrB,QAAyB,EACzB,GAAY,EACZ,KAAa,EACM,EAAE;IACrB,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAA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CAAC,KAAK,EAAE,EAC7G,gBAAgB,CACjB,CAAA;KACF;IACD,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,CAAA;IACjC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE;QAC3B,OAAO,mBAAmB,CACxB,oCAAoC,SAAS,GAAG,EAChD,gBAAgB,EAChB,UAAU,CACX,CAAA;KACF;IAED,OAAO,MAAM,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;AACnE,CAAC"}
|
package/dist/handlers/get.js
CHANGED
|
@@ -1,62 +1,56 @@
|
|
|
1
1
|
import debugLib from 'debug';
|
|
2
2
|
import pLimit from 'p-limit';
|
|
3
|
-
import { createErrorResponse,
|
|
4
|
-
import
|
|
5
|
-
import { isAuthorizedAction } from '../service/utils/authAction.js';
|
|
3
|
+
import { createErrorResponse, createUnknownServiceError, combineResponses, setOrigin, } from '../utils/response.js';
|
|
4
|
+
import mutateAndSend from '../utils/mutateAndSend.js';
|
|
6
5
|
const debug = debugLib('great');
|
|
7
6
|
const isErrorResponse = (response) => response.status !== 'ok' && response.status !== 'notfound';
|
|
8
7
|
const getIdFromAction = ({ payload: { id } }) => Array.isArray(id) && id.length === 1 ? id[0] : id;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
function combineIndividualResponses(action, responses) {
|
|
9
|
+
const errorResponses = responses.filter(isErrorResponse);
|
|
10
|
+
if (errorResponses.length > 0) {
|
|
11
|
+
const combinedResponse = combineResponses(errorResponses);
|
|
12
|
+
return setOrigin({
|
|
13
|
+
...combinedResponse,
|
|
14
|
+
error: `One or more of the requests for ids ${getIdFromAction(action)} failed with the following error(s): ${combinedResponse.error}`,
|
|
15
|
+
}, 'handler:GET');
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return {
|
|
19
|
+
...action.response,
|
|
20
|
+
status: 'ok',
|
|
21
|
+
data: responses.map((response) => Array.isArray(response.data) ? response.data[0] : response.data),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
16
25
|
const isMembersScope = (endpoint) => endpoint?.match?.scope === 'members';
|
|
17
26
|
const setIdOnActionPayload = (action, id) => ({
|
|
18
27
|
...action,
|
|
19
28
|
payload: { ...action.payload, id },
|
|
20
29
|
});
|
|
21
30
|
const createNoEndpointError = (action, serviceId) => createErrorResponse(`No endpoint matching ${action.type} request to service '${serviceId}'.`, 'handler:GET', 'badrequest');
|
|
22
|
-
async function runAsIndividualActions(action, service
|
|
23
|
-
const actions = action.payload.id.map((
|
|
31
|
+
async function runAsIndividualActions(action, service) {
|
|
32
|
+
const actions = action.payload.id.map((individualId) => setIdOnActionPayload(action, individualId));
|
|
24
33
|
const endpoint = await service.endpointFromAction(actions[0]);
|
|
25
34
|
if (!endpoint) {
|
|
26
35
|
return createNoEndpointError(action, service.id);
|
|
27
36
|
}
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
return service.mutateResponse(setResponseOnAction(action, validateResponse), endpoint);
|
|
31
|
-
}
|
|
32
|
-
return combineResponses(action, await Promise.all(actions.map((action) => pLimit(1)(() => mapPerId(endpoint)(action)))));
|
|
37
|
+
const responses = await Promise.all(actions.map((individualAction) => pLimit(1)(() => mutateAndSend(service, endpoint, individualAction))));
|
|
38
|
+
return combineIndividualResponses(action, responses);
|
|
33
39
|
}
|
|
34
40
|
const doRunIndividualIds = (action, endpoint) => Array.isArray(action.payload.id) &&
|
|
35
|
-
isAuthorizedAction(action) &&
|
|
36
41
|
!isMembersScope(endpoint);
|
|
37
|
-
async function runOneOrMany(action, service
|
|
42
|
+
async function runOneOrMany(action, service) {
|
|
38
43
|
const endpoint = await service.endpointFromAction(action);
|
|
39
44
|
if (!endpoint) {
|
|
40
45
|
return createNoEndpointError(action, service.id);
|
|
41
46
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return await service.mutateResponse(authorizedAction, endpoint);
|
|
45
|
-
}
|
|
46
|
-
if (doRunIndividualIds(authorizedAction, endpoint)) {
|
|
47
|
-
return runAsIndividualActions(authorizedAction, service, mapPerId);
|
|
47
|
+
if (doRunIndividualIds(action, endpoint)) {
|
|
48
|
+
return runAsIndividualActions(action, service);
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return service.mutateResponse(setResponseOnAction(authorizedAction, validateResponse), endpoint);
|
|
50
|
+
else {
|
|
51
|
+
return mutateAndSend(service, endpoint, action);
|
|
52
52
|
}
|
|
53
|
-
return mapPerId(endpoint)(authorizedAction);
|
|
54
53
|
}
|
|
55
|
-
const runOne = (service) => (endpoint) => async function (action) {
|
|
56
|
-
const requestAction = await service.mutateRequest(action, endpoint);
|
|
57
|
-
const response = await service.send(requestAction);
|
|
58
|
-
return await service.mutateResponse(setResponseOnAction(action, response), endpoint);
|
|
59
|
-
};
|
|
60
54
|
export default async function get(action, { getService }) {
|
|
61
55
|
const { type, targetService: serviceId, endpoint: endpointId, } = action.payload;
|
|
62
56
|
const id = getIdFromAction(action);
|
|
@@ -72,6 +66,6 @@ export default async function get(action, { getService }) {
|
|
|
72
66
|
: `endpoint matching type '${type}' and id '${id}'`;
|
|
73
67
|
debug('GET: Fetch from service %s at %s', service.id, endpointDebug);
|
|
74
68
|
const nextAction = setIdOnActionPayload(action, id);
|
|
75
|
-
return await runOneOrMany(nextAction, service
|
|
69
|
+
return await runOneOrMany(nextAction, service);
|
|
76
70
|
}
|
|
77
71
|
//# sourceMappingURL=get.js.map
|
package/dist/handlers/get.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../src/handlers/get.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,OAAO,CAAA;AAC5B,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,
|
|
1
|
+
{"version":3,"file":"get.js","sourceRoot":"","sources":["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CAAC,CAAA;KACzD;IAED,MAAM,aAAa,GAAG,UAAU;QAC9B,CAAC,CAAC,aAAa,UAAU,GAAG;QAC5B,CAAC,CAAC,2BAA2B,IAAI,aAAa,EAAE,GAAG,CAAA;IACrD,KAAK,CAAC,kCAAkC,EAAE,OAAO,CAAC,EAAE,EAAE,aAAa,CAAC,CAAA;IAEpE,MAAM,UAAU,GAAG,oBAAoB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAEnD,OAAO,MAAM,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;AAChD,CAAC"}
|
package/dist/handlers/getAll.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createErrorResponse, setOrigin } from '../utils/
|
|
1
|
+
import { createErrorResponse, setOrigin } from '../utils/response.js';
|
|
2
2
|
import { isObject, isTypedData } from '../utils/is.js';
|
|
3
3
|
const extractLastId = (data, field = 'id') => Array.isArray(data) && isObject(data[data.length - 1])
|
|
4
4
|
?
|