azure-search
Advanced tools
Comparing version 0.0.20 to 0.0.21
// entry point for the browser | ||
global.AzureSearch = require('./index') |
45
index.js
@@ -8,3 +8,3 @@ var http = require('https') | ||
if (!options.key) throw new Error('please supply the key of the search service') | ||
if (!options.version) options.version = '2016-09-01' | ||
if (!options.version) options.version = '2017-11-11-Preview' | ||
@@ -42,3 +42,3 @@ var get = function (path, overrides, callback) { | ||
if (options.headers) { | ||
for (var h in options.headers){ | ||
for (var h in options.headers) { | ||
headers[h] = options.headers[h] | ||
@@ -445,2 +445,43 @@ } | ||
createSkillset: function (schema, cb) { | ||
if (!schema) throw new Error('schema is not defined') | ||
post(['skillsets'], schema, function (err, data) { | ||
if (err) return cb(err, null, data) | ||
if (data && data.error) return cb(data.error, null, data) | ||
cb(null, data, data) | ||
}) | ||
}, | ||
updateOrCreateSkillset: function (skillsetName, schema, cb) { | ||
if (!skillsetName) throw new Error('skillsetName is not defined') | ||
if (!schema) throw new Error('schema is not defined') | ||
put(['skillsets', skillsetName], schema, function (err, data) { | ||
if (err) return cb(err, null, data) | ||
if (data && data.error) return cb(data.error, null, data) | ||
cb(null, data, data) | ||
}) | ||
}, | ||
getSkillset: function (skillsetName, cb) { | ||
if (!skillsetName) throw new Error('skillsetName is not defined') | ||
get(['skillsets', skillsetName], null, function (err, data) { | ||
if (err) return cb(err, null, data) | ||
if (data && data.error) return cb(data.error, null, data) | ||
cb(null, data, data) | ||
}) | ||
}, | ||
listSkillsets: function (cb) { | ||
get(['skillsets'], null, function (err, data) { | ||
if (err) return cb(err, null, data) | ||
if (data && data.error) return cb(data.error, null, data) | ||
cb(null, data.value, data) | ||
}) | ||
}, | ||
deleteSkillset: function (skillsetName, cb) { | ||
if (!skillsetName) throw new Error('skillsetName is not defined') | ||
del(['skillsets', skillsetName], function (err, data) { | ||
if (err) return cb(err, null, data) | ||
if (data && data.error) return cb(data.error, null, data) | ||
cb(null, null, data) | ||
}) | ||
}, | ||
then: function (res, rej) { | ||
@@ -447,0 +488,0 @@ var ret = {} |
{ | ||
"name": "azure-search", | ||
"version": "0.0.20", | ||
"version": "0.0.21", | ||
"description": "A client for the Azure Search service", | ||
@@ -24,4 +24,4 @@ "main": "index.js", | ||
"standard": "^7.1.0", | ||
"uglifyjs": "^2.4.0" | ||
"uglify-js": "^2.4.0" | ||
} | ||
} |
@@ -0,1 +1,3 @@ | ||
[![Build Status](https://travis-ci.org/azure-contrib/node-azure-search.svg?branch=master)](https://travis-ci.org/azure-contrib/node-azure-search) | ||
# node-azure-search | ||
@@ -241,3 +243,3 @@ | ||
It is also possible to work with the (currently in preview) synonym maps: | ||
It is also possible to work with Synonym Maps: | ||
@@ -249,3 +251,3 @@ ```js | ||
// Mandatory in order to enable preview support of synonyms | ||
version: '2016-09-01-Preview' | ||
version: '2017-11-11' | ||
}) | ||
@@ -283,2 +285,51 @@ | ||
It is also possible to work with Skillsets for Cognitive Search, currently in preview version '2017-11-11-Preview': | ||
```js | ||
var client = require('azure-search')({ | ||
url: 'https://xxx.search.windows.net', | ||
key: 'your key goes here', | ||
// Mandatory in order to enable preview support of skillsets | ||
version: '2017-11-11-Preview' | ||
}) | ||
var schema = { | ||
name: 'myskillset', // Required for using the POST method | ||
description: 'My skillset description', // Optional | ||
skills: [{ // Required array of skills | ||
'@odata.type': '#Microsoft.Skills.Text.SentimentSkill', | ||
inputs: [{ | ||
name: 'text', | ||
source: '/document/content' | ||
}], | ||
outputs: [{ | ||
name: 'score', | ||
targetName: 'myScore' | ||
}] | ||
}] | ||
} | ||
client.createSkillset(schema, function(err, data) { | ||
// optional error or the created skillset data | ||
}); | ||
client.updateOrCreateSkillset('myskillset', schema, function(err, data) { | ||
// optional error or | ||
// when updating - data is empty | ||
// when creating - data would contain the created skillset data | ||
}); | ||
client.getSkillset('myskillset', function(err, data) { | ||
// optional error or the skillset data | ||
}); | ||
client.listSkillsets(function (err, maps) { | ||
// optional error or the list of skillsets defined under the account | ||
}) | ||
client.deleteSynonymMap('myskillset', function (err) { | ||
// optional error | ||
}); | ||
``` | ||
### Accessing the Raw Response | ||
@@ -285,0 +336,0 @@ |
92
test.js
@@ -5,6 +5,6 @@ /* globals describe, it */ | ||
var clientConfiguration = { | ||
url: 'https://xxx.search.windows.net', | ||
key: 'your key goes here', | ||
url: process.env.URL || 'https://xxx.search.windows.net', | ||
key: process.env.KEY || 'your key goes here', | ||
// This API version is required for all tests to pass | ||
version: '2016-09-01-Preview' | ||
version: '2017-11-11-Preview' | ||
} | ||
@@ -14,3 +14,3 @@ | ||
// Please, also create a container named 'azuresearchtest' in that account (can have private access, and be empty) | ||
var storageConnectionString = 'DefaultEndpointsProtocol=https;AccountName=aaa;AccountKey=bbb' | ||
var storageConnectionString = process.env.CONNECTION_STRING || 'DefaultEndpointsProtocol=https;AccountName=aaa;AccountKey=bbb' | ||
@@ -651,2 +651,86 @@ var clientFactory = require('./index') | ||
it('creates a skillset', function (done) { | ||
var schema = { | ||
name: 'myskillset', | ||
description: 'My skillset', | ||
skills: [{ | ||
'@odata.type': '#Microsoft.Skills.Text.SentimentSkill', | ||
inputs: [{ | ||
name: 'text', | ||
source: '/document/content' | ||
}], | ||
outputs: [{ | ||
name: 'score', | ||
targetName: 'myScore' | ||
}] | ||
}] | ||
} | ||
client.createSkillset(schema, function (err, data) { | ||
if (err) return done('error returned ' + err.message) | ||
if (!data) return done('data is not defined') | ||
if (data.name !== 'myskillset') return done('wrong skillset name') | ||
if (data.description !== 'My skillset') return done('wrong skillset description') | ||
if (data.skills.length !== 1) return done('wrong number of skills') | ||
return done() | ||
}) | ||
}) | ||
it('updates a skillset', function (done) { | ||
var schema = { | ||
name: 'myskillset', | ||
description: 'My updated skillset', | ||
skills: [{ | ||
'@odata.type': '#Microsoft.Skills.Text.SentimentSkill', | ||
inputs: [{ | ||
name: 'text', | ||
source: '/document/content' | ||
}], | ||
outputs: [{ | ||
name: 'score', | ||
targetName: 'myScore' | ||
}] | ||
}] | ||
} | ||
client.updateOrCreateSkillset('myskillset', schema, function (err, data) { | ||
if (err) return done('error returned ' + err.message) | ||
return done() | ||
}) | ||
}) | ||
it('gets a skillset', function (done) { | ||
client.getSkillset('myskillset', function (err, data) { | ||
if (err) return done('error returned ' + err.message) | ||
if (data.name !== 'myskillset') return done('wrong skillset name') | ||
if (data.description !== 'My updated skillset') return done('wrong skillset description') | ||
if (data.skills.length !== 1) return done('wrong number of skills') | ||
return done() | ||
}) | ||
}) | ||
it('lists skillsets', function (done) { | ||
client.listSkillsets(function (err, skillsets) { | ||
if (err) return done('error returned', err) | ||
if (!Array.isArray(skillsets)) return done('indexes is not an array') | ||
var found = false | ||
for (var idx = 0; idx < skillsets.length && !found; idx++) { | ||
if (skillsets[idx].name === 'myskillset') { | ||
found = true | ||
} | ||
} | ||
if (!found) { | ||
return done('Expected skillset "myskillset" was not found') | ||
} | ||
return done() | ||
}) | ||
}) | ||
it('deletes a skillset', function (done) { | ||
client.deleteSkillset('myskillset', function (err) { | ||
if (err) return done('error returned', err) | ||
return done() | ||
}) | ||
}) | ||
it('handles azure errors', function (done) { | ||
@@ -653,0 +737,0 @@ client.getSynonymMap('nonexistant', function (err, data) { |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
196540
7
1752
392
6