Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added basic auth support and moved the code base to typescript #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
/yarn.lock
/node_modules/

/test/config.json
/test/config.json

*.js
*.d.ts
42 changes: 0 additions & 42 deletions index.js

This file was deleted.

50 changes: 50 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { RestClient, RestClientInstance, RestClientOptions } from "./lib/rest_client";
import cart, { CartModule } from "./lib/cart";
import address, { AddressModule } from "./lib/address";
import order, { OrderModule } from "./lib/order";
import newsletter, { NewsletterModule } from "./lib/newsletter";
import user, { UserModule } from "./lib/user";
import stock, { StockModule } from "./lib/stock";
import contact, { ContactModule } from "./lib/contact";
import wishlist, { WishlistModule } from "./lib/wishlist";
import stockAlert, { StockAlertModule } from "./lib/stock_alert";

const MAGENTO_API_VERSION = 'V1';

interface Magento1ClientInstance {
user: UserModule
cart: CartModule
order: OrderModule
stock: StockModule
contact: ContactModule
wishlist: WishlistModule
stockAlert: StockAlertModule
newsletter: NewsletterModule
address: AddressModule
addMethods: (key: string, module: (restClient: RestClientInstance) => Record<string, (...params: any[]) => any>) => void
}

export function Magento1Client(options: RestClientOptions): Magento1ClientInstance {
options.version = MAGENTO_API_VERSION;
let client = RestClient(options);

return {
addMethods (key, module) {
if (module) {
if (this[key])
this[key] = Object.assign(this[key], module(client));
else
this[key] = module(client);
}
},
user: user(client),
cart: cart(client),
order: order(client),
stock: stock(client),
contact: contact(client),
wishlist: wishlist(client),
stockAlert: stockAlert(client),
newsletter: newsletter(client),
address: address(client)
};
};
36 changes: 0 additions & 36 deletions lib/address.js

This file was deleted.

57 changes: 57 additions & 0 deletions lib/address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { getResponse, RequestResponse, CustomerToken } from "./helper";
import { RestClientInstance } from "./rest_client";

interface ListCall {
(customerToken: CustomerToken): Promise<RequestResponse>
}
interface UpdateCall {
(customerToken: CustomerToken, addressData: any): Promise<RequestResponse>
}
interface GetCall {
(customerToken: CustomerToken, addressId: string|number): Promise<RequestResponse>
}
interface DeleteCall {
(customerToken: CustomerToken, addressData: any): Promise<RequestResponse>
}

export interface AddressModule {
list: ListCall
update: UpdateCall
get: GetCall
delete: DeleteCall
}

export default function (restClient: RestClientInstance): AddressModule {
let url = 'address/';

const listCall: ListCall = function (customerToken) {
url += `list?token=${customerToken}`
return restClient.get(url).then((data)=> {
return getResponse(data);
});
}
const updateCall: UpdateCall = function (customerToken, addressData) {
url += `update?token=${customerToken}`
return restClient.post(url, {address: addressData}).then((data)=> {
return getResponse(data);
});
}
const getCall: GetCall = function (customerToken, addressId) {
url += `get?token=${customerToken}&addressId=${addressId}`
return restClient.get(url).then((data)=> {
return getResponse(data);
});
}
const deleteCall: DeleteCall = function (customerToken, addressData) {
url += `delete?token=${customerToken}`
return restClient.post(url, {address: addressData}).then((data)=> {
return getResponse(data);
});
}
return {
list: listCall,
update: updateCall,
get: getCall,
delete: deleteCall
};
}
82 changes: 0 additions & 82 deletions lib/cart.js

This file was deleted.

Loading