Socket
Socket
Sign inDemoInstall

@uniformdev/canvas-algolia

Package Overview
Dependencies
Maintainers
11
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.1.1-alpha.1 to 17.1.1-alpha.151

102

dist/index.d.ts

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

import { ComponentParameter, ComponentParameterEnhancer } from '@uniformdev/canvas';
import { SearchClient } from 'algoliasearch';
import { LimitPolicy, ComponentParameterEnhancer } from '@uniformdev/canvas';
import { SearchIndex } from 'algoliasearch';
interface SettingsParams {
applicationId: string;
searchKey: string;
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 MeshEditorOptionsParams {
count: number;
source: string;
searchText: string;
facetsValues: {
[name: string]: 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 MeshEditorValueParams {
objectIDs?: string[];
options?: MeshEditorOptionsParams;
index_name?: string;
}
interface Hit {
/** 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 */
objectID: string;
[name: string]: any;
}
};
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 createAlgoliaRecordEnhancer({ clients, limitPolicy, }: CreateAlgoliaRecordEnhancerOptions): ComponentParameterEnhancer<AlgoliaRecordParameterValue, AlgoliaRecordEnhancerResult<unknown>>;
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 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 createEnhancer({ clients, }: createEnhancerOptions): ComponentParameterEnhancer<MeshEditorValueParams>;
declare function createAlgoliaQueryEnhancer({ clients, limitPolicy, }: CreateAlgoliaQueryEnhancerOptions): ComponentParameterEnhancer<AlgoliaQueryParameterValue, AlgoliaQueryEnhancerResult<unknown>>;
declare const ALGOLIA_PARAMETER_TYPES: readonly string[];
export { ALGOLIA_PARAMETER_TYPES, AlgoliaClient, Hit, MeshEditorOptionsParams, MeshEditorValueParams, SettingsParams, createEnhancer, createEnhancerOptions, isParameterOptionsDefined, isParameterValueDefined, parameterIsEntry, parameterIsOptions };
export { AddClientArgs, AlgoliaClientList, AlgoliaQueryEnhancerResult, AlgoliaQueryParameterValue, AlgoliaRecordEnhancerResult, AlgoliaRecordParameterValue, CANVAS_ALGOLIA_QUERY_PARAMETER_TYPES, CANVAS_ALGOLIA_RECORD_PARAMETER_TYPES, CreateAlgoliaQueryEnhancerOptions, CreateAlgoliaRecordEnhancerOptions, createAlgoliaQueryEnhancer, createAlgoliaRecordEnhancer };

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

var s=Object.freeze(["algolia-record-selector","algolia-record-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};
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(["algoliaRecord"]);function N({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=`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 w(e){return e.type===E[0]}function x(e){return!(!e||!e.objectIDs||e.objectIDs.length<1)}var v=Object.freeze(["algoliaQuery"]);function T({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(R(t)){if(!L(t.value))return null;let y=p({clients:e,parameterName:l,parameterValue:t.value,component:s,context:h}),i=t.value,f=b(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 R(e){return e.type===v[0]}function L(e){return!(!e||!e.source||typeof e.searchText=="undefined"||typeof e.count=="undefined")}function b(e){return!e||e<1?1:e>1e3?1e3:e}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}};export{C as AlgoliaClientList,v as CANVAS_ALGOLIA_QUERY_PARAMETER_TYPES,E as CANVAS_ALGOLIA_RECORD_PARAMETER_TYPES,T as createAlgoliaQueryEnhancer,N as createAlgoliaRecordEnhancer};

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

"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-selector","algolia-record-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});
"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:()=>x,CANVAS_ALGOLIA_RECORD_PARAMETER_TYPES:()=>w,createAlgoliaQueryEnhancer:()=>N,createAlgoliaRecordEnhancer:()=>I});module.exports=$(_);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(["algoliaRecord"]);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=`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 O(e){return e.type===w[0]}function F(e){return!(!e||!e.objectIDs||e.objectIDs.length<1)}var x=Object.freeze(["algoliaQuery"]);function N({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(Q(t)){if(!S(t.value))return null;let y=p({clients:e,parameterName:l,parameterValue:t.value,component:s,context:h}),o=t.value,f=T(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 Q(e){return e.type===x[0]}function S(e){return!(!e||!e.source||typeof e.searchText=="undefined"||typeof e.count=="undefined")}function T(e){return!e||e<1?1:e>1e3?1e3:e}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}};0&&(module.exports={AlgoliaClientList,CANVAS_ALGOLIA_QUERY_PARAMETER_TYPES,CANVAS_ALGOLIA_RECORD_PARAMETER_TYPES,createAlgoliaQueryEnhancer,createAlgoliaRecordEnhancer});
{
"name": "@uniformdev/canvas-algolia",
"version": "17.1.1-alpha.1+f2c07b0",
"description": "Algolia data enhancers for Uniform",
"version": "17.1.1-alpha.151+3c57dd245",
"description": "Algolia data enhancers for Uniform Canvas",
"license": "SEE LICENSE IN LICENSE.txt",

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

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

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

"dependencies": {
"@uniformdev/canvas": "17.1.0"
"@uniformdev/canvas": "^17.1.1-alpha.151+3c57dd245"
},
"devDependencies": {
"algoliasearch": "4.13.1"
},
"peerDependencies": {
"algoliasearch": ">= 4"
},
"devDependencies": {
"algoliasearch": "4.14.2"
},
"files": [

@@ -42,3 +42,3 @@ "/dist"

},
"gitHead": "f2c07b0729f376f2f873972308880b426fe39ebc"
"gitHead": "3c57dd245b59aa55368da8991d1e39bc633bbed8"
}

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