@lorikeetai/node-sdk 0.1.0-alpha.1
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 +18 -0
- package/LICENSE +201 -0
- package/README.md +288 -0
- package/_shims/MultipartBody.d.ts +9 -0
- package/_shims/MultipartBody.d.ts.map +1 -0
- package/_shims/MultipartBody.js +16 -0
- package/_shims/MultipartBody.js.map +1 -0
- package/_shims/MultipartBody.mjs +12 -0
- package/_shims/MultipartBody.mjs.map +1 -0
- package/_shims/README.md +46 -0
- package/_shims/auto/runtime-bun.d.ts +5 -0
- package/_shims/auto/runtime-bun.d.ts.map +1 -0
- package/_shims/auto/runtime-bun.js +21 -0
- package/_shims/auto/runtime-bun.js.map +1 -0
- package/_shims/auto/runtime-bun.mjs +2 -0
- package/_shims/auto/runtime-bun.mjs.map +1 -0
- package/_shims/auto/runtime-node.d.ts +5 -0
- package/_shims/auto/runtime-node.d.ts.map +1 -0
- package/_shims/auto/runtime-node.js +21 -0
- package/_shims/auto/runtime-node.js.map +1 -0
- package/_shims/auto/runtime-node.mjs +2 -0
- package/_shims/auto/runtime-node.mjs.map +1 -0
- package/_shims/auto/runtime.d.ts +5 -0
- package/_shims/auto/runtime.d.ts.map +1 -0
- package/_shims/auto/runtime.js +21 -0
- package/_shims/auto/runtime.js.map +1 -0
- package/_shims/auto/runtime.mjs +2 -0
- package/_shims/auto/runtime.mjs.map +1 -0
- package/_shims/auto/types-node.d.ts +5 -0
- package/_shims/auto/types-node.d.ts.map +1 -0
- package/_shims/auto/types-node.js +21 -0
- package/_shims/auto/types-node.js.map +1 -0
- package/_shims/auto/types-node.mjs +2 -0
- package/_shims/auto/types-node.mjs.map +1 -0
- package/_shims/auto/types.d.ts +101 -0
- package/_shims/auto/types.js +3 -0
- package/_shims/auto/types.mjs +3 -0
- package/_shims/bun-runtime.d.ts +6 -0
- package/_shims/bun-runtime.d.ts.map +1 -0
- package/_shims/bun-runtime.js +14 -0
- package/_shims/bun-runtime.js.map +1 -0
- package/_shims/bun-runtime.mjs +10 -0
- package/_shims/bun-runtime.mjs.map +1 -0
- package/_shims/index.d.ts +81 -0
- package/_shims/index.js +13 -0
- package/_shims/index.mjs +7 -0
- package/_shims/manual-types.d.ts +12 -0
- package/_shims/manual-types.js +3 -0
- package/_shims/manual-types.mjs +3 -0
- package/_shims/node-runtime.d.ts +3 -0
- package/_shims/node-runtime.d.ts.map +1 -0
- package/_shims/node-runtime.js +89 -0
- package/_shims/node-runtime.js.map +1 -0
- package/_shims/node-runtime.mjs +56 -0
- package/_shims/node-runtime.mjs.map +1 -0
- package/_shims/node-types.d.ts +42 -0
- package/_shims/node-types.js +3 -0
- package/_shims/node-types.mjs +3 -0
- package/_shims/registry.d.ts +37 -0
- package/_shims/registry.d.ts.map +1 -0
- package/_shims/registry.js +41 -0
- package/_shims/registry.js.map +1 -0
- package/_shims/registry.mjs +37 -0
- package/_shims/registry.mjs.map +1 -0
- package/_shims/web-runtime.d.ts +5 -0
- package/_shims/web-runtime.d.ts.map +1 -0
- package/_shims/web-runtime.js +78 -0
- package/_shims/web-runtime.js.map +1 -0
- package/_shims/web-runtime.mjs +71 -0
- package/_shims/web-runtime.mjs.map +1 -0
- package/_shims/web-types.d.ts +83 -0
- package/_shims/web-types.js +3 -0
- package/_shims/web-types.mjs +3 -0
- package/core.d.ts +242 -0
- package/core.d.ts.map +1 -0
- package/core.js +903 -0
- package/core.js.map +1 -0
- package/core.mjs +871 -0
- package/core.mjs.map +1 -0
- package/error.d.ts +53 -0
- package/error.d.ts.map +1 -0
- package/error.js +143 -0
- package/error.js.map +1 -0
- package/error.mjs +127 -0
- package/error.mjs.map +1 -0
- package/index.d.mts +128 -0
- package/index.d.ts +128 -0
- package/index.d.ts.map +1 -0
- package/index.js +146 -0
- package/index.js.map +1 -0
- package/index.mjs +118 -0
- package/index.mjs.map +1 -0
- package/internal/qs/formats.d.ts +6 -0
- package/internal/qs/formats.d.ts.map +1 -0
- package/internal/qs/formats.js +11 -0
- package/internal/qs/formats.js.map +1 -0
- package/internal/qs/formats.mjs +8 -0
- package/internal/qs/formats.mjs.map +1 -0
- package/internal/qs/index.d.ts +10 -0
- package/internal/qs/index.d.ts.map +1 -0
- package/internal/qs/index.js +14 -0
- package/internal/qs/index.js.map +1 -0
- package/internal/qs/index.mjs +10 -0
- package/internal/qs/index.mjs.map +1 -0
- package/internal/qs/stringify.d.ts +3 -0
- package/internal/qs/stringify.d.ts.map +1 -0
- package/internal/qs/stringify.js +280 -0
- package/internal/qs/stringify.js.map +1 -0
- package/internal/qs/stringify.mjs +276 -0
- package/internal/qs/stringify.mjs.map +1 -0
- package/internal/qs/types.d.ts +57 -0
- package/internal/qs/types.d.ts.map +1 -0
- package/internal/qs/types.js +3 -0
- package/internal/qs/types.js.map +1 -0
- package/internal/qs/types.mjs +2 -0
- package/internal/qs/types.mjs.map +1 -0
- package/internal/qs/utils.d.ts +14 -0
- package/internal/qs/utils.d.ts.map +1 -0
- package/internal/qs/utils.js +229 -0
- package/internal/qs/utils.js.map +1 -0
- package/internal/qs/utils.mjs +217 -0
- package/internal/qs/utils.mjs.map +1 -0
- package/package.json +103 -0
- package/resource.d.ts +6 -0
- package/resource.d.ts.map +1 -0
- package/resource.js +11 -0
- package/resource.js.map +1 -0
- package/resource.mjs +7 -0
- package/resource.mjs.map +1 -0
- package/resources/conversation.d.ts +45 -0
- package/resources/conversation.d.ts.map +1 -0
- package/resources/conversation.js +23 -0
- package/resources/conversation.js.map +1 -0
- package/resources/conversation.mjs +19 -0
- package/resources/conversation.mjs.map +1 -0
- package/resources/index.d.ts +3 -0
- package/resources/index.d.ts.map +1 -0
- package/resources/index.js +9 -0
- package/resources/index.js.map +1 -0
- package/resources/index.mjs +4 -0
- package/resources/index.mjs.map +1 -0
- package/resources/ingest.d.ts +58 -0
- package/resources/ingest.d.ts.map +1 -0
- package/resources/ingest.js +38 -0
- package/resources/ingest.js.map +1 -0
- package/resources/ingest.mjs +34 -0
- package/resources/ingest.mjs.map +1 -0
- package/resources/pets.d.ts +157 -0
- package/resources/pets.d.ts.map +1 -0
- package/resources/pets.js +75 -0
- package/resources/pets.js.map +1 -0
- package/resources/pets.mjs +71 -0
- package/resources/pets.mjs.map +1 -0
- package/resources/shared.d.ts +12 -0
- package/resources/shared.d.ts.map +1 -0
- package/resources/shared.js +4 -0
- package/resources/shared.js.map +1 -0
- package/resources/shared.mjs +3 -0
- package/resources/shared.mjs.map +1 -0
- package/resources/store/index.d.ts +3 -0
- package/resources/store/index.d.ts.map +1 -0
- package/resources/store/index.js +9 -0
- package/resources/store/index.js.map +1 -0
- package/resources/store/index.mjs +4 -0
- package/resources/store/index.mjs.map +1 -0
- package/resources/store/order.d.ts +16 -0
- package/resources/store/order.d.ts.map +1 -0
- package/resources/store/order.js +26 -0
- package/resources/store/order.js.map +1 -0
- package/resources/store/order.mjs +22 -0
- package/resources/store/order.mjs.map +1 -0
- package/resources/store/store.d.ts +35 -0
- package/resources/store/store.d.ts.map +1 -0
- package/resources/store/store.js +53 -0
- package/resources/store/store.js.map +1 -0
- package/resources/store/store.mjs +26 -0
- package/resources/store/store.mjs.map +1 -0
- package/resources/user.d.ts +96 -0
- package/resources/user.d.ts.map +1 -0
- package/resources/user.js +65 -0
- package/resources/user.js.map +1 -0
- package/resources/user.mjs +61 -0
- package/resources/user.mjs.map +1 -0
- package/shims/node.d.ts +30 -0
- package/shims/node.d.ts.map +1 -0
- package/shims/node.js +31 -0
- package/shims/node.js.map +1 -0
- package/shims/node.mjs +5 -0
- package/shims/node.mjs.map +1 -0
- package/shims/web.d.ts +26 -0
- package/shims/web.d.ts.map +1 -0
- package/shims/web.js +31 -0
- package/shims/web.js.map +1 -0
- package/shims/web.mjs +5 -0
- package/shims/web.mjs.map +1 -0
- package/src/_shims/MultipartBody.ts +9 -0
- package/src/_shims/README.md +46 -0
- package/src/_shims/auto/runtime-bun.ts +4 -0
- package/src/_shims/auto/runtime-node.ts +4 -0
- package/src/_shims/auto/runtime.ts +4 -0
- package/src/_shims/auto/types-node.ts +4 -0
- package/src/_shims/auto/types.d.ts +101 -0
- package/src/_shims/auto/types.js +3 -0
- package/src/_shims/auto/types.mjs +3 -0
- package/src/_shims/bun-runtime.ts +14 -0
- package/src/_shims/index.d.ts +81 -0
- package/src/_shims/index.js +13 -0
- package/src/_shims/index.mjs +7 -0
- package/src/_shims/manual-types.d.ts +12 -0
- package/src/_shims/manual-types.js +3 -0
- package/src/_shims/manual-types.mjs +3 -0
- package/src/_shims/node-runtime.ts +81 -0
- package/src/_shims/node-types.d.ts +42 -0
- package/src/_shims/node-types.js +3 -0
- package/src/_shims/node-types.mjs +3 -0
- package/src/_shims/registry.ts +67 -0
- package/src/_shims/web-runtime.ts +103 -0
- package/src/_shims/web-types.d.ts +83 -0
- package/src/_shims/web-types.js +3 -0
- package/src/_shims/web-types.mjs +3 -0
- package/src/core.ts +1196 -0
- package/src/error.ts +146 -0
- package/src/index.ts +243 -0
- package/src/internal/qs/LICENSE.md +13 -0
- package/src/internal/qs/README.md +3 -0
- package/src/internal/qs/formats.ts +9 -0
- package/src/internal/qs/index.ts +13 -0
- package/src/internal/qs/stringify.ts +388 -0
- package/src/internal/qs/types.ts +71 -0
- package/src/internal/qs/utils.ts +265 -0
- package/src/lib/.keep +4 -0
- package/src/resource.ts +11 -0
- package/src/resources/conversation.ts +62 -0
- package/src/resources/index.ts +15 -0
- package/src/resources/ingest.ts +92 -0
- package/src/resources/pets.ts +276 -0
- package/src/resources/shared.ts +18 -0
- package/src/resources/store/index.ts +4 -0
- package/src/resources/store/order.ts +26 -0
- package/src/resources/store/store.ts +59 -0
- package/src/resources/user.ts +185 -0
- package/src/shims/node.ts +50 -0
- package/src/shims/web.ts +50 -0
- package/src/tsconfig.json +11 -0
- package/src/uploads.ts +255 -0
- package/src/version.ts +1 -0
- package/uploads.d.ts +75 -0
- package/uploads.d.ts.map +1 -0
- package/uploads.js +171 -0
- package/uploads.js.map +1 -0
- package/uploads.mjs +158 -0
- package/uploads.mjs.map +1 -0
- package/version.d.ts +2 -0
- package/version.d.ts.map +1 -0
- package/version.js +5 -0
- package/version.js.map +1 -0
- package/version.mjs +2 -0
- package/version.mjs.map +1 -0
package/src/error.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { castToError, Headers } from './core';
|
|
4
|
+
|
|
5
|
+
export class LorikeetError extends Error {}
|
|
6
|
+
|
|
7
|
+
export class APIError extends LorikeetError {
|
|
8
|
+
readonly status: number | undefined;
|
|
9
|
+
readonly headers: Headers | undefined;
|
|
10
|
+
readonly error: Object | undefined;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
status: number | undefined,
|
|
14
|
+
error: Object | undefined,
|
|
15
|
+
message: string | undefined,
|
|
16
|
+
headers: Headers | undefined,
|
|
17
|
+
) {
|
|
18
|
+
super(`${APIError.makeMessage(status, error, message)}`);
|
|
19
|
+
this.status = status;
|
|
20
|
+
this.headers = headers;
|
|
21
|
+
this.error = error;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
|
|
25
|
+
const msg =
|
|
26
|
+
error?.message ?
|
|
27
|
+
typeof error.message === 'string' ?
|
|
28
|
+
error.message
|
|
29
|
+
: JSON.stringify(error.message)
|
|
30
|
+
: error ? JSON.stringify(error)
|
|
31
|
+
: message;
|
|
32
|
+
|
|
33
|
+
if (status && msg) {
|
|
34
|
+
return `${status} ${msg}`;
|
|
35
|
+
}
|
|
36
|
+
if (status) {
|
|
37
|
+
return `${status} status code (no body)`;
|
|
38
|
+
}
|
|
39
|
+
if (msg) {
|
|
40
|
+
return msg;
|
|
41
|
+
}
|
|
42
|
+
return '(no status code or body)';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static generate(
|
|
46
|
+
status: number | undefined,
|
|
47
|
+
errorResponse: Object | undefined,
|
|
48
|
+
message: string | undefined,
|
|
49
|
+
headers: Headers | undefined,
|
|
50
|
+
) {
|
|
51
|
+
if (!status) {
|
|
52
|
+
return new APIConnectionError({ message, cause: castToError(errorResponse) });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const error = errorResponse as Record<string, any>;
|
|
56
|
+
|
|
57
|
+
if (status === 400) {
|
|
58
|
+
return new BadRequestError(status, error, message, headers);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (status === 401) {
|
|
62
|
+
return new AuthenticationError(status, error, message, headers);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (status === 403) {
|
|
66
|
+
return new PermissionDeniedError(status, error, message, headers);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (status === 404) {
|
|
70
|
+
return new NotFoundError(status, error, message, headers);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (status === 409) {
|
|
74
|
+
return new ConflictError(status, error, message, headers);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (status === 422) {
|
|
78
|
+
return new UnprocessableEntityError(status, error, message, headers);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (status === 429) {
|
|
82
|
+
return new RateLimitError(status, error, message, headers);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (status >= 500) {
|
|
86
|
+
return new InternalServerError(status, error, message, headers);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return new APIError(status, error, message, headers);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export class APIUserAbortError extends APIError {
|
|
94
|
+
override readonly status: undefined = undefined;
|
|
95
|
+
|
|
96
|
+
constructor({ message }: { message?: string } = {}) {
|
|
97
|
+
super(undefined, undefined, message || 'Request was aborted.', undefined);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export class APIConnectionError extends APIError {
|
|
102
|
+
override readonly status: undefined = undefined;
|
|
103
|
+
|
|
104
|
+
constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
|
|
105
|
+
super(undefined, undefined, message || 'Connection error.', undefined);
|
|
106
|
+
// in some environments the 'cause' property is already declared
|
|
107
|
+
// @ts-ignore
|
|
108
|
+
if (cause) this.cause = cause;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export class APIConnectionTimeoutError extends APIConnectionError {
|
|
113
|
+
constructor({ message }: { message?: string } = {}) {
|
|
114
|
+
super({ message: message ?? 'Request timed out.' });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export class BadRequestError extends APIError {
|
|
119
|
+
override readonly status: 400 = 400;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export class AuthenticationError extends APIError {
|
|
123
|
+
override readonly status: 401 = 401;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export class PermissionDeniedError extends APIError {
|
|
127
|
+
override readonly status: 403 = 403;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export class NotFoundError extends APIError {
|
|
131
|
+
override readonly status: 404 = 404;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export class ConflictError extends APIError {
|
|
135
|
+
override readonly status: 409 = 409;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export class UnprocessableEntityError extends APIError {
|
|
139
|
+
override readonly status: 422 = 422;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export class RateLimitError extends APIError {
|
|
143
|
+
override readonly status: 429 = 429;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export class InternalServerError extends APIError {}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import * as Errors from './error';
|
|
4
|
+
import * as Uploads from './uploads';
|
|
5
|
+
import { type Agent } from './_shims/index';
|
|
6
|
+
import * as Core from './core';
|
|
7
|
+
import * as API from './resources/index';
|
|
8
|
+
|
|
9
|
+
export interface ClientOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The client ID associated with your account.
|
|
12
|
+
*/
|
|
13
|
+
bearerToken?: string | null | undefined;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The signature of the webhook - should be generated as a SHA256 hash of the payload and the secret key.
|
|
17
|
+
*/
|
|
18
|
+
apiKey?: string | null | undefined;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
|
22
|
+
*
|
|
23
|
+
* Defaults to process.env['LORIKEET_BASE_URL'].
|
|
24
|
+
*/
|
|
25
|
+
baseURL?: string | null | undefined;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The maximum amount of time (in milliseconds) that the client should wait for a response
|
|
29
|
+
* from the server before timing out a single request.
|
|
30
|
+
*
|
|
31
|
+
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
|
|
32
|
+
* much longer than this timeout before the promise succeeds or fails.
|
|
33
|
+
*/
|
|
34
|
+
timeout?: number;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* An HTTP agent used to manage HTTP(S) connections.
|
|
38
|
+
*
|
|
39
|
+
* If not provided, an agent will be constructed by default in the Node.js environment,
|
|
40
|
+
* otherwise no agent is used.
|
|
41
|
+
*/
|
|
42
|
+
httpAgent?: Agent;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Specify a custom `fetch` function implementation.
|
|
46
|
+
*
|
|
47
|
+
* If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
|
|
48
|
+
* defined globally.
|
|
49
|
+
*/
|
|
50
|
+
fetch?: Core.Fetch | undefined;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The maximum number of times that the client will retry a request in case of a
|
|
54
|
+
* temporary failure, like a network error or a 5XX error from the server.
|
|
55
|
+
*
|
|
56
|
+
* @default 2
|
|
57
|
+
*/
|
|
58
|
+
maxRetries?: number;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Default headers to include with every request to the API.
|
|
62
|
+
*
|
|
63
|
+
* These can be removed in individual requests by explicitly setting the
|
|
64
|
+
* header to `undefined` or `null` in request options.
|
|
65
|
+
*/
|
|
66
|
+
defaultHeaders?: Core.Headers;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Default query parameters to include with every request to the API.
|
|
70
|
+
*
|
|
71
|
+
* These can be removed in individual requests by explicitly setting the
|
|
72
|
+
* param to `undefined` in request options.
|
|
73
|
+
*/
|
|
74
|
+
defaultQuery?: Core.DefaultQuery;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* API Client for interfacing with the Lorikeet API.
|
|
79
|
+
*/
|
|
80
|
+
export class Lorikeet extends Core.APIClient {
|
|
81
|
+
bearerToken: string | null;
|
|
82
|
+
apiKey: string | null;
|
|
83
|
+
|
|
84
|
+
private _options: ClientOptions;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* API Client for interfacing with the Lorikeet API.
|
|
88
|
+
*
|
|
89
|
+
* @param {string | null | undefined} [opts.bearerToken=process.env['LORIKEET_CLIENT_ID'] ?? null]
|
|
90
|
+
* @param {string | null | undefined} [opts.apiKey]
|
|
91
|
+
* @param {string} [opts.baseURL=process.env['LORIKEET_BASE_URL'] ?? http://api.lorikeetcx.ai] - Override the default base URL for the API.
|
|
92
|
+
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
93
|
+
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
|
|
94
|
+
* @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
95
|
+
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
|
|
96
|
+
* @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
|
|
97
|
+
* @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
98
|
+
*/
|
|
99
|
+
constructor({
|
|
100
|
+
baseURL = Core.readEnv('LORIKEET_BASE_URL'),
|
|
101
|
+
bearerToken = Core.readEnv('LORIKEET_CLIENT_ID') ?? null,
|
|
102
|
+
apiKey = null,
|
|
103
|
+
...opts
|
|
104
|
+
}: ClientOptions = {}) {
|
|
105
|
+
const options: ClientOptions = {
|
|
106
|
+
bearerToken,
|
|
107
|
+
apiKey,
|
|
108
|
+
...opts,
|
|
109
|
+
baseURL: baseURL || `http://api.lorikeetcx.ai`,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
super({
|
|
113
|
+
baseURL: options.baseURL!,
|
|
114
|
+
timeout: options.timeout ?? 60000 /* 1 minute */,
|
|
115
|
+
httpAgent: options.httpAgent,
|
|
116
|
+
maxRetries: options.maxRetries,
|
|
117
|
+
fetch: options.fetch,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
this._options = options;
|
|
121
|
+
|
|
122
|
+
this.bearerToken = bearerToken;
|
|
123
|
+
this.apiKey = apiKey;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
conversation: API.Conversation = new API.Conversation(this);
|
|
127
|
+
ingest: API.Ingest = new API.Ingest(this);
|
|
128
|
+
|
|
129
|
+
protected override defaultQuery(): Core.DefaultQuery | undefined {
|
|
130
|
+
return this._options.defaultQuery;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers {
|
|
134
|
+
return {
|
|
135
|
+
...super.defaultHeaders(opts),
|
|
136
|
+
...this._options.defaultHeaders,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
protected override validateHeaders(headers: Core.Headers, customHeaders: Core.Headers) {
|
|
141
|
+
if (this.bearerToken && headers['authorization']) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (customHeaders['authorization'] === null) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (this.apiKey && headers['x-optech-webhook-signature']) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (customHeaders['x-optech-webhook-signature'] === null) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
throw new Error(
|
|
156
|
+
'Could not resolve authentication method. Expected either bearerToken or apiKey to be set. Or for one of the "Authorization" or "x-optech-webhook-signature" headers to be explicitly omitted',
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers {
|
|
161
|
+
const bearerAuth = this.bearerAuth(opts);
|
|
162
|
+
const apiKeyAuth = this.apiKeyAuth(opts);
|
|
163
|
+
|
|
164
|
+
if (bearerAuth != null && !Core.isEmptyObj(bearerAuth)) {
|
|
165
|
+
return bearerAuth;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (apiKeyAuth != null && !Core.isEmptyObj(apiKeyAuth)) {
|
|
169
|
+
return apiKeyAuth;
|
|
170
|
+
}
|
|
171
|
+
return {};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
protected bearerAuth(opts: Core.FinalRequestOptions): Core.Headers {
|
|
175
|
+
if (this.bearerToken == null) {
|
|
176
|
+
return {};
|
|
177
|
+
}
|
|
178
|
+
return { Authorization: `Bearer ${this.bearerToken}` };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
protected apiKeyAuth(opts: Core.FinalRequestOptions): Core.Headers {
|
|
182
|
+
if (this.apiKey == null) {
|
|
183
|
+
return {};
|
|
184
|
+
}
|
|
185
|
+
return { 'x-optech-webhook-signature': this.apiKey };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
static Lorikeet = this;
|
|
189
|
+
static DEFAULT_TIMEOUT = 60000; // 1 minute
|
|
190
|
+
|
|
191
|
+
static LorikeetError = Errors.LorikeetError;
|
|
192
|
+
static APIError = Errors.APIError;
|
|
193
|
+
static APIConnectionError = Errors.APIConnectionError;
|
|
194
|
+
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
|
|
195
|
+
static APIUserAbortError = Errors.APIUserAbortError;
|
|
196
|
+
static NotFoundError = Errors.NotFoundError;
|
|
197
|
+
static ConflictError = Errors.ConflictError;
|
|
198
|
+
static RateLimitError = Errors.RateLimitError;
|
|
199
|
+
static BadRequestError = Errors.BadRequestError;
|
|
200
|
+
static AuthenticationError = Errors.AuthenticationError;
|
|
201
|
+
static InternalServerError = Errors.InternalServerError;
|
|
202
|
+
static PermissionDeniedError = Errors.PermissionDeniedError;
|
|
203
|
+
static UnprocessableEntityError = Errors.UnprocessableEntityError;
|
|
204
|
+
|
|
205
|
+
static toFile = Uploads.toFile;
|
|
206
|
+
static fileFromPath = Uploads.fileFromPath;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export const {
|
|
210
|
+
LorikeetError,
|
|
211
|
+
APIError,
|
|
212
|
+
APIConnectionError,
|
|
213
|
+
APIConnectionTimeoutError,
|
|
214
|
+
APIUserAbortError,
|
|
215
|
+
NotFoundError,
|
|
216
|
+
ConflictError,
|
|
217
|
+
RateLimitError,
|
|
218
|
+
BadRequestError,
|
|
219
|
+
AuthenticationError,
|
|
220
|
+
InternalServerError,
|
|
221
|
+
PermissionDeniedError,
|
|
222
|
+
UnprocessableEntityError,
|
|
223
|
+
} = Errors;
|
|
224
|
+
|
|
225
|
+
export import toFile = Uploads.toFile;
|
|
226
|
+
export import fileFromPath = Uploads.fileFromPath;
|
|
227
|
+
|
|
228
|
+
export namespace Lorikeet {
|
|
229
|
+
export import RequestOptions = Core.RequestOptions;
|
|
230
|
+
|
|
231
|
+
export import Conversation = API.Conversation;
|
|
232
|
+
export import ConversationMessageResponse = API.ConversationMessageResponse;
|
|
233
|
+
export import ConversationStartResponse = API.ConversationStartResponse;
|
|
234
|
+
export import ConversationMessageParams = API.ConversationMessageParams;
|
|
235
|
+
|
|
236
|
+
export import Ingest = API.Ingest;
|
|
237
|
+
export import IngestValidateResponse = API.IngestValidateResponse;
|
|
238
|
+
export import IngestReturnWebhookParams = API.IngestReturnWebhookParams;
|
|
239
|
+
export import IngestTokenParams = API.IngestTokenParams;
|
|
240
|
+
export import IngestValidateParams = API.IngestValidateParams;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export default Lorikeet;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014, Nathan LaFreniere and other [contributors](https://github.com/puruvj/neoqs/graphs/contributors) All rights reserved.
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
8
|
+
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
10
|
+
|
|
11
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
12
|
+
|
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Format } from './types';
|
|
2
|
+
|
|
3
|
+
export const default_format: Format = 'RFC3986';
|
|
4
|
+
export const formatters: Record<Format, (str: PropertyKey) => string> = {
|
|
5
|
+
RFC1738: (v: PropertyKey) => String(v).replace(/%20/g, '+'),
|
|
6
|
+
RFC3986: (v: PropertyKey) => String(v),
|
|
7
|
+
};
|
|
8
|
+
export const RFC1738 = 'RFC1738';
|
|
9
|
+
export const RFC3986 = 'RFC3986';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { default_format, formatters, RFC1738, RFC3986 } from './formats';
|
|
2
|
+
|
|
3
|
+
const formats = {
|
|
4
|
+
formatters,
|
|
5
|
+
RFC1738,
|
|
6
|
+
RFC3986,
|
|
7
|
+
default: default_format,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { stringify } from './stringify';
|
|
11
|
+
export { formats };
|
|
12
|
+
|
|
13
|
+
export type { DefaultDecoder, DefaultEncoder, Format, ParseOptions, StringifyOptions } from './types';
|