@merchi/sdk 1.42.22 → 1.42.24

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.
Files changed (39) hide show
  1. package/dist/constants/index.d.ts +2 -1
  2. package/dist/constants/index.js +2 -1
  3. package/dist/constants/job_followup_types.d.ts +8 -0
  4. package/dist/constants/job_followup_types.js +8 -0
  5. package/dist/constants/job_status.d.ts +4 -0
  6. package/dist/constants/job_status.js +5 -0
  7. package/dist/constants/notification_types.d.ts +5 -1
  8. package/dist/constants/notification_types.js +4 -0
  9. package/dist/entities/domain.d.ts +2 -0
  10. package/dist/entities/domain.js +4 -0
  11. package/dist/entities/invoice.d.ts +15 -0
  12. package/dist/entities/invoice.js +45 -1
  13. package/dist/entities/invoice.test.js +89 -0
  14. package/dist/entities/job.d.ts +12 -0
  15. package/dist/entities/job.js +55 -0
  16. package/dist/entities/job_followup.d.ts +47 -0
  17. package/dist/entities/job_followup.js +114 -0
  18. package/dist/entities/job_followup.test.d.ts +1 -0
  19. package/dist/entities/job_followup.test.js +138 -0
  20. package/dist/entities/job_followup_template.d.ts +20 -0
  21. package/dist/entities/job_followup_template.js +84 -0
  22. package/dist/index.d.ts +4 -1
  23. package/dist/index.js +3 -1
  24. package/dist/merchi.d.ts +4 -0
  25. package/dist/merchi.js +4 -0
  26. package/package.json +1 -1
  27. package/src/constants/index.ts +2 -0
  28. package/src/constants/job_followup_types.ts +9 -0
  29. package/src/constants/job_status.ts +5 -0
  30. package/src/constants/notification_types.ts +4 -0
  31. package/src/entities/domain.ts +4 -0
  32. package/src/entities/invoice.test.ts +39 -0
  33. package/src/entities/invoice.ts +42 -0
  34. package/src/entities/job.ts +61 -0
  35. package/src/entities/job_followup.test.ts +99 -0
  36. package/src/entities/job_followup.ts +91 -0
  37. package/src/entities/job_followup_template.ts +45 -0
  38. package/src/index.ts +8 -0
  39. package/src/merchi.ts +8 -0
@@ -0,0 +1,138 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { NotificationType } from '../constants/notification_types.js';
38
+ import { JobFollowupType } from '../constants/job_followup_types.js';
39
+ import { Merchi } from '../merchi.js';
40
+ test('job follow-up notification type is 109', function () {
41
+ expect(NotificationType.JOB_FOLLOWUP).toBe(109);
42
+ });
43
+ test('can make a follow-up template', function () {
44
+ var merchi = new Merchi();
45
+ var template = new merchi.JobFollowupTemplate();
46
+ template.fromJson({
47
+ id: 11,
48
+ name: 'Completion',
49
+ followupType: JobFollowupType.COMPLETION,
50
+ defaultKey: 'completion',
51
+ subject: 'Your order is complete',
52
+ body: 'Hi {{client_first_name}}',
53
+ });
54
+ expect(template.name).toBe('Completion');
55
+ expect(template.followupType).toBe(0);
56
+ expect(template.defaultKey).toBe('completion');
57
+ });
58
+ test('job complete posts the follow-up sequence', function () { return __awaiter(void 0, void 0, void 0, function () {
59
+ var merchi, job, fetch, rows, body;
60
+ return __generator(this, function (_a) {
61
+ switch (_a.label) {
62
+ case 0:
63
+ merchi = new Merchi();
64
+ job = new merchi.Job();
65
+ job.id = 85;
66
+ fetch = jest.spyOn(merchi, 'authenticatedFetch').mockResolvedValue({
67
+ jobFollowups: [{
68
+ id: 4,
69
+ jobId: 85,
70
+ templateId: 11,
71
+ templateName: 'Review request',
72
+ followupType: JobFollowupType.REVIEW_REQUEST,
73
+ subject: 'How did we do?',
74
+ sendAt: '2026-11-04T09:00:00Z',
75
+ sendEmail: true,
76
+ sendSms: false,
77
+ status: 'pending',
78
+ sentAt: null,
79
+ }],
80
+ });
81
+ return [4 /*yield*/, job.complete([{
82
+ templateId: 11,
83
+ sendAt: '2026-11-04T09:00',
84
+ timezone: 'Australia/Melbourne',
85
+ sendEmail: true,
86
+ sendSms: false,
87
+ }])];
88
+ case 1:
89
+ rows = _a.sent();
90
+ expect(fetch).toHaveBeenCalledWith('/jobs/85/complete/', expect.objectContaining({ method: 'POST' }));
91
+ body = fetch.mock.calls[0][1].body;
92
+ expect(JSON.parse(String(body.get('followups')))).toEqual([{
93
+ templateId: 11,
94
+ sendAt: '2026-11-04T09:00',
95
+ timezone: 'Australia/Melbourne',
96
+ sendEmail: true,
97
+ sendSms: false,
98
+ }]);
99
+ expect(rows).toHaveLength(1);
100
+ expect(rows[0].sendAt).toBe('2026-11-04T09:00:00Z');
101
+ expect(rows[0].status).toBe('pending');
102
+ expect(rows[0].templateName).toBe('Review request');
103
+ return [2 /*return*/];
104
+ }
105
+ });
106
+ }); });
107
+ test('can update and cancel a pending follow-up', function () { return __awaiter(void 0, void 0, void 0, function () {
108
+ var merchi, job, fetch, updated, cancelled;
109
+ return __generator(this, function (_a) {
110
+ switch (_a.label) {
111
+ case 0:
112
+ merchi = new Merchi();
113
+ job = new merchi.Job();
114
+ job.id = 85;
115
+ fetch = jest.spyOn(merchi, 'authenticatedFetch').mockResolvedValue({
116
+ jobFollowup: {
117
+ id: 4,
118
+ status: 'cancelled',
119
+ sendAt: '2026-12-01T09:00:00Z',
120
+ },
121
+ });
122
+ return [4 /*yield*/, job.updateFollowup(4, {
123
+ sendAt: '2026-12-01T09:00',
124
+ timezone: 'Australia/Melbourne',
125
+ })];
126
+ case 1:
127
+ updated = _a.sent();
128
+ expect(fetch).toHaveBeenCalledWith('/jobs/85/followups/4/', expect.objectContaining({ method: 'PATCH' }));
129
+ expect(updated.sendAt).toBe('2026-12-01T09:00:00Z');
130
+ return [4 /*yield*/, job.cancelFollowup(4)];
131
+ case 2:
132
+ cancelled = _a.sent();
133
+ expect(fetch).toHaveBeenCalledWith('/jobs/85/followups/4/cancel/', expect.objectContaining({ method: 'POST' }));
134
+ expect(cancelled.status).toBe('cancelled');
135
+ return [2 /*return*/];
136
+ }
137
+ });
138
+ }); });
@@ -0,0 +1,20 @@
1
+ import type { Domain } from './domain.js';
2
+ import { Entity } from '../entity.js';
3
+ import type { User } from './user.js';
4
+ export declare class JobFollowupTemplate extends Entity {
5
+ protected static resourceName: string;
6
+ protected static singularName: string;
7
+ protected static pluralName: string;
8
+ archived?: Date | null;
9
+ id?: number;
10
+ name?: string;
11
+ followupType?: number;
12
+ defaultKey?: string | null;
13
+ subject?: string;
14
+ body?: string;
15
+ created?: Date;
16
+ updated?: Date;
17
+ removed?: Date | null;
18
+ domain?: Domain;
19
+ createdBy?: User;
20
+ }
@@ -0,0 +1,84 @@
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 { Entity } from '../entity.js';
26
+ var JobFollowupTemplate = /** @class */ (function (_super) {
27
+ __extends(JobFollowupTemplate, _super);
28
+ function JobFollowupTemplate() {
29
+ return _super !== null && _super.apply(this, arguments) || this;
30
+ }
31
+ JobFollowupTemplate.resourceName = 'job_followup_templates';
32
+ JobFollowupTemplate.singularName = 'jobFollowupTemplate';
33
+ JobFollowupTemplate.pluralName = 'jobFollowupTemplates';
34
+ __decorate([
35
+ JobFollowupTemplate.property({ type: Date }),
36
+ __metadata("design:type", Object)
37
+ ], JobFollowupTemplate.prototype, "archived", void 0);
38
+ __decorate([
39
+ JobFollowupTemplate.property(),
40
+ __metadata("design:type", Number)
41
+ ], JobFollowupTemplate.prototype, "id", void 0);
42
+ __decorate([
43
+ JobFollowupTemplate.property(),
44
+ __metadata("design:type", String)
45
+ ], JobFollowupTemplate.prototype, "name", void 0);
46
+ __decorate([
47
+ JobFollowupTemplate.property(),
48
+ __metadata("design:type", Number)
49
+ ], JobFollowupTemplate.prototype, "followupType", void 0);
50
+ __decorate([
51
+ JobFollowupTemplate.property({ type: String }),
52
+ __metadata("design:type", Object)
53
+ ], JobFollowupTemplate.prototype, "defaultKey", void 0);
54
+ __decorate([
55
+ JobFollowupTemplate.property(),
56
+ __metadata("design:type", String)
57
+ ], JobFollowupTemplate.prototype, "subject", void 0);
58
+ __decorate([
59
+ JobFollowupTemplate.property(),
60
+ __metadata("design:type", String)
61
+ ], JobFollowupTemplate.prototype, "body", void 0);
62
+ __decorate([
63
+ JobFollowupTemplate.property({ type: Date }),
64
+ __metadata("design:type", Date)
65
+ ], JobFollowupTemplate.prototype, "created", void 0);
66
+ __decorate([
67
+ JobFollowupTemplate.property({ type: Date }),
68
+ __metadata("design:type", Date)
69
+ ], JobFollowupTemplate.prototype, "updated", void 0);
70
+ __decorate([
71
+ JobFollowupTemplate.property({ type: Date }),
72
+ __metadata("design:type", Object)
73
+ ], JobFollowupTemplate.prototype, "removed", void 0);
74
+ __decorate([
75
+ JobFollowupTemplate.property({ type: 'Domain' }),
76
+ __metadata("design:type", Function)
77
+ ], JobFollowupTemplate.prototype, "domain", void 0);
78
+ __decorate([
79
+ JobFollowupTemplate.property({ type: 'User' }),
80
+ __metadata("design:type", Function)
81
+ ], JobFollowupTemplate.prototype, "createdBy", void 0);
82
+ return JobFollowupTemplate;
83
+ }(Entity));
84
+ export { JobFollowupTemplate };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { Address } from './entities/address.js';
2
2
  import { AgentConversation } from './entities/agent_conversation.js';
3
3
  import { AgentTokenUsage } from './entities/agent_token_usage.js';
4
4
  export type { AgentTokenAnalyticsSummary, AgentTokenAnalyticsTimeseries, AgentTokenUsageRecordPayload, AgentTokenUsageRecordResponse, CompanyAnalyticsResponse, DomainAnalyticsResponse, ProfileAnalyticsSummaryMetric, } from './entities/agent_token_analytics.js';
5
+ export type { JobFollowupUpdate, ScheduledJobFollowup, } from './entities/job_followup.js';
5
6
  import { AgentSkill } from './entities/agent_skill.js';
6
7
  import { AgentSkillVersion } from './entities/agent_skill_version.js';
7
8
  import { AgentSkillApproval } from './entities/agent_skill_approval.js';
@@ -41,6 +42,8 @@ import { Invoice } from './entities/invoice.js';
41
42
  import { Item } from './entities/item.js';
42
43
  import { Job } from './entities/job.js';
43
44
  import { JobComment } from './entities/job_comment.js';
45
+ import { JobFollowup } from './entities/job_followup.js';
46
+ import { JobFollowupTemplate } from './entities/job_followup_template.js';
44
47
  import { JobNote } from './entities/job_note.js';
45
48
  import { JobOperationLog } from './entities/job_operation_log.js';
46
49
  import { MatchingInventory } from './entities/matching_inventory.js';
@@ -85,4 +88,4 @@ import * as request from './request.js';
85
88
  import * as util from './util/index.js';
86
89
  import * as pricing from './pricing/index.js';
87
90
  import { toastNotifications } from './toasts.js';
88
- export { constants, request, util, pricing, toastNotifications, Address, AgentConversation, AgentTokenUsage, AgentSkill, AgentSkillVersion, AgentSkillApproval, DomainChatSettings, SupportConversation, SupportMessage, Assignment, AutomaticPaymentRelationship, Bank, Cart, CartItem, CartShipmentGroup, CartShipmentQuote, Category, Company, CompanyInvitation, ProductForm, ProductFormVersion, CountryTax, Discount, DiscountGroup, Domain, DomainInvitation, DomainTag, Draft, DraftComment, DraftTemplate, EmailAddress, EmailCounter, EnrolledDomain, Entity, EmbedDescriptor, ExchangeRate, InternalTag, Inventory, InventoryUnitVariation, Invoice, Item, Job, JobComment, JobNote, JobOperationLog, MatchingInventory, Merchi, MerchiFile, Notification, Payment, PaymentDevice, PhoneNumber, Product, ProductReview, ProductionComment, Quote, QuoteItem, Reminder, RequestOptions, apiFetch, apiFetchWithProgress, Session, Shipment, ShipmentLog, ShipmentItem, ShipmentItemFulfillment, ShipmentMethod, ShipmentMethodVariation, ShortUrl, SubscriptionPlan, SupplyDomain, SystemRole, Theme, ThemeCssSetting, User, UserCompany, Variation, VariationField, VariationFieldsOption, VariationOption, VariationsGroup, generateUUID, getCookie };
91
+ export { constants, request, util, pricing, toastNotifications, Address, AgentConversation, AgentTokenUsage, AgentSkill, AgentSkillVersion, AgentSkillApproval, DomainChatSettings, SupportConversation, SupportMessage, Assignment, AutomaticPaymentRelationship, Bank, Cart, CartItem, CartShipmentGroup, CartShipmentQuote, Category, Company, CompanyInvitation, ProductForm, ProductFormVersion, CountryTax, Discount, DiscountGroup, Domain, DomainInvitation, DomainTag, Draft, DraftComment, DraftTemplate, EmailAddress, EmailCounter, EnrolledDomain, Entity, EmbedDescriptor, ExchangeRate, InternalTag, Inventory, InventoryUnitVariation, Invoice, Item, Job, JobComment, JobFollowup, JobFollowupTemplate, JobNote, JobOperationLog, MatchingInventory, Merchi, MerchiFile, Notification, Payment, PaymentDevice, PhoneNumber, Product, ProductReview, ProductionComment, Quote, QuoteItem, Reminder, RequestOptions, apiFetch, apiFetchWithProgress, Session, Shipment, ShipmentLog, ShipmentItem, ShipmentItemFulfillment, ShipmentMethod, ShipmentMethodVariation, ShortUrl, SubscriptionPlan, SupplyDomain, SystemRole, Theme, ThemeCssSetting, User, UserCompany, Variation, VariationField, VariationFieldsOption, VariationOption, VariationsGroup, generateUUID, getCookie };
package/dist/index.js CHANGED
@@ -40,6 +40,8 @@ import { Invoice } from './entities/invoice.js';
40
40
  import { Item } from './entities/item.js';
41
41
  import { Job } from './entities/job.js';
42
42
  import { JobComment } from './entities/job_comment.js';
43
+ import { JobFollowup } from './entities/job_followup.js';
44
+ import { JobFollowupTemplate } from './entities/job_followup_template.js';
43
45
  import { JobNote } from './entities/job_note.js';
44
46
  import { JobOperationLog } from './entities/job_operation_log.js';
45
47
  import { MatchingInventory } from './entities/matching_inventory.js';
@@ -83,4 +85,4 @@ import * as request from './request.js';
83
85
  import * as util from './util/index.js';
84
86
  import * as pricing from './pricing/index.js';
85
87
  import { toastNotifications } from './toasts.js';
86
- export { constants, request, util, pricing, toastNotifications, Address, AgentConversation, AgentTokenUsage, AgentSkill, AgentSkillVersion, AgentSkillApproval, DomainChatSettings, SupportConversation, SupportMessage, Assignment, AutomaticPaymentRelationship, Bank, Cart, CartItem, CartShipmentGroup, CartShipmentQuote, Category, Company, CompanyInvitation, ProductForm, ProductFormVersion, CountryTax, Discount, DiscountGroup, Domain, DomainInvitation, DomainTag, Draft, DraftComment, DraftTemplate, EmailAddress, EmailCounter, EnrolledDomain, Entity, ExchangeRate, InternalTag, Inventory, InventoryUnitVariation, Invoice, Item, Job, JobComment, JobNote, JobOperationLog, MatchingInventory, Merchi, MerchiFile, Notification, Payment, PaymentDevice, PhoneNumber, Product, ProductReview, ProductionComment, Quote, QuoteItem, Reminder, apiFetch, apiFetchWithProgress, Session, Shipment, ShipmentLog, ShipmentItem, ShipmentItemFulfillment, ShipmentMethod, ShipmentMethodVariation, ShortUrl, SubscriptionPlan, SupplyDomain, SystemRole, Theme, ThemeCssSetting, User, UserCompany, Variation, VariationField, VariationFieldsOption, VariationOption, VariationsGroup, generateUUID, getCookie };
88
+ export { constants, request, util, pricing, toastNotifications, Address, AgentConversation, AgentTokenUsage, AgentSkill, AgentSkillVersion, AgentSkillApproval, DomainChatSettings, SupportConversation, SupportMessage, Assignment, AutomaticPaymentRelationship, Bank, Cart, CartItem, CartShipmentGroup, CartShipmentQuote, Category, Company, CompanyInvitation, ProductForm, ProductFormVersion, CountryTax, Discount, DiscountGroup, Domain, DomainInvitation, DomainTag, Draft, DraftComment, DraftTemplate, EmailAddress, EmailCounter, EnrolledDomain, Entity, ExchangeRate, InternalTag, Inventory, InventoryUnitVariation, Invoice, Item, Job, JobComment, JobFollowup, JobFollowupTemplate, JobNote, JobOperationLog, MatchingInventory, Merchi, MerchiFile, Notification, Payment, PaymentDevice, PhoneNumber, Product, ProductReview, ProductionComment, Quote, QuoteItem, Reminder, apiFetch, apiFetchWithProgress, Session, Shipment, ShipmentLog, ShipmentItem, ShipmentItemFulfillment, ShipmentMethod, ShipmentMethodVariation, ShortUrl, SubscriptionPlan, SupplyDomain, SystemRole, Theme, ThemeCssSetting, User, UserCompany, Variation, VariationField, VariationFieldsOption, VariationOption, VariationsGroup, generateUUID, getCookie };
package/dist/merchi.d.ts CHANGED
@@ -2,6 +2,8 @@ import { Entity, EmbedDescriptor } from './entity.js';
2
2
  import { AutomaticPaymentRelationship } from './entities/automatic_payment_relationship.js';
3
3
  import { Session } from './entities/session.js';
4
4
  import { JobComment } from './entities/job_comment.js';
5
+ import { JobFollowup } from './entities/job_followup.js';
6
+ import { JobFollowupTemplate } from './entities/job_followup_template.js';
5
7
  import { JobNote } from './entities/job_note.js';
6
8
  import { JobOperationLog } from './entities/job_operation_log.js';
7
9
  import { Domain } from './entities/domain.js';
@@ -105,6 +107,8 @@ export declare class Merchi {
105
107
  Inventory: typeof Inventory;
106
108
  InventoryGroup: typeof InventoryGroup;
107
109
  JobComment: typeof JobComment;
110
+ JobFollowup: typeof JobFollowup;
111
+ JobFollowupTemplate: typeof JobFollowupTemplate;
108
112
  JobNote: typeof JobNote;
109
113
  JobOperationLog: typeof JobOperationLog;
110
114
  VariationOption: typeof VariationOption;
package/dist/merchi.js CHANGED
@@ -12,6 +12,8 @@ var __assign = (this && this.__assign) || function () {
12
12
  import { AutomaticPaymentRelationship } from './entities/automatic_payment_relationship.js';
13
13
  import { Session } from './entities/session.js';
14
14
  import { JobComment } from './entities/job_comment.js';
15
+ import { JobFollowup } from './entities/job_followup.js';
16
+ import { JobFollowupTemplate } from './entities/job_followup_template.js';
15
17
  import { JobNote } from './entities/job_note.js';
16
18
  import { JobOperationLog } from './entities/job_operation_log.js';
17
19
  import { Domain } from './entities/domain.js';
@@ -280,6 +282,8 @@ var Merchi = /** @class */ (function () {
280
282
  this.MerchiFile = this.setupClass(MerchiFile);
281
283
  this.User = this.setupClass(User);
282
284
  this.JobComment = this.setupClass(JobComment);
285
+ this.JobFollowup = this.setupClass(JobFollowup);
286
+ this.JobFollowupTemplate = this.setupClass(JobFollowupTemplate);
283
287
  this.JobNote = this.setupClass(JobNote);
284
288
  this.JobOperationLog = this.setupClass(JobOperationLog);
285
289
  this.VariationOption = this.setupClass(VariationOption);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@merchi/sdk",
3
- "version": "1.42.22",
3
+ "version": "1.42.24",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -17,6 +17,7 @@ import * as production_status from './job/production_status.js';
17
17
  import * as shipment_status from './job/shipment_status.js';
18
18
  import * as call_to_actions from './call_to_actions.js';
19
19
  import * as domain_types from './domain_types.js';
20
+ import * as job_followup_types from './job_followup_types.js';
20
21
  import * as job_status from './job_status.js';
21
22
  import * as white_label_accessibilities from './white_label_accessibilities.js';
22
23
  import * as robots_meta_directives from './robots_meta_directives.js';
@@ -41,6 +42,7 @@ export {
41
42
  auto_assign_production_on_actions,
42
43
  product_types,
43
44
  drafting_status,
45
+ job_followup_types,
44
46
  job_types,
45
47
  payment_status,
46
48
  production_status,
@@ -0,0 +1,9 @@
1
+ export enum JobFollowupType {
2
+ COMPLETION = 0,
3
+ REVIEW_REQUEST = 1,
4
+ REORDER = 2,
5
+ FEEDBACK = 3,
6
+ CUSTOM = 4,
7
+ }
8
+
9
+ export type JobFollowupStatus = 'pending' | 'sent' | 'cancelled' | 'failed';
@@ -14,6 +14,11 @@ export enum PaymentStatus {
14
14
  FULLY_PAID = 4,
15
15
  }
16
16
 
17
+ export enum InvoiceQuoteStatus {
18
+ ISSUED = 'issued',
19
+ DECLINED = 'declined',
20
+ }
21
+
17
22
  export enum ProductionStatus {
18
23
  INIT = 0,
19
24
  REJECTED = 1,
@@ -98,4 +98,8 @@ export enum NotificationType {
98
98
  REFERRER_JOB_PAID = 106,
99
99
  REFERRER_JOB_RECEIVED = 107,
100
100
  FULFILLMENT_PARTNER_INVITED = 108,
101
+ JOB_FOLLOWUP = 109,
102
+ SEND_QUOTE = 110,
103
+ QUOTE_INVOICE_APPROVED = 111,
104
+ QUOTE_INVOICE_DECLINED = 112,
101
105
  }
@@ -16,6 +16,7 @@ import { Job } from './job.js';
16
16
  import { User } from './user.js';
17
17
  import { Notification } from './notification.js';
18
18
  import { Product } from './product.js';
19
+ import { JobFollowupTemplate } from './job_followup_template.js';
19
20
  import { Reminder } from './reminder.js';
20
21
  import { Session } from './session.js';
21
22
  import { SupplyDomain } from './supply_domain.js';
@@ -684,6 +685,9 @@ export class Domain extends Entity {
684
685
  @Domain.property({arrayType: 'Reminder'})
685
686
  public reminders?: Reminder[];
686
687
 
688
+ @Domain.property({arrayType: 'JobFollowupTemplate'})
689
+ public jobFollowupTemplates?: JobFollowupTemplate[];
690
+
687
691
  @Domain.property({arrayType: 'Product'})
688
692
  public products?: Product[];
689
693
 
@@ -42,6 +42,45 @@ test('client and invoice tokens supported by merchi', () => {
42
42
  return invocation;
43
43
  });
44
44
 
45
+ test('reads quote fields', () => {
46
+ const merchi = new Merchi();
47
+ const invoice = new merchi.Invoice();
48
+ invoice.fromJson({
49
+ id: 1,
50
+ isQuote: true,
51
+ quoteDeclinedDate: 1761700000,
52
+ quoteDeclineReason: 'Too expensive',
53
+ });
54
+ expect(invoice.isQuote).toBe(true);
55
+ expect(invoice.quoteDeclinedDate).toBeInstanceOf(Date);
56
+ expect(invoice.quoteDeclineReason).toBe('Too expensive');
57
+ });
58
+
59
+ test('approveQuote posts to approve_quote with the invoice token', async () => {
60
+ const merchi = new Merchi(undefined, undefined, 'i');
61
+ const fetch = mockFetch(
62
+ true, {invoice: {id: 1, isQuote: false}, paymentUrl: 'https://pay'}, 200);
63
+ const invoice = new merchi.Invoice();
64
+ invoice.id = 1;
65
+ invoice.isQuote = true;
66
+ const result = await invoice.approveQuote();
67
+ expect(fetch.mock.calls[0][0]).toContain('/invoices/1/approve_quote/');
68
+ expect(fetch.mock.calls[0][1]['method']).toBe('POST');
69
+ expect(fetch.mock.calls[0][1]['query']).toContainEqual(['invoice_token', 'i']);
70
+ expect(result.paymentUrl).toBe('https://pay');
71
+ expect(invoice.isQuote).toBe(false);
72
+ });
73
+
74
+ test('declineQuote sends the reason', async () => {
75
+ const merchi = new Merchi();
76
+ const fetch = mockFetch(true, {invoice: {id: 1}, paymentUrl: ''}, 200);
77
+ const invoice = new merchi.Invoice();
78
+ invoice.id = 1;
79
+ await invoice.declineQuote('Too expensive');
80
+ expect(fetch.mock.calls[0][0]).toContain('/invoices/1/decline_quote/');
81
+ expect(fetch.mock.calls[0][1]['body'].get('reason')).toBe('Too expensive');
82
+ });
83
+
45
84
  test('preserves server payment engine hint', () => {
46
85
  const merchi = new Merchi();
47
86
  const entity = new merchi.Invoice();
@@ -16,6 +16,7 @@ import { Payment } from './payment.js';
16
16
  import { PhoneNumber } from './phone_number.js';
17
17
  import { Shipment } from './shipment.js';
18
18
  import { User } from './user.js';
19
+ import { RequestOptions } from '../request.js';
19
20
 
20
21
  export class Invoice extends Entity {
21
22
  protected static resourceName = 'invoices';
@@ -85,6 +86,18 @@ export class Invoice extends Entity {
85
86
  @Invoice.property({type: Boolean})
86
87
  public isTest?: boolean | null;
87
88
 
89
+ @Invoice.property({type: Boolean})
90
+ public isQuote?: boolean | null;
91
+
92
+ @Invoice.property({type: Date})
93
+ public quoteApprovedDate?: Date | null;
94
+
95
+ @Invoice.property({type: Date})
96
+ public quoteDeclinedDate?: Date | null;
97
+
98
+ @Invoice.property({type: String})
99
+ public quoteDeclineReason?: string | null;
100
+
88
101
  @Invoice.property()
89
102
  public currency?: string;
90
103
 
@@ -130,6 +143,9 @@ export class Invoice extends Entity {
130
143
  @Invoice.property({type: User})
131
144
  public creator?: User | null;
132
145
 
146
+ @Invoice.property({type: User})
147
+ public quoteApprovedBy?: User | null;
148
+
133
149
  @Invoice.property()
134
150
  public client?: User;
135
151
 
@@ -192,4 +208,30 @@ export class Invoice extends Entity {
192
208
 
193
209
  @Invoice.property({arrayType: 'Payment'})
194
210
  public payments?: Payment[];
211
+
212
+ private respondToQuote = (action: 'approve' | 'decline', reason?: string) => {
213
+ if (this.id === undefined || this.id === null) {
214
+ throw new Error('id is undefined, did you forget to set it?');
215
+ }
216
+ const resource = `/invoices/${this.id}/${action}_quote/`;
217
+ const data = new FormData();
218
+ if (reason) {
219
+ data.append('reason', reason);
220
+ }
221
+ const fetchOptions: RequestOptions = {method: 'POST', body: data, query: []};
222
+ return this.merchi.authenticatedFetch(resource, fetchOptions).
223
+ then((payload: any) => {
224
+ this.fromJson(payload.invoice);
225
+ return {invoice: this, paymentUrl: payload.paymentUrl as string};
226
+ });
227
+ };
228
+
229
+ /** Approving a quote turns it into a payable invoice. */
230
+ public approveQuote = (): Promise<{invoice: Invoice; paymentUrl: string}> =>
231
+ this.respondToQuote('approve');
232
+
233
+ public declineQuote = (
234
+ reason?: string
235
+ ): Promise<{invoice: Invoice; paymentUrl: string}> =>
236
+ this.respondToQuote('decline', reason);
195
237
  }
@@ -13,6 +13,7 @@ import { MatchingInventory } from './matching_inventory.js';
13
13
  import { InternalTag } from './internal_tag.js';
14
14
  import { Invoice } from './invoice.js';
15
15
  import { JobComment } from './job_comment.js';
16
+ import { JobFollowup, JobFollowupUpdate, ScheduledJobFollowup } from './job_followup.js';
16
17
  import { JobNote } from './job_note.js';
17
18
  import { JobOperationLog } from './job_operation_log.js';
18
19
  import { Notification } from './notification.js';
@@ -25,6 +26,7 @@ import { User } from './user.js';
25
26
  import { Variation } from './variation.js';
26
27
  import { VariationsGroup } from './variations_group.js';
27
28
  import { InventoryStatus } from '../constants/inventory_statuses.js';
29
+ import { InvoiceQuoteStatus } from '../constants/job_status.js';
28
30
  import { Item } from './item.js';
29
31
 
30
32
 
@@ -132,6 +134,10 @@ export class Job extends Entity {
132
134
  @Job.property({type: Number})
133
135
  public paymentStatus?: number | null;
134
136
 
137
+ /** Set while the job's invoice is still a quote; paymentStatus stays INIT. */
138
+ @Job.property({type: String})
139
+ public invoiceQuoteStatus?: InvoiceQuoteStatus | null;
140
+
135
141
  @Job.property({type: Date})
136
142
  public deductionDate?: Date | null;
137
143
 
@@ -375,6 +381,9 @@ export class Job extends Entity {
375
381
  @Job.property({arrayType: 'Reminder'})
376
382
  public reminders?: Reminder[];
377
383
 
384
+ @Job.property({arrayType: 'JobFollowup'})
385
+ public jobFollowups?: JobFollowup[];
386
+
378
387
  @Job.property()
379
388
  public supplyAssignment?: Assignment;
380
389
 
@@ -440,4 +449,56 @@ export class Job extends Entity {
440
449
  }
441
450
  return this.deduct(this.matchingInventories);
442
451
  };
452
+
453
+ private jobResourceId = () => {
454
+ if (this.id === undefined || this.id === null) {
455
+ throw new Error('id is undefined, did you forget to set it?');
456
+ }
457
+ return this.id;
458
+ };
459
+
460
+ private readFollowups = (data: any): JobFollowup[] => {
461
+ const rows = data?.jobFollowups ?? [];
462
+ return rows.map((row: any) => new this.merchi.JobFollowup().fromJson(row));
463
+ };
464
+
465
+ private readFollowup = (data: any): JobFollowup => {
466
+ return new this.merchi.JobFollowup().fromJson(data?.jobFollowup ?? data);
467
+ };
468
+
469
+ public listFollowups = () => {
470
+ const resource = `/jobs/${this.jobResourceId()}/followups/`;
471
+ const fetchOptions: RequestOptions = {method: 'GET', query: []};
472
+ return this.merchi.authenticatedFetch(resource, fetchOptions).
473
+ then((data: any) => this.readFollowups(data));
474
+ };
475
+
476
+ public complete = (followups: ScheduledJobFollowup[] = []) => {
477
+ const resource = `/jobs/${this.jobResourceId()}/complete/`;
478
+ const data = new FormData();
479
+ data.append('followups', JSON.stringify(followups));
480
+ const fetchOptions: RequestOptions = {method: 'POST', body: data, query: []};
481
+ return this.merchi.authenticatedFetch(resource, fetchOptions).
482
+ then((payload: any) => this.readFollowups(payload));
483
+ };
484
+
485
+ public updateFollowup = (followupId: number, changes: JobFollowupUpdate) => {
486
+ const resource = `/jobs/${this.jobResourceId()}/followups/${followupId}/`;
487
+ const fetchOptions: RequestOptions = {
488
+ method: 'PATCH',
489
+ headers: {'Content-Type': 'application/json'},
490
+ body: JSON.stringify(changes),
491
+ query: [],
492
+ };
493
+ return this.merchi.authenticatedFetch(resource, fetchOptions).
494
+ then((data: any) => this.readFollowup(data));
495
+ };
496
+
497
+ public cancelFollowup = (followupId: number) => {
498
+ const resource =
499
+ `/jobs/${this.jobResourceId()}/followups/${followupId}/cancel/`;
500
+ const fetchOptions: RequestOptions = {method: 'POST', query: []};
501
+ return this.merchi.authenticatedFetch(resource, fetchOptions).
502
+ then((data: any) => this.readFollowup(data));
503
+ };
443
504
  }