@updraft-solutions/mcrit-sdk 0.11.2 → 0.12.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.
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { aC as activitySchema, aD as addressSchema, aE as aircraftPositionSchema, aF as aircraftRatingSchema, aK as airplaneSchema, aJ as airplanePermissionSchema, aL as airplaneShareInviteSchema, aM as airportSchema, aN as alertSchema, aO as allowedDocumentTypeSchema, aP as approachTypeSchema, aQ as availSchema, aR as baseMembershipSchema, aT as bookingSchema, aV as commentSchema, aW as companySchema, b0 as courseSchema, a_ as courseEnrollmentSchema, a$ as courseFeeSchema, aH as airplaneIssueSeverityEnum, b6 as documentSchema, b2 as documentComplianceStatus, b3 as documentRequirement, b4 as documentRequirementGroup, b5 as documentRequirementGroupAssignment, b7 as documentShareSchema, b8 as documentType, ba as eventSchema, bc as expenseSchema, bb as expenseItemSchema, bd as extendedAirplaneSchema, bf as feeSchema, be as feeCategoryOptionsSchema, bg as flightLogSchema, bo as invoiceSchema, bq as landingSchema, bp as landingFeeSchema, bs as maintenanceEventSchema, br as maintenanceEventEstimationSchema, bt as maintenanceStatusSchema, bu as mediaCollection, bw as membershipSchema, bx as membershipSignupSchema, by as postSchema, bz as postSubjectSchema, bB as prePaidPackageSchema, bC as priceSchema, bD as qualificationSchema, bE as recurringFlightSchema, bF as roleSchema, bG as runwaySchema, bH as scheduledFlightSchema, bI as settingSchema, bJ as specialFlightSchema, bQ as tagSchema, bR as ticketSchema, b$ as userSchema, bZ as userAircraftRatingSchema, b_ as userQualificationSchema, c0 as waypointSchema, aG as airplaneIssueSchema, aI as airplaneIssueStatusEnum, B as BaseModel$1, aY as courseCheckSyllabusSchema, aZ as courseEnrollmentMetricsSchema, bv as mediaSchema, l as FormSubmission } from '../training-D3dneyB8.cjs';
2
+ import { aC as activitySchema, aD as addressSchema, aE as aircraftPositionSchema, aF as aircraftRatingSchema, aK as airplaneSchema, aJ as airplanePermissionSchema, aL as airplaneShareInviteSchema, aM as airportSchema, aN as alertSchema, aO as allowedDocumentTypeSchema, aP as approachTypeSchema, aQ as availSchema, aR as baseMembershipSchema, aT as bookingSchema, aV as commentSchema, aX as companySchema, b1 as courseSchema, a$ as courseEnrollmentSchema, b0 as courseFeeSchema, aH as airplaneIssueSeverityEnum, b7 as documentSchema, b3 as documentComplianceStatus, b4 as documentRequirement, b5 as documentRequirementGroup, b6 as documentRequirementGroupAssignment, b8 as documentShareSchema, b9 as documentType, bb as eventSchema, bd as expenseSchema, bc as expenseItemSchema, be as extendedAirplaneSchema, bg as feeSchema, bf as feeCategoryOptionsSchema, bh as flightLogSchema, bp as invoiceSchema, br as landingSchema, bq as landingFeeSchema, bt as maintenanceEventSchema, bs as maintenanceEventEstimationSchema, bu as maintenanceStatusSchema, bv as mediaCollection, by as membershipSchema, bz as membershipSignupSchema, bB as postSchema, bC as postSubjectSchema, bE as prePaidPackageSchema, bF as priceSchema, bG as qualificationSchema, bH as recurringFlightSchema, bI as roleSchema, bJ as runwaySchema, bK as scheduledFlightSchema, bL as settingSchema, bM as specialFlightSchema, bT as tagSchema, bU as ticketSchema, c2 as userSchema, c0 as userAircraftRatingSchema, c1 as userQualificationSchema, c3 as waypointSchema, aG as airplaneIssueSchema, aI as airplaneIssueStatusEnum, B as BaseModel$1, aZ as courseCheckSyllabusSchema, a_ as courseEnrollmentMetricsSchema, bw as mediaSchema, l as FormSubmission } from '../training-B5bsRTKy.cjs';
3
3
 
4
4
  type BaseModel = z.infer<typeof BaseModel$1>;
5
5
  type User = z.infer<typeof userSchema>;
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { aC as activitySchema, aD as addressSchema, aE as aircraftPositionSchema, aF as aircraftRatingSchema, aK as airplaneSchema, aJ as airplanePermissionSchema, aL as airplaneShareInviteSchema, aM as airportSchema, aN as alertSchema, aO as allowedDocumentTypeSchema, aP as approachTypeSchema, aQ as availSchema, aR as baseMembershipSchema, aT as bookingSchema, aV as commentSchema, aW as companySchema, b0 as courseSchema, a_ as courseEnrollmentSchema, a$ as courseFeeSchema, aH as airplaneIssueSeverityEnum, b6 as documentSchema, b2 as documentComplianceStatus, b3 as documentRequirement, b4 as documentRequirementGroup, b5 as documentRequirementGroupAssignment, b7 as documentShareSchema, b8 as documentType, ba as eventSchema, bc as expenseSchema, bb as expenseItemSchema, bd as extendedAirplaneSchema, bf as feeSchema, be as feeCategoryOptionsSchema, bg as flightLogSchema, bo as invoiceSchema, bq as landingSchema, bp as landingFeeSchema, bs as maintenanceEventSchema, br as maintenanceEventEstimationSchema, bt as maintenanceStatusSchema, bu as mediaCollection, bw as membershipSchema, bx as membershipSignupSchema, by as postSchema, bz as postSubjectSchema, bB as prePaidPackageSchema, bC as priceSchema, bD as qualificationSchema, bE as recurringFlightSchema, bF as roleSchema, bG as runwaySchema, bH as scheduledFlightSchema, bI as settingSchema, bJ as specialFlightSchema, bQ as tagSchema, bR as ticketSchema, b$ as userSchema, bZ as userAircraftRatingSchema, b_ as userQualificationSchema, c0 as waypointSchema, aG as airplaneIssueSchema, aI as airplaneIssueStatusEnum, B as BaseModel$1, aY as courseCheckSyllabusSchema, aZ as courseEnrollmentMetricsSchema, bv as mediaSchema, l as FormSubmission } from '../training-D3dneyB8.js';
2
+ import { aC as activitySchema, aD as addressSchema, aE as aircraftPositionSchema, aF as aircraftRatingSchema, aK as airplaneSchema, aJ as airplanePermissionSchema, aL as airplaneShareInviteSchema, aM as airportSchema, aN as alertSchema, aO as allowedDocumentTypeSchema, aP as approachTypeSchema, aQ as availSchema, aR as baseMembershipSchema, aT as bookingSchema, aV as commentSchema, aX as companySchema, b1 as courseSchema, a$ as courseEnrollmentSchema, b0 as courseFeeSchema, aH as airplaneIssueSeverityEnum, b7 as documentSchema, b3 as documentComplianceStatus, b4 as documentRequirement, b5 as documentRequirementGroup, b6 as documentRequirementGroupAssignment, b8 as documentShareSchema, b9 as documentType, bb as eventSchema, bd as expenseSchema, bc as expenseItemSchema, be as extendedAirplaneSchema, bg as feeSchema, bf as feeCategoryOptionsSchema, bh as flightLogSchema, bp as invoiceSchema, br as landingSchema, bq as landingFeeSchema, bt as maintenanceEventSchema, bs as maintenanceEventEstimationSchema, bu as maintenanceStatusSchema, bv as mediaCollection, by as membershipSchema, bz as membershipSignupSchema, bB as postSchema, bC as postSubjectSchema, bE as prePaidPackageSchema, bF as priceSchema, bG as qualificationSchema, bH as recurringFlightSchema, bI as roleSchema, bJ as runwaySchema, bK as scheduledFlightSchema, bL as settingSchema, bM as specialFlightSchema, bT as tagSchema, bU as ticketSchema, c2 as userSchema, c0 as userAircraftRatingSchema, c1 as userQualificationSchema, c3 as waypointSchema, aG as airplaneIssueSchema, aI as airplaneIssueStatusEnum, B as BaseModel$1, aZ as courseCheckSyllabusSchema, a_ as courseEnrollmentMetricsSchema, bw as mediaSchema, l as FormSubmission } from '../training-B5bsRTKy.js';
3
3
 
4
4
  type BaseModel = z.infer<typeof BaseModel$1>;
5
5
  type User = z.infer<typeof userSchema>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@updraft-solutions/mcrit-sdk",
3
- "version": "0.11.2",
3
+ "version": "0.12.0",
4
4
  "description": "Shared TypeScript types, Zod schemas, and pure helpers for the MCRIT aviation fleet management platform",
5
5
  "homepage": "https://github.com/updraft-solutions/mcrit-sdk#readme",
6
6
  "bugs": {
@@ -108,11 +108,34 @@ export const userSchema = z.object({
108
108
  impersonation: impersonationStateSchema.optional(),
109
109
  });
110
110
 
111
+ /**
112
+ * Identity-only company — the shape a *nested* company gets: enough to name it
113
+ * and draw its avatar. No `permissions[]`, no `can{}`, no banking details.
114
+ *
115
+ * Server: `CompanyIdentityResource`. The authorization-bearing company travels
116
+ * only where a caller asked for it — `GET /users/{id}/memberships` (mobile's
117
+ * permission source) and a single-booking payload (a shared aircraft can put a
118
+ * booking in a partner company, so the client's active company is not the
119
+ * gate subject).
120
+ */
121
+ export const companyIdentitySchema = z.object({
122
+ type: z.literal("company"),
123
+ id: z.number(),
124
+ name: z.string(),
125
+ icao: z.string().nullable().optional(),
126
+ airport_id: z.number().nullable().optional(),
127
+ media: mediaCollection,
128
+ });
129
+
111
130
  export const companySchema = z.object({
112
131
  type: z.literal("company"),
113
132
  id: z.number(),
114
133
  name: z.string(),
115
134
  media: mediaCollection,
135
+ // Server-evaluated policy decisions for this instance. Only the gates the
136
+ // request asked for (`permissions[<model>]=…`, or every gate on a
137
+ // POST/PATCH) are present — an absent key means "not evaluated", which
138
+ // callers must treat exactly like an explicit null.
116
139
  can: z.record(z.string(), z.boolean().nullable()).optional(),
117
140
  permissions: z.array(z.string()).optional(),
118
141
  // Company display timezone (companies.timezone, default Europe/Berlin
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import {
3
3
  BaseModel,
4
+ companyIdentitySchema,
4
5
  companySchema,
5
6
  contactAttributeSchema,
6
7
  mediaCollection,
@@ -14,14 +15,32 @@ import {
14
15
  import { equipmentSchema } from "./equipment";
15
16
  import { courseCheckSyllabusSchema } from "./training";
16
17
 
17
- export const baseMembershipSchema = z.object({
18
+ /**
19
+ * Identity-only membership — the shape nested in list rows (server:
20
+ * `MembershipIdentityResource`). It answers "who is this" and nothing else:
21
+ * the full nesting carries the company payload, i.e. the requesting user's
22
+ * whole permission list, repeated on every row.
23
+ */
24
+ export const membershipIdentitySchema = z.object({
18
25
  type: z.literal("membership"),
19
26
  id: z.number(),
20
27
  user_id: z.number(),
21
28
  user: userSchema.optional(),
22
29
  company_id: z.number(),
23
- company: companySchema.nullable().optional(),
24
30
  name: z.string(),
31
+ });
32
+
33
+ /**
34
+ * The membership as nested in another model's payload: identity, plus the
35
+ * identity-only company for the surfaces that list rows across companies
36
+ * (pre-paid packages, course enrollments).
37
+ */
38
+ export const nestedMembershipSchema = membershipIdentitySchema.extend({
39
+ company: companyIdentitySchema.nullable().optional(),
40
+ });
41
+
42
+ export const baseMembershipSchema = membershipIdentitySchema.extend({
43
+ company: companyIdentitySchema.nullable().optional(),
25
44
  phone: z.string().nullable().optional(),
26
45
  status: z.string(),
27
46
  instructor: z.boolean(),
@@ -92,7 +111,7 @@ export const feeSchema = BaseModel.extend({
92
111
  prices: z.array(priceSchema).optional(),
93
112
  provider: z.string().nullable().optional(),
94
113
  company_id: z.number().optional(),
95
- company: companySchema.optional(),
114
+ company: companyIdentitySchema.optional(),
96
115
  ident: z.string().optional(),
97
116
  category: z.string().optional(),
98
117
  subcategory: z.string().nullable().optional(),
@@ -273,7 +292,7 @@ export const airplanePermissionSchema = z.object({
273
292
  airplane_id: z.number(),
274
293
  airplane: airplaneSchema.optional(),
275
294
  membership_id: z.number(),
276
- membership: baseMembershipSchema.optional(),
295
+ membership: nestedMembershipSchema.optional(),
277
296
  notes: z.string().nullable().optional(),
278
297
  conditions: z.string().nullable().optional(),
279
298
  expires_at: z.string().nullable().optional(),
@@ -404,7 +423,7 @@ export const extendedAirplaneSchema = airplaneSchema.extend({
404
423
  })
405
424
  .optional(),
406
425
  foreflight_profile_url: z.string().optional(),
407
- company: companySchema.optional(),
426
+ company: companyIdentitySchema.optional(),
408
427
  latestPosition: aircraftPositionSchema.nullable().optional(),
409
428
  total_flight_time_minutes: z.number().nullable().optional(),
410
429
  elapsed_time: z.number().nullable().optional(),
@@ -476,6 +495,9 @@ export const bookingSchema = BaseModel.extend({
476
495
  author: userSchema.optional(),
477
496
  company_id: z.number(),
478
497
  company_name: z.string().nullable().optional(),
498
+ // Single-booking payloads only (BookingDetailResource): the dialog gates
499
+ // on this company, which a shared aircraft can make a partner company.
500
+ // List rows never carry it.
479
501
  company: companySchema.optional(),
480
502
  airplane: airplaneSchema.optional(),
481
503
  etdZ: z.string(),
@@ -494,6 +516,9 @@ export const bookingSchema = BaseModel.extend({
494
516
  .enum(["draft", "awaiting_signatures", "signed"])
495
517
  .nullable()
496
518
  .optional(),
519
+ // Single-booking payloads only (BookingDetailResource): neighbour lookups
520
+ // cost two queries per booking and only the dialog's prev/next navigation
521
+ // uses them.
497
522
  next_booking_id: z.number().nullable().optional(),
498
523
  previous_booking_id: z.number().nullable().optional(),
499
524
  maintenance: z.number().optional(),
@@ -793,7 +818,7 @@ export const flightLogSchema = z.object({
793
818
  ac_call: z.string().nullable().optional(),
794
819
  booking_id: z.number().nullable().optional(),
795
820
  membership_id: z.number().nullable().optional(),
796
- membership: baseMembershipSchema.optional(),
821
+ membership: nestedMembershipSchema.optional(),
797
822
  billing_profile_id: z.number().nullable().optional(),
798
823
  author_id: z.number(),
799
824
  author: userSchema.optional(),
@@ -843,7 +868,10 @@ export const invoiceSchema = z.object({
843
868
  id: z.number(),
844
869
  title: z.string(),
845
870
  membership_id: z.number(),
846
- membership: baseMembershipSchema.optional(),
871
+ // List rows (InvoiceListResource) carry the identity-only membership; the
872
+ // single-invoice payload carries the full one. Typed as the identity shape —
873
+ // the guaranteed part — with the rest passed through.
874
+ membership: nestedMembershipSchema.optional(),
847
875
  // InvoiceResource always emits `billing_profile_id` (non-optional key,
848
876
  // nullable FK value). `billingProfile` is a `whenLoaded('billingProfile')`
849
877
  // relation, so it stays optional. (Fix round 1: as of the original Task 16
@@ -854,7 +882,12 @@ export const invoiceSchema = z.object({
854
882
  billingProfile: billingProfileSchema.optional(),
855
883
  company_id: z.number().optional(),
856
884
  company: companySchema.optional(),
885
+ // Numbering: invoices are numbered in `sequence_number`, receipts in
886
+ // `receipt_number`. `document_number` is whichever applies — render that.
887
+ document_type: z.string().nullable().optional(),
857
888
  sequence_number: z.string().nullable().optional(),
889
+ receipt_number: z.string().nullable().optional(),
890
+ document_number: z.string().nullable().optional(),
858
891
  order_number: z.string().nullable().optional(),
859
892
  invoice_date: z.string().nullable().optional(),
860
893
  due_date: z.string().nullable().optional(),
@@ -1054,7 +1087,7 @@ export const courseEnrollmentSchema = z.object({
1054
1087
  created_at: z.string(),
1055
1088
  updated_at: z.string(),
1056
1089
  course: courseSchema.optional(),
1057
- membership: membershipSchema.optional(),
1090
+ membership: nestedMembershipSchema.optional(),
1058
1091
  mentor: userSchema.optional(),
1059
1092
  // Present when eager-loaded (BaseCourseEnrollmentResource). Lazy: both
1060
1093
  // schemas are declared later in this file; there is no true cycle.
@@ -1098,7 +1131,7 @@ export const eventSchema = z.object({
1098
1131
  type: z.literal("event"),
1099
1132
  id: z.number(),
1100
1133
  company_id: z.number(),
1101
- company: companySchema.optional(),
1134
+ company: companyIdentitySchema.optional(),
1102
1135
  title: z.string(),
1103
1136
  description: z.string().nullable().optional(),
1104
1137
  media: mediaCollection,
@@ -1427,7 +1460,7 @@ export const expenseItemSchema = z.object({
1427
1460
  // maximum length"). No true cycle: invoiceSchema does not reference
1428
1461
  // expenseItemSchema back.
1429
1462
  invoice: z.lazy((): z.ZodTypeAny => invoiceSchema).optional(),
1430
- membership: baseMembershipSchema.optional(),
1463
+ membership: nestedMembershipSchema.optional(),
1431
1464
  prePaidPackageAssignments: z
1432
1465
  .array(prePaidPackageAssignmentSchema)
1433
1466
  .optional(),