Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ output/
**/metrics/
benchmarks.tar.gz
metrics.tar.gz


.idea
132 changes: 132 additions & 0 deletions assets/handlers/node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
### Node template
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

11 changes: 11 additions & 0 deletions assets/handlers/node/hash/definition.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import_path: hash
description: "Hashes the given password using the Argon2 hash function."
is_async: true
returns: true
signature:
function: hashPassword
parameters:
- arg: 0
type: string
minLength: 6
maxLength: 48
10 changes: 10 additions & 0 deletions assets/handlers/node/hash/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "hash",
"version": "1.0.0",
"description": "Simple function to hash a given password.",
"type": "module",
"main": "src/index.js",
"dependencies": {
"argon2": "^0.41.1"
}
}
18 changes: 18 additions & 0 deletions assets/handlers/node/hash/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { hash as argon2 } from 'argon2';

const options = {
timeCost: 2,
memoryCost: 6144,
saltLength: 16,
};

/**
*
* @param password {string}
* @returns {Promise<{hash: string}>}
*/
export async function hashPassword(password) {
return {
hash: await argon2(password, options),
};
}
12 changes: 12 additions & 0 deletions assets/handlers/node/hash/src/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { hashPassword } from './index.js';

describe('hashPassword', () => {
it('should hash password', async () => {
const result = await hashPassword('s3cr3t');

assert.ok(result.hash);
assert.ok(typeof result.hash === 'string');
});
});
6 changes: 6 additions & 0 deletions assets/handlers/node/hash/utilization.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CPU: 204.16257570163398
DISK_READ: 0.0
DISK_WRITE: 0.0
MEMORY: 117.12701934384017
NETWORK_RECEIVE: 0.029158250848014346
NETWORK_TRANSMIT: 0.039155974253793996
146 changes: 146 additions & 0 deletions assets/handlers/node/invoice-create/definition.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import_path: invoice-create
description: "Inserts a given invoice into a MongoDB collection."
is_async: true
returns: true
depends_on:
- name: db:mongo
init: seed-invoice
signature:
function: createInvoice
parameters:
- arg: 0
type: object
properties:
items:
type: array
items:
type: object
properties:
item:
type: object
properties:
price_in_cents:
type: integer
minimum: 0
maximum: 1000000
exclusiveMaximum: false
exclusiveMinimum: true
name:
type: string
minLength: 1
maxLength: 128
additionalProperties: false
required:
- price_in_cents
- name
quantity:
type: integer
minimum: 0
maximum: 10000
exclusiveMinimum: true
additionalProperties: false
required:
- item
- quantity
billing_address:
type: object
properties:
first_name:
type: string
minLength: 2
maxLength: 64
last_name:
type: string
minLength: 2
maxLength: 64
street:
type: string
minLength: 2
maxLength: 128
number:
type: integer
minimum: 0
maximum: 10000
exclusiveMinimum: true
zip_code:
type: integer
minimum: 1000
maximum: 99999
city:
type: string
minLength: 3
maxLength: 64
country:
type: string
minLength: 3
maxLength: 64
additionalProperties: false
required:
- first_name
- last_name
- street
- number
- zip_code
- city
- country
shipping_address:
type: object
properties:
first_name:
type: string
minLength: 2
maxLength: 64
last_name:
type: string
minLength: 2
maxLength: 64
street:
type: string
minLength: 2
maxLength: 128
number:
type: integer
minimum: 0
maximum: 10000
exclusiveMinimum: true
zip_code:
type: integer
minimum: 1000
maximum: 99999
city:
type: string
minLength: 3
maxLength: 64
country:
type: string
minLength: 3
maxLength: 64
additionalProperties: false
required:
- first_name
- last_name
- street
- number
- zip_code
- city
- country
user_id:
type: string
minLength: 10
maxLength: 24
extra_info:
type: string
minLength: 0
maxLength: 512
invoice_number:
type: string
minLength: 10
maxLength: 13
additionalProperties: false
required:
- items
- billing_address
- shipping_address
- user_id
- extra_info
- invoice_number
11 changes: 11 additions & 0 deletions assets/handlers/node/invoice-create/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "invoice-create",
"version": "1.0.0",
"description": "Simple CRUD operations for an invoice entity",
"type": "module",
"main": "src/index.js",
"dependencies": {
"joi": "^17.13.3",
"mongodb": "^6.12.0"
}
}
15 changes: 15 additions & 0 deletions assets/handlers/node/invoice-create/src/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { MongoClient } from 'mongodb';

const HOST = process.env['DB_MONGO_HOST'];
const PORT = process.env['DB_MONGO_PORT'] ?? '';
const USER = process.env['DB_MONGO_USER'];
const PASSWORD = process.env['DB_MONGO_PASSWORD'];

const url = (USER && PASSWORD) ? `mongodb://${USER}:${PASSWORD}@${HOST}:${PORT}`: `mongodb://${HOST}:${PORT}`;

const client = new MongoClient(url);

await client.connect();

export const invoiceDb = client.db('invoice_db');
export const invoiceCollection = invoiceDb.collection('invoice_collection');
15 changes: 15 additions & 0 deletions assets/handlers/node/invoice-create/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { validate } from './validate.js';
import { invoiceCollection } from './db.js';

/**
*
* @param buffer {Buffer}
* @returns {Promise<string>}
*/
export async function createInvoice(buffer) {
const invoice = await validate(buffer);

const insertResult = await invoiceCollection.insertOne(invoice);

return insertResult.insertedId.toString();
}
Loading