@olyzon/sdk 0.0.0 → 0.1.0-stg.2
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 +21 -0
- package/README.md +17 -1
- package/dist/client.d.ts +62 -0
- package/dist/client.js +104 -0
- package/dist/core/config.d.ts +153 -0
- package/dist/core/config.js +368 -0
- package/dist/core/contracts.d.ts +52 -0
- package/dist/core/contracts.js +12 -0
- package/dist/core/dpop.d.ts +39 -0
- package/dist/core/dpop.js +63 -0
- package/dist/core/errors.d.ts +34 -0
- package/dist/core/errors.js +43 -0
- package/dist/core/session.d.ts +82 -0
- package/dist/core/session.js +170 -0
- package/dist/core/transport.d.ts +38 -0
- package/dist/core/transport.js +84 -0
- package/dist/generated/index.d.ts +24 -0
- package/dist/generated/index.js +20 -0
- package/dist/generated/manifest.json +13 -0
- package/dist/generated/projects/client/client.gen.d.ts +2 -0
- package/dist/generated/projects/client/client.gen.js +216 -0
- package/dist/generated/projects/client/index.d.ts +10 -0
- package/dist/generated/projects/client/index.js +6 -0
- package/dist/generated/projects/client/types.gen.d.ts +120 -0
- package/dist/generated/projects/client/types.gen.js +2 -0
- package/dist/generated/projects/client/utils.gen.d.ts +37 -0
- package/dist/generated/projects/client/utils.gen.js +228 -0
- package/dist/generated/projects/client.gen.d.ts +12 -0
- package/dist/generated/projects/client.gen.js +3 -0
- package/dist/generated/projects/core/auth.gen.d.ts +25 -0
- package/dist/generated/projects/core/auth.gen.js +14 -0
- package/dist/generated/projects/core/bodySerializer.gen.d.ts +25 -0
- package/dist/generated/projects/core/bodySerializer.gen.js +57 -0
- package/dist/generated/projects/core/params.gen.d.ts +43 -0
- package/dist/generated/projects/core/params.gen.js +109 -0
- package/dist/generated/projects/core/pathSerializer.gen.d.ts +33 -0
- package/dist/generated/projects/core/pathSerializer.gen.js +106 -0
- package/dist/generated/projects/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/generated/projects/core/queryKeySerializer.gen.js +92 -0
- package/dist/generated/projects/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/generated/projects/core/serverSentEvents.gen.js +132 -0
- package/dist/generated/projects/core/types.gen.d.ts +83 -0
- package/dist/generated/projects/core/types.gen.js +2 -0
- package/dist/generated/projects/core/utils.gen.d.ts +19 -0
- package/dist/generated/projects/core/utils.gen.js +87 -0
- package/dist/generated/projects/index.d.ts +2 -0
- package/dist/generated/projects/index.js +2 -0
- package/dist/generated/projects/sdk.gen.d.ts +47 -0
- package/dist/generated/projects/sdk.gen.js +55 -0
- package/dist/generated/projects/types.gen.d.ts +388 -0
- package/dist/generated/projects/types.gen.js +2 -0
- package/dist/generated/projects.d.ts +54 -0
- package/dist/generated/projects.js +58 -0
- package/dist/generated/specs/projects.json +872 -0
- package/dist/generated/specs/sts.json +942 -0
- package/dist/generated/sts/client/client.gen.d.ts +2 -0
- package/dist/generated/sts/client/client.gen.js +216 -0
- package/dist/generated/sts/client/index.d.ts +10 -0
- package/dist/generated/sts/client/index.js +6 -0
- package/dist/generated/sts/client/types.gen.d.ts +120 -0
- package/dist/generated/sts/client/types.gen.js +2 -0
- package/dist/generated/sts/client/utils.gen.d.ts +37 -0
- package/dist/generated/sts/client/utils.gen.js +228 -0
- package/dist/generated/sts/client.gen.d.ts +12 -0
- package/dist/generated/sts/client.gen.js +3 -0
- package/dist/generated/sts/core/auth.gen.d.ts +25 -0
- package/dist/generated/sts/core/auth.gen.js +14 -0
- package/dist/generated/sts/core/bodySerializer.gen.d.ts +25 -0
- package/dist/generated/sts/core/bodySerializer.gen.js +57 -0
- package/dist/generated/sts/core/params.gen.d.ts +43 -0
- package/dist/generated/sts/core/params.gen.js +109 -0
- package/dist/generated/sts/core/pathSerializer.gen.d.ts +33 -0
- package/dist/generated/sts/core/pathSerializer.gen.js +106 -0
- package/dist/generated/sts/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/generated/sts/core/queryKeySerializer.gen.js +92 -0
- package/dist/generated/sts/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/generated/sts/core/serverSentEvents.gen.js +132 -0
- package/dist/generated/sts/core/types.gen.d.ts +83 -0
- package/dist/generated/sts/core/types.gen.js +2 -0
- package/dist/generated/sts/core/utils.gen.d.ts +19 -0
- package/dist/generated/sts/core/utils.gen.js +87 -0
- package/dist/generated/sts/index.d.ts +2 -0
- package/dist/generated/sts/index.js +2 -0
- package/dist/generated/sts/sdk.gen.d.ts +41 -0
- package/dist/generated/sts/sdk.gen.js +44 -0
- package/dist/generated/sts/types.gen.d.ts +445 -0
- package/dist/generated/sts/types.gen.js +2 -0
- package/dist/generated/sts.d.ts +44 -0
- package/dist/generated/sts.js +49 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +13 -0
- package/package.json +42 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Olyzon
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
1
|
# @olyzon/sdk
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The olyzon.ai platform SDK for TypeScript and JavaScript: every Olyzon API, generated from the OpenAPI documents the services serve, each call signed with a DPoP-bound Olyzon session.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @olyzon/sdk
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { Client } from "@olyzon/sdk";
|
|
11
|
+
|
|
12
|
+
// OLYZON_API_KEY + OLYZON_ORG_ID, or a profile in ~/.config/olyzon
|
|
13
|
+
const olyzon = new Client({ region: "us" });
|
|
14
|
+
const me = await olyzon.sts.getCallerIdentity();
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Node 22 or later, and current browsers; ESM only. Documentation: https://docs.prod.olyzon.ai
|
|
18
|
+
|
|
19
|
+
Staging builds (`X.Y.Z-stg.N`, generated from staging's APIs and calling staging by default) are under the `stg` tag: `npm install @olyzon/sdk@stg`. Their documentation: https://docs.stg.olyzon.ai
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Client`: every Olyzon API of this build, each call signed for the same
|
|
3
|
+
* caller. Its configuration comes from options, `OLYZON_*` variables and
|
|
4
|
+
* profiles (core/config.ts); its session from the STS (core/session.ts).
|
|
5
|
+
*/
|
|
6
|
+
import { type ClientConfigOptions, type ClientSettings } from "./core/config.ts";
|
|
7
|
+
import { type ForwardedCredentials, type GrantReference, type Session, type UserClient } from "./core/session.ts";
|
|
8
|
+
import { type Apis } from "./generated/index.ts";
|
|
9
|
+
export interface ClientOptions extends ClientConfigOptions {
|
|
10
|
+
/** `fetch` for every call (tests, proxies). Default: the global one. */
|
|
11
|
+
fetch?: typeof fetch;
|
|
12
|
+
/** Sessions closer than this to expiry are renewed. Default: 60 s. */
|
|
13
|
+
refreshMarginMs?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface Client extends Apis {
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Every Olyzon API of this build. With no options, the client reads its
|
|
19
|
+
* credential, org or role, environment and region from `OLYZON_*`
|
|
20
|
+
* environment variables and the profile in `~/.config/olyzon` (in a
|
|
21
|
+
* browser: the page's Clerk); any option overrides them (spec §10.6). It
|
|
22
|
+
* holds the DPoP key, gets and renews the session at the STS, and signs
|
|
23
|
+
* every call; errors are `ServiceError`s.
|
|
24
|
+
*
|
|
25
|
+
* const olyzon = new Client({ region: "us" });
|
|
26
|
+
* const me = await olyzon.sts.getCallerIdentity();
|
|
27
|
+
*/
|
|
28
|
+
export declare class Client {
|
|
29
|
+
#private;
|
|
30
|
+
/** The DPoP key, the STS exchange and the session cache. */
|
|
31
|
+
readonly user: UserClient;
|
|
32
|
+
/** The resolved settings and where each came from, without the credential. */
|
|
33
|
+
readonly config: ClientSettings;
|
|
34
|
+
constructor(options?: ClientOptions);
|
|
35
|
+
/** The org the client acts in now: in a browser, it follows the active Clerk org. */
|
|
36
|
+
get orgId(): string | undefined;
|
|
37
|
+
/** The Olyzon session the client's own calls are signed with. */
|
|
38
|
+
session(): Promise<Session>;
|
|
39
|
+
/**
|
|
40
|
+
* The APIs, called for the caller of a request this service is handling
|
|
41
|
+
* (spec §6.1): `caller` is the session and proof it received. Each call is
|
|
42
|
+
* signed with this client's session in the caller's org and carries the
|
|
43
|
+
* caller's credentials, which the receiver accepts for 60 s after the
|
|
44
|
+
* caller signed them. For Olyzon services, whose machine is named after
|
|
45
|
+
* their entry in the registry: receivers refuse anyone else.
|
|
46
|
+
*/
|
|
47
|
+
onBehalfOf(caller: ForwardedCredentials): Apis;
|
|
48
|
+
/**
|
|
49
|
+
* The APIs, called as the subject of a grant this client is the actor of
|
|
50
|
+
* (spec §6.3), for work that runs without its subject (scheduled jobs).
|
|
51
|
+
* Each API gets its own 5-minute session, exchanged with this client's
|
|
52
|
+
* session in the grant's org; the exchange fails once the grant is revoked
|
|
53
|
+
* or expired, or its subject is no longer a member.
|
|
54
|
+
*/
|
|
55
|
+
withGrant(grant: GrantReference): Apis;
|
|
56
|
+
/**
|
|
57
|
+
* The APIs, called as this client in another org: its own session there,
|
|
58
|
+
* with its role. For a service's machine acting on its own in each org it
|
|
59
|
+
* serves; not for calls made for a caller (`onBehalfOf`).
|
|
60
|
+
*/
|
|
61
|
+
inOrg(orgId: string): Apis;
|
|
62
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Client`: every Olyzon API of this build, each call signed for the same
|
|
3
|
+
* caller. Its configuration comes from options, `OLYZON_*` variables and
|
|
4
|
+
* profiles (core/config.ts); its session from the STS (core/session.ts).
|
|
5
|
+
*/
|
|
6
|
+
import { clerkTokenSource, clientScope, clientSettings, resolveClientConfig, } from "./core/config.js";
|
|
7
|
+
import { createUserClient, } from "./core/session.js";
|
|
8
|
+
import { createTransport } from "./core/transport.js";
|
|
9
|
+
import { decodeJwt } from "jose";
|
|
10
|
+
import { BUILD_ENVIRONMENT, LOCAL_PORTS, SERVICES, createApis, } from "./generated/index.js";
|
|
11
|
+
/**
|
|
12
|
+
* Every Olyzon API of this build. With no options, the client reads its
|
|
13
|
+
* credential, org or role, environment and region from `OLYZON_*`
|
|
14
|
+
* environment variables and the profile in `~/.config/olyzon` (in a
|
|
15
|
+
* browser: the page's Clerk); any option overrides them (spec §10.6). It
|
|
16
|
+
* holds the DPoP key, gets and renews the session at the STS, and signs
|
|
17
|
+
* every call; errors are `ServiceError`s.
|
|
18
|
+
*
|
|
19
|
+
* const olyzon = new Client({ region: "us" });
|
|
20
|
+
* const me = await olyzon.sts.getCallerIdentity();
|
|
21
|
+
*/
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
23
|
+
export class Client {
|
|
24
|
+
/** The DPoP key, the STS exchange and the session cache. */
|
|
25
|
+
user;
|
|
26
|
+
/** The resolved settings and where each came from, without the credential. */
|
|
27
|
+
config;
|
|
28
|
+
#scope;
|
|
29
|
+
#origins;
|
|
30
|
+
constructor(options = {}) {
|
|
31
|
+
const { fetch, refreshMarginMs, ...settings } = options;
|
|
32
|
+
const config = resolveClientConfig(settings, {
|
|
33
|
+
services: SERVICES,
|
|
34
|
+
localPorts: LOCAL_PORTS,
|
|
35
|
+
defaultEnvironment: BUILD_ENVIRONMENT,
|
|
36
|
+
});
|
|
37
|
+
const { credential, origins } = config;
|
|
38
|
+
this.user =
|
|
39
|
+
credential.kind === "user"
|
|
40
|
+
? credential.user
|
|
41
|
+
: createUserClient({
|
|
42
|
+
stsOrigin: origins.sts,
|
|
43
|
+
getClerkToken: clerkTokenSource(credential),
|
|
44
|
+
...(fetch ? { fetch } : {}),
|
|
45
|
+
...(refreshMarginMs === undefined ? {} : { refreshMarginMs }),
|
|
46
|
+
});
|
|
47
|
+
this.config = clientSettings(config);
|
|
48
|
+
this.#scope = clientScope(config);
|
|
49
|
+
this.#origins = origins;
|
|
50
|
+
const scope = this.#scope;
|
|
51
|
+
Object.assign(this, this.#apis(() => scope.session()));
|
|
52
|
+
}
|
|
53
|
+
#apis(scope) {
|
|
54
|
+
return createApis((service) => createTransport(this.user, scope, service, this.#origins[service]));
|
|
55
|
+
}
|
|
56
|
+
/** The org the client acts in now: in a browser, it follows the active Clerk org. */
|
|
57
|
+
get orgId() {
|
|
58
|
+
return this.#scope.orgId();
|
|
59
|
+
}
|
|
60
|
+
/** The Olyzon session the client's own calls are signed with. */
|
|
61
|
+
session() {
|
|
62
|
+
return this.user.getSession(this.#scope.session());
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The APIs, called for the caller of a request this service is handling
|
|
66
|
+
* (spec §6.1): `caller` is the session and proof it received. Each call is
|
|
67
|
+
* signed with this client's session in the caller's org and carries the
|
|
68
|
+
* caller's credentials, which the receiver accepts for 60 s after the
|
|
69
|
+
* caller signed them. For Olyzon services, whose machine is named after
|
|
70
|
+
* their entry in the registry: receivers refuse anyone else.
|
|
71
|
+
*/
|
|
72
|
+
onBehalfOf(caller) {
|
|
73
|
+
return this.#apis({
|
|
74
|
+
orgId: orgOfSession(caller.token),
|
|
75
|
+
role: this.config.role,
|
|
76
|
+
forward: caller,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The APIs, called as the subject of a grant this client is the actor of
|
|
81
|
+
* (spec §6.3), for work that runs without its subject (scheduled jobs).
|
|
82
|
+
* Each API gets its own 5-minute session, exchanged with this client's
|
|
83
|
+
* session in the grant's org; the exchange fails once the grant is revoked
|
|
84
|
+
* or expired, or its subject is no longer a member.
|
|
85
|
+
*/
|
|
86
|
+
withGrant(grant) {
|
|
87
|
+
return this.#apis({ role: this.config.role, grant });
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The APIs, called as this client in another org: its own session there,
|
|
91
|
+
* with its role. For a service's machine acting on its own in each org it
|
|
92
|
+
* serves; not for calls made for a caller (`onBehalfOf`).
|
|
93
|
+
*/
|
|
94
|
+
inOrg(orgId) {
|
|
95
|
+
return this.#apis({ orgId, role: this.config.role });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** The org a session acts in, read without verifying it: the receiver verifies it. */
|
|
99
|
+
function orgOfSession(token) {
|
|
100
|
+
const { org } = decodeJwt(token);
|
|
101
|
+
if (typeof org !== "string")
|
|
102
|
+
throw new TypeError("the caller's session has no org: nothing to act in");
|
|
103
|
+
return org;
|
|
104
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { SessionRequest, UserClient } from "./session.ts";
|
|
2
|
+
export declare const ENVIRONMENTS: readonly ["local", "stg", "prod"];
|
|
3
|
+
export type Environment = (typeof ENVIRONMENTS)[number];
|
|
4
|
+
export declare const REGIONS: readonly ["us", "eu"];
|
|
5
|
+
export type Region = (typeof REGIONS)[number];
|
|
6
|
+
/** `https://sts.us.stg.api.olyzon.ai` */
|
|
7
|
+
export declare function deployedOrigin(service: string, environment: Exclude<Environment, "local">, region: string): string;
|
|
8
|
+
/** What the SDK reads from Clerk: `useClerk()` in React, or `window.Clerk`. */
|
|
9
|
+
export interface ClerkLike {
|
|
10
|
+
readonly session?: {
|
|
11
|
+
getToken(): Promise<string | null>;
|
|
12
|
+
} | null;
|
|
13
|
+
readonly organization?: {
|
|
14
|
+
readonly id: string;
|
|
15
|
+
} | null;
|
|
16
|
+
}
|
|
17
|
+
export interface ClientConfigOptions {
|
|
18
|
+
/** An existing user client, to share its DPoP key and cached sessions. */
|
|
19
|
+
user?: UserClient;
|
|
20
|
+
/** A Clerk API key: a user key with `orgId`, an org key with `role`. */
|
|
21
|
+
apiKey?: string;
|
|
22
|
+
/**
|
|
23
|
+
* A Clerk M2M token (`mt_…`), for a machine: used as given, never renewed.
|
|
24
|
+
* Mint it with an expiry where the machine's secret lives, and replace it
|
|
25
|
+
* before then: the SDK never takes a machine secret.
|
|
26
|
+
*/
|
|
27
|
+
m2mToken?: string;
|
|
28
|
+
/** A Clerk instance (`useClerk()`): its session, and its active org unless `orgId` is given. */
|
|
29
|
+
clerk?: ClerkLike;
|
|
30
|
+
/** Any Clerk credential (desktop and mobile apps' OAuth tokens), read at every exchange. */
|
|
31
|
+
getClerkToken?: () => Promise<string | null>;
|
|
32
|
+
/** The org to act in; a function is read at every call. */
|
|
33
|
+
orgId?: string | (() => string | null | undefined);
|
|
34
|
+
/** The role named at exchange: org API keys and machines. */
|
|
35
|
+
role?: string;
|
|
36
|
+
/** `local`, `stg` or `prod`. Default: the environment this SDK was built for. */
|
|
37
|
+
environment?: Environment;
|
|
38
|
+
/** `us` or `eu`: required for `stg` and `prod`. */
|
|
39
|
+
region?: Region;
|
|
40
|
+
/** The profile to read in the config and credentials files. Default: `default`. */
|
|
41
|
+
profile?: string;
|
|
42
|
+
/** An origin per API (`sts`, …), over everything else. */
|
|
43
|
+
endpoints?: Record<string, string | undefined>;
|
|
44
|
+
/** `false`: read no environment variable and no file. Default: `true`. */
|
|
45
|
+
fromEnvironment?: boolean;
|
|
46
|
+
}
|
|
47
|
+
export type Credential = {
|
|
48
|
+
kind: "user";
|
|
49
|
+
user: UserClient;
|
|
50
|
+
} | {
|
|
51
|
+
kind: "apiKey";
|
|
52
|
+
apiKey: string;
|
|
53
|
+
} | {
|
|
54
|
+
kind: "m2mToken";
|
|
55
|
+
m2mToken: string;
|
|
56
|
+
} | {
|
|
57
|
+
kind: "clerk";
|
|
58
|
+
clerk: ClerkLike;
|
|
59
|
+
} | {
|
|
60
|
+
kind: "getClerkToken";
|
|
61
|
+
getClerkToken: () => Promise<string | null>;
|
|
62
|
+
};
|
|
63
|
+
export type CredentialKind = Credential["kind"];
|
|
64
|
+
/** The resolved configuration, with the credential itself: keep it private. */
|
|
65
|
+
export interface ClientConfig {
|
|
66
|
+
credential: Credential;
|
|
67
|
+
/** A function when it follows something that changes (the active Clerk org). */
|
|
68
|
+
orgId: string | (() => string | undefined) | undefined;
|
|
69
|
+
role: string | undefined;
|
|
70
|
+
environment: Environment;
|
|
71
|
+
region: Region | undefined;
|
|
72
|
+
/** The profile read in the files, when one was. */
|
|
73
|
+
profile: string | undefined;
|
|
74
|
+
/** Every API's origin, `sts` included. */
|
|
75
|
+
origins: Record<string, string>;
|
|
76
|
+
/**
|
|
77
|
+
* Where each setting came from: `options.apiKey`, `OLYZON_API_KEY`,
|
|
78
|
+
* `config [default]`, `credentials [default]`, `Clerk`, `built-in`. Keys:
|
|
79
|
+
* `credential`, `orgId`, `role`, `environment`, `region`, and each API's
|
|
80
|
+
* name for its origin.
|
|
81
|
+
*/
|
|
82
|
+
from: Record<string, string>;
|
|
83
|
+
}
|
|
84
|
+
/** The configuration without secrets: what `client.config` shows. */
|
|
85
|
+
export interface ClientSettings extends Omit<ClientConfig, "credential" | "orgId"> {
|
|
86
|
+
credential: CredentialKind;
|
|
87
|
+
/** The org, or `undefined` when it follows the active Clerk org (see `from.orgId`). */
|
|
88
|
+
orgId: string | undefined;
|
|
89
|
+
}
|
|
90
|
+
export interface ResolveContext {
|
|
91
|
+
/** The services of the build; `sts` is added when missing. */
|
|
92
|
+
services: readonly string[];
|
|
93
|
+
/** Each service's port on this machine (environment `local`). */
|
|
94
|
+
localPorts: Readonly<Record<string, number>>;
|
|
95
|
+
/** The environment the SDK was built for: the default. */
|
|
96
|
+
defaultEnvironment: Environment;
|
|
97
|
+
/** Environment variables. Default: `process.env` (none in a browser). */
|
|
98
|
+
env?: Readonly<Record<string, string | undefined>>;
|
|
99
|
+
/** Reads a file, `undefined` when it does not exist. Default: `node:fs`. */
|
|
100
|
+
readFile?: (path: string) => string | undefined;
|
|
101
|
+
/** The home directory, for `~/.config/olyzon`. Default: `node:os`. */
|
|
102
|
+
home?: string;
|
|
103
|
+
/** The page's Clerk. Default: `window.Clerk` in a browser. */
|
|
104
|
+
browserClerk?: ClerkLike;
|
|
105
|
+
}
|
|
106
|
+
/** Settings a profile in the config file may hold, besides one origin per API. */
|
|
107
|
+
export declare const CONFIG_KEYS: ReadonlySet<string>;
|
|
108
|
+
/** Settings a profile in the credentials file may hold: one of them. */
|
|
109
|
+
export declare const CREDENTIAL_KEYS: Readonly<Record<string, CredentialKind>>;
|
|
110
|
+
/** `OLYZON_STS_URL` for `sts`, `OLYZON_AD_REPORTS_URL` for `ad-reports`. */
|
|
111
|
+
export declare function originVariable(service: string): string;
|
|
112
|
+
/**
|
|
113
|
+
* The config and credentials files: `OLYZON_CONFIG_FILE` and
|
|
114
|
+
* `OLYZON_CREDENTIALS_FILE`, else `$XDG_CONFIG_HOME/olyzon/{config,credentials}`,
|
|
115
|
+
* by default under `~/.config`; `""` without a home directory.
|
|
116
|
+
*/
|
|
117
|
+
export declare function configFiles(env: Readonly<Record<string, string | undefined>>, home: string | undefined): {
|
|
118
|
+
config: string;
|
|
119
|
+
credentials: string;
|
|
120
|
+
};
|
|
121
|
+
type Sections = Map<string, Map<string, string>>;
|
|
122
|
+
/**
|
|
123
|
+
* An INI file: `[profile]` sections of `key = value` lines; `#` and `;` start
|
|
124
|
+
* a comment line. Keys are lowercased. Strict, like Python's configparser
|
|
125
|
+
* with the same settings: a repeated section or key, a line outside a section
|
|
126
|
+
* or without `=`, or a continuation line is an error.
|
|
127
|
+
*/
|
|
128
|
+
export declare function parseIni(text: string, file: string): Sections;
|
|
129
|
+
/** Resolves a client's configuration (spec §10.6). Throws `ConfigurationError`. */
|
|
130
|
+
export declare function resolveClientConfig(options: ClientConfigOptions, context: ResolveContext): ClientConfig;
|
|
131
|
+
/** The configuration without the credential itself. */
|
|
132
|
+
export declare function clientSettings(config: ClientConfig): ClientSettings;
|
|
133
|
+
/** What a client's own calls are for, read at each call. */
|
|
134
|
+
export interface ClientScope {
|
|
135
|
+
/** The org now: in a browser, the active Clerk org. */
|
|
136
|
+
orgId(): string | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* The session its own calls are signed with. A machine without an org
|
|
139
|
+
* only calls for the callers whose credentials it forwards (`onBehalfOf`):
|
|
140
|
+
* its own calls throw a `ConfigurationError`.
|
|
141
|
+
*/
|
|
142
|
+
session(): SessionRequest;
|
|
143
|
+
}
|
|
144
|
+
/** The org and session of a client's own calls, from its configuration. */
|
|
145
|
+
export declare function clientScope(config: ClientConfig): ClientScope;
|
|
146
|
+
/**
|
|
147
|
+
* The Clerk token the STS exchanges, for any credential but an existing user
|
|
148
|
+
* client: read again at every exchange.
|
|
149
|
+
*/
|
|
150
|
+
export declare function clerkTokenSource(credential: Exclude<Credential, {
|
|
151
|
+
kind: "user";
|
|
152
|
+
}>): () => Promise<string | null>;
|
|
153
|
+
export {};
|