Skip to content
Merged
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
58 changes: 57 additions & 1 deletion dist/shipthisapi-js/collections/generic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,44 @@ declare const updateGenericCollectionItem: (obj: {
requestData: any;
}) => any;
} | ShipthisAPI, collectionName: string, objectId: string, updatedData: any) => Promise<any>;
/**
* Patch specific fields of an item (partial update)
* @param obj - ShipthisAPI instance
* @param collectionName - Name of the collection
* @param objectId - Document ID
* @param updateFields - Fields to update
*/
declare const patchGenericCollectionItem: (obj: ShipthisAPI, collectionName: string, objectId: string, updateFields: any) => Promise<any>;
/**
* Bulk edit multiple items in a collection
* @param obj - ShipthisAPI instance
* @param collectionName - Name of the collection
* @param ids - List of document IDs to update
* @param updateData - Key-value pairs of fields to update
* @param externalUpdateData - Extra data for external updates (optional)
*/
declare const bulkEdit: (obj: ShipthisAPI, collectionName: string, ids: string[], updateData: Record<string, any>, externalUpdateData?: Record<string, any>) => Promise<any>;
/**
* Trigger a primary workflow transition (status change on a record)
* @param obj - ShipthisAPI instance
* @param collection - Target collection (e.g., "pickup_delivery")
* @param workflowId - Workflow status key (e.g., "job_status")
* @param objectId - Document ID
* @param actionIndex - Index of action within the status
* @param intendedStateId - Intended resulting state ID
* @param startStateId - Current/starting state ID (optional)
*/
declare const primaryWorkflowAction: (obj: ShipthisAPI, collection: string, workflowId: string, objectId: string, actionIndex: number, intendedStateId: string, startStateId?: string) => Promise<any>;
/**
* Trigger a secondary workflow transition (sub-status change)
* @param obj - ShipthisAPI instance
* @param collection - Target collection (e.g., "pickup_delivery")
* @param workflowId - Secondary status key (e.g., "driver_status")
* @param objectId - Document ID
* @param targetState - Resulting sub-state (e.g., "to_pick_up")
* @param additionalData - Optional additional data to send
*/
declare const secondaryWorkflowAction: (obj: ShipthisAPI, collection: string, workflowId: string, objectId: string, targetState: string, additionalData?: Record<string, any>) => Promise<any>;
declare const setJobStatus: (obj: {
internalRequest: (arg0: any, arg1: string, arg2: string, arg3: {
action_index: any;
Expand All @@ -45,6 +83,24 @@ declare const getGenericAutoComplete: (obj: ShipthisAPI, referenceName: string,
declare const getLocation: (obj: ShipthisAPI, collectionName: string, params?: CollectionParams) => Promise<any>;
declare const selectGoogleLocation: (obj: ShipthisAPI, collectionName: string, params: SelectGoogleLocationParams) => Promise<any>;
declare const conversation: (obj: ShipthisAPI, collectionName: string, data: any, params?: CollectionParams) => Promise<any>;
/**
* Create a conversation/message on a document
* @param obj - ShipthisAPI instance
* @param viewName - Collection/view name
* @param documentId - Document ID
* @param conversationData - Conversation data (message, type, etc.)
*/
declare const createConversation: (obj: ShipthisAPI, viewName: string, documentId: string, conversationData: any) => Promise<any>;
/**
* Get conversations for a document
* @param obj - ShipthisAPI instance
* @param viewName - Collection/view name
* @param documentId - Document ID
* @param messageType - Filter by message type (default: "all")
* @param page - Page number (default: 1)
* @param count - Items per page (default: 100)
*/
declare const getConversations: (obj: ShipthisAPI, viewName: string, documentId: string, messageType?: string, page?: number, count?: number) => Promise<any>;
declare const deleteGenericCollectionItem: (obj: {
internalRequest: (arg0: any, arg1: string, arg2: string) => any;
}, collectionName: string, objectId: string) => Promise<any>;
Expand All @@ -60,4 +116,4 @@ declare const getReportView: (obj: {
requestData: any;
}) => any;
}, report_name: string, start_date: string, end_date: string, location: any, output_type: string | undefined, skip_meta: string | undefined, post_data: any) => Promise<any>;
export { getOneGenericCollectionItem, getListGenericCollection, getSearchListCollection, getFullSearchListCollection, createGenericCollectionItem, updateGenericCollectionItem, deleteGenericCollectionItem, getExchangeRateForCurrency, getGenericAutoComplete, getLocation, conversation, getReportView, selectGoogleLocation, getListGeneric, setJobStatus, getJobStatus, getWorkflowReport, setWorkflowReport, };
export { getOneGenericCollectionItem, getListGenericCollection, getSearchListCollection, getFullSearchListCollection, createGenericCollectionItem, updateGenericCollectionItem, patchGenericCollectionItem, deleteGenericCollectionItem, bulkEdit, primaryWorkflowAction, secondaryWorkflowAction, getExchangeRateForCurrency, getGenericAutoComplete, getLocation, conversation, createConversation, getConversations, getReportView, selectGoogleLocation, getListGeneric, setJobStatus, getJobStatus, getWorkflowReport, setWorkflowReport, };
103 changes: 101 additions & 2 deletions dist/shipthisapi-js/collections/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,68 @@ const createGenericCollectionItem = async (obj, collectionName, itemData, params
const updateGenericCollectionItem = async (obj, collectionName, objectId, updatedData) => {
return obj.internalRequest(obj, 'PUT', `/incollection/${collectionName}/${objectId}`, { requestData: updatedData });
};
/**
* Patch specific fields of an item (partial update)
* @param obj - ShipthisAPI instance
* @param collectionName - Name of the collection
* @param objectId - Document ID
* @param updateFields - Fields to update
*/
const patchGenericCollectionItem = async (obj, collectionName, objectId, updateFields) => {
return obj.internalRequest(obj, 'PATCH', `/incollection/${collectionName}/${objectId}`, { requestData: { update_fields: updateFields } });
};
/**
* Bulk edit multiple items in a collection
* @param obj - ShipthisAPI instance
* @param collectionName - Name of the collection
* @param ids - List of document IDs to update
* @param updateData - Key-value pairs of fields to update
* @param externalUpdateData - Extra data for external updates (optional)
*/
const bulkEdit = async (obj, collectionName, ids, updateData, externalUpdateData) => {
const payload = {
data: {
ids,
update_data: updateData,
},
};
if (externalUpdateData) {
payload.data.external_update_data = externalUpdateData;
}
return obj.internalRequest(obj, 'POST', `/incollection_group_edit/${collectionName}`, { requestData: payload });
};
/**
* Trigger a primary workflow transition (status change on a record)
* @param obj - ShipthisAPI instance
* @param collection - Target collection (e.g., "pickup_delivery")
* @param workflowId - Workflow status key (e.g., "job_status")
* @param objectId - Document ID
* @param actionIndex - Index of action within the status
* @param intendedStateId - Intended resulting state ID
* @param startStateId - Current/starting state ID (optional)
*/
const primaryWorkflowAction = async (obj, collection, workflowId, objectId, actionIndex, intendedStateId, startStateId) => {
const payload = {
action_index: actionIndex,
intended_state_id: intendedStateId,
};
if (startStateId) {
payload.start_state_id = startStateId;
}
return obj.internalRequest(obj, 'POST', `/workflow/${collection}/${workflowId}/${objectId}`, { requestData: payload });
};
/**
* Trigger a secondary workflow transition (sub-status change)
* @param obj - ShipthisAPI instance
* @param collection - Target collection (e.g., "pickup_delivery")
* @param workflowId - Secondary status key (e.g., "driver_status")
* @param objectId - Document ID
* @param targetState - Resulting sub-state (e.g., "to_pick_up")
* @param additionalData - Optional additional data to send
*/
const secondaryWorkflowAction = async (obj, collection, workflowId, objectId, targetState, additionalData) => {
return obj.internalRequest(obj, 'POST', `/workflow/${collection}/${workflowId}/${objectId}/${targetState}`, { requestData: additionalData || {} });
};
const setJobStatus = async (obj, collectionName, objectId, index) => {
return obj.internalRequest(obj, 'POST', `/workflow/${collectionName}/job_status/${objectId}`, { action_index: index });
};
Expand All @@ -71,7 +133,8 @@ const getExchangeRateForCurrency = async (obj, currency) => {
};
// get the port of landing and discharge for shipments
const getGenericAutoComplete = async (obj, referenceName, data) => {
return obj.internalRequest(obj, 'POST', `autocomplete-reference/${referenceName}?location=new_york`, { requestData: data });
const location = obj.selectedLocation || 'new_york';
return obj.internalRequest(obj, 'POST', `autocomplete-reference/${referenceName}?location=${location}`, { requestData: data });
};
const getLocation = async (obj, collectionName, params) => {
if (!params) {
Expand All @@ -92,6 +155,42 @@ const conversation = async (obj, collectionName, data, params) => {
}
return obj.internalRequest(obj, 'POST', collectionName, data);
};
/**
* Create a conversation/message on a document
* @param obj - ShipthisAPI instance
* @param viewName - Collection/view name
* @param documentId - Document ID
* @param conversationData - Conversation data (message, type, etc.)
*/
const createConversation = async (obj, viewName, documentId, conversationData) => {
const payload = {
conversation: conversationData,
document_id: documentId,
view_name: viewName,
message_type: conversationData?.type || '',
};
return obj.internalRequest(obj, 'POST', 'conversation', { requestData: payload });
};
/**
* Get conversations for a document
* @param obj - ShipthisAPI instance
* @param viewName - Collection/view name
* @param documentId - Document ID
* @param messageType - Filter by message type (default: "all")
* @param page - Page number (default: 1)
* @param count - Items per page (default: 100)
*/
const getConversations = async (obj, viewName, documentId, messageType = 'all', page = 1, count = 100) => {
const params = new URLSearchParams({
view_name: viewName,
document_id: documentId,
page: String(page),
count: String(count),
message_type: messageType,
version: '2',
});
return obj.internalRequest(obj, 'GET', `conversation?${params.toString()}`);
};
const deleteGenericCollectionItem = async (obj, collectionName, objectId) => {
return obj.internalRequest(obj, 'DELETE', `/incollection/${collectionName}/${objectId}`);
};
Expand All @@ -101,4 +200,4 @@ const getReportView = async (obj, report_name, start_date, end_date, location, o
requestData: post_data,
});
};
export { getOneGenericCollectionItem, getListGenericCollection, getSearchListCollection, getFullSearchListCollection, createGenericCollectionItem, updateGenericCollectionItem, deleteGenericCollectionItem, getExchangeRateForCurrency, getGenericAutoComplete, getLocation, conversation, getReportView, selectGoogleLocation, getListGeneric, setJobStatus, getJobStatus, getWorkflowReport, setWorkflowReport, };
export { getOneGenericCollectionItem, getListGenericCollection, getSearchListCollection, getFullSearchListCollection, createGenericCollectionItem, updateGenericCollectionItem, patchGenericCollectionItem, deleteGenericCollectionItem, bulkEdit, primaryWorkflowAction, secondaryWorkflowAction, getExchangeRateForCurrency, getGenericAutoComplete, getLocation, conversation, createConversation, getConversations, getReportView, selectGoogleLocation, getListGeneric, setJobStatus, getJobStatus, getWorkflowReport, setWorkflowReport, };
6 changes: 6 additions & 0 deletions dist/shipthisapi-js/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ export declare class ShipthisAPI {
requestData: any;
}) => any;
} | ShipthisAPI, collectionName: string, objectId: string, updatedData: any) => Promise<any>;
patchGenericCollectionItem: (obj: ShipthisAPI, collectionName: string, objectId: string, updateFields: any) => Promise<any>;
deleteGenericCollectionItem: (obj: {
internalRequest: (arg0: any, arg1: string, arg2: string) => any;
}, collectionName: string, objectId: string) => Promise<any>;
bulkEdit: (obj: ShipthisAPI, collectionName: string, ids: string[], updateData: Record<string, any>, externalUpdateData?: Record<string, any>) => Promise<any>;
primaryWorkflowAction: (obj: ShipthisAPI, collection: string, workflowId: string, objectId: string, actionIndex: number, intendedStateId: string, startStateId?: string) => Promise<any>;
secondaryWorkflowAction: (obj: ShipthisAPI, collection: string, workflowId: string, objectId: string, targetState: string, additionalData?: Record<string, any>) => Promise<any>;
getExchangeRateForCurrency: (obj: ShipthisAPI, currency: string) => Promise<any>;
getGenericAutoComplete: (obj: ShipthisAPI, referenceName: string, data: any) => Promise<any>;
getLocation: (obj: ShipthisAPI, collectionName: string, params?: import("./interfaces/collection-params.interface.js").CollectionParams) => Promise<any>;
Expand All @@ -63,6 +67,8 @@ export declare class ShipthisAPI {
internalRequest: (arg0: any, arg1: string, arg2: string) => any;
}, objectId: string) => Promise<any>;
conversation: (obj: ShipthisAPI, collectionName: string, data: any, params?: import("./interfaces/collection-params.interface.js").CollectionParams) => Promise<any>;
createConversation: (obj: ShipthisAPI, viewName: string, documentId: string, conversationData: any) => Promise<any>;
getConversations: (obj: ShipthisAPI, viewName: string, documentId: string, messageType?: string, page?: number, count?: number) => Promise<any>;
getReportView: (obj: {
internalRequest: (arg0: any, arg1: string, arg2: string, arg3: {
params: {
Expand Down
8 changes: 7 additions & 1 deletion dist/shipthisapi-js/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createGenericCollectionItem, deleteGenericCollectionItem, getListGenericCollection, getSearchListCollection, getFullSearchListCollection, getOneGenericCollectionItem, getExchangeRateForCurrency, getGenericAutoComplete, getLocation, conversation, getReportView, updateGenericCollectionItem, selectGoogleLocation, getListGeneric, setJobStatus, getJobStatus, getWorkflowReport, setWorkflowReport, } from './collections/generic.js';
import { createGenericCollectionItem, deleteGenericCollectionItem, getListGenericCollection, getSearchListCollection, getFullSearchListCollection, getOneGenericCollectionItem, getExchangeRateForCurrency, getGenericAutoComplete, getLocation, conversation, createConversation, getConversations, getReportView, updateGenericCollectionItem, patchGenericCollectionItem, selectGoogleLocation, getListGeneric, setJobStatus, getJobStatus, getWorkflowReport, setWorkflowReport, bulkEdit, primaryWorkflowAction, secondaryWorkflowAction, } from './collections/generic.js';
import { internalRequest, uploadFile } from './utils/request.js';
import { Shipment } from './collections/shipment.js';
import { Setup } from './collections/setup.js';
Expand Down Expand Up @@ -27,7 +27,11 @@ export class ShipthisAPI {
getOneGenericCollectionItem = getOneGenericCollectionItem;
createGenericCollectionItem = createGenericCollectionItem;
updateGenericCollectionItem = updateGenericCollectionItem;
patchGenericCollectionItem = patchGenericCollectionItem;
deleteGenericCollectionItem = deleteGenericCollectionItem;
bulkEdit = bulkEdit;
primaryWorkflowAction = primaryWorkflowAction;
secondaryWorkflowAction = secondaryWorkflowAction;
getExchangeRateForCurrency = getExchangeRateForCurrency;
getGenericAutoComplete = getGenericAutoComplete;
getLocation = getLocation;
Expand All @@ -37,6 +41,8 @@ export class ShipthisAPI {
getWorkflowReport = getWorkflowReport;
setWorkflowReport = setWorkflowReport;
conversation = conversation;
createConversation = createConversation;
getConversations = getConversations;
getReportView = getReportView;
/**
* Collection Definition
Expand Down
6 changes: 5 additions & 1 deletion dist/shipthisapi-js/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"name": "shipthisapi-js",
"version": "2.0.7",
"version": "2.1.0",
"description": "Wrapper for shipthis api",
"engines": {
"node": ">=18"
},
"author": "Mayur Rawte",
"license": "Apache-2.0",
"overrides": {
"ajv": "^8.18.0",
"minimatch": "^10.2.2"
},
"main": "main.js",
"types": "main.d.ts",
"files": [
Expand Down
3 changes: 3 additions & 0 deletions dist/shipthisapi-js/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const prepareHeaders = async (obj) => {
if (obj.xApiKey) {
headers['x-api-key'] = obj.xApiKey || '';
}
if (obj.authorization) {
headers['authorization'] = obj.authorization || '';
}
return headers;
};
const internalRequest = async (obj, method, path, options) => {
Expand Down
14 changes: 7 additions & 7 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ export default {
preset: 'ts-jest/presets/js-with-ts',
testEnvironment: 'node',
extensionsToTreatAsEsm: ['.ts'],
globals: {
'ts-jest': {
useESM: true,
},
},
transform: {
'^.+\\.ts$': 'ts-jest',
'^.+\\.ts$': [
'ts-jest',
{
useESM: true,
},
],
},
testRegex: '(/tests/.*|(\\.|/)(test|spec))\\.ts$',
testRegex: '(/tests/.*|(\\.|/)(test|spec))\\.(?!d\\.ts$)ts$',
coverageDirectory: 'coverage',
collectCoverageFrom: ['src/**/*.ts', '!src/**/*.d.ts'],
testTimeout: 30000,
Expand Down
Loading
Loading