Verified Commit d2c894cf authored by Kevin Cristiano's avatar Kevin Cristiano 🌎
Browse files

from npm pack


Signed-off-by: Kevin Cristiano's avatarKevin Cristiano <kcristiano@kcristiano.com>
parents
{
"presets": [
"es2015",
"stage-2",
"flow"
]
}
{
"source": "./src",
"destination": "./docs",
"plugins": [
{
"name": "esdoc-standard-plugin",
"option": {
"brand": {
"logo": "./globe.svg",
"title": "Caldera API Client",
"description": "JavaScript API client for Caldera Forms",
"repository": "https://github.com/calderawp/caldera-api-client",
"site": "https://calderalabs.org/caldera-api-client/",
"author": "http://calderalabs.org",
"image": "https://calderaforms.com/wp-content/themes/caldera-forms-dot-com/img/caldera-forms-logo.svg"
},
"manual": {
"index": "./manual/index.md",
"globalIndex": true,
"files": [
"./manual/overview.md",
"./README.md"
]
}
}
},
{
"name": "esdoc-flow-plugin"
},
{
"name": "esdoc-jsx-plugin", "option": {"enable": true}
}
]
}
{
"env": {
"browser": true,
"es6": true,
"jest/globals": true
},
"extends": [
"eslint:recommended",
"plugin:flowtype/recommended"
],
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"sourceType": "module"
},
"parser": "babel-eslint",
"plugins": [
"flowtype",
"react",
"jest"
],
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"jest/prefer-to-have-length": "warn",
"jest/valid-expect": "error"
}
}
\ No newline at end of file
[ignore]
[include]
[libs]
[lints]
[options]
[strict]
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="FLOW" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/api-client.iml" filepath="$PROJECT_DIR$/.idea/api-client.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
language: node_js
node_js:
- "8"
cache:
yarn: true
directories:
- node_modules
script:
- yarn test:coverage
after_script:
- COVERALLS_REPO_TOKEN=$coveralls_repo_token npm run coveralls
\ No newline at end of file
# Contributing To Caldera API Client
Thanks for your help. If you would like to contribute, you can [create a pull request](https://help.github.com/articles/about-pull-requests/) [here](https://github.com/calderawp/caldera-api-client/pulls).
Please review the readme for notes on development scripts and installation.
This library uses Flow. Make sure to run flow checks before submitting your PR.
## Commits And Branches
Please keep the following in mind:
* Do not commit to the master branch of your fork. Create 1 branch per pull request. Name that branch for the issue number.
- Good: `feature/42` <- This adds the feature described in issue 42.
- Good: `bug/11` <- This fixes the bug described in issue 11.
- Find but not good `improve-form-endpoint` <- Descriptive, but not as descriptive as issue description is.
- Bad: `patch-1` <- What Github creates by default.
* Every commit must have a descriptive commit message that references the issue number and relates to one change.
- Good: `Added support for type argument in forms endpoint #42` <- Short, descriptive, has issue #
- Bad: `Added support for type argument in forms endpoint` <- No issue number
- Bad: `Added several new things #42` <- Meaningless.
* Every commit must have a descriptive commit message that references the issue number and relates to one change.
* Run the linter
## Code Quality
* Tests are required
- No pull requests that do not include tests or reduce the current test coverage will be rejected.
* All code must be documented inline using esdocs
- Any pull request that reduces the documentation coverage will not be accepted.
* If you are adding a new feature, include an example of how to use the feature in the manual.
MIT License
Copyright (c) 2017 Gokulnath Reddy
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.
# caldera-api-client
JavaScript API client for [Caldera Forms REST API](https://calderaforms.com/doc/caldera-forms-rest-api/) and Caldera Forms Pro REST API.
🌋 👀 [Documentation](https://calderalabs.org/caldera-api-client/)
[![Build Status](https://travis-ci.org/CalderaWP/caldera-api-client.svg?branch=master)](https://travis-ci.org/CalderaWP/caldera-api-client.svg)
[![Documentation Status](https://travis-ci.org/CalderaWP/caldera-api-client.svg?branch=master)](https://travis-ci.org/CalderaWP/caldera-api-client.svg)
[![Maintainability](https://api.codeclimate.com/v1/badges/a2e2c1afbb3eae8a6635/maintainability)](https://codeclimate.com/github/CalderaWP/caldera-api-client/maintainability)
## Install
`npm i @caldera-labs/api-client`
## Usage
Create a form client and use it to get page one of form configs via API
```js
import {wpClientFactory} from '@caldera-labs/api-client';
const formsAdminApiClient = wpClientFactory(
'https://hiroy.club/wp-json/cf-api/v2', //root of Caldera Forms REST API namespace
'12345', //the nonce for REST API cookie authentication
'forms' //type of client to get
);
let forms = [];
formsAdminApiClient(page).then(r => {
forms = r;
}).catch(error => {
console.log(error);
throw error;
});
```
See: [http://calderalabs.org/caldera-api-client/manual/overview.html#usage](http://calderalabs.org/caldera-api-client/manual/overview.html#usage)
## Development Requirements
* [npm](https://www.npmjs.com/get-npm)
* [Yarn](https://yarnpkg.com/lang/en/docs/install/#mac-stable)
* [Git]()
* [Flow](https://flow.org/en/docs/install/)
## Testing
We use [Facebook Jest](https://facebook.github.io/jest/) for unit tests. Test go in the directory `__tests__`.
* Run test watcher
```
yarn test
```
Make sure to review the docs on [testing requests](http://calderalabs.org/caldera-api-client/manual/overview.html#mocking-requests)
## Scripts
### Build for release
* `yarn build`
- Runs tests, and flow type checks and Babel compiles with minification and source map.
This script calls a pre, compile, and post subcommands. For consistency, please call other scripts at those three events.
### Tests
*`yarn test`
- Run test watcher
* `npm test:once`
- Run tests once
### Type-checking With Flow
* `yarn flow`
### Lint Code
* `yarn lint`
- Run linter and fixer watch
* `yarn lint:fix`
- Lint and fix code once
* `yarn lint:once`
- Lint code once
### Generate Documentation
* `npm run documentation`
- Generates documentation from inline docs
- Generates documentation from markdown files in /manual
### Release To npm
Must be [logged in as project maintainer via npm cli](https://docs.npmjs.com/cli/adduser)
* `yarn release`
import {EntriesClient} from '../src/EntriesClient';
const formId = 'CF5b197831b60ae';
const entriesCollection = require('./mock-data/entries/CF5b197831b60ae.json');
const entries26 = require('./mock-data/entries/CF5b197831b60ae/26.json');
const entries27 = require('./mock-data/entries/CF5b197831b60ae/27.json');
describe( 'Entries client', () => {
beforeEach(() => {
fetch.resetMocks();
});
describe( 'Mock data', () => {
it( 'has the mock data for entries', () => {
expect( typeof entriesCollection ).toBe( 'object' );
});
it( 'has the right number of mock entries', () => {
expect( Object.keys(entriesCollection) ).toHaveLength( 2 );
});
it( 'has entry 26', () => {
expect( typeof entries26 ).toBe( 'object' );
});
it( 'has entry 27', () => {
expect( typeof entries27 ).toBe( 'object' );
});
it( 'can re-serialize mock data and still be a good mock', () => {
expect(JSON.parse(JSON.stringify(entriesCollection))).toEqual(entriesCollection);
});
});
describe( 'Endpoint Urls', () => {
it( 'Forms entries list URL', () => {
const client = new EntriesClient('https://hiroy.club/wp-json/cf-api/v1');
expect( client.getEntriesEndpoint(formId)).toEqual('entries/CF5b197831b60ae');
});
it( 'Single entry URL', () => {
const client = new EntriesClient('https://hiroy.club/wp-json/cf-api/v1');
expect( client.getEntryEndpoint(formId,27)).toEqual('entries/CF5b197831b60ae/27');
});
it( 'Resend entry URL', () => {
const client = new EntriesClient('https://hiroy.club/wp-json/cf-api/v1');
expect( client.getEntryResendEndpoint(formId,27)).toEqual('entries/CF5b197831b60ae/27/resend');
});
});
describe( 'getting entries', () => {
it( 'Gets entries collection', () => {
fetch.mockResponseOnce(new Response(JSON.stringify({a:1})));
const client = new EntriesClient('https://hiroy.club/wp-json/cf-api/v1');
client.setNonce('aaaa-aa-a');
client.getEntries(formId).then( response => {
expect( response ).toEqual(entriesCollection);
},error => {});
expect(fetch.mock.calls).toHaveLength(1);
});
it( 'Gets a single entry', () => {
fetch.mockResponseOnce(new Response(JSON.stringify(entries26)));
const client = new EntriesClient('https://hiroy.club/wp-json/cf-api/v1');
client.getEntry(formId,26).then( response => {
expect( response ).toEqual(entries26);
},error => {});
expect(fetch.mock.calls).toHaveLength(1);
});
});
describe( 'Resending entries', () => {
it( 'Resends a single entry', () => {
const r = {
resent: true,
entry_id: '26'
};
fetch.mockResponseOnce(new Response(JSON.stringify(r)));
const client = new EntriesClient('https://hiroy.club/wp-json/cf-api/v1');
client.resendEntry(formId,26).then( response => {
expect( response ).toEqual({});
},error => {});
expect(fetch.mock.calls).toHaveLength(1);
});
});
describe( 'deleting entries', () => {
it( 'Deletes a single entry', () => {
const r = {
message: 'Entry Deleted'
};
fetch.mockResponseOnce(new Response(JSON.stringify(r)));
const client = new EntriesClient('https://hiroy.club/wp-json/cf-api/v1');
client.deleteEntry(formId,26).then( response => {
expect( response ).toEqual(r);
},error => {});
expect(fetch.mock.calls).toHaveLength(1);
});
it( 'Deletes all entries of form', () => {
const r = {
message: 'All Entry Deleted'
};
fetch.mockResponseOnce(new Response(JSON.stringify(r)));
const client = new EntriesClient('https://hiroy.club/wp-json/cf-api/v1');
client.deleteEntries(formId).then( response => {
expect( response ).toEqual(r);
},error => {});
expect(fetch.mock.calls).toHaveLength(1);
});
});
});
\ No newline at end of file
import {FormsClient} from '../src/FormsClient';
describe( 'Forms Client', () => {
beforeEach(() => {
fetch.resetMocks();
});
const form = {ID: 'CF1'};
const forms = [
form
];
const formsApiRoute = 'https://wordpress.test/wp-json/cf-api/v2/forms';
describe( 'Urls are correct', () => {
it( 'creates URL for form endpoint correctly', () => {
const client = new FormsClient(formsApiRoute );
expect( client.getFormEndpoint('cf1') ).toEqual('forms/cf1');
});
it( 'creates URL for forms endpoint correctly', () => {
const client = new FormsClient(formsApiRoute );
expect( client.getFormsEndpoint() ).toEqual('forms');
});
});
describe( 'Forms endpoint', () => {
it( 'Gets forms', () =>{
const client = new FormsClient(formsApiRoute );
client.setNonce('12345');
fetch.mockResponseOnce(JSON.stringify(forms));
client.getForms(1).then( response => {
expect( response ).toEqual(forms);
}).catch((error) => {
// eslint-disable-next-line no-console
console.log(error);
});
expect(fetch.mock.calls).toHaveLength(1);
});
});
describe( 'Form endpoint', () => {
it( 'Gets a form', () =>{
const client = new FormsClient(formsApiRoute );
client.setNonce('12345');
fetch.mockResponseOnce(JSON.stringify(form));
client.getForm('CF1').then( response => {
expect( response ).toEqual(form);
}).catch((error) => {
// eslint-disable-next-line no-console
console.log(error);
});
expect(fetch.mock.calls).toHaveLength(1);
});
});
describe( 'preview route', () => {
beforeEach(() => {
fetch.resetMocks();
});
it( 'gets form preview', () => {
const mockPreviewHtml = '<div><form></form></div>';
const mockResponse = {
js: {a:1},
css: {b:1},
html: mockPreviewHtml
};
const client = new FormsClient(formsApiRoute);
client.setNonce('12345');
fetch.mockResponseOnce(JSON.stringify(mockResponse));
client.getFormPreview('CF1').then(response => {
expect(response).toEqual(mockResponse);
},error => {
//nothing here, but test will generate an error without it.
});
expect(fetch.mock.calls).toHaveLength(1);
});
});
describe( 'Create form route', () => {
beforeEach(() => {
fetch.resetMocks();
});
it( 'creates forms', () => {
const client = new FormsClient(formsApiRoute );
client.setNonce('12345');
const mockForm = {
ID: 'cf12345',
name: 'new form'
};
fetch.mockResponseOnce(JSON.stringify(mockForm));
client.createForm('new form', {
ID: 'cf12345'
}).then( response => {
expect( response ).toEqual(mockForm);
}).catch((error) => {
// eslint-disable-next-line no-console
console.log(error);
});
expect(fetch.mock.calls).toHaveLength(1);
});
});
describe( 'Delete form route', () => {
beforeEach(() => {
fetch.resetMocks();
});
it( 'creates forms', () => {
const client = new FormsClient(formsApiRoute );
client.setNonce('12345');
const r = {
message: 'deleted'
};
fetch.mockResponseOnce(JSON.stringify(r));
client.deleteForm('cf12345').then( response => {
expect( response ).toEqual(r);
}).catch((error) => {
// eslint-disable-next-line no-console
console.log(error);
});
expect(fetch.mock.calls).toHaveLength(1);
});
});
});
import {GeneralSettingClient,prepareGeneralSettingsData} from '../src/GeneralSettingClient';
const settings = {
styleIncludes: {
grid: false,
form: true,
alert: true
},
otherSettings : {
cdnEnable: false
}
};
describe( 'prepareGeneralSettingsData', () => {
it( 'fills in missing style includes', () => {
expect(prepareGeneralSettingsData({
grid: false,
})).toEqual(settings);
});
});
describe( 'ProLocalSettingClient', () => {
beforeEach(() => {
fetch.resetMocks();
});
it( 'Gets settings', () => {
fetch.mockResponseOnce(new Response(JSON.stringify(settings)));
const client = new GeneralSettingClient('https://hiroy.club/wp-json/cf-api/v2');
client.getSettings().then(res => {
expect(res).toEqual(settings);
},error => {
//nothing here, but test will generate an error without it.
});
expect(fetch.mock.calls).toHaveLength(1);
});
it( 'Updates settings', () => {
fetch.mockResponseOnce(new Response(JSON.stringify(settings)));
const client = new GeneralSettingClient('https://hiroy.club/wp-json/cf-api/v2');
client.updateSettings(settings).then(res => {
expect(res).toEqual(settings);
},error => {
//nothing here, but test will generate an error without it.
});