@merchi/sdk 1.42.22 → 1.42.23

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.
@@ -17,9 +17,10 @@ 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';
23
24
  import * as inventory_statuses from './inventory_statuses.js';
24
25
  import * as discount_types from './discount_types.js';
25
- export { discount_types, field_types, input_types, inventory_statuses, platform, robots_meta_directives, system_roles, user_types, white_label_accessibilities, roles, notification_sections, notification_types, shipment_services, shipment_companies, auto_assign_production_on_actions, product_types, drafting_status, job_types, payment_status, production_status, shipment_status, call_to_actions, domain_types, job_status, };
26
+ export { discount_types, field_types, input_types, inventory_statuses, platform, robots_meta_directives, system_roles, user_types, white_label_accessibilities, roles, notification_sections, notification_types, shipment_services, shipment_companies, auto_assign_production_on_actions, product_types, drafting_status, job_followup_types, job_types, payment_status, production_status, shipment_status, call_to_actions, domain_types, job_status, };
@@ -17,9 +17,10 @@ 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';
23
24
  import * as inventory_statuses from './inventory_statuses.js';
24
25
  import * as discount_types from './discount_types.js';
25
- export { discount_types, field_types, input_types, inventory_statuses, platform, robots_meta_directives, system_roles, user_types, white_label_accessibilities, roles, notification_sections, notification_types, shipment_services, shipment_companies, auto_assign_production_on_actions, product_types, drafting_status, job_types, payment_status, production_status, shipment_status, call_to_actions, domain_types, job_status, };
26
+ export { discount_types, field_types, input_types, inventory_statuses, platform, robots_meta_directives, system_roles, user_types, white_label_accessibilities, roles, notification_sections, notification_types, shipment_services, shipment_companies, auto_assign_production_on_actions, product_types, drafting_status, job_followup_types, job_types, payment_status, production_status, shipment_status, call_to_actions, domain_types, job_status, };
@@ -0,0 +1,8 @@
1
+ export declare enum JobFollowupType {
2
+ COMPLETION = 0,
3
+ REVIEW_REQUEST = 1,
4
+ REORDER = 2,
5
+ FEEDBACK = 3,
6
+ CUSTOM = 4
7
+ }
8
+ export type JobFollowupStatus = 'pending' | 'sent' | 'cancelled' | 'failed';
@@ -0,0 +1,8 @@
1
+ export var JobFollowupType;
2
+ (function (JobFollowupType) {
3
+ JobFollowupType[JobFollowupType["COMPLETION"] = 0] = "COMPLETION";
4
+ JobFollowupType[JobFollowupType["REVIEW_REQUEST"] = 1] = "REVIEW_REQUEST";
5
+ JobFollowupType[JobFollowupType["REORDER"] = 2] = "REORDER";
6
+ JobFollowupType[JobFollowupType["FEEDBACK"] = 3] = "FEEDBACK";
7
+ JobFollowupType[JobFollowupType["CUSTOM"] = 4] = "CUSTOM";
8
+ })(JobFollowupType || (JobFollowupType = {}));
@@ -97,5 +97,6 @@ export declare enum NotificationType {
97
97
  REFERRER_ASSIGNED = 105,
98
98
  REFERRER_JOB_PAID = 106,
99
99
  REFERRER_JOB_RECEIVED = 107,
100
- FULFILLMENT_PARTNER_INVITED = 108
100
+ FULFILLMENT_PARTNER_INVITED = 108,
101
+ JOB_FOLLOWUP = 109
101
102
  }
@@ -99,4 +99,5 @@ export var NotificationType;
99
99
  NotificationType[NotificationType["REFERRER_JOB_PAID"] = 106] = "REFERRER_JOB_PAID";
100
100
  NotificationType[NotificationType["REFERRER_JOB_RECEIVED"] = 107] = "REFERRER_JOB_RECEIVED";
101
101
  NotificationType[NotificationType["FULFILLMENT_PARTNER_INVITED"] = 108] = "FULFILLMENT_PARTNER_INVITED";
102
+ NotificationType[NotificationType["JOB_FOLLOWUP"] = 109] = "JOB_FOLLOWUP";
102
103
  })(NotificationType || (NotificationType = {}));
@@ -13,6 +13,7 @@ import { Job } from './job.js';
13
13
  import { User } from './user.js';
14
14
  import { Notification } from './notification.js';
15
15
  import { Product } from './product.js';
16
+ import { JobFollowupTemplate } from './job_followup_template.js';
16
17
  import { Reminder } from './reminder.js';
17
18
  import { Session } from './session.js';
18
19
  import { SupplyDomain } from './supply_domain.js';
@@ -493,6 +494,7 @@ export declare class Domain extends Entity {
493
494
  categories?: Category[];
494
495
  notifications?: Notification[];
495
496
  reminders?: Reminder[];
497
+ jobFollowupTemplates?: JobFollowupTemplate[];
496
498
  products?: Product[];
497
499
  supplyProducts?: SupplyDomain[];
498
500
  jobs?: Job[];
@@ -530,6 +530,10 @@ var Domain = /** @class */ (function (_super) {
530
530
  Domain.property({ arrayType: 'Reminder' }),
531
531
  __metadata("design:type", Array)
532
532
  ], Domain.prototype, "reminders", void 0);
533
+ __decorate([
534
+ Domain.property({ arrayType: 'JobFollowupTemplate' }),
535
+ __metadata("design:type", Array)
536
+ ], Domain.prototype, "jobFollowupTemplates", void 0);
533
537
  __decorate([
534
538
  Domain.property({ arrayType: 'Product' }),
535
539
  __metadata("design:type", Array)
@@ -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';
@@ -143,6 +144,7 @@ export declare class Job extends Entity {
143
144
  notifications?: Notification[];
144
145
  assignments?: Assignment[];
145
146
  reminders?: Reminder[];
147
+ jobFollowups?: JobFollowup[];
146
148
  supplyAssignment?: Assignment;
147
149
  supplyJob?: Job;
148
150
  supplyQuoteTotalCost?: number;
@@ -153,4 +155,11 @@ export declare class Job extends Entity {
153
155
  getQuote: () => Promise<this>;
154
156
  deduct: (matchingInventories: MatchingInventory[]) => Promise<this>;
155
157
  bulkDeduct: () => Promise<this>;
158
+ private jobResourceId;
159
+ private readFollowups;
160
+ private readFollowup;
161
+ listFollowups: () => Promise<JobFollowup[]>;
162
+ complete: (followups?: ScheduledJobFollowup[]) => Promise<JobFollowup[]>;
163
+ updateFollowup: (followupId: number, changes: JobFollowupUpdate) => Promise<JobFollowup>;
164
+ cancelFollowup: (followupId: number) => Promise<JobFollowup>;
156
165
  }
@@ -81,6 +81,53 @@ var Job = /** @class */ (function (_super) {
81
81
  }
82
82
  return _this.deduct(_this.matchingInventories);
83
83
  };
84
+ _this.jobResourceId = function () {
85
+ if (_this.id === undefined || _this.id === null) {
86
+ throw new Error('id is undefined, did you forget to set it?');
87
+ }
88
+ return _this.id;
89
+ };
90
+ _this.readFollowups = function (data) {
91
+ var _a;
92
+ var rows = (_a = data === null || data === void 0 ? void 0 : data.jobFollowups) !== null && _a !== void 0 ? _a : [];
93
+ return rows.map(function (row) { return new _this.merchi.JobFollowup().fromJson(row); });
94
+ };
95
+ _this.readFollowup = function (data) {
96
+ var _a;
97
+ return new _this.merchi.JobFollowup().fromJson((_a = data === null || data === void 0 ? void 0 : data.jobFollowup) !== null && _a !== void 0 ? _a : data);
98
+ };
99
+ _this.listFollowups = function () {
100
+ var resource = "/jobs/".concat(_this.jobResourceId(), "/followups/");
101
+ var fetchOptions = { method: 'GET', query: [] };
102
+ return _this.merchi.authenticatedFetch(resource, fetchOptions).
103
+ then(function (data) { return _this.readFollowups(data); });
104
+ };
105
+ _this.complete = function (followups) {
106
+ if (followups === void 0) { followups = []; }
107
+ var resource = "/jobs/".concat(_this.jobResourceId(), "/complete/");
108
+ var data = new FormData();
109
+ data.append('followups', JSON.stringify(followups));
110
+ var fetchOptions = { method: 'POST', body: data, query: [] };
111
+ return _this.merchi.authenticatedFetch(resource, fetchOptions).
112
+ then(function (payload) { return _this.readFollowups(payload); });
113
+ };
114
+ _this.updateFollowup = function (followupId, changes) {
115
+ var resource = "/jobs/".concat(_this.jobResourceId(), "/followups/").concat(followupId, "/");
116
+ var fetchOptions = {
117
+ method: 'PATCH',
118
+ headers: { 'Content-Type': 'application/json' },
119
+ body: JSON.stringify(changes),
120
+ query: [],
121
+ };
122
+ return _this.merchi.authenticatedFetch(resource, fetchOptions).
123
+ then(function (data) { return _this.readFollowup(data); });
124
+ };
125
+ _this.cancelFollowup = function (followupId) {
126
+ var resource = "/jobs/".concat(_this.jobResourceId(), "/followups/").concat(followupId, "/cancel/");
127
+ var fetchOptions = { method: 'POST', query: [] };
128
+ return _this.merchi.authenticatedFetch(resource, fetchOptions).
129
+ then(function (data) { return _this.readFollowup(data); });
130
+ };
84
131
  return _this;
85
132
  }
86
133
  Job.resourceName = 'jobs';
@@ -542,6 +589,10 @@ var Job = /** @class */ (function (_super) {
542
589
  Job.property({ arrayType: 'Reminder' }),
543
590
  __metadata("design:type", Array)
544
591
  ], Job.prototype, "reminders", void 0);
592
+ __decorate([
593
+ Job.property({ arrayType: 'JobFollowup' }),
594
+ __metadata("design:type", Array)
595
+ ], Job.prototype, "jobFollowups", void 0);
545
596
  __decorate([
546
597
  Job.property(),
547
598
  __metadata("design:type", Assignment)
@@ -0,0 +1,47 @@
1
+ import type { Domain } from './domain.js';
2
+ import { Entity } from '../entity.js';
3
+ import type { Job } from './job.js';
4
+ import type { JobFollowupTemplate } from './job_followup_template.js';
5
+ import type { JobFollowupStatus } from '../constants/job_followup_types.js';
6
+ import type { User } from './user.js';
7
+ export interface ScheduledJobFollowup {
8
+ templateId: number;
9
+ sendAt: string;
10
+ timezone: string;
11
+ sendEmail: boolean;
12
+ sendSms: boolean;
13
+ subject?: string;
14
+ body?: string;
15
+ }
16
+ export interface JobFollowupUpdate {
17
+ sendAt?: string;
18
+ timezone?: string;
19
+ sendEmail?: boolean;
20
+ sendSms?: boolean;
21
+ subject?: string;
22
+ body?: string;
23
+ }
24
+ export declare class JobFollowup extends Entity {
25
+ protected static resourceName: string;
26
+ protected static singularName: string;
27
+ protected static pluralName: string;
28
+ id?: number;
29
+ jobId?: number;
30
+ domainId?: number;
31
+ templateId?: number | null;
32
+ templateName?: string;
33
+ followupType?: number;
34
+ subject?: string;
35
+ body?: string;
36
+ sendAt?: string;
37
+ sendEmail?: boolean;
38
+ sendSms?: boolean;
39
+ status?: JobFollowupStatus;
40
+ sentAt?: string | null;
41
+ lastError?: string | null;
42
+ created?: Date;
43
+ job?: Job;
44
+ domain?: Domain;
45
+ template?: JobFollowupTemplate;
46
+ createdBy?: User;
47
+ }
@@ -0,0 +1,114 @@
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 JobFollowup = /** @class */ (function (_super) {
27
+ __extends(JobFollowup, _super);
28
+ function JobFollowup() {
29
+ return _super !== null && _super.apply(this, arguments) || this;
30
+ }
31
+ // Scheduled rows are listed and updated under /jobs/<id>/followups/,
32
+ // not this collection path.
33
+ JobFollowup.resourceName = 'job_followups';
34
+ JobFollowup.singularName = 'jobFollowup';
35
+ JobFollowup.pluralName = 'jobFollowups';
36
+ __decorate([
37
+ JobFollowup.property(),
38
+ __metadata("design:type", Number)
39
+ ], JobFollowup.prototype, "id", void 0);
40
+ __decorate([
41
+ JobFollowup.property(),
42
+ __metadata("design:type", Number)
43
+ ], JobFollowup.prototype, "jobId", void 0);
44
+ __decorate([
45
+ JobFollowup.property(),
46
+ __metadata("design:type", Number)
47
+ ], JobFollowup.prototype, "domainId", void 0);
48
+ __decorate([
49
+ JobFollowup.property({ type: Number }),
50
+ __metadata("design:type", Object)
51
+ ], JobFollowup.prototype, "templateId", void 0);
52
+ __decorate([
53
+ JobFollowup.property(),
54
+ __metadata("design:type", String)
55
+ ], JobFollowup.prototype, "templateName", void 0);
56
+ __decorate([
57
+ JobFollowup.property(),
58
+ __metadata("design:type", Number)
59
+ ], JobFollowup.prototype, "followupType", void 0);
60
+ __decorate([
61
+ JobFollowup.property(),
62
+ __metadata("design:type", String)
63
+ ], JobFollowup.prototype, "subject", void 0);
64
+ __decorate([
65
+ JobFollowup.property(),
66
+ __metadata("design:type", String)
67
+ ], JobFollowup.prototype, "body", void 0);
68
+ __decorate([
69
+ JobFollowup.property(),
70
+ __metadata("design:type", String)
71
+ ], JobFollowup.prototype, "sendAt", void 0);
72
+ __decorate([
73
+ JobFollowup.property(),
74
+ __metadata("design:type", Boolean)
75
+ ], JobFollowup.prototype, "sendEmail", void 0);
76
+ __decorate([
77
+ JobFollowup.property(),
78
+ __metadata("design:type", Boolean)
79
+ ], JobFollowup.prototype, "sendSms", void 0);
80
+ __decorate([
81
+ JobFollowup.property({ type: String }),
82
+ __metadata("design:type", String)
83
+ ], JobFollowup.prototype, "status", void 0);
84
+ __decorate([
85
+ JobFollowup.property({ type: String }),
86
+ __metadata("design:type", Object)
87
+ ], JobFollowup.prototype, "sentAt", void 0);
88
+ __decorate([
89
+ JobFollowup.property({ type: String }),
90
+ __metadata("design:type", Object)
91
+ ], JobFollowup.prototype, "lastError", void 0);
92
+ __decorate([
93
+ JobFollowup.property({ type: Date }),
94
+ __metadata("design:type", Date)
95
+ ], JobFollowup.prototype, "created", void 0);
96
+ __decorate([
97
+ JobFollowup.property({ type: 'Job' }),
98
+ __metadata("design:type", Function)
99
+ ], JobFollowup.prototype, "job", void 0);
100
+ __decorate([
101
+ JobFollowup.property({ type: 'Domain' }),
102
+ __metadata("design:type", Function)
103
+ ], JobFollowup.prototype, "domain", void 0);
104
+ __decorate([
105
+ JobFollowup.property({ type: 'JobFollowupTemplate' }),
106
+ __metadata("design:type", Function)
107
+ ], JobFollowup.prototype, "template", void 0);
108
+ __decorate([
109
+ JobFollowup.property({ type: 'User' }),
110
+ __metadata("design:type", Function)
111
+ ], JobFollowup.prototype, "createdBy", void 0);
112
+ return JobFollowup;
113
+ }(Entity));
114
+ export { JobFollowup };
@@ -0,0 +1 @@
1
+ export {};
@@ -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.23",
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';
@@ -98,4 +98,5 @@ 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,
101
102
  }
@@ -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
 
@@ -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';
@@ -375,6 +376,9 @@ export class Job extends Entity {
375
376
  @Job.property({arrayType: 'Reminder'})
376
377
  public reminders?: Reminder[];
377
378
 
379
+ @Job.property({arrayType: 'JobFollowup'})
380
+ public jobFollowups?: JobFollowup[];
381
+
378
382
  @Job.property()
379
383
  public supplyAssignment?: Assignment;
380
384
 
@@ -440,4 +444,56 @@ export class Job extends Entity {
440
444
  }
441
445
  return this.deduct(this.matchingInventories);
442
446
  };
447
+
448
+ private jobResourceId = () => {
449
+ if (this.id === undefined || this.id === null) {
450
+ throw new Error('id is undefined, did you forget to set it?');
451
+ }
452
+ return this.id;
453
+ };
454
+
455
+ private readFollowups = (data: any): JobFollowup[] => {
456
+ const rows = data?.jobFollowups ?? [];
457
+ return rows.map((row: any) => new this.merchi.JobFollowup().fromJson(row));
458
+ };
459
+
460
+ private readFollowup = (data: any): JobFollowup => {
461
+ return new this.merchi.JobFollowup().fromJson(data?.jobFollowup ?? data);
462
+ };
463
+
464
+ public listFollowups = () => {
465
+ const resource = `/jobs/${this.jobResourceId()}/followups/`;
466
+ const fetchOptions: RequestOptions = {method: 'GET', query: []};
467
+ return this.merchi.authenticatedFetch(resource, fetchOptions).
468
+ then((data: any) => this.readFollowups(data));
469
+ };
470
+
471
+ public complete = (followups: ScheduledJobFollowup[] = []) => {
472
+ const resource = `/jobs/${this.jobResourceId()}/complete/`;
473
+ const data = new FormData();
474
+ data.append('followups', JSON.stringify(followups));
475
+ const fetchOptions: RequestOptions = {method: 'POST', body: data, query: []};
476
+ return this.merchi.authenticatedFetch(resource, fetchOptions).
477
+ then((payload: any) => this.readFollowups(payload));
478
+ };
479
+
480
+ public updateFollowup = (followupId: number, changes: JobFollowupUpdate) => {
481
+ const resource = `/jobs/${this.jobResourceId()}/followups/${followupId}/`;
482
+ const fetchOptions: RequestOptions = {
483
+ method: 'PATCH',
484
+ headers: {'Content-Type': 'application/json'},
485
+ body: JSON.stringify(changes),
486
+ query: [],
487
+ };
488
+ return this.merchi.authenticatedFetch(resource, fetchOptions).
489
+ then((data: any) => this.readFollowup(data));
490
+ };
491
+
492
+ public cancelFollowup = (followupId: number) => {
493
+ const resource =
494
+ `/jobs/${this.jobResourceId()}/followups/${followupId}/cancel/`;
495
+ const fetchOptions: RequestOptions = {method: 'POST', query: []};
496
+ return this.merchi.authenticatedFetch(resource, fetchOptions).
497
+ then((data: any) => this.readFollowup(data));
498
+ };
443
499
  }
@@ -0,0 +1,99 @@
1
+ import { NotificationType } from '../constants/notification_types.js';
2
+ import { JobFollowupType } from '../constants/job_followup_types.js';
3
+ import { Merchi } from '../merchi.js';
4
+
5
+ test('job follow-up notification type is 109', () => {
6
+ expect(NotificationType.JOB_FOLLOWUP).toBe(109);
7
+ });
8
+
9
+ test('can make a follow-up template', () => {
10
+ const merchi = new Merchi();
11
+ const template = new merchi.JobFollowupTemplate();
12
+ template.fromJson({
13
+ id: 11,
14
+ name: 'Completion',
15
+ followupType: JobFollowupType.COMPLETION,
16
+ defaultKey: 'completion',
17
+ subject: 'Your order is complete',
18
+ body: 'Hi {{client_first_name}}',
19
+ });
20
+ expect(template.name).toBe('Completion');
21
+ expect(template.followupType).toBe(0);
22
+ expect(template.defaultKey).toBe('completion');
23
+ });
24
+
25
+ test('job complete posts the follow-up sequence', async () => {
26
+ const merchi = new Merchi();
27
+ const job = new merchi.Job();
28
+ job.id = 85;
29
+ const fetch = jest.spyOn(merchi, 'authenticatedFetch').mockResolvedValue({
30
+ jobFollowups: [{
31
+ id: 4,
32
+ jobId: 85,
33
+ templateId: 11,
34
+ templateName: 'Review request',
35
+ followupType: JobFollowupType.REVIEW_REQUEST,
36
+ subject: 'How did we do?',
37
+ sendAt: '2026-11-04T09:00:00Z',
38
+ sendEmail: true,
39
+ sendSms: false,
40
+ status: 'pending',
41
+ sentAt: null,
42
+ }],
43
+ });
44
+
45
+ const rows = await job.complete([{
46
+ templateId: 11,
47
+ sendAt: '2026-11-04T09:00',
48
+ timezone: 'Australia/Melbourne',
49
+ sendEmail: true,
50
+ sendSms: false,
51
+ }]);
52
+
53
+ expect(fetch).toHaveBeenCalledWith(
54
+ '/jobs/85/complete/',
55
+ expect.objectContaining({method: 'POST'})
56
+ );
57
+ const body = fetch.mock.calls[0][1].body as FormData;
58
+ expect(JSON.parse(String(body.get('followups')))).toEqual([{
59
+ templateId: 11,
60
+ sendAt: '2026-11-04T09:00',
61
+ timezone: 'Australia/Melbourne',
62
+ sendEmail: true,
63
+ sendSms: false,
64
+ }]);
65
+ expect(rows).toHaveLength(1);
66
+ expect(rows[0].sendAt).toBe('2026-11-04T09:00:00Z');
67
+ expect(rows[0].status).toBe('pending');
68
+ expect(rows[0].templateName).toBe('Review request');
69
+ });
70
+
71
+ test('can update and cancel a pending follow-up', async () => {
72
+ const merchi = new Merchi();
73
+ const job = new merchi.Job();
74
+ job.id = 85;
75
+ const fetch = jest.spyOn(merchi, 'authenticatedFetch').mockResolvedValue({
76
+ jobFollowup: {
77
+ id: 4,
78
+ status: 'cancelled',
79
+ sendAt: '2026-12-01T09:00:00Z',
80
+ },
81
+ });
82
+
83
+ const updated = await job.updateFollowup(4, {
84
+ sendAt: '2026-12-01T09:00',
85
+ timezone: 'Australia/Melbourne',
86
+ });
87
+ expect(fetch).toHaveBeenCalledWith(
88
+ '/jobs/85/followups/4/',
89
+ expect.objectContaining({method: 'PATCH'})
90
+ );
91
+ expect(updated.sendAt).toBe('2026-12-01T09:00:00Z');
92
+
93
+ const cancelled = await job.cancelFollowup(4);
94
+ expect(fetch).toHaveBeenCalledWith(
95
+ '/jobs/85/followups/4/cancel/',
96
+ expect.objectContaining({method: 'POST'})
97
+ );
98
+ expect(cancelled.status).toBe('cancelled');
99
+ });
@@ -0,0 +1,91 @@
1
+ import type { Domain } from './domain.js';
2
+ import { Entity } from '../entity.js';
3
+ import type { Job } from './job.js';
4
+ import type { JobFollowupTemplate } from './job_followup_template.js';
5
+ import type { JobFollowupStatus } from '../constants/job_followup_types.js';
6
+ import type { User } from './user.js';
7
+
8
+ export interface ScheduledJobFollowup {
9
+ templateId: number;
10
+ sendAt: string;
11
+ timezone: string;
12
+ sendEmail: boolean;
13
+ sendSms: boolean;
14
+ subject?: string;
15
+ body?: string;
16
+ }
17
+
18
+ export interface JobFollowupUpdate {
19
+ sendAt?: string;
20
+ timezone?: string;
21
+ sendEmail?: boolean;
22
+ sendSms?: boolean;
23
+ subject?: string;
24
+ body?: string;
25
+ }
26
+
27
+ export class JobFollowup extends Entity {
28
+ // Scheduled rows are listed and updated under /jobs/<id>/followups/,
29
+ // not this collection path.
30
+ protected static resourceName = 'job_followups';
31
+ protected static singularName = 'jobFollowup';
32
+ protected static pluralName = 'jobFollowups';
33
+
34
+ @JobFollowup.property()
35
+ public id?: number;
36
+
37
+ @JobFollowup.property()
38
+ public jobId?: number;
39
+
40
+ @JobFollowup.property()
41
+ public domainId?: number;
42
+
43
+ @JobFollowup.property({type: Number})
44
+ public templateId?: number | null;
45
+
46
+ @JobFollowup.property()
47
+ public templateName?: string;
48
+
49
+ @JobFollowup.property()
50
+ public followupType?: number;
51
+
52
+ @JobFollowup.property()
53
+ public subject?: string;
54
+
55
+ @JobFollowup.property()
56
+ public body?: string;
57
+
58
+ // The job follow-up endpoints return an ISO timestamp, not unix seconds.
59
+ @JobFollowup.property()
60
+ public sendAt?: string;
61
+
62
+ @JobFollowup.property()
63
+ public sendEmail?: boolean;
64
+
65
+ @JobFollowup.property()
66
+ public sendSms?: boolean;
67
+
68
+ @JobFollowup.property({type: String})
69
+ public status?: JobFollowupStatus;
70
+
71
+ @JobFollowup.property({type: String})
72
+ public sentAt?: string | null;
73
+
74
+ @JobFollowup.property({type: String})
75
+ public lastError?: string | null;
76
+
77
+ @JobFollowup.property({type: Date})
78
+ public created?: Date;
79
+
80
+ @JobFollowup.property({type: 'Job'})
81
+ public job?: Job;
82
+
83
+ @JobFollowup.property({type: 'Domain'})
84
+ public domain?: Domain;
85
+
86
+ @JobFollowup.property({type: 'JobFollowupTemplate'})
87
+ public template?: JobFollowupTemplate;
88
+
89
+ @JobFollowup.property({type: 'User'})
90
+ public createdBy?: User;
91
+ }
@@ -0,0 +1,45 @@
1
+ import type { Domain } from './domain.js';
2
+ import { Entity } from '../entity.js';
3
+ import type { User } from './user.js';
4
+
5
+ export class JobFollowupTemplate extends Entity {
6
+ protected static resourceName = 'job_followup_templates';
7
+ protected static singularName = 'jobFollowupTemplate';
8
+ protected static pluralName = 'jobFollowupTemplates';
9
+
10
+ @JobFollowupTemplate.property({type: Date})
11
+ public archived?: Date | null;
12
+
13
+ @JobFollowupTemplate.property()
14
+ public id?: number;
15
+
16
+ @JobFollowupTemplate.property()
17
+ public name?: string;
18
+
19
+ @JobFollowupTemplate.property()
20
+ public followupType?: number;
21
+
22
+ @JobFollowupTemplate.property({type: String})
23
+ public defaultKey?: string | null;
24
+
25
+ @JobFollowupTemplate.property()
26
+ public subject?: string;
27
+
28
+ @JobFollowupTemplate.property()
29
+ public body?: string;
30
+
31
+ @JobFollowupTemplate.property({type: Date})
32
+ public created?: Date;
33
+
34
+ @JobFollowupTemplate.property({type: Date})
35
+ public updated?: Date;
36
+
37
+ @JobFollowupTemplate.property({type: Date})
38
+ public removed?: Date | null;
39
+
40
+ @JobFollowupTemplate.property({type: 'Domain'})
41
+ public domain?: Domain;
42
+
43
+ @JobFollowupTemplate.property({type: 'User'})
44
+ public createdBy?: User;
45
+ }
package/src/index.ts CHANGED
@@ -10,6 +10,10 @@ export type {
10
10
  DomainAnalyticsResponse,
11
11
  ProfileAnalyticsSummaryMetric,
12
12
  } from './entities/agent_token_analytics.js';
13
+ export type {
14
+ JobFollowupUpdate,
15
+ ScheduledJobFollowup,
16
+ } from './entities/job_followup.js';
13
17
  import { AgentSkill } from './entities/agent_skill.js';
14
18
  import { AgentSkillVersion } from './entities/agent_skill_version.js';
15
19
  import { AgentSkillApproval } from './entities/agent_skill_approval.js';
@@ -49,6 +53,8 @@ import { Invoice } from './entities/invoice.js';
49
53
  import { Item } from './entities/item.js';
50
54
  import { Job } from './entities/job.js';
51
55
  import { JobComment } from './entities/job_comment.js';
56
+ import { JobFollowup } from './entities/job_followup.js';
57
+ import { JobFollowupTemplate } from './entities/job_followup_template.js';
52
58
  import { JobNote } from './entities/job_note.js';
53
59
  import { JobOperationLog } from './entities/job_operation_log.js';
54
60
  import { MatchingInventory } from './entities/matching_inventory.js';
@@ -146,6 +152,8 @@ export {
146
152
  Item,
147
153
  Job,
148
154
  JobComment,
155
+ JobFollowup,
156
+ JobFollowupTemplate,
149
157
  JobNote,
150
158
  JobOperationLog,
151
159
  MatchingInventory,
package/src/merchi.ts CHANGED
@@ -6,6 +6,8 @@ import {
6
6
  import { AutomaticPaymentRelationship } from './entities/automatic_payment_relationship.js';
7
7
  import { Session } from './entities/session.js';
8
8
  import { JobComment } from './entities/job_comment.js';
9
+ import { JobFollowup } from './entities/job_followup.js';
10
+ import { JobFollowupTemplate } from './entities/job_followup_template.js';
9
11
  import { JobNote } from './entities/job_note.js';
10
12
  import { JobOperationLog } from './entities/job_operation_log.js';
11
13
  import { Domain } from './entities/domain.js';
@@ -130,6 +132,8 @@ export class Merchi {
130
132
  public Inventory: typeof Inventory;
131
133
  public InventoryGroup: typeof InventoryGroup;
132
134
  public JobComment: typeof JobComment;
135
+ public JobFollowup: typeof JobFollowup;
136
+ public JobFollowupTemplate: typeof JobFollowupTemplate;
133
137
  public JobNote: typeof JobNote;
134
138
  public JobOperationLog: typeof JobOperationLog;
135
139
  public VariationOption: typeof VariationOption;
@@ -365,6 +369,10 @@ export class Merchi {
365
369
  this.MerchiFile = this.setupClass(MerchiFile) as typeof MerchiFile;
366
370
  this.User = this.setupClass(User) as typeof User;
367
371
  this.JobComment = this.setupClass(JobComment) as typeof JobComment;
372
+ this.JobFollowup = this.setupClass(JobFollowup) as typeof JobFollowup;
373
+ this.JobFollowupTemplate = this.setupClass(
374
+ JobFollowupTemplate
375
+ ) as typeof JobFollowupTemplate;
368
376
  this.JobNote = this.setupClass(JobNote) as typeof JobNote;
369
377
  this.JobOperationLog = this.setupClass(JobOperationLog) as typeof JobOperationLog;
370
378
  this.VariationOption = this.setupClass(