proca 1.8.2 → 2.0.1

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 (55) hide show
  1. package/README.md +347 -195
  2. package/package.json +2 -1
  3. package/proca-cli +2 -2
  4. package/src/commands/action/add.mjs +131 -131
  5. package/src/commands/action/confirm.mjs +44 -44
  6. package/src/commands/action/count.mjs +41 -41
  7. package/src/commands/action/list.mjs +130 -130
  8. package/src/commands/action/replay.mjs +30 -30
  9. package/src/commands/action/requeue.mjs +110 -110
  10. package/src/commands/campaign/add.mjs +92 -83
  11. package/src/commands/campaign/copy.mjs +91 -0
  12. package/src/commands/campaign/delete.mjs +36 -56
  13. package/src/commands/campaign/get.mjs +5 -0
  14. package/src/commands/campaign/list.mjs +98 -111
  15. package/src/commands/campaign/queries.graphql +14 -14
  16. package/src/commands/campaign/status.mjs +39 -39
  17. package/src/commands/campaign/widget/archive.mjs +124 -0
  18. package/src/commands/campaign/widget/copy.mjs +175 -0
  19. package/src/commands/config/add.mjs +78 -78
  20. package/src/commands/config/folder.mjs +30 -30
  21. package/src/commands/config/server.mjs +15 -15
  22. package/src/commands/config/set.mjs +84 -84
  23. package/src/commands/config/user.mjs +50 -48
  24. package/src/commands/contact/area/count.mjs +38 -0
  25. package/src/commands/contact/count.mjs +0 -1
  26. package/src/commands/contact/list.mjs +128 -132
  27. package/src/commands/org/add.mjs +51 -51
  28. package/src/commands/org/crm.mjs +61 -61
  29. package/src/commands/org/delete.mjs +31 -31
  30. package/src/commands/org/email.mjs +94 -66
  31. package/src/commands/org/get.mjs +9 -1
  32. package/src/commands/service/add.mjs +59 -59
  33. package/src/commands/service/list.mjs +15 -15
  34. package/src/commands/target/add.mjs +52 -52
  35. package/src/commands/template/add.mjs +67 -67
  36. package/src/commands/template/list.mjs +33 -33
  37. package/src/commands/user/get.mjs +60 -60
  38. package/src/commands/user/invite.mjs +37 -37
  39. package/src/commands/user/join.mjs +51 -51
  40. package/src/commands/user/leave.mjs +47 -47
  41. package/src/commands/user/reset.mjs +72 -72
  42. package/src/commands/widget/add.mjs +61 -70
  43. package/src/commands/widget/delete.mjs +27 -27
  44. package/src/commands/widget/external/update.mjs +52 -0
  45. package/src/commands/widget/get.mjs +5 -0
  46. package/src/commands/widget/list.mjs +7 -5
  47. package/src/commands/widget/update.mjs +174 -0
  48. package/src/config.mjs +31 -31
  49. package/src/generated/schema.json +10675 -10675
  50. package/src/hooks/help.mjs +9 -9
  51. package/src/hooks/init.mjs +26 -26
  52. package/src/procaCommand.mjs +32 -9
  53. package/src/urql.mjs +39 -39
  54. package/src/util/twitter.mjs +19 -19
  55. package/theme.json +27 -27
@@ -1,14 +1,14 @@
1
1
  import { Config, Help } from "@oclif/core";
2
2
 
3
3
  export default class CustomHelp extends Help {
4
- showCommandHelp(command) {
5
- // console.log("This will be displayed in single-command CLIs");
6
- super.showCommandHelp(command);
7
- }
4
+ showCommandHelp(command) {
5
+ // console.log("This will be displayed in single-command CLIs");
6
+ super.showCommandHelp(command);
7
+ }
8
8
 
9
- async showHelp(argv) {
10
- // console.log('This will be displayed in multi-command CLIs')
11
- // Always include --all flag to show all commands
12
- await super.showHelp([...argv, "--all"]);
13
- }
9
+ async showHelp(argv) {
10
+ // console.log('This will be displayed in multi-command CLIs')
11
+ // Always include --all flag to show all commands
12
+ await super.showHelp([...argv, "--all"]);
13
+ }
14
14
  }
@@ -4,38 +4,38 @@ import { getFilename, load } from "#src/config.mjs";
4
4
  import CustomHelp from "./help.mjs";
5
5
 
6
6
  const getEnv = () => {
7
- const rawArgs = process.argv.slice(2);
8
- let envValue = undefined;
9
- // Manually check for --environment or -e
10
- rawArgs.findIndex((arg, envIndex) => {
11
- if (arg === "--env") {
12
- // || arg === '-e') {
13
- envValue = rawArgs[envIndex + 1]; // Next arg is the value
14
- return true;
15
- }
16
- if (arg.startsWith("--env=")) {
17
- envValue = arg.split("=")[1];
18
- return true;
19
- }
20
- });
7
+ const rawArgs = process.argv.slice(2);
8
+ let envValue = undefined;
9
+ // Manually check for --environment or -e
10
+ rawArgs.findIndex((arg, envIndex) => {
11
+ if (arg === "--env") {
12
+ // || arg === '-e') {
13
+ envValue = rawArgs[envIndex + 1]; // Next arg is the value
14
+ return true;
15
+ }
16
+ if (arg.startsWith("--env=")) {
17
+ envValue = arg.split("=")[1];
18
+ return true;
19
+ }
20
+ });
21
21
 
22
- // console.log(`Environment set to: ${envValue}`);
22
+ // console.log(`Environment set to: ${envValue}`);
23
23
 
24
- return envValue;
24
+ return envValue;
25
25
  };
26
26
 
27
27
  const hook = async (opts) => {
28
- const config = load(opts.config.configDir, getEnv());
29
- if (config) {
30
- opts.config.procaConfig = config;
31
- } else {
32
- const file = getFilename(opts.config.configDir);
33
- this.warn("missing config", file);
34
- }
28
+ const config = load(opts.config.configDir, getEnv());
29
+ if (config) {
30
+ opts.config.procaConfig = config;
31
+ } else {
32
+ const file = getFilename(opts.config.configDir);
33
+ this.warn("missing config", file);
34
+ }
35
35
 
36
- //console.log(opts);
37
- //console.log(opts.config.helpClass, CustomHelp);
38
- // opts.config.helpClass = CustomHelp;
36
+ //console.log(opts);
37
+ //console.log(opts.config.helpClass, CustomHelp);
38
+ // opts.config.helpClass = CustomHelp;
39
39
  };
40
40
 
41
41
  export default hook;
@@ -17,15 +17,10 @@ class ProcaCommand extends Command {
17
17
  default: "default",
18
18
  description: "allow to switch between configurations (server or users)",
19
19
  }),
20
- human: Flags.boolean({
21
- helpGroup: "OUTPUT", // Optional, groups it under a specific help section if desired
22
- description: "Format output to be read on screen by a human [default]",
23
- default: true,
24
- }),
25
20
  json: Flags.boolean({
26
21
  helpGroup: "OUTPUT", // Optional, groups it under a specific help section if desired
27
22
  description: "Format output as json",
28
- exclusive: ["human", "csv", "markdown"],
23
+ exclusive: ["csv", "markdown"],
29
24
  }),
30
25
  csv: Flags.boolean({
31
26
  description: "Format output as csv",
@@ -57,6 +52,14 @@ class ProcaCommand extends Command {
57
52
 
58
53
  static flagify(params = {}) {
59
54
  const flags = Object.assign({}, ProcaCommand.baseFlags);
55
+ if (params.name) {
56
+ flags.name = Flags.string({
57
+ char: "n",
58
+ charAliases: ["o"],
59
+ description: typeof params.name === "string" ? params.name : "name",
60
+ helpValue: "<the_short_name>",
61
+ });
62
+ }
60
63
  if (params.multiid) {
61
64
  flags.id = Flags.string({
62
65
  char: "i",
@@ -69,7 +72,6 @@ class ProcaCommand extends Command {
69
72
  });
70
73
  flags.name = Flags.string({
71
74
  char: "n",
72
- charAliases: ["o"],
73
75
  description: "name",
74
76
  helpValue: "<the_short_name>",
75
77
  });
@@ -79,6 +81,9 @@ class ProcaCommand extends Command {
79
81
 
80
82
  async parse() {
81
83
  const parsed = await super.parse();
84
+ if (this.ctor.args.id_name_dxid === undefined) {
85
+ return parsed;
86
+ }
82
87
  const maybe = parsed.args.id_name_dxid;
83
88
  if (maybe) {
84
89
  const d = dxid(maybe, false);
@@ -88,6 +93,17 @@ class ProcaCommand extends Command {
88
93
  if (parsed.flags.dxid) {
89
94
  parsed.flags.id = dxid(parsed.flags.dxid);
90
95
  }
96
+ const identified = [
97
+ parsed.flags.name,
98
+ parsed.flags.id,
99
+ parsed.flags.dxid,
100
+ ].filter(Boolean).length;
101
+
102
+ if (identified === 0) {
103
+ this.error("One of --name, --id, or --dxid is required");
104
+ }
105
+
106
+ await super.parse(); // check that either the first arg or the name/id/dxid are set
91
107
  return parsed;
92
108
  }
93
109
 
@@ -274,11 +290,15 @@ class ProcaCommand extends Command {
274
290
  this.log(Table.print(data, transformRow, print));
275
291
  }
276
292
 
277
- async output(data) {
293
+ single = (r) => {
294
+ this.table(r, null, null);
295
+ };
296
+
297
+ async output(data, { single = false } = {}) {
278
298
  if (this.format === "json") {
279
299
  if (this.flags.simplify)
280
300
  return data?.map(this.simplify) || this.simplify(data);
281
- const isDirectCall = process.argv.join(":").includes(this.id);
301
+ // const isDirectCall = process.argv.join(":").includes(this.id);
282
302
  return data;
283
303
  }
284
304
  if (this.format === "markdown") {
@@ -287,6 +307,9 @@ class ProcaCommand extends Command {
287
307
  if (this.format === "csv") {
288
308
  return this.csv(data);
289
309
  }
310
+ if (single === true) {
311
+ return this.single(data);
312
+ }
290
313
  return this.table(data);
291
314
  }
292
315
  }
package/src/urql.mjs CHANGED
@@ -1,60 +1,60 @@
1
1
  import { authExchange } from "@urql/exchange-auth";
2
2
  import {
3
- createClient as _createClient,
4
- cacheExchange,
5
- fetchExchange,
6
- gql,
3
+ createClient as _createClient,
4
+ cacheExchange,
5
+ fetchExchange,
6
+ gql,
7
7
  } from "urql";
8
8
 
9
9
  import { GraphQLError, formatError } from "graphql";
10
10
 
11
11
  export let client = {
12
- query: () => {
13
- throw new Error("urql graphql not initialised, call init first");
14
- },
12
+ query: () => {
13
+ throw new Error("urql graphql not initialised, call init first");
14
+ },
15
15
  };
16
16
 
17
17
  // Create a URQL client with your GraphQL API endpoint
18
18
  export const createClient = (config) => {
19
- if (!config) {
20
- console.error("config missing on createClient");
21
- }
22
- client = _createClient({
23
- url: config?.url || "https://api.proca.app/api",
24
- exchanges: [
25
- // cacheExchange, // Handles caching
26
- authExchange(async (utils) => {
27
- const token = config.token;
19
+ if (!config) {
20
+ console.error("config missing on createClient");
21
+ }
22
+ client = _createClient({
23
+ url: config?.url || "https://api.proca.app/api",
24
+ exchanges: [
25
+ // cacheExchange, // Handles caching
26
+ authExchange(async (utils) => {
27
+ const token = config.token;
28
28
 
29
- return {
30
- addAuthToOperation(operation) {
31
- if (!token) return operation;
32
- return utils.appendHeaders(operation, {
33
- Authorization: `Bearer ${token}`,
34
- });
35
- },
36
- };
37
- }),
38
- fetchExchange, // Handles fetching
39
- ],
40
- });
29
+ return {
30
+ addAuthToOperation(operation) {
31
+ if (!token) return operation;
32
+ return utils.appendHeaders(operation, {
33
+ Authorization: `Bearer ${token}`,
34
+ });
35
+ },
36
+ };
37
+ }),
38
+ fetchExchange, // Handles fetching
39
+ ],
40
+ });
41
41
  };
42
42
 
43
43
  export const query = async (query, payload) => {
44
- const result = await client.query(query, payload).toPromise();
45
- if (result.error) {
46
- //console.log(result.error);
47
- throw result.error;
48
- }
49
- return result.data;
44
+ const result = await client.query(query, payload).toPromise();
45
+ if (result.error) {
46
+ //console.log(result.error);
47
+ throw result.error;
48
+ }
49
+ return result.data;
50
50
  };
51
51
 
52
52
  export const mutation = async (mutation, payload) => {
53
- const result = await client.mutation(mutation, payload).toPromise();
54
- if (result.error) {
55
- throw result.error;
56
- }
57
- return result.data;
53
+ const result = await client.mutation(mutation, payload).toPromise();
54
+ if (result.error) {
55
+ throw result.error;
56
+ }
57
+ return result.data;
58
58
  };
59
59
 
60
60
  export { gql };
@@ -1,23 +1,23 @@
1
1
  export const getTwitter = async (org) => {
2
- const orgName = org.config.twitter?.screen_name || org.name;
3
- try {
4
- const res = await fetch(
5
- `https://twitter.proca.app/?screen_name=${orgName}`,
6
- );
2
+ const orgName = org.config.twitter?.screen_name || org.name;
3
+ try {
4
+ const res = await fetch(
5
+ `https://twitter.proca.app/?screen_name=${orgName}`,
6
+ );
7
7
 
8
- if (res.status >= 400) {
9
- throw new Error("Bad response from twitter.proca.app");
10
- }
8
+ if (res.status >= 400) {
9
+ throw new Error("Bad response from twitter.proca.app");
10
+ }
11
11
 
12
- const twitter = await res.json();
13
- twitter.picture = twitter.profile_image_url_https;
14
- twitter.profile_image_url_https = undefined;
15
- if (twitter) org.config.twitter = twitter;
16
- if (!org.config.description) org.config.description = twitter.description;
17
- if (!org.config.location) org.config.location = twitter.location;
18
- if (!org.config.url) org.config.url = twitter.url;
19
- if (!org.title) org.title = twitter.name;
20
- } catch (err) {
21
- console.error(err);
22
- }
12
+ const twitter = await res.json();
13
+ twitter.picture = twitter.profile_image_url_https;
14
+ twitter.profile_image_url_https = undefined;
15
+ if (twitter) org.config.twitter = twitter;
16
+ if (!org.config.description) org.config.description = twitter.description;
17
+ if (!org.config.location) org.config.location = twitter.location;
18
+ if (!org.config.url) org.config.url = twitter.url;
19
+ if (!org.title) org.title = twitter.name;
20
+ } catch (err) {
21
+ console.error(err);
22
+ }
23
23
  };
package/theme.json CHANGED
@@ -1,29 +1,29 @@
1
1
  {
2
- "info": "cyan",
3
- "warn": "#FFAB40",
4
- "error": "red",
5
- "bin": "block",
6
- "command": "cyan",
7
- "commandSummary": "black",
8
- "dollarSign": "white",
9
- "flag": "blackBright",
10
- "flagDefaultValue": "blue",
11
- "flagOptions": "white",
12
- "flagRequired": "red",
13
- "flagSeparator": "white",
14
- "json": {
15
- "brace": "magenta",
16
- "bracket": "magenta",
17
- "colon": "dim",
18
- "comma": "dim",
19
- "key": "yellow",
20
- "string": "green",
21
- "number": "green",
22
- "boolean": "green",
23
- "null": "red"
24
- },
25
- "sectionDescription": "blackBright",
26
- "sectionHeader": "underline",
27
- "topic": "cyan",
28
- "version": "white"
2
+ "info": "cyan",
3
+ "warn": "#FFAB40",
4
+ "error": "red",
5
+ "bin": "block",
6
+ "command": "cyan",
7
+ "commandSummary": "black",
8
+ "dollarSign": "white",
9
+ "flag": "blackBright",
10
+ "flagDefaultValue": "blue",
11
+ "flagOptions": "white",
12
+ "flagRequired": "red",
13
+ "flagSeparator": "white",
14
+ "json": {
15
+ "brace": "magenta",
16
+ "bracket": "magenta",
17
+ "colon": "dim",
18
+ "comma": "dim",
19
+ "key": "yellow",
20
+ "string": "green",
21
+ "number": "green",
22
+ "boolean": "green",
23
+ "null": "red"
24
+ },
25
+ "sectionDescription": "blackBright",
26
+ "sectionHeader": "underline",
27
+ "topic": "cyan",
28
+ "version": "white"
29
29
  }