open-index/open-npm huggingface dataset:
npm package: @jungle-commerce/sdk
Description: Jungle SDK for interacting with the Jungle Platform
Author: Jungle Commerce Pty Ltd
Latest version: 1.0.0-beta.26

# Jungle Commerce SDK

This is a set of libraries for integrating with the Jungle Platform with JavaScript/TypeScript.

## Developing the SDK

To make changes, first modify/add graphql files in the `operations/` folder. Then run:

```sh
npx gql-gen && npm i
```

or use the `SDK - Update` task in VS Code.

This will introspect the GraphQL schema, and regenerate the SDK based on those defined operations.
By default, it will retrieve the schema from your local platform instance.

## Using the SDK

### Getting Started

The preferred way to install the Jungle Commerce SDK for Node.js is to use npm:

```sh
npm install --save @jungle-commerce/sdk
```

### Example (Using API Key)

```ts
import { sdkInit } from "@jungle-commerce/sdk"

const { sdk, sdkApiKey, sdkWsClient } = sdkInit()

sdkApiKey("SecretFromSomewhere") // NOTE: Replace this with your API key.

async function example(sdk: typeof sdk) {
  // Query

  const { product } = await sdk.product({ productId: "abc" })

  // Mutation

  if (!product) {
    const { result } = await sdk.productCreate({ input: { barcode: "abc", name: "Alphabet" } })
    if (result.ok) {
      console.log("YAY!")
    } else {
      console.log("oh no!")
    }
  }

  // Subscription

  const { finished, unsubscribe } = sdk.onNow({
    next: console.log,
  })

  const delay = (() => new Promise((resolve) => setTimeout(resolve, 10000)))()

  await Promise.race([finished, delay]) // if no more msgs, or 10 seconds.

  unsubscribe()
}

example(sdk)
```