Skip to content

Commit 2f9d0ac

Browse files
authored
Merge pull request #33 from FoxComm/feature/ic-develop
Changes for IC work
2 parents eb24e23 + df19196 commit 2f9d0ac

10 files changed

Lines changed: 217 additions & 17 deletions

File tree

.babelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2+
"plugins": ["lodash"],
23
"presets": ["es2015", "stage-1"]
34
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/node_modules
22
/.idea
3+
/.vscode
34
/lib
45

56
*.log

index.html

Lines changed: 116 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ <h3 id='foxapi-property'>Properties</h3>
228228
<td><code><a href='#orders'>Orders</a></code></td>
229229
<td>Orders instance</td>
230230
</tr>
231+
<tr id='foxapi-analytics'>
232+
<td><code><b>analytics</b>
233+
<td><code><a href='#analytics'>Analytics</a></code></td>
234+
<td>Analytics instance</td>
235+
</tr>
231236
</tbody></table>
232237

233238
</section>
@@ -1461,6 +1466,103 @@ <h3 id='updateaddresspayload-field'>UpdateAddressPayload</h3>
14611466
</tbody></table>
14621467

14631468

1469+
</section>
1470+
1471+
</section>
1472+
<h2 id='analytics'>Analytics</h2><p>Accessible via <a href="#foxapi-analytics">analytics</a> property of <a href="#foxapi">FoxApi</a> instance.</p>
1473+
1474+
<section>
1475+
<h3 id='analytics-method'>Methods</h3>
1476+
1477+
<section >
1478+
1479+
1480+
1481+
<div class='section-comments'></div>
1482+
1483+
<table><thead>
1484+
<tr>
1485+
<th>Method</th>
1486+
<th>Returns</th>
1487+
<th>Description</th>
1488+
</tr>
1489+
</thead><tbody>
1490+
<tr id='analytics-trackevent'>
1491+
<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>
1492+
<td><code>Promise</code></td>
1493+
<td>Enables the tracking of UI specific events. The optional salt function must
1494+
be a random number generator.</td>
1495+
</tr>
1496+
</tbody></table>
1497+
1498+
</section>
1499+
1500+
</section>
1501+
<span id='sphextracker'></span>
1502+
1503+
<section>
1504+
<h3 id='sphextracker-field'>SphexTracker</h3>
1505+
1506+
<section >
1507+
1508+
1509+
1510+
<div class='section-comments'></div>
1511+
1512+
<table><thead>
1513+
<tr>
1514+
<th>Field</th>
1515+
<th>Type</th>
1516+
<th>Required</th>
1517+
<th>Example</th>
1518+
<th>Description</th>
1519+
</tr>
1520+
</thead><tbody>
1521+
<tr id='sphextracker-channel'>
1522+
<td><code><b>channel</b></code></td>
1523+
<td><code>Number</code>
1524+
<td><div data-icon="ei-check"></div></td>
1525+
<td></td>
1526+
<td>Unique Channel ID number</td>
1527+
</tr>
1528+
<tr id='sphextracker-subject'>
1529+
<td><code><b>subject</b></code></td>
1530+
<td><code>Number</code>
1531+
<td><div data-icon="ei-check"></div></td>
1532+
<td></td>
1533+
<td>Unique Subject ID number</td>
1534+
</tr>
1535+
<tr id='sphextracker-obj'>
1536+
<td><code><b>obj</b></code></td>
1537+
<td><code>String</code>
1538+
<td><div data-icon="ei-check"></div></td>
1539+
<td></td>
1540+
<td>Name of the object type you are tracking the event for</td>
1541+
</tr>
1542+
<tr id='sphextracker-verb'>
1543+
<td><code><b>verb</b></code></td>
1544+
<td><code>String</code>
1545+
<td><div data-icon="ei-check"></div></td>
1546+
<td></td>
1547+
<td>A single word that describes the event</td>
1548+
</tr>
1549+
<tr id='sphextracker-objid'>
1550+
<td><code><b>objId</b></code></td>
1551+
<td><code>Number</code>
1552+
<td><div data-icon="ei-check"></div></td>
1553+
<td></td>
1554+
<td>Unique number that can trace the object being tracked</td>
1555+
</tr>
1556+
<tr id='sphextracker-count'>
1557+
<td><code><b>count</b></code></td>
1558+
<td><code>Number</code>
1559+
<td><div data-icon="ei-check"></div></td>
1560+
<td></td>
1561+
<td></td>
1562+
</tr>
1563+
</tbody></table>
1564+
1565+
14641566
</section>
14651567

14661568
</section>
@@ -1503,6 +1605,12 @@ <h3 id='auth-method'>Methods</h3>
15031605
<td><code>Promse</code></td>
15041606
<td>Removes JWT cookie.</td>
15051607
</tr>
1608+
<tr id='auth-restorepassword'>
1609+
<td><code><b>restorePassword</b>(<nobr>&lt;String&gt;</nobr> <i>email</i>)</nobr></code></td>
1610+
<td><code>Promise</code></td>
1611+
<td>requests email instructions to reset password
1612+
creates new password</td>
1613+
</tr>
15061614
</tbody></table>
15071615

15081616
</section>
@@ -1687,11 +1795,15 @@ <h3 id='cart-method'>Methods</h3>
16871795
<td>Adds a gift card as payment method for the cart.
16881796
<p>Creates payment method with a given amount using store credit.</p></td>
16891797
</tr>
1690-
<tr id='cart-removegiftcards'>
1691-
<td><code><b>removeGiftCards</b>()</nobr></code></td>
1798+
<tr id='cart-removegiftcard'>
1799+
<td><code><b>removeGiftCard</b>(<nobr>&lt;string&gt;</nobr> <i>giftCardCode</i>)</nobr></code></td>
1800+
<td><code>Promise&lt;<a href='#fullorder'>FullOrder</a>&gt;</code></td>
1801+
<td>Removes gift card with provided code payment method from the cart.</td>
1802+
</tr>
1803+
<tr id='cart-removestorecredits'>
1804+
<td><code><b>removeStoreCredits</b>()</nobr></code></td>
16921805
<td><code>Promise&lt;<a href='#fullorder'>FullOrder</a>&gt;</code></td>
1693-
<td>Removes all gift cards payment methods of the cart.
1694-
<p>Removes all store credits payment methods of the cart.</p></td>
1806+
<td>Removes all store credits payment methods of the cart.</td>
16951807
</tr>
16961808
<tr id='cart-addcoupon'>
16971809
<td><code><b>addCoupon</b>(<nobr>&lt;Number&gt;</nobr> <i>code</i>)</nobr></code></td>

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@
2828
"homepage": "https://github.com/FoxComm/api-js#readme",
2929
"dependencies": {
3030
"debug": "^2.2.0",
31+
"jwt-decode": "^2.0.1",
32+
"lodash": "^4.17.4",
3133
"postinstall-build": "^0.2.1",
32-
"superagent": "^3.2.1",
33-
"jwt-decode": "^2.0.1"
34+
"superagent": "^3.2.1"
3435
},
3536
"devDependencies": {
3637
"babel-cli": "^6.9.0",
38+
"babel-plugin-lodash": "^3.2.11",
3739
"babel-preset-es2015": "^6.9.0",
3840
"babel-preset-stage-1": "^6.5.0",
3941
"escape-html": "^1.0.3",

src/api/analytics.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// @class Analytics
2+
// Accessible via [analytics](#foxapi-analytics) property of [FoxApi](#foxapi) instance.
3+
4+
import * as endpoints from '../endpoints';
5+
import querystring from 'querystring';
6+
7+
function randomSalt(maxRand = 100000) {
8+
return Math.floor(Math.random() * maxRand);
9+
}
10+
11+
// Add a count argument
12+
function sphexTrackerUrl(tracker, saltFunction = randomSalt) {
13+
const { channel, subject, verb, obj, objId, count = 1 } = tracker;
14+
15+
const queryParams = {
16+
ch: channel,
17+
sub: subject,
18+
v: verb,
19+
ob: obj,
20+
id: objId,
21+
c: count,
22+
slt: saltFunction(),
23+
};
24+
const query = querystring.stringify(queryParams);
25+
26+
return `${endpoints.hal}?${query}`;
27+
}
28+
29+
export default class Analytics {
30+
constructor(api) {
31+
this.api = api;
32+
}
33+
34+
/**
35+
* @method trackEvent(tracker: Object<SphexTracker>, saltFunction?: Function): Promise
36+
* Enables the tracking of UI specific events. The optional salt function must
37+
* be a random number generator.
38+
*/
39+
trackEvent(tracker, saltFunction = randomSalt) {
40+
return this.api.get(sphexTrackerUrl(tracker, saltFunction));
41+
}
42+
}
43+
44+
// @miniclass SphexTracker (Analytics)
45+
// @field channel: Number
46+
// Unique Channel ID number
47+
//
48+
// @field subject: Number
49+
// Unique Subject ID number
50+
//
51+
// @field obj: String
52+
// Name of the object type you are tracking the event for
53+
//
54+
// @field verb: String
55+
// A single word that describes the event
56+
//
57+
// @field objId: Number
58+
// Unique number that can trace the object being tracked
59+
//
60+
// @field count: Number
61+
// Quantity

src/api/cart.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ export default class Cart {
187187
}
188188

189189
/**
190-
* @method removeGiftCards(): Promise<FullOrder>
190+
* @method removeStoreCredits(): Promise<FullOrder>
191191
* Removes all store credits payment methods of the cart.
192192
*/
193-
removeStoreCrdits() {
193+
removeStoreCredits() {
194194
return this.api.delete(endpoints.cartPaymentStoreCredits).then(normalizeResponse);
195195
}
196196

src/api/credit-cards.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,21 @@ export default class CreditCards {
3636
if (response.error) {
3737
reject([response.error.message]);
3838
} else {
39-
var payload = creditCardFromStripePayload(response, billingAddress, addressIsNew);
39+
return createCardFromStripeToken(response, billingAddress, addressIsNew)
40+
.then(response => resolve(response))
41+
.catch(err => reject(err));
42+
}
43+
});
44+
});
45+
}
46+
47+
createCardFromStripeToken(token, billingAddress, addressIsNew) {
48+
return new Promise((resolve, reject) => {
49+
var payload = creditCardFromStripePayload(token, billingAddress, addressIsNew);
4050

4151
return this.api.post(endpoints.creditCards, payload)
4252
.then(response => resolve(response))
4353
.catch(err => !!err.responseJson.errors ? reject(err.responseJson.errors) : reject([err.message]));
44-
}
45-
});
4654
});
4755
}
4856

src/endpoints.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ export const changePassword = '/v1/my/account/change-password';
5454
// orders endpoints
5555
export const orders = '/v1/my/orders';
5656
export const order = referenceNumber => `/v1/my/orders/${referenceNumber}`;
57+
58+
// analytics endpoints
59+
export const hal = '/v1/hal';

src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import Cart from './api/cart';
2020
import Account from './api/account';
2121
import Orders from './api/orders';
2222
import jwtDecode from 'jwt-decode';
23+
import Analytics from './api/analytics';
2324

2425
export default class Api {
2526
constructor(args) {
@@ -62,6 +63,10 @@ export default class Api {
6263
// @property orders: Orders
6364
// Orders instance
6465
this.orders = new Orders(this);
66+
67+
// @property analytics: Analytics
68+
// Analytics instance
69+
this.analytics = new Analytics(this);
6570
}
6671

6772
// @method addAuth(jwt: String): FoxApi

yarn.lock

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ babel-plugin-check-es2015-constants@^6.3.13:
285285
dependencies:
286286
babel-runtime "^6.0.0"
287287

288+
babel-plugin-lodash@^3.2.11:
289+
version "3.2.11"
290+
resolved "https://registry.yarnpkg.com/babel-plugin-lodash/-/babel-plugin-lodash-3.2.11.tgz#21c8fdec9fe1835efaa737873e3902bdd66d5701"
291+
dependencies:
292+
glob "^7.1.1"
293+
lodash "^4.17.2"
294+
288295
babel-plugin-syntax-async-functions@^6.8.0:
289296
version "6.13.0"
290297
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95"
@@ -968,8 +975,8 @@ form-data@^2.1.1, form-data@~2.1.1:
968975
mime-types "^2.1.12"
969976

970977
formidable@^1.0.17:
971-
version "1.0.17"
972-
resolved "https://registry.yarnpkg.com/formidable/-/formidable-1.0.17.tgz#ef5491490f9433b705faa77249c99029ae348559"
978+
version "1.1.1"
979+
resolved "https://registry.yarnpkg.com/formidable/-/formidable-1.1.1.tgz#96b8886f7c3c3508b932d6bd70c4d3a88f35f1a9"
973980

974981
fs-readdir-recursive@^1.0.0:
975982
version "1.0.0"
@@ -1063,7 +1070,7 @@ glob@^5.0.5:
10631070
once "^1.3.0"
10641071
path-is-absolute "^1.0.0"
10651072

1066-
glob@^7.0.5:
1073+
glob@^7.0.5, glob@^7.1.1:
10671074
version "7.1.1"
10681075
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8"
10691076
dependencies:
@@ -1338,7 +1345,7 @@ kind-of@^3.0.2:
13381345
unicode-7.0.0 "^0.1.5"
13391346
xregexp "^2.0.0"
13401347

1341-
lodash@^4.2.0:
1348+
lodash@^4.17.2, lodash@^4.17.4, lodash@^4.2.0:
13421349
version "4.17.4"
13431350
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
13441351

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

18491856
superagent@^3.2.1:
1850-
version "3.3.2"
1851-
resolved "https://registry.yarnpkg.com/superagent/-/superagent-3.3.2.tgz#23b4ed895911215a1f90b44d16638b6492f9c114"
1857+
version "3.4.0"
1858+
resolved "https://registry.yarnpkg.com/superagent/-/superagent-3.4.0.tgz#cf8e40b303d5b2949c0fb036ddc30927e14958c7"
18521859
dependencies:
18531860
component-emitter "^1.2.0"
18541861
cookiejar "^2.0.6"

0 commit comments

Comments
 (0)