@proca/cli 3.3.1 → 3.8.3
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 +1992 -60
- package/package.json +88 -71
- package/proca-cli +8 -0
- package/src/commands/action/add.mjs +192 -0
- package/src/commands/action/confirm.mjs +93 -0
- package/src/commands/action/count.mjs +61 -0
- package/src/commands/action/list.mjs +204 -0
- package/src/commands/action/replay.mjs +56 -0
- package/src/commands/action/requeue.mjs +156 -0
- package/src/commands/campaign/add.mjs +113 -0
- package/src/commands/campaign/copy.mjs +91 -0
- package/src/commands/campaign/delete.mjs +41 -0
- package/src/commands/campaign/get.mjs +132 -0
- package/src/commands/campaign/list.mjs +161 -0
- package/src/commands/campaign/mtt.mjs +131 -0
- package/src/commands/campaign/queries.graphql +19 -0
- package/src/commands/campaign/status.mjs +63 -0
- package/src/commands/campaign/widget/archive.mjs +124 -0
- package/src/commands/campaign/widget/copy.mjs +175 -0
- package/src/commands/campaign/widget/get.mjs +19 -0
- package/src/commands/campaign/widget/index.mjs +17 -0
- package/src/commands/campaign/widget/rebuild.mjs +50 -0
- package/src/commands/config/add.mjs +97 -0
- package/src/commands/config/folder.mjs +42 -0
- package/src/commands/config/server.mjs +33 -0
- package/src/commands/config/set.mjs +103 -0
- package/src/commands/config/user.mjs +79 -0
- package/src/commands/contact/count.mjs +41 -0
- package/src/commands/contact/list.mjs +207 -0
- package/src/commands/org/add.mjs +75 -0
- package/src/commands/org/crm.mjs +88 -0
- package/src/commands/org/delete.mjs +48 -0
- package/src/commands/org/email.mjs +111 -0
- package/src/commands/org/get.mjs +152 -0
- package/src/commands/service/add.mjs +78 -0
- package/src/commands/service/list.mjs +24 -0
- package/src/commands/target/add.mjs +94 -0
- package/src/commands/template/add.mjs +97 -0
- package/src/commands/template/list.mjs +61 -0
- package/src/commands/user/get.mjs +91 -0
- package/src/commands/user/invite.mjs +56 -0
- package/src/commands/user/join.mjs +81 -0
- package/src/commands/user/leave.mjs +57 -0
- package/src/commands/user/list.mjs +80 -0
- package/src/commands/user/reset.mjs +83 -0
- package/src/commands/widget/add.mjs +116 -0
- package/src/commands/widget/delete.mjs +45 -0
- package/src/commands/widget/get.mjs +60 -0
- package/src/commands/widget/list.mjs +135 -0
- package/src/commands/widget/rebuild.mjs +64 -0
- package/src/commands/widget/update.mjs +174 -0
- package/src/config.mjs +49 -0
- package/src/generated/schema.json +10677 -0
- package/src/hooks/help.mjs +14 -0
- package/src/hooks/init.mjs +41 -0
- package/src/index.mjs +1 -0
- package/src/procaCommand.mjs +316 -0
- package/src/queries/campaign.mjs +35 -0
- package/src/queries/widget.mjs +25 -0
- package/src/urql.mjs +60 -0
- package/src/util/twitter.mjs +23 -0
- package/theme.json +29 -0
- package/LICENSE +0 -661
- package/bin/proca-cli +0 -4
- package/dist/a.d.ts +0 -1
- package/dist/a.js +0 -21
- package/dist/a.js.map +0 -1
- package/dist/browser.d.ts +0 -1
- package/dist/browser.js +0 -24
- package/dist/browser.js.map +0 -1
- package/dist/campaign.d.ts +0 -156
- package/dist/campaign.js +0 -188
- package/dist/campaign.js.map +0 -1
- package/dist/cli.d.ts +0 -40
- package/dist/cli.js +0 -411
- package/dist/cli.js.map +0 -1
- package/dist/client.d.ts +0 -2
- package/dist/client.js +0 -18
- package/dist/client.js.map +0 -1
- package/dist/config.d.ts +0 -35
- package/dist/config.js +0 -71
- package/dist/config.js.map +0 -1
- package/dist/crypto.d.ts +0 -40
- package/dist/crypto.js +0 -53
- package/dist/crypto.js.map +0 -1
- package/dist/decrypt.d.ts +0 -7
- package/dist/decrypt.js +0 -29
- package/dist/decrypt.js.map +0 -1
- package/dist/export.d.ts +0 -15
- package/dist/export.js +0 -141
- package/dist/export.js.map +0 -1
- package/dist/format.d.ts +0 -37
- package/dist/format.js +0 -200
- package/dist/format.js.map +0 -1
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -35
- package/dist/index.js.map +0 -1
- package/dist/keys.d.ts +0 -4
- package/dist/keys.js +0 -38
- package/dist/keys.js.map +0 -1
- package/dist/org.d.ts +0 -11
- package/dist/org.js +0 -93
- package/dist/org.js.map +0 -1
- package/dist/proca.d.ts +0 -2066
- package/dist/proca.js +0 -396
- package/dist/proca.js.map +0 -1
- package/dist/queue.d.ts +0 -8
- package/dist/queue.js +0 -126
- package/dist/queue.js.map +0 -1
- package/dist/queueMessage.d.ts +0 -102
- package/dist/queueMessage.js +0 -109
- package/dist/queueMessage.js.map +0 -1
- package/dist/scalarLocations.d.ts +0 -4
- package/dist/scalarLocations.js +0 -236
- package/dist/scalarLocations.js.map +0 -1
- package/dist/service/actionnetwork.d.ts +0 -10
- package/dist/service/actionnetwork.js +0 -302
- package/dist/service/actionnetwork.js.map +0 -1
- package/dist/service/distance.d.ts +0 -3
- package/dist/service/distance.js +0 -92
- package/dist/service/distance.js.map +0 -1
- package/dist/service/echo.d.ts +0 -4
- package/dist/service/echo.js +0 -19
- package/dist/service/echo.js.map +0 -1
- package/dist/service/email.d.ts +0 -14
- package/dist/service/email.js +0 -67
- package/dist/service/email.js.map +0 -1
- package/dist/service/identity.d.ts +0 -58
- package/dist/service/identity.js +0 -190
- package/dist/service/identity.js.map +0 -1
- package/dist/service/index.d.ts +0 -14
- package/dist/service/index.js +0 -61
- package/dist/service/index.js.map +0 -1
- package/dist/setup.d.ts +0 -2
- package/dist/setup.js +0 -287
- package/dist/setup.js.map +0 -1
- package/dist/test.d.ts +0 -1
- package/dist/test.js +0 -33
- package/dist/test.js.map +0 -1
- package/dist/util.d.ts +0 -5
- package/dist/util.js +0 -30
- package/dist/util.js.map +0 -1
- package/dist/watch.d.ts +0 -9
- package/dist/watch.js +0 -76
- package/dist/watch.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,83 +1,100 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proca/cli",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"browser": "dist/browser.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"sideEffects": false,
|
|
9
|
-
"repository": "git@github.com:TechToThePeople/proca-gw.git",
|
|
10
|
-
"author": "xavier.dutoit <xavier@tttp.eu>",
|
|
11
|
-
"license": "AGPL-3.0",
|
|
3
|
+
"description": "Access the proca api",
|
|
4
|
+
"version": "3.8.3",
|
|
5
|
+
"author": "Xavier",
|
|
12
6
|
"bin": {
|
|
13
|
-
"proca
|
|
7
|
+
"proca": "proca-cli"
|
|
14
8
|
},
|
|
15
|
-
"
|
|
16
|
-
"test": "echo No tests for proca/cli",
|
|
17
|
-
"build": "npx tsc",
|
|
18
|
-
"watch": "npx tsc -w",
|
|
19
|
-
"codegen": "yarn graphql-codegen",
|
|
20
|
-
"prepack": "yarn codegen && yarn build"
|
|
21
|
-
},
|
|
22
|
-
"files": [
|
|
23
|
-
"dist",
|
|
24
|
-
"bin",
|
|
25
|
-
"README.md"
|
|
26
|
-
],
|
|
9
|
+
"bugs": "https://github.com/fixthestatusquo/git@github.com:fixthestatusquo/proca-cli.git/issues",
|
|
27
10
|
"dependencies": {
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"node-fetch": "^2.6.1",
|
|
43
|
-
"node-mailjet": "^3.3.1",
|
|
44
|
-
"tweetnacl": "^1.0.3",
|
|
45
|
-
"tweetnacl-util": "^0.15.1",
|
|
46
|
-
"urql-serialize-scalars-exchange": "1.0.5-0",
|
|
47
|
-
"yargs": "^16.2.0"
|
|
11
|
+
"@oclif/core": "^4.2.10",
|
|
12
|
+
"@oclif/plugin-help": "^6",
|
|
13
|
+
"@oclif/plugin-plugins": "^5",
|
|
14
|
+
"@urql/exchange-auth": "^2.2.0",
|
|
15
|
+
"date-fns": "^4.1.0",
|
|
16
|
+
"dotenv": "^16.4.5",
|
|
17
|
+
"dxid": "^2.2.1",
|
|
18
|
+
"easy-table": "^1.2.0",
|
|
19
|
+
"fast-csv": "^5.0.1",
|
|
20
|
+
"graphql": "^16.10.0",
|
|
21
|
+
"merge-anything": "^6.0.6",
|
|
22
|
+
"prompts": "^2.4.2",
|
|
23
|
+
"typescript": "^5.7.3",
|
|
24
|
+
"urql": "^4.1.0"
|
|
48
25
|
},
|
|
49
26
|
"devDependencies": {
|
|
50
|
-
"@
|
|
51
|
-
"@graphql-codegen/
|
|
52
|
-
"@graphql-codegen/
|
|
53
|
-
"@graphql-codegen/typescript": "^
|
|
54
|
-
"@graphql-codegen/typescript-
|
|
55
|
-
"@
|
|
56
|
-
"@
|
|
57
|
-
"@
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"@types/line-by-line": "^0.1.4",
|
|
61
|
-
"@types/lodash": "^4.14.168",
|
|
62
|
-
"@types/node": "^14.14.7",
|
|
63
|
-
"@types/yargs": "^16.0.0",
|
|
64
|
-
"codegen-graphql-scalar-locations": "1.0.0-0",
|
|
65
|
-
"ketting": "^7.2.0",
|
|
66
|
-
"ts-node": "^10.2.1"
|
|
27
|
+
"@biomejs/biome": "^1.9.3",
|
|
28
|
+
"@graphql-codegen/cli": "^2.x.x",
|
|
29
|
+
"@graphql-codegen/introspection": "^2.x.x",
|
|
30
|
+
"@graphql-codegen/typescript-operations": "^4.2.3",
|
|
31
|
+
"@graphql-codegen/typescript-urql": "^4.0.0",
|
|
32
|
+
"@oclif/plugin-autocomplete": "^3.2.5",
|
|
33
|
+
"@oclif/plugin-commands": "^4.1.3",
|
|
34
|
+
"@oclif/plugin-not-found": "^3.2.22",
|
|
35
|
+
"lefthook": "^1.7.18",
|
|
36
|
+
"oclif": "^4.17.46"
|
|
67
37
|
},
|
|
68
|
-
"
|
|
69
|
-
"
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18.0.0"
|
|
70
40
|
},
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
"
|
|
41
|
+
"files": ["/proca-cli", "/src", "/theme.json"],
|
|
42
|
+
"homepage": "https://github.com/fixthestatusquo/git@github.com:fixthestatusquo/proca-cli.git",
|
|
43
|
+
"keywords": [
|
|
44
|
+
"cli",
|
|
45
|
+
"petition",
|
|
46
|
+
"proca",
|
|
47
|
+
"campaigning",
|
|
48
|
+
"digital-engagement",
|
|
49
|
+
"social-change",
|
|
50
|
+
"nonprofit",
|
|
51
|
+
"civic-tech",
|
|
52
|
+
"mobilisation",
|
|
53
|
+
"advocacy",
|
|
54
|
+
"activism",
|
|
55
|
+
"email-campaign",
|
|
56
|
+
"grassroots",
|
|
57
|
+
"gdpr"
|
|
58
|
+
],
|
|
59
|
+
"imports": {
|
|
60
|
+
"#src/*": "./src/*"
|
|
61
|
+
},
|
|
62
|
+
"license": "aGPL3",
|
|
63
|
+
"main": "./proca-cli",
|
|
64
|
+
"oclif": {
|
|
65
|
+
"repository": "github:fixthestatusquo/proca-cli",
|
|
66
|
+
"bin": "proca",
|
|
67
|
+
"theme": "theme.json",
|
|
68
|
+
"topicSeparator": " ",
|
|
69
|
+
"commands": "./src/commands",
|
|
70
|
+
"helpClass": "./src/hooks/help.mjs",
|
|
71
|
+
"topics": {
|
|
72
|
+
"widget": {
|
|
73
|
+
"description": "widgets (actionPages in the API)"
|
|
74
|
+
},
|
|
75
|
+
"campaign": {
|
|
76
|
+
"description": "campaigns"
|
|
77
|
+
},
|
|
78
|
+
"user": {
|
|
79
|
+
"description": "campaigners and other users"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"plugins": [
|
|
83
|
+
"@oclif/plugin-plugins",
|
|
84
|
+
"@oclif/plugin-help",
|
|
85
|
+
"@oclif/plugin-commands"
|
|
86
|
+
]
|
|
75
87
|
},
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"debug": "^4.3.1",
|
|
80
|
-
"node-mailjet": "^3.3.1"
|
|
88
|
+
"repository": {
|
|
89
|
+
"type": "git",
|
|
90
|
+
"url": "git+ssh://git@github.com/fixthestatusquo/proca-cli.git"
|
|
81
91
|
},
|
|
82
|
-
"
|
|
92
|
+
"scripts": {
|
|
93
|
+
"check": "npx @biomejs/biome check --write",
|
|
94
|
+
"format": "npx @biomejs/biome format --write",
|
|
95
|
+
"lint": "npx @biomejs/biome lint --write",
|
|
96
|
+
"prepack": "oclif manifest && oclif readme",
|
|
97
|
+
"oclif": "oclif manifest && oclif readme",
|
|
98
|
+
"version": "oclif readme && git add README.md"
|
|
99
|
+
}
|
|
83
100
|
}
|
package/proca-cli
ADDED
|
@@ -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: "register",
|
|
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
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Flags } from "@oclif/core";
|
|
2
|
+
import Command from "#src/procaCommand.mjs";
|
|
3
|
+
import { gql, mutation, query } from "#src/urql.mjs";
|
|
4
|
+
|
|
5
|
+
export default class Actionconfirm extends Command {
|
|
6
|
+
static description =
|
|
7
|
+
"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";
|
|
8
|
+
|
|
9
|
+
static flags = {
|
|
10
|
+
...super.globalFlags,
|
|
11
|
+
org: Flags.string({
|
|
12
|
+
aliases: ["name", "o"],
|
|
13
|
+
description: "organisation collecting the action",
|
|
14
|
+
exactlyOne: ["org", "campaign"],
|
|
15
|
+
}),
|
|
16
|
+
campaign: Flags.string({
|
|
17
|
+
aliases: ["c"],
|
|
18
|
+
description: "campaign collecting the action",
|
|
19
|
+
}),
|
|
20
|
+
confirm: Flags.boolean({
|
|
21
|
+
description: "should the supporters confirm each action",
|
|
22
|
+
default: true,
|
|
23
|
+
allowNo: true,
|
|
24
|
+
}),
|
|
25
|
+
template: Flags.string({
|
|
26
|
+
description: "template for sending the message",
|
|
27
|
+
}),
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
async mutate(flags) {
|
|
31
|
+
const DocumentOrg = gql`
|
|
32
|
+
mutation UpdateOrgProcessing(
|
|
33
|
+
$name: String!
|
|
34
|
+
$confirm: Boolean!
|
|
35
|
+
$template: String
|
|
36
|
+
) {
|
|
37
|
+
updateOrgProcessing(
|
|
38
|
+
name: $name
|
|
39
|
+
supporterConfirmTemplate: $template
|
|
40
|
+
supporterConfirm: $confirm
|
|
41
|
+
) {
|
|
42
|
+
id
|
|
43
|
+
name
|
|
44
|
+
processing {
|
|
45
|
+
supporterConfirm
|
|
46
|
+
supporterConfirmTemplate
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
const DocumentCampaign = gql`
|
|
52
|
+
mutation UpdateCampaignProcessing(
|
|
53
|
+
$name: String!
|
|
54
|
+
$confirm: Boolean!
|
|
55
|
+
$template: String
|
|
56
|
+
) {
|
|
57
|
+
updateCampaignProcessing(
|
|
58
|
+
name: $name
|
|
59
|
+
supporterConfirmTemplate: $template
|
|
60
|
+
supporterConfirm: $confirm
|
|
61
|
+
) {
|
|
62
|
+
id
|
|
63
|
+
name
|
|
64
|
+
campaignProcessing {
|
|
65
|
+
supporterConfirm
|
|
66
|
+
supporterConfirmTemplate
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
`;
|
|
71
|
+
const Document = flags.org ? DocumentOrg : DocumentCampaign;
|
|
72
|
+
|
|
73
|
+
const result = await mutation(Document, {
|
|
74
|
+
name: flags.org || flags.campaign,
|
|
75
|
+
confirm: flags.confirm,
|
|
76
|
+
template: flags.template,
|
|
77
|
+
});
|
|
78
|
+
return result.updateOrgProcessing || result.updateCommandProcessing;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
simplify = (d) => ({
|
|
82
|
+
id: d.id,
|
|
83
|
+
name: d.name,
|
|
84
|
+
template: d.processing.supporterConfirmTemplate,
|
|
85
|
+
confirm: d.processing.supporterConfirm,
|
|
86
|
+
});
|
|
87
|
+
async run() {
|
|
88
|
+
const { flags } = await this.parse();
|
|
89
|
+
const result = await this.mutate(flags);
|
|
90
|
+
|
|
91
|
+
this.output(result);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Args, Flags } from "@oclif/core";
|
|
2
|
+
import Command from "#src/procaCommand.mjs";
|
|
3
|
+
import { gql, query } from "#src/urql.mjs";
|
|
4
|
+
|
|
5
|
+
export default class CounterGet extends Command {
|
|
6
|
+
ignored = ["share_confirmed"];
|
|
7
|
+
secondary = ["share"];
|
|
8
|
+
|
|
9
|
+
static description = "counter of actions";
|
|
10
|
+
|
|
11
|
+
static examples = [
|
|
12
|
+
"<%= config.bin %> <%= command.id %> --id <id of the campaign>",
|
|
13
|
+
"<%= config.bin %> <%= command.id %> --name <name of the campaign>",
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
static args = this.multiid();
|
|
17
|
+
static flags = {
|
|
18
|
+
// flag with no value (-f, --force)
|
|
19
|
+
...this.flagify({ multiid: true }),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
fetch = async (params) => {
|
|
23
|
+
const GetCounterDocument = gql`
|
|
24
|
+
query GetCounter($name: String, $id: Int) {
|
|
25
|
+
campaign(name: $name, id: $id) {
|
|
26
|
+
stats {
|
|
27
|
+
actionCount {actionType, count}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
const result = await query(GetCounterDocument, params);
|
|
33
|
+
return result.campaign.stats;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
simplify = (d) => {
|
|
37
|
+
const result = { sharer: undefined };
|
|
38
|
+
let primary = 0;
|
|
39
|
+
let secondary = 0;
|
|
40
|
+
d.actionCount.forEach((type) => {
|
|
41
|
+
if (this.ignored.includes(type.actionType)) return;
|
|
42
|
+
if (this.secondary.includes(type.actionType)) {
|
|
43
|
+
secondary += type.count;
|
|
44
|
+
} else {
|
|
45
|
+
primary += type.count;
|
|
46
|
+
}
|
|
47
|
+
result[type.actionType] = type.count;
|
|
48
|
+
});
|
|
49
|
+
if (primary) result.sharer = `${Math.round((100 * secondary) / primary)}%`;
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
table = (r) => {
|
|
53
|
+
super.table(r, null, null);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
async run() {
|
|
57
|
+
const { args, flags } = await this.parse();
|
|
58
|
+
const data = await this.fetch(flags);
|
|
59
|
+
return this.output(data);
|
|
60
|
+
}
|
|
61
|
+
}
|