proca 2.0.1 → 2.1.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 CHANGED
@@ -107,11 +107,12 @@ you should also use the local proca-api in your [widget generator](https://githu
107
107
  * [`proca user whoami`](#proca-user-whoami)
108
108
  * [`proca widget add`](#proca-widget-add)
109
109
  * [`proca widget delete`](#proca-widget-delete)
110
- * [`proca widget external update`](#proca-widget-external-update)
111
110
  * [`proca widget get`](#proca-widget-get)
112
111
  * [`proca widget list`](#proca-widget-list)
113
112
  * [`proca widget rebuild`](#proca-widget-rebuild)
114
113
  * [`proca widget update`](#proca-widget-update)
114
+ * [`proca widget update external`](#proca-widget-update-external)
115
+ * [`proca widget update name`](#proca-widget-update-name)
115
116
 
116
117
  ## `proca action add`
117
118
 
@@ -1860,35 +1861,6 @@ DESCRIPTION
1860
1861
  Delete a widget
1861
1862
  ```
1862
1863
 
1863
- ## `proca widget external update`
1864
-
1865
- Update the global counter to add the actions collected elsewhere
1866
-
1867
- ```
1868
- USAGE
1869
- $ proca widget external update [ID_NAME_DXID] -t <value> [--json | --csv | --markdown] [--env
1870
- <value>] [--simplify] [-i <value> | -n <the_short_name> | -x <value>]
1871
-
1872
- FLAGS
1873
- -i, --id=<value>
1874
- -n, --name=<the_short_name> name
1875
- -t, --total=<value> (required) new total to include
1876
- -x, --dxid=<value> dxid
1877
- --env=<value> [default: default] allow to switch between configurations (server or users)
1878
-
1879
- OUTPUT FLAGS
1880
- --csv Format output as csv
1881
- --json Format output as json
1882
- --markdown Format output as markdown table
1883
- --[no-]simplify flatten and filter to output only the most important attributes, mostly relevant for json
1884
-
1885
- DESCRIPTION
1886
- Update the global counter to add the actions collected elsewhere
1887
-
1888
- EXAMPLES
1889
- see also proca contact count
1890
- ```
1891
-
1892
1864
  ## `proca widget get`
1893
1865
 
1894
1866
  view a widget
@@ -1984,14 +1956,13 @@ Update a widget's properties
1984
1956
  ```
1985
1957
  USAGE
1986
1958
  $ proca widget update [ID_NAME_DXID] [--json | --csv | --markdown] [--env <value>]
1987
- [--simplify] [-i <value> | -n <the_short_name> | -x <value>] [-n <widget name>] [-l <locale>] [--color <hex code>]
1988
- [--confirm-optin] [--confirm-action] [--dry-run]
1959
+ [--simplify] [-i <value> | -n <the_short_name> | -x <value>] [-l <locale>] [--color <hex code>] [--confirm-optin]
1960
+ [--confirm-action] [--dry-run]
1989
1961
 
1990
1962
  FLAGS
1991
1963
  -i, --id=<value>
1992
1964
  -l, --locale=<locale> change the locale
1993
1965
  -n, --name=<the_short_name> name
1994
- -n, --rename=<widget name> new name for the widget
1995
1966
  -x, --dxid=<value> dxid
1996
1967
  --color=<hex code> update color (not yet implemented)
1997
1968
  --confirm-action add actionConfirm (check email snack) to consent.email component
@@ -2009,12 +1980,70 @@ DESCRIPTION
2009
1980
  Update a widget's properties
2010
1981
 
2011
1982
  EXAMPLES
2012
- $ proca widget update 4454 --name new_widget_name
1983
+ $ proca widget update -i 42 --rename campaign/new_name
1984
+
1985
+ $ proca widget update -name campaign/widget --locale fr
1986
+
1987
+ $ proca widget update 42 --confirm-optin
1988
+
1989
+ $ proca widget update --dxid=pnc -confirm-optin --dry-run
1990
+ ```
1991
+
1992
+ ## `proca widget update external`
1993
+
1994
+ Update the global counter to add the actions collected elsewhere
1995
+
1996
+ ```
1997
+ USAGE
1998
+ $ proca widget update external [ID_NAME_DXID] -t <value> [--json | --csv | --markdown] [--env
1999
+ <value>] [--simplify] [-i <value> | -n <the_short_name> | -x <value>]
2000
+
2001
+ FLAGS
2002
+ -i, --id=<value>
2003
+ -n, --name=<the_short_name> name
2004
+ -t, --total=<value> (required) new total to include
2005
+ -x, --dxid=<value> dxid
2006
+ --env=<value> [default: default] allow to switch between configurations (server or users)
2007
+
2008
+ OUTPUT FLAGS
2009
+ --csv Format output as csv
2010
+ --json Format output as json
2011
+ --markdown Format output as markdown table
2012
+ --[no-]simplify flatten and filter to output only the most important attributes, mostly relevant for json
2013
+
2014
+ DESCRIPTION
2015
+ Update the global counter to add the actions collected elsewhere
2016
+
2017
+ EXAMPLES
2018
+ see also proca contact count
2019
+ ```
2020
+
2021
+ ## `proca widget update name`
2022
+
2023
+ Update the name of a widget
2013
2024
 
2014
- $ proca widget update 4454 --locale fr
2025
+ ```
2026
+ USAGE
2027
+ $ proca widget update name [ID_NAME_DXID] [--json | --csv | --markdown] [--env <value>]
2028
+ [--simplify] [-i <value> | -n <the_short_name> | -x <value>] [--rename <widget name>]
2015
2029
 
2016
- $ proca widget update 4454 --confirm-optin
2030
+ FLAGS
2031
+ -i, --id=<value>
2032
+ -n, --name=<the_short_name> name
2033
+ -x, --dxid=<value> dxid
2034
+ --env=<value> [default: default] allow to switch between configurations (server or users)
2035
+ --rename=<widget name> new name for the widget
2017
2036
 
2018
- $ proca widget update 4454 --confirm-optin --dry-run
2037
+ OUTPUT FLAGS
2038
+ --csv Format output as csv
2039
+ --json Format output as json
2040
+ --markdown Format output as markdown table
2041
+ --[no-]simplify flatten and filter to output only the most important attributes, mostly relevant for json
2042
+
2043
+ DESCRIPTION
2044
+ Update the name of a widget
2045
+
2046
+ EXAMPLES
2047
+ see also proca widget update name --name=campaign/old_name --rename=campaign/new_name
2019
2048
  ```
2020
2049
  <!-- commandsstop -->
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "proca",
3
3
  "description": "Access the proca api",
4
- "version": "2.0.1",
4
+ "version": "2.1.0",
5
5
  "author": "Xavier",
6
6
  "bin": {
7
7
  "proca": "proca-cli"
@@ -0,0 +1,28 @@
1
+ import { Flags } from "@oclif/core";
2
+ import { getWidget } from "#src/commands/widget/get.mjs";
3
+ import UpdateCommand from "#src/commands/widget/update.mjs";
4
+
5
+ export default class CounterUpdate extends UpdateCommand {
6
+ static description = "Update the name of a widget";
7
+
8
+ static examples = [
9
+ "see also <%= config.bin %> widget update name --name=campaign/old_name --rename=campaign/new_name",
10
+ ];
11
+ static args = this.multiid();
12
+
13
+ static flags = {
14
+ ...this.flagify({ multiid: true }),
15
+ rename: Flags.string({
16
+ description: "new name for the widget",
17
+ helpValue: "<widget name>",
18
+ }),
19
+ };
20
+
21
+ async run() {
22
+ const { flags } = await this.parse();
23
+ const widget = await getWidget(flags);
24
+
25
+ const updated = await this.update(widget.id, { name: flags.rename });
26
+ return this.output(updated, { single: true });
27
+ }
28
+ }
@@ -1,6 +1,6 @@
1
1
  import { Args, Flags } from "@oclif/core";
2
2
  import { merge } from "merge-anything";
3
- import WidgetGet from "#src/commands/widget/get.mjs";
3
+ import { getWidget } from "#src/commands/widget/get.mjs";
4
4
  import Command from "#src/procaCommand.mjs";
5
5
  import { gql, mutation } from "#src/urql.mjs";
6
6
 
@@ -8,10 +8,10 @@ export default class WidgetUpdate extends Command {
8
8
  static description = "Update a widget's properties";
9
9
 
10
10
  static examples = [
11
- "<%= config.bin %> <%= command.id %> 4454 --name new_widget_name",
12
- "<%= config.bin %> <%= command.id %> 4454 --locale fr",
13
- "<%= config.bin %> <%= command.id %> 4454 --confirm-optin",
14
- "<%= config.bin %> <%= command.id %> 4454 --confirm-optin --dry-run",
11
+ "<%= config.bin %> <%= command.id %> -i 42 --rename campaign/new_name",
12
+ "<%= config.bin %> <%= command.id %> -name campaign/widget --locale fr",
13
+ "<%= config.bin %> <%= command.id %> 42 --confirm-optin",
14
+ "<%= config.bin %> <%= command.id %> --dxid=pnc -confirm-optin --dry-run",
15
15
  ];
16
16
 
17
17
  static args = this.multiid();
@@ -20,7 +20,7 @@ export default class WidgetUpdate extends Command {
20
20
  // flag with no value (-f, --force)
21
21
  ...this.flagify({ multiid: true }),
22
22
  rename: Flags.string({
23
- char: "n",
23
+ hidden: true, // use proca widget update name instead
24
24
  description: "new name for the widget",
25
25
  helpValue: "<widget name>",
26
26
  }),
@@ -53,13 +53,7 @@ export default class WidgetUpdate extends Command {
53
53
  }),
54
54
  };
55
55
 
56
- fetchWidget = async (params) => {
57
- const widgetGet = new WidgetGet([], this.config);
58
- return widgetGet.fetch(params);
59
- };
60
-
61
56
  update = async (widgetId, input) => {
62
- console.log("Updating widget with input:", input);
63
57
  const Document = gql`
64
58
  mutation UpdateActionPage($id: Int!, $input: ActionPageInput!) {
65
59
  updateActionPage(id: $id, input: $input) {
@@ -98,6 +92,7 @@ export default class WidgetUpdate extends Command {
98
92
  const { flags } = await this.parse();
99
93
  const {
100
94
  id,
95
+ name,
101
96
  rename,
102
97
  locale,
103
98
  color,
@@ -107,7 +102,7 @@ export default class WidgetUpdate extends Command {
107
102
  } = flags;
108
103
 
109
104
  // Fetch current widget
110
- const widget = await this.fetchWidget({ id });
105
+ const widget = await getWidget({ id, name });
111
106
 
112
107
  if (!widget) {
113
108
  this.error("Widget not found");
@@ -115,7 +110,7 @@ export default class WidgetUpdate extends Command {
115
110
 
116
111
  // Validate name
117
112
  if (rename) {
118
- const nameParts = renname.split("/");
113
+ const nameParts = rename.split("/");
119
114
  if (nameParts.length < 2) {
120
115
  this.error(
121
116
  "Widget name must follow format: campaign_name/org_name or campaign_name/locale or campaign_name/org_name/locale",
@@ -124,8 +119,8 @@ export default class WidgetUpdate extends Command {
124
119
  }
125
120
 
126
121
  const input = {
127
- name: rename ?? widget.name,
128
- locale: locale ?? widget.locale,
122
+ name: rename ?? rename,
123
+ locale: locale ?? locale,
129
124
  };
130
125
 
131
126
  if (color) {
@@ -115,7 +115,7 @@ class ProcaCommand extends Command {
115
115
  };
116
116
  async init() {
117
117
  await super.init();
118
- const { argv, flags } = await this.parse();
118
+ const { flags } = await this.parse();
119
119
  this.flags = flags;
120
120
  if (flags.json) this.format = "json";
121
121
  if (flags.csv) this.format = "csv";
@@ -128,14 +128,29 @@ class ProcaCommand extends Command {
128
128
  createClient(this.procaConfig);
129
129
  }
130
130
 
131
- async _catch(err) {
132
- // Check if the error was caused by a missing flag or wrong argument format
133
- console.log("aaa", err);
134
- try {
135
- this.error(err.toString());
136
- } catch (e) {
137
- console.log(e);
131
+ async catch(err) {
132
+ const entity = this.id.split(":")[0];
133
+ if (err.graphQLErrors && err.graphQLErrors.length > 0) {
134
+ err.graphQLErrors.forEach((graphqlErr) => {
135
+ if (graphqlErr.extensions) {
136
+ const code = graphqlErr.extensions.code;
137
+ if (code === "not_found") {
138
+ this.error(`${entity} not found`, { exit: 1 });
139
+ }
140
+ }
141
+ });
142
+ }
143
+
144
+ if (err.networkError) {
145
+ this.info("Looks like there’s a problem with your internet connection");
146
+ this.error(err.networkError.cause, { exit: err.exitCode || 1 });
147
+ }
148
+ if (err instanceof SyntaxError) {
149
+ this.error(`Syntax error: ${err.message}`, { exit: 1 });
138
150
  }
151
+
152
+ // Default error handling
153
+ this.error(err.message, { exit: err.exitCode || 1 });
139
154
  }
140
155
 
141
156
  flatten = (obj, prefix = "", result = {}) => {
@@ -192,7 +207,7 @@ class ProcaCommand extends Command {
192
207
  }
193
208
 
194
209
  error(msg, options = {}) {
195
- const colouredMessage = ux.colorize(this.config.theme.error, msg);
210
+ const colouredMessage = `❌ ${ux.colorize(this.config.theme.error, msg)}`;
196
211
  super.error(colouredMessage, options);
197
212
  }
198
213
 
package/src/urql.mjs CHANGED
@@ -43,7 +43,6 @@ export const createClient = (config) => {
43
43
  export const query = async (query, payload) => {
44
44
  const result = await client.query(query, payload).toPromise();
45
45
  if (result.error) {
46
- //console.log(result.error);
47
46
  throw result.error;
48
47
  }
49
48
  return result.data;
@@ -52,6 +51,7 @@ export const query = async (query, payload) => {
52
51
  export const mutation = async (mutation, payload) => {
53
52
  const result = await client.mutation(mutation, payload).toPromise();
54
53
  if (result.error) {
54
+ console.log("error", result.error);
55
55
  throw result.error;
56
56
  }
57
57
  return result.data;