@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/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/dist/request.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ErrorType } from './constants/errors.js';
|
|
2
1
|
export interface RequestOptions extends RequestInit {
|
|
3
2
|
query?: string[][];
|
|
4
3
|
}
|
|
@@ -37,7 +36,8 @@ export interface ApiErrorDetails {
|
|
|
37
36
|
}
|
|
38
37
|
export declare class ApiError extends Error {
|
|
39
38
|
statusCode?: number;
|
|
40
|
-
|
|
39
|
+
/** Numeric API code, including values added after this SDK was published. */
|
|
40
|
+
errorCode?: number;
|
|
41
41
|
errorMessage: string;
|
|
42
42
|
/**
|
|
43
43
|
* Structured context the API may include alongside the error
|
package/dist/request.js
CHANGED
|
@@ -71,7 +71,6 @@ var __values = (this && this.__values) || function(o) {
|
|
|
71
71
|
};
|
|
72
72
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
73
73
|
};
|
|
74
|
-
// eslint-disable-next-line no-unused-vars
|
|
75
74
|
import { getErrorFromCode } from './constants/errors.js';
|
|
76
75
|
function resolveApiErrorMessage(err) {
|
|
77
76
|
if (err && typeof err === 'object' && typeof err.message === 'string' && err.message) {
|
package/dist/request.test.js
CHANGED
|
@@ -83,6 +83,41 @@ test('will get default errorCode', function () {
|
|
|
83
83
|
expect(e.message).toBe('just a test');
|
|
84
84
|
});
|
|
85
85
|
});
|
|
86
|
+
test('lead spam rejection keeps its API code through apiFetch', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
87
|
+
return __generator(this, function (_a) {
|
|
88
|
+
switch (_a.label) {
|
|
89
|
+
case 0:
|
|
90
|
+
mockFetch(false, {
|
|
91
|
+
statusCode: 400,
|
|
92
|
+
errorCode: 227,
|
|
93
|
+
message: 'Invalid submission',
|
|
94
|
+
}, 400);
|
|
95
|
+
return [4 /*yield*/, expect(apiFetch('https://api.merchi.co/', '/create_new_lead/', {
|
|
96
|
+
method: 'POST',
|
|
97
|
+
})).rejects.toMatchObject({
|
|
98
|
+
name: 'ApiError',
|
|
99
|
+
statusCode: 400,
|
|
100
|
+
errorCode: 227,
|
|
101
|
+
message: 'Invalid submission',
|
|
102
|
+
errorMessage: 'Invalid submission',
|
|
103
|
+
})];
|
|
104
|
+
case 1:
|
|
105
|
+
_a.sent();
|
|
106
|
+
return [2 /*return*/];
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}); });
|
|
110
|
+
test.each([226, 1000])('ApiError preserves new numeric API code %s', function (errorCode) {
|
|
111
|
+
var error = new ApiError({ statusCode: 400, errorCode: errorCode, message: 'Rejected' });
|
|
112
|
+
expect(error.errorCode).toBe(errorCode);
|
|
113
|
+
expect(error.original.errorCode).toBe(errorCode);
|
|
114
|
+
});
|
|
115
|
+
test.each(['227', 'INVALID_PHONE_NUMBER', NaN, -1])('ApiError rejects malformed API code %p', function (errorCode) {
|
|
116
|
+
var error = new ApiError({ statusCode: 400, errorCode: errorCode, message: 'Rejected' });
|
|
117
|
+
expect(error.errorCode).toBe(ErrorType.UNKNOWN_ERROR);
|
|
118
|
+
expect(error.statusCode).toBe(400);
|
|
119
|
+
expect(error.message).toBe('Rejected');
|
|
120
|
+
});
|
|
86
121
|
test('ApiError keeps plain string messages', function () {
|
|
87
122
|
var e = new ApiError('empty response');
|
|
88
123
|
expect(e.message).toBe('empty response');
|
package/package.json
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ErrorType, getErrorFromCode } from './errors.js';
|
|
2
|
+
|
|
3
|
+
test.each([ErrorType.UNKNOWN_ERROR, ErrorType.INVALID_PHONE_NUMBER, ErrorType.DOMAIN_NOT_FOUND])(
|
|
4
|
+
'preserves known API error code %s', code => {
|
|
5
|
+
expect(getErrorFromCode(code)).toBe(code);
|
|
6
|
+
},
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
// INVALID_HCAPTCHA and SPAM_DETECTED exist in the API's Python SDK but not
|
|
10
|
+
// this SDK's legacy enum. Future codes must remain diagnosable too.
|
|
11
|
+
test.each([226, 227, 1000, Number.MAX_SAFE_INTEGER])(
|
|
12
|
+
'preserves forward-compatible numeric API error code %s', code => {
|
|
13
|
+
expect(getErrorFromCode(code)).toBe(code);
|
|
14
|
+
},
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
test.each([
|
|
18
|
+
undefined, null, -1, 1.5, NaN, Infinity, -Infinity,
|
|
19
|
+
Number.MAX_SAFE_INTEGER + 1, '227', 'INVALID_PHONE_NUMBER',
|
|
20
|
+
'toString', '__proto__', true, {}, [],
|
|
21
|
+
])('uses UNKNOWN_ERROR for malformed API code %p', code => {
|
|
22
|
+
expect(getErrorFromCode(code)).toBe(ErrorType.UNKNOWN_ERROR);
|
|
23
|
+
});
|
package/src/constants/errors.ts
CHANGED
|
@@ -24,8 +24,10 @@ export enum ErrorType {
|
|
|
24
24
|
DOMAIN_NOT_FOUND = 22,
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export function getErrorFromCode(code:
|
|
28
|
-
|
|
27
|
+
export function getErrorFromCode(code: unknown): number {
|
|
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;
|
package/src/constants/index.ts
CHANGED
|
@@ -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,
|
package/src/entities/domain.ts
CHANGED
|
@@ -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
|
|
package/src/entities/job.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';
|
|
@@ -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(
|
package/src/request.test.ts
CHANGED
|
@@ -43,6 +43,38 @@ test('will get default errorCode', () => {
|
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
+
test('lead spam rejection keeps its API code through apiFetch', async () => {
|
|
47
|
+
mockFetch(false, {
|
|
48
|
+
statusCode: 400,
|
|
49
|
+
errorCode: 227,
|
|
50
|
+
message: 'Invalid submission',
|
|
51
|
+
}, 400);
|
|
52
|
+
await expect(apiFetch('https://api.merchi.co/', '/create_new_lead/', {
|
|
53
|
+
method: 'POST',
|
|
54
|
+
})).rejects.toMatchObject({
|
|
55
|
+
name: 'ApiError',
|
|
56
|
+
statusCode: 400,
|
|
57
|
+
errorCode: 227,
|
|
58
|
+
message: 'Invalid submission',
|
|
59
|
+
errorMessage: 'Invalid submission',
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test.each([226, 1000])('ApiError preserves new numeric API code %s', errorCode => {
|
|
64
|
+
const error = new ApiError({ statusCode: 400, errorCode, message: 'Rejected' });
|
|
65
|
+
expect(error.errorCode).toBe(errorCode);
|
|
66
|
+
expect(error.original.errorCode).toBe(errorCode);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test.each(['227', 'INVALID_PHONE_NUMBER', NaN, -1])(
|
|
70
|
+
'ApiError rejects malformed API code %p', errorCode => {
|
|
71
|
+
const error = new ApiError({ statusCode: 400, errorCode, message: 'Rejected' });
|
|
72
|
+
expect(error.errorCode).toBe(ErrorType.UNKNOWN_ERROR);
|
|
73
|
+
expect(error.statusCode).toBe(400);
|
|
74
|
+
expect(error.message).toBe('Rejected');
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
|
|
46
78
|
test('ApiError keeps plain string messages', () => {
|
|
47
79
|
const e = new ApiError('empty response');
|
|
48
80
|
expect(e.message).toBe('empty response');
|