@managemint-solutions/sdk 0.56.0 → 0.64.0

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 (53) hide show
  1. package/README.md +209 -7
  2. package/dist/audit/document-changes.d.ts +39 -0
  3. package/dist/audit/document-changes.js +332 -0
  4. package/dist/audit/index.d.ts +50 -2
  5. package/dist/audit/index.js +87 -44
  6. package/dist/client.d.ts +6 -0
  7. package/dist/client.js +9 -0
  8. package/dist/clients/dto.d.ts +18 -3
  9. package/dist/clients/dto.js +72 -2
  10. package/dist/clients/index.js +16 -0
  11. package/dist/documents/content.d.ts +39 -0
  12. package/dist/documents/content.js +443 -0
  13. package/dist/documents/document-templates.d.ts +37 -0
  14. package/dist/documents/document-templates.js +143 -0
  15. package/dist/documents/documents.d.ts +154 -0
  16. package/dist/documents/documents.js +330 -0
  17. package/dist/documents/dto.d.ts +125 -0
  18. package/dist/documents/dto.js +530 -0
  19. package/dist/documents/index.d.ts +4 -0
  20. package/dist/documents/index.js +24 -0
  21. package/dist/documents/render/html.d.ts +64 -0
  22. package/dist/documents/render/html.js +399 -0
  23. package/dist/documents/render/index.d.ts +2 -0
  24. package/dist/documents/render/index.js +23 -0
  25. package/dist/documents/render/values.d.ts +86 -0
  26. package/dist/documents/render/values.js +142 -0
  27. package/dist/index.d.ts +8 -1
  28. package/dist/index.js +27 -3
  29. package/dist/leads/index.js +1 -3
  30. package/dist/notifications/index.d.ts +6 -0
  31. package/dist/notifications/index.js +16 -0
  32. package/dist/organization-payment-methods/dto.d.ts +10 -0
  33. package/dist/organization-payment-methods/dto.js +56 -0
  34. package/dist/organization-payment-methods/index.d.ts +8 -1
  35. package/dist/organization-payment-methods/index.js +23 -0
  36. package/dist/payments/index.d.ts +67 -0
  37. package/dist/payments/index.js +137 -0
  38. package/dist/permissions/dto.d.ts +4 -0
  39. package/dist/permissions/dto.js +20 -8
  40. package/dist/service-client/index.d.ts +32 -0
  41. package/dist/service-client/index.js +60 -0
  42. package/dist/staff-client.d.ts +3 -0
  43. package/dist/staff-client.js +5 -0
  44. package/dist/supporting-files/index.js +4 -6
  45. package/dist/supporting-files/paths.d.ts +2 -0
  46. package/dist/supporting-files/paths.js +3 -1
  47. package/dist/validators.d.ts +6 -0
  48. package/dist/validators.js +14 -1
  49. package/dist/visibility/dto.d.ts +15 -0
  50. package/dist/visibility/dto.js +68 -0
  51. package/dist/visibility/index.d.ts +59 -0
  52. package/dist/visibility/index.js +165 -0
  53. package/package.json +6 -2
@@ -0,0 +1,530 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DocumentPaymentIdDto = exports.RecordDocumentPaymentDto = exports.PayDocumentDto = exports.DocumentPayQueryDto = exports.DocumentPayTokenDto = exports.SendDocumentDto = exports.ReassignPrivateDocumentsDto = exports.DocumentImageUrlsDto = exports.DocumentImageNameDto = exports.VoidDocumentDto = exports.UpdateDocumentDto = exports.CreateDocumentDto = exports.DocumentIdDto = exports.GetDocumentsDto = exports.CreateDocumentTemplateDto = exports.UpdateDocumentTemplateDto = exports.DocumentTemplateIdDto = exports.GetDocumentTemplatesDto = void 0;
13
+ const class_validator_1 = require("class-validator");
14
+ const class_transformer_1 = require("class-transformer");
15
+ const enum_1 = require("@managemint-solutions/entities/documents/enum");
16
+ const transforms_1 = require("../transforms");
17
+ const validators_1 = require("../validators");
18
+ const content_1 = require("./content");
19
+ const values_1 = require("./render/values");
20
+ // class-validator versions of the shared DTO types from @managemint-solutions/entities, so the
21
+ // wire contract cannot drift. The content rules (variables, blocks, values, currency) live in
22
+ // ./content.ts, once, and each decorator there answers with the specific problem it found.
23
+ //
24
+ // class-validator runs a property's decorators bottom-up, and the api answers with the first
25
+ // failure, so each property's type check sits last: a missing title says "Title must be text",
26
+ // not that it is too long.
27
+ // ------------------------------------------------------------
28
+ // Templates
29
+ // ------------------------------------------------------------
30
+ class GetDocumentTemplatesDto {
31
+ search;
32
+ category;
33
+ archive = false;
34
+ page = 1;
35
+ page_size = 10;
36
+ }
37
+ exports.GetDocumentTemplatesDto = GetDocumentTemplatesDto;
38
+ __decorate([
39
+ (0, class_validator_1.IsOptional)(),
40
+ (0, validators_1.IsNullable)(),
41
+ (0, class_validator_1.MaxLength)(255, { message: 'Search query cannot exceed 255 characters' }),
42
+ (0, class_validator_1.MinLength)(1, { message: 'Search query cannot be empty' }),
43
+ (0, class_validator_1.IsString)({ message: 'Search query must be a string' }),
44
+ __metadata("design:type", Object)
45
+ ], GetDocumentTemplatesDto.prototype, "search", void 0);
46
+ __decorate([
47
+ (0, class_validator_1.IsOptional)(),
48
+ (0, validators_1.IsNullable)(),
49
+ (0, content_1.IsDocumentCategory)(),
50
+ __metadata("design:type", Object)
51
+ ], GetDocumentTemplatesDto.prototype, "category", void 0);
52
+ __decorate([
53
+ (0, class_validator_1.IsOptional)(),
54
+ (0, validators_1.IsNullable)(),
55
+ (0, class_transformer_1.Transform)(({ value }) => value ? value === 'true' : false, { toClassOnly: true }),
56
+ (0, class_validator_1.IsBoolean)({ message: 'Include archived must be a boolean' }),
57
+ __metadata("design:type", Boolean)
58
+ ], GetDocumentTemplatesDto.prototype, "archive", void 0);
59
+ __decorate([
60
+ (0, class_validator_1.IsOptional)(),
61
+ (0, class_transformer_1.Transform)(({ value }) => value ? Number(value) : 1, { toClassOnly: true }),
62
+ (0, class_validator_1.Min)(1, { message: 'Page must be at least 1' }),
63
+ (0, class_validator_1.IsNumber)({}, { message: 'Page must be a number' }),
64
+ __metadata("design:type", Number)
65
+ ], GetDocumentTemplatesDto.prototype, "page", void 0);
66
+ __decorate([
67
+ (0, class_validator_1.IsOptional)(),
68
+ (0, class_transformer_1.Transform)(({ value }) => value ? Number(value) : 10, { toClassOnly: true }),
69
+ (0, class_validator_1.Max)(100, { message: 'Page size cannot exceed 100' }),
70
+ (0, class_validator_1.Min)(1, { message: 'Page size must be at least 1' }),
71
+ (0, class_validator_1.IsNumber)({}, { message: 'Page size must be a number' }),
72
+ __metadata("design:type", Number)
73
+ ], GetDocumentTemplatesDto.prototype, "page_size", void 0);
74
+ class DocumentTemplateIdDto {
75
+ templateId;
76
+ }
77
+ exports.DocumentTemplateIdDto = DocumentTemplateIdDto;
78
+ __decorate([
79
+ (0, class_validator_1.IsUUID)('7', { message: 'Invalid template ID format' }),
80
+ __metadata("design:type", String)
81
+ ], DocumentTemplateIdDto.prototype, "templateId", void 0);
82
+ /** Saving replaces the whole template. Its visibility changes only through the visibility route. */
83
+ class UpdateDocumentTemplateDto {
84
+ name;
85
+ category;
86
+ number_prefix;
87
+ variables;
88
+ blocks;
89
+ }
90
+ exports.UpdateDocumentTemplateDto = UpdateDocumentTemplateDto;
91
+ __decorate([
92
+ (0, class_validator_1.MaxLength)(100, { message: 'Name cannot exceed 100 characters' }),
93
+ (0, class_validator_1.MinLength)(1, { message: 'Name cannot be empty' }),
94
+ (0, class_validator_1.IsString)({ message: 'Name must be text' }),
95
+ __metadata("design:type", String)
96
+ ], UpdateDocumentTemplateDto.prototype, "name", void 0);
97
+ __decorate([
98
+ (0, class_validator_1.IsOptional)(),
99
+ (0, content_1.IsDocumentCategory)(),
100
+ __metadata("design:type", String)
101
+ ], UpdateDocumentTemplateDto.prototype, "category", void 0);
102
+ __decorate([
103
+ (0, class_validator_1.IsOptional)(),
104
+ (0, content_1.IsDocumentNumberPrefix)(),
105
+ __metadata("design:type", String)
106
+ ], UpdateDocumentTemplateDto.prototype, "number_prefix", void 0);
107
+ __decorate([
108
+ (0, content_1.IsDocumentVariables)(),
109
+ __metadata("design:type", Array)
110
+ ], UpdateDocumentTemplateDto.prototype, "variables", void 0);
111
+ __decorate([
112
+ (0, content_1.IsDocumentBlocks)(),
113
+ __metadata("design:type", Array)
114
+ ], UpdateDocumentTemplateDto.prototype, "blocks", void 0);
115
+ /** A new template: what a save holds, plus who sees it (omitted: the organization). */
116
+ class CreateDocumentTemplateDto extends UpdateDocumentTemplateDto {
117
+ visibility;
118
+ }
119
+ exports.CreateDocumentTemplateDto = CreateDocumentTemplateDto;
120
+ __decorate([
121
+ (0, class_validator_1.IsOptional)(),
122
+ (0, class_validator_1.IsEnum)(enum_1.DocumentVisibility, { message: `Visibility must be one of: ${Object.values(enum_1.DocumentVisibility).join(', ')}` }),
123
+ __metadata("design:type", String)
124
+ ], CreateDocumentTemplateDto.prototype, "visibility", void 0);
125
+ // ------------------------------------------------------------
126
+ // Documents
127
+ // ------------------------------------------------------------
128
+ class GetDocumentsDto {
129
+ search;
130
+ category;
131
+ status;
132
+ // A UUID, or the base64-JSON option value the portal's client select sends.
133
+ client_id;
134
+ template_id;
135
+ // Parents only when true; otherwise parents are left out of the list.
136
+ recurring;
137
+ repeat_from;
138
+ payment;
139
+ page = 1;
140
+ page_size = 10;
141
+ }
142
+ exports.GetDocumentsDto = GetDocumentsDto;
143
+ __decorate([
144
+ (0, class_validator_1.IsOptional)(),
145
+ (0, validators_1.IsNullable)(),
146
+ (0, class_validator_1.MaxLength)(255, { message: 'Search query cannot exceed 255 characters' }),
147
+ (0, class_validator_1.MinLength)(1, { message: 'Search query cannot be empty' }),
148
+ (0, class_validator_1.IsString)({ message: 'Search query must be a string' }),
149
+ __metadata("design:type", Object)
150
+ ], GetDocumentsDto.prototype, "search", void 0);
151
+ __decorate([
152
+ (0, class_validator_1.IsOptional)(),
153
+ (0, validators_1.IsNullable)(),
154
+ (0, content_1.IsDocumentCategory)(),
155
+ __metadata("design:type", Object)
156
+ ], GetDocumentsDto.prototype, "category", void 0);
157
+ __decorate([
158
+ (0, class_validator_1.IsOptional)(),
159
+ (0, validators_1.IsNullable)(),
160
+ (0, class_validator_1.IsEnum)(enum_1.DocumentStatus, { message: `Status must be one of: ${Object.values(enum_1.DocumentStatus).join(', ')}` }),
161
+ __metadata("design:type", Object)
162
+ ], GetDocumentsDto.prototype, "status", void 0);
163
+ __decorate([
164
+ (0, class_validator_1.IsOptional)(),
165
+ (0, validators_1.IsNullable)(),
166
+ (0, class_transformer_1.Transform)(({ value }) => (0, transforms_1.parseEntityIdFilter)(value), { toClassOnly: true }),
167
+ (0, class_validator_1.IsUUID)('7', { message: 'Invalid client ID format' }),
168
+ __metadata("design:type", Object)
169
+ ], GetDocumentsDto.prototype, "client_id", void 0);
170
+ __decorate([
171
+ (0, class_validator_1.IsOptional)(),
172
+ (0, validators_1.IsNullable)(),
173
+ (0, class_validator_1.IsUUID)('7', { message: 'Invalid template ID format' }),
174
+ __metadata("design:type", Object)
175
+ ], GetDocumentsDto.prototype, "template_id", void 0);
176
+ __decorate([
177
+ (0, class_validator_1.IsOptional)(),
178
+ (0, class_transformer_1.Transform)(({ value }) => value === true || value === 'true', { toClassOnly: true }),
179
+ (0, class_validator_1.IsBoolean)({ message: 'Recurring must be a boolean' }),
180
+ __metadata("design:type", Boolean)
181
+ ], GetDocumentsDto.prototype, "recurring", void 0);
182
+ __decorate([
183
+ (0, class_validator_1.IsOptional)(),
184
+ (0, validators_1.IsNullable)(),
185
+ (0, class_validator_1.IsUUID)('7', { message: 'Invalid recurring document ID format' }),
186
+ __metadata("design:type", Object)
187
+ ], GetDocumentsDto.prototype, "repeat_from", void 0);
188
+ __decorate([
189
+ (0, class_validator_1.IsOptional)(),
190
+ (0, validators_1.IsNullable)(),
191
+ (0, class_validator_1.IsEnum)(enum_1.DocumentPaymentFilter, { message: `Payment must be one of: ${Object.values(enum_1.DocumentPaymentFilter).join(', ')}` }),
192
+ __metadata("design:type", Object)
193
+ ], GetDocumentsDto.prototype, "payment", void 0);
194
+ __decorate([
195
+ (0, class_validator_1.IsOptional)(),
196
+ (0, class_transformer_1.Transform)(({ value }) => value ? Number(value) : 1, { toClassOnly: true }),
197
+ (0, class_validator_1.Min)(1, { message: 'Page must be at least 1' }),
198
+ (0, class_validator_1.IsNumber)({}, { message: 'Page must be a number' }),
199
+ __metadata("design:type", Number)
200
+ ], GetDocumentsDto.prototype, "page", void 0);
201
+ __decorate([
202
+ (0, class_validator_1.IsOptional)(),
203
+ (0, class_transformer_1.Transform)(({ value }) => value ? Number(value) : 10, { toClassOnly: true }),
204
+ (0, class_validator_1.Max)(100, { message: 'Page size cannot exceed 100' }),
205
+ (0, class_validator_1.Min)(1, { message: 'Page size must be at least 1' }),
206
+ (0, class_validator_1.IsNumber)({}, { message: 'Page size must be a number' }),
207
+ __metadata("design:type", Number)
208
+ ], GetDocumentsDto.prototype, "page_size", void 0);
209
+ class DocumentIdDto {
210
+ documentId;
211
+ }
212
+ exports.DocumentIdDto = DocumentIdDto;
213
+ __decorate([
214
+ (0, class_validator_1.IsUUID)('7', { message: 'Invalid document ID format' }),
215
+ __metadata("design:type", String)
216
+ ], DocumentIdDto.prototype, "documentId", void 0);
217
+ /** How many addresses one send may go to, and copy in, and how long its subject and message may be. */
218
+ const MAX_SEND_ADDRESSES = 5;
219
+ const MAX_SUBJECT_LENGTH = 200;
220
+ const MAX_MESSAGE_LENGTH = 5000;
221
+ /**
222
+ * A stored email (a recurring parent's, a scheduled draft's): exactly what `SendDocumentDto`
223
+ * takes, checked by the same rules, so what the cron sends later is what a send would accept now.
224
+ */
225
+ const IsDocumentEmail = (0, validators_1.fromProblem)('isDocumentEmail', (value) => {
226
+ if (!(0, values_1.isObject)(value))
227
+ return 'Email must be an object';
228
+ const errors = (0, class_validator_1.validateSync)((0, class_transformer_1.plainToInstance)(SendDocumentDto, value), { whitelist: true, forbidNonWhitelisted: true });
229
+ return errors.length === 0 ? null : `Email: ${Object.values(errors[0].constraints ?? {})[0] ?? 'is not valid'}`;
230
+ });
231
+ /**
232
+ * A recurring parent's schedule and a draft's issue date, on create and on a draft save. Each is
233
+ * checked alone here; how they go together (a parent needs its first date, never an issue date)
234
+ * is the api's.
235
+ */
236
+ class DocumentScheduleDto {
237
+ repeat;
238
+ repeat_next_at;
239
+ repeat_until;
240
+ repeat_paused;
241
+ issue_at;
242
+ email;
243
+ }
244
+ __decorate([
245
+ (0, class_validator_1.IsOptional)(),
246
+ (0, validators_1.IsNullable)(),
247
+ (0, class_validator_1.IsEnum)(enum_1.DocumentRepeat, { message: `Repeat must be one of: ${Object.values(enum_1.DocumentRepeat).join(', ')}` }),
248
+ __metadata("design:type", Object)
249
+ ], DocumentScheduleDto.prototype, "repeat", void 0);
250
+ __decorate([
251
+ (0, class_validator_1.IsOptional)(),
252
+ (0, validators_1.IsNullable)(),
253
+ (0, validators_1.IsCalendarDate)({ message: 'First issue date must be a calendar date (YYYY-MM-DD)' }),
254
+ __metadata("design:type", Object)
255
+ ], DocumentScheduleDto.prototype, "repeat_next_at", void 0);
256
+ __decorate([
257
+ (0, class_validator_1.IsOptional)(),
258
+ (0, validators_1.IsNullable)(),
259
+ (0, validators_1.IsCalendarDate)({ message: 'Repeat until must be a calendar date (YYYY-MM-DD)' }),
260
+ __metadata("design:type", Object)
261
+ ], DocumentScheduleDto.prototype, "repeat_until", void 0);
262
+ __decorate([
263
+ (0, class_validator_1.IsOptional)(),
264
+ (0, class_validator_1.IsBoolean)({ message: 'Paused must be true or false' }),
265
+ __metadata("design:type", Boolean)
266
+ ], DocumentScheduleDto.prototype, "repeat_paused", void 0);
267
+ __decorate([
268
+ (0, class_validator_1.IsOptional)(),
269
+ (0, validators_1.IsNullable)(),
270
+ (0, validators_1.IsCalendarDate)({ message: 'Issue date must be a calendar date (YYYY-MM-DD)' }),
271
+ __metadata("design:type", Object)
272
+ ], DocumentScheduleDto.prototype, "issue_at", void 0);
273
+ __decorate([
274
+ (0, class_validator_1.IsOptional)(),
275
+ (0, validators_1.IsNullable)(),
276
+ IsDocumentEmail(),
277
+ __metadata("design:type", Object)
278
+ ], DocumentScheduleDto.prototype, "email", void 0);
279
+ /**
280
+ * A new draft. Its values cannot be checked here - with a template, the variables they fill are
281
+ * the template's - so the api checks the draft it composes with `documentProblem`.
282
+ */
283
+ class CreateDocumentDto extends DocumentScheduleDto {
284
+ template_id;
285
+ client_id;
286
+ title;
287
+ currency;
288
+ variable_values;
289
+ // A blank draft's; one made from a template takes the template's, and its shares.
290
+ visibility;
291
+ }
292
+ exports.CreateDocumentDto = CreateDocumentDto;
293
+ __decorate([
294
+ (0, class_validator_1.IsOptional)(),
295
+ (0, validators_1.IsNullable)(),
296
+ (0, class_validator_1.IsUUID)('7', { message: 'Invalid template ID format' }),
297
+ __metadata("design:type", Object)
298
+ ], CreateDocumentDto.prototype, "template_id", void 0);
299
+ __decorate([
300
+ (0, class_validator_1.IsOptional)(),
301
+ (0, validators_1.IsNullable)(),
302
+ (0, class_validator_1.IsUUID)('7', { message: 'Invalid client ID format' }),
303
+ __metadata("design:type", Object)
304
+ ], CreateDocumentDto.prototype, "client_id", void 0);
305
+ __decorate([
306
+ (0, class_validator_1.IsOptional)(),
307
+ (0, class_validator_1.MaxLength)(200, { message: 'Title cannot exceed 200 characters' }),
308
+ (0, class_validator_1.IsString)({ message: 'Title must be text' }),
309
+ __metadata("design:type", String)
310
+ ], CreateDocumentDto.prototype, "title", void 0);
311
+ __decorate([
312
+ (0, class_validator_1.IsOptional)(),
313
+ (0, content_1.IsDocumentCurrency)(),
314
+ __metadata("design:type", Object)
315
+ ], CreateDocumentDto.prototype, "currency", void 0);
316
+ __decorate([
317
+ (0, class_validator_1.IsOptional)(),
318
+ (0, class_validator_1.IsObject)({ message: 'Variable values must be an object' }),
319
+ __metadata("design:type", Object)
320
+ ], CreateDocumentDto.prototype, "variable_values", void 0);
321
+ __decorate([
322
+ (0, class_validator_1.IsOptional)(),
323
+ (0, class_validator_1.IsEnum)(enum_1.DocumentVisibility, { message: `Visibility must be one of: ${Object.values(enum_1.DocumentVisibility).join(', ')}` }),
324
+ __metadata("design:type", String)
325
+ ], CreateDocumentDto.prototype, "visibility", void 0);
326
+ /** A whole draft, under the same content rules as a template, plus its values and currency. */
327
+ class UpdateDocumentDto extends DocumentScheduleDto {
328
+ client_id;
329
+ title;
330
+ category;
331
+ number_prefix;
332
+ currency;
333
+ variables;
334
+ variable_values;
335
+ blocks;
336
+ }
337
+ exports.UpdateDocumentDto = UpdateDocumentDto;
338
+ __decorate([
339
+ (0, validators_1.IsNullable)(),
340
+ (0, class_validator_1.IsUUID)('7', { message: 'Invalid client ID format' }),
341
+ __metadata("design:type", Object)
342
+ ], UpdateDocumentDto.prototype, "client_id", void 0);
343
+ __decorate([
344
+ (0, class_validator_1.MaxLength)(200, { message: 'Title cannot exceed 200 characters' }),
345
+ (0, class_validator_1.IsString)({ message: 'Title must be text' }),
346
+ __metadata("design:type", String)
347
+ ], UpdateDocumentDto.prototype, "title", void 0);
348
+ __decorate([
349
+ (0, content_1.IsDocumentCategory)(),
350
+ __metadata("design:type", String)
351
+ ], UpdateDocumentDto.prototype, "category", void 0);
352
+ __decorate([
353
+ (0, content_1.IsDocumentNumberPrefix)(),
354
+ __metadata("design:type", String)
355
+ ], UpdateDocumentDto.prototype, "number_prefix", void 0);
356
+ __decorate([
357
+ (0, content_1.IsDocumentCurrency)(),
358
+ __metadata("design:type", Object)
359
+ ], UpdateDocumentDto.prototype, "currency", void 0);
360
+ __decorate([
361
+ (0, content_1.IsDocumentVariables)(),
362
+ __metadata("design:type", Array)
363
+ ], UpdateDocumentDto.prototype, "variables", void 0);
364
+ __decorate([
365
+ (0, content_1.IsDocumentVariableValues)(),
366
+ __metadata("design:type", Object)
367
+ ], UpdateDocumentDto.prototype, "variable_values", void 0);
368
+ __decorate([
369
+ (0, content_1.IsDocumentBlocks)(),
370
+ __metadata("design:type", Array)
371
+ ], UpdateDocumentDto.prototype, "blocks", void 0);
372
+ class VoidDocumentDto {
373
+ reason;
374
+ }
375
+ exports.VoidDocumentDto = VoidDocumentDto;
376
+ __decorate([
377
+ (0, class_validator_1.MaxLength)(500, { message: 'Reason cannot exceed 500 characters' }),
378
+ (0, class_validator_1.Matches)(/\S/, { message: 'Give a reason for voiding the document' }),
379
+ (0, class_validator_1.IsString)({ message: 'Give a reason for voiding the document' }),
380
+ __metadata("design:type", String)
381
+ ], VoidDocumentDto.prototype, "reason", void 0);
382
+ class DocumentImageNameDto {
383
+ // The resource checks the name itself (characters, length, an image extension) before it
384
+ // keeps the extension, which a decorator cannot.
385
+ name;
386
+ }
387
+ exports.DocumentImageNameDto = DocumentImageNameDto;
388
+ __decorate([
389
+ (0, class_validator_1.MinLength)(1, { message: 'Image name cannot be empty' }),
390
+ (0, class_validator_1.IsString)({ message: 'Image name must be text' }),
391
+ __metadata("design:type", String)
392
+ ], DocumentImageNameDto.prototype, "name", void 0);
393
+ /** How many image paths one call may sign - more than any document holds. */
394
+ const MAX_IMAGE_PATHS = 50;
395
+ /**
396
+ * Image paths to sign for reading, as a query (`?paths=a&paths=b`; one `paths` arrives as a plain
397
+ * string and is taken as a list of one). Each must be one `createImageUploadUrl` handed out
398
+ * (`documents/images/<uuid>.<ext>`); `imageUrls` then signs it under the caller's own
399
+ * organization, so nothing outside that folder can be named.
400
+ */
401
+ class DocumentImageUrlsDto {
402
+ paths;
403
+ }
404
+ exports.DocumentImageUrlsDto = DocumentImageUrlsDto;
405
+ __decorate([
406
+ (0, class_validator_1.Matches)(content_1.IMAGE_PATH, { each: true, message: 'Each path must be an image uploaded for documents' }),
407
+ (0, class_validator_1.IsString)({ each: true, message: 'Each path must be an image uploaded for documents' }),
408
+ (0, class_validator_1.ArrayMaxSize)(MAX_IMAGE_PATHS, { message: `Cannot sign more than ${MAX_IMAGE_PATHS} images at once` }),
409
+ (0, class_validator_1.ArrayMinSize)(1, { message: 'Give at least one image path' }),
410
+ (0, class_validator_1.IsArray)({ message: 'Paths must be a list' }),
411
+ (0, class_transformer_1.Transform)(({ value }) => (typeof value === 'string' ? [value] : value), { toClassOnly: true }),
412
+ __metadata("design:type", Array)
413
+ ], DocumentImageUrlsDto.prototype, "paths", void 0);
414
+ /** The owner's move of one person's private templates and documents to another; v4 user ids. */
415
+ class ReassignPrivateDocumentsDto {
416
+ from_user_id;
417
+ to_user_id;
418
+ }
419
+ exports.ReassignPrivateDocumentsDto = ReassignPrivateDocumentsDto;
420
+ __decorate([
421
+ (0, class_validator_1.IsUUID)('4', { message: 'Invalid from user ID format' }),
422
+ __metadata("design:type", String)
423
+ ], ReassignPrivateDocumentsDto.prototype, "from_user_id", void 0);
424
+ __decorate([
425
+ (0, class_validator_1.IsUUID)('4', { message: 'Invalid to user ID format' }),
426
+ __metadata("design:type", String)
427
+ ], ReassignPrivateDocumentsDto.prototype, "to_user_id", void 0);
428
+ // ------------------------------------------------------------
429
+ // Sending and paying
430
+ // ------------------------------------------------------------
431
+ /** A pay link's token: the document's mms_id, a dot, and the api's base64url HMAC-SHA256 of it. */
432
+ const PAY_TOKEN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.[A-Za-z0-9_-]{43}$/;
433
+ /** An issued document's email. Who may send it, and whether Pay now may go on it, is the api's. */
434
+ class SendDocumentDto {
435
+ to;
436
+ cc;
437
+ subject;
438
+ message;
439
+ pay_now;
440
+ }
441
+ exports.SendDocumentDto = SendDocumentDto;
442
+ __decorate([
443
+ (0, class_validator_1.IsEmail)({}, { each: true, message: 'Each recipient must be an email address' }),
444
+ (0, class_validator_1.ArrayMaxSize)(MAX_SEND_ADDRESSES, { message: `Send to ${MAX_SEND_ADDRESSES} addresses at most` }),
445
+ (0, class_validator_1.ArrayMinSize)(1, { message: 'Give at least one recipient' }),
446
+ (0, class_validator_1.IsArray)({ message: 'Recipients must be a list' }),
447
+ __metadata("design:type", Array)
448
+ ], SendDocumentDto.prototype, "to", void 0);
449
+ __decorate([
450
+ (0, class_validator_1.IsOptional)(),
451
+ (0, class_validator_1.IsEmail)({}, { each: true, message: 'Each copy address must be an email address' }),
452
+ (0, class_validator_1.ArrayMaxSize)(MAX_SEND_ADDRESSES, { message: `Copy ${MAX_SEND_ADDRESSES} addresses at most` }),
453
+ (0, class_validator_1.IsArray)({ message: 'Copy addresses must be a list' }),
454
+ __metadata("design:type", Array)
455
+ ], SendDocumentDto.prototype, "cc", void 0);
456
+ __decorate([
457
+ (0, class_validator_1.MaxLength)(MAX_SUBJECT_LENGTH, { message: `Subject cannot exceed ${MAX_SUBJECT_LENGTH} characters` }),
458
+ (0, class_validator_1.Matches)(/\S/, { message: 'Give the email a subject' }),
459
+ (0, class_validator_1.IsString)({ message: 'Give the email a subject' }),
460
+ __metadata("design:type", String)
461
+ ], SendDocumentDto.prototype, "subject", void 0);
462
+ __decorate([
463
+ (0, class_validator_1.MaxLength)(MAX_MESSAGE_LENGTH, { message: `Message cannot exceed ${MAX_MESSAGE_LENGTH} characters` }),
464
+ (0, class_validator_1.IsString)({ message: 'Message must be text' }),
465
+ __metadata("design:type", String)
466
+ ], SendDocumentDto.prototype, "message", void 0);
467
+ __decorate([
468
+ (0, class_validator_1.IsBoolean)({ message: 'Pay now must be true or false' }),
469
+ __metadata("design:type", Boolean)
470
+ ], SendDocumentDto.prototype, "pay_now", void 0);
471
+ /** A public pay link's token. Only its shape is checked here; the api checks the signature. */
472
+ class DocumentPayTokenDto {
473
+ token;
474
+ }
475
+ exports.DocumentPayTokenDto = DocumentPayTokenDto;
476
+ __decorate([
477
+ (0, class_validator_1.Matches)(PAY_TOKEN, { message: 'This payment link is not valid' }),
478
+ (0, class_validator_1.IsString)({ message: 'This payment link is not valid' }),
479
+ __metadata("design:type", String)
480
+ ], DocumentPayTokenDto.prototype, "token", void 0);
481
+ /** Paystack's return to the pay page: its reference - letters, digits and - . = only, as Paystack allows. */
482
+ class DocumentPayQueryDto {
483
+ reference;
484
+ }
485
+ exports.DocumentPayQueryDto = DocumentPayQueryDto;
486
+ __decorate([
487
+ (0, class_validator_1.IsOptional)(),
488
+ (0, class_validator_1.Matches)(/^[A-Za-z0-9.=-]{1,100}$/, { message: 'Invalid payment reference' }),
489
+ (0, class_validator_1.IsString)({ message: 'Invalid payment reference' }),
490
+ __metadata("design:type", String)
491
+ ], DocumentPayQueryDto.prototype, "reference", void 0);
492
+ class PayDocumentDto {
493
+ email;
494
+ }
495
+ exports.PayDocumentDto = PayDocumentDto;
496
+ __decorate([
497
+ (0, class_validator_1.MaxLength)(254, { message: 'Email cannot exceed 254 characters' }),
498
+ (0, class_validator_1.IsEmail)({}, { message: 'Give a valid email address for your receipt' }),
499
+ __metadata("design:type", String)
500
+ ], PayDocumentDto.prototype, "email", void 0);
501
+ /** A document marked paid by hand: the date the money arrived, and the bank reference if any. */
502
+ class RecordDocumentPaymentDto {
503
+ paid_at;
504
+ reference;
505
+ }
506
+ exports.RecordDocumentPaymentDto = RecordDocumentPaymentDto;
507
+ __decorate([
508
+ (0, validators_1.IsCalendarDate)({ message: 'Paid on must be a calendar date (YYYY-MM-DD)' }),
509
+ __metadata("design:type", String)
510
+ ], RecordDocumentPaymentDto.prototype, "paid_at", void 0);
511
+ __decorate([
512
+ (0, class_validator_1.IsOptional)(),
513
+ (0, validators_1.IsNullable)(),
514
+ (0, class_validator_1.MaxLength)(100, { message: 'Reference cannot exceed 100 characters' }),
515
+ (0, class_validator_1.IsString)({ message: 'Reference must be text' }),
516
+ __metadata("design:type", Object)
517
+ ], RecordDocumentPaymentDto.prototype, "reference", void 0);
518
+ class DocumentPaymentIdDto {
519
+ documentId;
520
+ paymentId;
521
+ }
522
+ exports.DocumentPaymentIdDto = DocumentPaymentIdDto;
523
+ __decorate([
524
+ (0, class_validator_1.IsUUID)('7', { message: 'Invalid document ID format' }),
525
+ __metadata("design:type", String)
526
+ ], DocumentPaymentIdDto.prototype, "documentId", void 0);
527
+ __decorate([
528
+ (0, class_validator_1.IsUUID)('7', { message: 'Invalid payment ID format' }),
529
+ __metadata("design:type", String)
530
+ ], DocumentPaymentIdDto.prototype, "paymentId", void 0);
@@ -0,0 +1,4 @@
1
+ export * from './dto';
2
+ export { documentProblem } from './content';
3
+ export { DocumentTemplatesResource, type DocumentTemplateRecord } from './document-templates';
4
+ export { DocumentsResource, type CreateDocumentRow, type DocumentListRecord, type DocumentRecord, type DocumentSendEvent, type UpdateDocumentRow, } from './documents';
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.DocumentsResource = exports.DocumentTemplatesResource = exports.documentProblem = void 0;
18
+ __exportStar(require("./dto"), exports);
19
+ var content_1 = require("./content");
20
+ Object.defineProperty(exports, "documentProblem", { enumerable: true, get: function () { return content_1.documentProblem; } });
21
+ var document_templates_1 = require("./document-templates");
22
+ Object.defineProperty(exports, "DocumentTemplatesResource", { enumerable: true, get: function () { return document_templates_1.DocumentTemplatesResource; } });
23
+ var documents_1 = require("./documents");
24
+ Object.defineProperty(exports, "DocumentsResource", { enumerable: true, get: function () { return documents_1.DocumentsResource; } });
@@ -0,0 +1,64 @@
1
+ import type { DocumentBlock, DocumentVariable, DocumentVariableValues } from '@managemint-solutions/entities/documents';
2
+ import { DocumentStatus } from '@managemint-solutions/entities/documents/enum';
3
+ /** What is printed: a document, or a template (saved, or unsaved in the builder). */
4
+ export type PrintableDocument = {
5
+ title: string;
6
+ number: string | null;
7
+ /** Null for a template. */
8
+ status: DocumentStatus | null;
9
+ /** The document's currency, or the organization's when it has none. */
10
+ currency: string;
11
+ variables: DocumentVariable[];
12
+ /** Every value to print, the system values included. */
13
+ values: DocumentVariableValues;
14
+ blocks: DocumentBlock[];
15
+ };
16
+ /**
17
+ * Plain text with each `{{key}}` replaced by its value as the document prints it - money in its
18
+ * currency, dates written out - and a key with no value left empty: a stored email's subject and
19
+ * message, written before the document had a number, filled when it is sent. Text, not HTML, so
20
+ * nothing is escaped; the email template shows it as text.
21
+ */
22
+ export declare const fillText: (text: string, document: Pick<PrintableDocument, "variables" | "values" | "currency" | "status">) => string;
23
+ /** A running header or footer: its left and right text as HTML, escaped, page counters as spans. */
24
+ export type DocumentBand = {
25
+ left: string;
26
+ right: string;
27
+ };
28
+ /** A document rendered: the page body, and the bands that repeat on every page. */
29
+ export type RenderedDocument = {
30
+ /** Self-contained HTML: the first page's letterhead, then the blocks. Header and footer blocks are not in it. */
31
+ html: string;
32
+ /** The header block's text, or null without one (no header at all). */
33
+ header: DocumentBand | null;
34
+ /** The footer block's text - or, with none, the organization, title and number, and "Page X of Y". */
35
+ footer: DocumentBand;
36
+ };
37
+ /**
38
+ * The page geometry, in inches: the side and bottom margins, and the top margin - grown to make
39
+ * room when the document has a header. The api's PDF and the portal's paged preview use the same.
40
+ */
41
+ export declare const DOCUMENT_PAGE_MARGINS: {
42
+ readonly top: 0.62;
43
+ readonly topWithHeader: 0.95;
44
+ readonly bottom: 0.7;
45
+ readonly side: 0.7;
46
+ };
47
+ /**
48
+ * One band as a styled block: left text left, right text right, in the footer's small grey type.
49
+ * The styles are inline (a placeholder's included) because Chromium's header and footer templates
50
+ * ignore the document's CSS; the side margins mirror the page's. The api hands it to Chromium as
51
+ * the header or footer template; the portal's preview places it on each page.
52
+ */
53
+ export declare const renderBand: (band: DocumentBand, edge: "top" | "bottom") => string;
54
+ /**
55
+ * A document's blocks and values as HTML, plus its running header and footer - the only way a
56
+ * document or template is shown, so what is seen is what prints. Styled as the subscription
57
+ * invoice is: the first page's letterhead - the organization top left against the title, number,
58
+ * issue date and status top right - then the blocks. Header and footer blocks print nothing in the
59
+ * body: their text is `header` / `footer`, with `{{key}}`s printed as in the body and
60
+ * `{{page_number}}` / `{{page_count}}` as page-counter spans. `imageUrls` maps the image blocks'
61
+ * paths to URLs the caller signed; a path without one prints as `[Image]` on a draft or template
62
+ * and as nothing once issued.
63
+ */
64
+ export declare const renderDocument: (document: PrintableDocument, imageUrls: Record<string, string>) => RenderedDocument;