@kinotic-ai/app-api 5.0.0-beta.1 → 5.0.0-beta.3
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 +80 -10
- package/dist/index.cjs +140 -84
- package/dist/index.d.cts +197 -120
- package/dist/index.d.ts +197 -120
- package/dist/index.js +142 -92
- package/package.json +3 -6
package/README.md
CHANGED
|
@@ -1,17 +1,87 @@
|
|
|
1
1
|
# @kinotic-ai/app-api
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
What a Kinotic application's project is built against: the client of the app server's sign-in and
|
|
4
|
+
sign-up routes, the zone the application's services live in, and the project's configuration type.
|
|
5
|
+
It depends on `@kinotic-ai/core` alone.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
**[Get started at kinotic.ai/getting-started](https://kinotic.ai/getting-started)**
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bun add @kinotic-ai/app-api@beta @kinotic-ai/core@beta
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Signing a UI's users in
|
|
16
|
+
|
|
17
|
+
A browser cannot set WebSocket upgrade headers, so a UI signs its user in over REST at its
|
|
18
|
+
application's API host, which sets the session cookie, and then opens the connection on that cookie.
|
|
19
|
+
`ApplicationLogin` makes those calls, and `serverFromEnv` reads the API host from the
|
|
20
|
+
`VITE_KINOTIC_HOST`, `VITE_KINOTIC_PORT` and `VITE_KINOTIC_USE_SSL` variables a deployment hands the
|
|
21
|
+
UI's build:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { ApplicationLogin, LoginMethodType, serverFromEnv, SignUpStartedType } from '@kinotic-ai/app-api'
|
|
25
|
+
import { Kinotic, SessionEndType } from '@kinotic-ai/core'
|
|
26
|
+
|
|
27
|
+
const login = new ApplicationLogin(serverFromEnv(import.meta.env))
|
|
28
|
+
|
|
29
|
+
// the login page: the password form, and a "Continue with <name>" button for each OIDC method
|
|
30
|
+
const methods = await login.loginMethods()
|
|
31
|
+
await login.login(email, password)
|
|
32
|
+
await login.continueWith(methods.find(method => method.type === LoginMethodType.OIDC)!)
|
|
33
|
+
|
|
34
|
+
// a returning tab, and the page a provider returned to
|
|
35
|
+
await login.resume()
|
|
36
|
+
|
|
37
|
+
// the sign-up page, and the /signup/verify page its link opens
|
|
38
|
+
const started = await login.startSignUp(email)
|
|
39
|
+
if (started.type === SignUpStartedType.LINK) {
|
|
40
|
+
// the server sends no email: show started.verificationUrl for the person to open
|
|
41
|
+
}
|
|
42
|
+
const connected = await login.completeSignUp(token, password, displayName)
|
|
43
|
+
// null: the user exists but the connection could not be opened, so send them to the login page
|
|
44
|
+
|
|
45
|
+
// the session: sign out, and learn that it ended
|
|
46
|
+
await Kinotic.session.logout()
|
|
47
|
+
Kinotic.session.ended.subscribe(end => {
|
|
48
|
+
// SessionEndType.SIGNED_OUT or SessionEndType.CONNECTION_LOST: send the user to the login page
|
|
49
|
+
})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
A page that is not one of a tenant's sites signs in to a tenant with
|
|
53
|
+
`new ApplicationLogin(server, tenantId)`.
|
|
54
|
+
|
|
55
|
+
## Publishing services in the application's zone
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { appZone } from '@kinotic-ai/app-api'
|
|
8
59
|
import { Kinotic } from '@kinotic-ai/core'
|
|
9
|
-
import
|
|
60
|
+
import config from './.config/kinotic.config'
|
|
10
61
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const tenant = await Kinotic.tenant.getTenant()
|
|
14
|
-
await Kinotic.tenantMembers.inviteMember('colleague@example.com', 'Colleague')
|
|
62
|
+
// before any @Publish class is instantiated
|
|
63
|
+
Kinotic.zonePrefix = appZone(config.organizationId, config.applicationId)
|
|
15
64
|
```
|
|
16
65
|
|
|
17
|
-
The
|
|
66
|
+
## The project's configuration
|
|
67
|
+
|
|
68
|
+
`.config/kinotic.config.ts` exports a `KinoticProjectConfig`, which the Kinotic CLI reads:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import type { KinoticProjectConfig } from '@kinotic-ai/app-api'
|
|
72
|
+
|
|
73
|
+
const config: KinoticProjectConfig = {
|
|
74
|
+
organizationId: 'acme',
|
|
75
|
+
applicationId: 'orders',
|
|
76
|
+
projectId: 'orders-main',
|
|
77
|
+
entitiesPaths: ['packages/domain/model'],
|
|
78
|
+
generatedPath: 'packages/domain/repositories',
|
|
79
|
+
fileExtensionForImports: '.js'
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export default config
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
Elastic License 2.0 with the Kinotic Additional Limitations.
|
package/dist/index.cjs
CHANGED
|
@@ -40,97 +40,153 @@ var __export = (target, all) => {
|
|
|
40
40
|
// packages/app-api/src/index.ts
|
|
41
41
|
var exports_src = {};
|
|
42
42
|
__export(exports_src, {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
APP_ZONE_PREFIX: () => APP_ZONE_PREFIX,
|
|
44
|
+
ApplicationLogin: () => ApplicationLogin,
|
|
45
|
+
KinoticProjectConfig: () => KinoticProjectConfig,
|
|
46
|
+
LoginMethodType: () => LoginMethodType,
|
|
47
|
+
SignUpStartedType: () => SignUpStartedType,
|
|
48
|
+
appZone: () => appZone,
|
|
49
|
+
serverFromEnv: () => serverFromEnv
|
|
48
50
|
});
|
|
49
51
|
module.exports = __toCommonJS(exports_src);
|
|
50
|
-
var import_management_api3 = require("@kinotic-ai/management-api");
|
|
51
52
|
|
|
52
|
-
// packages/app-api/src/api/
|
|
53
|
-
class Tenant {
|
|
54
|
-
id;
|
|
55
|
-
organizationId;
|
|
56
|
-
applicationId;
|
|
57
|
-
tenantId;
|
|
58
|
-
name = "";
|
|
59
|
-
createdBy = null;
|
|
60
|
-
ssoConfigId = null;
|
|
61
|
-
ssoRoleId = null;
|
|
62
|
-
created = null;
|
|
63
|
-
updated = null;
|
|
64
|
-
}
|
|
65
|
-
// packages/app-api/src/api/services/ITenantService.ts
|
|
66
|
-
var import_management_api = require("@kinotic-ai/management-api");
|
|
67
|
-
|
|
68
|
-
class TenantService {
|
|
69
|
-
serviceProxy;
|
|
70
|
-
constructor(kinotic) {
|
|
71
|
-
this.serviceProxy = kinotic.serviceProxy(`${import_management_api.APP_API_ZONE}~org.kinotic.domain.api.services.TenantService`);
|
|
72
|
-
}
|
|
73
|
-
getTenant() {
|
|
74
|
-
return this.serviceProxy.invoke("getTenant", []);
|
|
75
|
-
}
|
|
76
|
-
rename(name) {
|
|
77
|
-
return this.serviceProxy.invoke("rename", [name]);
|
|
78
|
-
}
|
|
79
|
-
getSso() {
|
|
80
|
-
return this.serviceProxy.invoke("getSso", []);
|
|
81
|
-
}
|
|
82
|
-
configureSso(configuration, ssoRoleId) {
|
|
83
|
-
return this.serviceProxy.invoke("configureSso", [configuration, ssoRoleId]);
|
|
84
|
-
}
|
|
85
|
-
removeSso() {
|
|
86
|
-
return this.serviceProxy.invoke("removeSso", []);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
// packages/app-api/src/api/services/security/ITenantMemberService.ts
|
|
90
|
-
var import_management_api2 = require("@kinotic-ai/management-api");
|
|
53
|
+
// packages/app-api/src/api/ApplicationLogin.ts
|
|
91
54
|
var import_core = require("@kinotic-ai/core");
|
|
92
55
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
56
|
+
// packages/app-api/src/api/model/SignUpStartedType.ts
|
|
57
|
+
var SignUpStartedType;
|
|
58
|
+
((SignUpStartedType) => {
|
|
59
|
+
SignUpStartedType["EMAILED"] = "EMAILED";
|
|
60
|
+
SignUpStartedType["LINK"] = "LINK";
|
|
61
|
+
})(SignUpStartedType ||= {});
|
|
62
|
+
|
|
63
|
+
// packages/app-api/src/api/ApplicationLogin.ts
|
|
64
|
+
class ApplicationLogin {
|
|
65
|
+
server;
|
|
66
|
+
tenantId;
|
|
67
|
+
constructor(server, tenantId) {
|
|
68
|
+
this.server = server;
|
|
69
|
+
this.tenantId = tenantId;
|
|
70
|
+
}
|
|
71
|
+
async loginMethods() {
|
|
72
|
+
const response = await fetch(this.url("/api/auth/app/login/methods" + this.tenantQuery()), { credentials: "include" });
|
|
73
|
+
if (!response.ok) {
|
|
74
|
+
throw new Error(await errorMessage(response, "Could not load sign-in methods"));
|
|
75
|
+
}
|
|
76
|
+
return await response.json();
|
|
77
|
+
}
|
|
78
|
+
async login(email, password) {
|
|
79
|
+
const response = await this.post("/api/auth/app/login", { email, password, tenantId: this.tenantId });
|
|
80
|
+
if (!response.ok) {
|
|
81
|
+
throw new Error(await errorMessage(response, response.status === 401 ? "Invalid credentials" : "Could not sign in"));
|
|
82
|
+
}
|
|
83
|
+
return this.resume();
|
|
84
|
+
}
|
|
85
|
+
async continueWith(method) {
|
|
86
|
+
const response = await this.post("/api/auth/app/login/oidc/start/" + encodeURIComponent(method.configurationId) + this.tenantQuery());
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
throw new Error(await errorMessage(response, "Could not start sign-in"));
|
|
89
|
+
}
|
|
90
|
+
const { redirect } = await response.json();
|
|
91
|
+
window.location.assign(redirect);
|
|
92
|
+
}
|
|
93
|
+
resume() {
|
|
94
|
+
return import_core.Kinotic.session.resume({
|
|
95
|
+
server: this.server,
|
|
96
|
+
maxConnectionAttempts: 3
|
|
97
|
+
});
|
|
117
98
|
}
|
|
118
|
-
|
|
119
|
-
|
|
99
|
+
async startSignUp(email) {
|
|
100
|
+
const response = await this.post("/api/auth/app/signup", { email });
|
|
101
|
+
if (response.status === 409) {
|
|
102
|
+
throw new Error("An account already exists for this email. Sign in instead.");
|
|
103
|
+
}
|
|
104
|
+
if (!response.ok) {
|
|
105
|
+
throw new Error(await errorMessage(response, "Could not start sign-up"));
|
|
106
|
+
}
|
|
107
|
+
let ret;
|
|
108
|
+
if (response.status === 200) {
|
|
109
|
+
const { verificationUrl } = await response.json();
|
|
110
|
+
ret = { type: "LINK" /* LINK */, verificationUrl };
|
|
111
|
+
} else {
|
|
112
|
+
ret = { type: "EMAILED" /* EMAILED */ };
|
|
113
|
+
}
|
|
114
|
+
return ret;
|
|
115
|
+
}
|
|
116
|
+
async completeSignUp(token, password, displayName) {
|
|
117
|
+
const response = await this.post("/api/auth/app/signup/complete", { token, password, displayName });
|
|
118
|
+
if (!response.ok) {
|
|
119
|
+
throw new Error(await errorMessage(response, "Could not finish sign-up"));
|
|
120
|
+
}
|
|
121
|
+
let ret = null;
|
|
122
|
+
try {
|
|
123
|
+
ret = await this.resume();
|
|
124
|
+
} catch {}
|
|
125
|
+
return ret;
|
|
126
|
+
}
|
|
127
|
+
post(path, body) {
|
|
128
|
+
return fetch(this.url(path), {
|
|
129
|
+
method: "POST",
|
|
130
|
+
credentials: "include",
|
|
131
|
+
headers: body ? { "Content-Type": "application/json" } : undefined,
|
|
132
|
+
body: body ? JSON.stringify(body) : undefined
|
|
133
|
+
});
|
|
120
134
|
}
|
|
121
|
-
|
|
122
|
-
return this.
|
|
135
|
+
url(path) {
|
|
136
|
+
return import_core.buildServerUrl(this.server, "http") + path;
|
|
123
137
|
}
|
|
124
|
-
|
|
125
|
-
return this.
|
|
138
|
+
tenantQuery() {
|
|
139
|
+
return this.tenantId ? "?tenantId=" + encodeURIComponent(this.tenantId) : "";
|
|
126
140
|
}
|
|
127
141
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
142
|
+
async function errorMessage(response, fallback) {
|
|
143
|
+
let ret = fallback;
|
|
144
|
+
try {
|
|
145
|
+
const body = await response.json();
|
|
146
|
+
ret = body.error || fallback;
|
|
147
|
+
} catch {}
|
|
148
|
+
return ret;
|
|
149
|
+
}
|
|
150
|
+
// packages/app-api/src/api/BuildEnv.ts
|
|
151
|
+
function serverFromEnv(env) {
|
|
152
|
+
const host = env.VITE_KINOTIC_HOST;
|
|
153
|
+
if (!host) {
|
|
154
|
+
throw new Error("VITE_KINOTIC_HOST is not set: the build was not handed the address of the application's API host");
|
|
155
|
+
}
|
|
156
|
+
const useSSL = env.VITE_KINOTIC_USE_SSL === "true";
|
|
157
|
+
let port = useSSL ? 443 : 80;
|
|
158
|
+
if (env.VITE_KINOTIC_PORT) {
|
|
159
|
+
port = /^\d+$/.test(env.VITE_KINOTIC_PORT) ? Number(env.VITE_KINOTIC_PORT) : NaN;
|
|
160
|
+
if (!(port >= 1 && port <= 65535)) {
|
|
161
|
+
throw new Error(`VITE_KINOTIC_PORT is not a port: ${env.VITE_KINOTIC_PORT}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return { host, port, useSSL };
|
|
165
|
+
}
|
|
166
|
+
// packages/app-api/src/api/Zones.ts
|
|
167
|
+
var import_core2 = require("@kinotic-ai/core");
|
|
168
|
+
var APP_ZONE_PREFIX = "app";
|
|
169
|
+
function appZone(organizationId, applicationId) {
|
|
170
|
+
import_core2.validateLabel(organizationId);
|
|
171
|
+
import_core2.validateLabel(applicationId);
|
|
172
|
+
return `${APP_ZONE_PREFIX}.${organizationId}.${applicationId}`;
|
|
173
|
+
}
|
|
174
|
+
// packages/app-api/src/api/model/KinoticProjectConfig.ts
|
|
175
|
+
class KinoticProjectConfig {
|
|
176
|
+
name;
|
|
177
|
+
description;
|
|
178
|
+
organizationId;
|
|
179
|
+
applicationId;
|
|
180
|
+
projectId;
|
|
181
|
+
entitiesPaths;
|
|
182
|
+
servicesPaths;
|
|
183
|
+
generatedPath;
|
|
184
|
+
fileExtensionForImports = ".js";
|
|
185
|
+
validate;
|
|
186
|
+
}
|
|
187
|
+
// packages/app-api/src/api/model/LoginMethodType.ts
|
|
188
|
+
var LoginMethodType;
|
|
189
|
+
((LoginMethodType) => {
|
|
190
|
+
LoginMethodType["PASSWORD"] = "PASSWORD";
|
|
191
|
+
LoginMethodType["OIDC"] = "OIDC";
|
|
192
|
+
})(LoginMethodType ||= {});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,143 +1,220 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Identifiable } from "@kinotic-ai/core";
|
|
1
|
+
import { ConnectedInfo, ServerInfo } from "@kinotic-ai/core";
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
5
|
-
* object the application's store grants on. A tenant is created by a customer signing up, or by the application
|
|
6
|
-
* for each user when it isolates them.
|
|
3
|
+
* How a sign-in method signs a person in.
|
|
7
4
|
*/
|
|
8
|
-
declare
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
declare enum LoginMethodType {
|
|
6
|
+
/** With an email and a password, which the page offers as a form. */
|
|
7
|
+
PASSWORD = "PASSWORD",
|
|
8
|
+
/** Through an OIDC provider, which the page offers as a button that starts a sign-in through it. */
|
|
9
|
+
OIDC = "OIDC"
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A sign-in method an application's login offers, as its login and sign-up pages render it.
|
|
13
|
+
*/
|
|
14
|
+
interface LoginMethod {
|
|
15
|
+
/** The id of the configuration offered; an OIDC method's starts a sign-in through it. */
|
|
16
|
+
configurationId: string;
|
|
17
|
+
type: LoginMethodType;
|
|
18
|
+
/** The name the page shows for the method. */
|
|
19
|
+
name: string;
|
|
20
|
+
/** The key of the OIDC provider kind ({@code google}, {@code azure-ad}, {@code okta}, …), for branding, or null for an email and a password. */
|
|
21
|
+
provider: string | null;
|
|
13
22
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
23
|
+
* Whether a person who has no user yet becomes one: with an email and a password, by signing up with
|
|
24
|
+
* them, or through an OIDC provider, on the first sign-in of a person it verifies.
|
|
16
25
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
signUp: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* How the person who started a sign-up gets the link that completes it.
|
|
30
|
+
*/
|
|
31
|
+
declare enum SignUpStartedType {
|
|
32
|
+
/** The server emailed the link, so the page tells the person to check their inbox. */
|
|
33
|
+
EMAILED = "EMAILED",
|
|
34
|
+
/** The server sends no email and answered with the link, which the page shows for the person to open. */
|
|
35
|
+
LINK = "LINK"
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* What the sign-up page shows once the server accepted the email.
|
|
39
|
+
*/
|
|
40
|
+
type SignUpStarted = {
|
|
41
|
+
type: SignUpStartedType.EMAILED;
|
|
42
|
+
} | {
|
|
43
|
+
type: SignUpStartedType.LINK;
|
|
44
|
+
verificationUrl: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The login of an application, or of one of its tenants, as a page of one of the application's UIs uses
|
|
48
|
+
* it in a browser: the app server's sign-in and sign-up routes at the application's API host. A sign-in
|
|
49
|
+
* establishes the session cookie for that host, and the connection is opened on it through
|
|
50
|
+
* {@code Kinotic.session}, which also signs the page out ({@code Kinotic.session.logout()}) and reports a
|
|
51
|
+
* session that ended ({@code Kinotic.session.ended}).
|
|
52
|
+
*/
|
|
53
|
+
declare class ApplicationLogin {
|
|
54
|
+
private readonly server;
|
|
55
|
+
private readonly tenantId?;
|
|
22
56
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
57
|
+
* @param server the application's API host, see {@link serverFromEnv}
|
|
58
|
+
* @param tenantId the tenant to sign in to from a page that is not one of the tenant's sites; a page
|
|
59
|
+
* served at a tenant's site signs in to that tenant without it
|
|
25
60
|
*/
|
|
26
|
-
|
|
61
|
+
constructor(server: ServerInfo, tenantId?: string | undefined);
|
|
27
62
|
/**
|
|
28
|
-
* The
|
|
29
|
-
*
|
|
63
|
+
* The sign-in methods the login offers, in the order to show them: the password form for
|
|
64
|
+
* {@link LoginMethodType.PASSWORD}, a "Continue with name" button for each {@link LoginMethodType.OIDC}.
|
|
30
65
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
66
|
+
loginMethods(): Promise<LoginMethod[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Signs in with a user's email and password, then opens the connection.
|
|
69
|
+
* @return the {@link ConnectedInfo} of the connection
|
|
70
|
+
* @throws Error with the server's message; when it gives none, "Invalid credentials" for a refused
|
|
71
|
+
* login and "Could not sign in" for any other failure
|
|
72
|
+
*/
|
|
73
|
+
login(email: string, password: string): Promise<ConnectedInfo>;
|
|
74
|
+
/**
|
|
75
|
+
* Starts a sign-in through an OIDC method; the browser leaves the page for the provider, and returns
|
|
76
|
+
* to {@code /} of the site signed in, or to its {@code /login?error=<code>}.
|
|
77
|
+
*/
|
|
78
|
+
continueWith(method: LoginMethod): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Opens the connection on the session cookie, for a returning tab and for a page the provider
|
|
81
|
+
* returned to; rejects when the page is not signed in or the connection cannot be opened in three
|
|
82
|
+
* attempts. The connection is reconnected when it drops, and ends for good after three failed
|
|
83
|
+
* attempts to, which {@code Kinotic.session.ended} reports.
|
|
84
|
+
* @return the {@link ConnectedInfo} of the connection
|
|
85
|
+
*/
|
|
86
|
+
resume(): Promise<ConnectedInfo>;
|
|
87
|
+
/**
|
|
88
|
+
* Starts a sign-up with an email and a password, offered while the password method's
|
|
89
|
+
* {@link LoginMethod.signUp} is true.
|
|
90
|
+
* @return how the person gets the link that completes the sign-up
|
|
91
|
+
* @throws Error when the server reports that the email already has a user, who signs in instead
|
|
92
|
+
*/
|
|
93
|
+
startSignUp(email: string): Promise<SignUpStarted>;
|
|
94
|
+
/**
|
|
95
|
+
* Completes the sign-up the link's token was issued for, which creates the user and signs the page in,
|
|
96
|
+
* then opens the connection.
|
|
97
|
+
* @param token the {@code token} parameter of the link, on the UI's {@code /signup/verify} page
|
|
98
|
+
* @param password the password the person chose
|
|
99
|
+
* @param displayName the person's name, at most 200 characters
|
|
100
|
+
* @return the {@link ConnectedInfo} of the connection, or null when the user was created but the
|
|
101
|
+
* connection could not be opened: the link is spent, so the page sends the person to its
|
|
102
|
+
* login page to sign in with the new password
|
|
103
|
+
* @throws Error with the server's message when the sign-up was not completed
|
|
104
|
+
*/
|
|
105
|
+
completeSignUp(token: string, password: string, displayName?: string): Promise<ConnectedInfo | null>;
|
|
106
|
+
private post;
|
|
107
|
+
private url;
|
|
108
|
+
private tenantQuery;
|
|
34
109
|
}
|
|
35
|
-
import {
|
|
36
|
-
import { IKinotic } from "@kinotic-ai/core";
|
|
110
|
+
import { ServerInfo as ServerInfo2 } from "@kinotic-ai/core";
|
|
37
111
|
/**
|
|
38
|
-
* The
|
|
39
|
-
*
|
|
40
|
-
* checked on that tenant in the application's store.
|
|
112
|
+
* The variables a deployment hands a UI's build to name the application's API host, as Vite exposes them
|
|
113
|
+
* on {@code import.meta.env}.
|
|
41
114
|
*/
|
|
42
|
-
interface
|
|
43
|
-
/** The
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
* users sign in through it from the application's login page by the tenant's id, and a user it signs in
|
|
52
|
-
* for the first time is created in the tenant, granted the given role on it. The configuration names the
|
|
53
|
-
* provider kind, the client id and the authority; a client secret is named by reference to one an
|
|
54
|
-
* operator stores, or left out for a public client. Needs tenant_can_edit.
|
|
55
|
-
* @param configuration the provider, as a new configuration; its ownership is set by the platform
|
|
56
|
-
* @param ssoRoleId the role granted to a user the provider signs in for the first time, one of those
|
|
57
|
-
* ITenantMemberService.findRoles lists, or null for membership alone
|
|
58
|
-
* @return the tenant as saved, naming the configuration
|
|
59
|
-
*/
|
|
60
|
-
configureSso(configuration: OidcConfiguration, ssoRoleId: string | null): Promise<Tenant>;
|
|
61
|
-
/**
|
|
62
|
-
* Removes the caller's tenant's identity provider, so its users sign in with passwords; a user the
|
|
63
|
-
* provider created keeps its account. Needs tenant_can_edit.
|
|
64
|
-
* @return the tenant as saved
|
|
65
|
-
*/
|
|
66
|
-
removeSso(): Promise<Tenant>;
|
|
67
|
-
}
|
|
68
|
-
declare class TenantService implements ITenantService {
|
|
69
|
-
private readonly serviceProxy;
|
|
70
|
-
constructor(kinotic: IKinotic);
|
|
71
|
-
getTenant(): Promise<Tenant>;
|
|
72
|
-
rename(name: string): Promise<Tenant>;
|
|
73
|
-
getSso(): Promise<OidcConfiguration | null>;
|
|
74
|
-
configureSso(configuration: OidcConfiguration, ssoRoleId: string | null): Promise<Tenant>;
|
|
75
|
-
removeSso(): Promise<Tenant>;
|
|
115
|
+
interface KinoticBuildEnv {
|
|
116
|
+
/** The application's API host, such as {@code acme--orders.apps-api.kinotic.io}. */
|
|
117
|
+
readonly VITE_KINOTIC_HOST?: string;
|
|
118
|
+
/** Its port, 1 through 65535; absent, the default port of the scheme. */
|
|
119
|
+
readonly VITE_KINOTIC_PORT?: string;
|
|
120
|
+
/** {@code "true"} when the host is reached over TLS. */
|
|
121
|
+
readonly VITE_KINOTIC_USE_SSL?: string;
|
|
122
|
+
/** The build's other variables, so {@code import.meta.env} is accepted whether or not the UI declares these three. */
|
|
123
|
+
readonly [name: string]: any;
|
|
76
124
|
}
|
|
77
|
-
import { Grant, PendingInviteSummary, RoleDefinition, Subject, UserParticipantIdentity } from "@kinotic-ai/management-api";
|
|
78
|
-
import { IKinotic as IKinotic2, IterablePage, Pageable } from "@kinotic-ai/core";
|
|
79
125
|
/**
|
|
80
|
-
* The
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* and managing them tenant_can_manage_access, all of which the tenant's administrator holds.
|
|
126
|
+
* The server a UI was built against.
|
|
127
|
+
* @param env the build's variables; a Vite UI passes {@code import.meta.env}
|
|
128
|
+
* @return the application's API host, to connect to and to send the sign-in requests to
|
|
129
|
+
* @throws Error when the build was handed no host, or a port that is not one
|
|
85
130
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
131
|
+
declare function serverFromEnv(env: KinoticBuildEnv): ServerInfo2;
|
|
132
|
+
/**
|
|
133
|
+
* The leading label of application zones, which follow the form app.<organizationId>.<applicationId>
|
|
134
|
+
*/
|
|
135
|
+
declare const APP_ZONE_PREFIX = "app";
|
|
136
|
+
/**
|
|
137
|
+
* Builds the zone that all of an application's services live in
|
|
138
|
+
* @param organizationId the id of the organization that owns the application
|
|
139
|
+
* @param applicationId the id of the application
|
|
140
|
+
* @return the application zone, app.<organizationId>.<applicationId>
|
|
141
|
+
*/
|
|
142
|
+
declare function appZone(organizationId: string, applicationId: string): string;
|
|
143
|
+
/**
|
|
144
|
+
* Configuration for a single entities path and its corresponding repository output.
|
|
145
|
+
*/
|
|
146
|
+
type EntitiesPathConfig = {
|
|
89
147
|
/**
|
|
90
|
-
*
|
|
91
|
-
* Rejects when the email already has an account in the application or an invitation is pending for it,
|
|
92
|
-
* and when the application does not enable invitations into a tenant.
|
|
148
|
+
* The path to search for classes decorated with @Entity.
|
|
93
149
|
*/
|
|
94
|
-
|
|
95
|
-
/** The live (unexpired) invitations into the tenant. */
|
|
96
|
-
findPendingInvites(pageable: Pageable): Promise<IterablePage<PendingInviteSummary>>;
|
|
97
|
-
/** Cancels an invitation into the tenant. */
|
|
98
|
-
cancelInvite(inviteId: string): Promise<void>;
|
|
150
|
+
path: string;
|
|
99
151
|
/**
|
|
100
|
-
*
|
|
101
|
-
* themselves.
|
|
152
|
+
* The path where generated Repository classes will be placed.
|
|
102
153
|
*/
|
|
103
|
-
|
|
154
|
+
repositoryPath: string;
|
|
104
155
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
156
|
+
* If true, the subfolder structure under the entities path will be mirrored under the repository path.
|
|
157
|
+
* For example, if entitiesPath is "src/model" and contains "payments/Payment.ts",
|
|
158
|
+
* the generated repository will be placed in "repositoryPath/payments/".
|
|
159
|
+
* If false, all generated repositories are placed directly in the repositoryPath.
|
|
160
|
+
* Defaults to true.
|
|
107
161
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
162
|
+
mirrorFolderStructure?: boolean;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* The project configuration for a Kinotic project.
|
|
166
|
+
*/
|
|
167
|
+
declare class KinoticProjectConfig {
|
|
111
168
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
* @param subject a user naming the identity id of one of the tenant's users
|
|
115
|
-
* @param roleId the role granted, one {@link findRoles} lists, such as tenant.viewer or invoice.editor
|
|
169
|
+
* The name of the project or undefined if a project name is used.
|
|
170
|
+
* i.e. if the project is typescript the package.json name will be used.
|
|
116
171
|
*/
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
172
|
+
name?: string;
|
|
173
|
+
/**
|
|
174
|
+
* The description of the project.
|
|
175
|
+
*/
|
|
176
|
+
description?: string;
|
|
177
|
+
/**
|
|
178
|
+
* The id of the Kinotic Organization that this project belongs to.
|
|
179
|
+
*/
|
|
180
|
+
organizationId: string;
|
|
181
|
+
/**
|
|
182
|
+
* The id of the Kinotic Application that this project belongs to.
|
|
183
|
+
*/
|
|
184
|
+
applicationId: string;
|
|
185
|
+
/**
|
|
186
|
+
* The id of the Kinotic Project this configuration belongs to. Every server interaction the CLI
|
|
187
|
+
* makes on the project's behalf, such as `kinotic sync`, addresses this project; it must already
|
|
188
|
+
* exist in Kinotic OS.
|
|
189
|
+
*/
|
|
190
|
+
projectId: string;
|
|
191
|
+
/**
|
|
192
|
+
* The paths to search for classes decorated with @Entity that Kinotic will be created for.
|
|
193
|
+
* Each entry can be a string (simple path) or an {@link EntitiesPathConfig} object for full control
|
|
194
|
+
* over where repository classes are generated.
|
|
195
|
+
*
|
|
196
|
+
* When a plain string is provided, the {@link generatedPath} will be used as the repository output path.
|
|
197
|
+
*/
|
|
198
|
+
entitiesPaths: (string | EntitiesPathConfig)[];
|
|
199
|
+
/**
|
|
200
|
+
* The paths to search for classes decorated with @Publish, the services the project serves. `kinotic sync`
|
|
201
|
+
* writes their definitions to the ServiceDefinitions module in {@link generatedPath}, which the project
|
|
202
|
+
* imports so each service registers in the platform's service directory as it comes online.
|
|
203
|
+
*/
|
|
204
|
+
servicesPaths?: string[];
|
|
205
|
+
/**
|
|
206
|
+
* The default path to where generated files will be placed when entitiesPaths contains plain strings, and
|
|
207
|
+
* where the ServiceDefinitions module of {@link servicesPaths} is written.
|
|
208
|
+
* Ignored for entitiesPaths entries that use {@link EntitiesPathConfig}.
|
|
209
|
+
*/
|
|
210
|
+
generatedPath?: string;
|
|
211
|
+
/**
|
|
212
|
+
* The file extension to use for imports in generated files.
|
|
213
|
+
*/
|
|
214
|
+
fileExtensionForImports: string;
|
|
215
|
+
/**
|
|
216
|
+
* If true the generated Repository classes will validate all data before sending to the server.
|
|
217
|
+
*/
|
|
218
|
+
validate?: boolean;
|
|
142
219
|
}
|
|
143
|
-
export {
|
|
220
|
+
export { APP_ZONE_PREFIX, ApplicationLogin, EntitiesPathConfig, KinoticBuildEnv, KinoticProjectConfig, LoginMethod, LoginMethodType, SignUpStarted, SignUpStartedType, appZone, serverFromEnv };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,143 +1,220 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Identifiable } from "@kinotic-ai/core";
|
|
1
|
+
import { ConnectedInfo, ServerInfo } from "@kinotic-ai/core";
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
5
|
-
* object the application's store grants on. A tenant is created by a customer signing up, or by the application
|
|
6
|
-
* for each user when it isolates them.
|
|
3
|
+
* How a sign-in method signs a person in.
|
|
7
4
|
*/
|
|
8
|
-
declare
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
declare enum LoginMethodType {
|
|
6
|
+
/** With an email and a password, which the page offers as a form. */
|
|
7
|
+
PASSWORD = "PASSWORD",
|
|
8
|
+
/** Through an OIDC provider, which the page offers as a button that starts a sign-in through it. */
|
|
9
|
+
OIDC = "OIDC"
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A sign-in method an application's login offers, as its login and sign-up pages render it.
|
|
13
|
+
*/
|
|
14
|
+
interface LoginMethod {
|
|
15
|
+
/** The id of the configuration offered; an OIDC method's starts a sign-in through it. */
|
|
16
|
+
configurationId: string;
|
|
17
|
+
type: LoginMethodType;
|
|
18
|
+
/** The name the page shows for the method. */
|
|
19
|
+
name: string;
|
|
20
|
+
/** The key of the OIDC provider kind ({@code google}, {@code azure-ad}, {@code okta}, …), for branding, or null for an email and a password. */
|
|
21
|
+
provider: string | null;
|
|
13
22
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
23
|
+
* Whether a person who has no user yet becomes one: with an email and a password, by signing up with
|
|
24
|
+
* them, or through an OIDC provider, on the first sign-in of a person it verifies.
|
|
16
25
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
signUp: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* How the person who started a sign-up gets the link that completes it.
|
|
30
|
+
*/
|
|
31
|
+
declare enum SignUpStartedType {
|
|
32
|
+
/** The server emailed the link, so the page tells the person to check their inbox. */
|
|
33
|
+
EMAILED = "EMAILED",
|
|
34
|
+
/** The server sends no email and answered with the link, which the page shows for the person to open. */
|
|
35
|
+
LINK = "LINK"
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* What the sign-up page shows once the server accepted the email.
|
|
39
|
+
*/
|
|
40
|
+
type SignUpStarted = {
|
|
41
|
+
type: SignUpStartedType.EMAILED;
|
|
42
|
+
} | {
|
|
43
|
+
type: SignUpStartedType.LINK;
|
|
44
|
+
verificationUrl: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The login of an application, or of one of its tenants, as a page of one of the application's UIs uses
|
|
48
|
+
* it in a browser: the app server's sign-in and sign-up routes at the application's API host. A sign-in
|
|
49
|
+
* establishes the session cookie for that host, and the connection is opened on it through
|
|
50
|
+
* {@code Kinotic.session}, which also signs the page out ({@code Kinotic.session.logout()}) and reports a
|
|
51
|
+
* session that ended ({@code Kinotic.session.ended}).
|
|
52
|
+
*/
|
|
53
|
+
declare class ApplicationLogin {
|
|
54
|
+
private readonly server;
|
|
55
|
+
private readonly tenantId?;
|
|
22
56
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
57
|
+
* @param server the application's API host, see {@link serverFromEnv}
|
|
58
|
+
* @param tenantId the tenant to sign in to from a page that is not one of the tenant's sites; a page
|
|
59
|
+
* served at a tenant's site signs in to that tenant without it
|
|
25
60
|
*/
|
|
26
|
-
|
|
61
|
+
constructor(server: ServerInfo, tenantId?: string | undefined);
|
|
27
62
|
/**
|
|
28
|
-
* The
|
|
29
|
-
*
|
|
63
|
+
* The sign-in methods the login offers, in the order to show them: the password form for
|
|
64
|
+
* {@link LoginMethodType.PASSWORD}, a "Continue with name" button for each {@link LoginMethodType.OIDC}.
|
|
30
65
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
66
|
+
loginMethods(): Promise<LoginMethod[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Signs in with a user's email and password, then opens the connection.
|
|
69
|
+
* @return the {@link ConnectedInfo} of the connection
|
|
70
|
+
* @throws Error with the server's message; when it gives none, "Invalid credentials" for a refused
|
|
71
|
+
* login and "Could not sign in" for any other failure
|
|
72
|
+
*/
|
|
73
|
+
login(email: string, password: string): Promise<ConnectedInfo>;
|
|
74
|
+
/**
|
|
75
|
+
* Starts a sign-in through an OIDC method; the browser leaves the page for the provider, and returns
|
|
76
|
+
* to {@code /} of the site signed in, or to its {@code /login?error=<code>}.
|
|
77
|
+
*/
|
|
78
|
+
continueWith(method: LoginMethod): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Opens the connection on the session cookie, for a returning tab and for a page the provider
|
|
81
|
+
* returned to; rejects when the page is not signed in or the connection cannot be opened in three
|
|
82
|
+
* attempts. The connection is reconnected when it drops, and ends for good after three failed
|
|
83
|
+
* attempts to, which {@code Kinotic.session.ended} reports.
|
|
84
|
+
* @return the {@link ConnectedInfo} of the connection
|
|
85
|
+
*/
|
|
86
|
+
resume(): Promise<ConnectedInfo>;
|
|
87
|
+
/**
|
|
88
|
+
* Starts a sign-up with an email and a password, offered while the password method's
|
|
89
|
+
* {@link LoginMethod.signUp} is true.
|
|
90
|
+
* @return how the person gets the link that completes the sign-up
|
|
91
|
+
* @throws Error when the server reports that the email already has a user, who signs in instead
|
|
92
|
+
*/
|
|
93
|
+
startSignUp(email: string): Promise<SignUpStarted>;
|
|
94
|
+
/**
|
|
95
|
+
* Completes the sign-up the link's token was issued for, which creates the user and signs the page in,
|
|
96
|
+
* then opens the connection.
|
|
97
|
+
* @param token the {@code token} parameter of the link, on the UI's {@code /signup/verify} page
|
|
98
|
+
* @param password the password the person chose
|
|
99
|
+
* @param displayName the person's name, at most 200 characters
|
|
100
|
+
* @return the {@link ConnectedInfo} of the connection, or null when the user was created but the
|
|
101
|
+
* connection could not be opened: the link is spent, so the page sends the person to its
|
|
102
|
+
* login page to sign in with the new password
|
|
103
|
+
* @throws Error with the server's message when the sign-up was not completed
|
|
104
|
+
*/
|
|
105
|
+
completeSignUp(token: string, password: string, displayName?: string): Promise<ConnectedInfo | null>;
|
|
106
|
+
private post;
|
|
107
|
+
private url;
|
|
108
|
+
private tenantQuery;
|
|
34
109
|
}
|
|
35
|
-
import {
|
|
36
|
-
import { IKinotic } from "@kinotic-ai/core";
|
|
110
|
+
import { ServerInfo as ServerInfo2 } from "@kinotic-ai/core";
|
|
37
111
|
/**
|
|
38
|
-
* The
|
|
39
|
-
*
|
|
40
|
-
* checked on that tenant in the application's store.
|
|
112
|
+
* The variables a deployment hands a UI's build to name the application's API host, as Vite exposes them
|
|
113
|
+
* on {@code import.meta.env}.
|
|
41
114
|
*/
|
|
42
|
-
interface
|
|
43
|
-
/** The
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
* users sign in through it from the application's login page by the tenant's id, and a user it signs in
|
|
52
|
-
* for the first time is created in the tenant, granted the given role on it. The configuration names the
|
|
53
|
-
* provider kind, the client id and the authority; a client secret is named by reference to one an
|
|
54
|
-
* operator stores, or left out for a public client. Needs tenant_can_edit.
|
|
55
|
-
* @param configuration the provider, as a new configuration; its ownership is set by the platform
|
|
56
|
-
* @param ssoRoleId the role granted to a user the provider signs in for the first time, one of those
|
|
57
|
-
* ITenantMemberService.findRoles lists, or null for membership alone
|
|
58
|
-
* @return the tenant as saved, naming the configuration
|
|
59
|
-
*/
|
|
60
|
-
configureSso(configuration: OidcConfiguration, ssoRoleId: string | null): Promise<Tenant>;
|
|
61
|
-
/**
|
|
62
|
-
* Removes the caller's tenant's identity provider, so its users sign in with passwords; a user the
|
|
63
|
-
* provider created keeps its account. Needs tenant_can_edit.
|
|
64
|
-
* @return the tenant as saved
|
|
65
|
-
*/
|
|
66
|
-
removeSso(): Promise<Tenant>;
|
|
67
|
-
}
|
|
68
|
-
declare class TenantService implements ITenantService {
|
|
69
|
-
private readonly serviceProxy;
|
|
70
|
-
constructor(kinotic: IKinotic);
|
|
71
|
-
getTenant(): Promise<Tenant>;
|
|
72
|
-
rename(name: string): Promise<Tenant>;
|
|
73
|
-
getSso(): Promise<OidcConfiguration | null>;
|
|
74
|
-
configureSso(configuration: OidcConfiguration, ssoRoleId: string | null): Promise<Tenant>;
|
|
75
|
-
removeSso(): Promise<Tenant>;
|
|
115
|
+
interface KinoticBuildEnv {
|
|
116
|
+
/** The application's API host, such as {@code acme--orders.apps-api.kinotic.io}. */
|
|
117
|
+
readonly VITE_KINOTIC_HOST?: string;
|
|
118
|
+
/** Its port, 1 through 65535; absent, the default port of the scheme. */
|
|
119
|
+
readonly VITE_KINOTIC_PORT?: string;
|
|
120
|
+
/** {@code "true"} when the host is reached over TLS. */
|
|
121
|
+
readonly VITE_KINOTIC_USE_SSL?: string;
|
|
122
|
+
/** The build's other variables, so {@code import.meta.env} is accepted whether or not the UI declares these three. */
|
|
123
|
+
readonly [name: string]: any;
|
|
76
124
|
}
|
|
77
|
-
import { Grant, PendingInviteSummary, RoleDefinition, Subject, UserParticipantIdentity } from "@kinotic-ai/management-api";
|
|
78
|
-
import { IKinotic as IKinotic2, IterablePage, Pageable } from "@kinotic-ai/core";
|
|
79
125
|
/**
|
|
80
|
-
* The
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* and managing them tenant_can_manage_access, all of which the tenant's administrator holds.
|
|
126
|
+
* The server a UI was built against.
|
|
127
|
+
* @param env the build's variables; a Vite UI passes {@code import.meta.env}
|
|
128
|
+
* @return the application's API host, to connect to and to send the sign-in requests to
|
|
129
|
+
* @throws Error when the build was handed no host, or a port that is not one
|
|
85
130
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
131
|
+
declare function serverFromEnv(env: KinoticBuildEnv): ServerInfo2;
|
|
132
|
+
/**
|
|
133
|
+
* The leading label of application zones, which follow the form app.<organizationId>.<applicationId>
|
|
134
|
+
*/
|
|
135
|
+
declare const APP_ZONE_PREFIX = "app";
|
|
136
|
+
/**
|
|
137
|
+
* Builds the zone that all of an application's services live in
|
|
138
|
+
* @param organizationId the id of the organization that owns the application
|
|
139
|
+
* @param applicationId the id of the application
|
|
140
|
+
* @return the application zone, app.<organizationId>.<applicationId>
|
|
141
|
+
*/
|
|
142
|
+
declare function appZone(organizationId: string, applicationId: string): string;
|
|
143
|
+
/**
|
|
144
|
+
* Configuration for a single entities path and its corresponding repository output.
|
|
145
|
+
*/
|
|
146
|
+
type EntitiesPathConfig = {
|
|
89
147
|
/**
|
|
90
|
-
*
|
|
91
|
-
* Rejects when the email already has an account in the application or an invitation is pending for it,
|
|
92
|
-
* and when the application does not enable invitations into a tenant.
|
|
148
|
+
* The path to search for classes decorated with @Entity.
|
|
93
149
|
*/
|
|
94
|
-
|
|
95
|
-
/** The live (unexpired) invitations into the tenant. */
|
|
96
|
-
findPendingInvites(pageable: Pageable): Promise<IterablePage<PendingInviteSummary>>;
|
|
97
|
-
/** Cancels an invitation into the tenant. */
|
|
98
|
-
cancelInvite(inviteId: string): Promise<void>;
|
|
150
|
+
path: string;
|
|
99
151
|
/**
|
|
100
|
-
*
|
|
101
|
-
* themselves.
|
|
152
|
+
* The path where generated Repository classes will be placed.
|
|
102
153
|
*/
|
|
103
|
-
|
|
154
|
+
repositoryPath: string;
|
|
104
155
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
156
|
+
* If true, the subfolder structure under the entities path will be mirrored under the repository path.
|
|
157
|
+
* For example, if entitiesPath is "src/model" and contains "payments/Payment.ts",
|
|
158
|
+
* the generated repository will be placed in "repositoryPath/payments/".
|
|
159
|
+
* If false, all generated repositories are placed directly in the repositoryPath.
|
|
160
|
+
* Defaults to true.
|
|
107
161
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
162
|
+
mirrorFolderStructure?: boolean;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* The project configuration for a Kinotic project.
|
|
166
|
+
*/
|
|
167
|
+
declare class KinoticProjectConfig {
|
|
111
168
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
* @param subject a user naming the identity id of one of the tenant's users
|
|
115
|
-
* @param roleId the role granted, one {@link findRoles} lists, such as tenant.viewer or invoice.editor
|
|
169
|
+
* The name of the project or undefined if a project name is used.
|
|
170
|
+
* i.e. if the project is typescript the package.json name will be used.
|
|
116
171
|
*/
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
172
|
+
name?: string;
|
|
173
|
+
/**
|
|
174
|
+
* The description of the project.
|
|
175
|
+
*/
|
|
176
|
+
description?: string;
|
|
177
|
+
/**
|
|
178
|
+
* The id of the Kinotic Organization that this project belongs to.
|
|
179
|
+
*/
|
|
180
|
+
organizationId: string;
|
|
181
|
+
/**
|
|
182
|
+
* The id of the Kinotic Application that this project belongs to.
|
|
183
|
+
*/
|
|
184
|
+
applicationId: string;
|
|
185
|
+
/**
|
|
186
|
+
* The id of the Kinotic Project this configuration belongs to. Every server interaction the CLI
|
|
187
|
+
* makes on the project's behalf, such as `kinotic sync`, addresses this project; it must already
|
|
188
|
+
* exist in Kinotic OS.
|
|
189
|
+
*/
|
|
190
|
+
projectId: string;
|
|
191
|
+
/**
|
|
192
|
+
* The paths to search for classes decorated with @Entity that Kinotic will be created for.
|
|
193
|
+
* Each entry can be a string (simple path) or an {@link EntitiesPathConfig} object for full control
|
|
194
|
+
* over where repository classes are generated.
|
|
195
|
+
*
|
|
196
|
+
* When a plain string is provided, the {@link generatedPath} will be used as the repository output path.
|
|
197
|
+
*/
|
|
198
|
+
entitiesPaths: (string | EntitiesPathConfig)[];
|
|
199
|
+
/**
|
|
200
|
+
* The paths to search for classes decorated with @Publish, the services the project serves. `kinotic sync`
|
|
201
|
+
* writes their definitions to the ServiceDefinitions module in {@link generatedPath}, which the project
|
|
202
|
+
* imports so each service registers in the platform's service directory as it comes online.
|
|
203
|
+
*/
|
|
204
|
+
servicesPaths?: string[];
|
|
205
|
+
/**
|
|
206
|
+
* The default path to where generated files will be placed when entitiesPaths contains plain strings, and
|
|
207
|
+
* where the ServiceDefinitions module of {@link servicesPaths} is written.
|
|
208
|
+
* Ignored for entitiesPaths entries that use {@link EntitiesPathConfig}.
|
|
209
|
+
*/
|
|
210
|
+
generatedPath?: string;
|
|
211
|
+
/**
|
|
212
|
+
* The file extension to use for imports in generated files.
|
|
213
|
+
*/
|
|
214
|
+
fileExtensionForImports: string;
|
|
215
|
+
/**
|
|
216
|
+
* If true the generated Repository classes will validate all data before sending to the server.
|
|
217
|
+
*/
|
|
218
|
+
validate?: boolean;
|
|
142
219
|
}
|
|
143
|
-
export {
|
|
220
|
+
export { APP_ZONE_PREFIX, ApplicationLogin, EntitiesPathConfig, KinoticBuildEnv, KinoticProjectConfig, LoginMethod, LoginMethodType, SignUpStarted, SignUpStartedType, appZone, serverFromEnv };
|
package/dist/index.js
CHANGED
|
@@ -1,99 +1,149 @@
|
|
|
1
|
-
// packages/app-api/src/
|
|
2
|
-
import {
|
|
1
|
+
// packages/app-api/src/api/ApplicationLogin.ts
|
|
2
|
+
import { buildServerUrl, Kinotic } from "@kinotic-ai/core";
|
|
3
3
|
|
|
4
|
-
// packages/app-api/src/api/model/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
name = "";
|
|
11
|
-
createdBy = null;
|
|
12
|
-
ssoConfigId = null;
|
|
13
|
-
ssoRoleId = null;
|
|
14
|
-
created = null;
|
|
15
|
-
updated = null;
|
|
16
|
-
}
|
|
17
|
-
// packages/app-api/src/api/services/ITenantService.ts
|
|
18
|
-
import { APP_API_ZONE } from "@kinotic-ai/management-api";
|
|
4
|
+
// packages/app-api/src/api/model/SignUpStartedType.ts
|
|
5
|
+
var SignUpStartedType;
|
|
6
|
+
((SignUpStartedType) => {
|
|
7
|
+
SignUpStartedType["EMAILED"] = "EMAILED";
|
|
8
|
+
SignUpStartedType["LINK"] = "LINK";
|
|
9
|
+
})(SignUpStartedType ||= {});
|
|
19
10
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
11
|
+
// packages/app-api/src/api/ApplicationLogin.ts
|
|
12
|
+
class ApplicationLogin {
|
|
13
|
+
server;
|
|
14
|
+
tenantId;
|
|
15
|
+
constructor(server, tenantId) {
|
|
16
|
+
this.server = server;
|
|
17
|
+
this.tenantId = tenantId;
|
|
18
|
+
}
|
|
19
|
+
async loginMethods() {
|
|
20
|
+
const response = await fetch(this.url("/api/auth/app/login/methods" + this.tenantQuery()), { credentials: "include" });
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
throw new Error(await errorMessage(response, "Could not load sign-in methods"));
|
|
23
|
+
}
|
|
24
|
+
return await response.json();
|
|
25
|
+
}
|
|
26
|
+
async login(email, password) {
|
|
27
|
+
const response = await this.post("/api/auth/app/login", { email, password, tenantId: this.tenantId });
|
|
28
|
+
if (!response.ok) {
|
|
29
|
+
throw new Error(await errorMessage(response, response.status === 401 ? "Invalid credentials" : "Could not sign in"));
|
|
30
|
+
}
|
|
31
|
+
return this.resume();
|
|
32
|
+
}
|
|
33
|
+
async continueWith(method) {
|
|
34
|
+
const response = await this.post("/api/auth/app/login/oidc/start/" + encodeURIComponent(method.configurationId) + this.tenantQuery());
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
throw new Error(await errorMessage(response, "Could not start sign-in"));
|
|
37
|
+
}
|
|
38
|
+
const { redirect } = await response.json();
|
|
39
|
+
window.location.assign(redirect);
|
|
40
|
+
}
|
|
41
|
+
resume() {
|
|
42
|
+
return Kinotic.session.resume({
|
|
43
|
+
server: this.server,
|
|
44
|
+
maxConnectionAttempts: 3
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
async startSignUp(email) {
|
|
48
|
+
const response = await this.post("/api/auth/app/signup", { email });
|
|
49
|
+
if (response.status === 409) {
|
|
50
|
+
throw new Error("An account already exists for this email. Sign in instead.");
|
|
51
|
+
}
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
throw new Error(await errorMessage(response, "Could not start sign-up"));
|
|
54
|
+
}
|
|
55
|
+
let ret;
|
|
56
|
+
if (response.status === 200) {
|
|
57
|
+
const { verificationUrl } = await response.json();
|
|
58
|
+
ret = { type: "LINK" /* LINK */, verificationUrl };
|
|
59
|
+
} else {
|
|
60
|
+
ret = { type: "EMAILED" /* EMAILED */ };
|
|
61
|
+
}
|
|
62
|
+
return ret;
|
|
63
|
+
}
|
|
64
|
+
async completeSignUp(token, password, displayName) {
|
|
65
|
+
const response = await this.post("/api/auth/app/signup/complete", { token, password, displayName });
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
throw new Error(await errorMessage(response, "Could not finish sign-up"));
|
|
68
|
+
}
|
|
69
|
+
let ret = null;
|
|
70
|
+
try {
|
|
71
|
+
ret = await this.resume();
|
|
72
|
+
} catch {}
|
|
73
|
+
return ret;
|
|
74
|
+
}
|
|
75
|
+
post(path, body) {
|
|
76
|
+
return fetch(this.url(path), {
|
|
77
|
+
method: "POST",
|
|
78
|
+
credentials: "include",
|
|
79
|
+
headers: body ? { "Content-Type": "application/json" } : undefined,
|
|
80
|
+
body: body ? JSON.stringify(body) : undefined
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
url(path) {
|
|
84
|
+
return buildServerUrl(this.server, "http") + path;
|
|
85
|
+
}
|
|
86
|
+
tenantQuery() {
|
|
87
|
+
return this.tenantId ? "?tenantId=" + encodeURIComponent(this.tenantId) : "";
|
|
39
88
|
}
|
|
40
89
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
class TenantMemberService {
|
|
50
|
-
serviceProxy;
|
|
51
|
-
constructor(kinotic) {
|
|
52
|
-
this.serviceProxy = kinotic.serviceProxy(`${APP_API_ZONE2}~org.kinotic.domain.api.services.security.TenantMemberService`);
|
|
53
|
-
}
|
|
54
|
-
async findMembers(pageable) {
|
|
55
|
-
const page = await this.serviceProxy.invoke("findMembers", [pageable]);
|
|
56
|
-
return new FunctionalIterablePage(pageable, page, (next) => this.serviceProxy.invoke("findMembers", [next]));
|
|
57
|
-
}
|
|
58
|
-
inviteMember(email, displayName) {
|
|
59
|
-
return this.serviceProxy.invoke("inviteMember", [email, displayName]);
|
|
60
|
-
}
|
|
61
|
-
async findPendingInvites(pageable) {
|
|
62
|
-
const page = await this.serviceProxy.invoke("findPendingInvites", [pageable]);
|
|
63
|
-
return new FunctionalIterablePage(pageable, page, (next) => this.serviceProxy.invoke("findPendingInvites", [next]));
|
|
64
|
-
}
|
|
65
|
-
cancelInvite(inviteId) {
|
|
66
|
-
return this.serviceProxy.invoke("cancelInvite", [inviteId]);
|
|
67
|
-
}
|
|
68
|
-
removeMember(userId) {
|
|
69
|
-
return this.serviceProxy.invoke("removeMember", [userId]);
|
|
70
|
-
}
|
|
71
|
-
findRoles() {
|
|
72
|
-
return this.serviceProxy.invoke("findRoles", []);
|
|
73
|
-
}
|
|
74
|
-
findGrants() {
|
|
75
|
-
return this.serviceProxy.invoke("findGrants", []);
|
|
76
|
-
}
|
|
77
|
-
grant(subject, roleId) {
|
|
78
|
-
return this.serviceProxy.invoke("grant", [subject, roleId]);
|
|
79
|
-
}
|
|
80
|
-
revoke(grantId) {
|
|
81
|
-
return this.serviceProxy.invoke("revoke", [grantId]);
|
|
82
|
-
}
|
|
90
|
+
async function errorMessage(response, fallback) {
|
|
91
|
+
let ret = fallback;
|
|
92
|
+
try {
|
|
93
|
+
const body = await response.json();
|
|
94
|
+
ret = body.error || fallback;
|
|
95
|
+
} catch {}
|
|
96
|
+
return ret;
|
|
83
97
|
}
|
|
84
|
-
// packages/app-api/src/api/
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
98
|
+
// packages/app-api/src/api/BuildEnv.ts
|
|
99
|
+
function serverFromEnv(env) {
|
|
100
|
+
const host = env.VITE_KINOTIC_HOST;
|
|
101
|
+
if (!host) {
|
|
102
|
+
throw new Error("VITE_KINOTIC_HOST is not set: the build was not handed the address of the application's API host");
|
|
103
|
+
}
|
|
104
|
+
const useSSL = env.VITE_KINOTIC_USE_SSL === "true";
|
|
105
|
+
let port = useSSL ? 443 : 80;
|
|
106
|
+
if (env.VITE_KINOTIC_PORT) {
|
|
107
|
+
port = /^\d+$/.test(env.VITE_KINOTIC_PORT) ? Number(env.VITE_KINOTIC_PORT) : NaN;
|
|
108
|
+
if (!(port >= 1 && port <= 65535)) {
|
|
109
|
+
throw new Error(`VITE_KINOTIC_PORT is not a port: ${env.VITE_KINOTIC_PORT}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { host, port, useSSL };
|
|
113
|
+
}
|
|
114
|
+
// packages/app-api/src/api/Zones.ts
|
|
115
|
+
import { validateLabel } from "@kinotic-ai/core";
|
|
116
|
+
var APP_ZONE_PREFIX = "app";
|
|
117
|
+
function appZone(organizationId, applicationId) {
|
|
118
|
+
validateLabel(organizationId);
|
|
119
|
+
validateLabel(applicationId);
|
|
120
|
+
return `${APP_ZONE_PREFIX}.${organizationId}.${applicationId}`;
|
|
121
|
+
}
|
|
122
|
+
// packages/app-api/src/api/model/KinoticProjectConfig.ts
|
|
123
|
+
class KinoticProjectConfig {
|
|
124
|
+
name;
|
|
125
|
+
description;
|
|
126
|
+
organizationId;
|
|
127
|
+
applicationId;
|
|
128
|
+
projectId;
|
|
129
|
+
entitiesPaths;
|
|
130
|
+
servicesPaths;
|
|
131
|
+
generatedPath;
|
|
132
|
+
fileExtensionForImports = ".js";
|
|
133
|
+
validate;
|
|
134
|
+
}
|
|
135
|
+
// packages/app-api/src/api/model/LoginMethodType.ts
|
|
136
|
+
var LoginMethodType;
|
|
137
|
+
((LoginMethodType) => {
|
|
138
|
+
LoginMethodType["PASSWORD"] = "PASSWORD";
|
|
139
|
+
LoginMethodType["OIDC"] = "OIDC";
|
|
140
|
+
})(LoginMethodType ||= {});
|
|
93
141
|
export {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
142
|
+
APP_ZONE_PREFIX,
|
|
143
|
+
ApplicationLogin,
|
|
144
|
+
KinoticProjectConfig,
|
|
145
|
+
LoginMethodType,
|
|
146
|
+
SignUpStartedType,
|
|
147
|
+
appZone,
|
|
148
|
+
serverFromEnv
|
|
99
149
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kinotic-ai/app-api",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.3",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Client API for the Kinotic platform's application plane: the tenant services an application's own pages call for the user they serve.",
|
|
6
5
|
"files": [
|
|
7
6
|
"dist"
|
|
8
7
|
],
|
|
@@ -38,12 +37,10 @@
|
|
|
38
37
|
"coverage": "bun test --coverage --pass-with-no-tests"
|
|
39
38
|
},
|
|
40
39
|
"peerDependencies": {
|
|
41
|
-
"@kinotic-ai/core": "^5.0.0-beta.
|
|
42
|
-
"@kinotic-ai/management-api": "^5.0.0-beta.48"
|
|
40
|
+
"@kinotic-ai/core": "^5.0.0-beta.31"
|
|
43
41
|
},
|
|
44
42
|
"devDependencies": {
|
|
45
|
-
"@kinotic-ai/core": "5.0.0-beta.
|
|
46
|
-
"@kinotic-ai/management-api": "5.0.0-beta.48",
|
|
43
|
+
"@kinotic-ai/core": "5.0.0-beta.31",
|
|
47
44
|
"@types/bun": "^1.3.9",
|
|
48
45
|
"typescript": "^5.9.3"
|
|
49
46
|
}
|