proca 0.8.1 → 1.1.5

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.
Files changed (106) hide show
  1. package/README.md +1079 -28
  2. package/package.json +94 -101
  3. package/proca-cli +8 -0
  4. package/src/commands/action/count.mjs +61 -0
  5. package/src/commands/action/list.mjs +204 -0
  6. package/src/commands/action/replay.mjs +54 -0
  7. package/src/commands/campaign/add.mjs +101 -0
  8. package/src/commands/campaign/delete.mjs +61 -0
  9. package/src/commands/campaign/get.mjs +107 -0
  10. package/src/commands/campaign/list.mjs +156 -0
  11. package/src/commands/campaign/queries.graphql +19 -0
  12. package/src/commands/config/add.mjs +101 -0
  13. package/src/commands/config/get.mjs +33 -0
  14. package/src/commands/config/set.mjs +103 -0
  15. package/src/commands/config/token.mjs +34 -0
  16. package/src/commands/config/user.mjs +76 -0
  17. package/src/commands/org/add.mjs +66 -0
  18. package/src/commands/org/crm.mjs +88 -0
  19. package/src/commands/org/delete.mjs +48 -0
  20. package/src/commands/org/get.mjs +97 -0
  21. package/src/commands/org/join.mjs +77 -0
  22. package/src/commands/supporter/count.mjs +96 -0
  23. package/src/commands/user/get.mjs +91 -0
  24. package/src/commands/user/leave.mjs +52 -0
  25. package/src/commands/user/list.mjs +71 -0
  26. package/src/commands/widget/add.mjs +101 -0
  27. package/src/commands/widget/cache.mjs +29 -0
  28. package/src/commands/widget/get.mjs +59 -0
  29. package/src/commands/widget/list.mjs +116 -0
  30. package/src/config.mjs +36 -0
  31. package/src/generated/schema.json +10677 -0
  32. package/src/hooks/help.mjs +14 -0
  33. package/src/hooks/init.mjs +20 -0
  34. package/src/index.mjs +1 -0
  35. package/src/procaCommand.mjs +242 -0
  36. package/src/queries/campaign.mjs +21 -0
  37. package/src/queries/widget.mjs +12 -0
  38. package/src/urql.mjs +60 -0
  39. package/src/util/twitter.mjs +23 -0
  40. package/theme.json +29 -0
  41. package/LICENSE +0 -661
  42. package/dist/App.css +0 -22
  43. package/dist/App.js +0 -25
  44. package/dist/App.test.js +0 -8
  45. package/dist/Wizard.js +0 -32
  46. package/dist/components/Alert.js +0 -49
  47. package/dist/components/Clickify.js +0 -26
  48. package/dist/components/Consent.js +0 -120
  49. package/dist/components/Country.js +0 -94
  50. package/dist/components/Dialog.js +0 -84
  51. package/dist/components/Disabled.js +0 -3
  52. package/dist/components/Emoji.js +0 -12
  53. package/dist/components/FAB.js +0 -70
  54. package/dist/components/Html.js +0 -56
  55. package/dist/components/Loader.js +0 -14
  56. package/dist/components/Openletter.js +0 -443
  57. package/dist/components/Organisation.js +0 -181
  58. package/dist/components/Petition.js +0 -16
  59. package/dist/components/ProcaRoot.js +0 -23
  60. package/dist/components/ProcaStyle.js +0 -94
  61. package/dist/components/ProgressCounter.js +0 -64
  62. package/dist/components/Register.js +0 -345
  63. package/dist/components/Share.js +0 -177
  64. package/dist/components/TextField.js +0 -58
  65. package/dist/components/Twitter.js +0 -127
  66. package/dist/components/TwitterAction.js +0 -111
  67. package/dist/components/TwitterList.js +0 -25
  68. package/dist/components/TwitterText.js +0 -42
  69. package/dist/components/Widget.js +0 -266
  70. package/dist/components/bespoke/Download.js +0 -49
  71. package/dist/components/bespoke/Register-CH.js +0 -505
  72. package/dist/data/countries.json +0 -114
  73. package/dist/hooks/useConfig.js +0 -217
  74. package/dist/hooks/useCount.js +0 -95
  75. package/dist/hooks/useData.js +0 -59
  76. package/dist/hooks/useElementWidth.js +0 -46
  77. package/dist/hooks/useGeoLocation.js +0 -45
  78. package/dist/hooks/useLayout.js +0 -63
  79. package/dist/images/Twitter.js +0 -16
  80. package/dist/images/Twitter.svg +0 -1
  81. package/dist/index.css +0 -13
  82. package/dist/index.js +0 -114
  83. package/dist/lib/domparser.js +0 -12
  84. package/dist/lib/i18n.js +0 -40
  85. package/dist/lib/init.js +0 -7
  86. package/dist/lib/server.js +0 -331
  87. package/dist/lib/urlparser.js +0 -65
  88. package/dist/lib/uuid.js +0 -30
  89. package/dist/locales/README.md +0 -37
  90. package/dist/locales/common.json +0 -189
  91. package/dist/locales/de/common.json +0 -46
  92. package/dist/locales/de/index.js +0 -0
  93. package/dist/locales/en/common.json +0 -45
  94. package/dist/locales/fr/common.json +0 -51
  95. package/dist/locales/index.js +0 -27
  96. package/dist/locales/it/common.json +0 -46
  97. package/dist/logo.svg +0 -1
  98. package/dist/module.js +0 -14
  99. package/dist/slingshot.xcf +0 -0
  100. package/dist/tmp.config/0.json +0 -21
  101. package/dist/tmp.config/2.json +0 -11
  102. package/dist/tmp.config/20.json +0 -29
  103. package/dist/tmp.config/28.json +0 -14
  104. package/dist/tmp.config/32.json +0 -34
  105. package/dist/tmp.config/35.json +0 -14
  106. package/dist/tmp.config/null.json +0 -1
package/package.json CHANGED
@@ -1,103 +1,96 @@
1
1
  {
2
- "name": "proca",
3
- "version": "0.8.1",
4
- "private": false,
5
- "files": [
6
- "dist",
7
- "README.md"
8
- ],
9
- "main": "dist/module.js",
10
- "licence": "aGPL3",
11
- "nope.resolutions": {
12
- "@babel/preset-env": "^7.8.7"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "https://github.com/TechToThePeople/proca"
17
- },
18
- "peerDependencies": {
19
- "@material-ui/core": "^4.11.0",
20
- "@material-ui/icons": "^4.9.1",
21
- "@material-ui/lab": "^4.0.0-alpha.56",
22
- "base64url": "^3.0.1",
23
- "i18next": "^19.6.3",
24
- "react": "^16.13.1",
25
- "react-dom": "^16.13.1",
26
- "react-hook-form": "^3.28.2",
27
- "react-i18next": "^11.7.0",
28
- "react-share": "^4.2.1",
29
- "recoil": "^0.0.10",
30
- "uuid": "^8.3.0"
31
- },
32
- "dependencies": {
33
- "@alienfast/i18next-loader": "^1.1.4",
34
- "base64url": "^3.0.1",
35
- "dotenv": "^8.2.0",
36
- "global": "^4.4.0",
37
- "i18next": "^19.6.3",
38
- "i18next-extract": "^0.1.3",
39
- "i18next-xhr-backend": "^3.2.2",
40
- "page-metadata-parser": "^1.1.4",
41
- "react-i18next": "^11.7.0",
42
- "react-ipgeolocation": "^1.3.0",
43
- "react-share": "^4.2.1",
44
- "recoil": "^0.0.10",
45
- "uuid": "^8.3.0"
46
- },
47
- "devDependencies": {
48
- "@babel/cli": "^7.10.5",
49
- "@babel/plugin-proposal-class-properties": "^7.10.4",
50
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.10.4",
51
- "@babel/plugin-proposal-optional-chaining": "^7.11.0",
52
- "@babel/plugin-transform-object-assign": "^7.10.4",
53
- "@material-ui/core": "^4.11.0",
54
- "@material-ui/icons": "^4.9.1",
55
- "@material-ui/lab": "^4.0.0-alpha.54",
56
- "@svgr/webpack": "5.4.0",
57
- "@testing-library/jest-dom": "^4.2.4",
58
- "@testing-library/react": "^9.3.2",
59
- "@testing-library/user-event": "^7.1.2",
60
- "babel-plugin-module-resolver": "^4.0.0",
61
- "babel-plugin-optimize-clsx": "^2.6.1",
62
- "compression-webpack-plugin": "^4.0.0",
63
- "customize-cra": "^1.0.0",
64
- "customize-cra-react-refresh": "^1.1.0",
65
- "js-yaml": "^3.14.0",
66
- "react": "^16.13.1",
67
- "react-app-rewired": "^2.1.6",
68
- "react-dom": "^16.13.1",
69
- "react-hook-form-input": "^1.0.8",
70
- "react-hot-loader": "^4.12.21",
71
- "react-scripts": "3.4.2",
72
- "react-test-renderer": "^16.12.0",
73
- "webpack-hot-middleware": "^2.25.0",
74
- "webpack-visualizer-plugin": "^0.1.11",
75
- "yarn": "^1.21.1"
76
- },
77
- "scripts": {
78
- "nope.prepublish": "babel src --out-dir lib",
79
- "prepublishOnly": "node src/locales/index.js && rm -r dist/* && babel src --out-dir dist --copy-files",
80
- "start": "react-app-rewired start",
81
- "build": "react-app-rewired build",
82
- "test": "react-app-rewired test --env=jsdom",
83
- "eject": "react-scripts eject",
84
- "ostart": "node scripts/start.js",
85
- "obuild": "node scripts/build.js",
86
- "otest": "node scripts/test.js"
87
- },
88
- "eslintConfig": {
89
- "extends": "react-app"
90
- },
91
- "browserslist": {
92
- "production": [
93
- ">0.2%",
94
- "not dead",
95
- "not op_mini all"
96
- ],
97
- "development": [
98
- "last 1 chrome version",
99
- "last 1 firefox version",
100
- "last 1 safari version"
101
- ]
102
- }
2
+ "name": "proca",
3
+ "description": "Access the proca api",
4
+ "version": "1.1.5",
5
+ "author": "Xavier",
6
+ "bin": {
7
+ "proca": "proca-cli"
8
+ },
9
+ "bugs": "https://github.com/fixthestatusquo/git@github.com:fixthestatusquo/proca-cli.git/issues",
10
+ "dependencies": {
11
+ "@oclif/core": "^4.2.10",
12
+ "@oclif/plugin-help": "^6",
13
+ "@oclif/plugin-plugins": "^5",
14
+ "@urql/exchange-auth": "^2.2.0",
15
+ "dotenv": "^16.4.5",
16
+ "dxid": "^2.2.1",
17
+ "easy-table": "^1.2.0",
18
+ "fast-csv": "^5.0.1",
19
+ "graphql": "^16.10.0",
20
+ "typescript": "^5.7.3",
21
+ "urql": "^4.1.0"
22
+ },
23
+ "devDependencies": {
24
+ "@biomejs/biome": "^1.9.3",
25
+ "@graphql-codegen/cli": "^2.x.x",
26
+ "@graphql-codegen/introspection": "^2.x.x",
27
+ "@graphql-codegen/typescript-operations": "^4.2.3",
28
+ "@graphql-codegen/typescript-urql": "^4.0.0",
29
+ "@oclif/plugin-autocomplete": "^3.2.5",
30
+ "@oclif/plugin-commands": "^4.1.3",
31
+ "@oclif/plugin-not-found": "^3.2.22",
32
+ "lefthook": "^1.7.18",
33
+ "oclif": "^4.17.46"
34
+ },
35
+ "engines": {
36
+ "node": ">=18.0.0"
37
+ },
38
+ "files": ["/proca-cli", "/src", "/theme.json"],
39
+ "homepage": "https://github.com/fixthestatusquo/git@github.com:fixthestatusquo/proca-cli.git",
40
+ "keywords": [
41
+ "cli",
42
+ "petition",
43
+ "proca",
44
+ "campaigning",
45
+ "digital-engagement",
46
+ "social-change",
47
+ "nonprofit",
48
+ "civic-tech",
49
+ "mobilisation",
50
+ "advocacy",
51
+ "activism",
52
+ "email-campaign",
53
+ "grassroots",
54
+ "gdpr"
55
+ ],
56
+ "imports": {
57
+ "#src/*": "./src/*"
58
+ },
59
+ "license": "aGPL3",
60
+ "main": "./proca-cli",
61
+ "oclif": {
62
+ "repository": "github:fixthestatusquo/proca-cli",
63
+ "bin": "proca",
64
+ "theme": "theme.json",
65
+ "topicSeparator": " ",
66
+ "commands": "./src/commands",
67
+ "helpClass": "./src/hooks/help.mjs",
68
+ "topics": {
69
+ "widget": {
70
+ "description": "widgets (actionPages in the API)"
71
+ },
72
+ "campaign": {
73
+ "description": "campaigns"
74
+ },
75
+ "user": {
76
+ "description": "campaigners and other users"
77
+ }
78
+ },
79
+ "plugins": [
80
+ "@oclif/plugin-plugins",
81
+ "@oclif/plugin-help",
82
+ "@oclif/plugin-commands"
83
+ ]
84
+ },
85
+ "repository": {
86
+ "type": "git",
87
+ "url": "git+ssh://git@github.com/fixthestatusquo/proca-cli.git"
88
+ },
89
+ "scripts": {
90
+ "check": "npx @biomejs/biome check --write",
91
+ "format": "npx @biomejs/biome format --write",
92
+ "lint": "npx @biomejs/biome lint --write",
93
+ "prepack": "oclif manifest && oclif readme",
94
+ "version": "oclif readme && git add README.md"
95
+ }
103
96
  }
package/proca-cli ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env -S node --trace-warnings
2
+ const url = require('url');
3
+
4
+ (async () => {
5
+ const metaUrl = url.pathToFileURL(__filename).href;
6
+ const { execute } = await import('@oclif/core');
7
+ await execute({ dir: metaUrl });
8
+ })();
@@ -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
+ }
@@ -0,0 +1,204 @@
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 {
5
+ FragmentOrg,
6
+ FragmentStats,
7
+ FragmentSummary,
8
+ } from "#src/queries/campaign.mjs";
9
+ import { gql, query } from "#src/urql.mjs";
10
+
11
+ export default class CampaignList extends Command {
12
+ actionTypes = new Set();
13
+
14
+ static args = {
15
+ title: Args.string({ description: "name of the campaign, % for wildchar" }),
16
+ };
17
+
18
+ static examples = ["<%= config.bin %> <%= command.id %> %pizza%"];
19
+
20
+ static flags = {
21
+ // flag with no value (-f, --force)
22
+ ...super.globalFlags,
23
+ org: Flags.string({
24
+ char: "o",
25
+ description: "campaigns of the organisation (coordinator or partner)",
26
+ required: true,
27
+ // exactlyOne: ["org", "title"],
28
+ helpValue: "<organisation name>",
29
+ }),
30
+ campaign: Flags.string({
31
+ char: "c",
32
+ description: "name of the campaign, % for wildchar",
33
+ helpValue: "<campaign title>",
34
+ }),
35
+ limit: Flags.string({
36
+ description: "max number of actions",
37
+ parse: (input) => Number.parseInt(input, 10),
38
+ }),
39
+ after: Flags.string({
40
+ description: "only actions after a date",
41
+ helpValue: "2025-04-09",
42
+ parse: (input) => new Date(input).toISOString(),
43
+ }),
44
+ today: Flags.boolean({
45
+ description: "only actions today",
46
+ exclusive: ["after"],
47
+ parse: (input) => `${new Date().toISOString().split("T")[0]}T00:00:00Z`,
48
+ }),
49
+ optin: Flags.boolean({
50
+ description: "only export the optin actions",
51
+ default: false,
52
+ }),
53
+ testing: Flags.boolean({
54
+ description: "also export the test actions",
55
+ default: false,
56
+ }),
57
+ doi: Flags.boolean({
58
+ description: "only export the double optin actions",
59
+ default: false,
60
+ }),
61
+ utm: Flags.boolean({
62
+ description: "display the utm tracking parameters",
63
+ default: true,
64
+ allowNo: true,
65
+ exclusive: ["simplify"],
66
+ }),
67
+ comment: Flags.boolean({
68
+ description: "display the comment",
69
+ default: true,
70
+ allowNo: true,
71
+ exclusive: ["simplify"],
72
+ }),
73
+ };
74
+
75
+ fetch = async (flags) => {
76
+ const Document = gql`
77
+ query (
78
+ $after: DateTime
79
+ $campaignId: Int
80
+ $campaignName: String
81
+ $includeTesting: Boolean
82
+ $limit: Int
83
+ $onlyDoubleOptIn: Boolean
84
+ $onlyOptIn: Boolean
85
+ $orgName: String!
86
+ $start: Int
87
+ ) {
88
+ exportActions(
89
+ after: $after
90
+ campaignId: $campaignId
91
+ campaignName: $campaignName
92
+ includeTesting: $includeTesting
93
+ limit: $limit
94
+ onlyDoubleOptIn: $onlyDoubleOptIn
95
+ onlyOptIn: $onlyOptIn
96
+ orgName: $orgName
97
+ start: $start
98
+ ) {
99
+ actionId
100
+ actionPage {
101
+ locale
102
+ name
103
+ }
104
+ actionType
105
+ campaign {
106
+ name
107
+ }
108
+ contact {
109
+ contactRef
110
+ payload
111
+ nonce
112
+ publicKey {
113
+ public
114
+ }
115
+ }
116
+ createdAt
117
+ customFields
118
+ privacy {
119
+ emailStatus
120
+ emailStatusChanged
121
+ givenAt
122
+ optIn
123
+ withConsent
124
+ }
125
+ tracking {
126
+ campaign
127
+ content
128
+ medium
129
+ source
130
+ }
131
+ }
132
+ }
133
+ `;
134
+ const result = await query(Document, {
135
+ after: flags.after,
136
+ // "campaignId": 42,
137
+ campaignName: flags.campaign,
138
+ includeTesting: flags.testing,
139
+ limit: flags.limit,
140
+ onlyDoubleOptIn: flags.doi,
141
+ onlyOptIn: flags.optin,
142
+ orgName: flags.org,
143
+ start: flags.start,
144
+ });
145
+ return result.exportActions.map((d) => {
146
+ d.customFields = JSON.parse(d.customFields);
147
+ if (!d.contact.publicKey) {
148
+ const ref = d.contactRef;
149
+ d.contact = JSON.parse(d.contact.payload);
150
+ d.contact.contactRef = ref;
151
+ } else {
152
+ this.error(
153
+ `encrypted contact we need the private key for ${d.contact.publicKey.public}`,
154
+ );
155
+ }
156
+ return d;
157
+ });
158
+ // return result.exportActions;
159
+ };
160
+
161
+ simplify = (d) => {
162
+ const result = {
163
+ id: d.actionId,
164
+ firstname: d.contact.firstName,
165
+ country: d.contact.country,
166
+ email: d.contact.email,
167
+ type: d.actionType,
168
+ date: d.createdAt,
169
+ campaign: d.campaign.name,
170
+ widget_id: d.actionPage.id,
171
+ widget: d.actionPage.name,
172
+ // customFields
173
+ };
174
+ if (this.flags.comment && d.customFields?.comment)
175
+ result.comment = d.customFields.comment;
176
+ if (d.customFields?.emailProvider)
177
+ result.provider = d.customFields.emailProvider;
178
+ if (this.flags.utm && d.tracking) {
179
+ result.utm_medium =
180
+ d.tracking.medium === "unknown" ? undefined : d.tracking.medium;
181
+ result.utm_source =
182
+ d.tracking.source === "unknown" ? undefined : d.tracking.source;
183
+ result.utm_campaign =
184
+ d.tracking.campaign === "unknown" ? undefined : d.tracking.campaign;
185
+ if (d.tracking.content)
186
+ result.utm_content =
187
+ d.tracking.content === "unknown" ? undefined : d.tracking.content;
188
+ }
189
+ return result;
190
+ };
191
+
192
+ _table = (r) => {
193
+ super.table(r, null, (table) => table.sort(["id|des"]).toString());
194
+ };
195
+
196
+ async run() {
197
+ const { args, flags } = await this.parse();
198
+ if (flags.today) flags.after = flags.today;
199
+ let data = [];
200
+
201
+ data = await this.fetch(flags);
202
+ return this.output(data);
203
+ }
204
+ }
@@ -0,0 +1,54 @@
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, query } from "#src/urql.mjs";
5
+
6
+ export default class ReplayAction extends Command {
7
+ static examples = ["<%= config.bin %> <%= command.id %> %pizza%"];
8
+
9
+ static flags = {
10
+ // flag with no value (-f, --force)
11
+ ...super.globalFlags,
12
+ org: Flags.string({
13
+ char: "o",
14
+ description: "campaigns of the organisation (coordinator or partner)",
15
+ required: true,
16
+ // exactlyOne: ["org", "title"],
17
+ helpValue: "<organisation name>",
18
+ }),
19
+ /* queue: Flag.string({
20
+ default: "CUSTOM_ACTION_DELIVER",
21
+ options: [
22
+ 'CUSTOM_ACTION_CONFIRM',
23
+ 'CUSTOM_ACTION_DELIVER',
24
+ 'CUSTOM_SUPPORTER_CONFIRM',
25
+ 'EMAIL_SUPPORTER',
26
+ 'SQS',
27
+ 'WEBHOOK'
28
+ ],
29
+ }),
30
+ */
31
+ campaign: Flags.string({
32
+ char: "c",
33
+ description: "name of the campaign, % for wildchar",
34
+ helpValue: "<campaign title>",
35
+ }),
36
+ };
37
+
38
+ mutate = async (org, id, queue) => {
39
+ const Document = gql`
40
+ mutation Requeue($org: String!, $ids: [Int!]!, $queue: Queue!){
41
+ requeueActions(orgName:$org, ids: $ids, queue: $queue) {
42
+ count failed
43
+ }
44
+ }`;
45
+ };
46
+
47
+ async run() {
48
+ const { args, flags } = await this.parse();
49
+ let data = [];
50
+ const ids = [];
51
+ data = await this.mutate(flags.org, ids, flags.queue);
52
+ return this.output(data);
53
+ }
54
+ }
@@ -0,0 +1,101 @@
1
+ import { Args, Flags } from "@oclif/core";
2
+ import { error, stdout, ux } from "@oclif/core/ux";
3
+ import OrgGet from "#src/commands/org/get.mjs";
4
+ import Command from "#src/procaCommand.mjs";
5
+ import { gql, mutation } from "#src/urql.mjs";
6
+ import { getTwitter } from "#src/util/twitter.mjs";
7
+
8
+ export default class CampaignAdd extends Command {
9
+ static args = {
10
+ title: Args.string({
11
+ description: "title of the campaign",
12
+ multiple: true,
13
+ }),
14
+ };
15
+ // static strict = false;
16
+
17
+ static examples = [
18
+ "<%= config.bin %> <%= command.id %> -n <new_campaign> the full name of the campaign",
19
+ ];
20
+
21
+ static flags = {
22
+ // flag with no value (-f, --force)
23
+ ...super.globalFlags,
24
+ name: Flags.string({
25
+ char: "n",
26
+ description: "name of the campaign",
27
+ helpValue: "<campaign name>",
28
+ required: true,
29
+ }),
30
+ org: Flags.string({
31
+ char: "o",
32
+ description: "name of the coordinator",
33
+ helpValue: "<org name>",
34
+ required: true,
35
+ }),
36
+ };
37
+
38
+ create = async (campaign) => {
39
+ const org = await this.getOrg(campaign.org);
40
+
41
+ const config = {
42
+ locales: {
43
+ en: {
44
+ "campaign:": {
45
+ description: "",
46
+ },
47
+ "common:": {},
48
+ },
49
+ },
50
+ };
51
+ if (org.config.locale && org.config.locale !== "en") {
52
+ config.locales[org.config.locale] = {};
53
+ }
54
+ if (!config.portal) {
55
+ config.portal = [];
56
+ }
57
+ const AddOrgDocument = gql`
58
+ mutation ($org: String!
59
+ $name: String!
60
+ $title: String!
61
+ $config: Json!
62
+ ) {
63
+ addCampaign (input: { name: $name, title: $title, config: $config }, orgName: $org) {
64
+ name
65
+ title
66
+ config
67
+ }
68
+ }
69
+ `;
70
+ const result = await mutation(AddOrgDocument, {
71
+ org: org.name,
72
+ name: campaign.name,
73
+ title: campaign.title,
74
+ config: JSON.stringify(config),
75
+ });
76
+
77
+ console.log("result", result);
78
+ return result;
79
+ };
80
+
81
+ async getOrg(orgName) {
82
+ const { config } = this;
83
+ const orgGet = new OrgGet({}, this.config);
84
+ const org = await orgGet.fetch({ name: orgName });
85
+ return org;
86
+ }
87
+
88
+ async run() {
89
+ //const { args, flags } = await this.parse(CampaignAdd);
90
+ const { args, flags } = await this.parse();
91
+
92
+ const campaign = {
93
+ org: flags.org,
94
+ name: flags.name,
95
+ title: args.title || flags.name,
96
+ };
97
+
98
+ const data = await this.create(campaign);
99
+ return this.output(data);
100
+ }
101
+ }