@simpleapps-com/augur-api
Version:
TypeScript client library for Augur microservices API endpoints
312 lines • 14 kB
JavaScript
import { CustomerCustomerIdResponseSchema, CustomerCustomerIdDocResponseSchema, CustomerCustomerIdAddressParamsSchema, CustomerCustomerIdAddressResponseSchema, CustomerCustomerIdContactsListParamsSchema, CustomerCustomerIdContactsListResponseSchema, CustomerCustomerIdContactsCreateParamsSchema, CustomerCustomerIdContactsCreateResponseSchema, CustomerCustomerIdShipToListParamsSchema, CustomerCustomerIdShipToListResponseSchema, CustomerCustomerIdShipToCreateParamsSchema, CustomerCustomerIdShipToCreateResponseSchema, CustomerCustomerIdOrdersParamsSchema, CustomerCustomerIdOrdersHeaderResponseSchema, CustomerCustomerIdOrdersDocumentResponseSchema, CustomerCustomerIdOrdersOrderNoResponseSchema, CustomerCustomerIdInvoicesParamsSchema, CustomerCustomerIdInvoicesResponseSchema, CustomerCustomerIdInvoicesInvoiceNoResponseSchema, CustomerCustomerIdQuotesParamsSchema, CustomerCustomerIdQuotesResponseSchema, CustomerCustomerIdQuotesQuoteNoResponseSchema, CustomerCustomerIdPurchasedItemsParamsSchema, CustomerCustomerIdPurchasedItemsResponseSchema, } from '../schemas';
/**
* Creates the customer resource methods
* OpenAPI Path: /customer/{customerId} → customer(customerId).*
* @description Customer-specific operations and nested resources
*/
export function createCustomerResource(executeRequest) {
return (customerId) => ({
/**
* Direct customer endpoint - OpenAPI Path: /customer/{customerId} (GET)
* @fullPath api.customers.customer.get
* @description Returns the customer by ID
* @service customers
* @domain customer-management
* @dataMethod customerData.get
* @discoverable true
*/
get: async () => {
return executeRequest({
method: 'GET',
path: '/customer/{customerId}',
responseSchema: CustomerCustomerIdResponseSchema,
}, undefined, { customerId: String(customerId) });
},
/**
* Customer document endpoint - OpenAPI Path: /customer/{customerId}/doc (GET)
* @fullPath api.customers.customer.doc
* @description Returns full customer document including addresses, contacts, and ship-to addresses
* @service customers
* @domain customer-management
* @dataMethod customerData.doc.get
* @discoverable true
*/
doc: {
get: async () => {
return executeRequest({
method: 'GET',
path: '/customer/{customerId}/doc',
responseSchema: CustomerCustomerIdDocResponseSchema,
}, undefined, { customerId: String(customerId) });
},
},
/**
* Customer address endpoint - OpenAPI Path: /customer/{customerId}/address (GET)
* @fullPath api.customers.customer.address
* @service customers
* @domain customer-management
* @dataMethod customerData.address.get
* @discoverable true
*/
address: {
get: async (params) => {
return executeRequest({
method: 'GET',
path: '/customer/{customerId}/address',
paramsSchema: CustomerCustomerIdAddressParamsSchema,
responseSchema: CustomerCustomerIdAddressResponseSchema,
}, params, { customerId: String(customerId) });
},
},
/**
* Customer contacts endpoint - OpenAPI Path: /customer/{customerId}/contacts
* @fullPath api.customers.customer.contacts
* @service customers
* @domain contact-management
* @dataMethod customerData.contacts.list, customerData.contacts.create
* @discoverable true
*/
contacts: {
list: async (params) => {
return executeRequest({
method: 'GET',
path: '/customer/{customerId}/contacts',
paramsSchema: CustomerCustomerIdContactsListParamsSchema,
responseSchema: CustomerCustomerIdContactsListResponseSchema,
}, params, { customerId: String(customerId) });
},
create: async (data) => {
return executeRequest({
method: 'POST',
path: '/customer/{customerId}/contacts',
paramsSchema: CustomerCustomerIdContactsCreateParamsSchema,
responseSchema: CustomerCustomerIdContactsCreateResponseSchema,
}, data, { customerId: String(customerId) });
},
},
/**
* Customer ship-to endpoint - OpenAPI Path: /customer/{customerId}/ship-to
* @fullPath api.customers.customer.shipTo
* @service customers
* @domain customer-management
* @dataMethod customerData.shipTo.list, customerData.shipTo.create
* @discoverable true
*/
shipTo: {
list: async (params) => {
return executeRequest({
method: 'GET',
path: '/customer/{customerId}/ship-to',
paramsSchema: CustomerCustomerIdShipToListParamsSchema,
responseSchema: CustomerCustomerIdShipToListResponseSchema,
}, params, { customerId: String(customerId) });
},
create: async (data) => {
return executeRequest({
method: 'POST',
path: '/customer/{customerId}/ship-to',
paramsSchema: CustomerCustomerIdShipToCreateParamsSchema,
responseSchema: CustomerCustomerIdShipToCreateResponseSchema,
}, data, { customerId: String(customerId) });
},
},
/**
* Customer orders endpoint - OpenAPI Path: /customer/{customerId}/orders
* @fullPath api.customers.customer.orders
* @service customers
* @domain order-management
* @dataMethod customerData.orders.get (factory), customerData.orders.list
* @discoverable true
*/
orders: Object.assign(
// Factory function for specific orders
(orderNo) => ({
get: async () => {
return executeRequest({
method: 'GET',
path: '/customer/{customerId}/orders/{orderNo}',
responseSchema: CustomerCustomerIdOrdersOrderNoResponseSchema,
}, undefined, { customerId: String(customerId), orderNo: String(orderNo) });
},
}),
// Static list method
{
list: async (params) => {
const isFullDocument = params?.fullDocument === 'Y';
const responseSchema = isFullDocument
? CustomerCustomerIdOrdersDocumentResponseSchema
: CustomerCustomerIdOrdersHeaderResponseSchema;
return executeRequest({
method: 'GET',
path: '/customer/{customerId}/orders',
paramsSchema: CustomerCustomerIdOrdersParamsSchema,
responseSchema: responseSchema,
}, params, { customerId: String(customerId) });
},
}),
/**
* Customer invoices endpoint - OpenAPI Path: /customer/{customerId}/invoices
* @fullPath api.customers.customer.invoices
* @service customers
* @domain invoice-management
* @dataMethod customerData.invoices.get (factory), customerData.invoices.list
* @discoverable true
*/
invoices: Object.assign(
// Factory function for specific invoices
(invoiceNo) => ({
get: async () => {
return executeRequest({
method: 'GET',
path: '/customer/{customerId}/invoices/{invoiceNo}',
responseSchema: CustomerCustomerIdInvoicesInvoiceNoResponseSchema,
}, undefined, { customerId: String(customerId), invoiceNo: String(invoiceNo) });
},
}),
// Static list method
{
list: async (params) => {
return executeRequest({
method: 'GET',
path: '/customer/{customerId}/invoices',
paramsSchema: CustomerCustomerIdInvoicesParamsSchema,
responseSchema: CustomerCustomerIdInvoicesResponseSchema,
}, params, { customerId: String(customerId) });
},
}),
/**
* Customer quotes endpoint - OpenAPI Path: /customer/{customerId}/quotes
* @fullPath api.customers.customer.quotes
* @service customers
* @domain quote-management
* @dataMethod customerData.quotes.get (factory), customerData.quotes.list
* @discoverable true
*/
quotes: Object.assign(
// Factory function for specific quotes
(quoteNo) => ({
get: async () => {
return executeRequest({
method: 'GET',
path: '/customer/{customerId}/quotes/{quoteNo}',
responseSchema: CustomerCustomerIdQuotesQuoteNoResponseSchema,
}, undefined, { customerId: String(customerId), quoteNo: String(quoteNo) });
},
}),
// Static list method
{
list: async (params) => {
return executeRequest({
method: 'GET',
path: '/customer/{customerId}/quotes',
paramsSchema: CustomerCustomerIdQuotesParamsSchema,
responseSchema: CustomerCustomerIdQuotesResponseSchema,
}, params, { customerId: String(customerId) });
},
}),
/**
* Customer purchased items endpoint - OpenAPI Path: /customer/{customerId}/purchased-items
* @fullPath api.customers.customer.purchasedItems
* @service customers
* @domain purchase-history
* @dataMethod customerData.purchasedItems.list
* @discoverable true
*/
purchasedItems: {
list: async (params) => {
return executeRequest({
method: 'GET',
path: '/customer/{customerId}/purchased-items',
paramsSchema: CustomerCustomerIdPurchasedItemsParamsSchema,
responseSchema: CustomerCustomerIdPurchasedItemsResponseSchema,
}, params, { customerId: String(customerId) });
},
},
});
}
/**
* Creates the customerData resource methods (data-only versions)
*/
export function createCustomerDataResource(customer) {
return (customerId) => {
const customerInstance = customer(customerId);
return {
get: async () => {
const response = await customerInstance.get();
return response.data;
},
doc: {
get: async () => {
const response = await customerInstance.doc.get();
return response.data;
},
},
address: {
get: async (params) => {
const response = await customerInstance.address.get(params);
return response.data;
},
},
contacts: {
list: async (params) => {
const response = await customerInstance.contacts.list(params);
return response.data;
},
create: async (data) => {
const response = await customerInstance.contacts.create(data);
return response.data;
},
},
shipTo: {
list: async (params) => {
const response = await customerInstance.shipTo.list(params);
return response.data;
},
create: async (data) => {
const response = await customerInstance.shipTo.create(data);
return response.data;
},
},
orders: Object.assign((orderNo) => ({
get: async () => {
const response = await customerInstance.orders(orderNo).get();
return response.data;
},
}), {
list: async (params) => {
const response = await customerInstance.orders.list(params);
return response.data;
},
}),
invoices: Object.assign((invoiceNo) => ({
get: async () => {
const response = await customerInstance.invoices(invoiceNo).get();
return response.data;
},
}), {
list: async (params) => {
const response = await customerInstance.invoices.list(params);
return response.data;
},
}),
quotes: Object.assign((quoteNo) => ({
get: async () => {
const response = await customerInstance.quotes(quoteNo).get();
return response.data;
},
}), {
list: async (params) => {
const response = await customerInstance.quotes.list(params);
return response.data;
},
}),
purchasedItems: {
list: async (params) => {
const response = await customerInstance.purchasedItems.list(params);
return response.data;
},
},
};
};
}
//# sourceMappingURL=customer.js.map