@cronvello/sdk 0.3.0 → 0.4.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/README.md +42 -0
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/{dispatch-handler-B5b9iCyH.d.cts → dispatch-handler-yHIFEnNG.d.cts} +1 -1
- package/dist/{dispatch-handler-B5b9iCyH.d.ts → dispatch-handler-yHIFEnNG.d.ts} +1 -1
- package/dist/express.d.cts +1 -1
- package/dist/express.d.ts +1 -1
- package/dist/index.cjs +107 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +251 -3
- package/dist/index.d.ts +251 -3
- package/dist/index.js +107 -1
- package/dist/index.js.map +1 -1
- package/dist/next.d.cts +1 -1
- package/dist/next.d.ts +1 -1
- package/package.json +1 -1
|
@@ -562,4 +562,4 @@ interface DispatchHandler {
|
|
|
562
562
|
handle(req: DispatchRequest): Promise<DispatchResponse>;
|
|
563
563
|
}
|
|
564
564
|
|
|
565
|
-
export { type AccountTasksQuery as A, type
|
|
565
|
+
export { type AccountTasksQuery as A, type ReconcileTaskChange as B, type CronvelloAppConfig as C, type DispatchRequest as D, type ExecutionMode as E, type FetchLike as F, type RegistryReconcileChange as G, type HttpMethod as H, type RegistryTaskInput as I, type JobCreateBody as J, type RunStatus as K, type RunType as L, type MeResponse as M, type SuccessCriteria as N, type DispatchHandler as O, type PublicJob as P, type RunNowResult as R, type SyncOptions as S, Transport as T, type UsageResponse as U, type JobUpdateBody as a, type PublicTask as b, type TaskCreateBody as c, type TasksPage as d, type TaskUpdateBody as e, type RunsQuery as f, type RunsPage as g, type AccountRunsQuery as h, type PublicRun as i, type RegistryReconcileRequest as j, type RegistryReconcileResponse as k, type ResolvedJob as l, type ReconcileResult as m, type DispatchResponse as n, type Urgency as o, type CallbackStatus as p, type CronvelloHooks as q, type CronvelloJobConfig as r, type CronvelloJobConfigWithKey as s, type CronvelloJobContext as t, type CronvelloJobHandler as u, type CronvelloJobsInput as v, type CronvelloLogger as w, type CronvelloRunSource as x, type JobStatus as y, type Pagination as z };
|
|
@@ -562,4 +562,4 @@ interface DispatchHandler {
|
|
|
562
562
|
handle(req: DispatchRequest): Promise<DispatchResponse>;
|
|
563
563
|
}
|
|
564
564
|
|
|
565
|
-
export { type AccountTasksQuery as A, type
|
|
565
|
+
export { type AccountTasksQuery as A, type ReconcileTaskChange as B, type CronvelloAppConfig as C, type DispatchRequest as D, type ExecutionMode as E, type FetchLike as F, type RegistryReconcileChange as G, type HttpMethod as H, type RegistryTaskInput as I, type JobCreateBody as J, type RunStatus as K, type RunType as L, type MeResponse as M, type SuccessCriteria as N, type DispatchHandler as O, type PublicJob as P, type RunNowResult as R, type SyncOptions as S, Transport as T, type UsageResponse as U, type JobUpdateBody as a, type PublicTask as b, type TaskCreateBody as c, type TasksPage as d, type TaskUpdateBody as e, type RunsQuery as f, type RunsPage as g, type AccountRunsQuery as h, type PublicRun as i, type RegistryReconcileRequest as j, type RegistryReconcileResponse as k, type ResolvedJob as l, type ReconcileResult as m, type DispatchResponse as n, type Urgency as o, type CallbackStatus as p, type CronvelloHooks as q, type CronvelloJobConfig as r, type CronvelloJobConfigWithKey as s, type CronvelloJobContext as t, type CronvelloJobHandler as u, type CronvelloJobsInput as v, type CronvelloLogger as w, type CronvelloRunSource as x, type JobStatus as y, type Pagination as z };
|
package/dist/express.d.cts
CHANGED
package/dist/express.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1916,6 +1916,112 @@ function field(value, min, max, label) {
|
|
|
1916
1916
|
return value;
|
|
1917
1917
|
}
|
|
1918
1918
|
|
|
1919
|
+
// src/client/admin-client.ts
|
|
1920
|
+
var CronvelloAdminClient = class {
|
|
1921
|
+
transport;
|
|
1922
|
+
/** The resolved base URL in use. */
|
|
1923
|
+
baseUrl;
|
|
1924
|
+
/** Registration, status, key rotation and removal of external apps. */
|
|
1925
|
+
externalApps;
|
|
1926
|
+
constructor(options) {
|
|
1927
|
+
if (!options || !options.serviceKey) {
|
|
1928
|
+
throw new CronvelloConfigError(
|
|
1929
|
+
"CronvelloAdminClient requires a `serviceKey` (Cronvello's backend-to-backend key, not an account apiKey)."
|
|
1930
|
+
);
|
|
1931
|
+
}
|
|
1932
|
+
this.baseUrl = (options.baseUrl ?? CRONVELLO_DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
1933
|
+
this.transport = new Transport({
|
|
1934
|
+
baseUrl: this.baseUrl,
|
|
1935
|
+
apiKey: options.serviceKey,
|
|
1936
|
+
...options.timeoutMs !== void 0 ? { timeoutMs: options.timeoutMs } : {},
|
|
1937
|
+
...options.maxRetries !== void 0 ? { maxRetries: options.maxRetries } : {},
|
|
1938
|
+
...options.fetch ? { fetch: options.fetch } : {},
|
|
1939
|
+
...options.onRequest ? { onRequest: options.onRequest } : {}
|
|
1940
|
+
});
|
|
1941
|
+
this.externalApps = new ExternalAppsResource(this.transport);
|
|
1942
|
+
}
|
|
1943
|
+
};
|
|
1944
|
+
var ExternalAppsResource = class {
|
|
1945
|
+
constructor(t) {
|
|
1946
|
+
this.t = t;
|
|
1947
|
+
}
|
|
1948
|
+
t;
|
|
1949
|
+
/**
|
|
1950
|
+
* Idempotent upsert, keyed on the string `appId`: creates when unknown, updates credentials
|
|
1951
|
+
* and URL when it already exists. Safe to retry and to re-run on every provisioning pass.
|
|
1952
|
+
*
|
|
1953
|
+
* When the server mints the token (`generateApiKey: true` on a *new* app) it comes back as
|
|
1954
|
+
* `generatedApiKey` — plaintext, exactly once. On an update it is `null`.
|
|
1955
|
+
*/
|
|
1956
|
+
register(input) {
|
|
1957
|
+
assertRegisterInput(input);
|
|
1958
|
+
return this.t.request({ method: "POST", path: "/external-apps/service/register", body: input });
|
|
1959
|
+
}
|
|
1960
|
+
/** Registration status, last-sync info and job count for one app, by its string `appId`. */
|
|
1961
|
+
status(appId) {
|
|
1962
|
+
assertAppId(appId, "status");
|
|
1963
|
+
return this.t.request({ method: "GET", path: `/external-apps/service/status/${enc2(appId)}` });
|
|
1964
|
+
}
|
|
1965
|
+
/**
|
|
1966
|
+
* Mint a fresh per-app token, by string `appId`. The new token is returned once as `newApiKey`
|
|
1967
|
+
* and must be written into the app's environment — the previous one stops working.
|
|
1968
|
+
*
|
|
1969
|
+
* Use this for drift recovery when the current token is no longer known.
|
|
1970
|
+
*/
|
|
1971
|
+
rotateKey(appId) {
|
|
1972
|
+
assertAppId(appId, "rotateKey");
|
|
1973
|
+
return this.t.request({ method: "POST", path: `/external-apps/service/rotate-key/${enc2(appId)}` });
|
|
1974
|
+
}
|
|
1975
|
+
/**
|
|
1976
|
+
* Delete a registration, cascading its jobs and tasks.
|
|
1977
|
+
*
|
|
1978
|
+
* ⚠ This one takes the **numeric** {@link ExternalApp.id}, not the string `appId` the other
|
|
1979
|
+
* three methods take — an asymmetry in the server's route contract. Read the id off a
|
|
1980
|
+
* `register()` result (or a prior lookup); passing a string `appId` here is rejected locally.
|
|
1981
|
+
*/
|
|
1982
|
+
delete(id) {
|
|
1983
|
+
if (!Number.isInteger(id) || id <= 0) {
|
|
1984
|
+
throw new CronvelloConfigError(
|
|
1985
|
+
`externalApps.delete() takes the numeric app id (ExternalApp.id), not the string appId \u2014 received ${JSON.stringify(id)}.`
|
|
1986
|
+
);
|
|
1987
|
+
}
|
|
1988
|
+
return this.t.request({ method: "DELETE", path: `/external-apps/service/delete/${id}` });
|
|
1989
|
+
}
|
|
1990
|
+
};
|
|
1991
|
+
function assertRegisterInput(input) {
|
|
1992
|
+
if (!input || typeof input !== "object") {
|
|
1993
|
+
throw new CronvelloConfigError("externalApps.register() requires an input object.");
|
|
1994
|
+
}
|
|
1995
|
+
if (!input.appId || !input.appId.trim()) {
|
|
1996
|
+
throw new CronvelloConfigError("externalApps.register() requires a non-empty `appId`.");
|
|
1997
|
+
}
|
|
1998
|
+
if (!input.name || !input.name.trim()) {
|
|
1999
|
+
throw new CronvelloConfigError("externalApps.register() requires a non-empty `name`.");
|
|
2000
|
+
}
|
|
2001
|
+
if (!input.base_url && input.targetUrl === void 0) {
|
|
2002
|
+
throw new CronvelloConfigError("externalApps.register() requires either `base_url` or `targetUrl`.");
|
|
2003
|
+
}
|
|
2004
|
+
const authMethod = input.authMethod ?? (input.oauthClientId || input.oauthClientSecret ? "oauth" : "api_key");
|
|
2005
|
+
if (authMethod === "api_key" && !input.apiKey && !input.generateApiKey) {
|
|
2006
|
+
throw new CronvelloConfigError(
|
|
2007
|
+
"externalApps.register() with api_key auth requires either `apiKey` or `generateApiKey: true`."
|
|
2008
|
+
);
|
|
2009
|
+
}
|
|
2010
|
+
if (authMethod === "oauth" && (!input.oauthClientId || !input.oauthClientSecret)) {
|
|
2011
|
+
throw new CronvelloConfigError(
|
|
2012
|
+
"externalApps.register() with oauth auth requires both `oauthClientId` and `oauthClientSecret`."
|
|
2013
|
+
);
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
function assertAppId(appId, method) {
|
|
2017
|
+
if (typeof appId !== "string" || !appId.trim()) {
|
|
2018
|
+
throw new CronvelloConfigError(`externalApps.${method}() requires a non-empty string appId.`);
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
function enc2(segment) {
|
|
2022
|
+
return encodeURIComponent(segment);
|
|
2023
|
+
}
|
|
2024
|
+
|
|
1919
2025
|
// src/index.ts
|
|
1920
2026
|
function generateDispatchSecret(bytes = 32) {
|
|
1921
2027
|
const buf = new Uint8Array(bytes);
|
|
@@ -1924,6 +2030,7 @@ function generateDispatchSecret(bytes = 32) {
|
|
|
1924
2030
|
}
|
|
1925
2031
|
|
|
1926
2032
|
exports.CRONVELLO_DEFAULT_BASE_URL = CRONVELLO_DEFAULT_BASE_URL;
|
|
2033
|
+
exports.CronvelloAdminClient = CronvelloAdminClient;
|
|
1927
2034
|
exports.CronvelloApiError = CronvelloApiError;
|
|
1928
2035
|
exports.CronvelloClient = CronvelloClient;
|
|
1929
2036
|
exports.CronvelloConfigError = CronvelloConfigError;
|