@signalhousellc/sdk 1.0.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.
- package/README.md +38 -0
- package/package.json +19 -0
- package/src/SignalHouseSDK.js +144 -0
- package/src/domains/Auth.js +36 -0
- package/src/domains/Billing.js +154 -0
- package/src/domains/Brands.js +196 -0
- package/src/domains/Campaigns.js +178 -0
- package/src/domains/Groups.js +92 -0
- package/src/domains/Landings.js +116 -0
- package/src/domains/Messages.js +209 -0
- package/src/domains/Numbers.js +130 -0
- package/src/domains/Shortlinks.js +44 -0
- package/src/domains/Subgroups.js +106 -0
- package/src/domains/Subscriptions.js +140 -0
- package/src/domains/Users.js +163 -0
- package/src/domains/Webhooks.js +74 -0
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# @signalhouse/sdk
|
|
2
|
+
|
|
3
|
+
A lightweight Node.js SDK for the Signal House platform.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @signalhouse/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Quick Start
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
import { SignalHouseSDK } from '@signalhouse/sdk';
|
|
15
|
+
|
|
16
|
+
const sdk = new SignalHouseSDK({
|
|
17
|
+
apiKey: 'your-api-key',
|
|
18
|
+
baseUrl: 'api url'
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const token = await sdk.auth.login({
|
|
22
|
+
email: 'youremail',
|
|
23
|
+
password: 'yourpassword'
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
console.log(token);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Features
|
|
30
|
+
Full support for Signal House API v2
|
|
31
|
+
Integrated Axios with standardized returns
|
|
32
|
+
Lightweight and tree-shakeable
|
|
33
|
+
|
|
34
|
+
Documentation
|
|
35
|
+
For full API reference and advanced usage, visit https://api.signalhouse.io
|
|
36
|
+
|
|
37
|
+
License
|
|
38
|
+
ISC © Signal House
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@signalhousellc/sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Signal House SDK for use with the Signal House platform",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/SignalHouseSDK.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/SignalHouseSDK.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src/",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"author": "Signal House LLC",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"axios": "^1.13.5"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {Object} RequestOptions
|
|
5
|
+
* @property {string} [token] - An optional bearer token to include in the request for authentication
|
|
6
|
+
* @property {object} [headers] - Additional headers to include in the request
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Main SDK Class (SignalHouseSDK.js)
|
|
10
|
+
import { Auth } from "./domains/Auth.js";
|
|
11
|
+
import { Billing } from "./domains/Billing.js";
|
|
12
|
+
import { Brands } from "./domains/Brands.js";
|
|
13
|
+
import { Campaigns } from "./domains/Campaigns.js";
|
|
14
|
+
import { Groups } from "./domains/Groups.js";
|
|
15
|
+
import { Landings } from "./domains/Landings.js";
|
|
16
|
+
import { Messages } from "./domains/Messages.js";
|
|
17
|
+
import { Numbers } from "./domains/Numbers.js";
|
|
18
|
+
import { Shortlinks } from "./domains/Shortlinks.js";
|
|
19
|
+
import { Subgroups } from "./domains/Subgroups.js";
|
|
20
|
+
import { Subscriptions } from "./domains/Subscriptions.js";
|
|
21
|
+
import { Users } from "./domains/Users.js";
|
|
22
|
+
import { Webhooks } from "./domains/Webhooks.js";
|
|
23
|
+
|
|
24
|
+
export class SignalHouseSDK {
|
|
25
|
+
/**
|
|
26
|
+
* Initialize the SignalHouseSDK with the required configuration
|
|
27
|
+
* @param {Object} config - The configuration object for initializing the SDK
|
|
28
|
+
* @param {string} config.apiKey - The API key for authenticating requests to the SignalHouse API
|
|
29
|
+
* @param {string} config.baseUrl - The base URL for the SignalHouse API (e.g., "https://api.signalhouse.com")
|
|
30
|
+
* @throws {Error} Throws an error if the API key or base URL is missing from the configuration
|
|
31
|
+
* @returns {SignalHouseSDK} An instance of the SignalHouseSDK
|
|
32
|
+
*/
|
|
33
|
+
constructor(config = {}) {
|
|
34
|
+
// Validate required config parameters
|
|
35
|
+
if (!config.apiKey) {
|
|
36
|
+
throw new Error("API key is required to initialize SignalHouseSDK");
|
|
37
|
+
}
|
|
38
|
+
if (!config.baseUrl) {
|
|
39
|
+
throw new Error("Base URL is required to initialize SignalHouseSDK");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Set instance properties
|
|
43
|
+
this.baseUrl = config.baseUrl;
|
|
44
|
+
this.apiKey = config.apiKey;
|
|
45
|
+
this.enableAdmin = config.enableAdmin || false;
|
|
46
|
+
|
|
47
|
+
// Shared internal request helper
|
|
48
|
+
const client = this._createClient(false);
|
|
49
|
+
const multipartClient = this._createClient(true);
|
|
50
|
+
|
|
51
|
+
// API Domains
|
|
52
|
+
this.auth = new Auth(client, this.enableAdmin);
|
|
53
|
+
this.billing = new Billing(client, this.enableAdmin);
|
|
54
|
+
this.brands = new Brands(client, this.enableAdmin);
|
|
55
|
+
this.campaigns = new Campaigns(client, this.enableAdmin);
|
|
56
|
+
this.groups = new Groups(client, this.enableAdmin);
|
|
57
|
+
this.landings = new Landings(client, multipartClient, this.enableAdmin);
|
|
58
|
+
this.messages = new Messages(client, multipartClient, this.enableAdmin);
|
|
59
|
+
this.numbers = new Numbers(client, this.enableAdmin);
|
|
60
|
+
this.shortlinks = new Shortlinks(client, this.enableAdmin);
|
|
61
|
+
this.subgroups = new Subgroups(client, this.enableAdmin);
|
|
62
|
+
this.subscriptions = new Subscriptions(client, this.enableAdmin);
|
|
63
|
+
this.users = new Users(client, this.enableAdmin);
|
|
64
|
+
this.webhooks = new Webhooks(client, this.enableAdmin);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Client for API requests
|
|
69
|
+
* @private
|
|
70
|
+
* @param {boolean} isMultipart - Whether to set the Content-Type header for multipart requests
|
|
71
|
+
* @throws {Error} Throws an error if the API key or base URL is missing
|
|
72
|
+
* @returns {Function} A function to make API requests
|
|
73
|
+
*/
|
|
74
|
+
_createClient(isMultipart = false) {
|
|
75
|
+
// Create an Axios instance with the base URL and default headers
|
|
76
|
+
const instance = axios.create({ baseURL: this.baseUrl, headers: isMultipart ? {} : { "Content-Type": "application/json" } });
|
|
77
|
+
|
|
78
|
+
// Add a request interceptor to include the API key in the Authorization header
|
|
79
|
+
instance.interceptors.request.use((config) => {
|
|
80
|
+
const token = config.headers.token || this.apiKey;
|
|
81
|
+
config.headers.Authorization = `Bearer ${token}`;
|
|
82
|
+
return config;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const client = async (url, options = {}) => {
|
|
86
|
+
try {
|
|
87
|
+
// Extract the body from options and keep the rest as axios config
|
|
88
|
+
const { body, ...axiosConfig } = options;
|
|
89
|
+
const response = await instance({ url, data: body, ...axiosConfig });
|
|
90
|
+
return response.data;
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (error.response) {
|
|
93
|
+
// Create a custom error object so the user sees the code and message clearly
|
|
94
|
+
const apiError = new Error(error.response.data?.message || "API Error");
|
|
95
|
+
apiError.status = error.response.status;
|
|
96
|
+
apiError.data = error.response.data;
|
|
97
|
+
throw apiError;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// If it's a network error or some other issue, rethrow it
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// Attach helpers to the client
|
|
106
|
+
client._getQueryString = this._getQueryString.bind(this);
|
|
107
|
+
client._require = this._require.bind(this);
|
|
108
|
+
|
|
109
|
+
return client;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Helper method to convert an object to a query string, excluding undefined values and the 'options' key
|
|
114
|
+
* @private
|
|
115
|
+
* @param {Object} obj - The object to convert to a query string
|
|
116
|
+
* @returns {string} The query string
|
|
117
|
+
*/
|
|
118
|
+
_getQueryString(obj) {
|
|
119
|
+
const params = new URLSearchParams();
|
|
120
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
121
|
+
if (value !== undefined && key !== "options") {
|
|
122
|
+
params.append(key, value);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
return params.toString() ? `?${params.toString()}` : "";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Helper method to validate required fields necessary for a request parameter
|
|
130
|
+
* @private
|
|
131
|
+
* @param {Object} fields - An object where keys are field names and values are the corresponding values to check
|
|
132
|
+
* @throws {Error} Throws an error if any required field is missing or empty
|
|
133
|
+
*/
|
|
134
|
+
_require(fields) {
|
|
135
|
+
for(const [name, value] of Object.entries(fields)) {
|
|
136
|
+
if(value === undefined || value === null || value === "") {
|
|
137
|
+
const error = new Error(`Missing required parameter: ${name}`);
|
|
138
|
+
error.name = "SignalHouseValidationError";
|
|
139
|
+
error.status = 400; // Match API validation code
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export class Auth {
|
|
2
|
+
constructor(client, enableAdmin) {
|
|
3
|
+
this.client = client;
|
|
4
|
+
this.enableAdmin = enableAdmin;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Login with email and password
|
|
9
|
+
* @async
|
|
10
|
+
* @roles public
|
|
11
|
+
* @param {Object} params
|
|
12
|
+
* @param {string} params.email - The user's email address
|
|
13
|
+
* @param {string} params.password - The user's password
|
|
14
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
15
|
+
* @returns {Promise<Object>} The response from the server
|
|
16
|
+
*/
|
|
17
|
+
async login({ email, password, options = {} }) {
|
|
18
|
+
return this.client(`/auth`, { method: "POST", body: { email, password }, ...options });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Reset a user's password
|
|
23
|
+
* @async
|
|
24
|
+
* @roles api, admin, self
|
|
25
|
+
* @param {Object} params
|
|
26
|
+
* @param {string} params.userId - The id of the user
|
|
27
|
+
* @param {string} params.newPassword - The new password to set for the user
|
|
28
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
29
|
+
* @returns {Promise<Object>} The response from the server
|
|
30
|
+
*/
|
|
31
|
+
async resetPassword({ userId, newPassword, options = {} }) {
|
|
32
|
+
this.client._require({ userId, newPassword });
|
|
33
|
+
const safeUserId = encodeURIComponent(userId);
|
|
34
|
+
return this.client(`/auth/resetpassword/${safeUserId}`, { method: "POST", body: { newPassword }, ...options });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
export class Billing {
|
|
2
|
+
constructor(client, enableAdmin) {
|
|
3
|
+
this.client = client;
|
|
4
|
+
this.enableAdmin = enableAdmin;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get transaction history with optional filters
|
|
9
|
+
* @async
|
|
10
|
+
* @roles api, admin, developer, billing, user
|
|
11
|
+
* @param {Object} params - The parameters for filtering the transaction history
|
|
12
|
+
* @param {string} [params.groupId] - The ID of the group to filter by
|
|
13
|
+
* @param {string} [params.subgroupId] - The ID of the subgroup to filter by
|
|
14
|
+
* @param {string} [params.entryType] - The type of entry to filter by
|
|
15
|
+
* @param {string} [params.transactionType] - The type of transaction to filter by
|
|
16
|
+
* @param {string} [params.startDate] - The start date for the filter
|
|
17
|
+
* @param {string} [params.endDate] - The end date for the filter
|
|
18
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
19
|
+
* @returns {Promise<Array>} The response from the server
|
|
20
|
+
*/
|
|
21
|
+
async getTransactionHistory({ groupId, subgroupId, entryType, transactionType, startDate, endDate, options = {} }) {
|
|
22
|
+
const filters = { groupId, subgroupId, entryType, transactionType, startDate, endDate };
|
|
23
|
+
const queryString = this.client._getQueryString(filters);
|
|
24
|
+
return this.client(`/billing/wallet/transactionHistory${queryString}`, { method: "GET", ...options });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Get the wallet information for a specific group
|
|
29
|
+
* @async
|
|
30
|
+
* @roles api, admin, developer, billing, user
|
|
31
|
+
* @param {Object} params - The parameters for getting the wallet information
|
|
32
|
+
* @param {string} params.groupId - The ID of the group to get the wallet information for
|
|
33
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
34
|
+
* @throws {Error} Throws an error if the groupId parameter is missing
|
|
35
|
+
* @returns {Promise<Object>} The response from the server
|
|
36
|
+
*/
|
|
37
|
+
async getWallet({ groupId, options = {} }) {
|
|
38
|
+
this.client._require({ groupId });
|
|
39
|
+
const safeGroupId = encodeURIComponent(groupId);
|
|
40
|
+
return this.client(`/billing/wallet/${safeGroupId}`, { method: "GET", ...options });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Update the wallet settings for a specific group
|
|
45
|
+
* @async
|
|
46
|
+
* @roles api, admin, developer, billing, user
|
|
47
|
+
* @param {Object} params - The parameters for updating the wallet settings
|
|
48
|
+
* @param {string} params.groupId - The ID of the group to update the wallet settings for
|
|
49
|
+
* @param {boolean} [params.autoRechargeEnabled] - Whether auto-recharge is enabled for the wallet
|
|
50
|
+
* @param {number} [params.autoRechargeThreshold] - The threshold amount for auto-recharge to trigger
|
|
51
|
+
* @param {number} [params.autoRechargeToAmount] - The amount to recharge to when auto-recharge is triggered
|
|
52
|
+
* @param {string} [params.primaryPaymentMethodId] - The ID of the primary payment method to use for auto-recharge
|
|
53
|
+
* @param {string} [params.secondaryPaymentMethodId] - The ID of the secondary payment method to use for auto-recharge if the primary method fails
|
|
54
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
55
|
+
* @throws {Error} Throws an error if the groupId parameter is missing
|
|
56
|
+
* @returns {Promise<Object>} The response from the server
|
|
57
|
+
*/
|
|
58
|
+
async updateWallet({ groupId, autoRechargeEnabled, autoRechargeThreshold, autoRechargeToAmount, primaryPaymentMethodId, secondaryPaymentMethodId, options = {} }) {
|
|
59
|
+
this.client._require({ groupId });
|
|
60
|
+
const safeGroupId = encodeURIComponent(groupId);
|
|
61
|
+
return this.client(`/billing/wallet/${safeGroupId}`, {
|
|
62
|
+
method: "PUT",
|
|
63
|
+
body: { autoRechargeEnabled, autoRechargeThreshold, autoRechargeToAmount, primaryPaymentMethodId, secondaryPaymentMethodId },
|
|
64
|
+
...options,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get the payment methods for a specific group
|
|
70
|
+
* @async
|
|
71
|
+
* @roles api, admin, developer, billing, user
|
|
72
|
+
* @param {Object} params - The parameters for getting the payment methods
|
|
73
|
+
* @param {string} params.groupId - The ID of the group to get the payment methods for
|
|
74
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
75
|
+
* @throws {Error} Throws an error if the groupId parameter is missing
|
|
76
|
+
* @returns {Promise<Array>} The response from the server
|
|
77
|
+
*/
|
|
78
|
+
async getPaymentMethods({ groupId, options = {} }) {
|
|
79
|
+
this.client._require({ groupId });
|
|
80
|
+
const safeGroupId = encodeURIComponent(groupId);
|
|
81
|
+
return this.client(`/billing/wallet/paymentmethods/${safeGroupId}`, { method: "GET", ...options });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Add funds to a group's wallet
|
|
86
|
+
* @async
|
|
87
|
+
* @roles api, admin, developer, billing, user
|
|
88
|
+
* @param {Object} params - The parameters for adding funds
|
|
89
|
+
* @param {string} params.groupId - The ID of the group to add funds to
|
|
90
|
+
* @param {number} params.amount - The amount to add to the group's wallet in microdollars (e.g., $10 would be 10000000)
|
|
91
|
+
* @param {string} [params.paymentMethodId] - The ID of the payment method to use for adding funds
|
|
92
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
93
|
+
* @throws {Error} Throws an error if the groupId or amount parameters are missing
|
|
94
|
+
* @returns {Promise<Object>} The response from the server
|
|
95
|
+
*/
|
|
96
|
+
async addFunds({ groupId, amount, paymentMethodId = undefined, options = {} }) {
|
|
97
|
+
this.client._require({ groupId, amount });
|
|
98
|
+
const safeGroupId = encodeURIComponent(groupId);
|
|
99
|
+
return this.client(`/billing/wallet/addfunds/${safeGroupId}`, { method: "POST", body: { amount, paymentMethodId }, ...options });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Add a payment method to a group's wallet
|
|
104
|
+
* @async
|
|
105
|
+
* @roles api, admin, developer, billing, user
|
|
106
|
+
* @param {Object} params - The parameters for adding a payment method
|
|
107
|
+
* @param {string} params.groupId - The ID of the group to add the payment method to
|
|
108
|
+
* @param {string} params.paymentMethodId - The ID of the payment method to add
|
|
109
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
110
|
+
* @throws {Error} Throws an error if the groupId or paymentMethodId parameters are missing
|
|
111
|
+
* @returns {Promise<Object>} The response from the server
|
|
112
|
+
*/
|
|
113
|
+
async addPaymentMethod({ groupId, paymentMethodId, options = {} }) {
|
|
114
|
+
this.client._require({ groupId, paymentMethodId });
|
|
115
|
+
const safeGroupId = encodeURIComponent(groupId);
|
|
116
|
+
return this.client(`/billing/wallet/paymentmethods/${safeGroupId}`, { method: "POST", body: { paymentMethodId }, ...options });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Remove a payment method from a group's wallet
|
|
121
|
+
* @async
|
|
122
|
+
* @roles api, admin, developer, billing, user
|
|
123
|
+
* @param {Object} params - The parameters for removing a payment method
|
|
124
|
+
* @param {string} params.groupId - The ID of the group to remove the payment method from
|
|
125
|
+
* @param {string} params.paymentMethodId - The ID of the payment method to remove
|
|
126
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
127
|
+
* @throws {Error} Throws an error if the groupId or paymentMethodId parameters are missing
|
|
128
|
+
* @returns {Promise<Object>} The response from the server
|
|
129
|
+
*/
|
|
130
|
+
async removePaymentMethod({ groupId, paymentMethodId, options = {} }) {
|
|
131
|
+
this.client._require({ groupId, paymentMethodId });
|
|
132
|
+
const safeGroupId = encodeURIComponent(groupId);
|
|
133
|
+
const safePaymentMethodId = encodeURIComponent(paymentMethodId);
|
|
134
|
+
return this.client(`/billing/wallet/paymentmethods/${safeGroupId}/${safePaymentMethodId}`, { method: "DELETE", ...options });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Get invoice details with optional filters
|
|
139
|
+
* @async
|
|
140
|
+
* @roles api, admin, developer, billing, user
|
|
141
|
+
* @param {Object} params - The parameters for filtering the invoice details
|
|
142
|
+
* @param {string} [params.groupId] - The ID of the group to filter by
|
|
143
|
+
* @param {string} [params.subgroupId] - The ID of the subgroup to filter by
|
|
144
|
+
* @param {string} [params.startDate] - The start date for the filter
|
|
145
|
+
* @param {string} [params.endDate] - The end date for the filter
|
|
146
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
147
|
+
* @returns {Promise<Object>} The response from the server
|
|
148
|
+
*/
|
|
149
|
+
async getInvoiceDetails({ groupId, subgroupId, startDate, endDate, options = {} }) {
|
|
150
|
+
const filters = { groupId, subgroupId, startDate, endDate };
|
|
151
|
+
const queryString = this.client._getQueryString(filters);
|
|
152
|
+
return this.client(`/billing/invoiceDetails${queryString}`, { method: "GET", ...options });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} CreateBrandData
|
|
3
|
+
* @property {string} subgroupId - The ID of the subgroup to create the brand under
|
|
4
|
+
* @property {string} entityType - The type of entity for the brand (PRIVATE_PROFIT, PUBLIC_PROFIT, NON_PROFIT, GOVERNMENT)
|
|
5
|
+
* @property {string} displayName - The display name for the brand
|
|
6
|
+
* @property {string} companyName - The company name for the brand
|
|
7
|
+
* @property {string} ein - The EIN (Employer Identification Number) for the brand
|
|
8
|
+
* @property {string} [einIssuingCountry] - The country that issued the EIN for the brand
|
|
9
|
+
* @property {string} [altBusinessId] - An alternative business identifier for the brand (e.g., DUNS number)
|
|
10
|
+
* @property {string} [altBusinessIdType] - The type of the alternative business identifier ("NONE", "DUNS", "LEI", "GIIN")
|
|
11
|
+
* @property {string} [firstName] - The first name of the primary contact for the brand
|
|
12
|
+
* @property {string} [lastName] - The last name of the primary contact for the brand
|
|
13
|
+
* @property {string} phone - The phone number of the primary contact for the brand
|
|
14
|
+
* @property {string} street - The street address of the primary contact for the brand
|
|
15
|
+
* @property {string} city - The city of the primary contact for the brand
|
|
16
|
+
* @property {string} state - The state of the primary contact for the brand
|
|
17
|
+
* @property {string} postalCode - The postal code of the primary contact for the brand
|
|
18
|
+
* @property {string} country - The country code of the primary contact for the brand (e.g., "US")
|
|
19
|
+
* @property {string} email - The email address of the primary contact for the brand
|
|
20
|
+
* @property {string} [mobilePhone] - The mobile phone number of the primary contact for the brand
|
|
21
|
+
* @property {string} [stockSymbol] - The stock symbol for the brand if it is a publicly traded company
|
|
22
|
+
* @property {string} [stockExchange] - The stock exchange where the brand is listed if it is a publicly traded company
|
|
23
|
+
* @property {string} [website] - The website URL for the brand
|
|
24
|
+
* @property {string} vertical - The vertical for the brand (PROFESSIONAL, REAL_ESTATE, HEALTHCARE, HUMAN_RESOURCES, ENERGY, ENTERTAINMENT, RETAIL, TRANSPORTATION, AGRICULTURE, INSURANCE, POSTAL, EDUCATION, HOSPITALITY, FINANCIAL, POLITICAL, GAMBLING, LEGAL, CONSTRUCTION, NGO, MANUFACTURING, GOVERNMENT, TECHNOLOGY, COMMUNICATION)
|
|
25
|
+
* @property {string} [referenceId] - A unique reference for the brand
|
|
26
|
+
* @property {Array<string>} [tag] - An array of tags to associate with the brand
|
|
27
|
+
* @property {boolean} [mock] - Whether to create the brand in the mock environment (for testing purposes only)
|
|
28
|
+
* @property {string} [businessContactEmail] - The email address of the business contact for the brand (required if entityType is PUBLIC_PROFIT or NON_PROFIT)
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @typedef {Object} UpdateBrandData
|
|
33
|
+
* @property {string} [companyName] - The company name for the brand
|
|
34
|
+
* @property {string} [ein] - The EIN (Employer Identification Number) for the brand
|
|
35
|
+
* @property {string} [einIssuingCountry] - The country that issued the EIN for the brand
|
|
36
|
+
* @property {string} [entityType] - The type of entity for the brand (PRIVATE_PROFIT, PUBLIC_PROFIT, NON_PROFIT, GOVERNMENT)
|
|
37
|
+
* @property {string} [firstName] - The first name of the primary contact for the brand
|
|
38
|
+
* @property {string} [lastName] - The last name of the primary contact for the brand
|
|
39
|
+
* @property {string} [displayName] - The display name for the brand
|
|
40
|
+
* @property {string} [website] - The website URL for the brand
|
|
41
|
+
* @property {string} [street] - The street address of the primary contact for the brand
|
|
42
|
+
* @property {string} [city] - The city of the primary contact for the brand
|
|
43
|
+
* @property {string} [state] - The state of the primary contact for the brand
|
|
44
|
+
* @property {string} [postalCode] - The postal code of the primary contact for the brand
|
|
45
|
+
* @property {string} [country] - The country code of the primary contact for the brand (e.g., "US")
|
|
46
|
+
* @property {string} [email] - The email address of the primary contact for the brand
|
|
47
|
+
* @property {string} [referenceId] - A unique reference for the brand
|
|
48
|
+
* @property {string} [phone] - The phone number of the primary contact for the brand
|
|
49
|
+
* @property {string} [vertical] - The vertical for the brand (PROFESSIONAL, REAL_ESTATE, HEALTHCARE, HUMAN_RESOURCES, ENERGY, ENTERTAINMENT, RETAIL, TRANSPORTATION, AGRICULTURE, INSURANCE, POSTAL, EDUCATION, HOSPITALITY, FINANCIAL, POLITICAL, GAMBLING, LEGAL, CONSTRUCTION, NGO, MANUFACTURING, GOVERNMENT, TECHNOLOGY, COMMUNICATION)
|
|
50
|
+
* @property {string} [stockSymbol] - The stock symbol for the brand if it is a publicly traded company
|
|
51
|
+
* @property {string} [stockExchange] - The stock exchange where the brand is listed if it is a publicly traded company
|
|
52
|
+
* @property {string} [altBusinessId] - An alternative business identifier for the brand (e.g., DUNS number)
|
|
53
|
+
* @property {string} [altBusinessIdType] - The type of the alternative business identifier ("NONE", "DUNS", "LEI", "GIIN")
|
|
54
|
+
* @property {string} [brandRelationship] - Not in use - reserved for future use
|
|
55
|
+
* @property {string} [businessContactEmail] - The email address of the business contact for the brand (required if entityType is PUBLIC_PROFIT or NON_PROFIT)
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
export class Brands {
|
|
59
|
+
constructor(client, enableAdmin) {
|
|
60
|
+
this.client = client;
|
|
61
|
+
this.enableAdmin = enableAdmin;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Get a list of brands with optional filters
|
|
66
|
+
* @async
|
|
67
|
+
* @roles api, admin, developer, user
|
|
68
|
+
* @param {Object} params - The parameters for filtering the brands
|
|
69
|
+
* @param {string} [params.id] - The ID of the brand to filter by
|
|
70
|
+
* @param {string} [params.subgroupId] - The ID of the subgroup to filter by
|
|
71
|
+
* @param {string} [params.groupId] - The ID of the group to filter by
|
|
72
|
+
* @param {number} [params.page] - The page number for pagination
|
|
73
|
+
* @param {number} [params.limit] - The number of items per page
|
|
74
|
+
* @param {string} [params.status] - The status of the brand to filter by (PENDING_CREATION, PENDING_APPROVAL, UNVERIFIED, VERIFIED, VETTED_VERIFIED, PENDING_DELETE, DELETED)
|
|
75
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
76
|
+
* @returns {Promise<Array>} The response from the server
|
|
77
|
+
*/
|
|
78
|
+
async getBrands({ id, subgroupId, groupId, page, limit, status, options = {} }) {
|
|
79
|
+
const filters = { id, subgroupId, groupId, page, limit, status };
|
|
80
|
+
const queryString = this.client._getQueryString(filters);
|
|
81
|
+
return this.client(`/brand${queryString}`, { method: "GET", ...options });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Get external vetting information for a brand
|
|
86
|
+
* @async
|
|
87
|
+
* @roles api, admin, developer, user
|
|
88
|
+
* @param {Object} params - The parameters for getting the external vetting information
|
|
89
|
+
* @param {string} params.brandId - The ID of the brand to get the external vetting information for
|
|
90
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
91
|
+
* @throws {Error} Throws an error if the brandId parameter is missing
|
|
92
|
+
* @returns {Promise<Object>} The response from the server
|
|
93
|
+
*/
|
|
94
|
+
async getExternalVetting({ brandId, options = {} }) {
|
|
95
|
+
this.client._require({ brandId });
|
|
96
|
+
const safeBrandId = encodeURIComponent(brandId);
|
|
97
|
+
return this.client(`/brand/externalvetting/${safeBrandId}`, { method: "GET", ...options });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Create a new brand
|
|
102
|
+
* @async
|
|
103
|
+
* @roles api, admin, developer, billing, user
|
|
104
|
+
* @param {Object} params - The parameters for creating the brand (see CreateBrandData typedef for details)
|
|
105
|
+
* @param {CreateBrandData} params.brandData - The data for the brand to be created
|
|
106
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
107
|
+
* @throws {Error} Throws an error if the brandData parameter is missing or if required fields in brandData are missing
|
|
108
|
+
* @returns {Promise<Object>} The response from the server
|
|
109
|
+
*/
|
|
110
|
+
async createBrand({ brandData, options = {} }) {
|
|
111
|
+
this.client._require({ brandData: brandData, "brandData.subgroupId": brandData.subgroupId });
|
|
112
|
+
return this.client(`/brand`, { method: "POST", body: brandData, ...options });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Transfer one or more brands to a different subgroup
|
|
117
|
+
* @async
|
|
118
|
+
* @roles api, admin, developer, billing, user
|
|
119
|
+
* @param {Object} params - The parameters for transferring the brands
|
|
120
|
+
* @param {string} params.subgroupId - The ID of the subgroup to transfer the brands to
|
|
121
|
+
* @param {Array<string>} params.brandIds - The IDs of the brands to be transferred
|
|
122
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
123
|
+
* @throws {Error} Throws an error if the subgroupId or brandIds parameters are missing
|
|
124
|
+
* @returns {Promise<Object>} The response from the server
|
|
125
|
+
*/
|
|
126
|
+
async transferBrand({ subgroupId, brandIds, options = {} }) {
|
|
127
|
+
this.client._require({ subgroupId, brandIds });
|
|
128
|
+
const safeSubgroupId = encodeURIComponent(subgroupId);
|
|
129
|
+
return this.client(`/brand/transfer/${safeSubgroupId}`, { method: "POST", body: { brandIds }, ...options });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Create external vetting for a brand
|
|
134
|
+
* @async
|
|
135
|
+
* @roles api, admin, developer, billing, user
|
|
136
|
+
* @param {Object} params - The parameters for creating external vetting
|
|
137
|
+
* @param {string} params.brandId - The ID of the brand to create external vetting for
|
|
138
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
139
|
+
* @throws {Error} Throws an error if the brandId parameter is missing
|
|
140
|
+
* @returns {Promise<Object>} The response from the server
|
|
141
|
+
*/
|
|
142
|
+
async createExternalVetting({ brandId, options = {} }) {
|
|
143
|
+
this.client._require({ brandId });
|
|
144
|
+
const safeBrandId = encodeURIComponent(brandId);
|
|
145
|
+
return this.client(`/brand/externalvetting/${safeBrandId}`, { method: "POST", ...options });
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Update a brand's information
|
|
150
|
+
* @async
|
|
151
|
+
* @roles api, admin, developer, billing, user
|
|
152
|
+
* @param {Object} params - The parameters for updating the brand (see UpdateBrandData typedef for details)
|
|
153
|
+
* @param {string} params.brandId - The ID of the brand to update
|
|
154
|
+
* @param {UpdateBrandData} params.brandData - The data for the brand to be updated
|
|
155
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
156
|
+
* @throws {Error} Throws an error if the brandId parameter is missing
|
|
157
|
+
* @returns {Promise<Object>} The response from the server
|
|
158
|
+
*/
|
|
159
|
+
async updateBrand({ brandId, brandData, options = {} }) {
|
|
160
|
+
this.client._require({ brandId });
|
|
161
|
+
const safeBrandId = encodeURIComponent(brandId);
|
|
162
|
+
return this.client(`/brand/${safeBrandId}`, { method: "PUT", body: brandData, ...options });
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Revet a brand that is in UNVERIFIED status due to an update afer it was previously VERIFIED or VETTED_VERIFIED
|
|
167
|
+
* @async
|
|
168
|
+
* @roles api, admin, developer, billing, user
|
|
169
|
+
* @param {Object} params - The parameters for reverting the brand
|
|
170
|
+
* @param {string} params.brandId - The ID of the brand to revert
|
|
171
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
172
|
+
* @throws {Error} Throws an error if the brandId parameter is missing
|
|
173
|
+
* @returns {Promise<Object>} The response from the server
|
|
174
|
+
*/
|
|
175
|
+
async revetBrand({ brandId, options = {} }) {
|
|
176
|
+
this.client._require({ brandId });
|
|
177
|
+
const safeBrandId = encodeURIComponent(brandId);
|
|
178
|
+
return this.client(`/brand/revet/${safeBrandId}`, { method: "POST", ...options });
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Delete a brand (mark it as DELETED). The brand will still be retrievable
|
|
183
|
+
* @async
|
|
184
|
+
* @roles api, admin, developer, billing, user
|
|
185
|
+
* @param {Object} params - The parameters for deleting the brand
|
|
186
|
+
* @param {string} params.brandId - The ID of the brand to delete
|
|
187
|
+
* @param {import('../SignalHouseSDK').RequestOptions} [params.options] - Additional options for the request
|
|
188
|
+
* @throws {Error} Throws an error if the brandId parameter is missing
|
|
189
|
+
* @returns {Promise<Object>} The response from the server
|
|
190
|
+
*/
|
|
191
|
+
async deleteBrand({ brandId, options = {} }) {
|
|
192
|
+
this.client._require({ brandId });
|
|
193
|
+
const safeBrandId = encodeURIComponent(brandId);
|
|
194
|
+
return this.client(`/brand/${safeBrandId}`, { method: "DELETE", ...options });
|
|
195
|
+
}
|
|
196
|
+
}
|