Skip to content

Commit

Permalink
feat: customer app endpoints, types and errors (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
algoflows authored Apr 21, 2022
1 parent 28764fb commit 96d1212
Show file tree
Hide file tree
Showing 27 changed files with 1,031 additions and 38 deletions.
11 changes: 11 additions & 0 deletions lib/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ module.exports = {
Tasks: require('./resources/Admin/Tasks'),
}),

Customer: resourceNamespace('customer', {
Contests: require('./resources/Customer/Contests'),
Customers: require('./resources/Customer/Customers'),
EntryCodes: require('./resources/Customer/EntryCodes'),
Orders: require('./resources/Customer/Orders'),
PasswordReset: require('./resources/Customer/PasswordReset'),
Payments: require('./resources/Customer/Payments'),
Products: require('./resources/Customer/Products'),
Sessions: require('./resources/Customer/Sessions'),
}),

Store: resourceNamespace('store', {
Checkouts: require('./resources/Store/Checkouts'),
CheckoutZone: require('./resources/Store/CheckoutZone'),
Expand Down
13 changes: 13 additions & 0 deletions lib/resources/Customer/Contests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const AifiResource = require('../../AifiResource');
const aifiMethod = AifiResource.method;

module.exports = AifiResource.extend({
path: 'customer/v2/contests',

create: aifiMethod({
method: 'POST',
path: '',
}),
});
23 changes: 23 additions & 0 deletions lib/resources/Customer/Customers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const AifiResource = require('../../AifiResource');
const aifiMethod = AifiResource.method;

module.exports = AifiResource.extend({
path: 'customer/v2/customers',

create: aifiMethod({
method: 'POST',
path: '',
}),

retrieve: aifiMethod({
method: 'GET',
path: '/me',
}),

update: aifiMethod({
method: 'PATCH',
path: '/me',
}),
});
13 changes: 13 additions & 0 deletions lib/resources/Customer/EntryCodes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const AifiResource = require('../../AifiResource');
const aifiMethod = AifiResource.method;

module.exports = AifiResource.extend({
path: 'customer/v2/entry-codes',

create: aifiMethod({
method: 'POST',
path: '',
}),
});
33 changes: 33 additions & 0 deletions lib/resources/Customer/Orders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

const AifiResource = require('../../AifiResource');
const aifiMethod = AifiResource.method;

module.exports = AifiResource.extend({
path: 'customer/v2/orders',

list: aifiMethod({
method: 'GET',
path: '',
}),

retrieve: aifiMethod({
method: 'GET',
path: '/{orderId}',
}),

payment: aifiMethod({
method: 'POST',
path: '/{orderId}/payment',
}),

listDrafts: aifiMethod({
method: 'GET',
path: 'draft',
}),

retreiveDraft: aifiMethod({
method: 'POST',
path: '/draft/{draftOrderID}',
}),
});
23 changes: 23 additions & 0 deletions lib/resources/Customer/PasswordReset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const AifiResource = require('../../AifiResource');
const aifiMethod = AifiResource.method;

module.exports = AifiResource.extend({
path: 'customer/v2/password-reset',

reset: aifiMethod({
method: 'POST',
path: '',
}),

set: aifiMethod({
method: 'PATCH',
path: '',
}),

verify: aifiMethod({
method: 'POST',
path: '/verify',
}),
});
13 changes: 13 additions & 0 deletions lib/resources/Customer/Payments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const AifiResource = require('../../AifiResource');
const aifiMethod = AifiResource.method;

module.exports = AifiResource.extend({
path: 'customer/v2/payments',

create: aifiMethod({
method: 'GET',
path: '/methods/initialize',
}),
});
13 changes: 13 additions & 0 deletions lib/resources/Customer/Products.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const AifiResource = require('../../AifiResource');
const aifiMethod = AifiResource.method;

module.exports = AifiResource.extend({
path: 'customer/v2/products',

search: aifiMethod({
method: 'GET',
path: '',
}),
});
23 changes: 23 additions & 0 deletions lib/resources/Customer/Sessions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const AifiResource = require('../../AifiResource');
const aifiMethod = AifiResource.method;

module.exports = AifiResource.extend({
path: 'customer/v2/sessions',

login: aifiMethod({
method: 'POST',
path: '',
}),

logout: aifiMethod({
method: 'DELETE',
path: '/{customerId}',
}),

refresh: aifiMethod({
method: 'POST',
path: '/refresh',
}),
});
30 changes: 30 additions & 0 deletions test/resources/Customer/Customers.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

const aifi = require('../../../testUtils').getSpyableAifi();

const expect = require('chai').expect;

describe('Customer', () => {
describe('Contests Resource', () => {
describe('create', () => {
it('Sends the correct request', () => {
aifi.customer.contests.create({
productId: '1',
quantity: 1,
items: [],
});
expect(aifi.LAST_REQUEST).to.deep.equal({
method: 'POST',
url: '/api/customer/v2/contests',
headers: {},
data: {
productId: '1',
quantity: 1,
items: [],
},
settings: {},
});
});
});
});
});
43 changes: 5 additions & 38 deletions types/Admin/Customers.d.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,7 @@
declare module 'aifi' {
namespace Aifi {
namespace Admin {
/**
* The Customer object.
*/
interface Customer {
/**
* Unique identifier for the object.
*/
id: string;

/**
* The customer's email address.
*/
email: string;

/**
* The customer's first name.
*/
firstName?: string;

/**
* The customer's last name.
*/
lastName?: string;

/**
* The customer's phone number.
*/
phone?: string;

/**
* A reference to a unique external identified for the customer.
*/
externalId?: string;
}
interface Customer extends Aifi.Models.Customer {}

interface CustomerEntryCode {
code: string;
Expand Down Expand Up @@ -175,15 +142,15 @@ declare module 'aifi' {
create(
params: CustomerCreateParams,
options?: RequestOptions
): Promise<Aifi.Response<Aifi.Admin.Customer>>;
): Promise<Aifi.Response<Aifi.Models.Customer>>;

/**
* Retrieves a Customer object.
*/
retrieve(
customerId: string,
options?: RequestOptions
): Promise<Aifi.Response<Aifi.Admin.Customer>>;
): Promise<Aifi.Response<Aifi.Models.Customer>>;

/**
* Updates the specified customer by setting the values of the parameters passed.
Expand All @@ -192,7 +159,7 @@ declare module 'aifi' {
customerId: string,
params?: CustomerUpdateParams,
options?: RequestOptions
): Promise<Aifi.Response<Aifi.Admin.Customer>>;
): Promise<Aifi.Response<Aifi.Models.Customer>>;

/**
* Creates a store entry code for that customer
Expand All @@ -201,7 +168,7 @@ declare module 'aifi' {
customerId: string,
params?: CustomerCreateEntryCodeParams,
options?: RequestOptions
): Promise<Aifi.Response<Aifi.Admin.CustomerEntryCode>>;
): Promise<Aifi.Response<Aifi.Models.Customer>>;
}
}
}
Expand Down
34 changes: 34 additions & 0 deletions types/Customer/Contests.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
declare module 'aifi' {
namespace Aifi {
namespace Customer {
interface ContestCreateParams {
/**
* The order id to be contested
*/
orderId: string;

/**
* The customer's email address.
*/
message: string;

/**
* Items array
*/
items: Aifi.Models.ContestItem[];
}

class ContestsResource {
/**
* Retrieves an auth token.
*/
create(
params: ContestCreateParams,
options?: RequestOptions
): Promise<
Aifi.Response<Aifi.Models.ContestItem[] | Aifi.Models.Error>
>;
}
}
}
}
Loading

0 comments on commit 96d1212

Please sign in to comment.