@merchi/sdk 1.42.19 → 1.42.21
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/cart.test.js +69 -0
- package/dist/entities/category.d.ts +3 -0
- package/dist/entities/category.js +8 -0
- package/dist/entities/category.test.js +13 -0
- package/dist/entities/domain_tag.d.ts +2 -0
- package/dist/entities/domain_tag.js +4 -0
- package/dist/entities/domain_tag.test.js +9 -0
- package/dist/entities/user.d.ts +1 -0
- package/dist/entities/user.js +4 -0
- package/dist/entities/user.test.js +9 -0
- package/dist/entity.js +15 -2
- package/package.json +1 -1
- package/src/entities/cart.test.ts +48 -0
- package/src/entities/category.test.ts +13 -0
- package/src/entities/category.ts +7 -0
- package/src/entities/domain_tag.test.ts +9 -0
- package/src/entities/domain_tag.ts +4 -0
- package/src/entities/user.test.ts +9 -0
- package/src/entities/user.ts +3 -0
- package/src/entity.ts +15 -2
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
1
16
|
import { Merchi } from '../merchi.js';
|
|
2
17
|
import { setup, mockFetch } from '../test_util.js';
|
|
3
18
|
setup();
|
|
@@ -55,6 +70,60 @@ test('preserves isTest', function () {
|
|
|
55
70
|
entity.fromJson({ id: 1, isTest: true });
|
|
56
71
|
expect(entity.toJson()).toMatchObject({ isTest: true });
|
|
57
72
|
});
|
|
73
|
+
test('serialises a new cart when FormData has no set', function () {
|
|
74
|
+
var AppendOnlyFormData = /** @class */ (function () {
|
|
75
|
+
function AppendOnlyFormData() {
|
|
76
|
+
this.fields = new Map();
|
|
77
|
+
}
|
|
78
|
+
AppendOnlyFormData.prototype.append = function (name, value) {
|
|
79
|
+
this.fields.set(name, String(value));
|
|
80
|
+
};
|
|
81
|
+
AppendOnlyFormData.prototype.get = function (name) {
|
|
82
|
+
return this.fields.has(name) ? this.fields.get(name) : null;
|
|
83
|
+
};
|
|
84
|
+
AppendOnlyFormData.prototype.entries = function () {
|
|
85
|
+
return this.fields.entries();
|
|
86
|
+
};
|
|
87
|
+
return AppendOnlyFormData;
|
|
88
|
+
}());
|
|
89
|
+
var ReplacingFormData = /** @class */ (function (_super) {
|
|
90
|
+
__extends(ReplacingFormData, _super);
|
|
91
|
+
function ReplacingFormData() {
|
|
92
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
93
|
+
_this.ready = false;
|
|
94
|
+
return _this;
|
|
95
|
+
}
|
|
96
|
+
ReplacingFormData.prototype.append = function (name, value) {
|
|
97
|
+
if (!this.ready) {
|
|
98
|
+
throw new Error("delete was not called before append(".concat(name, ")"));
|
|
99
|
+
}
|
|
100
|
+
this.ready = false;
|
|
101
|
+
_super.prototype.append.call(this, name, value);
|
|
102
|
+
};
|
|
103
|
+
ReplacingFormData.prototype.delete = function () {
|
|
104
|
+
this.ready = true;
|
|
105
|
+
};
|
|
106
|
+
return ReplacingFormData;
|
|
107
|
+
}(AppendOnlyFormData));
|
|
108
|
+
var serialise = function (form) {
|
|
109
|
+
var merchi = new Merchi();
|
|
110
|
+
var cart = new merchi.Cart();
|
|
111
|
+
cart.isTest = false;
|
|
112
|
+
var domain = new merchi.Domain();
|
|
113
|
+
domain.id = 9;
|
|
114
|
+
cart.domain = domain;
|
|
115
|
+
cart.toFormData({ existing: form });
|
|
116
|
+
return form;
|
|
117
|
+
};
|
|
118
|
+
var appended = serialise(new AppendOnlyFormData());
|
|
119
|
+
expect(appended.get('isTest')).toBe('false');
|
|
120
|
+
expect(appended.get('domain-0-id')).toBe('9');
|
|
121
|
+
expect(appended.get('domain-count')).toBe('1');
|
|
122
|
+
var replaced = serialise(new ReplacingFormData());
|
|
123
|
+
expect(replaced.get('isTest')).toBe('false');
|
|
124
|
+
expect(replaced.get('domain-0-id')).toBe('9');
|
|
125
|
+
expect(replaced.get('domain-count')).toBe('1');
|
|
126
|
+
});
|
|
58
127
|
test('preserves source attribution', function () {
|
|
59
128
|
var merchi = new Merchi();
|
|
60
129
|
var entity = new merchi.Cart();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Domain } from './domain.js';
|
|
2
|
+
import { DomainTag } from './domain_tag.js';
|
|
2
3
|
import { Entity } from '../entity.js';
|
|
3
4
|
import { MerchiFile } from './file.js';
|
|
4
5
|
import { Product } from './product.js';
|
|
@@ -20,6 +21,8 @@ export declare class Category extends Entity {
|
|
|
20
21
|
domain?: Domain;
|
|
21
22
|
products?: Product[];
|
|
22
23
|
users?: User[];
|
|
24
|
+
tags?: DomainTag[];
|
|
25
|
+
assigned?: User[];
|
|
23
26
|
subcategories?: Category[];
|
|
24
27
|
parent?: Category;
|
|
25
28
|
image?: MerchiFile | null;
|
|
@@ -84,6 +84,14 @@ var Category = /** @class */ (function (_super) {
|
|
|
84
84
|
Category.property({ arrayType: 'User' }),
|
|
85
85
|
__metadata("design:type", Array)
|
|
86
86
|
], Category.prototype, "users", void 0);
|
|
87
|
+
__decorate([
|
|
88
|
+
Category.property({ arrayType: 'DomainTag' }),
|
|
89
|
+
__metadata("design:type", Array)
|
|
90
|
+
], Category.prototype, "tags", void 0);
|
|
91
|
+
__decorate([
|
|
92
|
+
Category.property({ arrayType: 'User' }),
|
|
93
|
+
__metadata("design:type", Array)
|
|
94
|
+
], Category.prototype, "assigned", void 0);
|
|
87
95
|
__decorate([
|
|
88
96
|
Category.property({ arrayType: 'Category' }),
|
|
89
97
|
__metadata("design:type", Array)
|
|
@@ -33,6 +33,19 @@ test('can get and set product', function () {
|
|
|
33
33
|
p1.categories = undefined;
|
|
34
34
|
expect(p1.categories).toBe(undefined);
|
|
35
35
|
});
|
|
36
|
+
test('can set tags and assigned team members', function () {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
var merchi = new Merchi();
|
|
39
|
+
var category = new merchi.Category();
|
|
40
|
+
var tag = new merchi.DomainTag();
|
|
41
|
+
var user = new merchi.User();
|
|
42
|
+
tag.id = 4;
|
|
43
|
+
user.id = 9;
|
|
44
|
+
category.tags = [tag];
|
|
45
|
+
category.assigned = [user];
|
|
46
|
+
expect((_a = category.tags) === null || _a === void 0 ? void 0 : _a.map(function (item) { return item.id; })).toEqual([4]);
|
|
47
|
+
expect((_b = category.assigned) === null || _b === void 0 ? void 0 : _b.map(function (item) { return item.id; })).toEqual([9]);
|
|
48
|
+
});
|
|
36
49
|
test('independence of entities', function () {
|
|
37
50
|
var merchi = new Merchi();
|
|
38
51
|
var c1 = new merchi.Category();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Category } from './category.js';
|
|
1
2
|
import { Domain } from './domain.js';
|
|
2
3
|
import { Entity } from '../entity.js';
|
|
3
4
|
import { Invoice } from './invoice.js';
|
|
@@ -18,4 +19,5 @@ export declare class DomainTag extends Entity {
|
|
|
18
19
|
products?: Product[];
|
|
19
20
|
invoices?: Invoice[];
|
|
20
21
|
shipments?: Shipment[];
|
|
22
|
+
categories?: Category[];
|
|
21
23
|
}
|
|
@@ -72,6 +72,10 @@ var DomainTag = /** @class */ (function (_super) {
|
|
|
72
72
|
DomainTag.property({ arrayType: 'Shipment' }),
|
|
73
73
|
__metadata("design:type", Array)
|
|
74
74
|
], DomainTag.prototype, "shipments", void 0);
|
|
75
|
+
__decorate([
|
|
76
|
+
DomainTag.property({ arrayType: 'Category' }),
|
|
77
|
+
__metadata("design:type", Array)
|
|
78
|
+
], DomainTag.prototype, "categories", void 0);
|
|
75
79
|
return DomainTag;
|
|
76
80
|
}(Entity));
|
|
77
81
|
export { DomainTag };
|
|
@@ -4,3 +4,12 @@ test('can make DomainTag', function () {
|
|
|
4
4
|
var domainTag = new merchi.DomainTag();
|
|
5
5
|
expect(domainTag).toBeTruthy();
|
|
6
6
|
});
|
|
7
|
+
test('can set categories', function () {
|
|
8
|
+
var _a;
|
|
9
|
+
var merchi = new Merchi();
|
|
10
|
+
var domainTag = new merchi.DomainTag();
|
|
11
|
+
var category = new merchi.Category();
|
|
12
|
+
category.id = 3;
|
|
13
|
+
domainTag.categories = [category];
|
|
14
|
+
expect((_a = domainTag.categories) === null || _a === void 0 ? void 0 : _a.map(function (item) { return item.id; })).toEqual([3]);
|
|
15
|
+
});
|
package/dist/entities/user.d.ts
CHANGED
|
@@ -90,6 +90,7 @@ export declare class User extends Entity {
|
|
|
90
90
|
_companies?: UserCompany[];
|
|
91
91
|
companiesNeedStripe?: Company[];
|
|
92
92
|
categories?: Category[];
|
|
93
|
+
assignedCategories?: Category[];
|
|
93
94
|
products?: Product[];
|
|
94
95
|
profilePicture?: MerchiFile | null;
|
|
95
96
|
phoneNumbers?: PhoneNumber[];
|
package/dist/entities/user.js
CHANGED
|
@@ -372,6 +372,10 @@ var User = /** @class */ (function (_super) {
|
|
|
372
372
|
User.property({ arrayType: 'Category' }),
|
|
373
373
|
__metadata("design:type", Array)
|
|
374
374
|
], User.prototype, "categories", void 0);
|
|
375
|
+
__decorate([
|
|
376
|
+
User.property({ arrayType: 'Category' }),
|
|
377
|
+
__metadata("design:type", Array)
|
|
378
|
+
], User.prototype, "assignedCategories", void 0);
|
|
375
379
|
__decorate([
|
|
376
380
|
User.property({ arrayType: 'Product' }),
|
|
377
381
|
__metadata("design:type", Array)
|
|
@@ -11,6 +11,15 @@ test('can make User', function () {
|
|
|
11
11
|
var user = new merchi.User();
|
|
12
12
|
expect(user).toBeTruthy();
|
|
13
13
|
});
|
|
14
|
+
test('can set assignedCategories', function () {
|
|
15
|
+
var _a;
|
|
16
|
+
var merchi = new Merchi();
|
|
17
|
+
var user = new merchi.User();
|
|
18
|
+
var category = new merchi.Category();
|
|
19
|
+
category.id = 3;
|
|
20
|
+
user.assignedCategories = [category];
|
|
21
|
+
expect((_a = user.assignedCategories) === null || _a === void 0 ? void 0 : _a.map(function (item) { return item.id; })).toEqual([3]);
|
|
22
|
+
});
|
|
14
23
|
test('can issue public create request to server', function () {
|
|
15
24
|
var merchi = new Merchi();
|
|
16
25
|
var user = new merchi.User();
|
package/dist/entity.js
CHANGED
|
@@ -302,6 +302,19 @@ var Entity = /** @class */ (function () {
|
|
|
302
302
|
if (fileIndex === undefined) {
|
|
303
303
|
fileIndex = { value: 0 };
|
|
304
304
|
}
|
|
305
|
+
// Prefer set so a repeated key is replaced. Fall back to append for
|
|
306
|
+
// FormData implementations that never added set.
|
|
307
|
+
var writeField = function (target, name, value) {
|
|
308
|
+
if (typeof target.set === 'function') {
|
|
309
|
+
target.set(name, value);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
var legacy = target;
|
|
313
|
+
if (typeof legacy.delete === 'function') {
|
|
314
|
+
legacy.delete(name);
|
|
315
|
+
}
|
|
316
|
+
target.append(name, value);
|
|
317
|
+
};
|
|
305
318
|
var appendData = function (name, value) {
|
|
306
319
|
/* istanbul ignore next */
|
|
307
320
|
if (name === undefined || value === undefined) {
|
|
@@ -311,10 +324,10 @@ var Entity = /** @class */ (function () {
|
|
|
311
324
|
if (prefix) {
|
|
312
325
|
name = prefix + '-' + name;
|
|
313
326
|
}
|
|
314
|
-
result
|
|
327
|
+
writeField(result, name, value);
|
|
315
328
|
};
|
|
316
329
|
if (_this.fileData !== undefined) {
|
|
317
|
-
result
|
|
330
|
+
writeField(result, String(fileIndex.value), _this.fileData);
|
|
318
331
|
appendData('fileDataIndex', fileIndex.value);
|
|
319
332
|
fileIndex.value++;
|
|
320
333
|
}
|
package/package.json
CHANGED
|
@@ -63,6 +63,54 @@ test('preserves isTest', () => {
|
|
|
63
63
|
expect(entity.toJson()).toMatchObject({ isTest: true });
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
+
test('serialises a new cart when FormData has no set', () => {
|
|
67
|
+
class AppendOnlyFormData {
|
|
68
|
+
fields = new Map<string, string>();
|
|
69
|
+
append(name: string, value: any) {
|
|
70
|
+
this.fields.set(name, String(value));
|
|
71
|
+
}
|
|
72
|
+
get(name: string) {
|
|
73
|
+
return this.fields.has(name) ? this.fields.get(name) : null;
|
|
74
|
+
}
|
|
75
|
+
entries() {
|
|
76
|
+
return this.fields.entries();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
class ReplacingFormData extends AppendOnlyFormData {
|
|
80
|
+
private ready = false;
|
|
81
|
+
append(name: string, value: any) {
|
|
82
|
+
if (!this.ready) {
|
|
83
|
+
throw new Error(`delete was not called before append(${name})`);
|
|
84
|
+
}
|
|
85
|
+
this.ready = false;
|
|
86
|
+
super.append(name, value);
|
|
87
|
+
}
|
|
88
|
+
delete() {
|
|
89
|
+
this.ready = true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const serialise = (form: AppendOnlyFormData) => {
|
|
93
|
+
const merchi = new Merchi();
|
|
94
|
+
const cart = new merchi.Cart();
|
|
95
|
+
cart.isTest = false;
|
|
96
|
+
const domain = new merchi.Domain();
|
|
97
|
+
domain.id = 9;
|
|
98
|
+
cart.domain = domain;
|
|
99
|
+
cart.toFormData({existing: form as unknown as FormData});
|
|
100
|
+
return form;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const appended = serialise(new AppendOnlyFormData());
|
|
104
|
+
expect(appended.get('isTest')).toBe('false');
|
|
105
|
+
expect(appended.get('domain-0-id')).toBe('9');
|
|
106
|
+
expect(appended.get('domain-count')).toBe('1');
|
|
107
|
+
|
|
108
|
+
const replaced = serialise(new ReplacingFormData());
|
|
109
|
+
expect(replaced.get('isTest')).toBe('false');
|
|
110
|
+
expect(replaced.get('domain-0-id')).toBe('9');
|
|
111
|
+
expect(replaced.get('domain-count')).toBe('1');
|
|
112
|
+
});
|
|
113
|
+
|
|
66
114
|
test('preserves source attribution', () => {
|
|
67
115
|
const merchi = new Merchi();
|
|
68
116
|
const entity = new merchi.Cart();
|
|
@@ -38,6 +38,19 @@ test('can get and set product', () => {
|
|
|
38
38
|
expect(p1.categories).toBe(undefined);
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
+
test('can set tags and assigned team members', () => {
|
|
42
|
+
const merchi = new Merchi();
|
|
43
|
+
const category = new merchi.Category();
|
|
44
|
+
const tag = new merchi.DomainTag();
|
|
45
|
+
const user = new merchi.User();
|
|
46
|
+
tag.id = 4;
|
|
47
|
+
user.id = 9;
|
|
48
|
+
category.tags = [tag];
|
|
49
|
+
category.assigned = [user];
|
|
50
|
+
expect(category.tags?.map((item) => item.id)).toEqual([4]);
|
|
51
|
+
expect(category.assigned?.map((item) => item.id)).toEqual([9]);
|
|
52
|
+
});
|
|
53
|
+
|
|
41
54
|
test('independence of entities', () => {
|
|
42
55
|
const merchi = new Merchi();
|
|
43
56
|
const c1 = new merchi.Category();
|
package/src/entities/category.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Domain } from './domain.js';
|
|
2
|
+
import { DomainTag } from './domain_tag.js';
|
|
2
3
|
import { Entity } from '../entity.js';
|
|
3
4
|
import { MerchiFile } from './file.js';
|
|
4
5
|
import { Product } from './product.js';
|
|
@@ -48,6 +49,12 @@ export class Category extends Entity {
|
|
|
48
49
|
@Category.property({arrayType: 'User'})
|
|
49
50
|
public users?: User[];
|
|
50
51
|
|
|
52
|
+
@Category.property({arrayType: 'DomainTag'})
|
|
53
|
+
public tags?: DomainTag[];
|
|
54
|
+
|
|
55
|
+
@Category.property({arrayType: 'User'})
|
|
56
|
+
public assigned?: User[];
|
|
57
|
+
|
|
51
58
|
@Category.property({arrayType: 'Category'})
|
|
52
59
|
public subcategories?: Category[];
|
|
53
60
|
|
|
@@ -5,3 +5,12 @@ test('can make DomainTag', () => {
|
|
|
5
5
|
const domainTag = new merchi.DomainTag();
|
|
6
6
|
expect(domainTag).toBeTruthy();
|
|
7
7
|
});
|
|
8
|
+
|
|
9
|
+
test('can set categories', () => {
|
|
10
|
+
const merchi = new Merchi();
|
|
11
|
+
const domainTag = new merchi.DomainTag();
|
|
12
|
+
const category = new merchi.Category();
|
|
13
|
+
category.id = 3;
|
|
14
|
+
domainTag.categories = [category];
|
|
15
|
+
expect(domainTag.categories?.map((item) => item.id)).toEqual([3]);
|
|
16
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Category } from './category.js';
|
|
1
2
|
import { Domain } from './domain.js';
|
|
2
3
|
import { Entity } from '../entity.js';
|
|
3
4
|
import { Invoice } from './invoice.js';
|
|
@@ -39,4 +40,7 @@ export class DomainTag extends Entity {
|
|
|
39
40
|
|
|
40
41
|
@DomainTag.property({arrayType: 'Shipment'})
|
|
41
42
|
public shipments?: Shipment[];
|
|
43
|
+
|
|
44
|
+
@DomainTag.property({arrayType: 'Category'})
|
|
45
|
+
public categories?: Category[];
|
|
42
46
|
}
|
|
@@ -15,6 +15,15 @@ test('can make User', () => {
|
|
|
15
15
|
expect(user).toBeTruthy();
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
+
test('can set assignedCategories', () => {
|
|
19
|
+
const merchi = new Merchi();
|
|
20
|
+
const user = new merchi.User();
|
|
21
|
+
const category = new merchi.Category();
|
|
22
|
+
category.id = 3;
|
|
23
|
+
user.assignedCategories = [category];
|
|
24
|
+
expect(user.assignedCategories?.map((item) => item.id)).toEqual([3]);
|
|
25
|
+
});
|
|
26
|
+
|
|
18
27
|
test('can issue public create request to server', () => {
|
|
19
28
|
const merchi = new Merchi();
|
|
20
29
|
const user = new merchi.User();
|
package/src/entities/user.ts
CHANGED
|
@@ -204,6 +204,9 @@ export class User extends Entity {
|
|
|
204
204
|
@User.property({ arrayType: 'Category' })
|
|
205
205
|
public categories?: Category[];
|
|
206
206
|
|
|
207
|
+
@User.property({ arrayType: 'Category' })
|
|
208
|
+
public assignedCategories?: Category[];
|
|
209
|
+
|
|
207
210
|
@User.property({ arrayType: 'Product' })
|
|
208
211
|
public products?: Product[];
|
|
209
212
|
|
package/src/entity.ts
CHANGED
|
@@ -928,6 +928,19 @@ export class Entity {
|
|
|
928
928
|
if (fileIndex === undefined) {
|
|
929
929
|
fileIndex = {value: 0};
|
|
930
930
|
}
|
|
931
|
+
// Prefer set so a repeated key is replaced. Fall back to append for
|
|
932
|
+
// FormData implementations that never added set.
|
|
933
|
+
const writeField = (target: FormData, name: string, value: any) => {
|
|
934
|
+
if (typeof target.set === 'function') {
|
|
935
|
+
target.set(name, value);
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
const legacy = target as FormData & {delete?: (field: string) => void};
|
|
939
|
+
if (typeof legacy.delete === 'function') {
|
|
940
|
+
legacy.delete(name);
|
|
941
|
+
}
|
|
942
|
+
target.append(name, value);
|
|
943
|
+
};
|
|
931
944
|
const appendData = (name: string, value: any) => {
|
|
932
945
|
/* istanbul ignore next */
|
|
933
946
|
if (name === undefined || value === undefined) {
|
|
@@ -937,10 +950,10 @@ export class Entity {
|
|
|
937
950
|
if (prefix) {
|
|
938
951
|
name = prefix + '-' + name;
|
|
939
952
|
}
|
|
940
|
-
result
|
|
953
|
+
writeField(result, name, value);
|
|
941
954
|
};
|
|
942
955
|
if ((this as any).fileData !== undefined) {
|
|
943
|
-
result
|
|
956
|
+
writeField(result, String(fileIndex.value), (this as any).fileData);
|
|
944
957
|
appendData('fileDataIndex', fileIndex.value);
|
|
945
958
|
fileIndex.value++;
|
|
946
959
|
}
|