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,61 @@
|
|
|
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, mutation } from "#src/urql.mjs";
|
|
10
|
+
|
|
11
|
+
export default class CampaignDelete extends Command {
|
|
12
|
+
actionTypes = new Set();
|
|
13
|
+
|
|
14
|
+
static args = {};
|
|
15
|
+
|
|
16
|
+
static description = "delete a campaign";
|
|
17
|
+
|
|
18
|
+
static examples = ["<%= config.bin %> <%= command.id %> -i 42"];
|
|
19
|
+
|
|
20
|
+
static flags = {
|
|
21
|
+
// flag with no value (-f, --force)
|
|
22
|
+
...super.globalFlags,
|
|
23
|
+
id: Flags.string({
|
|
24
|
+
char: "i",
|
|
25
|
+
parse: (input) => {
|
|
26
|
+
return Number.parseInt(input, 10);
|
|
27
|
+
},
|
|
28
|
+
description: "id of the campaign",
|
|
29
|
+
exactlyOne: ["id", "name"],
|
|
30
|
+
helpValue: "<organisation name>",
|
|
31
|
+
}),
|
|
32
|
+
name: Flags.string({
|
|
33
|
+
char: "n",
|
|
34
|
+
description: "name of the campaign",
|
|
35
|
+
helpValue: "<campaign name>",
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
mutate = async ({ id, name }) => {
|
|
40
|
+
const Document = gql`
|
|
41
|
+
mutation ($id: Int, $name: String) {
|
|
42
|
+
deleteCampaign(id: $id, name: $name)
|
|
43
|
+
}`;
|
|
44
|
+
const result = await mutation(Document, {
|
|
45
|
+
id: id,
|
|
46
|
+
name: name,
|
|
47
|
+
});
|
|
48
|
+
return result.deleteCampaign;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
table = (r) => {
|
|
52
|
+
super.table(r, null, null);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
async run() {
|
|
56
|
+
const { args, flags } = await this.parse();
|
|
57
|
+
|
|
58
|
+
const data = await this.mutate({ id: flags.id, name: flags.name });
|
|
59
|
+
return this.output(data);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
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 CampaignGet extends Command {
|
|
12
|
+
actionTypes = new Set();
|
|
13
|
+
|
|
14
|
+
static args = this.multiid();
|
|
15
|
+
|
|
16
|
+
static description = "view a campaign";
|
|
17
|
+
|
|
18
|
+
static examples = ["<%= config.bin %> <%= command.id %> -i 42"];
|
|
19
|
+
|
|
20
|
+
static flags = {
|
|
21
|
+
// flag with no value (-f, --force)
|
|
22
|
+
...this.flagify({ multiid: true }),
|
|
23
|
+
config: Flags.boolean({
|
|
24
|
+
description: "display the config",
|
|
25
|
+
default: false,
|
|
26
|
+
allowNo: true,
|
|
27
|
+
}),
|
|
28
|
+
stats: Flags.boolean({
|
|
29
|
+
description: "display the stats",
|
|
30
|
+
default: true,
|
|
31
|
+
allowNo: true,
|
|
32
|
+
}),
|
|
33
|
+
locale: Flags.string({
|
|
34
|
+
description: "display a locale",
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
fetch = async ({ id, name }) => {
|
|
39
|
+
const GetCampaignDocument = gql`
|
|
40
|
+
query GetCampaign($id: Int, $name: String, $withStats: Boolean = false) {
|
|
41
|
+
campaign (name: $name, id: $id) {
|
|
42
|
+
...Summary
|
|
43
|
+
...Org
|
|
44
|
+
config
|
|
45
|
+
...Stats @include(if: $withStats)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
${FragmentStats}
|
|
49
|
+
${FragmentSummary}
|
|
50
|
+
${FragmentOrg}
|
|
51
|
+
`;
|
|
52
|
+
const result = await query(GetCampaignDocument, {
|
|
53
|
+
id: id,
|
|
54
|
+
name: name,
|
|
55
|
+
withStats: this.flags.stats,
|
|
56
|
+
});
|
|
57
|
+
return result.campaign;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
simplify = (d) => {
|
|
61
|
+
const result = {
|
|
62
|
+
id: d.id,
|
|
63
|
+
Name: d.name,
|
|
64
|
+
Title: d.title,
|
|
65
|
+
Org: d.org.name,
|
|
66
|
+
Status: d.status,
|
|
67
|
+
locales: d.config.locales && Object.keys(d.config.locales).join(" "),
|
|
68
|
+
journey: d.config.journey?.join(" → "),
|
|
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.locale) {
|
|
87
|
+
this.prettyJson(r.config?.locales[this.flags.locale]);
|
|
88
|
+
}
|
|
89
|
+
if (this.flags.config) {
|
|
90
|
+
r.config.locales = undefined;
|
|
91
|
+
this.prettyJson(r.config);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
async run() {
|
|
96
|
+
const { args, flags } = await this.parse();
|
|
97
|
+
|
|
98
|
+
const data = await this.fetch({ id: flags.id, name: flags.name });
|
|
99
|
+
if (this.flags.stats) {
|
|
100
|
+
data.stats.actionCount.forEach((d) => {
|
|
101
|
+
//skip share_confirmed?
|
|
102
|
+
this.actionTypes.add(d.actionType);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return this.output(data);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
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 description = "list all the campaigns";
|
|
19
|
+
|
|
20
|
+
static examples = ["<%= config.bin %> <%= command.id %> %pizza%"];
|
|
21
|
+
|
|
22
|
+
static flags = {
|
|
23
|
+
// flag with no value (-f, --force)
|
|
24
|
+
...super.globalFlags,
|
|
25
|
+
org: Flags.string({
|
|
26
|
+
char: "o",
|
|
27
|
+
description: "campaigns of the organisation (coordinator or partner)",
|
|
28
|
+
exactlyOne: ["org", "title"],
|
|
29
|
+
helpValue: "<organisation name>",
|
|
30
|
+
}),
|
|
31
|
+
title: Flags.string({
|
|
32
|
+
char: "t",
|
|
33
|
+
description: "name of the campaign, % for wildchar",
|
|
34
|
+
helpValue: "<campaign title>",
|
|
35
|
+
}),
|
|
36
|
+
stats: Flags.boolean({
|
|
37
|
+
description: "display the stats",
|
|
38
|
+
default: true,
|
|
39
|
+
allowNo: true,
|
|
40
|
+
}),
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
OrgSearch = async (name) => {
|
|
44
|
+
const SearchCampaignsDocument = gql`
|
|
45
|
+
query SearchCampaigns($org: String!, $withStats: Boolean = false) {
|
|
46
|
+
org (name:$org) {
|
|
47
|
+
campaigns {
|
|
48
|
+
...Summary
|
|
49
|
+
...Org
|
|
50
|
+
...Stats @include(if: $withStats)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
${FragmentStats}
|
|
55
|
+
${FragmentOrg}
|
|
56
|
+
${FragmentSummary}
|
|
57
|
+
`;
|
|
58
|
+
const result = await query(SearchCampaignsDocument, {
|
|
59
|
+
org: name,
|
|
60
|
+
withStats: this.flags.stats,
|
|
61
|
+
});
|
|
62
|
+
return result.org.campaigns;
|
|
63
|
+
//return result.campaigns.map (d => {d.config = JSON.parse(d.config); return d});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
Search = async (title) => {
|
|
67
|
+
const SearchCampaignsDocument = gql`
|
|
68
|
+
query SearchCampaigns($title: String!, $withStats: Boolean = false) {
|
|
69
|
+
campaigns(title: $title) {
|
|
70
|
+
...Summary
|
|
71
|
+
...Org
|
|
72
|
+
...Stats @include(if: $withStats)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
${FragmentStats}
|
|
76
|
+
${FragmentOrg}
|
|
77
|
+
${FragmentSummary}
|
|
78
|
+
`;
|
|
79
|
+
const result = await query(SearchCampaignsDocument, {
|
|
80
|
+
title: title,
|
|
81
|
+
withStats: this.flags.stats,
|
|
82
|
+
});
|
|
83
|
+
return result.campaigns;
|
|
84
|
+
//return result.campaigns.map (d => {d.config = JSON.parse(d.config); return d});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
simplify = (d) => {
|
|
88
|
+
const result = {
|
|
89
|
+
id: d.id,
|
|
90
|
+
Name: d.name,
|
|
91
|
+
Title: d.title,
|
|
92
|
+
Org: d.org.name,
|
|
93
|
+
Status: d.status,
|
|
94
|
+
};
|
|
95
|
+
if (this.flags.stats) {
|
|
96
|
+
result["#Supporters"] = d.stats.supporterCount;
|
|
97
|
+
|
|
98
|
+
this.actionTypes.forEach((type) => {
|
|
99
|
+
const action = d.stats.actionCount.find(
|
|
100
|
+
(action) => action.actionType === type,
|
|
101
|
+
);
|
|
102
|
+
if (action) result[`#${type}`] = action.count;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
table = (r) => {
|
|
109
|
+
super.table(r, null, (table) => table.sort(["id|des"]).toString());
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
async run() {
|
|
113
|
+
const { args, flags } = await this.parse(CampaignList);
|
|
114
|
+
let data = [];
|
|
115
|
+
|
|
116
|
+
if (args.title && flags.title) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
`${this.id} EITHER [title of the campaign] OR --title [title of the campaign]`,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (args.title) {
|
|
122
|
+
flags.title = args.title;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!flags.title && !flags.org) {
|
|
126
|
+
throw new Error(
|
|
127
|
+
`${this.id} -t [title of the campaign] or -o [organisation]`,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (flags.title) {
|
|
132
|
+
data = await this.Search(flags.title);
|
|
133
|
+
if (this.flags.stats) {
|
|
134
|
+
data.forEach((d) => {
|
|
135
|
+
d.stats.actionCount.forEach((d) => {
|
|
136
|
+
//skip share_confirmed?
|
|
137
|
+
this.actionTypes.add(d.actionType);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (flags.org) {
|
|
144
|
+
data = await this.OrgSearch(flags.org);
|
|
145
|
+
if (this.flags.stats) {
|
|
146
|
+
data.forEach((d) => {
|
|
147
|
+
d.stats.actionCount.forEach((d) => {
|
|
148
|
+
//skip share_confirmed?
|
|
149
|
+
this.actionTypes.add(d.actionType);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return this.output(data);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Args, Flags } from "@oclif/core";
|
|
2
|
+
import { error, stdout, ux } from "@oclif/core/ux";
|
|
3
|
+
import { get as getConfig, getFilename, write } from "#src/config.mjs";
|
|
4
|
+
import Command from "#src/procaCommand.mjs";
|
|
5
|
+
|
|
6
|
+
export default class CampaignList extends Command {
|
|
7
|
+
static enableJsonFlag = true;
|
|
8
|
+
static aliases = ["config:setup"];
|
|
9
|
+
static deprecateAliases = true;
|
|
10
|
+
|
|
11
|
+
static args = {
|
|
12
|
+
environment: Args.string({
|
|
13
|
+
description: "environment",
|
|
14
|
+
default: "default",
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
static description = "create setting to access the server authentication";
|
|
19
|
+
|
|
20
|
+
static examples = [
|
|
21
|
+
"<%= config.bin %> <%= command.id %> --user=xavier@example.org --token=API-12345789",
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
static flags = {
|
|
25
|
+
// flag with no value (-f, --force)
|
|
26
|
+
...super.globalFlags,
|
|
27
|
+
force: Flags.boolean({
|
|
28
|
+
description: "write over an existing configuration",
|
|
29
|
+
default: false,
|
|
30
|
+
helpValue: "(default false)",
|
|
31
|
+
}),
|
|
32
|
+
url: Flags.string({
|
|
33
|
+
description: "url of the proca server api",
|
|
34
|
+
default: "https://api.proca.app/api",
|
|
35
|
+
helpValue: "<url>",
|
|
36
|
+
}),
|
|
37
|
+
token: Flags.string({
|
|
38
|
+
description: "user token on proca server",
|
|
39
|
+
helpValue: "<API-token>",
|
|
40
|
+
required: true,
|
|
41
|
+
}),
|
|
42
|
+
n8n: Flags.string({
|
|
43
|
+
description: "api access on the n8n server",
|
|
44
|
+
helpValue: "<n8n api>",
|
|
45
|
+
}),
|
|
46
|
+
supabase: Flags.string({
|
|
47
|
+
description: "url of the supabase",
|
|
48
|
+
helpValue: "<url>",
|
|
49
|
+
}),
|
|
50
|
+
"supabase-anon-key": Flags.string({
|
|
51
|
+
description: "anonymous key",
|
|
52
|
+
}),
|
|
53
|
+
"supabase-secrey-key": Flags.string({
|
|
54
|
+
description: "secret service key",
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
format = (obj) => {
|
|
59
|
+
const content = ["# generated by proca-api"];
|
|
60
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
61
|
+
if (value) {
|
|
62
|
+
content.push(`${key}='${value.replace(/'/g, "''")}'`);
|
|
63
|
+
} else {
|
|
64
|
+
content.push(`#${key}= `);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return content.join("\n");
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
generate = function () {
|
|
71
|
+
const mapping = {
|
|
72
|
+
REACT_APP_NAME: "proca",
|
|
73
|
+
REACT_APP_API_URL: this.flags.url,
|
|
74
|
+
PROCA_TOKEN: this.flags.token,
|
|
75
|
+
N8N_TOKEN: this.flags.n8n,
|
|
76
|
+
REACT_APP_SUPABASE_URL: this.flags.supabase,
|
|
77
|
+
REACT_APP_SUPABASE_ANON_KEY: this.flags.supabase_anon_key,
|
|
78
|
+
SUPABASE_SECRET_KEY: this.flags.supabase_secret_key,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return this.format(mapping);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
async run() {
|
|
85
|
+
const { args, flags } = await this.parse();
|
|
86
|
+
const file = getFilename(this.config.configDir);
|
|
87
|
+
|
|
88
|
+
const userConfig = getConfig(file);
|
|
89
|
+
if (userConfig && !this.flags.force) {
|
|
90
|
+
this.error("config file exists already", {
|
|
91
|
+
code: "CONFIG_ERR",
|
|
92
|
+
_ref: "README.md#",
|
|
93
|
+
suggestions: [
|
|
94
|
+
`edit ${file}`,
|
|
95
|
+
"add --force flag\nWARNING, it will delete the existing file",
|
|
96
|
+
],
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
write(file, this.generate());
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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/widget.mjs";
|
|
5
|
+
import { gql, query } from "#src/urql.mjs";
|
|
6
|
+
|
|
7
|
+
export default class ConfigServer extends Command {
|
|
8
|
+
static description = "get the server config";
|
|
9
|
+
|
|
10
|
+
fetch = async () => {
|
|
11
|
+
const Document = gql`
|
|
12
|
+
query {
|
|
13
|
+
application {
|
|
14
|
+
logLevel
|
|
15
|
+
name
|
|
16
|
+
version
|
|
17
|
+
}
|
|
18
|
+
}`;
|
|
19
|
+
const result = await query(Document, {});
|
|
20
|
+
return result.application;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
table = (r) => {
|
|
24
|
+
super.table(r, null, null);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
async run() {
|
|
28
|
+
// const { args, flags } = await this.parse();
|
|
29
|
+
|
|
30
|
+
const data = await this.fetch();
|
|
31
|
+
return this.output(data);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Args, Flags } from "@oclif/core";
|
|
2
|
+
import { error, stdout, ux } from "@oclif/core/ux";
|
|
3
|
+
import { get as getConfig, getFilename, load, write } from "#src/config.mjs";
|
|
4
|
+
import Command from "#src/procaCommand.mjs";
|
|
5
|
+
|
|
6
|
+
export default class CampaignList extends Command {
|
|
7
|
+
static enableJsonFlag = true;
|
|
8
|
+
static aliases = ["config:setup"];
|
|
9
|
+
static deprecateAliases = true;
|
|
10
|
+
|
|
11
|
+
static args = {
|
|
12
|
+
key: Args.string({
|
|
13
|
+
description: "variable name",
|
|
14
|
+
multiple: false,
|
|
15
|
+
}),
|
|
16
|
+
value: Args.string({
|
|
17
|
+
description: "value",
|
|
18
|
+
multiple: true,
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
static description =
|
|
23
|
+
"update the setting used to authenticate to the servers and services";
|
|
24
|
+
|
|
25
|
+
static examples = [
|
|
26
|
+
"<%= config.bin %> <%= command.id %> --user=xavier@example.org --token=API-12345789",
|
|
27
|
+
"<%= config.bin %> <%= command.id %> VAR1 VALUE",
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
static flags = {
|
|
31
|
+
// flag with no value (-f, --force)
|
|
32
|
+
...super.globalFlags,
|
|
33
|
+
environment: Flags.string({
|
|
34
|
+
description: "environment",
|
|
35
|
+
default: "default",
|
|
36
|
+
}),
|
|
37
|
+
url: Flags.string({
|
|
38
|
+
description: "url of the proca server api",
|
|
39
|
+
default: "https://api.proca.app/api",
|
|
40
|
+
helpValue: "<url>",
|
|
41
|
+
}),
|
|
42
|
+
token: Flags.string({
|
|
43
|
+
description: "user token on proca server",
|
|
44
|
+
helpValue: "<API-token>",
|
|
45
|
+
}),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
format = (obj) => {
|
|
49
|
+
const content = ["# generated by proca-api"];
|
|
50
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
51
|
+
if (value) {
|
|
52
|
+
content.push(`${key}='${value.replace(/'/g, "''")}'`);
|
|
53
|
+
} else {
|
|
54
|
+
content.push(`#${key}= `);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return content.join("\n");
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
generate = function () {
|
|
61
|
+
const mapping = {
|
|
62
|
+
...args,
|
|
63
|
+
REACT_APP_NAME: "proca",
|
|
64
|
+
REACT_APP_API_URL: this.flags.url,
|
|
65
|
+
PROCA_TOKEN: this.flags.token,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return this.format(mapping);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
regenerate = function (config, args) {
|
|
72
|
+
config[args.key] = args.value;
|
|
73
|
+
console.log(this.format(config));
|
|
74
|
+
process.exit(1);
|
|
75
|
+
return this.format(config);
|
|
76
|
+
};
|
|
77
|
+
async run() {
|
|
78
|
+
const config = this.config;
|
|
79
|
+
const { args, flags, raw } = await this.parse();
|
|
80
|
+
const rawf = raw.filter((d) => d.type === "flag").map((d) => d.flag);
|
|
81
|
+
|
|
82
|
+
const file = getFilename(this.config.configDir);
|
|
83
|
+
|
|
84
|
+
const userConfig = getConfig(file, true);
|
|
85
|
+
|
|
86
|
+
this.info("config file", file);
|
|
87
|
+
|
|
88
|
+
if (userConfig) {
|
|
89
|
+
if (args.key && args.value) {
|
|
90
|
+
write(file, this.regenerate(userConfig, args));
|
|
91
|
+
} else {
|
|
92
|
+
console.log(userConfig);
|
|
93
|
+
this.error("config file exists already", {
|
|
94
|
+
code: "CONFIG_ERR",
|
|
95
|
+
_ref: "README.md#",
|
|
96
|
+
suggestions: ["add KEY VALUE to update or add new variables"],
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
write(file, this.generate());
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import { Args, Flags } from "@oclif/core";
|
|
3
|
+
import { error, stdout, ux } from "@oclif/core/ux";
|
|
4
|
+
import Command from "#src/procaCommand.mjs";
|
|
5
|
+
|
|
6
|
+
export default class UserList extends Command {
|
|
7
|
+
static description = "convert between token and sql value";
|
|
8
|
+
|
|
9
|
+
static flags = {
|
|
10
|
+
token: Flags.string({
|
|
11
|
+
exactlyOne: ["token"],
|
|
12
|
+
description: "the token in your config",
|
|
13
|
+
helpValue: "API-xxx",
|
|
14
|
+
}),
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
async run() {
|
|
18
|
+
const { args, flags } = await this.parse();
|
|
19
|
+
if (flags.token) {
|
|
20
|
+
const token = flags.token
|
|
21
|
+
.replace("API-", "")
|
|
22
|
+
.replace(/-/g, "+")
|
|
23
|
+
.replace(/_/g, "/");
|
|
24
|
+
const decoded = Buffer.from(token, "base64").toString("utf-8");
|
|
25
|
+
const hexa = crypto.createHash("sha256").update(decoded).digest("hex");
|
|
26
|
+
console.log(token, decoded, hexa);
|
|
27
|
+
|
|
28
|
+
return this.output({ hexa: `\\x${hexa}` });
|
|
29
|
+
}
|
|
30
|
+
const data = flags;
|
|
31
|
+
|
|
32
|
+
return this.output(data);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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 =
|
|
8
|
+
"fetch the information about the current user (based on the token)";
|
|
9
|
+
|
|
10
|
+
static examples = ["<%= config.bin %> <%= command.id %>"];
|
|
11
|
+
|
|
12
|
+
static flags = {
|
|
13
|
+
...super.globalFlags,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
fetch = async (params) => {
|
|
17
|
+
const Document = gql`
|
|
18
|
+
query {
|
|
19
|
+
currentUser {
|
|
20
|
+
apiToken {
|
|
21
|
+
expiresAt
|
|
22
|
+
}
|
|
23
|
+
email
|
|
24
|
+
id
|
|
25
|
+
isAdmin
|
|
26
|
+
jobTitle
|
|
27
|
+
phone
|
|
28
|
+
pictureUrl
|
|
29
|
+
roles {
|
|
30
|
+
role org {name}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
const result = await query(Document);
|
|
36
|
+
return result.currentUser;
|
|
37
|
+
//return result.users.map (d => {d.config = JSON.parse(d.config); return d});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
simplify = (d) => {
|
|
41
|
+
const result = {
|
|
42
|
+
id: d.id,
|
|
43
|
+
email: d.email,
|
|
44
|
+
};
|
|
45
|
+
if (d.apiToken) {
|
|
46
|
+
result.tokenExpire = d.apiToken.expiresAt;
|
|
47
|
+
}
|
|
48
|
+
if (d.isAdmin) {
|
|
49
|
+
result.admin = true;
|
|
50
|
+
}
|
|
51
|
+
const roles = d.roles.reduce((acc, item) => {
|
|
52
|
+
if (!acc[item.role]) {
|
|
53
|
+
acc[item.role] = [];
|
|
54
|
+
}
|
|
55
|
+
acc[item.role].push(item.org.name);
|
|
56
|
+
return acc;
|
|
57
|
+
}, {});
|
|
58
|
+
for (const role in roles) {
|
|
59
|
+
result[role] = roles[role].join(",");
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
table = (r) => {
|
|
65
|
+
super.table(r, null, null);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
async run() {
|
|
69
|
+
const { args, flags } = await this.parse();
|
|
70
|
+
let data = [];
|
|
71
|
+
|
|
72
|
+
data = await this.fetch();
|
|
73
|
+
|
|
74
|
+
return this.output(data);
|
|
75
|
+
}
|
|
76
|
+
}
|