import {z} from 'zod' export type AuditLogType = 'productCreated' | 'productChanged' | 'productDeleted' | 'productsReordered' | 'productPreferencesUpdated' | 'teamMemberInvited' | 'teamMemberInvitationRevoked' | 'teamMemberJoined' | 'teamMemberPermissionGroupChanged' | 'teamMemberRemoved' | 'teamMemberLeft' | 'teamMemberInvitationChanged' | 'teamMemberInvitationResent' | 'teamMemberInvitationRejected' | 'teamMemberAddedToProduct' | 'configCreated' | 'configChanged' | 'configDeleted' | 'configsReordered' | 'environmentCreated' | 'environmentChanged' | 'environmentDeleted' | 'environmentsReordered' | 'settingCreated' | 'settingChanged' | 'settingDeleted' | 'settingsReordered' | 'predefinedVariationsChanged' | 'settingConvertedToPredefinedVariations' | 'settingConvertedToFreeFormValues' | 'settingValueChanged' | 'webHookCreated' | 'webHookChanged' | 'webHookDeleted' | 'permissionGroupCreated' | 'permissionGroupChanged' | 'permissionGroupDeleted' | 'permissionGroupDefault' | 'apiKeyAdded' | 'apiKeyRemoved' | 'integrationAdded' | 'integrationChanged' | 'integrationRemoved' | 'apiKeyConnected' | 'integrationLinkAdded' | 'integrationLinkRemoved' | 'organizationAdded' | 'organizationChanged' | 'organizationSubscriptionTypeChanged' | 'organizationAdminChanged' | 'organizationAdminLeft' | 'twoFactorDisabledForMember' | 'tagAdded' | 'tagChanged' | 'tagRemoved' | 'settingTagAdded' | 'settingTagRemoved' | 'publicApiAccessTokenAdded' | 'publicApiAccessTokenRemoved' | 'domainAdded' | 'domainVerified' | 'domainRemoved' | 'autoProvisioningConfigurationChanged' | 'samlIdpConfigurationAdded' | 'samlIdpConfigurationRemoved' | 'samlIdpConfigurationUpdated' | 'autoProvisioningEnabledChanged' | 'organizationMemberJoined' | 'organizationMemberProductJoinRequested' | 'organizationMemberProductJoinRequestRejected' | 'organizationMemberProductJoinRequestApproved' | 'organizationMemberRemoved' | 'codeReferencesUploaded' | 'codeReferenceDeleted' | 'codeReferenceStaleBranchDeleted' | 'segmentCreated' | 'segmentChanged' | 'segmentDeleted' | 'webhookSigningKeyDeleted' | 'webhookSigningKeyCreated' | 'userProvisioningConfigurationChanged' | 'syncGroupProvisioningRuleChanged' | 'syncGroupsReordered' | 'syncUserProvisioningEnabled' | 'syncUserProvisioningDisabled' | 'userEmailChanged' | 'userFullNameChanged' | 'userDisabled' | 'awsConnected' | 'awsDisconnected' | 'userEnabled' | 'syncUserDeleted' | 'syncGroupDeleted' | 'proxyConfigurationCreated' | 'proxyConfigurationChanged' | 'proxyConfigurationDeleted' | 'proxyConfigurationSecretRegenerated' | 'proxyNotificationSettingsUpdated' | 'proxyNotificationSettingsDeleted' | 'proxyNotificationSigningKeyAdded' | 'proxyNotificationSigningKeyDeleted' | 'changeRequestCreated' | 'changeRequestUpdated' | 'changeRequestSettingValuesUpdated' | 'changeRequestSettingValueRebased' | 'changeRequestApproved' | 'changeRequestApprovalDismissed' | 'changeRequestApplied' | 'changeRequestAppliedOnSchedule' | 'changeRequestClosed' | 'changeRequestNeedsAttention' | 'changeRequestCommentAdded' | 'changeRequestCommentEdited' | 'changeRequestCommentDeleted' | 'changeRequestSettingDeleted' | 'changeRequestNeedsAttentionFixed' | 'changeRequestOwnershipClaimed'; export type GetApiV2OrganizationsOrganizationIdAuditlogsArgs = {organizationId: string, productId?: string | undefined, configId?: string | undefined, environmentId?: string | undefined, auditLogType?: (AuditLogType | null) | undefined, fromUtcDateTime?: string | undefined, toUtcDateTime?: string | undefined, pageNumber?: number | undefined, pageSize?: number | undefined}; export type GetApiV2OrganizationsOrganizationIdAuditlogsOptions = {baseUrl?: string | undefined, Basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const pagingResponseInfo = z.object({currentPage: z.number().int(), totalPages: z.number().int(), pageSize: z.number().int(), totalCount: z.number().int(), hasPrevious: z.boolean(), hasNext: z.boolean()}); export const auditLogType = z.enum(["productCreated", "productChanged", "productDeleted", "productsReordered", "productPreferencesUpdated", "teamMemberInvited", "teamMemberInvitationRevoked", "teamMemberJoined", "teamMemberPermissionGroupChanged", "teamMemberRemoved", "teamMemberLeft", "teamMemberInvitationChanged", "teamMemberInvitationResent", "teamMemberInvitationRejected", "teamMemberAddedToProduct", "configCreated", "configChanged", "configDeleted", "configsReordered", "environmentCreated", "environmentChanged", "environmentDeleted", "environmentsReordered", "settingCreated", "settingChanged", "settingDeleted", "settingsReordered", "predefinedVariationsChanged", "settingConvertedToPredefinedVariations", "settingConvertedToFreeFormValues", "settingValueChanged", "webHookCreated", "webHookChanged", "webHookDeleted", "permissionGroupCreated", "permissionGroupChanged", "permissionGroupDeleted", "permissionGroupDefault", "apiKeyAdded", "apiKeyRemoved", "integrationAdded", "integrationChanged", "integrationRemoved", "apiKeyConnected", "integrationLinkAdded", "integrationLinkRemoved", "organizationAdded", "organizationChanged", "organizationSubscriptionTypeChanged", "organizationAdminChanged", "organizationAdminLeft", "twoFactorDisabledForMember", "tagAdded", "tagChanged", "tagRemoved", "settingTagAdded", "settingTagRemoved", "publicApiAccessTokenAdded", "publicApiAccessTokenRemoved", "domainAdded", "domainVerified", "domainRemoved", "autoProvisioningConfigurationChanged", "samlIdpConfigurationAdded", "samlIdpConfigurationRemoved", "samlIdpConfigurationUpdated", "autoProvisioningEnabledChanged", "organizationMemberJoined", "organizationMemberProductJoinRequested", "organizationMemberProductJoinRequestRejected", "organizationMemberProductJoinRequestApproved", "organizationMemberRemoved", "codeReferencesUploaded", "codeReferenceDeleted", "codeReferenceStaleBranchDeleted", "segmentCreated", "segmentChanged", "segmentDeleted", "webhookSigningKeyDeleted", "webhookSigningKeyCreated", "userProvisioningConfigurationChanged", "syncGroupProvisioningRuleChanged", "syncGroupsReordered", "syncUserProvisioningEnabled", "syncUserProvisioningDisabled", "userEmailChanged", "userFullNameChanged", "userDisabled", "awsConnected", "awsDisconnected", "userEnabled", "syncUserDeleted", "syncGroupDeleted", "proxyConfigurationCreated", "proxyConfigurationChanged", "proxyConfigurationDeleted", "proxyConfigurationSecretRegenerated", "proxyNotificationSettingsUpdated", "proxyNotificationSettingsDeleted", "proxyNotificationSigningKeyAdded", "proxyNotificationSigningKeyDeleted", "changeRequestCreated", "changeRequestUpdated", "changeRequestSettingValuesUpdated", "changeRequestSettingValueRebased", "changeRequestApproved", "changeRequestApprovalDismissed", "changeRequestApplied", "changeRequestAppliedOnSchedule", "changeRequestClosed", "changeRequestNeedsAttention", "changeRequestCommentAdded", "changeRequestCommentEdited", "changeRequestCommentDeleted", "changeRequestSettingDeleted", "changeRequestNeedsAttentionFixed", "changeRequestOwnershipClaimed"]); export const auditLogItemModel = z.object({auditLogId: z.number().int(), auditLogDateTime: z.string(), auditLogTypeEnum: auditLogType, truncated: z.boolean(), modelVersion: z.number().int(), auditLogType: z.string(), userEmail: z.string().nullable(), userName: z.string(), where: z.string(), why: z.string().nullable(), actionTarget: z.string(), details: z.string()}); export const auditLogItemModelPagedList = z.object({paging: pagingResponseInfo.nullable(), data: z.array(auditLogItemModel).nullable()}); 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 }; /** * List Audit log items for Organization (V2) * * GET /v2/organizations/{organizationId}/auditlogs */ export const getApiV2OrganizationsOrganizationIdAuditlogs = async (args: GetApiV2OrganizationsOrganizationIdAuditlogsArgs, options?: GetApiV2OrganizationsOrganizationIdAuditlogsOptions) => { const {baseUrl = "https://api.configcat.com", fetch: fetchFn = fetch, Basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.productId != null) query.append("productId", String(args.productId)) if (args.configId != null) query.append("configId", String(args.configId)) if (args.environmentId != null) query.append("environmentId", String(args.environmentId)) if (args.auditLogType != null) query.append("auditLogType", String(args.auditLogType)) if (args.fromUtcDateTime != null) query.append("fromUtcDateTime", String(args.fromUtcDateTime)) if (args.toUtcDateTime != null) query.append("toUtcDateTime", String(args.toUtcDateTime)) if (args.pageNumber != null) query.append("pageNumber", String(args.pageNumber)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (Basic !== undefined) headers.set('authorization', `Basic ${btoa(`${Basic.username}:${Basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/organizations/${encodeURIComponent(String(args.organizationId))}/auditlogs${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(auditLogItemModelPagedList, await res.json()) };