This package has been deprecated

Author message:

This package is deprecated in favor of @azure/digital-twins-core.

@azure/digital-twins
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-preview.1 • Public • Published

Azure Azure Digital Twins client library for JavaScript

This package contains an isomorphic SDK for Azure Digital Twins API to provide access to the Azure Digital Twins service for managing twins, models, relationships, etc.

Getting started

Currently supported environments

  • Node.js version 6.x.x or higher
  • Browser JavaScript

How to Install

npm install @azure/digital-twins

How to use

nodejs - Authentication, client creation and list digitalTwinModels as an example written in TypeScript.

Install @azure/ms-rest-nodeauth
npm install @azure/ms-rest-nodeauth
Sample code
import * as coreHttp from "@azure/core-http";
import * as coreArm from "@azure/core-arm";
import * as msRestNodeAuth from "@azure/ms-rest-nodeauth";
import {
  AzureDigitalTwinsAPI,
  AzureDigitalTwinsAPIModels,
  AzureDigitalTwinsAPIMappers
} from "@azure/digital-twins";
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];
msRestNodeAuth
  .interactiveLogin()
  .then((creds) => {
    const client = new AzureDigitalTwinsAPI(creds, subscriptionId);
    const dependenciesFor = ["testdependenciesFor"];
    const includeModelDefinition = true;
    const maxItemCount = 1;
    client.digitalTwinModels
      .list(dependenciesFor, includeModelDefinition, maxItemCount)
      .then((result) => {
        console.log("The result is:");
        console.log(result);
      });
  }
  .catch((err) => {
    console.error(err);
  })

browser - Authentication, client creation and list digitalTwinModels as an example written in JavaScript.

Install @azure/ms-rest-browserauth
npm install @azure/ms-rest-browserauth
Sample code

See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser.

  • index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>@azure/digital-twins sample</title>
    <script src="node_modules/@azure/core-http/dist/coreHttp.browser.js"></script>
    <script src="node_modules/@azure/core-arm/dist/coreArm.js"></script>
    <script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script>
    <script src="node_modules/@azure/digital-twins/dist/digital-twins.js"></script>
    <script type="text/javascript">
      const subscriptionId = "<Subscription_Id>";
      const authManager = new msAuth.AuthManager({
        clientId: "<client id for your Azure AD app>",
        tenant: "<optional tenant for your organization>"
      });
      authManager.finalizeLogin().then((res) => {
        if (!res.isLoggedIn) {
          // may cause redirects
          authManager.login();
        }
        const client = new Azure.Digitaltwins.AzureDigitalTwinsAPI(res.creds, subscriptionId);
        const dependenciesFor = ["testdependenciesFor"];
        const includeModelDefinition = true;
        const maxItemCount = 1;
        client.digitalTwinModels
          .list(dependenciesFor, includeModelDefinition, maxItemCount)
          .then((result) => {
            console.log("The result is:");
            console.log(result);
          })
          .catch((err) => {
            console.log("An error occurred:");
            console.error(err);
          });
      });
    </script>
  </head>
  <body></body>
</html

Key concepts

Azure Digital Twins Preview is an Azure IoT service that creates comprehensive models of the physical environment. It can create spatial intelligence graphs to model the relationships and interactions between people, spaces, and devices. You can learn more about Azure Digital Twins by visiting Azure Digital Twins Documentation

Examples

Please take a look at the Readme file in samples directory for detailed examples on how to use this library.

Troubleshooting

Enable logs

You can set the following environment variable to get the debug logging output when using this library.

export AZURE_LOG_LEVEL=verbose

For more detailed instructions on how to enable logs, you can look at the @azure/logger package docs.

Next steps

Please take a look at the samples directory for detailed examples on how to use this library.

Contributing

If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.

Related projects

Package Sidebar

Install

npm i @azure/digital-twins

Weekly Downloads

38

Version

1.0.0-preview.1

License

MIT

Unpacked Size

561 kB

Total Files

33

Last publish

Collaborators

  • microsoft1es
  • azure-sdk