Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@makeflow/gateway-server

Package Overview
Dependencies
Maintainers
7
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@makeflow/gateway-server - npm Package Compare versions

Comparing version 0.1.0-alpha.5 to 0.1.0-alpha.6

migrations/001-initial-schema.sql

9

bld/api/command.js

@@ -58,4 +58,11 @@ "use strict";

router.post('/command/:name/execute', rpcService.processor(async ({ name, parameters }) => {
await commandService.enqueueCommandAndTryToExecute(name, parameters);
await commandService.enqueueCommandAndTryToExecute(name, parameters, true);
}, {
authorization: true,
token: false,
requiredParams: ['parameters'],
}));
router.post('/command/:name/enqueue', rpcService.processor(async ({ name, parameters, waiting }, {}, { tokenLabel }) => {
await commandService.enqueueCommandAndTryToExecute(name, parameters, false, tokenLabel, !!waiting);
}, {
authorization: false,

@@ -62,0 +69,0 @@ token: true,

@@ -37,3 +37,3 @@ "use strict";

}));
router.post('/makeflow/power-item/action/:action', rpcService.processor(async ({ action, token, configs, inputs }) => {
router.post('/makeflow/power-item/:item/action/:action', rpcService.processor(async ({ action, token, configs, inputs }) => {
let { token: configToken } = configs;

@@ -49,4 +49,8 @@ if (typeof token !== 'string') {

}));
// To fit power item related api
router.post('/makeflow/power-item/:item/(activate|update|deactivate)', rpcService.processor(() => { }, { authorization: false, token: false }));
// To fit app installation related api
router.post('/makeflow/installation/(activate|update|deactivate)', rpcService.processor(() => { }, { authorization: false, token: false }));
}
exports.routeMakeflow = routeMakeflow;
//# sourceMappingURL=makeflow.js.map

7

bld/services/command-service.d.ts

@@ -24,3 +24,3 @@ /// <reference types="node" />

private commandsPath;
private readonly commandsConfigPath;
private get commandsConfigPath();
constructor(configService: ConfigService, fileService: FileService, dbService: DBService, adapterMap: Map<string, ICommandAdapter>, commandsPath: string);

@@ -30,4 +30,5 @@ updateConfigURL(url: string): Promise<void>;

getCommandsConfig(): Promise<CommandsConfig | undefined>;
enqueueCommand(name: string, parameters?: CommandParameters): Promise<Command>;
enqueueCommandAndTryToExecute(name: string, parameters?: CommandParameters, waiting?: boolean): Promise<Command>;
requireCommandsConfig(): Promise<CommandsConfig>;
enqueueCommand(name: string, parameters?: CommandParameters, tokenName?: string): Promise<Command>;
enqueueCommandAndTryToExecute(name: string, parameters: CommandParameters | undefined, immediate: boolean, tokenLabel?: string, waiting?: boolean): Promise<Command>;
executeCommandFromQueue(id: number): Promise<void>;

@@ -34,0 +35,0 @@ getCommandHistoryItems({ before: beforeId, after: afterId, limit, }: GetCommandHistoryItemsOptions): Promise<Command[]>;

@@ -44,3 +44,10 @@ "use strict";

}
async enqueueCommand(name, parameters = {}) {
async requireCommandsConfig() {
let config = await this.getCommandsConfig();
if (!config) {
throw new gateway_shared_1.ExpectedError('COMMANDS_CONFIG_NOT_FOUND', 'The commands config file was not found');
}
return config;
}
async enqueueCommand(name, parameters = {}, tokenName) {
let { type, source, parameters: parametersConfig = [], manual = true, } = await this.requireCommandConfig(name);

@@ -55,2 +62,3 @@ let { filteredParameters, deniedParameters } = filterParameters(parameters, parametersConfig);

manual,
from: tokenName,
createdAt: Date.now(),

@@ -64,5 +72,5 @@ };

}
async enqueueCommandAndTryToExecute(name, parameters = {}, waiting = false) {
let command = await this.enqueueCommand(name, parameters);
if (!command.manual) {
async enqueueCommandAndTryToExecute(name, parameters = {}, immediate, tokenLabel, waiting = false) {
let command = await this.enqueueCommand(name, parameters, tokenLabel);
if (!command.manual || immediate) {
if (waiting) {

@@ -86,3 +94,3 @@ await this.executeCommand(command);

if (beforeId && afterId) {
throw new gateway_shared_1.ExpectedError('"after" and "before" cannot appear at the same time');
throw new gateway_shared_1.ExpectedError('INCORRECT_PARAMETERS', '"after" and "before" cannot appear at the same time');
}

@@ -113,3 +121,3 @@ let query = sql_template_strings_1.default `SELECT * FROM commands`;

if (!adapter) {
throw new gateway_shared_1.ExpectedError('COMMAND_ADAPTER_NOT_FOUND');
throw new gateway_shared_1.ExpectedError('COMMAND_ADAPTER_NOT_FOUND', `The adapter for type "${command.type}" was not found`);
}

@@ -137,16 +145,13 @@ let { options } = await this.requireCommandConfig(command.name);

async requireCommandConfig(name) {
let config = await this.getCommandsConfig();
if (!config) {
throw new gateway_shared_1.ExpectedError('COMMANDS_CONFIG_NOT_FOUND');
}
let config = await this.requireCommandsConfig();
let commandConfig = config.commands.find(config => config.name === name);
if (!commandConfig) {
throw new gateway_shared_1.ExpectedError('COMMAND_CONFIG_NOT_FOUND');
throw new gateway_shared_1.ExpectedError('COMMAND_CONFIG_NOT_FOUND', `The command config for name "${name}" was not found`);
}
return commandConfig;
}
async insertCommandHistoryItem({ name, type, source, manual, parameters, deniedParameters, createdAt, }) {
async insertCommandHistoryItem({ name, type, source, manual, parameters, deniedParameters, from, createdAt, }) {
let statement = await this.dbService.db.run(sql_template_strings_1.default `INSERT INTO commands
(name, type, source, manual, parameters, denied_parameters, created_at)
VALUES (${name}, ${type}, ${source}, ${manual}, ${JSON.stringify(parameters)}, ${JSON.stringify(deniedParameters)}, ${createdAt})`);
(name, type, source, manual, parameters, denied_parameters, "from", created_at)
VALUES (${name}, ${type}, ${source}, ${manual}, ${JSON.stringify(parameters)}, ${JSON.stringify(deniedParameters)}, ${from}, ${createdAt})`);
return statement.lastID;

@@ -167,3 +172,3 @@ }

function convertCommandHistoryItemDocToCommandHistoryItem(doc) {
let { id, name, type, source, manual, parameters, denied_parameters, output, error, created_at, executed_at, } = doc;
let { id, name, type, source, manual, parameters, denied_parameters, from, output, error, created_at, executed_at, } = doc;
return {

@@ -177,2 +182,3 @@ id,

deniedParameters: denied_parameters && JSON.parse(denied_parameters),
from,
result: {

@@ -234,3 +240,3 @@ output,

if (config.required && typeof resolvedValue === 'undefined') {
throw new gateway_shared_1.ExpectedError('CANNOT_RESOLVE_OPTION');
throw new gateway_shared_1.ExpectedError('CANNOT_RESOLVE_OPTION', `The value of "${config.key}" cannot be resolved`);
}

@@ -237,0 +243,0 @@ return resolvedValue;

@@ -5,5 +5,5 @@ import { Database } from 'sqlite';

private _db;
readonly db: Database;
get db(): Database;
constructor(path: string);
private initialize;
}

@@ -8,8 +8,8 @@ "use strict";

class DBService {
constructor(path) {
this.ready = this.initialize(path);
}
get db() {
return this._db;
}
constructor(path) {
this.ready = this.initialize(path);
}
async initialize(path) {

@@ -16,0 +16,0 @@ let dirname = Path.dirname(path);

import { MFUserCandidate } from '@makeflow/gateway-shared';
import { PowerApp } from '@makeflow/types';
import { Dict } from 'tslang';
import { MFPowerAppDefinition } from '../types';
import { APIService } from './api-service';

@@ -18,3 +18,3 @@ import { CommandService } from './command-service';

publishApp(): Promise<void>;
generateAppDefinition(): Promise<MFPowerAppDefinition>;
generateAppDefinition(): Promise<PowerApp.RawDefinition>;
authenticate(username: string, password: string, userId: string): Promise<void>;

@@ -21,0 +21,0 @@ processAction(action: string, token: string, powerItemToken: string, inputs: Dict<unknown>): Promise<void>;

@@ -37,11 +37,8 @@ "use strict";

async generateAppDefinition() {
let commandsConfig = await this.commandService.getCommandsConfig();
let commandsConfig = await this.commandService.requireCommandsConfig();
let { externalURL, makeflowPowerAppName, } = await this.configService.getConfig();
if (!commandsConfig) {
throw new gateway_shared_1.ExpectedError('MISSING_COMMANDS_CONFIG', 'To publish makeflow power app require commands config');
}
if (!externalURL) {
throw new gateway_shared_1.ExpectedError('MISSING_REQUIRED_CONFIGS', 'To publish makeflow power app require "externalURL" config');
}
let powerItemBaseURL = `${externalURL}/api/makeflow/power-item`;
let hookBaseURL = `${externalURL}/api/makeflow`;
return {

@@ -53,2 +50,3 @@ name: makeflowPowerAppName,

description: 'Makeflow Gateway 自动生成的 APP.',
hookBaseURL,
configs: [

@@ -63,3 +61,3 @@ {

contributions: {
powerItems: convertCommandConfigsToPowerItemDefinitions(commandsConfig.commands, powerItemBaseURL),
powerItems: convertCommandConfigsToPowerItemDefinitions(commandsConfig.commands),
},

@@ -75,4 +73,4 @@ };

async processAction(action, token, powerItemToken, inputs) {
await this.tokenService.validateToken(token);
let command = await this.commandService.enqueueCommand(action, inputs);
let tokenLabel = await this.tokenService.validateToken(token);
let command = await this.commandService.enqueueCommand(action, inputs, tokenLabel);
await this.insertPowerItem(command.id, powerItemToken);

@@ -160,3 +158,3 @@ if (!command.manual) {

async updatePowerItemResponse(id, response) {
await this.dbService.db.run(sql_template_strings_1.default `UPDATE makeflow_power_item_tokens SET response=${response} WHERE id=${id}`);
await this.dbService.db.run(sql_template_strings_1.default `UPDATE makeflow_power_items SET response=${response} WHERE id=${id}`);
}

@@ -190,12 +188,11 @@ initialize() {

exports.MakeflowService = MakeflowService;
function convertCommandConfigsToPowerItemDefinitions(configs, powerItemBaseURL) {
function convertCommandConfigsToPowerItemDefinitions(configs) {
return configs.map(({ name, parameters = [] }) => {
return {
name,
name: name,
displayName: name,
hookBaseURL: powerItemBaseURL,
fields: parameters.map(convertCommandConfigParameterToPowerItemField),
actions: [
{
name,
name: name,
displayName: '执行命令',

@@ -211,3 +208,3 @@ inputs: parameters.map(convertCommandConfigParamaterToPowerItemActionInput),

return {
name,
name: name,
type: 'variable',

@@ -219,3 +216,2 @@ variable: name,

let name = typeof parameter === 'string' ? parameter : parameter.name;
// TODO: Waiting for '@makeflow/types'
return {

@@ -222,0 +218,0 @@ base: 'input',

@@ -6,3 +6,6 @@ import Koa, { ParameterizedContext } from 'koa';

import { TokenService } from './token-service';
export declare type RPCProcessor = (paramDict: Dict<any>, context: Readonly<ParameterizedContext<void, KoaCustomType>>) => any;
export declare type RPCProcessor = (paramDict: Dict<any>, context: Readonly<ParameterizedContext<void, KoaCustomType>>, options: RPCProcessorOptions) => any;
export interface RPCProcessorOptions {
tokenLabel: string | undefined;
}
export interface RPCResultError {

@@ -16,3 +19,3 @@ code: string;

}
export interface RPCProcessorOptions {
export interface RPCServiceProcessorOptions {
authorization?: boolean;

@@ -26,5 +29,5 @@ token?: boolean;

constructor(configService: ConfigService, tokenService: TokenService);
processor(processor: RPCProcessor, { authorization, token, requiredParams, }?: RPCProcessorOptions): Koa.Middleware<void, KoaCustomType>;
processor(processor: RPCProcessor, { authorization: authorizationRequired, token: tokenRequired, requiredParams, }?: RPCServiceProcessorOptions): Koa.Middleware<void, KoaCustomType>;
authenticator(): Koa.Middleware<void, KoaCustomType>;
private validateToken;
}

@@ -9,11 +9,12 @@ "use strict";

}
processor(processor, { authorization = true, token = true, requiredParams = [], } = {}) {
processor(processor, { authorization: authorizationRequired = true, token: tokenRequired = true, requiredParams = [], } = {}) {
return async (context, next) => {
let result;
try {
if (authorization && !context.session.logged) {
if (authorizationRequired && !context.session.logged) {
throw new gateway_shared_1.ExpectedError('AUTHORIZATION_REQUIRED');
}
if (token) {
await this.validateToken(context);
let tokenLabel;
if (tokenRequired) {
tokenLabel = await this.validateToken(context);
}

@@ -23,3 +24,3 @@ let existedFields = Object.entries(context.request.body || {}).map(([key]) => key);

if (!requiredParams.every(field => existedFields.includes(field))) {
throw new gateway_shared_1.ExpectedError('MISSING_REQUIRED_FIELD', `Missing required field ${missingFields
throw new gateway_shared_1.ExpectedError('MISSING_REQUIRED_FIELD', `Missing required fields ${missingFields
.map(fieldName => `"${fieldName}"`)

@@ -29,3 +30,3 @@ .join(', ')}`);

let params = { ...context.params, ...context.request.body };
let processorResult = await processor(params, context);
let processorResult = await processor(params, context, { tokenLabel });
result = {

@@ -87,3 +88,3 @@ data: processorResult,

}
await this.tokenService.validateToken(token);
return this.tokenService.validateToken(token);
}

@@ -90,0 +91,0 @@ }

@@ -8,3 +8,3 @@ import { Token } from '@makeflow/gateway-shared';

deactivateToken(id: number): Promise<void>;
validateToken(token: string): Promise<void>;
validateToken(token: string): Promise<string>;
getActiveTokens(): Promise<Token[]>;

@@ -11,0 +11,0 @@ private findActiveTokenByHash;

@@ -27,2 +27,3 @@ "use strict";

}
return activeToken.label;
}

@@ -29,0 +30,0 @@ async getActiveTokens() {

@@ -10,2 +10,3 @@ import { CommandConfig } from '@makeflow/gateway-shared';

denied_parameters?: string;
from?: string;
created_at: number;

@@ -12,0 +13,0 @@ executed_at?: number;

@@ -5,3 +5,2 @@ export * from './command';

export * from './token';
export * from './power-app';
export * from './makeflow';
export declare type PowerItemResponse = undefined | 'completed' | 'error';
export interface PowerItem {
export interface PowerItemData {
id: number;

@@ -4,0 +4,0 @@ commandId: number;

{
"name": "@makeflow/gateway-server",
"description": "Makeflow gateway server package",
"version": "0.1.0-alpha.5",
"version": "0.1.0-alpha.6",
"author": "Chengdu Mufan Technology Co., Ltd.",

@@ -18,3 +18,5 @@ "license": "MIT",

"dependencies": {
"@makeflow/gateway-shared": "^0.1.0-alpha.5",
"@makeflow/gateway-shared": "^0.1.0-alpha.6",
"@makeflow/types": "^0.1.2",
"@makeflow/types-nominal": "^0.1.1",
"koa": "^2.7.0",

@@ -58,3 +60,3 @@ "koa-bodyparser": "^4.2.1",

},
"gitHead": "37a71aa5805981827a548c423a1eef8908380759"
"gitHead": "0ea402e29455fece10b03f8e3626a281f8c2d58f"
}

@@ -124,5 +124,29 @@ import Router from 'koa-router';

async ({name, parameters}) => {
await commandService.enqueueCommandAndTryToExecute(name, parameters);
await commandService.enqueueCommandAndTryToExecute(
name,
parameters,
true,
);
},
{
authorization: true,
token: false,
requiredParams: ['parameters'],
},
),
);
router.post(
'/command/:name/enqueue',
rpcService.processor(
async ({name, parameters, waiting}, {}, {tokenLabel}) => {
await commandService.enqueueCommandAndTryToExecute(
name,
parameters,
false,
tokenLabel,
!!waiting,
);
},
{
authorization: false,

@@ -129,0 +153,0 @@ token: true,

@@ -80,3 +80,3 @@ import {ExpectedError} from '@makeflow/gateway-shared';

router.post(
'/makeflow/power-item/action/:action',
'/makeflow/power-item/:item/action/:action',
rpcService.processor(

@@ -99,2 +99,14 @@ async ({action, token, configs, inputs}) => {

);
// To fit power item related api
router.post(
'/makeflow/power-item/:item/(activate|update|deactivate)',
rpcService.processor(() => {}, {authorization: false, token: false}),
);
// To fit app installation related api
router.post(
'/makeflow/installation/(activate|update|deactivate)',
rpcService.processor(() => {}, {authorization: false, token: false}),
);
}

@@ -85,5 +85,19 @@ import {exec as _exec, execFile as _execFile} from 'child_process';

async requireCommandsConfig(): Promise<CommandsConfig> {
let config = await this.getCommandsConfig();
if (!config) {
throw new ExpectedError(
'COMMANDS_CONFIG_NOT_FOUND',
'The commands config file was not found',
);
}
return config;
}
async enqueueCommand(
name: string,
parameters: CommandParameters = {},
tokenName?: string,
): Promise<Command> {

@@ -109,2 +123,3 @@ let {

manual,
from: tokenName,
createdAt: Date.now(),

@@ -124,7 +139,9 @@ };

parameters: CommandParameters = {},
immediate: boolean,
tokenLabel?: string,
waiting = false,
): Promise<Command> {
let command = await this.enqueueCommand(name, parameters);
let command = await this.enqueueCommand(name, parameters, tokenLabel);
if (!command.manual) {
if (!command.manual || immediate) {
if (waiting) {

@@ -157,2 +174,3 @@ await this.executeCommand(command);

throw new ExpectedError(
'INCORRECT_PARAMETERS',
'"after" and "before" cannot appear at the same time',

@@ -199,3 +217,6 @@ );

if (!adapter) {
throw new ExpectedError('COMMAND_ADAPTER_NOT_FOUND');
throw new ExpectedError(
'COMMAND_ADAPTER_NOT_FOUND',
`The adapter for type "${command.type}" was not found`,
);
}

@@ -235,12 +256,11 @@

private async requireCommandConfig(name: string): Promise<CommandConfig> {
let config = await this.getCommandsConfig();
let config = await this.requireCommandsConfig();
if (!config) {
throw new ExpectedError('COMMANDS_CONFIG_NOT_FOUND');
}
let commandConfig = config.commands.find(config => config.name === name);
if (!commandConfig) {
throw new ExpectedError('COMMAND_CONFIG_NOT_FOUND');
throw new ExpectedError(
'COMMAND_CONFIG_NOT_FOUND',
`The command config for name "${name}" was not found`,
);
}

@@ -258,2 +278,3 @@

deniedParameters,
from,
createdAt,

@@ -263,6 +284,6 @@ }: Omit<Command, 'id'>): Promise<number> {

SQL`INSERT INTO commands
(name, type, source, manual, parameters, denied_parameters, created_at)
(name, type, source, manual, parameters, denied_parameters, "from", created_at)
VALUES (${name}, ${type}, ${source}, ${manual}, ${JSON.stringify(
parameters,
)}, ${JSON.stringify(deniedParameters)}, ${createdAt})`,
)}, ${JSON.stringify(deniedParameters)}, ${from}, ${createdAt})`,
);

@@ -306,2 +327,3 @@

denied_parameters,
from,
output,

@@ -321,2 +343,3 @@ error,

deniedParameters: denied_parameters && JSON.parse(denied_parameters),
from,
result: {

@@ -421,3 +444,6 @@ output,

if (config.required && typeof resolvedValue === 'undefined') {
throw new ExpectedError('CANNOT_RESOLVE_OPTION');
throw new ExpectedError(
'CANNOT_RESOLVE_OPTION',
`The value of "${config.key}" cannot be resolved`,
);
}

@@ -424,0 +450,0 @@

@@ -10,2 +10,8 @@ import {URL} from 'url';

} from '@makeflow/gateway-shared';
import {
PowerApp,
PowerAppConfig,
PowerAppInput,
PowerItem,
} from '@makeflow/types';
import semver from 'semver';

@@ -15,10 +21,3 @@ import SQL from 'sql-template-strings';

import {
MFPowerAppDefinition,
PowerAppInputOptions,
PowerItem,
PowerItemDefinition,
PowerItemFieldDefinition,
PowerItemResponse,
} from '../types';
import {PowerItemData, PowerItemResponse} from '../types';

@@ -86,4 +85,4 @@ import {APIService, APIServiceCallOptions} from './api-service';

async generateAppDefinition(): Promise<MFPowerAppDefinition> {
let commandsConfig = await this.commandService.getCommandsConfig();
async generateAppDefinition(): Promise<PowerApp.RawDefinition> {
let commandsConfig = await this.commandService.requireCommandsConfig();
let {

@@ -94,9 +93,2 @@ externalURL,

if (!commandsConfig) {
throw new ExpectedError(
'MISSING_COMMANDS_CONFIG',
'To publish makeflow power app require commands config',
);
}
if (!externalURL) {

@@ -109,3 +101,3 @@ throw new ExpectedError(

let powerItemBaseURL = `${externalURL}/api/makeflow/power-item`;
let hookBaseURL = `${externalURL}/api/makeflow`;

@@ -118,6 +110,7 @@ return {

description: 'Makeflow Gateway 自动生成的 APP.',
hookBaseURL,
configs: [
{
field: 'password',
name: 'token',
name: 'token' as PowerAppConfig.Name,
displayName: '用于执行 Gateway 命令的 Token',

@@ -130,3 +123,2 @@ required: true,

commandsConfig.commands,
powerItemBaseURL,
),

@@ -155,5 +147,9 @@ },

): Promise<void> {
await this.tokenService.validateToken(token);
let tokenLabel = await this.tokenService.validateToken(token);
let command = await this.commandService.enqueueCommand(action, inputs);
let command = await this.commandService.enqueueCommand(
action,
inputs,
tokenLabel,
);

@@ -273,3 +269,3 @@ await this.insertPowerItem(command.id, powerItemToken);

commandId: number,
): Promise<PowerItem | undefined> {
): Promise<PowerItemData | undefined> {
let doc = await this.dbService.db.get(

@@ -298,3 +294,3 @@ SQL`SELECT * FROM makeflow_power_items WHERE command_id=${commandId}`,

await this.dbService.db.run(
SQL`UPDATE makeflow_power_item_tokens SET response=${response} WHERE id=${id}`,
SQL`UPDATE makeflow_power_items SET response=${response} WHERE id=${id}`,
);

@@ -348,14 +344,12 @@ }

configs: CommandConfig[],
powerItemBaseURL: string,
): PowerItemDefinition[] {
): PowerItem.Definition[] {
return configs.map(
({name, parameters = []}): PowerItemDefinition => {
({name, parameters = []}): PowerItem.Definition => {
return {
name,
name: name as PowerItem.Name,
displayName: name,
hookBaseURL: powerItemBaseURL,
fields: parameters.map(convertCommandConfigParameterToPowerItemField),
actions: [
{
name,
name: name as PowerItem.ActionName,
displayName: '执行命令',

@@ -374,7 +368,7 @@ inputs: parameters.map(

parameter: CommandConfigParameter,
): PowerAppInputOptions {
): PowerAppInput.Options {
let name = typeof parameter === 'string' ? parameter : parameter.name;
return {
name,
name: name as PowerAppInput.Name,
type: 'variable',

@@ -387,11 +381,10 @@ variable: name,

parameter: CommandConfigParameter,
): PowerItemFieldDefinition {
): PowerItem.PowerItemFieldDefinition {
let name = typeof parameter === 'string' ? parameter : parameter.name;
// TODO: Waiting for '@makeflow/types'
return ({
return {
base: 'input',
output: name,
displayName: name,
} as unknown) as PowerItemFieldDefinition;
};
}

@@ -13,4 +13,9 @@ import {ExpectedError} from '@makeflow/gateway-shared';

context: Readonly<ParameterizedContext<void, KoaCustomType>>,
options: RPCProcessorOptions,
) => any;
export interface RPCProcessorOptions {
tokenLabel: string | undefined;
}
export interface RPCResultError {

@@ -26,3 +31,3 @@ code: string;

export interface RPCProcessorOptions {
export interface RPCServiceProcessorOptions {
authorization?: boolean;

@@ -42,6 +47,6 @@ token?: boolean;

{
authorization = true,
token = true,
authorization: authorizationRequired = true,
token: tokenRequired = true,
requiredParams = [],
}: RPCProcessorOptions = {},
}: RPCServiceProcessorOptions = {},
): Koa.Middleware<void, KoaCustomType> {

@@ -52,8 +57,10 @@ return async (context, next) => {

try {
if (authorization && !context.session.logged) {
if (authorizationRequired && !context.session.logged) {
throw new ExpectedError('AUTHORIZATION_REQUIRED');
}
if (token) {
await this.validateToken(context);
let tokenLabel: string | undefined;
if (tokenRequired) {
tokenLabel = await this.validateToken(context);
}

@@ -72,3 +79,3 @@

'MISSING_REQUIRED_FIELD',
`Missing required field ${missingFields
`Missing required fields ${missingFields
.map(fieldName => `"${fieldName}"`)

@@ -81,3 +88,3 @@ .join(', ')}`,

let processorResult = await processor(params, context);
let processorResult = await processor(params, context, {tokenLabel});

@@ -140,3 +147,3 @@ result = {

context: Readonly<ParameterizedContext<void, KoaCustomType>>,
): Promise<void> {
): Promise<string> {
let authorization = context.header['authorization'] as string | undefined;

@@ -154,4 +161,4 @@

await this.tokenService.validateToken(token);
return this.tokenService.validateToken(token);
}
}

@@ -30,3 +30,3 @@ import crypto from 'crypto';

async validateToken(token: string): Promise<void> {
async validateToken(token: string): Promise<string> {
let tokenHash = calculateTokenHash(token);

@@ -39,2 +39,4 @@

}
return activeToken.label;
}

@@ -41,0 +43,0 @@

@@ -11,2 +11,3 @@ import {CommandConfig} from '@makeflow/gateway-shared';

denied_parameters?: string;
from?: string;
created_at: number;

@@ -13,0 +14,0 @@ executed_at?: number;

@@ -5,3 +5,2 @@ export * from './command';

export * from './token';
export * from './power-app';
export * from './makeflow';
export type PowerItemResponse = undefined | 'completed' | 'error';
export interface PowerItem {
export interface PowerItemData {
id: number;

@@ -5,0 +5,0 @@ commandId: number;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc