diff --git a/.stats.yml b/.stats.yml index f37c12c..b37ef5d 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 39 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/plastic-labs%2Fhoncho-d259b106accde65e100275c3eee2d01d0b91792abc0e67ae807dae74fb32f4de.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/plastic-labs%2Fhoncho-3b94ec668fd95755a2447237b113b61d5c82e62960832d065e8a6f06a1916286.yml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e508f2b..bea6750 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,9 +5,9 @@ Other package managers may work but are not officially supported for development To set up the repository, run: -```bash -yarn -yarn build +```sh +$ yarn +$ yarn build ``` This will install all the required dependencies and build output files to `dist/`. @@ -22,7 +22,7 @@ modify the contents of the `src/lib/` and `examples/` directories. All files in the `examples/` directory are not modified by the generator and can be freely edited or added to. -```bash +```ts // add an example to examples/.ts #!/usr/bin/env -S npm run tsn -T @@ -41,38 +41,38 @@ If you’d like to use the repository from source, you can either install from g To install via git: -```bash -npm install git+ssh://git@github.com:plastic-labs/honcho-node.git +```sh +$ npm install git+ssh://git@github.com:plastic-labs/honcho-node.git ``` Alternatively, to link a local copy of the repo: -```bash +```sh # Clone -git clone https://www.github.com/plastic-labs/honcho-node -cd honcho-node +$ git clone https://www.github.com/plastic-labs/honcho-node +$ cd honcho-node # With yarn -yarn link -cd ../my-package -yarn link honcho +$ yarn link +$ cd ../my-package +$ yarn link honcho # With pnpm -pnpm link --global -cd ../my-package -pnpm link -—global honcho +$ pnpm link --global +$ cd ../my-package +$ pnpm link -—global honcho ``` ## Running tests Most tests require you to [set up a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests. -```bash -npx prism mock path/to/your/openapi.yml +```sh +$ npx prism mock path/to/your/openapi.yml ``` -```bash -yarn run test +```sh +$ yarn run test ``` ## Linting and formatting @@ -82,14 +82,14 @@ This repository uses [prettier](https://www.npmjs.com/package/prettier) and To lint: -```bash -yarn lint +```sh +$ yarn lint ``` To format and fix all lint issues automatically: -```bash -yarn fix +```sh +$ yarn fix ``` ## Publishing and releases diff --git a/README.md b/README.md index 96b9490..ec444ca 100644 --- a/README.md +++ b/README.md @@ -137,37 +137,6 @@ On timeout, an `APIConnectionTimeoutError` is thrown. Note that requests which time out will be [retried twice by default](#retries). -## Auto-pagination - -List methods in the Honcho API are paginated. -You can use `for await … of` syntax to iterate through items across all pages: - -```ts -async function fetchAllAppsUsers(params) { - const allAppsUsers = []; - // Automatically fetches more pages as needed. - for await (const user of client.apps.users.list('REPLACE_ME')) { - allAppsUsers.push(user); - } - return allAppsUsers; -} -``` - -Alternatively, you can make request a single page at a time: - -```ts -let page = await client.apps.users.list('REPLACE_ME'); -for (const user of page.items) { - console.log(user); -} - -// Convenience methods are provided for manually paginating: -while (page.hasNextPage()) { - page = page.getNextPage(); - // ... -} -``` - ## Advanced Usage ### Accessing raw Response data (e.g., headers) @@ -319,3 +288,7 @@ The following runtimes are supported: Note that React Native is not supported at this time. If you are interested in other runtime environments, please open or upvote an issue on GitHub. + +## Contributing + +See [the contributing documentation](./CONTRIBUTING.md). diff --git a/api.md b/api.md index 34d4c5d..94d7ada 100644 --- a/api.md +++ b/api.md @@ -6,11 +6,11 @@ Types: Methods: -- client.apps.create({ ...params }) -> App -- client.apps.update(appId, { ...params }) -> App -- client.apps.get(appId) -> App -- client.apps.getByName(name) -> App -- client.apps.getOrCreate(name) -> App +- client.apps.create({ ...params }) -> App +- client.apps.update(appId, { ...params }) -> App +- client.apps.get(appId) -> App +- client.apps.getByName(name) -> App +- client.apps.getOrCreate(name) -> App ## Users @@ -21,18 +21,18 @@ Types: Methods: -- client.apps.users.create(appId, { ...params }) -> User -- client.apps.users.update(appId, userId, { ...params }) -> User -- client.apps.users.list(appId, { ...params }) -> UsersPage -- client.apps.users.get(appId, userId) -> User -- client.apps.users.getByName(appId, name) -> User -- client.apps.users.getOrCreate(appId, name) -> User +- client.apps.users.create(appId, { ...params }) -> User +- client.apps.users.update(appId, userId, { ...params }) -> User +- client.apps.users.list(appId, { ...params }) -> UsersPage +- client.apps.users.get(appId, userId) -> User +- client.apps.users.getByName(appId, name) -> User +- client.apps.users.getOrCreate(appId, name) -> User ### Metamessages Methods: -- client.apps.users.metamessages.list(appId, userId, { ...params }) -> MetamessagesPage +- client.apps.users.metamessages.list(appId, userId, { ...params }) -> MetamessagesPage ### Sessions @@ -46,13 +46,13 @@ Types: Methods: -- client.apps.users.sessions.create(appId, userId, { ...params }) -> Session -- client.apps.users.sessions.update(appId, userId, sessionId, { ...params }) -> Session -- client.apps.users.sessions.list(appId, userId, { ...params }) -> SessionsPage -- client.apps.users.sessions.delete(appId, userId, sessionId) -> unknown -- client.apps.users.sessions.chat(appId, userId, sessionId, { ...params }) -> AgentChat -- client.apps.users.sessions.get(appId, userId, sessionId) -> Session -- client.apps.users.sessions.stream(appId, userId, sessionId, { ...params }) -> unknown +- client.apps.users.sessions.create(appId, userId, { ...params }) -> Session +- client.apps.users.sessions.update(appId, userId, sessionId, { ...params }) -> Session +- client.apps.users.sessions.list(appId, userId, { ...params }) -> SessionsPage +- client.apps.users.sessions.delete(appId, userId, sessionId) -> unknown +- client.apps.users.sessions.chat(appId, userId, sessionId, { ...params }) -> AgentChat +- client.apps.users.sessions.get(appId, userId, sessionId) -> Session +- client.apps.users.sessions.stream(appId, userId, sessionId, { ...params }) -> unknown #### Messages @@ -63,10 +63,10 @@ Types: Methods: -- client.apps.users.sessions.messages.create(appId, userId, sessionId, { ...params }) -> Message -- client.apps.users.sessions.messages.update(appId, userId, sessionId, messageId, { ...params }) -> Message -- client.apps.users.sessions.messages.list(appId, userId, sessionId, { ...params }) -> MessagesPage -- client.apps.users.sessions.messages.get(appId, userId, sessionId, messageId) -> Message +- client.apps.users.sessions.messages.create(appId, userId, sessionId, { ...params }) -> Message +- client.apps.users.sessions.messages.update(appId, userId, sessionId, messageId, { ...params }) -> Message +- client.apps.users.sessions.messages.list(appId, userId, sessionId, { ...params }) -> MessagesPage +- client.apps.users.sessions.messages.get(appId, userId, sessionId, messageId) -> Message #### Metamessages @@ -77,10 +77,10 @@ Types: Methods: -- client.apps.users.sessions.metamessages.create(appId, userId, sessionId, { ...params }) -> Metamessage -- client.apps.users.sessions.metamessages.update(appId, userId, sessionId, metamessageId, { ...params }) -> Metamessage -- client.apps.users.sessions.metamessages.list(appId, userId, sessionId, { ...params }) -> MetamessagesPage -- client.apps.users.sessions.metamessages.get(appId, userId, sessionId, metamessageId, { ...params }) -> Metamessage +- client.apps.users.sessions.metamessages.create(appId, userId, sessionId, { ...params }) -> Metamessage +- client.apps.users.sessions.metamessages.update(appId, userId, sessionId, metamessageId, { ...params }) -> Metamessage +- client.apps.users.sessions.metamessages.list(appId, userId, sessionId, { ...params }) -> MetamessagesPage +- client.apps.users.sessions.metamessages.get(appId, userId, sessionId, metamessageId, { ...params }) -> Metamessage ### Collections @@ -92,12 +92,12 @@ Types: Methods: -- client.apps.users.collections.create(appId, userId, { ...params }) -> Collection -- client.apps.users.collections.update(appId, userId, collectionId, { ...params }) -> Collection -- client.apps.users.collections.list(appId, userId, { ...params }) -> CollectionsPage -- client.apps.users.collections.delete(appId, userId, collectionId) -> unknown -- client.apps.users.collections.get(appId, userId, collectionId) -> Collection -- client.apps.users.collections.getByName(appId, userId, name) -> Collection +- client.apps.users.collections.create(appId, userId, { ...params }) -> Collection +- client.apps.users.collections.update(appId, userId, collectionId, { ...params }) -> Collection +- client.apps.users.collections.list(appId, userId, { ...params }) -> CollectionsPage +- client.apps.users.collections.delete(appId, userId, collectionId) -> unknown +- client.apps.users.collections.get(appId, userId, collectionId) -> Collection +- client.apps.users.collections.getByName(appId, userId, name) -> Collection #### Documents @@ -110,9 +110,9 @@ Types: Methods: -- client.apps.users.collections.documents.create(appId, userId, collectionId, { ...params }) -> Document -- client.apps.users.collections.documents.update(appId, userId, collectionId, documentId, { ...params }) -> Document -- client.apps.users.collections.documents.list(appId, userId, collectionId, { ...params }) -> DocumentsPage -- client.apps.users.collections.documents.delete(appId, userId, collectionId, documentId) -> unknown -- client.apps.users.collections.documents.get(appId, userId, collectionId, documentId) -> Document -- client.apps.users.collections.documents.query(appId, userId, collectionId, { ...params }) -> DocumentQueryResponse +- client.apps.users.collections.documents.create(appId, userId, collectionId, { ...params }) -> Document +- client.apps.users.collections.documents.update(appId, userId, collectionId, documentId, { ...params }) -> Document +- client.apps.users.collections.documents.list(appId, userId, collectionId, { ...params }) -> DocumentsPage +- client.apps.users.collections.documents.delete(appId, userId, collectionId, documentId) -> unknown +- client.apps.users.collections.documents.get(appId, userId, collectionId, documentId) -> Document +- client.apps.users.collections.documents.query(appId, userId, collectionId, { ...params }) -> DocumentQueryResponse diff --git a/package.json b/package.json index 557b1bb..c313376 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "eslint": "^8.49.0", "eslint-plugin-prettier": "^5.0.1", "eslint-plugin-unused-imports": "^3.0.0", + "iconv-lite": "^0.6.3", "jest": "^29.4.0", "prettier": "^3.0.0", "ts-jest": "^29.1.0", diff --git a/src/_shims/node-types.d.ts b/src/_shims/node-types.d.ts index b31698f..c159e5f 100644 --- a/src/_shims/node-types.d.ts +++ b/src/_shims/node-types.d.ts @@ -7,7 +7,7 @@ import * as fd from 'formdata-node'; export { type Agent } from 'node:http'; export { type Readable } from 'node:stream'; export { type ReadStream as FsReadStream } from 'node:fs'; -export { ReadableStream } from 'web-streams-polyfill'; +export { ReadableStream } from 'node:stream/web'; export const fetch: typeof nf.default; diff --git a/src/core.ts b/src/core.ts index 2389e75..4215121 100644 --- a/src/core.ts +++ b/src/core.ts @@ -84,8 +84,10 @@ export class APIPromise extends Promise { }); } - _thenUnwrap(transform: (data: T) => U): APIPromise { - return new APIPromise(this.responsePromise, async (props) => transform(await this.parseResponse(props))); + _thenUnwrap(transform: (data: T, props: APIResponseProps) => U): APIPromise { + return new APIPromise(this.responsePromise, async (props) => + transform(await this.parseResponse(props), props), + ); } /** @@ -274,7 +276,10 @@ export abstract class APIClient { return null; } - buildRequest(options: FinalRequestOptions): { req: RequestInit; url: string; timeout: number } { + buildRequest( + options: FinalRequestOptions, + { retryCount = 0 }: { retryCount?: number } = {}, + ): { req: RequestInit; url: string; timeout: number } { const { method, path, query, headers: headers = {} } = options; const body = @@ -306,7 +311,7 @@ export abstract class APIClient { headers[this.idempotencyHeader] = options.idempotencyKey; } - const reqHeaders = this.buildHeaders({ options, headers, contentLength }); + const reqHeaders = this.buildHeaders({ options, headers, contentLength, retryCount }); const req: RequestInit = { method, @@ -325,10 +330,12 @@ export abstract class APIClient { options, headers, contentLength, + retryCount, }: { options: FinalRequestOptions; headers: Record; contentLength: string | null | undefined; + retryCount: number; }): Record { const reqHeaders: Record = {}; if (contentLength) { @@ -344,6 +351,16 @@ export abstract class APIClient { delete reqHeaders['content-type']; } + // Don't set the retry count header if it was already set or removed through default headers or by the + // caller. We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to + // account for the removal case. + if ( + getHeader(defaultHeaders, 'x-stainless-retry-count') === undefined && + getHeader(headers, 'x-stainless-retry-count') === undefined + ) { + reqHeaders['x-stainless-retry-count'] = String(retryCount); + } + this.validateHeaders(reqHeaders, headers); return reqHeaders; @@ -395,13 +412,14 @@ export abstract class APIClient { retriesRemaining: number | null, ): Promise { const options = await optionsInput; + const maxRetries = options.maxRetries ?? this.maxRetries; if (retriesRemaining == null) { - retriesRemaining = options.maxRetries ?? this.maxRetries; + retriesRemaining = maxRetries; } await this.prepareOptions(options); - const { req, url, timeout } = this.buildRequest(options); + const { req, url, timeout } = this.buildRequest(options, { retryCount: maxRetries - retriesRemaining }); await this.prepareRequest(req, { url, options }); @@ -1120,7 +1138,15 @@ export const isHeadersProtocol = (headers: any): headers is HeadersProtocol => { return typeof headers?.get === 'function'; }; -export const getRequiredHeader = (headers: HeadersLike, header: string): string => { +export const getRequiredHeader = (headers: HeadersLike | Headers, header: string): string => { + const foundHeader = getHeader(headers, header); + if (foundHeader === undefined) { + throw new Error(`Could not find ${header} header`); + } + return foundHeader; +}; + +export const getHeader = (headers: HeadersLike | Headers, header: string): string | undefined => { const lowerCasedHeader = header.toLowerCase(); if (isHeadersProtocol(headers)) { // to deal with the case where the header looks like Stainless-Event-Id @@ -1146,7 +1172,7 @@ export const getRequiredHeader = (headers: HeadersLike, header: string): string } } - throw new Error(`Could not find ${header} header`); + return undefined; }; /** diff --git a/src/resources/apps/apps.ts b/src/resources/apps/apps.ts index 4a2e929..9b3ab8a 100644 --- a/src/resources/apps/apps.ts +++ b/src/resources/apps/apps.ts @@ -16,30 +16,30 @@ export class Apps extends APIResource { * Returns: schemas.App: Created App object */ create(body: AppCreateParams, options?: Core.RequestOptions): Core.APIPromise { - return this._client.post('/apps', { body, ...options }); + return this._client.post('/v1/apps', { body, ...options }); } /** * Update an App * - * Args: app_id (uuid.UUID): The ID of the app to update app (schemas.AppUpdate): - * The App object containing any new metadata + * Args: app_id (str): The ID of the app to update app (schemas.AppUpdate): The App + * object containing any new metadata * * Returns: schemas.App: The App object of the updated App */ update(appId: string, body: AppUpdateParams, options?: Core.RequestOptions): Core.APIPromise { - return this._client.put(`/apps/${appId}`, { body, ...options }); + return this._client.put(`/v1/apps/${appId}`, { body, ...options }); } /** * Get an App by ID * - * Args: app_id (uuid.UUID): The ID of the app + * Args: app_id (str): The ID of the app * * Returns: schemas.App: App object */ get(appId: string, options?: Core.RequestOptions): Core.APIPromise { - return this._client.get(`/apps/${appId}`, options); + return this._client.get(`/v1/apps/${appId}`, options); } /** @@ -50,7 +50,7 @@ export class Apps extends APIResource { * Returns: schemas.App: App object */ getByName(name: string, options?: Core.RequestOptions): Core.APIPromise { - return this._client.get(`/apps/name/${name}`, options); + return this._client.get(`/v1/apps/name/${name}`, options); } /** @@ -61,7 +61,7 @@ export class Apps extends APIResource { * Returns: schemas.App: App object */ getOrCreate(name: string, options?: Core.RequestOptions): Core.APIPromise { - return this._client.get(`/apps/get_or_create/${name}`, options); + return this._client.get(`/v1/apps/get_or_create/${name}`, options); } } @@ -78,7 +78,7 @@ export interface App { export interface AppCreateParams { name: string; - metadata?: Record | null; + metadata?: Record; } export interface AppUpdateParams { diff --git a/src/resources/apps/users/collections/collections.ts b/src/resources/apps/users/collections/collections.ts index 4d44468..1b9f629 100644 --- a/src/resources/apps/users/collections/collections.ts +++ b/src/resources/apps/users/collections/collections.ts @@ -1,7 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../../../resource'; -import { isRequestOptions } from '../../../../core'; import * as Core from '../../../../core'; import * as CollectionsAPI from './collections'; import * as DocumentsAPI from './documents'; @@ -19,7 +18,7 @@ export class Collections extends APIResource { body: CollectionCreateParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this._client.post(`/apps/${appId}/users/${userId}/collections`, { body, ...options }); + return this._client.post(`/v1/apps/${appId}/users/${userId}/collections`, { body, ...options }); } /** @@ -32,7 +31,7 @@ export class Collections extends APIResource { body: CollectionUpdateParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this._client.put(`/apps/${appId}/users/${userId}/collections/${collectionId}`, { + return this._client.put(`/v1/apps/${appId}/users/${userId}/collections/${collectionId}`, { body, ...options, }); @@ -41,34 +40,22 @@ export class Collections extends APIResource { /** * Get All Collections for a User * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user_id (uuid.UUID): The User ID representing the user, managed by - * the user + * Args: app_id (str): The ID of the app representing the client application using + * honcho user_id (str): The User ID representing the user, managed by the user * * Returns: list[schemas.Collection]: List of Collection objects */ list( appId: string, userId: string, - query?: CollectionListParams, - options?: Core.RequestOptions, - ): Core.PagePromise; - list( - appId: string, - userId: string, - options?: Core.RequestOptions, - ): Core.PagePromise; - list( - appId: string, - userId: string, - query: CollectionListParams | Core.RequestOptions = {}, + params: CollectionListParams, options?: Core.RequestOptions, ): Core.PagePromise { - if (isRequestOptions(query)) { - return this.list(appId, userId, {}, query); - } - return this._client.getAPIList(`/apps/${appId}/users/${userId}/collections`, CollectionsPage, { - query, + const { page, reverse, size, ...body } = params; + return this._client.getAPIList(`/v1/apps/${appId}/users/${userId}/collections/list`, CollectionsPage, { + query: { page, reverse, size }, + body, + method: 'post', ...options, }); } @@ -82,7 +69,7 @@ export class Collections extends APIResource { collectionId: string, options?: Core.RequestOptions, ): Core.APIPromise { - return this._client.delete(`/apps/${appId}/users/${userId}/collections/${collectionId}`, options); + return this._client.delete(`/v1/apps/${appId}/users/${userId}/collections/${collectionId}`, options); } /** @@ -94,7 +81,7 @@ export class Collections extends APIResource { collectionId: string, options?: Core.RequestOptions, ): Core.APIPromise { - return this._client.get(`/apps/${appId}/users/${userId}/collections/${collectionId}`, options); + return this._client.get(`/v1/apps/${appId}/users/${userId}/collections/${collectionId}`, options); } /** @@ -106,7 +93,7 @@ export class Collections extends APIResource { name: string, options?: Core.RequestOptions, ): Core.APIPromise { - return this._client.get(`/apps/${appId}/users/${userId}/collections/name/${name}`, options); + return this._client.get(`/v1/apps/${appId}/users/${userId}/collections/name/${name}`, options); } } @@ -151,9 +138,15 @@ export interface CollectionUpdateParams { } export interface CollectionListParams extends PageParams { - filter?: string | null; - + /** + * Query param: + */ reverse?: boolean | null; + + /** + * Body param: + */ + filter?: Record | null; } export namespace Collections { diff --git a/src/resources/apps/users/collections/documents.ts b/src/resources/apps/users/collections/documents.ts index 50bb5e3..c1d7229 100644 --- a/src/resources/apps/users/collections/documents.ts +++ b/src/resources/apps/users/collections/documents.ts @@ -1,7 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../../../resource'; -import { isRequestOptions } from '../../../../core'; import * as Core from '../../../../core'; import * as DocumentsAPI from './documents'; import { Page, type PageParams } from '../../../../pagination'; @@ -17,7 +16,7 @@ export class Documents extends APIResource { body: DocumentCreateParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this._client.post(`/apps/${appId}/users/${userId}/collections/${collectionId}/documents`, { + return this._client.post(`/v1/apps/${appId}/users/${userId}/collections/${collectionId}/documents`, { body, ...options, }); @@ -35,7 +34,7 @@ export class Documents extends APIResource { options?: Core.RequestOptions, ): Core.APIPromise { return this._client.put( - `/apps/${appId}/users/${userId}/collections/${collectionId}/documents/${documentId}`, + `/v1/apps/${appId}/users/${userId}/collections/${collectionId}/documents/${documentId}`, { body, ...options }, ); } @@ -47,29 +46,14 @@ export class Documents extends APIResource { appId: string, userId: string, collectionId: string, - query?: DocumentListParams, - options?: Core.RequestOptions, - ): Core.PagePromise; - list( - appId: string, - userId: string, - collectionId: string, - options?: Core.RequestOptions, - ): Core.PagePromise; - list( - appId: string, - userId: string, - collectionId: string, - query: DocumentListParams | Core.RequestOptions = {}, + params: DocumentListParams, options?: Core.RequestOptions, ): Core.PagePromise { - if (isRequestOptions(query)) { - return this.list(appId, userId, collectionId, {}, query); - } + const { page, reverse, size, ...body } = params; return this._client.getAPIList( - `/apps/${appId}/users/${userId}/collections/${collectionId}/documents`, + `/v1/apps/${appId}/users/${userId}/collections/${collectionId}/documents/list`, DocumentsPage, - { query, ...options }, + { query: { page, reverse, size }, body, method: 'post', ...options }, ); } @@ -84,7 +68,7 @@ export class Documents extends APIResource { options?: Core.RequestOptions, ): Core.APIPromise { return this._client.delete( - `/apps/${appId}/users/${userId}/collections/${collectionId}/documents/${documentId}`, + `/v1/apps/${appId}/users/${userId}/collections/${collectionId}/documents/${documentId}`, options, ); } @@ -100,7 +84,7 @@ export class Documents extends APIResource { options?: Core.RequestOptions, ): Core.APIPromise { return this._client.get( - `/apps/${appId}/users/${userId}/collections/${collectionId}/documents/${documentId}`, + `/v1/apps/${appId}/users/${userId}/collections/${collectionId}/documents/${documentId}`, options, ); } @@ -115,7 +99,7 @@ export class Documents extends APIResource { query: DocumentQueryParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this._client.get(`/apps/${appId}/users/${userId}/collections/${collectionId}/documents/query`, { + return this._client.get(`/v1/apps/${appId}/users/${userId}/collections/${collectionId}/documents/query`, { query, ...options, }); @@ -165,9 +149,15 @@ export interface DocumentUpdateParams { } export interface DocumentListParams extends PageParams { - filter?: string | null; - + /** + * Query param: + */ reverse?: boolean | null; + + /** + * Body param: + */ + filter?: Record | null; } export interface DocumentQueryParams { diff --git a/src/resources/apps/users/metamessages.ts b/src/resources/apps/users/metamessages.ts index b999ccb..87d004f 100644 --- a/src/resources/apps/users/metamessages.ts +++ b/src/resources/apps/users/metamessages.ts @@ -1,7 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../../resource'; -import { isRequestOptions } from '../../../core'; import * as Core from '../../../core'; import * as MetamessagesAPI from './metamessages'; import * as SessionsMetamessagesAPI from './sessions/metamessages'; @@ -12,9 +11,9 @@ export class Metamessages extends APIResource { /** * Paginate through the user metamessages for a user * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user_id (str): The User ID representing the user, managed by the - * user reverse (bool): Whether to reverse the order of the metamessages + * Args: app_id (str): The ID of the app representing the client application using + * honcho user_id (str): The User ID representing the user, managed by the user + * reverse (bool): Whether to reverse the order of the metamessages * * Returns: list[schemas.Message]: List of Message objects * @@ -23,36 +22,34 @@ export class Metamessages extends APIResource { list( appId: string, userId: string, - query?: MetamessageListParams, - options?: Core.RequestOptions, - ): Core.PagePromise; - list( - appId: string, - userId: string, - options?: Core.RequestOptions, - ): Core.PagePromise; - list( - appId: string, - userId: string, - query: MetamessageListParams | Core.RequestOptions = {}, + params: MetamessageListParams, options?: Core.RequestOptions, ): Core.PagePromise { - if (isRequestOptions(query)) { - return this.list(appId, userId, {}, query); - } - return this._client.getAPIList(`/apps/${appId}/users/${userId}/metamessages`, MetamessagesPage, { - query, + const { page, reverse, size, ...body } = params; + return this._client.getAPIList(`/v1/apps/${appId}/users/${userId}/metamessages/list`, MetamessagesPage, { + query: { page, reverse, size }, + body, + method: 'post', ...options, }); } } export interface MetamessageListParams extends PageParams { - filter?: string | null; + /** + * Query param: + */ + reverse?: boolean | null; - metamessage_type?: string | null; + /** + * Body param: + */ + filter?: Record | null; - reverse?: boolean | null; + /** + * Body param: + */ + metamessage_type?: string | null; } export namespace Metamessages { diff --git a/src/resources/apps/users/sessions/messages.ts b/src/resources/apps/users/sessions/messages.ts index 8387161..0547481 100644 --- a/src/resources/apps/users/sessions/messages.ts +++ b/src/resources/apps/users/sessions/messages.ts @@ -1,7 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../../../resource'; -import { isRequestOptions } from '../../../../core'; import * as Core from '../../../../core'; import * as MessagesAPI from './messages'; import { Page, type PageParams } from '../../../../pagination'; @@ -10,9 +9,9 @@ export class Messages extends APIResource { /** * Adds a message to a session * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user_id (str): The User ID representing the user, managed by the - * user session_id (int): The ID of the Session to add the message to message + * Args: app_id (str): The ID of the app representing the client application using + * honcho user_id (str): The User ID representing the user, managed by the user + * session_id (int): The ID of the Session to add the message to message * (schemas.MessageCreate): The Message object to add containing the message * content and type * @@ -27,7 +26,7 @@ export class Messages extends APIResource { body: MessageCreateParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this._client.post(`/apps/${appId}/users/${userId}/sessions/${sessionId}/messages`, { + return this._client.post(`/v1/apps/${appId}/users/${userId}/sessions/${sessionId}/messages`, { body, ...options, }); @@ -44,7 +43,7 @@ export class Messages extends APIResource { body: MessageUpdateParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this._client.put(`/apps/${appId}/users/${userId}/sessions/${sessionId}/messages/${messageId}`, { + return this._client.put(`/v1/apps/${appId}/users/${userId}/sessions/${sessionId}/messages/${messageId}`, { body, ...options, }); @@ -53,10 +52,10 @@ export class Messages extends APIResource { /** * Get all messages for a session * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user_id (str): The User ID representing the user, managed by the - * user session_id (int): The ID of the Session to retrieve reverse (bool): Whether - * to reverse the order of the messages + * Args: app_id (str): The ID of the app representing the client application using + * honcho user_id (str): The User ID representing the user, managed by the user + * session_id (int): The ID of the Session to retrieve reverse (bool): Whether to + * reverse the order of the messages * * Returns: list[schemas.Message]: List of Message objects * @@ -66,29 +65,14 @@ export class Messages extends APIResource { appId: string, userId: string, sessionId: string, - query?: MessageListParams, - options?: Core.RequestOptions, - ): Core.PagePromise; - list( - appId: string, - userId: string, - sessionId: string, - options?: Core.RequestOptions, - ): Core.PagePromise; - list( - appId: string, - userId: string, - sessionId: string, - query: MessageListParams | Core.RequestOptions = {}, + params: MessageListParams, options?: Core.RequestOptions, ): Core.PagePromise { - if (isRequestOptions(query)) { - return this.list(appId, userId, sessionId, {}, query); - } + const { page, reverse, size, ...body } = params; return this._client.getAPIList( - `/apps/${appId}/users/${userId}/sessions/${sessionId}/messages`, + `/v1/apps/${appId}/users/${userId}/sessions/${sessionId}/messages/list`, MessagesPage, - { query, ...options }, + { query: { page, reverse, size }, body, method: 'post', ...options }, ); } @@ -103,7 +87,7 @@ export class Messages extends APIResource { options?: Core.RequestOptions, ): Core.APIPromise { return this._client.get( - `/apps/${appId}/users/${userId}/sessions/${sessionId}/messages/${messageId}`, + `/v1/apps/${appId}/users/${userId}/sessions/${sessionId}/messages/${messageId}`, options, ); } @@ -142,7 +126,7 @@ export interface MessageCreateParams { is_user: boolean; - metadata?: Record | null; + metadata?: Record; } export interface MessageUpdateParams { @@ -150,9 +134,15 @@ export interface MessageUpdateParams { } export interface MessageListParams extends PageParams { - filter?: string | null; - + /** + * Query param: + */ reverse?: boolean | null; + + /** + * Body param: + */ + filter?: Record | null; } export namespace Messages { diff --git a/src/resources/apps/users/sessions/metamessages.ts b/src/resources/apps/users/sessions/metamessages.ts index bc9fdbf..92f9e38 100644 --- a/src/resources/apps/users/sessions/metamessages.ts +++ b/src/resources/apps/users/sessions/metamessages.ts @@ -1,7 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../../../resource'; -import { isRequestOptions } from '../../../../core'; import * as Core from '../../../../core'; import * as MetamessagesAPI from './metamessages'; import { Page, type PageParams } from '../../../../pagination'; @@ -10,9 +9,9 @@ export class Metamessages extends APIResource { /** * Adds a message to a session * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user_id (str): The User ID representing the user, managed by the - * user session_id (int): The ID of the Session to add the message to metamessage + * Args: app_id (str): The ID of the app representing the client application using + * honcho user_id (str): The User ID representing the user, managed by the user + * session_id (int): The ID of the Session to add the message to metamessage * (schemas.MeteamessageCreate): The metamessage creation object * * Returns: schemas.Metamessage: The Metamessage object of the added metamessage @@ -26,7 +25,7 @@ export class Metamessages extends APIResource { body: MetamessageCreateParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this._client.post(`/apps/${appId}/users/${userId}/sessions/${sessionId}/metamessages`, { + return this._client.post(`/v1/apps/${appId}/users/${userId}/sessions/${sessionId}/metamessages`, { body, ...options, }); @@ -44,7 +43,7 @@ export class Metamessages extends APIResource { options?: Core.RequestOptions, ): Core.APIPromise { return this._client.put( - `/apps/${appId}/users/${userId}/sessions/${sessionId}/metamessages/${metamessageId}`, + `/v1/apps/${appId}/users/${userId}/sessions/${sessionId}/metamessages/${metamessageId}`, { body, ...options }, ); } @@ -52,10 +51,10 @@ export class Metamessages extends APIResource { /** * Get all messages for a session * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user_id (str): The User ID representing the user, managed by the - * user session_id (int): The ID of the Session to retrieve reverse (bool): Whether - * to reverse the order of the metamessages + * Args: app_id (str): The ID of the app representing the client application using + * honcho user_id (str): The User ID representing the user, managed by the user + * session_id (int): The ID of the Session to retrieve reverse (bool): Whether to + * reverse the order of the metamessages * * Returns: list[schemas.Message]: List of Message objects * @@ -65,38 +64,23 @@ export class Metamessages extends APIResource { appId: string, userId: string, sessionId: string, - query?: MetamessageListParams, - options?: Core.RequestOptions, - ): Core.PagePromise; - list( - appId: string, - userId: string, - sessionId: string, - options?: Core.RequestOptions, - ): Core.PagePromise; - list( - appId: string, - userId: string, - sessionId: string, - query: MetamessageListParams | Core.RequestOptions = {}, + params: MetamessageListParams, options?: Core.RequestOptions, ): Core.PagePromise { - if (isRequestOptions(query)) { - return this.list(appId, userId, sessionId, {}, query); - } + const { page, reverse, size, ...body } = params; return this._client.getAPIList( - `/apps/${appId}/users/${userId}/sessions/${sessionId}/metamessages`, + `/v1/apps/${appId}/users/${userId}/sessions/${sessionId}/metamessages/list`, MetamessagesPage, - { query, ...options }, + { query: { page, reverse, size }, body, method: 'post', ...options }, ); } /** * Get a specific Metamessage by ID * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user_id (str): The User ID representing the user, managed by the - * user session_id (int): The ID of the Session to retrieve + * Args: app_id (str): The ID of the app representing the client application using + * honcho user_id (str): The User ID representing the user, managed by the user + * session_id (int): The ID of the Session to retrieve * * Returns: schemas.Session: The Session object of the requested Session * @@ -111,7 +95,7 @@ export class Metamessages extends APIResource { options?: Core.RequestOptions, ): Core.APIPromise { return this._client.get( - `/apps/${appId}/users/${userId}/sessions/${sessionId}/metamessages/${metamessageId}`, + `/v1/apps/${appId}/users/${userId}/sessions/${sessionId}/metamessages/${metamessageId}`, { query, ...options }, ); } @@ -164,13 +148,25 @@ export interface MetamessageUpdateParams { } export interface MetamessageListParams extends PageParams { - filter?: string | null; + /** + * Query param: + */ + reverse?: boolean | null; + + /** + * Body param: + */ + filter?: Record | null; + /** + * Body param: + */ message_id?: string | null; + /** + * Body param: + */ metamessage_type?: string | null; - - reverse?: boolean | null; } export interface MetamessageGetParams { diff --git a/src/resources/apps/users/sessions/sessions.ts b/src/resources/apps/users/sessions/sessions.ts index 67da642..10df414 100644 --- a/src/resources/apps/users/sessions/sessions.ts +++ b/src/resources/apps/users/sessions/sessions.ts @@ -1,7 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../../../resource'; -import { isRequestOptions } from '../../../../core'; import * as Core from '../../../../core'; import * as SessionsAPI from './sessions'; import * as MessagesAPI from './messages'; @@ -15,10 +14,9 @@ export class Sessions extends APIResource { /** * Create a Session for a User * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user_id (uuid.UUID): The User ID representing the user, managed by - * the user session (schemas.SessionCreate): The Session object containing any - * metadata + * Args: app_id (str): The ID of the app representing the client application using + * honcho user_id (str): The User ID representing the user, managed by the user + * session (schemas.SessionCreate): The Session object containing any metadata * * Returns: schemas.Session: The Session object of the new Session */ @@ -28,15 +26,15 @@ export class Sessions extends APIResource { body: SessionCreateParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this._client.post(`/apps/${appId}/users/${userId}/sessions`, { body, ...options }); + return this._client.post(`/v1/apps/${appId}/users/${userId}/sessions`, { body, ...options }); } /** * Update the metadata of a Session * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user_id (uuid.UUID): The User ID representing the user, managed by - * the user session_id (uuid.UUID): The ID of the Session to update session + * Args: app_id (str): The ID of the app representing the client application using + * honcho user_id (str): The User ID representing the user, managed by the user + * session_id (str): The ID of the Session to update session * (schemas.SessionUpdate): The Session object containing any new metadata * * Returns: schemas.Session: The Session object of the updated Session @@ -48,36 +46,28 @@ export class Sessions extends APIResource { body: SessionUpdateParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this._client.put(`/apps/${appId}/users/${userId}/sessions/${sessionId}`, { body, ...options }); + return this._client.put(`/v1/apps/${appId}/users/${userId}/sessions/${sessionId}`, { body, ...options }); } /** * Get All Sessions for a User * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user_id (uuid.UUID): The User ID representing the user, managed by - * the user + * Args: app_id (str): The ID of the app representing the client application using + * honcho user_id (str): The User ID representing the user, managed by the user * * Returns: list[schemas.Session]: List of Session objects */ list( appId: string, userId: string, - query?: SessionListParams, - options?: Core.RequestOptions, - ): Core.PagePromise; - list(appId: string, userId: string, options?: Core.RequestOptions): Core.PagePromise; - list( - appId: string, - userId: string, - query: SessionListParams | Core.RequestOptions = {}, + params: SessionListParams, options?: Core.RequestOptions, ): Core.PagePromise { - if (isRequestOptions(query)) { - return this.list(appId, userId, {}, query); - } - return this._client.getAPIList(`/apps/${appId}/users/${userId}/sessions`, SessionsPage, { - query, + const { page, reverse, size, ...body } = params; + return this._client.getAPIList(`/v1/apps/${appId}/users/${userId}/sessions/list`, SessionsPage, { + query: { page, reverse, size }, + body, + method: 'post', ...options, }); } @@ -85,9 +75,9 @@ export class Sessions extends APIResource { /** * Delete a session by marking it as inactive * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user_id (uuid.UUID): The User ID representing the user, managed by - * the user session_id (uuid.UUID): The ID of the Session to delete + * Args: app_id (str): The ID of the app representing the client application using + * honcho user_id (str): The User ID representing the user, managed by the user + * session_id (str): The ID of the Session to delete * * Returns: dict: A message indicating that the session was deleted * @@ -99,7 +89,7 @@ export class Sessions extends APIResource { sessionId: string, options?: Core.RequestOptions, ): Core.APIPromise { - return this._client.delete(`/apps/${appId}/users/${userId}/sessions/${sessionId}`, options); + return this._client.delete(`/v1/apps/${appId}/users/${userId}/sessions/${sessionId}`, options); } /** @@ -112,7 +102,7 @@ export class Sessions extends APIResource { body: SessionChatParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this._client.post(`/apps/${appId}/users/${userId}/sessions/${sessionId}/chat`, { + return this._client.post(`/v1/apps/${appId}/users/${userId}/sessions/${sessionId}/chat`, { body, ...options, }); @@ -121,9 +111,9 @@ export class Sessions extends APIResource { /** * Get a specific session for a user by ID * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user_id (uuid.UUID): The User ID representing the user, managed by - * the user session_id (uuid.UUID): The ID of the Session to retrieve + * Args: app_id (str): The ID of the app representing the client application using + * honcho user_id (str): The User ID representing the user, managed by the user + * session_id (str): The ID of the Session to retrieve * * Returns: schemas.Session: The Session object of the requested Session * @@ -135,7 +125,7 @@ export class Sessions extends APIResource { sessionId: string, options?: Core.RequestOptions, ): Core.APIPromise { - return this._client.get(`/apps/${appId}/users/${userId}/sessions/${sessionId}`, options); + return this._client.get(`/v1/apps/${appId}/users/${userId}/sessions/${sessionId}`, options); } /** @@ -148,7 +138,7 @@ export class Sessions extends APIResource { body: SessionStreamParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this._client.post(`/apps/${appId}/users/${userId}/sessions/${sessionId}/chat/stream`, { + return this._client.post(`/v1/apps/${appId}/users/${userId}/sessions/${sessionId}/chat/stream`, { body, ...options, }); @@ -190,7 +180,7 @@ export type SessionDeleteResponse = unknown; export type SessionStreamResponse = unknown; export interface SessionCreateParams { - metadata?: Record | null; + metadata?: Record; } export interface SessionUpdateParams { @@ -198,11 +188,20 @@ export interface SessionUpdateParams { } export interface SessionListParams extends PageParams { - filter?: string | null; + /** + * Query param: + */ + reverse?: boolean | null; - is_active?: boolean | null; + /** + * Body param: + */ + filter?: Record | null; - reverse?: boolean | null; + /** + * Body param: + */ + is_active?: boolean; } export interface SessionChatParams { diff --git a/src/resources/apps/users/users.ts b/src/resources/apps/users/users.ts index 0655e15..1c45147 100644 --- a/src/resources/apps/users/users.ts +++ b/src/resources/apps/users/users.ts @@ -1,7 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../../resource'; -import { isRequestOptions } from '../../../core'; import * as Core from '../../../core'; import * as UsersAPI from './users'; import * as MetamessagesAPI from './metamessages'; @@ -17,21 +16,21 @@ export class Users extends APIResource { /** * Create a User * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user (schemas.UserCreate): The User object containing any metadata + * Args: app_id (str): The ID of the app representing the client application using + * honcho user (schemas.UserCreate): The User object containing any metadata * * Returns: schemas.User: Created User object */ create(appId: string, body: UserCreateParams, options?: Core.RequestOptions): Core.APIPromise { - return this._client.post(`/apps/${appId}/users`, { body, ...options }); + return this._client.post(`/v1/apps/${appId}/users`, { body, ...options }); } /** * Update a User * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user_id (str): The User ID representing the user, managed by the - * user user (schemas.UserCreate): The User object containing any metadata + * Args: app_id (str): The ID of the app representing the client application using + * honcho user_id (str): The User ID representing the user, managed by the user + * user (schemas.UserCreate): The User object containing any metadata * * Returns: schemas.User: Updated User object */ @@ -41,71 +40,65 @@ export class Users extends APIResource { body: UserUpdateParams, options?: Core.RequestOptions, ): Core.APIPromise { - return this._client.put(`/apps/${appId}/users/${userId}`, { body, ...options }); + return this._client.put(`/v1/apps/${appId}/users/${userId}`, { body, ...options }); } /** * Get All Users for an App * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho + * Args: app_id (str): The ID of the app representing the client application using + * honcho * * Returns: list[schemas.User]: List of User objects */ list( appId: string, - query?: UserListParams, - options?: Core.RequestOptions, - ): Core.PagePromise; - list(appId: string, options?: Core.RequestOptions): Core.PagePromise; - list( - appId: string, - query: UserListParams | Core.RequestOptions = {}, + params: UserListParams, options?: Core.RequestOptions, ): Core.PagePromise { - if (isRequestOptions(query)) { - return this.list(appId, {}, query); - } - return this._client.getAPIList(`/apps/${appId}/users`, UsersPage, { query, ...options }); + const { page, reverse, size, ...body } = params; + return this._client.getAPIList(`/v1/apps/${appId}/users/list`, UsersPage, { + query: { page, reverse, size }, + body, + method: 'post', + ...options, + }); } /** * Get a User * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user_id (str): The User ID representing the user, managed by the - * user + * Args: app_id (str): The ID of the app representing the client application using + * honcho user_id (str): The User ID representing the user, managed by the user * * Returns: schemas.User: User object */ get(appId: string, userId: string, options?: Core.RequestOptions): Core.APIPromise { - return this._client.get(`/apps/${appId}/users/${userId}`, options); + return this._client.get(`/v1/apps/${appId}/users/${userId}`, options); } /** * Get a User * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user_id (str): The User ID representing the user, managed by the - * user + * Args: app_id (str): The ID of the app representing the client application using + * honcho user_id (str): The User ID representing the user, managed by the user * * Returns: schemas.User: User object */ getByName(appId: string, name: string, options?: Core.RequestOptions): Core.APIPromise { - return this._client.get(`/apps/${appId}/users/name/${name}`, options); + return this._client.get(`/v1/apps/${appId}/users/name/${name}`, options); } /** * Get or Create a User * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user_id (str): The User ID representing the user, managed by the - * user + * Args: app_id (str): The ID of the app representing the client application using + * honcho user_id (str): The User ID representing the user, managed by the user * * Returns: schemas.User: User object */ getOrCreate(appId: string, name: string, options?: Core.RequestOptions): Core.APIPromise { - return this._client.get(`/apps/${appId}/users/get_or_create/${name}`, options); + return this._client.get(`/v1/apps/${appId}/users/get_or_create/${name}`, options); } } @@ -138,7 +131,7 @@ export interface User { export interface UserCreateParams { name: string; - metadata?: Record | null; + metadata?: Record; } export interface UserUpdateParams { @@ -148,9 +141,15 @@ export interface UserUpdateParams { } export interface UserListParams extends PageParams { - filter?: string | null; - + /** + * Query param: + */ reverse?: boolean; + + /** + * Body param: + */ + filter?: Record | null; } export namespace Users { diff --git a/tests/api-resources/apps/apps.test.ts b/tests/api-resources/apps/apps.test.ts index a8f7e1b..7ffdb5f 100644 --- a/tests/api-resources/apps/apps.test.ts +++ b/tests/api-resources/apps/apps.test.ts @@ -25,7 +25,7 @@ describe('resource apps', () => { }); test('update', async () => { - const responsePromise = client.apps.update('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {}); + const responsePromise = client.apps.update('app_id', {}); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -36,7 +36,7 @@ describe('resource apps', () => { }); test('get', async () => { - const responsePromise = client.apps.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); + const responsePromise = client.apps.get('app_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -48,9 +48,9 @@ describe('resource apps', () => { test('get: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect( - client.apps.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }), - ).rejects.toThrow(Honcho.NotFoundError); + await expect(client.apps.get('app_id', { path: '/_stainless_unknown_path' })).rejects.toThrow( + Honcho.NotFoundError, + ); }); test('getByName', async () => { diff --git a/tests/api-resources/apps/users/collections/collections.test.ts b/tests/api-resources/apps/users/collections/collections.test.ts index 445b940..5b57bea 100644 --- a/tests/api-resources/apps/users/collections/collections.test.ts +++ b/tests/api-resources/apps/users/collections/collections.test.ts @@ -10,11 +10,7 @@ const client = new Honcho({ describe('resource collections', () => { test('create: only required params', async () => { - const responsePromise = client.apps.users.collections.create( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { name: 'name' }, - ); + const responsePromise = client.apps.users.collections.create('app_id', 'user_id', { name: 'name' }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -25,20 +21,14 @@ describe('resource collections', () => { }); test('create: required and optional params', async () => { - const response = await client.apps.users.collections.create( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { name: 'name', metadata: { foo: 'bar' } }, - ); + const response = await client.apps.users.collections.create('app_id', 'user_id', { + name: 'name', + metadata: { foo: 'bar' }, + }); }); test('update', async () => { - const responsePromise = client.apps.users.collections.update( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - {}, - ); + const responsePromise = client.apps.users.collections.update('app_id', 'user_id', 'collection_id', {}); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -49,10 +39,7 @@ describe('resource collections', () => { }); test('list', async () => { - const responsePromise = client.apps.users.collections.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - ); + const responsePromise = client.apps.users.collections.list('app_id', 'user_id', {}); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -62,35 +49,8 @@ describe('resource collections', () => { expect(dataAndResponse.response).toBe(rawResponse); }); - test('list: request options instead of params are passed correctly', async () => { - // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect( - client.apps.users.collections.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { path: '/_stainless_unknown_path' }, - ), - ).rejects.toThrow(Honcho.NotFoundError); - }); - - test('list: request options and params are passed correctly', async () => { - // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect( - client.apps.users.collections.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { filter: 'filter', page: 1, reverse: true, size: 1 }, - { path: '/_stainless_unknown_path' }, - ), - ).rejects.toThrow(Honcho.NotFoundError); - }); - test('delete', async () => { - const responsePromise = client.apps.users.collections.delete( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - ); + const responsePromise = client.apps.users.collections.delete('app_id', 'user_id', 'collection_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -103,21 +63,14 @@ describe('resource collections', () => { test('delete: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - client.apps.users.collections.delete( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { path: '/_stainless_unknown_path' }, - ), + client.apps.users.collections.delete('app_id', 'user_id', 'collection_id', { + path: '/_stainless_unknown_path', + }), ).rejects.toThrow(Honcho.NotFoundError); }); test('get', async () => { - const responsePromise = client.apps.users.collections.get( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - ); + const responsePromise = client.apps.users.collections.get('app_id', 'user_id', 'collection_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -130,21 +83,14 @@ describe('resource collections', () => { test('get: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - client.apps.users.collections.get( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { path: '/_stainless_unknown_path' }, - ), + client.apps.users.collections.get('app_id', 'user_id', 'collection_id', { + path: '/_stainless_unknown_path', + }), ).rejects.toThrow(Honcho.NotFoundError); }); test('getByName', async () => { - const responsePromise = client.apps.users.collections.getByName( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - 'name', - ); + const responsePromise = client.apps.users.collections.getByName('app_id', 'user_id', 'name'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -157,12 +103,9 @@ describe('resource collections', () => { test('getByName: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - client.apps.users.collections.getByName( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - 'name', - { path: '/_stainless_unknown_path' }, - ), + client.apps.users.collections.getByName('app_id', 'user_id', 'name', { + path: '/_stainless_unknown_path', + }), ).rejects.toThrow(Honcho.NotFoundError); }); }); diff --git a/tests/api-resources/apps/users/collections/documents.test.ts b/tests/api-resources/apps/users/collections/documents.test.ts index 5422441..feec7c8 100644 --- a/tests/api-resources/apps/users/collections/documents.test.ts +++ b/tests/api-resources/apps/users/collections/documents.test.ts @@ -11,9 +11,9 @@ const client = new Honcho({ describe('resource documents', () => { test('create: only required params', async () => { const responsePromise = client.apps.users.collections.documents.create( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + 'app_id', + 'user_id', + 'collection_id', { content: 'content' }, ); const rawResponse = await responsePromise.asResponse(); @@ -27,19 +27,19 @@ describe('resource documents', () => { test('create: required and optional params', async () => { const response = await client.apps.users.collections.documents.create( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + 'app_id', + 'user_id', + 'collection_id', { content: 'content', metadata: { foo: 'bar' } }, ); }); test('update', async () => { const responsePromise = client.apps.users.collections.documents.update( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + 'app_id', + 'user_id', + 'collection_id', + 'document_id', {}, ); const rawResponse = await responsePromise.asResponse(); @@ -53,9 +53,10 @@ describe('resource documents', () => { test('list', async () => { const responsePromise = client.apps.users.collections.documents.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + 'app_id', + 'user_id', + 'collection_id', + {}, ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -66,37 +67,12 @@ describe('resource documents', () => { expect(dataAndResponse.response).toBe(rawResponse); }); - test('list: request options instead of params are passed correctly', async () => { - // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect( - client.apps.users.collections.documents.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { path: '/_stainless_unknown_path' }, - ), - ).rejects.toThrow(Honcho.NotFoundError); - }); - - test('list: request options and params are passed correctly', async () => { - // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect( - client.apps.users.collections.documents.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { filter: 'filter', page: 1, reverse: true, size: 1 }, - { path: '/_stainless_unknown_path' }, - ), - ).rejects.toThrow(Honcho.NotFoundError); - }); - test('delete', async () => { const responsePromise = client.apps.users.collections.documents.delete( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + 'app_id', + 'user_id', + 'collection_id', + 'document_id', ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -110,22 +86,18 @@ describe('resource documents', () => { test('delete: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - client.apps.users.collections.documents.delete( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { path: '/_stainless_unknown_path' }, - ), + client.apps.users.collections.documents.delete('app_id', 'user_id', 'collection_id', 'document_id', { + path: '/_stainless_unknown_path', + }), ).rejects.toThrow(Honcho.NotFoundError); }); test('get', async () => { const responsePromise = client.apps.users.collections.documents.get( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + 'app_id', + 'user_id', + 'collection_id', + 'document_id', ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -139,21 +111,17 @@ describe('resource documents', () => { test('get: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - client.apps.users.collections.documents.get( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { path: '/_stainless_unknown_path' }, - ), + client.apps.users.collections.documents.get('app_id', 'user_id', 'collection_id', 'document_id', { + path: '/_stainless_unknown_path', + }), ).rejects.toThrow(Honcho.NotFoundError); }); test('query: only required params', async () => { const responsePromise = client.apps.users.collections.documents.query( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + 'app_id', + 'user_id', + 'collection_id', { query: 'query' }, ); const rawResponse = await responsePromise.asResponse(); @@ -167,9 +135,9 @@ describe('resource documents', () => { test('query: required and optional params', async () => { const response = await client.apps.users.collections.documents.query( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + 'app_id', + 'user_id', + 'collection_id', { query: 'query', filter: 'filter', top_k: 0 }, ); }); diff --git a/tests/api-resources/apps/users/metamessages.test.ts b/tests/api-resources/apps/users/metamessages.test.ts index ab1d0a6..0bfb20f 100644 --- a/tests/api-resources/apps/users/metamessages.test.ts +++ b/tests/api-resources/apps/users/metamessages.test.ts @@ -10,10 +10,7 @@ const client = new Honcho({ describe('resource metamessages', () => { test('list', async () => { - const responsePromise = client.apps.users.metamessages.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - ); + const responsePromise = client.apps.users.metamessages.list('app_id', 'user_id', {}); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -22,27 +19,4 @@ describe('resource metamessages', () => { expect(dataAndResponse.data).toBe(response); expect(dataAndResponse.response).toBe(rawResponse); }); - - test('list: request options instead of params are passed correctly', async () => { - // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect( - client.apps.users.metamessages.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { path: '/_stainless_unknown_path' }, - ), - ).rejects.toThrow(Honcho.NotFoundError); - }); - - test('list: request options and params are passed correctly', async () => { - // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect( - client.apps.users.metamessages.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { filter: 'filter', metamessage_type: 'metamessage_type', page: 1, reverse: true, size: 1 }, - { path: '/_stainless_unknown_path' }, - ), - ).rejects.toThrow(Honcho.NotFoundError); - }); }); diff --git a/tests/api-resources/apps/users/sessions/messages.test.ts b/tests/api-resources/apps/users/sessions/messages.test.ts index d8702be..c24b603 100644 --- a/tests/api-resources/apps/users/sessions/messages.test.ts +++ b/tests/api-resources/apps/users/sessions/messages.test.ts @@ -10,12 +10,10 @@ const client = new Honcho({ describe('resource messages', () => { test('create: only required params', async () => { - const responsePromise = client.apps.users.sessions.messages.create( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { content: 'content', is_user: true }, - ); + const responsePromise = client.apps.users.sessions.messages.create('app_id', 'user_id', 'session_id', { + content: 'content', + is_user: true, + }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -26,20 +24,19 @@ describe('resource messages', () => { }); test('create: required and optional params', async () => { - const response = await client.apps.users.sessions.messages.create( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { content: 'content', is_user: true, metadata: { foo: 'bar' } }, - ); + const response = await client.apps.users.sessions.messages.create('app_id', 'user_id', 'session_id', { + content: 'content', + is_user: true, + metadata: { foo: 'bar' }, + }); }); test('update', async () => { const responsePromise = client.apps.users.sessions.messages.update( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + 'app_id', + 'user_id', + 'session_id', + 'message_id', {}, ); const rawResponse = await responsePromise.asResponse(); @@ -52,11 +49,7 @@ describe('resource messages', () => { }); test('list', async () => { - const responsePromise = client.apps.users.sessions.messages.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - ); + const responsePromise = client.apps.users.sessions.messages.list('app_id', 'user_id', 'session_id', {}); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -66,37 +59,12 @@ describe('resource messages', () => { expect(dataAndResponse.response).toBe(rawResponse); }); - test('list: request options instead of params are passed correctly', async () => { - // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect( - client.apps.users.sessions.messages.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { path: '/_stainless_unknown_path' }, - ), - ).rejects.toThrow(Honcho.NotFoundError); - }); - - test('list: request options and params are passed correctly', async () => { - // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect( - client.apps.users.sessions.messages.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { filter: 'filter', page: 1, reverse: true, size: 1 }, - { path: '/_stainless_unknown_path' }, - ), - ).rejects.toThrow(Honcho.NotFoundError); - }); - test('get', async () => { const responsePromise = client.apps.users.sessions.messages.get( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + 'app_id', + 'user_id', + 'session_id', + 'message_id', ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -110,13 +78,9 @@ describe('resource messages', () => { test('get: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - client.apps.users.sessions.messages.get( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { path: '/_stainless_unknown_path' }, - ), + client.apps.users.sessions.messages.get('app_id', 'user_id', 'session_id', 'message_id', { + path: '/_stainless_unknown_path', + }), ).rejects.toThrow(Honcho.NotFoundError); }); }); diff --git a/tests/api-resources/apps/users/sessions/metamessages.test.ts b/tests/api-resources/apps/users/sessions/metamessages.test.ts index faa2a1b..941f2b9 100644 --- a/tests/api-resources/apps/users/sessions/metamessages.test.ts +++ b/tests/api-resources/apps/users/sessions/metamessages.test.ts @@ -11,14 +11,10 @@ const client = new Honcho({ describe('resource metamessages', () => { test('create: only required params', async () => { const responsePromise = client.apps.users.sessions.metamessages.create( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { - content: 'content', - message_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - metamessage_type: 'metamessage_type', - }, + 'app_id', + 'user_id', + 'session_id', + { content: 'content', message_id: 'message_id', metamessage_type: 'metamessage_type' }, ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -30,26 +26,21 @@ describe('resource metamessages', () => { }); test('create: required and optional params', async () => { - const response = await client.apps.users.sessions.metamessages.create( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { - content: 'content', - message_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - metamessage_type: 'metamessage_type', - metadata: { foo: 'bar' }, - }, - ); + const response = await client.apps.users.sessions.metamessages.create('app_id', 'user_id', 'session_id', { + content: 'content', + message_id: 'message_id', + metamessage_type: 'metamessage_type', + metadata: { foo: 'bar' }, + }); }); test('update: only required params', async () => { const responsePromise = client.apps.users.sessions.metamessages.update( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { message_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e' }, + 'app_id', + 'user_id', + 'session_id', + 'metamessage_id', + { message_id: 'message_id' }, ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -62,23 +53,20 @@ describe('resource metamessages', () => { test('update: required and optional params', async () => { const response = await client.apps.users.sessions.metamessages.update( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { - message_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - metadata: { foo: 'bar' }, - metamessage_type: 'metamessage_type', - }, + 'app_id', + 'user_id', + 'session_id', + 'metamessage_id', + { message_id: 'message_id', metadata: { foo: 'bar' }, metamessage_type: 'metamessage_type' }, ); }); test('list', async () => { const responsePromise = client.apps.users.sessions.metamessages.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + 'app_id', + 'user_id', + 'session_id', + {}, ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -89,45 +77,13 @@ describe('resource metamessages', () => { expect(dataAndResponse.response).toBe(rawResponse); }); - test('list: request options instead of params are passed correctly', async () => { - // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect( - client.apps.users.sessions.metamessages.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { path: '/_stainless_unknown_path' }, - ), - ).rejects.toThrow(Honcho.NotFoundError); - }); - - test('list: request options and params are passed correctly', async () => { - // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect( - client.apps.users.sessions.metamessages.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { - filter: 'filter', - message_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - metamessage_type: 'metamessage_type', - page: 1, - reverse: true, - size: 1, - }, - { path: '/_stainless_unknown_path' }, - ), - ).rejects.toThrow(Honcho.NotFoundError); - }); - test('get: only required params', async () => { const responsePromise = client.apps.users.sessions.metamessages.get( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { message_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e' }, + 'app_id', + 'user_id', + 'session_id', + 'metamessage_id', + { message_id: 'message_id' }, ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -140,11 +96,11 @@ describe('resource metamessages', () => { test('get: required and optional params', async () => { const response = await client.apps.users.sessions.metamessages.get( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { message_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e' }, + 'app_id', + 'user_id', + 'session_id', + 'metamessage_id', + { message_id: 'message_id' }, ); }); }); diff --git a/tests/api-resources/apps/users/sessions/sessions.test.ts b/tests/api-resources/apps/users/sessions/sessions.test.ts index 458bf61..c033d9c 100644 --- a/tests/api-resources/apps/users/sessions/sessions.test.ts +++ b/tests/api-resources/apps/users/sessions/sessions.test.ts @@ -10,11 +10,7 @@ const client = new Honcho({ describe('resource sessions', () => { test('create', async () => { - const responsePromise = client.apps.users.sessions.create( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - {}, - ); + const responsePromise = client.apps.users.sessions.create('app_id', 'user_id', {}); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -25,12 +21,7 @@ describe('resource sessions', () => { }); test('update', async () => { - const responsePromise = client.apps.users.sessions.update( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - {}, - ); + const responsePromise = client.apps.users.sessions.update('app_id', 'user_id', 'session_id', {}); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -41,10 +32,7 @@ describe('resource sessions', () => { }); test('list', async () => { - const responsePromise = client.apps.users.sessions.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - ); + const responsePromise = client.apps.users.sessions.list('app_id', 'user_id', {}); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -54,35 +42,8 @@ describe('resource sessions', () => { expect(dataAndResponse.response).toBe(rawResponse); }); - test('list: request options instead of params are passed correctly', async () => { - // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect( - client.apps.users.sessions.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { path: '/_stainless_unknown_path' }, - ), - ).rejects.toThrow(Honcho.NotFoundError); - }); - - test('list: request options and params are passed correctly', async () => { - // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect( - client.apps.users.sessions.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { filter: 'filter', is_active: true, page: 1, reverse: true, size: 1 }, - { path: '/_stainless_unknown_path' }, - ), - ).rejects.toThrow(Honcho.NotFoundError); - }); - test('delete', async () => { - const responsePromise = client.apps.users.sessions.delete( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - ); + const responsePromise = client.apps.users.sessions.delete('app_id', 'user_id', 'session_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -95,22 +56,16 @@ describe('resource sessions', () => { test('delete: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - client.apps.users.sessions.delete( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { path: '/_stainless_unknown_path' }, - ), + client.apps.users.sessions.delete('app_id', 'user_id', 'session_id', { + path: '/_stainless_unknown_path', + }), ).rejects.toThrow(Honcho.NotFoundError); }); test('chat: only required params', async () => { - const responsePromise = client.apps.users.sessions.chat( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { queries: 'string' }, - ); + const responsePromise = client.apps.users.sessions.chat('app_id', 'user_id', 'session_id', { + queries: 'string', + }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -121,20 +76,13 @@ describe('resource sessions', () => { }); test('chat: required and optional params', async () => { - const response = await client.apps.users.sessions.chat( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { queries: 'string' }, - ); + const response = await client.apps.users.sessions.chat('app_id', 'user_id', 'session_id', { + queries: 'string', + }); }); test('get', async () => { - const responsePromise = client.apps.users.sessions.get( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - ); + const responsePromise = client.apps.users.sessions.get('app_id', 'user_id', 'session_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -147,22 +95,14 @@ describe('resource sessions', () => { test('get: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - client.apps.users.sessions.get( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { path: '/_stainless_unknown_path' }, - ), + client.apps.users.sessions.get('app_id', 'user_id', 'session_id', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(Honcho.NotFoundError); }); test('stream: only required params', async () => { - const responsePromise = client.apps.users.sessions.stream( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { queries: 'string' }, - ); + const responsePromise = client.apps.users.sessions.stream('app_id', 'user_id', 'session_id', { + queries: 'string', + }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -173,11 +113,8 @@ describe('resource sessions', () => { }); test('stream: required and optional params', async () => { - const response = await client.apps.users.sessions.stream( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { queries: 'string' }, - ); + const response = await client.apps.users.sessions.stream('app_id', 'user_id', 'session_id', { + queries: 'string', + }); }); }); diff --git a/tests/api-resources/apps/users/users.test.ts b/tests/api-resources/apps/users/users.test.ts index a67db27..38333ed 100644 --- a/tests/api-resources/apps/users/users.test.ts +++ b/tests/api-resources/apps/users/users.test.ts @@ -10,9 +10,7 @@ const client = new Honcho({ describe('resource users', () => { test('create: only required params', async () => { - const responsePromise = client.apps.users.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { - name: 'name', - }); + const responsePromise = client.apps.users.create('app_id', { name: 'name' }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -23,18 +21,11 @@ describe('resource users', () => { }); test('create: required and optional params', async () => { - const response = await client.apps.users.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { - name: 'name', - metadata: { foo: 'bar' }, - }); + const response = await client.apps.users.create('app_id', { name: 'name', metadata: { foo: 'bar' } }); }); test('update', async () => { - const responsePromise = client.apps.users.update( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - {}, - ); + const responsePromise = client.apps.users.update('app_id', 'user_id', {}); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -45,7 +36,7 @@ describe('resource users', () => { }); test('list', async () => { - const responsePromise = client.apps.users.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); + const responsePromise = client.apps.users.list('app_id', {}); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -55,29 +46,8 @@ describe('resource users', () => { expect(dataAndResponse.response).toBe(rawResponse); }); - test('list: request options instead of params are passed correctly', async () => { - // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect( - client.apps.users.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }), - ).rejects.toThrow(Honcho.NotFoundError); - }); - - test('list: request options and params are passed correctly', async () => { - // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect( - client.apps.users.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { filter: 'filter', page: 1, reverse: true, size: 1 }, - { path: '/_stainless_unknown_path' }, - ), - ).rejects.toThrow(Honcho.NotFoundError); - }); - test('get', async () => { - const responsePromise = client.apps.users.get( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - ); + const responsePromise = client.apps.users.get('app_id', 'user_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -90,14 +60,12 @@ describe('resource users', () => { test('get: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - client.apps.users.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { - path: '/_stainless_unknown_path', - }), + client.apps.users.get('app_id', 'user_id', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(Honcho.NotFoundError); }); test('getByName', async () => { - const responsePromise = client.apps.users.getByName('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'name'); + const responsePromise = client.apps.users.getByName('app_id', 'name'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -110,14 +78,12 @@ describe('resource users', () => { test('getByName: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - client.apps.users.getByName('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'name', { - path: '/_stainless_unknown_path', - }), + client.apps.users.getByName('app_id', 'name', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(Honcho.NotFoundError); }); test('getOrCreate', async () => { - const responsePromise = client.apps.users.getOrCreate('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'name'); + const responsePromise = client.apps.users.getOrCreate('app_id', 'name'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -130,9 +96,7 @@ describe('resource users', () => { test('getOrCreate: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error await expect( - client.apps.users.getOrCreate('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'name', { - path: '/_stainless_unknown_path', - }), + client.apps.users.getOrCreate('app_id', 'name', { path: '/_stainless_unknown_path' }), ).rejects.toThrow(Honcho.NotFoundError); }); }); diff --git a/tests/index.test.ts b/tests/index.test.ts index f263c9d..b5b9023 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -254,6 +254,122 @@ describe('retries', () => { expect(count).toEqual(3); }); + test('retry count header', async () => { + let count = 0; + let capturedRequest: RequestInit | undefined; + const testFetch = async (url: RequestInfo, init: RequestInit = {}): Promise => { + count++; + if (count <= 2) { + return new Response(undefined, { + status: 429, + headers: { + 'Retry-After': '0.1', + }, + }); + } + capturedRequest = init; + return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } }); + }; + + const client = new Honcho({ apiKey: 'My API Key', fetch: testFetch, maxRetries: 4 }); + + expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 }); + + expect((capturedRequest!.headers as Headers)['x-stainless-retry-count']).toEqual('2'); + expect(count).toEqual(3); + }); + + test('omit retry count header', async () => { + let count = 0; + let capturedRequest: RequestInit | undefined; + const testFetch = async (url: RequestInfo, init: RequestInit = {}): Promise => { + count++; + if (count <= 2) { + return new Response(undefined, { + status: 429, + headers: { + 'Retry-After': '0.1', + }, + }); + } + capturedRequest = init; + return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } }); + }; + const client = new Honcho({ apiKey: 'My API Key', fetch: testFetch, maxRetries: 4 }); + + expect( + await client.request({ + path: '/foo', + method: 'get', + headers: { 'X-Stainless-Retry-Count': null }, + }), + ).toEqual({ a: 1 }); + + expect(capturedRequest!.headers as Headers).not.toHaveProperty('x-stainless-retry-count'); + }); + + test('omit retry count header by default', async () => { + let count = 0; + let capturedRequest: RequestInit | undefined; + const testFetch = async (url: RequestInfo, init: RequestInit = {}): Promise => { + count++; + if (count <= 2) { + return new Response(undefined, { + status: 429, + headers: { + 'Retry-After': '0.1', + }, + }); + } + capturedRequest = init; + return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } }); + }; + const client = new Honcho({ + apiKey: 'My API Key', + fetch: testFetch, + maxRetries: 4, + defaultHeaders: { 'X-Stainless-Retry-Count': null }, + }); + + expect( + await client.request({ + path: '/foo', + method: 'get', + }), + ).toEqual({ a: 1 }); + + expect(capturedRequest!.headers as Headers).not.toHaveProperty('x-stainless-retry-count'); + }); + + test('overwrite retry count header', async () => { + let count = 0; + let capturedRequest: RequestInit | undefined; + const testFetch = async (url: RequestInfo, init: RequestInit = {}): Promise => { + count++; + if (count <= 2) { + return new Response(undefined, { + status: 429, + headers: { + 'Retry-After': '0.1', + }, + }); + } + capturedRequest = init; + return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } }); + }; + const client = new Honcho({ apiKey: 'My API Key', fetch: testFetch, maxRetries: 4 }); + + expect( + await client.request({ + path: '/foo', + method: 'get', + headers: { 'X-Stainless-Retry-Count': '42' }, + }), + ).toEqual({ a: 1 }); + + expect((capturedRequest!.headers as Headers)['x-stainless-retry-count']).toBe('42'); + }); + test('retry on 429 with retry-after', async () => { let count = 0; const testFetch = async (url: RequestInfo, { signal }: RequestInit = {}): Promise => { diff --git a/yarn.lock b/yarn.lock index 0f17a27..10ebd6d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1959,6 +1959,13 @@ humanize-ms@^1.2.1: dependencies: ms "^2.0.0" +iconv-lite@^0.6.3: + version "0.6.3" + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.6.3.tgz#a52f80bf38da1952eb5c681790719871a1a72501" + integrity sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw== + dependencies: + safer-buffer ">= 2.1.2 < 3.0.0" + ignore@^5.2.0, ignore@^5.2.4: version "5.2.4" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.4.tgz#a291c0c6178ff1b960befe47fcdec301674a6324" @@ -3041,6 +3048,11 @@ safe-buffer@~5.2.0: resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== +"safer-buffer@>= 2.1.2 < 3.0.0": + version "2.1.2" + resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" + integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== + semver@^6.3.0, semver@^6.3.1: version "6.3.1" resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"