@quartal/messages-client 0.2.0 → 0.3.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/dist/mod.d.ts +11 -3
- package/dist/mod.js +25 -5
- package/package.json +2 -2
package/dist/mod.d.ts
CHANGED
|
@@ -95,8 +95,16 @@ interface ClientConfig {
|
|
|
95
95
|
iamApiUrl: string;
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
98
|
+
* Sets the configuration at runtime, over `import.meta.env`: for an app that is not built with the
|
|
99
|
+
* `VITE_*` variables, such as a channel plugin's page that learns the API's address from the Hub.
|
|
100
|
+
* Such an app needs only what it uses: {@link loadClientConfig} then requires `messagesApiUrl` alone.
|
|
101
|
+
* @param config The values to use; a later call adds to and overrides the earlier ones.
|
|
102
|
+
*/
|
|
103
|
+
declare function configureClient(config: Partial<ClientConfig>): void;
|
|
104
|
+
/**
|
|
105
|
+
* Reads `ClientConfig` from `import.meta.env` and the values given with {@link configureClient}.
|
|
106
|
+
* Throws when a required value is missing so the failure surfaces at app startup, not at the first
|
|
107
|
+
* call.
|
|
100
108
|
*/
|
|
101
109
|
declare function loadClientConfig(): ClientConfig;
|
|
102
110
|
//#endregion
|
|
@@ -714,4 +722,4 @@ type FilesResource = Omit<MessagesApi['files'], 'forOwner' | 'createDemo'>;
|
|
|
714
722
|
*/
|
|
715
723
|
declare function filesSource(files: FilesResource, owner: string): QFsSource;
|
|
716
724
|
//#endregion
|
|
717
|
-
export { type AgentPatch, AgentsApi, ApiError, type ChannelAgentPatch, type ChannelCreateInput, ChannelsApi, type ChannelsFilter, type ChannelsRefreshResult, type ClientConfig, type FilesResource, HttpClient, type IChannelsApi, type ICrudApiBase, ID_FORMAT_PATTERN, type IModelsApi, type LiveEventHandler, LiveEvents, MessagesApi, ModelsApi, type ModelsFilter, type ODataQuery, type Query, type RequestOptions, type ThreadPatch, type TokenProvider, base64ToBytes, blobToBase64, bytesToBase64, filesSource, isValidId, loadClientConfig, toFsError };
|
|
725
|
+
export { type AgentPatch, AgentsApi, ApiError, type ChannelAgentPatch, type ChannelCreateInput, ChannelsApi, type ChannelsFilter, type ChannelsRefreshResult, type ClientConfig, type FilesResource, HttpClient, type IChannelsApi, type ICrudApiBase, ID_FORMAT_PATTERN, type IModelsApi, type LiveEventHandler, LiveEvents, MessagesApi, ModelsApi, type ModelsFilter, type ODataQuery, type Query, type RequestOptions, type ThreadPatch, type TokenProvider, base64ToBytes, blobToBase64, bytesToBase64, configureClient, filesSource, isValidId, loadClientConfig, toFsError };
|
package/dist/mod.js
CHANGED
|
@@ -26,19 +26,39 @@ function isValidId(id) {
|
|
|
26
26
|
//#region src/config/ClientConfig.ts
|
|
27
27
|
/** Default scopes: profile plus the IAM API and Messages API audiences. */
|
|
28
28
|
const DEFAULT_SCOPE = "openid profile email iam-api quartal-hub-test";
|
|
29
|
+
/** The values given with {@link configureClient}; null when the app uses `import.meta.env` only. */
|
|
30
|
+
let configured = null;
|
|
29
31
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
+
* Sets the configuration at runtime, over `import.meta.env`: for an app that is not built with the
|
|
33
|
+
* `VITE_*` variables, such as a channel plugin's page that learns the API's address from the Hub.
|
|
34
|
+
* Such an app needs only what it uses: {@link loadClientConfig} then requires `messagesApiUrl` alone.
|
|
35
|
+
* @param config The values to use; a later call adds to and overrides the earlier ones.
|
|
36
|
+
*/
|
|
37
|
+
function configureClient(config) {
|
|
38
|
+
configured = {
|
|
39
|
+
...configured,
|
|
40
|
+
...config
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Reads `ClientConfig` from `import.meta.env` and the values given with {@link configureClient}.
|
|
45
|
+
* Throws when a required value is missing so the failure surfaces at app startup, not at the first
|
|
46
|
+
* call.
|
|
32
47
|
*/
|
|
33
48
|
function loadClientConfig() {
|
|
34
|
-
const env = import.meta.env;
|
|
49
|
+
const env = import.meta.env ?? {};
|
|
35
50
|
const config = {
|
|
36
51
|
messagesApiUrl: env.VITE_MESSAGES_API_URL ?? "",
|
|
37
52
|
oidcAuthority: env.VITE_OIDC_AUTHORITY ?? "",
|
|
38
53
|
oidcClientId: env.VITE_OIDC_CLIENT_ID ?? "",
|
|
39
54
|
oidcScope: env.VITE_OIDC_SCOPE || DEFAULT_SCOPE,
|
|
40
|
-
iamApiUrl: env.VITE_IAM_API_URL ?? ""
|
|
55
|
+
iamApiUrl: env.VITE_IAM_API_URL ?? "",
|
|
56
|
+
...configured
|
|
41
57
|
};
|
|
58
|
+
if (configured) {
|
|
59
|
+
if (!config.messagesApiUrl) throw new Error("configureClient() was called without messagesApiUrl.");
|
|
60
|
+
return config;
|
|
61
|
+
}
|
|
42
62
|
const missing = Object.entries(config).filter(([, v]) => !v).map(([k]) => k);
|
|
43
63
|
if (missing.length) throw new Error(`Missing ${missing.join(", ")} (VITE_MESSAGES_API_URL, VITE_OIDC_AUTHORITY, VITE_OIDC_CLIENT_ID, VITE_IAM_API_URL). Copy .env.example to .env at the repo root and fill in the values.`);
|
|
44
64
|
return config;
|
|
@@ -945,4 +965,4 @@ var MessagesApi = class {
|
|
|
945
965
|
};
|
|
946
966
|
};
|
|
947
967
|
//#endregion
|
|
948
|
-
export { AgentsApi, ApiError, ChannelsApi, HttpClient, ID_FORMAT_PATTERN, LiveEvents, MessagesApi, ModelsApi, base64ToBytes, blobToBase64, bytesToBase64, filesSource, isValidId, loadClientConfig, toFsError };
|
|
968
|
+
export { AgentsApi, ApiError, ChannelsApi, HttpClient, ID_FORMAT_PATTERN, LiveEvents, MessagesApi, ModelsApi, base64ToBytes, blobToBase64, bytesToBase64, configureClient, filesSource, isValidId, loadClientConfig, toFsError };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quartal/messages-client",
|
|
3
3
|
"description": "The browser SDK of the Quartal Messages API",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Quartal Accounting Software Oy",
|
|
7
7
|
"repository": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@quartal/core": "^1.5.1",
|
|
29
|
-
"@quartal/messages-types": "0.2.
|
|
29
|
+
"@quartal/messages-types": "0.2.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"tsdown": "^0.21.9",
|