merchi_sdk_ts 1.3.2-a → 1.3.2-c
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/product.test.js +1 -0
- package/dist/entities/support_conversation.js +2 -10
- package/dist/entities/support_conversation.test.js +6 -0
- package/dist/entities/support_message.js +9 -83
- package/dist/entities/support_message.test.js +6 -0
- package/dist/entity.js +4 -0
- package/package.json +1 -1
- package/src/entities/product.test.ts +1 -0
- package/src/entities/support_conversation.test.ts +7 -0
- package/src/entities/support_conversation.ts +2 -8
- package/src/entities/support_message.test.ts +7 -0
- package/src/entities/support_message.ts +8 -71
- package/src/entity.ts +5 -0
|
@@ -45,26 +45,18 @@ var SupportConversation = /** @class */ (function (_super) {
|
|
|
45
45
|
SupportConversation.property({ type: Date }),
|
|
46
46
|
__metadata("design:type", Object)
|
|
47
47
|
], SupportConversation.prototype, "lastMessageAt", void 0);
|
|
48
|
-
__decorate([
|
|
49
|
-
SupportConversation.property(),
|
|
50
|
-
__metadata("design:type", Number)
|
|
51
|
-
], SupportConversation.prototype, "domainId", void 0);
|
|
52
48
|
__decorate([
|
|
53
49
|
SupportConversation.property({ type: Domain }),
|
|
54
50
|
__metadata("design:type", Domain)
|
|
55
51
|
], SupportConversation.prototype, "domain", void 0);
|
|
56
52
|
__decorate([
|
|
57
|
-
SupportConversation.property(),
|
|
53
|
+
SupportConversation.property({ type: String }),
|
|
58
54
|
__metadata("design:type", Object)
|
|
59
55
|
], SupportConversation.prototype, "guestId", void 0);
|
|
60
56
|
__decorate([
|
|
61
|
-
SupportConversation.property(),
|
|
57
|
+
SupportConversation.property({ type: String }),
|
|
62
58
|
__metadata("design:type", Object)
|
|
63
59
|
], SupportConversation.prototype, "clientFingerprint", void 0);
|
|
64
|
-
__decorate([
|
|
65
|
-
SupportConversation.property(),
|
|
66
|
-
__metadata("design:type", Object)
|
|
67
|
-
], SupportConversation.prototype, "userId", void 0);
|
|
68
60
|
__decorate([
|
|
69
61
|
SupportConversation.property({ type: User }),
|
|
70
62
|
__metadata("design:type", Object)
|
|
@@ -22,109 +22,35 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
22
22
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
23
23
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
24
24
|
};
|
|
25
|
-
var __values = (this && this.__values) || function(o) {
|
|
26
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
27
|
-
if (m) return m.call(o);
|
|
28
|
-
if (o && typeof o.length === "number") return {
|
|
29
|
-
next: function () {
|
|
30
|
-
if (o && i >= o.length) o = void 0;
|
|
31
|
-
return { value: o && o[i++], done: !o };
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
35
|
-
};
|
|
36
25
|
import { Entity } from '../entity.js';
|
|
26
|
+
import { SupportConversation } from './support_conversation.js';
|
|
27
|
+
import { User } from './user.js';
|
|
37
28
|
var SupportMessage = /** @class */ (function (_super) {
|
|
38
29
|
__extends(SupportMessage, _super);
|
|
39
30
|
function SupportMessage() {
|
|
40
31
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
41
32
|
}
|
|
42
|
-
/**
|
|
43
|
-
* List messages for a conversation (`GET …/support_conversations/<id>/support_messages/`).
|
|
44
|
-
* The generic `/support_messages/` list route is not used for widget/dashboard chat.
|
|
45
|
-
*/
|
|
46
|
-
SupportMessage.listForConversation = function (conversationId, options) {
|
|
47
|
-
var _this = this;
|
|
48
|
-
var resource = "/support_conversations/".concat(conversationId, "/support_messages/");
|
|
49
|
-
var fetchOptions = { method: 'GET', query: [] };
|
|
50
|
-
if ((options === null || options === void 0 ? void 0 : options.offset) !== undefined) {
|
|
51
|
-
fetchOptions.query.push(['offset', String(options.offset)]);
|
|
52
|
-
}
|
|
53
|
-
if ((options === null || options === void 0 ? void 0 : options.limit) !== undefined) {
|
|
54
|
-
fetchOptions.query.push(['limit', String(options.limit)]);
|
|
55
|
-
}
|
|
56
|
-
fetchOptions.query.push(['skip_rights', 'y']);
|
|
57
|
-
return this.merchi.authenticatedFetch(resource, fetchOptions).then(function (data) {
|
|
58
|
-
var e_1, _a;
|
|
59
|
-
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
60
|
-
var pluralName = _this.pluralName;
|
|
61
|
-
var rawItems = (_b = data[pluralName]) !== null && _b !== void 0 ? _b : [];
|
|
62
|
-
var singularName = _this.singularName;
|
|
63
|
-
var entities = [];
|
|
64
|
-
try {
|
|
65
|
-
for (var rawItems_1 = __values(rawItems), rawItems_1_1 = rawItems_1.next(); !rawItems_1_1.done; rawItems_1_1 = rawItems_1.next()) {
|
|
66
|
-
var item = rawItems_1_1.value;
|
|
67
|
-
var entity = (new _this());
|
|
68
|
-
entity.fromJson(item[singularName]);
|
|
69
|
-
entities.push(entity);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
73
|
-
finally {
|
|
74
|
-
try {
|
|
75
|
-
if (rawItems_1_1 && !rawItems_1_1.done && (_a = rawItems_1.return)) _a.call(rawItems_1);
|
|
76
|
-
}
|
|
77
|
-
finally { if (e_1) throw e_1.error; }
|
|
78
|
-
}
|
|
79
|
-
var pagination = (_c = data.pagination) !== null && _c !== void 0 ? _c : {};
|
|
80
|
-
var total = (_e = (_d = pagination.totalCount) !== null && _d !== void 0 ? _d : pagination.available) !== null && _e !== void 0 ? _e : entities.length;
|
|
81
|
-
var metadata = {
|
|
82
|
-
available: total,
|
|
83
|
-
count: total,
|
|
84
|
-
limit: (_g = (_f = pagination.limit) !== null && _f !== void 0 ? _f : options === null || options === void 0 ? void 0 : options.limit) !== null && _g !== void 0 ? _g : 50,
|
|
85
|
-
offset: (_j = (_h = pagination.offset) !== null && _h !== void 0 ? _h : options === null || options === void 0 ? void 0 : options.offset) !== null && _j !== void 0 ? _j : 0,
|
|
86
|
-
};
|
|
87
|
-
return { items: entities, metadata: metadata };
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
/** POST a manager message to a conversation (dashboard session). */
|
|
91
|
-
SupportMessage.createForConversation = function (conversationId, content) {
|
|
92
|
-
var _this = this;
|
|
93
|
-
var resource = "/support_conversations/".concat(conversationId, "/support_messages/");
|
|
94
|
-
var fetchOptions = {
|
|
95
|
-
method: 'POST',
|
|
96
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
97
|
-
body: new URLSearchParams({ content: content }).toString(),
|
|
98
|
-
};
|
|
99
|
-
fetchOptions.query = [['skip_rights', 'y']];
|
|
100
|
-
return this.merchi.authenticatedFetch(resource, fetchOptions).then(function (data) {
|
|
101
|
-
var entity = (new _this());
|
|
102
|
-
entity.fromJson(data[_this.singularName]);
|
|
103
|
-
return entity;
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
33
|
SupportMessage.resourceName = 'support_messages';
|
|
107
34
|
SupportMessage.singularName = 'supportMessage';
|
|
108
|
-
|
|
109
|
-
SupportMessage.pluralName = 'supportMessagesList';
|
|
35
|
+
SupportMessage.pluralName = 'supportMessages';
|
|
110
36
|
__decorate([
|
|
111
37
|
SupportMessage.property(),
|
|
112
38
|
__metadata("design:type", Number)
|
|
113
39
|
], SupportMessage.prototype, "id", void 0);
|
|
114
40
|
__decorate([
|
|
115
|
-
SupportMessage.property(),
|
|
116
|
-
__metadata("design:type",
|
|
117
|
-
], SupportMessage.prototype, "
|
|
41
|
+
SupportMessage.property({ type: SupportConversation }),
|
|
42
|
+
__metadata("design:type", SupportConversation)
|
|
43
|
+
], SupportMessage.prototype, "conversation", void 0);
|
|
118
44
|
__decorate([
|
|
119
|
-
SupportMessage.property(),
|
|
45
|
+
SupportMessage.property({ type: String }),
|
|
120
46
|
__metadata("design:type", String)
|
|
121
47
|
], SupportMessage.prototype, "senderType", void 0);
|
|
122
48
|
__decorate([
|
|
123
|
-
SupportMessage.property(),
|
|
49
|
+
SupportMessage.property({ type: User }),
|
|
124
50
|
__metadata("design:type", Object)
|
|
125
51
|
], SupportMessage.prototype, "user", void 0);
|
|
126
52
|
__decorate([
|
|
127
|
-
SupportMessage.property(),
|
|
53
|
+
SupportMessage.property({ type: String }),
|
|
128
54
|
__metadata("design:type", String)
|
|
129
55
|
], SupportMessage.prototype, "content", void 0);
|
|
130
56
|
__decorate([
|
package/dist/entity.js
CHANGED
|
@@ -814,6 +814,10 @@ var Entity = /** @class */ (function () {
|
|
|
814
814
|
fetchOptions.query.push(['component_id',
|
|
815
815
|
options.componentId.toString()]);
|
|
816
816
|
}
|
|
817
|
+
if (options.conversationId !== undefined) {
|
|
818
|
+
fetchOptions.query.push(['conversation_id',
|
|
819
|
+
options.conversationId.toString()]);
|
|
820
|
+
}
|
|
817
821
|
if (options.groupBuyForJobId !== undefined) {
|
|
818
822
|
fetchOptions.query.push(['group_buy_for_job_id',
|
|
819
823
|
options.groupBuyForJobId.toString()]);
|
package/package.json
CHANGED
|
@@ -17,22 +17,16 @@ export class SupportConversation extends Entity {
|
|
|
17
17
|
@SupportConversation.property({ type: Date })
|
|
18
18
|
public lastMessageAt?: Date | null;
|
|
19
19
|
|
|
20
|
-
@SupportConversation.property()
|
|
21
|
-
public domainId?: number;
|
|
22
|
-
|
|
23
20
|
@SupportConversation.property({ type: Domain })
|
|
24
21
|
public domain?: Domain;
|
|
25
22
|
|
|
26
|
-
@SupportConversation.property()
|
|
23
|
+
@SupportConversation.property({ type: String })
|
|
27
24
|
public guestId?: string | null;
|
|
28
25
|
|
|
29
26
|
/** Opaque client fingerprint for repeat-visitor / spam correlation (max 512 chars). */
|
|
30
|
-
@SupportConversation.property()
|
|
27
|
+
@SupportConversation.property({ type: String })
|
|
31
28
|
public clientFingerprint?: string | null;
|
|
32
29
|
|
|
33
|
-
@SupportConversation.property()
|
|
34
|
-
public userId?: number | null;
|
|
35
|
-
|
|
36
30
|
@SupportConversation.property({ type: User })
|
|
37
31
|
public user?: User | null;
|
|
38
32
|
|
|
@@ -1,90 +1,27 @@
|
|
|
1
|
-
import { Entity
|
|
2
|
-
|
|
3
|
-
import { RequestOptions } from '../request.js';
|
|
1
|
+
import { Entity } from '../entity.js';
|
|
2
|
+
import { SupportConversation } from './support_conversation.js';
|
|
4
3
|
import { User } from './user.js';
|
|
5
4
|
|
|
6
5
|
export class SupportMessage extends Entity {
|
|
7
6
|
protected static resourceName = 'support_messages';
|
|
8
7
|
protected static singularName = 'supportMessage';
|
|
9
|
-
|
|
10
|
-
protected static pluralName = 'supportMessagesList';
|
|
8
|
+
protected static pluralName = 'supportMessages';
|
|
11
9
|
|
|
12
10
|
@SupportMessage.property()
|
|
13
11
|
public id?: number;
|
|
14
12
|
|
|
15
|
-
@SupportMessage.property()
|
|
16
|
-
public
|
|
13
|
+
@SupportMessage.property({ type: SupportConversation })
|
|
14
|
+
public conversation?: SupportConversation;
|
|
17
15
|
|
|
18
|
-
@SupportMessage.property()
|
|
16
|
+
@SupportMessage.property({ type: String })
|
|
19
17
|
public senderType?: string; // 'guest' | 'manager'
|
|
20
18
|
|
|
21
|
-
@SupportMessage.property()
|
|
19
|
+
@SupportMessage.property({ type: User })
|
|
22
20
|
public user?: User | null;
|
|
23
21
|
|
|
24
|
-
@SupportMessage.property()
|
|
22
|
+
@SupportMessage.property({ type: String })
|
|
25
23
|
public content?: string;
|
|
26
24
|
|
|
27
25
|
@SupportMessage.property({ type: Date })
|
|
28
26
|
public creationDate?: Date | null;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* List messages for a conversation (`GET …/support_conversations/<id>/support_messages/`).
|
|
32
|
-
* The generic `/support_messages/` list route is not used for widget/dashboard chat.
|
|
33
|
-
*/
|
|
34
|
-
public static listForConversation<T extends typeof SupportMessage>(
|
|
35
|
-
this: T,
|
|
36
|
-
conversationId: number,
|
|
37
|
-
options?: { limit?: number; offset?: number }
|
|
38
|
-
): Promise<ListResponse<InstanceType<T>>> {
|
|
39
|
-
const resource = `/support_conversations/${conversationId}/support_messages/`;
|
|
40
|
-
const fetchOptions: RequestOptions = { method: 'GET', query: [] };
|
|
41
|
-
if (options?.offset !== undefined) {
|
|
42
|
-
fetchOptions.query!.push(['offset', String(options.offset)]);
|
|
43
|
-
}
|
|
44
|
-
if (options?.limit !== undefined) {
|
|
45
|
-
fetchOptions.query!.push(['limit', String(options.limit)]);
|
|
46
|
-
}
|
|
47
|
-
fetchOptions.query!.push(['skip_rights', 'y']);
|
|
48
|
-
return this.merchi.authenticatedFetch(resource, fetchOptions).then((data: any) => {
|
|
49
|
-
const pluralName = this.pluralName;
|
|
50
|
-
const rawItems: any[] = data[pluralName] ?? [];
|
|
51
|
-
const singularName = this.singularName;
|
|
52
|
-
const entities: InstanceType<T>[] = [];
|
|
53
|
-
for (const item of rawItems) {
|
|
54
|
-
const entity: InstanceType<T> = (new this()) as InstanceType<T>;
|
|
55
|
-
entity.fromJson(item[singularName]);
|
|
56
|
-
entities.push(entity);
|
|
57
|
-
}
|
|
58
|
-
const pagination = data.pagination ?? {};
|
|
59
|
-
const total =
|
|
60
|
-
pagination.totalCount ?? pagination.available ?? entities.length;
|
|
61
|
-
const metadata = {
|
|
62
|
-
available: total,
|
|
63
|
-
count: total,
|
|
64
|
-
limit: pagination.limit ?? options?.limit ?? 50,
|
|
65
|
-
offset: pagination.offset ?? options?.offset ?? 0,
|
|
66
|
-
};
|
|
67
|
-
return { items: entities, metadata };
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** POST a manager message to a conversation (dashboard session). */
|
|
72
|
-
public static createForConversation<T extends typeof SupportMessage>(
|
|
73
|
-
this: T,
|
|
74
|
-
conversationId: number,
|
|
75
|
-
content: string
|
|
76
|
-
): Promise<InstanceType<T>> {
|
|
77
|
-
const resource = `/support_conversations/${conversationId}/support_messages/`;
|
|
78
|
-
const fetchOptions: RequestOptions = {
|
|
79
|
-
method: 'POST',
|
|
80
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
81
|
-
body: new URLSearchParams({ content }).toString(),
|
|
82
|
-
};
|
|
83
|
-
fetchOptions.query = [['skip_rights', 'y']];
|
|
84
|
-
return this.merchi.authenticatedFetch(resource, fetchOptions).then((data: any) => {
|
|
85
|
-
const entity: InstanceType<T> = (new this()) as InstanceType<T>;
|
|
86
|
-
entity.fromJson(data[this.singularName]);
|
|
87
|
-
return entity;
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
27
|
}
|
package/src/entity.ts
CHANGED
|
@@ -85,6 +85,7 @@ interface ListOptions {
|
|
|
85
85
|
companyId?: number;
|
|
86
86
|
companySupplierId?: number;
|
|
87
87
|
componentId?: number;
|
|
88
|
+
conversationId?: number;
|
|
88
89
|
dateFrom?: Date;
|
|
89
90
|
dateTo?: Date;
|
|
90
91
|
domainRoles?: Role[];
|
|
@@ -615,6 +616,10 @@ export class Entity {
|
|
|
615
616
|
fetchOptions.query.push(['component_id',
|
|
616
617
|
options.componentId.toString()]);
|
|
617
618
|
}
|
|
619
|
+
if (options.conversationId !== undefined) {
|
|
620
|
+
fetchOptions.query.push(['conversation_id',
|
|
621
|
+
options.conversationId.toString()]);
|
|
622
|
+
}
|
|
618
623
|
if (options.groupBuyForJobId !== undefined) {
|
|
619
624
|
fetchOptions.query.push(['group_buy_for_job_id',
|
|
620
625
|
options.groupBuyForJobId.toString()]);
|