@skyvexsoftware/stratos-sdk 0.17.0 → 0.19.1

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,23 @@
1
+ import type { PluginFileAttachment } from "../types/context";
2
+ /**
3
+ * Mark a file on disk for attachment to the PIREP.
4
+ *
5
+ * This only records the path. It doesn't open or read the file, so it never
6
+ * throws and never slows the handler. Stratos reads the file later, when the
7
+ * PIREP is sent, streaming it from disk. A file that can't be read at that
8
+ * point is skipped with the reason recorded, and the flight still files.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * ctx.flight.attachToPirepSubmission(async (sub) => {
13
+ * const receipts = await groundOps.receiptsFor(sub.flightId);
14
+ * if (!receipts.length) return null;
15
+ * return { receipts: receipts.map((r) => attachFile(r.path)) };
16
+ * });
17
+ * ```
18
+ */
19
+ export declare function attachFile(path: string, opts?: {
20
+ filename?: string;
21
+ contentType?: string;
22
+ }): PluginFileAttachment;
23
+ //# sourceMappingURL=attach-file.d.ts.map
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Mark a file on disk for attachment to the PIREP.
3
+ *
4
+ * This only records the path. It doesn't open or read the file, so it never
5
+ * throws and never slows the handler. Stratos reads the file later, when the
6
+ * PIREP is sent, streaming it from disk. A file that can't be read at that
7
+ * point is skipped with the reason recorded, and the flight still files.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * ctx.flight.attachToPirepSubmission(async (sub) => {
12
+ * const receipts = await groundOps.receiptsFor(sub.flightId);
13
+ * if (!receipts.length) return null;
14
+ * return { receipts: receipts.map((r) => attachFile(r.path)) };
15
+ * });
16
+ * ```
17
+ */
18
+ export function attachFile(path, opts) {
19
+ return {
20
+ __stratosFile: true,
21
+ path,
22
+ ...(opts?.filename !== undefined ? { filename: opts.filename } : {}),
23
+ ...(opts?.contentType !== undefined
24
+ ? { contentType: opts.contentType }
25
+ : {}),
26
+ };
27
+ }
@@ -1,4 +1,5 @@
1
1
  export { createPlugin } from "./createPlugin";
2
+ export { attachFile } from "./attach-file";
2
3
  export { STRATOS_APP_PORT, STRATOS_APP_BASE } from "./server";
3
4
  export { weightToLbs, weightFromLbs, altitudeToFt, altitudeFromFt, verticalSpeedFromFpm, verticalSpeedToFpm, distanceToNm, distanceFromNm, formatWeight, formatAltitude, formatDistance, formatVerticalSpeed, } from "./units";
4
5
  export type { WeightUnit, AltitudeUnit, DistanceUnit, UnitPreferences, } from "./units";
@@ -1,4 +1,5 @@
1
1
  export { createPlugin } from "./createPlugin";
2
+ export { attachFile } from "./attach-file";
2
3
  export { STRATOS_APP_PORT, STRATOS_APP_BASE } from "./server";
3
4
  export { weightToLbs, weightFromLbs, altitudeToFt, altitudeFromFt, verticalSpeedFromFpm, verticalSpeedToFpm, distanceToNm, distanceFromNm, formatWeight, formatAltitude, formatDistance, formatVerticalSpeed, } from "./units";
4
5
  export { classifyAircraft } from "./aircraft";
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export type { PluginAuthor, PluginManifest } from "./types/manifest";
2
- export type { PluginAirline, PluginAirlineAccessor, PluginAuthAccessor, PluginVaApiClient, PluginConfigStore, PluginContext, PluginDatabaseAccessor, PluginIPCRegistrar, PluginLogger, PluginServerRegistrar, PluginFlightAccessor, PluginFlightLogWriter, PluginFlightLogInput, PluginFlightLogPatch, PluginStartGuard, PluginStartContext, PluginStartDecision, PluginNotifier, PluginToastInput, BuiltInSound, PluginAlertSound, PluginDialogApi, PluginPromptApi, PluginDialogAlertInput, PluginDialogConfirmInput, PluginPromptTextInput, PluginPromptNumberInput, PluginPromptSelectInput, PluginIndicatorType, PluginIndicatorInput, PluginSelfApi, } from "./types/context";
2
+ export type { PluginAirline, PluginAirlineAccessor, PluginAuthAccessor, PluginVaApiClient, PluginConfigStore, PluginContext, PluginDatabaseAccessor, PluginIPCRegistrar, PluginLogger, PluginServerRegistrar, PluginFlightAccessor, PluginFlightLogWriter, PluginFlightLogInput, PluginFlightLogPatch, PluginStartGuard, PluginStartContext, PluginStartDecision, PluginPirepSubmissionContext, PluginPirepAttachment, PluginPirepAttachHandler, PluginFileAttachment, PluginNotifier, PluginToastInput, BuiltInSound, PluginAlertSound, PluginDialogApi, PluginPromptApi, PluginDialogAlertInput, PluginDialogConfirmInput, PluginPromptTextInput, PluginPromptNumberInput, PluginPromptSelectInput, PluginIndicatorType, PluginIndicatorInput, PluginSelfApi, } from "./types/context";
3
3
  export type { PluginNavigationHelper, PluginPilotUser, PluginToastAPI, PluginUIContext, } from "./types/context-ui";
4
4
  export type { PluginSettingType, PluginSettingOption, PluginSettingDefinition, PluginAvailableSettings, BooleanSettingDef, TextSettingDef, LongtextSettingDef, NumberSettingDef, RangeSettingDef, ListSettingDef, RadioSettingDef, DateSettingDef, JsonSettingDef, } from "./types/settings";
5
5
  export type { PluginBackgroundModule, PluginRouteComponent, PluginUIModule, } from "./types/module";
@@ -13,6 +13,7 @@ export { ADDITIONAL_FIELD_PHASES, toPhaseKey, } from "./shared-types/additional-
13
13
  export type { AdditionalFieldsConfig, FieldDelivery, } from "./shared-types/additional-fields";
14
14
  export type { FlightPlan, FlightStatus, CurrentFlight, FlightComment, PreflightCheck, PreflightCheckResult, StartFlightOptions, FlightManagerPayload, StartFlightResult, RecoverableFlight, } from "./shared-types/flight-manager";
15
15
  export { createPlugin } from "./helpers/createPlugin";
16
+ export { attachFile } from "./helpers/attach-file";
16
17
  export { STRATOS_APP_PORT, STRATOS_APP_BASE } from "./helpers/server";
17
18
  export { vaApi } from "./api/vaApi";
18
19
  export { weightToLbs, weightFromLbs, altitudeToFt, altitudeFromFt, verticalSpeedFromFpm, verticalSpeedToFpm, distanceToNm, distanceFromNm, formatWeight, formatAltitude, formatDistance, formatVerticalSpeed, } from "./helpers/units";
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ export { EventCategory } from "./shared-types/flight-events";
4
4
  export { ADDITIONAL_FIELD_PHASES, toPhaseKey, } from "./shared-types/additional-fields";
5
5
  // ── Helper Functions ───────────────────────────────────────────────────
6
6
  export { createPlugin } from "./helpers/createPlugin";
7
+ export { attachFile } from "./helpers/attach-file";
7
8
  export { STRATOS_APP_PORT, STRATOS_APP_BASE } from "./helpers/server";
8
9
  export { vaApi } from "./api/vaApi";
9
10
  export { weightToLbs, weightFromLbs, altitudeToFt, altitudeFromFt, verticalSpeedFromFpm, verticalSpeedToFpm, distanceToNm, distanceFromNm, formatWeight, formatAltitude, formatDistance, formatVerticalSpeed, } from "./helpers/units";
@@ -162,6 +162,29 @@ export type PluginFlightAccessor = {
162
162
  * Multiple guards: the first `allow: false` wins. Returns an unsubscribe.
163
163
  */
164
164
  registerStartGuard(guard: PluginStartGuard): () => void;
165
+ /**
166
+ * Register a handler consulted while the airline PIREP is assembled, after
167
+ * every milestone capture and immediately before the body is posted.
168
+ * Whatever it returns is attached to the submission under
169
+ * `plugin_data["<your-plugin-id>"]`. Return null or undefined to attach
170
+ * nothing.
171
+ *
172
+ * Handlers are fail-open: a throw, a rejection, a timeout (3s), a
173
+ * non-object return, or returned data over the size cap omits this plugin's
174
+ * key and the PIREP is submitted regardless. The cap is 256 KB per plugin
175
+ * and 512 KB across all plugins, measured on the returned JSON. Files
176
+ * attached with `attachFile()` do not count towards it; each is only a
177
+ * short reference in the JSON and is sent as its own part, with no size
178
+ * limit.
179
+ *
180
+ * Handlers run only for `completed`, `diverted` and `crashed` flights, never
181
+ * for cancelled ones, and only when an airline is bound. If the airline
182
+ * rejects the PIREP the pilot can retry, which runs every handler again, so
183
+ * a handler must be idempotent and free of side effects. Registering more
184
+ * than one handler is allowed; their results are shallow-merged under the
185
+ * single plugin key. Returns an unsubscribe.
186
+ */
187
+ attachToPirepSubmission(handler: PluginPirepAttachHandler): () => void;
165
188
  };
166
189
  /** Context handed to a start guard. */
167
190
  export type PluginStartContext = {
@@ -178,6 +201,49 @@ export type PluginStartDecision = {
178
201
  };
179
202
  /** Guard run inside `startFlight` before the flight is created/persisted. */
180
203
  export type PluginStartGuard = (ctx: PluginStartContext) => PluginStartDecision | Promise<PluginStartDecision>;
204
+ /**
205
+ * Context handed to a PIREP submission attachment handler.
206
+ * Describes the PIREP that is about to be filed with the airline.
207
+ */
208
+ export type PluginPirepSubmissionContext = {
209
+ /** Local (core DB) flight id. */
210
+ flightId: string;
211
+ /** Skyvex flight UUID, or null if the flight was never relayed. */
212
+ stratosFlightId: string | null;
213
+ /** VA tracking id for the PIREP being filed. */
214
+ vaTrackingId: string;
215
+ /** Terminal status being filed. Cancelled flights never reach a handler. */
216
+ status: "completed" | "diverted" | "crashed";
217
+ /** The flight plan being filed. */
218
+ plan: FlightPlan;
219
+ /** Last simulator snapshot, or null when no sim is connected. */
220
+ snapshot: SimDataSnapshot | null;
221
+ };
222
+ /**
223
+ * Data to attach to the PIREP. Returning null or undefined (a bare `return;`
224
+ * included) attaches nothing for this flight.
225
+ */
226
+ export type PluginPirepAttachment = Record<string, unknown> | null | undefined;
227
+ /** Handler registered through `ctx.flight.attachToPirepSubmission`. */
228
+ export type PluginPirepAttachHandler = (ctx: PluginPirepSubmissionContext) => PluginPirepAttachment | Promise<PluginPirepAttachment>;
229
+ /**
230
+ * A file to attach to the PIREP, produced by `attachFile()`. Place one anywhere
231
+ * inside the object your handler returns; the shell lifts it out into its own
232
+ * part of a multipart submission and leaves a reference in its place.
233
+ *
234
+ * Carries a `__stratosFile` discriminator rather than relying on object
235
+ * identity, because attachments are JSON round-tripped before the shell walks
236
+ * them.
237
+ */
238
+ export type PluginFileAttachment = {
239
+ readonly __stratosFile: true;
240
+ /** Absolute path to the file on disk. */
241
+ path: string;
242
+ /** Name sent to the airline. Defaults to the basename of `path`. */
243
+ filename?: string;
244
+ /** MIME type. Defaults to a lookup on the extension, else application/octet-stream. */
245
+ contentType?: string;
246
+ };
181
247
  /**
182
248
  * Toast + sound surface. Backs `ctx.notify`.
183
249
  *
@@ -1,5 +1,5 @@
1
1
  export type { PluginAuthor, PluginManifest } from "./manifest";
2
- export type { PluginAirline, PluginAirlineAccessor, PluginAuthAccessor, PluginConfigStore, PluginContext, PluginDatabaseAccessor, PluginIPCRegistrar, PluginLogger, PluginServerRegistrar, PluginFlightAccessor, PluginFlightLogWriter, PluginFlightLogInput, PluginFlightLogPatch, PluginStartGuard, PluginStartContext, PluginStartDecision, PluginNotifier, PluginToastInput, BuiltInSound, PluginAlertSound, } from "./context";
2
+ export type { PluginAirline, PluginAirlineAccessor, PluginAuthAccessor, PluginConfigStore, PluginContext, PluginDatabaseAccessor, PluginIPCRegistrar, PluginLogger, PluginServerRegistrar, PluginFlightAccessor, PluginFlightLogWriter, PluginFlightLogInput, PluginFlightLogPatch, PluginStartGuard, PluginStartContext, PluginStartDecision, PluginPirepSubmissionContext, PluginPirepAttachment, PluginPirepAttachHandler, PluginFileAttachment, PluginNotifier, PluginToastInput, BuiltInSound, PluginAlertSound, } from "./context";
3
3
  export type { PluginNavigationHelper, PluginToastAPI, PluginUIContext, } from "./context-ui";
4
4
  export type { PluginBackgroundModule, PluginRouteComponent, PluginUIModule, } from "./module";
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -44,5 +44,7 @@ export type PluginManifest = {
44
44
  availableSettings?: PluginSettingDefinition[];
45
45
  /** Whether to include source maps in the published CDN bundle. Defaults to false — source maps are stripped on approval. Set to true if you want end users to have access to source maps for debugging. */
46
46
  includeSourceMaps?: boolean;
47
+ /** Advisory: this plugin attaches files to the PIREP, which changes how flight submissions are encoded for the airline. Surfaced as a warning in the airline's plugin list; the shell does not enforce it. */
48
+ attachesFilesToPirep?: boolean;
47
49
  };
48
50
  //# sourceMappingURL=manifest.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyvexsoftware/stratos-sdk",
3
- "version": "0.17.0",
3
+ "version": "0.19.1",
4
4
  "description": "Plugin SDK for Stratos — types, hooks, and UI components",
5
5
  "author": {
6
6
  "name": "Skyvex Software Pty Ltd",