From 6fc45952517857f5f24e973740c948e57cdebbe8 Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Wed, 14 Feb 2018 14:51:01 +0000 Subject: [PATCH] Update require references to scoped package --- CHANGES.md | 4 +++- README.md | 30 +++++++++++++++--------------- example/crud.js | 2 +- example/package.json | 4 ++-- package.json | 2 +- test/legacy/readme-examples.js | 30 +++++++++++++++--------------- 6 files changed, 37 insertions(+), 35 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a6e20679..1b4840e0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,6 @@ -# 2.0.2 (UNRELEASED) +# 2.0.2 (2018-02-14) +- [NOTE] Updated `require` references to use scoped package + `@cloudant/cloudant`. # 2.0.1 (2018-02-14) - [NEW] Added API for upcoming IBM Cloud Identity and Access Management support diff --git a/README.md b/README.md index 6e2912f7..30911f59 100644 --- a/README.md +++ b/README.md @@ -38,11 +38,11 @@ This is the official Cloudant library for Node.js. The best way to use the Cloudant client is to begin with your own Node.js project, and define this work as your dependency. In other words, put me in your package.json dependencies. The `npm` tool can do this for you, from the command line: - $ npm install --save cloudant + $ npm install --save @cloudant/cloudant Notice that your package.json will now reflect this package. Everything is working if you can run this command with no errors: - $ node -e 'require("cloudant"); console.log("Cloudant works");' + $ node -e 'require("@cloudant/cloudant"); console.log("Cloudant works");' Cloudant works ### Getting Started @@ -53,7 +53,7 @@ Initialize your Cloudant connection by supplying your *account* and *password*, ~~~ js // Load the Cloudant library. -var Cloudant = require('cloudant'); +var Cloudant = require('@cloudant/cloudant'); var me = 'nodejs'; // Set this to your own account var password = process.env.cloudant_password; @@ -89,7 +89,7 @@ Here is simple but complete example of working with data: require('dotenv').load(); // Load the Cloudant library. -var Cloudant = require('cloudant'); +var Cloudant = require('@cloudant/cloudant'); // Initialize Cloudant with settings from .env var username = process.env.cloudant_username || "nodejs"; @@ -129,7 +129,7 @@ You can find a further CRUD example in the [example](https://github.com/cloudant ### Initialization -To use Cloudant, add `require('cloudant')` in your code. In general, the common style is that `Cloudant` (upper-case) is the **package** you load; whereas `cloudant` (lower-case) is your connection to your database (i.e. the result of calling `Cloudant()`). +To use Cloudant, add `require('@cloudant/cloudant')` in your code. In general, the common style is that `Cloudant` (upper-case) is the **package** you load; whereas `cloudant` (lower-case) is your connection to your database (i.e. the result of calling `Cloudant()`). You can initialize your client in _one_ of the following ways: @@ -138,7 +138,7 @@ You can initialize your client in _one_ of the following ways: You can initialize Cloudant with a URL: ~~~ js -var Cloudant = require('cloudant') +var Cloudant = require('@cloudant/cloudant') var cloudant = Cloudant("http://MYUSERNAME:MYPASSWORD@localhost:5984"); ~~~ @@ -149,14 +149,14 @@ var cloudant = Cloudant("http://MYUSERNAME:MYPASSWORD@localhost:5984"); You can just pass your account name and password (see the [security note](#security-note) about placing your password into your source code). ~~~ js -var Cloudant = require('cloudant'); +var Cloudant = require('@cloudant/cloudant'); var cloudant = Cloudant({account:me, password:password}); ~~~ By default, when you connect to your cloudant account (i.e. "me.cloudant.com"), you authenticate as the account owner (i.e. "me"). However, you can use Cloudant with any username and password. Just provide an additional "username" option when you initialize Cloudant. This will connect to your account, but using the username as the authenticated user. (And of course, use the appropriate password.) ~~~ js -var Cloudant = require('cloudant'); +var Cloudant = require('@cloudant/cloudant'); var me = "nodejs"; // Substitute with your Cloudant user account. var otherUsername = "jhs"; // Substitute with some other Cloudant user account. var otherPassword = process.env.other_cloudant_password; @@ -188,7 +188,7 @@ Cloudant({url:"companycloudant.local", username:"somebody", password:"somebody's You can initialize Cloudant directly from the `VCAP_SERVICES` environment variable. Just pass `vcapServices` and your `vcapInstanceName` (or alias `instanceName`) in the client configuration: ~~~ js -var Cloudant = require('cloudant'); +var Cloudant = require('@cloudant/cloudant'); var cloudant = Cloudant({ vcapInstanceName: 'foo', vcapServices: JSON.parse(process.env.VCAP_SERVICES) }); ~~~ @@ -203,7 +203,7 @@ You can optionally provide a callback to the Cloudant initialization function. T Here is a simple example of initializing asynchronously, using its optional callback parameter: ~~~ js -var Cloudant = require('cloudant'); +var Cloudant = require('@cloudant/cloudant'); var me = 'nodejs'; // Replace with your account. var password = process.env.cloudant_password; @@ -391,7 +391,7 @@ Use the authorization feature to generate new API keys to access your data. An A ### Generate an API key ~~~ js -var Cloudant = require('cloudant'); +var Cloudant = require('@cloudant/cloudant'); var me = 'nodejs'; // Replace with your account. var password = process.env.cloudant_password; var cloudant = Cloudant({account:me, password:password}); @@ -458,7 +458,7 @@ See the [Authorization] documentation for further details. To use an API key, initialize a new Cloudant connection, and provide an additional "key" option when you initialize Cloudant. This will connect to your account, but using the "key" as the authenticated user. (And of course, use the appropriate password associated with the API key.) ~~~ js -var Cloudant = require('cloudant'); +var Cloudant = require('@cloudant/cloudant'); var cloudant = Cloudant({account:"me", key:api.key, password:api.password}); ~~~ @@ -804,7 +804,7 @@ var options = , "password" : "secret" , "requestDefaults": { "proxy": "http://localhost:8080" } } -var cloudant = require('cloudant')(opts); +var cloudant = require('@cloudant/cloudant')(opts); // Now using the HTTP proxy... ~~~ @@ -831,7 +831,7 @@ var myagent = new HttpsAgent({ maxKeepAliveRequests: 0, maxKeepAliveTime: 30000 }); -var cloudant = require('cloudant')({account:"me", password:"secret", requestDefaults:{agent:myagent}}); +var cloudant = require('@cloudant/cloudant')({account:"me", password:"secret", requestDefaults:{agent:myagent}}); // Using Cloudant with myagent... ~~~ @@ -929,7 +929,7 @@ Now your project has the dependency in place, however you can work on both of th Here is simple but complete example of working with data: ~~~ js -var Cloudant = require('cloudant') +var Cloudant = require('@cloudant/cloudant') var me = 'nodejs' // Set this to your own account var password = process.env.cloudant_password diff --git a/example/crud.js b/example/crud.js index 77a2a71e..86b49ca6 100644 --- a/example/crud.js +++ b/example/crud.js @@ -20,7 +20,7 @@ if (!process.env.CLOUDANT_URL) { // load the Cloudant library var async = require('async'); -var Cloudant = require('cloudant'); +var Cloudant = require('@cloudant/cloudant'); var cloudant = Cloudant({url: process.env.CLOUDANT_URL}); var dbname = 'crud'; var db = null; diff --git a/example/package.json b/example/package.json index 99d26282..d60bab1c 100644 --- a/example/package.json +++ b/example/package.json @@ -1,6 +1,6 @@ { "dependencies": { "async": "^1.5.0", - "cloudant": "^1.3.0" + "@cloudant/cloudant": "^2.0.1" } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 5175c113..f1c12f50 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "type": "git", "url": "git@github.com:cloudant/nodejs-cloudant.git" }, - "version": "2.0.2-SNAPSHOT", + "version": "2.0.2", "author": { "name": "IBM Cloudant", "email": "support@cloudant.com" diff --git a/test/legacy/readme-examples.js b/test/legacy/readme-examples.js index 11e69914..eaeca844 100644 --- a/test/legacy/readme-examples.js +++ b/test/legacy/readme-examples.js @@ -47,7 +47,7 @@ var console = { log: function() {} }; describe('Getting Started', function() { var mocks; after(function(done) { - var Cloudant = require('cloudant'); + var Cloudant = require('@cloudant/cloudant'); var cloudant = Cloudant({account: ME, password: PASSWORD, plugins: 'retry'}); cloudant.db.destroy('alice', function(er, d) { should(er).equal(null); @@ -70,7 +70,7 @@ describe('Getting Started', function() { it('Example 1', function(done) { // Load the Cloudant library. - var Cloudant = require('cloudant'); + var Cloudant = require('@cloudant/cloudant'); var me = ME; // Set this to your own account var password = process.env.cloudant_password || 'sjedon'; @@ -87,7 +87,7 @@ describe('Getting Started', function() { it('Example 2', function(done) { // Load the Cloudant library. - var Cloudant = require('cloudant'); + var Cloudant = require('@cloudant/cloudant'); // Initialize Cloudant with settings from .env var username = ME; @@ -132,7 +132,7 @@ describe('Initialization', function() { }); it('Example 1', function(done) { - var Cloudant = require('cloudant'); + var Cloudant = require('@cloudant/cloudant'); var me = ME; // Replace with your account. var password = process.env.cloudant_password || 'sjedon'; @@ -168,7 +168,7 @@ describe('Password authentication', function() { }); it('Example 1', function(done) { - var Cloudant = require('cloudant'); + var Cloudant = require('@cloudant/cloudant'); Cloudant({account: ME, username: ME, password: PASSWORD}, function(er, cloudant, reply) { if (er) { @@ -205,7 +205,7 @@ describe('Authorization and API Keys', function() { }); it('Example 1', function(done) { - var Cloudant = require('cloudant'); + var Cloudant = require('@cloudant/cloudant'); var me = ME; // Replace with your account. var password = process.env.cloudant_password || 'sjedon'; var cloudant = Cloudant({account: me, password: password, plugins: 'retry'}); @@ -272,7 +272,7 @@ describe('CORS', function() { var cloudant; before(function() { - var Cloudant = require('cloudant'); + var Cloudant = require('@cloudant/cloudant'); cloudant = Cloudant({account: ME, password: process.env.cloudant_password, plugins: 'retry'}); }); @@ -327,7 +327,7 @@ describe('Virtual Hosts', function() { var cloudant; before(function() { - var Cloudant = require('cloudant'); + var Cloudant = require('@cloudant/cloudant'); cloudant = Cloudant({account: ME, password: process.env.cloudant_password, plugins: 'retry'}); }); @@ -383,7 +383,7 @@ describe('Cloudant Query', function() { var cloudant, db; before(function(done) { - var Cloudant = require('cloudant'); + var Cloudant = require('@cloudant/cloudant'); cloudant = Cloudant({account: ME, password: process.env.cloudant_password, plugins: 'retry'}); cloudant.db.create('my_db', function(er) { if (er) throw er; @@ -465,7 +465,7 @@ describe('Cloudant Search', function() { var cloudant, db; before(function(done) { - var Cloudant = require('cloudant'); + var Cloudant = require('@cloudant/cloudant'); cloudant = Cloudant({account: ME, password: process.env.cloudant_password, plugins: 'retry'}); cloudant.db.create('my_db', function(er) { if (er) throw er; @@ -552,7 +552,7 @@ describe('Cookie Authentication', function() { var cloudant; var mocks; after(function(done) { - var Cloudant = require('cloudant'); + var Cloudant = require('@cloudant/cloudant'); cloudant = Cloudant({account: ME, password: process.env.cloudant_password, plugins: []}); cloudant.db.destroy('alice', function() { mocks.done(); @@ -567,7 +567,7 @@ describe('Cookie Authentication', function() { .get('/_session').reply(200, {ok: true, userCtx: {name: ME, roles: ['_admin', '_reader', '_writer']}}) .delete('/alice').reply(200, {ok: true}); - var Cloudant = require('cloudant'); + var Cloudant = require('@cloudant/cloudant'); cloudant = Cloudant({account: ME, password: process.env.cloudant_password, plugins: []}); cloudant.db.create('alice', function() { done(); @@ -577,7 +577,7 @@ describe('Cookie Authentication', function() { var cookies; it('Example 1', function(done) { - var Cloudant = require('cloudant'); + var Cloudant = require('@cloudant/cloudant'); var username = ME; // Set this to your own account var password = process.env.cloudant_password || 'sjedon'; var cloudant = Cloudant({account: username, password: password, plugins: []}); @@ -607,7 +607,7 @@ describe('Cookie Authentication', function() { it('Example 2', function(done) { // Make a new connection with the cookie. - var Cloudant = require('cloudant'); + var Cloudant = require('@cloudant/cloudant'); var username = ME; // Set this to your own account var other_cloudant = Cloudant({account: username, cookie: cookies[username], plugins: []}); @@ -632,7 +632,7 @@ describe('Cookie Authentication', function() { it('Example 3', function(done) { // (Presuming the "cookie" global from the above example is still in scope.) - var Cloudant = require('cloudant'); + var Cloudant = require('@cloudant/cloudant'); var username = ME; // Set this to your own account var cloudant = Cloudant({account: username, cookie: cookies[username], plugins: []});