builtwith-api 1.0.8 → 3.2.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/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +796 -0
- package/dist/cli.js.map +18 -0
- package/dist/commands.d.ts +16 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +162 -0
- package/dist/commands.js.map +10 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/errors.d.ts +2 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +22 -0
- package/dist/errors.js.map +10 -0
- package/dist/format.d.ts +2 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +469 -0
- package/dist/index.js.map +14 -0
- package/dist/params.d.ts +9 -0
- package/dist/params.d.ts.map +1 -0
- package/dist/request.d.ts +5 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/schemas.d.ts +470 -0
- package/dist/schemas.d.ts.map +1 -0
- package/package.json +48 -14
- package/README.md +0 -100
- package/src/config.js +0 -7
- package/src/index.js +0 -244
- package/src/index.test.js +0 -90
- package/src/utils.js +0 -54
package/src/index.js
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
const _ = require("lodash");
|
|
2
|
-
|
|
3
|
-
const utils = require("./utils");
|
|
4
|
-
const { VALID_RESPONSE_TYPES } = require("./config");
|
|
5
|
-
|
|
6
|
-
function BuiltWith(apiKey, moduleParams = {}) {
|
|
7
|
-
const responseFormat = _.get(moduleParams, "responseFormat", "json");
|
|
8
|
-
|
|
9
|
-
if (!Object.values(VALID_RESPONSE_TYPES).includes(responseFormat)) {
|
|
10
|
-
throw new Error(
|
|
11
|
-
`Invalid 'responseFormat'. Valid format are 'xml', 'txt', and 'json'. You input ${responseFormat}`,
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (responseFormat === VALID_RESPONSE_TYPES.TXT) {
|
|
16
|
-
console.warn(
|
|
17
|
-
"TXT response format is only supported for the BuiltWith Lists API. See: https://api.builtwith.com/lists-api",
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function constructBuiltWithURL(
|
|
22
|
-
apiName,
|
|
23
|
-
requestParams = {},
|
|
24
|
-
subdomain = "api",
|
|
25
|
-
) {
|
|
26
|
-
let bwURL = `https://${subdomain}.builtwith.com/${apiName}/api.${responseFormat}?KEY=${apiKey}`;
|
|
27
|
-
|
|
28
|
-
if (!_.isEmpty(requestParams)) {
|
|
29
|
-
bwURL += `&${utils.paramsObjToQueryString(requestParams)}`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return bwURL;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function checkUrlData(url, isMultiDomain = true) {
|
|
36
|
-
let isArray = Array.isArray(url);
|
|
37
|
-
if (isArray) {
|
|
38
|
-
if (!isMultiDomain) throw "API does not allow for multi-domain LOOKUP";
|
|
39
|
-
if (url.length > 16) throw "Domain LOOKUP size to big (16 max)";
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
/**
|
|
45
|
-
* Make a request to the BuiltWith Free API
|
|
46
|
-
*
|
|
47
|
-
* @see https://api.builtwith.com/free-api
|
|
48
|
-
* @param {String} url
|
|
49
|
-
*/
|
|
50
|
-
free: async function (url) {
|
|
51
|
-
checkUrlData(url, false);
|
|
52
|
-
|
|
53
|
-
const bwURL = constructBuiltWithURL("free1", {
|
|
54
|
-
LOOKUP: url,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const res = await utils.makeStandardRequest(bwURL, responseFormat);
|
|
58
|
-
return res;
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Make a request to the BuiltWith Domain API
|
|
63
|
-
*
|
|
64
|
-
* @see https://api.builtwith.com/domain-api
|
|
65
|
-
* @param {(string|string[])} url
|
|
66
|
-
* @param {Object} params
|
|
67
|
-
*/
|
|
68
|
-
domain: async function (url, params) {
|
|
69
|
-
checkUrlData(url);
|
|
70
|
-
const hideAll = _.get(params, "hideAll", false);
|
|
71
|
-
const noMetaData = _.get(params, "noMetaData", false);
|
|
72
|
-
const noAttributeData = _.get(params, "noAttributeData", false);
|
|
73
|
-
const hideDescriptionAndLinks = _.get(
|
|
74
|
-
params,
|
|
75
|
-
"hideDescriptionAndLinks",
|
|
76
|
-
false,
|
|
77
|
-
);
|
|
78
|
-
const onlyLiveTechnologies = _.get(params, "onlyLiveTechnologies", false);
|
|
79
|
-
|
|
80
|
-
const bwURL = constructBuiltWithURL("v15", {
|
|
81
|
-
LOOKUP: url,
|
|
82
|
-
HIDETEXT: hideAll,
|
|
83
|
-
HIDEDL: hideDescriptionAndLinks,
|
|
84
|
-
LIVEONLY: onlyLiveTechnologies,
|
|
85
|
-
NOMETA: noMetaData,
|
|
86
|
-
NOATTR: noAttributeData,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const res = await utils.makeStandardRequest(bwURL, responseFormat);
|
|
90
|
-
|
|
91
|
-
return res;
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Make a request to the BuiltWith Lists API
|
|
96
|
-
*
|
|
97
|
-
* @see: https://api.builtwith.com/lists-api
|
|
98
|
-
* @param {String} technology
|
|
99
|
-
* @param {Object} params
|
|
100
|
-
*/
|
|
101
|
-
lists: async function (technology, params) {
|
|
102
|
-
const includeMetaData = _.get(params, "includeMetaData", false);
|
|
103
|
-
const offset = _.get(params, "offset");
|
|
104
|
-
const since = _.get(params, "since");
|
|
105
|
-
|
|
106
|
-
const bwURL = constructBuiltWithURL("lists5", {
|
|
107
|
-
TECH: technology,
|
|
108
|
-
META: includeMetaData,
|
|
109
|
-
OFFSET: offset,
|
|
110
|
-
SINCE: since,
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
const res = await utils.makeBulletProofRequest(bwURL);
|
|
114
|
-
return res;
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Make a request to the BuiltWith Relationships API
|
|
119
|
-
*
|
|
120
|
-
* @note Relationships API may throw an error related to the maxJSONLength property for certain URLs. This is thrown in BuiltWith and cannot be handled here.
|
|
121
|
-
*
|
|
122
|
-
* @see https://api.builtwith.com/relationships-api
|
|
123
|
-
* @param {(string|string[])} url
|
|
124
|
-
*/
|
|
125
|
-
relationships: async function (url) {
|
|
126
|
-
checkUrlData(url);
|
|
127
|
-
const bwURL = constructBuiltWithURL("rv1", {
|
|
128
|
-
LOOKUP: url,
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
const res = await utils.makeStandardRequest(bwURL, responseFormat);
|
|
132
|
-
|
|
133
|
-
return res;
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Make a request to the BuiltWith Keywords API
|
|
138
|
-
*
|
|
139
|
-
* @see https://api.builtwith.com/keywords-api
|
|
140
|
-
* @param {(string|string[])} url
|
|
141
|
-
*/
|
|
142
|
-
keywords: async function (url) {
|
|
143
|
-
checkUrlData(url);
|
|
144
|
-
const bwURL = constructBuiltWithURL("kw2", {
|
|
145
|
-
LOOKUP: url,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
const res = await utils.makeStandardRequest(bwURL, responseFormat);
|
|
149
|
-
return res;
|
|
150
|
-
},
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Make a request to the BuiltWith Trends API
|
|
154
|
-
*
|
|
155
|
-
* @see: https://api.builtwith.com/trends-api
|
|
156
|
-
* @param {String} technology
|
|
157
|
-
* @param {Object} params
|
|
158
|
-
*/
|
|
159
|
-
trends: async function (technology, params) {
|
|
160
|
-
const date = _.get(params, "date");
|
|
161
|
-
|
|
162
|
-
const bwURL = constructBuiltWithURL("trends/v6", {
|
|
163
|
-
TECH: technology,
|
|
164
|
-
DATE: date,
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
const res = await utils.makeBulletProofRequest(bwURL);
|
|
168
|
-
return res;
|
|
169
|
-
},
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Make a request to the BuiltWith Company to URL API
|
|
173
|
-
*
|
|
174
|
-
* @see: https://api.builtwith.com/trends-api
|
|
175
|
-
* @param {String} companyName
|
|
176
|
-
* @param {Object} params
|
|
177
|
-
*/
|
|
178
|
-
companyToUrl: async function (companyName, params) {
|
|
179
|
-
const tld = _.get(params, "tld");
|
|
180
|
-
const amount = _.get(params, "noMetaData");
|
|
181
|
-
|
|
182
|
-
const bwURL = constructBuiltWithURL(
|
|
183
|
-
"ctu1",
|
|
184
|
-
{
|
|
185
|
-
COMPANY: encodeURIComponent(companyName),
|
|
186
|
-
TLD: tld,
|
|
187
|
-
AMOUNT: amount,
|
|
188
|
-
},
|
|
189
|
-
"ctu",
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
const res = await utils.makeStandardRequest(bwURL, responseFormat);
|
|
193
|
-
return res;
|
|
194
|
-
},
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Make a request to the BuiltWith Domain Live API
|
|
198
|
-
*
|
|
199
|
-
* @see https://api.builtwith.com/domain-live-api
|
|
200
|
-
* @param {String} url
|
|
201
|
-
*/
|
|
202
|
-
domainLive: async function (url) {
|
|
203
|
-
const bwURL = constructBuiltWithURL("ddlv2", {
|
|
204
|
-
LOOKUP: url,
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
const res = await utils.makeStandardRequest(bwURL, responseFormat);
|
|
208
|
-
return res;
|
|
209
|
-
},
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Make a request to the BuiltWith Domain Live API
|
|
213
|
-
*
|
|
214
|
-
* @see https://api.builtwith.com/trust-api
|
|
215
|
-
* @param {String} url
|
|
216
|
-
* @param {Object} params
|
|
217
|
-
*/
|
|
218
|
-
trust: async function (url, params) {
|
|
219
|
-
const words = _.get(params, "words", "");
|
|
220
|
-
const live = _.get(params, "live", false);
|
|
221
|
-
|
|
222
|
-
const bwURL = constructBuiltWithURL("trustv1", {
|
|
223
|
-
LOOKUP: url,
|
|
224
|
-
// 'wordOne, wordTwo' ==> 'wordOne,wordTwo'
|
|
225
|
-
WORDS: words
|
|
226
|
-
.split(",")
|
|
227
|
-
.map((wrd) => wrd.trim())
|
|
228
|
-
.join(","),
|
|
229
|
-
LIVE: live,
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
const res = await utils.makeStandardRequest(bwURL, responseFormat);
|
|
233
|
-
return res;
|
|
234
|
-
},
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Constructor to authenticate and get module
|
|
239
|
-
module.exports = function (apiKey, moduleParams) {
|
|
240
|
-
if (!apiKey) {
|
|
241
|
-
throw new Error("You must initialize the BuiltWith module with an api key");
|
|
242
|
-
}
|
|
243
|
-
return BuiltWith(apiKey, moduleParams);
|
|
244
|
-
};
|
package/src/index.test.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
const nock = require('nock');
|
|
2
|
-
const BuiltWith = require('../src/index');
|
|
3
|
-
|
|
4
|
-
const apiKey = 'testApiKey';
|
|
5
|
-
const moduleParams = { isBulletProof: false };
|
|
6
|
-
|
|
7
|
-
describe('BuiltWith', () => {
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
nock('https://api.builtwith.com')
|
|
10
|
-
.get(/.*/)
|
|
11
|
-
.reply(200, { test: 'data' });
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
afterEach(() => {
|
|
15
|
-
nock.cleanAll();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should make a standard request for the domain API', async () => {
|
|
19
|
-
const bw = BuiltWith(apiKey, moduleParams);
|
|
20
|
-
|
|
21
|
-
const response = await bw.domain('testUrl');
|
|
22
|
-
|
|
23
|
-
expect(response).toEqual({ test: 'data' });
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should make a standard request for the lists API', async () => {
|
|
27
|
-
const bw = BuiltWith(apiKey, moduleParams);
|
|
28
|
-
|
|
29
|
-
const response = await bw.lists('testUrl');
|
|
30
|
-
|
|
31
|
-
expect(response).toEqual({ test: 'data' });
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should make a standard request for the relationships API', async () => {
|
|
35
|
-
const bw = BuiltWith(apiKey, moduleParams);
|
|
36
|
-
|
|
37
|
-
const response = await bw.relationships('testUrl');
|
|
38
|
-
|
|
39
|
-
expect(response).toEqual({ test: 'data' });
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
it('should make a standard request for the free API', async () => {
|
|
44
|
-
const bw = BuiltWith(apiKey, moduleParams);
|
|
45
|
-
|
|
46
|
-
const response = await bw.free('testUrl');
|
|
47
|
-
|
|
48
|
-
expect(response).toEqual({ test: 'data' });
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should make a standard request for the keywords API', async () => {
|
|
52
|
-
const bw = BuiltWith(apiKey, moduleParams);
|
|
53
|
-
|
|
54
|
-
const response = await bw.keywords('testUrl');
|
|
55
|
-
|
|
56
|
-
expect(response).toEqual({ test: 'data' });
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should make a standard request for the trends API', async () => {
|
|
60
|
-
const bw = BuiltWith(apiKey, moduleParams);
|
|
61
|
-
|
|
62
|
-
const response = await bw.trends('testUrl');
|
|
63
|
-
|
|
64
|
-
expect(response).toEqual({ test: 'data' });
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should make a standard request for the companyToUrl API', async () => {
|
|
68
|
-
const bw = BuiltWith(apiKey, moduleParams);
|
|
69
|
-
|
|
70
|
-
const response = await bw.companyToUrl('My Company');
|
|
71
|
-
|
|
72
|
-
expect(response).toEqual({ test: 'data' });
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should make a standard request for the domainLive API', async () => {
|
|
76
|
-
const bw = BuiltWith(apiKey, moduleParams);
|
|
77
|
-
|
|
78
|
-
const response = await bw.domainLive('testUrl');
|
|
79
|
-
|
|
80
|
-
expect(response).toEqual({ test: 'data' });
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('should make a standard request for the trust API', async () => {
|
|
84
|
-
const bw = BuiltWith(apiKey, moduleParams);
|
|
85
|
-
|
|
86
|
-
const response = await bw.trust('testUrl');
|
|
87
|
-
|
|
88
|
-
expect(response).toEqual({ test: 'data' });
|
|
89
|
-
});
|
|
90
|
-
});
|
package/src/utils.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
const { VALID_RESPONSE_TYPES } = require("./config");
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
makeStandardRequest: async function (url, responseFormat) {
|
|
5
|
-
const res = await fetch(url);
|
|
6
|
-
if (responseFormat === VALID_RESPONSE_TYPES.XML) {
|
|
7
|
-
return res.text();
|
|
8
|
-
} else {
|
|
9
|
-
return res.json();
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
makeBulletProofRequest: async function (url, responseFormat) {
|
|
14
|
-
const res = await fetch(url);
|
|
15
|
-
if (
|
|
16
|
-
responseFormat === VALID_RESPONSE_TYPES.TXT ||
|
|
17
|
-
responseFormat === VALID_RESPONSE_TYPES.XML
|
|
18
|
-
) {
|
|
19
|
-
return res.text();
|
|
20
|
-
} else {
|
|
21
|
-
/**
|
|
22
|
-
* BuiltWith sends invalid formats as errors, which break JSON parsing.
|
|
23
|
-
*/
|
|
24
|
-
let parsed = await res.text();
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
return JSON.parse(parsed);
|
|
28
|
-
} catch (e) {
|
|
29
|
-
console.warn(
|
|
30
|
-
"BuiltWith sent an invalid JSON payload. Falling back to text parsing.",
|
|
31
|
-
);
|
|
32
|
-
return parsed;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Convert a parameters object into a query string, joined by the `&` char
|
|
39
|
-
* { paramOne: 'hello', paramTwo: 'goodbye' }
|
|
40
|
-
* @param {Object} params
|
|
41
|
-
*/
|
|
42
|
-
paramsObjToQueryString: function (params) {
|
|
43
|
-
// '¶mOne=hello¶mTwo=goodbye
|
|
44
|
-
return Object.entries(params) // [['paramOne', 'hello'], ['paramTwo', 'goodbye]]
|
|
45
|
-
.filter(([, value]) => {
|
|
46
|
-
if (value === undefined) return false;
|
|
47
|
-
else return true;
|
|
48
|
-
})
|
|
49
|
-
.map(([key, value]) => {
|
|
50
|
-
return `${key}=${value}`; // ['paramOne=hello', 'paramTwo=goodbye']
|
|
51
|
-
})
|
|
52
|
-
.join("&"); // 'paramOne=hello¶mTwo=goodBye'
|
|
53
|
-
},
|
|
54
|
-
};
|