// GENERATED by genCli.ts import { getApiKey } from "../zygonApi"; import program from "../program"; const API_ENDPOINT = process.env.API_ENDPOINT ?? "https://api.zygon.tech"; program .command("users/delete") .description(`Updates a batch of users.`) .argument("ids", `A list of Collaborator ids.`) .action(async (ids) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { ids }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/users/delete", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("user/update") .description(`Updates a user.`) .argument("id", `Collaborator id.`) .option("--firstName ", `First name.`) .option( "--lastName ", `Last name. Full name will be firstName + " " + lastName.`, ) .option("--fullName ", `Full name.`) .option("--primaryEmail ", `Main email address.`) .option( "--role ", `Role on zygon. Authorized values are admin, standard, none, unknown.`, ) .option( "--contractEndDate ", `When is the contract of this user finished? Use at your discretion for customizing offboarding flows. Accepts null.`, ) .option( "--workEndDate ", `Use at your discretion for customizing offboarding flows. Accepts null.`, ) .option( "--contractStartDate ", `Use at your discretion for customizing onboarding flows. Accepts null.`, ) .option( "--visibility ", `Convenience flag to remove a user from the list without removing it from Zygon. Authorized values are visible, ignored.`, ) .option( "--status ", `(missing description). Authorized values are needsOnboarding, active, beingOffboarded, suspended, archived.`, ) .option("--custom ", `custom data field in JSON.`) .action(async (id, options) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values, TS isnt smart enough to guess the type of options Object.entries(options).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); // manages null values const required = { id }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/user/update", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("user/remove-labels") .description(``) .argument("userId", `Collaborator id.`) .argument("labelNames", `(missing description).`) .action(async (userId, labelNames) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { userId, labelNames }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/user/remove-labels", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("user/notify") .description(``) .argument("userIds", `A list of Collaborator ids.`) .argument("subject", `(missing description).`) .argument("message", `(missing description).`) .action(async (userIds, subject, message) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { userIds, subject, message }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/user/notify", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("user/get-by-view") .description(``) .argument("viewName", `(missing description).`) .action(async (viewName) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { viewName }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/user/get-by-view", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("user/get-by-label") .description(``) .argument("labelName", `(missing description).`) .action(async (labelName) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { labelName }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/user/get-by-label", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("user/get-by-id") .description(``) .argument("id", `Collaborator id.`) .action(async (id) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { id }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/user/get-by-id", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("user/delete") .description(`Updates a user.`) .argument("id", `Collaborator id.`) .action(async (id) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { id }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/user/delete", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("user/create") .description(`Creates a user.`) .argument("firstName", `First name.`) .argument( "lastName", `Last name. Full name will be firstName + " " + lastName.`, ) .argument("primaryEmail", `Main email address.`) .option( "--role ", `(missing description). Authorized values are admin, standard, none, unknown.`, ) .option( "--contractEndDate ", `When is the contract of this user finished? Use at your discretion for customizing offboarding flows.`, ) .option( "--workEndDate ", `Use at your discretion for customizing offboarding flows.`, ) .option( "--contractStartDate ", `Use at your discretion for customizing onboarding flows.`, ) .option( "--visibility ", `Convenience flag to remove a user from the list without removing it from Zygon. Authorized values are visible, ignored.`, ) .option( "--status ", `(missing description). Authorized values are needsOnboarding, active, beingOffboarded, suspended, archived.`, ) .action(async (firstName, lastName, primaryEmail, options) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values, TS isnt smart enough to guess the type of options Object.entries(options).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); // manages null values const required = { firstName, lastName, primaryEmail }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/user/create", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("user/add-labels") .description(``) .argument("userId", `Collaborator id.`) .argument("labelNames", `(missing description).`) .action(async (userId, labelNames) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { userId, labelNames }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/user/add-labels", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("user/activity") .description(`Logs activity for a user.`) .argument("url", `The url of the app the user is having activity on.`) .argument("timeSpent", `Time in seconds that this activity lasted.`) .option("--newNavigation ", `Is it the start of a new session?`) .action(async (url, timeSpent, options) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values, TS isnt smart enough to guess the type of options Object.entries(options).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); // manages null values const required = { url, timeSpent }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/user/activity", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("task/get-by-view") .description(``) .argument("viewName", `(missing description).`) .action(async (viewName) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { viewName }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/task/get-by-view", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("task/get-by-label") .description(``) .argument("labelName", `(missing description).`) .action(async (labelName) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { labelName }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/task/get-by-label", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("task/get-by-id") .description(``) .argument("id", `Todo id.`) .action(async (id) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { id }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/task/get-by-id", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("task/add-labels") .description(``) .argument("todoId", `Todo id.`) .argument("labelNames", `(missing description).`) .action(async (todoId, labelNames) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { todoId, labelNames }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/task/add-labels", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app/update-owners") .description(`Update the list of owners of the app`) .argument("appInstanceId", `AppInstance id.`) .argument("ownerIds", `A list of Collaborator ids.`) .action(async (appInstanceId, ownerIds) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { appInstanceId, ownerIds }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app/update-owners", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app/update") .description(`Updates an app.`) .argument("id", `AppInstance id.`) .option("--appId ", `App id.`) .option("--name ", `The name displayed on Zygon.`) .option("--appCategoryId ", `AppCategory id.`) .option( "--primaryDomain ", `The main domain among the list of domains.`, ) .option( "--domains ", `A list of domains, used for email and oauth shadow IT detection.`, ) .option( "--adminUrl ", `The Url that points to the list of active accounts on the app itself.`, ) .option( "--visibility ", `Convenience flag to hide an app from the default list. Authorized values are visible, ignored.`, ) .option("--notes ", `Arbitrary text for a note.`) .option("--scimUrl ", `The SCIM Url to use. Accepts null.`) .option("--scimToken ", `The SCIM BearerToken to use. Accepts null.`) .option("--oktaIds ", `List of Okta ids.`) .option( "--renewalDate ", `When the contract needs to be renewed. Accepts null.`, ) .option("--provisioningWorkflowId ", `Workflow id. Accepts null.`) .option("--deprovisioningWorkflowId ", `Workflow id. Accepts null.`) .action(async (id, options) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values, TS isnt smart enough to guess the type of options Object.entries(options).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); // manages null values const required = { id }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app/update", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app/remove-labels") .description(``) .argument("appId", `AppInstance id.`) .argument("labelNames", `(missing description).`) .action(async (appId, labelNames) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { appId, labelNames }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app/remove-labels", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app/instance/merge") .description(`Merges two apps instances one with another.`) .argument("toDeleteAppInstanceId", `AppInstance id.`) .argument("masterAppInstanceId", `AppInstance id.`) .action(async (toDeleteAppInstanceId, masterAppInstanceId) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { toDeleteAppInstanceId, masterAppInstanceId }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app/instance/merge", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app/get-owners") .description(``) .argument("appId", `AppInstance id.`) .action(async (appId) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { appId }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app/get-owners", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app/get-by-view") .description(``) .argument("viewName", `(missing description).`) .action(async (viewName) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { viewName }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app/get-by-view", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app/get-by-label") .description(``) .argument("labelName", `(missing description).`) .action(async (labelName) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { labelName }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app/get-by-label", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app/get-by-id") .description(``) .argument("id", `AppInstance id.`) .action(async (id) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { id }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app/get-by-id", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app/delete") .description(`Deletes an app.`) .argument("id", `AppInstance id.`) .action(async (id) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { id }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app/delete", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app/declare") .description(`Creates an app from a template.`) .option( "--appId ", `App template Id to be derived from. Accepts null.`, ) .argument("name", `The name of the new app.`) .action(async (name, options) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values, TS isnt smart enough to guess the type of options Object.entries(options).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); // manages null values const required = { name }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app/declare", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app/create") .description(`Creates an app from scratch.`) .argument("name", `The name displayed on Zygon.`) .option("--appCategoryId ", `AppCategory id.`) .option( "--primaryDomain ", `The main domain among the list of domains.`, ) .option( "--domains ", `A list of domains, used for email and oauth shadow IT detection.`, ) .option( "--adminUrl ", `The Url that points to the list of active accounts on the app itself.`, ) .option( "--visibility ", `Convenience flag to hide an app from the default list. Authorized values are visible, ignored.`, ) .option("--notes ", `Arbitrary text for a note.`) .option("--scimUrl ", `The SCIM Url to use.`) .option("--scimToken ", `The SCIM BearerToken to use.`) .option("--oktaIds ", `List of Okta ids.`) .option( "--renewalDate ", `When the contract needs to be renewed. Accepts null.`, ) .option("--appId ", `App id.`) .action(async (name, options) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values, TS isnt smart enough to guess the type of options Object.entries(options).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); // manages null values const required = { name }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app/create", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app/add-labels") .description(``) .argument("appId", `AppInstance id.`) .argument("labelNames", `(missing description).`) .action(async (appId, labelNames) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { appId, labelNames }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app/add-labels", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app-account/update") .description(`Updates an app account`) .argument("id", `Account id.`) .option( "--status ", `Status of the account. Authorized values are active, suspended, pendingActivation, pendingSuspension, unknown, notExisting.`, ) .option("--role ", `DEPRECATED.`) .option("--roleLabel ", `A role label.`) .option( "--deletedAt ", `Pass a non-null date to soft delete or null to restore entry. Accepts null.`, ) .option("--notes ", `Arbitrary text for a note. Accepts null.`) .action(async (id, options) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values, TS isnt smart enough to guess the type of options Object.entries(options).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); // manages null values const required = { id }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app-account/update", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app-account/remove-labels") .description(``) .argument("accountId", `AppAccount id.`) .argument("labelNames", `(missing description).`) .action(async (accountId, labelNames) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { accountId, labelNames }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch( API_ENDPOINT + "/app-account/remove-labels", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }, ); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app-account/get-by-view") .description(``) .argument("viewName", `(missing description).`) .action(async (viewName) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { viewName }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app-account/get-by-view", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app-account/get-by-label") .description(``) .argument("labelName", `(missing description).`) .action(async (labelName) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { labelName }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app-account/get-by-label", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app-account/get-by-id") .description(``) .argument("id", `AppAccount id.`) .action(async (id) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { id }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app-account/get-by-id", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app-account/delete-oauth-tokens") .description(`Deletes all the oauth tokens associated with an app account.`) .argument("id", `AppAccount id.`) .action(async (id) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { id }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch( API_ENDPOINT + "/app-account/delete-oauth-tokens", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }, ); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app-account/delete") .description(`Deletes an app account`) .argument("id", `AppAccount id.`) .action(async (id) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { id }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app-account/delete", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app-account/create") .description(`Creates an app account`) .argument("collaboratorId", `Collaborator id.`) .argument("appInstanceId", `AppInstance id.`) .option( "--status ", `(missing description). Authorized values are active, suspended, pendingActivation, pendingSuspension, unknown, notExisting.`, ) .option("--role ", `(missing description).`) .option( "--deletedAt ", `Pass a non-null date to soft delete or null to restore entry. Accepts null.`, ) .option( "--notes ", `Arbitrary notes for your own convenience. Accepts null.`, ) .action(async (collaboratorId, appInstanceId, options) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values, TS isnt smart enough to guess the type of options Object.entries(options).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); // manages null values const required = { collaboratorId, appInstanceId }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app-account/create", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } }); program .command("app-account/add-labels") .description(``) .argument("accountId", `AppAccount id.`) .argument("labelNames", `(missing description).`) .action(async (accountId, labelNames) => { try { const params: { [k: string]: string | null | undefined } = {}; // manages null values const required = { accountId, labelNames }; Object.entries(required).forEach(([key, value]) => { if (value.toLowerCase() === "null") params[key] = null; params[key] = value; }); const response = await fetch(API_ENDPOINT + "/app-account/add-labels", { method: "post", headers: { "Content-Type": "application/json", credentials: "include", mode: "cors", authorization: "Bearer " + getApiKey(), }, body: JSON.stringify(params), }); if (!response.ok) { throw new Error(await response.text()); } console.log(JSON.stringify(await response.json(), null, 2)); } catch (error: unknown) { console.error("Error:", (error as Error).message); process.exit(1); } });