merchi_sdk_ts 1.3.1 → 1.3.2-a

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.
@@ -25,6 +25,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
25
25
  import { Company } from './company.js';
26
26
  import { Entity } from '../entity.js';
27
27
  import { MerchiFile } from './file.js';
28
+ import { DomainChatSettings } from './domain_chat_settings.js';
28
29
  import { Theme } from './theme.js';
29
30
  import { DomainType } from '../constants/domain_types.js';
30
31
  var Domain = /** @class */ (function (_super) {
@@ -361,6 +362,10 @@ var Domain = /** @class */ (function (_super) {
361
362
  Domain.property({ arrayType: 'SeoDomainPage' }),
362
363
  __metadata("design:type", Array)
363
364
  ], Domain.prototype, "seoDomainPages", void 0);
365
+ __decorate([
366
+ Domain.property({ type: DomainChatSettings }),
367
+ __metadata("design:type", Object)
368
+ ], Domain.prototype, "domainChatSettings", void 0);
364
369
  __decorate([
365
370
  Domain.property({ arrayType: 'Theme' }),
366
371
  __metadata("design:type", Array)
@@ -0,0 +1,82 @@
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
+ })();
16
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
17
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
18
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
19
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
20
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
21
+ };
22
+ var __metadata = (this && this.__metadata) || function (k, v) {
23
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
24
+ };
25
+ import { Domain } from './domain.js';
26
+ import { Entity } from '../entity.js';
27
+ import { MerchiFile } from './file.js';
28
+ var DomainChatSettings = /** @class */ (function (_super) {
29
+ __extends(DomainChatSettings, _super);
30
+ function DomainChatSettings() {
31
+ return _super !== null && _super.apply(this, arguments) || this;
32
+ }
33
+ DomainChatSettings.resourceName = 'domain_chat_settings';
34
+ DomainChatSettings.singularName = 'domainChatSettings';
35
+ DomainChatSettings.pluralName = 'domainChatSettingsList';
36
+ __decorate([
37
+ DomainChatSettings.property(),
38
+ __metadata("design:type", Number)
39
+ ], DomainChatSettings.prototype, "id", void 0);
40
+ __decorate([
41
+ DomainChatSettings.property(),
42
+ __metadata("design:type", Domain)
43
+ ], DomainChatSettings.prototype, "domain", void 0);
44
+ __decorate([
45
+ DomainChatSettings.property(),
46
+ __metadata("design:type", Boolean)
47
+ ], DomainChatSettings.prototype, "enabled", void 0);
48
+ __decorate([
49
+ DomainChatSettings.property(),
50
+ __metadata("design:type", Object)
51
+ ], DomainChatSettings.prototype, "displayName", void 0);
52
+ __decorate([
53
+ DomainChatSettings.property({ type: MerchiFile }),
54
+ __metadata("design:type", Object)
55
+ ], DomainChatSettings.prototype, "avatar", void 0);
56
+ __decorate([
57
+ DomainChatSettings.property(),
58
+ __metadata("design:type", Object)
59
+ ], DomainChatSettings.prototype, "welcomeMessage", void 0);
60
+ __decorate([
61
+ DomainChatSettings.property(),
62
+ __metadata("design:type", Object)
63
+ ], DomainChatSettings.prototype, "privacyPolicyUrl", void 0);
64
+ __decorate([
65
+ DomainChatSettings.property(),
66
+ __metadata("design:type", Object)
67
+ ], DomainChatSettings.prototype, "workingHours", void 0);
68
+ __decorate([
69
+ DomainChatSettings.property(),
70
+ __metadata("design:type", Object)
71
+ ], DomainChatSettings.prototype, "awayMessage", void 0);
72
+ __decorate([
73
+ DomainChatSettings.property(),
74
+ __metadata("design:type", Boolean)
75
+ ], DomainChatSettings.prototype, "notifyEmailNewConversation", void 0);
76
+ __decorate([
77
+ DomainChatSettings.property(),
78
+ __metadata("design:type", Boolean)
79
+ ], DomainChatSettings.prototype, "notifyEmailNewMessage", void 0);
80
+ return DomainChatSettings;
81
+ }(Entity));
82
+ export { DomainChatSettings };
@@ -0,0 +1,78 @@
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
+ })();
16
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
17
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
18
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
19
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
20
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
21
+ };
22
+ var __metadata = (this && this.__metadata) || function (k, v) {
23
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
24
+ };
25
+ import { Domain } from './domain.js';
26
+ import { Entity } from '../entity.js';
27
+ import { User } from './user.js';
28
+ var SupportConversation = /** @class */ (function (_super) {
29
+ __extends(SupportConversation, _super);
30
+ function SupportConversation() {
31
+ return _super !== null && _super.apply(this, arguments) || this;
32
+ }
33
+ SupportConversation.resourceName = 'support_conversations';
34
+ SupportConversation.singularName = 'supportConversation';
35
+ SupportConversation.pluralName = 'supportConversations';
36
+ __decorate([
37
+ SupportConversation.property(),
38
+ __metadata("design:type", Number)
39
+ ], SupportConversation.prototype, "id", void 0);
40
+ __decorate([
41
+ SupportConversation.property({ type: Date }),
42
+ __metadata("design:type", Object)
43
+ ], SupportConversation.prototype, "creationDate", void 0);
44
+ __decorate([
45
+ SupportConversation.property({ type: Date }),
46
+ __metadata("design:type", Object)
47
+ ], SupportConversation.prototype, "lastMessageAt", void 0);
48
+ __decorate([
49
+ SupportConversation.property(),
50
+ __metadata("design:type", Number)
51
+ ], SupportConversation.prototype, "domainId", void 0);
52
+ __decorate([
53
+ SupportConversation.property({ type: Domain }),
54
+ __metadata("design:type", Domain)
55
+ ], SupportConversation.prototype, "domain", void 0);
56
+ __decorate([
57
+ SupportConversation.property(),
58
+ __metadata("design:type", Object)
59
+ ], SupportConversation.prototype, "guestId", void 0);
60
+ __decorate([
61
+ SupportConversation.property(),
62
+ __metadata("design:type", Object)
63
+ ], SupportConversation.prototype, "clientFingerprint", void 0);
64
+ __decorate([
65
+ SupportConversation.property(),
66
+ __metadata("design:type", Object)
67
+ ], SupportConversation.prototype, "userId", void 0);
68
+ __decorate([
69
+ SupportConversation.property({ type: User }),
70
+ __metadata("design:type", Object)
71
+ ], SupportConversation.prototype, "user", void 0);
72
+ __decorate([
73
+ SupportConversation.property({ arrayType: 'SupportMessage' }),
74
+ __metadata("design:type", Array)
75
+ ], SupportConversation.prototype, "messages", void 0);
76
+ return SupportConversation;
77
+ }(Entity));
78
+ export { SupportConversation };
@@ -0,0 +1,136 @@
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
+ })();
16
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
17
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
18
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
19
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
20
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
21
+ };
22
+ var __metadata = (this && this.__metadata) || function (k, v) {
23
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
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
+ import { Entity } from '../entity.js';
37
+ var SupportMessage = /** @class */ (function (_super) {
38
+ __extends(SupportMessage, _super);
39
+ function SupportMessage() {
40
+ return _super !== null && _super.apply(this, arguments) || this;
41
+ }
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
+ SupportMessage.resourceName = 'support_messages';
107
+ SupportMessage.singularName = 'supportMessage';
108
+ /** Matches API `plural_json_name` (list responses use `supportMessagesList`). */
109
+ SupportMessage.pluralName = 'supportMessagesList';
110
+ __decorate([
111
+ SupportMessage.property(),
112
+ __metadata("design:type", Number)
113
+ ], SupportMessage.prototype, "id", void 0);
114
+ __decorate([
115
+ SupportMessage.property(),
116
+ __metadata("design:type", Number)
117
+ ], SupportMessage.prototype, "conversationId", void 0);
118
+ __decorate([
119
+ SupportMessage.property(),
120
+ __metadata("design:type", String)
121
+ ], SupportMessage.prototype, "senderType", void 0);
122
+ __decorate([
123
+ SupportMessage.property(),
124
+ __metadata("design:type", Object)
125
+ ], SupportMessage.prototype, "user", void 0);
126
+ __decorate([
127
+ SupportMessage.property(),
128
+ __metadata("design:type", String)
129
+ ], SupportMessage.prototype, "content", void 0);
130
+ __decorate([
131
+ SupportMessage.property({ type: Date }),
132
+ __metadata("design:type", Object)
133
+ ], SupportMessage.prototype, "creationDate", void 0);
134
+ return SupportMessage;
135
+ }(Entity));
136
+ export { SupportMessage };
package/dist/index.js CHANGED
@@ -1,5 +1,8 @@
1
1
  import { Address } from './entities/address.js';
2
2
  import { AgentConversation } from './entities/agent_conversation.js';
3
+ import { DomainChatSettings } from './entities/domain_chat_settings.js';
4
+ import { SupportConversation } from './entities/support_conversation.js';
5
+ import { SupportMessage } from './entities/support_message.js';
3
6
  import { Assignment } from './entities/assignment.js';
4
7
  import { AutomaticPaymentRelationship } from './entities/automatic_payment_relationship.js';
5
8
  import { Bank } from './entities/bank.js';
@@ -75,4 +78,4 @@ import * as constants from './constants/index.js';
75
78
  import * as request from './request.js';
76
79
  import * as util from './util/index.js';
77
80
  import { toastNotifications } from './toasts.js';
78
- export { constants, request, util, toastNotifications, Address, AgentConversation, Assignment, AutomaticPaymentRelationship, Bank, Cart, CartItem, CartShipmentGroup, CartShipmentQuote, Category, Company, CompanyInvitation, Component, ComponentTag, ComponentVersion, CountryTax, Discount, DiscountGroup, Domain, DomainInvitation, DomainTag, Draft, DraftComment, DraftTemplate, EmailAddress, EmailCounter, EnrolledDomain, Entity, ExchangeRate, InternalTag, Inventory, InventoryUnitVariation, Invoice, Item, Job, JobComment, MatchingInventory, Menu, MenuItem, Merchi, MerchiFile, Notification, Page, Payment, PaymentDevice, PhoneNumber, Product, ProductionComment, Quote, QuoteItem, Reminder, apiFetch, apiFetchWithProgress, Session, Shipment, ShipmentItem, ShipmentItemFulfillment, ShipmentMethod, ShipmentMethodVariation, ShortUrl, SubscriptionPlan, SupplyDomain, SystemRole, Theme, ThemeCssSetting, User, UserCompany, Variation, VariationField, VariationFieldsOption, VariationOption, VariationsGroup, generateUUID, getCookie };
81
+ export { constants, request, util, toastNotifications, Address, AgentConversation, DomainChatSettings, SupportConversation, SupportMessage, Assignment, AutomaticPaymentRelationship, Bank, Cart, CartItem, CartShipmentGroup, CartShipmentQuote, Category, Company, CompanyInvitation, Component, ComponentTag, ComponentVersion, CountryTax, Discount, DiscountGroup, Domain, DomainInvitation, DomainTag, Draft, DraftComment, DraftTemplate, EmailAddress, EmailCounter, EnrolledDomain, Entity, ExchangeRate, InternalTag, Inventory, InventoryUnitVariation, Invoice, Item, Job, JobComment, MatchingInventory, Menu, MenuItem, Merchi, MerchiFile, Notification, Page, Payment, PaymentDevice, PhoneNumber, Product, ProductionComment, Quote, QuoteItem, Reminder, apiFetch, apiFetchWithProgress, Session, Shipment, ShipmentItem, ShipmentItemFulfillment, ShipmentMethod, ShipmentMethodVariation, ShortUrl, SubscriptionPlan, SupplyDomain, SystemRole, Theme, ThemeCssSetting, User, UserCompany, Variation, VariationField, VariationFieldsOption, VariationOption, VariationsGroup, generateUUID, getCookie };
package/dist/merchi.js CHANGED
@@ -78,6 +78,9 @@ import { Variation } from './entities/variation.js';
78
78
  import { CartItem } from './entities/cart_item.js';
79
79
  import { Address } from './entities/address.js';
80
80
  import { AgentConversation } from './entities/agent_conversation.js';
81
+ import { DomainChatSettings } from './entities/domain_chat_settings.js';
82
+ import { SupportConversation } from './entities/support_conversation.js';
83
+ import { SupportMessage } from './entities/support_message.js';
81
84
  import { Assignment } from './entities/assignment.js';
82
85
  import { MatchingInventory } from './entities/matching_inventory.js';
83
86
  import { SubscriptionPlan } from './entities/subscription_plan.js';
@@ -253,6 +256,9 @@ var Merchi = /** @class */ (function () {
253
256
  this.VariationFieldsOption = this.setupClass(VariationFieldsOption);
254
257
  this.Address = this.setupClass(Address);
255
258
  this.AgentConversation = this.setupClass(AgentConversation);
259
+ this.DomainChatSettings = this.setupClass(DomainChatSettings);
260
+ this.SupportConversation = this.setupClass(SupportConversation);
261
+ this.SupportMessage = this.setupClass(SupportMessage);
256
262
  this.Item = this.setupClass(Item);
257
263
  this.SupplyDomain = this.setupClass(SupplyDomain);
258
264
  this.DomainInvitation = this.setupClass(DomainInvitation);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "merchi_sdk_ts",
3
- "version": "1.3.1",
3
+ "version": "1.3.2a",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "repository": "git@github.com:merchisdk/merchi_sdk_ts.git",
@@ -17,6 +17,7 @@ import { Reminder } from './reminder.js';
17
17
  import { Session } from './session.js';
18
18
  import { SupplyDomain } from './supply_domain.js';
19
19
  import { SeoDomainPage } from './seo_domain_page.js';
20
+ import { DomainChatSettings } from './domain_chat_settings.js';
20
21
  import { Theme } from './theme.js';
21
22
  import { DomainType } from '../constants/domain_types.js';
22
23
  import { ShipmentMethod } from './shipment_method.js';
@@ -257,6 +258,9 @@ export class Domain extends Entity {
257
258
  @Domain.property({arrayType: 'SeoDomainPage'})
258
259
  public seoDomainPages?: SeoDomainPage[];
259
260
 
261
+ @Domain.property({ type: DomainChatSettings })
262
+ public domainChatSettings?: DomainChatSettings | null;
263
+
260
264
  @Domain.property({arrayType: 'Theme'})
261
265
  public themes?: Theme[];
262
266
 
@@ -0,0 +1,42 @@
1
+ import { Domain } from './domain.js';
2
+ import { Entity } from '../entity.js';
3
+ import { MerchiFile } from './file.js';
4
+
5
+ export class DomainChatSettings extends Entity {
6
+ protected static resourceName = 'domain_chat_settings';
7
+ protected static singularName = 'domainChatSettings';
8
+ protected static pluralName = 'domainChatSettingsList';
9
+
10
+ @DomainChatSettings.property()
11
+ public id?: number;
12
+
13
+ @DomainChatSettings.property()
14
+ public domain?: Domain;
15
+
16
+ @DomainChatSettings.property()
17
+ public enabled?: boolean;
18
+
19
+ @DomainChatSettings.property()
20
+ public displayName?: string | null;
21
+
22
+ @DomainChatSettings.property({ type: MerchiFile })
23
+ public avatar?: MerchiFile | null;
24
+
25
+ @DomainChatSettings.property()
26
+ public welcomeMessage?: string | null;
27
+
28
+ @DomainChatSettings.property()
29
+ public privacyPolicyUrl?: string | null;
30
+
31
+ @DomainChatSettings.property()
32
+ public workingHours?: any | null;
33
+
34
+ @DomainChatSettings.property()
35
+ public awayMessage?: string | null;
36
+
37
+ @DomainChatSettings.property()
38
+ public notifyEmailNewConversation?: boolean;
39
+
40
+ @DomainChatSettings.property()
41
+ public notifyEmailNewMessage?: boolean;
42
+ }
@@ -0,0 +1,41 @@
1
+ import { Domain } from './domain.js';
2
+ import { Entity } from '../entity.js';
3
+ import { User } from './user.js';
4
+ import { SupportMessage } from './support_message.js';
5
+
6
+ export class SupportConversation extends Entity {
7
+ protected static resourceName = 'support_conversations';
8
+ protected static singularName = 'supportConversation';
9
+ protected static pluralName = 'supportConversations';
10
+
11
+ @SupportConversation.property()
12
+ public id?: number;
13
+
14
+ @SupportConversation.property({ type: Date })
15
+ public creationDate?: Date | null;
16
+
17
+ @SupportConversation.property({ type: Date })
18
+ public lastMessageAt?: Date | null;
19
+
20
+ @SupportConversation.property()
21
+ public domainId?: number;
22
+
23
+ @SupportConversation.property({ type: Domain })
24
+ public domain?: Domain;
25
+
26
+ @SupportConversation.property()
27
+ public guestId?: string | null;
28
+
29
+ /** Opaque client fingerprint for repeat-visitor / spam correlation (max 512 chars). */
30
+ @SupportConversation.property()
31
+ public clientFingerprint?: string | null;
32
+
33
+ @SupportConversation.property()
34
+ public userId?: number | null;
35
+
36
+ @SupportConversation.property({ type: User })
37
+ public user?: User | null;
38
+
39
+ @SupportConversation.property({ arrayType: 'SupportMessage' })
40
+ public messages?: SupportMessage[];
41
+ }
@@ -0,0 +1,90 @@
1
+ import { Entity, ListResponse } from '../entity.js';
2
+ // eslint-disable-next-line no-unused-vars
3
+ import { RequestOptions } from '../request.js';
4
+ import { User } from './user.js';
5
+
6
+ export class SupportMessage extends Entity {
7
+ protected static resourceName = 'support_messages';
8
+ protected static singularName = 'supportMessage';
9
+ /** Matches API `plural_json_name` (list responses use `supportMessagesList`). */
10
+ protected static pluralName = 'supportMessagesList';
11
+
12
+ @SupportMessage.property()
13
+ public id?: number;
14
+
15
+ @SupportMessage.property()
16
+ public conversationId?: number;
17
+
18
+ @SupportMessage.property()
19
+ public senderType?: string; // 'guest' | 'manager'
20
+
21
+ @SupportMessage.property()
22
+ public user?: User | null;
23
+
24
+ @SupportMessage.property()
25
+ public content?: string;
26
+
27
+ @SupportMessage.property({ type: Date })
28
+ 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
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import { Address } from './entities/address.js';
2
2
  import { AgentConversation } from './entities/agent_conversation.js';
3
+ import { DomainChatSettings } from './entities/domain_chat_settings.js';
4
+ import { SupportConversation } from './entities/support_conversation.js';
5
+ import { SupportMessage } from './entities/support_message.js';
3
6
  import { Assignment } from './entities/assignment.js';
4
7
  import { AutomaticPaymentRelationship } from './entities/automatic_payment_relationship.js';
5
8
  import { Bank } from './entities/bank.js';
@@ -83,6 +86,9 @@ export {
83
86
  toastNotifications,
84
87
  Address,
85
88
  AgentConversation,
89
+ DomainChatSettings,
90
+ SupportConversation,
91
+ SupportMessage,
86
92
  Assignment,
87
93
  AutomaticPaymentRelationship,
88
94
  Bank,
package/src/merchi.ts CHANGED
@@ -72,6 +72,9 @@ import { Variation } from './entities/variation.js';
72
72
  import { CartItem } from './entities/cart_item.js';
73
73
  import { Address } from './entities/address.js';
74
74
  import { AgentConversation } from './entities/agent_conversation.js';
75
+ import { DomainChatSettings } from './entities/domain_chat_settings.js';
76
+ import { SupportConversation } from './entities/support_conversation.js';
77
+ import { SupportMessage } from './entities/support_message.js';
75
78
  import { Assignment } from './entities/assignment.js';
76
79
  import { MatchingInventory } from './entities/matching_inventory.js';
77
80
  import { SubscriptionPlan } from './entities/subscription_plan.js';
@@ -153,6 +156,9 @@ export class Merchi {
153
156
  public Company: typeof Company;
154
157
  public Address: typeof Address;
155
158
  public AgentConversation: typeof AgentConversation;
159
+ public DomainChatSettings: typeof DomainChatSettings;
160
+ public SupportConversation: typeof SupportConversation;
161
+ public SupportMessage: typeof SupportMessage;
156
162
  public ComponentTag: typeof ComponentTag;
157
163
  public Discount: typeof Discount;
158
164
  public DiscountGroup: typeof DiscountGroup;
@@ -324,6 +330,9 @@ export class Merchi {
324
330
  ) as typeof VariationFieldsOption;
325
331
  this.Address = this.setupClass(Address) as typeof Address;
326
332
  this.AgentConversation = this.setupClass(AgentConversation) as typeof AgentConversation;
333
+ this.DomainChatSettings = this.setupClass(DomainChatSettings) as typeof DomainChatSettings;
334
+ this.SupportConversation = this.setupClass(SupportConversation) as typeof SupportConversation;
335
+ this.SupportMessage = this.setupClass(SupportMessage) as typeof SupportMessage;
327
336
  this.Item = this.setupClass(Item) as typeof Item;
328
337
  this.SupplyDomain = this.setupClass(SupplyDomain) as typeof SupplyDomain;
329
338
  this.DomainInvitation = this.setupClass(