@proca/cli 3.3.1 → 3.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1992 -60
- package/package.json +88 -71
- package/proca-cli +8 -0
- package/src/commands/action/add.mjs +192 -0
- package/src/commands/action/confirm.mjs +93 -0
- package/src/commands/action/count.mjs +61 -0
- package/src/commands/action/list.mjs +204 -0
- package/src/commands/action/replay.mjs +56 -0
- package/src/commands/action/requeue.mjs +156 -0
- package/src/commands/campaign/add.mjs +113 -0
- package/src/commands/campaign/copy.mjs +91 -0
- package/src/commands/campaign/delete.mjs +41 -0
- package/src/commands/campaign/get.mjs +132 -0
- package/src/commands/campaign/list.mjs +161 -0
- package/src/commands/campaign/mtt.mjs +131 -0
- package/src/commands/campaign/queries.graphql +19 -0
- package/src/commands/campaign/status.mjs +63 -0
- package/src/commands/campaign/widget/archive.mjs +124 -0
- package/src/commands/campaign/widget/copy.mjs +175 -0
- package/src/commands/campaign/widget/get.mjs +19 -0
- package/src/commands/campaign/widget/index.mjs +17 -0
- package/src/commands/campaign/widget/rebuild.mjs +50 -0
- package/src/commands/config/add.mjs +97 -0
- package/src/commands/config/folder.mjs +42 -0
- package/src/commands/config/server.mjs +33 -0
- package/src/commands/config/set.mjs +103 -0
- package/src/commands/config/user.mjs +79 -0
- package/src/commands/contact/count.mjs +41 -0
- package/src/commands/contact/list.mjs +207 -0
- package/src/commands/org/add.mjs +75 -0
- package/src/commands/org/crm.mjs +88 -0
- package/src/commands/org/delete.mjs +48 -0
- package/src/commands/org/email.mjs +111 -0
- package/src/commands/org/get.mjs +152 -0
- package/src/commands/service/add.mjs +78 -0
- package/src/commands/service/list.mjs +24 -0
- package/src/commands/target/add.mjs +94 -0
- package/src/commands/template/add.mjs +97 -0
- package/src/commands/template/list.mjs +61 -0
- package/src/commands/user/get.mjs +91 -0
- package/src/commands/user/invite.mjs +56 -0
- package/src/commands/user/join.mjs +81 -0
- package/src/commands/user/leave.mjs +57 -0
- package/src/commands/user/list.mjs +80 -0
- package/src/commands/user/reset.mjs +83 -0
- package/src/commands/widget/add.mjs +116 -0
- package/src/commands/widget/delete.mjs +45 -0
- package/src/commands/widget/get.mjs +60 -0
- package/src/commands/widget/list.mjs +135 -0
- package/src/commands/widget/rebuild.mjs +64 -0
- package/src/commands/widget/update.mjs +174 -0
- package/src/config.mjs +49 -0
- package/src/generated/schema.json +10677 -0
- package/src/hooks/help.mjs +14 -0
- package/src/hooks/init.mjs +41 -0
- package/src/index.mjs +1 -0
- package/src/procaCommand.mjs +316 -0
- package/src/queries/campaign.mjs +35 -0
- package/src/queries/widget.mjs +25 -0
- package/src/urql.mjs +60 -0
- package/src/util/twitter.mjs +23 -0
- package/theme.json +29 -0
- package/LICENSE +0 -661
- package/bin/proca-cli +0 -4
- package/dist/a.d.ts +0 -1
- package/dist/a.js +0 -21
- package/dist/a.js.map +0 -1
- package/dist/browser.d.ts +0 -1
- package/dist/browser.js +0 -24
- package/dist/browser.js.map +0 -1
- package/dist/campaign.d.ts +0 -156
- package/dist/campaign.js +0 -188
- package/dist/campaign.js.map +0 -1
- package/dist/cli.d.ts +0 -40
- package/dist/cli.js +0 -411
- package/dist/cli.js.map +0 -1
- package/dist/client.d.ts +0 -2
- package/dist/client.js +0 -18
- package/dist/client.js.map +0 -1
- package/dist/config.d.ts +0 -35
- package/dist/config.js +0 -71
- package/dist/config.js.map +0 -1
- package/dist/crypto.d.ts +0 -40
- package/dist/crypto.js +0 -53
- package/dist/crypto.js.map +0 -1
- package/dist/decrypt.d.ts +0 -7
- package/dist/decrypt.js +0 -29
- package/dist/decrypt.js.map +0 -1
- package/dist/export.d.ts +0 -15
- package/dist/export.js +0 -141
- package/dist/export.js.map +0 -1
- package/dist/format.d.ts +0 -37
- package/dist/format.js +0 -200
- package/dist/format.js.map +0 -1
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -35
- package/dist/index.js.map +0 -1
- package/dist/keys.d.ts +0 -4
- package/dist/keys.js +0 -38
- package/dist/keys.js.map +0 -1
- package/dist/org.d.ts +0 -11
- package/dist/org.js +0 -93
- package/dist/org.js.map +0 -1
- package/dist/proca.d.ts +0 -2066
- package/dist/proca.js +0 -396
- package/dist/proca.js.map +0 -1
- package/dist/queue.d.ts +0 -8
- package/dist/queue.js +0 -126
- package/dist/queue.js.map +0 -1
- package/dist/queueMessage.d.ts +0 -102
- package/dist/queueMessage.js +0 -109
- package/dist/queueMessage.js.map +0 -1
- package/dist/scalarLocations.d.ts +0 -4
- package/dist/scalarLocations.js +0 -236
- package/dist/scalarLocations.js.map +0 -1
- package/dist/service/actionnetwork.d.ts +0 -10
- package/dist/service/actionnetwork.js +0 -302
- package/dist/service/actionnetwork.js.map +0 -1
- package/dist/service/distance.d.ts +0 -3
- package/dist/service/distance.js +0 -92
- package/dist/service/distance.js.map +0 -1
- package/dist/service/echo.d.ts +0 -4
- package/dist/service/echo.js +0 -19
- package/dist/service/echo.js.map +0 -1
- package/dist/service/email.d.ts +0 -14
- package/dist/service/email.js +0 -67
- package/dist/service/email.js.map +0 -1
- package/dist/service/identity.d.ts +0 -58
- package/dist/service/identity.js +0 -190
- package/dist/service/identity.js.map +0 -1
- package/dist/service/index.d.ts +0 -14
- package/dist/service/index.js +0 -61
- package/dist/service/index.js.map +0 -1
- package/dist/setup.d.ts +0 -2
- package/dist/setup.js +0 -287
- package/dist/setup.js.map +0 -1
- package/dist/test.d.ts +0 -1
- package/dist/test.js +0 -33
- package/dist/test.js.map +0 -1
- package/dist/util.d.ts +0 -5
- package/dist/util.js +0 -30
- package/dist/util.js.map +0 -1
- package/dist/watch.d.ts +0 -9
- package/dist/watch.js +0 -76
- package/dist/watch.js.map +0 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Flags } from "@oclif/core";
|
|
2
|
+
import Command from "#src/procaCommand.mjs";
|
|
3
|
+
import { gql, mutation, query } from "#src/urql.mjs";
|
|
4
|
+
|
|
5
|
+
const SERVICE_NAMES = [
|
|
6
|
+
"MAILJET",
|
|
7
|
+
"SES",
|
|
8
|
+
"STRIPE",
|
|
9
|
+
"TEST_STRIPE",
|
|
10
|
+
"PREVIEW",
|
|
11
|
+
// "SYSTEM", not an external service type, just an alias
|
|
12
|
+
"WEBHOOK",
|
|
13
|
+
"SUPABASE",
|
|
14
|
+
"SMTP",
|
|
15
|
+
].map((d) => d.toLowerCase());
|
|
16
|
+
|
|
17
|
+
export default class OrgEmail extends Command {
|
|
18
|
+
static description =
|
|
19
|
+
"Set service, usually email backend for an org, the specific meaning of each param is dependant on the service";
|
|
20
|
+
|
|
21
|
+
static flags = {
|
|
22
|
+
...super.globalFlags,
|
|
23
|
+
org: Flags.string({
|
|
24
|
+
char: "o",
|
|
25
|
+
description: "organisation running the service",
|
|
26
|
+
required: true,
|
|
27
|
+
}),
|
|
28
|
+
type: Flags.string({
|
|
29
|
+
description: "type of the service",
|
|
30
|
+
options: SERVICE_NAMES,
|
|
31
|
+
required: true,
|
|
32
|
+
default: "system",
|
|
33
|
+
}),
|
|
34
|
+
user: Flags.string({
|
|
35
|
+
description: "credential of the account on the service",
|
|
36
|
+
}),
|
|
37
|
+
password: Flags.string({
|
|
38
|
+
description: "credential of the account on the service",
|
|
39
|
+
}),
|
|
40
|
+
host: Flags.string({
|
|
41
|
+
description: "server of the service",
|
|
42
|
+
}),
|
|
43
|
+
path: Flags.string({
|
|
44
|
+
description: "path on the service",
|
|
45
|
+
}),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
async mutate(flags) {
|
|
49
|
+
const Document = gql`
|
|
50
|
+
mutation ($id: Int, $input: ServiceInput!, $orgName: String!) {
|
|
51
|
+
upsertService(id: $id, input: $input, orgName: $orgName) { host id name path user }
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
const variables = {
|
|
56
|
+
// id: flags.id || null
|
|
57
|
+
orgName: flags.org,
|
|
58
|
+
input: {
|
|
59
|
+
name: flags.type.toUpperCase(),
|
|
60
|
+
host: flags.host || "",
|
|
61
|
+
path: flags.path || "",
|
|
62
|
+
user: flags.user || "",
|
|
63
|
+
password: flags.password || "",
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const result = await mutation(Document, variables);
|
|
68
|
+
return result.upsertService;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
table = (r) => super.table(r, null, null);
|
|
72
|
+
|
|
73
|
+
async run() {
|
|
74
|
+
const { flags } = await this.parse();
|
|
75
|
+
const result = await this.mutate(flags);
|
|
76
|
+
this.output(result);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Flags } from "@oclif/core";
|
|
2
|
+
import Org from "#src/commands/org/get.mjs";
|
|
3
|
+
import Command from "#src/procaCommand.mjs";
|
|
4
|
+
import { gql, mutation, query } from "#src/urql.mjs";
|
|
5
|
+
|
|
6
|
+
export default class OrgServices extends Command {
|
|
7
|
+
static description = "list services set for an organisation";
|
|
8
|
+
|
|
9
|
+
static flags = {
|
|
10
|
+
...super.globalFlags,
|
|
11
|
+
org: Flags.string({
|
|
12
|
+
char: "o",
|
|
13
|
+
description: "organisation running the service",
|
|
14
|
+
required: true,
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
async run() {
|
|
19
|
+
const { flags } = await this.parse();
|
|
20
|
+
const orgCmd = new Org({}, this.config);
|
|
21
|
+
const org = await orgCmd.fetch({ name: flags.org });
|
|
22
|
+
this.output(org.services);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { Args, Flags } from "@oclif/core";
|
|
3
|
+
import { error, stdout, ux } from "@oclif/core/ux";
|
|
4
|
+
import Command from "#src/procaCommand.mjs";
|
|
5
|
+
import { gql, mutation, query } from "#src/urql.mjs";
|
|
6
|
+
|
|
7
|
+
export default class TargetAdd extends Command {
|
|
8
|
+
static flags = {
|
|
9
|
+
// flag with no value (-f, --force)
|
|
10
|
+
...this.flagify({ multiid: false }),
|
|
11
|
+
campaign: Flags.string({
|
|
12
|
+
char: "c",
|
|
13
|
+
description: "mtt campaign to add the target",
|
|
14
|
+
required: true,
|
|
15
|
+
}),
|
|
16
|
+
name: Flags.string({
|
|
17
|
+
description: "name of the target",
|
|
18
|
+
required: true,
|
|
19
|
+
}),
|
|
20
|
+
email: Flags.string({
|
|
21
|
+
description: "email of the target",
|
|
22
|
+
required: true,
|
|
23
|
+
}),
|
|
24
|
+
external_id: Flags.string({
|
|
25
|
+
description: "external id of the target",
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
getCampaignId = async (name) => {
|
|
30
|
+
const Document = gql`
|
|
31
|
+
query getCampaignId($campaign: String!) {
|
|
32
|
+
campaign (name:$campaign) { id
|
|
33
|
+
}
|
|
34
|
+
}`;
|
|
35
|
+
|
|
36
|
+
const result = await query(Document, {
|
|
37
|
+
campaign: name,
|
|
38
|
+
});
|
|
39
|
+
return result.campaign.id;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
create = async (flags) => {
|
|
43
|
+
const id = await this.getCampaignId(flags.campaign);
|
|
44
|
+
|
|
45
|
+
const Document = gql`
|
|
46
|
+
mutation (
|
|
47
|
+
$campaignId: Int!
|
|
48
|
+
$outdatedTargets: OutdatedTargets
|
|
49
|
+
$targets: [TargetInput!]!
|
|
50
|
+
) {
|
|
51
|
+
upsertTargets(
|
|
52
|
+
campaignId: $campaignId
|
|
53
|
+
outdatedTargets: $outdatedTargets
|
|
54
|
+
targets: $targets
|
|
55
|
+
) {
|
|
56
|
+
area
|
|
57
|
+
emails {
|
|
58
|
+
email
|
|
59
|
+
emailStatus
|
|
60
|
+
error
|
|
61
|
+
}
|
|
62
|
+
externalId
|
|
63
|
+
fields
|
|
64
|
+
id
|
|
65
|
+
locale
|
|
66
|
+
name
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
const result = await mutation(Document, {
|
|
71
|
+
campaignId: id,
|
|
72
|
+
outdatedTargets: "KEEP",
|
|
73
|
+
targets: [
|
|
74
|
+
{
|
|
75
|
+
name: flags.name,
|
|
76
|
+
externalId: flags.external_id,
|
|
77
|
+
emails: [{ email: flags.email }],
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
});
|
|
81
|
+
return result.upsertTargets;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
async run() {
|
|
85
|
+
//const { args, flags } = await this.parse(CampaignAdd);
|
|
86
|
+
const { args, flags } = await this.parse();
|
|
87
|
+
if (!flags.external_id) {
|
|
88
|
+
flags.external_id = `${flags.campaign}_${flags.email}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const data = await this.create(flags);
|
|
92
|
+
return this.output(data);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -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 { gql, mutation } from "#src/urql.mjs";
|
|
5
|
+
|
|
6
|
+
export default class TemplateAdd extends Command {
|
|
7
|
+
//static args = { path: { description: "" } };
|
|
8
|
+
|
|
9
|
+
static flags = {
|
|
10
|
+
// flag with no value (-f, --force)
|
|
11
|
+
...super.globalFlags,
|
|
12
|
+
org: Flags.string({
|
|
13
|
+
char: "o",
|
|
14
|
+
description: "organisation",
|
|
15
|
+
required: true,
|
|
16
|
+
}),
|
|
17
|
+
type: Flags.string({
|
|
18
|
+
options: ["thankyou", "doi", "confirm", "doi_thankyou", "doi_confirm"],
|
|
19
|
+
default: "thankyou",
|
|
20
|
+
}),
|
|
21
|
+
lang: Flags.string({
|
|
22
|
+
char: "l",
|
|
23
|
+
description: "language",
|
|
24
|
+
default: "en",
|
|
25
|
+
helpValue: "<locale>",
|
|
26
|
+
}),
|
|
27
|
+
name: Flags.string({
|
|
28
|
+
char: "n",
|
|
29
|
+
description: "name",
|
|
30
|
+
helpValue: "by default type@language",
|
|
31
|
+
}),
|
|
32
|
+
subject: Flags.string({
|
|
33
|
+
char: "s",
|
|
34
|
+
description: "subject",
|
|
35
|
+
helpValue: "'template:' + type",
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
create = async (flag) => {
|
|
40
|
+
const orgName = flag.org;
|
|
41
|
+
|
|
42
|
+
const addTemplateDocument = gql`
|
|
43
|
+
mutation (
|
|
44
|
+
$org: String!
|
|
45
|
+
$name: String!
|
|
46
|
+
$lang: String!
|
|
47
|
+
$subject: String!
|
|
48
|
+
$text: String
|
|
49
|
+
$html: String
|
|
50
|
+
) {
|
|
51
|
+
upsertTemplate(
|
|
52
|
+
orgName: $org
|
|
53
|
+
input: { name: $name, locale: $lang, subject:$subject,text: $text, html: $html }
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
if (!flag.name) {
|
|
59
|
+
flag.name = flag.type; // +'@'+flag.lang;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!flag.subject) {
|
|
63
|
+
flag.subject = `template ${flag.type} in ${flag.lang}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!flag.text) {
|
|
67
|
+
flag.text = "This is the email body";
|
|
68
|
+
}
|
|
69
|
+
if (!flag.html) {
|
|
70
|
+
flag.html = "This is the email html body";
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const r = await mutation(addTemplateDocument, flag);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
const errors = e.graphQLErrors;
|
|
76
|
+
console.log(JSON.stringify(e.graphQLErrors, null, 2));
|
|
77
|
+
if (errors[0].path[1] === "name") {
|
|
78
|
+
this.error(`invalid name (already taken?): ${flag.name}`);
|
|
79
|
+
throw new Error(errors[0].message);
|
|
80
|
+
}
|
|
81
|
+
if (errors[0].extensions?.code === "permission_denied") {
|
|
82
|
+
console.error("permission denied to create", flag.name, flag.org);
|
|
83
|
+
throw new Error(errors[0].message);
|
|
84
|
+
}
|
|
85
|
+
throw new Error(errors[0].message);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
async run() {
|
|
90
|
+
const { args, flags } = await this.parse();
|
|
91
|
+
|
|
92
|
+
// const org = { name: flags.twitter || flags.name, config: {} };
|
|
93
|
+
|
|
94
|
+
const data = await this.create(flags);
|
|
95
|
+
return this.output(data);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Flags } from "@oclif/core";
|
|
2
|
+
import Org from "#src/commands/org/get.mjs";
|
|
3
|
+
import Command from "#src/procaCommand.mjs";
|
|
4
|
+
import { gql, mutation, query } from "#src/urql.mjs";
|
|
5
|
+
|
|
6
|
+
export default class OrgTemplate extends Command {
|
|
7
|
+
static description = "list services set for an organisation";
|
|
8
|
+
|
|
9
|
+
static flags = {
|
|
10
|
+
...super.globalFlags,
|
|
11
|
+
org: Flags.string({
|
|
12
|
+
char: "o",
|
|
13
|
+
description: "organisation having the templates",
|
|
14
|
+
required: true,
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
fetch = async (org) => {
|
|
19
|
+
const GetOrgDocument = gql`
|
|
20
|
+
query GetOrg($name: String!) {
|
|
21
|
+
org (name: $name) {
|
|
22
|
+
id name title
|
|
23
|
+
personalData {
|
|
24
|
+
supporterConfirm
|
|
25
|
+
supporterConfirmTemplate
|
|
26
|
+
}
|
|
27
|
+
processing {
|
|
28
|
+
emailFrom
|
|
29
|
+
emailTemplates
|
|
30
|
+
supporterConfirm
|
|
31
|
+
supporterConfirmTemplate
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
const result = await query(GetOrgDocument, {
|
|
39
|
+
name: org,
|
|
40
|
+
});
|
|
41
|
+
const supporterConfirm = (tplName) => {
|
|
42
|
+
if (
|
|
43
|
+
tplName.split("@")[0] === result.org.processing.supporterConfirmTemplate
|
|
44
|
+
) {
|
|
45
|
+
return result.org.processing.supporterConfirm ? "enabled" : "disabled";
|
|
46
|
+
}
|
|
47
|
+
return "";
|
|
48
|
+
};
|
|
49
|
+
const tpl = result.org.processing?.emailTemplates?.map((d) => ({
|
|
50
|
+
name: d,
|
|
51
|
+
actionConfirm: supporterConfirm(d),
|
|
52
|
+
}));
|
|
53
|
+
return tpl;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
async run() {
|
|
57
|
+
const { flags } = await this.parse();
|
|
58
|
+
const tpl = await this.fetch(flags.org);
|
|
59
|
+
this.output(tpl);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -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,56 @@
|
|
|
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 UserInviteOrg extends Command {
|
|
7
|
+
static description = "invite a user to join an organisation with a role";
|
|
8
|
+
|
|
9
|
+
static examples = ["<%= config.bin %> <%= command.id %>"];
|
|
10
|
+
|
|
11
|
+
static flags = {
|
|
12
|
+
...super.globalFlags,
|
|
13
|
+
role: Flags.string({
|
|
14
|
+
description: "permission level in that org",
|
|
15
|
+
default: "campaigner",
|
|
16
|
+
options: ["owner", "campaigner", "coordinator", "translator"],
|
|
17
|
+
}),
|
|
18
|
+
org: Flags.string({
|
|
19
|
+
char: "o",
|
|
20
|
+
required: true,
|
|
21
|
+
description: "name of the org",
|
|
22
|
+
helpValue: "<org name>",
|
|
23
|
+
}),
|
|
24
|
+
user: Flags.string({
|
|
25
|
+
char: "u",
|
|
26
|
+
required: true,
|
|
27
|
+
description: "email",
|
|
28
|
+
helpValue: "<user email>",
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
invite = async (params) => {
|
|
33
|
+
const Document = gql`
|
|
34
|
+
mutation ($user: String!, $role: String!, $org: String!, $message: String) {
|
|
35
|
+
inviteOrgUser(orgName: $org, message: $message, input: { email: $user, role: $role}) {
|
|
36
|
+
objectId
|
|
37
|
+
code
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
const result = await mutation(Document, params);
|
|
42
|
+
//return result.users.map (d => {d.config = JSON.parse(d.config); return d});
|
|
43
|
+
console.log(result);
|
|
44
|
+
return result.inviteOrgUser;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
table = (r) => {
|
|
48
|
+
super.table(r, null, null);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
async run() {
|
|
52
|
+
const { args, flags } = await this.parse();
|
|
53
|
+
const data = await this.invite(flags);
|
|
54
|
+
this.output(data);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
role: Flags.string({
|
|
14
|
+
description: "permission level in that org",
|
|
15
|
+
default: "campaigner",
|
|
16
|
+
options: ["owner", "campaigner", "coordinator", "translator"],
|
|
17
|
+
}),
|
|
18
|
+
org: Flags.string({
|
|
19
|
+
char: "o",
|
|
20
|
+
required: true,
|
|
21
|
+
description: "name of the org",
|
|
22
|
+
helpValue: "<org name>",
|
|
23
|
+
}),
|
|
24
|
+
user: Flags.string({
|
|
25
|
+
char: "u",
|
|
26
|
+
description: "email",
|
|
27
|
+
helpValue: "<user email>",
|
|
28
|
+
}),
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
join = async (org) => {
|
|
32
|
+
const Document = gql`
|
|
33
|
+
mutation ($name: String!) {
|
|
34
|
+
joinOrg(name: $name) {
|
|
35
|
+
org {
|
|
36
|
+
config
|
|
37
|
+
name
|
|
38
|
+
title
|
|
39
|
+
}
|
|
40
|
+
status
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
const result = await mutation(Document, {
|
|
45
|
+
name: org,
|
|
46
|
+
});
|
|
47
|
+
//return result.users.map (d => {d.config = JSON.parse(d.config); return d});
|
|
48
|
+
return { ...result.joinOrg.org, status: result.joinOrg.status };
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
mutate = async (params) => {
|
|
52
|
+
const Document = gql`
|
|
53
|
+
mutation ($org: String!, $user: String!, $role: String = "campaigner") {
|
|
54
|
+
addOrgUser (orgName: $org, input : { email: $user, role: $role }) {
|
|
55
|
+
status
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
59
|
+
const result = await mutation(Document, {
|
|
60
|
+
user: params.user,
|
|
61
|
+
org: params.org,
|
|
62
|
+
role: params.role,
|
|
63
|
+
});
|
|
64
|
+
return result.addOrgUser;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
table = (r) => {
|
|
68
|
+
super.table(r, null, null);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
async run() {
|
|
72
|
+
const { args, flags } = await this.parse();
|
|
73
|
+
let data = undefined;
|
|
74
|
+
if (!flags.user) {
|
|
75
|
+
data = await this.join(flags.org);
|
|
76
|
+
} else {
|
|
77
|
+
data = await this.mutate(flags);
|
|
78
|
+
}
|
|
79
|
+
this.output(data);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Args, Flags } from "@oclif/core";
|
|
2
|
+
import { error, stdout, ux } from "@oclif/core/ux";
|
|
3
|
+
import { getCurrentUser } from "#src/commands/config/user.mjs";
|
|
4
|
+
import Command from "#src/procaCommand.mjs";
|
|
5
|
+
import { gql, mutation } from "#src/urql.mjs";
|
|
6
|
+
|
|
7
|
+
export default class OrgLeave extends Command {
|
|
8
|
+
actionTypes = new Set();
|
|
9
|
+
|
|
10
|
+
static args = {};
|
|
11
|
+
|
|
12
|
+
static description = "leave a org";
|
|
13
|
+
|
|
14
|
+
static examples = ["<%= config.bin %> <%= command.id %> -i 42"];
|
|
15
|
+
|
|
16
|
+
static flags = {
|
|
17
|
+
// flag with no value (-f, --force)
|
|
18
|
+
...super.globalFlags,
|
|
19
|
+
user: Flags.string({
|
|
20
|
+
char: "u",
|
|
21
|
+
description: "email",
|
|
22
|
+
helpValue: "<user email>",
|
|
23
|
+
}),
|
|
24
|
+
org: Flags.string({
|
|
25
|
+
char: "o",
|
|
26
|
+
description: "name of the org",
|
|
27
|
+
required: true,
|
|
28
|
+
helpValue: "<org name>",
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
mutate = async ({ user, org }) => {
|
|
33
|
+
const Document = gql`
|
|
34
|
+
mutation ($email: String!, $org: String!) {
|
|
35
|
+
deleteOrgUser(email: $email, orgName: $org) { status }
|
|
36
|
+
}`;
|
|
37
|
+
const result = await mutation(Document, {
|
|
38
|
+
email: user,
|
|
39
|
+
org: org,
|
|
40
|
+
});
|
|
41
|
+
return result.deleteOrgUser;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
table = (r) => {
|
|
45
|
+
super.table(r, null, null);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
async run() {
|
|
49
|
+
const { args, flags } = await this.parse();
|
|
50
|
+
if (!flags.user) {
|
|
51
|
+
const me = await getCurrentUser();
|
|
52
|
+
flags.user = me.email;
|
|
53
|
+
}
|
|
54
|
+
const data = await this.mutate(flags);
|
|
55
|
+
this.output(data);
|
|
56
|
+
}
|
|
57
|
+
}
|