ts-onvif
Version:
Client to ONVIF devices
305 lines • 11.3 kB
JavaScript
;
/**
* AuthenticationBehavior ver10 module
* @author Andrew D.Laptev <a.d.laptev@gmail.com>
* @see https://www.onvif.org/ver10/authenticationbehavior/wsdl
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthenticationBehavior = void 0;
const service_1 = __importDefault(require("./service"));
/**
* AuthenticationBehavior service
* @example
* ```ts
* const profiles = await cam.authenticationBehavior.getAuthenticationProfileList();
* const token = profiles.authenticationProfile![0].token;
* const levels = await cam.authenticationBehavior.getSecurityLevelList();
* ```
*/
class AuthenticationBehavior extends service_1.default {
constructor(onvif, service) {
super(onvif, service);
}
static tokensToBuild(tokens) {
if (!tokens?.length) {
return undefined;
}
return tokens.length === 1 ? tokens[0] : tokens;
}
static oneOrMany(items, builder) {
if (!items?.length) {
return undefined;
}
const built = items.map((item) => builder(item));
return built.length === 1 ? built[0] : built;
}
static securityLevelConstraintToBuild(constraint) {
return {
ActiveRegularSchedule: constraint.activeRegularSchedule,
ActiveSpecialDaySchedule: constraint.activeSpecialDaySchedule,
...(constraint.authenticationMode && { AuthenticationMode: constraint.authenticationMode }),
SecurityLevelToken: constraint.securityLevelToken,
...(constraint.extension && { Extension: constraint.extension }),
};
}
static authenticationPolicyToBuild(policy) {
return {
ScheduleToken: policy.scheduleToken,
SecurityLevelConstraint: AuthenticationBehavior.oneOrMany(policy.securityLevelConstraint, AuthenticationBehavior.securityLevelConstraintToBuild),
...(policy.extension && { Extension: policy.extension }),
};
}
static recognitionMethodToBuild(method) {
return {
RecognitionType: method.recognitionType,
Order: method.order,
...(method.extension && { Extension: method.extension }),
};
}
static recognitionGroupToBuild(group) {
return {
...(group.recognitionMethod && {
RecognitionMethod: AuthenticationBehavior.oneOrMany(group.recognitionMethod, AuthenticationBehavior.recognitionMethodToBuild),
}),
...(group.extension && { Extension: group.extension }),
};
}
static authenticationProfileInfoToBuild(profile) {
return {
$: { token: profile.token },
Name: profile.name,
...(profile.description && { Description: profile.description }),
};
}
static authenticationProfileToBuild(profile) {
return {
...AuthenticationBehavior.authenticationProfileInfoToBuild(profile),
DefaultSecurityLevelToken: profile.defaultSecurityLevelToken,
...(profile.authenticationPolicy && {
AuthenticationPolicy: AuthenticationBehavior.oneOrMany(profile.authenticationPolicy, AuthenticationBehavior.authenticationPolicyToBuild),
}),
...(profile.extension && { Extension: profile.extension }),
};
}
static securityLevelInfoToBuild(level) {
return {
$: { token: level.token },
Name: level.name,
Priority: level.priority,
...(level.description && { Description: level.description }),
};
}
static securityLevelToBuild(level) {
return {
...AuthenticationBehavior.securityLevelInfoToBuild(level),
...(level.recognitionGroup && {
RecognitionGroup: AuthenticationBehavior.oneOrMany(level.recognitionGroup, AuthenticationBehavior.recognitionGroupToBuild),
}),
...(level.extension && { Extension: level.extension }),
};
}
/**
* Returns the capabilities of the authentication behavior service.
*/
async getServiceCapabilities() {
const response = await this.request({
GetServiceCapabilities: {},
});
return response.getServiceCapabilitiesResponse?.capabilities ?? {};
}
/**
* Returns authentication profile info items for the requested tokens.
* @param options
*/
async getAuthenticationProfileInfo({ token, }) {
const response = await this.request({
GetAuthenticationProfileInfo: {
Token: AuthenticationBehavior.tokensToBuild(token),
},
}, { array: ['authenticationProfileInfo'] });
return response.getAuthenticationProfileInfoResponse ?? {};
}
/**
* Returns a list of authentication profile info items.
* @param options
*/
async getAuthenticationProfileInfoList(options = {}) {
const response = await this.request({
GetAuthenticationProfileInfoList: {
...(options.limit !== undefined && { Limit: options.limit }),
...(options.startReference && { StartReference: options.startReference }),
},
}, { array: ['authenticationProfileInfo'] });
return response.getAuthenticationProfileInfoListResponse ?? {};
}
/**
* Returns authentication profile items for the requested tokens.
* @param options
*/
async getAuthenticationProfiles({ token, }) {
const response = await this.request({
GetAuthenticationProfiles: {
Token: AuthenticationBehavior.tokensToBuild(token),
},
}, { array: ['authenticationProfile'] });
return response.getAuthenticationProfilesResponse ?? {};
}
/**
* Returns a list of authentication profile items.
* @param options
*/
async getAuthenticationProfileList(options = {}) {
const response = await this.request({
GetAuthenticationProfileList: {
...(options.limit !== undefined && { Limit: options.limit }),
...(options.startReference && { StartReference: options.startReference }),
},
}, { array: ['authenticationProfile'] });
return response.getAuthenticationProfileListResponse ?? {};
}
/**
* Creates a new authentication profile.
* @param options
*/
async createAuthenticationProfile({ authenticationProfile, }) {
const response = await this.request({
CreateAuthenticationProfile: {
AuthenticationProfile: AuthenticationBehavior.authenticationProfileToBuild(authenticationProfile),
},
});
return response.createAuthenticationProfileResponse.token;
}
/**
* Creates or replaces an authentication profile (requires ClientSuppliedTokenSupported).
* @param options
*/
async setAuthenticationProfile({ authenticationProfile }) {
await this.request({
SetAuthenticationProfile: {
AuthenticationProfile: AuthenticationBehavior.authenticationProfileToBuild(authenticationProfile),
},
});
}
/**
* Modifies an existing authentication profile.
* @param options
*/
async modifyAuthenticationProfile({ authenticationProfile }) {
await this.request({
ModifyAuthenticationProfile: {
AuthenticationProfile: AuthenticationBehavior.authenticationProfileToBuild(authenticationProfile),
},
});
}
/**
* Deletes an authentication profile.
* @param options
*/
async deleteAuthenticationProfile({ token }) {
await this.request({
DeleteAuthenticationProfile: {
Token: token,
},
});
}
/**
* Returns security level info items for the requested tokens.
* @param options
*/
async getSecurityLevelInfo({ token }) {
const response = await this.request({
GetSecurityLevelInfo: {
Token: AuthenticationBehavior.tokensToBuild(token),
},
}, { array: ['securityLevelInfo'] });
return response.getSecurityLevelInfoResponse ?? {};
}
/**
* Returns a list of security level info items.
* @param options
*/
async getSecurityLevelInfoList(options = {}) {
const response = await this.request({
GetSecurityLevelInfoList: {
...(options.limit !== undefined && { Limit: options.limit }),
...(options.startReference && { StartReference: options.startReference }),
},
}, { array: ['securityLevelInfo'] });
return response.getSecurityLevelInfoListResponse ?? {};
}
/**
* Returns security level items for the requested tokens.
* @param options
*/
async getSecurityLevels({ token }) {
const response = await this.request({
GetSecurityLevels: {
Token: AuthenticationBehavior.tokensToBuild(token),
},
}, { array: ['securityLevel'] });
return response.getSecurityLevelsResponse ?? {};
}
/**
* Returns a list of security level items.
* @param options
*/
async getSecurityLevelList(options = {}) {
const response = await this.request({
GetSecurityLevelList: {
...(options.limit !== undefined && { Limit: options.limit }),
...(options.startReference && { StartReference: options.startReference }),
},
}, { array: ['securityLevel'] });
return response.getSecurityLevelListResponse ?? {};
}
/**
* Creates a new security level.
* @param options
*/
async createSecurityLevel({ securityLevel }) {
const response = await this.request({
CreateSecurityLevel: {
SecurityLevel: AuthenticationBehavior.securityLevelToBuild(securityLevel),
},
});
return response.createSecurityLevelResponse.token;
}
/**
* Creates or replaces a security level (requires ClientSuppliedTokenSupported).
* @param options
*/
async setSecurityLevel({ securityLevel }) {
await this.request({
SetSecurityLevel: {
SecurityLevel: AuthenticationBehavior.securityLevelToBuild(securityLevel),
},
});
}
/**
* Modifies an existing security level.
* @param options
*/
async modifySecurityLevel({ securityLevel }) {
await this.request({
ModifySecurityLevel: {
SecurityLevel: AuthenticationBehavior.securityLevelToBuild(securityLevel),
},
});
}
/**
* Deletes a security level.
* @param options
*/
async deleteSecurityLevel({ token }) {
await this.request({
DeleteSecurityLevel: {
Token: token,
},
});
}
}
exports.AuthenticationBehavior = AuthenticationBehavior;
//# sourceMappingURL=authenticationbehavior.js.map