@proca/cli 3.4.5 → 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 +1991 -61
- package/package.json +88 -72
- 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/bin/proca-cli +0 -4
- package/dist/browser.d.ts +0 -1
- package/dist/browser.js +0 -28
- package/dist/browser.js.map +0 -1
- package/dist/campaign.d.ts +0 -156
- package/dist/campaign.js +0 -192
- package/dist/campaign.js.map +0 -1
- package/dist/cli.d.ts +0 -40
- package/dist/cli.js +0 -416
- 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/export.d.ts +0 -15
- package/dist/export.js +0 -145
- 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 -39
- 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 -97
- package/dist/org.js.map +0 -1
- package/dist/proca.d.ts +0 -2095
- package/dist/proca.js +0 -398
- 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/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 -96
- 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 -291
- package/dist/setup.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 -80
- package/dist/watch.js.map +0 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Flags } from "@oclif/core";
|
|
2
|
+
import Command from "#src/procaCommand.mjs";
|
|
3
|
+
import { gql, query } from "#src/urql.mjs";
|
|
4
|
+
|
|
5
|
+
export default class UserList extends Command {
|
|
6
|
+
actionTypes = new Set();
|
|
7
|
+
|
|
8
|
+
static description = "list all the users";
|
|
9
|
+
|
|
10
|
+
static examples = ["<%= config.bin %> <%= command.id %> %pizza%"];
|
|
11
|
+
static aliases = ["org:user:get"];
|
|
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 =
|
|
53
|
+
d.roles.filter((d) => d.org.name === this.flags.org)[0]?.role || "??";
|
|
54
|
+
|
|
55
|
+
if (d.roles.length <= 4)
|
|
56
|
+
result.other_orgs = d.roles
|
|
57
|
+
.filter((d) => d.org.name !== this.flags.org)
|
|
58
|
+
.map((d) => d.org.name)
|
|
59
|
+
.join(",");
|
|
60
|
+
else result.other_orgs = `${d.roles.length - 1}`;
|
|
61
|
+
|
|
62
|
+
if (d.isAdmin) {
|
|
63
|
+
result.superadmin = true;
|
|
64
|
+
}
|
|
65
|
+
if (d.apiToken) {
|
|
66
|
+
result.tokenExpire = d.apiToken.tokenExpire;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return result;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
async run() {
|
|
73
|
+
const { flags } = await this.parse(UserList);
|
|
74
|
+
let data = [];
|
|
75
|
+
|
|
76
|
+
data = await this.fetch(flags.org);
|
|
77
|
+
|
|
78
|
+
return this.output(data);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Args, Flags } from "@oclif/core";
|
|
2
|
+
import { error, stdout } from "@oclif/core/ux";
|
|
3
|
+
import prompts from "prompts";
|
|
4
|
+
import { format, get as getConfig, getFilename, write } from "#src/config.mjs";
|
|
5
|
+
import Command from "#src/procaCommand.mjs";
|
|
6
|
+
|
|
7
|
+
export default class UserReset extends Command {
|
|
8
|
+
static description = "Reset user API token";
|
|
9
|
+
|
|
10
|
+
static args = {
|
|
11
|
+
user: Args.string({ description: "Username (email)" }),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
static flags = {
|
|
15
|
+
...super.globalFlags,
|
|
16
|
+
password: Flags.string({ description: "Password" }),
|
|
17
|
+
url: Flags.string({ description: "URL of the Proca server API" }),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
async run() {
|
|
21
|
+
const { args, flags } = await this.parse(UserReset);
|
|
22
|
+
|
|
23
|
+
const file = getFilename(this.config.configDir, flags.env);
|
|
24
|
+
const userConfig = getConfig(file, true) || {};
|
|
25
|
+
|
|
26
|
+
if (!args.user) {
|
|
27
|
+
const response = await prompts({
|
|
28
|
+
type: "text",
|
|
29
|
+
name: "user",
|
|
30
|
+
message: "Username:",
|
|
31
|
+
});
|
|
32
|
+
args.user = response.user;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!flags.password) {
|
|
36
|
+
const response = await prompts({
|
|
37
|
+
type: "password",
|
|
38
|
+
name: "password",
|
|
39
|
+
message: "Password:",
|
|
40
|
+
});
|
|
41
|
+
flags.password = response.password;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const url =
|
|
45
|
+
flags.url || userConfig.REACT_APP_API_URL || "https://api.proca.app/api";
|
|
46
|
+
|
|
47
|
+
if (!args.user || !flags.password) {
|
|
48
|
+
return error("User and password are required.");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const query = `mutation {
|
|
52
|
+
resetApiToken
|
|
53
|
+
}`;
|
|
54
|
+
|
|
55
|
+
const auth = `Basic ${Buffer.from(`${args.user}:${flags.password}`).toString("base64")}`;
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
const response = await fetch(url, {
|
|
59
|
+
method: "POST",
|
|
60
|
+
headers: {
|
|
61
|
+
"Content-Type": "application/json",
|
|
62
|
+
Authorization: auth,
|
|
63
|
+
},
|
|
64
|
+
body: JSON.stringify({ query }),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const data = await response.json();
|
|
68
|
+
|
|
69
|
+
if (data.errors) {
|
|
70
|
+
return error(data.errors.map((e) => e.message).join("\n"));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const newToken = data.data.resetApiToken;
|
|
74
|
+
this.log(`New API token: ${newToken}`);
|
|
75
|
+
|
|
76
|
+
userConfig.PROCA_TOKEN = newToken;
|
|
77
|
+
write(file, format(userConfig));
|
|
78
|
+
this.log(`Token saved to ${file}`);
|
|
79
|
+
} catch (e) {
|
|
80
|
+
error(e.message);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Flags } from "@oclif/core";
|
|
2
|
+
import { getCampaign } from "#src/commands/campaign/get.mjs";
|
|
3
|
+
import { getOrg } from "#src/commands/org/get.mjs";
|
|
4
|
+
import Command from "#src/procaCommand.mjs";
|
|
5
|
+
import { gql, mutation } from "#src/urql.mjs";
|
|
6
|
+
|
|
7
|
+
export default class WidgetAdd extends Command {
|
|
8
|
+
static flags = {
|
|
9
|
+
...super.globalFlags,
|
|
10
|
+
campaign: Flags.string({
|
|
11
|
+
char: "c",
|
|
12
|
+
required: true,
|
|
13
|
+
description: "name of the campaign",
|
|
14
|
+
helpValue: "<campaign name>",
|
|
15
|
+
}),
|
|
16
|
+
org: Flags.string({
|
|
17
|
+
char: "o",
|
|
18
|
+
description: "organisation",
|
|
19
|
+
helpValue: "<en>",
|
|
20
|
+
}),
|
|
21
|
+
lang: Flags.string({
|
|
22
|
+
char: "l",
|
|
23
|
+
default: "en",
|
|
24
|
+
description: "language",
|
|
25
|
+
helpValue: "<en>",
|
|
26
|
+
}),
|
|
27
|
+
name: Flags.string({
|
|
28
|
+
char: "n",
|
|
29
|
+
description: "url slug",
|
|
30
|
+
helpValue: "by default <campaign>/<org>/<lang>",
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
create = async (flag) => {
|
|
35
|
+
let campaign = null;
|
|
36
|
+
|
|
37
|
+
if (!flag.org) {
|
|
38
|
+
campaign = await getCampaign({ name: flag.campaign });
|
|
39
|
+
if (!campaign) {
|
|
40
|
+
throw new Error(`campaign not found: ${flag.campaign}`);
|
|
41
|
+
}
|
|
42
|
+
flag.org = campaign.org.name;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const org = await getOrg({
|
|
46
|
+
name: flag.org,
|
|
47
|
+
campaigns: false,
|
|
48
|
+
keys: false,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const input = {
|
|
52
|
+
name: flag.name ?? `${flag.campaign}/${flag.org}/${flag.lang}`,
|
|
53
|
+
locale: flag.lang,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
if (flag.config) {
|
|
57
|
+
input.config =
|
|
58
|
+
typeof flag.config === "string" ? JSON.parse(flag.config) : flag.config;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// else if (org?.config?.layout) {
|
|
62
|
+
// input.config = { layout: org.config.layout };
|
|
63
|
+
// }
|
|
64
|
+
|
|
65
|
+
// Optional ActionPage fields
|
|
66
|
+
if (flag.journey) input.journey = flag.journey;
|
|
67
|
+
if (flag.thankYouTemplate) {
|
|
68
|
+
input.thank_you_template = flag.thankYouTemplate;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (flag.live !== undefined) input.live = flag.live;
|
|
72
|
+
|
|
73
|
+
const Document = gql`
|
|
74
|
+
mutation addPage(
|
|
75
|
+
$campaignName: String!
|
|
76
|
+
$orgName: String!
|
|
77
|
+
$input: ActionPageInput!
|
|
78
|
+
) {
|
|
79
|
+
addActionPage(
|
|
80
|
+
campaignName: $campaignName
|
|
81
|
+
orgName: $orgName
|
|
82
|
+
input: $input
|
|
83
|
+
) {
|
|
84
|
+
id
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
`;
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const r = await mutation(Document, {
|
|
91
|
+
campaignName: flag.campaign,
|
|
92
|
+
orgName: flag.org,
|
|
93
|
+
input,
|
|
94
|
+
});
|
|
95
|
+
return { id: r.addActionPage.id };
|
|
96
|
+
} catch (e) {
|
|
97
|
+
const err = e.graphQLErrors?.[0];
|
|
98
|
+
|
|
99
|
+
if (err?.path?.[1] === "name") {
|
|
100
|
+
this.error(`invalid name (already taken?): ${input.name}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (err?.extensions?.code === "permission_denied") {
|
|
104
|
+
this.error(`permission denied to create widget for org ${flag.org}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
throw new Error(err?.message ?? "failed to create widget");
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
async run() {
|
|
112
|
+
const { flags } = await this.parse();
|
|
113
|
+
const data = await this.create(flags);
|
|
114
|
+
return this.output(data);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createInterface } from "node:readline";
|
|
2
|
+
import { Flags } from "@oclif/core";
|
|
3
|
+
import WidgetGet from "#src/commands/widget/get.mjs";
|
|
4
|
+
import Command from "#src/procaCommand.mjs";
|
|
5
|
+
import { gql, mutation } from "#src/urql.mjs";
|
|
6
|
+
|
|
7
|
+
export default class WidgetDelete extends Command {
|
|
8
|
+
static description = "Delete a widget";
|
|
9
|
+
|
|
10
|
+
static args = this.multiid();
|
|
11
|
+
|
|
12
|
+
static flags = {
|
|
13
|
+
...this.flagify({ multiid: true }),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
delete = async (flags) => {
|
|
17
|
+
const deletePageDocument = gql`
|
|
18
|
+
mutation delete( $name:String!) {
|
|
19
|
+
deleteActionPage(name: $name)
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
const r = await mutation(deletePageDocument, { name: flags.name });
|
|
24
|
+
return { deleted: r.deleteActionPage };
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
table = (r) => {
|
|
28
|
+
super.table(r, null, null);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
async run() {
|
|
32
|
+
const { flags } = await this.parse(WidgetDelete);
|
|
33
|
+
const wg = new WidgetGet([], this.config);
|
|
34
|
+
const widget = await wg.fetch(flags);
|
|
35
|
+
try {
|
|
36
|
+
const data = await this.delete({ name: widget.name });
|
|
37
|
+
widget.status = data.deleted;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
widget.status = "can't delete widgets with actions";
|
|
40
|
+
this.output(widget);
|
|
41
|
+
this.error("a widget with actions can't be deleted");
|
|
42
|
+
}
|
|
43
|
+
return this.output(widget);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Flags } from "@oclif/core";
|
|
2
|
+
import Command from "#src/procaCommand.mjs";
|
|
3
|
+
import { FragmentSummary } from "#src/queries/widget.mjs";
|
|
4
|
+
import { gql, query } from "#src/urql.mjs";
|
|
5
|
+
|
|
6
|
+
export const getWidget = (params) => {
|
|
7
|
+
const d = new WidgetGet([]);
|
|
8
|
+
return d.fetch(params);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default class WidgetGet extends Command {
|
|
12
|
+
static description = "view a widget";
|
|
13
|
+
|
|
14
|
+
static args = this.multiid();
|
|
15
|
+
|
|
16
|
+
static flags = {
|
|
17
|
+
// flag with no value (-f, --force)
|
|
18
|
+
...this.flagify({ multiid: true }),
|
|
19
|
+
config: Flags.boolean({
|
|
20
|
+
description: "display the config",
|
|
21
|
+
default: true,
|
|
22
|
+
allowNo: true,
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
fetch = async (params) => {
|
|
27
|
+
const GetWidgetDocument = gql`
|
|
28
|
+
query GetWidget($name: String, $id: Int, $config: Boolean = true) {
|
|
29
|
+
actionPage(name: $name, id: $id) {
|
|
30
|
+
...Summary
|
|
31
|
+
org {
|
|
32
|
+
name
|
|
33
|
+
}
|
|
34
|
+
campaign {
|
|
35
|
+
name
|
|
36
|
+
}
|
|
37
|
+
thankYouTemplate
|
|
38
|
+
config @include(if: $config)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
${FragmentSummary}
|
|
42
|
+
`;
|
|
43
|
+
const result = await query(GetWidgetDocument, params);
|
|
44
|
+
result.actionPage.config = JSON.parse(result.actionPage.config);
|
|
45
|
+
return result.actionPage;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
table = (r) => {
|
|
49
|
+
super.table(r, null, null);
|
|
50
|
+
if (this.flags.config) {
|
|
51
|
+
this.prettyJson(r.config);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
async run() {
|
|
56
|
+
const { args, flags } = await this.parse();
|
|
57
|
+
const data = await this.fetch(flags);
|
|
58
|
+
return this.output(data);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Args, Flags, Help } from "@oclif/core";
|
|
2
|
+
import { error, stdout, ux } from "@oclif/core/ux";
|
|
3
|
+
import Command from "#src/procaCommand.mjs";
|
|
4
|
+
import { FragmentSummary, FragmentSummaryOrg } from "#src/queries/widget.mjs";
|
|
5
|
+
import { gql, query } from "#src/urql.mjs";
|
|
6
|
+
|
|
7
|
+
export const getWidgetList = (params) => {
|
|
8
|
+
const d = new WidgetList([]);
|
|
9
|
+
return d.fetch(params);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default class WidgetList extends Command {
|
|
13
|
+
static description = "list all the widgets of an org or campaign";
|
|
14
|
+
|
|
15
|
+
static examples = ["<%= config.bin %> <%= command.id %> -o <organisation>"];
|
|
16
|
+
|
|
17
|
+
// static aliases = ["campaign:widget:get", "org:widget:get"]; let's rewrite them for better aliasing
|
|
18
|
+
|
|
19
|
+
static flags = {
|
|
20
|
+
// flag with no value (-f, --force)
|
|
21
|
+
...super.globalFlags,
|
|
22
|
+
org: Flags.string({
|
|
23
|
+
char: "o",
|
|
24
|
+
// exactlyOne: ["campaign", "org"], actually, we can filter on both
|
|
25
|
+
description: "widgets of the organisation (coordinator or partner)",
|
|
26
|
+
helpValue: "<organisation name>",
|
|
27
|
+
exactlyOne: ["campaign", "org"],
|
|
28
|
+
// required: true,
|
|
29
|
+
}),
|
|
30
|
+
campaign: Flags.string({
|
|
31
|
+
char: "c",
|
|
32
|
+
description: "widgets of the campaign (coordinator or partner)",
|
|
33
|
+
helpValue: "<campaign name>",
|
|
34
|
+
// required: true,
|
|
35
|
+
}),
|
|
36
|
+
config: Flags.boolean({
|
|
37
|
+
description: "get the config",
|
|
38
|
+
default: false,
|
|
39
|
+
allowNo: true,
|
|
40
|
+
}),
|
|
41
|
+
};
|
|
42
|
+
fetchCampaign = async (name) => {
|
|
43
|
+
const Document = gql`
|
|
44
|
+
query SearchWidgets($campaign: String!, $withConfig: Boolean!) {
|
|
45
|
+
campaign (name:$campaign) { ...on PrivateCampaign {
|
|
46
|
+
actionPages {
|
|
47
|
+
...Summary
|
|
48
|
+
config @include(if: $withConfig)
|
|
49
|
+
thankYouTemplate
|
|
50
|
+
thankYouTemplateRef
|
|
51
|
+
...on PrivateActionPage {
|
|
52
|
+
supporterConfirmTemplate
|
|
53
|
+
}
|
|
54
|
+
}}
|
|
55
|
+
}
|
|
56
|
+
${FragmentSummary}
|
|
57
|
+
}`;
|
|
58
|
+
const result = await query(Document, {
|
|
59
|
+
campaign: name,
|
|
60
|
+
withConfig: this.flags.config,
|
|
61
|
+
});
|
|
62
|
+
if (this.flags.org) {
|
|
63
|
+
return result.campaign.actionPages.filter(
|
|
64
|
+
(d) => d.org.name === this.flags.org,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
return result.campaign.actionPages;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
fetchOrg = async (name) => {
|
|
71
|
+
const Document = gql`
|
|
72
|
+
query SearchWidgets($org: String!, $withConfig: Boolean!) {
|
|
73
|
+
org (name:$org) {
|
|
74
|
+
actionPages {
|
|
75
|
+
...Summary
|
|
76
|
+
config @include(if: $withConfig)
|
|
77
|
+
thankYouTemplate
|
|
78
|
+
thankYouTemplateRef
|
|
79
|
+
...on PrivateActionPage {
|
|
80
|
+
supporterConfirmTemplate
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
${FragmentSummaryOrg}
|
|
85
|
+
}`;
|
|
86
|
+
const result = await query(Document, {
|
|
87
|
+
org: name,
|
|
88
|
+
withConfig: this.flags.config,
|
|
89
|
+
});
|
|
90
|
+
return result.org.actionPages;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
simplify = (d) => {
|
|
94
|
+
const result = {
|
|
95
|
+
id: d.id,
|
|
96
|
+
name: d.name,
|
|
97
|
+
locale: d.locale,
|
|
98
|
+
status: d.status.toLowerCase(),
|
|
99
|
+
location: d.location?.startsWith("https://widget.proca.app")
|
|
100
|
+
? undefined
|
|
101
|
+
: d.location || undefined,
|
|
102
|
+
// live: d.live,
|
|
103
|
+
|
|
104
|
+
// thankYouTemplate: d.thankYouTemplate || undefined,
|
|
105
|
+
// thankYouTemplateRef: d.thankYouTemplateRef || undefined,
|
|
106
|
+
// supporterConfirmTemplate: d.supporterConfirmTemplate || undefined,
|
|
107
|
+
};
|
|
108
|
+
if (d.extraSupporters > 0) {
|
|
109
|
+
result.extra = d.extraSupporters;
|
|
110
|
+
}
|
|
111
|
+
// if (d.journey) result.journey = d.journey.join(" → ");
|
|
112
|
+
if (d.org) {
|
|
113
|
+
result.org = d.org.name;
|
|
114
|
+
result.org_id = d.org.id;
|
|
115
|
+
}
|
|
116
|
+
if (d.campaign) {
|
|
117
|
+
result.campaign = d.campaign.name;
|
|
118
|
+
}
|
|
119
|
+
if (this.flags.config) {
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
table = (r) => {
|
|
125
|
+
super.table(r, null, (table) => table.sort(["id|des"]).toString());
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
async run() {
|
|
129
|
+
const { flags } = await this.parse(WidgetList);
|
|
130
|
+
let data = [];
|
|
131
|
+
if (flags.org) data = await this.fetchOrg(flags.org);
|
|
132
|
+
if (flags.campaign) data = await this.fetchCampaign(flags.campaign);
|
|
133
|
+
return this.output(data);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Flags } from "@oclif/core";
|
|
2
|
+
import { mergeAndConcat as merge } from "merge-anything";
|
|
3
|
+
import WidgetGet from "#src/commands/widget/get.mjs";
|
|
4
|
+
import Command from "#src/procaCommand.mjs";
|
|
5
|
+
import { gql, mutation } from "#src/urql.mjs";
|
|
6
|
+
|
|
7
|
+
export default class WidgetRebuild extends Command {
|
|
8
|
+
static description = "(re)build a widget";
|
|
9
|
+
|
|
10
|
+
static examples = [
|
|
11
|
+
"<%= config.bin %> widget rebuild 42",
|
|
12
|
+
"<%= config.bin %> widget rebuild climate-action/my-org/en",
|
|
13
|
+
"SEE ALSO:",
|
|
14
|
+
"<%= config.bin %> campaign widget rebuild Rebuild all the widgets of a campaign",
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
static args = this.multiid();
|
|
18
|
+
|
|
19
|
+
static flags = {
|
|
20
|
+
// flag with no value (-f, --force)
|
|
21
|
+
...this.flagify({ multiid: true }),
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
rebuild = async ({ widget, timestamp = new Date().toISOString() }) => {
|
|
25
|
+
//
|
|
26
|
+
const data = merge(widget, { config: { layout: { update: timestamp } } });
|
|
27
|
+
|
|
28
|
+
const PushWidgetDocument = gql`
|
|
29
|
+
mutation updateActionPage($id: Int!, $config: Json!) {
|
|
30
|
+
updateActionPage(id: $id, input: {config:$config}) {
|
|
31
|
+
id, name, locale, config
|
|
32
|
+
...on PrivateActionPage {
|
|
33
|
+
status
|
|
34
|
+
location
|
|
35
|
+
org {name}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
const r = await mutation(PushWidgetDocument, {
|
|
41
|
+
id: data.id,
|
|
42
|
+
config: JSON.stringify(data.config),
|
|
43
|
+
});
|
|
44
|
+
if (r.errors) {
|
|
45
|
+
console.log(r);
|
|
46
|
+
console.log("check your config $npx proca config user");
|
|
47
|
+
throw new Error(r.errors[0].message || "can't update on the server");
|
|
48
|
+
}
|
|
49
|
+
r.updateActionPage.update = data.config.layout.update;
|
|
50
|
+
return r.updateActionPage;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
table = (r) => {
|
|
54
|
+
super.table(r, null, null);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
async run() {
|
|
58
|
+
const { flags } = await this.parse();
|
|
59
|
+
const wapi = new WidgetGet();
|
|
60
|
+
const widget = await wapi.fetch(flags);
|
|
61
|
+
const r = await this.rebuild({ widget });
|
|
62
|
+
return this.output(r);
|
|
63
|
+
}
|
|
64
|
+
}
|