merchi_sdk_ts 1.43.0 → 1.43.2
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/dist/entities/file.js +4 -0
- package/dist/entities/quote.js +4 -0
- package/dist/request.js +11 -3
- package/dist/request.test.js +21 -2
- package/package.json +1 -1
- package/src/entities/file.ts +4 -0
- package/src/entities/quote.ts +4 -0
- package/src/request.test.ts +23 -2
- package/src/request.ts +12 -3
package/dist/entities/file.js
CHANGED
|
@@ -213,6 +213,10 @@ var MerchiFile = /** @class */ (function (_super) {
|
|
|
213
213
|
MerchiFile.property({ arrayType: 'ProductionComment' }),
|
|
214
214
|
__metadata("design:type", Array)
|
|
215
215
|
], MerchiFile.prototype, "productionComments", void 0);
|
|
216
|
+
__decorate([
|
|
217
|
+
MerchiFile.property({ arrayType: 'Quote' }),
|
|
218
|
+
__metadata("design:type", Array)
|
|
219
|
+
], MerchiFile.prototype, "quotes", void 0);
|
|
216
220
|
return MerchiFile;
|
|
217
221
|
}(Entity));
|
|
218
222
|
export { MerchiFile };
|
package/dist/entities/quote.js
CHANGED
|
@@ -155,6 +155,10 @@ var Quote = /** @class */ (function (_super) {
|
|
|
155
155
|
Quote.property({ arrayType: 'QuoteItem' }),
|
|
156
156
|
__metadata("design:type", Array)
|
|
157
157
|
], Quote.prototype, "quoteItems", void 0);
|
|
158
|
+
__decorate([
|
|
159
|
+
Quote.property({ arrayType: 'MerchiFile' }),
|
|
160
|
+
__metadata("design:type", Array)
|
|
161
|
+
], Quote.prototype, "files", void 0);
|
|
158
162
|
__decorate([
|
|
159
163
|
Quote.property({ arrayType: 'Assignment' }),
|
|
160
164
|
__metadata("design:type", Array)
|
package/dist/request.js
CHANGED
|
@@ -26,17 +26,25 @@ var __values = (this && this.__values) || function(o) {
|
|
|
26
26
|
};
|
|
27
27
|
// eslint-disable-next-line no-unused-vars
|
|
28
28
|
import { getErrorFromCode } from './constants/errors.js';
|
|
29
|
+
function resolveApiErrorMessage(err) {
|
|
30
|
+
if (err && typeof err === 'object' && typeof err.message === 'string' && err.message) {
|
|
31
|
+
return err.message;
|
|
32
|
+
}
|
|
33
|
+
if (typeof err === 'string' && err) {
|
|
34
|
+
return err;
|
|
35
|
+
}
|
|
36
|
+
return 'No error message';
|
|
37
|
+
}
|
|
29
38
|
var ApiError = /** @class */ (function (_super) {
|
|
30
39
|
__extends(ApiError, _super);
|
|
31
40
|
function ApiError(err) {
|
|
32
41
|
var _this = this;
|
|
33
|
-
var message =
|
|
42
|
+
var message = resolveApiErrorMessage(err);
|
|
34
43
|
/* istanbul ignore next */
|
|
35
44
|
_this = _super.call(this, message) || this;
|
|
36
45
|
_this.statusCode = err.statusCode;
|
|
37
46
|
_this.errorCode = getErrorFromCode(err.errorCode);
|
|
38
|
-
_this.errorMessage =
|
|
39
|
-
err.message : 'No error message';
|
|
47
|
+
_this.errorMessage = message;
|
|
40
48
|
_this.details = err.details;
|
|
41
49
|
_this.name = 'ApiError';
|
|
42
50
|
_this.original = err;
|
package/dist/request.test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { apiFetch } from './request.js';
|
|
1
|
+
import { apiFetch, ApiError } from './request.js';
|
|
2
2
|
import { ErrorType } from './constants/errors.js';
|
|
3
3
|
import { setup, mockFetch } from './test_util.js';
|
|
4
4
|
setup();
|
|
@@ -28,11 +28,30 @@ test('will get default errorCode', function () {
|
|
|
28
28
|
mockFetch(false, { 'statusCode': 404,
|
|
29
29
|
'errorCode': -1,
|
|
30
30
|
'message': 'just a test' }, 404);
|
|
31
|
-
apiFetch('https://api.merchi.co/', '/test').catch(function (e) {
|
|
31
|
+
return apiFetch('https://api.merchi.co/', '/test').catch(function (e) {
|
|
32
32
|
expect(e.statusCode).toBe(404);
|
|
33
33
|
expect(e.name).toBe('ApiError');
|
|
34
34
|
expect(e.errorCode).toBe(ErrorType.UNKNOWN_ERROR);
|
|
35
35
|
expect(e.errorMessage).toBe('just a test');
|
|
36
|
+
expect(e.message).toBe('just a test');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
test('ApiError keeps plain string messages', function () {
|
|
40
|
+
var e = new ApiError('empty response');
|
|
41
|
+
expect(e.message).toBe('empty response');
|
|
42
|
+
expect(e.errorMessage).toBe('empty response');
|
|
43
|
+
});
|
|
44
|
+
test('ApiError.message is the human-readable text, not serialized JSON', function () {
|
|
45
|
+
mockFetch(false, {
|
|
46
|
+
'statusCode': 403,
|
|
47
|
+
'errorCode': ErrorType.UNKNOWN_ERROR,
|
|
48
|
+
'message': 'cannot set referrer',
|
|
49
|
+
}, 403);
|
|
50
|
+
return apiFetch('https://api.merchi.co/', '/test').catch(function (e) {
|
|
51
|
+
expect(e.message).toBe('cannot set referrer');
|
|
52
|
+
expect(e.errorMessage).toBe('cannot set referrer');
|
|
53
|
+
expect(e.message).not.toContain('errorCode');
|
|
54
|
+
expect(e.message).not.toContain('statusCode');
|
|
36
55
|
});
|
|
37
56
|
});
|
|
38
57
|
test('ApiError exposes details when the server supplies them', function () {
|
package/package.json
CHANGED
package/src/entities/file.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { JobNote } from './job_note.js';
|
|
|
10
10
|
import { Notification } from './notification.js';
|
|
11
11
|
import { Product } from './product.js';
|
|
12
12
|
import { ProductionComment } from './production_comment.js';
|
|
13
|
+
import { Quote } from './quote.js';
|
|
13
14
|
import { Theme } from './theme.js';
|
|
14
15
|
import { User } from './user.js';
|
|
15
16
|
import { Variation } from './variation.js';
|
|
@@ -152,6 +153,9 @@ export class MerchiFile extends Entity {
|
|
|
152
153
|
@MerchiFile.property({arrayType: 'ProductionComment'})
|
|
153
154
|
public productionComments?: ProductionComment[];
|
|
154
155
|
|
|
156
|
+
@MerchiFile.property({arrayType: 'Quote'})
|
|
157
|
+
public quotes?: Quote[];
|
|
158
|
+
|
|
155
159
|
public isImage = () => {
|
|
156
160
|
if (this.mimetype === undefined) {
|
|
157
161
|
const err = 'mimetype is undefined, did you forget to embed it?';
|
package/src/entities/quote.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Assignment } from './assignment.js';
|
|
|
2
2
|
import { QuoteItem } from './quote_item.js';
|
|
3
3
|
import { Shipment } from './shipment.js';
|
|
4
4
|
import { Invoice } from './invoice.js';
|
|
5
|
+
import { MerchiFile } from './file.js';
|
|
5
6
|
import { Entity } from '../entity.js';
|
|
6
7
|
import { kahanSum } from '../util/float.js';
|
|
7
8
|
|
|
@@ -32,6 +33,9 @@ export class Quote extends Entity {
|
|
|
32
33
|
@Quote.property({arrayType: 'QuoteItem'})
|
|
33
34
|
public quoteItems?: QuoteItem[];
|
|
34
35
|
|
|
36
|
+
@Quote.property({arrayType: 'MerchiFile'})
|
|
37
|
+
public files?: MerchiFile[];
|
|
38
|
+
|
|
35
39
|
@Quote.property({arrayType: 'Assignment'})
|
|
36
40
|
public assignments?: Assignment[];
|
|
37
41
|
|
package/src/request.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { apiFetch } from './request.js';
|
|
1
|
+
import { apiFetch, ApiError } from './request.js';
|
|
2
2
|
import { ErrorType } from './constants/errors.js';
|
|
3
3
|
import { setup, mockFetch } from './test_util.js';
|
|
4
4
|
|
|
@@ -34,11 +34,32 @@ test('will get default errorCode', () => {
|
|
|
34
34
|
{'statusCode': 404,
|
|
35
35
|
'errorCode': -1,
|
|
36
36
|
'message': 'just a test'}, 404);
|
|
37
|
-
apiFetch('https://api.merchi.co/', '/test').catch(e => {
|
|
37
|
+
return apiFetch('https://api.merchi.co/', '/test').catch(e => {
|
|
38
38
|
expect(e.statusCode).toBe(404);
|
|
39
39
|
expect(e.name).toBe('ApiError');
|
|
40
40
|
expect(e.errorCode).toBe(ErrorType.UNKNOWN_ERROR);
|
|
41
41
|
expect(e.errorMessage).toBe('just a test');
|
|
42
|
+
expect(e.message).toBe('just a test');
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('ApiError keeps plain string messages', () => {
|
|
47
|
+
const e = new ApiError('empty response');
|
|
48
|
+
expect(e.message).toBe('empty response');
|
|
49
|
+
expect(e.errorMessage).toBe('empty response');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('ApiError.message is the human-readable text, not serialized JSON', () => {
|
|
53
|
+
mockFetch(false, {
|
|
54
|
+
'statusCode': 403,
|
|
55
|
+
'errorCode': ErrorType.UNKNOWN_ERROR,
|
|
56
|
+
'message': 'cannot set referrer',
|
|
57
|
+
}, 403);
|
|
58
|
+
return apiFetch('https://api.merchi.co/', '/test').catch(e => {
|
|
59
|
+
expect(e.message).toBe('cannot set referrer');
|
|
60
|
+
expect(e.errorMessage).toBe('cannot set referrer');
|
|
61
|
+
expect(e.message).not.toContain('errorCode');
|
|
62
|
+
expect(e.message).not.toContain('statusCode');
|
|
42
63
|
});
|
|
43
64
|
});
|
|
44
65
|
|
package/src/request.ts
CHANGED
|
@@ -38,6 +38,16 @@ export interface ApiErrorDetails {
|
|
|
38
38
|
[key: string]: any;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
function resolveApiErrorMessage(err: any): string {
|
|
42
|
+
if (err && typeof err === 'object' && typeof err.message === 'string' && err.message) {
|
|
43
|
+
return err.message;
|
|
44
|
+
}
|
|
45
|
+
if (typeof err === 'string' && err) {
|
|
46
|
+
return err;
|
|
47
|
+
}
|
|
48
|
+
return 'No error message';
|
|
49
|
+
}
|
|
50
|
+
|
|
41
51
|
export class ApiError extends Error {
|
|
42
52
|
public statusCode?: number;
|
|
43
53
|
public errorCode?: ErrorType;
|
|
@@ -52,13 +62,12 @@ export class ApiError extends Error {
|
|
|
52
62
|
public details?: ApiErrorDetails;
|
|
53
63
|
public original: any;
|
|
54
64
|
public constructor(err: any) {
|
|
55
|
-
const message =
|
|
65
|
+
const message = resolveApiErrorMessage(err);
|
|
56
66
|
/* istanbul ignore next */
|
|
57
67
|
super(message);
|
|
58
68
|
this.statusCode = err.statusCode;
|
|
59
69
|
this.errorCode = getErrorFromCode(err.errorCode);
|
|
60
|
-
this.errorMessage =
|
|
61
|
-
err.message : 'No error message';
|
|
70
|
+
this.errorMessage = message;
|
|
62
71
|
this.details = err.details;
|
|
63
72
|
this.name = 'ApiError';
|
|
64
73
|
this.original = err;
|