npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

samplepartnerapi

v1.0.13

Published

Follow the steps in this page to get started with developing the Sample Component On this page, you will learn how to build simple Component and integrate with MyHub. In the newdirectory use the following command to generate a package.json file

Downloads

14

Readme

Getting Started

Building a Component from scratch

Follow the steps in this page to get started with developing the Sample Component On this page, you will learn how to build simple Component and integrate with MyHub. In the newdirectory use the following command to generate a package.json file

npm init

The Next Step is to add the Component in the src folder

import * as React from "react";

export default function SampleDiv(): React.ReactElement {
    return <div>Hello, world!</div>;
}

Add config.js in the src folder and copy the following lines of code to convert the SampleDiv.tsx into dashboard-card.js bundle.This config file is used in the webpack.config.js for bundling

module.exports = {
    "dashboard-card": "./src/SampleDiv.tsx"
};

Open package.json in your code editor, and add a webpack script (right after the babel script). Also include the related dependencies. The scripts section should now look like this:

{
    "name": "samplepartnerapi",
    "version": "1.0.12",
    "description": "",
    "main": "src/SampleDiv.tsx",
    "scripts": {
    "start": "webpack-dev-server --mode development --open --hot",
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack"
},
    "keywords": [],
    "author": "",
    "license": "ISC",
    "types": "lib/SampleDiv.d.ts",
    "dependencies": {
    /*Add all the required dependencies*/
        "@uifabric/charting": "^0.138.0",
        "axios": "^0.19.0",
        "office-ui-fabric-react": "^7.61.1",
        "react": "^16.12.0",
        "react-dom": "^16.12.0",
        "react-redux": "^7.1.3",
        "react-router-dom": "^5.1.2",
        "redux": "^4.0.4",
        "redux-logger": "^3.0.6",
        "redux-persist": "^6.0.0",
        "redux-saga": "^1.1.3",
        "styled-components": "^4.4.1"
},
    "devDependencies": {
        "eslint": "^6.6.0",
        "eslint-config-prettier": "^6.7.0",
        "eslint-plugin-prettier": "^3.1.1",
        "eslint-plugin-react": "^7.16.0",
        "eslint-plugin-react-hooks": "^2.3.0",
        "@babel/plugin-transform-modules-commonjs": "^7.7.0",
        "ts-loader": "^6.2.1",
        "typescript": "^3.7.2",
        "webpack": "^4.41.2",
        "webpack-cli": "^3.3.10",
        "webpack-dev-server": "^3.9.0"
}

}

Create a new file named webpack.config.js defined as follows:

    var path = require("path");
    var webpack = require("webpack");
    const dashboardDynamicCompnoents = require("./src/config");
    
    const dynamicComponents = {
      /* =========================
       * Add micro-frontend app entry points here
       * ====================== */
      ...dashboardDynamicCompnoents
    };
    
    const globals = {
      /* =========================
       * Add build time variables here
       * These variables also need to added in ./global.d.ts file to be available in Typescript
       * ====================== */
    
      __APP_NAME__: "partnerapi",
      __CLIENT_ID__: process.env.clientId || "dd722e00-f76f-4f10-89cb-f9f8ae3f9b7a",
      __BASE_URL__: process.env.baseUrl || "http://localhost:9003",
      __INSTRUMENTATION_KEY__:
        process.env.instrumentationKey || "958d6073-76a5-443a-9901-9ec4c35c030e"
    };
    
    module.exports = {
      entry: dynamicComponents,
      output: {
        path: path.join(__dirname, "public", "bundles"),
        library: ["__WIDGETS__", "[name]"],
        libraryTarget: "umd"
      },
      externals: {
        react: "React",
        "react-dom": "ReactDOM",
        "react-router-dom": "ReactRouterDOM",
        "styled-components": "styled"
      },
      module: {
        rules: [
          {
            test: /\.ts|\.tsx$/,
            loader: "ts-loader",
            options: {
              transpileOnly: true
            }
          }
        ]
      },
      resolve: {
        extensions: [".ts", ".tsx", ".js"],
        modules: [path.resolve(__dirname, "node_modules"), "node_modules"]
      },
      plugins: [new webpack.DefinePlugin(stringifyConfigValues(globals))],
      devServer: {
        contentBase: path.join(__dirname, "public"),
        compress: true,
        port: 9001,
        historyApiFallback: true,
        writeToDisk: true,
        https: true
      }
    };
    
    function stringifyConfigValues(config) {
      const result = {};
      Object.keys(config).forEach(key => {
        result[key] = JSON.stringify(config[key]);
      });
    
      return result;
    }

Please note that the react dependencies should be added to externals.This allows us to load the dependencies dynamically and reduces the size our code. Also it helps to avoid the version conflicts. Add the global.d.ts file

import * as styledUMD from 'styled-components';

declare global {
    const styled: typeof styledUMD.default;
    const __APP_NAME__: string;
    const __CLIENT_ID__: string;
    const __BASE_URL__: string;
    const __INSTRUMENTATION_KEY__: string;
}

Create a new file named tsconfig.js defined as follows

    {
      "compilerOptions": {
        "jsx": "react",
        "moduleResolution": "node",
        "sourceMap": true,
        "lib": ["dom", "es6"],
        "target": "es5",
        "module": "commonjs",
        "declaration": true,
        "outDir": "./lib",
        "strict": true,
        "esModuleInterop": true
      },
      "include": ["./src/**/*.tsx", "./src/**/*.ts", "./src/ts/**/*"],
      "exclude": ["node_modules"]
    }

Finally, the setup is ready. On the command line, make sure you are in the es6-tutorial directory and type the following command to build the application:

yarn
yarn start

Bundle file is generated using the webpack in the public folder. Please upload the respective bundlefile in Azure CDN.

Integration with MyHub

We have leveraged the Dynamic Component of EE framework to add the component to the MyHub dynamically. Firstly , In the Card.tsx(src/Pages/Dashboard/Card) , import the DynamicComponent dependency by the adding the following code.

import { ComponentProvider } from '@employee-experience/common/lib/ComponentProvider';

Next , Add the following lines of code to integrate the component with myhub.Please make sure the name in the componentConfig is same as the name of the component.

const componentConfig: IComponentConfig = {
    id: 'HELLOCARD_UNIQUE_ID',
    name: 'HelloCard',
    script: 'https://myhubstorageaccount.blob.core.windows.net/myhubcontainer/dashboard-card.js'
};

In <Styled.Body> tag, replace the code as given below

<ComponentProvider
    renderPlaceholder={(): React.ReactElement => <ErrorCard />}
    renderError={(): React.ReactElement => <ErrorCard />}
    config={componentConfig}
/>

Finally , Please build the solution using the following code. The Sample Component is integrated with MyHub and ready for Testing.

yarn
yarn start