proca 2.2.1 → 2.5.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
@@ -48,6 +48,7 @@ you should also use the local proca-api in your [widget generator](https://githu
48
48
 
49
49
  <!-- commands -->
50
50
  * [`proca action add`](#proca-action-add)
51
+ * [`proca action add mtt`](#proca-action-add-mtt)
51
52
  * [`proca action confirm`](#proca-action-confirm)
52
53
  * [`proca action count`](#proca-action-count)
53
54
  * [`proca action list [TITLE]`](#proca-action-list-title)
@@ -74,6 +75,8 @@ you should also use the local proca-api in your [widget generator](https://githu
74
75
  * [`proca config user`](#proca-config-user)
75
76
  * [`proca contact area count`](#proca-contact-area-count)
76
77
  * [`proca contact count`](#proca-contact-count)
78
+ * [`proca contact delete`](#proca-contact-delete)
79
+ * [`proca contact get`](#proca-contact-get)
77
80
  * [`proca contact list`](#proca-contact-list)
78
81
  * [`proca help [COMMAND]`](#proca-help-command)
79
82
  * [`proca org add`](#proca-org-add)
@@ -81,6 +84,7 @@ you should also use the local proca-api in your [widget generator](https://githu
81
84
  * [`proca org delete`](#proca-org-delete)
82
85
  * [`proca org email`](#proca-org-email)
83
86
  * [`proca org get`](#proca-org-get)
87
+ * [`proca org logo`](#proca-org-logo)
84
88
  * [`proca org user get`](#proca-org-user-get)
85
89
  * [`proca plugins`](#proca-plugins)
86
90
  * [`proca plugins add PLUGIN`](#proca-plugins-add-plugin)
@@ -107,6 +111,8 @@ you should also use the local proca-api in your [widget generator](https://githu
107
111
  * [`proca user whoami`](#proca-user-whoami)
108
112
  * [`proca widget add`](#proca-widget-add)
109
113
  * [`proca widget delete`](#proca-widget-delete)
114
+ * [`proca widget external`](#proca-widget-external)
115
+ * [`proca widget external cron`](#proca-widget-external-cron)
110
116
  * [`proca widget get`](#proca-widget-get)
111
117
  * [`proca widget list`](#proca-widget-list)
112
118
  * [`proca widget rebuild`](#proca-widget-rebuild)
@@ -158,6 +164,50 @@ EXAMPLES
158
164
  $ proca action add -i <widget_id> --firstname=John --email=john@example.org target=715a9580-cfe6-4005-9e23-61a62ddecfea --subject='MTT subject' --body='message MTT'
159
165
  ```
160
166
 
167
+ ## `proca action add mtt`
168
+
169
+ ```
170
+ USAGE
171
+ $ proca action add mtt [ID_NAME_DXID...] -i <value> --firstname <value> --email <value>
172
+ [--json | --csv | --markdown] [--env <value>] [--simplify] [-n <the_short_name>] [-x <value>] [--testing] [--optin]
173
+ [--action_type <value>] [--lastname <value>] [--street <value>] [--locality <value>] [--region <value>] [--country
174
+ <value>] [--utm <value>] [--target <value>] [--subject <value>] [--body <value>]
175
+
176
+ FLAGS
177
+ -i, --id=<value> (required) widget's id
178
+ -n, --name=<the_short_name> name (technical short name, also called slug)
179
+ -x, --dxid=<value> dxid
180
+ --action_type=<value> [default: email]
181
+ --body=<value> [mtt] body of the email
182
+ --country=<value> 2-letter country iso code
183
+ --email=<value> (required) email
184
+ --env=<value> [default: default] allow to switch between configurations (server or users)
185
+ --firstname=<value> (required) supporter's firstname
186
+ --lastname=<value>
187
+ --locality=<value>
188
+ --[no-]optin Whether the user opts in (default: false). Use --optin to enable or --no-optin to
189
+ explicitly disable.
190
+ --region=<value>
191
+ --street=<value>
192
+ --subject=<value> [mtt] subject of the email
193
+ --target=<value> [mtt] uid of the target
194
+ --[no-]testing Run action in testing mode (default: true). Use --no-testing to disable.
195
+ --utm=<value> utm=campaign.source.medium
196
+
197
+ OUTPUT FLAGS
198
+ --csv Format output as csv
199
+ --json Format output as json
200
+ --markdown Format output as markdown table
201
+ --[no-]simplify flatten and filter to output only the most important attributes, mostly relevant for json
202
+
203
+ EXAMPLES
204
+ $ proca action add mtt -i <widget_id> --firstname=John --email=john@example.org
205
+
206
+ $ proca action add mtt -i <widget_id> --firstname=John --email=john@example.org --country=FR custom1=A custom2=B
207
+
208
+ $ proca action add mtt -i <widget_id> --firstname=John --email=john@example.org target=715a9580-cfe6-4005-9e23-61a62ddecfea --subject='MTT subject' --body='message MTT'
209
+ ```
210
+
161
211
  ## `proca action confirm`
162
212
 
163
213
  Should the supporter confirm the action? it can be set either for all the widgets or an organisation or all the widgets of a campaign
@@ -337,12 +387,15 @@ EXAMPLES
337
387
  ```
338
388
  USAGE
339
389
  $ proca campaign close [ID_NAME_DXID] --status draft|live|closed|ignored [--json | --csv
340
- | --markdown] [--env <value>] [--simplify]
390
+ | --markdown] [--env <value>] [--simplify] [-n <campaign>] [--start YYYY-MM-DD] [--end YYYY-MM-DD]
341
391
 
342
392
  FLAGS
343
- --env=<value> [default: default] allow to switch between configurations (server or users)
344
- --status=<option> (required) Status to set
345
- <options: draft|live|closed|ignored>
393
+ -n, --name=<campaign> name (technical short name, also called slug)
394
+ --end=YYYY-MM-DD end date of the campaign
395
+ --env=<value> [default: default] allow to switch between configurations (server or users)
396
+ --start=YYYY-MM-DD start date of the campaign
397
+ --status=<option> (required) Status to set
398
+ <options: draft|live|closed|ignored>
346
399
 
347
400
  OUTPUT FLAGS
348
401
  --csv Format output as csv
@@ -354,9 +407,7 @@ ALIASES
354
407
  $ proca campaign close
355
408
 
356
409
  EXAMPLES
357
- $ proca campaign close -name <campaign>
358
-
359
- $ proca campaign close -i <campaign_id>
410
+ $ proca campaign close -name <campaign> --end=2025-01-02 --status=close
360
411
  ```
361
412
 
362
413
  ## `proca campaign copy`
@@ -465,8 +516,8 @@ list all the campaigns
465
516
 
466
517
  ```
467
518
  USAGE
468
- $ proca campaign list [--json | --csv | --markdown] [--env <value>] [--simplify] [-n
469
- <name of the organisation>] [-t <campaign title>...] [--stats]
519
+ $ proca campaign list [NAME] [--json | --csv | --markdown] [--env <value>] [--simplify]
520
+ [-n <name of the organisation>] [-t <campaign title>...] [--stats]
470
521
 
471
522
  FLAGS
472
523
  -n, --name=<name of the organisation> name (technical short name, also called slug)
@@ -526,12 +577,15 @@ EXAMPLES
526
577
  ```
527
578
  USAGE
528
579
  $ proca campaign status [ID_NAME_DXID] --status draft|live|closed|ignored [--json | --csv
529
- | --markdown] [--env <value>] [--simplify]
580
+ | --markdown] [--env <value>] [--simplify] [-n <campaign>] [--start YYYY-MM-DD] [--end YYYY-MM-DD]
530
581
 
531
582
  FLAGS
532
- --env=<value> [default: default] allow to switch between configurations (server or users)
533
- --status=<option> (required) Status to set
534
- <options: draft|live|closed|ignored>
583
+ -n, --name=<campaign> name (technical short name, also called slug)
584
+ --end=YYYY-MM-DD end date of the campaign
585
+ --env=<value> [default: default] allow to switch between configurations (server or users)
586
+ --start=YYYY-MM-DD start date of the campaign
587
+ --status=<option> (required) Status to set
588
+ <options: draft|live|closed|ignored>
535
589
 
536
590
  OUTPUT FLAGS
537
591
  --csv Format output as csv
@@ -543,9 +597,7 @@ ALIASES
543
597
  $ proca campaign close
544
598
 
545
599
  EXAMPLES
546
- $ proca campaign status -name <campaign>
547
-
548
- $ proca campaign status -i <campaign_id>
600
+ $ proca campaign status -name <campaign> --end=2025-01-02 --status=close
549
601
  ```
550
602
 
551
603
  ## `proca campaign widget archive`
@@ -961,18 +1013,58 @@ EXAMPLES
961
1013
  $ proca contact count --name <name of the campaign>
962
1014
  ```
963
1015
 
1016
+ ## `proca contact delete`
1017
+
1018
+ ```
1019
+ USAGE
1020
+ $ proca contact delete -c from contact get [--json | --csv | --markdown] [--env <value>]
1021
+ [--simplify] [-n <org>]
1022
+
1023
+ FLAGS
1024
+ -c, --ref=from contact get (required) contact reference
1025
+ -n, --name=<org> name (technical short name, also called slug)
1026
+ --env=<value> [default: default] allow to switch between configurations (server or users)
1027
+
1028
+ OUTPUT FLAGS
1029
+ --csv Format output as csv
1030
+ --json Format output as json
1031
+ --markdown Format output as markdown table
1032
+ --[no-]simplify flatten and filter to output only the most important attributes, mostly relevant for json
1033
+ ```
1034
+
1035
+ ## `proca contact get`
1036
+
1037
+ ```
1038
+ USAGE
1039
+ $ proca contact get -e <supporter@example.org> [--json | --csv | --markdown] [--env
1040
+ <value>] [-n <org>] [--utm | --simplify] [--comment | ]
1041
+
1042
+ FLAGS
1043
+ -e, --email=<supporter@example.org> (required) email of the supporter
1044
+ -n, --name=<org> name (technical short name, also called slug)
1045
+ --[no-]comment display the comment
1046
+ --env=<value> [default: default] allow to switch between configurations (server or users)
1047
+ --[no-]utm display the utm tracking parameters
1048
+
1049
+ OUTPUT FLAGS
1050
+ --csv Format output as csv
1051
+ --json Format output as json
1052
+ --markdown Format output as markdown table
1053
+ --[no-]simplify flatten and filter to output only the most important attributes, mostly relevant for json
1054
+ ```
1055
+
964
1056
  ## `proca contact list`
965
1057
 
966
1058
  ```
967
1059
  USAGE
968
- $ proca contact list -o <organisation name> [--json | --csv | --markdown] [--env
969
- <value>] [-c <campaign title>] [-n <value>] [--today | --after 2025-04-09] [--optin] [--testing] [--doi] [--utm |
970
- --simplify] [--comment | ]
1060
+ $ proca contact list [--json | --csv | --markdown] [--env <value>] [-n <org>] [-c
1061
+ <campaign title>] [-n <value>] [--today | --after 2025-04-09] [--optin] [--testing] [--doi] [--utm | --simplify]
1062
+ [--comment | ]
971
1063
 
972
1064
  FLAGS
973
1065
  -c, --campaign=<campaign title> name of the campaign, % for wildchar
974
1066
  -n, --limit=<value> max number of actions
975
- -o, --org=<organisation name> (required) campaigns of the organisation (coordinator or partner)
1067
+ -n, --name=<org> name (technical short name, also called slug)
976
1068
  --after=2025-04-09 only actions after a date
977
1069
  --[no-]comment display the comment
978
1070
  --doi only export the double optin actions
@@ -987,9 +1079,6 @@ OUTPUT FLAGS
987
1079
  --json Format output as json
988
1080
  --markdown Format output as markdown table
989
1081
  --[no-]simplify flatten and filter to output only the most important attributes, mostly relevant for json
990
-
991
- EXAMPLES
992
- $ proca contact list %pizza%
993
1082
  ```
994
1083
 
995
1084
  ## `proca help [COMMAND]`
@@ -1126,10 +1215,10 @@ view a org
1126
1215
  ```
1127
1216
  USAGE
1128
1217
  $ proca org get [ID_NAME_DXID] [--json | --csv | --markdown] [--env <value>]
1129
- [--simplify] [-n <org name>] [--config] [--personaldata] [--processing] [--keys] [--campaigns] [--users]
1218
+ [--simplify] [-n <org>] [--config] [--personaldata] [--processing] [--keys] [--campaigns] [--users]
1130
1219
 
1131
1220
  FLAGS
1132
- -n, --name=<org name> name of the org
1221
+ -n, --name=<org> name (technical short name, also called slug)
1133
1222
  --[no-]campaigns
1134
1223
  --[no-]config display the config
1135
1224
  --env=<value> [default: default] allow to switch between configurations (server or users)
@@ -1151,6 +1240,36 @@ EXAMPLES
1151
1240
  $ proca org get <name of the ngo>
1152
1241
  ```
1153
1242
 
1243
+ ## `proca org logo`
1244
+
1245
+ add a logo to the org
1246
+
1247
+ ```
1248
+ USAGE
1249
+ $ proca org logo [ID_NAME_DXID] [--json | --csv | --markdown] [--env <value>]
1250
+ [--simplify] [-n <org>] [--url <value>] [--update]
1251
+
1252
+ FLAGS
1253
+ -n, --name=<org> name (technical short name, also called slug)
1254
+ --env=<value> [default: default] allow to switch between configurations (server or users)
1255
+ --[no-]update use that url (and update it)
1256
+ --url=<value> use that url (and update it)
1257
+
1258
+ OUTPUT FLAGS
1259
+ --csv Format output as csv
1260
+ --json Format output as json
1261
+ --markdown Format output as markdown table
1262
+ --[no-]simplify flatten and filter to output only the most important attributes, mostly relevant for json
1263
+
1264
+ DESCRIPTION
1265
+ add a logo to the org
1266
+
1267
+ EXAMPLES
1268
+ $ proca org logo <name of the ngo>
1269
+ ```
1270
+
1271
+ _See code: [src/commands/org/logo.ts](https://github.com/fixthestatusquo/proca-cli/blob/v2.5.0/src/commands/org/logo.ts)_
1272
+
1154
1273
  ## `proca org user get`
1155
1274
 
1156
1275
  list all the users
@@ -1472,7 +1591,7 @@ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/
1472
1591
 
1473
1592
  ## `proca service add`
1474
1593
 
1475
- Set service, usually email backend for an org, the specific meaning of each param is dependant on the service
1594
+ Set service, usually email backend for an org. the specific meaning of each param is dependant on the service.
1476
1595
 
1477
1596
  ```
1478
1597
  USAGE
@@ -1486,7 +1605,7 @@ FLAGS
1486
1605
  --host=<value> server of the service
1487
1606
  --password=<value> credential of the account on the service
1488
1607
  --path=<value> path on the service
1489
- --type=<option> (required) [default: system] type of the service
1608
+ --type=<option> (required) type of the service
1490
1609
  <options: mailjet|ses|stripe|test_stripe|preview|webhook|supabase|smtp>
1491
1610
  --user=<value> credential of the account on the service
1492
1611
 
@@ -1497,7 +1616,15 @@ OUTPUT FLAGS
1497
1616
  --[no-]simplify flatten and filter to output only the most important attributes, mostly relevant for json
1498
1617
 
1499
1618
  DESCRIPTION
1500
- Set service, usually email backend for an org, the specific meaning of each param is dependant on the service
1619
+ Set service, usually email backend for an org. the specific meaning of each param is dependant on the service.
1620
+ If a service from that type exists, it will replace it
1621
+
1622
+ EXAMPLES
1623
+ $ proca service add -o example_org --type system
1624
+
1625
+ $ proca service add -o example_org --host=tls://mail.example.org:587 --user=login --password "secret" --type smtp
1626
+
1627
+ $ proca service add -o example_org --host=ssl://mail.example.org:465 --user=login --password "secret" --type smtp
1501
1628
  ```
1502
1629
 
1503
1630
  ## `proca service list`
@@ -1654,12 +1781,12 @@ let a user join an organisation with a role
1654
1781
 
1655
1782
  ```
1656
1783
  USAGE
1657
- $ proca user join -o <org name> [--json | --csv | --markdown] [--env <value>]
1658
- [--simplify] [--role owner|campaigner|coordinator|translator] [-u <user email>]
1784
+ $ proca user join [ID_NAME_DXID] [--json | --csv | --markdown] [--env <value>]
1785
+ [--simplify] [-n <org>] [--role owner|campaigner|coordinator|translator] [-u <user email>]
1659
1786
 
1660
1787
  FLAGS
1661
- -o, --org=<org name> (required) name of the org
1662
- -u, --user=<user email> email
1788
+ -n, --name=<org> name (technical short name, also called slug)
1789
+ -u, --user=<user email> email, default current user
1663
1790
  --env=<value> [default: default] allow to switch between configurations (server or users)
1664
1791
  --role=<option> [default: campaigner] permission level in that org
1665
1792
  <options: owner|campaigner|coordinator|translator>
@@ -1863,6 +1990,68 @@ DESCRIPTION
1863
1990
  Delete a widget
1864
1991
  ```
1865
1992
 
1993
+ ## `proca widget external`
1994
+
1995
+ Pull external counter and save it into a widget extra Supporter
1996
+
1997
+ ```
1998
+ USAGE
1999
+ $ proca widget external [ID_NAME_DXID] [--json | --csv | --markdown] [--env <value>]
2000
+ [--simplify] [-i <value> | -n <the_short_name> | -x <value>] [-u <value>] [--path object.sub-object.total] [--total
2001
+ <value>] [--timeout <value>] [--dry-run]
2002
+
2003
+ FLAGS
2004
+ -i, --id=<value>
2005
+ -n, --name=<the_short_name> name (technical short name, also called slug)
2006
+ -u, --url=<value> API endpoint URL to pull from
2007
+ -x, --dxid=<value> dxid
2008
+ --dry-run just fetch, don't update
2009
+ --env=<value> [default: default] allow to switch between configurations (server or users)
2010
+ --path=object.sub-object.total dot notation path to the counter field in the json returned by the url
2011
+ --timeout=<value> [default: 10000] Request timeout in milliseconds
2012
+ --total=<value> number to add to the total
2013
+
2014
+ OUTPUT FLAGS
2015
+ --csv Format output as csv
2016
+ --json Format output as json
2017
+ --markdown Format output as markdown table
2018
+ --[no-]simplify flatten and filter to output only the most important attributes, mostly relevant for json
2019
+
2020
+ DESCRIPTION
2021
+ Pull external counter and save it into a widget extra Supporter
2022
+
2023
+ EXAMPLES
2024
+ $ proca widget external --url https://mitmachen.wwf.de/node/506/polling
2025
+ ```
2026
+
2027
+ ## `proca widget external cron`
2028
+
2029
+ Pull all external counters and save it into a widget extra Supporter. symlink the widget json into config/counter
2030
+
2031
+ ```
2032
+ USAGE
2033
+ $ proca widget external cron [--json | --csv | --markdown] [--env <value>] [--simplify]
2034
+ [--dry-run]
2035
+
2036
+ FLAGS
2037
+ --dry-run just fetch, don't update
2038
+ --env=<value> [default: default] allow to switch between configurations (server or users)
2039
+
2040
+ OUTPUT FLAGS
2041
+ --csv Format output as csv
2042
+ --json Format output as json
2043
+ --markdown Format output as markdown table
2044
+ --[no-]simplify flatten and filter to output only the most important attributes, mostly relevant for json
2045
+
2046
+ DESCRIPTION
2047
+ Pull all external counters and save it into a widget extra Supporter. symlink the widget json into config/counter
2048
+
2049
+ EXAMPLES
2050
+ $ proca widget external cron
2051
+ ```
2052
+
2053
+ _See code: [src/commands/widget/external/cron.ts](https://github.com/fixthestatusquo/proca-cli/blob/v2.5.0/src/commands/widget/external/cron.ts)_
2054
+
1866
2055
  ## `proca widget get`
1867
2056
 
1868
2057
  view a 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.2.1",
4
+ "version": "2.5.0",
5
5
  "author": "Xavier",
6
6
  "bin": {
7
7
  "proca": "proca-cli"
@@ -19,7 +19,9 @@
19
19
  "fast-csv": "^5.0.1",
20
20
  "graphql": "^16.10.0",
21
21
  "merge-anything": "^6.0.6",
22
+ "object-path": "^0.11.8",
22
23
  "prompts": "^2.4.2",
24
+ "simple-git": "^3.33.0",
23
25
  "typescript": "^5.7.3",
24
26
  "urql": "^4.1.0"
25
27
  },
@@ -0,0 +1,192 @@
1
+ import { Args, Flags } from "@oclif/core";
2
+ import { error, stdout, ux } from "@oclif/core/ux";
3
+ import Command from "#src/procaCommand.mjs";
4
+ import { gql, mutation } from "#src/urql.mjs";
5
+ import { getTwitter } from "#src/util/twitter.mjs";
6
+
7
+ export default class ActionAdd extends Command {
8
+ static examples = [
9
+ "<%= config.bin %> <%= command.id %> -i <widget_id> --firstname=John --email=john@example.org",
10
+ "<%= config.bin %> <%= command.id %> -i <widget_id> --firstname=John --email=john@example.org --country=FR custom1=A custom2=B",
11
+ "<%= config.bin %> <%= command.id %> -i <widget_id> --firstname=John --email=john@example.org target=715a9580-cfe6-4005-9e23-61a62ddecfea --subject='MTT subject' --body='message MTT'",
12
+ ];
13
+
14
+ static args = this.multiid();
15
+ static strict = false; //THIS DOES NOT WORK
16
+
17
+ static flags = {
18
+ ...this.flagify({ multiid: true }),
19
+ id: Flags.integer({
20
+ char: "i",
21
+ description: "widget's id",
22
+ required: true,
23
+ }),
24
+ testing: Flags.boolean({
25
+ default: true,
26
+ allowNo: true, // ✅ enables --no-testing
27
+ description:
28
+ "Run action in testing mode (default: true). Use --no-testing to disable.",
29
+ }),
30
+ optin: Flags.boolean({
31
+ default: false,
32
+ allowNo: true, // ✅ enables --no-optin
33
+ description:
34
+ "Whether the user opts in (default: false). Use --optin to enable or --no-optin to explicitly disable.",
35
+ }),
36
+ action_type: Flags.string({
37
+ default: "email",
38
+ }),
39
+ firstname: Flags.string({
40
+ description: "supporter's firstname",
41
+ required: true,
42
+ }),
43
+ lastname: Flags.string(),
44
+ street: Flags.string(),
45
+ locality: Flags.string(),
46
+ region: Flags.string(),
47
+ country: Flags.string({
48
+ description: "2-letter country iso code",
49
+ parse: async (input) => {
50
+ if (input && !/^[A-Za-z]{2}$/.test(input)) {
51
+ throw new Error("Country code must be exactly 2 letters");
52
+ }
53
+ return input?.toUpperCase(); // optional: normalize to uppercase
54
+ },
55
+ }),
56
+ utm: Flags.string({
57
+ description: "utm=campaign.source.medium",
58
+ }),
59
+ email: Flags.string({
60
+ description: "email",
61
+ required: true,
62
+ }),
63
+ target: Flags.string({ description: "[mtt] uid of the target" }),
64
+ subject: Flags.string({ description: "[mtt] subject of the email" }),
65
+ body: Flags.string({ description: "[mtt] body of the email" }),
66
+ };
67
+
68
+ create = async (flags) => {
69
+ const values = {
70
+ action: {
71
+ actionType: flags.action_type,
72
+ customFields: flags.customFields,
73
+ /* "mtt": {
74
+ "body": "body",
75
+ "files": [
76
+ "files"
77
+ ],
78
+ "subject": "subject",
79
+ "targets": [
80
+ "targets"
81
+ ]
82
+ },
83
+ */
84
+ testing: flags.testing,
85
+ },
86
+ actionPageId: flags.id,
87
+ contact: {
88
+ address: {
89
+ country: flags.country,
90
+ locality: flags.locality,
91
+ postcode: flags.postcode,
92
+ region: flags.region,
93
+ street: flags.street,
94
+ // "streetNumber": "streetNumber"
95
+ },
96
+ email: flags.email,
97
+ firstName: flags.firstname,
98
+ lastName: flags.lastname,
99
+ phone: flags.phone,
100
+ },
101
+ privacy: {
102
+ // "leadOptIn": true,
103
+ optIn: flags.optin,
104
+ },
105
+ tracking: {
106
+ ...flags.tracking,
107
+ location: "proca-cli/action/add",
108
+ },
109
+ };
110
+
111
+ if (flags.target) {
112
+ values.action.mtt = {
113
+ targets: [flags.target],
114
+ subject: flags.subject || "Test MTT",
115
+ body: flags.body || "Please ignore, this is a test",
116
+ };
117
+ values.action.actionType = "mail2target";
118
+ }
119
+ console.log(values.action.mtt);
120
+
121
+ const query = gql`
122
+ mutation (
123
+ $action: ActionInput!
124
+ $actionPageId: Int!
125
+ $contact: ContactInput!
126
+ $contactRef: ID
127
+ $privacy: ConsentInput!
128
+ $tracking: TrackingInput
129
+ ) {
130
+ addActionContact(
131
+ action: $action
132
+ actionPageId: $actionPageId
133
+ contact: $contact
134
+ contactRef: $contactRef
135
+ privacy: $privacy
136
+ tracking: $tracking
137
+ ) {
138
+ contactRef
139
+ firstName
140
+ }
141
+ }`;
142
+
143
+ const result = await mutation(query, values);
144
+
145
+ console.log("result", result);
146
+ return result;
147
+ };
148
+
149
+ parseUnknownFlags = (argv) => {
150
+ const knownFlags = Object.entries(ActionAdd.flags).flatMap(([key, def]) => {
151
+ const chars = def.char ? [def.char] : [];
152
+ return [key, ...chars];
153
+ });
154
+ /* doesn't work static=false has no effect const unknownFlags = Object.fromEntries(
155
+ argv
156
+ .filter(arg =>
157
+ (/^--?\w+=/.test(arg)) // --key=val or -x=val
158
+ )
159
+ .map(arg => {
160
+ const keyval = arg.replace(/^-+/, '').split('=')
161
+ return [keyval[0], keyval[1]]
162
+ })
163
+ .filter(([key]) => !knownFlags.includes(key))
164
+ )
165
+ */
166
+
167
+ // Extract key=val style positional args (e.g. foo=bar)
168
+ const kvArgs = Object.fromEntries(
169
+ argv
170
+ .filter((arg) => !arg.startsWith("-") && arg.includes("="))
171
+ .map((arg) => arg.split("=")),
172
+ );
173
+
174
+ if (!Object.keys(kvArgs).length) return undefined;
175
+
176
+ return kvArgs;
177
+ };
178
+ async run() {
179
+ const { args, flags } = await this.parse(ActionAdd, {
180
+ context: { strict: false /* this does not work*/ },
181
+ });
182
+
183
+ const customFields = this.parseUnknownFlags(this.argv);
184
+ if (customFields) flags.customFields = JSON.stringify(customFields);
185
+ if (flags.utm) {
186
+ const [campaign, source, medium] = flags.utm.split(".");
187
+ flags.tracking = { source, medium, campaign };
188
+ } else flags.tracking = {};
189
+ const data = await this.create(flags);
190
+ return this.output(data);
191
+ }
192
+ }
@@ -62,6 +62,7 @@ export default class CampaignGet extends Command {
62
62
  name: name,
63
63
  withStats: this.flags.stats,
64
64
  });
65
+ result.campaign.config = JSON.parse(result.campaign.config);
65
66
  return result.campaign;
66
67
  };
67
68
 
@@ -74,6 +75,8 @@ export default class CampaignGet extends Command {
74
75
  Status: d.status,
75
76
  locales: d.config.locales && Object.keys(d.config.locales).join(" "),
76
77
  journey: d.config.journey?.join(" → "),
78
+ from: d.start?.substring(0, 10),
79
+ to: d.end?.substring(0, 10),
77
80
  };
78
81
  if (d.mtt) {
79
82
  // we have an mtt
@@ -83,8 +86,8 @@ export default class CampaignGet extends Command {
83
86
  minute: "2-digit",
84
87
  hour12: false,
85
88
  });
86
- result.from = d.mtt.startAt.substring(0, 10);
87
- result.to = d.mtt.endAt.substring(0, 10);
89
+ result["mtt from"] = d.mtt.startAt.substring(0, 10);
90
+ result["mttt to"] = d.mtt.endAt.substring(0, 10);
88
91
  result.period = `${hhmm(d.mtt.startAt)}↔${hhmm(d.mtt.endAt)}`;
89
92
  result["test email"] = d.mtt.testEmail;
90
93
  result["mtt template"] = d.mtt.template;
@@ -106,7 +109,6 @@ export default class CampaignGet extends Command {
106
109
  };
107
110
 
108
111
  table = (r) => {
109
- r.config = JSON.parse(r.config);
110
112
  super.table(r, null, null);
111
113
  if (this.flags.locale) {
112
114
  this.prettyJson(r.config?.locales[this.flags.locale]);
@@ -18,11 +18,11 @@ export default class CampaignList extends Command {
18
18
 
19
19
  static description = "list all the campaigns";
20
20
 
21
- // static args = this.multiid();
21
+ static args = this.namearg();
22
22
 
23
23
  static flags = {
24
24
  // flag with no value (-f, --force)
25
- ...this.flagify({ name: "name of the organisation" }),
25
+ ...this.flagify({ name: "name of the organisation", char: "o" }),
26
26
  title: Flags.string({
27
27
  char: "t",
28
28
  description: "name of the campaign",
@@ -111,7 +111,7 @@ export default class CampaignList extends Command {
111
111
 
112
112
  if (!flags.title && !flags.name) {
113
113
  throw new Error(
114
- `${this.id} -t [title of the campaign] or -o [organisation]`,
114
+ `${this.id} -t [title of the campaign] or -n [organisation]`,
115
115
  );
116
116
  }
117
117