@xapp/arachne-web-service 0.5.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/LICENSE.md +176 -0
- package/README.md +3 -0
- package/lib/ArachneWebService.d.ts +73 -0
- package/lib/ArachneWebService.js +236 -0
- package/lib/ArachneWebService.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +19 -0
- package/lib/index.js.map +1 -0
- package/lib/utils/autoScroll.d.ts +10 -0
- package/lib/utils/autoScroll.js +37 -0
- package/lib/utils/autoScroll.js.map +1 -0
- package/lib/utils/findBestFaviconURL.d.ts +12 -0
- package/lib/utils/findBestFaviconURL.js +61 -0
- package/lib/utils/findBestFaviconURL.js.map +1 -0
- package/lib/utils/getDOMElementHREF.d.ts +11 -0
- package/lib/utils/getDOMElementHREF.js +35 -0
- package/lib/utils/getDOMElementHREF.js.map +1 -0
- package/lib/utils/image.d.ts +22 -0
- package/lib/utils/image.js +91 -0
- package/lib/utils/image.js.map +1 -0
- package/lib/utils/isLambda.d.ts +7 -0
- package/lib/utils/isLambda.js +14 -0
- package/lib/utils/isLambda.js.map +1 -0
- package/package.json +52 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*! Copyright (c) 2023, XAPP AI */
|
|
2
|
+
import "isomorphic-fetch";
|
|
3
|
+
import { DetectorResult } from "@xapp/arachne-parsers";
|
|
4
|
+
import { LocalBusiness } from "schema-dts";
|
|
5
|
+
export interface ArachneAppGetInfoOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Provide a path for the screenshots to be saved
|
|
8
|
+
*
|
|
9
|
+
* If not provided, you will not get primaryColor, secondaryColor, or images.
|
|
10
|
+
*/
|
|
11
|
+
screenshotsPath?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Run headless, true by default.
|
|
14
|
+
*/
|
|
15
|
+
headless?: boolean;
|
|
16
|
+
viewportSize?: {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Time in milliseconds to wait before it analyzes the page. It will also autoScroll.
|
|
22
|
+
*/
|
|
23
|
+
pageWait?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface WebsiteSchema {
|
|
26
|
+
localBusiness?: LocalBusiness;
|
|
27
|
+
}
|
|
28
|
+
export interface WebsiteDescriptiveData {
|
|
29
|
+
/**
|
|
30
|
+
* A square image that most likely is the logo.
|
|
31
|
+
*/
|
|
32
|
+
logo?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Primary color detected on the website
|
|
35
|
+
*/
|
|
36
|
+
primaryColor?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Secondary color that complements the primary color on the website.
|
|
39
|
+
*/
|
|
40
|
+
secondaryColor?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Calls to action detected on the website such as "Free Quote" or "Schedule Consultation"
|
|
43
|
+
*/
|
|
44
|
+
callsToAction?: {
|
|
45
|
+
callToAction: string;
|
|
46
|
+
url?: string;
|
|
47
|
+
}[];
|
|
48
|
+
/**
|
|
49
|
+
* A description of the organization found on the website
|
|
50
|
+
*/
|
|
51
|
+
description?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Phone numbers
|
|
54
|
+
*/
|
|
55
|
+
phoneNumbers?: {
|
|
56
|
+
number: string;
|
|
57
|
+
purpose?: string;
|
|
58
|
+
}[];
|
|
59
|
+
}
|
|
60
|
+
export interface WebsiteData {
|
|
61
|
+
site: WebsiteDescriptiveData;
|
|
62
|
+
detectedTechnologies: DetectorResult[];
|
|
63
|
+
schema: WebsiteSchema;
|
|
64
|
+
}
|
|
65
|
+
export declare class ArachneWebService {
|
|
66
|
+
/**
|
|
67
|
+
* Get data on the provided website.
|
|
68
|
+
* @param url
|
|
69
|
+
* @param options
|
|
70
|
+
* @returns
|
|
71
|
+
*/
|
|
72
|
+
getWebsiteData(url: string, options?: ArachneAppGetInfoOptions): Promise<WebsiteData>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ArachneWebService = void 0;
|
|
16
|
+
/*! Copyright (c) 2023, XAPP AI */
|
|
17
|
+
require("isomorphic-fetch"); // must be at top, making available to all
|
|
18
|
+
const path_1 = require("path");
|
|
19
|
+
const arachne_1 = require("@xapp/arachne");
|
|
20
|
+
const arachne_parsers_1 = require("@xapp/arachne-parsers");
|
|
21
|
+
const stentor_logger_1 = require("stentor-logger");
|
|
22
|
+
const stentor_utils_1 = require("stentor-utils");
|
|
23
|
+
const node_vibrant_1 = __importDefault(require("node-vibrant"));
|
|
24
|
+
const openai_1 = require("openai");
|
|
25
|
+
const autoScroll_1 = require("./utils/autoScroll");
|
|
26
|
+
const findBestFaviconURL_1 = require("./utils/findBestFaviconURL");
|
|
27
|
+
const image_1 = require("./utils/image");
|
|
28
|
+
const isLambda_1 = require("./utils/isLambda");
|
|
29
|
+
class ArachneWebService {
|
|
30
|
+
/**
|
|
31
|
+
* Get data on the provided website.
|
|
32
|
+
* @param url
|
|
33
|
+
* @param options
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
getWebsiteData(url, options) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const site = {};
|
|
39
|
+
let detectedTechnologies = [];
|
|
40
|
+
const schema = {};
|
|
41
|
+
const queue = new arachne_1.MemoryRequestQueue();
|
|
42
|
+
queue.addRequest({ url });
|
|
43
|
+
const launchOptions = {
|
|
44
|
+
timeout: 5000,
|
|
45
|
+
headless: typeof (options === null || options === void 0 ? void 0 : options.headless) === "boolean" ? options.headless : true,
|
|
46
|
+
};
|
|
47
|
+
const pageWait = typeof (options === null || options === void 0 ? void 0 : options.pageWait) === "number" ? true : false;
|
|
48
|
+
const pageWaitTime = (options === null || options === void 0 ? void 0 : options.pageWait) || 0;
|
|
49
|
+
if (!(0, isLambda_1.isLambda)()) {
|
|
50
|
+
// for local, this is required
|
|
51
|
+
launchOptions.executablePath = `/usr/bin/google-chrome`;
|
|
52
|
+
}
|
|
53
|
+
if (options === null || options === void 0 ? void 0 : options.viewportSize) {
|
|
54
|
+
launchOptions.defaultViewport = options.viewportSize;
|
|
55
|
+
launchOptions.args = [`--window-size=${options.viewportSize.width},${options.viewportSize.height}`];
|
|
56
|
+
}
|
|
57
|
+
let browser;
|
|
58
|
+
try {
|
|
59
|
+
(0, stentor_logger_1.log)().debug('Looking for chrome-aws-lambda');
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
61
|
+
const chromium = require('@sparticuz/chrome-aws-lambda');
|
|
62
|
+
browser = yield chromium.puppeteer.launch({
|
|
63
|
+
args: chromium.args,
|
|
64
|
+
defaultViewport: chromium.defaultViewport,
|
|
65
|
+
executablePath: yield chromium.executablePath,
|
|
66
|
+
headless: chromium.headless,
|
|
67
|
+
ignoreHTTPSErrors: true,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
(0, stentor_logger_1.log)().debug("Could not find chrome-aws-lambda layer, relying on local chrome installation.");
|
|
72
|
+
}
|
|
73
|
+
const crawler = arachne_1.Arachne.crawler({
|
|
74
|
+
stealth: true,
|
|
75
|
+
launchOptions,
|
|
76
|
+
queue,
|
|
77
|
+
browser,
|
|
78
|
+
pageHandlerTimeout: 50000,
|
|
79
|
+
pageHandler: (page, request) => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const title = yield page.title();
|
|
81
|
+
(0, stentor_logger_1.log)().info(`Loaded ${request.url} : ${title}`);
|
|
82
|
+
if (pageWait) {
|
|
83
|
+
(0, stentor_logger_1.log)().info(`Waiting for ${pageWaitTime} ms for page to completely load.`);
|
|
84
|
+
yield (0, autoScroll_1.autoScroll)(page, pageWaitTime);
|
|
85
|
+
(0, stentor_logger_1.log)().info('...and done waiting.');
|
|
86
|
+
}
|
|
87
|
+
// Get the raw HTML
|
|
88
|
+
// It is important to use page.content() versus response.text() since
|
|
89
|
+
// page.content() gets you the HTML after it has been modified by the JavaScript
|
|
90
|
+
// on the page while response.text() only gives you the HTML from the original GET
|
|
91
|
+
const html = yield page.content();
|
|
92
|
+
const detectors = [
|
|
93
|
+
new arachne_parsers_1.XAPPDetector(html),
|
|
94
|
+
new arachne_parsers_1.SurefireDetector(html)
|
|
95
|
+
];
|
|
96
|
+
detectedTechnologies = new arachne_parsers_1.MultiDetector(html, detectors).detect();
|
|
97
|
+
const things = new arachne_parsers_1.ArachneJSONLD(html).getThings();
|
|
98
|
+
let localBusiness;
|
|
99
|
+
for (const thing of things) {
|
|
100
|
+
if ((0, arachne_parsers_1.isLocalBusiness)(thing)) {
|
|
101
|
+
(0, stentor_logger_1.log)().debug(`Found local business information`);
|
|
102
|
+
localBusiness = thing;
|
|
103
|
+
schema.localBusiness = thing;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// We are going to try to figure out the icon!
|
|
107
|
+
if (localBusiness && typeof localBusiness !== "string") {
|
|
108
|
+
const localBusinessLogo = localBusiness.logo;
|
|
109
|
+
if (typeof localBusinessLogo === "string") {
|
|
110
|
+
const square = yield (0, image_1.imageIsSquare)(localBusinessLogo, 75);
|
|
111
|
+
if (square) {
|
|
112
|
+
(0, stentor_logger_1.log)().debug(`Found a square logo from json+ld ${localBusinessLogo}`);
|
|
113
|
+
site.logo = localBusinessLogo;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// See if we are installed
|
|
118
|
+
if (!site.logo) {
|
|
119
|
+
// try to get the
|
|
120
|
+
(0, stentor_logger_1.log)().debug(`Looking for logo from favicon`);
|
|
121
|
+
const favicon = yield (0, findBestFaviconURL_1.findBestFaviconURL)(page, request.url);
|
|
122
|
+
(0, stentor_logger_1.log)().debug(`Found a favicon ${favicon}`);
|
|
123
|
+
const square = yield (0, image_1.imageIsSquare)(favicon, 75);
|
|
124
|
+
if (square) {
|
|
125
|
+
(0, stentor_logger_1.log)().debug(`Favicon was square and bigger than 75 px, using it`);
|
|
126
|
+
site.logo = favicon;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
(0, stentor_logger_1.log)().debug(`Favicon didn't pass the test, ignoring`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Try to figure out primary color, yup
|
|
133
|
+
if (options === null || options === void 0 ? void 0 : options.screenshotsPath) {
|
|
134
|
+
const u = new URL(url);
|
|
135
|
+
const imageName = `${u.hostname}${u.pathname}`.replace(/[./]/g, "_");
|
|
136
|
+
const path = (0, path_1.resolve)(options === null || options === void 0 ? void 0 : options.screenshotsPath, `${imageName}.png`);
|
|
137
|
+
(0, stentor_logger_1.log)().debug(`Saving screenshot to ${path}`);
|
|
138
|
+
const captureBeyondViewport = options.viewportSize ? false : true;
|
|
139
|
+
const fullPage = options.viewportSize ? false : true;
|
|
140
|
+
yield page.screenshot({
|
|
141
|
+
path,
|
|
142
|
+
fullPage,
|
|
143
|
+
captureBeyondViewport
|
|
144
|
+
});
|
|
145
|
+
(0, stentor_logger_1.log)().debug(`Screenshot saved, analyzing colors`);
|
|
146
|
+
const v = new node_vibrant_1.default(path);
|
|
147
|
+
const palette = yield v.getPalette();
|
|
148
|
+
let swatchName = undefined;
|
|
149
|
+
let mostPopular;
|
|
150
|
+
let debugSwatches = "";
|
|
151
|
+
for (const swatch in palette) {
|
|
152
|
+
if (palette.hasOwnProperty(swatch) && palette[swatch]) {
|
|
153
|
+
const current = palette[swatch];
|
|
154
|
+
if (!mostPopular) {
|
|
155
|
+
swatchName = swatch;
|
|
156
|
+
mostPopular = current;
|
|
157
|
+
}
|
|
158
|
+
else if (current && mostPopular.population < current.population) {
|
|
159
|
+
swatchName = swatch;
|
|
160
|
+
mostPopular = current;
|
|
161
|
+
}
|
|
162
|
+
debugSwatches = `${debugSwatches} ${swatch}:${current === null || current === void 0 ? void 0 : current.hex}`;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (swatchName) {
|
|
166
|
+
(0, stentor_logger_1.log)().debug(`Most popular swatch ${swatchName} ${mostPopular === null || mostPopular === void 0 ? void 0 : mostPopular.hex}`);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
(0, stentor_logger_1.log)().debug(`Could not find a most popular swatch.`);
|
|
170
|
+
}
|
|
171
|
+
site.primaryColor = mostPopular === null || mostPopular === void 0 ? void 0 : mostPopular.hex;
|
|
172
|
+
site.secondaryColor = (0, image_1.complementHexColor)(site.primaryColor);
|
|
173
|
+
(0, stentor_logger_1.log)().debug(`Found primary color to be ${site.primaryColor}`);
|
|
174
|
+
(0, stentor_logger_1.log)().debug(`Alternative swatches are: ${debugSwatches}`);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
(0, stentor_logger_1.log)().info(`screenshotsPath not provided, cannot determine primaryColor and secondaryColor`);
|
|
178
|
+
}
|
|
179
|
+
// Use OpenAI to determine Call To Action
|
|
180
|
+
if (process.env.OPENAI_TOKEN) {
|
|
181
|
+
// Convert to markdown
|
|
182
|
+
const markdown = new arachne_parsers_1.ArachneHTMLtoText({ stripTags: [...arachne_parsers_1.DEFAULT_STRIP_TAGS, "img"] }).convert(html, true);
|
|
183
|
+
const configuration = new openai_1.Configuration({
|
|
184
|
+
apiKey: process.env.OPENAI_TOKEN,
|
|
185
|
+
});
|
|
186
|
+
const openai = new openai_1.OpenAIApi(configuration);
|
|
187
|
+
const prompt = `${markdown}\n==========================\nAbove is the markdown for a website found at ${url}. Please print out in JSON format information about the website above with the following keys:\n\n\"organization_name\" - The name of the organization for the website.\n\"phone_numbers\" - An array of phone numbers for the organization. If available, include what they are used for such as \"customer support\" or \"sales\", if unknown then leave it blank. Use an object with keys: number and purpose.\n\"addresses\" - An array of addresses for the organization.\n\"services\" - An array of the top five unique most common services the organization provides, they should be concise and no more than a few words such as \"Roofing\", \"Conversational AI Services\", \"Bathroom Remodelling\"\n\"calls_to_action\" - An array of the top five unique calls to action found on the site and their fully formed URL if they have one. Good examples of calls to actions are \"Request Demo\", \"Get Started\", \"Free Quote\", \"Schedule Consultation\", \"Sign Up\". Bad examples are \"Learn More\" or \"Follow us on Facebook\". Use an object with keys: url & callToAction in the array. For the url please combine it properly with the website's URL.\n\"description\" - A concise description of what the organization does in one sentence, include the name of the organization and their services and their location if available.\n \n{`;
|
|
188
|
+
console.time("open_ai");
|
|
189
|
+
const response = yield openai.createCompletion({
|
|
190
|
+
model: "text-davinci-003",
|
|
191
|
+
prompt,
|
|
192
|
+
temperature: 0.7,
|
|
193
|
+
max_tokens: 1017,
|
|
194
|
+
top_p: 1,
|
|
195
|
+
frequency_penalty: 0,
|
|
196
|
+
presence_penalty: 0,
|
|
197
|
+
});
|
|
198
|
+
console.timeEnd("open_ai");
|
|
199
|
+
if (response.status === 200) {
|
|
200
|
+
// Add the leading { as it is included in the query
|
|
201
|
+
const completion = `{\n${response.data.choices[0].text}`;
|
|
202
|
+
const siteData = JSON.parse(completion);
|
|
203
|
+
// eslint-disable-next-line no-console
|
|
204
|
+
site.callsToAction = siteData.calls_to_action;
|
|
205
|
+
site.description = siteData.description;
|
|
206
|
+
site.phoneNumbers = siteData.phone_numbers;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
// Try to figure out the call to action
|
|
211
|
+
// TODO: Can we use our model export and a simple NLU to better find possible matches?
|
|
212
|
+
const REGEX = new RegExp(/(free|get|request|schedule)( a| an|) (consultation|quote|estimate|inspection|estimates|assessment|appointment)/gmi);
|
|
213
|
+
const matches = html.match(REGEX);
|
|
214
|
+
// Just grab the first
|
|
215
|
+
if (matches && (0, stentor_utils_1.existsAndNotEmpty)(matches)) {
|
|
216
|
+
(0, stentor_logger_1.log)().debug(`Found ${matches.length} potential CTAs`);
|
|
217
|
+
const match = matches[0].toLowerCase();
|
|
218
|
+
const cleaned = match.split(" ").map((i) => (0, stentor_utils_1.capitalize)(i)).join(" ");
|
|
219
|
+
(0, stentor_logger_1.log)().debug(`Found CTA "${cleaned}"`);
|
|
220
|
+
site.callsToAction = [{ callToAction: cleaned }];
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
// end of the page handler
|
|
225
|
+
});
|
|
226
|
+
yield crawler.run();
|
|
227
|
+
return {
|
|
228
|
+
site,
|
|
229
|
+
detectedTechnologies,
|
|
230
|
+
schema
|
|
231
|
+
};
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
exports.ArachneWebService = ArachneWebService;
|
|
236
|
+
//# sourceMappingURL=ArachneWebService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArachneWebService.js","sourceRoot":"","sources":["../src/ArachneWebService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kCAAkC;AAClC,4BAA0B,CAAC,0CAA0C;AACrE,+BAA+B;AAE/B,2CAAyF;AACzF,2DAU+B;AAE/B,mDAAqC;AACrC,iDAA8D;AAG9D,gEAAmC;AACnC,mCAAkD;AAGlD,mDAAgD;AAChD,mEAAgE;AAChE,yCAAkE;AAClE,+CAA4C;AA6D5C,MAAa,iBAAiB;IAC1B;;;;;OAKG;IACU,cAAc,CAAC,GAAW,EAAE,OAAkC;;YAEvE,MAAM,IAAI,GAA2B,EAAE,CAAC;YACxC,IAAI,oBAAoB,GAAqB,EAAE,CAAC;YAChD,MAAM,MAAM,GAAkB,EAAE,CAAC;YAEjC,MAAM,KAAK,GAAG,IAAI,4BAAkB,EAAE,CAAC;YACvC,KAAK,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;YAE1B,MAAM,aAAa,GAAyE;gBACxF,OAAO,EAAE,IAAI;gBACb,QAAQ,EAAE,OAAO,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,CAAA,KAAK,SAAS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GAAE,CAAC,KAAK,CAAC,SAAS,OAAO,CAAC,MAAM,iBAAiB,CAAC,CAAC;4BACtD,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;4BACvC,MAAM,OAAO,GAAW,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,0BAAU,EAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;4BAC7E,IAAA,oBAAG,GAAE,CAAC,KAAK,CAAC,cAAc,OAAO,GAAG,CAAC,CAAC;4BACtC,IAAI,CAAC,aAAa,GAAG,CAAC,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC;yBACpD;qBACJ;gBACL,CAAC,CAAA;gBACD,0BAA0B;aAC7B,CAAC,CAAC;YAEH,MAAM,OAAO,CAAC,GAAG,EAAE,CAAC;YAEpB,OAAO;gBACH,IAAI;gBACJ,oBAAoB;gBACpB,MAAM;aACT,CAAC;QACN,CAAC;KAAA;CACJ;AAxPD,8CAwPC"}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/*! Copyright (c) 2023, XAPP AI */
|
|
18
|
+
__exportStar(require("./ArachneWebService"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kCAAkC;AAClC,sDAAoC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*! Copyright (c) 2023, XAPP AI */
|
|
2
|
+
import { ArachnePage } from "@xapp/arachne";
|
|
3
|
+
/**
|
|
4
|
+
* Autoscoll with wait timeout. Used to help with loading lazy loaded scripts.
|
|
5
|
+
*
|
|
6
|
+
* @param page
|
|
7
|
+
* @param timeout
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare const autoScroll: (page: ArachnePage, timeout?: number) => Promise<void>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.autoScroll = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* Autoscoll with wait timeout. Used to help with loading lazy loaded scripts.
|
|
15
|
+
*
|
|
16
|
+
* @param page
|
|
17
|
+
* @param timeout
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
const autoScroll = (page, timeout = 12000) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
yield page.evaluate((timeout) => {
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
const scrollHeight = document.body.scrollHeight;
|
|
24
|
+
const scrollWidget = document.body.scrollWidth;
|
|
25
|
+
// just scroll to the bottom right corner
|
|
26
|
+
window.scrollBy(scrollWidget, scrollHeight);
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
// finish waiting and done
|
|
29
|
+
resolve(() => { return; });
|
|
30
|
+
// bit of magic in this number
|
|
31
|
+
}, timeout);
|
|
32
|
+
});
|
|
33
|
+
}, timeout);
|
|
34
|
+
return;
|
|
35
|
+
});
|
|
36
|
+
exports.autoScroll = autoScroll;
|
|
37
|
+
//# sourceMappingURL=autoScroll.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autoScroll.js","sourceRoot":"","sources":["../../src/utils/autoScroll.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA;;;;;;GAMG;AACI,MAAM,UAAU,GAAG,CAAO,IAAiB,EAAE,UAAkB,KAAK,EAAiB,EAAE;IAC1F,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,EAAE;QAC5B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAE3B,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC;YAChD,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC;YAC/C,yCAAyC;YACzC,MAAM,CAAC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;YAE5C,UAAU,CAAC,GAAG,EAAE;gBACZ,0BAA0B;gBAC1B,OAAO,CAAC,GAAG,EAAE,GAAG,OAAM,CAAC,CAAC,CAAC,CAAC;gBAC1B,8BAA8B;YAClC,CAAC,EAAE,OAAO,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC,EAAE,OAAO,CAAC,CAAC;IACZ,OAAO;AACX,CAAC,CAAA,CAAA;AAjBY,QAAA,UAAU,cAiBtB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*! Copyright (c) 2023, XAPP AI */
|
|
2
|
+
import { ArachnePage } from "@xapp/arachne";
|
|
3
|
+
/**
|
|
4
|
+
* For the given page, find the best favicon URL.
|
|
5
|
+
*
|
|
6
|
+
* {@link https://semisignal.com/finding-fetching-and-rendering-favicons-with-puppeteer/}
|
|
7
|
+
*
|
|
8
|
+
* @param page
|
|
9
|
+
* @param pageUrl
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare function findBestFaviconURL(page: ArachnePage, pageUrl: string): Promise<string>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.findBestFaviconURL = void 0;
|
|
13
|
+
const getDOMElementHREF_1 = require("./getDOMElementHREF");
|
|
14
|
+
/**
|
|
15
|
+
* For the given page, find the best favicon URL.
|
|
16
|
+
*
|
|
17
|
+
* {@link https://semisignal.com/finding-fetching-and-rendering-favicons-with-puppeteer/}
|
|
18
|
+
*
|
|
19
|
+
* @param page
|
|
20
|
+
* @param pageUrl
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
function findBestFaviconURL(page, pageUrl) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const rootUrl = (new URL(pageUrl)).protocol + "//" + (new URL(pageUrl)).host;
|
|
26
|
+
const selectorsToTry = [
|
|
27
|
+
`link[rel="icon"]`,
|
|
28
|
+
`link[rel="shortcut icon"]`
|
|
29
|
+
];
|
|
30
|
+
let faviconUrlFromDocument = null;
|
|
31
|
+
for (let i = 0; i < selectorsToTry.length; i++) {
|
|
32
|
+
const href = yield (0, getDOMElementHREF_1.getDOMElementHREF)(page, selectorsToTry[i]);
|
|
33
|
+
if (typeof href === 'undefined' || href === null || href.length === 0) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
faviconUrlFromDocument = href;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
if (faviconUrlFromDocument === null) {
|
|
40
|
+
// No favicon link found in document, best URL is likley favicon.ico at root
|
|
41
|
+
return rootUrl + "/favicon.ico";
|
|
42
|
+
}
|
|
43
|
+
if (faviconUrlFromDocument.substr(0, 2) === "//") {
|
|
44
|
+
return `${new URL(pageUrl).protocol}${faviconUrlFromDocument}`;
|
|
45
|
+
}
|
|
46
|
+
else if (faviconUrlFromDocument.substr(0, 4) === "http") {
|
|
47
|
+
// absolute url
|
|
48
|
+
return faviconUrlFromDocument;
|
|
49
|
+
}
|
|
50
|
+
else if (faviconUrlFromDocument.substr(0, 1) === '/') {
|
|
51
|
+
// favicon relative to root
|
|
52
|
+
return (rootUrl + faviconUrlFromDocument);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// favicon relative to current (pageUrl) URL
|
|
56
|
+
return (pageUrl + "/" + faviconUrlFromDocument);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
exports.findBestFaviconURL = findBestFaviconURL;
|
|
61
|
+
//# sourceMappingURL=findBestFaviconURL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findBestFaviconURL.js","sourceRoot":"","sources":["../../src/utils/findBestFaviconURL.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,2DAAwD;AAExD;;;;;;;;GAQG;AACH,SAAsB,kBAAkB,CAAC,IAAiB,EAAE,OAAe;;QAEvE,MAAM,OAAO,GAAG,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,GAAG,IAAI,GAAG,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;QAC7E,MAAM,cAAc,GAAG;YACnB,kBAAkB;YAClB,2BAA2B;SAC9B,CAAC;QAEF,IAAI,sBAAsB,GAAG,IAAI,CAAC;QAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC5C,MAAM,IAAI,GAAG,MAAM,IAAA,qCAAiB,EAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;YAC9D,IAAI,OAAO,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;gBACnE,SAAS;aACZ;YAED,sBAAsB,GAAG,IAAI,CAAC;YAC9B,MAAM;SACT;QAED,IAAI,sBAAsB,KAAK,IAAI,EAAE;YACjC,4EAA4E;YAC5E,OAAO,OAAO,GAAG,cAAc,CAAC;SACnC;QAED,IAAI,sBAAsB,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE;YAC9C,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,QAAQ,GAAG,sBAAsB,EAAE,CAAC;SAClE;aAAM,IAAI,sBAAsB,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,EAAE;YACvD,eAAe;YACf,OAAO,sBAAsB,CAAC;SACjC;aAAM,IAAI,sBAAsB,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,EAAE;YACpD,2BAA2B;YAC3B,OAAO,CAAC,OAAO,GAAG,sBAAsB,CAAC,CAAC;SAC7C;aAAM;YACH,4CAA4C;YAC5C,OAAO,CAAC,OAAO,GAAG,GAAG,GAAG,sBAAsB,CAAC,CAAC;SACnD;IACL,CAAC;CAAA;AApCD,gDAoCC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*! Copyright (c) 2023, XAPP AI */
|
|
2
|
+
import { ArachnePage } from "@xapp/arachne";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* {@link https://semisignal.com/finding-fetching-and-rendering-favicons-with-puppeteer/}
|
|
6
|
+
*
|
|
7
|
+
* @param page
|
|
8
|
+
* @param query
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export declare function getDOMElementHREF(page: ArachnePage, query: string): Promise<string>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getDOMElementHREF = void 0;
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* {@link https://semisignal.com/finding-fetching-and-rendering-favicons-with-puppeteer/}
|
|
16
|
+
*
|
|
17
|
+
* @param page
|
|
18
|
+
* @param query
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
function getDOMElementHREF(page, query) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
return yield page.evaluate((q) => {
|
|
24
|
+
const elem = document.querySelector(q);
|
|
25
|
+
if (elem) {
|
|
26
|
+
return (elem.getAttribute('href') || '');
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
}, query);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
exports.getDOMElementHREF = getDOMElementHREF;
|
|
35
|
+
//# sourceMappingURL=getDOMElementHREF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDOMElementHREF.js","sourceRoot":"","sources":["../../src/utils/getDOMElementHREF.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA;;;;;;;GAOG;AACH,SAAsB,iBAAiB,CAAC,IAAiB,EAAE,KAAa;;QACpE,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE;YAC7B,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;YACvC,IAAI,IAAI,EAAE;gBACN,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;aAC5C;iBAAM;gBACH,OAAO,EAAE,CAAC;aACb;QACL,CAAC,EAAE,KAAK,CAAC,CAAC;IACd,CAAC;CAAA;AATD,8CASC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*! Copyright (c) 2022, XAPP AI */
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/**
|
|
4
|
+
* Determines if the image at the URL provided is square.
|
|
5
|
+
*
|
|
6
|
+
* Optionally, if you pass in a minimum size, it will also determine if the image meets the minimum size.
|
|
7
|
+
*
|
|
8
|
+
* @param url
|
|
9
|
+
* @param minimumSize
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare function imageIsSquare(url: string, minimumSize?: number): Promise<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* Provides a complementary hex color
|
|
15
|
+
*
|
|
16
|
+
* {@author OpenAI GPT4}
|
|
17
|
+
*
|
|
18
|
+
* @param hex
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
export declare function complementHexColor(hex: string | undefined): string | undefined;
|
|
22
|
+
export declare function generateImage(height: number, width: number, hex: string): Promise<Buffer>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*! Copyright (c) 2022, XAPP AI */
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.generateImage = exports.complementHexColor = exports.imageIsSquare = void 0;
|
|
17
|
+
const sharp_1 = __importDefault(require("sharp"));
|
|
18
|
+
/**
|
|
19
|
+
* Determines if the image at the URL provided is square.
|
|
20
|
+
*
|
|
21
|
+
* Optionally, if you pass in a minimum size, it will also determine if the image meets the minimum size.
|
|
22
|
+
*
|
|
23
|
+
* @param url
|
|
24
|
+
* @param minimumSize
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
function imageIsSquare(url, minimumSize) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const img = yield fetch(url);
|
|
30
|
+
const arrayBuffer = yield img.arrayBuffer();
|
|
31
|
+
const imgBuffer = Buffer.from(arrayBuffer);
|
|
32
|
+
const image = yield (0, sharp_1.default)(imgBuffer);
|
|
33
|
+
const meta = yield image.metadata();
|
|
34
|
+
const width = meta.width;
|
|
35
|
+
const height = meta.height;
|
|
36
|
+
const isSquare = width === height;
|
|
37
|
+
if (typeof minimumSize === "number" && typeof width === "number") {
|
|
38
|
+
return isSquare && width >= minimumSize;
|
|
39
|
+
}
|
|
40
|
+
return isSquare;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
exports.imageIsSquare = imageIsSquare;
|
|
44
|
+
/**
|
|
45
|
+
* Provides a complementary hex color
|
|
46
|
+
*
|
|
47
|
+
* {@author OpenAI GPT4}
|
|
48
|
+
*
|
|
49
|
+
* @param hex
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
function complementHexColor(hex) {
|
|
53
|
+
if (!hex) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
// Ensure the input hex color is in a valid format
|
|
57
|
+
const validHex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
|
|
58
|
+
if (!validHex.test(hex)) {
|
|
59
|
+
throw new TypeError('Invalid hex color format');
|
|
60
|
+
}
|
|
61
|
+
// Normalize the input hex color to 6 characters
|
|
62
|
+
if (hex.length === 4) {
|
|
63
|
+
hex = '#' + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3];
|
|
64
|
+
}
|
|
65
|
+
// Calculate the complementary color
|
|
66
|
+
let compColor = '#';
|
|
67
|
+
for (let i = 1; i < 6; i += 2) {
|
|
68
|
+
const colorComponent = parseInt(hex.slice(i, i + 2), 16);
|
|
69
|
+
const compComponent = (0xFF - colorComponent).toString(16).padStart(2, '0');
|
|
70
|
+
compColor += compComponent;
|
|
71
|
+
}
|
|
72
|
+
return compColor;
|
|
73
|
+
}
|
|
74
|
+
exports.complementHexColor = complementHexColor;
|
|
75
|
+
// not tested yet
|
|
76
|
+
function generateImage(height, width, hex) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
return (0, sharp_1.default)({
|
|
79
|
+
create: {
|
|
80
|
+
width,
|
|
81
|
+
height,
|
|
82
|
+
channels: 4,
|
|
83
|
+
background: hex
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
.png()
|
|
87
|
+
.toBuffer();
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
exports.generateImage = generateImage;
|
|
91
|
+
//# sourceMappingURL=image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../src/utils/image.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;;;;;;;;;;;;;AAElC,kDAA0B;AAE1B;;;;;;;;GAQG;AACH,SAAsB,aAAa,CAAC,GAAW,EAAE,WAAoB;;QAEjE,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7B,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,WAAW,EAAE,CAAC;QAC5C,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAE3C,MAAM,KAAK,GAAG,MAAM,IAAA,eAAK,EAAC,SAAS,CAAC,CAAC;QACrC,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC;QAEpC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB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C,CAAC;QAC5E,SAAS,IAAI,aAAa,CAAC;KAC9B;IAED,OAAO,SAAS,CAAC;AACrB,CAAC;AAxBD,gDAwBC;AAGD,iBAAiB;AACjB,SAAsB,aAAa,CAAC,MAAc,EAAE,KAAa,EAAE,GAAW;;QAC1E,OAAO,IAAA,eAAK,EAAC;YACT,MAAM,EAAE;gBACJ,KAAK;gBACL,MAAM;gBACN,QAAQ,EAAE,CAAC;gBACX,UAAU,EAAE,GAAG;aAClB;SACJ,CAAC;aACG,GAAG,EAAE;aACL,QAAQ,EAAE,CAAC;IACpB,CAAC;CAAA;AAXD,sCAWC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*! Copyright (c) 2022, XAPP AI */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.isLambda = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Check if you are running on AWS Lambda environment.
|
|
7
|
+
*
|
|
8
|
+
* @returns true if running on Lambda
|
|
9
|
+
*/
|
|
10
|
+
function isLambda() {
|
|
11
|
+
return !!process.env.LAMBDA_TASK_ROOT;
|
|
12
|
+
}
|
|
13
|
+
exports.isLambda = isLambda;
|
|
14
|
+
//# sourceMappingURL=isLambda.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isLambda.js","sourceRoot":"","sources":["../../src/utils/isLambda.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;AAElC;;;;GAIG;AACH,SAAgB,QAAQ;IACpB,OAAO,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;AAC1C,CAAC;AAFD,4BAEC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xapp/arachne-web-service",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"types": "lib/index",
|
|
5
|
+
"main": "lib/index",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib"
|
|
8
|
+
],
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": "^14 || ^16 || ^18"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@microsoft/api-extractor": "7.33.7",
|
|
18
|
+
"@types/chai": "4.3.4",
|
|
19
|
+
"@types/mocha": "10.0.1",
|
|
20
|
+
"@types/node": "18.11.18",
|
|
21
|
+
"@types/sinon": "10.0.13",
|
|
22
|
+
"@types/sinon-chai": "3.2.9",
|
|
23
|
+
"@xapp/config": "0.2.3",
|
|
24
|
+
"chai": "4.3.7",
|
|
25
|
+
"dotenv": "16.0.3",
|
|
26
|
+
"mocha": "10.2.0",
|
|
27
|
+
"sinon": "15.0.1",
|
|
28
|
+
"sinon-chai": "3.7.0",
|
|
29
|
+
"ts-node": "10.9.1",
|
|
30
|
+
"tslib": "2.5.0",
|
|
31
|
+
"typescript": "4.8.4"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@xapp/arachne": "0.5.0",
|
|
35
|
+
"@xapp/arachne-parsers": "0.5.0",
|
|
36
|
+
"isomorphic-fetch": "3.0.0",
|
|
37
|
+
"node-vibrant": "3.2.1-alpha.1",
|
|
38
|
+
"openai": "3.2.1",
|
|
39
|
+
"schema-dts": "1.1.0",
|
|
40
|
+
"sharp": "0.32.0",
|
|
41
|
+
"stentor-logger": "1.57.116",
|
|
42
|
+
"stentor-models": "1.57.115",
|
|
43
|
+
"stentor-utils": "1.57.116"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"api": "api-extractor run --local",
|
|
47
|
+
"build": "tsc -d true -p .",
|
|
48
|
+
"clean": "rm -rf ./lib/*",
|
|
49
|
+
"test:f": "mocha --recursive -r ts-node/register \"./src/**/*.ftest.ts\""
|
|
50
|
+
},
|
|
51
|
+
"gitHead": "3f8407d44b028384726efab7359aafe796469209"
|
|
52
|
+
}
|