New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@internetarchive/search-service

Package Overview
Dependencies
Maintainers
18
Versions
158
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@internetarchive/search-service - npm Package Compare versions

Comparing version 1.2.5-alpha.12 to 1.2.5-alpha.13

dist/src/models/hit-types/web-archive-hit.d.ts

5

dist/src/models/hit-types/hit.d.ts
import type { ItemHit } from './item-hit';
import type { TextHit } from './text-hit';
import type { FavoritedSearchHit } from './favorited-search-hit';
import { WebArchiveHit } from './web-archive-hit';
/**

@@ -8,3 +9,3 @@ * Union of the different hit_type values returned by the PPS.

*/
export declare type HitType = 'item' | 'text' | 'favorited_search';
export declare type HitType = 'item' | 'text' | 'favorited_search' | 'web_archive';
/**

@@ -25,3 +26,3 @@ * Additional information provided by the PPS about hits, separately from

*/
export declare type SearchResult = Partial<ItemHit & TextHit & FavoritedSearchHit> & HitInfo;
export declare type SearchResult = Partial<ItemHit & TextHit & FavoritedSearchHit & WebArchiveHit> & HitInfo;
export {};

4

dist/src/responses/page-elements.d.ts

@@ -53,2 +53,3 @@ import { Aggregation } from '../models/aggregation';

export declare type ForumPostsPageElement = ForumPost[];
export declare type PageElement = UploadsPageElement | ReviewsPageElement | CollectionsPageElement | LendingPageElement | WebArchivesPageElement | ForumPostsPageElement;
/**

@@ -58,3 +59,3 @@ * A map containing one or more page elements returned by the PPS, keyed by the

*/
export interface PageElementMap extends Partial<Record<PageElementName, unknown>> {
export interface PageElementMap extends Partial<Record<PageElementName, PageElement>> {
uploads?: UploadsPageElement;

@@ -67,2 +68,3 @@ reviews?: ReviewsPageElement;

}
export declare function convertWebArchivesToSearchHits(pageElement: WebArchivesPageElement): Record<string, unknown>[];
export {};

@@ -1,2 +0,22 @@

export {};
/**
* Converts dates from web capture "YYYYMMDDhhmmss" format to ISO-8601 "YYYY-MM-DDThh:mm:ssZ" format.
*/
function fixWebCaptureDateFormatting(date) {
return `${date.slice(0, 4)}-${date.slice(4, 6)}-${date.slice(6, 8)}T${date.slice(8, 10)}:${date.slice(10, 12)}:${date.slice(12, 14)}Z`;
}
export function convertWebArchivesToSearchHits(pageElement) {
var _a;
const results = [];
for (const entry of pageElement) {
results.push({
hit_type: 'web_archive',
fields: {
title: entry.url,
capture_dates: (_a = entry.captures) === null || _a === void 0 ? void 0 : _a.map(date => fixWebCaptureDateFormatting(date)),
__href__: `https://web.archive.org/web/${entry.captures[0]}/${encodeURIComponent(entry.url)}`,
},
});
}
return results;
}
//# sourceMappingURL=page-elements.js.map

@@ -6,2 +6,3 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

import { FavoritedSearchHit } from '../models/hit-types/favorited-search-hit';
import { convertWebArchivesToSearchHits } from './page-elements';
/**

@@ -15,7 +16,6 @@ * This is the search response details inside the SearchResponse object that contains

constructor(body, schema) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
this.schema = schema;
const schemaHitType = schema === null || schema === void 0 ? void 0 : schema.hit_type;
let firstPageElement;
console.log(body);
console.log('has page elements?', !!(body === null || body === void 0 ? void 0 : body.page_elements));

@@ -35,2 +35,6 @@ if (body === null || body === void 0 ? void 0 : body.page_elements) {

}
else if ((_c = this.pageElements) === null || _c === void 0 ? void 0 : _c['web_archives']) {
hits = convertWebArchivesToSearchHits(this.pageElements['web_archives']);
console.log('hits from web archives', hits);
}
// Use aggregations directly from the body if available.

@@ -46,8 +50,8 @@ // Otherwise, try extracting them from the first page_element.

}
this.totalResults = (_f = (_d = (_c = body === null || body === void 0 ? void 0 : body.hits) === null || _c === void 0 ? void 0 : _c.total) !== null && _d !== void 0 ? _d : (_e = firstPageElement === null || firstPageElement === void 0 ? void 0 : firstPageElement.hits) === null || _e === void 0 ? void 0 : _e.total) !== null && _f !== void 0 ? _f : 0;
this.totalResults = (_g = (_e = (_d = body === null || body === void 0 ? void 0 : body.hits) === null || _d === void 0 ? void 0 : _d.total) !== null && _e !== void 0 ? _e : (_f = firstPageElement === null || firstPageElement === void 0 ? void 0 : firstPageElement.hits) === null || _f === void 0 ? void 0 : _f.total) !== null && _g !== void 0 ? _g : 0;
this.returnedCount =
(_k = (_h = (_g = body === null || body === void 0 ? void 0 : body.hits) === null || _g === void 0 ? void 0 : _g.returned) !== null && _h !== void 0 ? _h : (_j = firstPageElement === null || firstPageElement === void 0 ? void 0 : firstPageElement.hits) === null || _j === void 0 ? void 0 : _j.returned) !== null && _k !== void 0 ? _k : 0;
(_l = (_j = (_h = body === null || body === void 0 ? void 0 : body.hits) === null || _h === void 0 ? void 0 : _h.returned) !== null && _j !== void 0 ? _j : (_k = firstPageElement === null || firstPageElement === void 0 ? void 0 : firstPageElement.hits) === null || _k === void 0 ? void 0 : _k.returned) !== null && _l !== void 0 ? _l : 0;
console.log('total/returned:', this.totalResults, this.returnedCount);
this.results =
(_l = hits === null || hits === void 0 ? void 0 : hits.map((hit) => { var _a; return SearchResponseDetails.createResult((_a = hit.hit_type) !== null && _a !== void 0 ? _a : schemaHitType, hit); })) !== null && _l !== void 0 ? _l : [];
(_m = hits === null || hits === void 0 ? void 0 : hits.map((hit) => { var _a; return SearchResponseDetails.createResult((_a = hit.hit_type) !== null && _a !== void 0 ? _a : schemaHitType, hit); })) !== null && _m !== void 0 ? _m : [];
console.log(this.results);

@@ -63,9 +67,9 @@ // Construct Aggregation objects

if (body === null || body === void 0 ? void 0 : body.collection_titles) {
this.collectionTitles = (_m = body.collection_titles) !== null && _m !== void 0 ? _m : {};
this.collectionTitles = (_o = body.collection_titles) !== null && _o !== void 0 ? _o : {};
}
if (body === null || body === void 0 ? void 0 : body.collection_extra_info) {
this.collectionExtraInfo = (_o = body.collection_extra_info) !== null && _o !== void 0 ? _o : null;
this.collectionExtraInfo = (_p = body.collection_extra_info) !== null && _p !== void 0 ? _p : null;
}
if (body === null || body === void 0 ? void 0 : body.account_extra_info) {
this.accountExtraInfo = (_p = body.account_extra_info) !== null && _p !== void 0 ? _p : null;
this.accountExtraInfo = (_q = body.account_extra_info) !== null && _q !== void 0 ? _q : null;
console.log('acct extra info (search service)', this.accountExtraInfo);

@@ -72,0 +76,0 @@ }

{
"name": "@internetarchive/search-service",
"version": "1.2.5-alpha.12",
"version": "1.2.5-alpha.13",
"description": "A search service for the Internet Archive",

@@ -5,0 +5,0 @@ "license": "AGPL-3.0-only",

import type { ItemHit } from './item-hit';
import type { TextHit } from './text-hit';
import type { FavoritedSearchHit } from './favorited-search-hit';
import { WebArchiveHit } from './web-archive-hit';

@@ -9,3 +10,3 @@ /**

*/
export type HitType = 'item' | 'text' | 'favorited_search';
export type HitType = 'item' | 'text' | 'favorited_search' | 'web_archive';

@@ -28,3 +29,3 @@ /**

*/
export type SearchResult = Partial<ItemHit & TextHit & FavoritedSearchHit> &
export type SearchResult = Partial<ItemHit & TextHit & FavoritedSearchHit & WebArchiveHit> &
HitInfo;
import { Aggregation } from '../models/aggregation';
import { SearchResult } from '../models/hit-types/hit';
import { ItemHit } from '../models/hit-types/item-hit';

@@ -67,2 +69,10 @@ /**

export type PageElement =
| UploadsPageElement
| ReviewsPageElement
| CollectionsPageElement
| LendingPageElement
| WebArchivesPageElement
| ForumPostsPageElement;
/**

@@ -73,3 +83,3 @@ * A map containing one or more page elements returned by the PPS, keyed by the

export interface PageElementMap
extends Partial<Record<PageElementName, unknown>> {
extends Partial<Record<PageElementName, PageElement>> {
uploads?: UploadsPageElement;

@@ -82,1 +92,25 @@ reviews?: ReviewsPageElement;

}
/**
* Converts dates from web capture "YYYYMMDDhhmmss" format to ISO-8601 "YYYY-MM-DDThh:mm:ssZ" format.
*/
function fixWebCaptureDateFormatting(date: string): string {
return `${date.slice(0, 4)}-${date.slice(4, 6)}-${date.slice(6, 8)}T${date.slice(8, 10)}:${date.slice(10, 12)}:${date.slice(12, 14)}Z`;
}
export function convertWebArchivesToSearchHits(pageElement: WebArchivesPageElement): Record<string, unknown>[] {
const results: Record<string, unknown>[] = [];
for (const entry of pageElement) {
results.push({
hit_type: 'web_archive',
fields: {
title: entry.url,
capture_dates: entry.captures?.map(date => fixWebCaptureDateFormatting(date)),
__href__: `https://web.archive.org/web/${entry.captures[0]}/${encodeURIComponent(entry.url)}`,
},
});
}
return results;
}

@@ -10,3 +10,3 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

import { AccountExtraInfo } from './account-extra-info';
import { PageElementMap, SearchResponseHits } from './page-elements';
import { PageElementMap, SearchResponseHits, convertWebArchivesToSearchHits } from './page-elements';

@@ -88,3 +88,2 @@ /**

let firstPageElement;
console.log(body);
console.log('has page elements?', !!body?.page_elements);

@@ -104,2 +103,5 @@ if (body?.page_elements) {

console.log('hits from page element', hits);
} else if (this.pageElements?.['web_archives']) {
hits = convertWebArchivesToSearchHits(this.pageElements['web_archives']);
console.log('hits from web archives', hits);
}

@@ -106,0 +108,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc