UNPKG

@dodi-smart/nuki-graphql-api

Version:
277 lines 12.7 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const builder_1 = require("../builder"); const session_1 = require("../session"); const utils_1 = require("../utils"); const graphql_1 = require("graphql"); builder_1.builder.objectType('Nuki', { fields: (t) => ({ account: t.field({ type: 'NukiAccount', resolve: (_parent, {}, context) => __awaiter(void 0, void 0, void 0, function* () { const { isAllowed } = context; if (!(yield isAllowed(context))) { throw new graphql_1.GraphQLError('Not allowed'); } const account = yield session_1.authHolder.appClient.account.getAccount(); return account; }) }), smartlock: t.field({ nullable: true, type: 'NukiSmartlock', args: { smartlockId: t.arg.string({ required: true }) }, resolve: (_parent, { smartlockId }, context) => __awaiter(void 0, void 0, void 0, function* () { const { isAllowed } = context; if (!(yield isAllowed(context))) { throw new graphql_1.GraphQLError('Not allowed'); } const smartlock = yield session_1.authHolder.appClient.smartlock.getSmartlock(+smartlockId); return smartlock; }) }), smartlocks: t.field({ type: ['NukiSmartlock'], resolve: (_parent, {}, context) => __awaiter(void 0, void 0, void 0, function* () { const { isAllowed } = context; if (!(yield isAllowed(context))) { throw new graphql_1.GraphQLError('Not allowed'); } const smartlocks = yield session_1.authHolder.appClient.smartlock.getSmartlocks(); return smartlocks; }) }) }) }); builder_1.builder.objectType('NukiMutations', { fields: (t) => ({ lockSmartlock: t.field({ type: 'Boolean', args: { smartlockId: t.arg.string({ required: true }) }, resolve: (_, { smartlockId }, context) => __awaiter(void 0, void 0, void 0, function* () { const { isAllowed } = context; if (!(yield isAllowed(context))) { throw new graphql_1.GraphQLError('Not allowed'); } yield session_1.authHolder.appClient.smartlock.lockSmartlock(smartlockId); return true; }) }), advancedLockSmartlock: t.field({ type: 'String', args: { smartlockId: t.arg.string({ required: true, description: 'A UUID to identify the upcoming asynchronously web hook response' }) }, resolve: (_, { smartlockId }, context) => __awaiter(void 0, void 0, void 0, function* () { const { isAllowed } = context; if (!(yield isAllowed(context))) { throw new graphql_1.GraphQLError('Not allowed'); } const res = yield session_1.authHolder.appClient.advancedApi.lockSmartlockAdvanced(smartlockId); return res.requestId; }) }), unlockSmartlock: t.field({ type: 'Boolean', args: { smartlockId: t.arg.string({ required: true }) }, resolve: (_, { smartlockId }, context) => __awaiter(void 0, void 0, void 0, function* () { const { isAllowed } = context; if (!(yield isAllowed(context))) { throw new graphql_1.GraphQLError('Not allowed'); } yield session_1.authHolder.appClient.smartlock.unlockSmartlock(smartlockId); return true; }) }), advancedUnlockSmartlock: t.field({ type: 'String', args: { smartlockId: t.arg.string({ required: true, description: 'A UUID to identify the upcoming asynchronously web hook response' }) }, resolve: (_, { smartlockId }, context) => __awaiter(void 0, void 0, void 0, function* () { const { isAllowed } = context; if (!(yield isAllowed(context))) { throw new graphql_1.GraphQLError('Not allowed'); } const res = yield session_1.authHolder.appClient.advancedApi.unlockSmartlockAdvanced(smartlockId); return res.requestId; }) }), operateSmartlock: t.field({ type: 'Boolean', args: { smartlockId: t.arg.string({ required: true }), action: t.arg.int({ description: "The action: type=0: 1 .. unlock, 2 .. lock, 3 .. unlatch, 4 .. lock 'n' go, 5 .. lock 'n' go with unlatch; type=1: 1 .. unlock; type=2: 1 activate ring to open, 2 .. deactivate ring to open, 3 .. open (electric strike actuation), 6 ... activate continuous mode, 7 ... deactivate continuous mode", required: true }), option: t.arg.int({ description: 'The option mask: 0 .. none, 2 .. force, 4 .. full lock', required: false }) }, resolve: (_, { smartlockId, action, option }, context) => __awaiter(void 0, void 0, void 0, function* () { const { isAllowed } = context; if (!(yield isAllowed(context))) { throw new graphql_1.GraphQLError('Not allowed'); } yield session_1.authHolder.appClient.smartlock.operateSmartlock(smartlockId, { action, option: (0, utils_1.fixNumberNullable)(option) }); return true; }) }), advancedOperateSmartlock: t.field({ type: 'String', args: { smartlockId: t.arg.string({ required: true, description: 'A UUID to identify the upcoming asynchronously web hook response' }), action: t.arg.int({ description: "The action: type=0: 1 .. unlock, 2 .. lock, 3 .. unlatch, 4 .. lock 'n' go, 5 .. lock 'n' go with unlatch; type=1: 1 .. unlock; type=2: 1 activate ring to open, 2 .. deactivate ring to open, 3 .. open (electric strike actuation), 6 ... activate continuous mode, 7 ... deactivate continuous mode", required: true }), option: t.arg.int({ description: 'The option mask: 0 .. none, 2 .. force, 4 .. full lock', required: false }) }, resolve: (_, { smartlockId, action, option }, context) => __awaiter(void 0, void 0, void 0, function* () { const { isAllowed } = context; if (!(yield isAllowed(context))) { throw new graphql_1.GraphQLError('Not allowed'); } const res = yield session_1.authHolder.appClient.advancedApi.operateSmartlockAdvanced(smartlockId, { action, option: (0, utils_1.fixNumberNullable)(option) }); return res.requestId; }) }), syncSmartlock: t.field({ type: 'Boolean', args: { smartlockId: t.arg.string({ required: true }) }, resolve: (_, { smartlockId }, context) => __awaiter(void 0, void 0, void 0, function* () { const { isAllowed } = context; if (!(yield isAllowed(context))) { throw new graphql_1.GraphQLError('Not allowed'); } yield session_1.authHolder.appClient.smartlock.syncSmartlock(smartlockId); return true; }) }), advancedCreateSmartlockAuthorization: t.field({ type: 'String', args: { name: t.arg.string({ required: true, description: 'The name of the authorization (max 32 chars)' }), accountUserId: t.arg.int({ required: true, description: 'The id of the linked account user' }), smartlockIds: t.arg.intList({ required: true, description: 'The list of smartlock ids' }), remoteAllowed: t.arg.boolean({ required: true, defaultValue: false, description: 'True if the auth has remote access' }), allowedFromDate: t.arg.string({ required: false, description: 'The allowed from date' }), allowedUntilDate: t.arg.string({ required: false, description: 'The allowed until date' }), allowedWeekDays: t.arg.int({ required: false, description: 'The allowed weekdays bitmask: 64 .. monday, 32 .. tuesday, 16 .. wednesday, 8 .. thursday, 4 .. friday, 2 .. saturday, 1 .. sunday' }), allowedFromTime: t.arg.int({ required: false, description: 'The allowed from time (in minutes from midnight)' }), allowedUntilTime: t.arg.int({ required: false, description: 'The allowed until time (in minutes from midnight)' }), smartActionsEnabled: t.arg.boolean({ required: false, description: 'The smart actions enabled flag' }) }, resolve: (_, { name, accountUserId, smartlockIds, remoteAllowed, allowedFromDate, allowedUntilDate, allowedWeekDays, allowedFromTime, allowedUntilTime, smartActionsEnabled }, context) => __awaiter(void 0, void 0, void 0, function* () { const { isAllowed } = context; if (!(yield isAllowed(context))) { throw new graphql_1.GraphQLError('Not allowed'); } const res = yield session_1.authHolder.appClient.advancedApi.createSmartlockAuthsAdvanced({ name: name.substring(0, 32), accountUserId, smartlockIds, remoteAllowed, allowedFromDate: (0, utils_1.fixStringNullable)(allowedFromDate), allowedUntilDate: (0, utils_1.fixStringNullable)(allowedUntilDate), allowedWeekDays: (0, utils_1.fixNumberNullable)(allowedWeekDays), allowedFromTime: (0, utils_1.fixNumberNullable)(allowedFromTime), allowedUntilTime: (0, utils_1.fixNumberNullable)(allowedUntilTime), smartActionsEnabled: (0, utils_1.fixBooleanNullable)(smartActionsEnabled) }); return res.requestId; }) }) }) }); builder_1.builder.queryFields((t) => ({ nuki: t.field({ type: 'Nuki', resolve: () => ({}) }) })); builder_1.builder.mutationFields((t) => ({ nuki: t.field({ type: 'NukiMutations', resolve: () => ({}) }) })); //# sourceMappingURL=nuki.js.map