@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.
Files changed (132) hide show
  1. package/README.md +1991 -61
  2. package/package.json +88 -72
  3. package/proca-cli +8 -0
  4. package/src/commands/action/add.mjs +192 -0
  5. package/src/commands/action/confirm.mjs +93 -0
  6. package/src/commands/action/count.mjs +61 -0
  7. package/src/commands/action/list.mjs +204 -0
  8. package/src/commands/action/replay.mjs +56 -0
  9. package/src/commands/action/requeue.mjs +156 -0
  10. package/src/commands/campaign/add.mjs +113 -0
  11. package/src/commands/campaign/copy.mjs +91 -0
  12. package/src/commands/campaign/delete.mjs +41 -0
  13. package/src/commands/campaign/get.mjs +132 -0
  14. package/src/commands/campaign/list.mjs +161 -0
  15. package/src/commands/campaign/mtt.mjs +131 -0
  16. package/src/commands/campaign/queries.graphql +19 -0
  17. package/src/commands/campaign/status.mjs +63 -0
  18. package/src/commands/campaign/widget/archive.mjs +124 -0
  19. package/src/commands/campaign/widget/copy.mjs +175 -0
  20. package/src/commands/campaign/widget/get.mjs +19 -0
  21. package/src/commands/campaign/widget/index.mjs +17 -0
  22. package/src/commands/campaign/widget/rebuild.mjs +50 -0
  23. package/src/commands/config/add.mjs +97 -0
  24. package/src/commands/config/folder.mjs +42 -0
  25. package/src/commands/config/server.mjs +33 -0
  26. package/src/commands/config/set.mjs +103 -0
  27. package/src/commands/config/user.mjs +79 -0
  28. package/src/commands/contact/count.mjs +41 -0
  29. package/src/commands/contact/list.mjs +207 -0
  30. package/src/commands/org/add.mjs +75 -0
  31. package/src/commands/org/crm.mjs +88 -0
  32. package/src/commands/org/delete.mjs +48 -0
  33. package/src/commands/org/email.mjs +111 -0
  34. package/src/commands/org/get.mjs +152 -0
  35. package/src/commands/service/add.mjs +78 -0
  36. package/src/commands/service/list.mjs +24 -0
  37. package/src/commands/target/add.mjs +94 -0
  38. package/src/commands/template/add.mjs +97 -0
  39. package/src/commands/template/list.mjs +61 -0
  40. package/src/commands/user/get.mjs +91 -0
  41. package/src/commands/user/invite.mjs +56 -0
  42. package/src/commands/user/join.mjs +81 -0
  43. package/src/commands/user/leave.mjs +57 -0
  44. package/src/commands/user/list.mjs +80 -0
  45. package/src/commands/user/reset.mjs +83 -0
  46. package/src/commands/widget/add.mjs +116 -0
  47. package/src/commands/widget/delete.mjs +45 -0
  48. package/src/commands/widget/get.mjs +60 -0
  49. package/src/commands/widget/list.mjs +135 -0
  50. package/src/commands/widget/rebuild.mjs +64 -0
  51. package/src/commands/widget/update.mjs +174 -0
  52. package/src/config.mjs +49 -0
  53. package/src/generated/schema.json +10677 -0
  54. package/src/hooks/help.mjs +14 -0
  55. package/src/hooks/init.mjs +41 -0
  56. package/src/index.mjs +1 -0
  57. package/src/procaCommand.mjs +316 -0
  58. package/src/queries/campaign.mjs +35 -0
  59. package/src/queries/widget.mjs +25 -0
  60. package/src/urql.mjs +60 -0
  61. package/src/util/twitter.mjs +23 -0
  62. package/theme.json +29 -0
  63. package/bin/proca-cli +0 -4
  64. package/dist/browser.d.ts +0 -1
  65. package/dist/browser.js +0 -28
  66. package/dist/browser.js.map +0 -1
  67. package/dist/campaign.d.ts +0 -156
  68. package/dist/campaign.js +0 -192
  69. package/dist/campaign.js.map +0 -1
  70. package/dist/cli.d.ts +0 -40
  71. package/dist/cli.js +0 -416
  72. package/dist/cli.js.map +0 -1
  73. package/dist/client.d.ts +0 -2
  74. package/dist/client.js +0 -18
  75. package/dist/client.js.map +0 -1
  76. package/dist/config.d.ts +0 -35
  77. package/dist/config.js +0 -71
  78. package/dist/config.js.map +0 -1
  79. package/dist/crypto.d.ts +0 -40
  80. package/dist/crypto.js +0 -53
  81. package/dist/crypto.js.map +0 -1
  82. package/dist/export.d.ts +0 -15
  83. package/dist/export.js +0 -145
  84. package/dist/export.js.map +0 -1
  85. package/dist/format.d.ts +0 -37
  86. package/dist/format.js +0 -200
  87. package/dist/format.js.map +0 -1
  88. package/dist/index.d.ts +0 -8
  89. package/dist/index.js +0 -39
  90. package/dist/index.js.map +0 -1
  91. package/dist/keys.d.ts +0 -4
  92. package/dist/keys.js +0 -38
  93. package/dist/keys.js.map +0 -1
  94. package/dist/org.d.ts +0 -11
  95. package/dist/org.js +0 -97
  96. package/dist/org.js.map +0 -1
  97. package/dist/proca.d.ts +0 -2095
  98. package/dist/proca.js +0 -398
  99. package/dist/proca.js.map +0 -1
  100. package/dist/queue.d.ts +0 -8
  101. package/dist/queue.js +0 -126
  102. package/dist/queue.js.map +0 -1
  103. package/dist/queueMessage.d.ts +0 -102
  104. package/dist/queueMessage.js +0 -109
  105. package/dist/queueMessage.js.map +0 -1
  106. package/dist/service/actionnetwork.d.ts +0 -10
  107. package/dist/service/actionnetwork.js +0 -302
  108. package/dist/service/actionnetwork.js.map +0 -1
  109. package/dist/service/distance.d.ts +0 -3
  110. package/dist/service/distance.js +0 -96
  111. package/dist/service/distance.js.map +0 -1
  112. package/dist/service/echo.d.ts +0 -4
  113. package/dist/service/echo.js +0 -19
  114. package/dist/service/echo.js.map +0 -1
  115. package/dist/service/email.d.ts +0 -14
  116. package/dist/service/email.js +0 -67
  117. package/dist/service/email.js.map +0 -1
  118. package/dist/service/identity.d.ts +0 -58
  119. package/dist/service/identity.js +0 -190
  120. package/dist/service/identity.js.map +0 -1
  121. package/dist/service/index.d.ts +0 -14
  122. package/dist/service/index.js +0 -61
  123. package/dist/service/index.js.map +0 -1
  124. package/dist/setup.d.ts +0 -2
  125. package/dist/setup.js +0 -291
  126. package/dist/setup.js.map +0 -1
  127. package/dist/util.d.ts +0 -5
  128. package/dist/util.js +0 -30
  129. package/dist/util.js.map +0 -1
  130. package/dist/watch.d.ts +0 -9
  131. package/dist/watch.js +0 -80
  132. package/dist/watch.js.map +0 -1
@@ -0,0 +1,174 @@
1
+ import { Args, Flags } from "@oclif/core";
2
+ import { 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 WidgetUpdate extends Command {
8
+ static description = "Update a widget's properties";
9
+
10
+ static examples = [
11
+ "<%= config.bin %> <%= command.id %> 4454 --name new_widget_name",
12
+ "<%= config.bin %> <%= command.id %> 4454 --locale fr",
13
+ "<%= config.bin %> <%= command.id %> 4454 --confirm-optin",
14
+ "<%= config.bin %> <%= command.id %> 4454 --confirm-optin --dry-run",
15
+ ];
16
+
17
+ static args = this.multiid();
18
+
19
+ static flags = {
20
+ // flag with no value (-f, --force)
21
+ ...this.flagify({ multiid: true }),
22
+ rename: Flags.string({
23
+ char: "n",
24
+ description: "new name for the widget",
25
+ helpValue: "<widget name>",
26
+ }),
27
+
28
+ locale: Flags.string({
29
+ char: "l",
30
+ description: "change the locale",
31
+ helpValue: "<locale>",
32
+ }),
33
+ color: Flags.string({
34
+ description: "update color (not yet implemented)",
35
+ helpValue: "<hex code>",
36
+ }),
37
+ "confirm-optin": Flags.boolean({
38
+ description:
39
+ "add confirmOptIn (check email snack) to consent.email component ",
40
+
41
+ default: false,
42
+ }),
43
+ "confirm-action": Flags.boolean({
44
+ description:
45
+ "add actionConfirm (check email snack) to consent.email component ",
46
+
47
+ default: false,
48
+ }),
49
+
50
+ "dry-run": Flags.boolean({
51
+ description: "Show changes without updating the widget",
52
+ default: false,
53
+ }),
54
+ };
55
+
56
+ fetchWidget = async (params) => {
57
+ const widgetGet = new WidgetGet([], this.config);
58
+ return widgetGet.fetch(params);
59
+ };
60
+
61
+ update = async (widgetId, input) => {
62
+ console.log("Updating widget with input:", input);
63
+ const Document = gql`
64
+ mutation UpdateActionPage($id: Int!, $input: ActionPageInput!) {
65
+ updateActionPage(id: $id, input: $input) {
66
+ id
67
+ name
68
+ locale
69
+ config
70
+ thankYouTemplate
71
+ }
72
+ }
73
+ `;
74
+
75
+ const payload = {
76
+ ...input,
77
+ ...(input.config && typeof input.config !== "string"
78
+ ? { config: JSON.stringify(input.config) }
79
+ : {}),
80
+ };
81
+
82
+ const r = await mutation(Document, {
83
+ id: widgetId,
84
+ input: payload,
85
+ });
86
+
87
+ return r.updateActionPage;
88
+ };
89
+
90
+ table = (r) => {
91
+ super.table(r, null, null);
92
+ if (this.flags.config) {
93
+ this.prettyJson(r.config);
94
+ }
95
+ };
96
+
97
+ async run() {
98
+ const { flags } = await this.parse();
99
+ const {
100
+ id,
101
+ rename,
102
+ locale,
103
+ color,
104
+ "confirm-optin": confirmOptIn,
105
+ "confirm-action": confirmAction,
106
+ "dry-run": dryRun,
107
+ } = flags;
108
+
109
+ // Fetch current widget
110
+ const widget = await this.fetchWidget({ id });
111
+
112
+ if (!widget) {
113
+ this.error("Widget not found");
114
+ }
115
+
116
+ // Validate name
117
+ if (rename) {
118
+ const nameParts = renname.split("/");
119
+ if (nameParts.length < 2) {
120
+ this.error(
121
+ "Widget name must follow format: campaign_name/org_name or campaign_name/locale or campaign_name/org_name/locale",
122
+ );
123
+ }
124
+ }
125
+
126
+ const input = {
127
+ name: rename ?? widget.name,
128
+ locale: locale ?? widget.locale,
129
+ };
130
+
131
+ if (color) {
132
+ this.error(`Color update requested: ${color} (not yet implemented)`);
133
+ }
134
+ if (confirmOptIn || confirmAction) {
135
+ const act = confirmOptIn ? "confirmOptIn" : "confirmAction";
136
+ const currentConfig =
137
+ typeof widget.config === "string"
138
+ ? JSON.parse(widget.config)
139
+ : (widget.config ?? {});
140
+
141
+ const nextConfig = merge(currentConfig, {
142
+ component: {
143
+ consent: {
144
+ email: {
145
+ [act]: true,
146
+ },
147
+ },
148
+ },
149
+ });
150
+
151
+ input.config = nextConfig;
152
+
153
+ this.log(`✓ Will set consent.email.${act} = true`);
154
+
155
+ if (dryRun) {
156
+ this.log("\n--- DRY RUN ---\n");
157
+ this.log("FROM:");
158
+ this.log(JSON.stringify(currentConfig, null, 2));
159
+ this.log("\nTO:");
160
+ this.log(JSON.stringify(nextConfig, null, 2));
161
+ this.log("\n(no mutation executed)");
162
+ return;
163
+ }
164
+ }
165
+
166
+ try {
167
+ const updated = await this.update(widget.id, input);
168
+ this.log("✓ Widget updated successfully");
169
+ return this.output(updated);
170
+ } catch (err) {
171
+ this.error(`Failed to update widget: ${err.message}`);
172
+ }
173
+ }
174
+ }
package/src/config.mjs ADDED
@@ -0,0 +1,49 @@
1
+ import { readFileSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { config as dotenv } from "dotenv";
4
+
5
+ export const getFilename = (folder, env = "default") =>
6
+ join(folder, `${env}.env`);
7
+
8
+ export const load = (folder, env = "default") => {
9
+ const file = getFilename(folder, env);
10
+ const config = dotenv({ path: file });
11
+
12
+ return {
13
+ token: config.parsed.PROCA_TOKEN,
14
+ url: config.parsed.REACT_APP_API_URL,
15
+ folder: process.env.PROCA_CONFIG_FOLDER,
16
+ };
17
+ };
18
+
19
+ export const get = (file, parsed = false) => {
20
+ try {
21
+ if (parsed) {
22
+ const config = dotenv({ path: file });
23
+ return config.parsed;
24
+ }
25
+ const userConfig = readFileSync(file, "utf8");
26
+ return userConfig;
27
+ } catch (e) {
28
+ if (e.code === "ENOENT") {
29
+ return undefined;
30
+ }
31
+ throw e;
32
+ }
33
+ };
34
+
35
+ export const write = (file, content) => {
36
+ writeFileSync(file, content);
37
+ };
38
+
39
+ export const format = (obj) => {
40
+ const content = ["# generated by proca-cli"];
41
+ for (const [key, value] of Object.entries(obj)) {
42
+ if (value) {
43
+ content.push(`${key}='${value.replace(/'/g, "''")}'`);
44
+ } else {
45
+ content.push(`#${key}= `);
46
+ }
47
+ }
48
+ return content.join("\n");
49
+ };