diff --git a/.stats.yml b/.stats.yml index 51913296bf..43a0559733 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 1680 +configured_endpoints: 1681 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-22aa409339ba3ba4e61a86e7e94dc5a66082c5c20615d1d30e3b9499d6407e31.yml openapi_spec_hash: e5eb84a55caa82c6dfdc82b7fbe3e8aa -config_hash: 713ebf60a015dd910800437b34425bea +config_hash: 6861676932ec6aacb336d1cdc59ca521 diff --git a/api.md b/api.md index d44c4c9741..54eb2eb649 100644 --- a/api.md +++ b/api.md @@ -7995,6 +7995,16 @@ Methods: - client.workflows.instances.status.edit(workflowName, instanceId, { ...params }) -> StatusEditResponse +### Events + +Types: + +- EventCreateResponse + +Methods: + +- client.workflows.instances.events.create(workflowName, instanceId, eventType, { ...params }) -> EventCreateResponse + ## Versions Types: diff --git a/src/resources/workflows/instances/events.ts b/src/resources/workflows/instances/events.ts new file mode 100644 index 0000000000..20f3a15ba5 --- /dev/null +++ b/src/resources/workflows/instances/events.ts @@ -0,0 +1,43 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { APIResource } from '../../../resource'; +import * as Core from '../../../core'; + +export class Events extends APIResource { + /** + * Send event to instance + */ + create( + workflowName: string, + instanceId: string, + eventType: string, + params: EventCreateParams, + options?: Core.RequestOptions, + ): Core.APIPromise { + const { account_id, body } = params ?? {}; + return ( + this._client.post( + `/accounts/${account_id}/workflows/${workflowName}/instances/${instanceId}/events/${eventType}`, + { body: body, ...options }, + ) as Core.APIPromise<{ result: EventCreateResponse }> + )._thenUnwrap((obj) => obj.result); + } +} + +export type EventCreateResponse = unknown; + +export interface EventCreateParams { + /** + * Path param: + */ + account_id: string; + + /** + * Body param: + */ + body?: unknown; +} + +export declare namespace Events { + export { type EventCreateResponse as EventCreateResponse, type EventCreateParams as EventCreateParams }; +} diff --git a/src/resources/workflows/instances/index.ts b/src/resources/workflows/instances/index.ts index 5a6cacc5b1..9c96da29fb 100644 --- a/src/resources/workflows/instances/index.ts +++ b/src/resources/workflows/instances/index.ts @@ -1,5 +1,6 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +export { Events, type EventCreateResponse, type EventCreateParams } from './events'; export { InstanceListResponsesV4PagePaginationArray, InstanceBulkResponsesSinglePage, diff --git a/src/resources/workflows/instances/instances.ts b/src/resources/workflows/instances/instances.ts index f550b3722f..587756087f 100644 --- a/src/resources/workflows/instances/instances.ts +++ b/src/resources/workflows/instances/instances.ts @@ -2,12 +2,15 @@ import { APIResource } from '../../../resource'; import * as Core from '../../../core'; +import * as EventsAPI from './events'; +import { EventCreateParams, EventCreateResponse, Events } from './events'; import * as StatusAPI from './status'; import { Status, StatusEditParams, StatusEditResponse } from './status'; import { SinglePage, V4PagePaginationArray, type V4PagePaginationArrayParams } from '../../../pagination'; export class Instances extends APIResource { status: StatusAPI.Status = new StatusAPI.Status(this._client); + events: EventsAPI.Events = new EventsAPI.Events(this._client); /** * Create a new workflow instance @@ -356,6 +359,7 @@ export interface InstanceGetParams { Instances.InstanceListResponsesV4PagePaginationArray = InstanceListResponsesV4PagePaginationArray; Instances.InstanceBulkResponsesSinglePage = InstanceBulkResponsesSinglePage; Instances.Status = Status; +Instances.Events = Events; export declare namespace Instances { export { @@ -376,4 +380,10 @@ export declare namespace Instances { type StatusEditResponse as StatusEditResponse, type StatusEditParams as StatusEditParams, }; + + export { + Events as Events, + type EventCreateResponse as EventCreateResponse, + type EventCreateParams as EventCreateParams, + }; } diff --git a/tests/api-resources/workflows/instances/events.test.ts b/tests/api-resources/workflows/instances/events.test.ts new file mode 100644 index 0000000000..a929a7e0d3 --- /dev/null +++ b/tests/api-resources/workflows/instances/events.test.ts @@ -0,0 +1,32 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import Cloudflare from 'cloudflare'; +import { Response } from 'node-fetch'; + +const client = new Cloudflare({ + apiKey: '144c9defac04969c7bfad8efaa8ea194', + apiEmail: 'user@example.com', + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', +}); + +describe('resource events', () => { + test('create: only required params', async () => { + const responsePromise = client.workflows.instances.events.create('x', 'x', 'x', { + account_id: 'account_id', + }); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + test('create: required and optional params', async () => { + const response = await client.workflows.instances.events.create('x', 'x', 'x', { + account_id: 'account_id', + body: {}, + }); + }); +});