@paddle/paddle-node-sdk 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -28
- package/dist/entities/transaction/index.d.ts +1 -0
- package/dist/entities/transaction/index.js +1 -0
- package/dist/entities/transaction/transaction-invoice-pdf.d.ts +6 -0
- package/dist/entities/transaction/transaction-invoice-pdf.js +14 -0
- package/dist/internal/api/client.js +19 -3
- package/dist/internal/base/logger.d.ts +10 -0
- package/dist/internal/base/logger.js +21 -0
- package/dist/resources/transactions/index.d.ts +3 -2
- package/dist/resources/transactions/index.js +11 -0
- package/dist/types/transaction/index.d.ts +1 -0
- package/dist/types/transaction/index.js +1 -0
- package/dist/types/transaction/transaction-invoice-pdf.d.ts +3 -0
- package/dist/types/transaction/transaction-invoice-pdf.js +2 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -12
package/README.md
CHANGED
|
@@ -11,11 +11,11 @@ For working with Paddle in your frontend, use [Paddle.js](https://developer.padd
|
|
|
11
11
|
|
|
12
12
|
## Before you begin
|
|
13
13
|
|
|
14
|
-
This SDK is in early access, which means that we're actively developing it based on feedback from our developer community.
|
|
14
|
+
This SDK is in early access, which means that we're actively developing it based on feedback from our developer community.
|
|
15
15
|
|
|
16
16
|
If you've used this SDK, we'd love to hear how you found it! Email us at [team-dx@paddle.com](mailto:team-dx@paddle.com) with any thoughts.
|
|
17
17
|
|
|
18
|
-
While in early access, we may introduce breaking changes. Where we can, we'll tag breaking changes and communicate ahead of time.
|
|
18
|
+
While in early access, we may introduce breaking changes. Where we can, we'll tag breaking changes and communicate ahead of time. Please pin the version of the SDK in your `package.json` to avoid downloading newer versions with potential breaking changes.
|
|
19
19
|
|
|
20
20
|
## Installation
|
|
21
21
|
|
|
@@ -51,8 +51,12 @@ const paddle = new Paddle('API_KEY')
|
|
|
51
51
|
...
|
|
52
52
|
|
|
53
53
|
async function getProducts() {
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
try {
|
|
55
|
+
const productCollection = await paddle.products.list()
|
|
56
|
+
return productCollection.next()
|
|
57
|
+
} catch (e) {
|
|
58
|
+
// Handle Network/API errors
|
|
59
|
+
}
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
const products = await getProducts()
|
|
@@ -87,19 +91,23 @@ const paddle = new Paddle('API_KEY')
|
|
|
87
91
|
|
|
88
92
|
async function getProducts() {
|
|
89
93
|
// creates an iterator instance
|
|
90
|
-
const
|
|
91
|
-
return
|
|
94
|
+
const productCollection = await paddle.products.list();
|
|
95
|
+
return productCollection;
|
|
92
96
|
}
|
|
93
97
|
|
|
94
|
-
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
try {
|
|
99
|
+
// Creates an iterator to loop through paginated data.
|
|
100
|
+
// At this point, It does not hold any data.
|
|
101
|
+
const productCollection = await getProducts();
|
|
102
|
+
|
|
103
|
+
// Call `next()` to retrieve first page of the dataset
|
|
104
|
+
const firstPage = await productCollection.next()
|
|
105
|
+
|
|
106
|
+
// Calling `next()` again will retrieve subsequent pages.
|
|
107
|
+
const secondPage = await productCollection.next()
|
|
108
|
+
} catch (e) {
|
|
109
|
+
// Handle Network/API errors
|
|
110
|
+
}
|
|
103
111
|
```
|
|
104
112
|
|
|
105
113
|
### Create an entity
|
|
@@ -114,10 +122,14 @@ const paddle = new Paddle('API_KEY')
|
|
|
114
122
|
...
|
|
115
123
|
|
|
116
124
|
async function createProduct(requestBody: CreateProductRequestBody) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
125
|
+
try {
|
|
126
|
+
// Pass the request body with the attributes required to create
|
|
127
|
+
const product = await paddle.products.create(requestBody)
|
|
128
|
+
// Returns a product entity
|
|
129
|
+
return product
|
|
130
|
+
} catch (e) {
|
|
131
|
+
// Handle Network/API errors
|
|
132
|
+
}
|
|
121
133
|
}
|
|
122
134
|
|
|
123
135
|
const product = await createProduct({... object with required attributes})
|
|
@@ -135,10 +147,14 @@ const paddle = new Paddle('API_KEY')
|
|
|
135
147
|
...
|
|
136
148
|
|
|
137
149
|
async function updateProduct(productId: string, requestBody: UpdateProductRequestBody) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
150
|
+
try {
|
|
151
|
+
// Pass the product id and request body with the attributes to update
|
|
152
|
+
const product = await paddle.products.update(productId, requestBody)
|
|
153
|
+
// Returns an updated product entity
|
|
154
|
+
return product
|
|
155
|
+
} catch (e) {
|
|
156
|
+
// Handle Network/API errors
|
|
157
|
+
}
|
|
142
158
|
}
|
|
143
159
|
|
|
144
160
|
const product = await updateProduct('id', {... object with attributes to be updated})
|
|
@@ -162,10 +178,14 @@ const paddle = new Paddle('API_KEY')
|
|
|
162
178
|
...
|
|
163
179
|
|
|
164
180
|
async function getProduct(productId: string) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
181
|
+
try {
|
|
182
|
+
// Pass the product id get
|
|
183
|
+
const product = await paddle.products.get(productId)
|
|
184
|
+
// Returns an updated product entity
|
|
185
|
+
return product
|
|
186
|
+
} catch (e) {
|
|
187
|
+
// Handle Network/API errors
|
|
188
|
+
}
|
|
169
189
|
}
|
|
170
190
|
|
|
171
191
|
const product = await getProduct('id')
|
|
@@ -229,7 +249,7 @@ This table shows which operations are available as of the latest release.
|
|
|
229
249
|
| Get a transaction | ✅ |
|
|
230
250
|
| Update a transaction | ✅ |
|
|
231
251
|
| Preview a transaction | ❌ |
|
|
232
|
-
| Get a PDF invoice for a transaction |
|
|
252
|
+
| Get a PDF invoice for a transaction | ✅ |
|
|
233
253
|
| **Subscriptions** | **Full** |
|
|
234
254
|
| List subscriptions | ✅ |
|
|
235
255
|
| Get a subscription | ✅ |
|
|
@@ -26,3 +26,4 @@ __exportStar(require("./adjustment-totals"), exports);
|
|
|
26
26
|
__exportStar(require("./transaction-includes"), exports);
|
|
27
27
|
__exportStar(require("./transaction"), exports);
|
|
28
28
|
__exportStar(require("./transaction-collection"), exports);
|
|
29
|
+
__exportStar(require("./transaction-invoice-pdf"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionInvoicePDF = void 0;
|
|
4
|
+
class TransactionInvoicePDF {
|
|
5
|
+
constructor(transaction) {
|
|
6
|
+
this.url = transaction.url;
|
|
7
|
+
}
|
|
8
|
+
toJson() {
|
|
9
|
+
return {
|
|
10
|
+
url: this.url,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.TransactionInvoicePDF = TransactionInvoicePDF;
|
|
@@ -17,6 +17,8 @@ const constants_1 = require("./constants");
|
|
|
17
17
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
18
18
|
const version_1 = require("../../version");
|
|
19
19
|
const environment_1 = require("./environment");
|
|
20
|
+
const crypto_1 = require("crypto");
|
|
21
|
+
const logger_1 = require("../base/logger");
|
|
20
22
|
class Client {
|
|
21
23
|
constructor(apiKey, options) {
|
|
22
24
|
this.apiKey = apiKey;
|
|
@@ -28,9 +30,11 @@ class Client {
|
|
|
28
30
|
return urlBasedOnEnv || '';
|
|
29
31
|
}
|
|
30
32
|
getHeaders() {
|
|
33
|
+
const uuid = (0, crypto_1.randomUUID)();
|
|
31
34
|
return {
|
|
32
35
|
Authorization: `bearer ${this.apiKey}`,
|
|
33
36
|
'user-agent': `PaddleSDK/node ${version_1.SDK_VERSION}`,
|
|
37
|
+
'X-Transaction-ID': uuid,
|
|
34
38
|
};
|
|
35
39
|
}
|
|
36
40
|
get(url, queryParams) {
|
|
@@ -39,29 +43,41 @@ class Client {
|
|
|
39
43
|
if (!finalUrl.includes('?') && queryParams) {
|
|
40
44
|
finalUrl += queryParams.toQueryString();
|
|
41
45
|
}
|
|
46
|
+
const logUrl = url.split('?')[0];
|
|
47
|
+
const headers = this.getHeaders();
|
|
48
|
+
logger_1.Logger.logRequest('GET', logUrl, headers);
|
|
42
49
|
const rawResponse = yield (0, node_fetch_1.default)(finalUrl, {
|
|
43
|
-
headers
|
|
50
|
+
headers,
|
|
44
51
|
});
|
|
52
|
+
logger_1.Logger.logResponse('GET', logUrl, headers, rawResponse);
|
|
45
53
|
return rawResponse.json();
|
|
46
54
|
});
|
|
47
55
|
}
|
|
48
56
|
post(url, requestBody) {
|
|
49
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const logUrl = url.split('?')[0];
|
|
59
|
+
const headers = this.getHeaders();
|
|
60
|
+
logger_1.Logger.logRequest('POST', logUrl, headers);
|
|
50
61
|
const rawResponse = yield (0, node_fetch_1.default)(`${this.baseUrl}${url}`, {
|
|
51
62
|
method: 'POST',
|
|
52
63
|
body: JSON.stringify(requestBody),
|
|
53
|
-
headers
|
|
64
|
+
headers,
|
|
54
65
|
});
|
|
66
|
+
logger_1.Logger.logResponse('POST', logUrl, headers, rawResponse);
|
|
55
67
|
return rawResponse.json();
|
|
56
68
|
});
|
|
57
69
|
}
|
|
58
70
|
patch(url, requestBody) {
|
|
59
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const logUrl = url.split('?')[0];
|
|
73
|
+
const headers = this.getHeaders();
|
|
74
|
+
logger_1.Logger.logRequest('PATCH', logUrl, headers);
|
|
60
75
|
const rawResponse = yield (0, node_fetch_1.default)(`${this.baseUrl}${url}`, {
|
|
61
76
|
method: 'PATCH',
|
|
62
77
|
body: JSON.stringify(requestBody),
|
|
63
|
-
headers
|
|
78
|
+
headers,
|
|
64
79
|
});
|
|
80
|
+
logger_1.Logger.logResponse('PATCH', logUrl, headers, rawResponse);
|
|
65
81
|
return rawResponse.json();
|
|
66
82
|
});
|
|
67
83
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Response } from 'node-fetch';
|
|
2
|
+
type LogInputProps = Array<string | undefined | null>;
|
|
3
|
+
export declare class Logger {
|
|
4
|
+
static log(...args: LogInputProps): void;
|
|
5
|
+
static warn(...args: LogInputProps): void;
|
|
6
|
+
static error(...args: LogInputProps): void;
|
|
7
|
+
static logRequest(method: string, url: string | undefined, headers: Record<string, string>): void;
|
|
8
|
+
static logResponse(method: string, url: string | undefined, headers: Record<string, string>, promise: Response): void;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
class Logger {
|
|
5
|
+
static log(...args) {
|
|
6
|
+
console.log('[Paddle] [LOG]', ...args);
|
|
7
|
+
}
|
|
8
|
+
static warn(...args) {
|
|
9
|
+
console.warn('[Paddle] [WARN]', ...args);
|
|
10
|
+
}
|
|
11
|
+
static error(...args) {
|
|
12
|
+
console.error('[Paddle] [ERROR]', ...args);
|
|
13
|
+
}
|
|
14
|
+
static logRequest(method, url, headers) {
|
|
15
|
+
Logger.log(method, url, 'Transaction ID:', headers['X-Transaction-ID']);
|
|
16
|
+
}
|
|
17
|
+
static logResponse(method, url, headers, promise) {
|
|
18
|
+
Logger.log(method, url, promise.status.toString(), 'Transaction ID:', headers['X-Transaction-ID'], 'Request ID:', promise.headers.get('Request-Id'));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.Logger = Logger;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Transaction, TransactionCollection, TransactionIncludes } from '../../entities';
|
|
1
|
+
import { Transaction, TransactionCollection, TransactionIncludes, TransactionInvoicePDF } from '../../entities';
|
|
2
2
|
import { BaseResource } from '../../internal/base';
|
|
3
|
-
import { type
|
|
3
|
+
import { type CreateTransactionQueryParameters, type CreateTransactionRequestBody, type GetTransactionQueryParameters, type ListTransactionQueryParameters, type UpdateTransactionRequestBody } from './operations';
|
|
4
4
|
export * from './operations';
|
|
5
5
|
export declare class TransactionsResource extends BaseResource {
|
|
6
6
|
list(queryParams?: ListTransactionQueryParameters): Promise<TransactionCollection>;
|
|
7
7
|
create(createTransactionParameters: CreateTransactionRequestBody, queryParams?: CreateTransactionQueryParameters): Promise<TransactionIncludes>;
|
|
8
8
|
update(transactionId: string, updateTransaction: UpdateTransactionRequestBody): Promise<Transaction>;
|
|
9
9
|
get(transactionId: string, queryParams?: GetTransactionQueryParameters): Promise<TransactionIncludes>;
|
|
10
|
+
getInvoicePDF(transactionId: string): Promise<TransactionInvoicePDF>;
|
|
10
11
|
}
|
|
@@ -31,6 +31,7 @@ const TransactionPaths = {
|
|
|
31
31
|
create: '/transactions',
|
|
32
32
|
get: '/transactions/{transaction_id}',
|
|
33
33
|
update: '/transactions/{transaction_id}',
|
|
34
|
+
getInvoicePDF: '/transactions/{transaction_id}/invoice',
|
|
34
35
|
};
|
|
35
36
|
__exportStar(require("./operations"), exports);
|
|
36
37
|
class TransactionsResource extends base_1.BaseResource {
|
|
@@ -69,5 +70,15 @@ class TransactionsResource extends base_1.BaseResource {
|
|
|
69
70
|
return new entities_1.TransactionIncludes(data);
|
|
70
71
|
});
|
|
71
72
|
}
|
|
73
|
+
getInvoicePDF(transactionId) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const urlWithPathParams = new base_1.PathParameters(TransactionPaths.getInvoicePDF, {
|
|
76
|
+
transaction_id: transactionId,
|
|
77
|
+
}).deriveUrl();
|
|
78
|
+
const response = yield this.client.get(urlWithPathParams);
|
|
79
|
+
const data = this.handleResponse(response);
|
|
80
|
+
return new entities_1.TransactionInvoicePDF(data);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
72
83
|
}
|
|
73
84
|
exports.TransactionsResource = TransactionsResource;
|
|
@@ -24,3 +24,4 @@ __exportStar(require("./transaction-adjustment"), exports);
|
|
|
24
24
|
__exportStar(require("./adjustment-totals-breakdown"), exports);
|
|
25
25
|
__exportStar(require("./adjustment-totals"), exports);
|
|
26
26
|
__exportStar(require("./transaction"), exports);
|
|
27
|
+
__exportStar(require("./transaction-invoice-pdf"), exports);
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.1.
|
|
1
|
+
export declare const SDK_VERSION = "0.1.5";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paddle/paddle-node-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "A NodeJS SDK for Paddle Billing API",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -18,25 +18,17 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
|
-
"repository": {
|
|
22
|
-
"type": "git",
|
|
23
|
-
"url": "git+https://github.com/PaddleHQ/paddle-node-sdk.git"
|
|
24
|
-
},
|
|
25
21
|
"keywords": [
|
|
26
22
|
"SDK"
|
|
27
23
|
],
|
|
28
|
-
"author": "
|
|
24
|
+
"author": "paddle.com",
|
|
29
25
|
"license": "Apache-2.0",
|
|
30
|
-
"
|
|
31
|
-
"url": "https://github.com/PaddleHQ/paddle-node-sdk/issues"
|
|
32
|
-
},
|
|
33
|
-
"homepage": "https://github.com/PaddleHQ/paddle-node-sdk#readme",
|
|
26
|
+
"homepage": "https://developer.paddle.com/api-reference/overview",
|
|
34
27
|
"devDependencies": {
|
|
35
28
|
"@babel/core": "^7.23.0",
|
|
36
29
|
"@babel/preset-env": "^7.22.20",
|
|
37
30
|
"@babel/preset-typescript": "^7.23.0",
|
|
38
31
|
"@types/jest": "^29.5.6",
|
|
39
|
-
"@types/lodash": "^4.14.198",
|
|
40
32
|
"@types/node": "^20.6.0",
|
|
41
33
|
"@types/node-fetch": "^2.6.6",
|
|
42
34
|
"@typescript-eslint/eslint-plugin": "^6.4.0",
|
|
@@ -52,7 +44,6 @@
|
|
|
52
44
|
"typescript": "^5.2.2"
|
|
53
45
|
},
|
|
54
46
|
"dependencies": {
|
|
55
|
-
"lodash": "^4.17.21",
|
|
56
47
|
"node-fetch": "^2.7.0"
|
|
57
48
|
}
|
|
58
49
|
}
|