@merchi/sdk 1.42.22 → 1.42.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/constants/index.d.ts +2 -1
  2. package/dist/constants/index.js +2 -1
  3. package/dist/constants/job_followup_types.d.ts +8 -0
  4. package/dist/constants/job_followup_types.js +8 -0
  5. package/dist/constants/job_status.d.ts +4 -0
  6. package/dist/constants/job_status.js +5 -0
  7. package/dist/constants/notification_types.d.ts +5 -1
  8. package/dist/constants/notification_types.js +4 -0
  9. package/dist/entities/domain.d.ts +2 -0
  10. package/dist/entities/domain.js +4 -0
  11. package/dist/entities/invoice.d.ts +15 -0
  12. package/dist/entities/invoice.js +45 -1
  13. package/dist/entities/invoice.test.js +89 -0
  14. package/dist/entities/job.d.ts +12 -0
  15. package/dist/entities/job.js +55 -0
  16. package/dist/entities/job_followup.d.ts +47 -0
  17. package/dist/entities/job_followup.js +114 -0
  18. package/dist/entities/job_followup.test.d.ts +1 -0
  19. package/dist/entities/job_followup.test.js +138 -0
  20. package/dist/entities/job_followup_template.d.ts +20 -0
  21. package/dist/entities/job_followup_template.js +84 -0
  22. package/dist/index.d.ts +4 -1
  23. package/dist/index.js +3 -1
  24. package/dist/merchi.d.ts +4 -0
  25. package/dist/merchi.js +4 -0
  26. package/package.json +1 -1
  27. package/src/constants/index.ts +2 -0
  28. package/src/constants/job_followup_types.ts +9 -0
  29. package/src/constants/job_status.ts +5 -0
  30. package/src/constants/notification_types.ts +4 -0
  31. package/src/entities/domain.ts +4 -0
  32. package/src/entities/invoice.test.ts +39 -0
  33. package/src/entities/invoice.ts +42 -0
  34. package/src/entities/job.ts +61 -0
  35. package/src/entities/job_followup.test.ts +99 -0
  36. package/src/entities/job_followup.ts +91 -0
  37. package/src/entities/job_followup_template.ts +45 -0
  38. package/src/index.ts +8 -0
  39. package/src/merchi.ts +8 -0
@@ -0,0 +1,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(