jinaga-server 1.0.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/LICENSE +22 -0
- package/dist/authentication/authentication-device.d.ts +20 -0
- package/dist/authentication/authentication-device.js +61 -0
- package/dist/authentication/authentication-device.js.map +1 -0
- package/dist/authentication/authentication-impl.d.ts +21 -0
- package/dist/authentication/authentication-impl.js +61 -0
- package/dist/authentication/authentication-impl.js.map +1 -0
- package/dist/authentication/authentication-session.d.ts +23 -0
- package/dist/authentication/authentication-session.js +85 -0
- package/dist/authentication/authentication-session.js.map +1 -0
- package/dist/authentication/authentication.d.ts +5 -0
- package/dist/authentication/authentication.js +3 -0
- package/dist/authentication/authentication.js.map +1 -0
- package/dist/authentication.d.ts +17 -0
- package/dist/authentication.js +52 -0
- package/dist/authentication.js.map +1 -0
- package/dist/authorization/authorization-keystore.d.ts +13 -0
- package/dist/authorization/authorization-keystore.js +61 -0
- package/dist/authorization/authorization-keystore.js.map +1 -0
- package/dist/http/node-http.d.ts +7 -0
- package/dist/http/node-http.js +126 -0
- package/dist/http/node-http.js.map +1 -0
- package/dist/http/router.d.ts +20 -0
- package/dist/http/router.js +223 -0
- package/dist/http/router.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/jinaga-server.d.ts +18 -0
- package/dist/jinaga-server.js +101 -0
- package/dist/jinaga-server.js.map +1 -0
- package/dist/keystore.d.ts +9 -0
- package/dist/keystore.js +3 -0
- package/dist/keystore.js.map +1 -0
- package/dist/memory/memory-keystore.d.ts +16 -0
- package/dist/memory/memory-keystore.js +86 -0
- package/dist/memory/memory-keystore.js.map +1 -0
- package/dist/postgres/connection.d.ts +12 -0
- package/dist/postgres/connection.js +83 -0
- package/dist/postgres/connection.js.map +1 -0
- package/dist/postgres/edge-record.d.ts +9 -0
- package/dist/postgres/edge-record.js +30 -0
- package/dist/postgres/edge-record.js.map +1 -0
- package/dist/postgres/maps.d.ts +21 -0
- package/dist/postgres/maps.js +86 -0
- package/dist/postgres/maps.js.map +1 -0
- package/dist/postgres/postgres-keystore.d.ts +20 -0
- package/dist/postgres/postgres-keystore.js +168 -0
- package/dist/postgres/postgres-keystore.js.map +1 -0
- package/dist/postgres/postgres-store.d.ts +20 -0
- package/dist/postgres/postgres-store.js +717 -0
- package/dist/postgres/postgres-store.js.map +1 -0
- package/dist/postgres/query-description-builder.d.ts +13 -0
- package/dist/postgres/query-description-builder.js +104 -0
- package/dist/postgres/query-description-builder.js.map +1 -0
- package/dist/postgres/query-description.d.ts +71 -0
- package/dist/postgres/query-description.js +256 -0
- package/dist/postgres/query-description.js.map +1 -0
- package/dist/postgres/specification-result-sql.d.ts +41 -0
- package/dist/postgres/specification-result-sql.js +260 -0
- package/dist/postgres/specification-result-sql.js.map +1 -0
- package/dist/postgres/specification-sql.d.ts +3 -0
- package/dist/postgres/specification-sql.js +119 -0
- package/dist/postgres/specification-sql.js.map +1 -0
- package/dist/postgres/sql.d.ts +10 -0
- package/dist/postgres/sql.js +396 -0
- package/dist/postgres/sql.js.map +1 -0
- package/dist/util/fn.d.ts +6 -0
- package/dist/util/fn.js +81 -0
- package/dist/util/fn.js.map +1 -0
- package/dist/util/promise.d.ts +1 -0
- package/dist/util/promise.js +10 -0
- package/dist/util/promise.js.map +1 -0
- package/docs/registrations.sql +22 -0
- package/docs/specification.txt +41 -0
- package/docs/sql-generator.gv +25 -0
- package/integration-test/docker-compose.yaml +13 -0
- package/integration-test/jinaga-test/Dockerfile +12 -0
- package/integration-test/jinaga-test/jinaga.test.js +425 -0
- package/integration-test/jinaga-test/package-lock.json +6767 -0
- package/integration-test/jinaga-test/package.json +25 -0
- package/integration-test/postgres/0-init-app-db.sh +16 -0
- package/integration-test/postgres/1-setup.sql +219 -0
- package/integration-test/postgres/2-grant.sh +17 -0
- package/integration-test/postgres/Dockerfile +5 -0
- package/integration-test/run.sh +17 -0
- package/integration-test/start_db.sh +2 -0
- package/integration-test/stop_db.sh +3 -0
- package/integration-test/test.sh +8 -0
- package/interactive/index.js +56 -0
- package/jest.config.js +12 -0
- package/package.json +51 -0
- package/scripts/combined.sql +46 -0
- package/scripts/cte.sql +55 -0
- package/scripts/separate.sql +27 -0
- package/setup.sh +34 -0
- package/setup.sql +329 -0
- package/src/authentication/authentication-device.ts +68 -0
- package/src/authentication/authentication-impl.ts +59 -0
- package/src/authentication/authentication-session.ts +95 -0
- package/src/authentication/authentication.ts +6 -0
- package/src/authentication.ts +45 -0
- package/src/authorization/authorization-keystore.ts +67 -0
- package/src/http/node-http.ts +106 -0
- package/src/http/router.ts +237 -0
- package/src/index.ts +1 -0
- package/src/jinaga-server.ts +125 -0
- package/src/keystore.ts +10 -0
- package/src/memory/memory-keystore.ts +93 -0
- package/src/postgres/connection.ts +73 -0
- package/src/postgres/edge-record.ts +36 -0
- package/src/postgres/maps.ts +89 -0
- package/src/postgres/postgres-keystore.ts +167 -0
- package/src/postgres/postgres-store.ts +874 -0
- package/src/postgres/query-description-builder.ts +116 -0
- package/src/postgres/query-description.ts +385 -0
- package/src/postgres/specification-result-sql.ts +362 -0
- package/src/postgres/specification-sql.ts +138 -0
- package/src/postgres/sql.ts +482 -0
- package/src/util/fn.ts +63 -0
- package/src/util/promise.ts +5 -0
- package/test/authorization/authorizationSpec.ts +209 -0
- package/test/postgres/postgresSpec.ts +385 -0
- package/test/postgres/postgresSpecificationSpec.ts +742 -0
- package/test/reporter.js +25 -0
- package/tsconfig.json +25 -0
- package/upgrade.sh +21 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Michael L Perry
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Channel, FactEnvelope, FactRecord, FactReference, Fork, LoginResponse, Observable, Query, Specification, UserIdentity } from "jinaga";
|
|
2
|
+
import { Keystore } from "../keystore";
|
|
3
|
+
import { Authentication } from "./authentication";
|
|
4
|
+
export declare class AuthenticationDevice implements Authentication {
|
|
5
|
+
private inner;
|
|
6
|
+
private keystore;
|
|
7
|
+
private localDeviceIdentity;
|
|
8
|
+
constructor(inner: Fork, keystore: Keystore, localDeviceIdentity: UserIdentity);
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
login(): Promise<LoginResponse>;
|
|
11
|
+
local(): Promise<FactRecord>;
|
|
12
|
+
from(fact: FactReference, query: Query): Observable;
|
|
13
|
+
save(envelopes: FactEnvelope[]): Promise<FactEnvelope[]>;
|
|
14
|
+
query(start: FactReference, query: Query): Promise<FactReference[][]>;
|
|
15
|
+
read(start: FactReference[], specification: Specification): Promise<any[]>;
|
|
16
|
+
whichExist(references: FactReference[]): Promise<FactReference[]>;
|
|
17
|
+
load(references: FactReference[]): Promise<FactRecord[]>;
|
|
18
|
+
addChannel(fact: FactReference, query: Query): Channel;
|
|
19
|
+
removeChannel(channel: Channel): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuthenticationDevice = void 0;
|
|
13
|
+
class AuthenticationDevice {
|
|
14
|
+
constructor(inner, keystore, localDeviceIdentity) {
|
|
15
|
+
this.inner = inner;
|
|
16
|
+
this.keystore = keystore;
|
|
17
|
+
this.localDeviceIdentity = localDeviceIdentity;
|
|
18
|
+
}
|
|
19
|
+
close() {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
yield this.inner.close();
|
|
22
|
+
yield this.keystore.close();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
login() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
throw new Error('No logged in user.');
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
local() {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
return yield this.keystore.getOrCreateDeviceFact(this.localDeviceIdentity);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
from(fact, query) {
|
|
36
|
+
return this.inner.from(fact, query);
|
|
37
|
+
}
|
|
38
|
+
save(envelopes) {
|
|
39
|
+
return this.inner.save(envelopes);
|
|
40
|
+
}
|
|
41
|
+
query(start, query) {
|
|
42
|
+
return this.inner.query(start, query);
|
|
43
|
+
}
|
|
44
|
+
read(start, specification) {
|
|
45
|
+
return this.inner.read(start, specification);
|
|
46
|
+
}
|
|
47
|
+
whichExist(references) {
|
|
48
|
+
throw new Error("whichExist method not implemented on AuthenticationDevice.");
|
|
49
|
+
}
|
|
50
|
+
load(references) {
|
|
51
|
+
return this.inner.load(references);
|
|
52
|
+
}
|
|
53
|
+
addChannel(fact, query) {
|
|
54
|
+
return this.inner.addChannel(fact, query);
|
|
55
|
+
}
|
|
56
|
+
removeChannel(channel) {
|
|
57
|
+
return this.inner.removeChannel(channel);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.AuthenticationDevice = AuthenticationDevice;
|
|
61
|
+
//# sourceMappingURL=authentication-device.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication-device.js","sourceRoot":"","sources":["../../src/authentication/authentication-device.ts"],"names":[],"mappings":";;;;;;;;;;;;AAgBA,MAAa,oBAAoB;IAC7B,YACY,KAAW,EACX,QAAkB,EAClB,mBAAiC;QAFjC,UAAK,GAAL,KAAK,CAAM;QACX,aAAQ,GAAR,QAAQ,CAAU;QAClB,wBAAmB,GAAnB,mBAAmB,CAAc;IAC1C,CAAC;IAEE,KAAK;;YACP,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACzB,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QAChC,CAAC;KAAA;IAEK,KAAK;;YACP,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAC1C,CAAC;KAAA;IAEK,KAAK;;YACP,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC/E,CAAC;KAAA;IAED,IAAI,CAAC,IAAmB,EAAE,KAAY;QAClC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IAED,IAAI,CAAC,SAAyB;QAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,KAAoB,EAAE,KAAY;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,CAAC,KAAsB,EAAE,aAA4B;QACrD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACjD,CAAC;IAED,UAAU,CAAC,UAA2B;QAClC,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;IAClF,CAAC;IAED,IAAI,CAAC,UAA2B;QAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,UAAU,CAAC,IAAmB,EAAE,KAAY;QACxC,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED,aAAa,CAAC,OAAgB;QAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;CACJ;AAnDD,oDAmDC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Channel, FactEnvelope, FactRecord, FactReference, Fork, Observable, Query, Specification, WebClient } from "jinaga";
|
|
2
|
+
import { Authentication } from "./authentication";
|
|
3
|
+
export declare class Principal {
|
|
4
|
+
}
|
|
5
|
+
export declare class AuthenticationImpl implements Authentication {
|
|
6
|
+
private inner;
|
|
7
|
+
private client;
|
|
8
|
+
private principal;
|
|
9
|
+
constructor(inner: Fork, client: WebClient);
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
login(): Promise<import("jinaga").LoginResponse>;
|
|
12
|
+
local(): Promise<FactRecord>;
|
|
13
|
+
save(envelopes: FactEnvelope[]): Promise<FactEnvelope[]>;
|
|
14
|
+
query(start: FactReference, query: Query): Promise<import("jinaga").FactPath[]>;
|
|
15
|
+
read(start: FactReference[], specification: Specification): Promise<any[]>;
|
|
16
|
+
whichExist(references: FactReference[]): Promise<FactReference[]>;
|
|
17
|
+
load(references: FactReference[]): Promise<FactRecord[]>;
|
|
18
|
+
from(fact: FactReference, query: Query): Observable;
|
|
19
|
+
addChannel(fact: FactReference, query: Query): Channel;
|
|
20
|
+
removeChannel(channel: Channel): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuthenticationImpl = exports.Principal = void 0;
|
|
13
|
+
class Principal {
|
|
14
|
+
}
|
|
15
|
+
exports.Principal = Principal;
|
|
16
|
+
class AuthenticationImpl {
|
|
17
|
+
constructor(inner, client) {
|
|
18
|
+
this.inner = inner;
|
|
19
|
+
this.client = client;
|
|
20
|
+
}
|
|
21
|
+
close() {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
yield this.inner.close();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
login() {
|
|
27
|
+
return this.client.login();
|
|
28
|
+
}
|
|
29
|
+
local() {
|
|
30
|
+
throw new Error('Local device has no persistence.');
|
|
31
|
+
}
|
|
32
|
+
save(envelopes) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const saved = yield this.inner.save(envelopes);
|
|
35
|
+
return saved;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
query(start, query) {
|
|
39
|
+
return this.inner.query(start, query);
|
|
40
|
+
}
|
|
41
|
+
read(start, specification) {
|
|
42
|
+
return this.inner.read(start, specification);
|
|
43
|
+
}
|
|
44
|
+
whichExist(references) {
|
|
45
|
+
throw new Error("whichExist method not implemented on AuthenticationImpl.");
|
|
46
|
+
}
|
|
47
|
+
load(references) {
|
|
48
|
+
return this.inner.load(references);
|
|
49
|
+
}
|
|
50
|
+
from(fact, query) {
|
|
51
|
+
return this.inner.from(fact, query);
|
|
52
|
+
}
|
|
53
|
+
addChannel(fact, query) {
|
|
54
|
+
return this.inner.addChannel(fact, query);
|
|
55
|
+
}
|
|
56
|
+
removeChannel(channel) {
|
|
57
|
+
this.inner.removeChannel(channel);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.AuthenticationImpl = AuthenticationImpl;
|
|
61
|
+
//# sourceMappingURL=authentication-impl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication-impl.js","sourceRoot":"","sources":["../../src/authentication/authentication-impl.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,MAAa,SAAS;CAErB;AAFD,8BAEC;AAED,MAAa,kBAAkB;IAG3B,YAAoB,KAAW,EAAU,MAAiB;QAAtC,UAAK,GAAL,KAAK,CAAM;QAAU,WAAM,GAAN,MAAM,CAAW;IAC1D,C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23 @@
|
|
|
1
|
+
import { AuthorizationRules, Channel, FactEnvelope, FactRecord, FactReference, Feed, LoginResponse, Observable, Query, Specification, UserIdentity } from "jinaga";
|
|
2
|
+
import { Keystore } from "../keystore";
|
|
3
|
+
import { Authentication } from "./authentication";
|
|
4
|
+
export declare class AuthenticationSession implements Authentication {
|
|
5
|
+
private inner;
|
|
6
|
+
private keystore;
|
|
7
|
+
private userIdentity;
|
|
8
|
+
private displayName;
|
|
9
|
+
private localDeviceIdentity;
|
|
10
|
+
private authorizationEngine;
|
|
11
|
+
constructor(inner: Feed, keystore: Keystore, authorizationRules: AuthorizationRules | null, userIdentity: UserIdentity, displayName: string, localDeviceIdentity: UserIdentity);
|
|
12
|
+
close(): Promise<void>;
|
|
13
|
+
login(): Promise<LoginResponse>;
|
|
14
|
+
local(): Promise<FactRecord>;
|
|
15
|
+
from(fact: FactReference, query: Query): Observable;
|
|
16
|
+
save(envelopes: FactEnvelope[]): Promise<FactEnvelope[]>;
|
|
17
|
+
query(start: FactReference, query: Query): Promise<FactReference[][]>;
|
|
18
|
+
read(start: FactReference[], specification: Specification): Promise<any[]>;
|
|
19
|
+
whichExist(references: FactReference[]): Promise<FactReference[]>;
|
|
20
|
+
load(references: FactReference[]): Promise<FactRecord[]>;
|
|
21
|
+
addChannel(fact: FactReference, query: Query): Channel;
|
|
22
|
+
removeChannel(channel: Channel): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuthenticationSession = void 0;
|
|
13
|
+
const jinaga_1 = require("jinaga");
|
|
14
|
+
class AuthenticationSession {
|
|
15
|
+
constructor(inner, keystore, authorizationRules, userIdentity, displayName, localDeviceIdentity) {
|
|
16
|
+
this.inner = inner;
|
|
17
|
+
this.keystore = keystore;
|
|
18
|
+
this.userIdentity = userIdentity;
|
|
19
|
+
this.displayName = displayName;
|
|
20
|
+
this.localDeviceIdentity = localDeviceIdentity;
|
|
21
|
+
this.authorizationEngine = authorizationRules &&
|
|
22
|
+
new jinaga_1.AuthorizationEngine(authorizationRules, inner);
|
|
23
|
+
}
|
|
24
|
+
close() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
yield this.inner.close();
|
|
27
|
+
yield this.keystore.close();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
login() {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const userFact = yield this.keystore.getOrCreateUserFact(this.userIdentity);
|
|
33
|
+
const signedFacts = yield this.keystore.signFacts(this.userIdentity, [userFact]);
|
|
34
|
+
yield this.inner.save(signedFacts);
|
|
35
|
+
return {
|
|
36
|
+
userFact,
|
|
37
|
+
profile: {
|
|
38
|
+
displayName: this.displayName
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
local() {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const deviceFact = yield this.keystore.getOrCreateDeviceFact(this.localDeviceIdentity);
|
|
46
|
+
const signedFact = {
|
|
47
|
+
fact: deviceFact,
|
|
48
|
+
signatures: []
|
|
49
|
+
};
|
|
50
|
+
yield this.inner.save([signedFact]);
|
|
51
|
+
return deviceFact;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
from(fact, query) {
|
|
55
|
+
return this.inner.from(fact, query);
|
|
56
|
+
}
|
|
57
|
+
save(envelopes) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const userFact = yield this.keystore.getUserFact(this.userIdentity);
|
|
60
|
+
const facts = envelopes.map(envelope => envelope.fact);
|
|
61
|
+
const authorizedFacts = yield this.authorizationEngine.authorizeFacts(facts, userFact);
|
|
62
|
+
const signedFacts = yield this.keystore.signFacts(this.userIdentity, authorizedFacts);
|
|
63
|
+
return yield this.inner.save(signedFacts);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
query(start, query) {
|
|
67
|
+
return this.inner.query(start, query);
|
|
68
|
+
}
|
|
69
|
+
read(start, specification) {
|
|
70
|
+
return this.inner.read(start, specification);
|
|
71
|
+
}
|
|
72
|
+
whichExist(references) {
|
|
73
|
+
throw new Error("WhichExist method not implemented on AuthenticationSession.");
|
|
74
|
+
}
|
|
75
|
+
load(references) {
|
|
76
|
+
return this.inner.load(references);
|
|
77
|
+
}
|
|
78
|
+
addChannel(fact, query) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
removeChannel(channel) {
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.AuthenticationSession = AuthenticationSession;
|
|
85
|
+
//# sourceMappingURL=authentication-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication-session.js","sourceRoot":"","sources":["../../src/authentication/authentication-session.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAagB;AAKhB,MAAa,qBAAqB;IAG9B,YACY,KAAW,EACX,QAAkB,EAC1B,kBAA6C,EACrC,YAA0B,EAC1B,WAAmB,EACnB,mBAAiC;QALjC,UAAK,GAAL,KAAK,CAAM;QACX,aAAQ,GAAR,QAAQ,CAAU;QAElB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,gBAAW,GAAX,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I,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACpE,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACvD,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YACvF,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;YACtF,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC9C,CAAC;KAAA;IAED,KAAK,CAAC,KAAoB,EAAE,KAAY;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,CAAC,KAAsB,EAAE,aAA4B;QACrD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACjD,CAAC;IAED,UAAU,CAAC,UAA2B;QAClC,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IACnF,CAAC;IAED,IAAI,CAAC,UAA2B;QAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,UAAU,CAAC,IAAmB,EAAE,KAAY;QACxC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,aAAa,CAAC,OAAgB;IAC9B,CAAC;CACJ;AA5ED,sDA4EC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication.js","sourceRoot":"","sources":["../../src/authentication/authentication.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FactEnvelope, FactRecord, FactReference, Feed, Observable, Query, Specification, WebClient } from "jinaga";
|
|
2
|
+
export declare class Principal {
|
|
3
|
+
}
|
|
4
|
+
export declare class Authentication implements Feed {
|
|
5
|
+
private inner;
|
|
6
|
+
private client;
|
|
7
|
+
private principal;
|
|
8
|
+
constructor(inner: Feed, client: WebClient);
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
login(): Promise<import("jinaga").LoginResponse>;
|
|
11
|
+
save(envelopes: FactEnvelope[]): Promise<FactEnvelope[]>;
|
|
12
|
+
query(start: FactReference, query: Query): Promise<import("jinaga").FactPath[]>;
|
|
13
|
+
read(start: FactReference[], specification: Specification): Promise<any[]>;
|
|
14
|
+
whichExist(references: FactReference[]): Promise<FactReference[]>;
|
|
15
|
+
load(references: FactReference[]): Promise<FactRecord[]>;
|
|
16
|
+
from(fact: FactReference, query: Query): Observable;
|
|
17
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Authentication = exports.Principal = void 0;
|
|
13
|
+
class Principal {
|
|
14
|
+
}
|
|
15
|
+
exports.Principal = Principal;
|
|
16
|
+
class Authentication {
|
|
17
|
+
constructor(inner, client) {
|
|
18
|
+
this.inner = inner;
|
|
19
|
+
this.client = client;
|
|
20
|
+
}
|
|
21
|
+
close() {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
yield this.inner.close();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
login() {
|
|
27
|
+
return this.client.login();
|
|
28
|
+
}
|
|
29
|
+
save(envelopes) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const saved = yield this.inner.save(envelopes);
|
|
32
|
+
return saved;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
query(start, query) {
|
|
36
|
+
return this.inner.query(start, query);
|
|
37
|
+
}
|
|
38
|
+
read(start, specification) {
|
|
39
|
+
return this.inner.read(start, specification);
|
|
40
|
+
}
|
|
41
|
+
whichExist(references) {
|
|
42
|
+
throw new Error("whichExist method not implemented on Authentication.");
|
|
43
|
+
}
|
|
44
|
+
load(references) {
|
|
45
|
+
return this.inner.load(references);
|
|
46
|
+
}
|
|
47
|
+
from(fact, query) {
|
|
48
|
+
return this.inner.from(fact, query);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.Authentication = Authentication;
|
|
52
|
+
//# sourceMappingURL=authentication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication.js","sourceRoot":"","sources":["../src/authentication.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,MAAa,SAAS;CAErB;AAFD,8BAEC;AAED,MAAa,cAAc;IAGvB,YAAoB,KAAW,EAAU,MAAiB;QAAtC,UAAK,GAAL,KAAK,CAAM;QAAU,WAAM,GAAN,MAAM,CAAW;IAC1D,CAAC;IAEK,KAAK;;YACP,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAC7B,CAAC;KAAA;IAED,KAAK;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IAEK,IAAI,CAAC,SAAyB;;YAChC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC/C,OAAO,KAAK,CAAC;QACjB,CAAC;KAAA;IAED,KAAK,CAAC,KAAoB,EAAE,KAAY;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,CAAC,KAAsB,EAAE,aAA4B;QACrD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACjD,CAAC;IAED,UAAU,CAAC,UAA2B;QAClC,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC5E,CAAC;IAED,IAAI,CAAC,UAA2B;QAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,IAAI,CAAC,IAAmB,EAAE,KAAY;QAClC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;CACJ;AAtCD,wCAsCC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Authorization, AuthorizationRules, FactRecord, FactReference, Feed, Query, Specification, UserIdentity } from "jinaga";
|
|
2
|
+
import { Keystore } from "../keystore";
|
|
3
|
+
export declare class AuthorizationKeystore implements Authorization {
|
|
4
|
+
private feed;
|
|
5
|
+
private keystore;
|
|
6
|
+
private authorizationEngine;
|
|
7
|
+
constructor(feed: Feed, keystore: Keystore, authorizationRules: AuthorizationRules | null);
|
|
8
|
+
getOrCreateUserFact(userIdentity: UserIdentity): Promise<FactRecord>;
|
|
9
|
+
query(userIdentity: UserIdentity, start: FactReference, query: Query): Promise<import("jinaga").FactPath[]>;
|
|
10
|
+
read(userIdentity: UserIdentity, start: FactReference[], specification: Specification): Promise<any[]>;
|
|
11
|
+
load(userIdentity: UserIdentity, references: FactReference[]): Promise<FactRecord[]>;
|
|
12
|
+
save(userIdentity: UserIdentity, facts: FactRecord[]): Promise<FactRecord[]>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuthorizationKeystore = void 0;
|
|
13
|
+
const jinaga_1 = require("jinaga");
|
|
14
|
+
class AuthorizationKeystore {
|
|
15
|
+
constructor(feed, keystore, authorizationRules) {
|
|
16
|
+
this.feed = feed;
|
|
17
|
+
this.keystore = keystore;
|
|
18
|
+
this.authorizationEngine = authorizationRules &&
|
|
19
|
+
new jinaga_1.AuthorizationEngine(authorizationRules, feed);
|
|
20
|
+
}
|
|
21
|
+
getOrCreateUserFact(userIdentity) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const userFact = yield this.keystore.getOrCreateUserFact(userIdentity);
|
|
24
|
+
const envelopes = [
|
|
25
|
+
{
|
|
26
|
+
fact: userFact,
|
|
27
|
+
signatures: []
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
yield this.feed.save(envelopes);
|
|
31
|
+
return userFact;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
query(userIdentity, start, query) {
|
|
35
|
+
return this.feed.query(start, query);
|
|
36
|
+
}
|
|
37
|
+
read(userIdentity, start, specification) {
|
|
38
|
+
return this.feed.read(start, specification);
|
|
39
|
+
}
|
|
40
|
+
load(userIdentity, references) {
|
|
41
|
+
return this.feed.load(references);
|
|
42
|
+
}
|
|
43
|
+
save(userIdentity, facts) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
if (!this.authorizationEngine) {
|
|
46
|
+
const envelopes = yield this.feed.save(facts.map(fact => ({
|
|
47
|
+
fact,
|
|
48
|
+
signatures: []
|
|
49
|
+
})));
|
|
50
|
+
return envelopes.map(envelope => envelope.fact);
|
|
51
|
+
}
|
|
52
|
+
const userFact = yield this.keystore.getUserFact(userIdentity);
|
|
53
|
+
const authorizedFacts = yield this.authorizationEngine.authorizeFacts(facts, userFact);
|
|
54
|
+
const signedFacts = yield this.keystore.signFacts(userIdentity, authorizedFacts);
|
|
55
|
+
const envelopes = yield this.feed.save(signedFacts);
|
|
56
|
+
return envelopes.map(envelope => envelope.fact);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.AuthorizationKeystore = AuthorizationKeystore;
|
|
61
|
+
//# sourceMappingURL=authorization-keystore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-keystore.js","sourceRoot":"","sources":["../../src/authorization/authorization-keystore.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAWgB;AAIhB,MAAa,qBAAqB;IAG9B,YACY,IAAU,EACV,QAAkB,EAC1B,kBAA6C;QAFrC,SAAI,GAAJ,IAAI,CAAM;QACV,aAAQ,GAAR,QAAQ,CAAU;QAG1B,IAAI,CAAC,mBAAmB,GAAG,kBAAkB;YACzC,IAAI,4BAAmB,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;IAC1D,CAAC;IAEK,mBAAmB,CAAC,YAA0B;;YAChD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC;YACvE,MAAM,SAAS,GAAG;gBACA;oBACV,IAAI,EAA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S,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACpD,OAAO,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACpD,CAAC;KAAA;CACJ;AAnDD,sDAmDC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HttpConnection, HttpResponse } from "jinaga";
|
|
2
|
+
export declare class NodeHttpConnection implements HttpConnection {
|
|
3
|
+
private url;
|
|
4
|
+
constructor(url: string);
|
|
5
|
+
get(path: string): Promise<{}>;
|
|
6
|
+
post(tail: string, body: {}, timeoutSeconds: number): Promise<HttpResponse>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.NodeHttpConnection = void 0;
|
|
27
|
+
const http = __importStar(require("http"));
|
|
28
|
+
const https = __importStar(require("https"));
|
|
29
|
+
const url = __importStar(require("url"));
|
|
30
|
+
class NodeHttpConnection {
|
|
31
|
+
constructor(url) {
|
|
32
|
+
this.url = url;
|
|
33
|
+
}
|
|
34
|
+
get(path) {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
const { protocol } = url.parse(this.url + path);
|
|
37
|
+
const get = protocol === "https:" ? https.get : http.get;
|
|
38
|
+
let data = "";
|
|
39
|
+
get(this.url + path, response => {
|
|
40
|
+
response.on("data", chunk => {
|
|
41
|
+
data += chunk;
|
|
42
|
+
});
|
|
43
|
+
response.on("end", () => {
|
|
44
|
+
try {
|
|
45
|
+
const result = JSON.parse(data);
|
|
46
|
+
resolve(result);
|
|
47
|
+
}
|
|
48
|
+
catch (x) {
|
|
49
|
+
reject(x);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}).on("error", err => reject(err));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
post(tail, body, timeoutSeconds) {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
const { protocol, host, port, path } = url.parse(this.url + tail);
|
|
58
|
+
const request = protocol === "https:" ? https.request : http.request;
|
|
59
|
+
let response = "";
|
|
60
|
+
const req = request({
|
|
61
|
+
method: "POST",
|
|
62
|
+
host, port, path,
|
|
63
|
+
headers: {
|
|
64
|
+
"Accept": "application/json",
|
|
65
|
+
"Content-Type": "application/json"
|
|
66
|
+
},
|
|
67
|
+
timeout: timeoutSeconds * 1000
|
|
68
|
+
}, res => {
|
|
69
|
+
res.on("data", chunk => {
|
|
70
|
+
if (chunk instanceof Buffer) {
|
|
71
|
+
response += chunk.toString();
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
response += chunk;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
res.on("error", err => {
|
|
78
|
+
resolve({
|
|
79
|
+
result: "failure",
|
|
80
|
+
error: err.message
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
res.on("end", () => {
|
|
84
|
+
if (res.statusCode === 403) {
|
|
85
|
+
reject(response);
|
|
86
|
+
}
|
|
87
|
+
else if (res.statusCode >= 400) {
|
|
88
|
+
resolve({
|
|
89
|
+
result: "retry",
|
|
90
|
+
error: response
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
else if (isJsonResult(res.headers["content-type"])) {
|
|
94
|
+
try {
|
|
95
|
+
const json = JSON.parse(response);
|
|
96
|
+
resolve({
|
|
97
|
+
result: "success",
|
|
98
|
+
response: json
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (x) {
|
|
102
|
+
reject(x);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
reject(response);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
req.on("error", err => {
|
|
111
|
+
resolve({
|
|
112
|
+
result: "failure",
|
|
113
|
+
error: err.message
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
req.write(JSON.stringify(body));
|
|
117
|
+
req.end();
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.NodeHttpConnection = NodeHttpConnection;
|
|
122
|
+
function isJsonResult(contentType) {
|
|
123
|
+
const json = contentType.split(";").indexOf("application/json");
|
|
124
|
+
return json >= 0;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=node-http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-http.js","sourceRoot":"","sources":["../../src/http/node-http.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,6CAA+B;AAE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,cAAc,CAAC,CAAC,EAAE;wBAChD,IAAI;4BACA,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;4BAClC,OAAO,CAAC;gCACJ,MAAM,EAAE,SAAS;gCACjB,QAAQ,EAAE,IAAI;6BACjB,CAAC,CAAC;yBACN;wBACD,OAAO,CAAC,EAAE;4BACN,MAAM,CAAC,CAAC,CAAC,CAAC;yBACb;qBACJ;yBACI;wBACD,MAAM,CAAC,QAAQ,CAAC,CAAC;qBACpB;gBACL,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;YAEH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE;gBAClB,OAAO,CAAC;oBACJ,MAAM,EAAE,SAAS;oBACjB,KAAK,EAAE,GAAG,CAAC,OAAO;iBACrB,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;YAEH,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;YAChC,GAAG,CAAC,GAAG,EAAE,CAAC;QACd,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AA/FD,gDA+FC;AAED,SAAS,YAAY,CAAC,WAAmB;IACrC,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAChE,OAAO,IAAI,IAAI,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Handler } from "express";
|
|
2
|
+
import { Authorization, ProfileMessage } from "jinaga";
|
|
3
|
+
export interface RequestUser {
|
|
4
|
+
provider: string;
|
|
5
|
+
id: string;
|
|
6
|
+
profile: ProfileMessage;
|
|
7
|
+
}
|
|
8
|
+
export declare class HttpRouter {
|
|
9
|
+
private authorization;
|
|
10
|
+
handler: Handler;
|
|
11
|
+
constructor(authorization: Authorization);
|
|
12
|
+
private login;
|
|
13
|
+
private query;
|
|
14
|
+
private load;
|
|
15
|
+
private save;
|
|
16
|
+
private read;
|
|
17
|
+
private write;
|
|
18
|
+
private feed;
|
|
19
|
+
private getKnownFacts;
|
|
20
|
+
}
|