Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stonelasley committed Sep 30, 2018
0 parents commit 35e0d9b
Show file tree
Hide file tree
Showing 35 changed files with 8,137 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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:8.12-jessie-browsers-legacy

# 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 "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: yarn install

- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}

# run tests!
- run: yarn test



2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BUNNY_API_KEY=this-is-found-here-https://bunnycdn.com/dashboard/account
BUNNY_STORAGE_API_KEY=this-is-found-here-https://bunnycdn.com/dashboard/storagezones/<ZONEID>/#config-content-ftpinfo
67 changes: 67 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# 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

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://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/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
docs
dist
.idea
.vscode
compiles
.rpt2_cache
10 changes: 10 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Build results
dist/
typings/**/*

# Others
~$*
*~
node_modules/
src/build/
coverage/
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: node_js
branches:
only:
- master
- /^greenkeeper/.*$/
cache:
yarn: true
directories:
- node_modules
notifications:
email: false
node_js:
- node
script:
- npm run test:prod && npm run build
after_success:
- npm run report-coverage
- npm run deploy-docs
- npm run semantic-release
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018

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.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# bunnycdn-node
[![CircleCI](https://circleci.com/gh/UintaGroup/bunnycdn-node.svg?style=svg)](https://circleci.com/gh/UintaGroup/bunnycdn-node)
[![codecov](https://codecov.io/gh/UintaGroup/bunnycdn-node/branch/master/graph/badge.svg)](https://codecov.io/gh/UintaGroup/bunnycdn-node)

BunnyCDN node.

117 changes: 117 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"name": "bunnycdn-node",
"version": "0.0.1",
"main": "dist/bunnycdn-node.umd.js",
"module": "dist/bunnycdn-node.es5.js",
"typings": "dist/types/bunnycdn-node.d.ts",
"files": [
"dist"
],
"engines": {
"node": ">=8.0.0"
},
"scripts": {
"lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
"prebuild": "rimraf dist",
"build": "tsc --module commonjs && rollup -c rollup.config.ts && typedoc --out docs --target es6 --theme minimal --mode file src",
"start": "rollup -c rollup.config.ts -w",
"test": "jest",
"test:watch": "jest --watch",
"test:prod": "npm run lint && npm run test -- --coverage --no-cache",
"deploy-docs": "ts-node tools/gh-pages-publish",
"report-coverage": "cat ./coverage/lcov.info | coveralls",
"commit": "git-cz",
"semantic-release": "semantic-release",
"semantic-release-prepare": "ts-node tools/semantic-release-prepare",
"precommit": "lint-staged"
},
"lint-staged": {
"{src,test}/**/*.ts": [
"prettier --write",
"git add"
]
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
}
},
"jest": {
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testEnvironment": "node",
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"/test/"
],
"coverageThreshold": {
"global": {
"branches": 85,
"functions": 85,
"lines": 90,
"statements": 85
}
},
"collectCoverage": true
},
"prettier": {
"printWidth": 80,
"singleQuote": true,
"trailingComma": "all"
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"license": "MIT",
"devDependencies": {
"@commitlint/cli": "^7.1.2",
"@commitlint/config-conventional": "^7.1.2",
"@types/jest": "^23.3.2",
"@types/node": "^10.11.3",
"colors": "^1.3.2",
"commitizen": "^2.10.1",
"coveralls": "^3.0.2",
"cross-env": "^5.2.0",
"cz-conventional-changelog": "^2.1.0",
"husky": "^1.0.1",
"jest": "^23.6.0",
"jest-config": "^23.6.0",
"lint-staged": "^7.3.0",
"lodash.camelcase": "^4.3.0",
"prettier": "^1.14.3",
"prompt": "^1.0.0",
"replace-in-file": "^3.4.2",
"rimraf": "^2.6.2",
"rollup": "^0.66.2",
"rollup-plugin-commonjs": "^9.1.8",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-typescript2": "^0.17.0",
"semantic-release": "^15.9.16",
"ts-jest": "^23.10.2",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0",
"tslint-config-standard": "^8.0.1",
"typedoc": "^0.12.0",
"typescript": "^3.0.3"
},
"dependencies": {
"axios": "^0.18.0",
"class-transformer": "^0.1.9",
"lodash": "^4.17.4",
"reflect-metadata": "^0.1.12"
},
"repository": "git@github.com:UintaGroup/bunnycdn-node.git",
"author": "Stone C. Lasley <stonelasley@gmail.com>"
}
38 changes: 38 additions & 0 deletions rollup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import sourceMaps from 'rollup-plugin-sourcemaps'
import camelCase from 'lodash.camelcase'
import typescript from 'rollup-plugin-typescript2'
import json from 'rollup-plugin-json'

const pkg = require('./package.json')

const libraryName = 'bunnycdn-node'

export default {
input: `src/bunny.ts`,
output: [
{ file: pkg.main, name: camelCase(libraryName), format: 'umd', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true },
],
// Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
external: [],
watch: {
include: 'src/**',
},
plugins: [
// Allow json resolution
json(),
// Compile TypeScript files
typescript({ useTsconfigDeclarationDir: true }),
// Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
commonjs(),
// Allow node_modules resolution, so you can use 'external' to control
// which external modules to include in the bundle
// https://github.com/rollup/rollup-plugin-node-resolve#usage
resolve(),

// Resolve source maps to the original source
sourceMaps(),
],
}
50 changes: 50 additions & 0 deletions src/bunny.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// @format
import 'reflect-metadata';
import { plainToClass } from 'class-transformer';
import axios, { AxiosResponse } from 'axios';
import { HttpBase, PullZoneClient, StorageClient } from './clients';
import { Billing, Statistic } from './models';
import { Resource, Endpoint, Parameter } from './enums';

export class Bunny extends HttpBase {
private _pullZoneClient: PullZoneClient;
public get pullZone(): PullZoneClient {
return this._pullZoneClient;
}

private _storageClient: StorageClient;
public get storage(): StorageClient {
return this._storageClient;
}

constructor(httpClient?: any) {
super(httpClient || axios);
this._pullZoneClient = new PullZoneClient(httpClient || axios);
this._storageClient = new StorageClient(httpClient || axios);
}

async statistics(): Promise<Statistic[]> {
const response: AxiosResponse = await super.fetch(Resource.Statistic);
return plainToClass(Statistic, response.data);
}

async billing(): Promise<Billing[]> {
const response: AxiosResponse = await super.fetch(Resource.Billing);
return plainToClass(Billing, response.data);
}

async applyCode(couponCode: string): Promise<void> {
await super.fetch(
`${Resource.Billing}/${Endpoint.ApplyCode}?${
Parameter.CouponCode
}=${couponCode}`,
);
}

async purge(url: string): Promise<void> {
await super.post(
`${Resource.PullZone}/${Endpoint.Purge}?${Parameter.URL}=${url}`,
null,
);
}
}
Loading

0 comments on commit 35e0d9b

Please sign in to comment.