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

react-native-azure-cosmos-gremlin

v1.2.0

Published

This package provide rest api for azure cosmos germlin graph data base query access

Downloads

21

Readme

react-native-azure-cosmos-gremlin

This package provide rest api for azure cosmos germlin graph data base query access

Install

Step 1

npm i react-native-azure-cosmos-gremlin --save

Step 2 Azure App Function

create APP FUNCTION project on VS and paste AzureGermlin.cs file content in this repository on it

how to create azure app function :

  • https://docs.microsoft.com/en-us/azure/azure-functions/functions-develop-vs

copy this function on your azure app function body

[FunctionName("AzureGermlin")]
        public static async Task<AzureResult> AzureGermlin(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            try
            {
                var tdate = req.Headers["x-ms-date"].FirstOrDefault();
                var reqDate = Convert.ToDateTime(tdate);
                if (reqDate < DateTime.UtcNow.AddMinutes(-10))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                var auth = req.Headers["Authorization"].FirstOrDefault();
                string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
                var data = JsonConvert.DeserializeObject<GraphQuery>(requestBody);
                var he = $"POST{data.Parameters.Count}AzureGermlin{tdate}";
                string password = $"{YOUR_AZURE_GERMLIN_DB_PASSWORD}";
                var hmacSha256 = new System.Security.Cryptography.HMACSHA256
                {
                    Key = Convert.FromBase64String(password)
                };
                byte[] hashPayLoad = hmacSha256.ComputeHash(System.Text.Encoding.UTF8.GetBytes(he));
                string signature = Convert.ToBase64String(hashPayLoad);
                if (signature != auth)
                {
                    throw new HttpResponseException(HttpStatusCode.Unauthorized);
                }

                data.Parameters.ForEach(t =>
                {

                    data.Query = data.Query.Replace(t.Name, t.Value);
                });




                var gremlinServer = new GremlinServer(YOU_AZURE_GERMLIN_DB_HOST, 443, enableSsl: true,
                                       username: YOU_AZURE_GERMLIN_DB_USERNAME,
                                       password: YOUR_AZURE_GERMLIN_DB_PASSWORD);

                using (var gremlinClient = new GremlinClient(gremlinServer,
                    new GraphSON2Reader(), new GraphSON2Writer(), GremlinClient.GraphSON2MimeType))
                {

                    var resultSet = await gremlinClient.SubmitAsync<dynamic>(data.Query);
                    return new AzureResult() { status = 200, result = resultSet };

                }
            }
            catch (Exception ex)
            {
                return new AzureResult() { status = 500, result = ex.Message };
            }

        }

You can follow this articale to implement your own c# germlin app function

  • https://docs.microsoft.com/en-us/azure/cosmos-db/create-graph-dotnet

Usage

Import library

import { azuregermlinfetch, initCosmosGermlin } from 'react-native-azure-cosmos-gremlin/germlin'

init azure cosmos germlin setting

  constructor(props) {
    super(props);
   initAzureCosmos({
      masterkey: "YOUR_GERMLIN_KEY",
      methodname: "YOUR_APP_FUNCTION_METHOD_NAME",
      serviceurl: "YOUR_APP_FUNCTION_SERVICE_URL"

    })
      ....
  }

upload file from cameraroll :

fetchgermlin = async () => {
   const response = await azuregermlinfetch({
      query: "g.addV('user').property('id', '@id').property('code', '@code').property('photoUri', '@photoUri').property('uid', '@uid')",
      "parameters": [
        { name: "@id", value: "10000000" },
        { name: "@code", value: "001" },
        { name: "@photoUri", value: "" },
        { name: "@uid", value: "[email protected]" },
      ]
    })
    const resData = await response.json();
    console.log(resData);

  }