Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
},
required: ['body']
}
}
/* Export inputSchema & outputSchema for automatic documentation */
exports.schema = schema
exports.handler = middy(businessLogic)
.use(httpHeaderNormalizer())
// parses the request body when it's a JSON and converts it to an object
.use(jsonBodyParser())
// validates the input
.use(validator({ inputSchema: schema.input }))
// handles common http errors and returns proper responses
.use(httpErrorHandler())
import { httpErrorHandler, cors } from "middy/middlewares";
import { encodeResponse } from "@internote/lib/middlewares";
import { success } from "@internote/lib/responses";
import { getUserIdentityId } from "@internote/lib/user";
import { GetHandler } from "@internote/lib/types";
import { listNotesByUserId } from "./db/queries";
const list: GetHandler = async (event, _ctx, callback) => {
const userId = getUserIdentityId(event);
const notes = await listNotesByUserId(userId);
return callback(null, success(notes));
};
export const handler = middy(list)
.use(encodeResponse())
.use(httpErrorHandler())
.use(cors());
const handlerBuilder = (aws) => {
return middy(new OccurrencesListHandler(aws))
.use(httpHeaderNormalizer())
.use(checkApiKey())
.use(httpErrorHandler())
.use(bodyStringifier())
.use(cors());
};
const handler = handlerBuilder(aws);
import { encodeResponse } from "@internote/lib/middlewares";
import { success } from "@internote/lib/responses";
import { getUserIdentityId } from "@internote/lib/user";
import { GetHandler } from "@internote/lib/types";
import { findNoteById } from "./db/queries";
const get: GetHandler<{ noteId: string }> = async (event, _ctx, callback) => {
const { noteId } = event.pathParameters;
const userId = getUserIdentityId(event);
const note = await findNoteById(noteId, userId);
return callback(null, success(note));
};
export const handler = middy(get)
.use(encodeResponse())
.use(httpErrorHandler())
.use(cors());
const handlerBuilder = (aws) => {
return middy(new ErrorsGetHandler(aws))
.use(httpHeaderNormalizer())
.use(checkApiKey())
.use(httpErrorHandler())
.use(bodyStringifier())
.use(cors());
};
const handler = handlerBuilder(aws);
const handlerBuilder = (aws) => {
return middy(new ErrorsListHandler(aws))
.use(httpHeaderNormalizer())
.use(checkApiKey())
.use(httpErrorHandler())
.use(bodyStringifier())
.use(cors());
};
const handler = handlerBuilder(aws);
const handlerBuilder = (aws) => {
return middy(new ErrorsPatchHandler(aws))
.use(checkApiKey())
.use(httpErrorHandler())
.use(bodyStringifier())
.use(cors());
};
const handler = handlerBuilder(aws);
Object.keys(exports).forEach(key => {
const handler = middy(exports[key])
.use(
loggerMiddleware({
logger: log
})
)
.use(httpEventNormalizer())
.use(jsonBodyParser())
.use(cors())
.use(autoProxyResponse())
.use(httpErrorHandler())
if (options.ssmParameters && process.env.SLIC_STAGE !== 'test') {
handler.use(
ssm({
cache: true,
names: options.ssmParameters,
awsSdkOptions: {
endpoint: process.env.SSM_ENDPOINT_URL
}
})
)
}
result[key] = handler
})
return result
const handlerBuilder = (aws) => {
return middy(new ErrorsDeleteHandler(aws))
.use(checkApiKey())
.use(httpErrorHandler())
.use(bodyStringifier())
.use(cors());
};
const handler = handlerBuilder(aws);
try {
const preferences = await findPreferencesById(getUserIdentityId(event));
return callback(null, success(preferences));
} catch (err) {
if (err instanceof HttpError.NotFound) {
const preferences = await createPreferences(getUserIdentityId(event));
return callback(null, success(preferences));
} else {
throw exception(err);
}
}
};
export const handler = middy(get)
.use(encodeResponse())
.use(httpErrorHandler())
.use(cors());