Commit 1552b417 authored by Sasha Ilieva's avatar Sasha Ilieva
Browse files

Add config and server

parent 379ed2d4
{
"API_HOST_URL": "https://azure-dev.vrgnservices.com/email-template-config"
}
......@@ -46,6 +46,8 @@ function addCompanyLogo() {
}
async function init() {
const config = await getConfig();
calendarInvoiceForm.addEventListener("submit", async function (e) {
try {
e.preventDefault();
......@@ -68,7 +70,7 @@ async function init() {
};
const response = await fetch(
"https://azure-dev.vrgnservices.com/email-template-config/api/emailTemplateConfig/set",
`${config.apiHostUrl}/api/emailTemplateConfig/set`,
{
method: "POST",
headers: headers,
......@@ -82,3 +84,33 @@ async function init() {
}
});
}
async function getConfig() {
if (generatedConfig) {
return generatedConfig;
}
return await fetch("./config.json", { cache: "reload" })
.then(response => response.json())
.then(res => {
generatedConfig = generateConfig(res);
return generatedConfig;
})
.catch(err => {
console.error(`Error loading configuration: ${err}`);
});
}
function removeLastSlash(url) {
let result = url;
if (url[url.length - 1] === "/") {
result = url.substring(0, url.length - 1);
}
return result;
}
function generateConfig(configs) {
return {
apiHostUrl: removeLastSlash(configs.API_HOST_URL)
};
}
../rc/cli.js
\ No newline at end of file
../serve/bin/serve.js
\ No newline at end of file
../which/bin/which
\ No newline at end of file
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:latest
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/mongo:3.4.4
working_directory: ~/repo
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "yarn.lock" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: yarn
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "yarn.lock" }}
# run tests!
- run: yarn test
root = true
[*]
indent_style = tab
indent_size = 4
tab_width = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[{*.json,*.json.example,*.gyp,*.yml,*.yaml}]
indent_style = space
indent_size = 2
[{*.py,*.asm}]
indent_style = space
[*.py]
indent_size = 4
[*.asm]
indent_size = 8
[*.md]
trim_trailing_whitespace = false
# Ideal settings - some plugins might support these.
[*.js]
quote_type = single
[{*.c,*.cc,*.h,*.hh,*.cpp,*.hpp,*.m,*.mm,*.mpp,*.js,*.java,*.go,*.rs,*.php,*.ng,*.jsx,*.ts,*.d,*.cs,*.swift}]
curly_bracket_next_line = false
spaces_around_operators = true
spaces_around_brackets = outside
# close enough to 1TB
indent_brace_style = K&R
MIT License
Copyright (c) 2018 ZEIT
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# ZEIT's schemas
[![Build Status](https://circleci.com/gh/zeit/schemas.svg?&style=shield)](https://circleci.com/gh/zeit/schemas)
[![Join the community on Spectrum](https://withspectrum.github.io/badge/badge.svg)](https://spectrum.chat/zeit)
The schemas contained within this package are used all across the ZEIT ecosystem to validate config files, requests to APIs and more. It ensures users always send just the right data.
## Why?
It is important that these schemas stay in sync between projects, so that the validations are always performed in the same way for the same kind of object.
The files located in this repository are `.js` and not `.json`, because parsing JSON takes a little bit longer.
## Usage
To get started, pick one of the schemas in this repository and load it:
```js
const schema = require('@zeit/schemas/deployment/config');
```
Next, set up [AJV](https://github.com/epoberezkin/ajv) (the validator) and run the schema through it:
```js
const AJV = require('ajv');
const ajv = new AJV({ allErrors: true });
const isValid = ajv.validate(schema, <object-to-validate>);
if (!isValid) {
console.error(`The following entries are wrong: ${JSON.stringify(ajv.errors)}`);
}
```
That is all! :tada:
## Contributing
1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device
2. Link the package to the global module directory: `npm link`
3. Within the module you want to test your local development instance of `@zeit/schemas`, just link it to the dependencies: `npm link @zeit/schemas` and load it!
## Author
Leo Lamprecht ([@notquiteleo](https://twitter.com/notquiteleo)) - [ZEIT](https://zeit.co)
const maxEnvLength = 100;
const EnvKey = {
type: 'string',
pattern: '^[A-z0-9_]+$',
minLength: 1,
maxLength: 256
};
const EnvKeys = {
type: 'array',
minItems: 0,
maxItems: maxEnvLength,
uniqueItems: true,
items: EnvKey,
additionalProperties: false
};
const EnvValue = {
type: 'string',
minLength: 0,
maxLength: 65536
};
// { 'FOO': 'BAR' }
const EnvObject = {
type: 'object',
minProperties: 0,
maxProperties: maxEnvLength,
patternProperties: {
'.+': EnvValue
},
additionalProperties: false
};
module.exports = {
EnvKey,
EnvKeys,
EnvValue,
EnvObject
};
module.exports = {
type: 'object',
properties: {
'public': {
type: 'string'
},
'cleanUrls': {
type: [
'boolean',
'array'
]
},
'rewrites': {
type: 'array'
},
'redirects': {
type: 'array'
},
'headers': {
type: 'array',
maxItems: 50,
minItems: 1,
uniqueItems: true,
items: {
type: 'object',
required: ['source', 'headers'],
properties: {
source: {
type: 'string',
maxLength: 100,
minLength: 1
},
headers: {
type: 'array',
maxItems: 50,
minItems: 1,
uniqueItems: true,
items: {
type: 'object',
required: ['key', 'value'],
properties: {
key: {
type: 'string',
minLength: 1,
maxLength: 128,
pattern: "^[a-zA-Z0-9_!#$%&'*+.^`|~-]+$"
},
value: {
type: 'string',
minLength: 1,
maxLength: 2048,
pattern: "^[a-zA-Z0-9_!#$%&'*+.;/:, =^`|~-]+$"
}
},
additionalProperties: false
}
}
},
additionalProperties: false
}
},
'directoryListing': {
type: [
'boolean',
'array'
]
},
'unlisted': {
type: 'array'
},
'trailingSlash': {
type: 'boolean'
},
'renderSingle': {
type: 'boolean'
}
},
additionalProperties: false
};
const {EnvKeys, EnvObject} = require('./config-env');
const staticSchema = require('./config-static');
module.exports = {
type: 'object',
additionalProperties: false,
dependencies: {
slot: {
type: 'object',
required: ['features'],
properties: {
features: {
type: 'object',
required: ['cloud'],
properties: {
cloud: {
'const': 'v2'
}
}
}
}
}
},
properties: {
'name': {
type: 'string',
minLength: 1
},
'alias': {
type: [
'string',
'array'
]
},
'env': { anyOf: [EnvObject, EnvKeys] },
'build': {
type: 'object',
additionalProperties: false,
properties: {
env: EnvObject
}
},
'scale': {
type: 'object',
patternProperties: {
'.+': {
type: 'object',
required: ['max', 'min'],
properties: {
max: {
anyOf: [
{
type: 'number',
minimum: 1
},
{'const': 'auto'}
]
},
min: {
type: 'number',
minimum: 0
}
}
}
},
additionalProperties: false
},
'regions': {
type: 'array'
},
'dotenv': {
type: [
'boolean',
'string'
]
},
'files': {
type: 'array'
},
'type': {
type: 'string'
},
'forwardNpm': {
type: 'boolean'
},
'public': {
type: 'boolean'
},
'engines': {
type: 'object'
},
'api': {
type: 'string'
},
'static': staticSchema,
'limits': {
type: 'object',
properties: {
duration: {
type: 'number',
minimum: 60000,
maximum: 60000 * 15 // max 15m runtime
},
maxConcurrentReqs: {
type: 'number',
minimum: 1,
maximum: 256
},
timeout: {
type: 'number',
minimum: 60000,
maximum: 60000 * 15 // max duration
}
},
additionalProperties: false
},
'features': {
type: 'object',
patternProperties: {
'.*': {
type: ['string', 'number', 'boolean']
}
}
},
'github': {
type: 'object',
properties: {
enabled: {
type: 'boolean'
},
aliasing: {
type: 'boolean'
},
autoAlias: {
type: 'boolean'
}
},
additionalProperties: false
},
'slot': {
type: 'string',
pattern: 'c.125-m512|c1-m4096|staging-*'
}
}
};
{
"_from": "@zeit/schemas@2.6.0",
"_id": "@zeit/schemas@2.6.0",
"_inBundle": false,
"_integrity": "sha512-uUrgZ8AxS+Lio0fZKAipJjAh415JyrOZowliZAzmnJSsf7piVL5w+G0+gFJ0KSu3QRhvui/7zuvpLz03YjXAhg==",
"_location": "/@zeit/schemas",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "@zeit/schemas@2.6.0",
"name": "@zeit/schemas",
"escapedName": "@zeit%2fschemas",
"scope": "@zeit",
"rawSpec": "2.6.0",
"saveSpec": null,
"fetchSpec": "2.6.0"
},
"_requiredBy": [
"/serve"
],
"_resolved": "https://registry.npmjs.org/@zeit/schemas/-/schemas-2.6.0.tgz",
"_shasum": "004e8e553b4cd53d538bd38eac7bcbf58a867fe3",
"_spec": "@zeit/schemas@2.6.0",
"_where": "/home/silieva/calendar-invoice-page/node_modules/serve",
"author": {
"name": "leo"
},
"bugs": {
"url": "https://github.com/zeit/schemas/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "All schemas used for validation that are shared between our projects",
"devDependencies": {
"@zeit/best": "0.4.3",
"@zeit/eslint-config-node": "0.3.0",
"@zeit/git-hooks": "0.1.4",
"ajv": "6.5.1",
"eslint": "4.19.1"
},
"eslintConfig": {
"extends": [
"@zeit/eslint-config-node"
]
},
"git": {
"pre-commit": "lint-staged"
},
"homepage": "https://github.com/zeit/schemas#readme",
"license": "MIT",
"name": "@zeit/schemas",
"repository": {
"type": "git",
"url": "git+https://github.com/zeit/schemas.git"
},
"scripts": {
"lint": "zeit-eslint --ext .jsx,.js .",
"lint-staged": "git diff --diff-filter=ACMRT --cached --name-only '*.js' '*.jsx' | xargs zeit-eslint",
"test": "yarn run lint && best --verbose"
},
"version": "2.6.0"
}
/* eslint camelcase: 0 */
const AJV = require('ajv');
const assert = require('assert');
const {
EnvKeys,
EnvObject
} = require('../deployment/config-env');
const ajv = new AJV({allErrors: true});
// EnvKeys
exports.test_env_keys_valid = () => {
const isValid = ajv.validate(EnvKeys, [
'FOO',
'BAR'
]);
assert.equal(isValid, true);
};
exports.test_env_keys_too_short = () => {
const isValid = ajv.validate(EnvKeys, [
'FOO',
''
]);
assert.equal(isValid, false);
assert.equal(ajv.errors[0].keyword, 'minLength');
};
exports.test_env_keys_too_long = () => {
const isValid = ajv.validate(EnvKeys, [
'FOO',
'A'.repeat(257)
]);