adapty 0.7.0 → 0.8.0-beta.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.
- package/dist/commands/flows/config/validate.d.ts +19 -0
- package/dist/commands/flows/config/validate.js +77 -0
- package/dist/commands/flows/media/upload.d.ts +14 -0
- package/dist/commands/flows/media/upload.js +46 -0
- package/dist/lib/api-schemas.d.ts +23 -0
- package/oclif.manifest.json +1860 -1750
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
import type { FlowConfigValidationDTO } from '../../../lib/api-schemas.js';
|
|
3
|
+
export default class FlowsConfigValidate extends Command {
|
|
4
|
+
static args: {
|
|
5
|
+
flow_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
6
|
+
};
|
|
7
|
+
static description: string;
|
|
8
|
+
static enableJsonFlag: boolean;
|
|
9
|
+
static examples: string[];
|
|
10
|
+
static flags: {
|
|
11
|
+
config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
'config-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
app: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
};
|
|
15
|
+
run(): Promise<FlowConfigValidationDTO>;
|
|
16
|
+
private parseJson;
|
|
17
|
+
private readConfig;
|
|
18
|
+
private readStdin;
|
|
19
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Args, Command, Flags } from '@oclif/core';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { createAuthenticatedClient } from '../../../lib/client-from-config.js';
|
|
4
|
+
import { appFlag, isValidUuid } from '../../../lib/flags.js';
|
|
5
|
+
import { printResponse } from '../../../lib/output.js';
|
|
6
|
+
export default class FlowsConfigValidate extends Command {
|
|
7
|
+
static args = {
|
|
8
|
+
flow_id: Args.string({ description: 'Flow ID (UUID)', required: true }),
|
|
9
|
+
};
|
|
10
|
+
static description = 'Check whether a builder config is publishable (advisory; does not save). Exits non-zero when the config is not publishable.';
|
|
11
|
+
static enableJsonFlag = true;
|
|
12
|
+
static examples = [
|
|
13
|
+
'<%= config.bin %> flows config validate --app UUID FLOW_UUID --config-file config.json',
|
|
14
|
+
'cat config.json | <%= config.bin %> flows config validate --app UUID FLOW_UUID --config-file -',
|
|
15
|
+
'<%= config.bin %> flows config validate --app UUID FLOW_UUID --config \'{"screens":[],"locales":[]}\'',
|
|
16
|
+
];
|
|
17
|
+
static flags = {
|
|
18
|
+
...appFlag,
|
|
19
|
+
config: Flags.string({
|
|
20
|
+
description: 'Builder config as a JSON string',
|
|
21
|
+
exactlyOne: ['config', 'config-file'],
|
|
22
|
+
}),
|
|
23
|
+
'config-file': Flags.string({
|
|
24
|
+
description: 'JSON file with the builder config, or - to read stdin',
|
|
25
|
+
exactlyOne: ['config', 'config-file'],
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
async run() {
|
|
29
|
+
const { args, flags } = await this.parse(FlowsConfigValidate);
|
|
30
|
+
if (!isValidUuid(args.flow_id)) {
|
|
31
|
+
this.error('Invalid flow ID format.', { exit: 2 });
|
|
32
|
+
}
|
|
33
|
+
const config = await this.readConfig(flags);
|
|
34
|
+
const body = { config };
|
|
35
|
+
const client = await createAuthenticatedClient(this.config);
|
|
36
|
+
const result = await client.post(`/apps/${flags.app}/flows/${args.flow_id}/config/validate`, body);
|
|
37
|
+
this.log(result.valid ? 'Config is publishable.' : 'Config is NOT publishable.');
|
|
38
|
+
printResponse(result, this.log.bind(this));
|
|
39
|
+
// Advisory endpoint always returns HTTP 200; surface the verdict as an exit code so scripts and agents
|
|
40
|
+
// can gate on it. The JSON/`valid` field stays the source of truth for programmatic consumers.
|
|
41
|
+
if (!result.valid) {
|
|
42
|
+
process.exitCode = 1;
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
parseJson(raw, label) {
|
|
47
|
+
try {
|
|
48
|
+
return JSON.parse(raw);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
this.error(`Invalid ${label} JSON: ${error instanceof Error ? error.message : String(error)}`, { exit: 2 });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async readConfig(flags) {
|
|
55
|
+
if (flags.config !== undefined) {
|
|
56
|
+
return this.parseJson(flags.config, '--config');
|
|
57
|
+
}
|
|
58
|
+
const path = flags['config-file'];
|
|
59
|
+
if (path === undefined) {
|
|
60
|
+
this.error('Provide --config or --config-file.', { exit: 2 });
|
|
61
|
+
}
|
|
62
|
+
let raw;
|
|
63
|
+
try {
|
|
64
|
+
raw = path === '-' ? await this.readStdin() : await readFile(path, 'utf8');
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
this.error(`Could not read ${path}.`, { exit: 2 });
|
|
68
|
+
}
|
|
69
|
+
return this.parseJson(raw, path);
|
|
70
|
+
}
|
|
71
|
+
async readStdin() {
|
|
72
|
+
const chunks = [];
|
|
73
|
+
for await (const chunk of process.stdin)
|
|
74
|
+
chunks.push(chunk);
|
|
75
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
import type { MediaDTO } from '../../../lib/api-schemas.js';
|
|
3
|
+
export default class FlowsMediaUpload extends Command {
|
|
4
|
+
static args: {
|
|
5
|
+
file: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
6
|
+
};
|
|
7
|
+
static description: string;
|
|
8
|
+
static enableJsonFlag: boolean;
|
|
9
|
+
static examples: string[];
|
|
10
|
+
static flags: {
|
|
11
|
+
app: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<MediaDTO>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Args, Command } from '@oclif/core';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { basename, extname } from 'node:path';
|
|
4
|
+
import { createAuthenticatedClient } from '../../../lib/client-from-config.js';
|
|
5
|
+
import { appFlag } from '../../../lib/flags.js';
|
|
6
|
+
import { printResponse } from '../../../lib/output.js';
|
|
7
|
+
const IMAGE_MIME_TYPES = {
|
|
8
|
+
'.gif': 'image/gif',
|
|
9
|
+
'.heic': 'image/heic',
|
|
10
|
+
'.jpeg': 'image/jpeg',
|
|
11
|
+
'.jpg': 'image/jpeg',
|
|
12
|
+
'.png': 'image/png',
|
|
13
|
+
'.svg': 'image/svg+xml',
|
|
14
|
+
'.webp': 'image/webp',
|
|
15
|
+
};
|
|
16
|
+
export default class FlowsMediaUpload extends Command {
|
|
17
|
+
static args = {
|
|
18
|
+
file: Args.string({ description: 'Path to the image file to upload', required: true }),
|
|
19
|
+
};
|
|
20
|
+
static description = 'Upload an image as a flow builder asset; prints the CDN URL to reference from a flow config';
|
|
21
|
+
static enableJsonFlag = true;
|
|
22
|
+
static examples = ['<%= config.bin %> flows media upload --app UUID ./onboarding-hero.png'];
|
|
23
|
+
static flags = {
|
|
24
|
+
...appFlag,
|
|
25
|
+
};
|
|
26
|
+
async run() {
|
|
27
|
+
const { args, flags } = await this.parse(FlowsMediaUpload);
|
|
28
|
+
let content;
|
|
29
|
+
try {
|
|
30
|
+
content = await readFile(args.file);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
this.error(`Cannot read file: ${args.file}`, { exit: 2 });
|
|
34
|
+
}
|
|
35
|
+
const name = basename(args.file);
|
|
36
|
+
const type = IMAGE_MIME_TYPES[extname(name).toLowerCase()] ?? 'application/octet-stream';
|
|
37
|
+
const form = new FormData();
|
|
38
|
+
form.append('file', new Blob([new Uint8Array(content)], { type }), name);
|
|
39
|
+
const client = await createAuthenticatedClient(this.config);
|
|
40
|
+
const result = await client.postForm(`/apps/${flags.app}/flows/media/images`, form);
|
|
41
|
+
this.log('Image uploaded!');
|
|
42
|
+
// `preview_base64` is a long data blob with no value in human output; --json still returns it in full.
|
|
43
|
+
printResponse({ id: result.id, name: result.name, url: result.url }, this.log.bind(this));
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -101,6 +101,29 @@ export interface FlowConfigWriteRequestDTO {
|
|
|
101
101
|
expected_updated_at?: null | number;
|
|
102
102
|
remote_configs?: FlowRemoteConfigDTO[];
|
|
103
103
|
}
|
|
104
|
+
export interface FlowConfigValidateRequestDTO {
|
|
105
|
+
config: Record<string, unknown>;
|
|
106
|
+
}
|
|
107
|
+
export interface FlowConfigIssueDTO {
|
|
108
|
+
/** Machine code, relayed from the transformer; absent until it reports path-level diagnostics. */
|
|
109
|
+
code?: null | string;
|
|
110
|
+
message: string;
|
|
111
|
+
/** Location of the issue; absent until the transformer reports path-level diagnostics. */
|
|
112
|
+
path?: null | string;
|
|
113
|
+
severity: string;
|
|
114
|
+
}
|
|
115
|
+
export interface FlowConfigValidationDTO {
|
|
116
|
+
issues: FlowConfigIssueDTO[];
|
|
117
|
+
valid: boolean;
|
|
118
|
+
}
|
|
119
|
+
export interface MediaDTO {
|
|
120
|
+
id: number;
|
|
121
|
+
name: string;
|
|
122
|
+
/** Base64-encoded preview thumbnail; absent when no preview was generated. */
|
|
123
|
+
preview_base64?: null | string;
|
|
124
|
+
/** CDN URL to reference from a flow config. */
|
|
125
|
+
url: string;
|
|
126
|
+
}
|
|
104
127
|
export interface SegmentDTO {
|
|
105
128
|
description: null | string;
|
|
106
129
|
id: string;
|