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.
- package/README.md +1079 -28
- package/package.json +94 -101
- package/proca-cli +8 -0
- package/src/commands/action/count.mjs +61 -0
- package/src/commands/action/list.mjs +204 -0
- package/src/commands/action/replay.mjs +54 -0
- package/src/commands/campaign/add.mjs +101 -0
- package/src/commands/campaign/delete.mjs +61 -0
- package/src/commands/campaign/get.mjs +107 -0
- package/src/commands/campaign/list.mjs +156 -0
- package/src/commands/campaign/queries.graphql +19 -0
- package/src/commands/config/add.mjs +101 -0
- package/src/commands/config/get.mjs +33 -0
- package/src/commands/config/set.mjs +103 -0
- package/src/commands/config/token.mjs +34 -0
- package/src/commands/config/user.mjs +76 -0
- package/src/commands/org/add.mjs +66 -0
- package/src/commands/org/crm.mjs +88 -0
- package/src/commands/org/delete.mjs +48 -0
- package/src/commands/org/get.mjs +97 -0
- package/src/commands/org/join.mjs +77 -0
- package/src/commands/supporter/count.mjs +96 -0
- package/src/commands/user/get.mjs +91 -0
- package/src/commands/user/leave.mjs +52 -0
- package/src/commands/user/list.mjs +71 -0
- package/src/commands/widget/add.mjs +101 -0
- package/src/commands/widget/cache.mjs +29 -0
- package/src/commands/widget/get.mjs +59 -0
- package/src/commands/widget/list.mjs +116 -0
- package/src/config.mjs +36 -0
- package/src/generated/schema.json +10677 -0
- package/src/hooks/help.mjs +14 -0
- package/src/hooks/init.mjs +20 -0
- package/src/index.mjs +1 -0
- package/src/procaCommand.mjs +242 -0
- package/src/queries/campaign.mjs +21 -0
- package/src/queries/widget.mjs +12 -0
- package/src/urql.mjs +60 -0
- package/src/util/twitter.mjs +23 -0
- package/theme.json +29 -0
- package/LICENSE +0 -661
- package/dist/App.css +0 -22
- package/dist/App.js +0 -25
- package/dist/App.test.js +0 -8
- package/dist/Wizard.js +0 -32
- package/dist/components/Alert.js +0 -49
- package/dist/components/Clickify.js +0 -26
- package/dist/components/Consent.js +0 -120
- package/dist/components/Country.js +0 -94
- package/dist/components/Dialog.js +0 -84
- package/dist/components/Disabled.js +0 -3
- package/dist/components/Emoji.js +0 -12
- package/dist/components/FAB.js +0 -70
- package/dist/components/Html.js +0 -56
- package/dist/components/Loader.js +0 -14
- package/dist/components/Openletter.js +0 -443
- package/dist/components/Organisation.js +0 -181
- package/dist/components/Petition.js +0 -16
- package/dist/components/ProcaRoot.js +0 -23
- package/dist/components/ProcaStyle.js +0 -94
- package/dist/components/ProgressCounter.js +0 -64
- package/dist/components/Register.js +0 -345
- package/dist/components/Share.js +0 -177
- package/dist/components/TextField.js +0 -58
- package/dist/components/Twitter.js +0 -127
- package/dist/components/TwitterAction.js +0 -111
- package/dist/components/TwitterList.js +0 -25
- package/dist/components/TwitterText.js +0 -42
- package/dist/components/Widget.js +0 -266
- package/dist/components/bespoke/Download.js +0 -49
- package/dist/components/bespoke/Register-CH.js +0 -505
- package/dist/data/countries.json +0 -114
- package/dist/hooks/useConfig.js +0 -217
- package/dist/hooks/useCount.js +0 -95
- package/dist/hooks/useData.js +0 -59
- package/dist/hooks/useElementWidth.js +0 -46
- package/dist/hooks/useGeoLocation.js +0 -45
- package/dist/hooks/useLayout.js +0 -63
- package/dist/images/Twitter.js +0 -16
- package/dist/images/Twitter.svg +0 -1
- package/dist/index.css +0 -13
- package/dist/index.js +0 -114
- package/dist/lib/domparser.js +0 -12
- package/dist/lib/i18n.js +0 -40
- package/dist/lib/init.js +0 -7
- package/dist/lib/server.js +0 -331
- package/dist/lib/urlparser.js +0 -65
- package/dist/lib/uuid.js +0 -30
- package/dist/locales/README.md +0 -37
- package/dist/locales/common.json +0 -189
- package/dist/locales/de/common.json +0 -46
- package/dist/locales/de/index.js +0 -0
- package/dist/locales/en/common.json +0 -45
- package/dist/locales/fr/common.json +0 -51
- package/dist/locales/index.js +0 -27
- package/dist/locales/it/common.json +0 -46
- package/dist/logo.svg +0 -1
- package/dist/module.js +0 -14
- package/dist/slingshot.xcf +0 -0
- package/dist/tmp.config/0.json +0 -21
- package/dist/tmp.config/2.json +0 -11
- package/dist/tmp.config/20.json +0 -29
- package/dist/tmp.config/28.json +0 -14
- package/dist/tmp.config/32.json +0 -34
- package/dist/tmp.config/35.json +0 -14
- package/dist/tmp.config/null.json +0 -1
|
@@ -0,0 +1,66 @@
|
|
|
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 OrgAdd extends Command {
|
|
8
|
+
static args = {};
|
|
9
|
+
|
|
10
|
+
static examples = [
|
|
11
|
+
"<%= config.bin %> <%= command.id %> --twitter <twitter of the organisation>",
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
static flags = {
|
|
15
|
+
// flag with no value (-f, --force)
|
|
16
|
+
...super.globalFlags,
|
|
17
|
+
twitter: Flags.string({
|
|
18
|
+
description: "twitter account",
|
|
19
|
+
helpValue: "<screen name>",
|
|
20
|
+
}),
|
|
21
|
+
name: Flags.string({
|
|
22
|
+
char: "n",
|
|
23
|
+
description: "name of the org",
|
|
24
|
+
helpValue: "<org name>",
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
create = async (_org) => {
|
|
29
|
+
const org = { ..._org, config: JSON.stringify(_org.config) };
|
|
30
|
+
console.log(org);
|
|
31
|
+
|
|
32
|
+
const AddOrgDocument = gql`
|
|
33
|
+
mutation ($org: OrgInput!) {
|
|
34
|
+
addOrg(input: $org) {
|
|
35
|
+
config
|
|
36
|
+
name
|
|
37
|
+
title
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
const result = await mutation(AddOrgDocument, {
|
|
42
|
+
org,
|
|
43
|
+
});
|
|
44
|
+
if (!result.addOrg) {
|
|
45
|
+
console.log(result);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
return result?.addOrg;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
async run() {
|
|
52
|
+
const { args, flags } = await this.parse();
|
|
53
|
+
if (!flags.name && !flags.twitter) {
|
|
54
|
+
this.error("You must provide either --name or --twitter");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const org = { name: flags.twitter || flags.name, config: {} };
|
|
58
|
+
|
|
59
|
+
if (flags.twitter) {
|
|
60
|
+
await getTwitter(org);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const data = await this.create(org);
|
|
64
|
+
return this.output(data);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
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 {FragmentSummary,} from "#src/queries/org.mjs";
|
|
5
|
+
import { gql, mutation, query } from "#src/urql.mjs";
|
|
6
|
+
|
|
7
|
+
export default class OrgCRM extends Command {
|
|
8
|
+
static description = "view a org crm synchroniser";
|
|
9
|
+
|
|
10
|
+
static flags = {
|
|
11
|
+
// flag with no value (-f, --force)
|
|
12
|
+
...super.globalFlags,
|
|
13
|
+
name: Flags.string({
|
|
14
|
+
char: "n",
|
|
15
|
+
charAliases: ["o"],
|
|
16
|
+
required: true,
|
|
17
|
+
description: "name of the org",
|
|
18
|
+
helpValue: "<org name>",
|
|
19
|
+
}),
|
|
20
|
+
synchronize: Flags.boolean({
|
|
21
|
+
// default: undefined,
|
|
22
|
+
aliases: ["deliver", "enable"],
|
|
23
|
+
description: "enable or disable the synchronisation queue",
|
|
24
|
+
allowNo: true,
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
fetch = async (params) => {
|
|
29
|
+
const GetOrgDocument = gql`
|
|
30
|
+
query GetOrg($name: String!) {
|
|
31
|
+
org (name: $name) {
|
|
32
|
+
id name title
|
|
33
|
+
processing { customActionDeliver }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
const result = await query(GetOrgDocument, {
|
|
38
|
+
name: params.name,
|
|
39
|
+
});
|
|
40
|
+
return result.org;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
mutate = async (name, deliver) => {
|
|
44
|
+
const Document = gql`
|
|
45
|
+
mutation ($name: String!, $deliver: Boolean!) {
|
|
46
|
+
updateOrgProcessing (name: $name,customActionDeliver: $deliver) {
|
|
47
|
+
id, name, title, processing {customActionDeliver}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
console.log("deliver", deliver);
|
|
52
|
+
const result = await mutation(Document, {
|
|
53
|
+
name: name,
|
|
54
|
+
deliver: deliver,
|
|
55
|
+
});
|
|
56
|
+
console.log("deliver", deliver);
|
|
57
|
+
return result.updateOrgProcessing;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
simplify = (d) => {
|
|
61
|
+
const result = {
|
|
62
|
+
id: d.id,
|
|
63
|
+
name: d.name,
|
|
64
|
+
title: d.title,
|
|
65
|
+
deliver: d.processing.customActionDeliver,
|
|
66
|
+
queue: d.processing.customActionDeliver
|
|
67
|
+
? `cus.${d.id}.deliver`
|
|
68
|
+
: "call with --synchronize to enable",
|
|
69
|
+
};
|
|
70
|
+
return result;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
table = (r) => {
|
|
74
|
+
super.table(r, null, null);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
async run() {
|
|
78
|
+
const { args, flags } = await this.parse();
|
|
79
|
+
if (typeof flags.synchronize === "boolean") {
|
|
80
|
+
const data = await this.mutate(flags.name, flags.synchronize);
|
|
81
|
+
return this.output(data);
|
|
82
|
+
}
|
|
83
|
+
const data = await this.fetch(flags);
|
|
84
|
+
if (!data.processing.customActionDeliver)
|
|
85
|
+
this.info("actions aren't delivered, call with --synchronize to enable");
|
|
86
|
+
return this.output(data);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
|
|
6
|
+
export default class OrgDelete extends Command {
|
|
7
|
+
static examples = [
|
|
8
|
+
"<%= config.bin %> <%= command.id %> <organisation_name>",
|
|
9
|
+
];
|
|
10
|
+
static args = this.multiid();
|
|
11
|
+
|
|
12
|
+
static flags = {
|
|
13
|
+
// flag with no value (-f, --force)
|
|
14
|
+
...this.flagify({ multiid: true }),
|
|
15
|
+
name: Flags.string({
|
|
16
|
+
char: "n",
|
|
17
|
+
description: "name of the org",
|
|
18
|
+
helpValue: "<org name>",
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
delete = async (org) => {
|
|
23
|
+
console.log(org);
|
|
24
|
+
|
|
25
|
+
const DeleteOrgDocument = gql`
|
|
26
|
+
mutation ($org: String!) {
|
|
27
|
+
deleteOrg(name: $org)
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
const result = await mutation(DeleteOrgDocument, {
|
|
32
|
+
org,
|
|
33
|
+
});
|
|
34
|
+
console.log(result);
|
|
35
|
+
if (!result.deleteOrg) {
|
|
36
|
+
console.log(result);
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
return result?.deleteOrg;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
async run() {
|
|
43
|
+
const { args, flags } = await this.parse();
|
|
44
|
+
|
|
45
|
+
const data = await this.delete(flags.name);
|
|
46
|
+
return data;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
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 {FragmentSummary,} from "#src/queries/org.mjs";
|
|
5
|
+
import { gql, query } from "#src/urql.mjs";
|
|
6
|
+
|
|
7
|
+
export default class OrgGet extends Command {
|
|
8
|
+
static description = "view a org";
|
|
9
|
+
|
|
10
|
+
static examples = ["<%= config.bin %> <%= command.id %> <name of the ngo>"];
|
|
11
|
+
|
|
12
|
+
static args = this.multiid();
|
|
13
|
+
|
|
14
|
+
static flags = {
|
|
15
|
+
// flag with no value (-f, --force)
|
|
16
|
+
...this.flagify({ multiid: false }),
|
|
17
|
+
name: Flags.string({
|
|
18
|
+
char: "n",
|
|
19
|
+
charAliases: ["o"],
|
|
20
|
+
description: "name of the org",
|
|
21
|
+
helpValue: "<org name>",
|
|
22
|
+
}),
|
|
23
|
+
config: Flags.boolean({
|
|
24
|
+
description: "display the config",
|
|
25
|
+
default: false,
|
|
26
|
+
allowNo: true,
|
|
27
|
+
}),
|
|
28
|
+
keys: Flags.boolean({
|
|
29
|
+
default: true,
|
|
30
|
+
allowNo: true,
|
|
31
|
+
}),
|
|
32
|
+
campaigns: Flags.boolean({
|
|
33
|
+
default: false,
|
|
34
|
+
allowNo: true,
|
|
35
|
+
}),
|
|
36
|
+
widgets: Flags.boolean({
|
|
37
|
+
default: true,
|
|
38
|
+
allowNo: true,
|
|
39
|
+
}),
|
|
40
|
+
users: Flags.boolean({
|
|
41
|
+
default: true,
|
|
42
|
+
allowNo: true,
|
|
43
|
+
}),
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
fetch = async (params) => {
|
|
47
|
+
const GetOrgDocument = gql`
|
|
48
|
+
query GetOrg($name: String!, $withCampaigns: Boolean = true) {
|
|
49
|
+
org (name: $name) {
|
|
50
|
+
id name title
|
|
51
|
+
config
|
|
52
|
+
campaigns @include(if: $withCampaigns) {id, name, title, org {name}}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
`;
|
|
56
|
+
const result = await query(GetOrgDocument, {
|
|
57
|
+
name: params.name,
|
|
58
|
+
withCampaigns: params.campaigns,
|
|
59
|
+
});
|
|
60
|
+
// result.org.config = JSON.parse (result.org.config);
|
|
61
|
+
return result.org;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
simplify = (d) => {
|
|
65
|
+
const result = {
|
|
66
|
+
id: d.id,
|
|
67
|
+
Name: d.name,
|
|
68
|
+
Title: d.title,
|
|
69
|
+
};
|
|
70
|
+
if (this.flags.stats) {
|
|
71
|
+
result["#Supporters"] = d.stats.supporterCount;
|
|
72
|
+
|
|
73
|
+
this.actionTypes.forEach((type) => {
|
|
74
|
+
const action = d.stats.actionCount.find(
|
|
75
|
+
(action) => action.actionType === type,
|
|
76
|
+
);
|
|
77
|
+
if (action) result[`#${type}`] = action.count;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
table = (r) => {
|
|
84
|
+
r.config = JSON.parse(r.config);
|
|
85
|
+
super.table(r, null, null);
|
|
86
|
+
if (this.flags.config) {
|
|
87
|
+
r.config.locales = undefined;
|
|
88
|
+
this.prettyJson(r.config);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
async run() {
|
|
93
|
+
const { args, flags } = await this.parse();
|
|
94
|
+
const data = await this.fetch(flags);
|
|
95
|
+
return this.output(data);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
|
|
6
|
+
export default class UserJoinOrg extends Command {
|
|
7
|
+
static description = "let a user join an organisation with a role";
|
|
8
|
+
|
|
9
|
+
static examples = ["<%= config.bin %> <%= command.id %>"];
|
|
10
|
+
|
|
11
|
+
static flags = {
|
|
12
|
+
...super.globalFlags,
|
|
13
|
+
user: Flags.string({ description: "user email" }),
|
|
14
|
+
role: Flags.string({
|
|
15
|
+
description: "permission level in that org",
|
|
16
|
+
default: "campaigner",
|
|
17
|
+
options: ["owner", "campaigner", "coordinator", "translator"],
|
|
18
|
+
}),
|
|
19
|
+
org: Flags.string({
|
|
20
|
+
char: "o",
|
|
21
|
+
required: true,
|
|
22
|
+
description: "name of the org",
|
|
23
|
+
helpValue: "<org name>",
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
join = async (org) => {
|
|
28
|
+
const Document = gql`
|
|
29
|
+
mutation ($name: String!) {
|
|
30
|
+
joinOrg(name: $name) {
|
|
31
|
+
org {
|
|
32
|
+
config
|
|
33
|
+
name
|
|
34
|
+
title
|
|
35
|
+
}
|
|
36
|
+
status
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
const result = await mutation(Document, {
|
|
41
|
+
name: org,
|
|
42
|
+
});
|
|
43
|
+
console.log(result);
|
|
44
|
+
return result.status;
|
|
45
|
+
//return result.users.map (d => {d.config = JSON.parse(d.config); return d});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
mutate = async (params) => {
|
|
49
|
+
const Document = gql`
|
|
50
|
+
mutation ($org: String!, $user: String!, $role: String = "campaigner") {
|
|
51
|
+
addOrgUser (orgName: $org, input : { email: $user, role: $role }) {
|
|
52
|
+
status
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
`;
|
|
56
|
+
const result = await mutation(Document, {
|
|
57
|
+
user: params.user,
|
|
58
|
+
org: params.org,
|
|
59
|
+
role: params.role,
|
|
60
|
+
});
|
|
61
|
+
console.log(result);
|
|
62
|
+
return result.status;
|
|
63
|
+
//return result.users.map (d => {d.config = JSON.parse(d.config); return d});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
async run() {
|
|
67
|
+
console.log("WIP, probably not working");
|
|
68
|
+
const { args, flags } = await this.parse();
|
|
69
|
+
|
|
70
|
+
if (!flags.user) {
|
|
71
|
+
data = await this.join(flags.org);
|
|
72
|
+
} else {
|
|
73
|
+
data = await this.mutate(flags);
|
|
74
|
+
}
|
|
75
|
+
console.log(data);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
static description = "counter of supporters";
|
|
7
|
+
|
|
8
|
+
static examples = [
|
|
9
|
+
"<%= config.bin %> <%= command.id %> --id <id of the campaign>",
|
|
10
|
+
"<%= config.bin %> <%= command.id %> --name <name of the campaign>",
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
static args = this.multiid();
|
|
14
|
+
static flags = {
|
|
15
|
+
// flag with no value (-f, --force)
|
|
16
|
+
...this.flagify({ multiid: true }),
|
|
17
|
+
org: Flags.boolean({
|
|
18
|
+
description: "segment by partner",
|
|
19
|
+
default: false,
|
|
20
|
+
}),
|
|
21
|
+
area: Flags.boolean({
|
|
22
|
+
description: "segment by area",
|
|
23
|
+
default: false,
|
|
24
|
+
}),
|
|
25
|
+
without: Flags.string({
|
|
26
|
+
description: "total to add to the partner's counter",
|
|
27
|
+
}),
|
|
28
|
+
number: Flags.boolean({
|
|
29
|
+
description: "just return the number to add to the partner's counter",
|
|
30
|
+
dependsOn: ["without"],
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
fetchExcluding = async (params) => {
|
|
35
|
+
const GetCounterDocument = gql`
|
|
36
|
+
query GetCounter($name: String, $id: Int, $without: String!) {
|
|
37
|
+
campaign(name: $name, id: $id) {
|
|
38
|
+
stats {
|
|
39
|
+
supporterCount
|
|
40
|
+
supporterCountByOthers (orgName: $without)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}`;
|
|
44
|
+
|
|
45
|
+
const result = await query(GetCounterDocument, params);
|
|
46
|
+
return result.campaign.stats;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
fetch = async (params) => {
|
|
50
|
+
const GetCounterDocument = gql`
|
|
51
|
+
query GetCounter($name: String, $id: Int, $org: Boolean = false, $area: Boolean = false) {
|
|
52
|
+
campaign(name: $name, id: $id) {
|
|
53
|
+
stats {
|
|
54
|
+
supporterCount
|
|
55
|
+
supporterCountByOrg @include(if: $org) { org { name } count }
|
|
56
|
+
supporterCountByArea @include(if: $area) { area count }
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}`;
|
|
60
|
+
|
|
61
|
+
const result = await query(GetCounterDocument, params);
|
|
62
|
+
return result.campaign.stats;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
simplify = (d) => {
|
|
66
|
+
const result = { total: d.supporterCount };
|
|
67
|
+
d.supporterCountByOrg
|
|
68
|
+
?.sort((a, b) => b.count - a.count)
|
|
69
|
+
.forEach((org) => {
|
|
70
|
+
result[org.org.name] = org.count;
|
|
71
|
+
});
|
|
72
|
+
d.supporterCountByArea
|
|
73
|
+
?.sort((a, b) => b.count - a.count)
|
|
74
|
+
.forEach((area) => {
|
|
75
|
+
result[area.area] = area.count;
|
|
76
|
+
});
|
|
77
|
+
if (d.supporterCountByOthers) {
|
|
78
|
+
result[`without ${this.flags.without}`] = d.supporterCountByOthers;
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
table = (r) => {
|
|
83
|
+
super.table(r, null, null);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
async run() {
|
|
87
|
+
const { args, flags } = await this.parse();
|
|
88
|
+
if (flags.without) {
|
|
89
|
+
const data = await this.fetchExcluding(flags);
|
|
90
|
+
if (flags.number) return console.log(data.supporterCountByOthers);
|
|
91
|
+
return this.output(data);
|
|
92
|
+
}
|
|
93
|
+
const data = await this.fetch(flags);
|
|
94
|
+
return this.output(data);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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 UserList extends Command {
|
|
7
|
+
static description = "fetch the information about a user";
|
|
8
|
+
|
|
9
|
+
static examples = ["<%= config.bin %> <%= command.id %>"];
|
|
10
|
+
|
|
11
|
+
static flags = {
|
|
12
|
+
...super.globalFlags,
|
|
13
|
+
email: Flags.string({ description: "user email" }),
|
|
14
|
+
org: Flags.string({
|
|
15
|
+
char: "o",
|
|
16
|
+
description: "name of the org",
|
|
17
|
+
exactlyOne: ["email", "id", "org"],
|
|
18
|
+
helpValue: "<org name>",
|
|
19
|
+
}),
|
|
20
|
+
id: Flags.string({
|
|
21
|
+
char: "i",
|
|
22
|
+
parse: (input) => {
|
|
23
|
+
return Number.parseInt(input, 10);
|
|
24
|
+
},
|
|
25
|
+
description: "id of the user",
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
fetch = async (params) => {
|
|
30
|
+
const Document = gql`
|
|
31
|
+
query ($email: String, $org: String, $id: Int) {
|
|
32
|
+
users (select: {email: $email, orgName: $org, id: $id}) {
|
|
33
|
+
apiToken {
|
|
34
|
+
expiresAt
|
|
35
|
+
}
|
|
36
|
+
email
|
|
37
|
+
id
|
|
38
|
+
isAdmin
|
|
39
|
+
jobTitle
|
|
40
|
+
phone
|
|
41
|
+
pictureUrl
|
|
42
|
+
roles {
|
|
43
|
+
role org {name}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
const result = await query(Document, {
|
|
49
|
+
org: params.org,
|
|
50
|
+
id: params.id,
|
|
51
|
+
email: params.email,
|
|
52
|
+
});
|
|
53
|
+
return result.users[0];
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
simplify = (d) => {
|
|
57
|
+
const result = {
|
|
58
|
+
id: d.id,
|
|
59
|
+
email: d.email,
|
|
60
|
+
};
|
|
61
|
+
if (d.apiToken) {
|
|
62
|
+
result.tokenExpire = d.apiToken.expire;
|
|
63
|
+
}
|
|
64
|
+
if (d.isAdmin) {
|
|
65
|
+
result.admin = true;
|
|
66
|
+
}
|
|
67
|
+
const roles = d.roles.reduce((acc, item) => {
|
|
68
|
+
if (!acc[item.role]) {
|
|
69
|
+
acc[item.role] = [];
|
|
70
|
+
}
|
|
71
|
+
acc[item.role].push(item.org.name);
|
|
72
|
+
return acc;
|
|
73
|
+
}, {});
|
|
74
|
+
for (const role in roles) {
|
|
75
|
+
result[role] = roles[role].join(",");
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
table = (r) => {
|
|
81
|
+
super.table(r, null, null);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
async run() {
|
|
85
|
+
const { args, flags } = await this.parse();
|
|
86
|
+
let data = [];
|
|
87
|
+
|
|
88
|
+
data = await this.fetch(flags);
|
|
89
|
+
return this.output(data);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
|
|
6
|
+
export default class OrgLeave extends Command {
|
|
7
|
+
actionTypes = new Set();
|
|
8
|
+
|
|
9
|
+
static args = {};
|
|
10
|
+
|
|
11
|
+
static description = "leave a org";
|
|
12
|
+
|
|
13
|
+
static examples = ["<%= config.bin %> <%= command.id %> -i 42"];
|
|
14
|
+
|
|
15
|
+
static flags = {
|
|
16
|
+
// flag with no value (-f, --force)
|
|
17
|
+
...super.globalFlags,
|
|
18
|
+
email: Flags.string({
|
|
19
|
+
description: "email",
|
|
20
|
+
required: true,
|
|
21
|
+
helpValue: "<user email>",
|
|
22
|
+
}),
|
|
23
|
+
org: Flags.string({
|
|
24
|
+
char: "o",
|
|
25
|
+
description: "name of the org",
|
|
26
|
+
required: true,
|
|
27
|
+
helpValue: "<org name>",
|
|
28
|
+
}),
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
mutate = async ({ email, org }) => {
|
|
32
|
+
const Document = gql`
|
|
33
|
+
mutation ($email: String!, $org: String!) {
|
|
34
|
+
deleteOrgUser(email: $email, orgName: $org) { status }
|
|
35
|
+
}`;
|
|
36
|
+
const result = await mutation(Document, {
|
|
37
|
+
email: email,
|
|
38
|
+
org: org,
|
|
39
|
+
});
|
|
40
|
+
return result.deleteOrgUser.status;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
table = (r) => {
|
|
44
|
+
super.table(r, null, null);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
async run() {
|
|
48
|
+
const { args, flags } = await this.parse();
|
|
49
|
+
const data = await this.mutate(flags);
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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 UserList extends Command {
|
|
7
|
+
actionTypes = new Set();
|
|
8
|
+
|
|
9
|
+
static description = "list all the users";
|
|
10
|
+
|
|
11
|
+
static examples = ["<%= config.bin %> <%= command.id %> %pizza%"];
|
|
12
|
+
|
|
13
|
+
static flags = {
|
|
14
|
+
// flag with no value (-f, --force)
|
|
15
|
+
...super.globalFlags,
|
|
16
|
+
org: Flags.string({
|
|
17
|
+
char: "o",
|
|
18
|
+
description: "organisation",
|
|
19
|
+
required: true,
|
|
20
|
+
}),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
fetch = async (org) => {
|
|
24
|
+
const SearchUsersDocument = gql`
|
|
25
|
+
query ($org: String!) {
|
|
26
|
+
users(select: {orgName: $org}) {
|
|
27
|
+
apiToken {
|
|
28
|
+
expiresAt
|
|
29
|
+
}
|
|
30
|
+
email
|
|
31
|
+
id
|
|
32
|
+
isAdmin
|
|
33
|
+
jobTitle
|
|
34
|
+
phone
|
|
35
|
+
pictureUrl
|
|
36
|
+
roles {
|
|
37
|
+
role org {name}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
const result = await query(SearchUsersDocument, { org: org });
|
|
43
|
+
return result.users;
|
|
44
|
+
//return result.users.map (d => {d.config = JSON.parse(d.config); return d});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
simplify = (d) => {
|
|
48
|
+
const result = {
|
|
49
|
+
id: d.id,
|
|
50
|
+
email: d.email,
|
|
51
|
+
};
|
|
52
|
+
result.role = d.roles.filter((d) => d.org.name === this.flags.org)[0].role;
|
|
53
|
+
if (d.isAdmin) {
|
|
54
|
+
result.superadmin = true;
|
|
55
|
+
}
|
|
56
|
+
if (d.apiToken) {
|
|
57
|
+
result.tokenExpire = d.apiToken.tokenExpire;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return result;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
async run() {
|
|
64
|
+
const { args, flags } = await this.parse(UserList);
|
|
65
|
+
let data = [];
|
|
66
|
+
|
|
67
|
+
data = await this.fetch(flags.org);
|
|
68
|
+
|
|
69
|
+
return this.output(data);
|
|
70
|
+
}
|
|
71
|
+
}
|