1.0.11 • Published 17 days ago

@gandalf-network/eyeofsauron v1.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
17 days ago

eyeofsauron

eyeofsauron is a command-line tool designed to generate the necessary files that makes it super easy to interact with the Sauron API. It completely abstracts away the complexity of authentication and interacting with the GraphQL APIs.

Features

  • Generate necessary files required for interacting with the Sauron API
  • Automatically install required dependencies

Installation

Prerequisites

  • NodeJS - version 18.x or higher

Installing eyeofsauron

npm install -g @gandalf-network/eyeofsauron

Usage

eyeofsauron generate

Flags

  • -f, --folder folder: Set the destination folder for the generated files

  • -esm, --esModules : Generate JavaScript files as ESModules, utilizing import statements for module imports.

  • -c, --commonJS : Generate JavaScript files as CommonJS modules, using require statements for module imports.

  • -ts, --typescript : Generate TypeScript files.

Using the Generated Files

Once you have successfully generated the necessary files and installed the required dependencies using eyeofsauron, you can proceed to use these files to interact with the API.

Initialization

// Typescript

// Change eyeofsauron to whatever name you specified for the file generation
import Eye, { Source } from './eyeofsauron';

const privateKey = process.env.PRIVATE_KEY
const eye = new Eye({ privateKey })
// ESModules

// Change eyeofsauron to whatever name you specified for the file generation
import Eye, { Source } from './eyeofsauron/index.js'

const privateKey = process.env.PRIVATE_KEY
const eye = new Eye({ privateKey })
// CommonJS

// Change eyeofsauron to whatever name you specified for the file generation
const Eye = require('./eyeofsauron').default
const { Source } = require('./eyeofsauron')

const privateKey = process.env.PRIVATE_KEY
const eye = new Eye({ privateKey })

Get Activity

// index.ts

async function getActivity() {
    try {
        const { data } = await eye.getActivity({
            dataKey: "MY_DATA_KEY",
            source: Source.Netflix,
            limit: 10,
            page: 1,
        })

        const activities = data.data

        for (const activity of activities) {
            console.log(activity?.id)

            const activityMetadata = activity?.metadata

            if (activityMetadata?.__typename === "NetflixActivityMetadata") {
                console.log(activityMetadata.title)
                console.log(activityMetadata.date)
                console.log(activityMetadata.subject)
            }
        }

    } catch (error: any) {
        console.log(error)
    }
}

Lookup Activity

// index.ts

async function lookupActivity() {
    try {
        const { data: activity } = await eye.lookupActivity({
            dataKey: "MY_DATA_KEY",
            activityId: "ACTIVITY_ID",
        })

        console.log(activity.id)

        if (activity.metadata.__typename === "NetflixActivityMetadata") {
            console.log(activity.metadata.date)
            console.log(activity.metadata.title)
            console.log(activity.metadata.subject)
        }
    } catch (error: any) {
        console.log(error)
    }
}

Contributing

Contributions are welcome, whether they're feature requests, bug fixes, or documentation improvements.

1.0.11

17 days ago

1.0.9

1 month ago

1.0.8

1 month ago

1.0.7

1 month ago

1.0.6

1 month ago

1.0.10

1 month ago

1.0.5

1 month ago

1.0.4

2 months ago

1.0.3

2 months ago

1.0.2

2 months ago

1.0.1

2 months ago

1.0.0

2 months ago