UNPKG

10.2 kBJavaScriptView Raw
1"use strict";
2/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
3/* eslint-disable @typescript-eslint/no-explicit-any */
4/*!
5 * Sitemap
6 * Copyright(c) 2011 Eugene Kalinin
7 * MIT Licensed
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.EmptySitemap = exports.EmptyStream = exports.InvalidVideoPriceCurrency = exports.InvalidVideoResolution = exports.InvalidVideoPriceType = exports.InvalidVideoRestrictionRelationship = exports.InvalidVideoRestriction = exports.InvalidVideoFamilyFriendly = exports.InvalidVideoCategory = exports.InvalidVideoTagCount = exports.InvalidVideoViewCount = exports.InvalidVideoTitle = exports.XMLLintUnavailable = exports.InvalidNewsAccessValue = exports.InvalidNewsFormat = exports.InvalidAttr = exports.InvalidAttrValue = exports.InvalidVideoRating = exports.InvalidVideoDescription = exports.InvalidVideoDuration = exports.InvalidVideoFormat = exports.UndefinedTargetFolder = exports.PriorityInvalidError = exports.ChangeFreqInvalidError = exports.NoConfigError = exports.NoURLError = void 0;
11/**
12 * URL in SitemapItem does not exist
13 */
14class NoURLError extends Error {
15 constructor(message) {
16 super(message || 'URL is required');
17 this.name = 'NoURLError';
18 Error.captureStackTrace(this, NoURLError);
19 }
20}
21exports.NoURLError = NoURLError;
22/**
23 * Config was not passed to SitemapItem constructor
24 */
25class NoConfigError extends Error {
26 constructor(message) {
27 super(message || 'SitemapItem requires a configuration');
28 this.name = 'NoConfigError';
29 Error.captureStackTrace(this, NoConfigError);
30 }
31}
32exports.NoConfigError = NoConfigError;
33/**
34 * changefreq property in sitemap is invalid
35 */
36class ChangeFreqInvalidError extends Error {
37 constructor(url, changefreq) {
38 super(`${url}: changefreq "${changefreq}" is invalid`);
39 this.name = 'ChangeFreqInvalidError';
40 Error.captureStackTrace(this, ChangeFreqInvalidError);
41 }
42}
43exports.ChangeFreqInvalidError = ChangeFreqInvalidError;
44/**
45 * priority property in sitemap is invalid
46 */
47class PriorityInvalidError extends Error {
48 constructor(url, priority) {
49 super(`${url}: priority "${priority}" must be a number between 0 and 1 inclusive`);
50 this.name = 'PriorityInvalidError';
51 Error.captureStackTrace(this, PriorityInvalidError);
52 }
53}
54exports.PriorityInvalidError = PriorityInvalidError;
55/**
56 * SitemapIndex target Folder does not exists
57 */
58class UndefinedTargetFolder extends Error {
59 constructor(message) {
60 super(message || 'Target folder must exist');
61 this.name = 'UndefinedTargetFolder';
62 Error.captureStackTrace(this, UndefinedTargetFolder);
63 }
64}
65exports.UndefinedTargetFolder = UndefinedTargetFolder;
66class InvalidVideoFormat extends Error {
67 constructor(url) {
68 super(`${url} video must include thumbnail_loc, title and description fields for videos`);
69 this.name = 'InvalidVideoFormat';
70 Error.captureStackTrace(this, InvalidVideoFormat);
71 }
72}
73exports.InvalidVideoFormat = InvalidVideoFormat;
74class InvalidVideoDuration extends Error {
75 constructor(url, duration) {
76 super(`${url} duration "${duration}" must be an integer of seconds between 0 and 28800`);
77 this.name = 'InvalidVideoDuration';
78 Error.captureStackTrace(this, InvalidVideoDuration);
79 }
80}
81exports.InvalidVideoDuration = InvalidVideoDuration;
82class InvalidVideoDescription extends Error {
83 constructor(url, length) {
84 const message = `${url}: video description is too long ${length} vs limit of 2048 characters.`;
85 super(message);
86 this.name = 'InvalidVideoDescription';
87 Error.captureStackTrace(this, InvalidVideoDescription);
88 }
89}
90exports.InvalidVideoDescription = InvalidVideoDescription;
91class InvalidVideoRating extends Error {
92 constructor(url, title, rating) {
93 super(`${url}: video "${title}" rating "${rating}" must be between 0 and 5 inclusive`);
94 this.name = 'InvalidVideoRating';
95 Error.captureStackTrace(this, InvalidVideoRating);
96 }
97}
98exports.InvalidVideoRating = InvalidVideoRating;
99class InvalidAttrValue extends Error {
100 // eslint-disable-next-line @typescript-eslint/no-explicit-any
101 constructor(key, val, validator) {
102 super('"' +
103 val +
104 '" tested against: ' +
105 validator +
106 ' is not a valid value for attr: "' +
107 key +
108 '"');
109 this.name = 'InvalidAttrValue';
110 Error.captureStackTrace(this, InvalidAttrValue);
111 }
112}
113exports.InvalidAttrValue = InvalidAttrValue;
114// InvalidAttr is only thrown when attrbuilder is called incorrectly internally
115/* istanbul ignore next */
116class InvalidAttr extends Error {
117 constructor(key) {
118 super('"' + key + '" is malformed');
119 this.name = 'InvalidAttr';
120 Error.captureStackTrace(this, InvalidAttr);
121 }
122}
123exports.InvalidAttr = InvalidAttr;
124class InvalidNewsFormat extends Error {
125 constructor(url) {
126 super(`${url} News must include publication, publication name, publication language, title, and publication_date for news`);
127 this.name = 'InvalidNewsFormat';
128 Error.captureStackTrace(this, InvalidNewsFormat);
129 }
130}
131exports.InvalidNewsFormat = InvalidNewsFormat;
132class InvalidNewsAccessValue extends Error {
133 constructor(url, access) {
134 super(`${url} News access "${access}" must be either Registration, Subscription or not be present`);
135 this.name = 'InvalidNewsAccessValue';
136 Error.captureStackTrace(this, InvalidNewsAccessValue);
137 }
138}
139exports.InvalidNewsAccessValue = InvalidNewsAccessValue;
140class XMLLintUnavailable extends Error {
141 constructor(message) {
142 super(message || 'xmlLint is not installed. XMLLint is required to validate');
143 this.name = 'XMLLintUnavailable';
144 Error.captureStackTrace(this, XMLLintUnavailable);
145 }
146}
147exports.XMLLintUnavailable = XMLLintUnavailable;
148class InvalidVideoTitle extends Error {
149 constructor(url, length) {
150 super(`${url}: video title is too long ${length} vs 100 character limit`);
151 this.name = 'InvalidVideoTitle';
152 Error.captureStackTrace(this, InvalidVideoTitle);
153 }
154}
155exports.InvalidVideoTitle = InvalidVideoTitle;
156class InvalidVideoViewCount extends Error {
157 constructor(url, count) {
158 super(`${url}: video view count must be positive, view count was ${count}`);
159 this.name = 'InvalidVideoViewCount';
160 Error.captureStackTrace(this, InvalidVideoViewCount);
161 }
162}
163exports.InvalidVideoViewCount = InvalidVideoViewCount;
164class InvalidVideoTagCount extends Error {
165 constructor(url, count) {
166 super(`${url}: video can have no more than 32 tags, this has ${count}`);
167 this.name = 'InvalidVideoTagCount';
168 Error.captureStackTrace(this, InvalidVideoTagCount);
169 }
170}
171exports.InvalidVideoTagCount = InvalidVideoTagCount;
172class InvalidVideoCategory extends Error {
173 constructor(url, count) {
174 super(`${url}: video category can only be 256 characters but was passed ${count}`);
175 this.name = 'InvalidVideoCategory';
176 Error.captureStackTrace(this, InvalidVideoCategory);
177 }
178}
179exports.InvalidVideoCategory = InvalidVideoCategory;
180class InvalidVideoFamilyFriendly extends Error {
181 constructor(url, fam) {
182 super(`${url}: video family friendly must be yes or no, was passed "${fam}"`);
183 this.name = 'InvalidVideoFamilyFriendly';
184 Error.captureStackTrace(this, InvalidVideoFamilyFriendly);
185 }
186}
187exports.InvalidVideoFamilyFriendly = InvalidVideoFamilyFriendly;
188class InvalidVideoRestriction extends Error {
189 constructor(url, code) {
190 super(`${url}: video restriction must be one or more two letter country codes. Was passed "${code}"`);
191 this.name = 'InvalidVideoRestriction';
192 Error.captureStackTrace(this, InvalidVideoRestriction);
193 }
194}
195exports.InvalidVideoRestriction = InvalidVideoRestriction;
196class InvalidVideoRestrictionRelationship extends Error {
197 constructor(url, val) {
198 super(`${url}: video restriction relationship must be either allow or deny. Was passed "${val}"`);
199 this.name = 'InvalidVideoRestrictionRelationship';
200 Error.captureStackTrace(this, InvalidVideoRestrictionRelationship);
201 }
202}
203exports.InvalidVideoRestrictionRelationship = InvalidVideoRestrictionRelationship;
204class InvalidVideoPriceType extends Error {
205 constructor(url, priceType, price) {
206 super(priceType === undefined && price === ''
207 ? `${url}: video priceType is required when price is not provided`
208 : `${url}: video price type "${priceType}" is not "rent" or "purchase"`);
209 this.name = 'InvalidVideoPriceType';
210 Error.captureStackTrace(this, InvalidVideoPriceType);
211 }
212}
213exports.InvalidVideoPriceType = InvalidVideoPriceType;
214class InvalidVideoResolution extends Error {
215 constructor(url, resolution) {
216 super(`${url}: video price resolution "${resolution}" is not hd or sd`);
217 this.name = 'InvalidVideoResolution';
218 Error.captureStackTrace(this, InvalidVideoResolution);
219 }
220}
221exports.InvalidVideoResolution = InvalidVideoResolution;
222class InvalidVideoPriceCurrency extends Error {
223 constructor(url, currency) {
224 super(`${url}: video price currency "${currency}" must be a three capital letter abbrieviation for the country currency`);
225 this.name = 'InvalidVideoPriceCurrency';
226 Error.captureStackTrace(this, InvalidVideoPriceCurrency);
227 }
228}
229exports.InvalidVideoPriceCurrency = InvalidVideoPriceCurrency;
230class EmptyStream extends Error {
231 constructor() {
232 super('You have ended the stream before anything was written. streamToPromise MUST be called before ending the stream.');
233 this.name = 'EmptyStream';
234 Error.captureStackTrace(this, EmptyStream);
235 }
236}
237exports.EmptyStream = EmptyStream;
238class EmptySitemap extends Error {
239 constructor() {
240 super('You ended the stream without writing anything.');
241 this.name = 'EmptySitemap';
242 Error.captureStackTrace(this, EmptyStream);
243 }
244}
245exports.EmptySitemap = EmptySitemap;