diff --git a/.babelrc b/.babelrc deleted file mode 100644 index e7f034a..0000000 --- a/.babelrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "presets": [ - "es2015", - "stage-2" - ], - "env": { - "test": { - "plugins": [ - "rewire" - ] - } - } -} diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index cffd38d..0000000 --- a/.editorconfig +++ /dev/null @@ -1,10 +0,0 @@ -root = true - -[*] -indent_style = space -indent_size = 4 -charset = utf-8 - -[{package.json,.babelrc,.eslintrc}] -indent_style = space -indent_size = 2 diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index af9d031..0000000 --- a/.eslintignore +++ /dev/null @@ -1,3 +0,0 @@ -**/node_modules -/examples -/dist \ No newline at end of file diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 92ec036..0000000 --- a/.eslintrc +++ /dev/null @@ -1,225 +0,0 @@ -{ - "parser": "babel-eslint", - "env": { - "browser": true, - "mocha": true, - "node": true - }, - "ecmaFeatures": { - "arrowFunctions": true, - "blockBindings": true, - "classes": true, - "defaultParams": true, - "destructuring": true, - "forOf": true, - "generators": true, - "modules": true, - "objectLiteralComputedProperties": true, - "objectLiteralDuplicateProperties": false, - "objectLiteralShorthandMethods": true, - "objectLiteralShorthandProperties": true, - "spread": true, - "superInFunctions": true, - "templateStrings": true, - "jsx": true - }, - "rules": { - "strict": [ - 2, - "never" - ], - "arrow-parens": [ - 2, - "always" - ], - "no-var": 2, - "prefer-const": 2, - "no-shadow": 2, - "no-shadow-restricted-names": 2, - "no-undef": 2, - "no-unused-vars": [ - 2, - { - "vars": "local", - "args": "after-used" - } - ], - "no-use-before-define": 0, - "comma-dangle": 0, - "no-cond-assign": [ - 2, - "always" - ], - "no-console": 1, - "no-debugger": 1, - "no-alert": 1, - "no-constant-condition": 1, - "no-dupe-keys": 2, - "no-duplicate-case": 2, - "no-empty": 2, - "no-ex-assign": 2, - "no-extra-boolean-cast": 0, - "no-extra-semi": 2, - "no-func-assign": 2, - "no-inner-declarations": 2, - "no-invalid-regexp": 2, - "no-irregular-whitespace": 2, - "no-obj-calls": 2, - "no-sparse-arrays": 2, - "no-unreachable": 2, - "use-isnan": 2, - "block-scoped-var": 2, - "consistent-return": 2, - "curly": [ - 2, - "multi-line" - ], - "default-case": 2, - "dot-notation": [ - 2, - { - "allowKeywords": true - } - ], - "eqeqeq": 2, - "guard-for-in": 2, - "no-caller": 2, - "no-else-return": 2, - "no-eq-null": 2, - "no-eval": 2, - "no-extend-native": 2, - "no-extra-bind": 2, - "no-fallthrough": 2, - "no-floating-decimal": 2, - "no-implied-eval": 2, - "no-lone-blocks": 2, - "no-loop-func": 2, - "no-multi-str": 2, - "no-native-reassign": 2, - "no-new": 2, - "no-new-func": 2, - "no-new-wrappers": 2, - "no-octal": 2, - "no-octal-escape": 2, - "no-param-reassign": 2, - "no-proto": 2, - "no-redeclare": 2, - "no-return-assign": 2, - "no-script-url": 2, - "no-self-compare": 2, - "no-sequences": 2, - "no-throw-literal": 2, - "no-with": 2, - "radix": 2, - "vars-on-top": 2, - "wrap-iife": [ - 2, - "any" - ], - "yoda": 2, - "indent": 2, - "brace-style": [ - 2, - "1tbs", - { - "allowSingleLine": true - } - ], - "quotes": [ - 2, - "single", - "avoid-escape" - ], - "camelcase": [ - 2, - { - "properties": "never" - } - ], - "comma-spacing": [ - 2, - { - "before": false, - "after": true - } - ], - "comma-style": [ - 2, - "last" - ], - "eol-last": 2, - "func-names": 0, - "key-spacing": [ - 2, - { - "beforeColon": false, - "afterColon": true - } - ], - "new-cap": [ - 2, - { - "newIsCap": true - } - ], - "no-multiple-empty-lines": [ - 2, - { - "max": 2 - } - ], - "no-mixed-spaces-and-tabs": [ - 2 - ], - "no-nested-ternary": 2, - "no-new-object": 2, - "no-spaced-func": 2, - "no-trailing-spaces": 2, - "no-extra-parens": [ - 2, - "functions" - ], - "no-underscore-dangle": 0, - "one-var": [ - 2, - "never" - ], - "padded-blocks": [ - 2, - "never" - ], - "semi": [ - 2, - "always" - ], - "semi-spacing": [ - 2, - { - "before": false, - "after": true - } - ], - "space-after-keywords": 2, - "space-before-blocks": 2, - "space-before-function-paren": [ - 2, - "never" - ], - "space-infix-ops": 2, - "space-return-throw-case": 2, - "spaced-comment": [ - 0, - "always", - { - "exceptions": [ - "-", - "+" - ], - "markers": [ - "=", - "!" - ] - } - ] - } -} \ No newline at end of file diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 603abbb..0000000 --- a/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# IDE -.idea - -# dependencies -node_modules - -*.log - -# Built Output -/dist \ No newline at end of file diff --git a/.npmignore b/.npmignore deleted file mode 100644 index bab0046..0000000 --- a/.npmignore +++ /dev/null @@ -1,10 +0,0 @@ -# IDE -.idea - -# dependencies -node_modules - -*.log -/src -**/*.specs.js -/examples diff --git a/32px.png b/32px.png deleted file mode 100644 index 928fd1f..0000000 Binary files a/32px.png and /dev/null differ diff --git a/ACKNOWLEDGEMENTS.md b/ACKNOWLEDGEMENTS.md deleted file mode 100644 index e4b44cd..0000000 --- a/ACKNOWLEDGEMENTS.md +++ /dev/null @@ -1,8 +0,0 @@ -## Acknowledgements -Base64 encoding and decoding support is provided by base64.js, which is open source software, Copyright (c) 2007, David Lindquist . - -The original software is available from: - http://www.stringify.com/static/js/base64.js - -This software is available under the MIT License: - http://opensource.org/licenses/MIT diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index f44b05b..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,52 +0,0 @@ -# Contributing to VersionOne SDK.JavaScript Library - - 1. [Getting Involved](#getting-involved) - 2. [Reporting Bugs](#reporting-bugs) - 3. [Improving Documentation](#improving-documentation) - 4. [Contributing Code](#contributing-code) - -## Getting Involved - -We need your help to make the VersionOne SDK.JavaScript Library a useful tool for developing integrations and complementary applications. While third-party patches are absolutely essential, they are not the only way to get involved. You can help the project by discovering and [reporting bugs](#reporting-bugs), [improving documentation](#improving-documentation), and helping others on the [versionone-dev group](http://groups.google.com/group/versionone-dev/) and [GitHub issues](https://github.com/versionone/VersionOne.SDK.JavaScript/issues). - -## Reporting Bugs - -Before reporting a bug on the project's [issues page](https://github.com/versionone/VersionOne.SDK.JavaScript/issues), first make sure that your issue is caused by the Library, not your application code (e.g. passing incorrect arguments to methods, etc.). Second, search the already reported issues for similar cases, and if it has been reported already, just add any additional details in the comments. - -After you made sure that you have found a new bug, here are some tips for creating a helpful report that will make fixing it much easier and quicker: - - * Write a **descriptive, specific title**. Bad: *Problem with filtering*. Good: *Scope.Workitems always returns an empty list*. - * Whenever possible, include **Function** info in the description. - * Create a **simple test case** that demonstrates the bug. - -## Improving Documentation - -All documentation and examples are located in the `gh-pages` branch. The easiest way to make little improvements such as fixing typos without even leaving the browser is by editing one of the files with the online GitHub editor: browse the [gh-pages branch](https://github.com/VersionOne/VersionOne.SDK.JavaScript/tree/gh-pages), choose a certain file for editing, click the Edit button, make changes and follow instructions from there. Once it gets merged, the changes will immediately appear on the website. - -If you need to make edits in a local repository to see how it looks in the process, do the following: - - 1. [Install Ruby](http://www.ruby-lang.org/en/) if do not have it yet. - 2. Run `gem install jekyll`. - 3. Run `jekyll --auto` inside the `VersionOne.SDK.JavaScript` folder. - 4. Open the website from the `_site` folder. - -Now any file changes will be reflected on the generated pages automatically. After commiting the changes, just send a pull request. - -If you need to update documentation according to a new feature that only appeared in the master version (not stable one), you need to make changes to `gh-pages-master` branch instead of `gh-pages`. It will get merged into the latter when released as stable. - -## Contributing Code - -### Making Changes to Source - -If you are not yet familiar with the way GitHub works (forking, pull requests, etc.), be sure to read [the article about forking](https://help.github.com/articles/fork-a-repo) on the GitHub Help website — it will get you started quickly. - -You should always write each batch of changes (feature, bugfix, etc.) in **its own topic branch**. Please do not commit to the `master` branch, or your unrelated changes will go into the same pull request. - -You should also follow the code style and whitespace conventions of the original codebase. - -### Considerations for Accepting Patches - -Before sending a pull request with a new feature, first check if it has been discussed before already (either on [GitHub issues](https://github.com/versionone/VersionOne.SDK.JavaScript/issues). If your feature or API improvement did get merged into master, please consider submitting another pull request with the corresponding [documentation update](#improving-documentation). - -### Open Source Licenses and Attribution -Regardless of whether attribution is required by included code or a dependency, we want to acknowledge the work that VersionOne.SDK.JavaScript depends on and make it easy for people to evaluate the legal implications of using this library. Therefore, all dependencies should be attributed in the ACKNOWLEDGEMENTS.md. This should include the persons or organizations who contributed the libraries, a link to the source code, and a link to the underlying license. diff --git a/Getting_Started_Live_Examples.html b/Getting_Started_Live_Examples.html new file mode 100644 index 0000000..376cc80 --- /dev/null +++ b/Getting_Started_Live_Examples.html @@ -0,0 +1,28 @@ + +

+VersionOne.SDK.JavaScript

+ +

API client for use with JavaScript or CoffeeScript, either from Node.JS on the server or within the web browser.

+ +

+Getting Started With Live Examples

+ +

The following JS Fiddle points to an instance behind the VersionOne firewall. Don't worry. We'll soon make this work against a public test instance and you'll be able to start learning the API right here.

+ +

+This example:

+ +
    +
  1. Imports the two VersionOne classes, V1Meta, and V1Server that are needed to communicate to a VersionOne instance.
  2. +
  3. Configures the server settings
  4. +
  5. Uses the query method to specify a where clause, a select list, and function callbacks for success and error results.
  6. +

The callbacks use jQuery and jQuery UI features to render the output html.

+ +

+Try this:

+ +

Change Username to Uuuusername. This will force an error and should show a big, ugly message insteda of the beautiful jQuery accordion that you get on success. TODO: fix so this actually works...

+ + + +
\ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index 5f5ee2c..0000000 --- a/LICENSE.md +++ /dev/null @@ -1,31 +0,0 @@ -# VersionOne SDK.JavaScript License -Copyright (c) 2012 VersionOne, Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of VersionOne, Inc. nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission of - VersionOne, Inc. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR -TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 966a648..0000000 --- a/README.md +++ /dev/null @@ -1,98 +0,0 @@ -[![Gitter](https://badges.gitter.im/versionone/VersionOne.SDK.JavaScript.svg)](https://gitter.im/versionone/VersionOne.SDK.JavaScript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) - -# VersionOne JavaScript SDK - -The VersionOne JavaScript SDK is an open-source and community supported JavaScript client for the VersionOne API. The SDK simplifies the creation of server-side JavaScript integrations (i.e. node/express server) with the VersionOne platform. - -As an "open-sourced and community supported" product, the VersionOne JavaScript SDK is not formally supported by VersionOne. That said, there are a number of options for getting your questions addressed: - -* [StackOverflow](http://stackoverflow.com/questions/tagged/versionone): For asking questions of the VersionOne Development Community. -* [GitHub Issues](https://github.com/versionone/VersionOne.SDK.JavaScript/issues): For submitting issues that others may try to address. -* [![Gitter](https://badges.gitter.im/versionone/VersionOne.SDK.JavaScript.svg)](https://gitter.im/versionone/VersionOne.SDK.JavaScript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge): For participating in the development of the SDK and chatting with other developers. - -In general, StackOverflow is your best option for getting support for the VersionOne JavaScript SDK. - -The source code for the VersionOne JavaScript SDK is free and open-source, and we encourage you to improve it by [submitting pull requests](https://help.github.com/articles/using-pull-requests)! - -# Getting Started - -Please note: -* 2.x.x SDK is only supported with a VersionOne instance 17.1 or later. -* 1.x.x SDK is only supported with a VersionOne instance 15.3-17.0 -* 1.x.x SDK currently does not support querying for Meta definitions; if this is something needed, please use any 0.x.x -version. - -**See the repo's Wiki for API usage and additional information.** - -## Installation via NPM - -`npm install v1sdk` - -### jQuery example -```javascript -import $ from 'jquery'; -import sdk, {jqueryConnector} from 'v1sdk'; - -const jqueryConnectedSdk = jqueryConnector($)(sdk); -const v1 = jqueryConnectedSdk('www14.v1host.com', 'v1sdktesting', 443, true) - .withCreds('admin', 'admin'); // usage with username/password - // .withAccessToken('your token'); // usage with access tokens - // .withImplicitAuth(); // let the browser do its thing - -v1.create('Story', {estimate: 5, status: 'Not Started'}) - .then((story) => v1.update(story.oidToken, {estimate: 7})) - .then(v1.query({ - from: 'Story', - select: ['Estimate', 'Status'], - where: { - Status: 'Not Started' - } - })) - .then(console.log) - .catch(console.log); -``` - -## More Examples -Additional examples are available in the [examples](/examples) folder. - -## Client Side Integrations -As stated above, the VersionOne JavaScript SDK is intended for server-side integration. By default client-side integration is not possible because browsers only allow scripts to interact with web pages/applications at the same origin. This restriction, known as the [same-origin policy (SOP)](https://en.wikipedia.org/wiki/Same-origin_policy), is intended to prevent malicious scripts from accessing sensitive data. - -The SOP can be overridden using a mechanism known as [Cross-origin resource sharing (CORS)](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing). Enabling CORS opens a hole in the SOP and permits scripts to view data from another origin. This defeats the security measures intended to prevent a malicious attack. - -Enabling CORS is possible - *but not recommended* - for both hosted and on-premise installations of VersionOne. - -If you are interested in enabling CORS in your on-premise instance you need to include an entry for ```CorsAllowedOrigins``` in your user.confg file. The value attribute should contain the list of valid domains. Only domains in this list will be allowed to make cross-origin requets. Separate domains names with a comma. - -Here is an example user.config file with CORS enabled for a single domain -```xml - - - - -``` - -Here is an example user.config file with CORS enabled for two domains -```xml - - - - -``` - -If you are interested in enabling CORS for a hosted instance of VersionOne, please contact your system administrator and ask them to email VersionOne support requesting this change. This email needs to include the list of domains you would like permitted. Because this change has security implications, we cannot accept requests from anyone. - -## Other Resources - -* [ACKNOWLEDGEMENTS.md](https://github.com/versionone/VersionOne.SDK.JavaScript/blob/master/ACKNOWLEDGEMENTS.md) - Acknowledgments of included software and associated licenses -* [LICENSE.md](https://github.com/versionone/VersionOne.SDK.NET.APIClient/blob/master/LICENSE.md) - License for source code and redistribution -* [CONTRIBUTING.md](https://github.com/versionone/VersionOne.SDK.JavaScript/blob/master/CONTRIBUTING.md) - Guidelines and information on contributing to this project - -### Getting Help -Need to bootstrap on VersionOne SDK.JavaScript quickly? VersionOne services brings a wealth of development experience to training and mentoring: - -http://www.versionone.com/training/product_training_services/ - -Not into the chat thing? Get help from the community of VersionOne developers: - -http://groups.google.com/group/versionone-dev/ diff --git a/examples/using-jquery-for-ajax.js b/examples/using-jquery-for-ajax.js deleted file mode 100644 index 0871c6e..0000000 --- a/examples/using-jquery-for-ajax.js +++ /dev/null @@ -1,24 +0,0 @@ -import $ from 'jquery'; -import sdk, {jqueryConnector} from 'v1sdk'; - -const jqueryConnectedSdk = jqueryConnector($)(sdk); -const v1 = jqueryConnectedSdk('www14.v1host.com', 'v1sdktesting', 443, true) - .withCreds('admin', 'admin'); // usage with username/password -// .withAccessToken('your token'); // usage with access tokens - -v1.create('Story', {estimate: 5, status: 'Not Started'}) - .then((story) => v1.update(story.oidToken, {estimate: 7})) - .then(v1.query({ - from: 'Story', - select: ['Estimate', 'Status'], - where: { - Status: 'Not Started' - } - })) - .then(console.log) - .catch(console.log); - -// Retrieve a description of all the Attributes, Operations for a given AssetType -v1.queryDefinition('Story') - .then(console.log) - .catch(console.log); diff --git a/package.json b/package.json deleted file mode 100644 index f11c87c..0000000 --- a/package.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "name": "v1sdk", - "version": "2.3.0", - "description": "VersionOne API Client for JavaScript", - "license": "MIT", - "keywords": [ - "VersionOne", - "V1", - "SDK" - ], - "homepage": "https://github.com/versionone/VersionOne.SDK.JavaScript", - "main": "./dist/index.js", - "repository": { - "type": "git", - "url": "git@github.com:versionone/VersionOne.SDK.JavaScript.git" - }, - "scripts": { - "clean": "rm -rf dist", - "prebuild": "npm run lint && npm run clean", - "build": "babel src -d dist --ignore *.specs.js", - "lint": "eslint ./src", - "test": "./node_modules/.bin/better-npm-run test", - "prepublish": "npm test && npm run build" - }, - "betterScripts": { - "test": { - "command": "mocha src/**/*.specs.js --compilers js:babel-core/register --recursive", - "env": { - "NODE_ENV": "test" - } - }, - "build:prod": { - "command": "webpack --config $npm_package_webpack --progress --colors", - "env": { - "NODE_ENV": "production" - } - } - }, - "dependencies": { - "btoa": "1.1.2", - "invariant": "2.2.0" - }, - "devDependencies": { - "babel": "6.3.13", - "babel-cli": "6.3.17", - "babel-core": "6.3.21", - "babel-eslint": "^6.1.0", - "babel-plugin-rewire": "1.0.0-beta-3", - "babel-polyfill": "^6.9.0", - "babel-preset-es2015": "6.3.13", - "babel-preset-stage-2": "6.3.13", - "babel-runtime": "6.3.19", - "better-npm-run": "0.0.8", - "chai": "3.4.1", - "chai-as-promised": "5.2.0", - "escope": "^3.3.0", - "eslint": "1.10.3", - "mocha": "2.3.4", - "sinon": "2.0.0-pre", - "wallaby-webpack": "0.0.22", - "webpack": "^1.13.1" - } -} diff --git a/src/Oid.js b/src/Oid.js deleted file mode 100644 index bfbfd54..0000000 --- a/src/Oid.js +++ /dev/null @@ -1,35 +0,0 @@ -export const InvalidOidToken = class { - constructor(message) { - this.name = this.constructor.name; - this.message = message; - if (typeof Error.captureStackTrace === 'function') { - Error.captureStackTrace(this, this.constructor); - } else { - this.stack = (new Error(message)).stack; - } - } -}; -InvalidOidToken.prototype = Object.create(Error.prototype); - -export default class { - constructor(oidToken) { - const oidParts = oidToken.split(':'); - if (/[1-9][0-9]*/.exec(oidParts[1]) === null) { - throw new InvalidOidToken(oidToken); - } - this.type = oidParts[0]; - this.idNumber = parseInt(oidParts[1], 10); - } - - get assetType() { - return this.type; - } - - get number() { - return this.idNumber; - } - - toString() { - return `${this.assetType}:${this.number}`; - } -} diff --git a/src/Oid.specs.js b/src/Oid.specs.js deleted file mode 100644 index 60c7291..0000000 --- a/src/Oid.specs.js +++ /dev/null @@ -1,52 +0,0 @@ -import Sut, {InvalidOidToken} from './Oid'; - -describe('src/Oid', function() { - beforeEach(() => { - this.actual = undefined; - }); - describe('given a valid Oid Token', () => { - beforeEach(() => { - this.oidToken = 'Member:20'; - }); - describe('when creating an Oid from the Oid Token', () => { - beforeEach(() => { - this.actual = new Sut(this.oidToken); - }); - it('it should return an Oid with an asset type', () => { - this.actual.assetType.should.equal('Member'); - }); - it('it should return a read-only asset type property', () => { - (() => this.actual.assetType = 'Story').should.throw(); - }); - it('it should return an Oid with a ID number', () => { - this.actual.number.should.equal(20); - }); - it('it should return a read-only ID number property', () => { - (() => this.actual.number = 25).should.throw(); - }); - }); - - describe('when toString is called', () => { - beforeEach(() => { - this.actual = new Sut(this.oidToken).toString(); - }); - it('it should return an Oid Token for the Oid', () => { - this.actual.should.equal('Member:20'); - }); - }); - }); - - describe('given an invalid Oid Token', () => { - beforeEach(() => { - this.oidToken = 'Member:Username'; - }); - describe('when creating an Oid from the Oid token', () => { - beforeEach(() => { - this.fn = () => this.actual = new Sut(this.oidToken); - }); - it('it should throw an InvalidOidToken error', () => { - this.fn.should.throw(InvalidOidToken); - }); - }); - }); -}); diff --git a/src/connectors/axiosConnector.js b/src/connectors/axiosConnector.js deleted file mode 100644 index 97607a2..0000000 --- a/src/connectors/axiosConnector.js +++ /dev/null @@ -1,15 +0,0 @@ -export default (axios) => (sdk) => sdk( - (url, data, headers) =>axios({ - method: 'POST', - url, - data, - headers - }), - (url, data, headers) => axios({ - method: 'GET', - url, - params: data, - headers - }) -); - diff --git a/src/connectors/jqueryConnector.js b/src/connectors/jqueryConnector.js deleted file mode 100644 index c744d65..0000000 --- a/src/connectors/jqueryConnector.js +++ /dev/null @@ -1,17 +0,0 @@ -export default ($) => (sdk) => sdk( - (url, data, headers) => new Promise((resolve, reject) => $.ajax(url, { - method: 'POST', - data: JSON.stringify(data), - dataType: 'json', - headers, - success: resolve, - error: reject - })), - (url, data, headers) => new Promise((resolve, reject) => $.ajax(url, { - method: 'GET', - data: JSON.stringify(data), - headers, - success: resolve, - error: reject - })) -); diff --git a/src/createMeta.js b/src/createMeta.js deleted file mode 100644 index 6845e7e..0000000 --- a/src/createMeta.js +++ /dev/null @@ -1,80 +0,0 @@ -import invariant from 'invariant'; -import transformDataToAsset from './transformDataToAsset'; -import getV1Urls from './getV1Urls'; -import Oid from './Oid'; - -export default ({hostname, instance, protocol, port, token, postFn, getFn, isBasic}) => { - const urls = getV1Urls(hostname, instance, protocol, port); - const headers = createHeaderObj(token, isBasic); - - return { - create(assetType, assetData) { - invariant(assetType, `Error: there was no \`assetType\` provided to create`); - invariant(assetData, `Error: there was no \`assetAttributeData\` provided to create`); - invariant(Object.keys(assetData).length, `Error: there was no \`assetAttributeData\` provided to create`); - const postData = transformDataToAsset(assetData); - const url = `${urls.rest}/${assetType}`; - return postFn(url, postData, headers); - }, - - update(oidToken, assetData, changeComment) { - invariant(oidToken, `Error: there was no \`oidToken\` provided to update`); - invariant(assetData, `Error: there was no \`assetAttributeData\` provided to update`); - invariant(Object.keys(assetData).length, `Error: there was no \`assetAttributeData\` provided to update`); - const oid = new Oid(oidToken); - const postData = transformDataToAsset(assetData); - const comment = changeComment ? `?comment=${encodeURIComponent(changeComment)}` : ''; - const url = `${urls.rest}/${oid.assetType}/${oid.number}${comment}`; - return postFn(url, postData, headers); - }, - - query(queryObj) { - invariant(queryObj.from, `Error: there was no \`from\` property on provided query: ${queryObj}`); - invariant(queryObj.select, `Error: there was no \`select\` property on provided query: ${queryObj}`); - invariant(Array.isArray(queryObj.select), `Error: \`select\` property must be an Array on provided query: ${queryObj}`); - invariant(queryObj.select.length, `Error: \`select\` property must contain values on provided query: ${queryObj}`); - const url = urls.query; - return postFn(url, queryObj, headers); - }, - - executeOperation(oidToken, operationName) { - invariant(oidToken, `Error: there was no \`oidToken\` provided to execute operation`); - invariant(operationName, `Error: there was no \`operationName\` provided to execute operation`); - const oid = new Oid(oidToken); - const url = `${urls.rest}/${oid.assetType}/${oid.number}?op=${operationName}`; - return postFn(url, null, headers); - }, - - queryDefinition(assetType) { - const queryAssetType = assetType ? assetType : ''; - const url = `${urls.meta}/${queryAssetType}`; - return getFn(url, null, headers); - }, - - getActivityStream(oidToken) { - invariant(oidToken, `Error: there was no \`oidToken\` provided to execute operation`); - const url = `${urls.activityStream}/${oidToken}`; - return getFn(url, null, headers); - } - }; -}; - -const createHeaderObj = (token, isBasic) => { - const headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - }; - - - const hasToken = Boolean(token); - const hasType = typeof isBasic !== 'undefined'; - - if (hasToken || hasType) { - invariant(hasToken, `Error: there was no \`token\` provided to the SDK`); - invariant(hasType, `Error: there was no \`isBasic\` provided to the SDK`); - - headers['Authorization'] = `${isBasic ? 'Basic' : 'Bearer'} ${token}`; // eslint-disable-line dot-notation - } - - return headers; -}; diff --git a/src/createMeta.specs.js b/src/createMeta.specs.js deleted file mode 100644 index e4e2ca7..0000000 --- a/src/createMeta.specs.js +++ /dev/null @@ -1,642 +0,0 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; -import createMeta, {__RewireAPI__ as RewireApi} from './createMeta'; -import sinon from 'sinon'; -chai.use(chaiAsPromised); -chai.should(); - -describe('src/meta', function() { - beforeEach(() => { - this.actual = undefined; - }); - describe('given a required meta creation information', () => { - beforeEach(() => { - this.postFn = sinon.stub(); - this.getFn = sinon.stub(); - }); - describe('when creating a meta object', () => { - beforeEach(() => { - this.actual = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80, token: 'token', postFn: this.postFn, getFn: this.getFn, isBasic: false }); - }); - it('it should return an object with a create asset function', () => { - this.actual.create.should.be.a('function'); - }); - it('it should return an object with an update asset function', () => { - this.actual.update.should.be.a('function'); - }); - it('it should return an object with a query function', () => { - this.actual.query.should.be.a('function'); - }); - it('it should return an object with an execution operation function', () => { - this.actual.executeOperation.should.be.a('function'); - }); - it('it should return an object with a query definition function', () => { - this.actual.queryDefinition.should.be.a('function'); - }); - it('it should return an object with a activity stream function', () => { - this.actual.getActivityStream.should.be.a('function'); - }); - }); - }); -}); - -describe('src/meta.create', function() { - beforeEach(() => { - this.actual = undefined; - }); - describe('given no asset type', () => { - beforeEach(() => { - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80 }, () => { - }, () => { - }, false); - }); - describe('when creating an asset', () => { - it('it should throw an invariant error', () => { - (() => this.meta.create()).should.throw(); - }); - }); - }); - describe('given no asset data', () => { - describe('when creating an asset', () => { - it('it should throw an invariant error', () => { - (() => this.meta.create('Actual')).should.throw(); - }); - }); - }); - describe('given empty asset data', () => { - describe('when creating an asset', () => { - it('it should throw an invariant error', () => { - (() => this.meta.create('Actual', {})).should.throw(); - }); - }); - }); - describe('given token based authentication', () => { - describe('given an asset type and asset data', () => { - describe('when creating an asset', () => { - beforeEach(() => { - this.assetData = {key: 'value'}; - this.headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Bearer token' - }; - const getV1Urls = sinon.mock() - .withArgs('h', 'i', 'http', 80) - .returns({ - rest: 'rest URL' - }); - const transformDataToAsset = sinon.mock() - .withArgs({Value: 5.5}) - .returns(this.assetData); - RewireApi.__Rewire__('getV1Urls', getV1Urls); - RewireApi.__Rewire__('transformDataToAsset', transformDataToAsset); - this.postFn = sinon.stub(); - - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80, token: 'token', postFn: this.postFn, isBasic: false }); - this.actual = this.meta.create('Actual', {Value: 5.5}); - }); - afterEach(() => { - RewireApi.__ResetDependency__('getV1Urls'); - RewireApi.__ResetDependency__('transformDataToAsset'); - }); - it('it should post the asset creation to the REST URL endpoint with token based authentication headers', () => { - this.postFn.calledWith('rest URL/Actual', this.assetData, this.headers).should.be.true; - }); - }); - }); - - describe('given basic authentication', () => { - describe('given an asset type and asset data', () => { - describe('when creating an asset', () => { - beforeEach(() => { - this.assetData = {key: 'value'}; - this.headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Basic token' - }; - const getV1Urls = sinon.mock() - .withArgs('h', 'i', 'http', 80) - .returns({ - rest: 'rest URL' - }); - const transformDataToAsset = sinon.mock() - .withArgs({Value: 5.5}) - .returns(this.assetData); - RewireApi.__Rewire__('getV1Urls', getV1Urls); - RewireApi.__Rewire__('transformDataToAsset', transformDataToAsset); - this.postFn = sinon.stub(); - - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80, token: 'token', postFn: this.postFn, isBasic: true }); - this.actual = this.meta.create('Actual', {Value: 5.5}); - }); - afterEach(() => { - RewireApi.__ResetDependency__('getV1Urls'); - RewireApi.__ResetDependency__('transformDataToAsset'); - }); - it('it should post the asset creation to the REST URL endpoint with basic authentication headers', () => { - this.postFn.calledWith('rest URL/Actual', this.assetData, this.headers).should.be.true; - }); - }); - }); - }); - - describe('given implicit authentication', () => { - describe('given an asset type and asset data', () => { - describe('when creating an asset', () => { - beforeEach(() => { - this.assetData = {key: 'value'}; - this.headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - }; - const getV1Urls = sinon.mock() - .withArgs('h', 'i', 'http', 80) - .returns({ - rest: 'rest URL' - }); - const transformDataToAsset = sinon.mock() - .withArgs({Value: 5.5}) - .returns(this.assetData); - RewireApi.__Rewire__('getV1Urls', getV1Urls); - RewireApi.__Rewire__('transformDataToAsset', transformDataToAsset); - this.postFn = sinon.stub(); - - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80, postFn: this.postFn }); - this.actual = this.meta.create('Actual', {Value: 5.5}); - }); - afterEach(() => { - RewireApi.__ResetDependency__('getV1Urls'); - RewireApi.__ResetDependency__('transformDataToAsset'); - }); - it('it should post the asset creation to the REST URL endpoint with basic authentication headers', () => { - this.postFn.calledWith('rest URL/Actual', this.assetData, this.headers).should.be.true; - }); - }); - }); - }); - }); -}); - -describe('src/meta.update', function() { - beforeEach(() => { - this.actual = undefined; - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80 }, () => { - }, () => { - }); - }); - describe('given no oid token', () => { - describe('when updating an asset', () => { - it('it should throw an invariant error', () => { - (() => this.meta.update()).should.throw(); - }); - }); - }); - describe('given no asset data', () => { - describe('when creating an asset', () => { - it('it should throw an invariant error', () => { - (() => this.meta.update('Actual:1001')).should.throw(); - }); - }); - }); - describe('given empty asset data', () => { - describe('when creating an asset', () => { - it('it should throw an invariant error', () => { - (() => this.meta.update('Actual:10001', {})).should.throw(); - }); - }); - }); - describe('given token based authentication', () => { - describe('given an asset type and asset data', () => { - describe('when updating an asset', () => { - beforeEach(() => { - this.assetData = {key: 'value'}; - this.headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Bearer token' - }; - const getV1Urls = sinon.mock() - .withArgs('h', 'i', 'http', 80) - .returns({ - rest: 'rest URL' - }); - const transformDataToAsset = sinon.mock() - .withArgs({Value: 5.5}) - .returns(this.assetData); - RewireApi.__Rewire__('getV1Urls', getV1Urls); - RewireApi.__Rewire__('transformDataToAsset', transformDataToAsset); - this.postFn = sinon.stub(); - - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80, token: 'token', postFn: this.postFn, getFn: this.getFn, isBasic: false }); - this.actual = this.meta.update('Actual:10011', {Value: 5.5}); - }); - afterEach(() => { - RewireApi.__ResetDependency__('getV1Urls'); - RewireApi.__ResetDependency__('transformDataToAsset'); - }); - it('it should post the asset update to the REST URL endpoint with token based authentication header', () => { - this.postFn.calledWith('rest URL/Actual/10011', this.assetData, this.headers).should.be.true; - }); - }); - }); - }); - describe('given basic authentication', () => { - describe('given an asset type and asset data', () => { - describe('when updating an asset', () => { - beforeEach(() => { - this.assetData = {key: 'value'}; - this.headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Basic token' - }; - const getV1Urls = sinon.mock() - .withArgs('h', 'i', 'http', 80) - .returns({ - rest: 'rest URL' - }); - const transformDataToAsset = sinon.mock() - .withArgs({Value: 5.5}) - .returns(this.assetData); - RewireApi.__Rewire__('getV1Urls', getV1Urls); - RewireApi.__Rewire__('transformDataToAsset', transformDataToAsset); - this.postFn = sinon.stub(); - - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80, token: 'token', postFn: this.postFn, getFn: this.getFn, isBasic: true }); - this.actual = this.meta.update('Actual:10011', {Value: 5.5}); - }); - afterEach(() => { - RewireApi.__ResetDependency__('getV1Urls'); - RewireApi.__ResetDependency__('transformDataToAsset'); - }); - it('it should post the asset update to the REST URL endpoint with token based authentication header', () => { - this.postFn.calledWith('rest URL/Actual/10011', this.assetData, this.headers).should.be.true; - }); - }); - }); - }); - describe('given an asset type, asset data, and change comment', () => { - describe('when updating an asset', () => { - beforeEach(() => { - this.assetData = {key: 'value'}; - this.headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Basic token' - }; - const getV1Urls = sinon.mock() - .withArgs('h', 'i', 'http', 80) - .returns({ - rest: 'rest URL' - }); - const transformDataToAsset = sinon.mock() - .withArgs({Value: 5.5}) - .returns(this.assetData); - RewireApi.__Rewire__('getV1Urls', getV1Urls); - RewireApi.__Rewire__('transformDataToAsset', transformDataToAsset); - this.postFn = sinon.stub(); - - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80, token: 'token', postFn: this.postFn, getFn: this.getFn, isBasic: true }); - this.actual = this.meta.update('Actual:10011', {Value: 5.5}, 'change comment'); - }); - afterEach(() => { - RewireApi.__ResetDependency__('getV1Urls'); - RewireApi.__ResetDependency__('transformDataToAsset'); - }); - it('it should post the asset update to the REST URL endpoint with token based authentication header', () => { - this.postFn.calledWith(`rest URL/Actual/10011?comment=${encodeURIComponent('change comment')}`, this.assetData, this.headers).should.be.true; - }); - }); - }); -}); - -describe('src/meta.query', function() { - beforeEach(() => { - this.actual = undefined; - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80 }, () => { - }, () => { - }); - }); - describe('given no query object', () => { - describe('when querying meta', () => { - it('it should throw an invariant error', () => { - (() => this.meta.query()).should.throw(); - }); - }); - }); - describe('given empty query object', () => { - describe('when querying meta', () => { - it('it should throw an invariant error', () => { - (() => this.meta.query({})).should.throw(); - }); - }); - }); - describe('given a query object without a from', () => { - describe('when querying meta', () => { - it('it should throw an invariant error', () => { - (() => this.meta.query({select: []})).should.throw(); - }); - }); - }); - describe('given a query object without a select', () => { - describe('when querying meta', () => { - it('it should throw an invariant error', () => { - (() => this.meta.query({from: 'Story'})).should.throw(); - }); - }); - }); - describe('given a query object with an empty select', () => { - describe('when querying meta', () => { - it('it should throw an invariant error', () => { - (() => this.meta.query({from: 'Story', select: []})).should.throw(); - }); - }); - }); - describe('given token based authentication', () => { - describe('given a valid query object', () => { - describe('when querying meta', () => { - beforeEach(() => { - this.query = {from: 'Story', select: ['Estimate']}; - this.headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Bearer token' - }; - const getV1Urls = sinon.mock() - .withArgs('h', 'i', 'http', 80) - .returns({ - query: 'query Url' - }); - RewireApi.__Rewire__('getV1Urls', getV1Urls); - this.postFn = sinon.stub(); - - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80, token: 'token', postFn: this.postFn, getFn: this.getFn, isBasic: false }); - this.actual = this.meta.query(this.query); - }); - afterEach(() => { - RewireApi.__ResetDependency__('getV1Urls'); - }); - it('it should post the asset update to the query URL endpoint with token based authentication header', () => { - this.postFn.calledWith('query Url', this.query, this.headers).should.be.true; - }); - }); - }); - }); - describe('given basic authentication', () => { - describe('given a valid query object', () => { - describe('when querying meta', () => { - beforeEach(() => { - this.query = {from: 'Story', select: ['Estimate']}; - this.headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Basic token' - }; - const getV1Urls = sinon.mock() - .withArgs('h', 'i', 'http', 80) - .returns({ - query: 'query Url' - }); - RewireApi.__Rewire__('getV1Urls', getV1Urls); - this.postFn = sinon.stub(); - - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80, token: 'token', postFn: this.postFn, getFn: this.getFn, isBasic: true }); - this.actual = this.meta.query(this.query); - }); - afterEach(() => { - RewireApi.__ResetDependency__('getV1Urls'); - }); - it('it should post the asset update to the query URL endpoint with basic authentication header', () => { - this.postFn.calledWith('query Url', this.query, this.headers).should.be.true; - }); - }); - }); - }); -}); - -describe('src/meta.executeOperation', function() { - beforeEach(() => { - this.actual = undefined; - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80 }, () => { - }, () => { - }); - }); - describe('given no oid token', () => { - describe('when executing an operation against an asset', () => { - it('it should throw an invariant error', () => { - (() => this.meta.executeOperation()).should.throw(); - }); - }); - }); - describe('given no operation name', () => { - describe('when executing an operation against an asset', () => { - it('it should throw an invariant error', () => { - (() => this.meta.executeOperation('Actual:10001')).should.throw(); - }); - }); - }); - describe('given token based authentication', () => { - describe('given an oid token and an operation name', () => { - describe('when executing an operation against an asset', () => { - beforeEach(() => { - this.operationName = 'operation name'; - this.headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Bearer token' - }; - const getV1Urls = sinon.mock() - .withArgs('h', 'i', 'http', 80) - .returns({ - rest: 'rest URL' - }); - RewireApi.__Rewire__('getV1Urls', getV1Urls); - this.postFn = sinon.stub(); - - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80, token: 'token', postFn: this.postFn, getFn: this.getFn, isBasic: false }); - this.actual = this.meta.executeOperation('Actual:10011', this.operationName); - }); - afterEach(() => { - RewireApi.__ResetDependency__('getV1Urls'); - }); - it('it should post the the operation to the REST URL endpoint with token based authentication header', () => { - this.postFn.calledWith(`rest URL/Actual/10011?op=${this.operationName}`, null, this.headers).should.be.true; - }); - }); - }); - }); - describe('given basic authentication', () => { - describe('given an oid token and an operation name', () => { - describe('when executing an operation against an asset', () => { - beforeEach(() => { - this.operationName = 'operation name'; - this.headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Basic token' - }; - const getV1Urls = sinon.mock() - .withArgs('h', 'i', 'http', 80) - .returns({ - rest: 'rest URL' - }); - RewireApi.__Rewire__('getV1Urls', getV1Urls); - this.postFn = sinon.stub(); - - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80, token: 'token', postFn: this.postFn, getFn: this.getFn, isBasic: true }); - this.actual = this.meta.executeOperation('Actual:10011', this.operationName); - }); - afterEach(() => { - RewireApi.__ResetDependency__('getV1Urls'); - }); - it('it should post the the operation to the REST URL endpoint with token basic authentication header', () => { - this.postFn.calledWith(`rest URL/Actual/10011?op=${this.operationName}`, null, this.headers).should.be.true; - }); - }); - }); - }); -}); - -describe('src/meta.queryDefinition', function() { - beforeEach(() => { - this.actual = undefined; - }); - describe('given no asset type', () => { - describe('when querying for meta data', () => { - beforeEach(() => { - this.headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Bearer token' - }; - const getV1Urls = sinon.mock() - .withArgs('h', 'i', 'http', 80) - .returns({ - meta: 'meta URL' - }); - RewireApi.__Rewire__('getV1Urls', getV1Urls); - this.getFn = sinon.stub(); - - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80, token: 'token', getFn: this.getFn, isBasic: false }); - this.actual = this.meta.queryDefinition(); - }); - afterEach(() => { - RewireApi.__ResetDependency__('getV1Urls'); - }); - it('it should query for all meta data', () => { - this.getFn.calledWith(`meta URL/`, null, this.headers).should.be.true; - }); - }); - }); - describe('given an asset type', () => { - describe('when querying for meta data for the asset type', () => { - beforeEach(() => { - this.headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Bearer token' - }; - const getV1Urls = sinon.mock() - .withArgs('h', 'i', 'http', 80) - .returns({ - meta: 'meta URL' - }); - RewireApi.__Rewire__('getV1Urls', getV1Urls); - this.getFn = sinon.stub(); - - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80, token: 'token', getFn: this.getFn, isBasic: false }); - this.actual = this.meta.queryDefinition('Actual'); - }); - afterEach(() => { - RewireApi.__ResetDependency__('getV1Urls'); - }); - it('it should post the the operation to the REST URL endpoint', () => { - this.getFn.calledWith(`meta URL/Actual`, null, this.headers).should.be.true; - }); - }); - }); - describe('given an oidToken', () => { - describe('when retreiving an activity stream for the asset', () => { - beforeEach(() => { - this.headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Bearer token' - }; - const getV1Urls = sinon.mock() - .withArgs('h', 'i', 'http', 80) - .returns({ - activityStream: 'activityStream URL' - }); - RewireApi.__Rewire__('getV1Urls', getV1Urls); - this.getFn = sinon.stub(); - - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80, token: 'token', getFn: this.getFn, isBasic: false }); - this.actual = this.meta.getActivityStream('Story:1234'); - }); - afterEach(() => { - RewireApi.__ResetDependency__('getV1Urls'); - }); - it('it should query the ActivityStream endpoint', () => { - this.getFn.calledWith(`activityStream URL/Story:1234`, null, this.headers).should.be.true; - }); - }); - }); - describe('given token based authentication', () => { - describe('when querying for meta data', () => { - beforeEach(() => { - this.headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Bearer token' - }; - const getV1Urls = sinon.mock() - .withArgs('h', 'i', 'http', 80) - .returns({ - meta: 'meta URL' - }); - RewireApi.__Rewire__('getV1Urls', getV1Urls); - this.getFn = sinon.stub(); - - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80, token: 'token', getFn: this.getFn, isBasic: false }); - this.actual = this.meta.queryDefinition(); - }); - afterEach(() => { - RewireApi.__ResetDependency__('getV1Urls'); - }); - it('it should query for all meta data', () => { - this.getFn.calledWith(`meta URL/`, null, this.headers).should.be.true; - }); - }); - describe('given basic authentication', () => { - describe('when querying for meta data', () => { - describe('when querying for meta data', () => { - beforeEach(() => { - this.headers = { - Accept: 'application/json', - 'Content-Type': 'application/json', - Authorization: 'Basic token' - }; - const getV1Urls = sinon.mock() - .withArgs('h', 'i', 'http', 80) - .returns({ - meta: 'meta URL' - }); - RewireApi.__Rewire__('getV1Urls', getV1Urls); - this.getFn = sinon.stub(); - - this.meta = createMeta({ hostname: 'h', instance: 'i', protocol: 'http', port: 80, token: 'token', getFn: this.getFn, isBasic: true }); - this.actual = this.meta.queryDefinition(); - }); - afterEach(() => { - RewireApi.__ResetDependency__('getV1Urls'); - }); - it('it should query for all meta data', () => { - this.getFn.calledWith(`meta URL/`, null, this.headers).should.be.true; - }); - }); - }); - }); - }); -}); diff --git a/src/getV1Urls.js b/src/getV1Urls.js deleted file mode 100644 index 623d48a..0000000 --- a/src/getV1Urls.js +++ /dev/null @@ -1,11 +0,0 @@ -export default (hostname, instance, protocol, port) => { - const rootUrl = getUrlToV1Server(hostname, instance, protocol, port); - return Object.freeze({ - rest: `${rootUrl}/rest-1.v1/Data`, - query: `${rootUrl}/query.v1`, - meta: `${rootUrl}/meta.v1`, - activityStream: `${rootUrl}/api/ActivityStream` - }); -}; - -const getUrlToV1Server = (hostname, instance, protocol, port) => `${protocol}://${hostname}:${port}/${instance}`; diff --git a/src/getV1Urls.specs.js b/src/getV1Urls.specs.js deleted file mode 100644 index 89e06b5..0000000 --- a/src/getV1Urls.specs.js +++ /dev/null @@ -1,31 +0,0 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; -import getV1Urls from './getV1Urls'; -chai.use(chaiAsPromised); -chai.should(); - -describe('src/getV1Urls', function() { - beforeEach(() => { - this.actual = undefined; - }); - describe('given a V1 hostname, instance name, protocol and port', () => { - describe('when getting the URLs for the VersionOne instance', () => { - beforeEach(() => { - this.actual = getV1Urls('some URL', 'some Instance', 'https', 8081); - }); - - it('it should return the Rest API URL', () => { - this.actual.rest.should.equal('https://some URL:8081/some Instance/rest-1.v1/Data'); - }); - it('it should return the Query API URL', () => { - this.actual.query.should.equal('https://some URL:8081/some Instance/query.v1'); - }); - it('it should return the Meta API URL', () => { - this.actual.meta.should.equal('https://some URL:8081/some Instance/meta.v1'); - }); - it('it should return the Activity Stream API URL', () => { - this.actual.activityStream.should.equal('https://some URL:8081/some Instance/api/ActivityStream'); - }); - }); - }); -}); diff --git a/src/index.js b/src/index.js deleted file mode 100644 index 9d335a2..0000000 --- a/src/index.js +++ /dev/null @@ -1,39 +0,0 @@ -import btoa from 'btoa'; -import createMeta from './createMeta'; - -export {default as Oid} from './Oid'; -export {default as jqueryConnector} from './connectors/jqueryConnector'; -export {default as axiosConnector} from './connectors/axiosConnector'; -export default (postFn, getFn) => (hostname, instance, port = 80, isHttps = false) => { - const protocol = isHttps ? 'https' : 'http'; - return { - withImplicitAuth: () => createMeta({ - hostname, - instance, - protocol, - port, - postFn, - getFn, - }), - withAccessToken: (token) => createMeta({ - hostname, - instance, - protocol, - port, - token, - postFn, - getFn, - isBasic: false, - }), - withCreds: (username, password) => createMeta({ - hostname, - instance, - protocol, - port, - token: btoa(`${username}:${password}`), - postFn, - getFn, - isBasic: true, - }) - }; -}; diff --git a/src/index.specs.js b/src/index.specs.js deleted file mode 100644 index 7744a9c..0000000 --- a/src/index.specs.js +++ /dev/null @@ -1,99 +0,0 @@ -import sdk, {Oid, __RewireAPI__ as RewireApi} from './index'; -import oid from './Oid'; -import sinon from 'sinon'; - -describe('when loading the module', function() { - it('it should export the sdk as the default', () => { - sdk.should.be.a('function'); - }); - it('it should export Oid', () => { - Oid.should.equal(oid); - }); - - beforeEach(() => { - this.actual = undefined; - }); - - describe('given a post and get AJAX function', () => { - beforeEach(() => { - this.postFn = sinon.stub(); - this.getFn = sinon.stub(); - this.sdk = sdk(this.postFn, this.getFn); - }); - it('it should return a function to set V1 host information', () => { - this.sdk.should.be.a('function'); - }); - - describe('given a hostname, instance name, port, and https protocol', () => { - beforeEach(() => { - this.setSecurity = this.sdk('hostname', 'instance', 80, true); - }); - it('it should return a meta object with function to authenticate via username and password', () => { - this.setSecurity.withCreds.should.be.a('function'); - }); - it('it should return a meta object with function to authenticate via an access token', () => { - this.setSecurity.withAccessToken.should.be.a('function'); - }); - it('it should return a meta object with function to authenticate implicitly', () => { - this.setSecurity.withImplicitAuth.should.be.a('function'); - }); - - describe('given an access token', () => { - beforeEach(() => { - this.accessToken = 'access token'; - }); - describe('when creating the SDK', () => { - beforeEach(() => { - this.metaStub = sinon.mock() - .withExactArgs({ hostname: 'hostname', instance: 'instance', protocol: 'https', port: 80, token: this.accessToken, postFn: this.postFn, getFn: this.getFn, isBasic: false }) - .returns('meta'); - RewireApi.__Rewire__('createMeta', this.metaStub); - this.meta = this.setSecurity.withAccessToken(this.accessToken); - }); - it('it should return a Meta object with the access token, hostname, instance, port, protocol, post and get functions', () => { - this.meta.should.equal('meta'); - }); - }); - }); - - describe('given a username and password', () => { - beforeEach(() => { - this.username = 'username'; - this.password = 'password'; - }); - describe('when creating the SDK', () => { - beforeEach(() => { - this.token = 'username token'; - this.metaStub = sinon.mock() - .withExactArgs({ hostname: 'hostname', instance: 'instance', protocol: 'https', port: 80, token: this.token, postFn: this.postFn, getFn: this.getFn, isBasic: true }) - .returns('meta1'); - this.btoa = sinon.mock() - .withArgs(`${this.username}:${this.password}`) - .returns(this.token); - RewireApi.__Rewire__('createMeta', this.metaStub); - RewireApi.__Rewire__('btoa', this.btoa); - this.meta = this.setSecurity.withCreds(this.username, this.password); - }); - it('it should return a Meta object with the username/password encoded token, hostname, instance, port, protocol, post and get functions', () => { - this.meta.should.equal('meta1'); - }); - }); - }); - - describe('given no explicit credentials', () => { - describe('when creating the SDK', () => { - beforeEach(() => { - this.metaStub = sinon.mock() - .withExactArgs({ hostname: 'hostname', instance: 'instance', protocol: 'https', port: 80, postFn: this.postFn, getFn: this.getFn }) - .returns('meta1'); - RewireApi.__Rewire__('createMeta', this.metaStub); - this.meta = this.setSecurity.withImplicitAuth(); - }); - it('it should return a Meta object with hostname, instance, port, protocol, post and get functions', () => { - this.meta.should.equal('meta1'); - }); - }); - }); - }); - }); -}); diff --git a/src/transformDataToAsset.js b/src/transformDataToAsset.js deleted file mode 100644 index 15c78f1..0000000 --- a/src/transformDataToAsset.js +++ /dev/null @@ -1,49 +0,0 @@ -export default (assetData) => ({ - Attributes: reduceAssetData(assetData) -}); - -const reduceAssetData = (obj) => Object.keys(obj) - .reduce((output, key) => { - const attributeData = obj[key]; - if (Array.isArray(attributeData)) { - return { - ...output, - [key]: { - name: key, - value: attributeData.map(reduceRelationalAttributes) - } - }; - } - if (isFunction(attributeData)) { - return { - ...output, - [key]: { - value: obj[key](), - act: 'set' - } - }; - } - return { - ...output, - [key]: { - value: obj[key], - act: 'set' - } - }; - }, {}); - -const reduceRelationalAttributes = (obj) => { - if (typeof obj === 'string') { - return { - idref: obj, - act: 'add' - }; - } - return Object.keys(obj).reduce((output)=> { - output.idref = obj.idref; - output.act = obj.act ? obj.act : 'add'; - return output; - }, {}); -}; - -const isFunction = (obj) => obj && obj.constructor && obj.call && obj.apply; diff --git a/src/transformDataToAsset.specs.js b/src/transformDataToAsset.specs.js deleted file mode 100644 index bdff2b0..0000000 --- a/src/transformDataToAsset.specs.js +++ /dev/null @@ -1,114 +0,0 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; -import transformDataToAsset from './transformDataToAsset'; -chai.use(chaiAsPromised); -chai.should(); - -describe('src/transformDataToAsset', function() { - beforeEach(() => { - this.actual = undefined; - }); - describe('given an object of asset data', () => { - beforeEach(() => { - this.assetData = { - Value: 20 - }; - }); - describe('when transforming the asset data into something acceptable to the V1 Server instance', () => { - beforeEach(() => { - this.actual = transformDataToAsset(this.assetData); - }); - it('it should return an object with Attributes property', () => { - chai.should().exist(this.actual.Attributes); - this.actual.Attributes.Value.value.should.equal(20); - this.actual.Attributes.Value.act.should.equal('set'); - }); - }); - }); - - describe('given an object of asset data with single-relational values', () => { - beforeEach(() => { - this.assetData = { - Value: 20, - Member: 'Member:20' - }; - }); - - describe('when transforming the asset data to something acceptable to the V1 Server instance', () => { - beforeEach(() => { - this.actual = transformDataToAsset(this.assetData); - }); - it('it should transform keys with non-array values to single-relation properties on the output object', () => { - this.actual.Attributes.Member.value.should.equal('Member:20'); - this.actual.Attributes.Value.value.should.equal(20); - }); - it('it should set the action to set for each output attribute', () => { - this.actual.Attributes.Member.act.should.be.equal('set'); - this.actual.Attributes.Value.act.should.be.equal('set'); - }); - }); - }); - - describe('given an object of asset data with mutli-relational values that do not contain an idref', () => { - beforeEach(() => { - this.assetData = { - Actuals: ['Actual:10001', 'Actual:10002'] - }; - }); - - describe('when transforming the asset data to something acceptable to the V1 Server instance', () => { - beforeEach(() => { - this.actual = transformDataToAsset(this.assetData); - }); - it('it should transform keys with array values to a multi-relation asset attribute property on the output object', () => { - this.actual.Attributes.Actuals.name.should.equal('Actuals'); - this.actual.Attributes.Actuals.value[0].idref.should.equal('Actual:10001'); - this.actual.Attributes.Actuals.value[1].idref.should.equal('Actual:10002'); - }); - it('it should set the action for each value to add', () => { - this.actual.Attributes.Actuals.value[0].act.should.equal('add'); - this.actual.Attributes.Actuals.value[1].act.should.equal('add'); - }); - }); - }); - - describe('given an object of asset data with mutli-relational values that contain an idref', () => { - beforeEach(() => { - this.assetData = { - Actuals: [{idref: 'Actual:10001'}, {idref: 'Actual:10002'}] - }; - }); - - describe('when transforming the asset data to something acceptable to the V1 Server instance', () => { - beforeEach(() => { - this.actual = transformDataToAsset(this.assetData); - }); - it('it should transform keys with array values to a multi-relation asset attribute property on the output object', () => { - this.actual.Attributes.Actuals.name.should.equal('Actuals'); - this.actual.Attributes.Actuals.value[0].idref.should.equal('Actual:10001'); - this.actual.Attributes.Actuals.value[1].idref.should.equal('Actual:10002'); - }); - it('it should set the action for each value to add', () => { - this.actual.Attributes.Actuals.value[0].act.should.equal('add'); - this.actual.Attributes.Actuals.value[1].act.should.equal('add'); - }); - }); - - describe('given the multi-relational values contain an act action', () => { - beforeEach(() => { - this.assetData = { - Actuals: [{idref: 'Actual:10001', act: 'add'}, {idref: 'Actual:10002', act: 'remove'}] - }; - }); - describe('when transforming the asset data to something acceptable to the V1 Server instance', () => { - beforeEach(() => { - this.actual = transformDataToAsset(this.assetData); - }); - it('it should set the action for each value to the provided value', () => { - this.actual.Attributes.Actuals.value[0].act.should.equal('add'); - this.actual.Attributes.Actuals.value[1].act.should.equal('remove'); - }); - }); - }); - }); -}); diff --git a/wallaby.js b/wallaby.js deleted file mode 100644 index 3ac0fd9..0000000 --- a/wallaby.js +++ /dev/null @@ -1,28 +0,0 @@ -process.env.BABEL_ENV = 'test'; -process.env.NODE_ENV = 'test'; -var wallabyWebpack = require('wallaby-webpack'); -var webpackPostprocessor = wallabyWebpack({}); - -module.exports = function wallabyConfig(wallaby) { - return { - files: [ - {pattern: 'node_modules/babel-polyfill/dist/polyfill.js', instrument: false}, - {pattern: 'node_modules/chai/chai.js', instrument: false}, - {pattern: 'node_modules/chai-as-promised/lib/chai-as-promised', instrument: false}, - {pattern: 'src/**/*.js', load: false}, - {pattern: '!src/**/*.specs.js'} - ], - tests: [ - {pattern: 'src/**/*.specs.js', load: false} - ], - compilers: { - 'src/**/*.js': wallaby.compilers.babel() - }, - testFramework: 'mocha', - postprocessor: webpackPostprocessor, - setup: function setup() { - chai.should(); - window.__moduleBundler.loadTests(); - } - }; -};