proca 2.1.0 → 2.2.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
@@ -119,13 +119,13 @@ you should also use the local proca-api in your [widget generator](https://githu
119
119
  ```
120
120
  USAGE
121
121
  $ proca action add [ID_NAME_DXID...] -i <value> --firstname <value> --email <value>
122
- [--json | --csv | --markdown] [--env <value>] [--simplify] [-x <value>] [-n <the_short_name>] [--testing] [--optin]
122
+ [--json | --csv | --markdown] [--env <value>] [--simplify] [-n <the_short_name>] [-x <value>] [--testing] [--optin]
123
123
  [--action_type <value>] [--lastname <value>] [--street <value>] [--locality <value>] [--region <value>] [--country
124
124
  <value>] [--utm <value>] [--target <value>] [--subject <value>] [--body <value>]
125
125
 
126
126
  FLAGS
127
127
  -i, --id=<value> (required) widget's id
128
- -n, --name=<the_short_name> name
128
+ -n, --name=<the_short_name> name (technical short name, also called slug)
129
129
  -x, --dxid=<value> dxid
130
130
  --action_type=<value> [default: register]
131
131
  --body=<value> [mtt] body of the email
@@ -196,7 +196,7 @@ USAGE
196
196
 
197
197
  FLAGS
198
198
  -i, --id=<value>
199
- -n, --name=<the_short_name> name
199
+ -n, --name=<the_short_name> name (technical short name, also called slug)
200
200
  -x, --dxid=<value> dxid
201
201
  --env=<value> [default: default] allow to switch between configurations (server or users)
202
202
 
@@ -371,7 +371,7 @@ USAGE
371
371
 
372
372
  FLAGS
373
373
  -i, --id=<value>
374
- -n, --name=<the_short_name> name
374
+ -n, --name=<the_short_name> name (technical short name, also called slug)
375
375
  -o, --org=<org name> organization for the new campaign (defaults to source campaign org)
376
376
  -t, --to=<campaign name> (required) new campaign name
377
377
  -x, --dxid=<value> dxid
@@ -405,7 +405,7 @@ USAGE
405
405
 
406
406
  FLAGS
407
407
  -i, --id=<value>
408
- -n, --name=<the_short_name> name
408
+ -n, --name=<the_short_name> name (technical short name, also called slug)
409
409
  -x, --dxid=<value> dxid
410
410
  --env=<value> [default: default] allow to switch between configurations (server or users)
411
411
 
@@ -439,7 +439,7 @@ USAGE
439
439
 
440
440
  FLAGS
441
441
  -i, --id=<value>
442
- -n, --name=<the_short_name> name
442
+ -n, --name=<the_short_name> name (technical short name, also called slug)
443
443
  -x, --dxid=<value> dxid
444
444
  --[no-]config display the config
445
445
  --env=<value> [default: default] allow to switch between configurations (server or users)
@@ -466,13 +466,13 @@ list all the campaigns
466
466
  ```
467
467
  USAGE
468
468
  $ proca campaign list [--json | --csv | --markdown] [--env <value>] [--simplify] [-n
469
- <the_short_name>] [-t <campaign title>...] [--stats]
469
+ <name of the organisation>] [-t <campaign title>...] [--stats]
470
470
 
471
471
  FLAGS
472
- -n, --name=<the_short_name> name of the organisation
473
- -t, --title=<campaign title>... name of the campaign
474
- --env=<value> [default: default] allow to switch between configurations (server or users)
475
- --[no-]stats display the stats
472
+ -n, --name=<name of the organisation> name (technical short name, also called slug)
473
+ -t, --title=<campaign title>... name of the campaign
474
+ --env=<value> [default: default] allow to switch between configurations (server or users)
475
+ --[no-]stats display the stats
476
476
 
477
477
  OUTPUT FLAGS
478
478
  --csv Format output as csv
@@ -496,7 +496,7 @@ USAGE
496
496
 
497
497
  FLAGS
498
498
  -i, --id=<value>
499
- -n, --name=<the_short_name> name
499
+ -n, --name=<the_short_name> name (technical short name, also called slug)
500
500
  -x, --dxid=<value> dxid
501
501
  --cc=<value> comma-separated list of CC email addresses
502
502
  --drip drip delivery or deliver as fast as possible
@@ -559,7 +559,7 @@ USAGE
559
559
 
560
560
  FLAGS
561
561
  -i, --id=<value>
562
- -n, --name=<the_short_name> name
562
+ -n, --name=<the_short_name> name (technical short name, also called slug)
563
563
  -s, --suffix=<suffix> [default: _archive] custom suffix to append (default: _archive)
564
564
  -x, --dxid=<value> dxid
565
565
  --dry-run preview changes without executing
@@ -593,7 +593,7 @@ USAGE
593
593
 
594
594
  FLAGS
595
595
  -i, --id=<value>
596
- -n, --name=<the_short_name> name
596
+ -n, --name=<the_short_name> name (technical short name, also called slug)
597
597
  -s, --suffix=<suffix> [default: _archive] suffix to remove from widget names (e.g., _archive, -v1)
598
598
  -t, --to=<campaign name> (required) destination campaign name
599
599
  -x, --dxid=<value> dxid
@@ -630,7 +630,7 @@ USAGE
630
630
 
631
631
  FLAGS
632
632
  -i, --id=<value>
633
- -n, --name=<the_short_name> name
633
+ -n, --name=<the_short_name> name (technical short name, also called slug)
634
634
  -x, --dxid=<value> dxid
635
635
  --env=<value> [default: default] allow to switch between configurations (server or users)
636
636
 
@@ -655,7 +655,7 @@ USAGE
655
655
 
656
656
  FLAGS
657
657
  -i, --id=<value>
658
- -n, --name=<the_short_name> name
658
+ -n, --name=<the_short_name> name (technical short name, also called slug)
659
659
  -x, --dxid=<value> dxid
660
660
  --env=<value> [default: default] allow to switch between configurations (server or users)
661
661
 
@@ -915,7 +915,7 @@ USAGE
915
915
 
916
916
  FLAGS
917
917
  -i, --id=<value>
918
- -n, --name=<the_short_name> name
918
+ -n, --name=<the_short_name> name (technical short name, also called slug)
919
919
  -x, --dxid=<value> dxid
920
920
  --env=<value> [default: default] allow to switch between configurations (server or users)
921
921
 
@@ -934,18 +934,19 @@ EXAMPLES
934
934
 
935
935
  ## `proca contact count`
936
936
 
937
- counter of supporters
937
+ counter of supporters of a campaign
938
938
 
939
939
  ```
940
940
  USAGE
941
941
  $ proca contact count [ID_NAME_DXID] [--json | --csv | --markdown] [--env <value>]
942
- [--simplify] [-i <value> | -n <the_short_name> | -x <value>]
942
+ [--simplify] [-i <value> | -n <campaign> | -x <value>] [--query]
943
943
 
944
944
  FLAGS
945
945
  -i, --id=<value>
946
- -n, --name=<the_short_name> name
947
- -x, --dxid=<value> dxid
948
- --env=<value> [default: default] allow to switch between configurations (server or users)
946
+ -n, --name=<campaign> name (technical short name, also called slug)
947
+ -x, --dxid=<value> dxid
948
+ --env=<value> [default: default] allow to switch between configurations (server or users)
949
+ --query display the REST api query
949
950
 
950
951
  OUTPUT FLAGS
951
952
  --csv Format output as csv
@@ -954,7 +955,7 @@ OUTPUT FLAGS
954
955
  --[no-]simplify flatten and filter to output only the most important attributes, mostly relevant for json
955
956
 
956
957
  DESCRIPTION
957
- counter of supporters
958
+ counter of supporters of a campaign
958
959
 
959
960
  EXAMPLES
960
961
  $ proca contact count --name <name of the campaign>
@@ -1095,7 +1096,8 @@ USAGE
1095
1096
 
1096
1097
  FLAGS
1097
1098
  -i, --id=<value>
1098
- -n, --name=<the_short_name> name
1099
+ -n, --name=<the_short_name> name (technical short name, also
1100
+ called slug)
1099
1101
  -x, --dxid=<value> dxid
1100
1102
  --env=<value> [default: default] allow to switch
1101
1103
  between configurations (server or
@@ -1847,7 +1849,7 @@ USAGE
1847
1849
 
1848
1850
  FLAGS
1849
1851
  -i, --id=<value>
1850
- -n, --name=<the_short_name> name
1852
+ -n, --name=<the_short_name> name (technical short name, also called slug)
1851
1853
  -x, --dxid=<value> dxid
1852
1854
  --env=<value> [default: default] allow to switch between configurations (server or users)
1853
1855
 
@@ -1872,7 +1874,7 @@ USAGE
1872
1874
 
1873
1875
  FLAGS
1874
1876
  -i, --id=<value>
1875
- -n, --name=<the_short_name> name
1877
+ -n, --name=<the_short_name> name (technical short name, also called slug)
1876
1878
  -x, --dxid=<value> dxid
1877
1879
  --[no-]config display the config
1878
1880
  --env=<value> [default: default] allow to switch between configurations (server or users)
@@ -1926,7 +1928,7 @@ USAGE
1926
1928
 
1927
1929
  FLAGS
1928
1930
  -i, --id=<value>
1929
- -n, --name=<the_short_name> name
1931
+ -n, --name=<the_short_name> name (technical short name, also called slug)
1930
1932
  -x, --dxid=<value> dxid
1931
1933
  --env=<value> [default: default] allow to switch between configurations (server or users)
1932
1934
 
@@ -1962,7 +1964,7 @@ USAGE
1962
1964
  FLAGS
1963
1965
  -i, --id=<value>
1964
1966
  -l, --locale=<locale> change the locale
1965
- -n, --name=<the_short_name> name
1967
+ -n, --name=<the_short_name> name (technical short name, also called slug)
1966
1968
  -x, --dxid=<value> dxid
1967
1969
  --color=<hex code> update color (not yet implemented)
1968
1970
  --confirm-action add actionConfirm (check email snack) to consent.email component
@@ -1980,8 +1982,6 @@ DESCRIPTION
1980
1982
  Update a widget's properties
1981
1983
 
1982
1984
  EXAMPLES
1983
- $ proca widget update -i 42 --rename campaign/new_name
1984
-
1985
1985
  $ proca widget update -name campaign/widget --locale fr
1986
1986
 
1987
1987
  $ proca widget update 42 --confirm-optin
@@ -2000,7 +2000,7 @@ USAGE
2000
2000
 
2001
2001
  FLAGS
2002
2002
  -i, --id=<value>
2003
- -n, --name=<the_short_name> name
2003
+ -n, --name=<the_short_name> name (technical short name, also called slug)
2004
2004
  -t, --total=<value> (required) new total to include
2005
2005
  -x, --dxid=<value> dxid
2006
2006
  --env=<value> [default: default] allow to switch between configurations (server or users)
@@ -2029,7 +2029,7 @@ USAGE
2029
2029
 
2030
2030
  FLAGS
2031
2031
  -i, --id=<value>
2032
- -n, --name=<the_short_name> name
2032
+ -n, --name=<the_short_name> name (technical short name, also called slug)
2033
2033
  -x, --dxid=<value> dxid
2034
2034
  --env=<value> [default: default] allow to switch between configurations (server or users)
2035
2035
  --rename=<widget name> new name for the widget
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "proca",
3
3
  "description": "Access the proca api",
4
- "version": "2.1.0",
4
+ "version": "2.2.0",
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 {
@@ -1,9 +1,11 @@
1
- import { Args, Flags } from "@oclif/core";
1
+ import { Flags } from "@oclif/core";
2
+ import { getCampaign } from "#src/commands/campaign/get.mjs";
2
3
  import Command from "#src/procaCommand.mjs";
4
+
3
5
  import { gql, query } from "#src/urql.mjs";
4
6
 
5
7
  export default class CounterGet extends Command {
6
- static description = "counter of supporters";
8
+ static description = "counter of supporters of a campaign";
7
9
 
8
10
  static examples = [
9
11
  "<%= config.bin %> <%= command.id %> --name <name of the campaign>",
@@ -12,10 +14,28 @@ export default class CounterGet extends Command {
12
14
  static args = this.multiid();
13
15
  static flags = {
14
16
  // flag with no value (-f, --force)
15
- ...this.flagify({ multiid: true }),
17
+ ...this.flagify({ multiid: true, name: "campaign" }),
18
+ query: Flags.boolean({
19
+ description: "display the REST api query",
20
+ default: false,
21
+ }),
16
22
  };
17
23
 
18
- fetch = async (params) => {
24
+ getMinifiedDoc = (id) => {
25
+ const query = `{
26
+ campaign(id: ${id}) {
27
+ stats {
28
+ supporterCount
29
+ }
30
+ }
31
+ }`;
32
+ return query
33
+ .replace(/\s*([{}():,])\s*/g, "$1")
34
+ .replace(/\s+/g, " ")
35
+ .trim();
36
+ };
37
+
38
+ getDoc = () => {
19
39
  const GetCounterDocument = gql`
20
40
  query GetCounter($name: String, $id: Int) {
21
41
  campaign(name: $name, id: $id) {
@@ -25,6 +45,11 @@ export default class CounterGet extends Command {
25
45
  }
26
46
  }
27
47
  `;
48
+ return GetCounterDocument;
49
+ };
50
+
51
+ fetch = async (params) => {
52
+ const GetCounterDocument = this.getDoc();
28
53
  const result = await query(GetCounterDocument, params);
29
54
  return result.campaign.stats;
30
55
  };
@@ -34,7 +59,16 @@ export default class CounterGet extends Command {
34
59
  };
35
60
 
36
61
  async run() {
37
- const { args, flags } = await this.parse();
62
+ const { flags } = await this.parse();
63
+ if (flags.query) {
64
+ const camp = await getCampaign(flags);
65
+ const query = this.getMinifiedDoc(camp.id);
66
+ return this.output({
67
+ api: query,
68
+ url: `${this.procaConfig.url}?query=${encodeURIComponent(query)}`,
69
+ });
70
+ }
71
+
38
72
  const data = await this.fetch(flags);
39
73
  return this.output(data);
40
74
  }
@@ -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";
@@ -6,9 +6,7 @@ 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 %> -i 42 --rename campaign/new_name",
12
10
  "<%= config.bin %> <%= command.id %> -name campaign/widget --locale fr",
13
11
  "<%= config.bin %> <%= command.id %> 42 --confirm-optin",
14
12
  "<%= config.bin %> <%= command.id %> --dxid=pnc -confirm-optin --dry-run",
@@ -16,8 +14,8 @@ export default class WidgetUpdate extends Command {
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
21
  hidden: true, // use proca widget update name instead
@@ -1,6 +1,6 @@
1
1
  import { Flags } from "@oclif/core";
2
2
  import { getWidget } from "#src/commands/widget/get.mjs";
3
- import UpdateCommand from "#src/commands/widget/update.mjs";
3
+ import UpdateCommand from "#src/commands/widget/update/index.mjs";
4
4
 
5
5
  export default class CounterUpdate extends UpdateCommand {
6
6
  static description = "Update the name of a widget";
@@ -44,23 +44,23 @@ class ProcaCommand extends Command {
44
44
  ignoreStdin: true,
45
45
  hidden: true,
46
46
  description:
47
- "it's better to use -i <id> or -x <dxid> or -n <name>, but you can for convenience",
47
+ "convenience, but try to use -i <id> or -x <dxid> or -n <name> instead",
48
48
  }),
49
49
  };
50
50
  return args;
51
51
  }
52
52
 
53
- static flagify(params = {}) {
53
+ static flagify({ multiid = false, name = false } = {}) {
54
54
  const flags = Object.assign({}, ProcaCommand.baseFlags);
55
- if (params.name) {
55
+ if (name || multiid) {
56
56
  flags.name = Flags.string({
57
57
  char: "n",
58
- charAliases: ["o"],
59
- description: typeof params.name === "string" ? params.name : "name",
60
- helpValue: "<the_short_name>",
58
+ description: "name (technical short name, also called slug)",
59
+ helpValue: typeof name === "string" ? `<${name}>` : "<the_short_name>",
60
+ parse: (input) => ProcaCommand.safeName(input),
61
61
  });
62
62
  }
63
- if (params.multiid) {
63
+ if (multiid) {
64
64
  flags.id = Flags.string({
65
65
  char: "i",
66
66
  parse: (input) => Number.parseInt(input, 10),
@@ -70,15 +70,18 @@ class ProcaCommand extends Command {
70
70
  char: "x",
71
71
  description: "dxid",
72
72
  });
73
- flags.name = Flags.string({
74
- char: "n",
75
- description: "name",
76
- helpValue: "<the_short_name>",
77
- });
78
73
  }
79
74
  return flags;
80
75
  }
81
76
 
77
+ static safeName = (input) => {
78
+ const pattern = /^[a-zA-Z0-9\-_]+$/;
79
+ if (!pattern.test(input)) {
80
+ throw new Error(`Invalid characters in: ${input}`);
81
+ }
82
+ return input;
83
+ };
84
+
82
85
  async parse() {
83
86
  const parsed = await super.parse();
84
87
  if (this.ctor.args.id_name_dxid === undefined) {
@@ -86,9 +89,20 @@ class ProcaCommand extends Command {
86
89
  }
87
90
  const maybe = parsed.args.id_name_dxid;
88
91
  if (maybe) {
92
+ const identified = [
93
+ parsed.flags.name,
94
+ parsed.flags.id,
95
+ parsed.flags.dxid,
96
+ ].filter(Boolean).length;
97
+
98
+ if (identified > 0) {
99
+ super.error("can't have --name, --id, or --dxid and an unamed arg", {
100
+ code: 1,
101
+ });
102
+ }
89
103
  const d = dxid(maybe, false);
90
104
  if (d) parsed.flags.id = d;
91
- else parsed.flags.name = maybe;
105
+ else parsed.flags.name = ProcaCommand.safeName(maybe);
92
106
  }
93
107
  if (parsed.flags.dxid) {
94
108
  parsed.flags.id = dxid(parsed.flags.dxid);
@@ -100,10 +114,11 @@ class ProcaCommand extends Command {
100
114
  ].filter(Boolean).length;
101
115
 
102
116
  if (identified === 0) {
103
- this.error("One of --name, --id, or --dxid is required");
117
+ super.error("One of --name, --id, or --dxid is required", {
118
+ code: 1,
119
+ });
104
120
  }
105
121
 
106
- await super.parse(); // check that either the first arg or the name/id/dxid are set
107
122
  return parsed;
108
123
  }
109
124
 
@@ -143,14 +158,14 @@ class ProcaCommand extends Command {
143
158
 
144
159
  if (err.networkError) {
145
160
  this.info("Looks like there’s a problem with your internet connection");
146
- this.error(err.networkError.cause, { exit: err.exitCode || 1 });
161
+ this.error(err.networkError.cause, { exit: err.code || 1 });
147
162
  }
148
163
  if (err instanceof SyntaxError) {
149
- this.error(`Syntax error: ${err.message}`, { exit: 1 });
164
+ this.error(`Syntax error: ${err.message}`, { code: 1 });
150
165
  }
151
166
 
152
167
  // Default error handling
153
- this.error(err.message, { exit: err.exitCode || 1 });
168
+ this.error(err.message, { exit: err.code || 1 });
154
169
  }
155
170
 
156
171
  flatten = (obj, prefix = "", result = {}) => {