proca 0.6.0 → 0.6.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 CHANGED
@@ -18,7 +18,7 @@ $ npm install -g proca
18
18
  $ proca COMMAND
19
19
  running command...
20
20
  $ proca (--version)
21
- proca/0.6.0 linux-x64 node-v20.12.2
21
+ proca/0.6.3 linux-x64 node-v20.12.2
22
22
  $ proca --help [COMMAND]
23
23
  USAGE
24
24
  $ proca COMMAND
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "proca",
3
3
  "description": "Access the proca api",
4
- "version": "0.6.0",
4
+ "version": "0.6.3",
5
5
  "author": "Xavier",
6
6
  "bin": {
7
7
  "proca": "./proca-cli"
@@ -16,6 +16,7 @@
16
16
  "dxid": "^2.2.1",
17
17
  "easy-table": "^1.2.0",
18
18
  "fast-csv": "^5.0.1",
19
+ "graphql": "^16.10.0",
19
20
  "typescript": "^5.7.3",
20
21
  "urql": "^4.1.0"
21
22
  },
@@ -1,5 +1,6 @@
1
1
  import { Args, Flags } from "@oclif/core";
2
2
  import { error, stdout, ux } from "@oclif/core/ux";
3
+ import CampaignGet from "#src/commands/campaign/get.mjs";
3
4
  import Command from "#src/procaCommand.mjs";
4
5
  import { gql, mutation } from "#src/urql.mjs";
5
6
 
@@ -34,20 +35,31 @@ export default class WidgetAdd extends Command {
34
35
  };
35
36
 
36
37
  create = async (flag) => {
38
+ const orgName = flag.org;
37
39
  let campaign = { org: { name: orgName } }; // no need to fetch the campaign if the orgName is specified
38
40
 
39
- const addWidgetDocument = gql`mutation addPage($campaign:String!,$org: String!, $name: String!, $locale: String!) {
40
- addActionPage(campaignName:$campaign, orgName: $org, input: {
41
- name: $name, locale:$locale
42
- }) {
43
- id
44
- }
45
- }
46
- `;
41
+ const addWidgetDocument = gql`
42
+ mutation addPage(
43
+ $campaign: String!
44
+ $org: String!
45
+ $name: String!
46
+ $lang: String!
47
+ ) {
48
+ addActionPage(
49
+ campaignName: $campaign
50
+ orgName: $org
51
+ input: { name: $name, locale: $lang }
52
+ ) {
53
+ id
54
+ }
55
+ }
56
+ `;
47
57
 
48
58
  if (!orgName) {
49
59
  try {
50
- campaign = await pullCampaign(campaignName);
60
+ const campapi = new CampaignGet();
61
+ campaign = await campapi.fetch({ name: flag.campaign });
62
+ flag.org = campaign.org.name;
51
63
  } catch (e) {
52
64
  console.log("error", e);
53
65
  throw e;
@@ -55,52 +67,27 @@ export default class WidgetAdd extends Command {
55
67
  }
56
68
 
57
69
  if (!campaign) {
58
- throw new Error(`campaign not found: ${campaignName}`);
70
+ throw new Error(`campaign not found: ${flag.campaign}`);
59
71
  }
60
72
 
61
- const r = await mutation(AddWidgetDocument, flag);
62
-
63
- console.log(r);
64
- if (r.errors) {
65
- try {
66
- console.log(r.errors);
67
- if (r.errors[0].path[1] === "name") {
68
- console.error("invalid name", name);
69
- throw new Error(r.errors[0].message);
70
- }
71
- if (r.errors[0].extensions?.code === "permission_denied") {
72
- console.error(
73
- "permission denied to create",
74
- name,
75
- campaign?.org.name,
76
- );
77
- throw new Error(r.errors[0].message);
78
- }
79
- const page = await fetchByName(name);
80
- console.warn("duplicate of widget", page.id);
73
+ try {
74
+ const r = await mutation(addWidgetDocument, flag);
75
+ return r;
76
+ } catch (e) {
77
+ const errors = e.graphQLErrors;
78
+ if (errors[0].path[1] === "name") {
79
+ this.error(`invalid name (already taken?): ${flag.name}`);
80
+ throw new Error(errors[0].message);
81
+ }
82
+ if (r.errors[0].extensions?.code === "permission_denied") {
83
+ console.error("permission denied to create", name, campaign?.org.name);
81
84
  throw new Error(r.errors[0].message);
82
- } catch (e) {
83
- console.log(e);
84
- throw e;
85
85
  }
86
+ const page = await fetchByName(name);
87
+ console.warn("duplicate of widget", page.id);
88
+ throw new Error(r.errors[0].message);
86
89
  }
87
90
  };
88
- _noCreate = async (_org) => {
89
- const AddWidgetDocument = gql`
90
- mutation ($org: String!,$name: String!,$title: String!) {
91
- addCampaign(orgName: $org, input: {$org}) {
92
- config
93
- name
94
- title
95
- }
96
- }
97
- `;
98
- const result = await mutation(AddWidgetDocument, {
99
- org,
100
- });
101
- console.log(result);
102
- return result.org;
103
- };
104
91
 
105
92
  async run() {
106
93
  const { args, flags } = await this.parse();
@@ -1,33 +0,0 @@
1
- /*
2
- * inspired by https://github.com/salesforcecli/cli/blob/main/src/flags.ts
3
- * Copyright (c) 2020, salesforce.com, inc.
4
- * All rights reserved.
5
- * Licensed under the BSD 3-Clause license.
6
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
- */
8
-
9
- // -------------------------------------------------------------------------------
10
- // No requires or imports since this is loaded early in the cli lifecycle and we
11
- // want to minimize the number of packages that load before enabling require
12
- // instrumentation.
13
- // -------------------------------------------------------------------------------
14
-
15
- export function _preprocessCliFlags(process) {
16
- process.argv.map((arg) => {
17
- if (arg === "--dev-debug") {
18
- let debug = "*";
19
- const filterIndex = process.argv.indexOf("--debug-filter");
20
- if (filterIndex > 0) {
21
- debug = process.argv[filterIndex + 1];
22
-
23
- process.argv.splice(filterIndex, 2);
24
- }
25
- // convert --dev-debug into a set of environment variables
26
- process.env.DEBUG = debug;
27
- process.env.PROCA_ENV = "development";
28
-
29
- // need to calculate indexOf --dev-debug here because it might've changed based on --debug-filter
30
- process.argv.splice(process.argv.indexOf("--dev-debug"), 1);
31
- }
32
- });
33
- }