### Install Rake and Dependencies Source: https://github.com/aws/aws-sdk-js/blob/master/CONTRIBUTING.md Install Rake and other necessary gems using Bundler to prepare for documentation testing. ```bash bundle install ``` -------------------------------- ### Install PhantomJS for Testing Source: https://github.com/aws/aws-sdk-js/blob/master/CONTRIBUTING.md Install PhantomJS using Homebrew, a dependency for running tests locally. ```bash brew install --cask phantomjs ``` -------------------------------- ### Install Bundler for Documentation Testing Source: https://github.com/aws/aws-sdk-js/blob/master/CONTRIBUTING.md Install the Bundler gem, a prerequisite for managing Ruby dependencies when testing documentation changes. ```bash gem install bundler ``` -------------------------------- ### Installing YARD for JavaScript Dependencies Source: https://github.com/aws/aws-sdk-js/blob/master/doc-src/yard-js/README.md Installs the necessary Ruby dependencies for YARD for JavaScript using Bundler. Ensure Ruby and Bundler are installed prior to running these commands. ```sh $ git clone git://github.com/lsegal/yard-js $ cd yard-js $ bundle install ``` -------------------------------- ### Configuring Mixin Module Expression Source: https://github.com/aws/aws-sdk-js/blob/master/doc-src/yard-js/README.md Specifies the syntax for detecting modules that are mixed into a class. This example uses `mixin` to identify module mixing operations. ```javascript mixin(MyClass, SomeMixin); ``` -------------------------------- ### Configuring Class Definition Expression Source: https://github.com/aws/aws-sdk-js/blob/master/doc-src/yard-js/README.md Specifies the JavaScript syntax used to define classes, enabling YARD to correctly identify class definitions. This example uses `inherit` as the class definition expression. ```javascript inherit(SuperClass, { // class implementation constructor: function() { /* constructor function */ }, foo: function() { /* an instance method */ } }); ``` -------------------------------- ### Configuring Class Update Expression Source: https://github.com/aws/aws-sdk-js/blob/master/doc-src/yard-js/README.md Defines the syntax for updating class objects, typically used for class-level methods or properties. This example uses `update` to identify blocks of class methods. ```javascript update(MyClass, { bar: function() { /* a method only available as MyClass.bar() */ } }); ``` -------------------------------- ### Generate GUID Source: https://github.com/aws/aws-sdk-js/blob/master/test/browser/sample/console.html Generates a universally unique identifier (UUID) using a combination of random numbers. ```javascript function s4() { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1); }; function guid() { return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); } ``` -------------------------------- ### Request Lifecycle Handlers Source: https://github.com/aws/aws-sdk-js/blob/master/test/browser/sample/console.html Defines functions to handle the start and end of AWS SDK requests, updating the history and setting global variables for debugging. ```javascript function startRequest(resp) { addHistoryEntry(resp.request); resp.requestStarted = new Date().getTime(); } function endRequest(resp) { // set window properties for console debugging window.response = resp; window.data = resp.data; window.error = resp.error; window.requestCount++; // update history info try { updateHistoryEntry(resp); } catch (err) { console.log(err.message); console.log(err.stack); } } ``` -------------------------------- ### YARD Options File Configuration Source: https://github.com/aws/aws-sdk-js/blob/master/doc-src/yard-js/README.md A sample `.yardopts` file demonstrating how to configure YARD for JavaScript options, including class definition, update, and mixin expressions, as well as Markdown formatting. ```text --define-class-expr inherit --update-class-expr update --mixin-module-expr mixin ``` -------------------------------- ### Initialize AWS SDK and Load Services Source: https://github.com/aws/aws-sdk-js/blob/master/test/browser/sample/console.html Sets up event listeners for SDK requests and loads available AWS services into a selector. This is typically called on page load. ```javascript function loadServices() { $("#serviceSelector").empty(); for (var key in AWS) { if (AWS[key].serviceIdentifier) { var svcVarName = AWS[key].serviceIdentifier; try { var svc = services[svcVarName] = window[svcVarName] = new AWS[key](); var fullName = svc.api.abbreviation || svc.api.fullName; var el = $("").attr('value', svcVarName).text(fullName); $("#serviceSelector").append(el).change(function () { loadOperationsForService($(this).val()); }); } catch (e) { console.log('Failed to load service ' + key + ': ' + e.message); } } } } function init() { loadEvents(); loaded(); } function loadEvents() { AWS.events. on('send', startRequest). on('complete', endRequest); } function loaded() { $("#selectOperation").tabs({collapsible: true}); $("#executeOperation").click(executeOperation); $("#header .title").text('AWS SDK for JavaScript ' + AWS.VERSION); } $(init); ``` -------------------------------- ### Release New Version and Update Changelog Source: https://github.com/aws/aws-sdk-js/blob/master/scripts/changelog/README.md Run this script for each release to create a new changelog entry based on JSON files in `.changes/next-release/`. It also generates a versioned JSON file in `.changes/` for recreation purposes. The `.changes/` and `next-release/` directories must exist prior to execution. ```bash ./scripts/changelog/release ``` -------------------------------- ### Generate API Documentation Source: https://github.com/aws/aws-sdk-js/blob/master/CONTRIBUTING.md Execute the Rake task to generate the API documentation, which will be saved to doc/latest/_index.html. ```bash bundle exec rake docs:api ``` -------------------------------- ### Initialize S3 Upload and Event Listeners Source: https://github.com/aws/aws-sdk-js/blob/master/test/browser/sample/s3upload.html Sets up event listeners for drag-and-drop file uploads and handles changes to the S3 bucket name. It also initializes the S3 client with the bucket value from local storage. ```javascript var elDropZone = document.getElementById('drop_zone'); var elFile = document.getElementById('file'); var elBucket = document.getElementById('bucket'); var elNotes = document.getElementById('notes'); elBucket.value = localStorage.s3BucketName; var s3 = new AWS.S3({params: {Bucket: elBucket.value || ''}}); function init() { elDropZone.addEventListener('dragover', handleDragOver, false); elDropZone.addEventListener('drop', handleFileSelect, false); elBucket.addEventListener('change', function () { localStorage.s3BucketName = elBucket.value; s3.config.params.Bucket = elBucket.value; }, false); } ``` -------------------------------- ### Run All Tests Source: https://github.com/aws/aws-sdk-js/blob/master/CONTRIBUTING.md Execute all tests for the AWS SDK for JavaScript using npm. ```bash npm test ``` -------------------------------- ### Load Operation Details Source: https://github.com/aws/aws-sdk-js/blob/master/test/browser/sample/console.html Loads and displays the sample input for a selected operation, formatting it for readability. ```javascript function loadOperation(operation) { if (currentOperation === operation) return; currentOperation = operation; var input = currentService.api.operations[operation].input; var obj = {shapeMap: {}}; var sampleInput = inputForShape.call(obj, input); sampleInput = JSON.stringify(sampleInput, null, 2); sampleInput = sampleInput.replace(/(\n\s*)"(.+?)":/g, '$1$2:'); $('#operationData').val(sampleInput); } ``` -------------------------------- ### Create Changelog from JSON Files Source: https://github.com/aws/aws-sdk-js/blob/master/scripts/changelog/README.md Use this script to create or recreate the changelog from JSON files located in the `.changes/` directory. Ensure the `.changes/` directory exists before running. ```bash ./scripts/changelog/create-changelog ``` -------------------------------- ### Initialize Amazon Login Source: https://github.com/aws/aws-sdk-js/blob/master/test/browser/sample/console.html Sets the Amazon App ID and attaches a click handler to the Amazon login button. It then authorizes the user and loads credentials upon successful login. ```javascript window.onAmazonLoginReady = function() { amazon.Login.setClientId(window.appInfo.amazon.appId); $("#login-amazon").click(function() { amazon.Login.authorize({scope: 'profile'}, function(response) { if (!response.error) { loadIDPCredentials('www.amazon.com', response.access_token); } }); }); }; ``` -------------------------------- ### Documenting a JavaScript Class with YARD Source: https://github.com/aws/aws-sdk-js/blob/master/doc-src/yard-js/README.md Demonstrates how to document a JavaScript class and its methods using YARD docstrings. This approach automatically detects class names and details, similar to YARD in Ruby. ```javascript /** * This class represents files on disk. * * @see FileSystem */ inherit(IO, { /** * Opens a new file at the location of `filename` * * @param filename [String] the location on disk of the file to open. * @param access [String] a combination or 'r' and 'w' for access modes. */ constructor: function (filename, access) { ... }, /** * Reads from the open file * * @param numBytes [number] the number of bytes to read. Leave this * empty to read all remaining data. * @return [Buffer] the data read from disk as a buffer. */ read: function (numBytes) { ... } }); ``` -------------------------------- ### Add Changelog Entry Source: https://github.com/aws/aws-sdk-js/blob/master/CONTRIBUTING.md Run this script from the SDK root to add a new entry to the changelog when submitting a pull request. Commit the resulting JSON file. ```bash npm run add-change ``` -------------------------------- ### Facebook SDK Initialization and Auth Response Handling Source: https://github.com/aws/aws-sdk-js/blob/master/test/browser/sample/s3upload.html Initializes the Facebook JS SDK and subscribes to auth response changes. If the user is connected, it loads identity credentials; otherwise, it prompts the user to log in. ```javascript window.fbAsyncInit = function() { FB.init({ appId: window.appInfo.facebook.appId, status: false, xfbml: false }); FB.Event.subscribe('auth.authResponseChange', function(response) { if (response.status === 'connected') { loadIDPCredentials('graph.facebook.com', window.appInfo.facebook.roleArn, response.authResponse.accessToken); } else { FB.login(); } }); FB.getLoginStatus(); }; (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); ``` -------------------------------- ### Add a New Changelog Entry via CLI Source: https://github.com/aws/aws-sdk-js/blob/master/scripts/changelog/README.md This script facilitates the creation of a changelog entry by prompting for the change type, category, and a description. It requires Node.js version 0.12.x or higher. The generated JSON file is placed in `$SDK_ROOT/.changes/next-release/`. ```javascript node ./scripts/changelog/add-change.js ``` -------------------------------- ### Run Unit Tests Source: https://github.com/aws/aws-sdk-js/blob/master/CONTRIBUTING.md Execute only the unit tests for the AWS SDK for JavaScript. ```bash npm run unit ``` -------------------------------- ### Generate Sample Input for Structure Shape Source: https://github.com/aws/aws-sdk-js/blob/master/test/browser/sample/console.html Generates a sample object for a structure shape, including only required members and recursively calling inputForShape for their types. ```javascript function inputForStructure(shape) { var self = this, obj = {}; AWS.util.each(shape.members, function(key, member) { if (shape.required.indexOf(key) < 0) return; ob ``` -------------------------------- ### DOM Content Loaded Initialization Source: https://github.com/aws/aws-sdk-js/blob/master/test/browser/sample/s3upload.html Ensures that the `init` function, which sets up the S3 upload functionality, is called only after the entire HTML document has been loaded and parsed. ```javascript document.addEventListener('DOMContentLoaded', init, false); ``` -------------------------------- ### Load Google Sign-In Client Source: https://github.com/aws/aws-sdk-js/blob/master/test/browser/sample/console.html Dynamically loads the Google+ API client script, which is necessary for implementing Google Sign-In functionality. ```javascript (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/client:plusone.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); ``` -------------------------------- ### Execute AWS SDK Operation Source: https://github.com/aws/aws-sdk-js/blob/master/test/browser/sample/console.html Retrieves parameters from a textarea, evaluates them as JavaScript, and sends the operation to the selected service. Use with caution due to `eval`. ```javascript function executeOperation() { var params = eval('var _=' + ($('#operationData').val() || '{}') + ';_'); currentService[currentOperation](params).send(); } ``` -------------------------------- ### Generate Sample Input for Map Shape Source: https://github.com/aws/aws-sdk-js/blob/master/test/browser/sample/console.html Generates a sample key-value pair for a map shape, recursively calling inputForShape for the value. ```javascript function inputForMap(shape) { return {someKey: inputForShape.call(this, shape.value)}; } ``` -------------------------------- ### Generate Sample Input for List Shape Source: https://github.com/aws/aws-sdk-js/blob/master/test/browser/sample/console.html Generates a sample array with three elements for a list shape, recursively calling inputForShape for the member type. ```javascript function inputForList(shape) { var value = inputForShape.call(this, shape.member); return [value, value, value]; } ``` -------------------------------- ### Load Amazon Login SDK Source: https://github.com/aws/aws-sdk-js/blob/master/test/browser/sample/console.html Dynamically loads the Amazon Login SDK script into the document. This script is required for the Amazon login functionality to work. ```javascript (function(d) { var a = d.createElement('script'); a.type = 'text/javascript'; a.async = true; a.id = 'amazon-login-sdk'; a.src = 'https://api-cdn.amazon.com/sdk/login1.js'; d.getElementById('amazon-root').appendChild(a); })(document); ``` -------------------------------- ### Remove .Client and .client Properties Source: https://github.com/aws/aws-sdk-js/blob/master/UPGRADING.md Remove `.Client` properties from Service classes and `.client` properties from service instances when upgrading. This change simplifies direct access to service operations. ```javascript var sts = new AWS.STS.Client(); // or var sts = new AWS.STS(); sts.client.operation(...); ``` ```javascript var sts = new AWS.STS(); sts.operation(...) ``` -------------------------------- ### Generating JavaScript Documentation with YARD Source: https://github.com/aws/aws-sdk-js/blob/master/doc-src/yard-js/README.md Generates documentation for a JavaScript project using YARD. The `-m markdown` flag enables Markdown for documentation comments, and `-e` specifies the YARD-JS library path. ```sh $ bundle exec yard -m markdown -e /path/to/yard-js/lib/yard-js.rb ``` -------------------------------- ### Template Rendering Source: https://github.com/aws/aws-sdk-js/blob/master/test/browser/sample/console.html Renders HTML templates by replacing placeholders with provided options. Used for dynamically generating UI elements. ```javascript function template(name, options) { var html = $('#template-' + name).html(); html = html.replace(/\{(.+?)\}/g, function(matches, key) { return key in options ? options[key] : ''; }); return html; } ``` -------------------------------- ### Load Operations for Service Source: https://github.com/aws/aws-sdk-js/blob/master/test/browser/sample/console.html Populates the operation selector dropdown for a given AWS service and sets up a change handler. ```javascript function loadOperationsForService(svc) { if (currentServiceVar === svc) return; currentServiceVar = svc; currentService = services[svc]; $('#operationSelector').empty(); for (var key in currentService.api.operations) { var el = $('').attr('value', key).text(key); $('#operationSelector').append(el).change(function() { loadOperation($(this).val()); }); } } ``` -------------------------------- ### Handle File Selection and S3 Upload Source: https://github.com/aws/aws-sdk-js/blob/master/test/browser/sample/s3upload.html Processes dropped files, uploads them to S3 using `s3.putObject`, and displays upload progress and results. It generates a signed URL for retrieved objects and displays them as images. ```javascript function handleFileSelect(evt) { if (firstTime) { firstTime = false; elDropZone.innerHTML = ''; } evt.stopPropagation(); evt.preventDefault(); var files = evt.dataTransfer.files; for (var i = 0; i < files.length; i++) { var params = {Key: files[i].name, ContentType: files[i].type, Body: files[i]}; var req = s3.putObject(params).on('httpUploadProgress', function (progress) { console.log(progress); }).send(function (err, data) { console.log("FINISHED"); if (err) { elDropZone.innerHTML += '
ERROR UPLOADING ' + files[i].name + '
'; } else { var url = s3.getSignedUrl('getObject', {Key: params.Key}); console.log(url) elDropZone.innerHTML += '