import {z} from 'zod' export type GetApiAuditsCompanyCompanyIdArgs = {companyId: number, 'filter[createdAt]'?: string | undefined, 'filter[event]'?: ('accepted' | 'acknowledged' | 'actionsReminder' | 'activated' | 'added' | 'addedAttribute' | 'addedCompanySubdomain' | 'addedDomain' | 'anonymized' | 'answer' | 'archived' | 'assignedQuestions' | 'authentication' | 'blocked' | 'bounced' | 'changedRole' | 'clear' | 'clearedComplaints' | 'cleared_bounces' | 'close' | 'complained' | 'completed' | 'confirmationRequest' | 'confirmed' | 'consent' | 'correlated' | 'create' | 'created' | 'createdCompanyShard' | 'dailySent' | 'dataObliterateStarted' | 'delete' | 'deleted' | 'deletedComment' | 'deletedCompanyShard' | 'deletedCompanySubdomain' | 'deletedInput' | 'disabled' | 'employeeAttributesChanged' | 'enabled' | 'ended' | 'exceeded' | 'expired' | 'frequenciesUpdated' | 'generateAuthenticationCode' | 'generatedAgentToken' | 'generatedLogHash' | 'hard-close' | 'hookDisabled' | 'hookEnabled' | 'hookFailed' | 'hookFired' | 'hookPaused' | 'importStarted' | 'imported' | 'incompleted' | 'lowParticipation' | 'markAllAsRead' | 'markAllAsViewed' | 'markAsUnviewed' | 'markAsViewed' | 'markedSensitive' | 'migrated' | 'notified' | 'nps' | 'obliterated' | 'open' | 'passwordChange' | 'passwordRecovery' | 'presentation' | 'push' | 'reasonSet' | 'recalculated' | 'recoveryRequest' | 'recurred' | 'regeneratedCode' | 'regenerated_token' | 'rejected' | 'remind' | 'reminded' | 'removedAttribute' | 'removedDomain' | 'reopen' | 'resend' | 'reset' | 'resetQueued' | 'responseRequest' | 'restored' | 'resubscribed' | 'retire' | 'revealIdentity' | 'samlLoginRequest' | 'samlLogoutRequest' | 'scheduleLowParticipation' | 'scheduleRemind' | 'scheduled' | 'segmentationDisabled' | 'segmentationEnabled' | 'send' | 'sendLowParticipation' | 'sent' | 'set' | 'signup_consent_given' | 'smsReceipt' | 'smsReceived' | 'smsSent' | 'statusUpdated' | 'stripped' | 'suggested' | 'switch' | 'transferComplete' | 'transferStart' | 'twofactorRegisterCompleted' | 'twofactorRegisterStarted' | 'twofactorRemoved' | 'twofactorSms' | 'twofactorVerified' | 'unarchived' | 'unassignedQuestions' | 'unblocked' | 'uncompleted' | 'unmarkedSensitive' | 'unsubscribed' | 'upcomingRound' | 'update' | 'updated' | 'updatedPrimaryCompanySubdomain' | 'upgrade' | 'upserted' | 'useAuthenticationCode' | 'verificationStatusChanged' | 'withdrawn') | undefined, 'filter[objectType]'?: ('Account' | 'AccountSettings' | 'Action' | 'ActionItem' | 'ActionRejection' | 'Answer' | 'AnswerTopic' | 'AppIntegration' | 'Application' | 'Attribute' | 'AttributeHierarchy' | 'AttributeLink' | 'AttributeOption' | 'AttributeRange' | 'AttributeTreeNode' | 'Bookmark' | 'Branding' | 'Category' | 'Comment' | 'CommentSemanticSearchFeedback' | 'Company' | 'CompanyAction' | 'CompanyBenchmarkVersion' | 'CompanyResource' | 'CompanySettings' | 'Consultant' | 'Conversation' | 'ConversationMessage' | 'CustomConsent' | 'CustomConsentAccept' | 'CustomSenderDomain' | 'DenylistedTopic' | 'Device' | 'Employee' | 'EmployeeAttribute' | 'ExternalMetric' | 'ExternalMetricObservation' | 'FeatureFlip' | 'Feedback' | 'FeedbackRecipient' | 'Group' | 'GroupMember' | 'MailDomain' | 'Notification' | 'NotificationSettings' | 'Phone' | 'PriorityDriver' | 'PrioritySegment' | 'Question' | 'QuestionRule' | 'Response' | 'Round' | 'SAMLConfiguration' | 'Schedule' | 'Segment' | 'SegmentLimit' | 'SegmentLink' | 'SegmentManager' | 'SemanticTag' | 'SemanticTagFeedback' | 'SensitiveComment' | 'SensitiveConcept' | 'SensitiveKeyword' | 'Session' | 'Share' | 'TeamSuggestion' | 'TestCompany' | 'Topic' | 'TopicFeedback' | 'Value' | 'Vote') | undefined}; export type GetApiAuditsCompanyCompanyIdOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; export const resourceIdentifier = z.object({type: z.string().optional(), id: z.string().optional()}); export const audits = z.object({type: z.string().optional(), id: z.string().optional(), attributes: z.object({createdAt: z.string().optional(), event: z.enum(["activated", "authentication", "bounced", "complained", "changedRole", "cleared_bounces", "clearedComplaints", "completed", "confirmationRequest", "confirmed", "created", "generateAuthenticationCode", "generatedAgentToken", "passwordChange", "passwordRecovery", "presentation", "recoveryRequest", "resubscribed", "samlLogoutRequest", "signup_consent_given", "twofactorRegisterCompleted", "twofactorRegisterStarted", "twofactorRemoved", "uncompleted", "unsubscribed", "updated", "upserted", "useAuthenticationCode", "archived", "deleted", "incompleted", "suggested", "unarchived", "acknowledged", "deletedComment", "deletedInput", "markedSensitive", "unmarkedSensitive", "delete", "hookFailed", "hookFired", "hookPaused", "hookDisabled", "hookEnabled", "obliterated", "segmentationDisabled", "segmentationEnabled", "assignedQuestions", "unassignedQuestions", "revealIdentity", "addedDomain", "removedDomain", "anonymized", "blocked", "imported", "importStarted", "dataObliterateStarted", "regeneratedCode", "samlLoginRequest", "unblocked", "createdCompanyShard", "deletedCompanyShard", "addedCompanySubdomain", "updatedPrimaryCompanySubdomain", "deletedCompanySubdomain", "generatedLogHash", "stripped", "ended", "accepted", "withdrawn", "enabled", "disabled", "verificationStatusChanged", "push", "actionsReminder", "consent", "dailySent", "lowParticipation", "markAllAsRead", "markAllAsViewed", "notified", "nps", "smsSent", "upcomingRound", "employeeAttributesChanged", "correlated", "added", "markAsViewed", "markAsUnviewed", "sent", "smsReceipt", "smsReceived", "set", "migrated", "rejected", "expired", "retire", "scheduled", "upgrade", "answer", "clear", "create", "open", "remind", "reopen", "resend", "reset", "responseRequest", "scheduleRemind", "send", "close", "hard-close", "scheduleLowParticipation", "sendLowParticipation", "update", "addedAttribute", "recurred", "reminded", "removedAttribute", "frequenciesUpdated", "restored", "recalculated", "exceeded", "statusUpdated", "reasonSet", "switch", "transferComplete", "transferStart", "twofactorSms", "twofactorVerified", "regenerated_token", "resetQueued"]).optional(), objectType: z.enum(["Account", "AccountSettings", "Action", "ActionItem", "ActionRejection", "Answer", "AnswerTopic", "AppIntegration", "Application", "Attribute", "AttributeHierarchy", "AttributeLink", "AttributeOption", "AttributeRange", "AttributeTreeNode", "Bookmark", "Branding", "Category", "Comment", "CommentSemanticSearchFeedback", "Company", "CompanyAction", "CompanyBenchmarkVersion", "CompanyResource", "CompanySettings", "Consultant", "Conversation", "ConversationMessage", "CustomConsent", "CustomConsentAccept", "CustomSenderDomain", "DenylistedTopic", "Device", "Employee", "EmployeeAttribute", "ExternalMetric", "ExternalMetricObservation", "FeatureFlip", "Feedback", "FeedbackRecipient", "Group", "GroupMember", "MailDomain", "Notification", "NotificationSettings", "Phone", "PriorityDriver", "PrioritySegment", "Question", "QuestionRule", "Response", "Round", "SAMLConfiguration", "Schedule", "Segment", "SegmentLimit", "SegmentLink", "SegmentManager", "SemanticTag", "SemanticTagFeedback", "SensitiveComment", "SensitiveConcept", "SensitiveKeyword", "Session", "Share", "TeamSuggestion", "TestCompany", "Topic", "TopicFeedback", "Value", "Vote"]).optional(), objectId: z.number().int().optional(), data: z.object({}).optional(), text: z.string().optional(), address: z.object({}).optional(), location: z.object({city: z.string().optional(), country: z.string().optional(), countryCode: z.string().optional(), location: z.object({latitude: z.number().optional(), longitude: z.number().optional()}).optional()}).optional(), agent: z.object({browser: z.string().optional(), version: z.string().optional(), os: z.string().optional(), osVersion: z.string().optional()}).optional()}).optional(), relationships: z.object({account: z.object({data: resourceIdentifier.optional()}).optional()}).optional()}); export const getApiAuditsCompanyCompanyIdResponse = z.object({data: z.array(audits).optional(), included: z.array(resourceIdentifier).optional()}); 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 audits * * GET /audits/company/{companyId} */ export const getApiAuditsCompanyCompanyId = async (args: GetApiAuditsCompanyCompanyIdArgs, options?: GetApiAuditsCompanyCompanyIdOptions) => { const {baseUrl = "https://api.peakon.com/api/v1", fetch: fetchFn = fetch, jwt} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['filter[createdAt]'] != null) query.append("filter[createdAt]", String(args['filter[createdAt]'])) if (args['filter[event]'] != null) query.append("filter[event]", String(args['filter[event]'])) if (args['filter[objectType]'] != null) query.append("filter[objectType]", String(args['filter[objectType]'])) if (jwt !== undefined) headers.set('authorization', `Bearer ${jwt}`) const url = `${baseUrl.replace(/\/+$/, '')}/audits/company/${encodeURIComponent(String(args.companyId))}${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(getApiAuditsCompanyCompanyIdResponse, await res.json()) };