Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"plugins": ["lodash"],
"presets": ["es2015", "stage-1"]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/node_modules
/.idea
/.vscode
/lib

*.log
120 changes: 116 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ <h3 id='foxapi-property'>Properties</h3>
<td><code><a href='#orders'>Orders</a></code></td>
<td>Orders instance</td>
</tr>
<tr id='foxapi-analytics'>
<td><code><b>analytics</b>
<td><code><a href='#analytics'>Analytics</a></code></td>
<td>Analytics instance</td>
</tr>
</tbody></table>

</section>
Expand Down Expand Up @@ -1461,6 +1466,103 @@ <h3 id='updateaddresspayload-field'>UpdateAddressPayload</h3>
</tbody></table>


</section>

</section>
<h2 id='analytics'>Analytics</h2><p>Accessible via <a href="#foxapi-analytics">analytics</a> property of <a href="#foxapi">FoxApi</a> instance.</p>

<section>
<h3 id='analytics-method'>Methods</h3>

<section >



<div class='section-comments'></div>

<table><thead>
<tr>
<th>Method</th>
<th>Returns</th>
<th>Description</th>
</tr>
</thead><tbody>
<tr id='analytics-trackevent'>
<td><code><b>trackEvent</b>(<nobr>&lt;Object&lt;<a href='#sphextracker'>SphexTracker</a>&gt;&gt;</nobr> <i>tracker</i>, <nobr>&lt;Function&gt;</nobr> <i>saltFunction?</i>)</nobr></code></td>
<td><code>Promise</code></td>
<td>Enables the tracking of UI specific events. The optional salt function must
be a random number generator.</td>
</tr>
</tbody></table>

</section>

</section>
<span id='sphextracker'></span>

<section>
<h3 id='sphextracker-field'>SphexTracker</h3>

<section >



<div class='section-comments'></div>

<table><thead>
<tr>
<th>Field</th>
<th>Type</th>
<th>Required</th>
<th>Example</th>
<th>Description</th>
</tr>
</thead><tbody>
<tr id='sphextracker-channel'>
<td><code><b>channel</b></code></td>
<td><code>Number</code>
<td><div data-icon="ei-check"></div></td>
<td></td>
<td>Unique Channel ID number</td>
</tr>
<tr id='sphextracker-subject'>
<td><code><b>subject</b></code></td>
<td><code>Number</code>
<td><div data-icon="ei-check"></div></td>
<td></td>
<td>Unique Subject ID number</td>
</tr>
<tr id='sphextracker-obj'>
<td><code><b>obj</b></code></td>
<td><code>String</code>
<td><div data-icon="ei-check"></div></td>
<td></td>
<td>Name of the object type you are tracking the event for</td>
</tr>
<tr id='sphextracker-verb'>
<td><code><b>verb</b></code></td>
<td><code>String</code>
<td><div data-icon="ei-check"></div></td>
<td></td>
<td>A single word that describes the event</td>
</tr>
<tr id='sphextracker-objid'>
<td><code><b>objId</b></code></td>
<td><code>Number</code>
<td><div data-icon="ei-check"></div></td>
<td></td>
<td>Unique number that can trace the object being tracked</td>
</tr>
<tr id='sphextracker-count'>
<td><code><b>count</b></code></td>
<td><code>Number</code>
<td><div data-icon="ei-check"></div></td>
<td></td>
<td></td>
</tr>
</tbody></table>


</section>

</section>
Expand Down Expand Up @@ -1503,6 +1605,12 @@ <h3 id='auth-method'>Methods</h3>
<td><code>Promse</code></td>
<td>Removes JWT cookie.</td>
</tr>
<tr id='auth-restorepassword'>
<td><code><b>restorePassword</b>(<nobr>&lt;String&gt;</nobr> <i>email</i>)</nobr></code></td>
<td><code>Promise</code></td>
<td>requests email instructions to reset password
creates new password</td>
</tr>
</tbody></table>

</section>
Expand Down Expand Up @@ -1687,11 +1795,15 @@ <h3 id='cart-method'>Methods</h3>
<td>Adds a gift card as payment method for the cart.
<p>Creates payment method with a given amount using store credit.</p></td>
</tr>
<tr id='cart-removegiftcards'>
<td><code><b>removeGiftCards</b>()</nobr></code></td>
<tr id='cart-removegiftcard'>
<td><code><b>removeGiftCard</b>(<nobr>&lt;string&gt;</nobr> <i>giftCardCode</i>)</nobr></code></td>
<td><code>Promise&lt;<a href='#fullorder'>FullOrder</a>&gt;</code></td>
<td>Removes gift card with provided code payment method from the cart.</td>
</tr>
<tr id='cart-removestorecredits'>
<td><code><b>removeStoreCredits</b>()</nobr></code></td>
<td><code>Promise&lt;<a href='#fullorder'>FullOrder</a>&gt;</code></td>
<td>Removes all gift cards payment methods of the cart.
<p>Removes all store credits payment methods of the cart.</p></td>
<td>Removes all store credits payment methods of the cart.</td>
</tr>
<tr id='cart-addcoupon'>
<td><code><b>addCoupon</b>(<nobr>&lt;Number&gt;</nobr> <i>code</i>)</nobr></code></td>
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
"homepage": "https://github.com/FoxComm/api-js#readme",
"dependencies": {
"debug": "^2.2.0",
"jwt-decode": "^2.0.1",
"lodash": "^4.17.4",
"postinstall-build": "^0.2.1",
"superagent": "^3.2.1",
"jwt-decode": "^2.0.1"
"superagent": "^3.2.1"
},
"devDependencies": {
"babel-cli": "^6.9.0",
"babel-plugin-lodash": "^3.2.11",
"babel-preset-es2015": "^6.9.0",
"babel-preset-stage-1": "^6.5.0",
"escape-html": "^1.0.3",
Expand Down
61 changes: 61 additions & 0 deletions src/api/analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// @class Analytics
// Accessible via [analytics](#foxapi-analytics) property of [FoxApi](#foxapi) instance.

import * as endpoints from '../endpoints';
import querystring from 'querystring';

function randomSalt(maxRand = 100000) {
return Math.floor(Math.random() * maxRand);
}

// Add a count argument
function sphexTrackerUrl(tracker, saltFunction = randomSalt) {
const { channel, subject, verb, obj, objId, count = 1 } = tracker;

const queryParams = {
ch: channel,
sub: subject,
v: verb,
ob: obj,
id: objId,
c: count,
slt: saltFunction(),
};
const query = querystring.stringify(queryParams);

return `${endpoints.hal}?${query}`;
}

export default class Analytics {
constructor(api) {
this.api = api;
}

/**
* @method trackEvent(tracker: Object<SphexTracker>, saltFunction?: Function): Promise
* Enables the tracking of UI specific events. The optional salt function must
* be a random number generator.
*/
trackEvent(tracker, saltFunction = randomSalt) {
return this.api.get(sphexTrackerUrl(tracker, saltFunction));
}
}

// @miniclass SphexTracker (Analytics)
// @field channel: Number
// Unique Channel ID number
//
// @field subject: Number
// Unique Subject ID number
//
// @field obj: String
// Name of the object type you are tracking the event for
//
// @field verb: String
// A single word that describes the event
//
// @field objId: Number
// Unique number that can trace the object being tracked
//
// @field count: Number
// Quantity
4 changes: 2 additions & 2 deletions src/api/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ export default class Cart {
}

/**
* @method removeGiftCards(): Promise<FullOrder>
* @method removeStoreCredits(): Promise<FullOrder>
* Removes all store credits payment methods of the cart.
*/
removeStoreCrdits() {
removeStoreCredits() {
return this.api.delete(endpoints.cartPaymentStoreCredits).then(normalizeResponse);
}

Expand Down
14 changes: 11 additions & 3 deletions src/api/credit-cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,21 @@ export default class CreditCards {
if (response.error) {
reject([response.error.message]);
} else {
var payload = creditCardFromStripePayload(response, billingAddress, addressIsNew);
return createCardFromStripeToken(response, billingAddress, addressIsNew)
.then(response => resolve(response))
.catch(err => reject(err));
}
});
});
}

createCardFromStripeToken(token, billingAddress, addressIsNew) {
return new Promise((resolve, reject) => {
var payload = creditCardFromStripePayload(token, billingAddress, addressIsNew);

return this.api.post(endpoints.creditCards, payload)
.then(response => resolve(response))
.catch(err => !!err.responseJson.errors ? reject(err.responseJson.errors) : reject([err.message]));
}
});
});
}

Expand Down
3 changes: 3 additions & 0 deletions src/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ export const changePassword = '/v1/my/account/change-password';
// orders endpoints
export const orders = '/v1/my/orders';
export const order = referenceNumber => `/v1/my/orders/${referenceNumber}`;

// analytics endpoints
export const hal = '/v1/hal';
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Cart from './api/cart';
import Account from './api/account';
import Orders from './api/orders';
import jwtDecode from 'jwt-decode';
import Analytics from './api/analytics';

export default class Api {
constructor(args) {
Expand Down Expand Up @@ -62,6 +63,10 @@ export default class Api {
// @property orders: Orders
// Orders instance
this.orders = new Orders(this);

// @property analytics: Analytics
// Analytics instance
this.analytics = new Analytics(this);
}

// @method addAuth(jwt: String): FoxApi
Expand Down
19 changes: 13 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ babel-plugin-check-es2015-constants@^6.3.13:
dependencies:
babel-runtime "^6.0.0"

babel-plugin-lodash@^3.2.11:
version "3.2.11"
resolved "https://registry.yarnpkg.com/babel-plugin-lodash/-/babel-plugin-lodash-3.2.11.tgz#21c8fdec9fe1835efaa737873e3902bdd66d5701"
dependencies:
glob "^7.1.1"
lodash "^4.17.2"

babel-plugin-syntax-async-functions@^6.8.0:
version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95"
Expand Down Expand Up @@ -968,8 +975,8 @@ form-data@^2.1.1, form-data@~2.1.1:
mime-types "^2.1.12"

formidable@^1.0.17:
version "1.0.17"
resolved "https://registry.yarnpkg.com/formidable/-/formidable-1.0.17.tgz#ef5491490f9433b705faa77249c99029ae348559"
version "1.1.1"
resolved "https://registry.yarnpkg.com/formidable/-/formidable-1.1.1.tgz#96b8886f7c3c3508b932d6bd70c4d3a88f35f1a9"

fs-readdir-recursive@^1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -1063,7 +1070,7 @@ glob@^5.0.5:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^7.0.5:
glob@^7.0.5, glob@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8"
dependencies:
Expand Down Expand Up @@ -1338,7 +1345,7 @@ kind-of@^3.0.2:
unicode-7.0.0 "^0.1.5"
xregexp "^2.0.0"

lodash@^4.2.0:
lodash@^4.17.2, lodash@^4.17.4, lodash@^4.2.0:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

Expand Down Expand Up @@ -1847,8 +1854,8 @@ strip-json-comments@~1.0.4:
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-1.0.4.tgz#1e15fbcac97d3ee99bf2d73b4c656b082bbafb91"

superagent@^3.2.1:
version "3.3.2"
resolved "https://registry.yarnpkg.com/superagent/-/superagent-3.3.2.tgz#23b4ed895911215a1f90b44d16638b6492f9c114"
version "3.4.0"
resolved "https://registry.yarnpkg.com/superagent/-/superagent-3.4.0.tgz#cf8e40b303d5b2949c0fb036ddc30927e14958c7"
dependencies:
component-emitter "^1.2.0"
cookiejar "^2.0.6"
Expand Down