Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@uniformdev/canvas-algolia

Package Overview
Dependencies
Maintainers
12
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uniformdev/canvas-algolia - npm Package Compare versions

Comparing version 17.7.1-alpha.34 to 17.8.0

102

dist/index.d.ts

@@ -1,66 +0,52 @@

import { SearchIndex } from 'algoliasearch';
import { LimitPolicy, ComponentParameterEnhancer } from '@uniformdev/canvas';
import { ComponentParameter, ComponentParameterEnhancer } from '@uniformdev/canvas';
import { SearchClient } from 'algoliasearch';
interface AddClientArgs {
/**
* The Algolia source public ID that this client maps to in the composition data.
* This is used to enable multiple Algolia indexes ids as data sources.
* If unspecified, the client will be the default source that is used when no source public ID
* is in the data, or the source ID is 'default'.
*/
source?: string;
/** The Algolia client instance to use when fetching published data */
client: SearchIndex;
/**
* The Algolia client instance to use when fetching preview data.
* If the preview client is not passed, it defaults to the client.
*/
previewClient?: SearchIndex;
interface SettingsParams {
applicationId: string;
searchKey: string;
}
declare class AlgoliaClientList {
private _clients;
constructor(clients?: AddClientArgs[] | AddClientArgs);
addClient({ source, client, previewClient }: AddClientArgs): void;
getClient({ source, isPreviewClient, }: {
source?: string;
isPreviewClient?: boolean;
}): SearchIndex | undefined;
interface MeshEditorOptionsParams {
count: number;
source: string;
searchText: string;
facetsValues: {
[name: string]: string[];
};
}
/** The default shape of the Algolia document. Note that this can change if the query is altered. */
declare type Hit<TFields> = TFields & {
/** System id field returned by the Algolia API */
interface MeshEditorValueParams {
objectIDs?: string[];
options?: MeshEditorOptionsParams;
index_name?: string;
}
interface Hit {
objectID: string;
};
[name: string]: any;
}
declare const CANVAS_ALGOLIA_QUERY_PARAMETER_TYPES: readonly string[];
declare type AlgoliaQueryParameterValue = {
source: string;
searchText: string;
count: number;
facetsValues: Record<string, string[]>;
} | null | undefined;
/** The default shape of the result value of the Algolia Query enhancer. Note that this can change if the query is altered. */
declare type AlgoliaQueryEnhancerResult<TFields> = Hit<TFields>[] | null;
declare type CreateAlgoliaQueryEnhancerOptions = {
/** Either a list of Algolia clients for use with multi-index-enabled Canvas projects. */
clients: AlgoliaClientList;
limitPolicy?: LimitPolicy;
};
declare function createAlgoliaQueryEnhancer({ clients, limitPolicy, }: CreateAlgoliaQueryEnhancerOptions): ComponentParameterEnhancer<AlgoliaQueryParameterValue, AlgoliaQueryEnhancerResult<unknown>>;
declare class AlgoliaClient implements SettingsParams {
applicationId: string;
searchKey: string;
client: SearchClient;
constructor({ applicationId, searchKey }: SettingsParams);
queryObjects({ index_name, options, }: {
index_name: string;
options?: MeshEditorOptionsParams;
}): Promise<Hit[]>;
getObjects({ index_name, objectIDs, }: {
index_name: string;
objectIDs?: string[];
}): Promise<Hit[]>;
}
declare const CANVAS_ALGOLIA_RECORD_PARAMETER_TYPES: readonly string[];
declare type AlgoliaRecordParameterValue = {
source: string;
objectIDs: string[];
} | null | undefined;
/** The default shape of the result value of the Algolia Record enhancer. Note that this can change if the record is altered. */
declare type AlgoliaRecordEnhancerResult<TFields> = (Hit<TFields> | null)[] | null;
declare type CreateAlgoliaRecordEnhancerOptions = {
/** Either a list of Algolia clients for use with multi-index-enabled Canvas projects. */
clients: AlgoliaClientList;
limitPolicy?: LimitPolicy;
declare function parameterIsEntry(parameter: ComponentParameter<MeshEditorValueParams>): boolean;
declare function parameterIsOptions(parameter: ComponentParameter<MeshEditorValueParams>): boolean;
declare function isParameterValueDefined(value: MeshEditorValueParams): boolean;
declare function isParameterOptionsDefined(value: MeshEditorValueParams): boolean;
declare type createEnhancerOptions = {
clients: AlgoliaClient;
};
declare function createAlgoliaRecordEnhancer({ clients, limitPolicy, }: CreateAlgoliaRecordEnhancerOptions): ComponentParameterEnhancer<AlgoliaRecordParameterValue, AlgoliaRecordEnhancerResult<unknown>>;
declare function createEnhancer({ clients, }: createEnhancerOptions): ComponentParameterEnhancer<MeshEditorValueParams>;
export { AddClientArgs, AlgoliaClientList, AlgoliaQueryEnhancerResult, AlgoliaQueryParameterValue, AlgoliaRecordEnhancerResult, AlgoliaRecordParameterValue, CANVAS_ALGOLIA_QUERY_PARAMETER_TYPES, CANVAS_ALGOLIA_RECORD_PARAMETER_TYPES, CreateAlgoliaQueryEnhancerOptions, CreateAlgoliaRecordEnhancerOptions, createAlgoliaQueryEnhancer, createAlgoliaRecordEnhancer };
declare const ALGOLIA_PARAMETER_TYPES: readonly string[];
export { ALGOLIA_PARAMETER_TYPES, AlgoliaClient, Hit, MeshEditorOptionsParams, MeshEditorValueParams, SettingsParams, createEnhancer, createEnhancerOptions, isParameterOptionsDefined, isParameterValueDefined, parameterIsEntry, parameterIsOptions };

@@ -1,1 +0,1 @@

var C=class{constructor(r){this._clients={},Array.isArray(r)?r.forEach(n=>this.addClient(n)):r&&this.addClient(r)}addClient({source:r="default",client:n,previewClient:o}){if(this._clients[r])throw new Error(`The source ${r} is always registered`);if(!n)throw new Error("You must provide an Algolia client for the AlgoliaClientList");this._clients[r]={client:n,previewClient:o||n}}getClient({source:r="default",isPreviewClient:n}){let o=this._clients[r];if(!!o)return n?o.previewClient:o.client}};import{createLimitPolicy as P}from"@uniformdev/canvas";var g=P({throttle:{limit:55,interval:1e3}});function d(e){return typeof e=="string"?e:typeof e=="object"&&e&&"error"in e?e.error:e instanceof Error?e.toString():JSON.stringify(e,null,2)}function p({clients:e,parameterValue:r,parameterName:n,component:o,context:t}){let{source:l="default"}=r,s=e.getClient({source:l,isPreviewClient:t.preview});if(!s)throw new Error(`No Algolia client could be resolved for source key '${l}' referenced in parameter '${n} in component '${o.type}'. Ensure that the 'clients' property you are passing to the enhancer has a client instance registered for the source key.`);return s}var E=Object.freeze(["algoliaQuery"]);function Q({clients:e,limitPolicy:r}){if(!e)throw new Error("No Algolia clients were provided to the enhancer. You must provide at least one client via the AlgoliaClientList.");return{enhanceOne:async function({parameter:t,parameterName:l,component:s,context:h}){var u;if(w(t)){if(!x(t.value))return null;let y=p({clients:e,parameterName:l,parameterValue:t.value,component:s,context:h}),i=t.value,f=v(i.count),c=Object.getOwnPropertyNames(i.facetsValues).filter(a=>Array.isArray(i.facetsValues[a])).map(a=>i.facetsValues[a].map(A=>`${a}:${A}`)),m=`fetch query: ${f} entries with '${i.searchText}' query and '${JSON.stringify(c)}' facets`;try{return console.time(m),(await y.search(i.searchText,{facetFilters:c,offset:0,length:f})).hits}catch(a){let A=d(a);throw new Error(`Failed loading Algolia entries with '${i.searchText}' query and '${JSON.stringify(c)}' facets from source '${(u=i.source)!=null?u:"default"}' referenced in parameter '${l}': ${A}`)}finally{console.timeEnd(m)}}},limitPolicy:r||g}}function w(e){return e.type===E[0]}function x(e){return!(!e||!e.source||typeof e.searchText=="undefined"||typeof e.count=="undefined")}function v(e){return!e||e<1?1:e>1e3?1e3:e}var R=Object.freeze(["algoliaRecord"]);function _({clients:e,limitPolicy:r}){if(!e)throw new Error("No Algolia clients were provided to the enhancer. You must provide at least one client via the AlgoliaClientList.");return{enhanceOne:async function({parameter:t,parameterName:l,component:s,context:h}){var u;if(L(t)){if(!b(t.value))return null;let y=p({clients:e,parameterName:l,parameterValue:t.value,component:s,context:h}),i=t.value,f=`fetch record: ${t.value.objectIDs.length} entries`;try{return console.time(f),(await y.getObjects(t.value.objectIDs)).results}catch(c){let m=d(c);throw new Error(`Failed loading Algolia ${t.value.objectIDs.length} entries from source '${(u=i.source)!=null?u:"default"}' referenced in parameter '${l}': ${m}`)}finally{console.timeEnd(f)}}},limitPolicy:r||g}}function L(e){return e.type===R[0]}function b(e){return!(!e||!e.objectIDs||e.objectIDs.length<1)}export{C as AlgoliaClientList,E as CANVAS_ALGOLIA_QUERY_PARAMETER_TYPES,R as CANVAS_ALGOLIA_RECORD_PARAMETER_TYPES,Q as createAlgoliaQueryEnhancer,_ as createAlgoliaRecordEnhancer};
var s=Object.freeze(["algolia-record","algolia-query"]);function m(t){var e,r;let n=t;return Boolean(s.includes(n.type)&&((e=n.value)==null?void 0:e.objectIDs)&&((r=n.value)==null?void 0:r.index_name))}function p(t){var e,r;let n=t;return Boolean(s.includes(n.type)&&((e=n.value)==null?void 0:e.options)&&((r=n.value)==null?void 0:r.index_name))}function h(t){return Boolean(t==null?void 0:t.objectIDs)}function u(t){return Boolean(t==null?void 0:t.options)}function E({clients:t}){if(!t)throw new Error("No Algolia clients were provided to the enhancer");return{enhanceOne:async function({parameter:e}){if(m(e)){if(!h(e.value))return null;try{let r=t,{objectIDs:a=[],index_name:o=""}=e.value||{};return r.getObjects({index_name:o,objectIDs:a})}catch(r){console.error("Error fetching data from Algolia (Object Selector parameter type). Data enhancer will skip. Details",{error:r})}}else if(p(e)){if(!u(e.value))return null;try{let r=t,{options:a,index_name:o=""}=e.value||{};return r.queryObjects({index_name:o,options:a})}catch(r){console.error("Error fetching data from Algolia (Object Query parameter type). Data enhancer will skip. Details",{error:r})}}}}}import f from"algoliasearch";var c=class{constructor({applicationId:n,searchKey:e}){this.applicationId=n,this.searchKey=e,this.client=f(n,e)}async queryObjects({index_name:n,options:e}){try{if(!e)return[];let r=Object.getOwnPropertyNames(e.facetsValues).filter(i=>Array.isArray(e.facetsValues[i])).map(i=>e.facetsValues[i].map(l=>`${i}:${l}`));return(await this.client.initIndex(n).search(e.searchText,{facetFilters:r,offset:0,length:e.count})).hits}catch(r){throw new Error("Failed to search objects.")}}async getObjects({index_name:n,objectIDs:e=[]}){try{return e.length?(await this.client.multipleGetObjects(e.map(a=>({indexName:n,objectID:a})))).results:[]}catch(r){throw new Error("Failed to get objects.")}}};export{s as ALGOLIA_PARAMETER_TYPES,c as AlgoliaClient,E as createEnhancer,u as isParameterOptionsDefined,h as isParameterValueDefined,m as parameterIsEntry,p as parameterIsOptions};

@@ -1,1 +0,1 @@

"use strict";var C=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var b=(e,r)=>{for(var n in r)C(e,n,{get:r[n],enumerable:!0})},V=(e,r,n,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of R(r))!L.call(e,t)&&t!==n&&C(e,t,{get:()=>r[t],enumerable:!(i=v(r,t))||i.enumerable});return e};var $=e=>V(C({},"__esModule",{value:!0}),e);var _={};b(_,{AlgoliaClientList:()=>P,CANVAS_ALGOLIA_QUERY_PARAMETER_TYPES:()=>w,CANVAS_ALGOLIA_RECORD_PARAMETER_TYPES:()=>x,createAlgoliaQueryEnhancer:()=>I,createAlgoliaRecordEnhancer:()=>Q});module.exports=$(_);var P=class{constructor(r){this._clients={},Array.isArray(r)?r.forEach(n=>this.addClient(n)):r&&this.addClient(r)}addClient({source:r="default",client:n,previewClient:i}){if(this._clients[r])throw new Error(`The source ${r} is always registered`);if(!n)throw new Error("You must provide an Algolia client for the AlgoliaClientList");this._clients[r]={client:n,previewClient:i||n}}getClient({source:r="default",isPreviewClient:n}){let i=this._clients[r];if(!!i)return n?i.previewClient:i.client}};var E=require("@uniformdev/canvas"),g=(0,E.createLimitPolicy)({throttle:{limit:55,interval:1e3}});function d(e){return typeof e=="string"?e:typeof e=="object"&&e&&"error"in e?e.error:e instanceof Error?e.toString():JSON.stringify(e,null,2)}function p({clients:e,parameterValue:r,parameterName:n,component:i,context:t}){let{source:l="default"}=r,s=e.getClient({source:l,isPreviewClient:t.preview});if(!s)throw new Error(`No Algolia client could be resolved for source key '${l}' referenced in parameter '${n} in component '${i.type}'. Ensure that the 'clients' property you are passing to the enhancer has a client instance registered for the source key.`);return s}var w=Object.freeze(["algoliaQuery"]);function I({clients:e,limitPolicy:r}){if(!e)throw new Error("No Algolia clients were provided to the enhancer. You must provide at least one client via the AlgoliaClientList.");return{enhanceOne:async function({parameter:t,parameterName:l,component:s,context:h}){var u;if(O(t)){if(!F(t.value))return null;let y=p({clients:e,parameterName:l,parameterValue:t.value,component:s,context:h}),o=t.value,f=N(o.count),c=Object.getOwnPropertyNames(o.facetsValues).filter(a=>Array.isArray(o.facetsValues[a])).map(a=>o.facetsValues[a].map(A=>`${a}:${A}`)),m=`fetch query: ${f} entries with '${o.searchText}' query and '${JSON.stringify(c)}' facets`;try{return console.time(m),(await y.search(o.searchText,{facetFilters:c,offset:0,length:f})).hits}catch(a){let A=d(a);throw new Error(`Failed loading Algolia entries with '${o.searchText}' query and '${JSON.stringify(c)}' facets from source '${(u=o.source)!=null?u:"default"}' referenced in parameter '${l}': ${A}`)}finally{console.timeEnd(m)}}},limitPolicy:r||g}}function O(e){return e.type===w[0]}function F(e){return!(!e||!e.source||typeof e.searchText=="undefined"||typeof e.count=="undefined")}function N(e){return!e||e<1?1:e>1e3?1e3:e}var x=Object.freeze(["algoliaRecord"]);function Q({clients:e,limitPolicy:r}){if(!e)throw new Error("No Algolia clients were provided to the enhancer. You must provide at least one client via the AlgoliaClientList.");return{enhanceOne:async function({parameter:t,parameterName:l,component:s,context:h}){var u;if(S(t)){if(!T(t.value))return null;let y=p({clients:e,parameterName:l,parameterValue:t.value,component:s,context:h}),o=t.value,f=`fetch record: ${t.value.objectIDs.length} entries`;try{return console.time(f),(await y.getObjects(t.value.objectIDs)).results}catch(c){let m=d(c);throw new Error(`Failed loading Algolia ${t.value.objectIDs.length} entries from source '${(u=o.source)!=null?u:"default"}' referenced in parameter '${l}': ${m}`)}finally{console.timeEnd(f)}}},limitPolicy:r||g}}function S(e){return e.type===x[0]}function T(e){return!(!e||!e.objectIDs||e.objectIDs.length<1)}0&&(module.exports={AlgoliaClientList,CANVAS_ALGOLIA_QUERY_PARAMETER_TYPES,CANVAS_ALGOLIA_RECORD_PARAMETER_TYPES,createAlgoliaQueryEnhancer,createAlgoliaRecordEnhancer});
"use strict";var E=Object.create;var s=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty;var b=(r,t)=>{for(var e in t)s(r,e,{get:t[e],enumerable:!0})},m=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of x(t))!O.call(r,a)&&a!==e&&s(r,a,{get:()=>t[a],enumerable:!(n=g(t,a))||n.enumerable});return r};var A=(r,t,e)=>(e=r!=null?E(y(r)):{},m(t||!r||!r.__esModule?s(e,"default",{value:r,enumerable:!0}):e,r)),j=r=>m(s({},"__esModule",{value:!0}),r);var C={};b(C,{ALGOLIA_PARAMETER_TYPES:()=>c,AlgoliaClient:()=>l,createEnhancer:()=>w,isParameterOptionsDefined:()=>f,isParameterValueDefined:()=>u,parameterIsEntry:()=>p,parameterIsOptions:()=>h});module.exports=j(C);var c=Object.freeze(["algolia-record","algolia-query"]);function p(r){var e,n;let t=r;return Boolean(c.includes(t.type)&&((e=t.value)==null?void 0:e.objectIDs)&&((n=t.value)==null?void 0:n.index_name))}function h(r){var e,n;let t=r;return Boolean(c.includes(t.type)&&((e=t.value)==null?void 0:e.options)&&((n=t.value)==null?void 0:n.index_name))}function u(r){return Boolean(r==null?void 0:r.objectIDs)}function f(r){return Boolean(r==null?void 0:r.options)}function w({clients:r}){if(!r)throw new Error("No Algolia clients were provided to the enhancer");return{enhanceOne:async function({parameter:e}){if(p(e)){if(!u(e.value))return null;try{let n=r,{objectIDs:a=[],index_name:o=""}=e.value||{};return n.getObjects({index_name:o,objectIDs:a})}catch(n){console.error("Error fetching data from Algolia (Object Selector parameter type). Data enhancer will skip. Details",{error:n})}}else if(h(e)){if(!f(e.value))return null;try{let n=r,{options:a,index_name:o=""}=e.value||{};return n.queryObjects({index_name:o,options:a})}catch(n){console.error("Error fetching data from Algolia (Object Query parameter type). Data enhancer will skip. Details",{error:n})}}}}}var d=A(require("algoliasearch")),l=class{constructor({applicationId:t,searchKey:e}){this.applicationId=t,this.searchKey=e,this.client=(0,d.default)(t,e)}async queryObjects({index_name:t,options:e}){try{if(!e)return[];let n=Object.getOwnPropertyNames(e.facetsValues).filter(i=>Array.isArray(e.facetsValues[i])).map(i=>e.facetsValues[i].map(P=>`${i}:${P}`));return(await this.client.initIndex(t).search(e.searchText,{facetFilters:n,offset:0,length:e.count})).hits}catch(n){throw new Error("Failed to search objects.")}}async getObjects({index_name:t,objectIDs:e=[]}){try{return e.length?(await this.client.multipleGetObjects(e.map(a=>({indexName:t,objectID:a})))).results:[]}catch(n){throw new Error("Failed to get objects.")}}};0&&(module.exports={ALGOLIA_PARAMETER_TYPES,AlgoliaClient,createEnhancer,isParameterOptionsDefined,isParameterValueDefined,parameterIsEntry,parameterIsOptions});
{
"name": "@uniformdev/canvas-algolia",
"version": "17.7.1-alpha.34+084da3172",
"description": "Algolia data enhancers for Uniform Canvas",
"version": "17.8.0",
"description": "Algolia data enhancers for Uniform",
"license": "SEE LICENSE IN LICENSE.txt",

@@ -21,3 +21,3 @@ "main": "./dist/index.js",

"clean": "rimraf dist",
"test": "jest --maxWorkers=1",
"test": "jest --maxWorkers=1 --passWithNoTests",
"lint": "eslint \"src/**/*.{js,ts,tsx}\"",

@@ -27,10 +27,10 @@ "format": "prettier --write \"src/**/*.{js,ts,tsx}\""

"dependencies": {
"@uniformdev/canvas": "^17.7.1-alpha.34+084da3172"
"@uniformdev/canvas": "17.7.0"
},
"devDependencies": {
"algoliasearch": "4.13.1"
},
"peerDependencies": {
"algoliasearch": ">= 4"
},
"devDependencies": {
"algoliasearch": "4.14.2"
},
"files": [

@@ -41,4 +41,3 @@ "/dist"

"access": "public"
},
"gitHead": "084da31729798e2c1a1f26ba38c764caabebc958"
}
}

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