@butlerbot/sdk 0.0.7-alpha.0 → 0.0.7-alpha.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/dist/config.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -2
- package/dist/modules/usage.d.ts +7 -4
- package/dist/modules/usage.js +7 -4
- package/package.json +1 -1
package/dist/config.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Conversation, ConversationOptions } from "./modules/conversation";
|
|
2
|
+
import { UsagePolicyDataOptions } from "./modules/usage";
|
|
2
3
|
type OptionalApiKey<T> = Omit<T, "apiKey"> & {
|
|
3
4
|
/** Optional API key, defaults to API key specified in client */
|
|
4
5
|
apiKey?: string;
|
|
@@ -21,7 +22,7 @@ export declare class ButlerBotClient {
|
|
|
21
22
|
/** Spawns a new Conversation, inherits api key and server URL */
|
|
22
23
|
createConversation(config?: OptionalApiKey<ConversationOptions>): Conversation;
|
|
23
24
|
/** Get current usage policy data */
|
|
24
|
-
getUsagePolicyData(
|
|
25
|
+
getUsagePolicyData(config: OptionalApiKey<UsagePolicyDataOptions>): Promise<import("./types/usage/policy").UsagePolicyData>;
|
|
25
26
|
}
|
|
26
27
|
export * from "./types/type_registry";
|
|
27
28
|
export { Conversation, ConversationOptions };
|
package/dist/index.js
CHANGED
|
@@ -54,8 +54,8 @@ class ButlerBotClient {
|
|
|
54
54
|
return new conversation_1.Conversation(Object.assign({ debug: this.debug, apiKey: this.apiKey, serverUrl: this.serverUrl }, config));
|
|
55
55
|
}
|
|
56
56
|
/** Get current usage policy data */
|
|
57
|
-
getUsagePolicyData(
|
|
58
|
-
return (0, usage_1.getUsagePolicyData)({ serverURL: this.serverUrl,
|
|
57
|
+
getUsagePolicyData(config) {
|
|
58
|
+
return (0, usage_1.getUsagePolicyData)(Object.assign({ serverURL: this.serverUrl, apiKey: this.apiKey, debug: this.debug }, config));
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
exports.ButlerBotClient = ButlerBotClient;
|
package/dist/modules/usage.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { UsagePolicyData } from "../types/usage/policy";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
serverURL: string;
|
|
2
|
+
export type UsagePolicyDataOptions = {
|
|
3
|
+
serverURL?: string;
|
|
5
4
|
path?: string;
|
|
6
|
-
|
|
5
|
+
apiKey: string;
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
};
|
|
8
|
+
/** Fetches the current usage policy data from the server */
|
|
9
|
+
export declare function getUsagePolicyData(options: UsagePolicyDataOptions): Promise<UsagePolicyData>;
|
package/dist/modules/usage.js
CHANGED
|
@@ -13,10 +13,10 @@ exports.getUsagePolicyData = getUsagePolicyData;
|
|
|
13
13
|
const config_1 = require("../config");
|
|
14
14
|
const url_formatter_1 = require("../util/url_formatter");
|
|
15
15
|
/** Fetches the current usage policy data from the server */
|
|
16
|
-
function getUsagePolicyData(
|
|
16
|
+
function getUsagePolicyData(options) {
|
|
17
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
const useEndpoint =
|
|
19
|
-
const url = (0, url_formatter_1.formatURL)(useEndpoint, {}, { apiKey, debug });
|
|
18
|
+
const useEndpoint = (options.serverURL || config_1.CONFIG.server) + (options.path || config_1.CONFIG.paths.usage.policy.v3.base);
|
|
19
|
+
const url = (0, url_formatter_1.formatURL)(useEndpoint, {}, { apiKey: options.apiKey, debug: options.debug });
|
|
20
20
|
const response = yield fetch(url);
|
|
21
21
|
const data = yield response.json();
|
|
22
22
|
if (!response.ok) {
|
|
@@ -26,6 +26,9 @@ function getUsagePolicyData(endpoint, apiKey, debug) {
|
|
|
26
26
|
if (!data.success) {
|
|
27
27
|
throw new Error(`API error while fetching usage policy data: ${data.error || 'Unknown error'}`);
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
if (!data.policy) {
|
|
30
|
+
throw new Error(`API error while fetching usage policy data: ${data.error || 'Unknown error'}`);
|
|
31
|
+
}
|
|
32
|
+
return data.policy;
|
|
30
33
|
});
|
|
31
34
|
}
|