From 3a94cfcea0e5d3f41b620bd401a26705229a7861 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Mon, 24 Jun 2024 14:14:17 +0000 Subject: [PATCH] feat(api): external connections made optional when updating items (#224) --- .stats.yml | 2 +- src/resources/items.ts | 15 +++++++-- src/resources/plans/external-plan-id.ts | 18 +++++------ tests/api-resources/items.test.ts | 41 +++++++++++++++---------- 4 files changed, 46 insertions(+), 30 deletions(-) diff --git a/.stats.yml b/.stats.yml index b6290eb..ca9f987 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 90 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb-d08c3c586f46f155358104a907afa8300ce44a25814c1574c0f4344935c1b838.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb-aebc7faa75113d98ef7b57673cf7fce499c87b96afabe6c2ddc5e22badc3ef33.yml diff --git a/src/resources/items.ts b/src/resources/items.ts index 2ba35cd..3e3f908 100644 --- a/src/resources/items.ts +++ b/src/resources/items.ts @@ -17,7 +17,16 @@ export class Items extends APIResource { /** * This endpoint can be used to update properties on the Item. */ - update(itemId: string, body: ItemUpdateParams, options?: Core.RequestOptions): Core.APIPromise { + update(itemId: string, body?: ItemUpdateParams, options?: Core.RequestOptions): Core.APIPromise; + update(itemId: string, options?: Core.RequestOptions): Core.APIPromise; + update( + itemId: string, + body: ItemUpdateParams | Core.RequestOptions = {}, + options?: Core.RequestOptions, + ): Core.APIPromise { + if (isRequestOptions(body)) { + return this.update(itemId, {}, body); + } return this._client.put(`/items/${itemId}`, { body, ...options }); } @@ -85,7 +94,9 @@ export interface ItemCreateParams { } export interface ItemUpdateParams { - external_connections: Array | null; + external_connections?: Array | null; + + name?: string | null; } export namespace ItemUpdateParams { diff --git a/src/resources/plans/external-plan-id.ts b/src/resources/plans/external-plan-id.ts index 97bd1a5..f47d39e 100644 --- a/src/resources/plans/external-plan-id.ts +++ b/src/resources/plans/external-plan-id.ts @@ -8,18 +8,10 @@ import * as PlansAPI from './plans'; export class ExternalPlanID extends APIResource { /** - * This endpoint is used to fetch [plan](../guides/concepts##plan-and-price) - * details given an external_plan_id identifier. It returns information about the - * prices included in the plan and their configuration, as well as the product that - * the plan is attached to. - * - * ## Serialized prices + * This endpoint can be used to update the `external_plan_id`, and `metadata` of an + * existing plan. * - * Orb supports a few different pricing models out of the box. Each of these models - * is serialized differently in a given [Price](../guides/concepts#plan-and-price) - * object. The `model_type` field determines the key for the configuration object - * that is present. A detailed explanation of price types can be found in the - * [Price schema](../guides/concepts#plan-and-price). + * Other fields on a customer are currently immutable. */ update( otherExternalPlanId: string, @@ -44,6 +36,10 @@ export class ExternalPlanID extends APIResource { * prices included in the plan and their configuration, as well as the product that * the plan is attached to. * + * If multiple plans are found to contain the specified external_plan_id, the + * active plans will take priority over archived ones, and among those, the + * endpoint will return the most recently created plan. + * * ## Serialized prices * * Orb supports a few different pricing models out of the box. Each of these models diff --git a/tests/api-resources/items.test.ts b/tests/api-resources/items.test.ts index cea11e8..d0cfd47 100644 --- a/tests/api-resources/items.test.ts +++ b/tests/api-resources/items.test.ts @@ -24,14 +24,8 @@ describe('resource items', () => { const response = await orb.items.create({ name: 'API requests' }); }); - test('update: only required params', async () => { - const responsePromise = orb.items.update('string', { - external_connections: [ - { external_connection_name: 'stripe', external_entity_id: 'string' }, - { external_connection_name: 'stripe', external_entity_id: 'string' }, - { external_connection_name: 'stripe', external_entity_id: 'string' }, - ], - }); + test('update', async () => { + const responsePromise = orb.items.update('string'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -41,14 +35,29 @@ describe('resource items', () => { expect(dataAndResponse.response).toBe(rawResponse); }); - test('update: required and optional params', async () => { - const response = await orb.items.update('string', { - external_connections: [ - { external_connection_name: 'stripe', external_entity_id: 'string' }, - { external_connection_name: 'stripe', external_entity_id: 'string' }, - { external_connection_name: 'stripe', external_entity_id: 'string' }, - ], - }); + test('update: 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(orb.items.update('string', { path: '/_stainless_unknown_path' })).rejects.toThrow( + Orb.NotFoundError, + ); + }); + + test('update: 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( + orb.items.update( + 'string', + { + external_connections: [ + { external_connection_name: 'stripe', external_entity_id: 'string' }, + { external_connection_name: 'stripe', external_entity_id: 'string' }, + { external_connection_name: 'stripe', external_entity_id: 'string' }, + ], + name: 'string', + }, + { path: '/_stainless_unknown_path' }, + ), + ).rejects.toThrow(Orb.NotFoundError); }); test('list', async () => {