@jsb188/mday 1.1.4 → 1.1.6

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.
@@ -0,0 +1,245 @@
1
+ import {
2
+ COMPLIANCE_DOCUMENT_TYPE_ENUMS,
3
+ OPERATION_ENUMS,
4
+ ORG_CONTACTS,
5
+ ROLE_CATEGORY_ENUMS,
6
+ ROLE_ENUMS
7
+ } from '../constants/organization.ts';
8
+ import { PRODUCT_FEATURES } from '../constants/product.ts';
9
+
10
+ import type { AddressObj, StorageData } from '@jsb188/app/types/other.d';
11
+ import type { LogTypeEnum } from '../types/log.d';
12
+
13
+ /*
14
+ * Enums
15
+ */
16
+
17
+ export type OrganizationFeatureEnum = typeof PRODUCT_FEATURES[number];
18
+ export type OrganizationRoleEnum = typeof ROLE_ENUMS[number];
19
+ export type OrganizationOperationEnum = typeof OPERATION_ENUMS[number];
20
+ export type OrganizationDepartmentEnum = typeof ORG_CONTACTS[number];
21
+ export type OrganizationRoleCategoryEnum = typeof ROLE_CATEGORY_ENUMS[number];
22
+ export type OrganizationComplianceType = typeof COMPLIANCE_DOCUMENT_TYPE_ENUMS[number];
23
+
24
+ /**
25
+ * Query filters
26
+ */
27
+
28
+ export interface ChildOrgsFilterArgs {
29
+ internationalOnly?: boolean;
30
+ }
31
+
32
+ /*
33
+ * ACL
34
+ */
35
+
36
+ type ACLPermission = 0 | 1 | 2 | 3; // 0: no access, 1: read-only, 2: allow-write, 3: allow-manage
37
+ type ACLPermissionEnum = 'NONE' | 'READ' | 'WRITE' | 'MANAGE';
38
+
39
+ export interface OrganizationACL {
40
+ billing: ACLPermission;
41
+ logs: ACLPermission;
42
+ members: ACLPermission;
43
+ finances: ACLPermission;
44
+ settings: ACLPermission;
45
+ integrations: ACLPermission;
46
+ digests: ACLPermission;
47
+ reminders: ACLPermission;
48
+ }
49
+
50
+ export interface OrganizationACLGQLData {
51
+ billing: ACLPermissionEnum;
52
+ logs: ACLPermissionEnum;
53
+ members: ACLPermissionEnum;
54
+ finances: ACLPermissionEnum;
55
+ settings: ACLPermissionEnum;
56
+ integrations: ACLPermissionEnum;
57
+ digests: ACLPermissionEnum;
58
+ reminders: ACLPermissionEnum;
59
+ }
60
+
61
+ /**
62
+ * Organization object
63
+ */
64
+
65
+ export interface OrganizationShortData {
66
+ id: string;
67
+ name: string;
68
+ primary: boolean;
69
+ acl: OrganizationACL;
70
+ }
71
+
72
+ export interface OrganizationData {
73
+ __table: 'organizations';
74
+ id: bigint;
75
+ stripeCustomerId: string | null;
76
+ name: string;
77
+ commodities: string[] | null;
78
+ operation: OrganizationOperationEnum;
79
+ dailyDigestTime: string | null;
80
+ features: OrganizationFeatureEnum[];
81
+ settings?: OrganizationSettingsObj | null;
82
+ address?:
83
+ | null
84
+ | AddressObj & {
85
+ __table: 'organization_addresses';
86
+ organizationId: bigint;
87
+ };
88
+ activated: boolean;
89
+ }
90
+
91
+ export interface OrganizationContact {
92
+ department: OrganizationDepartmentEnum;
93
+ name?: string | null;
94
+ phoneNumber?: string | null;
95
+ emailAddress?: string | null;
96
+ }
97
+
98
+ export interface OrganizationSettingsObj {
99
+ timeZone: string | null;
100
+ language: string | null;
101
+ color: string | null;
102
+ priorityService: boolean;
103
+ directory?: OrganizationContact[];
104
+ }
105
+
106
+ export interface OrganizationChildData {
107
+ __table: 'organization_rels';
108
+ parentId: number | bigint | null;
109
+ childId: number | bigint;
110
+ organization: OrganizationData;
111
+ preferredContacts?: {
112
+ [key: OrganizationDepartmentEnum]: Partial<{
113
+ name: string | null;
114
+ phoneNumber: string | null;
115
+ emailAddress: string | null;
116
+ }>;
117
+ };
118
+ addedAt: Date;
119
+ }
120
+
121
+ /**
122
+ * Full organization object with relationship
123
+ */
124
+
125
+ export interface OrganizationRelData {
126
+ id: string;
127
+ primary: boolean;
128
+ role: OrganizationRoleEnum;
129
+ acl: OrganizationACL;
130
+ organization: OrganizationData;
131
+ }
132
+
133
+ /**
134
+ * GraphQL data for organization types
135
+ */
136
+
137
+ export interface OrganizationComplianceGQL {
138
+ __deleted?: boolean;
139
+
140
+ id: string;
141
+ number: string;
142
+ name: string;
143
+ type: OrganizationComplianceType;
144
+ expirationDate: string; // YYYY-MM-DD
145
+ notes: string;
146
+ createdAt: string; // ISO date string
147
+ updatedAt: string; // ISO date string
148
+
149
+ files: {
150
+ id: string;
151
+ complianceId: string;
152
+ storageId: string;
153
+ uri: string | null;
154
+ contentType: string | null;
155
+ order: number;
156
+ }[];
157
+ }
158
+
159
+ export interface OrganizationGQL {
160
+ id: string;
161
+ stripeCustomerId: string | null;
162
+ name: string;
163
+ commodities: string[] | null;
164
+ address: AddressObj;
165
+ operation: OrganizationOperationEnum;
166
+ compliance: OrganizationComplianceGQL[] | null;
167
+ features: OrganizationFeatureEnum[];
168
+ settings?: OrganizationSettingsObj | null;
169
+ directory: OrganizationContact[];
170
+ activated: boolean;
171
+ membersCount: number;
172
+ }
173
+
174
+ export interface OrganizationRelGQL {
175
+ id: string;
176
+ primary: boolean;
177
+ role: OrganizationRoleEnum;
178
+ acl: OrganizationACLGQLData;
179
+ organization: OrganizationGQL;
180
+ }
181
+
182
+ export interface OrganizationChildGQL {
183
+ id: string;
184
+ organization: OrganizationGQL;
185
+ addedAt: Date;
186
+ }
187
+
188
+ /**
189
+ * Compliances
190
+ */
191
+
192
+ export interface OrganizationComplianceFileData {
193
+ __table: 'organization_compliance_files';
194
+ id: number;
195
+ complianceId: number;
196
+ storageId: number;
197
+ order: number;
198
+ file: StorageData;
199
+ }
200
+
201
+ export interface OrganizationComplianceObj {
202
+ storageIds: number[] | null;
203
+ number: string;
204
+ name: string;
205
+ type: OrganizationComplianceType;
206
+ expirationDate: string; // cast as date: "YYYY-MM-DD" format (in database)
207
+ notes?: string;
208
+ }
209
+
210
+ export interface OrganizationComplianceData extends Omit<OrganizationComplianceObj, 'expirationDate'> {
211
+ __table: 'organization_compliances';
212
+ id: number;
213
+ organizationId: number;
214
+ expirationDate: Date; // in runtime deno-postgres converts it into JS Date (apparently because it has to)
215
+ documents: OrganizationComplianceFileData[] | null;
216
+ createdAt: Date;
217
+ updatedAt: Date;
218
+ }
219
+
220
+ /**
221
+ * Workflow instructions
222
+ */
223
+
224
+ export interface OrganizationInstructionsData {
225
+ __table: 'organization_instructions';
226
+ id: bigint | number;
227
+ organizationId: bigint | number;
228
+ logType: LogTypeEnum;
229
+ instructions: string;
230
+ summary: string;
231
+ createdAt: Date;
232
+ updatedAt: Date;
233
+ }
234
+
235
+ export interface OrganizationInstructionsGQL {
236
+ __deleted?: boolean;
237
+
238
+ id: string;
239
+ organizationId: string;
240
+ logType: LogTypeEnum;
241
+ instructions: string;
242
+ summary: string;
243
+ createdAt: string; // ISO date string
244
+ updatedAt: string; // ISO date string
245
+ }
@@ -0,0 +1,173 @@
1
+ import { PRODUCT_LIVESTOCK_STATUS, PRODUCT_LIVESTOCK_TYPES, PRODUCT_TYPES } from '../constants/product';
2
+ import type { AccountData } from '@jsb188/app/types/account.d';
3
+ import type { OrganizationData, OrganizationGQL } from './types/organization.d';
4
+ import type { AddressObj, ScheduleObj } from '@jsb188/app/types/other.d';
5
+
6
+ /**
7
+ * Enums
8
+ */
9
+
10
+ export type ProductTypeEnum = typeof PRODUCT_TYPES[number];
11
+ export type ProductLivestockTypeEnum = typeof PRODUCT_LIVESTOCK_TYPES[number];
12
+ export type ProductLivestockStatusEnum = typeof PRODUCT_LIVESTOCK_STATUS[number];
13
+
14
+ /**
15
+ * Filters
16
+ */
17
+
18
+ export interface ProductsFilterArgs {
19
+ preset?: '?' | null;
20
+ productType: ProductTypeEnum;
21
+ query?: string | null;
22
+ calDate?: string | null; // "YYYY-MM-DD"
23
+ timeZone?: string | null; // Server only for now
24
+ // status: ProductLivestockStatusEnum;
25
+ }
26
+
27
+ /**
28
+ * Product details; Livestock
29
+ */
30
+
31
+ export interface ProductLivestockObj {
32
+ // This interface is not ready yet; old system has to be migrated.
33
+ '?': '?';
34
+ }
35
+
36
+ export interface ProductLivestockData {
37
+ __table: 'products_livestock';
38
+ id?: number | bigint;
39
+ productId: number | bigint;
40
+ type: ProductLivestockTypeEnum;
41
+ status: ProductLivestockStatusEnum;
42
+ birthDate?: string | null; // "YYYY-MM-DD"
43
+ deathDate?: string | null; // "YYYY-MM-DD"
44
+ damIdentifier?: string | null;
45
+ livestockIdentifier: string;
46
+ livestockGroup?: string | null;
47
+ metadata: {
48
+ overview: string;
49
+ };
50
+ }
51
+
52
+ export interface ProductLivestockGQL {
53
+ __typename: 'ProductLivestock';
54
+
55
+ id: string;
56
+ organizationId: string;
57
+ damIdentifier: string | null;
58
+ livestockIdentifier: string | null;
59
+ livestockGroup: string | null;
60
+
61
+ type: ProductLivestockTypeEnum;
62
+ status: ProductLivestockStatusEnum;
63
+ livestockClass: string;
64
+
65
+ birthDate: string | null; // "YYYY-MM-DD"
66
+ deathDate: string | null; // "YYYY-MM-DD"
67
+ }
68
+
69
+ /**
70
+ * Product details; Calendar event
71
+ */
72
+
73
+ export interface ProductCalEventObj {
74
+ name: string;
75
+ metadata: Partial<{
76
+ schedule: ScheduleObj | null;
77
+ address: Partial<AddressObj> | null;
78
+ }>;
79
+
80
+ startAt: Date | string; // ISO Date string
81
+ endAt?: Date | string | null; // ISO Date string
82
+ }
83
+
84
+ export interface ProductCalEventData extends ProductCalEventObj {
85
+ __table: 'products_calendar_events';
86
+ productId: number | bigint;
87
+ }
88
+
89
+ export interface ProductCalEventGQL {
90
+ __typename: 'ProductCalEvent';
91
+
92
+ id: string;
93
+ organizationId: string;
94
+
95
+ name: string;
96
+ schedule: ScheduleObj | null;
97
+ address: AddressObj | null;
98
+ startAt: Date;
99
+ endAt: Date;
100
+ }
101
+
102
+ export type ProductDetailsObj = ProductLivestockObj | ProductCalEventObj;
103
+ export type ProductDetailsData = ProductLivestockData | ProductCalEventData;
104
+ export type ProductDetailsGQL = ProductLivestockGQL | ProductCalEventGQL;
105
+
106
+ /**
107
+ * CalEvent; attendance
108
+ */
109
+
110
+ export interface ProductAttendanceObj {
111
+ productId: number | bigint;
112
+ organizationId: number | bigint;
113
+ accountId: number | bigint;
114
+ attended: boolean | null;
115
+ calDate: string; // "YYYY-MM-DD" format
116
+ history?: [string, '0' | '1'][] | null; // [YYYY-MM-DD, '0' | '1'][]
117
+ }
118
+
119
+ export interface ProductAttendanceData extends ProductAttendanceObj {
120
+ __table: 'products_attendance';
121
+ organization: OrganizationData;
122
+ account: AccountData; // account data
123
+ }
124
+
125
+ export interface ProductAttendanceGQL {
126
+ __deleted: boolean; // For client-side only
127
+ id: string;
128
+ productId: string;
129
+ organizationId: string;
130
+ attended: boolean | null;
131
+ calDate: string; // "YYYY-MM-DD" format
132
+ organization: OrganizationGQL;
133
+ checkedBy: any; // account data
134
+ }
135
+
136
+ /**
137
+ * CalEvent; load list
138
+ */
139
+
140
+ export interface ProductLoadListData {
141
+ __table: 'products_load_list';
142
+ organizationId: number | bigint;
143
+ productId: number | bigint;
144
+ calDate: Date; // Postgres returns "date" as JS Date, but it's safe to convert "YYYY-MM-DD" without time zone.
145
+ items: string[][]; // [ [itemName, quantity, unit], ... ]
146
+ createdAt: Date;
147
+ updatedAt: Date;
148
+ }
149
+
150
+ /**
151
+ * Product data objects
152
+ */
153
+
154
+ export interface ProductData {
155
+ __table: 'products';
156
+ productId: number | bigint;
157
+ organizationId: number | bigint;
158
+ details: ProductDetailsData;
159
+ createdAt: Date;
160
+ updatedAt: Date;
161
+ }
162
+
163
+ export interface ProductGQL {
164
+ __deleted?: boolean; // For client-side only
165
+
166
+ id: string;
167
+ organizationId: string;
168
+ cursor: string | null; // Cursor for pagination
169
+ details: ProductDetailsGQL | null;
170
+
171
+ createdAt: string; // ISO Date
172
+ updatedAt: string; // ISO Date
173
+ }
@@ -0,0 +1,177 @@
1
+ import { REPORT_SORT_OPTS, REPORT_TYPES, REPORT_ROW_PRESETS } from '../constants/report';
2
+
3
+ /**
4
+ * Enums
5
+ */
6
+
7
+ type ReportTypeEnum = typeof REPORT_TYPES[number];
8
+ type ReportRowPresetEnum = typeof REPORT_ROW_PRESETS[number];
9
+ type ReportsSortEnum = typeof REPORT_SORT_OPTS[number];
10
+
11
+ /**
12
+ * Filters
13
+ */
14
+
15
+ export interface ReportsFilterArgs {
16
+ preset?: '?' | null;
17
+ reportType: ReportTypeEnum;
18
+ period: string; // YYYY-MM-DD
19
+ query?: string | null;
20
+ }
21
+
22
+ /**
23
+ * Report; fields
24
+ */
25
+
26
+ interface ReportFieldsObj {
27
+ __allowMultiples?: boolean; // Allow multiple copies of the same report (from 1 report template)
28
+ __notAutomated?: boolean; // If true, report is not skipped during automation
29
+ __prompt: string; // Server-only, this prompt used on the entire report as a whole (ie. OSP generation)
30
+ gridLayoutStyle?: string;
31
+ sections?: ReportFieldsSection[];
32
+ rows?: ReportFieldsRow[];
33
+ metadata?: ReportFieldsRow[];
34
+ variables: {
35
+ month?: number; // Used for MONTH presets (required for all preset="MONTH" rows)
36
+ [key: string]: any;
37
+ };
38
+ }
39
+
40
+ interface ReportFieldsSection {
41
+ id?: string; // GraphQL Cursor, client-side only, but if present in Server, it will be an Array
42
+ key: string; // Every section must have a unique string UID
43
+ isGroupTitle?: boolean;
44
+ sectionKey: string;
45
+ sectionName: string;
46
+ title: string;
47
+ description: string;
48
+ rows?: ReportFieldsRow[];
49
+
50
+ __prompt_section?: string; // Server-only; full prompt for this section - this is the only prompt that allows {{variable}} regex
51
+ __prompt_examples?: string; // Server-only; for examples of what the output should be
52
+ __prompt_topics?: string; // Server-only; for topics this section should cover
53
+ }
54
+
55
+ interface ReportFieldsRow {
56
+ id?: string; // GraphQL Cursor, client-side only, but if present in Server, it will be an Array
57
+ key: string; // Key is used to map row/columns to answers
58
+ preset?: ReportRowPresetEnum;
59
+ className?: string;
60
+ isHeader?: boolean;
61
+ columns: Partial<ReportFieldsColumn>[];
62
+ }
63
+
64
+ type ReportRowGQL = Omit<ReportFieldsRow, 'key'> & {
65
+ id: string; // GraphQL Cursor, client-side only, but if present in Server, it will be an Array
66
+ };
67
+
68
+ interface ReportFieldsColumn {
69
+ id: string; // GraphQL Cursor, client-side only, but if present in Server, it will be an Array
70
+ key: string; // Key is used to map column to answers
71
+ className?: string;
72
+ labelClassName?: string;
73
+ label: string;
74
+ text: string;
75
+ placeholder: string | null;
76
+ value: string | null; // Available only in server; this value has the indexes to map answers to directly without keys
77
+ checked: boolean | null;
78
+ }
79
+
80
+ /**
81
+ * Report data
82
+ */
83
+
84
+ export interface ReportData {
85
+ __table: 'reports';
86
+
87
+ id: number;
88
+ type: ReportTypeEnum;
89
+ documentName: string;
90
+ title: string;
91
+ description: string;
92
+ order: number;
93
+
94
+ fields: ReportFieldsObj;
95
+ submission?: ReportSubmissionData | null;
96
+
97
+ template?: {
98
+ __table: 'report_templates';
99
+ id: number;
100
+ fields: ReportFieldsObj;
101
+ description: string | null;
102
+ };
103
+ }
104
+
105
+ export interface ReportGQL {
106
+ __deleted?: boolean;
107
+
108
+ id: string;
109
+ organizationId: string;
110
+ documentName: string;
111
+ title: string;
112
+ description: string;
113
+ type: ReportTypeEnum;
114
+ period: string; // YYYY-MM-DD
115
+ evidencesCount: number;
116
+ activityAt: string | null; // ISO date string
117
+
118
+ sections?: ReportFieldsSection[];
119
+ rows?: ReportRowGQL[];
120
+ }
121
+
122
+ /**
123
+ * Report submission data
124
+ */
125
+
126
+ export interface ReportEvidenceGQL {
127
+ __deleted?: boolean;
128
+
129
+ id: string; // GraphQL Cursor
130
+ reportSubmissionId: string;
131
+ sectionKey: string;
132
+ log: any; // LogEntryGQL
133
+ }
134
+
135
+ export interface ReportSubmissionGQL {
136
+ __deleted?: boolean;
137
+
138
+ id: string;
139
+ reportId: string;
140
+ organizationId: string;
141
+ sectionKey: string;
142
+ documentName: string;
143
+ sectionName: string;
144
+ title: string;
145
+ period: string; // YYYY-MM-DD
146
+ activityAt: string | null; // ISO date string
147
+ rows: ReportRowGQL[];
148
+ evidences: string[];
149
+ }
150
+
151
+ export interface ReportLogRelData {
152
+ __table: 'report_log_rels';
153
+ reportSubmissionId: number | bigint;
154
+ logId: number | bigint;
155
+ sectionKey: string;
156
+ }
157
+
158
+ export interface ReportSubmissionData {
159
+ __table: 'report_submissions';
160
+ id: number;
161
+ organizationId: number;
162
+ reportId: number;
163
+ period: Date; // YYYY-MM-DD in database, Date object in server via ORM
164
+ answers: Record<string, any>; // key-value pairs of answers
165
+ logRels?: ReportLogRelData[];
166
+ activityAt: Date;
167
+ }
168
+
169
+ /**
170
+ * Available reports
171
+ */
172
+
173
+ export interface ReportAvailabilityGQL {
174
+ id: string;
175
+ type: ReportTypeEnum;
176
+ periods: string[]; // YYYY-MM-DD
177
+ }