proca 2.0.1 → 2.1.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.
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,68 @@ 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 -name campaign/widget --locale fr
2013
1984
 
2014
- $ proca widget update 4454 --locale fr
1985
+ $ proca widget update 42 --confirm-optin
1986
+
1987
+ $ proca widget update --dxid=pnc -confirm-optin --dry-run
1988
+ ```
2015
1989
 
2016
- $ proca widget update 4454 --confirm-optin
1990
+ ## `proca widget update external`
2017
1991
 
2018
- $ proca widget update 4454 --confirm-optin --dry-run
1992
+ Update the global counter to add the actions collected elsewhere
1993
+
1994
+ ```
1995
+ USAGE
1996
+ $ proca widget update external [ID_NAME_DXID] -t <value> [--json | --csv | --markdown] [--env
1997
+ <value>] [--simplify] [-i <value> | -n <the_short_name> | -x <value>]
1998
+
1999
+ FLAGS
2000
+ -i, --id=<value>
2001
+ -n, --name=<the_short_name> name
2002
+ -t, --total=<value> (required) new total to include
2003
+ -x, --dxid=<value> dxid
2004
+ --env=<value> [default: default] allow to switch between configurations (server or users)
2005
+
2006
+ OUTPUT FLAGS
2007
+ --csv Format output as csv
2008
+ --json Format output as json
2009
+ --markdown Format output as markdown table
2010
+ --[no-]simplify flatten and filter to output only the most important attributes, mostly relevant for json
2011
+
2012
+ DESCRIPTION
2013
+ Update the global counter to add the actions collected elsewhere
2014
+
2015
+ EXAMPLES
2016
+ see also proca contact count
2017
+ ```
2018
+
2019
+ ## `proca widget update name`
2020
+
2021
+ Update the name of a widget
2022
+
2023
+ ```
2024
+ USAGE
2025
+ $ proca widget update name [ID_NAME_DXID] [--json | --csv | --markdown] [--env <value>]
2026
+ [--simplify] [-i <value> | -n <the_short_name> | -x <value>] [--rename <widget name>]
2027
+
2028
+ FLAGS
2029
+ -i, --id=<value>
2030
+ -n, --name=<the_short_name> name
2031
+ -x, --dxid=<value> dxid
2032
+ --env=<value> [default: default] allow to switch between configurations (server or users)
2033
+ --rename=<widget name> new name for the widget
2034
+
2035
+ OUTPUT FLAGS
2036
+ --csv Format output as csv
2037
+ --json Format output as json
2038
+ --markdown Format output as markdown table
2039
+ --[no-]simplify flatten and filter to output only the most important attributes, mostly relevant for json
2040
+
2041
+ DESCRIPTION
2042
+ Update the name of a widget
2043
+
2044
+ EXAMPLES
2045
+ see also proca widget update name --name=campaign/old_name --rename=campaign/new_name
2019
2046
  ```
2020
2047
  <!-- 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.1",
5
5
  "author": "Xavier",
6
6
  "bin": {
7
7
  "proca": "proca-cli"
@@ -2,7 +2,7 @@ import { Flags } from "@oclif/core";
2
2
  import prompts from "prompts";
3
3
  import CampaignGet from "#src/commands/campaign/get.mjs";
4
4
  import WidgetList from "#src/commands/widget/list.mjs";
5
- import WidgetUpdate from "#src/commands/widget/update.mjs";
5
+ import WidgetUpdate from "#src/commands/widget/update/index.mjs";
6
6
  import Command from "#src/procaCommand.mjs";
7
7
 
8
8
  export default class CampaignWidgetArchive extends Command {
@@ -10,7 +10,6 @@ export const getWidget = (params) => {
10
10
 
11
11
  export default class WidgetGet extends Command {
12
12
  static description = "view a widget";
13
-
14
13
  static args = this.multiid();
15
14
 
16
15
  static flags = {
@@ -2,6 +2,11 @@ import { Flags } from "@oclif/core";
2
2
  import Command from "#src/procaCommand.mjs";
3
3
  import { gql, mutation } from "#src/urql.mjs";
4
4
 
5
+ export const updateCounter = (id, counter) => {
6
+ const d = new CounterUpdate([]);
7
+ return d.updateCounter(id, counter);
8
+ };
9
+
5
10
  export default class CounterUpdate extends Command {
6
11
  static description =
7
12
  "Update the global counter to add the actions collected elsewhere";
@@ -1,26 +1,24 @@
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
 
7
7
  export default class WidgetUpdate extends Command {
8
8
  static description = "Update a widget's properties";
9
-
10
9
  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",
10
+ "<%= config.bin %> <%= command.id %> -name campaign/widget --locale fr",
11
+ "<%= config.bin %> <%= command.id %> 42 --confirm-optin",
12
+ "<%= config.bin %> <%= command.id %> --dxid=pnc -confirm-optin --dry-run",
15
13
  ];
16
14
 
17
15
  static args = this.multiid();
18
16
 
17
+ // @ivana, let's make separate update xxx than inherit, check external
19
18
  static flags = {
20
- // flag with no value (-f, --force)
21
19
  ...this.flagify({ multiid: true }),
22
20
  rename: Flags.string({
23
- char: "n",
21
+ hidden: true, // use proca widget update name instead
24
22
  description: "new name for the widget",
25
23
  helpValue: "<widget name>",
26
24
  }),
@@ -53,13 +51,7 @@ export default class WidgetUpdate extends Command {
53
51
  }),
54
52
  };
55
53
 
56
- fetchWidget = async (params) => {
57
- const widgetGet = new WidgetGet([], this.config);
58
- return widgetGet.fetch(params);
59
- };
60
-
61
54
  update = async (widgetId, input) => {
62
- console.log("Updating widget with input:", input);
63
55
  const Document = gql`
64
56
  mutation UpdateActionPage($id: Int!, $input: ActionPageInput!) {
65
57
  updateActionPage(id: $id, input: $input) {
@@ -98,6 +90,7 @@ export default class WidgetUpdate extends Command {
98
90
  const { flags } = await this.parse();
99
91
  const {
100
92
  id,
93
+ name,
101
94
  rename,
102
95
  locale,
103
96
  color,
@@ -107,7 +100,7 @@ export default class WidgetUpdate extends Command {
107
100
  } = flags;
108
101
 
109
102
  // Fetch current widget
110
- const widget = await this.fetchWidget({ id });
103
+ const widget = await getWidget({ id, name });
111
104
 
112
105
  if (!widget) {
113
106
  this.error("Widget not found");
@@ -115,7 +108,7 @@ export default class WidgetUpdate extends Command {
115
108
 
116
109
  // Validate name
117
110
  if (rename) {
118
- const nameParts = renname.split("/");
111
+ const nameParts = rename.split("/");
119
112
  if (nameParts.length < 2) {
120
113
  this.error(
121
114
  "Widget name must follow format: campaign_name/org_name or campaign_name/locale or campaign_name/org_name/locale",
@@ -124,8 +117,8 @@ export default class WidgetUpdate extends Command {
124
117
  }
125
118
 
126
119
  const input = {
127
- name: rename ?? widget.name,
128
- locale: locale ?? widget.locale,
120
+ name: rename ?? rename,
121
+ locale: locale ?? locale,
129
122
  };
130
123
 
131
124
  if (color) {
@@ -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/index.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
+ }
@@ -100,10 +100,11 @@ class ProcaCommand extends Command {
100
100
  ].filter(Boolean).length;
101
101
 
102
102
  if (identified === 0) {
103
- this.error("One of --name, --id, or --dxid is required");
103
+ super.error("One of --name, --id, or --dxid is required", {
104
+ code: 1,
105
+ });
104
106
  }
105
107
 
106
- await super.parse(); // check that either the first arg or the name/id/dxid are set
107
108
  return parsed;
108
109
  }
109
110
 
@@ -115,7 +116,7 @@ class ProcaCommand extends Command {
115
116
  };
116
117
  async init() {
117
118
  await super.init();
118
- const { argv, flags } = await this.parse();
119
+ const { flags } = await this.parse();
119
120
  this.flags = flags;
120
121
  if (flags.json) this.format = "json";
121
122
  if (flags.csv) this.format = "csv";
@@ -128,14 +129,29 @@ class ProcaCommand extends Command {
128
129
  createClient(this.procaConfig);
129
130
  }
130
131
 
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);
132
+ async catch(err) {
133
+ const entity = this.id.split(":")[0];
134
+ if (err.graphQLErrors && err.graphQLErrors.length > 0) {
135
+ err.graphQLErrors.forEach((graphqlErr) => {
136
+ if (graphqlErr.extensions) {
137
+ const code = graphqlErr.extensions.code;
138
+ if (code === "not_found") {
139
+ this.error(`${entity} not found`, { exit: 1 });
140
+ }
141
+ }
142
+ });
138
143
  }
144
+
145
+ if (err.networkError) {
146
+ this.info("Looks like there’s a problem with your internet connection");
147
+ this.error(err.networkError.cause, { exit: err.code || 1 });
148
+ }
149
+ if (err instanceof SyntaxError) {
150
+ this.error(`Syntax error: ${err.message}`, { code: 1 });
151
+ }
152
+
153
+ // Default error handling
154
+ this.error(err.message, { exit: err.code || 1 });
139
155
  }
140
156
 
141
157
  flatten = (obj, prefix = "", result = {}) => {
@@ -192,7 +208,7 @@ class ProcaCommand extends Command {
192
208
  }
193
209
 
194
210
  error(msg, options = {}) {
195
- const colouredMessage = ux.colorize(this.config.theme.error, msg);
211
+ const colouredMessage = `❌ ${ux.colorize(this.config.theme.error, msg)}`;
196
212
  super.error(colouredMessage, options);
197
213
  }
198
214
 
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;