@lorikeetai/node-sdk 0.1.0-alpha.1 → 0.1.0-alpha.10
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 +91 -0
- package/README.md +35 -24
- package/_shims/MultipartBody.js.map +1 -1
- package/_shims/MultipartBody.mjs.map +1 -1
- package/_shims/auto/runtime-bun.d.ts.map +1 -1
- package/_shims/auto/runtime-bun.js.map +1 -1
- package/_shims/auto/runtime-node.d.ts.map +1 -1
- package/_shims/auto/runtime-node.js.map +1 -1
- package/_shims/auto/runtime.d.ts.map +1 -1
- package/_shims/auto/runtime.js.map +1 -1
- package/_shims/auto/types-node.d.ts.map +1 -1
- package/_shims/auto/types-node.js.map +1 -1
- package/_shims/auto/types.d.ts +52 -52
- package/_shims/bun-runtime.d.ts.map +1 -1
- package/_shims/bun-runtime.js +1 -2
- package/_shims/bun-runtime.js.map +1 -1
- package/_shims/bun-runtime.mjs.map +1 -1
- package/_shims/index.d.ts +36 -36
- package/_shims/index.js +5 -5
- package/_shims/index.mjs +4 -4
- package/_shims/node-runtime.d.ts.map +1 -1
- package/_shims/node-runtime.js +1 -2
- package/_shims/node-runtime.js.map +1 -1
- package/_shims/node-runtime.mjs.map +1 -1
- package/_shims/node-types.d.ts +27 -27
- package/_shims/registry.d.ts.map +1 -1
- package/_shims/registry.js +2 -2
- package/_shims/registry.js.map +1 -1
- package/_shims/registry.mjs.map +1 -1
- package/_shims/web-runtime.d.ts.map +1 -1
- package/_shims/web-runtime.js +1 -2
- package/_shims/web-runtime.js.map +1 -1
- package/_shims/web-runtime.mjs.map +1 -1
- package/_shims/web-types.d.ts +52 -52
- package/core.d.ts +2 -4
- package/core.d.ts.map +1 -1
- package/core.js +7 -6
- package/core.js.map +1 -1
- package/core.mjs +2 -1
- package/core.mjs.map +1 -1
- package/error.d.ts.map +1 -1
- package/error.js.map +1 -1
- package/error.mjs.map +1 -1
- package/index.d.mts +14 -20
- package/index.d.ts +14 -20
- package/index.d.ts.map +1 -1
- package/index.js +29 -45
- package/index.js.map +1 -1
- package/index.mjs +28 -44
- package/index.mjs.map +1 -1
- package/internal/qs/formats.d.ts.map +1 -1
- package/internal/qs/formats.js.map +1 -1
- package/internal/qs/formats.mjs.map +1 -1
- package/internal/qs/index.d.ts.map +1 -1
- package/internal/qs/index.js.map +1 -1
- package/internal/qs/index.mjs.map +1 -1
- package/internal/qs/stringify.d.ts.map +1 -1
- package/internal/qs/stringify.js +1 -2
- package/internal/qs/stringify.js.map +1 -1
- package/internal/qs/stringify.mjs.map +1 -1
- package/internal/qs/types.d.ts.map +1 -1
- package/internal/qs/utils.d.ts.map +1 -1
- package/internal/qs/utils.js +9 -9
- package/internal/qs/utils.js.map +1 -1
- package/internal/qs/utils.mjs.map +1 -1
- package/lib/generate-signature.d.ts +5 -0
- package/lib/generate-signature.d.ts.map +1 -0
- package/lib/generate-signature.js +19 -0
- package/lib/generate-signature.js.map +1 -0
- package/lib/generate-signature.mjs +13 -0
- package/lib/generate-signature.mjs.map +1 -0
- package/package.json +16 -14
- package/resource.d.ts.map +1 -1
- package/resource.js.map +1 -1
- package/resource.mjs.map +1 -1
- package/resources/conversation/chat.d.ts +79 -0
- package/resources/conversation/chat.d.ts.map +1 -0
- package/resources/conversation/chat.js +20 -0
- package/resources/conversation/chat.js.map +1 -0
- package/resources/conversation/chat.mjs +16 -0
- package/resources/conversation/chat.mjs.map +1 -0
- package/resources/conversation/conversation.d.ts +15 -0
- package/resources/conversation/conversation.d.ts.map +1 -0
- package/resources/{store/store.js → conversation/conversation.js} +9 -22
- package/resources/conversation/conversation.js.map +1 -0
- package/resources/conversation/conversation.mjs +13 -0
- package/resources/conversation/conversation.mjs.map +1 -0
- package/resources/conversation/index.d.ts +3 -0
- package/resources/conversation/index.d.ts.map +1 -0
- package/resources/conversation/index.js +9 -0
- package/resources/conversation/index.js.map +1 -0
- package/resources/conversation/index.mjs +4 -0
- package/resources/conversation/index.mjs.map +1 -0
- package/resources/conversation.d.ts +0 -41
- package/resources/conversation.d.ts.map +1 -1
- package/resources/conversation.js +0 -14
- package/resources/conversation.js.map +1 -1
- package/resources/conversation.mjs +0 -14
- package/resources/conversation.mjs.map +1 -1
- package/resources/index.d.ts +3 -2
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +4 -2
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +3 -2
- package/resources/index.mjs.map +1 -1
- package/resources/ingest.d.ts +1 -53
- package/resources/ingest.d.ts.map +1 -1
- package/resources/ingest.js +2 -25
- package/resources/ingest.js.map +1 -1
- package/resources/ingest.mjs +2 -25
- package/resources/ingest.mjs.map +1 -1
- package/resources/token.d.ts +28 -0
- package/resources/token.d.ts.map +1 -0
- package/resources/token.js +18 -0
- package/resources/token.js.map +1 -0
- package/resources/token.mjs +14 -0
- package/resources/token.mjs.map +1 -0
- package/shims/node.d.ts +0 -4
- package/shims/node.d.ts.map +1 -1
- package/shims/node.js +0 -25
- package/shims/node.js.map +1 -1
- package/shims/node.mjs +0 -1
- package/shims/node.mjs.map +1 -1
- package/shims/web.d.ts.map +1 -1
- package/shims/web.js +0 -25
- package/shims/web.js.map +1 -1
- package/shims/web.mjs +0 -1
- package/shims/web.mjs.map +1 -1
- package/src/_shims/MultipartBody.ts +1 -1
- package/src/_shims/auto/runtime-bun.ts +1 -1
- package/src/_shims/auto/runtime-node.ts +1 -1
- package/src/_shims/auto/runtime.ts +1 -1
- package/src/_shims/auto/types-node.ts +1 -1
- package/src/_shims/auto/types.d.ts +52 -52
- package/src/_shims/bun-runtime.ts +6 -6
- package/src/_shims/index.d.ts +36 -36
- package/src/_shims/index.js +5 -5
- package/src/_shims/index.mjs +4 -4
- package/src/_shims/node-runtime.ts +32 -32
- package/src/_shims/node-types.d.ts +27 -27
- package/src/_shims/registry.ts +44 -44
- package/src/_shims/web-runtime.ts +16 -16
- package/src/_shims/web-types.d.ts +52 -52
- package/src/core.ts +373 -373
- package/src/error.ts +37 -37
- package/src/index.ts +88 -112
- package/src/internal/qs/formats.ts +5 -5
- package/src/internal/qs/index.ts +5 -5
- package/src/internal/qs/stringify.ts +98 -98
- package/src/internal/qs/types.ts +52 -52
- package/src/internal/qs/utils.ts +87 -87
- package/src/lib/generate-signature.ts +13 -0
- package/src/resource.ts +3 -3
- package/src/resources/conversation/chat.ts +102 -0
- package/src/resources/conversation/conversation.ts +18 -0
- package/src/resources/conversation/index.ts +12 -0
- package/src/resources/conversation.ts +2 -59
- package/src/resources/index.ts +3 -13
- package/src/resources/ingest.ts +5 -84
- package/src/resources/token.ts +41 -0
- package/src/shims/node.ts +24 -24
- package/src/shims/web.ts +24 -24
- package/src/uploads.ts +75 -74
- package/src/version.ts +1 -1
- package/uploads.d.ts +2 -2
- package/uploads.d.ts.map +1 -1
- package/uploads.js +3 -4
- package/uploads.js.map +1 -1
- package/uploads.mjs +1 -2
- package/uploads.mjs.map +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
- package/version.mjs +1 -1
- package/version.mjs.map +1 -1
- package/resources/pets.d.ts +0 -157
- package/resources/pets.d.ts.map +0 -1
- package/resources/pets.js +0 -75
- package/resources/pets.js.map +0 -1
- package/resources/pets.mjs +0 -71
- package/resources/pets.mjs.map +0 -1
- package/resources/shared.d.ts +0 -12
- package/resources/shared.d.ts.map +0 -1
- package/resources/shared.js +0 -4
- package/resources/shared.js.map +0 -1
- package/resources/shared.mjs +0 -3
- package/resources/shared.mjs.map +0 -1
- package/resources/store/index.d.ts +0 -3
- package/resources/store/index.d.ts.map +0 -1
- package/resources/store/index.js +0 -9
- package/resources/store/index.js.map +0 -1
- package/resources/store/index.mjs +0 -4
- package/resources/store/index.mjs.map +0 -1
- package/resources/store/order.d.ts +0 -16
- package/resources/store/order.d.ts.map +0 -1
- package/resources/store/order.js +0 -26
- package/resources/store/order.js.map +0 -1
- package/resources/store/order.mjs +0 -22
- package/resources/store/order.mjs.map +0 -1
- package/resources/store/store.d.ts +0 -35
- package/resources/store/store.d.ts.map +0 -1
- package/resources/store/store.js.map +0 -1
- package/resources/store/store.mjs +0 -26
- package/resources/store/store.mjs.map +0 -1
- package/resources/user.d.ts +0 -96
- package/resources/user.d.ts.map +0 -1
- package/resources/user.js +0 -65
- package/resources/user.js.map +0 -1
- package/resources/user.mjs +0 -61
- package/resources/user.mjs.map +0 -1
- package/src/resources/pets.ts +0 -276
- package/src/resources/shared.ts +0 -18
- package/src/resources/store/index.ts +0 -4
- package/src/resources/store/order.ts +0 -26
- package/src/resources/store/store.ts +0 -59
- package/src/resources/user.ts +0 -185
package/src/error.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { castToError, Headers } from './core'
|
|
3
|
+
import { castToError, Headers } from './core'
|
|
4
4
|
|
|
5
5
|
export class LorikeetError extends Error {}
|
|
6
6
|
|
|
7
7
|
export class APIError extends LorikeetError {
|
|
8
|
-
readonly status: number | undefined
|
|
9
|
-
readonly headers: Headers | undefined
|
|
10
|
-
readonly error: Object | undefined
|
|
8
|
+
readonly status: number | undefined
|
|
9
|
+
readonly headers: Headers | undefined
|
|
10
|
+
readonly error: Object | undefined
|
|
11
11
|
|
|
12
12
|
constructor(
|
|
13
13
|
status: number | undefined,
|
|
@@ -15,10 +15,10 @@ export class APIError extends LorikeetError {
|
|
|
15
15
|
message: string | undefined,
|
|
16
16
|
headers: Headers | undefined,
|
|
17
17
|
) {
|
|
18
|
-
super(`${APIError.makeMessage(status, error, message)}`)
|
|
19
|
-
this.status = status
|
|
20
|
-
this.headers = headers
|
|
21
|
-
this.error = error
|
|
18
|
+
super(`${APIError.makeMessage(status, error, message)}`)
|
|
19
|
+
this.status = status
|
|
20
|
+
this.headers = headers
|
|
21
|
+
this.error = error
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
|
|
@@ -28,18 +28,18 @@ export class APIError extends LorikeetError {
|
|
|
28
28
|
error.message
|
|
29
29
|
: JSON.stringify(error.message)
|
|
30
30
|
: error ? JSON.stringify(error)
|
|
31
|
-
: message
|
|
31
|
+
: message
|
|
32
32
|
|
|
33
33
|
if (status && msg) {
|
|
34
|
-
return `${status} ${msg}
|
|
34
|
+
return `${status} ${msg}`
|
|
35
35
|
}
|
|
36
36
|
if (status) {
|
|
37
|
-
return `${status} status code (no body)
|
|
37
|
+
return `${status} status code (no body)`
|
|
38
38
|
}
|
|
39
39
|
if (msg) {
|
|
40
|
-
return msg
|
|
40
|
+
return msg
|
|
41
41
|
}
|
|
42
|
-
return '(no status code or body)'
|
|
42
|
+
return '(no status code or body)'
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
static generate(
|
|
@@ -49,98 +49,98 @@ export class APIError extends LorikeetError {
|
|
|
49
49
|
headers: Headers | undefined,
|
|
50
50
|
) {
|
|
51
51
|
if (!status) {
|
|
52
|
-
return new APIConnectionError({ message, cause: castToError(errorResponse) })
|
|
52
|
+
return new APIConnectionError({ message, cause: castToError(errorResponse) })
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
const error = errorResponse as Record<string, any
|
|
55
|
+
const error = errorResponse as Record<string, any>
|
|
56
56
|
|
|
57
57
|
if (status === 400) {
|
|
58
|
-
return new BadRequestError(status, error, message, headers)
|
|
58
|
+
return new BadRequestError(status, error, message, headers)
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
if (status === 401) {
|
|
62
|
-
return new AuthenticationError(status, error, message, headers)
|
|
62
|
+
return new AuthenticationError(status, error, message, headers)
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
if (status === 403) {
|
|
66
|
-
return new PermissionDeniedError(status, error, message, headers)
|
|
66
|
+
return new PermissionDeniedError(status, error, message, headers)
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
if (status === 404) {
|
|
70
|
-
return new NotFoundError(status, error, message, headers)
|
|
70
|
+
return new NotFoundError(status, error, message, headers)
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
if (status === 409) {
|
|
74
|
-
return new ConflictError(status, error, message, headers)
|
|
74
|
+
return new ConflictError(status, error, message, headers)
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
if (status === 422) {
|
|
78
|
-
return new UnprocessableEntityError(status, error, message, headers)
|
|
78
|
+
return new UnprocessableEntityError(status, error, message, headers)
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
if (status === 429) {
|
|
82
|
-
return new RateLimitError(status, error, message, headers)
|
|
82
|
+
return new RateLimitError(status, error, message, headers)
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
if (status >= 500) {
|
|
86
|
-
return new InternalServerError(status, error, message, headers)
|
|
86
|
+
return new InternalServerError(status, error, message, headers)
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
return new APIError(status, error, message, headers)
|
|
89
|
+
return new APIError(status, error, message, headers)
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
export class APIUserAbortError extends APIError {
|
|
94
|
-
override readonly status: undefined = undefined
|
|
94
|
+
override readonly status: undefined = undefined
|
|
95
95
|
|
|
96
96
|
constructor({ message }: { message?: string } = {}) {
|
|
97
|
-
super(undefined, undefined, message || 'Request was aborted.', undefined)
|
|
97
|
+
super(undefined, undefined, message || 'Request was aborted.', undefined)
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
export class APIConnectionError extends APIError {
|
|
102
|
-
override readonly status: undefined = undefined
|
|
102
|
+
override readonly status: undefined = undefined
|
|
103
103
|
|
|
104
104
|
constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
|
|
105
|
-
super(undefined, undefined, message || 'Connection error.', undefined)
|
|
105
|
+
super(undefined, undefined, message || 'Connection error.', undefined)
|
|
106
106
|
// in some environments the 'cause' property is already declared
|
|
107
107
|
// @ts-ignore
|
|
108
|
-
if (cause) this.cause = cause
|
|
108
|
+
if (cause) this.cause = cause
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
export class APIConnectionTimeoutError extends APIConnectionError {
|
|
113
113
|
constructor({ message }: { message?: string } = {}) {
|
|
114
|
-
super({ message: message ?? 'Request timed out.' })
|
|
114
|
+
super({ message: message ?? 'Request timed out.' })
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
export class BadRequestError extends APIError {
|
|
119
|
-
override readonly status: 400 = 400
|
|
119
|
+
override readonly status: 400 = 400
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
export class AuthenticationError extends APIError {
|
|
123
|
-
override readonly status: 401 = 401
|
|
123
|
+
override readonly status: 401 = 401
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
export class PermissionDeniedError extends APIError {
|
|
127
|
-
override readonly status: 403 = 403
|
|
127
|
+
override readonly status: 403 = 403
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
export class NotFoundError extends APIError {
|
|
131
|
-
override readonly status: 404 = 404
|
|
131
|
+
override readonly status: 404 = 404
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
export class ConflictError extends APIError {
|
|
135
|
-
override readonly status: 409 = 409
|
|
135
|
+
override readonly status: 409 = 409
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
export class UnprocessableEntityError extends APIError {
|
|
139
|
-
override readonly status: 422 = 422
|
|
139
|
+
override readonly status: 422 = 422
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
export class RateLimitError extends APIError {
|
|
143
|
-
override readonly status: 429 = 429
|
|
143
|
+
override readonly status: 429 = 429
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
export class InternalServerError extends APIError {}
|
package/src/index.ts
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import * as Errors from './error'
|
|
4
|
-
import * as Uploads from './uploads'
|
|
5
|
-
import { type Agent } from './_shims/index'
|
|
6
|
-
import * as
|
|
7
|
-
import * as
|
|
3
|
+
import * as Errors from './error'
|
|
4
|
+
import * as Uploads from './uploads'
|
|
5
|
+
import { type Agent } from './_shims/index'
|
|
6
|
+
import * as qs from './internal/qs'
|
|
7
|
+
import * as Core from './core'
|
|
8
|
+
import * as API from './resources/index'
|
|
8
9
|
|
|
9
10
|
export interface ClientOptions {
|
|
10
11
|
/**
|
|
11
|
-
*
|
|
12
|
+
* client identifier authentication associated with the account.
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
+
clientId?: string | undefined
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
+
* Secret key pulled from the Lorikeet App
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
|
+
clientSecret?: string | undefined
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
|
22
23
|
*
|
|
23
24
|
* Defaults to process.env['LORIKEET_BASE_URL'].
|
|
24
25
|
*/
|
|
25
|
-
baseURL?: string | null | undefined
|
|
26
|
+
baseURL?: string | null | undefined
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* The maximum amount of time (in milliseconds) that the client should wait for a response
|
|
@@ -31,7 +32,7 @@ export interface ClientOptions {
|
|
|
31
32
|
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
|
|
32
33
|
* much longer than this timeout before the promise succeeds or fails.
|
|
33
34
|
*/
|
|
34
|
-
timeout?: number
|
|
35
|
+
timeout?: number
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* An HTTP agent used to manage HTTP(S) connections.
|
|
@@ -39,7 +40,7 @@ export interface ClientOptions {
|
|
|
39
40
|
* If not provided, an agent will be constructed by default in the Node.js environment,
|
|
40
41
|
* otherwise no agent is used.
|
|
41
42
|
*/
|
|
42
|
-
httpAgent?: Agent
|
|
43
|
+
httpAgent?: Agent
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
46
|
* Specify a custom `fetch` function implementation.
|
|
@@ -47,7 +48,7 @@ export interface ClientOptions {
|
|
|
47
48
|
* If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
|
|
48
49
|
* defined globally.
|
|
49
50
|
*/
|
|
50
|
-
fetch?: Core.Fetch | undefined
|
|
51
|
+
fetch?: Core.Fetch | undefined
|
|
51
52
|
|
|
52
53
|
/**
|
|
53
54
|
* The maximum number of times that the client will retry a request in case of a
|
|
@@ -55,7 +56,7 @@ export interface ClientOptions {
|
|
|
55
56
|
*
|
|
56
57
|
* @default 2
|
|
57
58
|
*/
|
|
58
|
-
maxRetries?: number
|
|
59
|
+
maxRetries?: number
|
|
59
60
|
|
|
60
61
|
/**
|
|
61
62
|
* Default headers to include with every request to the API.
|
|
@@ -63,7 +64,7 @@ export interface ClientOptions {
|
|
|
63
64
|
* These can be removed in individual requests by explicitly setting the
|
|
64
65
|
* header to `undefined` or `null` in request options.
|
|
65
66
|
*/
|
|
66
|
-
defaultHeaders?: Core.Headers
|
|
67
|
+
defaultHeaders?: Core.Headers
|
|
67
68
|
|
|
68
69
|
/**
|
|
69
70
|
* Default query parameters to include with every request to the API.
|
|
@@ -71,24 +72,24 @@ export interface ClientOptions {
|
|
|
71
72
|
* These can be removed in individual requests by explicitly setting the
|
|
72
73
|
* param to `undefined` in request options.
|
|
73
74
|
*/
|
|
74
|
-
defaultQuery?: Core.DefaultQuery
|
|
75
|
+
defaultQuery?: Core.DefaultQuery
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
/**
|
|
78
79
|
* API Client for interfacing with the Lorikeet API.
|
|
79
80
|
*/
|
|
80
81
|
export class Lorikeet extends Core.APIClient {
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
clientId: string
|
|
83
|
+
clientSecret: string
|
|
83
84
|
|
|
84
|
-
private _options: ClientOptions
|
|
85
|
+
private _options: ClientOptions
|
|
85
86
|
|
|
86
87
|
/**
|
|
87
88
|
* API Client for interfacing with the Lorikeet API.
|
|
88
89
|
*
|
|
89
|
-
* @param {string |
|
|
90
|
-
* @param {string |
|
|
91
|
-
* @param {string} [opts.baseURL=process.env['LORIKEET_BASE_URL'] ??
|
|
90
|
+
* @param {string | undefined} [opts.clientId=process.env['LORIKEET_CLIENT_ID'] ?? undefined]
|
|
91
|
+
* @param {string | undefined} [opts.clientSecret=process.env['LORIKEET_CLIENT_SECRET'] ?? undefined]
|
|
92
|
+
* @param {string} [opts.baseURL=process.env['LORIKEET_BASE_URL'] ?? https://api.lorikeetcx.ai] - Override the default base URL for the API.
|
|
92
93
|
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
93
94
|
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
|
|
94
95
|
* @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
@@ -98,16 +99,27 @@ export class Lorikeet extends Core.APIClient {
|
|
|
98
99
|
*/
|
|
99
100
|
constructor({
|
|
100
101
|
baseURL = Core.readEnv('LORIKEET_BASE_URL'),
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
clientId = Core.readEnv('LORIKEET_CLIENT_ID'),
|
|
103
|
+
clientSecret = Core.readEnv('LORIKEET_CLIENT_SECRET'),
|
|
103
104
|
...opts
|
|
104
105
|
}: ClientOptions = {}) {
|
|
106
|
+
if (clientId === undefined) {
|
|
107
|
+
throw new Errors.LorikeetError(
|
|
108
|
+
"The LORIKEET_CLIENT_ID environment variable is missing or empty; either provide it, or instantiate the Lorikeet client with an clientId option, like new Lorikeet({ clientId: 'My Client ID' }).",
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
if (clientSecret === undefined) {
|
|
112
|
+
throw new Errors.LorikeetError(
|
|
113
|
+
"The LORIKEET_CLIENT_SECRET environment variable is missing or empty; either provide it, or instantiate the Lorikeet client with an clientSecret option, like new Lorikeet({ clientSecret: 'My Client Secret' }).",
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
105
117
|
const options: ClientOptions = {
|
|
106
|
-
|
|
107
|
-
|
|
118
|
+
clientId,
|
|
119
|
+
clientSecret,
|
|
108
120
|
...opts,
|
|
109
|
-
baseURL: baseURL || `
|
|
110
|
-
}
|
|
121
|
+
baseURL: baseURL || `https://api.lorikeetcx.ai`,
|
|
122
|
+
}
|
|
111
123
|
|
|
112
124
|
super({
|
|
113
125
|
baseURL: options.baseURL!,
|
|
@@ -115,95 +127,62 @@ export class Lorikeet extends Core.APIClient {
|
|
|
115
127
|
httpAgent: options.httpAgent,
|
|
116
128
|
maxRetries: options.maxRetries,
|
|
117
129
|
fetch: options.fetch,
|
|
118
|
-
})
|
|
130
|
+
})
|
|
119
131
|
|
|
120
|
-
this._options = options
|
|
132
|
+
this._options = options
|
|
121
133
|
|
|
122
|
-
this.
|
|
123
|
-
this.
|
|
134
|
+
this.clientId = clientId
|
|
135
|
+
this.clientSecret = clientSecret
|
|
124
136
|
}
|
|
125
137
|
|
|
126
|
-
conversation: API.Conversation = new API.Conversation(this)
|
|
127
|
-
|
|
138
|
+
conversation: API.Conversation = new API.Conversation(this)
|
|
139
|
+
token: API.Token = new API.Token(this)
|
|
140
|
+
ingest: API.Ingest = new API.Ingest(this)
|
|
128
141
|
|
|
129
142
|
protected override defaultQuery(): Core.DefaultQuery | undefined {
|
|
130
|
-
return this._options.defaultQuery
|
|
143
|
+
return this._options.defaultQuery
|
|
131
144
|
}
|
|
132
145
|
|
|
133
146
|
protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers {
|
|
134
147
|
return {
|
|
135
148
|
...super.defaultHeaders(opts),
|
|
136
149
|
...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
150
|
}
|
|
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
151
|
}
|
|
159
152
|
|
|
160
153
|
protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers {
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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 {};
|
|
154
|
+
const signature = generateSignature(opts.body as string, this.clientSecret)
|
|
155
|
+
return {
|
|
156
|
+
// backwards compatibility
|
|
157
|
+
'x-optech-webhook-signature': signature,
|
|
158
|
+
'x-lorikeet-signature': signature,
|
|
159
|
+
authorization: `Bearer ${this.clientId}`,
|
|
177
160
|
}
|
|
178
|
-
return { Authorization: `Bearer ${this.bearerToken}` };
|
|
179
161
|
}
|
|
180
162
|
|
|
181
|
-
protected
|
|
182
|
-
|
|
183
|
-
return {};
|
|
184
|
-
}
|
|
185
|
-
return { 'x-optech-webhook-signature': this.apiKey };
|
|
163
|
+
protected override stringifyQuery(query: Record<string, unknown>): string {
|
|
164
|
+
return qs.stringify(query, { arrayFormat: 'comma' })
|
|
186
165
|
}
|
|
187
166
|
|
|
188
|
-
static Lorikeet = this
|
|
189
|
-
static DEFAULT_TIMEOUT = 60000
|
|
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
|
|
167
|
+
static Lorikeet = this
|
|
168
|
+
static DEFAULT_TIMEOUT = 60000 // 1 minute
|
|
169
|
+
|
|
170
|
+
static LorikeetError = Errors.LorikeetError
|
|
171
|
+
static APIError = Errors.APIError
|
|
172
|
+
static APIConnectionError = Errors.APIConnectionError
|
|
173
|
+
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError
|
|
174
|
+
static APIUserAbortError = Errors.APIUserAbortError
|
|
175
|
+
static NotFoundError = Errors.NotFoundError
|
|
176
|
+
static ConflictError = Errors.ConflictError
|
|
177
|
+
static RateLimitError = Errors.RateLimitError
|
|
178
|
+
static BadRequestError = Errors.BadRequestError
|
|
179
|
+
static AuthenticationError = Errors.AuthenticationError
|
|
180
|
+
static InternalServerError = Errors.InternalServerError
|
|
181
|
+
static PermissionDeniedError = Errors.PermissionDeniedError
|
|
182
|
+
static UnprocessableEntityError = Errors.UnprocessableEntityError
|
|
183
|
+
|
|
184
|
+
static toFile = Uploads.toFile
|
|
185
|
+
static fileFromPath = Uploads.fileFromPath
|
|
207
186
|
}
|
|
208
187
|
|
|
209
188
|
export const {
|
|
@@ -220,24 +199,21 @@ export const {
|
|
|
220
199
|
InternalServerError,
|
|
221
200
|
PermissionDeniedError,
|
|
222
201
|
UnprocessableEntityError,
|
|
223
|
-
} = Errors
|
|
202
|
+
} = Errors
|
|
224
203
|
|
|
225
|
-
export import toFile = Uploads.toFile
|
|
226
|
-
export import fileFromPath = Uploads.fileFromPath
|
|
204
|
+
export import toFile = Uploads.toFile
|
|
205
|
+
export import fileFromPath = Uploads.fileFromPath
|
|
206
|
+
import { generateSignature } from './lib/generate-signature'
|
|
227
207
|
|
|
228
208
|
export namespace Lorikeet {
|
|
229
|
-
export import RequestOptions = Core.RequestOptions
|
|
230
|
-
|
|
231
|
-
export import Conversation = API.Conversation
|
|
232
|
-
|
|
233
|
-
export import
|
|
234
|
-
export import
|
|
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;
|
|
209
|
+
export import RequestOptions = Core.RequestOptions
|
|
210
|
+
|
|
211
|
+
export import Conversation = API.Conversation
|
|
212
|
+
|
|
213
|
+
export import Token = API.Token
|
|
214
|
+
export import TokenCreateParams = API.TokenCreateParams
|
|
215
|
+
|
|
216
|
+
export import Ingest = API.Ingest
|
|
241
217
|
}
|
|
242
218
|
|
|
243
|
-
export default Lorikeet
|
|
219
|
+
export default Lorikeet
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Format } from './types'
|
|
1
|
+
import type { Format } from './types'
|
|
2
2
|
|
|
3
|
-
export const default_format: Format = 'RFC3986'
|
|
3
|
+
export const default_format: Format = 'RFC3986'
|
|
4
4
|
export const formatters: Record<Format, (str: PropertyKey) => string> = {
|
|
5
5
|
RFC1738: (v: PropertyKey) => String(v).replace(/%20/g, '+'),
|
|
6
6
|
RFC3986: (v: PropertyKey) => String(v),
|
|
7
|
-
}
|
|
8
|
-
export const RFC1738 = 'RFC1738'
|
|
9
|
-
export const RFC3986 = 'RFC3986'
|
|
7
|
+
}
|
|
8
|
+
export const RFC1738 = 'RFC1738'
|
|
9
|
+
export const RFC3986 = 'RFC3986'
|
package/src/internal/qs/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { default_format, formatters, RFC1738, RFC3986 } from './formats'
|
|
1
|
+
import { default_format, formatters, RFC1738, RFC3986 } from './formats'
|
|
2
2
|
|
|
3
3
|
const formats = {
|
|
4
4
|
formatters,
|
|
5
5
|
RFC1738,
|
|
6
6
|
RFC3986,
|
|
7
7
|
default: default_format,
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
9
|
|
|
10
|
-
export { stringify } from './stringify'
|
|
11
|
-
export { formats }
|
|
10
|
+
export { stringify } from './stringify'
|
|
11
|
+
export { formats }
|
|
12
12
|
|
|
13
|
-
export type { DefaultDecoder, DefaultEncoder, Format, ParseOptions, StringifyOptions } from './types'
|
|
13
|
+
export type { DefaultDecoder, DefaultEncoder, Format, ParseOptions, StringifyOptions } from './types'
|