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

API v2024-07 support #6

Merged
merged 30 commits into from
Aug 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6cd4035
renaming old order concept to dataset
Maldris Aug 12, 2024
483519c
boiler plate for new types
Maldris Aug 13, 2024
efa4842
mocking new order endpoints and path scheme
Maldris Aug 13, 2024
d8e60e0
updating documentation comments for endpoint documentation references
Maldris Aug 13, 2024
f12dee4
updating list endpoints to have new pagination structure
Maldris Aug 13, 2024
cb6ef76
adding pagination to list endpoints
Maldris Aug 13, 2024
95c0d88
separating list parsing into utility
Maldris Aug 13, 2024
5d012a5
campaign get datasets getter (and retrieve from endpoint
Maldris Aug 13, 2024
c7dffc8
caching campaign datasets
Maldris Aug 13, 2024
0cc59f3
decoding campaign datasets in from json
Maldris Aug 13, 2024
db043d7
providing campaign and dataset list getters for orders
Maldris Aug 13, 2024
da7e204
fixing path's in order sub list calls
Maldris Aug 13, 2024
2a7b7b7
order endpoints now return the new order structure
Maldris Aug 13, 2024
48203d9
handling new search response structure
Maldris Aug 13, 2024
34cdbd9
moving order structure back into archive
Maldris Aug 13, 2024
c3d7894
implementing order structures for tasking in the tasking package
Maldris Aug 13, 2024
a6e1b7e
updating references in archive tests
Maldris Aug 13, 2024
b36ec68
updating tasking test references
Maldris Aug 13, 2024
cfd5a4b
cleanup order endpoint errors before adding new endpoints
Maldris Aug 13, 2024
f165ee1
fixing type specifier in sub list debug message
Maldris Aug 14, 2024
762ed74
adding missing manual order status
Maldris Aug 14, 2024
658e2a4
handle custom datasets potentially not having a datetime
Maldris Aug 14, 2024
19dc788
dataset self load points to wrong endpoint
Maldris Aug 14, 2024
a495d7c
fixing wrong field name in tasking response decode
Maldris Aug 14, 2024
16ab604
updating environment variable references
Maldris Aug 14, 2024
1723648
updating order api test suite for new endpoints
Maldris Aug 14, 2024
d1802b6
fixing field name in priority encoding
Maldris Aug 15, 2024
6f17760
fixing status code checking of tasking orders
Maldris Aug 15, 2024
89aecb2
adding new env config for test environment
Maldris Aug 15, 2024
53611d3
adding other missing secret values and fixing name-spacing of secrets
Maldris Aug 15, 2024
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
Prev Previous commit
Next Next commit
updating list endpoints to have new pagination structure
  • Loading branch information
Maldris committed Aug 13, 2024
commit f12dee4601d693d6d21dbb4879832f8878a537ed
107 changes: 71 additions & 36 deletions src/orders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,90 +24,78 @@ export default class Orders {

/**
* list orders previously placed by this API from newest to oldest
* @returns {Promise<Order[]>} the list of orders
* @returns {Promise<ListResponse<Order>>} the list of orders
*
* @see {https://arlula.com/documentation/orders/#order-list|Orders List endpoint documentation}
* or
* @see {https://arlula.com/documentation/orders/#ref-order|Order structure reference}
*/
orderList(): Promise<Order[]> {
orderList(): Promise<ListResponse<Order>> {
return this._client("GET", paths.OrderList())
.then(jsonOrError)
.then((resp) => {
if (!Array.isArray(resp)) {
return Promise.reject("Orders list response is not array");
if (!(resp instanceof Object)) {
return Promise.reject("Order list endpoint returned a malformed response");
}

const orders: Order[] = [];
for (let i=0; i<resp.length; i++) {
const ord = orderFromJSON(this._client, resp[i])
if (!(ord instanceof Order)) {
return Promise.reject(ord);
}
orders.push(ord);
const list = parseListResponse<Order>(this._client, resp as {[key: string]: unknown}, orderFromJSON)
if (typeof list === "string") {
return Promise.reject(list);
}

return orders;
return list;
});
}

/**
* list tasking campaigns previously lodged by this API from newest to oldest
* @returns {Promise<Campaign[]>} the list of tasking campaigns
* @returns {Promise<ListResponse<Campaign>>} the list of tasking campaigns
*
* @see {https://arlula.com/documentation/orders/#campaign-list|Campaign List endpoint documentation}
* or
* @see {https://arlula.com/documentation/orders/#ref-campaign|Campaign structure reference}
*/
campaignList(): Promise<Campaign[]> {
campaignList(): Promise<ListResponse<Campaign>> {
return this._client("GET", paths.CampaignList())
.then(jsonOrError)
.then((resp) => {
if (!Array.isArray(resp)) {
return Promise.reject("Campaigns list response is not array");
if (!(resp instanceof Object)) {
return Promise.reject("Campaign list endpoint returned a malformed response");
}

const campaigns: Campaign[] = [];
for (let i=0; i<resp.length; i++) {
const ord = campaignFromJSON(this._client, resp[i])
if (!(ord instanceof Campaign)) {
return Promise.reject(ord);
}
campaigns.push(ord);
const list = parseListResponse<Campaign>(this._client, resp as {[key: string]: unknown}, campaignFromJSON)
if (typeof list === "string") {
return Promise.reject(list);
}

return campaigns;
return list;
});
}

/**
* list datasets available to this API from newest to oldest.
* this will include both those created by archive orders,
* and those generated by delivery from a tasking campaign
* @returns {Promise<Dataset[]>} the list of datasets
* @returns {Promise<ListResponse<Dataset>>} the list of datasets
*
* @see {https://arlula.com/documentation/orders/#dataset-list|Dataset List endpoint documentation}
* or
* @see {https://arlula.com/documentation/orders/#ref-dataset|Dataset structure reference}
*/
datasetList(): Promise<Dataset[]> {
datasetList(): Promise<ListResponse<Dataset>> {
return this._client("GET", paths.DatasetList())
.then(jsonOrError)
.then((resp) => {
if (!Array.isArray(resp)) {
return Promise.reject("Datasets list response is not array");
if (!(resp instanceof Object)) {
return Promise.reject("Campaign list endpoint returned a malformed response");
}

const datasets: Dataset[] = [];
for (let i=0; i<resp.length; i++) {
const ord = datasetFromJSON(this._client, resp[i])
if (!(ord instanceof Dataset)) {
return Promise.reject(ord);
}
datasets.push(ord);
const list = parseListResponse<Dataset>(this._client, resp as {[key: string]: unknown}, datasetFromJSON)
if (typeof list === "string") {
return Promise.reject(list);
}

return datasets;
return list;
});
}

Expand Down Expand Up @@ -247,3 +235,50 @@ export default class Orders {
return downloadFileHelper(this._client, id, ref);
}
}

export interface ListResponse<Type> {
content: Type[];
page: number;
length: number;
count: number;
}

function parseListResponse<Type>(client: requestBuilder, json: string|{[key: string]: unknown}, fromJSON: (client: requestBuilder, json: string|{[key: string]: unknown})=>Type|string): ListResponse<Type>|string {
if (typeof json === "string") {
json = JSON.parse(json);
}

if (!(json instanceof Object)) {
return "JSON does not correspond to an Order object";
}

if (typeof json.page != "number") {
return "list response is missing page number"
}
if (typeof json.length != "number") {
return "list response is missing page length"
}
if (typeof json.count != "number") {
return "list response is missing result count"
}
if (!Array.isArray(json.content)) {
return "list response content is not an array"
}

const resp: ListResponse<Type> = {
content: [],
page: json.page,
length: json.length,
count: json.count,
};

for (let i=0; i<json.content.length; i++) {
const ite = fromJSON(client, json.content[i]);
if (typeof ite === "string") {
return ite;
}
resp.content.push(ite)
}

return resp;
}