Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Print-one/print-one-js into next
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulRill00 committed Aug 7, 2024
2 parents 10cfc27 + 52ef1bd commit 3d04b5d
Show file tree
Hide file tree
Showing 17 changed files with 877 additions and 6 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# [1.3.0](https://github.com/Print-one/print-one-js/compare/v1.2.1...v1.3.0) (2024-07-01)


### Bug Fixes

* batch status filter ([2b0e209](https://github.com/Print-one/print-one-js/commit/2b0e20917d66ad21af372c5ed19f8f80da20ae71))
* batch status filter ([2db77de](https://github.com/Print-one/print-one-js/commit/2db77de99b2e53f85e459790e82828b91edd58db))
* import in CsvOrder.ts ([#19](https://github.com/Print-one/print-one-js/issues/19)) ([40986aa](https://github.com/Print-one/print-one-js/commit/40986aac4deb5ff5d9b87358f30c4a9138998a5e))
* typescript error on install ([8fb29c4](https://github.com/Print-one/print-one-js/commit/8fb29c4f83831d12510e31475fb3a6fdc4ed352f))


### Features

* :sparkles: added endpoint to get a CsvOrder by it's ID ([74b0313](https://github.com/Print-one/print-one-js/commit/74b0313fefc98ddb45184c3b27a9615ea39fe7e7))
* :sparkles: added remaining getBatches filters ([4c2996b](https://github.com/Print-one/print-one-js/commit/4c2996b4ad3cf29bab6daf32830ae419c9641e81))
* :sparkles: allow for getting CSV order by id ([0560944](https://github.com/Print-one/print-one-js/commit/0560944128abdeea5cf0ff5ec79391201e0598a3))
* :sparkles: allow for uploading CSVs to a Batch ([a4bd3a6](https://github.com/Print-one/print-one-js/commit/a4bd3a68ecc6f7d360ab751be88b22324249b6f6))
* :sparkles: support batch order's API urls ([c2ca919](https://github.com/Print-one/print-one-js/commit/c2ca919f5d91f0618f2699d180e6bc8830d560b7))
* :sparkles: webhook request validation logic ([ce81792](https://github.com/Print-one/print-one-js/commit/ce81792e9b554ceaf0694857a9402b003bb80392))
* ✨ added CsvOrder model + endpoints ([#7](https://github.com/Print-one/print-one-js/issues/7)) ([9e04141](https://github.com/Print-one/print-one-js/commit/9e041416bdc09a3f34d6f2da72bde6788770e39b))
* added format to DTO ([64ec3ad](https://github.com/Print-one/print-one-js/commit/64ec3adc8b51dd697d0c1244e663353b087a17c1))
* batch endpoints added ([#8](https://github.com/Print-one/print-one-js/issues/8)) ([0099217](https://github.com/Print-one/print-one-js/commit/009921704b0c7b75206341ef20b1f540c31e366c))
* implement PR feedback ([8420046](https://github.com/Print-one/print-one-js/commit/8420046c3655a0a9480f192f3879fcf9524c06f4))

# [1.3.0-next.3](https://github.com/Print-one/print-one-js/compare/v1.3.0-next.2...v1.3.0-next.3) (2024-07-02)


Expand Down
96 changes: 96 additions & 0 deletions docs/Coupon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
Contains all information about a given CsvOrder

# Fields

| Name | Type | Description |
| ---------------------- | ------------------------------------ | -------------------------------------------------------------------------------------------------------- |
| `id` | `string` | The ID of the coupon. |
| `name` | `string` | The name of the coupon. |
| `companyId` | `string` | The ID of the company the coupon belongs to. |
| `stats` | `object` | An object containing the stats of the coupon. With keys 'total', 'used' and 'remaining' |

# Methods

## `.refresh()`

Refresh the Coupon data to get the latest information

**Returns: `Promise<void>`**

**Example**

```js
const coupon: Coupon;
await coupon.refresh();
```

---

## `Coupon.getCodes()`

Get all coupon codes within the coupon. |

**Returns: [`Promise<PaginatedResponse<CouponCode>>`](./CouponCode)**

**Example**

```js
const couponCodes = await coupon.getCodes();
```

---

## `Coupon.getCode(id)`

Get all coupon codes by its ID.

**Parameters**

| Name | Type | Description |
| ---- | -------- | --------------------------------- |
| `id` | `string` | The ID of the coupon code to get. |

**Returns: [`Promise<PaginatedResponse<CouponCode>>`](./CouponCode)**

**Example**

```js
const couponCode = await coupon.getCode('example-coupon-code-id');
```

---

## `Coupon.addCodes(csv)`

Add coupon codes to the coupon by uploading a CSV.

**Parameters**

| Name | Type | Description |
| ---------- | ------------- | --------------------------------- |
| `csv` | `ArrayBuffer` | The file to upload. Must be a CSV |

**Returns: `Promise<void>`

**Example**

```js
const data = fs.readFileSync("example.csv").buffer;
const file = await coupon.addCodes(data);
```


---

## `Coupon.delete()`

Delete the coupon.

**Returns: `Promise<void>`

**Example**

```js
await coupon.delete();
```

43 changes: 43 additions & 0 deletions docs/CouponCode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Contains all information about a given CsvOrder

# Fields

| Name | Type | Description |
| ---------------------- | ------------------------------------ | --------------------------------------------------------------------------------- |
| `id` | `string` | The ID of the coupon code. |
| `couponId` | `string` | The ID of the parent coupon. |
| `code` | `string` | The actual code saved for the coupon code`. |
| `used` | `boolean` | Whether the coupon code has been used. |
| `usedAt` | `Date` or `null` | The date at which the coupon code was used or `null` if not used yet. |
| `orderId` | `string` or `null` | The order ID by which the coupon code was used or `null` if not used yet. |

# Methods
---

## `.refresh()`

Refresh the CouponCode data to get the latest information

**Returns: `Promise<void>`**

**Example**

```js
const couponCode: CouponCOde;
await couponCode.refresh();
```

---

## `.getOrder()`

Get the order the coupon code was used by. You might need to do [`CouponCode.refresh`](#refresh) first when coupon was used after fetching.

**Returns: [`Promise<Order|null>`](./Order)**

**Example**

```js
const couponCode: CouponCode
const order = await couponCode.getOrder();;
```
74 changes: 74 additions & 0 deletions docs/PrintOne.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,77 @@ const csvOrder = await client.getCsvOrder("example-order-id");
```
```

--

## `.createCoupon(data)`

Create a new coupon.

**Parameters**

| Name | Type | Description |
| ------ | -------- | ------------------------------------------------------------------------------------------- |
| `data` | `object` | The data to create the coupon with. See [`Order`](./Coupon#createcoupondata) for more info. |

**Returns: [`Promise<Coupon>`](./Order)**

**Example**

```js
const coupon = await client.createCoupon({
name: "coupon",
});
```

---

## `.getCoupons([options])`

Get all coupons.

**Parameters**

| Name | Type | Default | Description |
| ------------------------------- | ----------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `options.limit` | `number` | `10` | The maximum number of coupons to return. |
| `options.page` | `number` | `1` | The page of coupons to return. |
| `options.sortBy` | [`sort`](./Filtering#Sorting) | `createdAt:DESC` | The field(s) to sort the coupons by. Can be `createdAt` or `name` |
| `options.filter.name` | `string` \| `string[]` | `undefined` | The name(s) of the coupon(s) to filter |

**Returns: [`Promise<PaginatedResponse<Order>>`](./Order)**

**Example**

```js
const coupons = await client.getCoupons({
limit: 20,
page: 1,
sortBy: "createdAt:ASC",
filter: {
name: "test",
},
});
```

---

## `.getCoupon(id)`

Get a coupon by its ID.

**Parameters**

| Name | Type | Description |
| ---- | -------- | ---------------------------- |
| `id` | `string` | The ID of the coupon to get. |

**Returns: [`Promise<Coupon>`](./Coupon)**

**Example**

```js
const coupon = await client.getCoupon("example-coupon-id");
```

---
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@print-one/print-one-js",
"version": "1.3.0-next.3",
"version": "1.3.0",
"description": "The official javascript client for Print.one",
"license": "MIT",
"author": "Print.one",
Expand Down
61 changes: 59 additions & 2 deletions src/PrintOne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import { Webhook } from "~/models/Webhook";
import { CreateWebhook, IWebhook } from "~/models/_interfaces/IWebhook";
import { WebhookRequest, webhookRequestFactory } from "~/models/WebhookRequest";
import { IWebhookRequest } from "~/models/_interfaces/IWebhookRequest";
import { Coupon, CreateCoupon } from "~/models/Coupon";
import { ICoupon } from "~/models/_interfaces/ICoupon";

export type RequestHandler = new (
token: string,
Expand Down Expand Up @@ -527,7 +529,62 @@ export class PrintOne {
);
}

public isValidWebhook(
/**
* Create a coupon
* @param data The coupon data
*/
public async createCoupon(data: CreateCoupon): Promise<Coupon> {
const response = await this.client.POST<ICoupon>("coupons", {
name: data.name,
});

return new Coupon(this.protected, response);
}

/**
* Get all coupons.
* @param { PaginationOptions } options The options to use for pagination
* @param options.limit The maximum amount of coupons to return.
* @param options.page The page to return.
* @param options.sortBy The fields to sort by, can be "createdAt", "updatedAt".
* @param options.filter The filters to apply.
*/
public async getCoupons(
options: PaginationOptions<"name"> & {
filter?: {
name?: InFilter;
createdAt?: DateFilter;
};
} = {},
): Promise<PaginatedResponse<Coupon>> {
const params = {
...sortToQuery(options),
...inFilterToQuery("name", options.filter?.name),
};

const data = await this.client.GET<IPaginatedResponse<ICoupon>>("coupons", {
params: params,
});

return PaginatedResponse.safe(
this.protected,
data,
(data) => new Coupon(this.protected, data),
);
}

/**
* Get a coupon by its id.
* @param { string } id The id of the coupon.
* @throws { PrintOneError } If the coupon could not be found.
*/
public async getCoupon(id: string): Promise<Coupon> {
const data = await this.client.GET<ICoupon>(`coupons/${id}`);

return new Coupon(this.protected, data);
}

public validatedWebhook(
body: string,
headers: Record<string, string>,
secret: string,
Expand All @@ -542,7 +599,7 @@ export class PrintOne {
return hmac === hmacHeader;
}

public validateWebhook(
public isValidWebhook(
body: string,
headers: Record<string, string>,
secret: string,
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ export * from "./PrintOne";

// Models
export * from "./models/Address";
export * from "./models/Batch";
export * from "./models/Company";
export * from "./models/Coupon";
export * from "./models/CouponCode";
export * from "./models/CsvOrder";
export * from "./models/CustomFile";
export * from "./models/Order";
export * from "./models/PaginatedResponse";
export * from "./models/Preview";
export * from "./models/PreviewDetails";
export * from "./models/Template";
export * from "./models/Batch";

// Enums
export * from "./enums/CsvStatus";
Expand Down
Loading

0 comments on commit 3d04b5d

Please sign in to comment.