@jsb188/mday 1.1.5 → 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,42 @@
1
+ /**
2
+ * Actions data object
3
+ */
4
+
5
+ export interface ActionTaskObj {
6
+ id?: number | bigint; // Optional for updates/inserts
7
+ logId: number | bigint;
8
+ queue?: string | null;
9
+
10
+ title: string;
11
+ instruction: string;
12
+ message?: string | null;
13
+
14
+ scheduledAt: Date | null;
15
+ delay: number | null; // seconds
16
+ completed: boolean;
17
+
18
+ createdAt?: Date;
19
+ updatedAt?: Date;
20
+ }
21
+
22
+ /**
23
+ * Actions GraphQL data
24
+ */
25
+
26
+ export interface ActionTaskGQL {
27
+ __deleted?: boolean;
28
+
29
+ id: string;
30
+ logId: string;
31
+
32
+ title: string;
33
+ instruction: string;
34
+ message: string | null;
35
+
36
+ scheduledAt: string; // ISO date string
37
+ delay: number; // seconds
38
+ completed: boolean;
39
+
40
+ createdAt?: string; // ISO date string
41
+ updatedAt?: string; // ISO date string
42
+ }
@@ -1,16 +1,71 @@
1
- import type { OrganizationOperationEnum } from '@jsb188/app/types/organization.d';
2
1
  import type { AccountObj } from '@jsb188/app/types/account.d';
3
- import { LOG_ARABLE_ACTIVITY_ENUMS } from '../constants/log';
2
+ import type { ActionTaskGQL, ActionTaskObj } from '@jsb188/mday/types/action.d';
3
+ import type { OrganizationOperationEnum } from '../types/organization.d';
4
+ import {
5
+ LOG_ACTION_STATUS_ENUMS,
6
+ LOG_ARABLE_ACTIVITY_ENUMS,
7
+ LOG_FARMERS_MARKET_ACTIVITY_ENUMS,
8
+ LOG_LIVESTOCK_ACTIVITY_ENUMS,
9
+ LOG_SORT_ENUMS
10
+ } from '../constants/log';
4
11
 
5
- // All logs types
12
+ /**
13
+ * Enums
14
+ */
6
15
 
7
- export type LogArableTypeEnum = 'SEED' | 'PLANTING' | 'FIELD' | 'HARVEST' | 'POST_HARVEST' | 'SALES' | 'WATER';
8
- export type LogTypeEnum = LogArableTypeEnum;
16
+ export type LogActionStatusEnum = (typeof LOG_ACTION_STATUS_ENUMS)[number];
17
+ export type LogContentName = 'log' | 'ai_task' | 'invoice' | 'receipt'; // For UI visuals, client-side only
18
+ export type LogSortEnum = typeof LOG_SORT_ENUMS[number];
9
19
 
10
- // All logs activities
20
+ /**
21
+ * Arable
22
+ */
11
23
 
24
+ export type LogArableTypeEnum =
25
+ | 'SEED'
26
+ | 'PLANTING'
27
+ | 'FIELD'
28
+ | 'HARVEST'
29
+ | 'POST_HARVEST'
30
+ | 'SALES'
31
+ | 'WATER'
32
+ | 'HYGIENE'
33
+ | 'SANITATION'
34
+ | 'EQUIPMENTS'
35
+ | 'BIOSECURITY'
36
+ | 'EMPLOYEES';
12
37
  export type LogArableActivityEnum = typeof LOG_ARABLE_ACTIVITY_ENUMS[number];
13
- export type LogActivityEnum = LogArableActivityEnum;
38
+
39
+ /**
40
+ * Farmers Market
41
+ */
42
+
43
+ export type LogFarmersMarketTypeEnum = 'MARKET_RECEIPTS' | 'MARKET_OPERATIONS';
44
+ export type LogFarmersMarketActivityEnum = typeof LOG_FARMERS_MARKET_ACTIVITY_ENUMS[number];
45
+
46
+ /**
47
+ * Livestock
48
+ */
49
+
50
+ export type LogLivestockTypeEnum =
51
+ | 'SUPPLY_PURCHASE'
52
+ | 'LIVESTOCK_LIFE_CYCLE'
53
+ | 'LIVESTOCK_TRACKING'
54
+ | 'PASTURE_LAND_MANAGEMENT'
55
+ | 'LIVESTOCK_HEALTHCARE'
56
+ | 'LIVESTOCK_SALE';
57
+ export type LogLivestockActivityEnum = typeof LOG_LIVESTOCK_ACTIVITY_ENUMS[number];
58
+
59
+ /**
60
+ * All log types/activities Union
61
+ */
62
+
63
+ export type LogTypeEnum = LogArableTypeEnum | LogFarmersMarketTypeEnum | LogLivestockTypeEnum | 'AI_TASK';
64
+ export type LogActivityEnum = LogArableActivityEnum | LogFarmersMarketActivityEnum | LogLivestockActivityEnum;
65
+
66
+ /**
67
+ * Log metadata
68
+ */
14
69
 
15
70
  interface LogDetailsGQLBase {
16
71
  __typename: string;
@@ -20,71 +75,192 @@ interface LogDetailsGQLBase {
20
75
  notes: string;
21
76
  }
22
77
 
23
- // Log entry object
78
+ interface LogMetadataBase {
79
+ __before: any;
80
+ childOrg: never;
81
+ childOrgId: never;
82
+ referenceNumber: never;
24
83
 
25
- interface LogArableMetadata {
26
- crop: string;
84
+ recurFromLogId?: number;
85
+ recurredCount?: number;
86
+ summary?: string;
87
+ }
88
+
89
+ interface LabelValueObj {
90
+ label: string;
91
+ value: string;
92
+ quantity?: number;
93
+ }
94
+
95
+ /**
96
+ * Log details - Arable
97
+ */
98
+
99
+ export type LogArableMetadata = LogMetadataBase & {
100
+ item: string;
27
101
  quantity: number;
28
102
  unit: string;
29
103
  concentration: number;
30
104
  concentrationUnit: string;
31
- price: number;
32
- }
105
+ location: string;
106
+ fieldLocation?: string;
107
+ otherParty?: string;
108
+ referenceNumber?: string;
109
+ values?: LabelValueObj[];
110
+ tax: number;
111
+ };
33
112
 
34
- interface LogArableObj {
113
+ export interface LogArableObj {
35
114
  type?: LogArableTypeEnum; // Only set in server if manually extended
36
115
  activity: LogArableActivityEnum;
37
116
  notes: string | null;
117
+ translation?: string | null;
38
118
  metadata?: Partial<LogArableMetadata> | null;
39
119
  }
40
120
 
41
- interface LogArableDetailsObj extends LogArableObj {
121
+ export interface LogArableDetailsObj extends LogArableObj {
42
122
  __table: 'logs_arable';
43
- id: number;
123
+ id: number | bigint;
124
+ childOrg: never;
125
+ }
126
+
127
+ export type LogArableMetadataGQL = LogArableMetadata & LogDetailsGQLBase;
128
+
129
+ /**
130
+ * Log details - Farmers Market
131
+ */
132
+
133
+ export type LogFarmersMarketMetadata = LogMetadataBase & {
134
+ referenceNumber: string;
135
+ voided: boolean;
136
+ childOrgId?: number;
137
+ values: LabelValueObj[];
138
+ };
139
+
140
+ export interface LogFarmersMarketObj {
141
+ childOrgId: number | bigint;
142
+ type?: LogFarmersMarketTypeEnum; // Only set in server if manually extended
143
+ activity: LogFarmersMarketActivityEnum;
144
+ notes: string | null;
145
+ translation?: string | null;
146
+ metadata?: Partial<LogFarmersMarketMetadata> | null;
147
+ }
148
+
149
+ export interface LogFarmersMarketDetailsObj extends LogFarmersMarketObj {
150
+ __table: 'logs_farmers_market';
151
+ id: number | bigint;
152
+ childOrg: {
153
+ id: number | bigint;
154
+ name: string;
155
+ };
44
156
  }
45
157
 
46
- export type LogDetailsObj = LogArableObj;
158
+ export type LogFarmersMarketMetadataGQL = LogFarmersMarketMetadata & LogDetailsGQLBase;
159
+
160
+ /**
161
+ * Log details - Livestock
162
+ */
163
+
164
+ export type LogLivestockMetadata = LogMetadataBase & {
165
+ damIdentifier?: string;
166
+ livestockIdentifiers: string[];
167
+ livestockGroup?: string;
168
+ livestock: string;
169
+ otherParty?: string;
170
+ referenceNumber?: string;
171
+ values?: LabelValueObj[];
172
+ item: string;
173
+ quantity: number;
174
+ unit: string;
175
+ location: string;
176
+ fieldLocation?: string;
177
+ price: number;
178
+ tax: number;
179
+ };
180
+
181
+ export interface LogLivestockObj {
182
+ type?: LogLivestockTypeEnum; // Only set in server if manually extended
183
+ activity: LogLivestockActivityEnum;
184
+ notes: string | null;
185
+ translation?: string | null;
186
+ damIdentifier?: string;
187
+ livestockIdentifiers: string[];
188
+ livestockGroup?: string;
189
+ metadata?: Partial<LogLivestockMetadata> | null;
190
+ }
191
+
192
+ export interface LogLivestockDetailsObj extends LogLivestockObj {
193
+ __table: 'logs_livestock';
194
+ id: number | bigint;
195
+ childOrg: never;
196
+ }
197
+
198
+ export type LogLivestockMetadataGQL = LogLivestockMetadata & LogDetailsGQLBase;
199
+
200
+ /**
201
+ * Union type for log details
202
+ */
203
+
204
+ export type LogDetailsObj = LogArableObj | LogFarmersMarketObj | LogLivestockObj;
205
+ export type LogMetadataGQL = LogArableMetadataGQL | LogFarmersMarketMetadataGQL | LogLivestockMetadataGQL;
206
+
207
+ /**
208
+ * GQL data interfaces
209
+ */
210
+
211
+ export interface LogEntryGQL {
212
+ __deleted?: boolean;
47
213
 
48
- export interface LogEntryGQLData {
49
214
  id: string;
50
215
  accountId: string;
51
216
  organizationId: string;
52
- details: LogArableMetadata & LogDetailsGQLBase;
217
+ details: LogMetadataGQL;
218
+ status: LogActionStatusEnum | null;
53
219
 
54
220
  account: any;
221
+ actions?: ActionTaskGQL[];
222
+
55
223
  date: string; // ISO date string
56
224
  createdAt: string; // ISO date string
57
225
  updatedAt: string; // ISO date string
58
226
  }
59
227
 
60
228
  export interface LogEntryInsertObj {
61
- id?: number; // Only for edits
62
- accountId: number;
63
- organizationId: number;
64
- details: LogDetailsObj;
229
+ id?: number | bigint; // Only for edits
230
+ accountId: number | bigint;
231
+ organizationId: number | bigint;
232
+ status?: LogActionStatusEnum | null;
233
+ details: any;
65
234
  date: Date;
66
235
  }
67
236
 
68
- export interface LogEntryDataObj {
237
+ export interface LogEntryData {
69
238
  __table: 'logs';
70
- id: number;
71
- accountId: number;
72
- organizationId: number;
73
- details: LogArableDetailsObj;
239
+ id: number | bigint;
240
+ accountId: number | bigint;
241
+ organizationId: number | bigint;
242
+ status: LogActionStatusEnum | null;
243
+ distance?: number; // For vector search
244
+ details: LogArableDetailsObj | LogFarmersMarketDetailsObj | LogLivestockDetailsObj;
74
245
  date: Date;
75
246
  createdAt: Date;
76
247
  updatedAt: Date;
77
248
 
78
249
  // This is for outputs, but will never be set for inserts
79
250
  account?: AccountObj;
251
+ actions?: ActionTaskObj[];
80
252
  }
81
253
 
82
- // Filters for search
254
+ /**
255
+ * Filters for search for client-side
256
+ */
83
257
 
84
258
  export interface FilterLogEntriesArgs {
85
259
  operation: OrganizationOperationEnum;
86
260
  accountId?: string | null; // Account ID to filter logs by account
261
+ preset?: 'WEEKS_5' | 'AI_TASKS' | 'INCLUDE_AI_TASKS' | 'HIDE_AI_TASKS' | null;
87
262
  types?: LogTypeEnum[] | null;
263
+ activities?: LogActivityEnum[] | null;
88
264
  startDate?: string | null; // CalDate, with dashes (YYYY-MM-DD)
89
265
  endDate?: string | null; // CalDate, with dashes (YYYY-MM-DD)
90
266
  timeZone?: string | null; // Timezone string, e.g., 'America/New_York'
@@ -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
+ }