Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 21 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ There's more features, besides. See the detailed list of SDK features on the [re
## Requirements
1. Runtime libraries for Node.js installed. ([instructions](https://nodejs.org/en/download/))

2. To follow the tutorial on this page, also install some other libraries:
* [Express.js](http://expressjs.com/), a minimal web framework,
* The [EJS](https://ejs.co/) templating language, and
* The [UUID](https://www.npmjs.com/package/uuid) library. These are not actually a requirement of the SDK itself, so if your app doesn't use these libraries, no need to install them. They are only required for the tutorial on this page.
2. To follow the tutorial on this page, also install some other libraries:
* [Express.js](http://expressjs.com/), a minimal web framework, and
* The [EJS](https://ejs.co/) templating language.

These are not actually a requirement of the SDK itself, so if your app doesn't use these libraries, no need to install them. They are only required for the tutorial on this page.

Not using Node.js? See the [SDKs for other languages](https://help.learnosity.com/hc/en-us/sections/360000194318-Server-side-development-SDKs).

Expand All @@ -67,16 +68,15 @@ Using NPM is the recommended way to install the Learnosity SDK for Node.js in pr

npm install https://github.com/Learnosity/learnosity-sdk-nodejs

To follow the tutorial on this page, also install some other libraries:
* [Express.js](http://expressjs.com/), a minimal web framework,
* The [EJS](https://ejs.co/) templating language, and
* The [UUID](https://www.npmjs.com/package/uuid) library.
To follow the tutorial on this page, also install some other libraries:
* [Express.js](http://expressjs.com/), a minimal web framework, and
* The [EJS](https://ejs.co/) templating language.

Install these by running the following commands from the root folder of the project.

```
npm install express
npm install ejs
npm install uuid
```

*Note*: these additional libraries are not required by the Learnosity SDK. They are only required for the tutorial on this page.
Expand All @@ -90,16 +90,15 @@ One downloaded, run this command from the root folder to install dependencies:
npm install
```

To follow the tutorial on this page, also install some other libraries:
* [Express.js](http://expressjs.com/), a minimal web framework,
* The [EJS](https://ejs.co/) templating language, and
* The [UUID](https://www.npmjs.com/package/uuid) library.
To follow the tutorial on this page, also install some other libraries:
* [Express.js](http://expressjs.com/), a minimal web framework, and
* The [EJS](https://ejs.co/) templating language.

Install these by running the following commands from the root folder of the project.

```
npm install express
npm install ejs
npm install uuid
```

*Note*: these additional libraries are not required by the Learnosity SDK. They are only required for the tutorial on this page.
Expand All @@ -109,16 +108,15 @@ To install from the terminal, run this command:

git clone git@github.com:Learnosity/learnosity-sdk-nodejs.git

To follow the tutorial on this page, also install some other libraries:
* [Express.js](http://expressjs.com/), a minimal web framework,
* The [EJS](https://ejs.co/) templating language, and
* The [UUID](https://www.npmjs.com/package/uuid) library.
To follow the tutorial on this page, also install some other libraries:
* [Express.js](http://expressjs.com/), a minimal web framework, and
* The [EJS](https://ejs.co/) templating language.

Install these by running the following commands from the root folder of the project.

```
npm install express
npm install ejs
npm install uuid
```

*Note*: these additional libraries are not required by the Learnosity SDK. They are only required for the tutorial on this page.
Expand Down Expand Up @@ -177,12 +175,6 @@ const config = require('../config'); // Load consumer key & secret

<i>(of course, you should never normally put passwords into version control)</i>

We bring in the UUID library.

``` javascript
const uuid = require('uuid'); // Load the UUID library
```

We also specify a few libraries to run a minimal web server, "Express.js" for the purposes of this example.

``` javascript
Expand All @@ -199,9 +191,9 @@ app.set('view engine', 'ejs'); // Set EJS as the templating language
Now we set up the user_id, session_id (both UUID values), and domain configuration.

``` javascript
const user_id = uuid.v4(); // Generate a UUID for the user ID
const session_id = uuid.v4(); // Generate a UUID for the session ID
const domain = 'localhost'; // Set the domain
const user_id = Learnosity.Uuid.generate(); // Generate a UUID for the user ID
const session_id = Learnosity.Uuid.generate(); // Generate a UUID for the session ID
const domain = 'localhost'; // Set the domain
```

Now we'll declare the Learnosity configuration options for Items API. These specify which assessment content should be rendered, how it should be displayed, which user is taking this assessment and how their responses should be stored.
Expand Down Expand Up @@ -234,7 +226,7 @@ app.get('/', function (req, res) {

* `user_id`: unique student identifier. Note: we never send or save student's names or other personally identifiable information in these requests. The unique identifier should be used to look up the entry in a database of students accessible within your system only. [Learn more](https://help.learnosity.com/hc/en-us/articles/360002309578-Student-Privacy-and-Personally-Identifiable-Information-PII-).
* `activity_template_id`: reference of the Activity to retrieve from the Item bank. The Activity defines which Items will be served in this assessment.
* `session_id`: uniquely identifies this specific assessment attempt for save/resume, data retrieval and reporting purposes. Here, we're using the `Uuid` helper to auto-generate a unique session id.
* `session_id`: uniquely identifies this specific assessment attempt for save/resume, data retrieval and reporting purposes. Here, we're using the SDK's `Uuid.generate()` helper to auto-generate a unique session id.
* `activity_id`: a string you define, used solely for analytics to allow you run reporting and compare results of users submitting the same assessment.
* `rendering_type`: selects a rendering mode, `assess` mode is a "standalone" mode (loading a complete assessment player for navigation, as opposed to `inline` for embedding without).
* `type`: selects the context for the student response storage. `submit_practice` mode means the student responses will be stored in the Learnosity cloud, allowing for grading and review.
Expand Down
3 changes: 1 addition & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ Structure of Node.js project (based on Express.js and EJS template):
``` javascript
app.js:

const uuid = require('uuid');
const user_id = uuid.v4();
const Learnosity = require('learnosity-sdk-nodejs');
const user_id = Learnosity.Uuid.generate();
const express = require('express');
const app = express();

Expand Down
5 changes: 2 additions & 3 deletions docs/quickstart/assessment/standalone-assessment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// Include server side Learnosity SDK, and set up variables related to user access.
const Learnosity = require('../../../index'); // Include Learnosity SDK constructor
const config = require('../config'); // Load consumer key & secret from config.js
const uuid = require('uuid'); // Load the UUID library
const express = require('express'); // Load 'Express.js", a web server
const app = express(); // Instantiate the web server

Expand All @@ -16,8 +15,8 @@ app.set('view engine', 'ejs'); // Set EJS as our templating language
// - - - - - - Learnosity server-side configuration - - - - - - //

// Generate the user ID and session ID as UUIDs, set the web server domain.
const user_id = uuid.v4();
const session_id = uuid.v4();
const user_id = Learnosity.Uuid.generate();
const session_id = Learnosity.Uuid.generate();
const domain = 'localhost';

app.get('/', function (req, res) {
Expand Down
5 changes: 2 additions & 3 deletions docs/quickstart/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
const Learnosity = require('../../index');
const DataApi = require('../../lib/DataApi');
const config = require('./config');
const uuid = require('uuid');
const express = require('express');
const packageJson = require('../../package.json');
const app = express();
Expand All @@ -28,8 +27,8 @@ app.get('/', function (req, res) {
// Items API - Standalone Assessment
app.get('/itemsapi', function (req, res) {
const learnositySdk = new Learnosity();
const user_id = uuid.v4();
const session_id = uuid.v4();
const user_id = Learnosity.Uuid.generate();
const session_id = Learnosity.Uuid.generate();

const request = learnositySdk.init(
'items',
Expand Down
3 changes: 1 addition & 2 deletions docs/quickstart/questions/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
const Learnosity = require('../../../index'); // Include Learnosity SDK constructor
const config = require('../config'); // Load consumer key & secret from config.js
const express = require('express'); // Load 'Express.js", a web server
const uuid = require('uuid'); // Load the UUID library
const app = express(); // Instantiate the web server

app.set('view engine', 'ejs'); // Set EJS as our templating language
Expand All @@ -17,7 +16,7 @@ app.set('view engine', 'ejs'); // Set EJS as our templating language
// Set the web server domain.

const domain = 'localhost';
const user_id = uuid.v4();
const user_id = Learnosity.Uuid.generate();

app.get('/', function (req, res) {
const learnositySdk = new Learnosity(); // Instantiate the SDK
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import DataApiClass = require('./lib/DataApi');
import UuidClass = require('./lib/utils/Uuid');

export = LearnositySDK;
/**
Expand All @@ -20,6 +21,7 @@ declare class LearnositySDK {
init(service: Service, securityPacket: SecurityPacket, secret: string, requestPacket: RequestPacket, action?: Action): any;

static DataApi: typeof DataApiClass;
static Uuid: typeof UuidClass;
}
declare namespace LearnositySDK {
export { enableTelemetry, disableTelemetry, SecurityPacket, SDKMeta, RequestMeta, RequestPacket, Service, Action };
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,7 @@ LearnositySDK.prototype.init = function (
// Export DataApi class as a property
LearnositySDK.DataApi = require('./lib/DataApi');

// Export Uuid utility as a property
LearnositySDK.Uuid = require('./lib/utils/Uuid');

module.exports = LearnositySDK;
14 changes: 14 additions & 0 deletions lib/utils/Uuid.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export = Uuid;

/**
* UUID utility for generating UUIDv4 identifiers
* Commonly used for user_id and session_id in Learnosity API requests
*/
declare class Uuid {
/**
* Generate a UUIDv4 string
* @returns A UUIDv4 string
*/
static generate(): string;
}

21 changes: 21 additions & 0 deletions lib/utils/Uuid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

/**
* UUID utility for generating UUIDv4 identifiers
* Commonly used for user_id and session_id in Learnosity API requests
*/

const { v4: uuidv4 } = require('uuid');

class Uuid {
/**
* Generate a UUIDv4 string
* @returns {string} A UUIDv4 string
*/
static generate() {
return uuidv4();
}
}

module.exports = Uuid;

8 changes: 8 additions & 0 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

const Uuid = require('./Uuid');

module.exports = {
Uuid
};

43 changes: 43 additions & 0 deletions test/uuid.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

const assert = require('assert');
const LearnositySDK = require('../index');
const Uuid = LearnositySDK.Uuid;

describe('Uuid utility', () => {
describe('generate()', () => {
it('should generate a valid UUIDv4 string', () => {
const uuid = Uuid.generate();

// UUIDv4 format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
const uuidv4Regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;

assert.strictEqual(typeof uuid, 'string');
assert.strictEqual(uuid.length, 36);
assert.match(uuid, uuidv4Regex);
});

it('should generate unique UUIDs', () => {
const uuid1 = Uuid.generate();
const uuid2 = Uuid.generate();

assert.notStrictEqual(uuid1, uuid2);
});

it('should be accessible via LearnositySDK.Uuid', () => {
assert.strictEqual(typeof LearnositySDK.Uuid, 'function');
assert.strictEqual(typeof LearnositySDK.Uuid.generate, 'function');
});

it('should generate 1000 unique UUIDs', () => {
const uuids = new Set();

for (let i = 0; i < 1000; i++) {
uuids.add(Uuid.generate());
}

assert.strictEqual(uuids.size, 1000);
});
});
});