@pipedream/click2mail2 0.0.1 → 0.1.0

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.
@@ -0,0 +1,91 @@
1
+ import FormData from "form-data";
2
+ import fs from "fs";
3
+ import click2mail2 from "../../click2mail2.app.mjs";
4
+ import { FORMATS } from "../../common/constants.mjs";
5
+
6
+ export default {
7
+ key: "click2mail2-create-document",
8
+ name: "Create Document",
9
+ version: "0.0.1",
10
+ description: "Creates a new document in your account from an uploaded file or a URL. [See the documentation for file](https://developers.click2mail.com/reference/createdocument_1). [See the documentation for URL](https://developers.click2mail.com/reference/createdocumentfromurl)",
11
+ type: "action",
12
+ props: {
13
+ click2mail2,
14
+ uploadType: {
15
+ type: "string",
16
+ label: "Upload Type",
17
+ description: "The type of the upload.",
18
+ reloadProps: true,
19
+ options: [
20
+ "URL",
21
+ "File",
22
+ ],
23
+ },
24
+ documentName: {
25
+ type: "string",
26
+ label: "Document Name",
27
+ description: "Document name as it will be stored in your account.",
28
+ optional: true,
29
+ },
30
+ documentFormat: {
31
+ type: "string",
32
+ label: "Document Format",
33
+ description: "The format of the document.",
34
+ options: FORMATS,
35
+ },
36
+ documentClass: {
37
+ propDefinition: [
38
+ click2mail2,
39
+ "documentClass",
40
+ ],
41
+ },
42
+ },
43
+ async additionalProps() {
44
+ const props = {};
45
+ if (this.uploadType === "URL") {
46
+ props.url = {
47
+ type: "string",
48
+ label: "URL",
49
+ description: "Document url",
50
+ };
51
+ } else {
52
+ props.file = {
53
+ type: "string",
54
+ label: "File",
55
+ description: "Path of the file in /tmp folder. To upload a file to /tmp folder, please follow the [doc here](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
56
+ };
57
+ }
58
+ return props;
59
+ },
60
+ async run({ $ }) {
61
+ const {
62
+ click2mail2,
63
+ uploadType,
64
+ file,
65
+ ...params
66
+ } = this;
67
+
68
+ let objToSend = {};
69
+
70
+ if (uploadType === "File") {
71
+ const formData = new FormData();
72
+ formData.append("file", fs.createReadStream(file));
73
+
74
+ objToSend = {
75
+ data: formData,
76
+ headers: formData.getHeaders(),
77
+ };
78
+ }
79
+ const response = await click2mail2.create({
80
+ $,
81
+ path: `${uploadType === "File"
82
+ ? "documents"
83
+ : "documents/url"}`,
84
+ params,
85
+ ...objToSend,
86
+ });
87
+
88
+ $.export("$summary", `A new file with Id: ${response.id} was successfully created!`);
89
+ return response;
90
+ },
91
+ };
@@ -0,0 +1,196 @@
1
+ import click2mail2 from "../../click2mail2.app.mjs";
2
+ import {
3
+ COLOR,
4
+ ENVELOPE,
5
+ LAYOUT,
6
+ MAILCLASS,
7
+ PAPERTYPE,
8
+ PRINTOPTION,
9
+ } from "../../common/constants.mjs";
10
+
11
+ export default {
12
+ key: "click2mail2-create-job",
13
+ name: "Create Job",
14
+ version: "0.0.1",
15
+ description: "Creates a new new job in your account. [See the documentation](https://developers.click2mail.com/reference/post_2).",
16
+ type: "action",
17
+ props: {
18
+ click2mail2,
19
+ documentClass: {
20
+ propDefinition: [
21
+ click2mail2,
22
+ "documentClass",
23
+ ],
24
+ },
25
+ layout: {
26
+ type: "string",
27
+ label: "Layout",
28
+ description: "The specific type of the product",
29
+ options: LAYOUT,
30
+ },
31
+ envelope: {
32
+ type: "string",
33
+ label: "Envelope",
34
+ description: "If this is an enveloped product this determines the envelope in which the product is to be mailed; otherwise provide no value.",
35
+ options: ENVELOPE,
36
+ },
37
+ color: {
38
+ type: "string",
39
+ label: "Color",
40
+ description: "Print in color or black and white.",
41
+ options: COLOR,
42
+ },
43
+ paperType: {
44
+ type: "string",
45
+ label: "Paper Type",
46
+ description: "Sets the paper the mailing is to be printed on.",
47
+ options: PAPERTYPE,
48
+ },
49
+ printOption: {
50
+ type: "string",
51
+ label: "Print Option",
52
+ description: "Sets simplex or duplex printing.",
53
+ options: PRINTOPTION,
54
+ },
55
+ documentId: {
56
+ propDefinition: [
57
+ click2mail2,
58
+ "documentId",
59
+ ],
60
+ optional: true,
61
+ },
62
+ addressId: {
63
+ propDefinition: [
64
+ click2mail2,
65
+ "addressId",
66
+ ],
67
+ optional: true,
68
+ },
69
+ rtnName: {
70
+ type: "string",
71
+ label: "RTN Name",
72
+ description: "Return address Name.",
73
+ optional: true,
74
+ },
75
+ rtnOrganization: {
76
+ type: "string",
77
+ label: "RTN Organization",
78
+ description: "Return address Organization.",
79
+ optional: true,
80
+ },
81
+ rtnaddress1: {
82
+ type: "string",
83
+ label: "RTN Address1",
84
+ description: "Return address line 1.",
85
+ optional: true,
86
+ },
87
+ rtnaddress2: {
88
+ type: "string",
89
+ label: "RTN Address2",
90
+ description: "Return address line 2.",
91
+ optional: true,
92
+ },
93
+ rtnCity: {
94
+ type: "string",
95
+ label: "RTN City",
96
+ description: "Return address City.",
97
+ optional: true,
98
+ },
99
+ rtnState: {
100
+ type: "string",
101
+ label: "RTN State",
102
+ description: "Return address State.",
103
+ optional: true,
104
+ },
105
+ rtnZip: {
106
+ type: "string",
107
+ label: "RTN Zip",
108
+ description: "Return address Zip.",
109
+ optional: true,
110
+ },
111
+ mailClass: {
112
+ type: "string",
113
+ label: "Mail Class",
114
+ description: "Overrides the default of First Class for mailed products.",
115
+ options: MAILCLASS,
116
+ optional: true,
117
+ },
118
+ appSignature: {
119
+ type: "string",
120
+ label: "APP Signature",
121
+ description: "This is a short signature to identify orders that come from your app.",
122
+ optional: true,
123
+ },
124
+ projectId: {
125
+ propDefinition: [
126
+ click2mail2,
127
+ "projectId",
128
+ ],
129
+ optional: true,
130
+ },
131
+ mailingDate: {
132
+ type: "string",
133
+ label: "Mailing Date",
134
+ description: "Used to schedule the mailing date in the future. Format YYYYMMDD. If not provided the order will be mailed on the next available on the next business day. The business day cut off is 8PM EST.",
135
+ optional: true,
136
+ },
137
+ quantity: {
138
+ type: "string",
139
+ label: "Quantity",
140
+ description: "For products that do not use mailing lists. Quantity to print.",
141
+ optional: true,
142
+ },
143
+ jobDocumentId: {
144
+ propDefinition: [
145
+ click2mail2,
146
+ "jobDocumentId",
147
+ ({ documentId }) => ({
148
+ documentId,
149
+ }),
150
+ ],
151
+ optional: true,
152
+ },
153
+ jobAddressId: {
154
+ type: "string",
155
+ label: "Job Address Id",
156
+ description: "Address List Id of the job version.",
157
+ optional: true,
158
+ },
159
+ businessReplyAddressId: {
160
+ type: "integer",
161
+ label: "Business Reply Address Id",
162
+ description: "If you are mailing a business reply mail product use this to specify the busines reply address and permit information already in your account.",
163
+ optional: true,
164
+ },
165
+ courtesyReplyAddressId: {
166
+ type: "integer",
167
+ label: "Courtesy Reply Address Id",
168
+ description: "If you are mailing a courtesy reply mail product use this to specify a courtesy reply address already in your account.",
169
+ optional: true,
170
+ },
171
+ returnAddressId: {
172
+ type: "integer",
173
+ label: "Return Address Id",
174
+ description: "You may use the return address id to specify a return address already in your account.",
175
+ optional: true,
176
+ },
177
+ },
178
+ async run({ $ }) {
179
+ const {
180
+ click2mail2,
181
+ ...params
182
+ } = this;
183
+
184
+ const response = await click2mail2.create({
185
+ $,
186
+ path: "jobs",
187
+ params: {
188
+ productionTime: "Next Day",
189
+ ...params,
190
+ },
191
+ });
192
+
193
+ $.export("$summary", `A new job with Id: ${response.id} was successfully created!`);
194
+ return response;
195
+ },
196
+ };
@@ -1,11 +1,143 @@
1
+ import { axios } from "@pipedream/platform";
2
+ import {
3
+ CLASSES, LIMIT,
4
+ } from "./common/constants.mjs";
5
+
1
6
  export default {
2
7
  type: "app",
3
8
  app: "click2mail2",
4
- propDefinitions: {},
9
+ propDefinitions: {
10
+ addressId: {
11
+ type: "string",
12
+ label: "Address Id",
13
+ description: "This required if the product required a recipient address list.",
14
+ async options({ page }) {
15
+ const { addressListsInfo } = await this.list({
16
+ path: "addressLists",
17
+ params: {
18
+ numberOfDocuments: LIMIT,
19
+ offset: page * LIMIT,
20
+ },
21
+ });
22
+
23
+ return addressListsInfo.map(({
24
+ id: value, name: label,
25
+ }) => ({
26
+ label,
27
+ value,
28
+ }));
29
+ },
30
+ },
31
+ documentClass: {
32
+ type: "string",
33
+ label: "Document Class",
34
+ description: "The general type of the document.",
35
+ options: CLASSES,
36
+ },
37
+ documentId: {
38
+ type: "string",
39
+ label: "Document Id",
40
+ description: "ID of the document to print",
41
+ async options({ page }) {
42
+ const { document } = await this.list({
43
+ path: "documents",
44
+ params: {
45
+ numberOfDocuments: LIMIT,
46
+ offset: page * LIMIT,
47
+ },
48
+ });
49
+
50
+ return document.map(({
51
+ id: value, name: label,
52
+ }) => ({
53
+ label,
54
+ value,
55
+ }));
56
+ },
57
+ },
58
+ jobDocumentId: {
59
+ type: "string",
60
+ label: "Job Document Id",
61
+ description: "Document ID of the job version of the document.",
62
+ async options({
63
+ page, documentId,
64
+ }) {
65
+ try {
66
+
67
+ const { documentJob } = await this.list({
68
+ path: "documents/jobDocuments",
69
+ params: {
70
+ numberOfDocuments: LIMIT,
71
+ offset: page * LIMIT,
72
+ documentId,
73
+ },
74
+ });
75
+
76
+ return documentJob.map(({
77
+ jobId: value, description, product,
78
+ }) => ({
79
+ label: description || product,
80
+ value,
81
+ }));
82
+ } catch (e) {
83
+ return [];
84
+ }
85
+ },
86
+ },
87
+ projectId: {
88
+ type: "integer",
89
+ label: "Project Id",
90
+ description: "Use to place this job in a pre-existing project in your account",
91
+ async options({ page }) {
92
+ const { projects } = await this.list({
93
+ path: "projects",
94
+ params: {
95
+ numberOfDocuments: LIMIT,
96
+ offset: page * LIMIT,
97
+ },
98
+ });
99
+
100
+ return projects.map(({
101
+ id: value, name: label,
102
+ }) => ({
103
+ label,
104
+ value,
105
+ }));
106
+ },
107
+ },
108
+ },
5
109
  methods: {
6
- // this.$auth contains connected account data
7
- authKeys() {
8
- console.log(Object.keys(this.$auth));
110
+ _apiUrl() {
111
+ return `https://${this.$auth.subdomain}.click2mail.com/molpro`;
112
+ },
113
+ _getAuth() {
114
+ return {
115
+ "username": `${this.$auth.username}`,
116
+ "password": `${this.$auth.password}`,
117
+ };
118
+ },
119
+ _makeRequest({
120
+ $ = this, path, ...opts
121
+ }) {
122
+ const config = {
123
+ url: `${this._apiUrl()}/${path}`,
124
+ auth: this._getAuth(),
125
+ ...opts,
126
+ };
127
+
128
+ return axios($, config);
129
+ },
130
+ create(args = {}) {
131
+ return this._makeRequest({
132
+ method: "POST",
133
+ ...args,
134
+ });
135
+ },
136
+ list(args = {}) {
137
+ return this._makeRequest({
138
+ method: "GET",
139
+ ...args,
140
+ });
9
141
  },
10
142
  },
11
- };
143
+ };
@@ -0,0 +1,117 @@
1
+ export const CLASSES = [
2
+ "Postcard 6 x 11",
3
+ "Postcard 5 x 8",
4
+ "Postcard 4.25 x 6",
5
+ "Postcard 3.5 x 5",
6
+ "Postcard 4 x 9",
7
+ "Postcard 6 x 9",
8
+ "Notecard 4.25 x 5.5",
9
+ "Notecard - Folded 4.25 x 5.5",
10
+ "Rack Card 4 x 9 - Mailed",
11
+ "Flyer 8.5 x 11",
12
+ "Brochure 11 x 8.5",
13
+ "Letter 8.5 x 11",
14
+ "Letter 8.5 x 14",
15
+ "Secure Self Mailer 8.5 x 11",
16
+ "Booklet Self Mailer 8.5 x 11",
17
+ "Booklet 8.5 x 11 - Address Front Page",
18
+ "Booklet 8.5 x 11 - Address Back Page",
19
+ "Reply Letter 8.5 x 11",
20
+ "Reply Postcard 4.25 x 6",
21
+ "Certified Letter 8.5 x 11",
22
+ "Certified Self Mailer 8.5 x 11",
23
+ "Certified Self Mailer - with Green Card Receipt",
24
+ "Priority Letter 8.5 x 11",
25
+ "Priority Mail Express Letter 8.5 x 11",
26
+ "EDDM Mailer 6.25 x 11",
27
+ "EDDM Mailer 6.5 x 9",
28
+ "EDDM Mailer 8.5 x 12",
29
+ "EDDM Mailer 8.5 x 11",
30
+ "Postcard 3.5 x 5 - Shipped",
31
+ "Brochure 11 x 8.5 - Shipped",
32
+ "Postcard 4.25 x 6 - Shipped",
33
+ "Postcard 5 x 8 - Shipped",
34
+ "Postcard 6 x 11 - Shipped",
35
+ "Postcard 6.5 x 9 - Shipped",
36
+ "Cardstock 12 x 4.5 - Shipped",
37
+ "Flyer 8.5 x 11 - Shipped",
38
+ "Postcard 4 x 9 - Shipped",
39
+ "Rack Card 4 x 9 - Shipped",
40
+ "Postcard 4.25 x 6 Movers Format",
41
+ ];
42
+
43
+ export const COLOR = [
44
+ "Full Color",
45
+ "Black and White",
46
+ ];
47
+
48
+ export const ENDROSEMENT = [
49
+ {
50
+ "label": "No Ancillary Endorsement",
51
+ "value": "NONE",
52
+ },
53
+ {
54
+ "label": "Address Service Requested",
55
+ "value": "ADDRESS_SERVICE_REQUESTED",
56
+ },
57
+ {
58
+ "label": "Forwarding Service Requested",
59
+ "value": "FORWARDING_SERVICE_REQUESTED",
60
+ },
61
+ {
62
+ "label": "Return Service Requested",
63
+ "value": "RETURN_SERVICE_REQUESTED",
64
+ },
65
+ ];
66
+
67
+ export const ENVELOPE = [
68
+ "#10 Double Window",
69
+ "Best Fit",
70
+ "#10 Open Window Envelope",
71
+ "6 x 9.5 Double Window",
72
+ "6 x 9.5 Open Window",
73
+ "Flat Envelope",
74
+ ];
75
+
76
+ export const FORMATS = [
77
+ "PDF",
78
+ "DOC",
79
+ "DOCX",
80
+ "PUB",
81
+ "PPT",
82
+ "PPTX",
83
+ "ODT",
84
+ "JPEG",
85
+ "JPG",
86
+ "PNG",
87
+ ];
88
+
89
+ export const LAYOUT = [
90
+ "Address on Separate Page",
91
+ "Address on First Page",
92
+ "Picture and Address First Page",
93
+ "Address Back Page",
94
+ ];
95
+
96
+ export const LIMIT = 100;
97
+
98
+ export const MAILCLASS = [
99
+ "First Class",
100
+ "Standard",
101
+ "First Class Live Stamp",
102
+ "First Class Specialty Stamp",
103
+ "First Class No Move Update",
104
+ ];
105
+
106
+ export const PAPERTYPE = [
107
+ "White 24#",
108
+ "Off-White 28#",
109
+ "Canary 24#",
110
+ "White 28#",
111
+ "White 28# Matte",
112
+ ];
113
+
114
+ export const PRINTOPTION = [
115
+ "Printing One side",
116
+ "Printing both sides",
117
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/click2mail2",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Pipedream Click2Mail Components",
5
5
  "main": "click2mail2.app.mjs",
6
6
  "keywords": [
@@ -11,5 +11,10 @@
11
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12
12
  "publishConfig": {
13
13
  "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@pipedream/platform": "^1.5.1",
17
+ "form-data": "^4.0.0",
18
+ "fs": "^0.0.1-security"
14
19
  }
15
20
  }