@openmrp/sdk 0.19.3 → 0.19.4
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/CHANGELOG.md +2 -9
- package/LICENSE +1 -1
- package/README.md +31 -31
- package/client.d.mts +12 -12
- package/client.d.ts +12 -12
- package/client.js +47 -47
- package/client.js.map +1 -1
- package/client.mjs +45 -45
- package/client.mjs.map +1 -1
- package/core/api-promise.d.mts +2 -2
- package/core/api-promise.d.ts +2 -2
- package/core/error.d.mts +2 -2
- package/core/error.d.ts +2 -2
- package/core/error.js +4 -4
- package/core/error.mjs +2 -2
- package/core/resource.d.mts +3 -3
- package/core/resource.d.ts +3 -3
- package/index.d.mts +3 -3
- package/index.d.ts +3 -3
- package/index.js +4 -4
- package/index.mjs +3 -3
- package/internal/parse.d.mts +2 -2
- package/internal/parse.d.ts +2 -2
- package/internal/shims.js +1 -1
- package/internal/shims.mjs +1 -1
- package/internal/uploads.d.mts +4 -4
- package/internal/uploads.d.ts +4 -4
- package/internal/utils/base64.js +2 -2
- package/internal/utils/base64.mjs +3 -3
- package/internal/utils/log.d.mts +3 -3
- package/internal/utils/log.d.ts +3 -3
- package/internal/utils/path.js +1 -1
- package/internal/utils/path.mjs +2 -2
- package/internal/utils/values.js +5 -5
- package/internal/utils/values.mjs +6 -6
- package/package.json +3 -3
- package/resources/ai/agents.d.mts +8 -8
- package/resources/ai/agents.d.ts +8 -8
- package/resources/ai/agents.js +6 -6
- package/resources/ai/agents.mjs +6 -6
- package/resources/auth/api-keys/actions.d.mts +2 -2
- package/resources/auth/api-keys/actions.d.ts +2 -2
- package/resources/auth/api-keys/actions.js +2 -2
- package/resources/auth/api-keys/actions.mjs +2 -2
- package/resources/auth/api-keys/api-keys.d.mts +6 -6
- package/resources/auth/api-keys/api-keys.d.ts +6 -6
- package/resources/auth/api-keys/api-keys.js +5 -5
- package/resources/auth/api-keys/api-keys.mjs +5 -5
- package/resources/core/request-logs.d.mts +4 -3
- package/resources/core/request-logs.d.mts.map +1 -1
- package/resources/core/request-logs.d.ts +4 -3
- package/resources/core/request-logs.d.ts.map +1 -1
- package/resources/finance/payment-terms.d.mts +2 -2
- package/resources/finance/payment-terms.d.ts +2 -2
- package/resources/finance/payment-terms.js +2 -2
- package/resources/finance/payment-terms.mjs +2 -2
- package/resources/identity/account-users/account-users.d.mts +2 -2
- package/resources/identity/account-users/account-users.d.ts +2 -2
- package/resources/identity/account-users/account-users.js +2 -2
- package/resources/identity/account-users/account-users.mjs +2 -2
- package/src/client.ts +30 -30
- package/src/core/api-promise.ts +4 -4
- package/src/core/error.ts +2 -2
- package/src/core/resource.ts +3 -3
- package/src/index.ts +3 -3
- package/src/internal/parse.ts +2 -2
- package/src/internal/shims.ts +1 -1
- package/src/internal/uploads.ts +5 -5
- package/src/internal/utils/base64.ts +3 -3
- package/src/internal/utils/log.ts +3 -3
- package/src/internal/utils/path.ts +2 -2
- package/src/internal/utils/values.ts +6 -6
- package/src/resources/ai/agents.ts +8 -8
- package/src/resources/auth/api-keys/actions.ts +2 -2
- package/src/resources/auth/api-keys/api-keys.ts +6 -6
- package/src/resources/core/request-logs.ts +4 -3
- package/src/resources/finance/payment-terms.ts +2 -2
- package/src/resources/identity/account-users/account-users.ts +2 -2
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -11,8 +11,8 @@ class PaymentTerms extends resource_1.APIResource {
|
|
|
11
11
|
/**
|
|
12
12
|
* Returns a paginated list of payment terms.
|
|
13
13
|
*
|
|
14
|
-
* The list includes both payment terms created by your account and
|
|
15
|
-
* system defaults.
|
|
14
|
+
* The list includes both payment terms created by your account and
|
|
15
|
+
* OpenMRP-provided system defaults.
|
|
16
16
|
*
|
|
17
17
|
* This endpoint requires the permission: `payment_terms:read`.
|
|
18
18
|
*
|
|
@@ -8,8 +8,8 @@ export class PaymentTerms extends APIResource {
|
|
|
8
8
|
/**
|
|
9
9
|
* Returns a paginated list of payment terms.
|
|
10
10
|
*
|
|
11
|
-
* The list includes both payment terms created by your account and
|
|
12
|
-
* system defaults.
|
|
11
|
+
* The list includes both payment terms created by your account and
|
|
12
|
+
* OpenMRP-provided system defaults.
|
|
13
13
|
*
|
|
14
14
|
* This endpoint requires the permission: `payment_terms:read`.
|
|
15
15
|
*
|
|
@@ -68,7 +68,7 @@ export declare class AccountUsers extends APIResource {
|
|
|
68
68
|
* const accountUser =
|
|
69
69
|
* await client.identity.accountUsers.create({
|
|
70
70
|
* department_id: 'dp_m0jayebxnkos',
|
|
71
|
-
* email: 'jdoe@
|
|
71
|
+
* email: 'jdoe@openmrp.ai',
|
|
72
72
|
* name: 'John Doe',
|
|
73
73
|
* password: 'QgS7Z8Hhj3&1',
|
|
74
74
|
* preferences: [
|
|
@@ -100,7 +100,7 @@ export declare class AccountUsers extends APIResource {
|
|
|
100
100
|
* 'acus_e5zu8bde0z3h',
|
|
101
101
|
* {
|
|
102
102
|
* department_id: 'dp_m0jayebxnkos',
|
|
103
|
-
* email: 'jdoe@
|
|
103
|
+
* email: 'jdoe@openmrp.ai',
|
|
104
104
|
* name: 'John Doe',
|
|
105
105
|
* preferences: [
|
|
106
106
|
* {
|
|
@@ -68,7 +68,7 @@ export declare class AccountUsers extends APIResource {
|
|
|
68
68
|
* const accountUser =
|
|
69
69
|
* await client.identity.accountUsers.create({
|
|
70
70
|
* department_id: 'dp_m0jayebxnkos',
|
|
71
|
-
* email: 'jdoe@
|
|
71
|
+
* email: 'jdoe@openmrp.ai',
|
|
72
72
|
* name: 'John Doe',
|
|
73
73
|
* password: 'QgS7Z8Hhj3&1',
|
|
74
74
|
* preferences: [
|
|
@@ -100,7 +100,7 @@ export declare class AccountUsers extends APIResource {
|
|
|
100
100
|
* 'acus_e5zu8bde0z3h',
|
|
101
101
|
* {
|
|
102
102
|
* department_id: 'dp_m0jayebxnkos',
|
|
103
|
-
* email: 'jdoe@
|
|
103
|
+
* email: 'jdoe@openmrp.ai',
|
|
104
104
|
* name: 'John Doe',
|
|
105
105
|
* preferences: [
|
|
106
106
|
* {
|
|
@@ -77,7 +77,7 @@ class AccountUsers extends resource_1.APIResource {
|
|
|
77
77
|
* const accountUser =
|
|
78
78
|
* await client.identity.accountUsers.create({
|
|
79
79
|
* department_id: 'dp_m0jayebxnkos',
|
|
80
|
-
* email: 'jdoe@
|
|
80
|
+
* email: 'jdoe@openmrp.ai',
|
|
81
81
|
* name: 'John Doe',
|
|
82
82
|
* password: 'QgS7Z8Hhj3&1',
|
|
83
83
|
* preferences: [
|
|
@@ -112,7 +112,7 @@ class AccountUsers extends resource_1.APIResource {
|
|
|
112
112
|
* 'acus_e5zu8bde0z3h',
|
|
113
113
|
* {
|
|
114
114
|
* department_id: 'dp_m0jayebxnkos',
|
|
115
|
-
* email: 'jdoe@
|
|
115
|
+
* email: 'jdoe@openmrp.ai',
|
|
116
116
|
* name: 'John Doe',
|
|
117
117
|
* preferences: [
|
|
118
118
|
* {
|
|
@@ -73,7 +73,7 @@ export class AccountUsers extends APIResource {
|
|
|
73
73
|
* const accountUser =
|
|
74
74
|
* await client.identity.accountUsers.create({
|
|
75
75
|
* department_id: 'dp_m0jayebxnkos',
|
|
76
|
-
* email: 'jdoe@
|
|
76
|
+
* email: 'jdoe@openmrp.ai',
|
|
77
77
|
* name: 'John Doe',
|
|
78
78
|
* password: 'QgS7Z8Hhj3&1',
|
|
79
79
|
* preferences: [
|
|
@@ -108,7 +108,7 @@ export class AccountUsers extends APIResource {
|
|
|
108
108
|
* 'acus_e5zu8bde0z3h',
|
|
109
109
|
* {
|
|
110
110
|
* department_id: 'dp_m0jayebxnkos',
|
|
111
|
-
* email: 'jdoe@
|
|
111
|
+
* email: 'jdoe@openmrp.ai',
|
|
112
112
|
* name: 'John Doe',
|
|
113
113
|
* preferences: [
|
|
114
114
|
* {
|
package/src/client.ts
CHANGED
|
@@ -80,7 +80,7 @@ import {
|
|
|
80
80
|
import { isEmptyObj } from './internal/utils/values';
|
|
81
81
|
|
|
82
82
|
const environments = {
|
|
83
|
-
production: 'https://api.
|
|
83
|
+
production: 'https://api.openmrp.ai',
|
|
84
84
|
local: 'http://localhost:8081',
|
|
85
85
|
};
|
|
86
86
|
type Environment = keyof typeof environments;
|
|
@@ -94,13 +94,13 @@ export interface ClientOptions {
|
|
|
94
94
|
/**
|
|
95
95
|
* Current account UUID (OpenMRP-Account). Update when switching accounts.
|
|
96
96
|
*/
|
|
97
|
-
|
|
97
|
+
openmrpAccountID?: string | null | undefined;
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
100
|
* Specifies the environment to use for the API.
|
|
101
101
|
*
|
|
102
102
|
* Each environment maps to a different base URL:
|
|
103
|
-
* - `production` corresponds to `https://api.
|
|
103
|
+
* - `production` corresponds to `https://api.openmrp.ai`
|
|
104
104
|
* - `local` corresponds to `http://localhost:8081`
|
|
105
105
|
*/
|
|
106
106
|
environment?: Environment | undefined;
|
|
@@ -175,11 +175,11 @@ export interface ClientOptions {
|
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
/**
|
|
178
|
-
* API Client for interfacing with the
|
|
178
|
+
* API Client for interfacing with the Openmrp API.
|
|
179
179
|
*/
|
|
180
|
-
export class
|
|
180
|
+
export class Openmrp {
|
|
181
181
|
bearerToken: string | null;
|
|
182
|
-
|
|
182
|
+
openmrpAccountID: string | null;
|
|
183
183
|
|
|
184
184
|
baseURL: string;
|
|
185
185
|
maxRetries: number;
|
|
@@ -194,12 +194,12 @@ export class OpenMRP {
|
|
|
194
194
|
private _options: ClientOptions;
|
|
195
195
|
|
|
196
196
|
/**
|
|
197
|
-
* API Client for interfacing with the
|
|
197
|
+
* API Client for interfacing with the Openmrp API.
|
|
198
198
|
*
|
|
199
199
|
* @param {string | null | undefined} [opts.bearerToken=process.env['OPENMRP_API_KEY'] ?? null]
|
|
200
|
-
* @param {string | null | undefined} [opts.
|
|
200
|
+
* @param {string | null | undefined} [opts.openmrpAccountID]
|
|
201
201
|
* @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
|
|
202
|
-
* @param {string} [opts.baseURL=process.env['OPENMRP_BASE_URL'] ?? https://api.
|
|
202
|
+
* @param {string} [opts.baseURL=process.env['OPENMRP_BASE_URL'] ?? https://api.openmrp.ai] - Override the default base URL for the API.
|
|
203
203
|
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
204
204
|
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
|
|
205
205
|
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
@@ -210,25 +210,25 @@ export class OpenMRP {
|
|
|
210
210
|
constructor({
|
|
211
211
|
baseURL = readEnv('OPENMRP_BASE_URL'),
|
|
212
212
|
bearerToken = readEnv('OPENMRP_API_KEY') ?? null,
|
|
213
|
-
|
|
213
|
+
openmrpAccountID = null,
|
|
214
214
|
...opts
|
|
215
215
|
}: ClientOptions = {}) {
|
|
216
216
|
const options: ClientOptions = {
|
|
217
217
|
bearerToken,
|
|
218
|
-
|
|
218
|
+
openmrpAccountID,
|
|
219
219
|
...opts,
|
|
220
220
|
baseURL,
|
|
221
221
|
environment: opts.environment ?? 'production',
|
|
222
222
|
};
|
|
223
223
|
|
|
224
224
|
if (baseURL && opts.environment) {
|
|
225
|
-
throw new Errors.
|
|
225
|
+
throw new Errors.OpenmrpError(
|
|
226
226
|
'Ambiguous URL; The `baseURL` option (or OPENMRP_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null',
|
|
227
227
|
);
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
this.baseURL = options.baseURL || environments[options.environment || 'production'];
|
|
231
|
-
this.timeout = options.timeout ??
|
|
231
|
+
this.timeout = options.timeout ?? Openmrp.DEFAULT_TIMEOUT /* 1 minute */;
|
|
232
232
|
this.logger = options.logger ?? console;
|
|
233
233
|
const defaultLogLevel = 'warn';
|
|
234
234
|
// Set default logLevel early so that we can log a warning in parseLogLevel.
|
|
@@ -257,7 +257,7 @@ export class OpenMRP {
|
|
|
257
257
|
this._options = options;
|
|
258
258
|
|
|
259
259
|
this.bearerToken = bearerToken;
|
|
260
|
-
this.
|
|
260
|
+
this.openmrpAccountID = openmrpAccountID;
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
/**
|
|
@@ -275,7 +275,7 @@ export class OpenMRP {
|
|
|
275
275
|
fetch: this.fetch,
|
|
276
276
|
fetchOptions: this.fetchOptions,
|
|
277
277
|
bearerToken: this.bearerToken,
|
|
278
|
-
|
|
278
|
+
openmrpAccountID: this.openmrpAccountID,
|
|
279
279
|
...options,
|
|
280
280
|
});
|
|
281
281
|
return client;
|
|
@@ -723,7 +723,7 @@ export class OpenMRP {
|
|
|
723
723
|
Accept: 'application/json',
|
|
724
724
|
'User-Agent': this.getUserAgent(),
|
|
725
725
|
'OpenMRP-Version': '1.0.forge-preview.3',
|
|
726
|
-
'OpenMRP-Account': this.
|
|
726
|
+
'OpenMRP-Account': this.openmrpAccountID,
|
|
727
727
|
},
|
|
728
728
|
await this.authHeaders(options),
|
|
729
729
|
this._options.defaultHeaders,
|
|
@@ -787,10 +787,10 @@ export class OpenMRP {
|
|
|
787
787
|
}
|
|
788
788
|
}
|
|
789
789
|
|
|
790
|
-
static
|
|
790
|
+
static Openmrp = this;
|
|
791
791
|
static DEFAULT_TIMEOUT = 60000; // 1 minute
|
|
792
792
|
|
|
793
|
-
static
|
|
793
|
+
static OpenmrpError = Errors.OpenmrpError;
|
|
794
794
|
static APIError = Errors.APIError;
|
|
795
795
|
static APIConnectionError = Errors.APIConnectionError;
|
|
796
796
|
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
|
|
@@ -833,18 +833,18 @@ export class OpenMRP {
|
|
|
833
833
|
settings: API.Settings = new API.Settings(this);
|
|
834
834
|
}
|
|
835
835
|
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
export declare namespace
|
|
836
|
+
Openmrp.Auth = Auth;
|
|
837
|
+
Openmrp.Core = Core;
|
|
838
|
+
Openmrp.Catalog = Catalog;
|
|
839
|
+
Openmrp.AI = AI;
|
|
840
|
+
Openmrp.Messaging = Messaging;
|
|
841
|
+
Openmrp.Sales = Sales;
|
|
842
|
+
Openmrp.Finance = Finance;
|
|
843
|
+
Openmrp.Operations = Operations;
|
|
844
|
+
Openmrp.Identity = Identity;
|
|
845
|
+
Openmrp.Settings = Settings;
|
|
846
|
+
|
|
847
|
+
export declare namespace Openmrp {
|
|
848
848
|
export type RequestOptions = Opts.RequestOptions;
|
|
849
849
|
|
|
850
850
|
export { Auth as Auth };
|
package/src/core/api-promise.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { type
|
|
3
|
+
import { type Openmrp } from '../client';
|
|
4
4
|
|
|
5
5
|
import { type PromiseOrValue } from '../internal/types';
|
|
6
6
|
import { APIResponseProps, defaultParseResponse } from '../internal/parse';
|
|
@@ -11,13 +11,13 @@ import { APIResponseProps, defaultParseResponse } from '../internal/parse';
|
|
|
11
11
|
*/
|
|
12
12
|
export class APIPromise<T> extends Promise<T> {
|
|
13
13
|
private parsedPromise: Promise<T> | undefined;
|
|
14
|
-
#client:
|
|
14
|
+
#client: Openmrp;
|
|
15
15
|
|
|
16
16
|
constructor(
|
|
17
|
-
client:
|
|
17
|
+
client: Openmrp,
|
|
18
18
|
private responsePromise: Promise<APIResponseProps>,
|
|
19
19
|
private parseResponse: (
|
|
20
|
-
client:
|
|
20
|
+
client: Openmrp,
|
|
21
21
|
props: APIResponseProps,
|
|
22
22
|
) => PromiseOrValue<T> = defaultParseResponse,
|
|
23
23
|
) {
|
package/src/core/error.ts
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import { castToError } from '../internal/errors';
|
|
4
4
|
|
|
5
|
-
export class
|
|
5
|
+
export class OpenmrpError extends Error {}
|
|
6
6
|
|
|
7
7
|
export class APIError<
|
|
8
8
|
TStatus extends number | undefined = number | undefined,
|
|
9
9
|
THeaders extends Headers | undefined = Headers | undefined,
|
|
10
10
|
TError extends Object | undefined = Object | undefined,
|
|
11
|
-
> extends
|
|
11
|
+
> extends OpenmrpError {
|
|
12
12
|
/** HTTP status for the response that caused the error */
|
|
13
13
|
readonly status: TStatus;
|
|
14
14
|
/** HTTP headers for the response that caused the error */
|
package/src/core/resource.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { Openmrp } from '../client';
|
|
4
4
|
|
|
5
5
|
export abstract class APIResource {
|
|
6
|
-
protected _client:
|
|
6
|
+
protected _client: Openmrp;
|
|
7
7
|
|
|
8
|
-
constructor(client:
|
|
8
|
+
constructor(client: Openmrp) {
|
|
9
9
|
this._client = client;
|
|
10
10
|
}
|
|
11
11
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { Openmrp as default } from './client';
|
|
4
4
|
|
|
5
5
|
export { type Uploadable, toFile } from './core/uploads';
|
|
6
6
|
export { APIPromise } from './core/api-promise';
|
|
7
|
-
export {
|
|
7
|
+
export { Openmrp, type ClientOptions } from './client';
|
|
8
8
|
export {
|
|
9
|
-
|
|
9
|
+
OpenmrpError,
|
|
10
10
|
APIError,
|
|
11
11
|
APIConnectionError,
|
|
12
12
|
APIConnectionTimeoutError,
|
package/src/internal/parse.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
import type { FinalRequestOptions } from './request-options';
|
|
4
|
-
import { type
|
|
4
|
+
import { type Openmrp } from '../client';
|
|
5
5
|
import { formatRequestDetails, loggerFor } from './utils/log';
|
|
6
6
|
|
|
7
7
|
export type APIResponseProps = {
|
|
@@ -13,7 +13,7 @@ export type APIResponseProps = {
|
|
|
13
13
|
startTime: number;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
export async function defaultParseResponse<T>(client:
|
|
16
|
+
export async function defaultParseResponse<T>(client: Openmrp, props: APIResponseProps): Promise<T> {
|
|
17
17
|
const { response, requestLogID, retryOfRequestLogID, startTime } = props;
|
|
18
18
|
const body = await (async () => {
|
|
19
19
|
// fetch refuses to read the body when the status code is 204.
|
package/src/internal/shims.ts
CHANGED
|
@@ -16,7 +16,7 @@ export function getDefaultFetch(): Fetch {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
throw new Error(
|
|
19
|
-
'`fetch` is not defined as a global; Either pass `fetch` to the client, `new
|
|
19
|
+
'`fetch` is not defined as a global; Either pass `fetch` to the client, `new Openmrp({ fetch })` or polyfill the global, `globalThis.fetch = fetch`',
|
|
20
20
|
);
|
|
21
21
|
}
|
|
22
22
|
|
package/src/internal/uploads.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type RequestOptions } from './request-options';
|
|
2
2
|
import type { FilePropertyBag, Fetch } from './builtin-types';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Openmrp } from '../client';
|
|
4
4
|
import { ReadableStreamFrom } from './shims';
|
|
5
5
|
|
|
6
6
|
export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
|
|
@@ -74,7 +74,7 @@ export const isAsyncIterable = (value: any): value is AsyncIterable<any> =>
|
|
|
74
74
|
*/
|
|
75
75
|
export const maybeMultipartFormRequestOptions = async (
|
|
76
76
|
opts: RequestOptions,
|
|
77
|
-
fetch:
|
|
77
|
+
fetch: Openmrp | Fetch,
|
|
78
78
|
): Promise<RequestOptions> => {
|
|
79
79
|
if (!hasUploadableValue(opts.body)) return opts;
|
|
80
80
|
|
|
@@ -85,7 +85,7 @@ type MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & { body: unknow
|
|
|
85
85
|
|
|
86
86
|
export const multipartFormRequestOptions = async (
|
|
87
87
|
opts: MultipartFormRequestOptions,
|
|
88
|
-
fetch:
|
|
88
|
+
fetch: Openmrp | Fetch,
|
|
89
89
|
): Promise<RequestOptions> => {
|
|
90
90
|
return { ...opts, body: await createForm(opts.body, fetch) };
|
|
91
91
|
};
|
|
@@ -98,7 +98,7 @@ const supportsFormDataMap = /* @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>
|
|
|
98
98
|
* This function detects if the fetch function provided supports the global FormData object to avoid
|
|
99
99
|
* confusing error messages later on.
|
|
100
100
|
*/
|
|
101
|
-
function supportsFormData(fetchObject:
|
|
101
|
+
function supportsFormData(fetchObject: Openmrp | Fetch): Promise<boolean> {
|
|
102
102
|
const fetch: Fetch = typeof fetchObject === 'function' ? fetchObject : (fetchObject as any).fetch;
|
|
103
103
|
const cached = supportsFormDataMap.get(fetch);
|
|
104
104
|
if (cached) return cached;
|
|
@@ -124,7 +124,7 @@ function supportsFormData(fetchObject: OpenMRP | Fetch): Promise<boolean> {
|
|
|
124
124
|
|
|
125
125
|
export const createForm = async <T = Record<string, unknown>>(
|
|
126
126
|
body: T | undefined,
|
|
127
|
-
fetch:
|
|
127
|
+
fetch: Openmrp | Fetch,
|
|
128
128
|
): Promise<FormData> => {
|
|
129
129
|
if (!(await supportsFormData(fetch))) {
|
|
130
130
|
throw new TypeError(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { OpenmrpError } from '../../core/error';
|
|
4
4
|
import { encodeUTF8 } from './bytes';
|
|
5
5
|
|
|
6
6
|
export const toBase64 = (data: string | Uint8Array | null | undefined): string => {
|
|
@@ -18,7 +18,7 @@ export const toBase64 = (data: string | Uint8Array | null | undefined): string =
|
|
|
18
18
|
return btoa(String.fromCharCode.apply(null, data as any));
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
throw new
|
|
21
|
+
throw new OpenmrpError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export const fromBase64 = (str: string): Uint8Array => {
|
|
@@ -36,5 +36,5 @@ export const fromBase64 = (str: string): Uint8Array => {
|
|
|
36
36
|
return buf;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
throw new
|
|
39
|
+
throw new OpenmrpError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
|
|
40
40
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
import { hasOwn } from './values';
|
|
4
|
-
import { type
|
|
4
|
+
import { type Openmrp } from '../../client';
|
|
5
5
|
import { RequestOptions } from '../request-options';
|
|
6
6
|
|
|
7
7
|
type LogFn = (message: string, ...rest: unknown[]) => void;
|
|
@@ -24,7 +24,7 @@ const levelNumbers = {
|
|
|
24
24
|
export const parseLogLevel = (
|
|
25
25
|
maybeLevel: string | undefined,
|
|
26
26
|
sourceName: string,
|
|
27
|
-
client:
|
|
27
|
+
client: Openmrp,
|
|
28
28
|
): LogLevel | undefined => {
|
|
29
29
|
if (!maybeLevel) {
|
|
30
30
|
return undefined;
|
|
@@ -60,7 +60,7 @@ const noopLogger = {
|
|
|
60
60
|
|
|
61
61
|
let cachedLoggers = /* @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
|
|
62
62
|
|
|
63
|
-
export function loggerFor(client:
|
|
63
|
+
export function loggerFor(client: Openmrp): Logger {
|
|
64
64
|
const logger = client.logger;
|
|
65
65
|
const logLevel = client.logLevel ?? 'off';
|
|
66
66
|
if (!logger) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OpenmrpError } from '../../core/error';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Percent-encode everything that isn't safe to have in a path without encoding safe chars.
|
|
@@ -72,7 +72,7 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
|
|
72
72
|
return acc + spaces + arrows;
|
|
73
73
|
}, '');
|
|
74
74
|
|
|
75
|
-
throw new
|
|
75
|
+
throw new OpenmrpError(
|
|
76
76
|
`Path parameters result in path with invalid segments:\n${invalidSegments
|
|
77
77
|
.map((e) => e.error)
|
|
78
78
|
.join('\n')}\n${path}\n${underline}`,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { OpenmrpError } from '../../core/error';
|
|
4
4
|
|
|
5
5
|
// https://url.spec.whatwg.org/#url-scheme-string
|
|
6
6
|
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
|
|
@@ -39,7 +39,7 @@ export function isObj(obj: unknown): obj is Record<string, unknown> {
|
|
|
39
39
|
|
|
40
40
|
export const ensurePresent = <T>(value: T | null | undefined): T => {
|
|
41
41
|
if (value == null) {
|
|
42
|
-
throw new
|
|
42
|
+
throw new OpenmrpError(`Expected a value to be given but received ${value} instead.`);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
return value;
|
|
@@ -47,10 +47,10 @@ export const ensurePresent = <T>(value: T | null | undefined): T => {
|
|
|
47
47
|
|
|
48
48
|
export const validatePositiveInteger = (name: string, n: unknown): number => {
|
|
49
49
|
if (typeof n !== 'number' || !Number.isInteger(n)) {
|
|
50
|
-
throw new
|
|
50
|
+
throw new OpenmrpError(`${name} must be an integer`);
|
|
51
51
|
}
|
|
52
52
|
if (n < 0) {
|
|
53
|
-
throw new
|
|
53
|
+
throw new OpenmrpError(`${name} must be a positive integer`);
|
|
54
54
|
}
|
|
55
55
|
return n;
|
|
56
56
|
};
|
|
@@ -59,14 +59,14 @@ export const coerceInteger = (value: unknown): number => {
|
|
|
59
59
|
if (typeof value === 'number') return Math.round(value);
|
|
60
60
|
if (typeof value === 'string') return parseInt(value, 10);
|
|
61
61
|
|
|
62
|
-
throw new
|
|
62
|
+
throw new OpenmrpError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
export const coerceFloat = (value: unknown): number => {
|
|
66
66
|
if (typeof value === 'number') return value;
|
|
67
67
|
if (typeof value === 'string') return parseFloat(value);
|
|
68
68
|
|
|
69
|
-
throw new
|
|
69
|
+
throw new OpenmrpError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
export const coerceBoolean = (value: unknown): boolean => {
|
|
@@ -54,9 +54,9 @@ export class Agents extends APIResource {
|
|
|
54
54
|
/**
|
|
55
55
|
* Lists the agents available to your account, newest first.
|
|
56
56
|
*
|
|
57
|
-
* Covers both the `system` agents OpenMRP provides to every account and the
|
|
58
|
-
* agents created in yours. Deleted agents are never returned. The `q`
|
|
59
|
-
* matches an agent's name, slug, description, or ID.
|
|
57
|
+
* Covers both the `system` agents OpenMRP provides to every account and the
|
|
58
|
+
* `custom` agents created in yours. Deleted agents are never returned. The `q`
|
|
59
|
+
* parameter matches an agent's name, slug, description, or ID.
|
|
60
60
|
*
|
|
61
61
|
* This endpoint requires the permission: `agents:read`.
|
|
62
62
|
*
|
|
@@ -75,9 +75,9 @@ export class Agents extends APIResource {
|
|
|
75
75
|
/**
|
|
76
76
|
* Retrieves a single agent by ID.
|
|
77
77
|
*
|
|
78
|
-
* Resolves both the `system` agents OpenMRP provides and the `custom` agents in
|
|
79
|
-
* account; the `status` reflects whether the agent is enabled for your
|
|
80
|
-
* specifically.
|
|
78
|
+
* Resolves both the `system` agents OpenMRP provides and the `custom` agents in
|
|
79
|
+
* your account; the `status` reflects whether the agent is enabled for your
|
|
80
|
+
* account specifically.
|
|
81
81
|
*
|
|
82
82
|
* This endpoint requires the permission: `agents:read`.
|
|
83
83
|
*
|
|
@@ -434,8 +434,8 @@ export interface ConfigInput {
|
|
|
434
434
|
/**
|
|
435
435
|
* Instructions that define the agent's role and how it should behave.
|
|
436
436
|
*
|
|
437
|
-
* Sent to the model on every turn of a run, alongside the platform guidance
|
|
438
|
-
* adds automatically.
|
|
437
|
+
* Sent to the model on every turn of a run, alongside the platform guidance
|
|
438
|
+
* OpenMRP adds automatically.
|
|
439
439
|
*/
|
|
440
440
|
system_prompt?: string;
|
|
441
441
|
|
|
@@ -11,7 +11,7 @@ import { path } from '../../../internal/utils/path';
|
|
|
11
11
|
*/
|
|
12
12
|
export class Actions extends APIResource {
|
|
13
13
|
/**
|
|
14
|
-
* Rotates an [API key](https://docs.
|
|
14
|
+
* Rotates an [API key](https://docs.openmrp.ai/api/api-keys) by revoking the
|
|
15
15
|
* existing key and issuing a replacement with the same name, role, and expiration
|
|
16
16
|
* (unless overridden).
|
|
17
17
|
*
|
|
@@ -22,7 +22,7 @@ export class Actions extends APIResource {
|
|
|
22
22
|
*
|
|
23
23
|
* The secret key is returned once and cannot be retrieved later, so you should
|
|
24
24
|
* store it securely. We provide some
|
|
25
|
-
* [recommendations](https://docs.
|
|
25
|
+
* [recommendations](https://docs.openmrp.ai/api/managing-api-keys) on how you can
|
|
26
26
|
* manage your API keys.
|
|
27
27
|
*
|
|
28
28
|
* This endpoint requires the `admin` role type.
|
|
@@ -14,7 +14,7 @@ export class APIKeys extends APIResource {
|
|
|
14
14
|
actions: ActionsAPI.Actions = new ActionsAPI.Actions(this._client);
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Returns [API key](https://docs.
|
|
17
|
+
* Returns [API key](https://docs.openmrp.ai/api/api-keys) metadata by ID.
|
|
18
18
|
*
|
|
19
19
|
* Only the redacted key value is returned. The full secret is available only in
|
|
20
20
|
* the response that issued the key, so a lost secret must be replaced by rotating
|
|
@@ -38,7 +38,7 @@ export class APIKeys extends APIResource {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* Returns a paginated list of [API keys](https://docs.
|
|
41
|
+
* Returns a paginated list of [API keys](https://docs.openmrp.ai/api/api-keys),
|
|
42
42
|
* newest first.
|
|
43
43
|
*
|
|
44
44
|
* Only keys belonging to the account making the request are returned. The search
|
|
@@ -56,7 +56,7 @@ export class APIKeys extends APIResource {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* Creates an [API key](https://docs.
|
|
59
|
+
* Creates an [API key](https://docs.openmrp.ai/api/api-keys) to authenticate API
|
|
60
60
|
* requests.
|
|
61
61
|
*
|
|
62
62
|
* The key belongs to the account it was created under and only ever acts on behalf
|
|
@@ -65,7 +65,7 @@ export class APIKeys extends APIResource {
|
|
|
65
65
|
*
|
|
66
66
|
* The secret key is returned once and cannot be retrieved later, so you should
|
|
67
67
|
* store it securely. We provide some
|
|
68
|
-
* [recommendations](https://docs.
|
|
68
|
+
* [recommendations](https://docs.openmrp.ai/api/managing-api-keys) on how you can
|
|
69
69
|
* manage your API keys.
|
|
70
70
|
*
|
|
71
71
|
* This endpoint requires the `admin` role type.
|
|
@@ -85,7 +85,7 @@ export class APIKeys extends APIResource {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
|
-
* Revokes an [API key](https://docs.
|
|
88
|
+
* Revokes an [API key](https://docs.openmrp.ai/api/api-keys).
|
|
89
89
|
*
|
|
90
90
|
* Revocation takes effect immediately and cannot be undone; any request still
|
|
91
91
|
* presenting the key is rejected. The key record is kept, so it stays visible in
|
|
@@ -457,7 +457,7 @@ export interface CreatedAPIKey {
|
|
|
457
457
|
*
|
|
458
458
|
* This is the only response that ever contains the secret; if it is lost, rotate
|
|
459
459
|
* the key to issue a new one. Learn more about
|
|
460
|
-
* [managing your API keys](https://docs.
|
|
460
|
+
* [managing your API keys](https://docs.openmrp.ai/api/managing-api-keys).
|
|
461
461
|
*/
|
|
462
462
|
api_key_secret: string;
|
|
463
463
|
|
|
@@ -212,7 +212,7 @@ export interface RequestLog {
|
|
|
212
212
|
/**
|
|
213
213
|
* Request host.
|
|
214
214
|
*
|
|
215
|
-
* Usually `api.
|
|
215
|
+
* Usually `api.openmrp.ai`.
|
|
216
216
|
*/
|
|
217
217
|
host: string;
|
|
218
218
|
|
|
@@ -225,7 +225,8 @@ export interface RequestLog {
|
|
|
225
225
|
* Request latency in microseconds.
|
|
226
226
|
*
|
|
227
227
|
* Measured at the API edge, from the moment the request was received until the
|
|
228
|
-
* response was written, so it excludes network time between your client and
|
|
228
|
+
* response was written, so it excludes network time between your client and
|
|
229
|
+
* OpenMRP.
|
|
229
230
|
*/
|
|
230
231
|
latency_us: number;
|
|
231
232
|
|
|
@@ -436,7 +437,7 @@ export interface RequestLogListParams {
|
|
|
436
437
|
/**
|
|
437
438
|
* Filter by the request host.
|
|
438
439
|
*
|
|
439
|
-
* Typically `api.
|
|
440
|
+
* Typically `api.openmrp.ai`.
|
|
440
441
|
*/
|
|
441
442
|
hosts?: Array<string>;
|
|
442
443
|
|