mysendingbox 1.0.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/LICENSE.txt +22 -0
- package/README.md +315 -0
- package/lib/index.js +57 -0
- package/lib/resources/accounts.js +24 -0
- package/lib/resources/index.js +20 -0
- package/lib/resources/invoices.js +29 -0
- package/lib/resources/letters.js +44 -0
- package/lib/resources/postcards.js +40 -0
- package/lib/resources/price.js +34 -0
- package/lib/resources/resourceBase.js +107 -0
- package/lib/utils/params.js +23 -0
- package/package.json +38 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2025 Exaland.app
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
# mysendingbox-node
|
|
2
|
+
|
|
3
|
+
[downloads-image]: http://img.shields.io/npm/dm/mysendingbox.svg
|
|
4
|
+
[npm-url]: https://npmjs.org/package/mysendingbox
|
|
5
|
+
[npm-image]: https://badge.fury.io/js/mysendingbox.svg
|
|
6
|
+
|
|
7
|
+
[![NPM version][npm-image]][npm-url] [](https://gemnasium.com/github.com/exaland/mysendingbox-node)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
MySendingBox.com Node.js Client is a simple but flexible wrapper for the [MySendingBox.fr](https://www.mysendingbox.fr) API.
|
|
12
|
+
|
|
13
|
+
See full Seeuletter.com documentation [here](https://docs.mysendingbox.fr/).
|
|
14
|
+
|
|
15
|
+
For best results, be sure that you're using the latest version of the Seeuletter API and the latest version of the Node.js wrapper.
|
|
16
|
+
|
|
17
|
+
#### French
|
|
18
|
+
Un module NPM pour envoyer du courrier postal ou electronique en ligne depuis votre application Node.Js.
|
|
19
|
+
|
|
20
|
+
Seeuletter propose une API permettant d'envoyer très facilement du courrier postal ou électronique depuis votre ERP, CRM ou application web.
|
|
21
|
+
|
|
22
|
+
Pas de frais d'installation. Pas d'engagement. Vous payez ce que vous consommez.
|
|
23
|
+
|
|
24
|
+
Documentation : https://docs.mysendingbox.fr/
|
|
25
|
+
|
|
26
|
+
Bien démarrer : https://www.mysendingbox.fr/guide/bien-demarrer-avec-l-api-d-envoi-de-courrier
|
|
27
|
+
|
|
28
|
+
## Table of Contents
|
|
29
|
+
|
|
30
|
+
- [Getting Started](#getting-started)
|
|
31
|
+
- [Registration](#registration)
|
|
32
|
+
- [Installation](#installation)
|
|
33
|
+
- [Letters](#letters)
|
|
34
|
+
- [Postcards](#postcards)
|
|
35
|
+
- [Accounts](#accounts)
|
|
36
|
+
- [Invoices](#invoices)
|
|
37
|
+
- [Examples](#examples)
|
|
38
|
+
|
|
39
|
+
## Getting Started
|
|
40
|
+
|
|
41
|
+
Here's a general overview of the Seeuletter services available, click through to read more.
|
|
42
|
+
|
|
43
|
+
Please read through the official [API Documentation](https://docs.mysendingbox.fr/) to get a complete sense of what to expect from each endpoint.
|
|
44
|
+
|
|
45
|
+
### Registration
|
|
46
|
+
|
|
47
|
+
First, you will need to first create an account at [Seeuletter.com](https://www.mysendingbox.fr/signup) and obtain your Test and Live API Keys.
|
|
48
|
+
|
|
49
|
+
Once you have created an account, you can access your API Keys from the [Settings Panel](https://www.mysendingbox.fr/app/dashboard/keys).
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
### Installation
|
|
53
|
+
|
|
54
|
+
mysendingbox-node can be installed through the npm:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
$ npm install -S mysendingbox
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
To build and install from the latest source:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
$ git clone git@github.com:exaland/mysendingbox-node.git
|
|
64
|
+
$ npm install
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Letters
|
|
68
|
+
|
|
69
|
+
#### Create a new letter - Callback style
|
|
70
|
+
```javascript
|
|
71
|
+
var Seeuletter = require('seeuletter')('YOUR API KEY');
|
|
72
|
+
|
|
73
|
+
// callback pattern
|
|
74
|
+
Seeuletter.letters.create({
|
|
75
|
+
description: 'Test Letter from the Node.js Wrapper',
|
|
76
|
+
to: {
|
|
77
|
+
name: 'Erlich',
|
|
78
|
+
address_line1: '30 rue de rivoli',
|
|
79
|
+
address_line2: '',
|
|
80
|
+
address_city: 'Paris',
|
|
81
|
+
address_country: 'France',
|
|
82
|
+
address_postalcode: '75004'
|
|
83
|
+
},
|
|
84
|
+
postage_type: 'prioritaire',
|
|
85
|
+
color: 'bw',
|
|
86
|
+
source_file: '<html>Hello, {{nom}}</html>',
|
|
87
|
+
source_file_type: 'html',
|
|
88
|
+
variables: {
|
|
89
|
+
nom : 'Seeuletter'
|
|
90
|
+
}
|
|
91
|
+
}, function (err, body) {
|
|
92
|
+
if (err) console.log('err : ' , err.message);
|
|
93
|
+
console.log('body : ', body)
|
|
94
|
+
})
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### Create a new letter - Promise style
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
var Seeuletter = require('seeuletter')('YOUR API KEY');
|
|
101
|
+
|
|
102
|
+
// promise pattern
|
|
103
|
+
Seeuletter.letters.create({
|
|
104
|
+
description: 'Test Letter from the Node.js Wrapper',
|
|
105
|
+
to: {
|
|
106
|
+
name: 'Erlich',
|
|
107
|
+
address_line1: '30 rue de rivoli',
|
|
108
|
+
address_line2: '',
|
|
109
|
+
address_city: 'Paris',
|
|
110
|
+
address_country: 'France',
|
|
111
|
+
address_postalcode: '75004'
|
|
112
|
+
},
|
|
113
|
+
postage_type: 'prioritaire',
|
|
114
|
+
color: 'bw',
|
|
115
|
+
source_file: '<html>Hello, {{nom}}</html>',
|
|
116
|
+
source_file_type: 'html',
|
|
117
|
+
variables: {
|
|
118
|
+
nom : 'Seeuletter'
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
.then(function (response) {
|
|
122
|
+
console.log('response : ', response);
|
|
123
|
+
})
|
|
124
|
+
.catch(function (err) {
|
|
125
|
+
console.log('err : ', err);
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
#### Create a new electronic letter - Promise style
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
var Seeuletter = require('seeuletter')('YOUR API KEY');
|
|
133
|
+
|
|
134
|
+
// promise pattern
|
|
135
|
+
Seeuletter.letters.createElectronic({
|
|
136
|
+
description: 'Test electronic letter from the Node.js Wrapper',
|
|
137
|
+
to: {
|
|
138
|
+
email: 'erlich.dumas@example.com',
|
|
139
|
+
first_name: 'Erlich',
|
|
140
|
+
last_name: 'Dumas',
|
|
141
|
+
status: 'individual'
|
|
142
|
+
},
|
|
143
|
+
postage_type: 'lre',
|
|
144
|
+
content: 'Please review the attached documents:',
|
|
145
|
+
source_file: '<html>Hello, {{nom}}</html>',
|
|
146
|
+
source_file_type: 'html',
|
|
147
|
+
variables: {
|
|
148
|
+
nom : 'Seeuletter'
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
.then(function (response) {
|
|
152
|
+
console.log('response : ', response);
|
|
153
|
+
})
|
|
154
|
+
.catch(function (err) {
|
|
155
|
+
console.log('err : ', err);
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### List all Letters
|
|
160
|
+
|
|
161
|
+
```javascript
|
|
162
|
+
var Seeuletter = require('seeuletter')('test_12345678901234567890')
|
|
163
|
+
|
|
164
|
+
Seeuletter.letters.list()
|
|
165
|
+
.then(function (response) {
|
|
166
|
+
console.log('response : ', response);
|
|
167
|
+
})
|
|
168
|
+
.catch(function (err) {
|
|
169
|
+
console.log('err : ', err);
|
|
170
|
+
});
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
#### Retrieve a specific Letter
|
|
174
|
+
|
|
175
|
+
```javascript
|
|
176
|
+
var Seeuletter = require('seeuletter')('test_12345678901234567890')
|
|
177
|
+
|
|
178
|
+
Seeuletter.letters.retrieve('LETTER_ID')
|
|
179
|
+
.then(function (response) {
|
|
180
|
+
console.log('response : ', response);
|
|
181
|
+
})
|
|
182
|
+
.catch(function (err) {
|
|
183
|
+
console.log('err : ', err);
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Postcards
|
|
188
|
+
|
|
189
|
+
#### Create a new postcard - Promise style
|
|
190
|
+
|
|
191
|
+
```javascript
|
|
192
|
+
var Seeuletter = require('seeuletter')('YOUR API KEY');
|
|
193
|
+
|
|
194
|
+
// Create the address
|
|
195
|
+
Seeuletter.postcards.create({
|
|
196
|
+
description: 'Test Postcard from the Node.js Wrapper',
|
|
197
|
+
to: {
|
|
198
|
+
name: 'Erlich',
|
|
199
|
+
address_line1: '30 rue de rivoli',
|
|
200
|
+
address_line2: '',
|
|
201
|
+
address_city: 'Paris',
|
|
202
|
+
address_country: 'France',
|
|
203
|
+
address_postalcode: '75004'
|
|
204
|
+
},
|
|
205
|
+
// https://www.mysendingbox.fr/templates
|
|
206
|
+
source_file_front: 'YOUR TEMPLATE ID',
|
|
207
|
+
source_file_front_type: 'template_id',
|
|
208
|
+
source_file_back: 'YOUR TEMPLATE ID',
|
|
209
|
+
source_file_back_type: 'template_id',
|
|
210
|
+
|
|
211
|
+
variables: {
|
|
212
|
+
PRENOM: 'Erlich',
|
|
213
|
+
NOM: 'Bachman',
|
|
214
|
+
CODE_PROMO_BIENVENUE: 'CODE',
|
|
215
|
+
URL_COURTE_BIENVENUE: 'https://goo.gl/uqTHnD',
|
|
216
|
+
ADRESSE: '30 rue de Rivoli',
|
|
217
|
+
CODE_POSTAL : '75004',
|
|
218
|
+
VILLE : 'Paris',
|
|
219
|
+
PAYS : 'France'
|
|
220
|
+
}
|
|
221
|
+
})
|
|
222
|
+
.then(function (letter) {
|
|
223
|
+
console.log('The Seeuletter API Postcard responded : ', letter)
|
|
224
|
+
})
|
|
225
|
+
.catch(function (err) {
|
|
226
|
+
console.log('Error message : ', err.message)
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Accounts
|
|
232
|
+
|
|
233
|
+
#### Create a new account for the company
|
|
234
|
+
|
|
235
|
+
```javascript
|
|
236
|
+
var Seeuletter = require('seeuletter')('YOUR API KEY');
|
|
237
|
+
|
|
238
|
+
// Create the account
|
|
239
|
+
Seeuletter.accounts.create({
|
|
240
|
+
email: "msb.partner@example.com",
|
|
241
|
+
name: "Erlich Bachman",
|
|
242
|
+
phone: "+33104050607",
|
|
243
|
+
company_name: "MSB Partner",
|
|
244
|
+
address_line1: '30 rue de rivoli',
|
|
245
|
+
address_line2: '',
|
|
246
|
+
address_city: 'Paris',
|
|
247
|
+
address_country: 'France',
|
|
248
|
+
address_postalcode: '75004'
|
|
249
|
+
})
|
|
250
|
+
.then(function (account) {
|
|
251
|
+
console.log('The Seeuletter API Account responded : ', account)
|
|
252
|
+
})
|
|
253
|
+
.catch(function (err) {
|
|
254
|
+
console.log('Error message : ', err.message)
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
#### Update the account company email
|
|
260
|
+
|
|
261
|
+
```javascript
|
|
262
|
+
var Seeuletter = require('seeuletter')('YOUR API KEY');
|
|
263
|
+
|
|
264
|
+
// Update the account
|
|
265
|
+
Seeuletter.accounts.updateEmail("ACCOUNT COMPANY ID", "UPDATED EMAIL")
|
|
266
|
+
.then(function () {
|
|
267
|
+
console.log('The Seeuletter API Account responded with success')
|
|
268
|
+
})
|
|
269
|
+
.catch(function (err) {
|
|
270
|
+
console.log('Error message : ', err.message)
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Invoices
|
|
276
|
+
|
|
277
|
+
#### List all invoices for a company
|
|
278
|
+
|
|
279
|
+
```javascript
|
|
280
|
+
var Seeuletter = require('seeuletter')('YOUR API KEY');
|
|
281
|
+
|
|
282
|
+
// Getting the invoice list
|
|
283
|
+
Seeuletter.invoices.list({
|
|
284
|
+
// Pass optional filter here as object
|
|
285
|
+
})
|
|
286
|
+
.then(function (response) {
|
|
287
|
+
console.log('The Seeuletter API Invoices responded : ', response)
|
|
288
|
+
})
|
|
289
|
+
.catch(function (err) {
|
|
290
|
+
console.log('Error message : ', err.message)
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
#### Retrieve a specific invoice
|
|
296
|
+
|
|
297
|
+
```javascript
|
|
298
|
+
var Seeuletter = require('seeuletter')('YOUR API KEY');
|
|
299
|
+
|
|
300
|
+
// Getting the invoice list
|
|
301
|
+
Seeuletter.invoices.retrieve("INVOICE ID")
|
|
302
|
+
.then(function (invoice) {
|
|
303
|
+
console.log('The Seeuletter API Invoice responded : ', invoice)
|
|
304
|
+
})
|
|
305
|
+
.catch(function (err) {
|
|
306
|
+
console.log('Error message : ', err.message)
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
=======================
|
|
312
|
+
|
|
313
|
+
Copyright © 2025 Exaland.app
|
|
314
|
+
|
|
315
|
+
Released under the MIT License, which can be found in the repository in `LICENSE.txt`.
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var resources = require('./resources');
|
|
4
|
+
var clientVersion = require('../package.json').version;
|
|
5
|
+
|
|
6
|
+
var SEEULETTER_HOST = 'https://api.mysendingbox.fr/';
|
|
7
|
+
var SEEULETTER_USERAGENT = 'Seeuletter/v1 NodeBindings/' + clientVersion;
|
|
8
|
+
|
|
9
|
+
var Seeuletter = function (apiKey, options) {
|
|
10
|
+
|
|
11
|
+
if (!(this instanceof Seeuletter)) {
|
|
12
|
+
return new Seeuletter(apiKey, options);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
this.resourceBase = require('./resources/resourceBase');
|
|
16
|
+
|
|
17
|
+
if (apiKey && typeof apiKey === 'object') {
|
|
18
|
+
options = apiKey;
|
|
19
|
+
apiKey = null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
this.options = {
|
|
23
|
+
apiKey: apiKey,
|
|
24
|
+
host: SEEULETTER_HOST,
|
|
25
|
+
userAgent: SEEULETTER_USERAGENT,
|
|
26
|
+
headers: { 'user-agent': SEEULETTER_USERAGENT }
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
if (options && typeof options === 'object') {
|
|
30
|
+
|
|
31
|
+
if (options.hasOwnProperty('apiVersion')) {
|
|
32
|
+
this.options.headers['Seeuletter-Version'] = options.apiVersion;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
for (var key in options) {
|
|
36
|
+
this.options[key] = options[key];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this._initResources();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
(function () {
|
|
45
|
+
|
|
46
|
+
this._initResources = function () {
|
|
47
|
+
var services = Object.keys(resources);
|
|
48
|
+
|
|
49
|
+
for (var i = 0; i < services.length; i++) {
|
|
50
|
+
var service = services[i];
|
|
51
|
+
this[service] = new resources[service](this);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
}).call(Seeuletter.prototype);
|
|
56
|
+
|
|
57
|
+
module.exports = Seeuletter;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var util = require('util');
|
|
4
|
+
var ResourceBase = require('./resourceBase');
|
|
5
|
+
|
|
6
|
+
var Accounts = function (config) {
|
|
7
|
+
ResourceBase.call(this, 'accounts', { ...config, useBody: true });
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
util.inherits(Accounts, ResourceBase);
|
|
11
|
+
|
|
12
|
+
(function () {
|
|
13
|
+
|
|
14
|
+
this.create = function (params, callback) {
|
|
15
|
+
return this._transmit('POST', null, null, params, callback);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
this.updateEmail = function (id, email, callback) {
|
|
19
|
+
return this._transmit('PUT', id, null, { email: email }, callback);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}).call(Accounts.prototype);
|
|
23
|
+
|
|
24
|
+
module.exports = Accounts;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var files = fs.readdirSync(__dirname);
|
|
5
|
+
var resources = {};
|
|
6
|
+
|
|
7
|
+
for (var i = 0; i < files.length; i++) {
|
|
8
|
+
var resource = files[i];
|
|
9
|
+
|
|
10
|
+
if (resource === 'index.js' ||
|
|
11
|
+
resource === 'resourceBase.js' ||
|
|
12
|
+
resource.indexOf('.js') < 0) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
resource = resource.replace('.js', '');
|
|
17
|
+
resources[resource] = require('./' + resource);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = resources;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var util = require('util');
|
|
4
|
+
var ResourceBase = require('./resourceBase');
|
|
5
|
+
|
|
6
|
+
var Invoices = function (config) {
|
|
7
|
+
ResourceBase.call(this, 'invoices', config);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
util.inherits(Invoices, ResourceBase);
|
|
11
|
+
|
|
12
|
+
(function () {
|
|
13
|
+
|
|
14
|
+
this.list = function (options, callback) {
|
|
15
|
+
if (typeof options === 'function') {
|
|
16
|
+
callback = options;
|
|
17
|
+
options = {};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return this._transmit('GET', null, options, null, callback);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
this.retrieve = function (id, callback) {
|
|
24
|
+
return this._transmit('GET', id, null, null, callback);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}).call(Invoices.prototype);
|
|
28
|
+
|
|
29
|
+
module.exports = Invoices;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var util = require('util');
|
|
4
|
+
var ResourceBase = require('./resourceBase');
|
|
5
|
+
|
|
6
|
+
const { processCreateResourceParams } = require('../utils/params');
|
|
7
|
+
|
|
8
|
+
var Letters = function (config) {
|
|
9
|
+
ResourceBase.call(this, 'letters', config);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
util.inherits(Letters, ResourceBase);
|
|
13
|
+
|
|
14
|
+
(function () {
|
|
15
|
+
|
|
16
|
+
this.list = function (options, callback) {
|
|
17
|
+
|
|
18
|
+
if (typeof options === 'function') {
|
|
19
|
+
callback = options;
|
|
20
|
+
options = {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return this._transmit('GET', null, options, null, callback);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
this.retrieve = function (id, callback) {
|
|
27
|
+
return this._transmit('GET', id, null, null, callback);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
this.delete = function (id, callback) {
|
|
31
|
+
return this._transmit('DELETE', id, null, null, callback);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
this.create = function (params, callback) {
|
|
35
|
+
return this._transmit('POST', null, null, processCreateResourceParams(params), callback);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
this.createElectronic = function (params, callback) {
|
|
39
|
+
return this._transmit('POST', 'electronic', null, processCreateResourceParams(params), callback);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
}).call(Letters.prototype);
|
|
43
|
+
|
|
44
|
+
module.exports = Letters;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var util = require('util');
|
|
4
|
+
var ResourceBase = require('./resourceBase');
|
|
5
|
+
|
|
6
|
+
const { processCreateResourceParams } = require('../utils/params');
|
|
7
|
+
|
|
8
|
+
var Postcards = function (config) {
|
|
9
|
+
ResourceBase.call(this, 'postcards', config);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
util.inherits(Postcards, ResourceBase);
|
|
13
|
+
|
|
14
|
+
(function () {
|
|
15
|
+
|
|
16
|
+
this.list = function (options, callback) {
|
|
17
|
+
|
|
18
|
+
if (typeof options === 'function') {
|
|
19
|
+
callback = options;
|
|
20
|
+
options = {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return this._transmit('GET', null, options, null, callback);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
this.retrieve = function (id, callback) {
|
|
27
|
+
return this._transmit('GET', id, null, null, callback);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
this.delete = function (id, callback) {
|
|
31
|
+
return this._transmit('DELETE', id, null, null, callback);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
this.create = function (params, callback) {
|
|
35
|
+
return this._transmit('POST', null, null, processCreateResourceParams(params), callback);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
}).call(Postcards.prototype);
|
|
39
|
+
|
|
40
|
+
module.exports = Postcards;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var util = require('util');
|
|
4
|
+
var ResourceBase = require('./resourceBase');
|
|
5
|
+
|
|
6
|
+
const { processCreateResourceParams } = require('../utils/params');
|
|
7
|
+
|
|
8
|
+
var LettersPrice = function (config) {
|
|
9
|
+
ResourceBase.call(this, 'letters/price', config);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
util.inherits(LettersPrice, ResourceBase);
|
|
13
|
+
|
|
14
|
+
(function () {
|
|
15
|
+
|
|
16
|
+
this.list = function (options, callback) {
|
|
17
|
+
|
|
18
|
+
if (typeof options === 'function') {
|
|
19
|
+
callback = options;
|
|
20
|
+
options = {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return this._transmit('GET', null, options, null, callback);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
this.getPrice = function (params, callback) {
|
|
28
|
+
return this._transmit('POST', null, null, processCreateResourceParams(params), callback);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
}).call(LettersPrice.prototype);
|
|
33
|
+
|
|
34
|
+
module.exports = LettersPrice;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var stream = require('stream')
|
|
4
|
+
var request = require('request')
|
|
5
|
+
var bluebird = require('bluebird')
|
|
6
|
+
|
|
7
|
+
var ResourceBase = function (endpoint, config) {
|
|
8
|
+
this.uri = config.options.host + endpoint
|
|
9
|
+
this.config = config.options
|
|
10
|
+
this.useBody = config.useBody || false
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
(function () {
|
|
14
|
+
|
|
15
|
+
this._transmit = function (method, uri, qs, form, headers, callback) {
|
|
16
|
+
|
|
17
|
+
if (typeof headers === 'function') {
|
|
18
|
+
callback = headers
|
|
19
|
+
headers = {}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
headers = headers || {}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
for (var headerKey in headers) {
|
|
26
|
+
this.config.headers[headerKey] = headers[headerKey]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var opts = {
|
|
30
|
+
url: this.uri + (uri ? '/' + uri : ''),
|
|
31
|
+
method: method,
|
|
32
|
+
auth: {user: this.config.apiKey, password: ''},
|
|
33
|
+
headers: this.config.headers,
|
|
34
|
+
json: true
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var isMultiPartForm = false
|
|
38
|
+
|
|
39
|
+
for (var key in form) {
|
|
40
|
+
if (form[key] === true || form[key] === false) {
|
|
41
|
+
form[key] = form[key].toString()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
for (var param in form) {
|
|
46
|
+
var val = form[param]
|
|
47
|
+
|
|
48
|
+
if (val instanceof stream.Stream) {
|
|
49
|
+
isMultiPartForm = true
|
|
50
|
+
break
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (val !== undefined && val !== null && val.hasOwnProperty('value')) {
|
|
54
|
+
isMultiPartForm = true
|
|
55
|
+
break
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (qs) {
|
|
60
|
+
opts.qs = qs
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (form) {
|
|
64
|
+
if (this.useBody) {
|
|
65
|
+
opts.body = form
|
|
66
|
+
} else if (isMultiPartForm) {
|
|
67
|
+
opts.formData = form
|
|
68
|
+
} else {
|
|
69
|
+
opts.form = form
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return new bluebird(function (resolve, reject) {
|
|
74
|
+
request(opts, function (err, resp, body) {
|
|
75
|
+
|
|
76
|
+
if (err) {
|
|
77
|
+
return reject(err)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (body && body.error) {
|
|
81
|
+
var error = new Error(body.error.message)
|
|
82
|
+
error.status_code = body.error.status_code || resp.statusCode
|
|
83
|
+
error._response = resp
|
|
84
|
+
return reject(error)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (resp && resp.statusCode >= 500) {
|
|
88
|
+
var error = new Error(resp.statusMessage)
|
|
89
|
+
error.status_code = resp.statusCode
|
|
90
|
+
error._response = resp
|
|
91
|
+
return reject(error)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
Object.defineProperty(body, '_response', {
|
|
95
|
+
enumerable: false,
|
|
96
|
+
writable: false,
|
|
97
|
+
value: resp
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
return resolve(body)
|
|
101
|
+
})
|
|
102
|
+
}).nodeify(callback)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
}).call(ResourceBase.prototype)
|
|
106
|
+
|
|
107
|
+
module.exports = ResourceBase
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const flatten = require('flat');
|
|
2
|
+
|
|
3
|
+
function processCreateResourceParams(params) {
|
|
4
|
+
const files = {};
|
|
5
|
+
|
|
6
|
+
Object.keys(params)
|
|
7
|
+
.filter(key => key.startsWith('source_file') && !key.endsWith('_type'))
|
|
8
|
+
.forEach(key => {
|
|
9
|
+
files[key] = Buffer.isBuffer(params[key])
|
|
10
|
+
? {
|
|
11
|
+
value: params[key],
|
|
12
|
+
options: { filename: `${key}.pdf` }
|
|
13
|
+
}
|
|
14
|
+
: params[key];
|
|
15
|
+
delete params[key];
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return { ...flatten(params), ...files };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = {
|
|
22
|
+
processCreateResourceParams,
|
|
23
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mysendingbox",
|
|
3
|
+
"description": "Mysendingbox API wrapper",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"Mysendingbox",
|
|
6
|
+
"Mysendingbox-node",
|
|
7
|
+
"rest",
|
|
8
|
+
"exaland",
|
|
9
|
+
"api",
|
|
10
|
+
"wrapper",
|
|
11
|
+
"Mysendingbox.com",
|
|
12
|
+
"printing"
|
|
13
|
+
],
|
|
14
|
+
"version": "1.0.5",
|
|
15
|
+
"homepage": "https://github.com/exaland/mysendingbox-node",
|
|
16
|
+
"author": "Exaland Concept For -> Mysendingbox <hello@mysendingbox.fr> (https://www.mysendingbox.fr/)",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"bluebird": "^3.5.5",
|
|
19
|
+
"flat": "^4.1.0",
|
|
20
|
+
"request": "^2.88.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"moment": "^2.24.0"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/exaland/mysendingbox-node.git"
|
|
28
|
+
},
|
|
29
|
+
"bugs:": "https://github.com/exaland/mysendingbox-node/issues",
|
|
30
|
+
"main": "./lib/index",
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">= 0.10.0"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"lib",
|
|
36
|
+
"LICENSE.txt"
|
|
37
|
+
]
|
|
38
|
+
}
|