From 878407679d44d4d21e57ac31087f4f00aa1772ad Mon Sep 17 00:00:00 2001 From: Sophia Hage Date: Mon, 15 Apr 2024 10:50:21 +0200 Subject: [PATCH 1/4] fix: :bug: order creation not working with templateId --- src/PrintOne.ts | 18 ++++-------------- src/models/CsvOrder.ts | 12 ++++++++++-- src/models/Order.ts | 12 ++++++++++-- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/PrintOne.ts b/src/PrintOne.ts index 10230ed..ee626cd 100644 --- a/src/PrintOne.ts +++ b/src/PrintOne.ts @@ -245,13 +245,8 @@ export class PrintOne { * Create an order */ public async createOrder(data: CreateOrder): Promise { - let templateId: undefined | string; - - if (data.template instanceof Template) { - templateId = data.template.id; - } else { - templateId = data.template; - } + const template = data.templateId ?? data.template; + const templateId = template instanceof Template ? template.id : template; const sendDateStr = data.sendDate instanceof Date @@ -272,13 +267,8 @@ export class PrintOne { } public async createCsvOrder(data: CreateCsvOrder): Promise { - let templateId: undefined | string; - - if (data.template instanceof Template) { - templateId = data.template.id; - } else { - templateId = data.template; - } + const template = data.templateId ?? data.template; + const templateId = template instanceof Template ? template.id : template; const formData = new FormData(); formData.append( diff --git a/src/models/CsvOrder.ts b/src/models/CsvOrder.ts index a0118ca..8552f3c 100644 --- a/src/models/CsvOrder.ts +++ b/src/models/CsvOrder.ts @@ -14,11 +14,19 @@ export type CreateCsvOrder = { recipient: Address; mergeVariables?: Record; }; - template: Template | string; finish?: Finish; billingId?: string; sender?: Address; -}; +} & ( + | { + template: Template | string; + templateId: undefined; + } + | { + template: undefined; + templateId: string; + } +); export class CsvOrder { private _data: ICsvOrder; diff --git a/src/models/Order.ts b/src/models/Order.ts index dbac81b..c960138 100644 --- a/src/models/Order.ts +++ b/src/models/Order.ts @@ -10,7 +10,6 @@ import { sleep } from "../utils"; export type CreateOrder = { recipient: Address; sender?: Address; - template: Template | string; /** * @default GLOSSY */ @@ -18,7 +17,16 @@ export type CreateOrder = { mergeVariables?: Record; billingId?: string; sendDate?: Date | string; -}; +} & ( + | { + template: Template | string; + templateId: undefined; + } + | { + template: undefined; + templateId: string; + } +); export class Order { private _data: IOrder; From c09dd937e239d6efa9127def0852cdd7ab8d6e0c Mon Sep 17 00:00:00 2001 From: Sophia Hage Date: Mon, 15 Apr 2024 11:02:48 +0200 Subject: [PATCH 2/4] fix: :bug: incorrect ts marking for undefined properties --- src/models/CsvOrder.ts | 4 ++-- src/models/Order.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/models/CsvOrder.ts b/src/models/CsvOrder.ts index 8552f3c..e78f0f5 100644 --- a/src/models/CsvOrder.ts +++ b/src/models/CsvOrder.ts @@ -20,10 +20,10 @@ export type CreateCsvOrder = { } & ( | { template: Template | string; - templateId: undefined; + templateId?: undefined; } | { - template: undefined; + template?: undefined; templateId: string; } ); diff --git a/src/models/Order.ts b/src/models/Order.ts index c960138..d3a1e2a 100644 --- a/src/models/Order.ts +++ b/src/models/Order.ts @@ -20,10 +20,10 @@ export type CreateOrder = { } & ( | { template: Template | string; - templateId: undefined; + templateId?: undefined; } | { - template: undefined; + template?: undefined; templateId: string; } ); From 59a73ea4d118c20f3627e464dd90a395e30eaaef Mon Sep 17 00:00:00 2001 From: Sophia Hage Date: Mon, 15 Apr 2024 11:29:24 +0200 Subject: [PATCH 3/4] fix: :bug: incorrect check in csv order test --- test/CsvOrder.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CsvOrder.spec.ts b/test/CsvOrder.spec.ts index b0bc360..ea4c493 100644 --- a/test/CsvOrder.spec.ts +++ b/test/CsvOrder.spec.ts @@ -88,7 +88,7 @@ describe("getOrders", function () { // arrange // act - while (await order.getOrders({}).then((x) => x.data.length > 0)) { + while (await order.getOrders({}).then((x) => x.data.length < 1)) { await order.refresh(); await sleep(1000); } From 0a12e9b1a45a0327faf2cb40a93a99b00d42b674 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 15 Apr 2024 09:31:15 +0000 Subject: [PATCH 4/4] chore(release): 1.2.1 [skip ci] ## [1.2.1](https://github.com/Print-one/print-one-js/compare/v1.2.0...v1.2.1) (2024-04-15) ### Bug Fixes * :bug: incorrect check in csv order test ([59a73ea](https://github.com/Print-one/print-one-js/commit/59a73ea4d118c20f3627e464dd90a395e30eaaef)) * :bug: incorrect ts marking for undefined properties ([c09dd93](https://github.com/Print-one/print-one-js/commit/c09dd937e239d6efa9127def0852cdd7ab8d6e0c)) * :bug: order creation not working with templateId ([8784076](https://github.com/Print-one/print-one-js/commit/878407679d44d4d21e57ac31087f4f00aa1772ad)) --- CHANGELOG.md | 9 +++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c934fd5..2660746 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## [1.2.1](https://github.com/Print-one/print-one-js/compare/v1.2.0...v1.2.1) (2024-04-15) + + +### Bug Fixes + +* :bug: incorrect check in csv order test ([59a73ea](https://github.com/Print-one/print-one-js/commit/59a73ea4d118c20f3627e464dd90a395e30eaaef)) +* :bug: incorrect ts marking for undefined properties ([c09dd93](https://github.com/Print-one/print-one-js/commit/c09dd937e239d6efa9127def0852cdd7ab8d6e0c)) +* :bug: order creation not working with templateId ([8784076](https://github.com/Print-one/print-one-js/commit/878407679d44d4d21e57ac31087f4f00aa1772ad)) + # [1.2.0](https://github.com/Print-one/print-one-js/compare/v1.1.0...v1.2.0) (2024-04-04) diff --git a/package-lock.json b/package-lock.json index 72eced5..d3578ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@print-one/print-one-js", - "version": "1.2.0", + "version": "1.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@print-one/print-one-js", - "version": "1.2.0", + "version": "1.2.1", "license": "MIT", "dependencies": { "axios": "^1.6.6", diff --git a/package.json b/package.json index 811ff3b..2c14236 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@print-one/print-one-js", - "version": "1.2.0", + "version": "1.2.1", "description": "The official javascript client for Print.one", "license": "MIT", "author": "Print.one",