@merchi/sdk 1.42.23 → 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.
@@ -12,6 +12,10 @@ export declare enum PaymentStatus {
12
12
  PARTIAL_PAID = 3,
13
13
  FULLY_PAID = 4
14
14
  }
15
+ export declare enum InvoiceQuoteStatus {
16
+ ISSUED = "issued",
17
+ DECLINED = "declined"
18
+ }
15
19
  export declare enum ProductionStatus {
16
20
  INIT = 0,
17
21
  REJECTED = 1,
@@ -14,6 +14,11 @@ export var PaymentStatus;
14
14
  PaymentStatus[PaymentStatus["PARTIAL_PAID"] = 3] = "PARTIAL_PAID";
15
15
  PaymentStatus[PaymentStatus["FULLY_PAID"] = 4] = "FULLY_PAID";
16
16
  })(PaymentStatus || (PaymentStatus = {}));
17
+ export var InvoiceQuoteStatus;
18
+ (function (InvoiceQuoteStatus) {
19
+ InvoiceQuoteStatus["ISSUED"] = "issued";
20
+ InvoiceQuoteStatus["DECLINED"] = "declined";
21
+ })(InvoiceQuoteStatus || (InvoiceQuoteStatus = {}));
17
22
  export var ProductionStatus;
18
23
  (function (ProductionStatus) {
19
24
  ProductionStatus[ProductionStatus["INIT"] = 0] = "INIT";
@@ -98,5 +98,8 @@ export declare 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
+ JOB_FOLLOWUP = 109,
102
+ SEND_QUOTE = 110,
103
+ QUOTE_INVOICE_APPROVED = 111,
104
+ QUOTE_INVOICE_DECLINED = 112
102
105
  }
@@ -100,4 +100,7 @@ export var NotificationType;
100
100
  NotificationType[NotificationType["REFERRER_JOB_RECEIVED"] = 107] = "REFERRER_JOB_RECEIVED";
101
101
  NotificationType[NotificationType["FULFILLMENT_PARTNER_INVITED"] = 108] = "FULFILLMENT_PARTNER_INVITED";
102
102
  NotificationType[NotificationType["JOB_FOLLOWUP"] = 109] = "JOB_FOLLOWUP";
103
+ NotificationType[NotificationType["SEND_QUOTE"] = 110] = "SEND_QUOTE";
104
+ NotificationType[NotificationType["QUOTE_INVOICE_APPROVED"] = 111] = "QUOTE_INVOICE_APPROVED";
105
+ NotificationType[NotificationType["QUOTE_INVOICE_DECLINED"] = 112] = "QUOTE_INVOICE_DECLINED";
103
106
  })(NotificationType || (NotificationType = {}));
@@ -41,6 +41,10 @@ export declare class Invoice extends Entity {
41
41
  sendWhatsapp?: boolean | null;
42
42
  unpaid?: boolean | null;
43
43
  isTest?: boolean | null;
44
+ isQuote?: boolean | null;
45
+ quoteApprovedDate?: Date | null;
46
+ quoteDeclinedDate?: Date | null;
47
+ quoteDeclineReason?: string | null;
44
48
  currency?: string;
45
49
  acceptSquare?: boolean;
46
50
  acceptStripe?: boolean;
@@ -56,6 +60,7 @@ export declare class Invoice extends Entity {
56
60
  isCompletelyPaid?: boolean;
57
61
  responsibleManager?: User | null;
58
62
  creator?: User | null;
63
+ quoteApprovedBy?: User | null;
59
64
  client?: User;
60
65
  clientCompany?: Company | null;
61
66
  subscriptionCompanies?: Company[];
@@ -77,4 +82,14 @@ export declare class Invoice extends Entity {
77
82
  quotes?: Quote[];
78
83
  cart?: Cart;
79
84
  payments?: Payment[];
85
+ private respondToQuote;
86
+ /** Approving a quote turns it into a payable invoice. */
87
+ approveQuote: () => Promise<{
88
+ invoice: Invoice;
89
+ paymentUrl: string;
90
+ }>;
91
+ declineQuote: (reason?: string) => Promise<{
92
+ invoice: Invoice;
93
+ paymentUrl: string;
94
+ }>;
80
95
  }
@@ -34,7 +34,31 @@ import { User } from './user.js';
34
34
  var Invoice = /** @class */ (function (_super) {
35
35
  __extends(Invoice, _super);
36
36
  function Invoice() {
37
- return _super !== null && _super.apply(this, arguments) || this;
37
+ var _this = _super !== null && _super.apply(this, arguments) || this;
38
+ _this.respondToQuote = function (action, reason) {
39
+ if (_this.id === undefined || _this.id === null) {
40
+ throw new Error('id is undefined, did you forget to set it?');
41
+ }
42
+ var resource = "/invoices/".concat(_this.id, "/").concat(action, "_quote/");
43
+ var data = new FormData();
44
+ if (reason) {
45
+ data.append('reason', reason);
46
+ }
47
+ var fetchOptions = { method: 'POST', body: data, query: [] };
48
+ return _this.merchi.authenticatedFetch(resource, fetchOptions).
49
+ then(function (payload) {
50
+ _this.fromJson(payload.invoice);
51
+ return { invoice: _this, paymentUrl: payload.paymentUrl };
52
+ });
53
+ };
54
+ /** Approving a quote turns it into a payable invoice. */
55
+ _this.approveQuote = function () {
56
+ return _this.respondToQuote('approve');
57
+ };
58
+ _this.declineQuote = function (reason) {
59
+ return _this.respondToQuote('decline', reason);
60
+ };
61
+ return _this;
38
62
  }
39
63
  Invoice.resourceName = 'invoices';
40
64
  Invoice.singularName = 'invoice';
@@ -123,6 +147,22 @@ var Invoice = /** @class */ (function (_super) {
123
147
  Invoice.property({ type: Boolean }),
124
148
  __metadata("design:type", Object)
125
149
  ], Invoice.prototype, "isTest", void 0);
150
+ __decorate([
151
+ Invoice.property({ type: Boolean }),
152
+ __metadata("design:type", Object)
153
+ ], Invoice.prototype, "isQuote", void 0);
154
+ __decorate([
155
+ Invoice.property({ type: Date }),
156
+ __metadata("design:type", Object)
157
+ ], Invoice.prototype, "quoteApprovedDate", void 0);
158
+ __decorate([
159
+ Invoice.property({ type: Date }),
160
+ __metadata("design:type", Object)
161
+ ], Invoice.prototype, "quoteDeclinedDate", void 0);
162
+ __decorate([
163
+ Invoice.property({ type: String }),
164
+ __metadata("design:type", Object)
165
+ ], Invoice.prototype, "quoteDeclineReason", void 0);
126
166
  __decorate([
127
167
  Invoice.property(),
128
168
  __metadata("design:type", String)
@@ -183,6 +223,10 @@ var Invoice = /** @class */ (function (_super) {
183
223
  Invoice.property({ type: User }),
184
224
  __metadata("design:type", Object)
185
225
  ], Invoice.prototype, "creator", void 0);
226
+ __decorate([
227
+ Invoice.property({ type: User }),
228
+ __metadata("design:type", Object)
229
+ ], Invoice.prototype, "quoteApprovedBy", void 0);
186
230
  __decorate([
187
231
  Invoice.property(),
188
232
  __metadata("design:type", User)
@@ -1,3 +1,39 @@
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
+ };
1
37
  import { setup, mockFetch } from '../test_util.js';
2
38
  import { Merchi } from '../merchi.js';
3
39
  setup();
@@ -37,6 +73,59 @@ test('client and invoice tokens supported by merchi', function () {
37
73
  expect(fetch.mock.calls[0][1]['query']).toEqual(correct);
38
74
  return invocation;
39
75
  });
76
+ test('reads quote fields', function () {
77
+ var merchi = new Merchi();
78
+ var invoice = new merchi.Invoice();
79
+ invoice.fromJson({
80
+ id: 1,
81
+ isQuote: true,
82
+ quoteDeclinedDate: 1761700000,
83
+ quoteDeclineReason: 'Too expensive',
84
+ });
85
+ expect(invoice.isQuote).toBe(true);
86
+ expect(invoice.quoteDeclinedDate).toBeInstanceOf(Date);
87
+ expect(invoice.quoteDeclineReason).toBe('Too expensive');
88
+ });
89
+ test('approveQuote posts to approve_quote with the invoice token', function () { return __awaiter(void 0, void 0, void 0, function () {
90
+ var merchi, fetch, invoice, result;
91
+ return __generator(this, function (_a) {
92
+ switch (_a.label) {
93
+ case 0:
94
+ merchi = new Merchi(undefined, undefined, 'i');
95
+ fetch = mockFetch(true, { invoice: { id: 1, isQuote: false }, paymentUrl: 'https://pay' }, 200);
96
+ invoice = new merchi.Invoice();
97
+ invoice.id = 1;
98
+ invoice.isQuote = true;
99
+ return [4 /*yield*/, invoice.approveQuote()];
100
+ case 1:
101
+ result = _a.sent();
102
+ expect(fetch.mock.calls[0][0]).toContain('/invoices/1/approve_quote/');
103
+ expect(fetch.mock.calls[0][1]['method']).toBe('POST');
104
+ expect(fetch.mock.calls[0][1]['query']).toContainEqual(['invoice_token', 'i']);
105
+ expect(result.paymentUrl).toBe('https://pay');
106
+ expect(invoice.isQuote).toBe(false);
107
+ return [2 /*return*/];
108
+ }
109
+ });
110
+ }); });
111
+ test('declineQuote sends the reason', function () { return __awaiter(void 0, void 0, void 0, function () {
112
+ var merchi, fetch, invoice;
113
+ return __generator(this, function (_a) {
114
+ switch (_a.label) {
115
+ case 0:
116
+ merchi = new Merchi();
117
+ fetch = mockFetch(true, { invoice: { id: 1 }, paymentUrl: '' }, 200);
118
+ invoice = new merchi.Invoice();
119
+ invoice.id = 1;
120
+ return [4 /*yield*/, invoice.declineQuote('Too expensive')];
121
+ case 1:
122
+ _a.sent();
123
+ expect(fetch.mock.calls[0][0]).toContain('/invoices/1/decline_quote/');
124
+ expect(fetch.mock.calls[0][1]['body'].get('reason')).toBe('Too expensive');
125
+ return [2 /*return*/];
126
+ }
127
+ });
128
+ }); });
40
129
  test('preserves server payment engine hint', function () {
41
130
  var merchi = new Merchi();
42
131
  var entity = new merchi.Invoice();
@@ -25,6 +25,7 @@ import { User } from './user.js';
25
25
  import { Variation } from './variation.js';
26
26
  import { VariationsGroup } from './variations_group.js';
27
27
  import { InventoryStatus } from '../constants/inventory_statuses.js';
28
+ import { InvoiceQuoteStatus } from '../constants/job_status.js';
28
29
  import { Item } from './item.js';
29
30
  export declare class Job extends Entity {
30
31
  protected static resourceName: string;
@@ -63,6 +64,8 @@ export declare class Job extends Entity {
63
64
  jobInfoApprovedByClient?: boolean;
64
65
  groupBuyStatus?: number | null;
65
66
  paymentStatus?: number | null;
67
+ /** Set while the job's invoice is still a quote; paymentStatus stays INIT. */
68
+ invoiceQuoteStatus?: InvoiceQuoteStatus | null;
66
69
  deductionDate?: Date | null;
67
70
  shippingStatus?: number | null;
68
71
  completed?: boolean;
@@ -265,6 +265,10 @@ var Job = /** @class */ (function (_super) {
265
265
  Job.property({ type: Number }),
266
266
  __metadata("design:type", Object)
267
267
  ], Job.prototype, "paymentStatus", void 0);
268
+ __decorate([
269
+ Job.property({ type: String }),
270
+ __metadata("design:type", Object)
271
+ ], Job.prototype, "invoiceQuoteStatus", void 0);
268
272
  __decorate([
269
273
  Job.property({ type: Date }),
270
274
  __metadata("design:type", Object)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@merchi/sdk",
3
- "version": "1.42.23",
3
+ "version": "1.42.24",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -14,6 +14,11 @@ export enum PaymentStatus {
14
14
  FULLY_PAID = 4,
15
15
  }
16
16
 
17
+ export enum InvoiceQuoteStatus {
18
+ ISSUED = 'issued',
19
+ DECLINED = 'declined',
20
+ }
21
+
17
22
  export enum ProductionStatus {
18
23
  INIT = 0,
19
24
  REJECTED = 1,
@@ -99,4 +99,7 @@ export enum NotificationType {
99
99
  REFERRER_JOB_RECEIVED = 107,
100
100
  FULFILLMENT_PARTNER_INVITED = 108,
101
101
  JOB_FOLLOWUP = 109,
102
+ SEND_QUOTE = 110,
103
+ QUOTE_INVOICE_APPROVED = 111,
104
+ QUOTE_INVOICE_DECLINED = 112,
102
105
  }
@@ -42,6 +42,45 @@ test('client and invoice tokens supported by merchi', () => {
42
42
  return invocation;
43
43
  });
44
44
 
45
+ test('reads quote fields', () => {
46
+ const merchi = new Merchi();
47
+ const invoice = new merchi.Invoice();
48
+ invoice.fromJson({
49
+ id: 1,
50
+ isQuote: true,
51
+ quoteDeclinedDate: 1761700000,
52
+ quoteDeclineReason: 'Too expensive',
53
+ });
54
+ expect(invoice.isQuote).toBe(true);
55
+ expect(invoice.quoteDeclinedDate).toBeInstanceOf(Date);
56
+ expect(invoice.quoteDeclineReason).toBe('Too expensive');
57
+ });
58
+
59
+ test('approveQuote posts to approve_quote with the invoice token', async () => {
60
+ const merchi = new Merchi(undefined, undefined, 'i');
61
+ const fetch = mockFetch(
62
+ true, {invoice: {id: 1, isQuote: false}, paymentUrl: 'https://pay'}, 200);
63
+ const invoice = new merchi.Invoice();
64
+ invoice.id = 1;
65
+ invoice.isQuote = true;
66
+ const result = await invoice.approveQuote();
67
+ expect(fetch.mock.calls[0][0]).toContain('/invoices/1/approve_quote/');
68
+ expect(fetch.mock.calls[0][1]['method']).toBe('POST');
69
+ expect(fetch.mock.calls[0][1]['query']).toContainEqual(['invoice_token', 'i']);
70
+ expect(result.paymentUrl).toBe('https://pay');
71
+ expect(invoice.isQuote).toBe(false);
72
+ });
73
+
74
+ test('declineQuote sends the reason', async () => {
75
+ const merchi = new Merchi();
76
+ const fetch = mockFetch(true, {invoice: {id: 1}, paymentUrl: ''}, 200);
77
+ const invoice = new merchi.Invoice();
78
+ invoice.id = 1;
79
+ await invoice.declineQuote('Too expensive');
80
+ expect(fetch.mock.calls[0][0]).toContain('/invoices/1/decline_quote/');
81
+ expect(fetch.mock.calls[0][1]['body'].get('reason')).toBe('Too expensive');
82
+ });
83
+
45
84
  test('preserves server payment engine hint', () => {
46
85
  const merchi = new Merchi();
47
86
  const entity = new merchi.Invoice();
@@ -16,6 +16,7 @@ import { Payment } from './payment.js';
16
16
  import { PhoneNumber } from './phone_number.js';
17
17
  import { Shipment } from './shipment.js';
18
18
  import { User } from './user.js';
19
+ import { RequestOptions } from '../request.js';
19
20
 
20
21
  export class Invoice extends Entity {
21
22
  protected static resourceName = 'invoices';
@@ -85,6 +86,18 @@ export class Invoice extends Entity {
85
86
  @Invoice.property({type: Boolean})
86
87
  public isTest?: boolean | null;
87
88
 
89
+ @Invoice.property({type: Boolean})
90
+ public isQuote?: boolean | null;
91
+
92
+ @Invoice.property({type: Date})
93
+ public quoteApprovedDate?: Date | null;
94
+
95
+ @Invoice.property({type: Date})
96
+ public quoteDeclinedDate?: Date | null;
97
+
98
+ @Invoice.property({type: String})
99
+ public quoteDeclineReason?: string | null;
100
+
88
101
  @Invoice.property()
89
102
  public currency?: string;
90
103
 
@@ -130,6 +143,9 @@ export class Invoice extends Entity {
130
143
  @Invoice.property({type: User})
131
144
  public creator?: User | null;
132
145
 
146
+ @Invoice.property({type: User})
147
+ public quoteApprovedBy?: User | null;
148
+
133
149
  @Invoice.property()
134
150
  public client?: User;
135
151
 
@@ -192,4 +208,30 @@ export class Invoice extends Entity {
192
208
 
193
209
  @Invoice.property({arrayType: 'Payment'})
194
210
  public payments?: Payment[];
211
+
212
+ private respondToQuote = (action: 'approve' | 'decline', reason?: string) => {
213
+ if (this.id === undefined || this.id === null) {
214
+ throw new Error('id is undefined, did you forget to set it?');
215
+ }
216
+ const resource = `/invoices/${this.id}/${action}_quote/`;
217
+ const data = new FormData();
218
+ if (reason) {
219
+ data.append('reason', reason);
220
+ }
221
+ const fetchOptions: RequestOptions = {method: 'POST', body: data, query: []};
222
+ return this.merchi.authenticatedFetch(resource, fetchOptions).
223
+ then((payload: any) => {
224
+ this.fromJson(payload.invoice);
225
+ return {invoice: this, paymentUrl: payload.paymentUrl as string};
226
+ });
227
+ };
228
+
229
+ /** Approving a quote turns it into a payable invoice. */
230
+ public approveQuote = (): Promise<{invoice: Invoice; paymentUrl: string}> =>
231
+ this.respondToQuote('approve');
232
+
233
+ public declineQuote = (
234
+ reason?: string
235
+ ): Promise<{invoice: Invoice; paymentUrl: string}> =>
236
+ this.respondToQuote('decline', reason);
195
237
  }
@@ -26,6 +26,7 @@ import { User } from './user.js';
26
26
  import { Variation } from './variation.js';
27
27
  import { VariationsGroup } from './variations_group.js';
28
28
  import { InventoryStatus } from '../constants/inventory_statuses.js';
29
+ import { InvoiceQuoteStatus } from '../constants/job_status.js';
29
30
  import { Item } from './item.js';
30
31
 
31
32
 
@@ -133,6 +134,10 @@ export class Job extends Entity {
133
134
  @Job.property({type: Number})
134
135
  public paymentStatus?: number | null;
135
136
 
137
+ /** Set while the job's invoice is still a quote; paymentStatus stays INIT. */
138
+ @Job.property({type: String})
139
+ public invoiceQuoteStatus?: InvoiceQuoteStatus | null;
140
+
136
141
  @Job.property({type: Date})
137
142
  public deductionDate?: Date | null;
138
143