import {z} from 'zod' export type GetApiAssetsArgs = {offset?: number | undefined, limit?: number | undefined, countLimit?: number | undefined, cursor?: string | undefined, name?: string | undefined, nameMatchMode?: ('START' | 'END' | 'ANYWHERE' | 'EXACT') | undefined, domainId?: string | undefined, communityId?: string | undefined, typeIds?: Array | undefined, typePublicIds?: Array | undefined, typeId?: Array | undefined, statusIds?: Array | undefined, statusId?: Array | undefined, tagNames?: Array | undefined, typeInheritance?: boolean | undefined, excludeMeta?: boolean | undefined, sortField: 'NAME' | 'DISPLAY_NAME' | 'ID', sortOrder?: ('ASC' | 'DESC') | undefined}; export type GetApiAssetsOptions = {baseUrl: string, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const resourceType = z.enum(["View", "Asset", "Community", "Domain", "AssetType", "DomainType", "Status", "User", "ClassificationMatch", "UserGroup", "Attribute", "StringAttribute", "ScriptAttribute", "BooleanAttribute", "DateAttribute", "NumericAttribute", "SingleValueListAttribute", "MultiValueListAttribute", "Comment", "Attachment", "Responsibility", "Workflow", "Job", "Relation", "RelationType", "ComplexRelation", "ComplexRelationType", "ArticulationRule", "Assignment", "Scope", "RelationTrace", "ValidationRule", "DataQualityRule", "DataQualityMetric", "Address", "InstantMessagingAccount", "Email", "PhoneNumber", "Website", "Activity", "FormProperty", "WorkflowTask", "ActivityChange", "WorkflowInstance", "Role", "AttributeType", "BooleanAttributeType", "DateAttributeType", "DateTimeAttributeType", "MultiValueListAttributeType", "NumericAttributeType", "ScriptAttributeType", "SingleValueListAttributeType", "StringAttributeType", "ViewSharingRule", "ViewAssignmentRule", "JdbcDriverFile", "JdbcDriver", "JdbcIngestionProperties", "CsvIngestionProperties", "ExcelIngestionProperties", "ConnectionStringParameter", "AssignedCharacteristicType", "Notification", "Tag", "ComplexRelationLegType", "ComplexRelationAttributeType", "ComplexRelationLeg", "BaseDataType", "AdvancedDataType", "DiagramPicture", "DiagramPictureSharingRule", "DiagramPictureAssignmentRule", "Rating", "Classification", "PhysicalDataConnector", "Context"]); export const namedResourceReferenceImpl = z.object({id: z.string(), name: z.string().optional(), resourceType: resourceType}); export const assetImpl = z.object({id: z.string(), createdBy: z.string().optional(), createdOn: z.number().int().optional(), lastModifiedBy: z.string().optional(), lastModifiedOn: z.number().int().optional(), system: z.boolean().optional(), resourceType: z.enum(["View", "Asset", "Community", "Domain", "AssetType", "DomainType", "Status", "User", "ClassificationMatch", "UserGroup", "Attribute", "StringAttribute", "ScriptAttribute", "BooleanAttribute", "DateAttribute", "NumericAttribute", "SingleValueListAttribute", "MultiValueListAttribute", "Comment", "Attachment", "Responsibility", "Workflow", "Job", "Relation", "RelationType", "ComplexRelation", "ComplexRelationType", "ArticulationRule", "Assignment", "Scope", "RelationTrace", "ValidationRule", "DataQualityRule", "DataQualityMetric", "Address", "InstantMessagingAccount", "Email", "PhoneNumber", "Website", "Activity", "FormProperty", "WorkflowTask", "ActivityChange", "WorkflowInstance", "Role", "AttributeType", "BooleanAttributeType", "DateAttributeType", "DateTimeAttributeType", "MultiValueListAttributeType", "NumericAttributeType", "ScriptAttributeType", "SingleValueListAttributeType", "StringAttributeType", "ViewSharingRule", "ViewAssignmentRule", "JdbcDriverFile", "JdbcDriver", "JdbcIngestionProperties", "CsvIngestionProperties", "ExcelIngestionProperties", "ConnectionStringParameter", "AssignedCharacteristicType", "Notification", "Tag", "ComplexRelationLegType", "ComplexRelationAttributeType", "ComplexRelationLeg", "BaseDataType", "AdvancedDataType", "DiagramPicture", "DiagramPictureSharingRule", "DiagramPictureAssignmentRule", "Rating", "Classification", "PhysicalDataConnector", "Context"]), name: z.string().optional(), displayName: z.string().optional(), articulationScore: z.number().optional(), excludedFromAutoHyperlinking: z.boolean().optional(), domain: namedResourceReferenceImpl.optional(), type: namedResourceReferenceImpl.optional(), status: namedResourceReferenceImpl.optional(), avgRating: z.number().optional(), ratingsCount: z.number().int().optional()}); export const assetPagedResponse = z.object({total: z.number().int().optional(), offset: z.number().int().optional(), limit: z.number().int().optional(), results: z.array(assetImpl).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 }; /** * Find assets * * GET /assets * * Also accepts auth: jwtAuth, oauth2, oauth2 */ export const getApiAssets = async (args: GetApiAssetsArgs, options: GetApiAssetsOptions) => { const {baseUrl, fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.countLimit != null) query.append("countLimit", String(args.countLimit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.name != null) query.append("name", String(args.name)) if (args.nameMatchMode != null) query.append("nameMatchMode", String(args.nameMatchMode)) if (args.domainId != null) query.append("domainId", String(args.domainId)) if (args.communityId != null) query.append("communityId", String(args.communityId)) for (const item of args.typeIds ?? []) query.append("typeIds", String(item)) for (const item of args.typePublicIds ?? []) query.append("typePublicIds", String(item)) for (const item of args.typeId ?? []) query.append("typeId", String(item)) for (const item of args.statusIds ?? []) query.append("statusIds", String(item)) for (const item of args.statusId ?? []) query.append("statusId", String(item)) for (const item of args.tagNames ?? []) query.append("tagNames", String(item)) if (args.typeInheritance != null) query.append("typeInheritance", String(args.typeInheritance)) if (args.excludeMeta != null) query.append("excludeMeta", String(args.excludeMeta)) if (args.sortField != null) query.append("sortField", String(args.sortField)) if (args.sortOrder != null) query.append("sortOrder", String(args.sortOrder)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/assets${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(assetPagedResponse, await res.json()) };