Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3e7aa58
Updated README file
oparkins Sep 19, 2019
42acc67
Created Yarn project files and added Jest
oparkins Sep 19, 2019
1d0d41d
Added initial tests for StorageIntegration class
oparkins Sep 19, 2019
25b0c41
Added common elements to support testing the component
oparkins Sep 25, 2019
f779f48
Updated gitignore
oparkins Sep 25, 2019
a175435
Added travis CI script
oparkins Sep 25, 2019
421ebd9
Created the main interface and tests. Closed #1
oparkins Sep 25, 2019
5d03f01
Added Travis CI badge
oparkins Sep 25, 2019
7a1acf2
Added new interface
oparkins Sep 25, 2019
ca59a60
Added testing framework for the browser
oparkins Sep 25, 2019
bb3d350
Added webpack server
oparkins Sep 25, 2019
c4554d6
Separated node and browser test projects
oparkins Sep 25, 2019
0bd3598
Added browser local storage and storageFactory classes along with tests
oparkins Sep 25, 2019
064e9e2
Refined the behavior for the storageFactory to throw an error when no…
oparkins Sep 25, 2019
97e09ef
Had to fix the permissions on the app folder inside the container to …
oparkins Oct 9, 2019
7f2d411
Added packages to help clean browser tests and implement the node sto…
oparkins Oct 9, 2019
07fe4a2
Made puppeteer and jest not compile the ndoe modules during testing
oparkins Oct 9, 2019
904db96
Added node storage selection and updated tests to reflect new functio…
oparkins Oct 9, 2019
0f73d37
Added nodeStorage class and tests
oparkins Oct 9, 2019
77fc826
Updated comments for nodeStorage. This closes #4
oparkins Oct 9, 2019
801ddca
Renamed Jest projects
oparkins Oct 9, 2019
7ce74b1
Removed old test files that were separated
oparkins Oct 9, 2019
e31ee1c
Added new tests that combine the two different platforms
oparkins Oct 9, 2019
8184525
Added new tests that combine the two different platforms. Closes #5
oparkins Oct 9, 2019
9f63705
Merge branch 'issue/#5' of github.com:rgpm/storage-integrations into …
oparkins Oct 9, 2019
6f3ed61
Fixed travis CI issues and preparing for package publish on github
oparkins Oct 9, 2019
5bacf83
v0.1.0
oparkins Oct 9, 2019
7ab1aa6
Added yarn configuration file
oparkins Oct 12, 2019
c1d799f
Merge branch 'issue/#10' into issue/#5
oparkins Oct 12, 2019
c32317f
v0.1.1
oparkins Dec 28, 2019
77ad3fc
chore: Updated package to be published on npm instead of github
oparkins Dec 29, 2019
5cc1671
Updated function descriptions
oparkins Dec 29, 2019
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 @@ -59,3 +59,6 @@ typings/

# next.js build output
.next

# Make build artifacts
.build-tmp
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: minimal

services:
- docker

install:
- make

before_install:
- make build

script:
- make test
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM node:12-slim

# Install chrome for puppeteer tests
# From https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#running-puppeteer-in-docker
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf procps\
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
# Add user so we don't need --no-sandbox.
# same layer as npm install to keep re-chowned files from using up several hundred MBs more space
&& groupadd -r test && useradd -r -g test -G audio,video test \
&& mkdir -p /home/test/Downloads \
&& chown -R test:test /home/test


WORKDIR /app
COPY package.json /app
COPY yarn.lock /app
COPY webpack.config.js /app
COPY jest-puppeteer.config.js /app
RUN yarn install

COPY src /app/src/
COPY test /app/test/
RUN chown -R test:test /app
USER test

ENTRYPOINT ["yarn", "test"]
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
test: .build-tmp/build-image src/* test/*
docker run --rm -it --cap-add=SYS_ADMIN -v ${PWD}/src:/app/src:ro -v ${PWD}/test:/app/test:ro rgpm:storageIntegrations-test

build: .build-tmp/build-image src/* test/*

install:
yarn install --frozen-lockfile

.build-tmp/build-image: Dockerfile package.json yarn.lock webpack.config.js jest-puppeteer.config.js
docker build -t rgpm -t rgpm:storageIntegrations-test .
mkdir -p .build-tmp
@touch $@

clean:
rm -rf .build-tmp

clean-docker:
docker rmi rgpm:storageIntegrations-test

clean-all: clean clean-docker

.PHONY: build test install clean
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# storage-integrations
# RGPM
## Storage Integrations

[![Build Status](https://travis-ci.com/rgpm/storage-integrations.svg?branch=master)](https://travis-ci.com/rgpm/storage-integrations)

This repo is a supporting module for the [RGPM Core](github.com/rgpm/core).


### Current Supported Integrations
Have you seen this repo? There are no source files!


### Planned Integrations
- Local Browser Storage
- Google Drive
- Microsoft OneDrive
- Dropbox
- GitHub
- Keybase
6 changes: 6 additions & 0 deletions jest-puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
server: {
command: 'yarn serve',
port: 4444
}
}
40 changes: 40 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@rgpm/storage-integrations",
"version": "0.1.2",
"description": "Storage Integrations for RGPM Core",
"main": "index.js",
"repository": "git@github.com:rgpm/storage-integrations.git",
"author": "Owen Parkins <oparkins@gmail.com>",
"license": "LGPL-3.0-only",
"scripts": {
"serve": "node test/server.js",
"test": "jest"
},
"dependencies": {
"node-localstorage": "^1.3.1"
},
"devDependencies": {
"express": "^4.17.1",
"jest": "^24.9.0",
"jest-cli": "^24.9.0",
"jest-puppeteer": "^4.3.0",
"puppeteer": "^1.20.0",
"webpack": "^4.41.0",
"webpack-dev-middleware": "^3.7.1",
"webpack-node-externals": "^1.7.2"
},
"jest": {
"projects": [
{
"displayName": "RGPM Core Tests",
"testMatch": [
"**/test/*.test.js"
],
"preset": "jest-puppeteer",
"globals": {
"PATH": "http://localhost:4444"
}
}
]
}
}
74 changes: 74 additions & 0 deletions src/browserStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"use strict"

const NotImplementedError = require("./notImplementedError");
const StorageIntegration = require("./storageIntegration");

/**
* Uses localStorage in browsers to store information
*/
class BrowserStorage extends StorageIntegration {
constructor() {
super();
this.storage = window.localStorage;
}

/**
* Not needed.
*/
authorize() {
return true;
}

/**
* Not needed.
*/
unauthorize() {
return true;
}

/**
* Not needed.
*/
createFile(name) {
return true;
}

/**
* Returns the value from the specified key
* @param name The name of key
* @returns {String} The value contents
*/
readFile(name) {
return this.storage.getItem(name)
}

/**
* Updates the contents of the file
* @param {String} name The name of the file
* @param {String} content The file contents
*/
updateFile(name, content) {
this.storage.setItem(name, content)
return true;
}

/**
* Removes the file from storage
* @param {String} name The name of the file
*/
deleteFile(name) {
this.storage.removeItem(name);
return true;
}

check() {
return true;
}

type() {
return "browserStorage";
}
}

module.exports = BrowserStorage;

75 changes: 75 additions & 0 deletions src/nodeStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"use strict"

const NotImplementedError = require("./notImplementedError");
const StorageIntegration = require("./storageIntegration");

/**
* Uses a localStorage module to store information on the server (for node)
*/
class NodeStorage extends StorageIntegration {
constructor() {
super();
const LocalStorage = require('node-localstorage').LocalStorage;
this.storage = new LocalStorage('./rgpm.data');
}

/**
* Not needed.
*/
authorize() {
return true;
}

/**
* Not needed.
*/
unauthorize() {
return true;
}

/**
* Not needed.
*/
createFile(name) {
return true;
}

/**
* Returns the value from the specified key
* @param name The name of key
* @returns {String} The value contents
*/
readFile(name) {
return this.storage.getItem(name)
}

/**
* Updates the contents of the file
* @param {String} name The name of the file
* @param {String} content The file contents
*/
updateFile(name, content) {
this.storage.setItem(name, content)
return true;
}

/**
* Removes the file from storage
* @param {String} name The name of the file
*/
deleteFile(name) {
this.storage.removeItem(name);
return true;
}

check() {
return true;
}

type() {
return "nodeStorage";
}
}

module.exports = NodeStorage;

11 changes: 11 additions & 0 deletions src/notImplementedError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict"

class NotImplementedError extends Error {
constructor(message) {
super();
this.name = "NotImplementedError";
this.message = message;
}
}

module.exports = NotImplementedError;
35 changes: 35 additions & 0 deletions src/storageFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use strict"

const NotImplementedError = require("./notImplementedError");


class StorageFactory {
static getLocalStorage() {
/* Browser */
try {
/* Use crypto to reliability determine if browser or not*/
if (crypto.subtle !== undefined) {
const BrowserStorage = require("./browserStorage");
return new BrowserStorage();
}
} catch (e) {
if (!(e instanceof NotImplementedError) && !(e instanceof ReferenceError)) {
throw e;
}
}

/* Node */
try {
require('crypto');
const NodeStorage = require("./nodeStorage");
return new NodeStorage();
} catch (e) {
if (!(e instanceof NotImplementedError)) {
throw e;
}
}
throw new NotImplementedError("Local Storage for NodeJS not ready");
}
}

module.exports = StorageFactory;
40 changes: 40 additions & 0 deletions src/storageIntegration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"use strict"

const NotImplementedError = require("./notImplementedError");

class StorageIntegration {
authorize() {
throw new NotImplementedError("StorageIntegration: authorize: not implemented");
}

unauthorize() {
throw new NotImplementedError("StorageIntegration: unauthorize: not implemented");
}

createFile() {
throw new NotImplementedError("StorageIntegration: createFile: not implemented");
}

readFile() {
throw new NotImplementedError("StorageIntegration: readFile: not implemented");
}

updateFile() {
throw new NotImplementedError("StorageIntegration: updateFile: not implemented");
}

deleteFile() {
throw new NotImplementedError("StorageIntegration: deleteFile: not implemented");
}

check() {
throw new NotImplementedError("StorageIntegration: check: not implemented");
}

type() {
throw new NotImplementedError("StorageIntegration: check: not implemented");
}
}

module.exports = StorageIntegration;

8 changes: 8 additions & 0 deletions test/browserStorage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
describe("BrowserStorage", () => {
it("should be a class", () => {
const BrowserStorage = require("../src/browserStorage");
expect(typeof BrowserStorage).toBe("function");
// Classes are not callable; functions are
expect(BrowserStorage).toThrow(TypeError);
});
});
Loading