@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.
Files changed (217) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/README.md +35 -24
  3. package/_shims/MultipartBody.js.map +1 -1
  4. package/_shims/MultipartBody.mjs.map +1 -1
  5. package/_shims/auto/runtime-bun.d.ts.map +1 -1
  6. package/_shims/auto/runtime-bun.js.map +1 -1
  7. package/_shims/auto/runtime-node.d.ts.map +1 -1
  8. package/_shims/auto/runtime-node.js.map +1 -1
  9. package/_shims/auto/runtime.d.ts.map +1 -1
  10. package/_shims/auto/runtime.js.map +1 -1
  11. package/_shims/auto/types-node.d.ts.map +1 -1
  12. package/_shims/auto/types-node.js.map +1 -1
  13. package/_shims/auto/types.d.ts +52 -52
  14. package/_shims/bun-runtime.d.ts.map +1 -1
  15. package/_shims/bun-runtime.js +1 -2
  16. package/_shims/bun-runtime.js.map +1 -1
  17. package/_shims/bun-runtime.mjs.map +1 -1
  18. package/_shims/index.d.ts +36 -36
  19. package/_shims/index.js +5 -5
  20. package/_shims/index.mjs +4 -4
  21. package/_shims/node-runtime.d.ts.map +1 -1
  22. package/_shims/node-runtime.js +1 -2
  23. package/_shims/node-runtime.js.map +1 -1
  24. package/_shims/node-runtime.mjs.map +1 -1
  25. package/_shims/node-types.d.ts +27 -27
  26. package/_shims/registry.d.ts.map +1 -1
  27. package/_shims/registry.js +2 -2
  28. package/_shims/registry.js.map +1 -1
  29. package/_shims/registry.mjs.map +1 -1
  30. package/_shims/web-runtime.d.ts.map +1 -1
  31. package/_shims/web-runtime.js +1 -2
  32. package/_shims/web-runtime.js.map +1 -1
  33. package/_shims/web-runtime.mjs.map +1 -1
  34. package/_shims/web-types.d.ts +52 -52
  35. package/core.d.ts +2 -4
  36. package/core.d.ts.map +1 -1
  37. package/core.js +7 -6
  38. package/core.js.map +1 -1
  39. package/core.mjs +2 -1
  40. package/core.mjs.map +1 -1
  41. package/error.d.ts.map +1 -1
  42. package/error.js.map +1 -1
  43. package/error.mjs.map +1 -1
  44. package/index.d.mts +14 -20
  45. package/index.d.ts +14 -20
  46. package/index.d.ts.map +1 -1
  47. package/index.js +29 -45
  48. package/index.js.map +1 -1
  49. package/index.mjs +28 -44
  50. package/index.mjs.map +1 -1
  51. package/internal/qs/formats.d.ts.map +1 -1
  52. package/internal/qs/formats.js.map +1 -1
  53. package/internal/qs/formats.mjs.map +1 -1
  54. package/internal/qs/index.d.ts.map +1 -1
  55. package/internal/qs/index.js.map +1 -1
  56. package/internal/qs/index.mjs.map +1 -1
  57. package/internal/qs/stringify.d.ts.map +1 -1
  58. package/internal/qs/stringify.js +1 -2
  59. package/internal/qs/stringify.js.map +1 -1
  60. package/internal/qs/stringify.mjs.map +1 -1
  61. package/internal/qs/types.d.ts.map +1 -1
  62. package/internal/qs/utils.d.ts.map +1 -1
  63. package/internal/qs/utils.js +9 -9
  64. package/internal/qs/utils.js.map +1 -1
  65. package/internal/qs/utils.mjs.map +1 -1
  66. package/lib/generate-signature.d.ts +5 -0
  67. package/lib/generate-signature.d.ts.map +1 -0
  68. package/lib/generate-signature.js +19 -0
  69. package/lib/generate-signature.js.map +1 -0
  70. package/lib/generate-signature.mjs +13 -0
  71. package/lib/generate-signature.mjs.map +1 -0
  72. package/package.json +16 -14
  73. package/resource.d.ts.map +1 -1
  74. package/resource.js.map +1 -1
  75. package/resource.mjs.map +1 -1
  76. package/resources/conversation/chat.d.ts +79 -0
  77. package/resources/conversation/chat.d.ts.map +1 -0
  78. package/resources/conversation/chat.js +20 -0
  79. package/resources/conversation/chat.js.map +1 -0
  80. package/resources/conversation/chat.mjs +16 -0
  81. package/resources/conversation/chat.mjs.map +1 -0
  82. package/resources/conversation/conversation.d.ts +15 -0
  83. package/resources/conversation/conversation.d.ts.map +1 -0
  84. package/resources/{store/store.js → conversation/conversation.js} +9 -22
  85. package/resources/conversation/conversation.js.map +1 -0
  86. package/resources/conversation/conversation.mjs +13 -0
  87. package/resources/conversation/conversation.mjs.map +1 -0
  88. package/resources/conversation/index.d.ts +3 -0
  89. package/resources/conversation/index.d.ts.map +1 -0
  90. package/resources/conversation/index.js +9 -0
  91. package/resources/conversation/index.js.map +1 -0
  92. package/resources/conversation/index.mjs +4 -0
  93. package/resources/conversation/index.mjs.map +1 -0
  94. package/resources/conversation.d.ts +0 -41
  95. package/resources/conversation.d.ts.map +1 -1
  96. package/resources/conversation.js +0 -14
  97. package/resources/conversation.js.map +1 -1
  98. package/resources/conversation.mjs +0 -14
  99. package/resources/conversation.mjs.map +1 -1
  100. package/resources/index.d.ts +3 -2
  101. package/resources/index.d.ts.map +1 -1
  102. package/resources/index.js +4 -2
  103. package/resources/index.js.map +1 -1
  104. package/resources/index.mjs +3 -2
  105. package/resources/index.mjs.map +1 -1
  106. package/resources/ingest.d.ts +1 -53
  107. package/resources/ingest.d.ts.map +1 -1
  108. package/resources/ingest.js +2 -25
  109. package/resources/ingest.js.map +1 -1
  110. package/resources/ingest.mjs +2 -25
  111. package/resources/ingest.mjs.map +1 -1
  112. package/resources/token.d.ts +28 -0
  113. package/resources/token.d.ts.map +1 -0
  114. package/resources/token.js +18 -0
  115. package/resources/token.js.map +1 -0
  116. package/resources/token.mjs +14 -0
  117. package/resources/token.mjs.map +1 -0
  118. package/shims/node.d.ts +0 -4
  119. package/shims/node.d.ts.map +1 -1
  120. package/shims/node.js +0 -25
  121. package/shims/node.js.map +1 -1
  122. package/shims/node.mjs +0 -1
  123. package/shims/node.mjs.map +1 -1
  124. package/shims/web.d.ts.map +1 -1
  125. package/shims/web.js +0 -25
  126. package/shims/web.js.map +1 -1
  127. package/shims/web.mjs +0 -1
  128. package/shims/web.mjs.map +1 -1
  129. package/src/_shims/MultipartBody.ts +1 -1
  130. package/src/_shims/auto/runtime-bun.ts +1 -1
  131. package/src/_shims/auto/runtime-node.ts +1 -1
  132. package/src/_shims/auto/runtime.ts +1 -1
  133. package/src/_shims/auto/types-node.ts +1 -1
  134. package/src/_shims/auto/types.d.ts +52 -52
  135. package/src/_shims/bun-runtime.ts +6 -6
  136. package/src/_shims/index.d.ts +36 -36
  137. package/src/_shims/index.js +5 -5
  138. package/src/_shims/index.mjs +4 -4
  139. package/src/_shims/node-runtime.ts +32 -32
  140. package/src/_shims/node-types.d.ts +27 -27
  141. package/src/_shims/registry.ts +44 -44
  142. package/src/_shims/web-runtime.ts +16 -16
  143. package/src/_shims/web-types.d.ts +52 -52
  144. package/src/core.ts +373 -373
  145. package/src/error.ts +37 -37
  146. package/src/index.ts +88 -112
  147. package/src/internal/qs/formats.ts +5 -5
  148. package/src/internal/qs/index.ts +5 -5
  149. package/src/internal/qs/stringify.ts +98 -98
  150. package/src/internal/qs/types.ts +52 -52
  151. package/src/internal/qs/utils.ts +87 -87
  152. package/src/lib/generate-signature.ts +13 -0
  153. package/src/resource.ts +3 -3
  154. package/src/resources/conversation/chat.ts +102 -0
  155. package/src/resources/conversation/conversation.ts +18 -0
  156. package/src/resources/conversation/index.ts +12 -0
  157. package/src/resources/conversation.ts +2 -59
  158. package/src/resources/index.ts +3 -13
  159. package/src/resources/ingest.ts +5 -84
  160. package/src/resources/token.ts +41 -0
  161. package/src/shims/node.ts +24 -24
  162. package/src/shims/web.ts +24 -24
  163. package/src/uploads.ts +75 -74
  164. package/src/version.ts +1 -1
  165. package/uploads.d.ts +2 -2
  166. package/uploads.d.ts.map +1 -1
  167. package/uploads.js +3 -4
  168. package/uploads.js.map +1 -1
  169. package/uploads.mjs +1 -2
  170. package/uploads.mjs.map +1 -1
  171. package/version.d.ts +1 -1
  172. package/version.d.ts.map +1 -1
  173. package/version.js +1 -1
  174. package/version.js.map +1 -1
  175. package/version.mjs +1 -1
  176. package/version.mjs.map +1 -1
  177. package/resources/pets.d.ts +0 -157
  178. package/resources/pets.d.ts.map +0 -1
  179. package/resources/pets.js +0 -75
  180. package/resources/pets.js.map +0 -1
  181. package/resources/pets.mjs +0 -71
  182. package/resources/pets.mjs.map +0 -1
  183. package/resources/shared.d.ts +0 -12
  184. package/resources/shared.d.ts.map +0 -1
  185. package/resources/shared.js +0 -4
  186. package/resources/shared.js.map +0 -1
  187. package/resources/shared.mjs +0 -3
  188. package/resources/shared.mjs.map +0 -1
  189. package/resources/store/index.d.ts +0 -3
  190. package/resources/store/index.d.ts.map +0 -1
  191. package/resources/store/index.js +0 -9
  192. package/resources/store/index.js.map +0 -1
  193. package/resources/store/index.mjs +0 -4
  194. package/resources/store/index.mjs.map +0 -1
  195. package/resources/store/order.d.ts +0 -16
  196. package/resources/store/order.d.ts.map +0 -1
  197. package/resources/store/order.js +0 -26
  198. package/resources/store/order.js.map +0 -1
  199. package/resources/store/order.mjs +0 -22
  200. package/resources/store/order.mjs.map +0 -1
  201. package/resources/store/store.d.ts +0 -35
  202. package/resources/store/store.d.ts.map +0 -1
  203. package/resources/store/store.js.map +0 -1
  204. package/resources/store/store.mjs +0 -26
  205. package/resources/store/store.mjs.map +0 -1
  206. package/resources/user.d.ts +0 -96
  207. package/resources/user.d.ts.map +0 -1
  208. package/resources/user.js +0 -65
  209. package/resources/user.js.map +0 -1
  210. package/resources/user.mjs +0 -61
  211. package/resources/user.mjs.map +0 -1
  212. package/src/resources/pets.ts +0 -276
  213. package/src/resources/shared.ts +0 -18
  214. package/src/resources/store/index.ts +0 -4
  215. package/src/resources/store/order.ts +0 -26
  216. package/src/resources/store/store.ts +0 -59
  217. 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 Core from './core';
7
- import * as API from './resources/index';
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
- * The client ID associated with your account.
12
+ * client identifier authentication associated with the account.
12
13
  */
13
- bearerToken?: string | null | undefined;
14
+ clientId?: string | undefined
14
15
 
15
16
  /**
16
- * The signature of the webhook - should be generated as a SHA256 hash of the payload and the secret key.
17
+ * Secret key pulled from the Lorikeet App
17
18
  */
18
- apiKey?: string | null | undefined;
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
- bearerToken: string | null;
82
- apiKey: string | null;
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 | 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.
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
- bearerToken = Core.readEnv('LORIKEET_CLIENT_ID') ?? null,
102
- apiKey = null,
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
- bearerToken,
107
- apiKey,
118
+ clientId,
119
+ clientSecret,
108
120
  ...opts,
109
- baseURL: baseURL || `http://api.lorikeetcx.ai`,
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.bearerToken = bearerToken;
123
- this.apiKey = apiKey;
134
+ this.clientId = clientId
135
+ this.clientSecret = clientSecret
124
136
  }
125
137
 
126
- conversation: API.Conversation = new API.Conversation(this);
127
- ingest: API.Ingest = new API.Ingest(this);
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 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 {};
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 apiKeyAuth(opts: Core.FinalRequestOptions): Core.Headers {
182
- if (this.apiKey == null) {
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; // 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;
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
- 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;
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'
@@ -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'