@merchi/sdk 1.42.21 → 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.
- package/dist/constants/errors.d.ts +1 -1
- package/dist/constants/errors.js +3 -1
- package/dist/constants/errors.test.d.ts +1 -0
- package/dist/constants/errors.test.js +16 -0
- package/dist/constants/index.d.ts +2 -1
- package/dist/constants/index.js +2 -1
- package/dist/constants/job_followup_types.d.ts +8 -0
- package/dist/constants/job_followup_types.js +8 -0
- package/dist/constants/notification_types.d.ts +2 -1
- package/dist/constants/notification_types.js +1 -0
- package/dist/entities/domain.d.ts +2 -0
- package/dist/entities/domain.js +4 -0
- package/dist/entities/job.d.ts +9 -0
- package/dist/entities/job.js +51 -0
- package/dist/entities/job_followup.d.ts +47 -0
- package/dist/entities/job_followup.js +114 -0
- package/dist/entities/job_followup.test.d.ts +1 -0
- package/dist/entities/job_followup.test.js +138 -0
- package/dist/entities/job_followup_template.d.ts +20 -0
- package/dist/entities/job_followup_template.js +84 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/dist/merchi.d.ts +4 -0
- package/dist/merchi.js +4 -0
- package/dist/request.d.ts +2 -2
- package/dist/request.js +0 -1
- package/dist/request.test.js +35 -0
- package/package.json +1 -1
- package/src/constants/errors.test.ts +23 -0
- package/src/constants/errors.ts +4 -2
- package/src/constants/index.ts +2 -0
- package/src/constants/job_followup_types.ts +9 -0
- package/src/constants/notification_types.ts +1 -0
- package/src/entities/domain.ts +4 -0
- package/src/entities/job.ts +56 -0
- package/src/entities/job_followup.test.ts +99 -0
- package/src/entities/job_followup.ts +91 -0
- package/src/entities/job_followup_template.ts +45 -0
- package/src/index.ts +8 -0
- package/src/merchi.ts +8 -0
- package/src/request.test.ts +32 -0
- package/src/request.ts +3 -3
package/dist/constants/errors.js
CHANGED
|
@@ -25,7 +25,9 @@ export var ErrorType;
|
|
|
25
25
|
ErrorType[ErrorType["DOMAIN_NOT_FOUND"] = 22] = "DOMAIN_NOT_FOUND";
|
|
26
26
|
})(ErrorType || (ErrorType = {}));
|
|
27
27
|
export function getErrorFromCode(code) {
|
|
28
|
-
|
|
28
|
+
// The API can add error codes before this SDK's named constants are updated.
|
|
29
|
+
// Preserve those numeric diagnostics instead of turning them into UNKNOWN.
|
|
30
|
+
if (typeof code === 'number' && Number.isSafeInteger(code) && code >= 0) {
|
|
29
31
|
return code;
|
|
30
32
|
}
|
|
31
33
|
return ErrorType.UNKNOWN_ERROR;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ErrorType, getErrorFromCode } from './errors.js';
|
|
2
|
+
test.each([ErrorType.UNKNOWN_ERROR, ErrorType.INVALID_PHONE_NUMBER, ErrorType.DOMAIN_NOT_FOUND])('preserves known API error code %s', function (code) {
|
|
3
|
+
expect(getErrorFromCode(code)).toBe(code);
|
|
4
|
+
});
|
|
5
|
+
// INVALID_HCAPTCHA and SPAM_DETECTED exist in the API's Python SDK but not
|
|
6
|
+
// this SDK's legacy enum. Future codes must remain diagnosable too.
|
|
7
|
+
test.each([226, 227, 1000, Number.MAX_SAFE_INTEGER])('preserves forward-compatible numeric API error code %s', function (code) {
|
|
8
|
+
expect(getErrorFromCode(code)).toBe(code);
|
|
9
|
+
});
|
|
10
|
+
test.each([
|
|
11
|
+
undefined, null, -1, 1.5, NaN, Infinity, -Infinity,
|
|
12
|
+
Number.MAX_SAFE_INTEGER + 1, '227', 'INVALID_PHONE_NUMBER',
|
|
13
|
+
'toString', '__proto__', true, {}, [],
|
|
14
|
+
])('uses UNKNOWN_ERROR for malformed API code %p', function (code) {
|
|
15
|
+
expect(getErrorFromCode(code)).toBe(ErrorType.UNKNOWN_ERROR);
|
|
16
|
+
});
|
|
@@ -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, };
|
package/dist/constants/index.js
CHANGED
|
@@ -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 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 = {}));
|
|
@@ -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[];
|
package/dist/entities/domain.js
CHANGED
|
@@ -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)
|
package/dist/entities/job.d.ts
CHANGED
|
@@ -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
|
}
|
package/dist/entities/job.js
CHANGED
|
@@ -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 };
|