import {z} from 'zod' export type GetApiV1WorkflowsWorkflowIdRunsRunIdArgs = {workflowId: number, runId: number}; export type GetApiV1WorkflowsWorkflowIdRunsRunIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const providerConfigOptionEntity = z.object({id: z.number(), provider: z.lazy(() => providerEntity), config: z.string(), required: z.boolean(), description: z.string()}); export const providerEntity: z.ZodType = z.object({identifier: z.object({}), name: z.string(), description: z.string().nullable(), integrationMessage: z.string(), icon: z.string().nullable(), channel: z.object({}), configOptions: z.array(providerConfigOptionEntity), isActive: z.boolean(), createdAt: z.string(), updatedAt: z.string(), deletedAt: z.string()}); export const appChannelProviderConfigEntity = z.object({id: z.number(), appChannelProvider: z.lazy(() => appChannelProviderEntity), config: z.string(), value: z.string(), isEncrypted: z.boolean(), appChannelProviderId: z.number().optional()}); export const appChannelProviderEntity: z.ZodType = z.object({id: z.number(), app: z.lazy(() => appEntity), channel: z.object({}), provider: providerEntity, configs: z.array(appChannelProviderConfigEntity), enabled: z.boolean(), deliveryOrder: z.number(), selectionCondition: z.string().nullable().optional(), notificationCount: z.number().optional(), instanceName: z.string().nullable().optional()}); export const appEntity: z.ZodType = z.object({id: z.number(), clientId: z.number(), apiKey: z.string(), notificationEnabled: z.boolean(), name: z.string(), url: z.string(), channelProviders: z.array(appChannelProviderEntity), type: z.object({}), subdomain: z.string().nullable(), apiSecret: z.string(), gcmKey: z.string().nullable(), senderId: z.string().nullable(), domain: z.string().nullable(), welcomeMessage: z.string(), customEvents: z.string().nullable(), optInType: z.object({}), prePrompt: z.number(), serviceWorkerPath: z.string().nullable(), xPos: z.number(), yPos: z.number(), defaultPosition: z.string(), posTop: z.number().nullable(), posBottom: z.number().nullable(), posLeft: z.number().nullable(), posRight: z.number().nullable(), promptDelay: z.number(), bgcolor: z.string().nullable(), fcolor: z.string().nullable(), confirmationButtonText: z.string(), declineButtonText: z.string(), lastCheckedForCodeIntegration: z.string(), disableUserActivityTrackingByDefault: z.number(), disableLocationIpTracking: z.number(), websiteType: z.object({}), siteOnboardingCompleted: z.number(), panelUiStyle: z.string(), widgetType: z.string().nullable(), bellIconDivId: z.string().nullable(), websiteIcon: z.string().nullable(), onBoardingStepsCompleted: z.object({}).nullable(), playSound: z.number(), vapidPrivateKey: z.string(), vapidPublicKey: z.string(), hideBranding: z.boolean(), enableUserSignatureVerification: z.boolean(), enableWebPush: z.boolean(), rsaPublicKey: z.string().nullable(), rtmProvider: z.object({}), secureAuth: z.boolean(), deletedAt: z.string().optional(), inAppCodeIntegration: z.boolean(), webPushCodeIntegration: z.boolean(), isDefault: z.boolean().optional(), isProduction: z.boolean().optional(), order: z.number().optional()}); export const categoryEntity = z.object({id: z.number(), app: appEntity, name: z.string(), identifier: z.string(), createdAt: z.string(), updatedAt: z.string(), deletedAt: z.string(), hideInPreferenceManager: z.boolean(), hideInInApp: z.boolean()}); export const workflowBranchEntity = z.object({id: z.number(), branchCondition: z.string().nullable(), name: z.string().nullable(), ref: z.string().nullable(), branchFromStep: z.lazy(() => workflowStepEntity)}); export const workflowStepEntity: z.ZodType = z.object({id: z.number(), ref: z.string(), stepOrder: z.number(), type: z.enum(["branch", "delay", "channel", "batch", "waitForInput", "updatePreference", "fetch", "triggerWorkflow", "defineVariable", "editVariable"]), config: z.object({}), template: z.object({}).nullable(), channelKey: z.object({}), triggerCondition: z.string(), workflow: z.lazy(() => workflowEntity), workflowVersion: z.lazy(() => workflowVersionEntity), belongsToBranch: workflowBranchEntity.nullable(), branches: z.array(workflowBranchEntity), createdAt: z.string(), updatedAt: z.string(), deletedAt: z.string()}); export const workflowVersionEntity: z.ZodType = z.object({id: z.number(), workflowId: z.string(), workflow: z.lazy(() => workflowEntity), steps: z.array(workflowStepEntity), isActive: z.boolean(), createdAt: z.string(), updatedAt: z.string(), deletedAt: z.string()}); export const clientUserClientsEntity = z.object({mappingId: z.number(), role: z.object({}), clientUser: z.lazy(() => clientUserEntity), client: z.lazy(() => clientEntity)}); export const clientEntity: z.ZodType = z.object({id: z.number(), name: z.string(), createdAt: z.string(), updatedAt: z.string(), stripeId: z.string(), stripePaymentId: z.string(), defaultApp: z.number(), clientUsers: z.array(z.lazy(() => clientUserEntity)), clientUserClients: z.array(clientUserClientsEntity), licenseKey: z.string().optional(), licensePublicKey: z.string().optional(), licenseAuthToken: z.string().optional(), status: z.enum(["active", "send_suspended", "suspended"]), version: z.string().optional(), region: z.string().optional()}); export const clientUserEntity: z.ZodType = z.object({id: z.number(), firstName: z.string(), lastName: z.string(), address: z.string(), profilePicture: z.string(), email: z.string(), password: z.string(), address2: z.string(), city: z.string(), postcode: z.string(), country: z.string(), state: z.string(), cc: z.number(), phone: z.string(), activationHash: z.string(), activationEmailResentAt: z.string(), passwordLockedAt: z.string(), accountStatus: z.object({}), emailVerified: z.boolean(), timezone: z.string(), registeredIp: z.string(), createdAt: z.string(), updatedAt: z.string(), aid: z.string(), emailList: z.object({}), onboardingCompleted: z.number(), lastCheckedForInactivity: z.string(), receiveNewsletters: z.number(), lastLogin: z.string(), gitHubId: z.number(), googleId: z.number(), clients: z.array(clientEntity), clientUserClients: z.array(clientUserClientsEntity), source: z.string().optional(), isTwoFactorEnabled: z.number(), twoFactorSecret: z.string().optional(), passwordResetRequestedAt: z.string()}); export const workflowEntity: z.ZodType = z.object({id: z.number(), identifier: z.string(), category: categoryEntity.optional(), name: z.string(), app: appEntity, isActive: z.boolean(), jsonSpec: z.object({}), createdAt: z.string(), updatedAt: z.string(), deletedAt: z.string(), hasUnpublishedChanges: z.boolean(), versions: z.array(workflowVersionEntity), clientUser: clientUserEntity.optional()}); export const userProfileDataEntity = z.object({id: z.number(), user: z.lazy(() => userEntity), attribute: z.string(), value: z.string(), createdAt: z.string(), updatedAt: z.string(), deletedAt: z.string()}); export const userPreferenceEntity = z.object({id: z.number(), user: z.lazy(() => userEntity), category: categoryEntity, channel: z.object({}), enabled: z.boolean(), createdAt: z.string(), updatedAt: z.string()}); export const userEntity: z.ZodType = z.object({id: z.number(), siteId: z.number(), identifier: z.string(), profileDatas: z.array(userProfileDataEntity).optional(), preferences: z.array(userPreferenceEntity).optional(), startedAt: z.number(), lastMessageFetched: z.number(), isWebPushChannelActive: z.boolean(), createdAt: z.string(), deletedAt: z.string(), lastActivityAt: z.string()}); export const notificationContentTemplateStateEntity = z.object({id: z.number(), notificationTemplateContentId: z.number(), notificationTemplateContent: z.lazy(() => notificationTemplateContentEntity), state: z.string(), stateSpec: z.object({}), createdAt: z.string(), updatedAt: z.string(), deletedAt: z.string()}); export const notificationTemplateContentEntity: z.ZodType = z.object({id: z.number(), template: z.lazy(() => notificationTemplateEntity), channel: z.object({}), content: z.object({}), isDisabled: z.boolean(), order: z.number(), trigger: z.enum(["always", "delayed"]), triggerDelay: z.number(), triggerCondition: z.string(), batchingEnabled: z.boolean().optional(), batchingWindow: z.number().optional(), batchingContent: z.object({}), createdAt: z.string(), updatedAt: z.string(), deletedAt: z.string(), states: z.array(notificationContentTemplateStateEntity).optional()}); export const notificationTemplateEntity: z.ZodType = z.object({id: z.number(), app: appEntity, name: z.string(), category: categoryEntity, clientUser: clientUserEntity, contents: z.array(notificationTemplateContentEntity).optional(), createdAt: z.string(), updatedAt: z.string(), deletedAt: z.string(), identifier: z.string().optional()}); export const notificationEntity = z.object({id: z.number(), clientId: z.number(), siteId: z.number(), app: appEntity, requestId: z.string(), user: userEntity, category: categoryEntity, createdAt: z.string(), template: notificationTemplateEntity.nullable().optional(), workflow: workflowEntity.nullable().optional()}); export const workflowRunEntity = z.object({id: z.number(), workflow: workflowEntity, workflowVersion: workflowVersionEntity, user: userEntity, notification: notificationEntity, state: z.enum(["running", "success", "failed", "batched", "cancelled"]), triggerData: z.object({}), override: z.object({}), triggeredFromRunStep: z.lazy(() => workflowRunStepEntity), cancellationKey: z.string().optional(), createdAt: z.string(), updatedAt: z.string(), deletedAt: z.string()}); export const workflowRunStepEntity: z.ZodType = z.object({id: z.number(), workflowRun: workflowRunEntity, state: z.enum(["scheduled", "queued", "running", "success", "failed", "skipped", "batched", "cancelled"]), step: workflowStepEntity, stepRef: z.string(), runtimeData: z.object({}), createdAt: z.string(), updatedAt: z.string(), deletedAt: z.string()}); export const getApiV1WorkflowsWorkflowIdRunsRunIdResponse = z.array(workflowRunStepEntity); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * GET /v1/workflows/{workflowId}/runs/{runId} */ export const getApiV1WorkflowsWorkflowIdRunsRunId = async (args: GetApiV1WorkflowsWorkflowIdRunsRunIdArgs, options: GetApiV1WorkflowsWorkflowIdRunsRunIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/workflows/${encodeURIComponent(String(args.workflowId))}/runs/${encodeURIComponent(String(args.runId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1WorkflowsWorkflowIdRunsRunIdResponse, await res.json()) };