@swell/cli 2.7.0 → 2.9.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.
@@ -0,0 +1,267 @@
1
+ import { GroupInfo } from './table.js';
2
+ /**
3
+ * Manifest entry shape, matching `extensions[]` in the deployed app record
4
+ * and in local `./swell.json`. Mirrors the schema at
5
+ * schema-api-server/api/admin/models/apps.json:429-491.
6
+ */
7
+ export interface ManifestEntry {
8
+ id: string;
9
+ type: 'payment' | 'tax' | 'shipping';
10
+ name?: string;
11
+ description?: string;
12
+ setting?: string;
13
+ subscriptions?: boolean;
14
+ method?: string;
15
+ gateway?: string;
16
+ method_logo_src?: string;
17
+ method_icon_src?: string;
18
+ gateway_logo_src?: string;
19
+ gateway_icon_src?: string;
20
+ carrier?: string;
21
+ carrier_logo_src?: string;
22
+ carrier_icon_src?: string;
23
+ [key: string]: unknown;
24
+ }
25
+ /** CLI-resolved type. Diverges from raw manifest `type` for payment (card vs alt). */
26
+ export type ExtensionType = 'card' | 'alt' | 'shipping' | 'tax';
27
+ export type ExtensionStatus = 'not deployed' | 'not activated' | 'app id mismatch' | 'id mismatch' | 'not selected' | 'gateway missing' | 'not enabled' | 'no handler' | 'handler mismatch' | 'activated';
28
+ export type ActionOwner = 'dev' | 'merchant' | null;
29
+ export interface FunctionRecord {
30
+ id?: string;
31
+ name?: string;
32
+ enabled?: boolean;
33
+ app_id?: string;
34
+ extension?: string;
35
+ model?: {
36
+ events?: string[];
37
+ };
38
+ }
39
+ export interface ComponentRecord {
40
+ id?: string;
41
+ name?: string;
42
+ file_path?: string;
43
+ values?: {
44
+ [key: string]: unknown;
45
+ extension?: string;
46
+ };
47
+ [key: string]: unknown;
48
+ }
49
+ export interface PaymentMethodRecord {
50
+ id?: string;
51
+ name?: string;
52
+ gateway?: string;
53
+ extension_app_id?: string;
54
+ extension_config_id?: string;
55
+ enabled?: boolean;
56
+ activated?: boolean;
57
+ [key: string]: unknown;
58
+ }
59
+ export interface PaymentGatewayRecord {
60
+ id?: string;
61
+ name?: string;
62
+ extension_app_id?: string;
63
+ extension_config_id?: string;
64
+ [key: string]: unknown;
65
+ }
66
+ export interface ShippingCarrierRecord {
67
+ id?: string;
68
+ name?: string;
69
+ enabled?: boolean;
70
+ extension_app_id?: string;
71
+ extension_config_id?: string;
72
+ [key: string]: unknown;
73
+ }
74
+ export interface TaxSettingsRecord {
75
+ extension_app_id?: string;
76
+ extension_config_id?: string;
77
+ [key: string]: unknown;
78
+ }
79
+ export interface PaymentSettings {
80
+ methods?: PaymentMethodRecord[];
81
+ gateways?: PaymentGatewayRecord[];
82
+ [key: string]: unknown;
83
+ }
84
+ export interface ShippingSettings {
85
+ carriers?: ShippingCarrierRecord[];
86
+ [key: string]: unknown;
87
+ }
88
+ export interface NativeBinding {
89
+ path: string;
90
+ record: unknown;
91
+ field_checks: Record<string, boolean>;
92
+ }
93
+ export interface BoundFunction {
94
+ id?: string;
95
+ name?: string;
96
+ extension?: string;
97
+ enabled?: boolean;
98
+ model?: {
99
+ events?: string[];
100
+ };
101
+ }
102
+ export interface BoundComponent {
103
+ id?: string;
104
+ name?: string;
105
+ extension?: string;
106
+ file_path?: string;
107
+ }
108
+ export interface LocalDiff {
109
+ changed_fields: string[];
110
+ local: ManifestEntry;
111
+ deployed: ManifestEntry;
112
+ }
113
+ export interface ExtensionDetail {
114
+ status: ExtensionStatus;
115
+ action_owner: ActionOwner;
116
+ action: string | null;
117
+ type: ExtensionType | null;
118
+ manifest: ManifestEntry | null;
119
+ native_bindings: NativeBinding[];
120
+ bound: {
121
+ components: BoundComponent[];
122
+ functions: BoundFunction[];
123
+ };
124
+ required_events: string[];
125
+ missing_required_events: string[];
126
+ local_diff: LocalDiff | null;
127
+ }
128
+ /** Parsed identifier for `swell inspect extensions <id>`. */
129
+ export type ParsedExtensionKey = {
130
+ appPart: string;
131
+ extId: string;
132
+ kind: 'slug';
133
+ } | {
134
+ kind: 'name';
135
+ name: string;
136
+ } | {
137
+ input: string;
138
+ kind: 'invalid';
139
+ };
140
+ /**
141
+ * Parse a `swell inspect extensions` identifier.
142
+ *
143
+ * Accepts:
144
+ * - `app.<slug>.<extId>` → kind 'slug'
145
+ * - bare `<extId>` → kind 'name' (requires --app= scope at the call site)
146
+ *
147
+ * 24-char hex is intentionally NOT a valid form — the synthesized resource has
148
+ * no canonical 24-char id. Callers should reject hex shapes upstream so the
149
+ * error message can be clear about the cause.
150
+ */
151
+ export declare function parseExtensionKey(input: string): ParsedExtensionKey;
152
+ /** Build the column-1 paste-back key for a row. */
153
+ export declare function formatExtensionKey(slug: string, extId: string): string;
154
+ /**
155
+ * Resolve a manifest entry to the CLI's type taxonomy. Payment splits on
156
+ * `method`: when `method === 'card'` the extension provides a card gateway;
157
+ * otherwise it's an alt method. The platform formula at
158
+ * schema-api-server/api/admin/models/apps.json:457-458 defaults `method` to
159
+ * `id` when unset, so a payment extension whose `id` happens to be `card`
160
+ * resolves to `card` even with no explicit `method`.
161
+ */
162
+ export declare function resolveExtensionType(entry: Pick<ManifestEntry, 'type' | 'method' | 'id'>): ExtensionType;
163
+ /** Apply the platform's `if(method, method, id)` formula. */
164
+ export declare function paymentMethodIdFor(entry: Pick<ManifestEntry, 'method' | 'id'>): string;
165
+ /** Shipping records use `app_<appId>_<extId>` as both the row id and the carrier id. */
166
+ export declare function shippingBindId(appId: string, extId: string): string;
167
+ /** Card-gateway records use the same id form as shipping rows. */
168
+ export declare function gatewayBindId(appId: string, extId: string): string;
169
+ /**
170
+ * Required events per extension type, in the `<model>/<event>` form that
171
+ * function records actually store.
172
+ *
173
+ * Verified against:
174
+ * schema-api-server/server/vault.js:1818,1894 (payment.create_intent)
175
+ * schema-api-server/api/com/features/payments/index.js:701-757
176
+ * (payment.charge, payment.refund, dispatcher gate)
177
+ * schema-api-server/server/vault.js:2304-2322 (card-gateway intent path)
178
+ * schema-api-server/api/com/features/orders/shipping.js:411-417,424-431,452-458
179
+ * (shipping dispatch + enabled gate)
180
+ * schema-api-server/api/com/features/orders/taxes.js:123-176
181
+ * (tax dispatch)
182
+ * schema-api-server/api/com/features/orders/extensions.test.js:85,95,179,271,290,303,671,704
183
+ * (event-name format fixtures)
184
+ */
185
+ export declare function requiredEventsFor(type: ExtensionType): string[];
186
+ /**
187
+ * Strip `before:` / `after:` hook-type prefix from an event identifier.
188
+ *
189
+ * Both prefixes are platform-supported on function records; bare events
190
+ * default to `after`. For required-event coverage we treat any prefix as
191
+ * equivalent so that a function declaring `before:payment.charge` covers a
192
+ * required `payments/payment.charge`. Cite:
193
+ * schema-api-server/api/com/features/orders/extensions.test.js:95.
194
+ */
195
+ export declare function stripHookPrefix(event: string): string;
196
+ /**
197
+ * Compute the set of bare event identifiers covered by a function record's
198
+ * `model.events` list. The function event format is `<model>/<event>` with
199
+ * an optional `before:`/`after:` prefix on the bare event part. Returns the
200
+ * full `<model>/<event>` string with hook prefixes stripped from the event.
201
+ */
202
+ export declare function eventsCoveredByFunctions(functions: Pick<FunctionRecord, 'model'>[]): Set<string>;
203
+ /** Required events not covered by any of the bound functions. */
204
+ export declare function missingRequiredEvents(type: ExtensionType, functions: Pick<FunctionRecord, 'model'>[]): string[];
205
+ /** Lift a component record into the synthesized `BoundComponent` shape. */
206
+ export declare function liftBoundComponent(record: ComponentRecord): BoundComponent;
207
+ /** Lift a function record into the synthesized `BoundFunction` shape. */
208
+ export declare function liftBoundFunction(record: FunctionRecord): BoundFunction;
209
+ /**
210
+ * Compare a local manifest entry against the deployed entry. Uses deep
211
+ * equality for change detection and reports differing top-level keys. When
212
+ * the entries are equal, returns `null`.
213
+ */
214
+ export declare function diffManifestEntries(local: ManifestEntry, deployed: ManifestEntry): LocalDiff | null;
215
+ export interface BuildDetailInput {
216
+ appId: string;
217
+ appSlug: string;
218
+ extId: string;
219
+ manifest: ManifestEntry | null;
220
+ /** True when the local manifest has the entry but the deployed app record doesn't. */
221
+ notDeployed?: boolean;
222
+ payments?: PaymentSettings | null;
223
+ shipments?: ShippingSettings | null;
224
+ taxes?: TaxSettingsRecord | null;
225
+ /** Functions in the same app whose top-level `extension` matches this extId. */
226
+ functions: FunctionRecord[];
227
+ /** Components in the same app whose `values.extension` matches this extId. */
228
+ components: ComponentRecord[];
229
+ localDiff?: LocalDiff | null;
230
+ }
231
+ export interface BuildOrphanInput {
232
+ appId: string;
233
+ appSlug: string;
234
+ /** The unresolved extension value taken from the function/component. */
235
+ unresolvedId: string;
236
+ functions: FunctionRecord[];
237
+ components: ComponentRecord[];
238
+ }
239
+ /** Build the synthesized envelope for a regular (non-orphan) extension row. */
240
+ export declare function buildExtensionDetail(input: BuildDetailInput): ExtensionDetail;
241
+ /** Build the synthesized envelope for an orphan row. */
242
+ export declare function buildOrphanDetail(input: BuildOrphanInput): ExtensionDetail;
243
+ /**
244
+ * List-mode meta string for one row. Returns `undefined` when the row has
245
+ * nothing surface-worthy beyond the type tag (which is always present).
246
+ */
247
+ export declare function listMetaFor(detail: ExtensionDetail): string;
248
+ /**
249
+ * List-mode meta string for an orphan row. The type tag is replaced with
250
+ * the status word since there's no manifest to derive type from.
251
+ */
252
+ export declare function orphanListMeta(fnCount: number, compCount: number): string;
253
+ /**
254
+ * `Next steps:` lines per status. Runnable shell commands come first,
255
+ * merchant-UI lines come second prefixed with `(merchant)` so an agent can
256
+ * filter. Empty array when there are no actionable next steps.
257
+ */
258
+ export declare function nextStepLines(detail: ExtensionDetail): string[];
259
+ /**
260
+ * Section ordering for the list view. Apps render alphabetically; orphan
261
+ * rows land in a single trailing `<orphans>` group.
262
+ */
263
+ export declare function listGroupForApp(slug: string): GroupInfo;
264
+ export declare function listGroupForOrphans(): GroupInfo;
265
+ /** True when a function/component "belongs to" an extension by direct match. */
266
+ export declare function functionMatchesExtension(fn: FunctionRecord, extId: string): boolean;
267
+ export declare function componentMatchesExtension(comp: ComponentRecord, extId: string): boolean;