@ductape/cli 0.3.11 → 0.3.12
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.
- package/dist/commands/marketplace.d.ts +1 -0
- package/dist/commands/marketplace.js +1 -1
- package/dist/commands/products.d.ts +10 -0
- package/dist/commands/products.js +39 -6
- package/dist/index.js +31 -2
- package/dist/lib/platform-api.d.ts +9 -2
- package/dist/lib/platform-api.js +221 -9
- package/package.json +1 -1
|
@@ -17,7 +17,7 @@ export async function runMarketplace(verb, opts, args) {
|
|
|
17
17
|
const tag = opts.tag ?? args[0];
|
|
18
18
|
if (!tag)
|
|
19
19
|
throw new Error('marketplace get requires <tag> or --tag <tag>');
|
|
20
|
-
result = await getMarketplaceApp(ctx, tag);
|
|
20
|
+
result = await getMarketplaceApp(ctx, tag, Boolean(opts.full));
|
|
21
21
|
break;
|
|
22
22
|
}
|
|
23
23
|
case 'categories':
|
|
@@ -10,8 +10,18 @@ export declare function runProducts(verb: string, opts: {
|
|
|
10
10
|
export declare function runProductApps(verb: string, opts: {
|
|
11
11
|
profile?: string;
|
|
12
12
|
product?: string;
|
|
13
|
+
app?: string;
|
|
14
|
+
envMap?: string[];
|
|
13
15
|
json?: boolean;
|
|
16
|
+
full?: boolean;
|
|
14
17
|
}, extraArgs: string[]): Promise<void>;
|
|
18
|
+
export declare function runProductAppActions(verb: string, opts: {
|
|
19
|
+
profile?: string;
|
|
20
|
+
product?: string;
|
|
21
|
+
app?: string;
|
|
22
|
+
action?: string;
|
|
23
|
+
json?: boolean;
|
|
24
|
+
}): Promise<void>;
|
|
15
25
|
export declare function runProductComponents(verb: string, opts: {
|
|
16
26
|
profile?: string;
|
|
17
27
|
tag?: string;
|
|
@@ -2,7 +2,7 @@ import { schemaKeyForEntity } from '../lib/forms/index.js';
|
|
|
2
2
|
import { isInteractive, promptTag } from '../lib/forms/prompt.js';
|
|
3
3
|
import { toInteractiveOpts } from '../lib/interactive-opts.js';
|
|
4
4
|
import { bodyRequiredHint, resolveBody } from '../lib/read-body.js';
|
|
5
|
-
import { createProduct, deleteProduct, getProduct, listProductApps, listProducts, updateProduct, } from '../lib/platform-api.js';
|
|
5
|
+
import { connectMarketplaceApp, createProduct, deleteProduct, getProduct, getProductAppAction, listProductAppActions, listProductApps, listProducts, updateProduct, } from '../lib/platform-api.js';
|
|
6
6
|
import { printJson } from '../lib/output.js';
|
|
7
7
|
import { requireWorkspaceContext } from '../lib/workspace-context.js';
|
|
8
8
|
import { getSdkProxyForContext, getOptionalProject } from '../lib/proxy/context.js';
|
|
@@ -63,16 +63,49 @@ export async function runProducts(verb, opts, extraArgs) {
|
|
|
63
63
|
printJson(result, Boolean(opts.json));
|
|
64
64
|
}
|
|
65
65
|
export async function runProductApps(verb, opts, extraArgs) {
|
|
66
|
-
if (verb.toLowerCase() !== 'list') {
|
|
67
|
-
throw new Error('Only supported: ductape products apps list --product <id>');
|
|
68
|
-
}
|
|
69
66
|
const ctx = requireWorkspaceContext({ profile: opts.profile });
|
|
70
67
|
const productId = opts.product ?? extraArgs[0];
|
|
71
68
|
if (!productId)
|
|
72
|
-
throw new Error('Provide --product <
|
|
73
|
-
|
|
69
|
+
throw new Error('Provide --product <product_id_or_tag>');
|
|
70
|
+
let result;
|
|
71
|
+
if (verb.toLowerCase() === 'list') {
|
|
72
|
+
result = await listProductApps(ctx, productId, Boolean(opts.full));
|
|
73
|
+
}
|
|
74
|
+
else if (verb.toLowerCase() === 'connect') {
|
|
75
|
+
if (!opts.app)
|
|
76
|
+
throw new Error('Provide --app <marketplace_app_tag>');
|
|
77
|
+
const envs = (opts.envMap ?? []).map((mapping) => {
|
|
78
|
+
const [appEnv, productEnv, ...extra] = mapping.split(':');
|
|
79
|
+
if (!appEnv || !productEnv || extra.length) {
|
|
80
|
+
throw new Error(`Invalid --env-map "${mapping}"; expected <app_env>:<product_env>`);
|
|
81
|
+
}
|
|
82
|
+
return { app_env_slug: appEnv, product_env_slug: productEnv };
|
|
83
|
+
});
|
|
84
|
+
result = await connectMarketplaceApp(ctx, productId, opts.app, envs);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
throw new Error('Supported verbs: list | connect');
|
|
88
|
+
}
|
|
74
89
|
printJson(result, Boolean(opts.json));
|
|
75
90
|
}
|
|
91
|
+
export async function runProductAppActions(verb, opts) {
|
|
92
|
+
const ctx = requireWorkspaceContext({ profile: opts.profile });
|
|
93
|
+
if (!opts.product)
|
|
94
|
+
throw new Error('Provide --product <product_id_or_tag>');
|
|
95
|
+
if (!opts.app)
|
|
96
|
+
throw new Error('Provide --app <app_tag>');
|
|
97
|
+
if (verb === 'list') {
|
|
98
|
+
printJson(await listProductAppActions(ctx, opts.product, opts.app), Boolean(opts.json));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (verb === 'get') {
|
|
102
|
+
if (!opts.action)
|
|
103
|
+
throw new Error('Provide --action <action_tag>');
|
|
104
|
+
printJson(await getProductAppAction(ctx, opts.product, opts.app, opts.action), Boolean(opts.json));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
throw new Error('Supported verbs: list | get');
|
|
108
|
+
}
|
|
76
109
|
const COMPONENT_KEYS = {
|
|
77
110
|
apps: ['apps'],
|
|
78
111
|
databases: ['databases'],
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ import { runSecretImportEnv, runSecrets } from './commands/secrets.js';
|
|
|
22
22
|
import { runWorkspacesCurrent, runWorkspacesList, runWorkspacesRefresh, runWorkspacesUse, } from './commands/workspaces.js';
|
|
23
23
|
import { runGeneratePayload, runGenerateSnippet } from './commands/generate.js';
|
|
24
24
|
import { runCompletion } from './commands/completion.js';
|
|
25
|
-
import { runProducts, runProductApps, runProductComponents, runProductEnvironments } from './commands/products.js';
|
|
25
|
+
import { runProducts, runProductApps, runProductAppActions, runProductComponents, runProductEnvironments } from './commands/products.js';
|
|
26
26
|
import { runApps } from './commands/apps.js';
|
|
27
27
|
import { runAppsImport } from './commands/apps-import.js';
|
|
28
28
|
import { runMarketplace } from './commands/marketplace.js';
|
|
@@ -530,12 +530,40 @@ const products = program
|
|
|
530
530
|
return runProducts(verb, opts, []);
|
|
531
531
|
}));
|
|
532
532
|
const productApps = products.command('apps').description('Apps connected to a product');
|
|
533
|
+
function collectOption(value, previous) {
|
|
534
|
+
return previous.concat(value);
|
|
535
|
+
}
|
|
533
536
|
productApps
|
|
534
537
|
.command('list')
|
|
535
538
|
.option('--profile <name>')
|
|
536
|
-
.option('--product <id>', 'Product _id')
|
|
539
|
+
.option('--product <id-or-tag>', 'Product _id or tag')
|
|
540
|
+
.option('--full', 'Include complete app versions, actions, schemas, and responses')
|
|
537
541
|
.option('--json', 'JSON output')
|
|
538
542
|
.action(wrap((opts) => runProductApps('list', opts, [])));
|
|
543
|
+
productApps
|
|
544
|
+
.command('connect')
|
|
545
|
+
.requiredOption('--product <id-or-tag>', 'Product _id or tag')
|
|
546
|
+
.requiredOption('--app <tag>', 'Public marketplace app tag')
|
|
547
|
+
.requiredOption('--env-map <app-env:product-env>', 'Environment mapping; repeat for every product environment', collectOption, [])
|
|
548
|
+
.option('--profile <name>')
|
|
549
|
+
.option('--json', 'JSON output')
|
|
550
|
+
.action(wrap((opts) => runProductApps('connect', opts, [])));
|
|
551
|
+
const productAppActions = productApps.command('actions').description('Actions exposed by an app linked to a product');
|
|
552
|
+
productAppActions
|
|
553
|
+
.command('list')
|
|
554
|
+
.requiredOption('--product <id-or-tag>', 'Product _id or tag')
|
|
555
|
+
.requiredOption('--app <tag>', 'Linked app tag')
|
|
556
|
+
.option('--profile <name>')
|
|
557
|
+
.option('--json', 'JSON output')
|
|
558
|
+
.action(wrap((opts) => runProductAppActions('list', opts)));
|
|
559
|
+
productAppActions
|
|
560
|
+
.command('get')
|
|
561
|
+
.requiredOption('--product <id-or-tag>', 'Product _id or tag')
|
|
562
|
+
.requiredOption('--app <tag>', 'Linked app tag')
|
|
563
|
+
.requiredOption('--action <tag>', 'Action tag')
|
|
564
|
+
.option('--profile <name>')
|
|
565
|
+
.option('--json', 'JSON output')
|
|
566
|
+
.action(wrap((opts) => runProductAppActions('get', opts)));
|
|
539
567
|
const productComponents = products
|
|
540
568
|
.command('components')
|
|
541
569
|
.description('Compact, non-secret product component inventory');
|
|
@@ -635,6 +663,7 @@ program
|
|
|
635
663
|
.option('-c, --category <category>', 'Filter by category/domain name')
|
|
636
664
|
.option('-l, --limit <count>', 'Maximum results', '20')
|
|
637
665
|
.option('-t, --tag <tag>', 'Marketplace app tag for get')
|
|
666
|
+
.option('--full', 'Return the complete marketplace app definition for get')
|
|
638
667
|
.option('--json', 'JSON output')
|
|
639
668
|
.action(wrap((verb, terms, opts) => runMarketplace(verb, opts, terms)));
|
|
640
669
|
const events = program.command('events').description('Message broker CRUD (sdk-proxy, requires access key login)');
|
|
@@ -7,7 +7,14 @@ export declare function getProduct(ctx: WorkspaceContext, opts: {
|
|
|
7
7
|
export declare function createProduct(ctx: WorkspaceContext, body: Record<string, unknown>): Promise<unknown>;
|
|
8
8
|
export declare function updateProduct(ctx: WorkspaceContext, tag: string, body: Record<string, unknown>): Promise<unknown>;
|
|
9
9
|
export declare function deleteProduct(ctx: WorkspaceContext, productId: string): Promise<unknown>;
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function summarizeConnectedApp(value: unknown): unknown;
|
|
11
|
+
export declare function listProductApps(ctx: WorkspaceContext, productIdOrTag: string, full?: boolean): Promise<unknown[]>;
|
|
12
|
+
export declare function listProductAppActions(ctx: WorkspaceContext, product: string, appTag: string): Promise<unknown[]>;
|
|
13
|
+
export declare function getProductAppAction(ctx: WorkspaceContext, product: string, appTag: string, actionTag: string): Promise<unknown>;
|
|
14
|
+
export declare function connectMarketplaceApp(ctx: WorkspaceContext, product: string, appTag: string, envs: Array<{
|
|
15
|
+
app_env_slug: string;
|
|
16
|
+
product_env_slug: string;
|
|
17
|
+
}>): Promise<unknown>;
|
|
11
18
|
export declare function listApps(ctx: WorkspaceContext, status?: string): Promise<unknown[]>;
|
|
12
19
|
export declare function getApp(ctx: WorkspaceContext, opts: {
|
|
13
20
|
id?: string;
|
|
@@ -23,7 +30,7 @@ export interface MarketplaceSearchOptions {
|
|
|
23
30
|
limit?: number;
|
|
24
31
|
}
|
|
25
32
|
export declare function listMarketplaceCategories(ctx: WorkspaceContext): Promise<unknown[]>;
|
|
26
|
-
export declare function getMarketplaceApp(ctx: WorkspaceContext, tag: string): Promise<unknown>;
|
|
33
|
+
export declare function getMarketplaceApp(ctx: WorkspaceContext, tag: string, full?: boolean): Promise<unknown>;
|
|
27
34
|
export declare function searchMarketplaceApps(ctx: WorkspaceContext, opts: MarketplaceSearchOptions): Promise<unknown[]>;
|
|
28
35
|
export interface TierQuery {
|
|
29
36
|
provider?: string;
|
package/dist/lib/platform-api.js
CHANGED
|
@@ -56,8 +56,20 @@ export async function getProduct(ctx, opts) {
|
|
|
56
56
|
// The integrations REST fetch-by-tag route rejects current CLI login tokens with HTTP 401.
|
|
57
57
|
// Product inventory is an administrative read, so route it through the authenticated CLI
|
|
58
58
|
// SDK proxy (x-access-token), not the publishable-key runtime MCP proxy.
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
try {
|
|
60
|
+
const result = await proxy(ctx).execute('product', 'fetch', [opts.tag]);
|
|
61
|
+
return unwrapOne(result);
|
|
62
|
+
}
|
|
63
|
+
catch (proxyError) {
|
|
64
|
+
// Some deployed proxy versions fail product.fetch while the authenticated workspace
|
|
65
|
+
// inventory remains healthy. Resolve the exact tag from that inventory; never guess or
|
|
66
|
+
// turn a transport failure into an empty result.
|
|
67
|
+
const products = await listProducts(ctx, 'all');
|
|
68
|
+
const match = products.find((product) => product && typeof product === 'object' && product.tag === opts.tag);
|
|
69
|
+
if (match)
|
|
70
|
+
return match;
|
|
71
|
+
throw proxyError;
|
|
72
|
+
}
|
|
61
73
|
}
|
|
62
74
|
throw new Error('Provide --id <product_id> or --tag <product_tag>');
|
|
63
75
|
}
|
|
@@ -77,9 +89,185 @@ export async function updateProduct(ctx, tag, body) {
|
|
|
77
89
|
export async function deleteProduct(ctx, productId) {
|
|
78
90
|
return client(ctx).delete(`/integrations/v1/${productId}?${new URLSearchParams(workspaceAuthQuery(ctx)).toString()}`);
|
|
79
91
|
}
|
|
80
|
-
export
|
|
81
|
-
|
|
82
|
-
|
|
92
|
+
export function summarizeConnectedApp(value) {
|
|
93
|
+
if (!value || typeof value !== 'object')
|
|
94
|
+
return value;
|
|
95
|
+
const app = value;
|
|
96
|
+
const versions = Array.isArray(app.versions) ? app.versions : [];
|
|
97
|
+
const linkedEnvs = Array.isArray(app.envs) ? app.envs : [];
|
|
98
|
+
return {
|
|
99
|
+
_id: app._id ?? app.id,
|
|
100
|
+
tag: app.tag ?? app.app_tag,
|
|
101
|
+
access_tag: app.access_tag,
|
|
102
|
+
name: app.app_name ?? app.name,
|
|
103
|
+
description: app.description,
|
|
104
|
+
status: app.status,
|
|
105
|
+
active: app.active,
|
|
106
|
+
environments: linkedEnvs.map((item) => {
|
|
107
|
+
const env = item && typeof item === 'object' ? item : {};
|
|
108
|
+
return {
|
|
109
|
+
app_env_slug: env.app_env_slug,
|
|
110
|
+
product_env_slug: env.product_env_slug,
|
|
111
|
+
};
|
|
112
|
+
}),
|
|
113
|
+
versions: versions.map((item) => {
|
|
114
|
+
const version = item && typeof item === 'object' ? item : {};
|
|
115
|
+
return {
|
|
116
|
+
tag: version.tag,
|
|
117
|
+
latest: version.latest,
|
|
118
|
+
active: version.active,
|
|
119
|
+
environments: Array.isArray(version.envs) ? version.envs.length : 0,
|
|
120
|
+
actions: Array.isArray(version.actions) ? version.actions.length : 0,
|
|
121
|
+
webhooks: Array.isArray(version.webhooks) ? version.webhooks.length : 0,
|
|
122
|
+
};
|
|
123
|
+
}),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export async function listProductApps(ctx, productIdOrTag, full = false) {
|
|
127
|
+
const isObjectId = /^[a-f\d]{24}$/i.test(productIdOrTag);
|
|
128
|
+
// A tag is already sufficient for the compact SDK method; do not fetch the
|
|
129
|
+
// product catalogue merely to rediscover that same tag.
|
|
130
|
+
if (!full && !isObjectId) {
|
|
131
|
+
try {
|
|
132
|
+
const result = await proxy(ctx).execute('product', 'apps.list', [productIdOrTag]);
|
|
133
|
+
return unwrapList(result).map(summarizeConnectedApp);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
// Older deployments may not expose product.apps.list reliably. The product
|
|
137
|
+
// record itself still contains compact link records and is the safe fallback.
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const product = await getProduct(ctx, isObjectId ? { id: productIdOrTag } : { tag: productIdOrTag });
|
|
141
|
+
const row = product && typeof product === 'object' ? product : {};
|
|
142
|
+
const productId = String(row._id ?? row.id ?? (isObjectId ? productIdOrTag : ''));
|
|
143
|
+
const productTag = String(row.tag ?? (!isObjectId ? productIdOrTag : ''));
|
|
144
|
+
// The SDK proxy returns only the product's link records and avoids expanding every
|
|
145
|
+
// action contract. Prefer it for normal discovery; retain the expanded REST route
|
|
146
|
+
// solely for --full and compatibility with older deployed proxy versions.
|
|
147
|
+
if (!full && Array.isArray(row.apps)) {
|
|
148
|
+
return row.apps.map(summarizeConnectedApp);
|
|
149
|
+
}
|
|
150
|
+
if (!full && productTag) {
|
|
151
|
+
try {
|
|
152
|
+
const result = await proxy(ctx).execute('product', 'apps.list', [productTag]);
|
|
153
|
+
return unwrapList(result).map(summarizeConnectedApp);
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
// Fall through to the linked-app REST endpoint.
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (productId) {
|
|
160
|
+
try {
|
|
161
|
+
const result = await client(ctx).getPath(`/integrations/v1/fetch-product-apps/${productId}`, workspaceAuthQuery(ctx));
|
|
162
|
+
const apps = unwrapList(result);
|
|
163
|
+
return full ? apps : apps.map(summarizeConnectedApp);
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
if (!productTag)
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (!productTag)
|
|
171
|
+
throw new Error(`Could not resolve product tag for "${productIdOrTag}"`);
|
|
172
|
+
const result = await proxy(ctx).execute('product', 'apps.list', [productTag]);
|
|
173
|
+
const apps = unwrapList(result);
|
|
174
|
+
return full ? apps : apps.map(summarizeConnectedApp);
|
|
175
|
+
}
|
|
176
|
+
function actionSummary(value) {
|
|
177
|
+
if (!value || typeof value !== 'object')
|
|
178
|
+
return value;
|
|
179
|
+
const action = value;
|
|
180
|
+
return {
|
|
181
|
+
tag: action.tag,
|
|
182
|
+
name: action.name,
|
|
183
|
+
description: action.description,
|
|
184
|
+
method: action.method,
|
|
185
|
+
resource: action.resource,
|
|
186
|
+
request_type: action.request_type,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function actionsFromLinkedApp(app) {
|
|
190
|
+
const versions = Array.isArray(app.versions) ? app.versions : [];
|
|
191
|
+
const version = versions.find((item) => item.latest === true) ?? versions[0];
|
|
192
|
+
return Array.isArray(version?.actions) ? version.actions : [];
|
|
193
|
+
}
|
|
194
|
+
async function requireLinkedApp(ctx, product, appTag) {
|
|
195
|
+
const apps = await listProductApps(ctx, product);
|
|
196
|
+
const app = apps.find((item) => {
|
|
197
|
+
if (!item || typeof item !== 'object')
|
|
198
|
+
return false;
|
|
199
|
+
const row = item;
|
|
200
|
+
return row.tag === appTag || row.app_tag === appTag;
|
|
201
|
+
});
|
|
202
|
+
if (!app || typeof app !== 'object')
|
|
203
|
+
throw new Error(`App "${appTag}" is not linked to product "${product}"`);
|
|
204
|
+
return app;
|
|
205
|
+
}
|
|
206
|
+
export async function listProductAppActions(ctx, product, appTag) {
|
|
207
|
+
await requireLinkedApp(ctx, product, appTag);
|
|
208
|
+
try {
|
|
209
|
+
const result = await proxy(ctx).execute('app', 'actions.list', [appTag]);
|
|
210
|
+
return unwrapList(result).map(actionSummary);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
const app = await getApp(ctx, { tag: appTag });
|
|
214
|
+
if (!app || typeof app !== 'object')
|
|
215
|
+
throw new Error(`App "${appTag}" could not be fetched`);
|
|
216
|
+
return actionsFromLinkedApp(app).map(actionSummary);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
export async function getProductAppAction(ctx, product, appTag, actionTag) {
|
|
220
|
+
await requireLinkedApp(ctx, product, appTag);
|
|
221
|
+
try {
|
|
222
|
+
const result = unwrapOne(await proxy(ctx).execute('app', 'actions.fetch', [appTag, actionTag]));
|
|
223
|
+
if (result)
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
// Compatibility fallback for deployed SDKs predating app.actions.
|
|
228
|
+
}
|
|
229
|
+
const app = await getApp(ctx, { tag: appTag });
|
|
230
|
+
if (!app || typeof app !== 'object')
|
|
231
|
+
throw new Error(`App "${appTag}" could not be fetched`);
|
|
232
|
+
const action = actionsFromLinkedApp(app).find((item) => item && typeof item === 'object' && item.tag === actionTag);
|
|
233
|
+
if (!action)
|
|
234
|
+
throw new Error(`Action "${actionTag}" was not found on linked app "${appTag}"`);
|
|
235
|
+
return action;
|
|
236
|
+
}
|
|
237
|
+
export async function connectMarketplaceApp(ctx, product, appTag, envs) {
|
|
238
|
+
if (envs.length === 0)
|
|
239
|
+
throw new Error('At least one app-to-product environment mapping is required');
|
|
240
|
+
const marketplaceApp = await getMarketplaceApp(ctx, appTag, true);
|
|
241
|
+
if (!marketplaceApp || typeof marketplaceApp !== 'object')
|
|
242
|
+
throw new Error(`Marketplace app "${appTag}" was not found`);
|
|
243
|
+
const app = marketplaceApp;
|
|
244
|
+
if (app.status !== 'public')
|
|
245
|
+
throw new Error(`App "${appTag}" is not public in the marketplace`);
|
|
246
|
+
const versions = Array.isArray(app.versions) ? app.versions : [];
|
|
247
|
+
const latest = versions.find((version) => version.latest === true) ?? versions[0];
|
|
248
|
+
const availableAppEnvs = new Set((Array.isArray(latest?.envs) ? latest.envs : []).map((env) => String(env && typeof env === 'object' ? env.slug ?? '' : env)).filter(Boolean));
|
|
249
|
+
const productEnvs = unwrapList(await proxy(ctx).execute('product', 'environments.list', [product]));
|
|
250
|
+
const availableProductEnvs = new Set(productEnvs.map((env) => String(env.slug ?? '')).filter(Boolean));
|
|
251
|
+
for (const mapping of envs) {
|
|
252
|
+
if (!availableAppEnvs.has(mapping.app_env_slug)) {
|
|
253
|
+
throw new Error(`Marketplace app "${appTag}" has no environment "${mapping.app_env_slug}"`);
|
|
254
|
+
}
|
|
255
|
+
if (!availableProductEnvs.has(mapping.product_env_slug)) {
|
|
256
|
+
throw new Error(`Product "${product}" has no environment "${mapping.product_env_slug}"`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
const accessResult = unwrapOne(await proxy(ctx).execute('product', 'apps.connect', [product, appTag]));
|
|
260
|
+
const accessTag = String(accessResult?.access_tag ?? '');
|
|
261
|
+
if (!accessTag)
|
|
262
|
+
throw new Error(`Could not create or resolve access for marketplace app "${appTag}"`);
|
|
263
|
+
await proxy(ctx).execute('product', 'apps.add', [product, { access_tag: accessTag, envs }]);
|
|
264
|
+
return {
|
|
265
|
+
connected: true,
|
|
266
|
+
product,
|
|
267
|
+
app_tag: appTag,
|
|
268
|
+
access_tag: accessTag,
|
|
269
|
+
environments: envs,
|
|
270
|
+
};
|
|
83
271
|
}
|
|
84
272
|
// —— Apps (apps REST) ——
|
|
85
273
|
export async function listApps(ctx, status = 'all') {
|
|
@@ -99,7 +287,9 @@ export async function getApp(ctx, opts) {
|
|
|
99
287
|
return unwrapOne(result);
|
|
100
288
|
}
|
|
101
289
|
if (opts.tag) {
|
|
102
|
-
|
|
290
|
+
// The REST tag route is not consistent for namespaced/private apps. The authenticated SDK
|
|
291
|
+
// proxy uses AppBuilder's canonical tag lookup and works for tags such as ductape:paystack.
|
|
292
|
+
const result = await proxy(ctx).execute('app', 'fetch', [opts.tag]);
|
|
103
293
|
return unwrapOne(result);
|
|
104
294
|
}
|
|
105
295
|
throw new Error('Provide --id <app_id> or --tag <app_tag>');
|
|
@@ -164,13 +354,35 @@ function searchableMarketplaceText(app) {
|
|
|
164
354
|
}),
|
|
165
355
|
].filter((item) => typeof item === 'string').join(' ').toLowerCase();
|
|
166
356
|
}
|
|
357
|
+
function summarizeMarketplaceApp(value) {
|
|
358
|
+
if (!value || typeof value !== 'object')
|
|
359
|
+
return value;
|
|
360
|
+
const app = value;
|
|
361
|
+
const versions = Array.isArray(app.versions) ? app.versions : [];
|
|
362
|
+
const current = app.currentVersion && typeof app.currentVersion === 'object'
|
|
363
|
+
? app.currentVersion
|
|
364
|
+
: versions.find((version) => version.latest === true) ?? versions[0] ?? {};
|
|
365
|
+
const actions = Array.isArray(current.actions) ? current.actions : [];
|
|
366
|
+
return {
|
|
367
|
+
tag: app.tag,
|
|
368
|
+
name: app.app_name ?? app.name,
|
|
369
|
+
description: app.description,
|
|
370
|
+
categories: app.domains ?? [],
|
|
371
|
+
version: current.tag,
|
|
372
|
+
environments: Array.isArray(current.envs)
|
|
373
|
+
? current.envs.map((env) => env && typeof env === 'object' ? env.slug : env)
|
|
374
|
+
: [],
|
|
375
|
+
actions: actions.map(actionSummary),
|
|
376
|
+
};
|
|
377
|
+
}
|
|
167
378
|
export async function listMarketplaceCategories(ctx) {
|
|
168
379
|
const result = await client(ctx).getPath('/apps/v1/domains');
|
|
169
380
|
return unwrapList(result);
|
|
170
381
|
}
|
|
171
|
-
export async function getMarketplaceApp(ctx, tag) {
|
|
382
|
+
export async function getMarketplaceApp(ctx, tag, full = false) {
|
|
172
383
|
const result = await client(ctx).getPath('/apps/v1/fetch/tag', { tag });
|
|
173
|
-
|
|
384
|
+
const app = unwrapOne(result);
|
|
385
|
+
return full ? app : summarizeMarketplaceApp(app);
|
|
174
386
|
}
|
|
175
387
|
export async function searchMarketplaceApps(ctx, opts) {
|
|
176
388
|
const result = await client(ctx).getPath('/apps/v1/domains/all');
|
|
@@ -188,7 +400,7 @@ export async function searchMarketplaceApps(ctx, opts) {
|
|
|
188
400
|
const domains = app.domains;
|
|
189
401
|
return Array.isArray(domains) && domains.some((domain) => typeof domain === 'string' && domain.toLowerCase().includes(category));
|
|
190
402
|
});
|
|
191
|
-
return filtered.slice(0, Math.max(1, Math.min(opts.limit ?? 20, 100)));
|
|
403
|
+
return filtered.slice(0, Math.max(1, Math.min(opts.limit ?? 20, 100))).map(summarizeMarketplaceApp);
|
|
192
404
|
}
|
|
193
405
|
export async function listCloudTiers(ctx, q) {
|
|
194
406
|
const params = workspaceAuthQuery(ctx);
|
package/package.json
CHANGED