Skip to content

Commit 2fb1bb5

Browse files
Added customerId to address and business entities (#11)
1 parent 5227120 commit 2fb1bb5

23 files changed

+83
-17
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
Check our main [developer changelog](https://developer.paddle.com/?utm_source=dx&utm_medium=paddle-node-sdk) for information about changes to the Paddle Billing platform, the Paddle API, and other developer tools.
88

99

10+
## 1.0.2 - 2024-03-12
11+
12+
### Added
13+
14+
- Exported `ApiError` class for usage in `try/catch` block.
15+
16+
### Changed
17+
18+
- Added `customerId` property to `Address` and `Business` entities, see [related changelog](https://developer.paddle.com/changelog/2024/address-business-webhooks-customer-id?utm_source=dx&utm_medium=paddle-node-sdk).
19+
20+
---
21+
1022
## 1.0.1 - 2024-02-20
1123

1224
### Changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,26 @@ const product = await archiveProduct('id')
206206
console.log('Product', product)
207207
```
208208

209+
### Error Handling
210+
211+
If a request fails, Paddle returns an `error` object that contains the same information as [errors returned by the API](https://developer.paddle.com/api-reference/about/errors?utm_source=dx&utm_medium=paddle-node-sdk). You can use the `code` attribute to search an error in [the error reference](https://developer.paddle.com/errors/overview?utm_source=dx&utm_medium=paddle-node-sdk) and to handle the error in your app. Validation errors also return an array of `errors` that tell you which fields failed validation.
212+
213+
This example shows how to handle an error with the code `conflict`:
214+
215+
```typescript
216+
import { ApiError } from '@paddle/paddle-node-sdk'
217+
218+
try {
219+
// Call functions from the SDK
220+
} catch (e: any) {
221+
// e.code will always follow the error code defined in our documentation
222+
const paddleApiError = e as ApiError;
223+
if (paddleApiError.code === 'conflict') {
224+
// Handle Conflict error
225+
}
226+
}
227+
```
228+
209229
## Resources
210230

211231
### Webhook signature verification
@@ -265,4 +285,4 @@ The Node.js SDK has complete feature parity with the Paddle API. All operations
265285
## Learn more
266286

267287
- [Paddle API reference](https://developer.paddle.com/api-reference/overview?utm_source=dx&utm_medium=paddle-node-sdk)
268-
- [Sign up for Paddle Billing](https://login.paddle.com/signup?utm_source=dx&utm_medium=paddle-node-sdk)
288+
- [Sign up for Paddle Billing](https://login.paddle.com/signup?utm_source=dx&utm_medium=paddle-node-sdk)

jest.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ const config = {
99
testMatch: ['**/__tests__/**/*.test.ts'],
1010
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
1111
cacheDirectory: process.env.JEST_CACHE_FOLDER || '/tmp/node-sdk/.jest-cache',
12-
coveragePathIgnorePatterns: ['/src/types/', '__tests__', '/src/enums/', 'operations'],
12+
coveragePathIgnorePatterns: [
13+
'/src/types/',
14+
'__tests__',
15+
'/src/enums/',
16+
'operations',
17+
'index.ts',
18+
'src/notifications/types',
19+
],
1320
};
1421

1522
module.exports = config;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@paddle/paddle-node-sdk",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "A Node.js SDK that you can use to integrate Paddle Billing with applications written in server-side JavaScript.",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/__tests__/mocks/notifications/address-created.mock.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
* Changes may be overwritten as part of auto-generation.
55
*/
66

7-
import { type IEventsResponse, type IAddressResponse } from '../../../types';
7+
import { type IEventsResponse } from '../../../types';
8+
import { IAddressNotificationResponse } from '../../../notifications';
89

9-
export const AddressCreatedMock: IEventsResponse<IAddressResponse> = {
10+
export const AddressCreatedMock: IEventsResponse<IAddressNotificationResponse> = {
1011
event_id: 'evt_01h848pezaj15tkt3dsa36xe59',
1112
event_type: 'address.created',
1213
occurred_at: '2023-08-18T12:07:37.194676Z',
@@ -33,6 +34,7 @@ export const AddressCreatedMockExpectation = {
3334
countryCode: 'US',
3435
createdAt: '2023-08-18T12:07:36.9Z',
3536
customData: null,
37+
customerId: null,
3638
description: 'Head Office',
3739
firstLine: '4050 Jefferson Plaza, 41st Floor',
3840
id: 'add_01h848pep46enq8y372x7maj0p',

src/__tests__/mocks/notifications/address-imported.mock.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
* Changes may be overwritten as part of auto-generation.
55
*/
66

7-
import { type IEventsResponse, type IAddressResponse } from '../../../types';
7+
import { type IEventsResponse } from '../../../types';
8+
import { IAddressNotificationResponse } from '../../../notifications';
89

9-
export const AddressImportedMock: IEventsResponse<IAddressResponse> = {
10+
export const AddressImportedMock: IEventsResponse<IAddressNotificationResponse> = {
1011
event_id: 'evt_01hhy7cva3jgaez82k6n4n3x4b',
1112
event_type: 'address.imported',
1213
occurred_at: '2023-08-18T12:07:37.194676Z',
@@ -34,6 +35,7 @@ export const AddressImportedMockExpectation = {
3435
countryCode: 'US',
3536
createdAt: '2023-08-18T12:07:36.9Z',
3637
customData: null,
38+
customerId: null,
3739
description: 'Head Office',
3840
firstLine: '4050 Jefferson Plaza, 41st Floor',
3941
id: 'add_01h848pep46enq8y372x7maj0p',

src/__tests__/mocks/notifications/address-updated.mock.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
* Changes may be overwritten as part of auto-generation.
55
*/
66

7-
import { type IEventsResponse, type IAddressResponse } from '../../../types';
7+
import { type IEventsResponse } from '../../../types';
8+
import { IAddressNotificationResponse } from '../../../notifications';
89

9-
export const AddressUpdatedMock: IEventsResponse<IAddressResponse> = {
10+
export const AddressUpdatedMock: IEventsResponse<IAddressNotificationResponse> = {
1011
event_id: 'evt_01h849k5rs5jxgctb45s6pmkat',
1112
event_type: 'address.updated',
1213
occurred_at: '2023-08-18T12:23:18.041154Z',
@@ -33,6 +34,7 @@ export const AddressUpdatedMockExpectation = {
3334
countryCode: 'US',
3435
createdAt: '2023-08-18T12:22:44.543Z',
3536
customData: null,
37+
customerId: null,
3638
description: 'California Office',
3739
firstLine: '5400 E Washington Drive, Floor 2',
3840
id: 'add_01h849j51zpxv1e3zy2vgrrk6a',

src/__tests__/mocks/notifications/business-created.mock.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
* Changes may be overwritten as part of auto-generation.
55
*/
66

7-
import { type IEventsResponse, type IBusinessResponse } from '../../../types';
7+
import { type IEventsResponse } from '../../../types';
8+
import { IBusinessNotificationResponse } from '../../../notifications';
89

9-
export const BusinessCreatedMock: IEventsResponse<IBusinessResponse> = {
10+
export const BusinessCreatedMock: IEventsResponse<IBusinessNotificationResponse> = {
1011
event_id: 'evt_01h84a7j1cpqtrcdqs63ph1pqe',
1112
event_type: 'business.created',
1213
occurred_at: '2023-08-18T12:34:25.964234Z',
@@ -37,6 +38,7 @@ export const BusinessCreatedMockExpectation = {
3738
customData: {
3839
customer_reference_id: 'abcd1234',
3940
},
41+
customerId: null,
4042
id: 'biz_01h84a7hr4pzhsajkm8tev89ev',
4143
importMeta: null,
4244
name: 'ChatApp Inc.',

src/__tests__/mocks/notifications/business-imported.mock.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
* Changes may be overwritten as part of auto-generation.
55
*/
66

7-
import { type IEventsResponse, type IBusinessResponse } from '../../../types';
7+
import { type IEventsResponse } from '../../../types';
8+
import { IBusinessNotificationResponse } from '../../../notifications';
89

9-
export const BusinessImportedMock: IEventsResponse<IBusinessResponse> = {
10+
export const BusinessImportedMock: IEventsResponse<IBusinessNotificationResponse> = {
1011
event_id: 'evt_01hhvz7k9kekw1wfxw8v8gbqcy',
1112
event_type: 'business.imported',
1213
occurred_at: '2023-08-18T12:34:25.964234Z',
@@ -38,6 +39,7 @@ export const BusinessImportedMockExpectation = {
3839
customData: {
3940
customer_reference_id: 'abcd1234',
4041
},
42+
customerId: null,
4143
id: 'biz_01h84a7hr4pzhsajkm8tev89ev',
4244
importMeta: {
4345
externalId: '1fc0727f-d3d5-43a0-907a-f3c002535ca0',

src/__tests__/mocks/notifications/business-updated.mock.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
* Changes may be overwritten as part of auto-generation.
55
*/
66

7-
import { type IEventsResponse, type IBusinessResponse } from '../../../types';
7+
import { type IEventsResponse } from '../../../types';
8+
import { IBusinessNotificationResponse } from '../../../notifications';
89

9-
export const BusinessUpdatedMock: IEventsResponse<IBusinessResponse> = {
10+
export const BusinessUpdatedMock: IEventsResponse<IBusinessNotificationResponse> = {
1011
event_id: 'evt_01h84b8sq18asjb0m3tvn4g0dn',
1112
event_type: 'business.updated',
1213
occurred_at: '2023-08-18T12:52:35.169192Z',
@@ -49,6 +50,7 @@ export const BusinessUpdatedMockExpectation = {
4950
customData: {
5051
customer_reference_id: 'abcd1234',
5152
},
53+
customerId: null,
5254
id: 'biz_01h84a7hr4pzhsajkm8tev89ev',
5355
importMeta: null,
5456
name: 'ChatApp Inc.',

src/__tests__/mocks/resources/addresses.mock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const UpdateAddressExpectation = {
4242

4343
export const AddressMock: IAddressResponse = {
4444
id: 'add_01gm302t81w94gyjpjpqypkzkf',
45+
customer_id: 'ctm_01grnn4zta5a1mf02jjze7y2ys',
4546
description: 'Paddle.com',
4647
first_line: '3811 Ditmars Blvd',
4748
second_line: 'Suite 671',

src/__tests__/mocks/resources/businesses.mock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const UpdateBusinessExpectation = {
2727

2828
export const BusinessMock: IBusinessResponse = {
2929
id: 'biz_01grrebrzaee2qj2fqqhmcyzaj',
30+
customer_id: 'ctm_01grnn4zta5a1mf02jjze7y2ys',
3031
name: 'Lyda',
3132
company_number: '123456789',
3233
tax_identifier: 'AB0123456789',

src/entities/address/address.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { type IAddressResponse } from '../../types';
1010

1111
export class Address {
1212
public readonly id: string;
13+
public readonly customerId: string;
1314
public readonly description: string | null;
1415
public readonly firstLine: string | null;
1516
public readonly secondLine: string | null;
@@ -25,6 +26,7 @@ export class Address {
2526

2627
constructor(address: IAddressResponse) {
2728
this.id = address.id;
29+
this.customerId = address.customer_id;
2830
this.description = address.description ? address.description : null;
2931
this.firstLine = address.first_line ? address.first_line : null;
3032
this.secondLine = address.second_line ? address.second_line : null;

src/entities/business/business.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { type IBusinessResponse } from '../../types';
1010

1111
export class Business {
1212
public readonly id: string;
13+
public readonly customerId: string;
1314
public readonly name: string;
1415
public readonly companyNumber: string | null;
1516
public readonly taxIdentifier: string | null;
@@ -22,6 +23,7 @@ export class Business {
2223

2324
constructor(business: IBusinessResponse) {
2425
this.id = business.id;
26+
this.customerId = business.customer_id;
2527
this.name = business.name;
2628
this.companyNumber = business.company_number ? business.company_number : null;
2729
this.taxIdentifier = business.tax_identifier ? business.tax_identifier : null;

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Changes may be overwritten as part of auto-generation.
55
*/
66

7-
export { Environment } from './internal';
7+
export { Environment, ApiError, type PaddleOptions } from './internal';
88
export { SDK_VERSION } from './version';
99

1010
export { Paddle } from './paddle';

src/internal/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export type { ErrorResponse, ResponsePaginated, Response, ErrorDetail, ErrorField } from './types/response';
22
export type { PaddleOptions } from './types/config';
33
export * from './api';
4+
export { ApiError } from './errors/generic';

src/internal/types/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Environment } from '../api/environment';
1+
import { type Environment } from '../api';
22

33
export interface PaddleOptions {
44
environment?: Environment;

src/notifications/entities/address/address-notification.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { type IAddressNotificationResponse } from '../../types';
99

1010
export class AddressNotification {
1111
public readonly id: string;
12+
public readonly customerId: string | null;
1213
public readonly description: string | null;
1314
public readonly firstLine: string | null;
1415
public readonly secondLine: string | null;
@@ -24,6 +25,7 @@ export class AddressNotification {
2425

2526
constructor(address: IAddressNotificationResponse) {
2627
this.id = address.id;
28+
this.customerId = address.customer_id ?? null;
2729
this.description = address.description ? address.description : null;
2830
this.firstLine = address.first_line ? address.first_line : null;
2931
this.secondLine = address.second_line ? address.second_line : null;

src/notifications/entities/business/business-notification.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { type CustomData } from '../../../entities';
1111

1212
export class BusinessNotification {
1313
public readonly id: string;
14+
public readonly customerId: string | null;
1415
public readonly name: string;
1516
public readonly companyNumber: string | null;
1617
public readonly taxIdentifier: string | null;
@@ -23,6 +24,7 @@ export class BusinessNotification {
2324

2425
constructor(business: IBusinessNotificationResponse) {
2526
this.id = business.id;
27+
this.customerId = business.customer_id ?? null;
2628
this.name = business.name;
2729
this.companyNumber = business.company_number ? business.company_number : null;
2830
this.taxIdentifier = business.tax_identifier ? business.tax_identifier : null;

src/notifications/types/address/address-notification-response.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { type ICustomData, type IImportMetaResponse } from '../../../types';
88

99
export interface IAddressNotificationResponse {
1010
id: string;
11+
customer_id?: string | null;
1112
description?: string | null;
1213
first_line?: string | null;
1314
second_line?: string | null;

src/notifications/types/business/business-notification-response.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { type ICustomData } from '../../../types';
1010

1111
export interface IBusinessNotificationResponse {
1212
id: string;
13+
customer_id?: string | null;
1314
name: string;
1415
company_number?: string | null;
1516
tax_identifier?: string | null;

src/types/address/address-response.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { type CountryCode, type Status } from '../../enums';
99

1010
export interface IAddressResponse {
1111
id: string;
12+
customer_id: string;
1213
description?: string | null;
1314
first_line?: string | null;
1415
second_line?: string | null;

src/types/business/business-response.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { type Status } from '../../enums';
99

1010
export interface IBusinessResponse {
1111
id: string;
12+
customer_id: string;
1213
name: string;
1314
company_number?: string | null;
1415
tax_identifier?: string | null;

0 commit comments

Comments
 (0)