Skip to content

Commit

Permalink
fix: do not forward customerId & orderId to the body request when cre…
Browse files Browse the repository at this point in the history
…ating an order, closes #7
  • Loading branch information
Gomah committed Mar 25, 2023
1 parent 776eee7 commit a0c3aec
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,24 @@ export class SendleClient {
},

create: async (args: Sendle.OrderArgs): Promise<Sendle.Order | never> => {
const { customerId, orderId } = args;
let { idempotencyKey } = args;

if (!idempotencyKey) {
idempotencyKey =
customerId && orderId ? hasha(`${customerId}-${orderId}`) : this.#hyperIdInstance();
}
const { customerId, orderId, idempotencyKey, ...body } = args;

return this.request<Sendle.Order>({
path: `orders`,
method: 'post',
body: args,
body: {
...body,
metadata: {
customerId,
orderId,
...body.metadata,
},
},
headers: {
'Idempotency-Key': idempotencyKey,
'Idempotency-Key':
idempotencyKey || (customerId && orderId)
? hasha(`${customerId}-${orderId}`)
: this.#hyperIdInstance(),
'Content-Type': 'application/json',
Accept: 'application/json',
},
Expand Down

0 comments on commit a0c3aec

Please sign in to comment.