swipelime-client-node
Advanced tools
Comparing version 0.1.1 to 0.2.1
@@ -7,4 +7,15 @@ # Changelog | ||
## [1.0.1] - 2024-05-02 | ||
## [0.2.1] - 2024-05-12 | ||
### Added | ||
* Added new service handler method: addCustomOrderItem. | ||
### Fixed | ||
* Fixed various method type issues | ||
## [0.2.0] - 2024-05-11 | ||
### Added | ||
* Added new swipelime events: universal-menu-elements-added, universal-menu-elements-updated, universal-menu-elements-removed. | ||
* Added new service handler methods: getOrders, cancelOrderItems, getUniversalMenuElements, getUniversalMenuItems, getUniversalMenuCategories, getTables, getTable, deleteMenuElementsByIds, upsertUniversalMenuItems. | ||
## [0.1.1] - 2024-05-02 | ||
### Added | ||
* Added new swipelime events: customer-joined-table, order-items-added, order-items-confirmed, order-items-cancelled, payment-requested, payment-request-cancelled. | ||
@@ -15,4 +26,4 @@ * Added new service handler methods: markPaymentDone, markPaymentCancelled, finishTable. | ||
## [1.0.0] - 2024-04-25 | ||
## [0.1.0] - 2024-04-25 | ||
### Added | ||
* Initial version of the swipelime client. |
@@ -8,3 +8,3 @@ import Task from './Task'; | ||
constructor(doc: any, serviceHandler: ServiceHandler); | ||
refuse(): Promise<boolean>; | ||
refuse(): Promise<void>; | ||
} |
@@ -11,3 +11,3 @@ import Task from './Task'; | ||
*/ | ||
confirm(): Promise<boolean>; | ||
confirm(): Promise<void>; | ||
} |
@@ -7,3 +7,3 @@ /// <reference types="node" /> | ||
import TaskCommand from './models/TaskCommand'; | ||
import { ServiceHandlerEventTypes, IdOption } from './types'; | ||
import { ServiceHandlerEventTypes, DataIdType, OrderItemsData, UniversalMenuItem, UniversalMenuItemData, UniversalMenuCategory, NativeTable, CustomOrderItem } from './types'; | ||
export * from './types'; | ||
@@ -56,10 +56,16 @@ export declare class ServiceHandler { | ||
private checkOptionalIdValidity; | ||
confirmTaskEvents(tasks: (TaskEvent | string)[]): Promise<boolean>; | ||
confirmTaskEvent(task: TaskEvent | string): Promise<boolean>; | ||
confirmTestCommand(task: (TaskEvent | TaskCommand) | string): Promise<boolean>; | ||
confirmTaskEvents(tasks: (TaskEvent | string)[]): Promise<void>; | ||
confirmTaskEvent(task: TaskEvent | string): Promise<void>; | ||
/** | ||
* Confirms a test command. | ||
* The test command can be fired from the test suite in the integration settings in swipelime. When the test command received, this method has to be called to confirm it. It's for testing purposes only. | ||
* | ||
* @param task - The task event, task command, or task ID. | ||
*/ | ||
confirmTestCommand(task: (TaskEvent | TaskCommand) | string): Promise<void>; | ||
/** | ||
* Refusing multiple tasks. | ||
* @param tasks - The tasks to refuse but it can also be the IDs of the tasks. | ||
*/ | ||
refuseTaskCommands(tasks: (TaskCommand | string)[]): Promise<boolean>; | ||
refuseTaskCommands(tasks: (TaskCommand | string)[]): Promise<void>; | ||
/** | ||
@@ -69,5 +75,6 @@ * If you are not able to complete the command then you can refuse it. | ||
*/ | ||
refuseTaskCommand(task: TaskCommand | string): Promise<boolean>; | ||
refuseTaskCommand(task: TaskCommand | string): Promise<void>; | ||
/** | ||
* It marks the payment request as done for a specific table. | ||
* When the payment is done for a table this method has to be called so our system can reflect to that. | ||
* @param tableIdData - The ID of the table. | ||
@@ -77,5 +84,6 @@ * @returns A promise that resolves to true if it's successful. | ||
*/ | ||
markPaymentDone(tableIdData: IdOption): Promise<boolean>; | ||
markPaymentDone(tableIdData: DataIdType): Promise<void>; | ||
/** | ||
* It marks the payment request as cancelled for a specific table. | ||
* When the payment is cancelled for a table this method has to be called so our system can reflect to that. | ||
* @param tableIdData - The ID of the table. | ||
@@ -85,5 +93,6 @@ * @returns A promise that resolves to true if it's successful. | ||
*/ | ||
markPaymentCancelled(tableIdData: IdOption): Promise<boolean>; | ||
markPaymentCancelled(tableIdData: DataIdType): Promise<void>; | ||
/** | ||
* Finish all table sessions on the table. Users will not be able to order anymore. | ||
* When customers are leaving this method should be called to finish the table and lock their session so no more order can be made. | ||
* @param tableIdData - The ID of the table. | ||
@@ -93,3 +102,67 @@ * @returns A promise that resolves to true if it's successful. | ||
*/ | ||
finishTable(tableIdData: IdOption): Promise<boolean>; | ||
finishTable(tableIdData: DataIdType): Promise<void>; | ||
/** | ||
* Retrieves the orders for a specific table. | ||
* | ||
* @param tableIdData - The ID of the table. | ||
* @returns A promise that resolves to the order event data. | ||
*/ | ||
getOrders(tableIdData: DataIdType): Promise<OrderItemsData[]>; | ||
/** | ||
* Cancels the specified order items for a given table. | ||
* | ||
* @param tableIdData - The ID of the table. | ||
* @param orderItemIds - An array of order item IDs to be cancelled. | ||
* @returns A Promise that resolves to void. | ||
*/ | ||
cancelOrderItems(tableIdData: DataIdType, orderItemIds: string[]): Promise<void>; | ||
/** | ||
* Retrieves the universal menu elements from the server. | ||
* | ||
* @returns A promise that resolves to an array of UniversalMenuItem or UniversalMenuCategory objects. | ||
*/ | ||
getUniversalMenuElements(): Promise<(UniversalMenuItem | UniversalMenuCategory)[]>; | ||
/** | ||
* Retrieves the universal menu items. | ||
* @returns A promise that resolves to an array of UniversalMenuItem objects. | ||
*/ | ||
getUniversalMenuItems(): Promise<UniversalMenuItem[]>; | ||
/** | ||
* Retrieves the universal menu categories. | ||
* @returns A promise that resolves to an array of UniversalMenuCategory objects. | ||
*/ | ||
getUniversalMenuCategories(): Promise<UniversalMenuCategory[]>; | ||
/** | ||
* Retrieves all tables. | ||
* @returns A promise that resolves to an array of NativeTable objects. | ||
*/ | ||
getTables(): Promise<NativeTable[]>; | ||
/** | ||
* Retrieves a table based on the provided table ID. | ||
* @param tableIdData - The ID of the table. | ||
* @returns A promise that resolves to the retrieved NativeTable object. | ||
*/ | ||
getTable(tableIdData: DataIdType): Promise<NativeTable | undefined>; | ||
/** | ||
* Deletes menu elements (eg. items, categories) by their IDs. | ||
* @param ids - An array of IdOption objects representing the IDs of the menu elements to delete. | ||
* @returns A Promise that resolves to the number of menu elements deleted. | ||
*/ | ||
deleteMenuElements(ids: DataIdType[]): Promise<number>; | ||
/** | ||
* Upserts universal menu items. | ||
* | ||
* @param universalMenuItemsData - An array of partial UniversalMenuItemData objects. | ||
* @returns A promise that resolves to an object containing the number of items updated and the number of new items. | ||
*/ | ||
upsertUniversalMenuItems(universalMenuItemsData: Partial<UniversalMenuItemData>[]): Promise<{ | ||
updated: number; | ||
new: number; | ||
}>; | ||
/** | ||
* Adds a custom order item to the table. It only requires a label (which can be from any language) a quantity and a price. | ||
* @param tableIdData - The ID of the table where the custom order item will be added. | ||
* @param customOrderItem - The custom order item to be added. | ||
*/ | ||
addCustomOrderItem(tableIdData: DataIdType, customOrderItem: CustomOrderItem): Promise<void>; | ||
} |
@@ -149,10 +149,16 @@ "use strict"; | ||
} | ||
async confirmTaskEvents(tasks) { | ||
confirmTaskEvents(tasks) { | ||
const taskIds = tasks.map((task) => this.getTaskIdFromTask(task)); | ||
return this._ddpClient.call(`api/v${this._client.apiVersion}/markTasksAsProcessed`, this._tenantId, taskIds); | ||
} | ||
async confirmTaskEvent(task) { | ||
confirmTaskEvent(task) { | ||
return this.confirmTaskEvents([task]); | ||
} | ||
async confirmTestCommand(task) { | ||
/** | ||
* Confirms a test command. | ||
* The test command can be fired from the test suite in the integration settings in swipelime. When the test command received, this method has to be called to confirm it. It's for testing purposes only. | ||
* | ||
* @param task - The task event, task command, or task ID. | ||
*/ | ||
confirmTestCommand(task) { | ||
return this._ddpClient.call(`api/v${this._client.apiVersion}/confirmTestCommand`, this._tenantId, this.getTaskIdFromTask(task)); | ||
@@ -164,3 +170,3 @@ } | ||
*/ | ||
async refuseTaskCommands(tasks) { | ||
refuseTaskCommands(tasks) { | ||
const taskIds = tasks.map((task) => this.getTaskIdFromTask(task)); | ||
@@ -173,3 +179,3 @@ return this._ddpClient.call(`api/v${this._client.apiVersion}/refuseTaskCommand`, this._tenantId, taskIds); | ||
*/ | ||
async refuseTaskCommand(task) { | ||
refuseTaskCommand(task) { | ||
return this.refuseTaskCommands([task]); | ||
@@ -179,2 +185,3 @@ } | ||
* It marks the payment request as done for a specific table. | ||
* When the payment is done for a table this method has to be called so our system can reflect to that. | ||
* @param tableIdData - The ID of the table. | ||
@@ -184,3 +191,3 @@ * @returns A promise that resolves to true if it's successful. | ||
*/ | ||
async markPaymentDone(tableIdData) { | ||
markPaymentDone(tableIdData) { | ||
this.checkOptionalIdValidity(tableIdData); | ||
@@ -191,2 +198,3 @@ return this._ddpClient.call(`api/v${this._client.apiVersion}/markPaymentChanged`, this._tenantId, tableIdData, true); | ||
* It marks the payment request as cancelled for a specific table. | ||
* When the payment is cancelled for a table this method has to be called so our system can reflect to that. | ||
* @param tableIdData - The ID of the table. | ||
@@ -196,3 +204,3 @@ * @returns A promise that resolves to true if it's successful. | ||
*/ | ||
async markPaymentCancelled(tableIdData) { | ||
markPaymentCancelled(tableIdData) { | ||
this.checkOptionalIdValidity(tableIdData); | ||
@@ -203,2 +211,3 @@ return this._ddpClient.call(`api/v${this._client.apiVersion}/markPaymentChanged`, this._tenantId, tableIdData, false); | ||
* Finish all table sessions on the table. Users will not be able to order anymore. | ||
* When customers are leaving this method should be called to finish the table and lock their session so no more order can be made. | ||
* @param tableIdData - The ID of the table. | ||
@@ -208,7 +217,98 @@ * @returns A promise that resolves to true if it's successful. | ||
*/ | ||
async finishTable(tableIdData) { | ||
finishTable(tableIdData) { | ||
this.checkOptionalIdValidity(tableIdData); | ||
return this._ddpClient.call(`api/v${this._client.apiVersion}/finishTable`, this._tenantId, tableIdData); | ||
} | ||
/** | ||
* Retrieves the orders for a specific table. | ||
* | ||
* @param tableIdData - The ID of the table. | ||
* @returns A promise that resolves to the order event data. | ||
*/ | ||
getOrders(tableIdData) { | ||
this.checkOptionalIdValidity(tableIdData); | ||
return this._ddpClient.call(`api/v${this._client.apiVersion}/getOrders`, this._tenantId, tableIdData); | ||
} | ||
/** | ||
* Cancels the specified order items for a given table. | ||
* | ||
* @param tableIdData - The ID of the table. | ||
* @param orderItemIds - An array of order item IDs to be cancelled. | ||
* @returns A Promise that resolves to void. | ||
*/ | ||
cancelOrderItems(tableIdData, orderItemIds) { | ||
this.checkOptionalIdValidity(tableIdData); | ||
if (!orderItemIds?.length) | ||
throw (0, utils_1.swipelimeError)('cancelOrderItems method need valid orderItemIds'); | ||
return this._ddpClient.call(`api/v${this._client.apiVersion}/cancelOrderItems`, this._tenantId, orderItemIds); | ||
} | ||
/** | ||
* Retrieves the universal menu elements from the server. | ||
* | ||
* @returns A promise that resolves to an array of UniversalMenuItem or UniversalMenuCategory objects. | ||
*/ | ||
getUniversalMenuElements() { | ||
return this._ddpClient.call(`api/v${this._client.apiVersion}/getUniversalMenuElements`, this._tenantId); | ||
} | ||
/** | ||
* Retrieves the universal menu items. | ||
* @returns A promise that resolves to an array of UniversalMenuItem objects. | ||
*/ | ||
getUniversalMenuItems() { | ||
return this._ddpClient.call(`api/v${this._client.apiVersion}/getUniversalMenuElements`, this._tenantId); | ||
} | ||
/** | ||
* Retrieves the universal menu categories. | ||
* @returns A promise that resolves to an array of UniversalMenuCategory objects. | ||
*/ | ||
getUniversalMenuCategories() { | ||
return this._ddpClient.call(`api/v${this._client.apiVersion}/getUniversalMenuElements`, this._tenantId); | ||
} | ||
/** | ||
* Retrieves all tables. | ||
* @returns A promise that resolves to an array of NativeTable objects. | ||
*/ | ||
getTables() { | ||
return this._ddpClient.call(`api/v${this._client.apiVersion}/getTables`, this._tenantId); | ||
} | ||
/** | ||
* Retrieves a table based on the provided table ID. | ||
* @param tableIdData - The ID of the table. | ||
* @returns A promise that resolves to the retrieved NativeTable object. | ||
*/ | ||
async getTable(tableIdData) { | ||
this.checkOptionalIdValidity(tableIdData); | ||
return (await this._ddpClient.call(`api/v${this._client.apiVersion}/getTables`, this._tenantId, [tableIdData]))[0]; | ||
} | ||
/** | ||
* Deletes menu elements (eg. items, categories) by their IDs. | ||
* @param ids - An array of IdOption objects representing the IDs of the menu elements to delete. | ||
* @returns A Promise that resolves to the number of menu elements deleted. | ||
*/ | ||
deleteMenuElements(ids) { | ||
if (!ids?.length) | ||
throw (0, utils_1.swipelimeError)('deleteMenuElementsByIds method need valid ids'); | ||
return this._ddpClient.call(`api/v${this._client.apiVersion}/deleteMenuElementsByIds`, this._tenantId, ids); | ||
} | ||
/** | ||
* Upserts universal menu items. | ||
* | ||
* @param universalMenuItemsData - An array of partial UniversalMenuItemData objects. | ||
* @returns A promise that resolves to an object containing the number of items updated and the number of new items. | ||
*/ | ||
upsertUniversalMenuItems(universalMenuItemsData) { | ||
if (!universalMenuItemsData?.length) | ||
throw (0, utils_1.swipelimeError)('upsertUniversalMenuItems method need valid universalMenuItems'); | ||
return this._ddpClient.call(`api/v${this._client.apiVersion}/upsertUniversalMenuItems`, this._tenantId, universalMenuItemsData); | ||
} | ||
/** | ||
* Adds a custom order item to the table. It only requires a label (which can be from any language) a quantity and a price. | ||
* @param tableIdData - The ID of the table where the custom order item will be added. | ||
* @param customOrderItem - The custom order item to be added. | ||
*/ | ||
addCustomOrderItem(tableIdData, customOrderItem) { | ||
this.checkOptionalIdValidity(tableIdData); | ||
return this._ddpClient.call(`api/v${this._client.apiVersion}/addCustomOrderItem`, this._tenantId, tableIdData, customOrderItem); | ||
} | ||
} | ||
exports.ServiceHandler = ServiceHandler; |
@@ -19,2 +19,5 @@ import TaskEvent from './models/TaskEvent'; | ||
export type AllLanguage = typeof allLanguages[number]; | ||
export type LangType = { | ||
[key in AllLanguage]?: string; | ||
}; | ||
/** | ||
@@ -111,5 +114,5 @@ * The authentication parameters. | ||
*/ | ||
export type IdData = { | ||
export type ElementIdData = { | ||
id: string; | ||
externalIds: Record<string, string>; | ||
externalId?: string; | ||
}; | ||
@@ -120,3 +123,3 @@ /** | ||
*/ | ||
export type IdOption = { | ||
export type DataIdType = { | ||
id?: string; | ||
@@ -171,9 +174,9 @@ externalId?: string; | ||
*/ | ||
export type OrderItemsEventData = { | ||
export type OrderItemsData = { | ||
orderItemId: string; | ||
customerId: string; | ||
menuItemData: IdData; | ||
menuData?: IdData; | ||
variantData?: IdData; | ||
selectablesData?: IdData[]; | ||
menuItemData: ElementIdData; | ||
menuData?: ElementIdData; | ||
variantData?: ElementIdData; | ||
selectablesData?: ElementIdData[]; | ||
quantity: number; | ||
@@ -186,4 +189,4 @@ additionalRequests?: string; | ||
export type OrderEventData = { | ||
tableData: IdData; | ||
orderItems: OrderItemsEventData[]; | ||
tableData: ElementIdData; | ||
orderItems: OrderItemsData[]; | ||
}; | ||
@@ -193,3 +196,3 @@ /** | ||
*/ | ||
export declare const eventTypes: readonly ["test", "customer-joined-table", "order-items-added", "order-items-confirmed", "order-items-cancelled", "payment-requested", "payment-request-cancelled"]; | ||
export declare const eventTypes: readonly ["test", "customer-joined-table", "order-items-added", "order-items-confirmed", "order-items-cancelled", "payment-requested", "payment-request-cancelled", "universal-menu-elements-added", "universal-menu-elements-updated", "universal-menu-elements-removed"]; | ||
/** | ||
@@ -229,3 +232,3 @@ * The types of events. | ||
*/ | ||
export interface OrderItemsAddedEventData extends TaskEventDataBase { | ||
export interface OrderItemsChangedEventData extends TaskEventDataBase { | ||
eventType: 'order-items-added' | 'order-items-confirmed' | 'order-items-cancelled'; | ||
@@ -240,9 +243,60 @@ eventData: OrderEventData; | ||
eventData: { | ||
tableData: IdData; | ||
tableData: ElementIdData; | ||
paymentType: typeof PaymentTypes; | ||
}; | ||
} | ||
export interface UniversalMenuElementsEventData extends TaskEventDataBase { | ||
eventType: 'universal-menu-elements-added' | 'universal-menu-elements-updated' | 'universal-menu-elements-removed'; | ||
eventData: (UniversalMenuItem | UniversalMenuCategory)[]; | ||
} | ||
/** | ||
* The list of task event data. | ||
*/ | ||
export type TaskEventDataList = TestEventData | CustomerJoinedTableEventData | OrderItemsAddedEventData | PaymentRequestedEventData; | ||
export type TaskEventDataList = TestEventData | CustomerJoinedTableEventData | OrderItemsChangedEventData | PaymentRequestedEventData | UniversalMenuElementsEventData; | ||
export type UniversalMenuItemData = { | ||
id: string; | ||
externalId?: string; | ||
enabled: boolean; | ||
label: LangType; | ||
price: number; | ||
description?: LangType; | ||
longDescription?: LangType; | ||
created: string; | ||
updated: string; | ||
}; | ||
export type UniversalMenuItem = { | ||
type: 'item'; | ||
data: UniversalMenuItemData; | ||
}; | ||
export type UniversalMenuCategoryData = { | ||
id: string; | ||
externalId?: string; | ||
enabled: boolean; | ||
label: LangType; | ||
created?: string; | ||
updated?: string; | ||
}; | ||
/** | ||
* Represents a universal menu category. | ||
*/ | ||
export type UniversalMenuCategory = { | ||
type: 'category'; | ||
data: UniversalMenuCategoryData; | ||
}; | ||
/** | ||
* Represents a native table. | ||
*/ | ||
export type NativeTable = { | ||
id: string; | ||
externalId?: string; | ||
accessCode: string; | ||
label: LangType; | ||
children: string[]; | ||
created: string; | ||
updated: string; | ||
}; | ||
export type CustomOrderItem = { | ||
label: LangType; | ||
price: number; | ||
quantity: number; | ||
}; |
@@ -84,3 +84,6 @@ "use strict"; | ||
'payment-requested', | ||
'payment-request-cancelled' | ||
'payment-request-cancelled', | ||
'universal-menu-elements-added', | ||
'universal-menu-elements-updated', | ||
'universal-menu-elements-removed' | ||
]; | ||
@@ -91,1 +94,2 @@ ; | ||
; | ||
; |
{ | ||
"name": "swipelime-client-node", | ||
"description": "swipelime-client-node is the official swipelime Node.js client library", | ||
"version": "0.1.1", | ||
"version": "0.2.1", | ||
"author": "swipelime (https://swipelime.com)", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
51330
1182