@pipedream/billsby 0.0.3 → 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,39 @@
1
+ import billsby from "../../billsby.app.mjs";
2
+
3
+ export default {
4
+ key: "billsby-add-feature-tags",
5
+ name: "Add Feature Tags",
6
+ description: "Add feature tags to a subscription. [See the documentation](https://support.billsby.com/reference/post-subscription-tags)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ annotations: {
10
+ destructiveHint: false,
11
+ openWorldHint: true,
12
+ readOnlyHint: false,
13
+ },
14
+ props: {
15
+ billsby,
16
+ subscriptionIds: {
17
+ propDefinition: [
18
+ billsby,
19
+ "subscriptionIds",
20
+ ],
21
+ },
22
+ tagNames: {
23
+ type: "string[]",
24
+ label: "Tag Names",
25
+ description: "The names of the tags to add to the subscription",
26
+ },
27
+ },
28
+ async run({ $ }) {
29
+ const response = await this.billsby.addFeatureTags({
30
+ $,
31
+ data: {
32
+ subscriptionUniqueIds: this.subscriptionIds,
33
+ tagNames: this.tagNames,
34
+ },
35
+ });
36
+ $.export("$summary", "Successfully added feature tags to subscription");
37
+ return response;
38
+ },
39
+ };
@@ -0,0 +1,51 @@
1
+ import billsby from "../../billsby.app.mjs";
2
+
3
+ export default {
4
+ key: "billsby-create-one-time-charge",
5
+ name: "Create One-Time Charge",
6
+ description: "Create a one-time charge for a customer. [See the documentation](https://support.billsby.com/reference/create-a-one-time-charge)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ annotations: {
10
+ destructiveHint: false,
11
+ openWorldHint: true,
12
+ readOnlyHint: false,
13
+ },
14
+ props: {
15
+ billsby,
16
+ customerId: {
17
+ propDefinition: [
18
+ billsby,
19
+ "customerId",
20
+ ],
21
+ },
22
+ currencyCode: {
23
+ type: "string",
24
+ label: "Currency Code",
25
+ description: "The code for the currency of the one-time charge",
26
+ },
27
+ amount: {
28
+ type: "integer",
29
+ label: "Amount",
30
+ description: "The amount of the one-time charge",
31
+ },
32
+ description: {
33
+ type: "string",
34
+ label: "Description",
35
+ description: "The description for the one-time charge",
36
+ },
37
+ },
38
+ async run({ $ }) {
39
+ const response = await this.billsby.createOneTimeCharge({
40
+ $,
41
+ customerId: this.customerId,
42
+ data: {
43
+ currencyCode: this.currencyCode,
44
+ amount: this.amount,
45
+ description: this.description,
46
+ },
47
+ });
48
+ $.export("$summary", "Successfully created one-time charge");
49
+ return response;
50
+ },
51
+ };
@@ -0,0 +1,125 @@
1
+ import billsby from "../../billsby.app.mjs";
2
+
3
+ export default {
4
+ key: "billsby-update-customer-details",
5
+ name: "Update Customer Details",
6
+ description: "Update the details of a customer. [See the documentation](https://support.billsby.com/reference/put-customer)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ annotations: {
10
+ destructiveHint: true,
11
+ openWorldHint: true,
12
+ readOnlyHint: false,
13
+ },
14
+ props: {
15
+ billsby,
16
+ customerId: {
17
+ propDefinition: [
18
+ billsby,
19
+ "customerId",
20
+ ],
21
+ },
22
+ firstName: {
23
+ type: "string",
24
+ label: "First Name",
25
+ description: "The first name of the customer",
26
+ optional: true,
27
+ },
28
+ lastName: {
29
+ type: "string",
30
+ label: "Last Name",
31
+ description: "The last name of the customer",
32
+ optional: true,
33
+ },
34
+ email: {
35
+ type: "string",
36
+ label: "Email",
37
+ description: "The email of the customer",
38
+ optional: true,
39
+ },
40
+ addressLine1: {
41
+ type: "string",
42
+ label: "Address Line 1",
43
+ description: "The first line of the address of the customer",
44
+ optional: true,
45
+ },
46
+ addressLine2: {
47
+ type: "string",
48
+ label: "Address Line 2",
49
+ description: "The second line of the address of the customer",
50
+ optional: true,
51
+ },
52
+ city: {
53
+ type: "string",
54
+ label: "City",
55
+ description: "The city of the address of the customer",
56
+ optional: true,
57
+ },
58
+ state: {
59
+ type: "string",
60
+ label: "State",
61
+ description: "The state of the address of the customer",
62
+ optional: true,
63
+ },
64
+ postCode: {
65
+ type: "string",
66
+ label: "Post Code",
67
+ description: "The postal code of the address of the customer",
68
+ optional: true,
69
+ },
70
+ country: {
71
+ type: "string",
72
+ label: "Country",
73
+ description: "The country of the address of the customer",
74
+ optional: true,
75
+ },
76
+ phoneNumberDialCountry: {
77
+ type: "string",
78
+ label: "Phone Number Dial Country",
79
+ description: "The customers phone number dial country (i.e. \"UK\")",
80
+ optional: true,
81
+ },
82
+ phoneNumberDialCode: {
83
+ type: "string",
84
+ label: "Phone Number Dial Code",
85
+ description: "The customer phone number dial code",
86
+ optional: true,
87
+ },
88
+ phoneNumber: {
89
+ type: "string",
90
+ label: "Phone Number",
91
+ description: "The customer phone number",
92
+ optional: true,
93
+ },
94
+ },
95
+ async run({ $ }) {
96
+ const customer = await this.billsby.getCustomer({
97
+ $,
98
+ customerId: this.customerId,
99
+ });
100
+
101
+ const response = await this.billsby.updateCustomer({
102
+ $,
103
+ customerId: this.customerId,
104
+ data: {
105
+ firstName: this.firstName || customer.firstName,
106
+ lastName: this.lastName || customer.lastName,
107
+ email: this.email || customer.email,
108
+ phoneNumberDialCountry: this.phoneNumberDialCountry || customer.phoneNumberDialCountry,
109
+ phoneNumberDialCode: this.phoneNumberDialCode || customer.phoneNumberDialCode,
110
+ phoneNumber: this.phoneNumber || customer.phoneNumber,
111
+ billingAddress: {
112
+ addressLine1: this.addressLine1 || customer.billingAddress.addressLine1,
113
+ addressLine2: this.addressLine2 || customer.billingAddress.addressLine2,
114
+ city: this.city || customer.billingAddress.city,
115
+ state: this.state || customer.billingAddress.state,
116
+ postCode: this.postCode || customer.billingAddress.postCode,
117
+ country: this.country || customer.billingAddress.country,
118
+ },
119
+ },
120
+ });
121
+
122
+ $.export("$summary", "Successfully updated customer details");
123
+ return response;
124
+ },
125
+ };
package/billsby.app.mjs CHANGED
@@ -1,11 +1,143 @@
1
+ import { axios } from "@pipedream/platform";
2
+
1
3
  export default {
2
4
  type: "app",
3
5
  app: "billsby",
4
- propDefinitions: {},
6
+ propDefinitions: {
7
+ customerId: {
8
+ type: "string",
9
+ label: "Customer ID",
10
+ description: "The ID of the customer",
11
+ useQuery: true,
12
+ async options({
13
+ page, query,
14
+ }) {
15
+ const { results } = await this.listCustomers({
16
+ params: {
17
+ page: page + 1,
18
+ pageSize: 50,
19
+ search: query,
20
+ },
21
+ });
22
+ return results?.map(({
23
+ customerUniqueId: value, firstName, lastName,
24
+ }) => ({
25
+ label: `${firstName} ${lastName}`,
26
+ value,
27
+ })) || [];
28
+ },
29
+ },
30
+ subscriptionIds: {
31
+ type: "string[]",
32
+ label: "Subscription IDs",
33
+ description: "The IDs of the subscriptions",
34
+ async options({ page }) {
35
+ const { results } = await this.listSubscriptions({
36
+ params: {
37
+ page: page + 1,
38
+ pageSize: 50,
39
+ },
40
+ });
41
+ return results?.map(({
42
+ subscriptionUniqueId: value, customerFullname, productName,
43
+ }) => ({
44
+ label: `${customerFullname} - ${productName}`,
45
+ value,
46
+ })) || [];
47
+ },
48
+ },
49
+ },
5
50
  methods: {
6
- // this.$auth contains connected account data
7
- authKeys() {
8
- console.log(Object.keys(this.$auth));
51
+ _baseUrl() {
52
+ return `https://public.billsby.com/api/v1/rest/core/${this.$auth.company_domain}`;
53
+ },
54
+ _makeRequest({
55
+ $ = this, path, ...opts
56
+ }) {
57
+ return axios($, {
58
+ url: `${this._baseUrl()}${path}`,
59
+ headers: {
60
+ ApiKey: this.$auth.api_key,
61
+ },
62
+ ...opts,
63
+ });
64
+ },
65
+ getCustomer({
66
+ customerId, ...opts
67
+ }) {
68
+ return this._makeRequest({
69
+ path: `/customers/${customerId}`,
70
+ ...opts,
71
+ });
72
+ },
73
+ listCustomers(opts = {}) {
74
+ return this._makeRequest({
75
+ path: "/customers",
76
+ ...opts,
77
+ });
78
+ },
79
+ listSubscriptions(opts = {}) {
80
+ return this._makeRequest({
81
+ path: "/subscriptions",
82
+ ...opts,
83
+ });
84
+ },
85
+ listCompanyInvoices(opts = {}) {
86
+ return this._makeRequest({
87
+ path: "/companies/invoices",
88
+ ...opts,
89
+ });
90
+ },
91
+ createOneTimeCharge({
92
+ customerId, ...opts
93
+ }) {
94
+ return this._makeRequest({
95
+ method: "POST",
96
+ path: `/customers/${customerId}/invoices`,
97
+ ...opts,
98
+ });
99
+ },
100
+ updateCustomer({
101
+ customerId, ...opts
102
+ }) {
103
+ return this._makeRequest({
104
+ method: "PUT",
105
+ path: `/customers/${customerId}`,
106
+ ...opts,
107
+ });
108
+ },
109
+ addFeatureTags(opts = {}) {
110
+ return this._makeRequest({
111
+ method: "POST",
112
+ path: "/subscriptions/tags",
113
+ ...opts,
114
+ });
115
+ },
116
+ async *paginate({
117
+ fn, params, max,
118
+ }) {
119
+ params = {
120
+ ...params,
121
+ page: 1,
122
+ pageSize: 100,
123
+ };
124
+ let total, count = 0;
125
+ do {
126
+ const { results } = await fn({
127
+ params,
128
+ });
129
+ if (!results?.length) {
130
+ return;
131
+ }
132
+ for (const item of results) {
133
+ yield item;
134
+ if (max && ++count >= max) {
135
+ return;
136
+ }
137
+ }
138
+ total = results.length;
139
+ params.page++;
140
+ } while (total === params.pageSize);
9
141
  },
10
142
  },
11
143
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/billsby",
3
- "version": "0.0.3",
3
+ "version": "0.1.0",
4
4
  "description": "Pipedream Billsby Components",
5
5
  "main": "billsby.app.mjs",
6
6
  "keywords": [
@@ -11,5 +11,8 @@
11
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12
12
  "publishConfig": {
13
13
  "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@pipedream/platform": "^3.3.0"
14
17
  }
15
18
  }
@@ -0,0 +1,75 @@
1
+ import billsby from "../../billsby.app.mjs";
2
+ import {
3
+ DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, ConfigurationError,
4
+ } from "@pipedream/platform";
5
+
6
+ export default {
7
+ props: {
8
+ billsby,
9
+ db: "$.service.db",
10
+ timer: {
11
+ type: "$.interface.timer",
12
+ default: {
13
+ intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
14
+ },
15
+ },
16
+ },
17
+ methods: {
18
+ _getLastId() {
19
+ return this.db.get("lastId") || 0;
20
+ },
21
+ _setLastId(lastId) {
22
+ this.db.set("lastId", lastId);
23
+ },
24
+ getParams() {
25
+ return {};
26
+ },
27
+ getTsField() {
28
+ return "createdOn";
29
+ },
30
+ async processEvents(max) {
31
+ const lastId = this._getLastId();
32
+
33
+ const results = this.billsby.paginate({
34
+ fn: this.getResourceFn(),
35
+ params: this.getParams(),
36
+ max,
37
+ });
38
+
39
+ let items = [];
40
+ for await (const item of results) {
41
+ const ts = Date.parse(item[this.getTsField()]);
42
+ if (ts >= lastId) {
43
+ items.push(item);
44
+ } else {
45
+ break;
46
+ }
47
+ }
48
+
49
+ if (!items.length) {
50
+ return;
51
+ }
52
+
53
+ this._setLastId(Date.parse(items[0][this.getTsField()]));
54
+
55
+ items.forEach((item) => {
56
+ const meta = this.generateMeta(item);
57
+ this.$emit(item, meta);
58
+ });
59
+ },
60
+ getResourceFn() {
61
+ throw new ConfigurationError("getResourceFn is not implemented");
62
+ },
63
+ generateMeta() {
64
+ throw new ConfigurationError("generateMeta is not implemented");
65
+ },
66
+ },
67
+ hooks: {
68
+ async deploy() {
69
+ await this.processEvents(10);
70
+ },
71
+ },
72
+ async run() {
73
+ await this.processEvents();
74
+ },
75
+ };
@@ -0,0 +1,24 @@
1
+ import common from "../common/base-polling.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "billsby-new-customer-created",
6
+ name: "New Customer Created",
7
+ description: "Emit new event when a new customer is created. [See the documentation](https://support.billsby.com/reference/getting-started-with-your-api)",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ getResourceFn() {
14
+ return this.billsby.listCustomers;
15
+ },
16
+ generateMeta(customer) {
17
+ return {
18
+ id: customer.customerUniqueId,
19
+ summary: `New Customer with ID ${customer.customerUniqueId}`,
20
+ ts: Date.parse(customer.createdOn),
21
+ };
22
+ },
23
+ },
24
+ };
@@ -0,0 +1,29 @@
1
+ import common from "../common/base-polling.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "billsby-new-invoice-created",
6
+ name: "New Invoice Created",
7
+ description: "Emit new event when a new company invoice is created. [See the documentation](https://support.billsby.com/reference/get-company-credit-notes)",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ getResourceFn() {
14
+ return this.billsby.listCompanyInvoices;
15
+ },
16
+ getParams() {
17
+ return {
18
+ orderByDescending: "createdOn",
19
+ };
20
+ },
21
+ generateMeta(invoice) {
22
+ return {
23
+ id: invoice.invoiceId,
24
+ summary: `New Invoice with ID ${invoice.invoiceId}`,
25
+ ts: Date.parse(invoice.createdOn),
26
+ };
27
+ },
28
+ },
29
+ };
@@ -0,0 +1,29 @@
1
+ import common from "../common/base-polling.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "billsby-new-subscription-created",
6
+ name: "New Subscription Created",
7
+ description: "Emit new event when a new subscription is created. [See the documentation](https://support.billsby.com/reference/get-company-subscriptions)",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ methods: {
12
+ ...common.methods,
13
+ getResourceFn() {
14
+ return this.billsby.listSubscriptions;
15
+ },
16
+ getParams() {
17
+ return {
18
+ orderByDescending: "createdOn",
19
+ };
20
+ },
21
+ generateMeta(subscription) {
22
+ return {
23
+ id: subscription.subscriptionUniqueId,
24
+ summary: `New Subscription with ID ${subscription.subscriptionUniqueId}`,
25
+ ts: Date.parse(subscription.createdOn),
26
+ };
27
+ },
28
+ },
29
+ };