import {z} from 'zod' export type DeviceProfileId = {id: string, entityType: 'DEVICE_PROFILE'}; export type TenantId = {id: string, entityType: 'TENANT'}; export type RuleChainId = {id: string, entityType: 'RULE_CHAIN'}; export type DashboardId = {id: string, entityType: 'DASHBOARD'}; export type OtaPackageId = {id: string, entityType: 'OTA_PACKAGE'}; export type DefaultDeviceProfileConfiguration = {type: string}; export type JsonTransportPayloadConfiguration = {transportPayloadType: string}; export type ProtoTransportPayloadConfiguration = {transportPayloadType: string, deviceTelemetryProtoSchema?: string | undefined, deviceAttributesProtoSchema?: string | undefined, deviceRpcRequestProtoSchema?: string | undefined, deviceRpcResponseProtoSchema?: string | undefined, enableCompatibilityWithJsonPayloadFormat?: boolean | undefined, useJsonPayloadFormatForDefaultDownlinkTopics?: boolean | undefined}; export type DefaultCoapDeviceTypeConfiguration = {coapDeviceType: string, transportPayloadTypeConfiguration?: (JsonTransportPayloadConfiguration | ProtoTransportPayloadConfiguration) | undefined}; export type EfentoCoapDeviceTypeConfiguration = {coapDeviceType: string}; export type PowerSavingConfiguration = {powerMode?: ('PSM' | 'DRX' | 'E_DRX') | undefined, psmActivityTimer?: number | undefined, edrxCycle?: number | undefined, pagingTransmissionWindow?: number | undefined}; export type CoapDeviceProfileTransportConfiguration = {type: string, coapDeviceTypeConfiguration?: (DefaultCoapDeviceTypeConfiguration | EfentoCoapDeviceTypeConfiguration) | undefined, clientSettings?: PowerSavingConfiguration | undefined}; export type DefaultDeviceProfileTransportConfiguration = {type: string}; export type Version = unknown; export type LwM2mVersion = {supported?: boolean | undefined}; export type ObjectAttributes = {dim?: number | undefined, ssid?: number | undefined, uri?: string | undefined, ver?: Version | undefined, lwm2m?: LwM2mVersion | undefined, pmin?: number | undefined, pmax?: number | undefined, gt?: number | undefined, lt?: number | undefined, st?: number | undefined, epmin?: number | undefined, epmax?: number | undefined}; export type TelemetryMappingConfiguration = {keyName?: {[key: string]: string} | undefined, observe?: Array | undefined, attribute?: Array | undefined, telemetry?: Array | undefined, attributeLwm2m?: {[key: string]: ObjectAttributes} | undefined, initAttrTelAsObsStrategy?: boolean | undefined, observeStrategy?: ('SINGLE (0): One resource equals one single observe request' | 'COMPOSITE_ALL (1): All resources in one composite observe request' | 'COMPOSITE_BY_OBJECT (2): Grouped composite observe requests by object') | undefined}; export type NoSecLwM2MBootstrapServerCredential = {securityMode: string, shortServerId?: number | undefined, bootstrapServerIs?: boolean | undefined, host?: string | undefined, port?: number | undefined, clientHoldOffTime?: number | undefined, serverPublicKey?: string | undefined, serverCertificate?: string | undefined, bootstrapServerAccountTimeout?: number | undefined, lifetime?: number | undefined, defaultMinPeriod?: number | undefined, notifIfDisabled?: boolean | undefined, binding?: string | undefined}; export type PSKLwM2MBootstrapServerCredential = {securityMode: string, shortServerId?: number | undefined, bootstrapServerIs?: boolean | undefined, host?: string | undefined, port?: number | undefined, clientHoldOffTime?: number | undefined, serverPublicKey?: string | undefined, serverCertificate?: string | undefined, bootstrapServerAccountTimeout?: number | undefined, lifetime?: number | undefined, defaultMinPeriod?: number | undefined, notifIfDisabled?: boolean | undefined, binding?: string | undefined}; export type RPKLwM2MBootstrapServerCredential = {securityMode: string, shortServerId?: number | undefined, bootstrapServerIs?: boolean | undefined, host?: string | undefined, port?: number | undefined, clientHoldOffTime?: number | undefined, serverPublicKey?: string | undefined, serverCertificate?: string | undefined, bootstrapServerAccountTimeout?: number | undefined, lifetime?: number | undefined, defaultMinPeriod?: number | undefined, notifIfDisabled?: boolean | undefined, binding?: string | undefined}; export type X509LwM2MBootstrapServerCredential = {securityMode: string, shortServerId?: number | undefined, bootstrapServerIs?: boolean | undefined, host?: string | undefined, port?: number | undefined, clientHoldOffTime?: number | undefined, serverPublicKey?: string | undefined, serverCertificate?: string | undefined, bootstrapServerAccountTimeout?: number | undefined, lifetime?: number | undefined, defaultMinPeriod?: number | undefined, notifIfDisabled?: boolean | undefined, binding?: string | undefined}; export type OtherConfiguration = {useObject19ForOtaInfo?: boolean | undefined, fwUpdateStrategy?: number | undefined, swUpdateStrategy?: number | undefined, clientOnlyObserveAfterConnect?: number | undefined, powerMode?: ('PSM' | 'DRX' | 'E_DRX') | undefined, psmActivityTimer?: number | undefined, edrxCycle?: number | undefined, pagingTransmissionWindow?: number | undefined, fwUpdateResource?: string | undefined, swUpdateResource?: string | undefined, defaultObjectIDVer?: string | undefined}; export type Lwm2mDeviceProfileTransportConfiguration = {type: string, observeAttr?: TelemetryMappingConfiguration | undefined, bootstrapServerUpdateEnable?: boolean | undefined, bootstrap?: (Array) | undefined, clientLwM2mSettings?: OtherConfiguration | undefined}; export type MqttDeviceProfileTransportConfiguration = {type: string, deviceTelemetryTopic?: string | undefined, deviceAttributesTopic?: string | undefined, deviceAttributesSubscribeTopic?: string | undefined, transportPayloadTypeConfiguration?: (JsonTransportPayloadConfiguration | ProtoTransportPayloadConfiguration) | undefined, sparkplug?: boolean | undefined, sparkplugAttributesMetricNames?: Array | undefined, sendAckOnValidationException?: boolean | undefined}; export type SnmpMapping = {oid?: string | undefined, key?: string | undefined, dataType?: ('BOOLEAN' | 'LONG' | 'DOUBLE' | 'STRING' | 'JSON') | undefined}; export type ClientAttributesQueryingSnmpCommunicationConfig = {spec?: ('TELEMETRY_QUERYING' | 'CLIENT_ATTRIBUTES_QUERYING' | 'SHARED_ATTRIBUTES_SETTING' | 'TO_DEVICE_RPC_REQUEST' | 'TO_SERVER_RPC_REQUEST') | undefined, mappings?: Array | undefined, queryingFrequencyMs?: number | undefined}; export type SharedAttributesSettingSnmpCommunicationConfig = {spec?: ('TELEMETRY_QUERYING' | 'CLIENT_ATTRIBUTES_QUERYING' | 'SHARED_ATTRIBUTES_SETTING' | 'TO_DEVICE_RPC_REQUEST' | 'TO_SERVER_RPC_REQUEST') | undefined, mappings?: Array | undefined}; export type TelemetryQueryingSnmpCommunicationConfig = {spec?: ('TELEMETRY_QUERYING' | 'CLIENT_ATTRIBUTES_QUERYING' | 'SHARED_ATTRIBUTES_SETTING' | 'TO_DEVICE_RPC_REQUEST' | 'TO_SERVER_RPC_REQUEST') | undefined, mappings?: Array | undefined, queryingFrequencyMs?: number | undefined}; export type ToDeviceRpcRequestSnmpCommunicationConfig = {spec?: ('TELEMETRY_QUERYING' | 'CLIENT_ATTRIBUTES_QUERYING' | 'SHARED_ATTRIBUTES_SETTING' | 'TO_DEVICE_RPC_REQUEST' | 'TO_SERVER_RPC_REQUEST') | undefined, mappings?: Array | undefined}; export type ToServerRpcRequestSnmpCommunicationConfig = {spec?: ('TELEMETRY_QUERYING' | 'CLIENT_ATTRIBUTES_QUERYING' | 'SHARED_ATTRIBUTES_SETTING' | 'TO_DEVICE_RPC_REQUEST' | 'TO_SERVER_RPC_REQUEST') | undefined, mappings?: Array | undefined}; export type SnmpDeviceProfileTransportConfiguration = {type: string, timeoutMs?: number | undefined, retries?: number | undefined, communicationConfigs?: (Array) | undefined}; export type AllowCreateNewDevicesDeviceProfileProvisionConfiguration = {provisionDeviceSecret?: string | undefined, type: string}; export type CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration = {provisionDeviceSecret?: string | undefined, type: string}; export type DisabledDeviceProfileProvisionConfiguration = {provisionDeviceSecret?: string | undefined, type: string}; export type X509CertificateChainProvisionConfiguration = {provisionDeviceSecret?: string | undefined, type: string, certificateRegExPattern?: string | undefined, allowCreateNewDevicesByX509Certificate?: boolean | undefined}; export type AlarmConditionFilterKey = {type?: ('ATTRIBUTE' | 'TIME_SERIES' | 'ENTITY_FIELD' | 'CONSTANT') | undefined, key?: string | undefined}; export type DynamicValueBoolean = {sourceType?: ('CURRENT_TENANT' | 'CURRENT_CUSTOMER' | 'CURRENT_USER' | 'CURRENT_DEVICE') | undefined, sourceAttribute?: string | undefined, inherit?: boolean | undefined, resolvedValue?: boolean | undefined}; export type FilterPredicateValueBoolean = {defaultValue?: boolean | undefined, userValue?: boolean | undefined, dynamicValue?: DynamicValueBoolean | undefined}; export type BooleanFilterPredicate = {type: string, operation?: ('EQUAL' | 'NOT_EQUAL') | undefined, value?: FilterPredicateValueBoolean | undefined}; export type DynamicValueDouble = {sourceType?: ('CURRENT_TENANT' | 'CURRENT_CUSTOMER' | 'CURRENT_USER' | 'CURRENT_DEVICE') | undefined, sourceAttribute?: string | undefined, inherit?: boolean | undefined, resolvedValue?: number | undefined}; export type FilterPredicateValueDouble = {defaultValue?: number | undefined, userValue?: number | undefined, dynamicValue?: DynamicValueDouble | undefined}; export type NumericFilterPredicate = {type: string, operation?: ('EQUAL' | 'NOT_EQUAL' | 'GREATER' | 'LESS' | 'GREATER_OR_EQUAL' | 'LESS_OR_EQUAL') | undefined, value?: FilterPredicateValueDouble | undefined}; export type DynamicValueString = {sourceType?: ('CURRENT_TENANT' | 'CURRENT_CUSTOMER' | 'CURRENT_USER' | 'CURRENT_DEVICE') | undefined, sourceAttribute?: string | undefined, inherit?: boolean | undefined, resolvedValue?: string | undefined}; export type FilterPredicateValueString = {defaultValue?: string | undefined, userValue?: string | undefined, dynamicValue?: DynamicValueString | undefined}; export type StringFilterPredicate = {type: string, operation?: ('EQUAL' | 'NOT_EQUAL' | 'STARTS_WITH' | 'ENDS_WITH' | 'CONTAINS' | 'NOT_CONTAINS' | 'IN' | 'NOT_IN') | undefined, value?: FilterPredicateValueString | undefined, ignoreCase?: boolean | undefined}; export type ComplexFilterPredicate = {type: string, operation?: ('AND' | 'OR') | undefined, predicates?: (Array) | undefined}; export type AlarmConditionFilter = {key?: AlarmConditionFilterKey | undefined, valueType?: ('STRING' | 'NUMERIC' | 'BOOLEAN' | 'DATE_TIME') | undefined, value: unknown, predicate?: (BooleanFilterPredicate | ComplexFilterPredicate | NumericFilterPredicate | StringFilterPredicate) | undefined}; export type DynamicValueLong = {sourceType?: ('CURRENT_TENANT' | 'CURRENT_CUSTOMER' | 'CURRENT_USER' | 'CURRENT_DEVICE') | undefined, sourceAttribute?: string | undefined, inherit?: boolean | undefined, resolvedValue?: number | undefined}; export type FilterPredicateValueLong = {defaultValue?: number | undefined, userValue?: number | undefined, dynamicValue?: DynamicValueLong | undefined}; export type DurationAlarmConditionSpec = {type: string, unit?: ('NANOSECONDS' | 'MICROSECONDS' | 'MILLISECONDS' | 'SECONDS' | 'MINUTES' | 'HOURS' | 'DAYS') | undefined, predicate?: FilterPredicateValueLong | undefined}; export type DynamicValueInteger = {sourceType?: ('CURRENT_TENANT' | 'CURRENT_CUSTOMER' | 'CURRENT_USER' | 'CURRENT_DEVICE') | undefined, sourceAttribute?: string | undefined, inherit?: boolean | undefined, resolvedValue?: number | undefined}; export type FilterPredicateValueInteger = {defaultValue?: number | undefined, userValue?: number | undefined, dynamicValue?: DynamicValueInteger | undefined}; export type RepeatingAlarmConditionSpec = {type: string, predicate?: FilterPredicateValueInteger | undefined}; export type SimpleAlarmConditionSpec = {type: string}; export type AlarmCondition = {condition?: Array | undefined, spec?: (DurationAlarmConditionSpec | RepeatingAlarmConditionSpec | SimpleAlarmConditionSpec) | undefined}; export type AnyTimeSchedule = {type?: ('ANY_TIME' | 'SPECIFIC_TIME' | 'CUSTOM') | undefined, dynamicValue?: DynamicValueString | undefined}; export type CustomTimeScheduleItem = {enabled?: boolean | undefined, dayOfWeek?: number | undefined, startsOn?: number | undefined, endsOn?: number | undefined}; export type CustomTimeSchedule = {type?: ('ANY_TIME' | 'SPECIFIC_TIME' | 'CUSTOM') | undefined, dynamicValue?: DynamicValueString | undefined, timezone?: string | undefined, items?: Array | undefined}; export type SpecificTimeSchedule = {type?: ('ANY_TIME' | 'SPECIFIC_TIME' | 'CUSTOM') | undefined, dynamicValue?: DynamicValueString | undefined, timezone?: string | undefined, daysOfWeek?: Array | undefined, startsOn?: number | undefined, endsOn?: number | undefined}; export type AlarmRule = {condition?: AlarmCondition | undefined, schedule?: (AnyTimeSchedule | CustomTimeSchedule | SpecificTimeSchedule) | undefined, alarmDetails?: string | undefined, dashboardId?: DashboardId | undefined}; export type DeviceProfileAlarm = {id?: string | undefined, alarmType?: string | undefined, createRules?: {[key: string]: AlarmRule} | undefined, clearRule?: AlarmRule | undefined, propagate?: boolean | undefined, propagateToOwner?: boolean | undefined, propagateToTenant?: boolean | undefined, propagateRelationTypes?: Array | undefined}; export type DeviceProfileData = {configuration?: DefaultDeviceProfileConfiguration | undefined, transportConfiguration?: (CoapDeviceProfileTransportConfiguration | DefaultDeviceProfileTransportConfiguration | Lwm2mDeviceProfileTransportConfiguration | MqttDeviceProfileTransportConfiguration | SnmpDeviceProfileTransportConfiguration) | undefined, provisionConfiguration?: (AllowCreateNewDevicesDeviceProfileProvisionConfiguration | CheckPreProvisionedDevicesDeviceProfileProvisionConfiguration | DisabledDeviceProfileProvisionConfiguration | X509CertificateChainProvisionConfiguration) | undefined, alarms?: Array | undefined}; export type DeviceProfile = {id?: DeviceProfileId | undefined, createdTime?: number | undefined, tenantId?: TenantId | undefined, name?: string | undefined, description?: string | undefined, image?: string | undefined, type?: 'DEFAULT' | undefined, transportType?: ('DEFAULT' | 'MQTT' | 'COAP' | 'LWM2M' | 'SNMP') | undefined, provisionType?: ('DISABLED' | 'ALLOW_CREATE_NEW_DEVICES' | 'CHECK_PRE_PROVISIONED_DEVICES' | 'X509_CERTIFICATE_CHAIN') | undefined, defaultRuleChainId?: RuleChainId | undefined, defaultDashboardId?: DashboardId | undefined, defaultQueueName?: string | undefined, provisionDeviceKey?: string | undefined, firmwareId?: OtaPackageId | undefined, softwareId?: OtaPackageId | undefined, defaultEdgeRuleChainId?: RuleChainId | undefined, version?: number | undefined, default?: boolean | undefined, profileData?: DeviceProfileData | undefined}; export type CreateApiApiDeviceProfileArgs = {body: DeviceProfile}; export type CreateApiApiDeviceProfileOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const deviceProfileId = z.object({id: z.string(), entityType: z.literal("DEVICE_PROFILE")}); export const tenantId = z.object({id: z.string(), entityType: z.literal("TENANT")}); export const ruleChainId = z.object({id: z.string(), entityType: z.literal("RULE_CHAIN")}); export const dashboardId = z.object({id: z.string(), entityType: z.literal("DASHBOARD")}); export const otaPackageId = z.object({id: z.string(), entityType: z.literal("OTA_PACKAGE")}); export const defaultDeviceProfileConfiguration = z.object({type: z.string()}); export const jsonTransportPayloadConfiguration = z.object({transportPayloadType: z.string()}); export const protoTransportPayloadConfiguration = z.object({transportPayloadType: z.string(), deviceTelemetryProtoSchema: z.string().optional(), deviceAttributesProtoSchema: z.string().optional(), deviceRpcRequestProtoSchema: z.string().optional(), deviceRpcResponseProtoSchema: z.string().optional(), enableCompatibilityWithJsonPayloadFormat: z.boolean().optional(), useJsonPayloadFormatForDefaultDownlinkTopics: z.boolean().optional()}); export const defaultCoapDeviceTypeConfiguration = z.object({coapDeviceType: z.string(), transportPayloadTypeConfiguration: z.union([jsonTransportPayloadConfiguration, protoTransportPayloadConfiguration]).optional()}); export const efentoCoapDeviceTypeConfiguration = z.object({coapDeviceType: z.string()}); export const powerSavingConfiguration = z.object({powerMode: z.enum(["PSM", "DRX", "E_DRX"]).optional(), psmActivityTimer: z.number().int().optional(), edrxCycle: z.number().int().optional(), pagingTransmissionWindow: z.number().int().optional()}); export const coapDeviceProfileTransportConfiguration = z.object({type: z.string(), coapDeviceTypeConfiguration: z.union([defaultCoapDeviceTypeConfiguration, efentoCoapDeviceTypeConfiguration]).optional(), clientSettings: powerSavingConfiguration.optional()}); export const defaultDeviceProfileTransportConfiguration = z.object({type: z.string()}); export const version = z.unknown(); export const lwM2mVersion = z.object({supported: z.boolean().optional()}); export const objectAttributes = z.object({dim: z.number().int().optional(), ssid: z.number().int().optional(), uri: z.string().optional(), ver: version.optional(), lwm2m: lwM2mVersion.optional(), pmin: z.number().int().optional(), pmax: z.number().int().optional(), gt: z.number().optional(), lt: z.number().optional(), st: z.number().optional(), epmin: z.number().int().optional(), epmax: z.number().int().optional()}); export const telemetryMappingConfiguration = z.object({keyName: z.record(z.string(), z.string()).optional(), observe: z.array(z.string()).optional(), attribute: z.array(z.string()).optional(), telemetry: z.array(z.string()).optional(), attributeLwm2m: z.record(z.string(), objectAttributes).optional(), initAttrTelAsObsStrategy: z.boolean().optional(), observeStrategy: z.enum(["SINGLE (0): One resource equals one single observe request", "COMPOSITE_ALL (1): All resources in one composite observe request", "COMPOSITE_BY_OBJECT (2): Grouped composite observe requests by object"]).optional()}); export const noSecLwM2MBootstrapServerCredential = z.object({securityMode: z.string(), shortServerId: z.number().int().optional(), bootstrapServerIs: z.boolean().optional(), host: z.string().optional(), port: z.number().int().optional(), clientHoldOffTime: z.number().int().optional(), serverPublicKey: z.string().optional(), serverCertificate: z.string().optional(), bootstrapServerAccountTimeout: z.number().int().optional(), lifetime: z.number().int().optional(), defaultMinPeriod: z.number().int().optional(), notifIfDisabled: z.boolean().optional(), binding: z.string().optional()}); export const pSKLwM2MBootstrapServerCredential = z.object({securityMode: z.string(), shortServerId: z.number().int().optional(), bootstrapServerIs: z.boolean().optional(), host: z.string().optional(), port: z.number().int().optional(), clientHoldOffTime: z.number().int().optional(), serverPublicKey: z.string().optional(), serverCertificate: z.string().optional(), bootstrapServerAccountTimeout: z.number().int().optional(), lifetime: z.number().int().optional(), defaultMinPeriod: z.number().int().optional(), notifIfDisabled: z.boolean().optional(), binding: z.string().optional()}); export const rPKLwM2MBootstrapServerCredential = z.object({securityMode: z.string(), shortServerId: z.number().int().optional(), bootstrapServerIs: z.boolean().optional(), host: z.string().optional(), port: z.number().int().optional(), clientHoldOffTime: z.number().int().optional(), serverPublicKey: z.string().optional(), serverCertificate: z.string().optional(), bootstrapServerAccountTimeout: z.number().int().optional(), lifetime: z.number().int().optional(), defaultMinPeriod: z.number().int().optional(), notifIfDisabled: z.boolean().optional(), binding: z.string().optional()}); export const x509LwM2MBootstrapServerCredential = z.object({securityMode: z.string(), shortServerId: z.number().int().optional(), bootstrapServerIs: z.boolean().optional(), host: z.string().optional(), port: z.number().int().optional(), clientHoldOffTime: z.number().int().optional(), serverPublicKey: z.string().optional(), serverCertificate: z.string().optional(), bootstrapServerAccountTimeout: z.number().int().optional(), lifetime: z.number().int().optional(), defaultMinPeriod: z.number().int().optional(), notifIfDisabled: z.boolean().optional(), binding: z.string().optional()}); export const otherConfiguration = z.object({useObject19ForOtaInfo: z.boolean().optional(), fwUpdateStrategy: z.number().int().optional(), swUpdateStrategy: z.number().int().optional(), clientOnlyObserveAfterConnect: z.number().int().optional(), powerMode: z.enum(["PSM", "DRX", "E_DRX"]).optional(), psmActivityTimer: z.number().int().optional(), edrxCycle: z.number().int().optional(), pagingTransmissionWindow: z.number().int().optional(), fwUpdateResource: z.string().optional(), swUpdateResource: z.string().optional(), defaultObjectIDVer: z.string().optional()}); export const lwm2mDeviceProfileTransportConfiguration = z.object({type: z.string(), observeAttr: telemetryMappingConfiguration.optional(), bootstrapServerUpdateEnable: z.boolean().optional(), bootstrap: z.array(z.union([noSecLwM2MBootstrapServerCredential, pSKLwM2MBootstrapServerCredential, rPKLwM2MBootstrapServerCredential, x509LwM2MBootstrapServerCredential])).optional(), clientLwM2mSettings: otherConfiguration.optional()}); export const mqttDeviceProfileTransportConfiguration = z.object({type: z.string(), deviceTelemetryTopic: z.string().optional(), deviceAttributesTopic: z.string().optional(), deviceAttributesSubscribeTopic: z.string().optional(), transportPayloadTypeConfiguration: z.union([jsonTransportPayloadConfiguration, protoTransportPayloadConfiguration]).optional(), sparkplug: z.boolean().optional(), sparkplugAttributesMetricNames: z.array(z.string()).optional(), sendAckOnValidationException: z.boolean().optional()}); export const snmpMapping = z.object({oid: z.string().optional(), key: z.string().optional(), dataType: z.enum(["BOOLEAN", "LONG", "DOUBLE", "STRING", "JSON"]).optional()}); export const clientAttributesQueryingSnmpCommunicationConfig = z.object({spec: z.enum(["TELEMETRY_QUERYING", "CLIENT_ATTRIBUTES_QUERYING", "SHARED_ATTRIBUTES_SETTING", "TO_DEVICE_RPC_REQUEST", "TO_SERVER_RPC_REQUEST"]).optional(), mappings: z.array(snmpMapping).optional(), queryingFrequencyMs: z.number().int().optional()}); export const sharedAttributesSettingSnmpCommunicationConfig = z.object({spec: z.enum(["TELEMETRY_QUERYING", "CLIENT_ATTRIBUTES_QUERYING", "SHARED_ATTRIBUTES_SETTING", "TO_DEVICE_RPC_REQUEST", "TO_SERVER_RPC_REQUEST"]).optional(), mappings: z.array(snmpMapping).optional()}); export const telemetryQueryingSnmpCommunicationConfig = z.object({spec: z.enum(["TELEMETRY_QUERYING", "CLIENT_ATTRIBUTES_QUERYING", "SHARED_ATTRIBUTES_SETTING", "TO_DEVICE_RPC_REQUEST", "TO_SERVER_RPC_REQUEST"]).optional(), mappings: z.array(snmpMapping).optional(), queryingFrequencyMs: z.number().int().optional()}); export const toDeviceRpcRequestSnmpCommunicationConfig = z.object({spec: z.enum(["TELEMETRY_QUERYING", "CLIENT_ATTRIBUTES_QUERYING", "SHARED_ATTRIBUTES_SETTING", "TO_DEVICE_RPC_REQUEST", "TO_SERVER_RPC_REQUEST"]).optional(), mappings: z.array(snmpMapping).optional()}); export const toServerRpcRequestSnmpCommunicationConfig = z.object({spec: z.enum(["TELEMETRY_QUERYING", "CLIENT_ATTRIBUTES_QUERYING", "SHARED_ATTRIBUTES_SETTING", "TO_DEVICE_RPC_REQUEST", "TO_SERVER_RPC_REQUEST"]).optional(), mappings: z.array(snmpMapping).optional()}); export const snmpDeviceProfileTransportConfiguration = z.object({type: z.string(), timeoutMs: z.number().int().optional(), retries: z.number().int().optional(), communicationConfigs: z.array(z.union([clientAttributesQueryingSnmpCommunicationConfig, sharedAttributesSettingSnmpCommunicationConfig, telemetryQueryingSnmpCommunicationConfig, toDeviceRpcRequestSnmpCommunicationConfig, toServerRpcRequestSnmpCommunicationConfig])).optional()}); export const allowCreateNewDevicesDeviceProfileProvisionConfiguration = z.object({provisionDeviceSecret: z.string().optional(), type: z.string()}); export const checkPreProvisionedDevicesDeviceProfileProvisionConfiguration = z.object({provisionDeviceSecret: z.string().optional(), type: z.string()}); export const disabledDeviceProfileProvisionConfiguration = z.object({provisionDeviceSecret: z.string().optional(), type: z.string()}); export const x509CertificateChainProvisionConfiguration = z.object({provisionDeviceSecret: z.string().optional(), type: z.string(), certificateRegExPattern: z.string().optional(), allowCreateNewDevicesByX509Certificate: z.boolean().optional()}); export const alarmConditionFilterKey = z.object({type: z.enum(["ATTRIBUTE", "TIME_SERIES", "ENTITY_FIELD", "CONSTANT"]).optional(), key: z.string().optional()}); export const dynamicValueBoolean = z.object({sourceType: z.enum(["CURRENT_TENANT", "CURRENT_CUSTOMER", "CURRENT_USER", "CURRENT_DEVICE"]).optional(), sourceAttribute: z.string().optional(), inherit: z.boolean().optional(), resolvedValue: z.boolean().optional()}); export const filterPredicateValueBoolean = z.object({defaultValue: z.boolean().optional(), userValue: z.boolean().optional(), dynamicValue: dynamicValueBoolean.optional()}); export const booleanFilterPredicate = z.object({type: z.string(), operation: z.enum(["EQUAL", "NOT_EQUAL"]).optional(), value: filterPredicateValueBoolean.optional()}); export const dynamicValueDouble = z.object({sourceType: z.enum(["CURRENT_TENANT", "CURRENT_CUSTOMER", "CURRENT_USER", "CURRENT_DEVICE"]).optional(), sourceAttribute: z.string().optional(), inherit: z.boolean().optional(), resolvedValue: z.number().optional()}); export const filterPredicateValueDouble = z.object({defaultValue: z.number().optional(), userValue: z.number().optional(), dynamicValue: dynamicValueDouble.optional()}); export const numericFilterPredicate = z.object({type: z.string(), operation: z.enum(["EQUAL", "NOT_EQUAL", "GREATER", "LESS", "GREATER_OR_EQUAL", "LESS_OR_EQUAL"]).optional(), value: filterPredicateValueDouble.optional()}); export const dynamicValueString = z.object({sourceType: z.enum(["CURRENT_TENANT", "CURRENT_CUSTOMER", "CURRENT_USER", "CURRENT_DEVICE"]).optional(), sourceAttribute: z.string().optional(), inherit: z.boolean().optional(), resolvedValue: z.string().optional()}); export const filterPredicateValueString = z.object({defaultValue: z.string().optional(), userValue: z.string().optional(), dynamicValue: dynamicValueString.optional()}); export const stringFilterPredicate = z.object({type: z.string(), operation: z.enum(["EQUAL", "NOT_EQUAL", "STARTS_WITH", "ENDS_WITH", "CONTAINS", "NOT_CONTAINS", "IN", "NOT_IN"]).optional(), value: filterPredicateValueString.optional(), ignoreCase: z.boolean().optional()}); export const complexFilterPredicate: z.ZodType = z.object({type: z.string(), operation: z.enum(["AND", "OR"]).optional(), predicates: z.array(z.union([booleanFilterPredicate, z.lazy(() => complexFilterPredicate), numericFilterPredicate, stringFilterPredicate])).optional()}); export const alarmConditionFilter = z.object({key: alarmConditionFilterKey.optional(), valueType: z.enum(["STRING", "NUMERIC", "BOOLEAN", "DATE_TIME"]).optional(), value: z.unknown(), predicate: z.union([booleanFilterPredicate, complexFilterPredicate, numericFilterPredicate, stringFilterPredicate]).optional()}); export const dynamicValueLong = z.object({sourceType: z.enum(["CURRENT_TENANT", "CURRENT_CUSTOMER", "CURRENT_USER", "CURRENT_DEVICE"]).optional(), sourceAttribute: z.string().optional(), inherit: z.boolean().optional(), resolvedValue: z.number().int().optional()}); export const filterPredicateValueLong = z.object({defaultValue: z.number().int().optional(), userValue: z.number().int().optional(), dynamicValue: dynamicValueLong.optional()}); export const durationAlarmConditionSpec = z.object({type: z.string(), unit: z.enum(["NANOSECONDS", "MICROSECONDS", "MILLISECONDS", "SECONDS", "MINUTES", "HOURS", "DAYS"]).optional(), predicate: filterPredicateValueLong.optional()}); export const dynamicValueInteger = z.object({sourceType: z.enum(["CURRENT_TENANT", "CURRENT_CUSTOMER", "CURRENT_USER", "CURRENT_DEVICE"]).optional(), sourceAttribute: z.string().optional(), inherit: z.boolean().optional(), resolvedValue: z.number().int().optional()}); export const filterPredicateValueInteger = z.object({defaultValue: z.number().int().optional(), userValue: z.number().int().optional(), dynamicValue: dynamicValueInteger.optional()}); export const repeatingAlarmConditionSpec = z.object({type: z.string(), predicate: filterPredicateValueInteger.optional()}); export const simpleAlarmConditionSpec = z.object({type: z.string()}); export const alarmCondition = z.object({condition: z.array(alarmConditionFilter).optional(), spec: z.union([durationAlarmConditionSpec, repeatingAlarmConditionSpec, simpleAlarmConditionSpec]).optional()}); export const anyTimeSchedule = z.object({type: z.enum(["ANY_TIME", "SPECIFIC_TIME", "CUSTOM"]).optional(), dynamicValue: dynamicValueString.optional()}); export const customTimeScheduleItem = z.object({enabled: z.boolean().optional(), dayOfWeek: z.number().int().optional(), startsOn: z.number().int().optional(), endsOn: z.number().int().optional()}); export const customTimeSchedule = z.object({type: z.enum(["ANY_TIME", "SPECIFIC_TIME", "CUSTOM"]).optional(), dynamicValue: dynamicValueString.optional(), timezone: z.string().optional(), items: z.array(customTimeScheduleItem).optional()}); export const specificTimeSchedule = z.object({type: z.enum(["ANY_TIME", "SPECIFIC_TIME", "CUSTOM"]).optional(), dynamicValue: dynamicValueString.optional(), timezone: z.string().optional(), daysOfWeek: z.array(z.number().int()).optional(), startsOn: z.number().int().optional(), endsOn: z.number().int().optional()}); export const alarmRule = z.object({condition: alarmCondition.optional(), schedule: z.union([anyTimeSchedule, customTimeSchedule, specificTimeSchedule]).optional(), alarmDetails: z.string().optional(), dashboardId: dashboardId.optional()}); export const deviceProfileAlarm = z.object({id: z.string().optional(), alarmType: z.string().optional(), createRules: z.record(z.string(), alarmRule).optional(), clearRule: alarmRule.optional(), propagate: z.boolean().optional(), propagateToOwner: z.boolean().optional(), propagateToTenant: z.boolean().optional(), propagateRelationTypes: z.array(z.string()).optional()}); export const deviceProfileData = z.object({configuration: defaultDeviceProfileConfiguration.optional(), transportConfiguration: z.union([coapDeviceProfileTransportConfiguration, defaultDeviceProfileTransportConfiguration, lwm2mDeviceProfileTransportConfiguration, mqttDeviceProfileTransportConfiguration, snmpDeviceProfileTransportConfiguration]).optional(), provisionConfiguration: z.union([allowCreateNewDevicesDeviceProfileProvisionConfiguration, checkPreProvisionedDevicesDeviceProfileProvisionConfiguration, disabledDeviceProfileProvisionConfiguration, x509CertificateChainProvisionConfiguration]).optional(), alarms: z.array(deviceProfileAlarm).optional()}); export const deviceProfile = z.object({id: deviceProfileId.optional(), createdTime: z.number().int().optional(), tenantId: tenantId.optional(), name: z.string().optional(), description: z.string().optional(), image: z.string().optional(), type: z.literal("DEFAULT").optional(), transportType: z.enum(["DEFAULT", "MQTT", "COAP", "LWM2M", "SNMP"]).optional(), provisionType: z.enum(["DISABLED", "ALLOW_CREATE_NEW_DEVICES", "CHECK_PRE_PROVISIONED_DEVICES", "X509_CERTIFICATE_CHAIN"]).optional(), defaultRuleChainId: ruleChainId.optional(), defaultDashboardId: dashboardId.optional(), defaultQueueName: z.string().optional(), provisionDeviceKey: z.string().optional(), firmwareId: otaPackageId.optional(), softwareId: otaPackageId.optional(), defaultEdgeRuleChainId: ruleChainId.optional(), version: z.number().int().optional(), default: z.boolean().optional(), profileData: deviceProfileData.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 }; /** * Create Or Update Device Profile (saveDeviceProfile) * * POST /api/deviceProfile */ export const createApiApiDeviceProfile = async (args: CreateApiApiDeviceProfileArgs, options?: CreateApiApiDeviceProfileOptions) => { const {baseUrl = "https://demo.thingsboard.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/deviceProfile${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(deviceProfile, await res.json()) };