guesty-cli 1.0.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 (47) hide show
  1. package/dist/auth.d.ts +2 -0
  2. package/dist/auth.js +156 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +46 -0
  5. package/dist/client.d.ts +7 -0
  6. package/dist/client.js +109 -0
  7. package/dist/commands/accounting.d.ts +2 -0
  8. package/dist/commands/accounting.js +102 -0
  9. package/dist/commands/calendar.d.ts +2 -0
  10. package/dist/commands/calendar.js +60 -0
  11. package/dist/commands/conversations.d.ts +2 -0
  12. package/dist/commands/conversations.js +40 -0
  13. package/dist/commands/financials.d.ts +2 -0
  14. package/dist/commands/financials.js +56 -0
  15. package/dist/commands/guests.d.ts +2 -0
  16. package/dist/commands/guests.js +57 -0
  17. package/dist/commands/init.d.ts +2 -0
  18. package/dist/commands/init.js +109 -0
  19. package/dist/commands/integrations.d.ts +2 -0
  20. package/dist/commands/integrations.js +62 -0
  21. package/dist/commands/listings.d.ts +2 -0
  22. package/dist/commands/listings.js +72 -0
  23. package/dist/commands/owners.d.ts +2 -0
  24. package/dist/commands/owners.js +76 -0
  25. package/dist/commands/properties.d.ts +2 -0
  26. package/dist/commands/properties.js +104 -0
  27. package/dist/commands/quotes.d.ts +2 -0
  28. package/dist/commands/quotes.js +31 -0
  29. package/dist/commands/raw.d.ts +2 -0
  30. package/dist/commands/raw.js +19 -0
  31. package/dist/commands/reservations.d.ts +2 -0
  32. package/dist/commands/reservations.js +126 -0
  33. package/dist/commands/reviews.d.ts +2 -0
  34. package/dist/commands/reviews.js +39 -0
  35. package/dist/commands/tasks.d.ts +2 -0
  36. package/dist/commands/tasks.js +60 -0
  37. package/dist/commands/users.d.ts +2 -0
  38. package/dist/commands/users.js +59 -0
  39. package/dist/commands/webhooks.d.ts +2 -0
  40. package/dist/commands/webhooks.js +52 -0
  41. package/dist/env.d.ts +1 -0
  42. package/dist/env.js +44 -0
  43. package/dist/output.d.ts +2 -0
  44. package/dist/output.js +22 -0
  45. package/dist/stdin.d.ts +1 -0
  46. package/dist/stdin.js +12 -0
  47. package/package.json +41 -0
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const tasks: Command;
@@ -0,0 +1,60 @@
1
+ import { Command } from "commander";
2
+ import { guestyFetch } from "../client.js";
3
+ import { print } from "../output.js";
4
+ import { readStdin } from "../stdin.js";
5
+ export const tasks = new Command("tasks")
6
+ .description("Manage tasks");
7
+ tasks
8
+ .command("list")
9
+ .description("List tasks")
10
+ .option("--status <status>", "Filter by status")
11
+ .option("--listing <id>", "Filter by listing ID")
12
+ .option("--limit <n>", "Max results", "25")
13
+ .option("--skip <n>", "Offset", "0")
14
+ .action(async (opts) => {
15
+ const params = {
16
+ limit: parseInt(opts.limit),
17
+ skip: parseInt(opts.skip),
18
+ };
19
+ if (opts.status)
20
+ params.status = opts.status;
21
+ if (opts.listing)
22
+ params.listingId = opts.listing;
23
+ const data = await guestyFetch("/v1/tasks-open-api/tasks", { params });
24
+ print(data);
25
+ });
26
+ tasks
27
+ .command("get <id>")
28
+ .description("Get a single task")
29
+ .action(async (id) => {
30
+ const data = await guestyFetch(`/v1/tasks-open-api/${id}`);
31
+ print(data);
32
+ });
33
+ tasks
34
+ .command("create")
35
+ .description("Create a task (--data or stdin)")
36
+ .option("--data <json>", "JSON body")
37
+ .action(async (opts) => {
38
+ const body = opts.data
39
+ ? JSON.parse(opts.data)
40
+ : JSON.parse(await readStdin());
41
+ const data = await guestyFetch("/v1/tasks-open-api/create-single-task", {
42
+ method: "POST",
43
+ body,
44
+ });
45
+ print(data);
46
+ });
47
+ tasks
48
+ .command("update <id>")
49
+ .description("Update a task (--data or stdin)")
50
+ .option("--data <json>", "JSON body")
51
+ .action(async (id, opts) => {
52
+ const body = opts.data
53
+ ? JSON.parse(opts.data)
54
+ : JSON.parse(await readStdin());
55
+ const data = await guestyFetch(`/v1/tasks-open-api/${id}`, {
56
+ method: "PUT",
57
+ body,
58
+ });
59
+ print(data);
60
+ });
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const users: Command;
@@ -0,0 +1,59 @@
1
+ import { Command } from "commander";
2
+ import { guestyFetch } from "../client.js";
3
+ import { print } from "../output.js";
4
+ import { readStdin } from "../stdin.js";
5
+ export const users = new Command("users")
6
+ .description("Manage users and roles");
7
+ users
8
+ .command("list")
9
+ .description("List all users")
10
+ .action(async () => {
11
+ const data = await guestyFetch("/v1/users");
12
+ print(data);
13
+ });
14
+ users
15
+ .command("get <id>")
16
+ .description("Get a user by ID")
17
+ .action(async (id) => {
18
+ const data = await guestyFetch(`/v1/users/${id}`);
19
+ print(data);
20
+ });
21
+ users
22
+ .command("create")
23
+ .description("Create a user (--data or stdin)")
24
+ .option("--data <json>", "JSON body")
25
+ .action(async (opts) => {
26
+ const body = opts.data ? JSON.parse(opts.data) : JSON.parse(await readStdin());
27
+ const data = await guestyFetch("/v1/users", { method: "POST", body });
28
+ print(data);
29
+ });
30
+ users
31
+ .command("update <id>")
32
+ .description("Update a user (--data or stdin)")
33
+ .option("--data <json>", "JSON body")
34
+ .action(async (id, opts) => {
35
+ const body = opts.data ? JSON.parse(opts.data) : JSON.parse(await readStdin());
36
+ const data = await guestyFetch(`/v1/users/${id}`, { method: "PUT", body });
37
+ print(data);
38
+ });
39
+ users
40
+ .command("delete <id>")
41
+ .description("Delete a user")
42
+ .action(async (id) => {
43
+ const data = await guestyFetch(`/v1/users/${id}`, { method: "DELETE" });
44
+ print(data);
45
+ });
46
+ users
47
+ .command("roles")
48
+ .description("Get available roles")
49
+ .action(async () => {
50
+ const data = await guestyFetch("/v1/roles");
51
+ print(data);
52
+ });
53
+ users
54
+ .command("account")
55
+ .description("Get current account details")
56
+ .action(async () => {
57
+ const data = await guestyFetch("/v1/accounts/me");
58
+ print(data);
59
+ });
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare const webhooks: Command;
@@ -0,0 +1,52 @@
1
+ import { Command } from "commander";
2
+ import { guestyFetch } from "../client.js";
3
+ import { print } from "../output.js";
4
+ import { readStdin } from "../stdin.js";
5
+ export const webhooks = new Command("webhooks")
6
+ .description("Manage webhooks");
7
+ webhooks
8
+ .command("list")
9
+ .description("List all webhooks")
10
+ .action(async () => {
11
+ const data = await guestyFetch("/v1/webhooks");
12
+ print(data);
13
+ });
14
+ webhooks
15
+ .command("get <id>")
16
+ .description("Get a webhook by ID")
17
+ .action(async (id) => {
18
+ const data = await guestyFetch(`/v1/webhooks/${id}`);
19
+ print(data);
20
+ });
21
+ webhooks
22
+ .command("create")
23
+ .description("Create a webhook (--data or stdin)")
24
+ .option("--data <json>", "JSON body")
25
+ .action(async (opts) => {
26
+ const body = opts.data ? JSON.parse(opts.data) : JSON.parse(await readStdin());
27
+ const data = await guestyFetch("/v1/webhooks", { method: "POST", body });
28
+ print(data);
29
+ });
30
+ webhooks
31
+ .command("update <id>")
32
+ .description("Update a webhook (--data or stdin)")
33
+ .option("--data <json>", "JSON body")
34
+ .action(async (id, opts) => {
35
+ const body = opts.data ? JSON.parse(opts.data) : JSON.parse(await readStdin());
36
+ const data = await guestyFetch(`/v1/webhooks/${id}`, { method: "PUT", body });
37
+ print(data);
38
+ });
39
+ webhooks
40
+ .command("delete <id>")
41
+ .description("Delete a webhook")
42
+ .action(async (id) => {
43
+ const data = await guestyFetch(`/v1/webhooks/${id}`, { method: "DELETE" });
44
+ print(data);
45
+ });
46
+ webhooks
47
+ .command("secret")
48
+ .description("Get webhook secret")
49
+ .action(async () => {
50
+ const data = await guestyFetch("/v1/webhooks-v2/secret");
51
+ print(data);
52
+ });
package/dist/env.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function loadEnv(): void;
package/dist/env.js ADDED
@@ -0,0 +1,44 @@
1
+ import { readFileSync, realpathSync } from "node:fs";
2
+ import { resolve, dirname } from "node:path";
3
+ import { homedir } from "node:os";
4
+ function getScriptEnvPath() {
5
+ try {
6
+ const real = realpathSync(process.argv[1]);
7
+ return resolve(dirname(real), "..", ".env");
8
+ }
9
+ catch {
10
+ return null;
11
+ }
12
+ }
13
+ export function loadEnv() {
14
+ const paths = [
15
+ resolve(homedir(), ".guesty-cli", ".env"),
16
+ getScriptEnvPath(),
17
+ resolve(process.cwd(), ".env"),
18
+ ].filter((p) => p !== null);
19
+ for (const envPath of paths) {
20
+ try {
21
+ const content = readFileSync(envPath, "utf8");
22
+ for (const line of content.split("\n")) {
23
+ const trimmed = line.trim();
24
+ if (!trimmed || trimmed.startsWith("#"))
25
+ continue;
26
+ const eqIdx = trimmed.indexOf("=");
27
+ if (eqIdx === -1)
28
+ continue;
29
+ const key = trimmed.slice(0, eqIdx).trim();
30
+ let val = trimmed.slice(eqIdx + 1).trim();
31
+ if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
32
+ val = val.slice(1, -1);
33
+ }
34
+ if (!process.env[key]) {
35
+ process.env[key] = val;
36
+ }
37
+ }
38
+ return;
39
+ }
40
+ catch {
41
+ continue;
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,2 @@
1
+ export declare function print(data: unknown): void;
2
+ export declare function printTable(rows: Record<string, unknown>[], columns?: string[]): void;
package/dist/output.js ADDED
@@ -0,0 +1,22 @@
1
+ export function print(data) {
2
+ if (data === undefined || data === null) {
3
+ process.stdout.write("null\n");
4
+ return;
5
+ }
6
+ process.stdout.write(JSON.stringify(data, null, 2) + "\n");
7
+ }
8
+ export function printTable(rows, columns) {
9
+ if (rows.length === 0) {
10
+ process.stdout.write("[]\n");
11
+ return;
12
+ }
13
+ const cols = columns ?? Object.keys(rows[0]);
14
+ const widths = cols.map((col) => Math.max(col.length, ...rows.map((r) => String(r[col] ?? "").length)));
15
+ const header = cols.map((c, i) => c.padEnd(widths[i])).join(" ");
16
+ const sep = widths.map((w) => "-".repeat(w)).join(" ");
17
+ process.stdout.write(`${header}\n${sep}\n`);
18
+ for (const row of rows) {
19
+ const line = cols.map((c, i) => String(row[c] ?? "").padEnd(widths[i])).join(" ");
20
+ process.stdout.write(`${line}\n`);
21
+ }
22
+ }
@@ -0,0 +1 @@
1
+ export declare function readStdin(): Promise<string>;
package/dist/stdin.js ADDED
@@ -0,0 +1,12 @@
1
+ export function readStdin() {
2
+ return new Promise((resolve, reject) => {
3
+ let data = "";
4
+ process.stdin.setEncoding("utf8");
5
+ process.stdin.on("data", (chunk) => (data += chunk));
6
+ process.stdin.on("end", () => resolve(data));
7
+ process.stdin.on("error", reject);
8
+ if (process.stdin.isTTY) {
9
+ reject(new Error("No data on stdin. Use --data or pipe JSON."));
10
+ }
11
+ });
12
+ }
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "guesty-cli",
3
+ "version": "1.0.0",
4
+ "description": "CLI for the Guesty property management API with built-in OAuth token caching and rate limiting",
5
+ "type": "module",
6
+ "bin": {
7
+ "guesty": "dist/cli.js"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "README.md"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsc",
15
+ "dev": "tsc --watch",
16
+ "link": "npm run build && npm link",
17
+ "prepublishOnly": "npm run build"
18
+ },
19
+ "keywords": [
20
+ "guesty",
21
+ "property-management",
22
+ "vacation-rental",
23
+ "cli",
24
+ "api"
25
+ ],
26
+ "license": "MIT",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/164investments/guesty-cli.git"
30
+ },
31
+ "engines": {
32
+ "node": ">=18"
33
+ },
34
+ "dependencies": {
35
+ "commander": "^13.0.0"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^22.0.0",
39
+ "typescript": "^5.7.0"
40
+ }
41
+ }