dataiku-sdk 0.10.0 → 0.11.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.
Files changed (133) hide show
  1. package/dist/packages/types/src/index.d.ts +15 -2
  2. package/dist/packages/types/src/index.js +9 -1
  3. package/dist/src/cli/coerce.d.ts +36 -0
  4. package/dist/src/cli/coerce.js +239 -0
  5. package/dist/src/cli/commands/api-deployer.d.ts +2 -0
  6. package/dist/src/cli/commands/api-deployer.js +170 -0
  7. package/dist/src/cli/commands/api-service.d.ts +2 -0
  8. package/dist/src/cli/commands/api-service.js +102 -0
  9. package/dist/src/cli/commands/app.d.ts +2 -0
  10. package/dist/src/cli/commands/app.js +78 -0
  11. package/dist/src/cli/commands/bundle.d.ts +2 -0
  12. package/dist/src/cli/commands/bundle.js +107 -0
  13. package/dist/src/cli/commands/business-app.d.ts +2 -0
  14. package/dist/src/cli/commands/business-app.js +76 -0
  15. package/dist/src/cli/commands/code-env.d.ts +2 -0
  16. package/dist/src/cli/commands/code-env.js +255 -0
  17. package/dist/src/cli/commands/code.d.ts +2 -0
  18. package/dist/src/cli/commands/code.js +63 -0
  19. package/dist/src/cli/commands/connection.d.ts +2 -0
  20. package/dist/src/cli/commands/connection.js +54 -0
  21. package/dist/src/cli/commands/continuous-activity.d.ts +2 -0
  22. package/dist/src/cli/commands/continuous-activity.js +38 -0
  23. package/dist/src/cli/commands/dashboard.d.ts +2 -0
  24. package/dist/src/cli/commands/dashboard.js +99 -0
  25. package/dist/src/cli/commands/data-quality.d.ts +2 -0
  26. package/dist/src/cli/commands/data-quality.js +235 -0
  27. package/dist/src/cli/commands/dataset.d.ts +2 -0
  28. package/dist/src/cli/commands/dataset.js +288 -0
  29. package/dist/src/cli/commands/discussion.d.ts +2 -0
  30. package/dist/src/cli/commands/discussion.js +47 -0
  31. package/dist/src/cli/commands/doctor.d.ts +2 -0
  32. package/dist/src/cli/commands/doctor.js +9 -0
  33. package/dist/src/cli/commands/flow-zone.d.ts +2 -0
  34. package/dist/src/cli/commands/flow-zone.js +282 -0
  35. package/dist/src/cli/commands/folder.d.ts +2 -0
  36. package/dist/src/cli/commands/folder.js +202 -0
  37. package/dist/src/cli/commands/future.d.ts +2 -0
  38. package/dist/src/cli/commands/future.js +57 -0
  39. package/dist/src/cli/commands/index.d.ts +2 -0
  40. package/dist/src/cli/commands/index.js +70 -0
  41. package/dist/src/cli/commands/insight.d.ts +2 -0
  42. package/dist/src/cli/commands/insight.js +156 -0
  43. package/dist/src/cli/commands/job.d.ts +2 -0
  44. package/dist/src/cli/commands/job.js +406 -0
  45. package/dist/src/cli/commands/meaning.d.ts +2 -0
  46. package/dist/src/cli/commands/meaning.js +115 -0
  47. package/dist/src/cli/commands/metrics.d.ts +2 -0
  48. package/dist/src/cli/commands/metrics.js +39 -0
  49. package/dist/src/cli/commands/notebook.d.ts +2 -0
  50. package/dist/src/cli/commands/notebook.js +242 -0
  51. package/dist/src/cli/commands/project-deployer.d.ts +2 -0
  52. package/dist/src/cli/commands/project-deployer.js +118 -0
  53. package/dist/src/cli/commands/project-library.d.ts +2 -0
  54. package/dist/src/cli/commands/project-library.js +197 -0
  55. package/dist/src/cli/commands/project.d.ts +2 -0
  56. package/dist/src/cli/commands/project.js +132 -0
  57. package/dist/src/cli/commands/recipe.d.ts +2 -0
  58. package/dist/src/cli/commands/recipe.js +632 -0
  59. package/dist/src/cli/commands/scenario.d.ts +2 -0
  60. package/dist/src/cli/commands/scenario.js +190 -0
  61. package/dist/src/cli/commands/sql.d.ts +2 -0
  62. package/dist/src/cli/commands/sql.js +109 -0
  63. package/dist/src/cli/commands/statistics.d.ts +2 -0
  64. package/dist/src/cli/commands/statistics.js +165 -0
  65. package/dist/src/cli/commands/streaming-endpoint.d.ts +2 -0
  66. package/dist/src/cli/commands/streaming-endpoint.js +50 -0
  67. package/dist/src/cli/commands/variable.d.ts +2 -0
  68. package/dist/src/cli/commands/variable.js +49 -0
  69. package/dist/src/cli/commands/webapp.d.ts +2 -0
  70. package/dist/src/cli/commands/webapp.js +67 -0
  71. package/dist/src/cli/commands/wiki.d.ts +2 -0
  72. package/dist/src/cli/commands/wiki.js +123 -0
  73. package/dist/src/cli/commands/workspace.d.ts +2 -0
  74. package/dist/src/cli/commands/workspace.js +68 -0
  75. package/dist/src/cli/contract.d.ts +104 -0
  76. package/dist/src/cli/contract.js +2031 -0
  77. package/dist/src/cli/doctor.d.ts +104 -0
  78. package/dist/src/cli/doctor.js +356 -0
  79. package/dist/src/cli/env.d.ts +2 -0
  80. package/dist/src/cli/env.js +37 -0
  81. package/dist/src/cli/flags.d.ts +16 -0
  82. package/dist/src/cli/flags.js +255 -0
  83. package/dist/src/cli/helpers/cleanup.d.ts +3 -0
  84. package/dist/src/cli/helpers/cleanup.js +158 -0
  85. package/dist/src/cli/helpers/dataset.d.ts +2 -0
  86. package/dist/src/cli/helpers/dataset.js +17 -0
  87. package/dist/src/cli/helpers/flow-zone.d.ts +69 -0
  88. package/dist/src/cli/helpers/flow-zone.js +420 -0
  89. package/dist/src/cli/helpers/recipe.d.ts +11 -0
  90. package/dist/src/cli/helpers/recipe.js +83 -0
  91. package/dist/src/cli/output.d.ts +38 -0
  92. package/dist/src/cli/output.js +159 -0
  93. package/dist/src/cli/runtime.d.ts +15 -0
  94. package/dist/src/cli/runtime.js +59 -0
  95. package/dist/src/cli/types.d.ts +25 -0
  96. package/dist/src/cli/types.js +1 -0
  97. package/dist/src/cli/usage.d.ts +16 -0
  98. package/dist/src/cli/usage.js +80 -0
  99. package/dist/src/cli/version.d.ts +14 -0
  100. package/dist/src/cli/version.js +63 -0
  101. package/dist/src/cli.js +671 -8254
  102. package/dist/src/client.d.ts +1 -1
  103. package/dist/src/client.js +14 -13
  104. package/dist/src/errors.d.ts +6 -0
  105. package/dist/src/errors.js +127 -4
  106. package/dist/src/index.d.ts +3 -3
  107. package/dist/src/index.js +2 -2
  108. package/dist/src/resources/applications.d.ts +1 -1
  109. package/dist/src/resources/applications.js +27 -1
  110. package/dist/src/resources/bundles.js +2 -2
  111. package/dist/src/resources/continuous-activities.js +1 -0
  112. package/dist/src/resources/data-quality.js +5 -3
  113. package/dist/src/resources/datasets.d.ts +3 -0
  114. package/dist/src/resources/datasets.js +3 -0
  115. package/dist/src/resources/flow-zones.d.ts +2 -2
  116. package/dist/src/resources/flow-zones.js +4 -1
  117. package/dist/src/resources/meanings.d.ts +2 -0
  118. package/dist/src/resources/meanings.js +4 -0
  119. package/dist/src/resources/notebooks.d.ts +5 -7
  120. package/dist/src/resources/notebooks.js +10 -7
  121. package/dist/src/resources/projects.d.ts +1 -1
  122. package/dist/src/resources/projects.js +2 -2
  123. package/dist/src/resources/recipes.d.ts +3 -3
  124. package/dist/src/resources/recipes.js +50 -7
  125. package/dist/src/resources/scenarios.js +67 -26
  126. package/dist/src/resources/statistics.js +9 -0
  127. package/dist/src/schemas.d.ts +2 -2
  128. package/dist/src/schemas.js +1 -1
  129. package/dist/src/skill.js +2 -2
  130. package/dist/src/utils/sanitize.js +2 -1
  131. package/package.json +1 -1
  132. package/packages/types/dist/index.d.ts +15 -2
  133. package/packages/types/dist/index.js +9 -1
@@ -0,0 +1,159 @@
1
+ import { DataikuError, } from "../errors.js";
2
+ let outputFieldProjection;
3
+ export function setOutputFieldProjection(fields) {
4
+ outputFieldProjection = fields;
5
+ }
6
+ /**
7
+ * Non-fatal diagnostics queued during a command and flushed to stderr as one
8
+ * JSON envelope, so agents get a loud, machine-parseable signal (e.g. truncated
9
+ * exports) without polluting the stdout result contract.
10
+ */
11
+ let pendingCliWarnings = [];
12
+ export function enqueueCliWarning(warning) {
13
+ pendingCliWarnings.push(warning);
14
+ }
15
+ /** Emit queued warnings as one JSONL warning event on stderr. Idempotent. */
16
+ function flushCliWarnings() {
17
+ if (pendingCliWarnings.length === 0)
18
+ return;
19
+ const warnings = pendingCliWarnings;
20
+ pendingCliWarnings = [];
21
+ process.stderr.write(`${JSON.stringify({ type: "warning", warnings, })}\n`);
22
+ }
23
+ function resolveFieldPath(source, field) {
24
+ let current = source;
25
+ for (const segment of field.split(".")) {
26
+ if (current === null || typeof current !== "object" || Array.isArray(current))
27
+ return null;
28
+ current = current[segment];
29
+ }
30
+ return current ?? null;
31
+ }
32
+ export function pickResultFields(item, fields) {
33
+ if (!item || typeof item !== "object" || Array.isArray(item))
34
+ return item;
35
+ const source = item;
36
+ const picked = {};
37
+ for (const field of fields)
38
+ picked[field] = resolveFieldPath(source, field);
39
+ return picked;
40
+ }
41
+ /**
42
+ * Project the top-level fields callers asked for via --fields. Arrays are mapped
43
+ * element-wise; scalars and string results pass through untouched. Requested keys
44
+ * that are absent become null so every row keeps a stable, predictable shape.
45
+ */
46
+ export function projectResultFields(result, fields) {
47
+ if (Array.isArray(result))
48
+ return result.map((item) => pickResultFields(item, fields));
49
+ return pickResultFields(result, fields);
50
+ }
51
+ export function writeCommandResult(result) {
52
+ flushCliWarnings();
53
+ const projected = outputFieldProjection
54
+ ? projectResultFields(result, outputFieldProjection)
55
+ : result;
56
+ process.stdout.write(`${JSON.stringify(projected ?? { ok: true, }, null, 2)}\n`);
57
+ }
58
+ export function transientBodyWithTargetContext(body, target, elapsedMs) {
59
+ try {
60
+ const parsed = JSON.parse(body);
61
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
62
+ const record = parsed;
63
+ const message = typeof record.message === "string" && record.message.length > 0
64
+ ? `Target: ${target}\nElapsed: ${elapsedMs}ms\n${record.message}`
65
+ : `Target: ${target}\nElapsed: ${elapsedMs}ms`;
66
+ return JSON.stringify({ ...record, message, target, elapsedMs, });
67
+ }
68
+ }
69
+ catch {
70
+ // Non-JSON DSS bodies are wrapped as text below.
71
+ }
72
+ return `Target: ${target}\nElapsed: ${elapsedMs}ms\n${body}`;
73
+ }
74
+ export function addTransientTargetContext(error, target, elapsedMs) {
75
+ if (error instanceof DataikuError && error.category === "transient") {
76
+ throw new DataikuError(error.status, error.statusText, transientBodyWithTargetContext(error.body, target, elapsedMs), error.retry, error.requestId);
77
+ }
78
+ throw error;
79
+ }
80
+ export function isFailedWaitResult(result) {
81
+ if (result === null || typeof result !== "object" || Array.isArray(result))
82
+ return false;
83
+ const record = result;
84
+ return record.success === false
85
+ && typeof record.elapsedMs === "number"
86
+ && typeof record.pollCount === "number"
87
+ && (typeof record.state === "string" || typeof record.outcome === "string");
88
+ }
89
+ export function commandFailureExitCode(result) {
90
+ if (isFailedWaitResult(result))
91
+ return 4;
92
+ if (result && typeof result === "object" && result.unchanged === false)
93
+ return 4;
94
+ return undefined;
95
+ }
96
+ export class CommandResultFailure extends Error {
97
+ result;
98
+ exitCode;
99
+ constructor(result, exitCode) {
100
+ super(commandFailureMessage(result));
101
+ this.name = "CommandResultFailure";
102
+ this.result = result;
103
+ this.exitCode = exitCode;
104
+ }
105
+ }
106
+ export function commandFailureMessage(result) {
107
+ if (isFailedWaitResult(result)) {
108
+ const record = result;
109
+ const state = typeof record.state === "string" ? record.state : record.outcome;
110
+ return `Command completed with failed long-running result${state ? `: ${state}` : ""}.`;
111
+ }
112
+ if (result && typeof result === "object" && result.unchanged === false) {
113
+ return "Command completed with failed assertion result.";
114
+ }
115
+ return "Command completed with failed result.";
116
+ }
117
+ export function isNotFoundError(error) {
118
+ if (error instanceof DataikuError)
119
+ return error.category === "not_found";
120
+ if (error instanceof Error)
121
+ return /not found|does not exist|unknown/i.test(error.message);
122
+ return false;
123
+ }
124
+ export async function readIfExists(reader) {
125
+ try {
126
+ return await reader();
127
+ }
128
+ catch (error) {
129
+ if (isNotFoundError(error))
130
+ return undefined;
131
+ throw error;
132
+ }
133
+ }
134
+ export function skipResult(resource, id, reason, extra = {}) {
135
+ return { skipped: id, reason, resource, ...extra, };
136
+ }
137
+ export function planResult(resource, action, options) {
138
+ return {
139
+ plan: true,
140
+ action,
141
+ resource,
142
+ ...(options.plannedAndDryRun ? { plannedAndDryRun: true, } : {}),
143
+ ...options.identifiers,
144
+ ...(options.method ? { method: options.method, } : {}),
145
+ ...(options.endpoint ? { endpoint: options.endpoint, } : {}),
146
+ ...(options.payload !== undefined ? { payload: options.payload, } : {}),
147
+ ...(options.localWrites !== undefined ? { localWrites: options.localWrites, } : {}),
148
+ ...(options.wait !== undefined ? { wait: options.wait, } : {}),
149
+ idempotency: options.idempotency,
150
+ async: options.asyncKind,
151
+ exitCodesOnFailure: options.exitCodesOnFailure,
152
+ };
153
+ }
154
+ export function encodedProjectEndpoint(client, projectKey, suffix) {
155
+ return `/public/api/projects/${encodeURIComponent(client.resolveProjectKey(projectKey))}${suffix}`;
156
+ }
157
+ export function encodedProjectEndpointForPlan(projectKey, suffix) {
158
+ return `/public/api/projects/${encodeURIComponent(projectKey)}${suffix}`;
159
+ }
@@ -0,0 +1,15 @@
1
+ import { type DssCredentials } from "../config.js";
2
+ export type TlsSettings = Pick<DssCredentials, "tlsRejectUnauthorized" | "caCertPath">;
3
+ export declare function resolveTlsSettings(flags: Record<string, string | boolean>, saved?: TlsSettings): TlsSettings;
4
+ export declare const currentCommandContext: {
5
+ resource?: string;
6
+ action?: string;
7
+ projectKey?: string;
8
+ };
9
+ export declare function resolveCredentials(flags: Record<string, string | boolean>): {
10
+ url: string;
11
+ apiKey: string;
12
+ projectKey?: string;
13
+ tlsRejectUnauthorized?: boolean;
14
+ caCertPath?: string;
15
+ };
@@ -0,0 +1,59 @@
1
+ import { loadCredentials, } from "../config.js";
2
+ import { dataikuEnvironmentEnabled, } from "./env.js";
3
+ function parseTlsRejectUnauthorizedEnv(value) {
4
+ if (value === undefined)
5
+ return undefined;
6
+ const normalized = value.trim().toLowerCase();
7
+ if (normalized === "0" || normalized === "false" || normalized === "no")
8
+ return false;
9
+ if (normalized === "1" || normalized === "true" || normalized === "yes")
10
+ return true;
11
+ return undefined;
12
+ }
13
+ export function resolveTlsSettings(flags, saved) {
14
+ let tlsRejectUnauthorized = flags["insecure"] === true ? false : undefined;
15
+ let caCertPath = flags["ca-cert"];
16
+ tlsRejectUnauthorized ??= parseTlsRejectUnauthorizedEnv(process.env.NODE_TLS_REJECT_UNAUTHORIZED);
17
+ caCertPath ??= process.env.NODE_EXTRA_CA_CERTS;
18
+ if (tlsRejectUnauthorized === undefined) {
19
+ tlsRejectUnauthorized = saved?.tlsRejectUnauthorized;
20
+ }
21
+ caCertPath ??= saved?.caCertPath;
22
+ return { tlsRejectUnauthorized, caCertPath, };
23
+ }
24
+ export const currentCommandContext = {};
25
+ // ---------------------------------------------------------------------------
26
+ // Credential resolution
27
+ // ---------------------------------------------------------------------------
28
+ export function resolveCredentials(flags) {
29
+ const hasUrlFlag = Object.hasOwn(flags, "url");
30
+ const hasApiKeyFlag = Object.hasOwn(flags, "api-key");
31
+ const hasProjectKeyFlag = Object.hasOwn(flags, "project-key");
32
+ let url = hasUrlFlag ? flags["url"] : undefined;
33
+ let apiKey = hasApiKeyFlag ? flags["api-key"] : undefined;
34
+ let projectKey = hasProjectKeyFlag ? flags["project-key"] : undefined;
35
+ const saved = loadCredentials();
36
+ const useEnv = dataikuEnvironmentEnabled();
37
+ if (useEnv) {
38
+ if (!hasUrlFlag)
39
+ url ??= process.env.DATAIKU_URL;
40
+ if (!hasApiKeyFlag)
41
+ apiKey ??= process.env.DATAIKU_API_KEY;
42
+ if (!hasProjectKeyFlag)
43
+ projectKey ??= process.env.DATAIKU_PROJECT_KEY;
44
+ }
45
+ if (saved) {
46
+ if (!hasUrlFlag)
47
+ url ??= saved.url;
48
+ if (!hasApiKeyFlag)
49
+ apiKey ??= saved.apiKey;
50
+ if (!hasProjectKeyFlag)
51
+ projectKey ??= saved.projectKey;
52
+ }
53
+ return {
54
+ url: url ?? "",
55
+ apiKey: apiKey ?? "",
56
+ projectKey,
57
+ ...resolveTlsSettings(flags, saved ?? undefined),
58
+ };
59
+ }
@@ -0,0 +1,25 @@
1
+ import type { DataikuClient } from "../client.js";
2
+ export type CommandHandler = (client: DataikuClient, args: string[], flags: Record<string, string | boolean>) => Promise<unknown>;
3
+ export interface CommandPayloadSchema {
4
+ stdin?: boolean;
5
+ dataFlag?: boolean;
6
+ dataFileFlag?: boolean;
7
+ jsonShape?: "object" | "array";
8
+ }
9
+ export interface CommandFlagChoice {
10
+ oneOf: string[][];
11
+ }
12
+ export interface CommandRegistryOverride {
13
+ requiredFlags?: string[];
14
+ requiredOneOf?: CommandFlagChoice[];
15
+ optionalFlags?: string[];
16
+ payloadSchema?: CommandPayloadSchema;
17
+ examplePayload?: unknown;
18
+ cleanupCommand?: string;
19
+ }
20
+ export interface CommandMeta extends CommandRegistryOverride {
21
+ handler: CommandHandler;
22
+ usage: string;
23
+ description?: string;
24
+ examples?: string[];
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { StableErrorCode } from "../errors.js";
2
+ export declare const RESOURCE_NAMES: string[];
3
+ export declare class UsageError extends Error {
4
+ readonly code: StableErrorCode;
5
+ readonly hint?: string;
6
+ readonly details?: Record<string, unknown>;
7
+ constructor(message: string, code?: StableErrorCode, hint?: string, details?: Record<string, unknown>);
8
+ }
9
+ export declare const COMMANDS_RUN_HINT = "Use `dss commands run` for machine-readable command discovery.";
10
+ export declare function unsupportedHelpFlag(): UsageError;
11
+ export declare function noCommandError(): UsageError;
12
+ export declare function missingActionError(resource: string, validActions: string[], usage?: string): UsageError;
13
+ export declare function unknownResourceError(resource: string): UsageError;
14
+ export declare function unknownActionError(resource: string, action: string | undefined, validActions: string[], hint?: string): UsageError;
15
+ export declare function requireArgs(args: string[], count: number, usage: string): void;
16
+ export declare function requireNoArgs(args: string[], usage: string): void;
@@ -0,0 +1,80 @@
1
+ export const RESOURCE_NAMES = [
2
+ "project",
3
+ "app",
4
+ "business-app",
5
+ "webapp",
6
+ "api-service",
7
+ "api-deployer",
8
+ "bundle",
9
+ "project-deployer",
10
+ "project-library",
11
+ "streaming-endpoint",
12
+ "continuous-activity",
13
+ "statistics",
14
+ "discussion",
15
+ "meaning",
16
+ "workspace",
17
+ "metrics",
18
+ "doctor",
19
+ "wiki",
20
+ "dashboard",
21
+ "insight",
22
+ "data-quality",
23
+ "future",
24
+ "flow-zone",
25
+ "dataset",
26
+ "recipe",
27
+ "job",
28
+ "scenario",
29
+ "folder",
30
+ "variable",
31
+ "connection",
32
+ "code-env",
33
+ "sql",
34
+ "code",
35
+ "notebook",
36
+ "auth",
37
+ "cleanup",
38
+ "commands",
39
+ "fixtures",
40
+ "install-skill",
41
+ ]
42
+ .sort();
43
+ export class UsageError extends Error {
44
+ code;
45
+ hint;
46
+ details;
47
+ constructor(message, code = "usage_error", hint, details) {
48
+ super(message);
49
+ this.name = "UsageError";
50
+ this.code = code;
51
+ this.hint = hint;
52
+ this.details = details;
53
+ }
54
+ }
55
+ export const COMMANDS_RUN_HINT = "Use `dss commands run` for machine-readable command discovery.";
56
+ export function unsupportedHelpFlag() {
57
+ return new UsageError("Help screens are not supported.", "usage_error", COMMANDS_RUN_HINT, { command: "dss commands run", });
58
+ }
59
+ export function noCommandError() {
60
+ return new UsageError("No command provided.", "usage_error", COMMANDS_RUN_HINT, { command: "dss commands run", resources: RESOURCE_NAMES, });
61
+ }
62
+ export function missingActionError(resource, validActions, usage) {
63
+ return new UsageError(`Missing action for ${resource}.`, "usage_error", usage ?? COMMANDS_RUN_HINT, { resource, validActions, });
64
+ }
65
+ export function unknownResourceError(resource) {
66
+ return new UsageError(`Unknown resource: ${resource}.`, "usage_error", COMMANDS_RUN_HINT, { resource, validResources: RESOURCE_NAMES, });
67
+ }
68
+ export function unknownActionError(resource, action, validActions, hint) {
69
+ return new UsageError(`Unknown action: ${resource} ${action ?? ""}`.trim(), "usage_error", hint ?? COMMANDS_RUN_HINT, { resource, action, validActions, });
70
+ }
71
+ export function requireArgs(args, count, usage) {
72
+ if (args.length < count) {
73
+ throw new UsageError(`Expected ${count} argument(s), got ${args.length}.\nUsage: ${usage}`, "missing_required_arg");
74
+ }
75
+ }
76
+ export function requireNoArgs(args, usage) {
77
+ if (args.length > 0) {
78
+ throw new UsageError(`Unexpected argument(s): ${args.join(" ")}.\nUsage: ${usage}`, "usage_error");
79
+ }
80
+ }
@@ -0,0 +1,14 @@
1
+ export declare function findPackageRoot(): string | undefined;
2
+ export declare function packageVersion(packageRoot: string | undefined): string;
3
+ export declare function gitDirectory(packageRoot: string): string;
4
+ export declare function gitRevision(packageRoot: string | undefined): string | undefined;
5
+ export declare const PACKAGE_ROOT: string | undefined;
6
+ export declare const CLI_VERSION: string;
7
+ export declare const CLI_GIT_REVISION: string | undefined;
8
+ export declare const AGENT_CONTRACT_VERSION = 1;
9
+ export declare const JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
10
+ export declare const AGENT_CONTRACT_SCHEMA_ID = "https://clssck.github.io/dataiku-sdk/schemas/agent-contract-v1.json";
11
+ export declare function cliVersionResult(): {
12
+ version: string;
13
+ gitRevision: string | null;
14
+ };
@@ -0,0 +1,63 @@
1
+ import { readFileSync, } from "node:fs";
2
+ import { dirname, resolve, } from "node:path";
3
+ import { fileURLToPath, } from "node:url";
4
+ export function findPackageRoot() {
5
+ let dir = dirname(fileURLToPath(import.meta.url));
6
+ for (let i = 0; i < 5; i++) {
7
+ try {
8
+ readFileSync(resolve(dir, "package.json"), "utf-8");
9
+ return dir;
10
+ }
11
+ catch {
12
+ dir = dirname(dir);
13
+ }
14
+ }
15
+ return undefined;
16
+ }
17
+ export function packageVersion(packageRoot) {
18
+ if (!packageRoot)
19
+ return "unknown";
20
+ try {
21
+ return JSON.parse(readFileSync(resolve(packageRoot, "package.json"), "utf-8")).version;
22
+ }
23
+ catch {
24
+ return "unknown";
25
+ }
26
+ }
27
+ export function gitDirectory(packageRoot) {
28
+ try {
29
+ const gitFile = readFileSync(resolve(packageRoot, ".git"), "utf-8").trim();
30
+ if (gitFile.startsWith("gitdir:")) {
31
+ return resolve(packageRoot, gitFile.slice("gitdir:".length).trim());
32
+ }
33
+ }
34
+ catch {
35
+ // Normal checkouts have a .git directory, not a .git file.
36
+ }
37
+ return resolve(packageRoot, ".git");
38
+ }
39
+ export function gitRevision(packageRoot) {
40
+ if (!packageRoot)
41
+ return undefined;
42
+ try {
43
+ const gitDir = gitDirectory(packageRoot);
44
+ const head = readFileSync(resolve(gitDir, "HEAD"), "utf-8").trim();
45
+ if (!head.startsWith("ref:"))
46
+ return head.slice(0, 7);
47
+ const ref = head.slice("ref:".length).trim();
48
+ const full = readFileSync(resolve(gitDir, ref), "utf-8").trim();
49
+ return full.slice(0, 7);
50
+ }
51
+ catch {
52
+ return undefined;
53
+ }
54
+ }
55
+ export const PACKAGE_ROOT = findPackageRoot();
56
+ export const CLI_VERSION = packageVersion(PACKAGE_ROOT);
57
+ export const CLI_GIT_REVISION = gitRevision(PACKAGE_ROOT);
58
+ export const AGENT_CONTRACT_VERSION = 1;
59
+ export const JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
60
+ export const AGENT_CONTRACT_SCHEMA_ID = "https://clssck.github.io/dataiku-sdk/schemas/agent-contract-v1.json";
61
+ export function cliVersionResult() {
62
+ return { version: CLI_VERSION, gitRevision: CLI_GIT_REVISION ?? null, };
63
+ }